Local preservation snapshot, not a new deployment or simulation acceptance.
80 lines
2.8 KiB
Python
80 lines
2.8 KiB
Python
"""Worker-local Warp BVH for editing against the collider while physics is paused.
|
|
|
|
This queries the prepared metric terrain, never splat density or rover visuals.
|
|
Warp ships with Isaac; no operator-side geometry or added service is involved.
|
|
"""
|
|
|
|
import numpy as np
|
|
import warp as wp
|
|
|
|
|
|
@wp.kernel
|
|
def intersections(
|
|
mesh: wp.uint64,
|
|
origin: wp.vec3,
|
|
direction: wp.vec3,
|
|
distance: float,
|
|
positions: wp.array(dtype=wp.vec3),
|
|
normals: wp.array(dtype=wp.vec3),
|
|
count: wp.array(dtype=wp.int32),
|
|
):
|
|
start = origin
|
|
remaining = distance
|
|
count[0] = 0
|
|
for i in range(64):
|
|
hit = wp.mesh_query_ray(mesh, start, direction, remaining)
|
|
if not hit.result:
|
|
break
|
|
position = start + hit.t * direction
|
|
positions[i] = position
|
|
normals[i] = hit.normal
|
|
count[0] = i + 1
|
|
start = position + 0.001 * direction
|
|
remaining = remaining - hit.t - 0.001
|
|
if remaining <= 0.0:
|
|
break
|
|
|
|
|
|
class TerrainPicker:
|
|
def __init__(self, stage):
|
|
from pxr import UsdGeom
|
|
|
|
geometry = UsdGeom.Mesh(stage.GetPrimAtPath("/World/Terrain"))
|
|
points = np.array(geometry.GetPointsAttr().Get())
|
|
low, high = float(points[:, 2].min()), float(points[:, 2].max())
|
|
# Gaussian ellipsoid extents can span kilometres because of a handful of
|
|
# reconstruction outliers. The prepared metric scene defines the useful
|
|
# height range; the top endpoint explicitly disables clipping altogether.
|
|
self.height_bounds = (max(-10000, low), min(10000, max(high, low + 0.1)))
|
|
device = "cuda:0"
|
|
self.mesh = wp.Mesh(
|
|
points=wp.array(points, dtype=wp.vec3, device=device),
|
|
indices=wp.array(
|
|
np.array(geometry.GetFaceVertexIndicesAttr().Get()), dtype=wp.int32, device=device
|
|
),
|
|
)
|
|
self.positions = wp.empty(64, dtype=wp.vec3, device=device)
|
|
self.normals = wp.empty(64, dtype=wp.vec3, device=device)
|
|
self.count = wp.zeros(1, dtype=wp.int32, device=device)
|
|
|
|
def raycast_all(self, origin, direction, distance, collect, bothSides=True):
|
|
wp.launch(
|
|
intersections,
|
|
dim=1,
|
|
device=self.count.device,
|
|
inputs=[self.mesh.id, wp.vec3(*origin), wp.vec3(*direction), float(distance)],
|
|
outputs=[self.positions, self.normals, self.count],
|
|
)
|
|
count = int(self.count.numpy()[0])
|
|
positions, normals = self.positions.numpy(), self.normals.numpy()
|
|
for i in range(count):
|
|
if not collect(
|
|
{
|
|
"collision": "/World/Terrain",
|
|
"position": positions[i].tolist(),
|
|
"normal": normals[i].tolist(),
|
|
}
|
|
):
|
|
break
|
|
return count > 0
|