Question

We are studying on product designer project. Designer is ready.

I want to do 3d preview result with three.js.

How can we texture one side of phone case? or can we border texture mapping?

OBJLoader version: http://www.shopilife.com/baskiburada/viewer/viewer_4.html

And some obj files cannot be textured. Error is "GL_INVALID_OPERATION : glDrawElements: attempt to access out of range vertices in attribute 2" http://www.shopilife.com/baskiburada/viewer/viewer2.html

Was it helpful?

Solution

First, regarding re-texturing the back vs. front of the phone case. The approach here is to seperate the UV coordinates on the model itself. This way you have two sets of materials/textures/UVs. Then during runtime you load them both using a MeshFaceMaterial to load the two materials in an array like so:

materialArray.push(THREE.BasicMeshMaterial({color: 0xff0000})); //use whatever Material type you'd like of course
materialArray.push(THREE.BasicMeshMaterial({color: 0x0000ff}));
var multipleMaterial = new THREE.MeshFaceMaterial(materialArray);
phoneCaseMesh= new THREE.Mesh( geometry, multipleMaterial );

Then when you want to switch one out you would grab the mesh and change the mapping to the desired side something like:

phoneCaseMesh.material.materials[1].map = THREE.ImageUtils.loadTexture( 'newtexture.jpg' );

Second, regarding the Error on you second sample, WestLangley is correct the OBJ file has no UV coordinates to map to, so the index is out of bounds when you apply a texture. If you look at both OBJ files your iphone4.obj has vt entities while the untitled.obj is just v and f. Hope that helps

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top