Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing face colors during run-time in Three.js on a model imported from blender

I've imported a model of a soccer ball (truncated icosahedron) from blender (via JSON loader) and I wanted to change the face colors upon clicking. The faces are correctly identified I can change the color of the entire model but not particular faces. I have dug a bit deeper and I found that the colors are correctly assigned to soccerball.geometry.faces[i] but the new face colors are not shown.

I've gone through all of the similar threads and tried all of the proposed solutions (different materials, dirtyColors, dynamic, colorsNeedUpdate, etc.) but nothing helped.

this is how I import the model:

var loader = new THREE.JSONLoader(  );
var onGeometry = function(geom) {
soccer = new THREE.Mesh( geom, new THREE.MeshLambertMaterial());
soccer.position.set( 0, 0, 0 );
soccer.scale.set( 2, 2, 2 );
soccer.geometry.dynamic  = true;
soccer.geometry.dirty = true;
soccer.overdraw = true;
objects.push(soccer);
scene.add(soccer);
};

loader.load("models/model.js", onGeometry);

Can you please help me? thanks in advance

like image 343
Victor Avatar asked Nov 13 '22 17:11

Victor


1 Answers

soccer.material.vertexColors = THREE.VertexColors ;

or

soccer.material.vertexColors = THREE.FaceColors;

If that doesn't work then I'll need to havre the model itself to do some tests.

like image 87
Gero3 Avatar answered Nov 15 '22 08:11

Gero3