Genesis
Genesis copied to clipboard
[Bug]: Mesh with many vertices disappears when using FEM material
Bug Description
Mesh with many vertices (as shown in the obj file in attachment below) disappears in viewer when using FEM material
Steps to Reproduce
import os
import genesis as gs
os.environ["PYOPENGL_PLATFORM"] = "glx"
########################## init ##########################
gs.init(
backend=gs.cpu,
debug=True,
)
########################## create a scene ##########################
dt = 4e-3
scene = gs.Scene(
sim_options=gs.options.SimOptions(
dt=dt,
substeps=10,
),
fem_options=gs.options.FEMOptions(
dt=dt,
damping=45.0,
),
viewer_options=gs.options.ViewerOptions(
camera_fov=30,
res=(1280, 720),
max_FPS=60,
run_in_thread=False,
),
show_viewer=True,
)
########################## entities ##########################
plane = scene.add_entity(
morph=gs.morphs.Plane(),
)
cloth_2 = scene.add_entity(
material=gs.materials.FEM.Elastic(),
morph=gs.morphs.Mesh(
file="./Cube_Simple_SubD.obj",
scale=0.3,
pos=(0, 0, 2.0),
euler=(0.0, 0, 0.0),
),
surface=gs.surfaces.Default(
color=(0.8, 0.4, 0.2, 1.0),
vis_mode="visual",
),
)
########################## build ##########################
scene.build()
horizon = 1000
for i in range(horizon):
scene.step()
Model (also includes other problematic models): Cube_Simple_SubD.zip
Expected Behavior
The cube should appear in the viewer.
Screenshots/Videos
Relevant log output
python test.py
[Genesis] [11:58:45] [INFO] ╭─────────────────────────────────────────────────────────────────────────────────────╮
[Genesis] [11:58:45] [INFO] │┈┉┈┉┈┉┈┉┈┉┈┉┈┉┈┉┈┉┈┉┈┉┈┉┈┉┈┉┈┉┈┉┈┉┈┉┈┉ Genesis ┈┉┈┉┈┉┈┉┈┉┈┉┈┉┈┉┈┉┈┉┈┉┈┉┈┉┈┉┈┉┈┉┈┉┈┉┈┉│
[Genesis] [11:58:45] [INFO] ╰─────────────────────────────────────────────────────────────────────────────────────╯
[Genesis] [11:58:46] [INFO] Beware running Genesis in debug mode dramatically reduces runtime speed.
[Genesis] [11:58:46] [INFO] Running on [AMD Ryzen 7 6800U with Radeon Graphics] with backend gs.cpu. Device memory: 14.94 GB.
[Genesis] [11:58:46] [DEBUG] [Taichi] version 1.7.3, llvm 15.0.4, commit 5ec301be, linux, python 3.11.11
[Genesis] [11:58:46] [DEBUG] [Taichi] Starting on arch=x64
[Genesis] [11:58:46] [INFO] 🚀 Genesis initialized. 🔖 version: 0.2.1, 🌱 seed: None, 📏 precision: '32', 🐛 debug: True, 🎨 theme: 'dark'.
[Genesis] [11:58:46] [INFO] Scene <1383465> created.
[Genesis] [11:58:46] [INFO] Adding <gs.RigidEntity>. idx: 0, uid: <871454e>, morph: <gs.morphs.Plane>, material: <gs.materials.Rigid>.
[Genesis] [11:58:46] [DEBUG] Preprocessed file (`.gsd`) found in cache for geom idx 0.
[Genesis] [11:58:46] [INFO] Adding <gs.FEMEntity>. idx: 1, uid: <6ca64df>, morph: <gs.morphs.Mesh(file='/home/yar2001/Downloads/Cube_Simple_SubD.obj')>, material: <gs.FEM.Elastic>.
[Genesis] [11:58:46] [DEBUG] Tetrahedra file (`.tet`) found in cache.
[Genesis] [11:58:46] [INFO] Building scene <1383465>...
[Genesis] [11:58:46] [DEBUG] Constraint solver time constant not specified. Using minimum value (`0.0008`).
[W 05/23/25 11:58:46.864 322670] [frontend_ir.cpp:begin_frontend_struct_for_on_snode@1678] ti.loop_config(serialize=True) does not have effect on the struct for. The execution order is not guaranteed.
[Genesis] [11:58:46] [DEBUG] Constraint solver time constant not specified. Using minimum value (`0.0008`).
[W 05/23/25 11:58:46.953 322670] [frontend_ir.cpp:begin_frontend_struct_for_on_snode@1678] ti.loop_config(serialize=True) does not have effect on the struct for. The execution order is not guaranteed.
[W 05/23/25 11:58:47.389 322670] [frontend_ir.cpp:begin_frontend_struct_for_on_external_tensor@1694] ti.loop_config(serialize=True) does not have effect on the struct for. The execution order is not guaranteed.
[W 05/23/25 11:58:48.735 322670] [frontend_ir.cpp:begin_frontend_struct_for_on_snode@1678] ti.loop_config(serialize=True) does not have effect on the struct for. The execution order is not guaranteed.
[Genesis] [11:58:48] [INFO] Entity <6ca64df> added. class: FEMEntity, morph: Mesh, size: (1924, 533), material: <gs.FEM.Elastic>.
[Genesis] [11:58:48] [INFO] Compiling simulation kernels...
[Genesis] [11:58:58] [INFO] Building visualizer...
[Genesis] [11:58:58] [DEBUG] Trying to create OpenGL Context for PYOPENGL_PLATFORM='glx'...
[Genesis] [11:58:59] [INFO] Viewer created. Resolution: 1280×720, max_FPS: 60.
[Genesis] [11:58:59] [INFO] Running at 254.82 FPS.
[Genesis] [11:58:59] [INFO] Running at 156.87 FPS.
[Genesis] [11:58:59] [INFO] Running at 111.28 FPS.
[Genesis] [11:58:59] [INFO] Running at 89.79 FPS.
[Genesis] [11:58:59] [INFO] Running at 77.39 FPS.
[Genesis] [11:58:59] [INFO] Running at 68.29 FPS.
[Genesis] [11:58:59] [INFO] Running at 61.74 FPS.
[Genesis] [11:58:59] [INFO] Running at 56.28 FPS.
[Genesis] [11:58:59] [INFO] Running at 51.79 FPS.
[Genesis] [11:58:59] [INFO] Running at 48.25 FPS.
[Genesis] [11:58:59] [INFO] Running at 45.37 FPS.
[Genesis] [11:58:59] [INFO] Running at 41.95 FPS.
[Genesis] [11:58:59] [INFO] Running at 39.78 FPS.
[Genesis] [11:58:59] [INFO] Running at 37.92 FPS.
[Genesis] [11:59:00] [INFO] Running at 36.43 FPS.
[Genesis] [11:59:00] [INFO] Running at 35.01 FPS.
[Genesis] [11:59:00] [INFO] Running at 33.89 FPS.
[Genesis] [11:59:00] [INFO] Running at 32.84 FPS.
Environment
- OS: Linux 6.12.21-amd64 Debian 6.12.21-1 (2025-03-30) x86_64 GNU/Linux
- CPU: AMD Ryzen 7 6800U
Release version or Commit ID
49ce8c746e7ce1255cdd97b904434b70f8fd4e40
Additional Context
No response
me too,have u fixed it?
me too,have u fixed it?
Not yet :(
import genesis as gs
import trimesh
import os
import time
import numpy as np
def main():
# 初始化Genesis
gs.init(backend=gs.gpu) # 使用GPU后端
# 创建场景,使用用户给定的参数
scene = gs.Scene(
show_viewer = True,
viewer_options = gs.options.ViewerOptions(
res = (640, 480), # 降低分辨率
camera_pos = (20, 20, 20), # 调整相机位置到更高的位置
camera_lookat = (10, 10, 10), # 看向物体下落的位置
camera_fov = 60, # 增加视场角以看到更多场景
max_FPS = 30, # 降低帧率
),
vis_options = gs.options.VisOptions(
show_world_frame = True, # 显示原点坐标系
world_frame_size = 0.5, # 坐标系长度(米)
show_link_frame = False, # 不显示实体链接坐标系
show_cameras = False, # 不显示相机网格和视锥
plane_reflection = False, # 开启平面反射
ambient_light = (0.1, 0.1, 0.1), # 环境光
),
renderer = gs.renderers.Rasterizer(), # 使用光栅化渲染器
rigid_options=gs.options.RigidOptions(
enable_collision=True, # 启用碰撞
gravity=(0, 0, -9.81), # 添加重力
),
)
plane = scene.add_entity(
gs.morphs.Plane(),
)
# 读取temp目录下前100个prism_xxx.obj文件
temp_dir = "examples/obj/temp/temp"
obj_files = sorted([f for f in os.listdir(temp_dir) if f.endswith('.obj')])[:100]
print(f"将渲染以下文件: {obj_files}")
for obj_file in obj_files:
file_path = os.path.join(temp_dir, obj_file)
# 计算三棱柱体积和质量(可选)
mesh = trimesh.load(file_path)
volume = mesh.volume
mass = volume * 10.0 # 假设密度为10
# 添加到场景
scene.add_entity(
morph=gs.morphs.Mesh(
file=file_path,
pos=(10, 10, 10), # 可根据需要调整位置
fixed=False, # 允许物理模拟
),
surface=gs.surfaces.Default(
color=(0.8, 0.8, 0.8), # 浅灰色
smooth=True, # 平滑渲染
),
)
# 添加一个平面作为地面
# scene.add_entity(
# morph=gs.morphs.Box(
# pos=(0.0, 0.0, -0.5), # 位置
# size=(10.0, 10.0, 0.1), # 大小
# fixed=True, # 固定地面
# ),
# surface=gs.surfaces.Default(
# color=(0.8, 0.8, 0.8), # 浅灰色
# smooth=True,
# ),
# )
# 添加坐标轴
# X轴(红色)
scene.add_entity(
gs.morphs.Cylinder(
pos=(0.5, 0.0, 0.0),
radius=0.005,
height=1.0,
euler=(0, 90, 0), # 绕Y轴旋转90度
fixed=True,
),
surface=gs.surfaces.Default(color=(1.0, 0.0, 0.0)), # 红色
)
# Y轴(绿色)
scene.add_entity(
gs.morphs.Cylinder(
pos=(0.0, 0.5, 0.0),
radius=0.005,
height=1.0,
euler=(90, 0, 0), # 绕X轴旋转90度
fixed=True,
),
surface=gs.surfaces.Default(color=(0.0, 1.0, 0.0)), # 绿色
)
# Z轴(蓝色)
scene.add_entity(
gs.morphs.Cylinder(
pos=(0.0, 0.0, 0.5),
radius=0.005,
height=1.0,
fixed=True,
),
surface=gs.surfaces.Default(color=(0.0, 0.0, 1.0)), # 蓝色
)
# 添加录屏相机(必须在scene.build()之前)
cam = scene.add_camera(
res = (1280, 960),
pos = (20, 15, 15),
lookat = (10, 10, 10),
fov = 40,
GUI = False,
)
# 构建场景
scene.build()
# 录屏主循环
cam.start_recording()
steps = 30 * 10 # 10秒,30帧每秒
for i in range(steps):
scene.step()
cam.render()
cam.stop_recording(save_to_filename='examples/obj/prism_simulation.mp4', fps=30)
print('录屏已结束,视频已保存。')
# 继续交互式运行(可选)
while True:
scene.step()
if __name__ == "__main__":
main()
ALL OBJS HAVE DISAPPERED
@Tryoe You should provide all the assets, otherwise it is impossible to help you.
@yar2001 I can confirm that this simple script is already failing. The mesh gets extremely distorted and "disappears".
import genesis as gs
gs.init(backend=gs.cpu, precision="64", logging_level="debug")
scene = gs.Scene(
sim_options=gs.options.SimOptions(
dt=0.001,
),
show_viewer=True,
)
scene.add_entity(
material=gs.materials.FEM.Elastic(),
morph=gs.morphs.Mesh(
file="./Cube_Simple_SubD.obj",
scale=0.1,
pos=(0, 0, 1.0),
),
)
scene.build()
for i in range(10):
scene.step()
Here is the asset "./Cube_Simple_SubD.obj" with .txt extension instead of .obj: Cube_Simple_SubD.obj
@Tryoe You should provide all the assets, otherwise it is impossible to help you.
temp.zip This is all of my asset files. I tried loading the first 20 for testing, but found that all the objects disappeared. I hope to get your help. Thank you.
The disappearance is caused by the failure of the fem solver. It is currently using an explicit Euler integration and is prone to divergence. A temporary fix would be using a smaller dt or more substeps. I tried using dt=1e-3 /substeps=10 and dt=4e-3\substeps=40 and the cube worked fine. We will be improving our solver soon to be more robust.