isl-org / Open3D

Open3D: A Modern Library for 3D Data Processing
http://www.open3d.org
Other
11.53k stars 2.32k forks source link

Is there a way to keep the texture on the mesh, after "o3d.visualization.rendering.MaterialRecord()" is called #4603

Open MagJ1 opened 2 years ago

MagJ1 commented 2 years ago

Checklist

My Question

Dear Developer-Team,

I am currently working on an animation for an IMU sensor. I have a while-loop with a delay(). After each altering of the geometry, I remove it from the scene and add it again to it. Between that, I have to to call o3d.visualization.rendering.MaterialRecord(). But with that call, I lose my texture. I could reload the texture as well, but that slows down the animation quite a lot. Is there a way to keep the texture on the mesh?

while 1:
    time.sleep(0.1)

    def update_sensorNode_positions():

            for sensorNodeObject in self.sensorNodeObjectList:

                    # remove sensorNode from scene
                    self.vis.remove_geometry(str(sensorNodeObject.sensorNodeID))

                    self.mat = o3d.visualization.rendering.MaterialRecord()
                    self.mat.shader = "defaultLit"
                    self.mat.albedo_img = config.textureOfSensorNode

                    self.vis.add_geometry(str(sensorNodeObject.sensorNodeID), sensorNodeObject.meshBox, self.mat)

        o3d.visualization.gui.Application.instance.post_to_main_thread(self.vis, update_sensorNode_positions)

Thanks in advance.

errissa commented 2 years ago

What version of Open3D are you using?

If the texture does not change you should be able to load it and store it somewhere. The assignment self.mat.albedo_img = is just a smart pointer copy so it is not expensive. Or you could store the material. You don't need to recreate it every loop if it's not changing. Also, with recent versions of Open3D (>=0.14.1) textures are cached so it is already on the GPU when you add the next geometry. It should be pretty fast.