Genesis icon indicating copy to clipboard operation
Genesis copied to clipboard

[Bug]: Tetrahedral meshing of obj file

Open bahadir14 opened this issue 8 months ago • 5 comments

Bug Description

Hi, the scripts run without problem. But, the meshed geometry does not appear in visualization. Is there any solution for this?

### Steps to Reproduce
import argparse

import numpy as np
import os
import torch

from dask.order import order
from mpmath import euler
from pygel3d.hmesh import minimize_dihedral_angle

#from samples.control_your_robot import jnt_names
from os import path

#from samples.gsmtm_11 import jnt_name

os.environ['PYOPENGL_PLATFORM'] = 'glx'
import genesis as gs


def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("-v", "--vis", action="store_true", default=False)
    args = parser.parse_args()

    ########################## init ##########################
    gs.init(seed=0, precision="32", logging_level="debug")

    ########################## create a scene ##########################

    scene = gs.Scene(
        sim_options=gs.options.SimOptions(
            dt=4e-3,
            substeps=10,
        ),

        fem_options=gs.options.FEMOptions(
            damping=0.1,
        ),
        viewer_options=gs.options.ViewerOptions(
            camera_pos=(9.6, 4.8, 14.0),
            camera_lookat=(0.0, 0.0, 0.0),
            camera_fov=35,
            max_FPS=30,
        ),
        show_viewer=True,
        vis_options=gs.options.VisOptions(
            #visualize_mpm_boundary=True,
        ),
    )
    cam = scene.add_camera(
        res=(1280, 800),
        pos=(5.5, 6.5, 3.2),
        lookat=(0.5, 1.5, 1.5),
        fov=30,
        GUI=True,
    )

    plane = scene.add_entity(
        material=gs.materials.Rigid(),

        morph=gs.morphs.URDF(file="urdf/plane/plane.urdf", fixed=True),
    )
    E, nu = 1.e7,0.3
    rho = 100.0

    obj1 = scene.add_entity(
        material=gs.materials.FEM.Elastic(
            E=E,
            nu=nu,
            rho=rho,
            model="linear",
        ),
        morph=gs.morphs.Mesh(
            file="/home/bahadir/Desktop/genesis/genesis/part_1/tensorflow_model/container_new.obj",
            # size=(1,1,1),
            scale=0.05,
            euler=(-225, -45, 90),
            pos=(0.0, 5.0, 5.0),
        ),
        surface=gs.surfaces.Iron(vis_mode="visual",),
    )

    scene.build()
    cam.start_recording()

    horizon = 1000
    for i in range(horizon):
            #if i < 400:
                #obj1.set_dofs_velocity([0.0, -2.0, 0.0,0.0,0.0,0.0])
            #else:
                #print(obj2.get_dofs_force(dofs_idx))
                #obj2.control_dofs_velocity([0, -5.0, -5.0, -2.0, 0, 0])

            scene.step()
            cam.render()
    cam.stop_recording(save_to_filename="missile_force.mp4", fps=60)

if __name__ == "__main__":
    main()

Expected Behavior

Meshed geometry appear in visual

Release version or Commit ID

0.2.1

bahadir14 avatar May 23 '25 06:05 bahadir14

You should provide the assets, i.e. "/home/bahadir/Desktop/genesis/genesis/part_1/tensorflow_model/container_new.obj" otherwise it is impossible to help you. That being said, try installing the main branch following the README instructions. I think this issue has been fixed since latest release on pypi.

duburcqa avatar May 23 '25 13:05 duburcqa

This looks like to be the same as my issue #1182 (the mesh disappears). The tetrahedral algorithm seems to have no problem since I have tested in tetgen library (the tetrahedral mesh generated well):

import numpy as np
import pyvista as pv
import tetgen
import trimesh

from genesis.utils.mesh import make_tetgen_switches

pv.set_plot_theme("document")

mesh = trimesh.load("./problematic_mesh.obj", file_type="obj")
pv_obj = pv.wrap(mesh)

tet = tetgen.TetGen(pv_obj)

# tet.tetrahedralize(order=1, mindihedral=20, minratio=1.5)
switches = make_tetgen_switches(
    {"order": 1, "mindihedral": 10, "minratio": 1.1, "nobisect": True, "quality": True, "maxvolume": -1.0, "verbose": 0}
)
verts, elems = tet.tetrahedralize(switches=switches)
grid = tet.grid
grid.plot(show_edges=True)

yar2001 avatar May 26 '25 08:05 yar2001

The tetrahedral algorithm seems to have no problem since I have tested in tetgen library

What do you mean exactly? I'm not sure to understand.

duburcqa avatar May 26 '25 08:05 duburcqa

What do you mean exactly? I'm not sure to understand.

The problem encountered by the author might be the same as mine (he uses FEM material). At first, I also thought it was a problem of tetrahedral meshing (because of its console output), but later after debugging, I found it probably wasn't.

yar2001 avatar May 26 '25 09:05 yar2001

