warp-lang 1.9.1__py3-none-manylinux_2_34_aarch64.whl → 1.10.0rc2__py3-none-manylinux_2_34_aarch64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of warp-lang might be problematic. Click here for more details.
- warp/__init__.py +301 -287
- warp/__init__.pyi +794 -305
- warp/_src/__init__.py +14 -0
- warp/_src/autograd.py +1075 -0
- warp/_src/build.py +618 -0
- warp/_src/build_dll.py +640 -0
- warp/{builtins.py → _src/builtins.py} +1382 -377
- warp/_src/codegen.py +4359 -0
- warp/{config.py → _src/config.py} +178 -169
- warp/_src/constants.py +57 -0
- warp/_src/context.py +8294 -0
- warp/_src/dlpack.py +462 -0
- warp/_src/fabric.py +355 -0
- warp/_src/fem/__init__.py +14 -0
- warp/_src/fem/adaptivity.py +508 -0
- warp/_src/fem/cache.py +687 -0
- warp/_src/fem/dirichlet.py +188 -0
- warp/{fem → _src/fem}/domain.py +40 -30
- warp/_src/fem/field/__init__.py +131 -0
- warp/_src/fem/field/field.py +701 -0
- warp/{fem → _src/fem}/field/nodal_field.py +30 -15
- warp/{fem → _src/fem}/field/restriction.py +1 -1
- warp/{fem → _src/fem}/field/virtual.py +53 -27
- warp/_src/fem/geometry/__init__.py +32 -0
- warp/{fem → _src/fem}/geometry/adaptive_nanogrid.py +77 -163
- warp/_src/fem/geometry/closest_point.py +97 -0
- warp/{fem → _src/fem}/geometry/deformed_geometry.py +14 -22
- warp/{fem → _src/fem}/geometry/element.py +32 -10
- warp/{fem → _src/fem}/geometry/geometry.py +48 -20
- warp/{fem → _src/fem}/geometry/grid_2d.py +12 -23
- warp/{fem → _src/fem}/geometry/grid_3d.py +12 -23
- warp/{fem → _src/fem}/geometry/hexmesh.py +40 -63
- warp/{fem → _src/fem}/geometry/nanogrid.py +255 -248
- warp/{fem → _src/fem}/geometry/partition.py +121 -63
- warp/{fem → _src/fem}/geometry/quadmesh.py +26 -45
- warp/{fem → _src/fem}/geometry/tetmesh.py +40 -63
- warp/{fem → _src/fem}/geometry/trimesh.py +26 -45
- warp/{fem → _src/fem}/integrate.py +164 -158
- warp/_src/fem/linalg.py +383 -0
- warp/_src/fem/operator.py +396 -0
- warp/_src/fem/polynomial.py +229 -0
- warp/{fem → _src/fem}/quadrature/pic_quadrature.py +15 -20
- warp/{fem → _src/fem}/quadrature/quadrature.py +95 -47
- warp/_src/fem/space/__init__.py +248 -0
- warp/{fem → _src/fem}/space/basis_function_space.py +20 -11
- warp/_src/fem/space/basis_space.py +679 -0
- warp/{fem → _src/fem}/space/dof_mapper.py +3 -3
- warp/{fem → _src/fem}/space/function_space.py +14 -13
- warp/{fem → _src/fem}/space/grid_2d_function_space.py +4 -7
- warp/{fem → _src/fem}/space/grid_3d_function_space.py +4 -4
- warp/{fem → _src/fem}/space/hexmesh_function_space.py +4 -10
- warp/{fem → _src/fem}/space/nanogrid_function_space.py +3 -9
- warp/{fem → _src/fem}/space/partition.py +117 -60
- warp/{fem → _src/fem}/space/quadmesh_function_space.py +4 -10
- warp/{fem → _src/fem}/space/restriction.py +66 -33
- warp/_src/fem/space/shape/__init__.py +152 -0
- warp/{fem → _src/fem}/space/shape/cube_shape_function.py +9 -9
- warp/{fem → _src/fem}/space/shape/shape_function.py +8 -9
- warp/{fem → _src/fem}/space/shape/square_shape_function.py +6 -6
- warp/{fem → _src/fem}/space/shape/tet_shape_function.py +3 -3
- warp/{fem → _src/fem}/space/shape/triangle_shape_function.py +3 -3
- warp/{fem → _src/fem}/space/tetmesh_function_space.py +3 -9
- warp/_src/fem/space/topology.py +459 -0
- warp/{fem → _src/fem}/space/trimesh_function_space.py +3 -9
- warp/_src/fem/types.py +112 -0
- warp/_src/fem/utils.py +486 -0
- warp/_src/jax.py +186 -0
- warp/_src/jax_experimental/__init__.py +14 -0
- warp/_src/jax_experimental/custom_call.py +387 -0
- warp/_src/jax_experimental/ffi.py +1284 -0
- warp/_src/jax_experimental/xla_ffi.py +656 -0
- warp/_src/marching_cubes.py +708 -0
- warp/_src/math.py +414 -0
- warp/_src/optim/__init__.py +14 -0
- warp/_src/optim/adam.py +163 -0
- warp/_src/optim/linear.py +1606 -0
- warp/_src/optim/sgd.py +112 -0
- warp/_src/paddle.py +406 -0
- warp/_src/render/__init__.py +14 -0
- warp/_src/render/imgui_manager.py +289 -0
- warp/_src/render/render_opengl.py +3636 -0
- warp/_src/render/render_usd.py +937 -0
- warp/_src/render/utils.py +160 -0
- warp/_src/sparse.py +2716 -0
- warp/_src/tape.py +1206 -0
- warp/{thirdparty → _src/thirdparty}/unittest_parallel.py +9 -2
- warp/_src/torch.py +391 -0
- warp/_src/types.py +5870 -0
- warp/_src/utils.py +1693 -0
- warp/autograd.py +12 -1054
- warp/bin/warp-clang.so +0 -0
- warp/bin/warp.so +0 -0
- warp/build.py +8 -588
- warp/build_dll.py +6 -721
- warp/codegen.py +6 -4251
- warp/constants.py +6 -39
- warp/context.py +12 -8062
- warp/dlpack.py +6 -444
- warp/examples/distributed/example_jacobi_mpi.py +4 -5
- warp/examples/fem/example_adaptive_grid.py +1 -1
- warp/examples/fem/example_apic_fluid.py +1 -1
- warp/examples/fem/example_burgers.py +8 -8
- warp/examples/fem/example_diffusion.py +1 -1
- warp/examples/fem/example_distortion_energy.py +1 -1
- warp/examples/fem/example_mixed_elasticity.py +2 -2
- warp/examples/fem/example_navier_stokes.py +1 -1
- warp/examples/fem/example_nonconforming_contact.py +7 -7
- warp/examples/fem/example_stokes.py +1 -1
- warp/examples/fem/example_stokes_transfer.py +1 -1
- warp/examples/fem/utils.py +2 -2
- warp/examples/interop/example_jax_callable.py +1 -1
- warp/examples/interop/example_jax_ffi_callback.py +1 -1
- warp/examples/interop/example_jax_kernel.py +1 -1
- warp/examples/tile/example_tile_mcgp.py +191 -0
- warp/fabric.py +6 -337
- warp/fem/__init__.py +159 -97
- warp/fem/adaptivity.py +7 -489
- warp/fem/cache.py +9 -648
- warp/fem/dirichlet.py +6 -184
- warp/fem/field/__init__.py +8 -109
- warp/fem/field/field.py +7 -652
- warp/fem/geometry/__init__.py +7 -18
- warp/fem/geometry/closest_point.py +11 -77
- warp/fem/linalg.py +18 -366
- warp/fem/operator.py +11 -369
- warp/fem/polynomial.py +9 -209
- warp/fem/space/__init__.py +5 -211
- warp/fem/space/basis_space.py +6 -662
- warp/fem/space/shape/__init__.py +41 -118
- warp/fem/space/topology.py +6 -437
- warp/fem/types.py +6 -81
- warp/fem/utils.py +11 -444
- warp/jax.py +8 -165
- warp/jax_experimental/__init__.py +14 -1
- warp/jax_experimental/custom_call.py +8 -365
- warp/jax_experimental/ffi.py +17 -873
- warp/jax_experimental/xla_ffi.py +5 -605
- warp/marching_cubes.py +5 -689
- warp/math.py +16 -393
- warp/native/array.h +385 -37
- warp/native/builtin.h +314 -37
- warp/native/bvh.cpp +43 -9
- warp/native/bvh.cu +62 -27
- warp/native/bvh.h +310 -309
- warp/native/clang/clang.cpp +102 -97
- warp/native/coloring.cpp +0 -1
- warp/native/crt.h +208 -0
- warp/native/exports.h +156 -0
- warp/native/hashgrid.cu +2 -0
- warp/native/intersect.h +24 -1
- warp/native/intersect_tri.h +44 -35
- warp/native/mat.h +1456 -276
- warp/native/mesh.cpp +4 -4
- warp/native/mesh.cu +4 -2
- warp/native/mesh.h +176 -61
- warp/native/quat.h +0 -52
- warp/native/scan.cu +2 -0
- warp/native/sparse.cu +7 -3
- warp/native/spatial.h +12 -0
- warp/native/tile.h +681 -89
- warp/native/tile_radix_sort.h +1 -1
- warp/native/tile_reduce.h +394 -46
- warp/native/tile_scan.h +4 -4
- warp/native/vec.h +469 -0
- warp/native/version.h +23 -0
- warp/native/volume.cpp +1 -1
- warp/native/volume.cu +1 -0
- warp/native/volume.h +1 -1
- warp/native/volume_builder.cu +2 -0
- warp/native/warp.cpp +57 -29
- warp/native/warp.cu +253 -171
- warp/native/warp.h +11 -8
- warp/optim/__init__.py +6 -3
- warp/optim/adam.py +6 -145
- warp/optim/linear.py +14 -1585
- warp/optim/sgd.py +6 -94
- warp/paddle.py +6 -388
- warp/render/__init__.py +8 -4
- warp/render/imgui_manager.py +7 -267
- warp/render/render_opengl.py +6 -3618
- warp/render/render_usd.py +6 -919
- warp/render/utils.py +6 -142
- warp/sparse.py +37 -2563
- warp/tape.py +6 -1188
- warp/tests/__main__.py +1 -1
- warp/tests/cuda/test_async.py +4 -4
- warp/tests/cuda/test_conditional_captures.py +1 -1
- warp/tests/cuda/test_multigpu.py +1 -1
- warp/tests/cuda/test_streams.py +58 -1
- warp/tests/geometry/test_bvh.py +157 -22
- warp/tests/geometry/test_marching_cubes.py +0 -1
- warp/tests/geometry/test_mesh.py +5 -3
- warp/tests/geometry/test_mesh_query_aabb.py +5 -12
- warp/tests/geometry/test_mesh_query_point.py +5 -2
- warp/tests/geometry/test_mesh_query_ray.py +15 -3
- warp/tests/geometry/test_volume_write.py +5 -5
- warp/tests/interop/test_dlpack.py +14 -14
- warp/tests/interop/test_jax.py +772 -49
- warp/tests/interop/test_paddle.py +1 -1
- warp/tests/test_adam.py +0 -1
- warp/tests/test_arithmetic.py +9 -9
- warp/tests/test_array.py +527 -100
- warp/tests/test_array_reduce.py +3 -3
- warp/tests/test_atomic.py +12 -8
- warp/tests/test_atomic_bitwise.py +209 -0
- warp/tests/test_atomic_cas.py +4 -4
- warp/tests/test_bool.py +2 -2
- warp/tests/test_builtins_resolution.py +5 -571
- warp/tests/test_codegen.py +33 -14
- warp/tests/test_conditional.py +1 -1
- warp/tests/test_context.py +6 -6
- warp/tests/test_copy.py +242 -161
- warp/tests/test_ctypes.py +3 -3
- warp/tests/test_devices.py +24 -2
- warp/tests/test_examples.py +16 -84
- warp/tests/test_fabricarray.py +35 -35
- warp/tests/test_fast_math.py +0 -2
- warp/tests/test_fem.py +56 -10
- warp/tests/test_fixedarray.py +3 -3
- warp/tests/test_func.py +8 -5
- warp/tests/test_generics.py +1 -1
- warp/tests/test_indexedarray.py +24 -24
- warp/tests/test_intersect.py +39 -9
- warp/tests/test_large.py +1 -1
- warp/tests/test_lerp.py +3 -1
- warp/tests/test_linear_solvers.py +1 -1
- warp/tests/test_map.py +35 -4
- warp/tests/test_mat.py +52 -62
- warp/tests/test_mat_constructors.py +4 -5
- warp/tests/test_mat_lite.py +1 -1
- warp/tests/test_mat_scalar_ops.py +121 -121
- warp/tests/test_math.py +34 -0
- warp/tests/test_module_aot.py +4 -4
- warp/tests/test_modules_lite.py +28 -2
- warp/tests/test_print.py +11 -11
- warp/tests/test_quat.py +93 -58
- warp/tests/test_runlength_encode.py +1 -1
- warp/tests/test_scalar_ops.py +38 -10
- warp/tests/test_smoothstep.py +1 -1
- warp/tests/test_sparse.py +126 -15
- warp/tests/test_spatial.py +105 -87
- warp/tests/test_special_values.py +6 -6
- warp/tests/test_static.py +7 -7
- warp/tests/test_struct.py +13 -2
- warp/tests/test_triangle_closest_point.py +48 -1
- warp/tests/test_types.py +27 -15
- warp/tests/test_utils.py +52 -52
- warp/tests/test_vec.py +29 -29
- warp/tests/test_vec_constructors.py +5 -5
- warp/tests/test_vec_scalar_ops.py +97 -97
- warp/tests/test_version.py +75 -0
- warp/tests/tile/test_tile.py +178 -0
- warp/tests/tile/test_tile_atomic_bitwise.py +403 -0
- warp/tests/tile/test_tile_cholesky.py +7 -4
- warp/tests/tile/test_tile_load.py +26 -2
- warp/tests/tile/test_tile_mathdx.py +3 -3
- warp/tests/tile/test_tile_matmul.py +1 -1
- warp/tests/tile/test_tile_mlp.py +2 -4
- warp/tests/tile/test_tile_reduce.py +214 -13
- warp/tests/unittest_suites.py +6 -14
- warp/tests/unittest_utils.py +10 -9
- warp/tests/walkthrough_debug.py +3 -1
- warp/torch.py +6 -373
- warp/types.py +29 -5764
- warp/utils.py +10 -1659
- {warp_lang-1.9.1.dist-info → warp_lang-1.10.0rc2.dist-info}/METADATA +46 -99
- warp_lang-1.10.0rc2.dist-info/RECORD +468 -0
- warp_lang-1.10.0rc2.dist-info/licenses/licenses/Gaia-LICENSE.txt +6 -0
- warp_lang-1.10.0rc2.dist-info/licenses/licenses/appdirs-LICENSE.txt +22 -0
- warp_lang-1.10.0rc2.dist-info/licenses/licenses/asset_pixel_jpg-LICENSE.txt +3 -0
- warp_lang-1.10.0rc2.dist-info/licenses/licenses/cuda-LICENSE.txt +1582 -0
- warp_lang-1.10.0rc2.dist-info/licenses/licenses/dlpack-LICENSE.txt +201 -0
- warp_lang-1.10.0rc2.dist-info/licenses/licenses/fp16-LICENSE.txt +28 -0
- warp_lang-1.10.0rc2.dist-info/licenses/licenses/libmathdx-LICENSE.txt +220 -0
- warp_lang-1.10.0rc2.dist-info/licenses/licenses/llvm-LICENSE.txt +279 -0
- warp_lang-1.10.0rc2.dist-info/licenses/licenses/moller-LICENSE.txt +16 -0
- warp_lang-1.10.0rc2.dist-info/licenses/licenses/nanovdb-LICENSE.txt +2 -0
- warp_lang-1.10.0rc2.dist-info/licenses/licenses/nvrtc-LICENSE.txt +1592 -0
- warp_lang-1.10.0rc2.dist-info/licenses/licenses/svd-LICENSE.txt +23 -0
- warp_lang-1.10.0rc2.dist-info/licenses/licenses/unittest_parallel-LICENSE.txt +21 -0
- warp_lang-1.10.0rc2.dist-info/licenses/licenses/usd-LICENSE.txt +213 -0
- warp_lang-1.10.0rc2.dist-info/licenses/licenses/windingnumber-LICENSE.txt +21 -0
- warp/examples/assets/cartpole.urdf +0 -110
- warp/examples/assets/crazyflie.usd +0 -0
- warp/examples/assets/nv_ant.xml +0 -92
- warp/examples/assets/nv_humanoid.xml +0 -183
- warp/examples/assets/quadruped.urdf +0 -268
- warp/examples/optim/example_bounce.py +0 -266
- warp/examples/optim/example_cloth_throw.py +0 -228
- warp/examples/optim/example_drone.py +0 -870
- warp/examples/optim/example_inverse_kinematics.py +0 -182
- warp/examples/optim/example_inverse_kinematics_torch.py +0 -191
- warp/examples/optim/example_softbody_properties.py +0 -400
- warp/examples/optim/example_spring_cage.py +0 -245
- warp/examples/optim/example_trajectory.py +0 -227
- warp/examples/sim/example_cartpole.py +0 -143
- warp/examples/sim/example_cloth.py +0 -225
- warp/examples/sim/example_cloth_self_contact.py +0 -316
- warp/examples/sim/example_granular.py +0 -130
- warp/examples/sim/example_granular_collision_sdf.py +0 -202
- warp/examples/sim/example_jacobian_ik.py +0 -244
- warp/examples/sim/example_particle_chain.py +0 -124
- warp/examples/sim/example_quadruped.py +0 -203
- warp/examples/sim/example_rigid_chain.py +0 -203
- warp/examples/sim/example_rigid_contact.py +0 -195
- warp/examples/sim/example_rigid_force.py +0 -133
- warp/examples/sim/example_rigid_gyroscopic.py +0 -115
- warp/examples/sim/example_rigid_soft_contact.py +0 -140
- warp/examples/sim/example_soft_body.py +0 -196
- warp/examples/tile/example_tile_walker.py +0 -327
- warp/sim/__init__.py +0 -74
- warp/sim/articulation.py +0 -793
- warp/sim/collide.py +0 -2570
- warp/sim/graph_coloring.py +0 -307
- warp/sim/import_mjcf.py +0 -791
- warp/sim/import_snu.py +0 -227
- warp/sim/import_urdf.py +0 -579
- warp/sim/import_usd.py +0 -898
- warp/sim/inertia.py +0 -357
- warp/sim/integrator.py +0 -245
- warp/sim/integrator_euler.py +0 -2000
- warp/sim/integrator_featherstone.py +0 -2101
- warp/sim/integrator_vbd.py +0 -2487
- warp/sim/integrator_xpbd.py +0 -3295
- warp/sim/model.py +0 -4821
- warp/sim/particles.py +0 -121
- warp/sim/render.py +0 -431
- warp/sim/utils.py +0 -431
- warp/tests/sim/disabled_kinematics.py +0 -244
- warp/tests/sim/test_cloth.py +0 -863
- warp/tests/sim/test_collision.py +0 -743
- warp/tests/sim/test_coloring.py +0 -347
- warp/tests/sim/test_inertia.py +0 -161
- warp/tests/sim/test_model.py +0 -226
- warp/tests/sim/test_sim_grad.py +0 -287
- warp/tests/sim/test_sim_grad_bounce_linear.py +0 -212
- warp/tests/sim/test_sim_kinematics.py +0 -98
- warp/thirdparty/__init__.py +0 -0
- warp_lang-1.9.1.dist-info/RECORD +0 -456
- /warp/{fem → _src/fem}/quadrature/__init__.py +0 -0
- /warp/{tests/sim → _src/thirdparty}/__init__.py +0 -0
- /warp/{thirdparty → _src/thirdparty}/appdirs.py +0 -0
- /warp/{thirdparty → _src/thirdparty}/dlpack.py +0 -0
- {warp_lang-1.9.1.dist-info → warp_lang-1.10.0rc2.dist-info}/WHEEL +0 -0
- {warp_lang-1.9.1.dist-info → warp_lang-1.10.0rc2.dist-info}/licenses/LICENSE.md +0 -0
- {warp_lang-1.9.1.dist-info → warp_lang-1.10.0rc2.dist-info}/top_level.txt +0 -0
warp/tests/sim/test_collision.py
DELETED
|
@@ -1,743 +0,0 @@
|
|
|
1
|
-
# SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
|
2
|
-
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
#
|
|
4
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
# you may not use this file except in compliance with the License.
|
|
6
|
-
# You may obtain a copy of the License at
|
|
7
|
-
#
|
|
8
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
#
|
|
10
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
# See the License for the specific language governing permissions and
|
|
14
|
-
# limitations under the License.
|
|
15
|
-
|
|
16
|
-
import unittest
|
|
17
|
-
|
|
18
|
-
import warp as wp
|
|
19
|
-
import warp.examples
|
|
20
|
-
import warp.sim
|
|
21
|
-
from warp.sim.collide import (
|
|
22
|
-
TriMeshCollisionDetector,
|
|
23
|
-
init_triangle_collision_data_kernel,
|
|
24
|
-
triangle_closest_point,
|
|
25
|
-
vertex_adjacent_to_triangle,
|
|
26
|
-
)
|
|
27
|
-
from warp.sim.integrator_euler import eval_triangles_contact
|
|
28
|
-
from warp.tests.unittest_utils import *
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
@wp.kernel
|
|
32
|
-
def vertex_triangle_collision_detection_brute_force(
|
|
33
|
-
query_radius: float,
|
|
34
|
-
bvh_id: wp.uint64,
|
|
35
|
-
pos: wp.array(dtype=wp.vec3),
|
|
36
|
-
tri_indices: wp.array(dtype=wp.int32, ndim=2),
|
|
37
|
-
vertex_colliding_triangles: wp.array(dtype=wp.int32),
|
|
38
|
-
vertex_colliding_triangles_count: wp.array(dtype=wp.int32),
|
|
39
|
-
vertex_colliding_triangles_offsets: wp.array(dtype=wp.int32),
|
|
40
|
-
vertex_colliding_triangles_buffer_size: wp.array(dtype=wp.int32),
|
|
41
|
-
vertex_colliding_triangles_min_dist: wp.array(dtype=float),
|
|
42
|
-
triangle_colliding_vertices: wp.array(dtype=wp.int32),
|
|
43
|
-
triangle_colliding_vertices_count: wp.array(dtype=wp.int32),
|
|
44
|
-
triangle_colliding_vertices_buffer_offsets: wp.array(dtype=wp.int32),
|
|
45
|
-
triangle_colliding_vertices_buffer_sizes: wp.array(dtype=wp.int32),
|
|
46
|
-
triangle_colliding_vertices_min_dist: wp.array(dtype=float),
|
|
47
|
-
resize_flags: wp.array(dtype=wp.int32),
|
|
48
|
-
):
|
|
49
|
-
v_index = wp.tid()
|
|
50
|
-
v = pos[v_index]
|
|
51
|
-
|
|
52
|
-
vertex_num_collisions = wp.int32(0)
|
|
53
|
-
min_dis_to_tris = query_radius
|
|
54
|
-
for tri_index in range(tri_indices.shape[0]):
|
|
55
|
-
t1 = tri_indices[tri_index, 0]
|
|
56
|
-
t2 = tri_indices[tri_index, 1]
|
|
57
|
-
t3 = tri_indices[tri_index, 2]
|
|
58
|
-
if vertex_adjacent_to_triangle(v_index, t1, t2, t3):
|
|
59
|
-
continue
|
|
60
|
-
|
|
61
|
-
u1 = pos[t1]
|
|
62
|
-
u2 = pos[t2]
|
|
63
|
-
u3 = pos[t3]
|
|
64
|
-
|
|
65
|
-
closest_p, bary, feature_type = triangle_closest_point(u1, u2, u3, v)
|
|
66
|
-
|
|
67
|
-
dis = wp.length(closest_p - v)
|
|
68
|
-
|
|
69
|
-
if dis < query_radius:
|
|
70
|
-
vertex_num_collisions = vertex_num_collisions + 1
|
|
71
|
-
min_dis_to_tris = wp.min(dis, min_dis_to_tris)
|
|
72
|
-
|
|
73
|
-
wp.atomic_add(triangle_colliding_vertices_count, tri_index, 1)
|
|
74
|
-
wp.atomic_min(triangle_colliding_vertices_min_dist, tri_index, dis)
|
|
75
|
-
|
|
76
|
-
vertex_colliding_triangles_count[v_index] = vertex_num_collisions
|
|
77
|
-
vertex_colliding_triangles_min_dist[v_index] = min_dis_to_tris
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
@wp.kernel
|
|
81
|
-
def vertex_triangle_collision_detection_brute_force_no_triangle_buffers(
|
|
82
|
-
query_radius: float,
|
|
83
|
-
bvh_id: wp.uint64,
|
|
84
|
-
pos: wp.array(dtype=wp.vec3),
|
|
85
|
-
tri_indices: wp.array(dtype=wp.int32, ndim=2),
|
|
86
|
-
vertex_colliding_triangles: wp.array(dtype=wp.int32),
|
|
87
|
-
vertex_colliding_triangles_count: wp.array(dtype=wp.int32),
|
|
88
|
-
vertex_colliding_triangles_offsets: wp.array(dtype=wp.int32),
|
|
89
|
-
vertex_colliding_triangles_buffer_size: wp.array(dtype=wp.int32),
|
|
90
|
-
vertex_colliding_triangles_min_dist: wp.array(dtype=float),
|
|
91
|
-
triangle_colliding_vertices_min_dist: wp.array(dtype=float),
|
|
92
|
-
resize_flags: wp.array(dtype=wp.int32),
|
|
93
|
-
):
|
|
94
|
-
v_index = wp.tid()
|
|
95
|
-
v = pos[v_index]
|
|
96
|
-
|
|
97
|
-
vertex_num_collisions = wp.int32(0)
|
|
98
|
-
min_dis_to_tris = query_radius
|
|
99
|
-
for tri_index in range(tri_indices.shape[0]):
|
|
100
|
-
t1 = tri_indices[tri_index, 0]
|
|
101
|
-
t2 = tri_indices[tri_index, 1]
|
|
102
|
-
t3 = tri_indices[tri_index, 2]
|
|
103
|
-
if vertex_adjacent_to_triangle(v_index, t1, t2, t3):
|
|
104
|
-
continue
|
|
105
|
-
|
|
106
|
-
u1 = pos[t1]
|
|
107
|
-
u2 = pos[t2]
|
|
108
|
-
u3 = pos[t3]
|
|
109
|
-
|
|
110
|
-
closest_p, bary, feature_type = triangle_closest_point(u1, u2, u3, v)
|
|
111
|
-
|
|
112
|
-
dis = wp.length(closest_p - v)
|
|
113
|
-
|
|
114
|
-
if dis < query_radius:
|
|
115
|
-
vertex_num_collisions = vertex_num_collisions + 1
|
|
116
|
-
min_dis_to_tris = wp.min(dis, min_dis_to_tris)
|
|
117
|
-
|
|
118
|
-
wp.atomic_min(triangle_colliding_vertices_min_dist, tri_index, dis)
|
|
119
|
-
|
|
120
|
-
vertex_colliding_triangles_count[v_index] = vertex_num_collisions
|
|
121
|
-
vertex_colliding_triangles_min_dist[v_index] = min_dis_to_tris
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
@wp.kernel
|
|
125
|
-
def validate_vertex_collisions(
|
|
126
|
-
query_radius: float,
|
|
127
|
-
bvh_id: wp.uint64,
|
|
128
|
-
pos: wp.array(dtype=wp.vec3),
|
|
129
|
-
tri_indices: wp.array(dtype=wp.int32, ndim=2),
|
|
130
|
-
vertex_colliding_triangles: wp.array(dtype=wp.int32),
|
|
131
|
-
vertex_colliding_triangles_count: wp.array(dtype=wp.int32),
|
|
132
|
-
vertex_colliding_triangles_offsets: wp.array(dtype=wp.int32),
|
|
133
|
-
vertex_colliding_triangles_buffer_size: wp.array(dtype=wp.int32),
|
|
134
|
-
vertex_colliding_triangles_min_dist: wp.array(dtype=float),
|
|
135
|
-
resize_flags: wp.array(dtype=wp.int32),
|
|
136
|
-
):
|
|
137
|
-
v_index = wp.tid()
|
|
138
|
-
v = pos[v_index]
|
|
139
|
-
|
|
140
|
-
num_cols = vertex_colliding_triangles_count[v_index]
|
|
141
|
-
offset = vertex_colliding_triangles_offsets[v_index]
|
|
142
|
-
min_dis = vertex_colliding_triangles_min_dist[v_index]
|
|
143
|
-
for col in range(vertex_colliding_triangles_buffer_size[v_index]):
|
|
144
|
-
vertex_index = vertex_colliding_triangles[2 * (offset + col)]
|
|
145
|
-
tri_index = vertex_colliding_triangles[2 * (offset + col) + 1]
|
|
146
|
-
if col < num_cols:
|
|
147
|
-
t1 = tri_indices[tri_index, 0]
|
|
148
|
-
t2 = tri_indices[tri_index, 1]
|
|
149
|
-
t3 = tri_indices[tri_index, 2]
|
|
150
|
-
# wp.expect_eq(vertex_on_triangle(v_index, t1, t2, t3), False)
|
|
151
|
-
|
|
152
|
-
u1 = pos[t1]
|
|
153
|
-
u2 = pos[t2]
|
|
154
|
-
u3 = pos[t3]
|
|
155
|
-
|
|
156
|
-
closest_p, bary, feature_type = triangle_closest_point(u1, u2, u3, v)
|
|
157
|
-
dis = wp.length(closest_p - v)
|
|
158
|
-
wp.expect_eq(dis < query_radius, True)
|
|
159
|
-
wp.expect_eq(dis >= min_dis, True)
|
|
160
|
-
wp.expect_eq(v_index == vertex_colliding_triangles[2 * (offset + col)], True)
|
|
161
|
-
|
|
162
|
-
# wp.printf("vertex %d, offset %d, num cols %d, colliding with triangle: %d, dis: %f\n",
|
|
163
|
-
# v_index, offset, num_cols, tri_index, dis)
|
|
164
|
-
else:
|
|
165
|
-
wp.expect_eq(vertex_index == -1, True)
|
|
166
|
-
wp.expect_eq(tri_index == -1, True)
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
@wp.kernel
|
|
170
|
-
def validate_triangle_collisions(
|
|
171
|
-
query_radius: float,
|
|
172
|
-
bvh_id: wp.uint64,
|
|
173
|
-
pos: wp.array(dtype=wp.vec3),
|
|
174
|
-
tri_indices: wp.array(dtype=wp.int32, ndim=2),
|
|
175
|
-
triangle_colliding_vertices: wp.array(dtype=wp.int32),
|
|
176
|
-
triangle_colliding_vertices_count: wp.array(dtype=wp.int32),
|
|
177
|
-
triangle_colliding_vertices_buffer_offsets: wp.array(dtype=wp.int32),
|
|
178
|
-
triangle_colliding_vertices_buffer_sizes: wp.array(dtype=wp.int32),
|
|
179
|
-
triangle_colliding_vertices_min_dist: wp.array(dtype=float),
|
|
180
|
-
resize_flags: wp.array(dtype=wp.int32),
|
|
181
|
-
):
|
|
182
|
-
tri_index = wp.tid()
|
|
183
|
-
|
|
184
|
-
t1 = tri_indices[tri_index, 0]
|
|
185
|
-
t2 = tri_indices[tri_index, 1]
|
|
186
|
-
t3 = tri_indices[tri_index, 2]
|
|
187
|
-
# wp.expect_eq(vertex_on_triangle(v_index, t1, t2, t3), False)
|
|
188
|
-
|
|
189
|
-
u1 = pos[t1]
|
|
190
|
-
u2 = pos[t2]
|
|
191
|
-
u3 = pos[t3]
|
|
192
|
-
|
|
193
|
-
num_cols = triangle_colliding_vertices_count[tri_index]
|
|
194
|
-
offset = triangle_colliding_vertices_buffer_offsets[tri_index]
|
|
195
|
-
min_dis = triangle_colliding_vertices_min_dist[tri_index]
|
|
196
|
-
for col in range(wp.min(num_cols, triangle_colliding_vertices_buffer_sizes[tri_index])):
|
|
197
|
-
v_index = triangle_colliding_vertices[offset + col]
|
|
198
|
-
v = pos[v_index]
|
|
199
|
-
|
|
200
|
-
closest_p, bary, feature_type = triangle_closest_point(u1, u2, u3, v)
|
|
201
|
-
dis = wp.length(closest_p - v)
|
|
202
|
-
wp.expect_eq(dis < query_radius, True)
|
|
203
|
-
wp.expect_eq(dis >= min_dis, True)
|
|
204
|
-
|
|
205
|
-
# wp.printf("vertex %d, offset %d, num cols %d, colliding with triangle: %d, dis: %f\n",
|
|
206
|
-
# v_index, offset, num_cols, tri_index, dis)
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
@wp.kernel
|
|
210
|
-
def edge_edge_collision_detection_brute_force(
|
|
211
|
-
query_radius: float,
|
|
212
|
-
bvh_id: wp.uint64,
|
|
213
|
-
pos: wp.array(dtype=wp.vec3),
|
|
214
|
-
edge_indices: wp.array(dtype=wp.int32, ndim=2),
|
|
215
|
-
edge_colliding_edges_offsets: wp.array(dtype=wp.int32),
|
|
216
|
-
edge_colliding_edges_buffer_sizes: wp.array(dtype=wp.int32),
|
|
217
|
-
edge_edge_parallel_epsilon: float,
|
|
218
|
-
# outputs
|
|
219
|
-
edge_colliding_edges: wp.array(dtype=wp.int32),
|
|
220
|
-
edge_colliding_edges_count: wp.array(dtype=wp.int32),
|
|
221
|
-
edge_colliding_edges_min_dist: wp.array(dtype=float),
|
|
222
|
-
resize_flags: wp.array(dtype=wp.int32),
|
|
223
|
-
):
|
|
224
|
-
e_index = wp.tid()
|
|
225
|
-
|
|
226
|
-
e0_v0 = edge_indices[e_index, 2]
|
|
227
|
-
e0_v1 = edge_indices[e_index, 3]
|
|
228
|
-
|
|
229
|
-
e0_v0_pos = pos[e0_v0]
|
|
230
|
-
e0_v1_pos = pos[e0_v1]
|
|
231
|
-
|
|
232
|
-
min_dis_to_edges = query_radius
|
|
233
|
-
edge_num_collisions = wp.int32(0)
|
|
234
|
-
for e1_index in range(edge_indices.shape[0]):
|
|
235
|
-
e1_v0 = edge_indices[e1_index, 2]
|
|
236
|
-
e1_v1 = edge_indices[e1_index, 3]
|
|
237
|
-
|
|
238
|
-
if e0_v0 == e1_v0 or e0_v0 == e1_v1 or e0_v1 == e1_v0 or e0_v1 == e1_v1:
|
|
239
|
-
continue
|
|
240
|
-
|
|
241
|
-
e1_v0_pos = pos[e1_v0]
|
|
242
|
-
e1_v1_pos = pos[e1_v1]
|
|
243
|
-
|
|
244
|
-
st = wp.closest_point_edge_edge(e0_v0_pos, e0_v1_pos, e1_v0_pos, e1_v1_pos, edge_edge_parallel_epsilon)
|
|
245
|
-
s = st[0]
|
|
246
|
-
t = st[1]
|
|
247
|
-
c1 = e0_v0_pos + (e0_v1_pos - e0_v0_pos) * s
|
|
248
|
-
c2 = e1_v0_pos + (e1_v1_pos - e1_v0_pos) * t
|
|
249
|
-
|
|
250
|
-
dist = wp.length(c1 - c2)
|
|
251
|
-
if dist < query_radius:
|
|
252
|
-
edge_buffer_offset = edge_colliding_edges_offsets[e_index]
|
|
253
|
-
edge_buffer_size = edge_colliding_edges_offsets[e_index + 1] - edge_buffer_offset
|
|
254
|
-
|
|
255
|
-
# record e-e collision to e0, and leave e1; e1 will detect this collision from its own thread
|
|
256
|
-
min_dis_to_edges = wp.min(min_dis_to_edges, dist)
|
|
257
|
-
if edge_num_collisions < edge_buffer_size:
|
|
258
|
-
edge_colliding_edges[edge_buffer_offset + edge_num_collisions] = e1_index
|
|
259
|
-
else:
|
|
260
|
-
resize_flags[1] = 1
|
|
261
|
-
|
|
262
|
-
edge_num_collisions = edge_num_collisions + 1
|
|
263
|
-
|
|
264
|
-
edge_colliding_edges_count[e_index] = edge_num_collisions
|
|
265
|
-
edge_colliding_edges_min_dist[e_index] = min_dis_to_edges
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
@wp.kernel
|
|
269
|
-
def validate_edge_collisions(
|
|
270
|
-
query_radius: float,
|
|
271
|
-
bvh_id: wp.uint64,
|
|
272
|
-
pos: wp.array(dtype=wp.vec3),
|
|
273
|
-
edge_indices: wp.array(dtype=wp.int32, ndim=2),
|
|
274
|
-
edge_colliding_edges_offsets: wp.array(dtype=wp.int32),
|
|
275
|
-
edge_colliding_edges_buffer_sizes: wp.array(dtype=wp.int32),
|
|
276
|
-
edge_edge_parallel_epsilon: float,
|
|
277
|
-
# outputs
|
|
278
|
-
edge_colliding_edges: wp.array(dtype=wp.int32),
|
|
279
|
-
edge_colliding_edges_count: wp.array(dtype=wp.int32),
|
|
280
|
-
edge_colliding_edges_min_dist: wp.array(dtype=float),
|
|
281
|
-
resize_flags: wp.array(dtype=wp.int32),
|
|
282
|
-
):
|
|
283
|
-
e0_index = wp.tid()
|
|
284
|
-
|
|
285
|
-
e0_v0 = edge_indices[e0_index, 2]
|
|
286
|
-
e0_v1 = edge_indices[e0_index, 3]
|
|
287
|
-
|
|
288
|
-
e0_v0_pos = pos[e0_v0]
|
|
289
|
-
e0_v1_pos = pos[e0_v1]
|
|
290
|
-
|
|
291
|
-
num_cols = edge_colliding_edges_count[e0_index]
|
|
292
|
-
offset = edge_colliding_edges_offsets[e0_index]
|
|
293
|
-
min_dist = edge_colliding_edges_min_dist[e0_index]
|
|
294
|
-
for col in range(edge_colliding_edges_buffer_sizes[e0_index]):
|
|
295
|
-
e1_index = edge_colliding_edges[2 * (offset + col) + 1]
|
|
296
|
-
|
|
297
|
-
if col < num_cols:
|
|
298
|
-
e1_v0 = edge_indices[e1_index, 2]
|
|
299
|
-
e1_v1 = edge_indices[e1_index, 3]
|
|
300
|
-
|
|
301
|
-
if e0_v0 == e1_v0 or e0_v0 == e1_v1 or e0_v1 == e1_v0 or e0_v1 == e1_v1:
|
|
302
|
-
wp.expect_eq(False, True)
|
|
303
|
-
|
|
304
|
-
e1_v0_pos = pos[e1_v0]
|
|
305
|
-
e1_v1_pos = pos[e1_v1]
|
|
306
|
-
|
|
307
|
-
st = wp.closest_point_edge_edge(e0_v0_pos, e0_v1_pos, e1_v0_pos, e1_v1_pos, edge_edge_parallel_epsilon)
|
|
308
|
-
s = st[0]
|
|
309
|
-
t = st[1]
|
|
310
|
-
c1 = e0_v0_pos + (e0_v1_pos - e0_v0_pos) * s
|
|
311
|
-
c2 = e1_v0_pos + (e1_v1_pos - e1_v0_pos) * t
|
|
312
|
-
|
|
313
|
-
dist = wp.length(c2 - c1)
|
|
314
|
-
|
|
315
|
-
wp.expect_eq(dist >= min_dist, True)
|
|
316
|
-
wp.expect_eq(e0_index == edge_colliding_edges[2 * (offset + col)], True)
|
|
317
|
-
else:
|
|
318
|
-
wp.expect_eq(e1_index == -1, True)
|
|
319
|
-
wp.expect_eq(edge_colliding_edges[2 * (offset + col)] == -1, True)
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
def init_model(vs, fs, device, record_triangle_contacting_vertices=True):
|
|
323
|
-
vertices = [wp.vec3(v) for v in vs]
|
|
324
|
-
|
|
325
|
-
builder = wp.sim.ModelBuilder()
|
|
326
|
-
builder.add_cloth_mesh(
|
|
327
|
-
pos=wp.vec3(0.0, 200.0, 0.0),
|
|
328
|
-
rot=wp.quat_from_axis_angle(wp.vec3(1.0, 0.0, 0.0), 0.0),
|
|
329
|
-
scale=1.0,
|
|
330
|
-
vertices=vertices,
|
|
331
|
-
indices=fs,
|
|
332
|
-
vel=wp.vec3(0.0, 0.0, 0.0),
|
|
333
|
-
density=0.02,
|
|
334
|
-
tri_ke=0,
|
|
335
|
-
tri_ka=0,
|
|
336
|
-
tri_kd=0,
|
|
337
|
-
)
|
|
338
|
-
model = builder.finalize(device=device)
|
|
339
|
-
|
|
340
|
-
collision_detector = TriMeshCollisionDetector(model=model, record_triangle_contacting_vertices=True)
|
|
341
|
-
|
|
342
|
-
return model, collision_detector
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
def get_data():
|
|
346
|
-
from pxr import Usd, UsdGeom
|
|
347
|
-
|
|
348
|
-
usd_stage = Usd.Stage.Open(os.path.join(warp.examples.get_asset_directory(), "bunny.usd"))
|
|
349
|
-
usd_geom = UsdGeom.Mesh(usd_stage.GetPrimAtPath("/root/bunny"))
|
|
350
|
-
|
|
351
|
-
vertices = np.array(usd_geom.GetPointsAttr().Get())
|
|
352
|
-
faces = np.array(usd_geom.GetFaceVertexIndicesAttr().Get())
|
|
353
|
-
|
|
354
|
-
return vertices, faces
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
@unittest.skipUnless(USD_AVAILABLE, "Requires usd-core")
|
|
358
|
-
def test_vertex_triangle_collision(test, device):
|
|
359
|
-
vertices, faces = get_data()
|
|
360
|
-
|
|
361
|
-
# record triangle contacting vertices
|
|
362
|
-
model, collision_detector = init_model(vertices, faces, device, True)
|
|
363
|
-
|
|
364
|
-
rs = [1e-2, 2e-2, 5e-2, 1e-1]
|
|
365
|
-
|
|
366
|
-
for query_radius in rs:
|
|
367
|
-
collision_detector.vertex_triangle_collision_detection(query_radius)
|
|
368
|
-
vertex_colliding_triangles_count_1 = collision_detector.vertex_colliding_triangles_count.numpy()
|
|
369
|
-
vertex_min_dis_1 = collision_detector.vertex_colliding_triangles_min_dist.numpy()
|
|
370
|
-
|
|
371
|
-
triangle_colliding_vertices_count_1 = collision_detector.triangle_colliding_vertices_count.numpy()
|
|
372
|
-
triangle_min_dis_1 = collision_detector.triangle_colliding_vertices_min_dist.numpy()
|
|
373
|
-
|
|
374
|
-
wp.launch(
|
|
375
|
-
kernel=validate_vertex_collisions,
|
|
376
|
-
inputs=[
|
|
377
|
-
query_radius,
|
|
378
|
-
collision_detector.bvh_tris.id,
|
|
379
|
-
collision_detector.model.particle_q,
|
|
380
|
-
collision_detector.model.tri_indices,
|
|
381
|
-
collision_detector.vertex_colliding_triangles,
|
|
382
|
-
collision_detector.vertex_colliding_triangles_count,
|
|
383
|
-
collision_detector.vertex_colliding_triangles_offsets,
|
|
384
|
-
collision_detector.vertex_colliding_triangles_buffer_sizes,
|
|
385
|
-
collision_detector.vertex_colliding_triangles_min_dist,
|
|
386
|
-
collision_detector.resize_flags,
|
|
387
|
-
],
|
|
388
|
-
dim=model.particle_count,
|
|
389
|
-
device=device,
|
|
390
|
-
)
|
|
391
|
-
|
|
392
|
-
wp.launch(
|
|
393
|
-
kernel=validate_triangle_collisions,
|
|
394
|
-
inputs=[
|
|
395
|
-
query_radius,
|
|
396
|
-
collision_detector.bvh_tris.id,
|
|
397
|
-
collision_detector.model.particle_q,
|
|
398
|
-
collision_detector.model.tri_indices,
|
|
399
|
-
collision_detector.triangle_colliding_vertices,
|
|
400
|
-
collision_detector.triangle_colliding_vertices_count,
|
|
401
|
-
collision_detector.triangle_colliding_vertices_offsets,
|
|
402
|
-
collision_detector.triangle_colliding_vertices_buffer_sizes,
|
|
403
|
-
collision_detector.triangle_colliding_vertices_min_dist,
|
|
404
|
-
collision_detector.resize_flags,
|
|
405
|
-
],
|
|
406
|
-
dim=model.tri_count,
|
|
407
|
-
device=model.device,
|
|
408
|
-
)
|
|
409
|
-
|
|
410
|
-
wp.launch(
|
|
411
|
-
kernel=init_triangle_collision_data_kernel,
|
|
412
|
-
inputs=[
|
|
413
|
-
query_radius,
|
|
414
|
-
collision_detector.triangle_colliding_vertices_count,
|
|
415
|
-
collision_detector.triangle_colliding_vertices_min_dist,
|
|
416
|
-
collision_detector.resize_flags,
|
|
417
|
-
],
|
|
418
|
-
dim=model.tri_count,
|
|
419
|
-
device=model.device,
|
|
420
|
-
)
|
|
421
|
-
|
|
422
|
-
wp.launch(
|
|
423
|
-
kernel=vertex_triangle_collision_detection_brute_force,
|
|
424
|
-
inputs=[
|
|
425
|
-
query_radius,
|
|
426
|
-
collision_detector.bvh_tris.id,
|
|
427
|
-
collision_detector.model.particle_q,
|
|
428
|
-
collision_detector.model.tri_indices,
|
|
429
|
-
collision_detector.vertex_colliding_triangles,
|
|
430
|
-
collision_detector.vertex_colliding_triangles_count,
|
|
431
|
-
collision_detector.vertex_colliding_triangles_offsets,
|
|
432
|
-
collision_detector.vertex_colliding_triangles_buffer_sizes,
|
|
433
|
-
collision_detector.vertex_colliding_triangles_min_dist,
|
|
434
|
-
collision_detector.triangle_colliding_vertices,
|
|
435
|
-
collision_detector.triangle_colliding_vertices_count,
|
|
436
|
-
collision_detector.triangle_colliding_vertices_offsets,
|
|
437
|
-
collision_detector.triangle_colliding_vertices_buffer_sizes,
|
|
438
|
-
collision_detector.triangle_colliding_vertices_min_dist,
|
|
439
|
-
collision_detector.resize_flags,
|
|
440
|
-
],
|
|
441
|
-
dim=model.particle_count,
|
|
442
|
-
device=model.device,
|
|
443
|
-
)
|
|
444
|
-
|
|
445
|
-
vertex_colliding_triangles_count_2 = collision_detector.vertex_colliding_triangles_count.numpy()
|
|
446
|
-
vertex_min_dis_2 = collision_detector.vertex_colliding_triangles_min_dist.numpy()
|
|
447
|
-
|
|
448
|
-
triangle_colliding_vertices_count_2 = collision_detector.triangle_colliding_vertices_count.numpy()
|
|
449
|
-
triangle_min_dis_2 = collision_detector.triangle_colliding_vertices_min_dist.numpy()
|
|
450
|
-
|
|
451
|
-
assert_np_equal(vertex_colliding_triangles_count_2, vertex_colliding_triangles_count_1)
|
|
452
|
-
assert_np_equal(triangle_min_dis_2, triangle_min_dis_1)
|
|
453
|
-
assert_np_equal(triangle_colliding_vertices_count_2, triangle_colliding_vertices_count_1)
|
|
454
|
-
assert_np_equal(vertex_min_dis_2, vertex_min_dis_1)
|
|
455
|
-
|
|
456
|
-
# do not record triangle contacting vertices
|
|
457
|
-
model, collision_detector = init_model(vertices, faces, device, False)
|
|
458
|
-
|
|
459
|
-
rs = [1e-2, 2e-2, 5e-2, 1e-1]
|
|
460
|
-
|
|
461
|
-
for query_radius in rs:
|
|
462
|
-
collision_detector.vertex_triangle_collision_detection(query_radius)
|
|
463
|
-
vertex_colliding_triangles_count_1 = collision_detector.vertex_colliding_triangles_count.numpy()
|
|
464
|
-
vertex_min_dis_1 = collision_detector.vertex_colliding_triangles_min_dist.numpy()
|
|
465
|
-
|
|
466
|
-
triangle_min_dis_1 = collision_detector.triangle_colliding_vertices_min_dist.numpy()
|
|
467
|
-
|
|
468
|
-
wp.launch(
|
|
469
|
-
kernel=validate_vertex_collisions,
|
|
470
|
-
inputs=[
|
|
471
|
-
query_radius,
|
|
472
|
-
collision_detector.bvh_tris.id,
|
|
473
|
-
collision_detector.model.particle_q,
|
|
474
|
-
collision_detector.model.tri_indices,
|
|
475
|
-
collision_detector.vertex_colliding_triangles,
|
|
476
|
-
collision_detector.vertex_colliding_triangles_count,
|
|
477
|
-
collision_detector.vertex_colliding_triangles_offsets,
|
|
478
|
-
collision_detector.vertex_colliding_triangles_buffer_sizes,
|
|
479
|
-
collision_detector.vertex_colliding_triangles_min_dist,
|
|
480
|
-
collision_detector.resize_flags,
|
|
481
|
-
],
|
|
482
|
-
dim=model.particle_count,
|
|
483
|
-
device=device,
|
|
484
|
-
)
|
|
485
|
-
|
|
486
|
-
wp.launch(
|
|
487
|
-
kernel=vertex_triangle_collision_detection_brute_force_no_triangle_buffers,
|
|
488
|
-
inputs=[
|
|
489
|
-
query_radius,
|
|
490
|
-
collision_detector.bvh_tris.id,
|
|
491
|
-
collision_detector.model.particle_q,
|
|
492
|
-
collision_detector.model.tri_indices,
|
|
493
|
-
collision_detector.vertex_colliding_triangles,
|
|
494
|
-
collision_detector.vertex_colliding_triangles_count,
|
|
495
|
-
collision_detector.vertex_colliding_triangles_offsets,
|
|
496
|
-
collision_detector.vertex_colliding_triangles_buffer_sizes,
|
|
497
|
-
collision_detector.vertex_colliding_triangles_min_dist,
|
|
498
|
-
collision_detector.triangle_colliding_vertices_min_dist,
|
|
499
|
-
collision_detector.resize_flags,
|
|
500
|
-
],
|
|
501
|
-
dim=model.particle_count,
|
|
502
|
-
device=model.device,
|
|
503
|
-
)
|
|
504
|
-
|
|
505
|
-
vertex_colliding_triangles_count_2 = collision_detector.vertex_colliding_triangles_count.numpy()
|
|
506
|
-
vertex_min_dis_2 = collision_detector.vertex_colliding_triangles_min_dist.numpy()
|
|
507
|
-
triangle_min_dis_2 = collision_detector.triangle_colliding_vertices_min_dist.numpy()
|
|
508
|
-
|
|
509
|
-
assert_np_equal(vertex_colliding_triangles_count_2, vertex_colliding_triangles_count_1)
|
|
510
|
-
assert_np_equal(triangle_min_dis_2, triangle_min_dis_1)
|
|
511
|
-
assert_np_equal(vertex_min_dis_2, vertex_min_dis_1)
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
@unittest.skipUnless(USD_AVAILABLE, "Requires usd-core")
|
|
515
|
-
def test_edge_edge_collision(test, device):
|
|
516
|
-
vertices, faces = get_data()
|
|
517
|
-
|
|
518
|
-
model, collision_detector = init_model(vertices, faces, device)
|
|
519
|
-
|
|
520
|
-
rs = [1e-2, 2e-2, 5e-2, 1e-1]
|
|
521
|
-
edge_edge_parallel_epsilon = 1e-5
|
|
522
|
-
|
|
523
|
-
for query_radius in rs:
|
|
524
|
-
collision_detector.edge_edge_collision_detection(query_radius)
|
|
525
|
-
edge_colliding_edges_count_1 = collision_detector.edge_colliding_edges_count.numpy()
|
|
526
|
-
edge_min_dist_1 = collision_detector.edge_colliding_edges_min_dist.numpy()
|
|
527
|
-
|
|
528
|
-
wp.launch(
|
|
529
|
-
kernel=validate_edge_collisions,
|
|
530
|
-
inputs=[
|
|
531
|
-
query_radius,
|
|
532
|
-
collision_detector.bvh_edges.id,
|
|
533
|
-
collision_detector.model.particle_q,
|
|
534
|
-
collision_detector.model.edge_indices,
|
|
535
|
-
collision_detector.edge_colliding_edges_offsets,
|
|
536
|
-
collision_detector.edge_colliding_edges_buffer_sizes,
|
|
537
|
-
edge_edge_parallel_epsilon,
|
|
538
|
-
],
|
|
539
|
-
outputs=[
|
|
540
|
-
collision_detector.edge_colliding_edges,
|
|
541
|
-
collision_detector.edge_colliding_edges_count,
|
|
542
|
-
collision_detector.edge_colliding_edges_min_dist,
|
|
543
|
-
collision_detector.resize_flags,
|
|
544
|
-
],
|
|
545
|
-
dim=model.particle_count,
|
|
546
|
-
device=device,
|
|
547
|
-
)
|
|
548
|
-
|
|
549
|
-
wp.launch(
|
|
550
|
-
kernel=edge_edge_collision_detection_brute_force,
|
|
551
|
-
inputs=[
|
|
552
|
-
query_radius,
|
|
553
|
-
collision_detector.bvh_edges.id,
|
|
554
|
-
collision_detector.model.particle_q,
|
|
555
|
-
collision_detector.model.edge_indices,
|
|
556
|
-
collision_detector.edge_colliding_edges_offsets,
|
|
557
|
-
collision_detector.edge_colliding_edges_buffer_sizes,
|
|
558
|
-
edge_edge_parallel_epsilon,
|
|
559
|
-
],
|
|
560
|
-
outputs=[
|
|
561
|
-
collision_detector.edge_colliding_edges,
|
|
562
|
-
collision_detector.edge_colliding_edges_count,
|
|
563
|
-
collision_detector.edge_colliding_edges_min_dist,
|
|
564
|
-
collision_detector.resize_flags,
|
|
565
|
-
],
|
|
566
|
-
dim=model.edge_count,
|
|
567
|
-
device=device,
|
|
568
|
-
)
|
|
569
|
-
|
|
570
|
-
edge_colliding_edges_count_2 = collision_detector.edge_colliding_edges_count.numpy()
|
|
571
|
-
edge_min_dist_2 = collision_detector.edge_colliding_edges_min_dist.numpy()
|
|
572
|
-
|
|
573
|
-
assert_np_equal(edge_colliding_edges_count_2, edge_colliding_edges_count_1)
|
|
574
|
-
assert_np_equal(edge_min_dist_1, edge_min_dist_2)
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
def test_particle_collision(test, device):
|
|
578
|
-
with wp.ScopedDevice(device):
|
|
579
|
-
contact_radius = 1.23
|
|
580
|
-
builder1 = wp.sim.ModelBuilder()
|
|
581
|
-
builder1.add_cloth_grid(
|
|
582
|
-
pos=wp.vec3(0.0, 0.0, 0.0),
|
|
583
|
-
rot=wp.quat_identity(),
|
|
584
|
-
vel=wp.vec3(0.0, 0.0, 0.0),
|
|
585
|
-
dim_x=100,
|
|
586
|
-
dim_y=100,
|
|
587
|
-
cell_x=0.1,
|
|
588
|
-
cell_y=0.1,
|
|
589
|
-
mass=0.1,
|
|
590
|
-
particle_radius=contact_radius,
|
|
591
|
-
)
|
|
592
|
-
|
|
593
|
-
cloth_grid = builder1.finalize()
|
|
594
|
-
cloth_grid_particle_radius = cloth_grid.particle_radius.numpy()
|
|
595
|
-
assert_np_equal(cloth_grid_particle_radius, np.full(cloth_grid_particle_radius.shape, contact_radius), tol=1e-5)
|
|
596
|
-
|
|
597
|
-
vertices = [
|
|
598
|
-
[2.0, 0.0, 0.0],
|
|
599
|
-
[2.0, 2.0, 0.0],
|
|
600
|
-
[0.0, 0.0, 0.0],
|
|
601
|
-
[1.0, 0.0, 1.0],
|
|
602
|
-
[1.0, 1.0, 1.0],
|
|
603
|
-
[0.0, 0.0, 1.0],
|
|
604
|
-
]
|
|
605
|
-
vertices = [wp.vec3(v) for v in vertices]
|
|
606
|
-
faces = [0, 1, 2, 3, 4, 5]
|
|
607
|
-
|
|
608
|
-
builder2 = wp.sim.ModelBuilder()
|
|
609
|
-
builder2.add_cloth_mesh(
|
|
610
|
-
pos=wp.vec3(0.0, 0.0, 0.0),
|
|
611
|
-
rot=wp.quat_from_axis_angle(wp.vec3(1.0, 0.0, 0.0), 0.0),
|
|
612
|
-
scale=1.0,
|
|
613
|
-
vertices=vertices,
|
|
614
|
-
indices=faces,
|
|
615
|
-
tri_ke=1e4,
|
|
616
|
-
tri_ka=1e4,
|
|
617
|
-
tri_kd=1e-5,
|
|
618
|
-
edge_ke=10,
|
|
619
|
-
edge_kd=0.0,
|
|
620
|
-
vel=wp.vec3(0.0, 0.0, 0.0),
|
|
621
|
-
density=0.1,
|
|
622
|
-
particle_radius=contact_radius,
|
|
623
|
-
)
|
|
624
|
-
cloth_mesh = builder2.finalize()
|
|
625
|
-
cloth_mesh_particle_radius = cloth_mesh.particle_radius.numpy()
|
|
626
|
-
assert_np_equal(cloth_mesh_particle_radius, np.full(cloth_mesh_particle_radius.shape, contact_radius), tol=1e-5)
|
|
627
|
-
|
|
628
|
-
state = cloth_mesh.state()
|
|
629
|
-
particle_f = wp.zeros_like(state.particle_q)
|
|
630
|
-
wp.launch(
|
|
631
|
-
kernel=eval_triangles_contact,
|
|
632
|
-
dim=cloth_mesh.tri_count * cloth_mesh.particle_count,
|
|
633
|
-
inputs=[
|
|
634
|
-
cloth_mesh.particle_count,
|
|
635
|
-
state.particle_q,
|
|
636
|
-
state.particle_qd,
|
|
637
|
-
cloth_mesh.tri_indices,
|
|
638
|
-
cloth_mesh.tri_materials,
|
|
639
|
-
cloth_mesh.particle_radius,
|
|
640
|
-
],
|
|
641
|
-
outputs=[particle_f],
|
|
642
|
-
)
|
|
643
|
-
test.assertTrue((np.linalg.norm(particle_f.numpy(), axis=1) != 0).all())
|
|
644
|
-
|
|
645
|
-
builder3 = wp.sim.ModelBuilder()
|
|
646
|
-
builder3.add_cloth_mesh(
|
|
647
|
-
pos=wp.vec3(0.0, 0.0, 0.0),
|
|
648
|
-
rot=wp.quat_from_axis_angle(wp.vec3(1.0, 0.0, 0.0), 0.0),
|
|
649
|
-
scale=1.0,
|
|
650
|
-
vertices=vertices,
|
|
651
|
-
indices=faces,
|
|
652
|
-
tri_ke=1e4,
|
|
653
|
-
tri_ka=1e4,
|
|
654
|
-
tri_kd=1e-5,
|
|
655
|
-
edge_ke=10,
|
|
656
|
-
edge_kd=0.0,
|
|
657
|
-
vel=wp.vec3(0.0, 0.0, 0.0),
|
|
658
|
-
density=0.1,
|
|
659
|
-
particle_radius=0.5,
|
|
660
|
-
)
|
|
661
|
-
cloth_mesh_2 = builder3.finalize()
|
|
662
|
-
cloth_mesh_2_particle_radius = cloth_mesh_2.particle_radius.numpy()
|
|
663
|
-
assert_np_equal(cloth_mesh_2_particle_radius, np.full(cloth_mesh_2_particle_radius.shape, 0.5), tol=1e-5)
|
|
664
|
-
|
|
665
|
-
state_2 = cloth_mesh_2.state()
|
|
666
|
-
particle_f_2 = wp.zeros_like(cloth_mesh_2.particle_q)
|
|
667
|
-
wp.launch(
|
|
668
|
-
kernel=eval_triangles_contact,
|
|
669
|
-
dim=cloth_mesh_2.tri_count * cloth_mesh_2.particle_count,
|
|
670
|
-
inputs=[
|
|
671
|
-
cloth_mesh_2.particle_count,
|
|
672
|
-
state_2.particle_q,
|
|
673
|
-
state_2.particle_qd,
|
|
674
|
-
cloth_mesh_2.tri_indices,
|
|
675
|
-
cloth_mesh_2.tri_materials,
|
|
676
|
-
cloth_mesh_2.particle_radius,
|
|
677
|
-
],
|
|
678
|
-
outputs=[particle_f_2],
|
|
679
|
-
)
|
|
680
|
-
test.assertTrue((np.linalg.norm(particle_f_2.numpy(), axis=1) == 0).all())
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
def test_mesh_ground_collision_index(test, device):
|
|
684
|
-
# create a mesh with 1 triangle for testing
|
|
685
|
-
vertices = np.array(
|
|
686
|
-
[
|
|
687
|
-
[0.0, 0.0, 0.0],
|
|
688
|
-
[1.0, 1.0, 0.0],
|
|
689
|
-
[0.5, 2.0, 0.0],
|
|
690
|
-
]
|
|
691
|
-
)
|
|
692
|
-
mesh = wp.sim.Mesh(vertices=vertices, indices=[0, 1, 2])
|
|
693
|
-
builder = wp.sim.ModelBuilder()
|
|
694
|
-
# create body with nonzero mass to ensure it is not static
|
|
695
|
-
# and contact points will be computed
|
|
696
|
-
b = builder.add_body(m=1.0)
|
|
697
|
-
builder.add_shape_mesh(
|
|
698
|
-
body=b,
|
|
699
|
-
mesh=mesh,
|
|
700
|
-
has_shape_collision=False,
|
|
701
|
-
)
|
|
702
|
-
# add another mesh that is not in contact
|
|
703
|
-
b2 = builder.add_body(m=1.0, origin=wp.transform((0.0, 3.0, 0.0), wp.quat_identity()))
|
|
704
|
-
builder.add_shape_mesh(
|
|
705
|
-
body=b2,
|
|
706
|
-
mesh=mesh,
|
|
707
|
-
has_shape_collision=False,
|
|
708
|
-
)
|
|
709
|
-
model = builder.finalize(device=device)
|
|
710
|
-
test.assertEqual(model.rigid_contact_max, 6)
|
|
711
|
-
test.assertEqual(model.shape_contact_pair_count, 0)
|
|
712
|
-
test.assertEqual(model.shape_ground_contact_pair_count, 2)
|
|
713
|
-
model.ground = True
|
|
714
|
-
# ensure all the mesh vertices will be within the contact margin
|
|
715
|
-
model.rigid_contact_margin = 2.0
|
|
716
|
-
state = model.state()
|
|
717
|
-
wp.sim.collide(model, state)
|
|
718
|
-
test.assertEqual(model.rigid_contact_count.numpy()[0], 3)
|
|
719
|
-
tids = model.rigid_contact_tids.list()
|
|
720
|
-
test.assertEqual(sorted(tids), [-1, -1, -1, 0, 1, 2])
|
|
721
|
-
tids = [t for t in tids if t != -1]
|
|
722
|
-
# retrieve the mesh vertices from the contact thread indices
|
|
723
|
-
assert_np_equal(model.rigid_contact_point0.numpy()[:3], vertices[tids])
|
|
724
|
-
assert_np_equal(model.rigid_contact_point1.numpy()[:3, 0], vertices[tids, 0])
|
|
725
|
-
assert_np_equal(model.rigid_contact_point1.numpy()[:3, 1:], np.zeros((3, 2)))
|
|
726
|
-
assert_np_equal(model.rigid_contact_normal.numpy()[:3], np.tile([0.0, 1.0, 0.0], (3, 1)))
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
devices = get_test_devices(mode="basic")
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
class TestCollision(unittest.TestCase):
|
|
733
|
-
pass
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
add_function_test(TestCollision, "test_vertex_triangle_collision", test_vertex_triangle_collision, devices=devices)
|
|
737
|
-
add_function_test(TestCollision, "test_edge_edge_collision", test_edge_edge_collision, devices=devices)
|
|
738
|
-
add_function_test(TestCollision, "test_particle_collision", test_particle_collision, devices=devices)
|
|
739
|
-
add_function_test(TestCollision, "test_mesh_ground_collision_index", test_mesh_ground_collision_index, devices=devices)
|
|
740
|
-
|
|
741
|
-
if __name__ == "__main__":
|
|
742
|
-
wp.clear_kernel_cache()
|
|
743
|
-
unittest.main(verbosity=2, failfast=True)
|