I have been experimenting with the Threejs cars example found at the following URL:
It's a great way to test realistic objects. I was trying to change the materials for the car on runtime, but I hit a roadblock due to the way the mesh is being added to the scene. I would really appreciate it if someone could help me out by providing a code snippet or a fiddle.
This is how the mesh is currently being added to the scene:
var loader = new THREE.CTMLoader();
loader.loadParts( "catalog/view/javascript/models/ctm/camaro/camaro.js", function( geometries, materials ) {
hackMaterials( materials );
for ( var i = 0; i < geometries.length; i ++ ) {
var mesh = new THREE.Mesh( geometries[ i ], materials[ i ] );
mesh.position.copy( position );
mesh.scale.copy( scale );
scene.add( mesh );
}
Here is the hackMaterials(materials) function that modifies the materials:
function hackMaterials( materials ) {
// Material modification logic here
}
I have been attempting to use dat.gui.js to create a color control, but I have only managed to change the color in the console without applying it to the car. It would be greatly appreciated if someone could provide a simple working example with a dropdown color changer.
Thanks in advance.