Make the robot transparent

Hello,
How could I make the robot transparent without changing my *.dae file?
I am loading a mesh with some png files.
I have tried with the below code snippet but it doesn’t work.

    for (int i = 0; i < robot->getNumBodyNodes(); ++i) {
        dart::dynamics::BodyNodePtr bn = robot->getBodyNode(i);
        auto sns = bn->getShapeNodesWith<dart::dynamics::VisualAspect>();
        for (auto sn : sns) {
            sn->getVisualAspect()->setAlpha(0.4);
        }
    }

It’s probably because the mesh isn’t indeed updated after the alpha change assuming the mesh properties are static. Could you try below code?

    for (int i = 0; i < robot->getNumBodyNodes(); ++i) {
        dart::dynamics::BodyNodePtr bn = robot->getBodyNode(i);
        auto sns = bn->getShapeNodesWith<dart::dynamics::VisualAspect>();
        for (auto sn : sns) {
            sn->addDataVariance(dart::dynamics::Shape::DYNAMIC_COLOR);  // inform that the color (and transparency) changes over time
            sn->getVisualAspect()->setAlpha(0.4);
        }
    }

Do you mean

    for (int i = 0; i < robot->getNumBodyNodes(); ++i) {
        dart::dynamics::BodyNodePtr bn = robot->getBodyNode(i);
        auto sns = bn->getShapeNodesWith<dart::dynamics::VisualAspect>();
        for (auto sn : sns) {
            sn->getShape()->addDataVariance(dart::dynamics::Shape::DYNAMIC_COLOR);
            sn->getVisualAspect()->setAlpha(0.4);
        }
    }

With the above code, I am getting segmentation fault at mesh->mColors[0][j][3] = alpha; in function void MeshShape::notifyAlphaUpdated(double alpha)

Could you provide the permalink to the code line? Not sure what version of the code is.

That function is removed in DART 6.9.0. Could you try the lastest DART version (i.e., 6.9.1)?

After using the latest 6.9.1, it works now!

I appreciate :slight_smile:

1 Like