access meshes by name from AS3 export from Prefab2

Software: Prefab3D

David Mosemann, Newbie
Posted: 21 August 2012 07:15 PM   Total Posts: 18

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(
0i<numOfMeshesi++){
 
var mesh:Mesh _model.meshes[i];
 var 
name:String mesh.name;
 if (
name == "gastank1")
 
{
  mesh
.material = new ColorMaterial(0xFF0000);
 
}

Any suggestions?

Thanks,
David

   

Avatar
Fabrice Closier, Administrator
Posted: 27 August 2012 07:55 PM   Total Posts: 1265   [ # 1 ]

The classes do not register the meshes to the AssetLibrary. (Mmm, may be I could add an option for this…)
You could do it by hand by using the meshes array that the class provides and   add them to the AssetLibrary ( via addAsset ) Then you could access by name from the AssetLibrary ( via getAsset(id) ).

Glad you like the tool!

   

David Mosemann, Newbie
Posted: 30 August 2012 01:47 PM   Total Posts: 18   [ # 2 ]

Thanks for the tip on adding them to the AssetLibrary by hand… working nicely. Although it would be a nice option to have on export from PreFab in the future. I’ll add a post in the Feature Request.

Thanks!

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X