Reputation: 171
I am trying to simply change the colour of a model in autodesk forge. I am using the following code.
Creation of the material
var material = new THREE.MeshPhongMaterial
({
color: new THREE.Color("rgb(255, 0, 0)"),
transparent: false
});
Adding it to the list of materials
materials.addMaterial(
'NewMaterial',
material,
true)
Line of code that actually sets the material
fragList.setMaterial(fragId, material);
This works almost perfectly. The colour of the model changes to red as it should but as you move the view around, what looks like the underlying grey of the model seems to be showing through the red like its clipping through in certain areas.
I have been through https://threejs.org/docs/#api/materials/MeshPhongMaterial and messed with a bunch of properties of the material and while they changed the look of the material especially the lighting properties however nothing would stop the grey clipping through. Any suggestions on what could be causing this or where to look would be appreciated
Upvotes: 0
Views: 433
Reputation: 171
Not sure if there is a down side to using this method but I used the setThemingColour that was demonstrated in the easter code sample. https://forge.autodesk.com/blog/happy-easter-setthemingcolor-model-material
var red = new THREE.Vector4(1, 0, 0, 0.5);
viewer.setThemingColor(dbId, red);
Changed the colour, doesnt show through other models like overlays and doesnt have the clipping issue I had.
Upvotes: 1
Reputation: 823
use this extension from Autodesk forge instead of working on three.js directly.
It is very simple, you just have to write few lines:
viewer.loadExtension('Autodesk.ADN.Viewing.Extension.Color');
viewer.setColorMaterial([objectIds],colorcodes);
Upvotes: 0