|
dmen, Newbie
Posted: 10 August 2011 04:27 PM Total Posts: 11
OK - used Away for sometime, but never did anything too complex with it until now. I have a Collada model exported from Cinema 4D. Loads fine - but I’m having some problems targeting object and materials. I figured preFab would be a big help here but I’m still not quite grasping it.
So, I drop my model into prefab - I see in the Renderings pane 5 meshes… They have ID’s like ID45 and ID9 - How do I target those in AS3 using Away so I can move the mesh, change the material and such?
Also, there is just one texture map applied to all 5 meshes. I need to modify this bitmap in realtime in my project. Not quite sure how I target the texture in code.
Any help much appreciated.
|
Choons, Sr. Member
Posted: 10 August 2011 06:06 PM Total Posts: 281
[ # 1 ]
I haven’t used collada in Away3D but I know that OBJ models get parsed in with names automatically. I usually parse a model into an ObjectContainer3D and then to access the meshes by name I use
for each(var child:Mesh in myObjectContainer3D) {
trace(child.name);
...do other things like assign materials to each mesh using name
}
|
dmen, Newbie
Posted: 10 August 2011 07:58 PM Total Posts: 11
[ # 2 ]
Thanks! I’m probably rustier than I thought - After I load the model I am currently parsing into an Object3D with:
mesh = e.loader.handle;
If I change to objectContainer3D I get an error that it wants Obejct3D…
If I cast to objectContainer3D it’s not working:
mesh = ObjectContainer3D(e.loader.handle);
myScene.addChild(mesh);
for each(var child:Mesh in mesh) {
trace(child.name);
}
I don’t get the model in the scene, and no trace
|
Choons, Sr. Member
Posted: 10 August 2011 08:09 PM Total Posts: 281
[ # 3 ]
I believe that if your model has more than one mesh in it that Object3D gets cast in the background to an ObjectContainer3D. Not sure about that. Try it the way you were doing it and see if that for each(var child:Mesh in mesh) line works. Or you might try mesh = e.loader.handle as ObjectContainer3D and go from there
|
dmen, Newbie
Posted: 10 August 2011 08:16 PM Total Posts: 11
[ # 4 ]
Thanks again.
And Darnit!
Trying it like I had it - just using Object3D I get nothing traced by the for each loop…
I also get no traces using e.loader.handle as ObjectContainer3D
I get the model added to the scene though - all 5 pieces of it. So I’m not sure what I’m doing wrong.
|
dmen, Newbie
Posted: 10 August 2011 08:21 PM Total Posts: 11
[ # 5 ]
PS - If I do:
trace(mesh.children.length);
I get 5.
|
Choons, Sr. Member
Posted: 10 August 2011 08:24 PM Total Posts: 281
[ # 6 ]
OK had a look at some old code. What’s likely going on is your Object3D contains an ObjectContainer3D which in turn contains your mesh objects. So try that trace thing again with the for each instead looking for ObjectContainer3D in your Object3D and see if you get something. It likely won’t have a name so just put “OBJC3D found” in your trace statement to report its presence
|
Choons, Sr. Member
Posted: 10 August 2011 08:35 PM Total Posts: 281
[ # 7 ]
you could also try that with the for each Mesh - just a simple trace “mesh found” in case they aren’t getting parsed in with any names
|
dmen, Newbie
Posted: 10 August 2011 08:36 PM Total Posts: 11
[ # 8 ]
Thanks! That got me where I needed. I ended up using the children property of ObjectContainer3D like so:
var c:Vector.<Object3D> = mesh.children;
for (var i:int = 0; i < c.length; i++) {
trace(c.name);
}
And this traces the ID names I see in PreFab. Then I can get a particular object like so:
flWheel = mesh.getChildByName(“ID45”);
Now to get the material applied so I can change it as needed…
|
Choons, Sr. Member
Posted: 10 August 2011 08:36 PM Total Posts: 281
[ # 9 ]
|
dmen, Newbie
Posted: 10 August 2011 08:50 PM Total Posts: 11
[ # 10 ]
So, If I can get the mesh with getChildByName - how do I go about getting the texture applied to that mesh? I don’t see any applicable methods in the ObejctContainer3D class…
|
Choons, Sr. Member
Posted: 10 August 2011 08:51 PM Total Posts: 281
[ # 11 ]
see if there is a mesh object inside the container3D
|
dmen, Newbie
Posted: 10 August 2011 08:52 PM Total Posts: 11
[ # 12 ]
Yeah, just realized getChildByName returns an Object3D not a container - and Obejct3D does have material methods.
Thanks!
|
Choons, Sr. Member
Posted: 10 August 2011 08:54 PM Total Posts: 281
[ # 13 ]
cool. post a demo in here when ready
|