Search code examples
three.jsblendergltf

Manipulate gltf model children


I'VE loaded a GLTF file with 2 mesh object in it (cube1, cube2) and rendered it, looks OK.

The problem is this :

I'm trying to manipulate the opacity / scale of those objects separately.

Tried to address them with:

Var cube1 = gltf.Scene.GetObjectByName('Cube1');

But when I try to define cube1.opacity, I get an "undefined" error.

Any help is appreciated! Thanks


Solution

  • Well... even tho' the question is simple, the answer not so much.

    First you are using a loader, usually this implies that your cube model will be a bit more complicated. You will go something like this:

    3D Object > Children > Mesh [x] > material > Opacity

    I have a live example here: https://boxelizer.com/renderer.php?mid=7740369e824e4eadbd83e6f01fa96caa

    In which you can go into the console and change that property like this:

    model.children[1].material.transparent = true;
    model.children[1].material.opacity = .5;
    model.children[1].material.needsUpdate = true;
    

    Your model may be a bit different but I hope this example helps you figure out yours.