Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
90
rated 0 times [  91] [ 1]  / answers: 1 / hits: 40975  / 12 Years ago, thu, april 26, 2012, 12:00:00

I want to do picking via IdMapping in Three.js



Because of performance issues I only have one huge geometry, computed like this:



for (var i = 0; i < numberOfVertices; i += 9) {
p1 = new THREE.Vector3(graphData.triangles.vertices[i+0], graphData.triangles.vertices[i+1], graphData.triangles.vertices[i+2]);
p2 = new THREE.Vector3(graphData.triangles.vertices[i+3], graphData.triangles.vertices[i+4], graphData.triangles.vertices[i+5]);
p3 = new THREE.Vector3(graphData.triangles.vertices[i+6], graphData.triangles.vertices[i+7], graphData.triangles.vertices[i+8]);
geometry.vertices.push(new THREE.Vertex( p1.clone() ));
geometry.vertices.push(new THREE.Vertex( p2.clone() ));
geometry.vertices.push(new THREE.Vertex( p3.clone() ));
geometry.faces.push( new THREE.Face3( i/3, i/3+1, i/3+2 ) );

// i want to do something like this:
geometry.colors.push(new THREE.Color(0xFF0000));
geometry.colors.push(new THREE.Color(0xFF0000));
geometry.colors.push(new THREE.Color(0xFF0000));
}

geometry.computeFaceNormals();
var material = new THREE.MeshBasicMaterial({});

var triangles = new THREE.Mesh( geometry, material );
scene.add(triangles);


How can I assign different colors to each vertex in my geometry?


More From » webgl

 Answers
5

It has to be geometry.vertexColors instead of geometry.colors (push a colour per vertex).



And the material:



material = new THREE.MeshBasicMaterial({ vertexColors: THREE.VertexColors });

[#85962] Wednesday, April 25, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
rianna

Total Points: 67
Total Questions: 113
Total Answers: 113

Location: French Polynesia
Member since Tue, Jul 7, 2020
4 Years ago
;