Hello,
So I’ve been working with Prefab2 for a few weeks now and really getting the hang of it.. it’s a great and intuitive tool.
So my question is more in regards of accessing individual meshes from my Main class after exporting my model as a AS3. Eventually I’d like to be able to update materials, turn visibility on and off etc. as I continue to expand my understand of Away3d4
Right now, as I’ve set up my work flow, I import a 3ds Max model into Prefab3d2, add lights and update materials, and then export as AS. I can see in the AS3 class where it takes each object from my 3D model and generates a mesh naming it using the name of that object as it was in 3ds Max. But when I go to access that individual mesh from my Main class, i’m getting an undefined property error - obviously I’m not doing something right. Here is that bit of code:
///setting up variables
private var _model:MyClass = new MyClass;
private var _container:ObjectContainer3D = _model.containers[0];
//then later in the initContent i try to change the color of an individual mesh
private function initContent():void
{
_view.scene.addChild(_model);
_camera.lookAt(_model.position);
var gastank:Mesh = _container.gastank1;
gastank.material = new ColorMaterial(0xFF0000);
}
So, the only way I’ve been able to get it to work is to for loop through the meshes array and assign individual meshes through a conditional statement to a new variable. It works fine, but I’m hoping there is a more direct route (read: less code) out there.
for loop code:
var i:int;
var numOfMeshes:int = _model.meshes.length;
for(i = 0; i<numOfMeshes; i++){
var mesh:Mesh = _model.meshes[i];
var name:String = mesh.name;
if (name == "gastank1")
{
mesh.material = new ColorMaterial(0xFF0000);
}
}
Any suggestions?
Thanks,
David