Three.js: How to clone a model in THREE.js

Created on 30 Apr 2012  路  5Comments  路  Source: mrdoob/three.js

Hello it's me again

This time I want to have 10 helicopters in my game
They are using the same model,so I think I should load the model only once,right?

So I loaded the model as an object of THREE.Mesh,I gave it a name : myModel

I use myModel for my 10 helicopters
But the problem is I want to make different materials
For example I will change mesh.geometry.materials for each 10 helicopters,to make them look different
But if I use the reference of myModel,the 10 helicopters' mesh are actually the same,right?
So in this way,does it possible to make 10 helicopters different materials?

Or should I clone the mesh?
I've seen the THREE.Mesh and THREE.Geometry source code
There is no clone method(but THREE.Vector3D has)
So if I want to clone a mesh or geometry and don't wanna load it again
what should I to do?

Thank you

Question

Most helpful comment

You need to study more ;)

All 5 comments

loader.load( 'helicopter.js', function ( geometry ) {

    var helicopter1 = new THREE.Mesh( geometry, new THREE.MeshBasicMaterial( { color: 0xff0000 } );
    var helicopter2 = new THREE.Mesh( geometry, new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
    var helicopter3 = new THREE.Mesh( geometry, new THREE.MeshBasicMaterial( { color: 0x0000ff } );
    ...

@mrdoob
I need to load the 10 helicopters in a Dynamic way

I find a way to make it using THREE.GeometryUtils.clone(geometry)
in this way I can clone the geometry
so I can build a new model mesh,right?

You don't need to clone the geometry, if your materials are structurally the same, you can just share the geometry exactly like @mrdoob's example.

@alteredq You are right
I can build different meshs share the same geometry
But I think I should just share the shape,the vertices and faces,but not the materials of the geometry,right?
this way,my helicopters share the same shape and have different texture & color
so what should I do?

By the way,can you tell me the difference between Geometry.materials and Mesh.material ?
I add texture and color to the helicopter using Geometry.materials
I don't know what Mesh.material can do

Thankyou

You need to study more ;)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Bandit picture Bandit  路  3Comments

filharvey picture filharvey  路  3Comments

boyravikumar picture boyravikumar  路  3Comments

danieljack picture danieljack  路  3Comments

zsitro picture zsitro  路  3Comments