FreshRSS

Normální zobrazení

Jsou dostupné nové články, klikněte pro obnovení stránky.
PředevčíremHlavní kanál
  • ✇Recent Questions - Game Development Stack Exchange
  • NVIDIA Warp Defomable Mesh using add_soft_meshMelissa Herondale
    I am trying to simulate a deformable/soft mesh falling onto the ground plane using the NVIDIA Warp framework, but I get the message "inverted tetrahedral element". I downloaded the Stanford bunny as bunny.obj so I am assuming the mesh data is fine? Could it be because of how they are loaded in the code? The code I am using is: import os import numpy as np import warp as wp import warp.examples import warp.sim import openmesh import meshio import warp.sim.render
     

NVIDIA Warp Defomable Mesh using add_soft_mesh

I am trying to simulate a deformable/soft mesh falling onto the ground plane using the NVIDIA Warp framework, but I get the message "inverted tetrahedral element". I downloaded the Stanford bunny as bunny.obj so I am assuming the mesh data is fine? Could it be because of how they are loaded in the code?

The code I am using is:

    import os
    import numpy as np
    import warp as wp
    import warp.examples
    import warp.sim
    import openmesh
    import meshio
    import warp.sim.render
    from SimulationDataConfig import *
    from pxr import Usd, UsdGeom

class Example:
    def __init__(self, stage_path="bunny.usd"):
        self.sim_width = 8
        self.sim_height = 8



        fps = 60
        self.frame_dt = 1.0 / fps
        self.sim_substeps = 32
        self.sim_dt = self.frame_dt / self.sim_substeps
        self.sim_time = 0.0
        self.sim_iterations = 1
        self.sim_relaxation = 1.0
        self.profiler = {}

        builder = wp.sim.ModelBuilder()

        #m = openmesh.read_trimesh("cylinder.obj")
        mesh_points, mesh_indices = wp.sim.utils.load_mesh(filename="bunny.obj", method="meshio")
        print(mesh_points)        

        mesh_p = np.array(mesh_points, dtype=np.int32).reshape(-1, 3)
        mesh_ind = np.array(mesh_indices, dtype=np.int32).flatten()
        print(mesh_ind)

        #correct_indices = preprocess_tetrahedra(mesh_points, mesh_indices)
        
        #mesh = wp.sim.Mesh(mesh_points, mesh_indices)
        builder.default_particle_radius = 0.01

        builder.add_soft_mesh(
            pos=wp.vec3(0.0, 10.0, 0.0), 
            rot=wp.quat_identity(),
            scale=1.0,
            vel=wp.vec3(0.0, 0.0, 0.0), 
            vertices=mesh_p, 
            indices=mesh_ind, 
            density=100.0,
            k_mu=500.0,
            k_lambda=200.0,
            k_damp=0.0)

        self.model = builder.finalize()
        self.model.ground = True
        self.model.soft_contact_ke = 1.0e3
        self.model.soft_contact_kd = 0.0
        self.model.soft_contact_kf = 1.0e3

        self.integrator = wp.sim.SemiImplicitIntegrator()

        output_dir_root = "example_sims/output"
        output = os.path.join(output_dir_root,"h5_f_{:010d}.h5")


        output_dir = os.path.dirname(output)
        config_file = os.path.join(output_dir, 'config.h5')
        #config = SimulationConfig(self.model, self.sim_dt)
        #self.config = config
        #self.config.write_to_file(config_file)

        self.state_0 = self.model.state()
        self.state_1 = self.model.state()

        if stage_path:
            self.renderer = wp.sim.render.SimRenderer(self.model, stage_path, scaling=1.0)
        else:
            self.renderer = None

        self.use_cuda_graph = wp.get_device().is_cuda
        if self.use_cuda_graph:
            with wp.ScopedCapture() as capture:
                self.simulate()
            self.graph = capture.graph


    def simulate(self):
        for _s in range(self.sim_substeps):
            wp.sim.collide(self.model, self.state_0)

            self.state_0.clear_forces()
            self.state_1.clear_forces()

            self.integrator.simulate(self.model, self.state_0, self.state_1, self.sim_dt)

            # swap states
            (self.state_0, self.state_1) = (self.state_1, self.state_0)

    def step(self):
        with wp.ScopedTimer("step", dict=self.profiler):
            if self.use_cuda_graph:
                wp.capture_launch(self.graph)
            else:
                self.simulate()
            self.sim_time += self.frame_dt

    def render(self):
        if self.renderer is None:
            return

        with wp.ScopedTimer("render"):
            self.renderer.begin_frame(self.sim_time)
            self.renderer.render(self.state_0)
            self.renderer.end_frame()

if __name__ == "__main__":
    import argparse

    parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument("--device", type=str, default=None, help="Override the default Warp device.")
    parser.add_argument(
        "--stage_path",
        type=lambda x: None if x == "None" else str(x),
        default="bunny.usd",
        help="Path to the output USD file.",
    )
    parser.add_argument("--num_frames", type=int, default=300, help="Total number of frames.")

    args = parser.parse_known_args()[0]

    with wp.ScopedDevice(args.device):
        example = Example(stage_path=args.stage_path)

        for _ in range(args.num_frames):
            example.step()
            example.render()

        if example.renderer:
            example.renderer.save()

What could be the reason for this message? Does anyone know a fix or how I should approach it

❌
❌