mrdoob/three.js — Issue #1243: Texture Coordinates
Author: gnitsuk
Created: 2012-02-03 16:22:44+00:00
State: open

Hi, can anyone tell me, would the following be the correct way to set the texture coordinates on a custom made triangle?

(it isn't working, if I comment out the triangle code and comment in the new THREE.CubeGeometry then the cube is textured fine)

m_material = new THREE.MeshLambertMaterial( { color: 0xf0c00a, map:texture} );

//m_cubeGeometry = new THREE.CubeGeometry(1,1,1);

m_cubeGeometry = new THREE.Geometry();
m_cubeGeometry.vertices.push(new THREE.Vertex(new THREE.Vector3(-1,-1,0)));
m_cubeGeometry.vertices.push(new THREE.Vertex(new THREE.Vector3(-1,1, 0)));
m_cubeGeometry.vertices.push(new THREE.Vertex(new THREE.Vector3(1,-1,0)));
m_cubeGeometry.faces.push(new THREE.Face3(0,2,1));

m_cubeGeometry.faceUvs = [[]];
m_cubeGeometry.faceVertexUvs = [[]];
m_cubeGeometry.faceUvs[0].push(new THREE.UV(0,1));
m_cubeGeometry.faceUvs[0].push(new THREE.UV(1,1));
m_cubeGeometry.faceUvs[0].push(new THREE.UV(1,0));
m_cubeGeometry.faceVertexUvs[0].push(new THREE.UV(0,1));
m_cubeGeometry.faceVertexUvs[0].push(new THREE.UV(1,1));
m_cubeGeometry.faceVertexUvs[0].push(new THREE.UV(1,1));

m_cubeGeometry.computeCentroids();
m_cubeGeometry.computeFaceNormals();
m_cubeGeometry.computeVertexNormals();

m_cubeMesh = new THREE.Mesh(m_cubeGeometry, m_material);
m_cubeMesh.doubleSided = true;
m_cubeMesh.overdraw = true;
m_scene.add(m_cubeMesh);

Thanks for any help,
Mitch.