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

移植Drake C++可变形环面示例至Python后MeshCat无环面显示

Drake Python可变形环面无法在MeshCat显示

我尝试将Drake官方的C++可变形环面示例移植到Python,但环面未在MeshCat中显示。运行无报错,仅能看到"ground"(地面),无法看到环面:

截图显示:MeshCat界面中仅存在灰色地面模型,无环面出现

(暂未包含机械臂相关代码,仅尝试先让环面显示)

def run_demo():
    builder = DiagramBuilder()

    plant_config = MultibodyPlantConfig()
    plant_config.time_step = time_step
    plant_config.discrete_contact_solver = "sap"

    plant, scene_graph = AddMultibodyPlant(plant_config, builder)

    rigid_proximity_props = ProximityProperties()
    surface_friction = CoulombFriction(1.15, 1.15)
    rigid_proximity_props.AddProperty("hydroelastic",
                                      "resolution_hint", 1.0)
    AddContactMaterial(friction = surface_friction,
                       properties = rigid_proximity_props)
    
    ground = Box(4, 4, 4)
    X_WG = RigidTransform(RotationMatrix(), [0, 0, -2])
    plant.RegisterCollisionGeometry(plant.world_body(), X_WG, ground,
                                    "ground_collision", rigid_proximity_props)
    plant.RegisterVisualGeometry(plant.world_body(), X_WG, ground,
                                 "ground_visual", [0.7, 0.5, 0.4, 0.8])

    owned_deformable_model = DeformableModel(plant)

    deformable_config = DeformableBodyConfig()
    deformable_config.set_youngs_modulus(E)
    deformable_config.set_poissons_ratio(nu)
    deformable_config.set_mass_density(density)
    deformable_config.set_stiffness_damping_coefficient(beta)

    scale = 0.65;
    torus_mesh = Mesh("./torus.vtk", scale)
    kL = 0.09 * scale
    X_WB = RigidTransform(RotationMatrix(), [0, 0, kL/2])
    torus_instance = GeometryInstance(X_WB, torus_mesh, "deformable_torus")

    deformable_proximity_props = ProximityProperties()
    AddContactMaterial(friction = surface_friction,
                       properties = deformable_proximity_props)
    torus_instance.set_proximity_properties(deformable_proximity_props)

    unused_resolution_hint = 1.0
    owned_deformable_model.RegisterDeformableBody(
        torus_instance, deformable_config, unused_resolution_hint)

    plant.AddPhysicalModel(owned_deformable_model)
    deformable_model = owned_deformable_model

    plant.Finalize();

    builder.Connect(
        deformable_model.vertex_positions_port(),
        scene_graph.get_source_configuration_port(plant.get_source_id()));
    
    MeshcatVisualizer.AddToBuilder(builder, scene_graph, meshcat)
    diagram = builder.Build()
    diagram_context = diagram.CreateDefaultContext()
    simulator = Simulator(diagram)
    simulator.Initialize()
    simulator.set_target_realtime_rate(realtime_rate)
    meshcat.AddButton("Stop Simulation", "Escape")

    while meshcat.GetButtonClicks("Stop Simulation") < 1:
        simulator.AdvanceTo(simulator.get_context().get_time() + 2.0)
        
    meshcat.DeleteButton("Stop Simulation")
    meshcat.DeleteAddedControls()

我怀疑问题出在代码行:plant.AddPhysicalModel(owned_deformable_model),或可变形模型创建流程的更早阶段,但无法确定...

完整项目可在DeepNote工作区查看。


内容的提问来源于stack exchange,提问作者Shao Yuan Chew Chia

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.06 18:11:03