Making a copy of .obj model

Hi, I am doing MultiPass rendering and I am stuck at following issue:

How to make a copy of a 3d model(ex: .obj model loaded via OBJLoader) so that each copy(I need four) can be rendered with different Custom Shader to Render Targets Seperately. Later on in the final pass these renders can be blended together to produce final material that is rendered to the screen in the end.

I’m not an expert but can’t you just add the same 3D Object to different scenes and then render those scenes into various render targets with different shaders … (Or, even, render the same scene into various render targets)

@GuzmanTierno Sorry I think I was not very clear in my query.

Each 3d mesh has a geometry and a material. When I load a model I use the custom material(via shader). For each pass the geometry is same but the material is different. Thus arises the need to make a copy of the geometry. Just adding the same 3d object to different scenes would not work.

Likewise adding same scene to every render target would not solve the problem, because every seen is different to the extent the material is different(even for the same geometry), thus the mesh is different.

I tried using .clone() function, but it didn’t work.

When you call load on your OBJLoader:

loader.load(
	function ( object ) {
		scene.add( object );
	},
	function ( xhr ) {},
	function ( error ) {}
);

what you receive back in the first function is actually a THREE.Group containing all the meshes with their geometries and materials … so something like

object.children[0].geometry

gives you the geometry of the first object in the group …
that you can use to build a different mesh with new materials (you can also clone the geometry but I don’t think you need to).

@GuzmanTierno Thank you! Your advice worked.

However, I Still had to use copy function:

var geometryS = new THREE.BufferGeometry();

loader.load(function(object){
object.traverse(function(child){
if(child instanceof THREE.Mesh){
//geometryS=child.geometry.clone();
geometryS.copy(child.geometry);
},
.
.
.
);

For some reason I don’t know, directly assigning value of geometry as you suggested or the clone() does not yielded any results on the screen.

1 Like