We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.

Change opacity from an existing object with texture

Home Forums Programming Change opacity from an existing object with texture

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #50656
    moiamy
    Participant

    Hello

    I have just tried this code from the Verge3F forum with the exec script puzzle. It doesn’t work for me. No problem on the console output.

    app.scene.traverse(function(obj) {
       console.log("start");
       var object = app.scene.getObjectByName("earth_R2"); 
        object.material.opacity = 0.5;
        object.material.transparent = true; 
    });

    What did I miss ?

    #51688

    Hi,

    If the material you want to change is one of the native threejs (which verge3d is built on top) materials like for example MeshBasicMaterial, then you can do that as follows:

    material.opacity = 0.5;
    material.transparent = true;
    material.needsUpdate = true;
    

    But if you exported your scene from Blender/3dsMax then all materials are most likely of type MeshNodeMaterial and to change the opacity of such material you first need to connect a corresponding Value/Float node to the alpha input in the node material setup in the 3d editor. After doing that you can change the opacity by controlling the value of that node accessing it by its name:

    let index = material.nodeValueMap['Value.001'];
    material.nodeValue[index] = 0.5;
    material.needsUpdate = true;
    

    Co-founder and lead developer at Soft8Soft.

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.