We can create multiple meshes with the same geometry and material. But are there duplicates in the properties of each meshes ? I'm concerned about memory problems. Thanks !
Asked
Active
Viewed 473 times
1
-
What properties are you talking about ? Have a `console.log(mesh)` to see. : you may want to keep the geometry and material parameters... the rest are few numbers and booleans used to define the orientation, position, shadow casting... – Mouloud85 Oct 19 '15 at 20:51
-
I'm talking about those two properties exactly, there are apparently not reference to an uuid but a instance. I mean, the same geometry with the same uuid is duplicate throught the meshes. it's right ? – Tiramitsu Oct 19 '15 at 21:46
2 Answers
1
As you can see in THREE.Mesh
code :
THREE.Mesh = function ( geometry, material ) {
THREE.Object3D.call( this );
this.type = 'Mesh';
this.geometry = geometry !== undefined ? geometry : new THREE.Geometry();
this.material = material !== undefined ? material : new THREE.MeshBasicMaterial( { color: Math.random() * 0xffffff } );
this.updateMorphTargets();
};
And in the clone
method :
THREE.Mesh.prototype.clone = function () {
return new this.constructor( this.geometry, this.material ).copy( this );
};
That is to say when creating a mesh from a geometry/a material, or cloning a mesh, its geometry and material properties are references to the same objects. If you modify the material's color, or the geometry's vertices, both original and copy will have the new color/geometry.

Mouloud85
- 3,826
- 5
- 22
- 42
-
see also http://stackoverflow.com/questions/14145275/many-meshes-with-the-same-geometry-and-material-can-i-change-their-colors?rq=1 – Mouloud85 Oct 20 '15 at 16:21
-
Perfect ! That what I wanted to know ! Sources are really helpfull, thanks ! – Tiramitsu Oct 23 '15 at 13:36
-
I haven't enough reputation points yet... but, i'll remember ! Be sure ! – Tiramitsu Oct 23 '15 at 15:00
-
@Tiramitsu you can always validate answers. I upvoted your question to give you some initial reputation – Mouloud85 Oct 23 '15 at 19:45
0
I think the best idea is cloning
var Box_geometry = Box_geometry.clone();
var Box_material = Box_material.clone();
I've prepared a simple example in JSFIDDLE.
r.73

MrFreeman555
- 98
- 1
- 12
-
The clone method create a new and separate geometry for each meshes, that is not my goal. I wanted to know if it exist a way for link all the meshes to the same geometry (reference to the a geometry object). Otherwise, hundred meshes in the scene could spend a lot of memory ! Each object3D has a uuid, it can be usefull, or not ? thanks ! – Tiramitsu Oct 20 '15 at 11:36
-
I don't think so, [please take a look in mrdoob page](https://github.com/mrdoob/three.js/issues/4796) – MrFreeman555 Oct 20 '15 at 13:16