All reports

SDF grinding in Newton

A small example of SDF-SDF contact and geometric material removal. It does not run a dynamics solver.

Overview

Video

ViewerGL shows the moving tool, updated workpiece, pressure-colored contact field, and integrated normal-load plot.

Set up SDF-SDF contact

workpiece_sdf = workpiece_mesh.build_sdf(
    max_resolution=256,
    narrow_band_range=(-0.08, 0.08),
    texture_format="float32",
    paired_samples=False,
)

shape_cfg = newton.ModelBuilder.ShapeConfig(
    is_hydroelastic=True,
    kh=1.0e8,
    gap=0.005,
    margin=0.0,
)

pipeline = newton.CollisionPipeline(
    model,
    sdf_hydroelastic_config=newton.geometry.HydroelasticSDF.Config(
        output_contact_surface=True,
    ),
)
contacts = pipeline.contacts()
pipeline.collide(state, contacts)

viewer.show_hydro_contact_surface = True
viewer.log_hydro_contact_surface(
    pipeline.hydroelastic_sdf.get_contact_surface()
)

Remove material

point_in_tool = wp.transform_point(
    wp.transform_inverse(grinder_xform), point
)
tool_distance = _sdf_cylinder_z(
    point_in_tool, grinder_radius, grinder_half_width
)
sdf_values[z, y, x] = wp.max(sdf_values[z, y, x], -tool_distance)

texture_data.coarse_texture.copy_from(coarse_values)
texture_data.subgrid_texture.copy_from(subgrid_values)

surface = workpiece_sdf.extract_isomesh(device=model.device)
viewer.log_mesh(
    "/workpiece_sdf", points, indices, dynamic=True
)

Notes

Run

cd <newton-checkout>
uv sync --extra examples
uv run python <path-to-download>/example_sdf_grinding.py

Full source

Loading example_sdf_grinding.py…