Z sorting of 3DS models

Software: Away3D 4.x

jdeluca, Newbie
Posted: 16 July 2012 03:09 PM   Total Posts: 28   [ # 16 ]

Hmmm. Interesting…. That is the first time I ever looked at an obj file in a text editor. Just never thought to do so. Cool..

Ok. Well, I couldn’t find ‘//’ in the obj file. Next I’ll see if I can get some uv’s on this model.

Thanks!

   

jdeluca, Newbie
Posted: 16 July 2012 04:24 PM   Total Posts: 28   [ # 17 ]

Well, I reset uv’s in Blender and then exported again. Still same issue.

I brought it into Prefab and it says the same thing.

I exported OBJ out of prefab.
Loaded it in away3d
The Z buffer issue is still there.

   

jdeluca, Newbie
Posted: 16 July 2012 04:30 PM   Total Posts: 28   [ # 18 ]

A simple cube exported as obj out of blender works fine in away3d.

   

jdeluca, Newbie
Posted: 16 July 2012 04:40 PM   Total Posts: 28   [ # 19 ]

A simple cube that has been extruded in blender exported to obj and loaded into away 3d works fine.

   

John Brookes, Moderator
Posted: 16 July 2012 05:01 PM   Total Posts: 732   [ # 20 ]

You cant have face materials, use a single texture per mesh.
Exports from maya fine with the above.

Actually just noticed you have mesh errors..run cleanup in Maya, you should see them on the wheels.

   

jdeluca, Newbie
Posted: 16 July 2012 05:16 PM   Total Posts: 28   [ # 21 ]

Thanks John trying that now.

   

jdeluca, Newbie
Posted: 16 July 2012 06:11 PM   Total Posts: 28   [ # 22 ]

Well I haven’t tried the cleanup yet.

I just tried another version of the same 3d model that was a new export from maya with my requests. Single object scaled correctly with initial shading group.

I had no errors bringing it into Prefab but it locked it up.

I was able to bring it into blender. There was no material so I assigned it a material.

I exported a new one. Brought it into Prefab with no errors. It looked correct with a mat material.

Then loaded it into Away 3d and still have the same results.

Frustrating…..

   

jdeluca, Newbie
Posted: 16 July 2012 09:14 PM   Total Posts: 28   [ # 23 ]

I have put textures on the models to see if that worked any better.  Still having the same rendering issues.

I did fix a model that was partly invisible by fixing its uv mapping. I’m still seeing parts of the model through itself and objects that should be passing underneath objects are appearing on top.

   

jdeluca, Newbie
Posted: 16 July 2012 10:13 PM   Total Posts: 28   [ # 24 ]

Alright… I decided to quit worrying with the 3d model rendering issues.

Focusing only on the z depth issues. Models appearing in front of other models when they should be behind them.

I created some spheres and added them to the view. Somehow it is always getting the z depth wrong.

The sphere that is furthest from the camera is always shown in front. It does not matter the order which I create them either.

   

John Brookes, Moderator
Posted: 16 July 2012 10:29 PM   Total Posts: 732   [ # 25 ]

I think you meed to post some code of what your doing.
If anyhthing, away 4 doesnt have z sorting issues.

   

jdeluca, Newbie
Posted: 17 July 2012 03:55 PM   Total Posts: 28   [ # 26 ]

Thanks John. It has to be something I am doing wrong. I know it. Today I swapped out the 4.0.7 swc and it renders the same. So here is some code

private var view:View3D;
private var g:GameGlobals= GameGlobals.getInstance();

protected function init():void

  setupAway3D();
  setupLights();
  setupGeometry();
  setupSkyBox();
  setupCameras();
 

 
  //var HUD:MovieClip= new HUD_mc();
  //HUDSprite.addChild(HUD);
  //HUDSprite.x=stage.stageWidth/2;
  //HUDSprite.y=stage.stageHeight/2;
 
  BtnShoot.y=(stage.stageHeight-BtnShoot.height)/2
}

private function setupAway3D():void{
  //setup Away3D
  view=new View3D();
  g.view=view;
  g.view.backgroundColor = 0x666666;
  g.view.antiAlias = 4;
  away3DContainer.addChild(g.view);
}

private var pointLight:PointLight;
private var directionalLight:DirectionalLight;
private var fillLighting:PointLight;
private var keyLighting:PointLight;
private var backLighting:PointLight;
private var frontLighting:PointLight;

private function setupLights():void{
trace(“setup lights”);
// Setup Pointlight 1
pointLight = new PointLight();
pointLight.diffuse = 0.4;
pointLight.specular = 0.5;
pointLight.y = 1000;
pointLight.x = 1000;
pointLight.z = 1000;
g.pointLight=pointLight;
g.view.scene.addChild(g.pointLight);

// Setip DirectLIghting 1
directionalLight = new DirectionalLight();
directionalLight.diffuse = 0.4;
directionalLight.specular = 0.5;
directionalLight.y = 1000;
directionalLight.x = -1000;
directionalLight.z = -1000;
g.directionalLight=directionalLight;
g.view.scene.addChild(g.directionalLight);

// Setup fillLighting
fillLighting = new PointLight();
fillLighting.diffuse = 0.5;
fillLighting.specular = 0.7;
fillLighting.y = 50000;
fillLighting.x = -50000;
fillLighting.z = -50000;
fillLighting.radius = 89;
fillLighting.fallOff = 250;
g.fillLighting=fillLighting;
g.view.scene.addChild(g.fillLighting);

// Setup keyLighting
keyLighting = new PointLight();
keyLighting.diffuse = 0.3;
keyLighting.specular = 0.5;
keyLighting.y = 90000;
keyLighting.x = 50000;
keyLighting.z = -50000;
keyLighting.radius = 452;
keyLighting.fallOff = 1000;
g.keyLighting=keyLighting;
g.view.scene.addChild(g.keyLighting);

// Setup backLighting
backLighting = new PointLight();
backLighting.diffuse = 0.3;
backLighting.specular = 0.5;
backLighting.y = 90000;
backLighting.x = 0;
backLighting.z = 50000;
g.backLighting=backLighting;
g.view.scene.addChild(g.backLighting);

// Setup frontLighting
frontLighting = new PointLight();
frontLighting.diffuse = 0.3;
frontLighting.specular = 0.2;
frontLighting.y = 90000;
frontLighting.x = 0;
frontLighting.z = -50000;
g.frontLighting=frontLighting;
g.view.scene.addChild(g.frontLighting);

var staticLightPicker:StaticLightPicker = new StaticLightPicker([pointLight, fillLighting, directionalLight]);
g.staticLightPicker=staticLightPicker;
//planeMaterial.lights=[pointLight, directionalLight, fillLighting, keyLighting, backLighting, frontLighting];
}

private function setupGeometry():void
{
 
var colorRed:ColorMaterial= new ColorMaterial(0x990000,0); //1 is alpha transparent
//colorRed.lightPicker = g.staticLightPicker;
var colorGreen:ColorMaterial= new ColorMaterial(0x73F673,0); //1 is alpha transparent
//colorGreen.lightPicker = g.staticLightPicker;
var colorBlue:ColorMaterial= new ColorMaterial(0x0000FF,0); //1 is alpha transparent
//colorBlue.lightPicker = g.staticLightPicker;
var colorOrange:ColorMaterial= new ColorMaterial(0xFD8700,0); //1 is alpha transparent
//colorOrange.lightPicker = g.staticLightPicker;
var colorYellow:ColorMaterial= new ColorMaterial(0xFFFF00,0); //1 is alpha transparent
//colorYellow.lightPicker = g.staticLightPicker;

createHitObject(“sphere1”,colorRed, 100, 1000, 0, 200);
createHitObject(“sphere2”,colorBlue, 100, 1000, -200, 200);
createHitObject(“sphere3”,colorGreen, 100, 1000, -400, 200);
createHitObject(“sphere4”,colorOrange, 100, 1000, -600, 200);
createHitObject(“sphere5”,colorYellow, 100, 1000, -800, 200);

addHitObjectsArrayToView();

var loadGlobalHawk:LoaderGlobalHawk= new LoaderGlobalHawk();
var loadMQ1:LoaderMQ1= new LoaderMQ1();
var loadMQ9:LoaderMQ9= new LoaderMQ9();
var loadRQ11Raven:LoaderRQ11Raven = new LoaderRQ11Raven();
var loadRQ170:LoaderRQ170 = new LoaderRQ170();
var loadRQ7Shadow:LoaderRQ7Shadow = new LoaderRQ7Shadow();
var loadScanEagle:LoaderScanEagle = new LoaderScanEagle();
loadGlobalHawk=null;
loadMQ9=null;
loadRQ11Raven=null;
loadRQ170=null;
loadRQ7Shadow=null;
loadScanEagle=null;
g.view.camera.lookAt(new Vector3D(2000,0,0));

var LoadAllModelsTimer:Timer = new Timer(1000);
LoadAllModelsTimer.addEventListener(TimerEvent.TIMER, checkAllModelsLoaded);
LoadAllModelsTimer.start();

}

Code continued in next post

   

jdeluca, Newbie
Posted: 17 July 2012 04:00 PM   Total Posts: 28   [ # 27 ]

private function checkAllModelsLoaded(event:TimerEvent):void
{
var checkTimer:Timer = event.currentTarget as Timer;
if ((g.isGlobalHawkLoaded)&&(g.isMQ1Loaded)&&(g.isMQ9Loaded)&&(g.isRQ11RavenLoaded)&&(g.isScanEagleLoaded))
//if (g.isGlobalHawkLoaded)
{
  g.areAllModelsLoaded=true;
  var mesh0:Mesh = g.meshGlobalHawk.clone() as Mesh;
  var mesh0Container:ObjectContainer3D = new ObjectContainer3D;
  mesh0Container.addChild(mesh0);
 
  var mesh1:Mesh = g.meshMQ1.clone() as Mesh;
  var mesh1Container:ObjectContainer3D = new ObjectContainer3D;
  mesh1Container.addChild(mesh1);
 
  var mesh2:Mesh = g.meshRQ7Shadow.clone() as Mesh;
  var mesh2Container:ObjectContainer3D = new ObjectContainer3D;
  mesh2Container.addChild(mesh2);
 
  var mesh3:Mesh = g.meshRQ11Raven.clone() as Mesh;
  var mesh3Container:ObjectContainer3D = new ObjectContainer3D;
  mesh3Container.addChild(mesh3);
 
  var mesh4:Mesh = g.meshRQ170.clone() as Mesh;
  var mesh4Container:ObjectContainer3D = new ObjectContainer3D;
  mesh4Container.addChild(mesh4);
 
  g.hitObjectsArray[0][“objContainer”].getChildAt(0).addChild(mesh0Container);
  g.hitObjectsArray[1][“objContainer”].getChildAt(0).addChild(mesh1Container);
  g.hitObjectsArray[2][“objContainer”].getChildAt(0).addChild(mesh2Container);
  g.hitObjectsArray[3][“objContainer”].getChildAt(0).addChild(mesh3Container);
  g.hitObjectsArray[4][“objContainer”].getChildAt(0).addChild(mesh4Container);
  checkTimer.stop();
  setupAccelerometer();
}
else{
  trace(“g.isGlobalHawkLoaded=”+g.isGlobalHawkLoaded.toString());
  //  trace(“g.isMQ1Loaded=”+g.isMQ1Loaded.toString());
  //  trace(“g.isMQ9Loaded=”+g.isMQ9Loaded.toString());
  //  trace(“g.isRQ11RavenLoaded=”+g.isRQ11RavenLoaded.toString());
  //  trace(“g.isRQ170Loaded=”+g.isRQ170Loaded.toString());
  //  trace(“g.isRQ7ShadowLoaded=”+g.isRQ7ShadowLoaded.toString());
  trace(“g.isScanEagleLoaded=”+g.isScanEagleLoaded.toString());
}
}

private function createHitObject(sphereName:String,
      colorMaterial:ColorMaterial,
      sphereScale:int,
      sphereX:int,
      sphereY:int,
      sphereZ:int):void{
var sphereGeometry:SphereGeometry =new SphereGeometry(sphereScale,8,6,true);
var sphereMesh:Mesh = new Mesh(sphereGeometry);//new Mesh(sphereGeometry, colorMaterial)// new Mesh(sphereGeometry)
sphereMesh.x=sphereX;sphereMesh.y=sphereY;sphereMesh.z=sphereZ;
var sphereGrp:ObjectContainer3D = new ObjectContainer3D();
sphereGrp.addChild(sphereMesh);

var hitObject:Object = {objName:sphereName,
    objContainer:sphereGrp,
    objColor:colorMaterial,
    objScale:sphereScale,
    objX:sphereX,
    objY:sphereY,
    objZ:sphereZ};
g.hitObjectsArray.push(hitObject);

}

[Embed(source=“GameAssets/SkyBox2/Top.jpg”)]
private var skyTop:Class;
[Embed(source=“GameAssets/SkyBox2/Bottom.jpg”)]
private var skyBottom:Class;
[Embed(source=“GameAssets/SkyBox2/Right.jpg”)]
private var skyRight:Class;
[Embed(source=“GameAssets/SkyBox2/Left.jpg”)]
private var skyLeft:Class;
[Embed(source=“GameAssets/SkyBox2/Front.jpg”)]
private var skyFront:Class;
[Embed(source=“GameAssets/SkyBox2/Back.jpg”)]
private var skyBack:Class;

private function setupSkyBox():void{
// Setup Skybox with Texture

var _skyboxCubeMap:BitmapCubeTexture= new BitmapCubeTexture(
  new skyRight().bitmapData, new skyLeft().bitmapData,
  new skyTop().bitmapData, new skyBottom().bitmapData,
  new skyFront().bitmapData, new skyBack().bitmapData
);
var _skybox:SkyBox = new SkyBox(_skyboxCubeMap);
_skybox.scale(3);
g.view.scene.addChild(_skybox);
}

private var accelerometer:Accelerometer; 

private function setupAccelerometer():void
{
if (Accelerometer.isSupported==true)
{
  accelerometer = new Accelerometer();
  accelerometer.setRequestedUpdateInterval(10);
  accelerometer.addEventListener(AccelerometerEvent.UPDATE, Accelerometer_onUpdate);
}
}

private function Accelerometer_onUpdate(event:AccelerometerEvent):void
{
//constrain the camera UP DN
if ((g.view.camera.rotationX<=60)&&(g.view.camera.rotationX>=-60))
  {g.view.camera.rotationX-=event.accelerationY*10;}
else if (g.view.camera.rotationX>60)
  {g.view.camera.rotationX=60;}
else if (g.view.camera.rotationX<-60)  {g.view.camera.rotati

g.view.camera.rotationY-=event.accelerationX*10;//left Right
animateBox();

}

//private var hitCount:int=0
private function checkCollision():void
{
var _ray:Ray=new Ray();
var cameraVector:Vector3D = view.camera.position;
var directionVector:Vector3D = Matrix3DUtils.getForward(g.view.camera.transform);
directionVector.normalize();


for (var _i:int = 0; _i < g.hitObjectsArray.length; _i++)
{
  var _obj:Mesh = g.hitObjectsArray[_i][“objContainer”].getChildAt(0);
  var _objPosition:Vector3D = _obj.scenePosition;
 
  var isColliding:Boolean = _ray.intersectsSphere(cameraVector, directionVector, _objPosition, g.hitObjectsArray[_i][“objScale”]);
  if (isColliding == true)
  {
  trace(g.hitObjectsArray[_i][“objName”]);
  //hitCount++;
  //trace(“HIT COUNT=”+ hitCount.toString());
  }
}

}

private function animateBox():void
{
// rotate the group of objects
//cubeGroup.yaw(1);
if (g.isCreatedHitObject==true)
{
  g.hitObjectsArray[0][“objContainer”].rotationY+=0;
  g.hitObjectsArray[1][“objContainer”].rotationY+=.2;
  g.hitObjectsArray[2][“objContainer”].rotationY+=.4;
  g.hitObjectsArray[3][“objContainer”].rotationY+=.5;
  g.hitObjectsArray[4][“objContainer”].rotationY+=.8;
 
}
// rotate the sphere
//cubeModel.yaw(-10);
g.view.render();
}

private function BtnShoot_onClick():void
{
checkCollision();
}

code continued in next post

   

jdeluca, Newbie
Posted: 17 July 2012 04:02 PM   Total Posts: 28   [ # 28 ]

BELOW is the LoaderGlobalHawk class.

public class LoaderGlobalHawk extends ObjectContainer3D

  private var jetLoader:Loader3D;
  private var g:GameGlobals= GameGlobals.getInstance();
  public function LoaderGlobalHawk()
  {
  //Loader3D.enableParser(Max3DSParser);
  Loader3D.enableParser(OBJParser);
  jetLoader = new Loader3D(); 
  jetLoader.addEventListener(LoaderEvent.RESOURCE_COMPLETE, onResourceComplete_jetLoader);
  jetLoader.addEventListener(LoaderEvent.LOAD_ERROR, onLoadError_jetLoader);
  jetLoader.load(new URLRequest(‘GameAssets/Models3D/OBJ/GlobalHawk.obj’));
  }
 
  private function onLoadError_jetLoader(e:LoaderEvent) : void
  {
  trace(‘Could not find’, e.url);
  jetLoader.removeEventListener(LoaderEvent.RESOURCE_COMPLETE, onResourceComplete_jetLoader);
  jetLoader.removeEventListener(LoaderEvent.LOAD_ERROR, onLoadError_jetLoader);
  jetLoader = null;
  }
 
  private function onResourceComplete_jetLoader(e:LoaderEvent) : void
  {
  jetLoader.removeEventListener(LoaderEvent.RESOURCE_COMPLETE, onResourceComplete_jetLoader);
  jetLoader.removeEventListener(LoaderEvent.LOAD_ERROR, onLoadError_jetLoader);
  jetLoader.x=0;jetLoader.y=0;jetLoader.z=0;
  //jetLoader.x=1000;

  var colorMat:ColorMaterial= new ColorMaterial(0xffffff);//for some reason 1 does not work correctly.
  var mesh:Mesh = Mesh(jetLoader.getChildAt(0));
 
  mesh.material = colorMat;
  mesh.material.lightPicker=g.staticLightPicker;
  mesh.scale(30);
  g.meshGlobalHawk = mesh;
  jetLoader=null;
  mesh=null;
  colorMat=null;
   
  g.isGlobalHawkLoaded=true;
  trace(“isGlobalHawkLoaded=true”);
  }
}

   

jdeluca, Newbie
Posted: 17 July 2012 04:15 PM   Total Posts: 28   [ # 29 ]

The code above is an earlier version but it is essentially the same.

The gameGlobals is a singleton with a references to objects that I need to use in other classes. Mainly the only classes that I need to reference anything is the Loader Classes for loading the 3d models.

When the model loads i put it in the gameGlobals and clone it when I need it.

There is some comments I forgot to remove in function setupGeometry. //1 is alpha transparent That was fixed in a previous build of away3d.

In a later version I actually apply the materials to the clones and they come through with a solid color. I changed that to use a bitmap texture but I kept seeing through the geometry in certain places.

I did a simple test yesterday and this morning of simple sphere meshes with no ObjectContainer3D. I created all the same size spheres with a different y position. The same x position away from the camera(so they are visible from the camera which is at the origin). The sphere were big so they overlap each other.

The findings are that the one that should be furthest from the camera is in front.

So today I played with camera lenses and a new camera. No such luck. I know it has to be something simple but I just can’t seem to pinpoint it.

Thanks for any help! smile

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X