How to clone a mesh of a class as3

Software: Away3D 4.x

Nusakan, Newbie
Posted: 28 April 2015 04:10 PM   Total Posts: 10

Hello!
I Have a model 3d that I have exported as class as3 from Prefab, but I donĀ“t know how to clone it.
Some help with this please?
I am using Away 4.1
thx

   

Avatar
Fabrice Closier, Administrator
Posted: 28 April 2015 06:49 PM   Total Posts: 1265   [ # 1 ]

If you use prefab’s class.
just make a new one.

var object1:MyExport = new MyExport();
scene.addChild(object1);
var object2:MyExport = new MyExport();
scene.addChild(object2);

if you want to duplicate one mesh, or want to share its geometry
which is memory wise better than the above

var object1:MyExport = new MyExport();
var m1:Mesh;
var m2:Mesh;
var m3:Mesh;
for(var i:uint=0;i<object1.meshes.length;i++){
  m1 = object1.meshes [ i ];
  m2 = new Mesh(m1.geometry, m1.material); //shares same geometry
  m3 = new Mesh(m1.geometry.clone(), m1.material); //duplicates
  scene.addChild(m1);
  scene.addChild(m2);
  scene.addChild(m3);
}

   

Nusakan, Newbie
Posted: 30 April 2015 06:55 PM   Total Posts: 10   [ # 2 ]

Hey Fabrice! thank you very much!
It was exactly what was searching.
It is a very clear explanation

   

Avatar
Fabrice Closier, Administrator
Posted: 30 April 2015 08:45 PM   Total Posts: 1265   [ # 3 ]

you’re welcome.
Just to be complete: I don’t know what for do you use the exports, but if its a game, many use the Prefab exports to store assets, and init at game level, where the class acts as a library. Because the meshes aren’t registered to library if you dispose a geometry, it’s still available for construct within the class without the need to store it constantly. You may also want to add methods to construct specific meshes as seen into the export main class but be more efficient memory wize. I haven’t added more methods because too many projects require different approaches. But its very easy to extend or alter if you look at these classes.

Glad this old version of Prefab is still of use smile

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X