You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

手动向Drake场景图添加锚定几何网格未显示的问题

解决Drake场景图添加.obj模型不显示的问题

你的代码核心问题是创建了空的IllustrationProperties,Meshcat需要基础渲染属性(比如颜色)才能正常显示模型,空属性会导致模型被渲染引擎忽略。另外,非必需的Perception/Proximity属性如果没有实际需求,可暂时不配置,避免无效设置。

以下是修正后的代码:

import os
from pydrake.geometry import (
    Mesh, GeometryInstance, RigidTransform, IllustrationProperties,
    SceneGraph
)

def add_mesh_to_scene_graph(name, path, scene_graph):
    # 先检查模型文件路径是否存在
    if not os.path.exists(path):
        raise ValueError(f"找不到模型文件:{path}")
    
    mesh = Mesh(path)
    source_id = scene_graph.RegisterSource()
    geometry = GeometryInstance(RigidTransform(), mesh, name)
    
    # 配置渲染属性:设置基础漫反射颜色(RGBA格式,范围0-1)
    illustration_props = IllustrationProperties()
    illustration_props.AddProperty("phong", "diffuse", [0.7, 0.7, 0.7, 1.0])
    geometry.set_illustration_properties(illustration_props)
    
    # 若不需要感知/碰撞交互,可注释以下两行;需要时再按需配置
    # geometry.set_perception_properties(PerceptionProperties())
    # geometry.set_proximity_properties(ProximityProperties())
    
    scene_graph.RegisterGeometry(source_id, scene_graph.world_frame_id(), geometry)

关键修改说明

  • 给IllustrationProperties添加了phong/diffuse颜色属性,这是Meshcat渲染模型的必要条件,你可以根据需求修改RGBA值
  • 增加了文件路径检查,方便快速排查路径错误
  • 注释了非必需的属性设置,若后续需要碰撞交互,可参考下方配置示例补充ProximityProperties:
from pydrake.geometry import ProximityProperties
proximity_props = ProximityProperties()
# 设置碰撞体厚度(针对网格模型)
proximity_props.AddProperty("hydroelastic", "slab_thickness", 0.01)
# 设置静摩擦系数
proximity_props.AddProperty("material", "static_friction", 0.5)
geometry.set_proximity_properties(proximity_props)

内容的提问来源于stack exchange,提问作者Mark

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.16 18:48:07