I called the function in the console (i was trying to make that work ) as shown in the second picture of my second post.
As you can see I don’t have any errors.
I first tried line by line in the console, once I was able to change the color,
I created the function then reloaded the page and called the function with no effect.
Your question pushed me to try to call the function in the onLoad callback of the GLTFLoader…and it worked !!
But why it does not work in the console? there are concepts that I am missing here?
I waited a long time to call it in the console.
function changeSkinMeshColor(skinMesh){
const x = Math.random();
const y = Math.random();
const z = Math.random() ;
skinMesh.material.vertexColors = true;
const geometry = skinMesh.geometry;
const count = geometry.attributes.position.count;
if(!geometry.attributes.color){
const buffer = new THREE.BufferAttribute( new Float32Array( count * 3 ), 3 )
geometry.setAttribute( 'color', buffer );
};
for (let i = 0;i < count ;i++)geometry.attributes.color.setXYZ(i,x,y,z);
geometry.attributes.color.needsUpdate = true;
}
Indeed, I attached a button to it, but for some reason, I HAVE TO first call the function in the onLoad function of the GLTFLoader… otherwise, the button has no effect.
If I comment the call of the function in the onLoad callback then I HAVE TO execute the code in the console line by line …to make that button works. Calling the function directly in the console has no effect ! ( with no errors…)
I am very curious about the reason for these behaviors.