Hi @duburcqa,

I installed latest version of genesis and it still does not show meshed geometry.

Here is the geometry file:

https://drive.google.com/file/d/13IcODtOAwrfXYd9grEpuSmd3v3FmmOk2/view?usp=sharing

Is there any way to solve problem?


My second question is that I want to apply volumetric tetrahedral mesh to my own geometry and use it in Genesis.

Which meshing software do you recommend for meshing geometry and in which format (vtk,stl,obj,...) should I insert my meshed geometry into Genesis?

bahadir14 avatar May 27 '25 06:05 bahadir14

Hi @bahadir14, have you solved the problem?

LeoHsuProgrammingLab avatar Aug 07 '25 22:08 LeoHsuProgrammingLab

Hi @LeoHsuProgrammingLab, unfortunately no. Hi @duburcqa, Could you help me about this bug?

bahadir14 avatar Aug 08 '25 05:08 bahadir14

The issue is not about geometry not displayed in the viewer. Here is what you get right after build():

Image

duburcqa avatar Aug 11 '25 22:08 duburcqa

Basically the FEM solver is failing, which "breaks" the mesh. Nothing to do with rendering. See related issue https://github.com/Genesis-Embodied-AI/Genesis/issues/1182

duburcqa avatar Aug 11 '25 22:08 duburcqa

This script is running and the mesh does not disappear. The result is definitely bad, but that is another issue:

import argparse

import os

import genesis as gs


gs.init(seed=0, precision="32", logging_level="debug")


scene = gs.Scene(
    sim_options=gs.options.SimOptions(
        dt=0.01,
    ),
    fem_options=gs.options.FEMOptions(
        use_implicit_solver=True,
        damping=0.1,
    ),
    viewer_options=gs.options.ViewerOptions(
        camera_pos=(9.6, 4.8, 14.0),
        camera_lookat=(0.0, 0.0, 0.0),
        camera_fov=35,
    ),
    show_viewer=True,
    show_FPS=False,
)
plane = scene.add_entity(
    morph=gs.morphs.URDF(file="urdf/plane/plane.urdf", fixed=True),
    material=gs.materials.Rigid(),
)
obj1 = scene.add_entity(
    morph=gs.morphs.Mesh(
        file="/Users/alexis.duburcq/Downloads/container_new.obj",
        scale=0.05,
        euler=(-225, -45, 90),
        pos=(0.0, 5.0, 5.0),
    ),
    material=gs.materials.FEM.Elastic(
        E=1.0e7,
        nu=0.3,
        rho=100.0,
        model="linear",
    ),
    surface=gs.surfaces.Iron(
        vis_mode="visual",
    ),
)

scene.build()
for i in range(1000):
    scene.step()

duburcqa avatar Aug 11 '25 23:08 duburcqa

Hi @duburcqa,

I had to modify your script in order to run in my ws. Here is the full script:


import argparse import numpy as np import os from os import path os.environ['PYOPENGL_PLATFORM'] = 'glx' import genesis as gs

def main(): parser = argparse.ArgumentParser() parser.add_argument("-v", "--vis", action="store_true", default=False) args = parser.parse_args()

gs.init(seed=0, precision="32", logging_level="debug")


scene = gs.Scene(
    sim_options=gs.options.SimOptions(
        dt=0.01,
    ),
    fem_options=gs.options.FEMOptions(
    use_implicit_solver=True,
        damping=0.1,
    ),
    viewer_options=gs.options.ViewerOptions(
        camera_pos=(9.6, 4.8, 14.0),
        camera_lookat=(0.0, 0.0, 0.0),
        camera_fov=35,
    ),
    show_viewer=True,
    show_FPS=False,
)
plane = scene.add_entity(
    morph=gs.morphs.URDF(file="urdf/plane/plane.urdf", fixed=True),
    material=gs.materials.Rigid(),
)
obj1 = scene.add_entity(
    morph=gs.morphs.Mesh(
        file="/home/bahadir/Desktop/genesis/genesis/part_1/tensorflow_model/container_new.obj",
        scale=0.05,
        euler=(-225, -45, 90),
        pos=(0.0, 5.0, 5.0),
    ),
    material=gs.materials.FEM.Elastic(
        E=1.0e7,
        nu=0.3,
        rho=100.0,
        model="linear",
    ),
    surface=gs.surfaces.Iron(
        vis_mode="visual",
    ),
)

scene.build()
for i in range(1000):
    scene.step()

if name == "main": main()


I still get no meshed geometry and use_implicit_solver command is not working for me. Do you have any suggestions?

bahadir14 avatar Aug 12 '25 07:08 bahadir14

I still get no meshed geometry and use_implicit_solver command is not working for me. Do you have any suggestions?

I guess you need to update Genesis. You are using an outdated version probably.

duburcqa avatar Aug 12 '25 18:08 duburcqa

I solved the problem, thank you @duburcqa

bahadir14 avatar Aug 13 '25 07:08 bahadir14