Hi Joseph,
the children array is a property of an ObjectContainer3D.
but depending on the model structure, it can be that the child 0 is
also of the same type.
simple traces as trace(mymodel is Mesh), is ObjectContainer3D etc...
can help you parse your model.
if you however seek a more generic option consider codes like this:
loadedsuccessEvent (e:LoaderEvent)
parse(e.loader.handle);
private function parse(object3d:Object3D):void
{
if(object3d is ObjectContainer3D){
var obj:ObjectContainer3D = (object3d as
ObjectContainer3D);
for(var i:int =0;i<obj.children.length;++i){
if(obj.children[i] is
ObjectContainer3D){
parse(obj.children[i]); --> we
go deeper
} else if(obj.children[i] is Mesh){
doSomething( obj.children[i]); --> do something with the Mesh
object
}
}
} else if(object3d is Mesh){
doSomething( object3d as Mesh); --> do something with the Mesh
object
}
}
Fabrice
On Apr 27, 2009, at 12:29 PM, Joseph wrote:
The only problem is I have never been able to get
object.children.length to work without an error.
I've tried it on the obj loader:
var obj1:Object3DLoader = Obj.load("assetts/teapot_1.obj");
trace(obj1.children.length);
and it results in child.length of 1 ... not sure what that implies for
just the loader ...
tried grabbing the handle and then doing it:
obj1object3d = e.loader.handle;
trace(obj1object3d.children.length);
1119: Access of possibly undefined property children through a
reference with static type away3d.core.base:Object3D.
and tried converting to mesh:
obj1mesh = (obj1object3d as ObjectContainer3D).children[0];
trace(obj1mesh.children.length);
1119: Access of possibly undefined property children through a
reference with static type away3d.core.base:Mesh.
I changed code (since only have 1 child apparently) to:
for ( var j : Number = 0; j < obj1mesh.faces.length; j++ ) {
obj1mesh.faces[j].material = texture3;}
and error popped:
TypeError: Error #1034: Type Coercion failed: cannot convert
Test67_texture3$ to away3d.materials.ITriangleMaterial.
On Apr 27, 2:49 am, routine <[email protected]> wrote:
just try this one:
var texture1 : BitemapFileMaterial = new
BitmapFileMaterial( yourURL);
for ( var i : Number = 0; i < object.children.length; i++ ) {
for ( var j : Number = 0; j <
object.children[i].faces.length; j++ ) {
object.children[i].faces[j].material = texture1;
}
this probably should work.
Roland