warp-lang 1.7.0__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 +139 -0
- warp/__init__.pyi +1 -0
- warp/autograd.py +1142 -0
- warp/bin/warp-clang.so +0 -0
- warp/bin/warp.so +0 -0
- warp/build.py +557 -0
- warp/build_dll.py +405 -0
- warp/builtins.py +6855 -0
- warp/codegen.py +3969 -0
- warp/config.py +158 -0
- warp/constants.py +57 -0
- warp/context.py +6812 -0
- warp/dlpack.py +462 -0
- warp/examples/__init__.py +24 -0
- warp/examples/assets/bear.usd +0 -0
- warp/examples/assets/bunny.usd +0 -0
- warp/examples/assets/cartpole.urdf +110 -0
- warp/examples/assets/crazyflie.usd +0 -0
- warp/examples/assets/cube.usd +0 -0
- warp/examples/assets/nonuniform.usd +0 -0
- warp/examples/assets/nv_ant.xml +92 -0
- warp/examples/assets/nv_humanoid.xml +183 -0
- warp/examples/assets/nvidia_logo.png +0 -0
- warp/examples/assets/pixel.jpg +0 -0
- warp/examples/assets/quadruped.urdf +268 -0
- warp/examples/assets/rocks.nvdb +0 -0
- warp/examples/assets/rocks.usd +0 -0
- warp/examples/assets/sphere.usd +0 -0
- warp/examples/assets/square_cloth.usd +0 -0
- warp/examples/benchmarks/benchmark_api.py +389 -0
- warp/examples/benchmarks/benchmark_cloth.py +296 -0
- warp/examples/benchmarks/benchmark_cloth_cupy.py +96 -0
- warp/examples/benchmarks/benchmark_cloth_jax.py +105 -0
- warp/examples/benchmarks/benchmark_cloth_numba.py +161 -0
- warp/examples/benchmarks/benchmark_cloth_numpy.py +85 -0
- warp/examples/benchmarks/benchmark_cloth_paddle.py +94 -0
- warp/examples/benchmarks/benchmark_cloth_pytorch.py +94 -0
- warp/examples/benchmarks/benchmark_cloth_taichi.py +120 -0
- warp/examples/benchmarks/benchmark_cloth_warp.py +153 -0
- warp/examples/benchmarks/benchmark_gemm.py +164 -0
- warp/examples/benchmarks/benchmark_interop_paddle.py +166 -0
- warp/examples/benchmarks/benchmark_interop_torch.py +166 -0
- warp/examples/benchmarks/benchmark_launches.py +301 -0
- warp/examples/benchmarks/benchmark_tile_load_store.py +103 -0
- warp/examples/browse.py +37 -0
- warp/examples/core/example_cupy.py +86 -0
- warp/examples/core/example_dem.py +241 -0
- warp/examples/core/example_fluid.py +299 -0
- warp/examples/core/example_graph_capture.py +150 -0
- warp/examples/core/example_marching_cubes.py +194 -0
- warp/examples/core/example_mesh.py +180 -0
- warp/examples/core/example_mesh_intersect.py +211 -0
- warp/examples/core/example_nvdb.py +182 -0
- warp/examples/core/example_raycast.py +111 -0
- warp/examples/core/example_raymarch.py +205 -0
- warp/examples/core/example_render_opengl.py +193 -0
- warp/examples/core/example_sample_mesh.py +300 -0
- warp/examples/core/example_sph.py +411 -0
- warp/examples/core/example_torch.py +211 -0
- warp/examples/core/example_wave.py +269 -0
- warp/examples/fem/example_adaptive_grid.py +286 -0
- warp/examples/fem/example_apic_fluid.py +423 -0
- warp/examples/fem/example_burgers.py +261 -0
- warp/examples/fem/example_convection_diffusion.py +178 -0
- warp/examples/fem/example_convection_diffusion_dg.py +204 -0
- warp/examples/fem/example_deformed_geometry.py +172 -0
- warp/examples/fem/example_diffusion.py +196 -0
- warp/examples/fem/example_diffusion_3d.py +225 -0
- warp/examples/fem/example_diffusion_mgpu.py +220 -0
- warp/examples/fem/example_distortion_energy.py +228 -0
- warp/examples/fem/example_magnetostatics.py +240 -0
- warp/examples/fem/example_mixed_elasticity.py +291 -0
- warp/examples/fem/example_navier_stokes.py +261 -0
- warp/examples/fem/example_nonconforming_contact.py +298 -0
- warp/examples/fem/example_stokes.py +213 -0
- warp/examples/fem/example_stokes_transfer.py +262 -0
- warp/examples/fem/example_streamlines.py +352 -0
- warp/examples/fem/utils.py +1000 -0
- warp/examples/interop/example_jax_callable.py +116 -0
- warp/examples/interop/example_jax_ffi_callback.py +132 -0
- warp/examples/interop/example_jax_kernel.py +205 -0
- warp/examples/optim/example_bounce.py +266 -0
- warp/examples/optim/example_cloth_throw.py +228 -0
- warp/examples/optim/example_diffray.py +561 -0
- warp/examples/optim/example_drone.py +870 -0
- warp/examples/optim/example_fluid_checkpoint.py +497 -0
- warp/examples/optim/example_inverse_kinematics.py +182 -0
- warp/examples/optim/example_inverse_kinematics_torch.py +191 -0
- warp/examples/optim/example_softbody_properties.py +400 -0
- warp/examples/optim/example_spring_cage.py +245 -0
- warp/examples/optim/example_trajectory.py +227 -0
- warp/examples/sim/example_cartpole.py +143 -0
- warp/examples/sim/example_cloth.py +225 -0
- warp/examples/sim/example_cloth_self_contact.py +322 -0
- warp/examples/sim/example_granular.py +130 -0
- warp/examples/sim/example_granular_collision_sdf.py +202 -0
- warp/examples/sim/example_jacobian_ik.py +244 -0
- warp/examples/sim/example_particle_chain.py +124 -0
- warp/examples/sim/example_quadruped.py +203 -0
- warp/examples/sim/example_rigid_chain.py +203 -0
- warp/examples/sim/example_rigid_contact.py +195 -0
- warp/examples/sim/example_rigid_force.py +133 -0
- warp/examples/sim/example_rigid_gyroscopic.py +115 -0
- warp/examples/sim/example_rigid_soft_contact.py +140 -0
- warp/examples/sim/example_soft_body.py +196 -0
- warp/examples/tile/example_tile_cholesky.py +87 -0
- warp/examples/tile/example_tile_convolution.py +66 -0
- warp/examples/tile/example_tile_fft.py +55 -0
- warp/examples/tile/example_tile_filtering.py +113 -0
- warp/examples/tile/example_tile_matmul.py +85 -0
- warp/examples/tile/example_tile_mlp.py +383 -0
- warp/examples/tile/example_tile_nbody.py +199 -0
- warp/examples/tile/example_tile_walker.py +327 -0
- warp/fabric.py +355 -0
- warp/fem/__init__.py +106 -0
- warp/fem/adaptivity.py +508 -0
- warp/fem/cache.py +572 -0
- warp/fem/dirichlet.py +202 -0
- warp/fem/domain.py +411 -0
- warp/fem/field/__init__.py +125 -0
- warp/fem/field/field.py +619 -0
- warp/fem/field/nodal_field.py +326 -0
- warp/fem/field/restriction.py +37 -0
- warp/fem/field/virtual.py +848 -0
- warp/fem/geometry/__init__.py +32 -0
- warp/fem/geometry/adaptive_nanogrid.py +857 -0
- warp/fem/geometry/closest_point.py +84 -0
- warp/fem/geometry/deformed_geometry.py +221 -0
- warp/fem/geometry/element.py +776 -0
- warp/fem/geometry/geometry.py +362 -0
- warp/fem/geometry/grid_2d.py +392 -0
- warp/fem/geometry/grid_3d.py +452 -0
- warp/fem/geometry/hexmesh.py +911 -0
- warp/fem/geometry/nanogrid.py +571 -0
- warp/fem/geometry/partition.py +389 -0
- warp/fem/geometry/quadmesh.py +663 -0
- warp/fem/geometry/tetmesh.py +855 -0
- warp/fem/geometry/trimesh.py +806 -0
- warp/fem/integrate.py +2335 -0
- warp/fem/linalg.py +419 -0
- warp/fem/operator.py +293 -0
- warp/fem/polynomial.py +229 -0
- warp/fem/quadrature/__init__.py +17 -0
- warp/fem/quadrature/pic_quadrature.py +299 -0
- warp/fem/quadrature/quadrature.py +591 -0
- warp/fem/space/__init__.py +228 -0
- warp/fem/space/basis_function_space.py +468 -0
- warp/fem/space/basis_space.py +667 -0
- warp/fem/space/dof_mapper.py +251 -0
- warp/fem/space/function_space.py +309 -0
- warp/fem/space/grid_2d_function_space.py +177 -0
- warp/fem/space/grid_3d_function_space.py +227 -0
- warp/fem/space/hexmesh_function_space.py +257 -0
- warp/fem/space/nanogrid_function_space.py +201 -0
- warp/fem/space/partition.py +367 -0
- warp/fem/space/quadmesh_function_space.py +223 -0
- warp/fem/space/restriction.py +179 -0
- warp/fem/space/shape/__init__.py +143 -0
- warp/fem/space/shape/cube_shape_function.py +1105 -0
- warp/fem/space/shape/shape_function.py +133 -0
- warp/fem/space/shape/square_shape_function.py +926 -0
- warp/fem/space/shape/tet_shape_function.py +834 -0
- warp/fem/space/shape/triangle_shape_function.py +672 -0
- warp/fem/space/tetmesh_function_space.py +271 -0
- warp/fem/space/topology.py +424 -0
- warp/fem/space/trimesh_function_space.py +194 -0
- warp/fem/types.py +99 -0
- warp/fem/utils.py +420 -0
- warp/jax.py +187 -0
- warp/jax_experimental/__init__.py +16 -0
- warp/jax_experimental/custom_call.py +351 -0
- warp/jax_experimental/ffi.py +698 -0
- warp/jax_experimental/xla_ffi.py +602 -0
- warp/math.py +244 -0
- warp/native/array.h +1145 -0
- warp/native/builtin.h +1800 -0
- warp/native/bvh.cpp +492 -0
- warp/native/bvh.cu +791 -0
- warp/native/bvh.h +554 -0
- warp/native/clang/clang.cpp +536 -0
- warp/native/coloring.cpp +613 -0
- warp/native/crt.cpp +51 -0
- warp/native/crt.h +362 -0
- warp/native/cuda_crt.h +1058 -0
- warp/native/cuda_util.cpp +646 -0
- warp/native/cuda_util.h +307 -0
- warp/native/error.cpp +77 -0
- warp/native/error.h +36 -0
- warp/native/exports.h +1878 -0
- warp/native/fabric.h +245 -0
- warp/native/hashgrid.cpp +311 -0
- warp/native/hashgrid.cu +87 -0
- warp/native/hashgrid.h +240 -0
- warp/native/initializer_array.h +41 -0
- warp/native/intersect.h +1230 -0
- warp/native/intersect_adj.h +375 -0
- warp/native/intersect_tri.h +339 -0
- warp/native/marching.cpp +19 -0
- warp/native/marching.cu +514 -0
- warp/native/marching.h +19 -0
- warp/native/mat.h +2220 -0
- warp/native/mathdx.cpp +87 -0
- warp/native/matnn.h +343 -0
- warp/native/mesh.cpp +266 -0
- warp/native/mesh.cu +404 -0
- warp/native/mesh.h +1980 -0
- warp/native/nanovdb/GridHandle.h +366 -0
- warp/native/nanovdb/HostBuffer.h +590 -0
- warp/native/nanovdb/NanoVDB.h +6624 -0
- warp/native/nanovdb/PNanoVDB.h +3390 -0
- warp/native/noise.h +859 -0
- warp/native/quat.h +1371 -0
- warp/native/rand.h +342 -0
- warp/native/range.h +139 -0
- warp/native/reduce.cpp +174 -0
- warp/native/reduce.cu +364 -0
- warp/native/runlength_encode.cpp +79 -0
- warp/native/runlength_encode.cu +61 -0
- warp/native/scan.cpp +47 -0
- warp/native/scan.cu +53 -0
- warp/native/scan.h +23 -0
- warp/native/solid_angle.h +466 -0
- warp/native/sort.cpp +251 -0
- warp/native/sort.cu +277 -0
- warp/native/sort.h +33 -0
- warp/native/sparse.cpp +378 -0
- warp/native/sparse.cu +524 -0
- warp/native/spatial.h +657 -0
- warp/native/svd.h +702 -0
- warp/native/temp_buffer.h +46 -0
- warp/native/tile.h +2584 -0
- warp/native/tile_reduce.h +264 -0
- warp/native/vec.h +1426 -0
- warp/native/volume.cpp +501 -0
- warp/native/volume.cu +67 -0
- warp/native/volume.h +969 -0
- warp/native/volume_builder.cu +477 -0
- warp/native/volume_builder.h +52 -0
- warp/native/volume_impl.h +70 -0
- warp/native/warp.cpp +1082 -0
- warp/native/warp.cu +3636 -0
- warp/native/warp.h +381 -0
- warp/optim/__init__.py +17 -0
- warp/optim/adam.py +163 -0
- warp/optim/linear.py +1137 -0
- warp/optim/sgd.py +112 -0
- warp/paddle.py +407 -0
- warp/render/__init__.py +18 -0
- warp/render/render_opengl.py +3518 -0
- warp/render/render_usd.py +784 -0
- warp/render/utils.py +160 -0
- warp/sim/__init__.py +65 -0
- warp/sim/articulation.py +793 -0
- warp/sim/collide.py +2395 -0
- warp/sim/graph_coloring.py +300 -0
- warp/sim/import_mjcf.py +790 -0
- warp/sim/import_snu.py +227 -0
- warp/sim/import_urdf.py +579 -0
- warp/sim/import_usd.py +894 -0
- warp/sim/inertia.py +324 -0
- warp/sim/integrator.py +242 -0
- warp/sim/integrator_euler.py +1997 -0
- warp/sim/integrator_featherstone.py +2101 -0
- warp/sim/integrator_vbd.py +2048 -0
- warp/sim/integrator_xpbd.py +3292 -0
- warp/sim/model.py +4791 -0
- warp/sim/particles.py +121 -0
- warp/sim/render.py +427 -0
- warp/sim/utils.py +428 -0
- warp/sparse.py +2057 -0
- warp/stubs.py +3333 -0
- warp/tape.py +1203 -0
- warp/tests/__init__.py +1 -0
- warp/tests/__main__.py +4 -0
- warp/tests/assets/curlnoise_golden.npy +0 -0
- warp/tests/assets/mlp_golden.npy +0 -0
- warp/tests/assets/pixel.npy +0 -0
- warp/tests/assets/pnoise_golden.npy +0 -0
- warp/tests/assets/spiky.usd +0 -0
- warp/tests/assets/test_grid.nvdb +0 -0
- warp/tests/assets/test_index_grid.nvdb +0 -0
- warp/tests/assets/test_int32_grid.nvdb +0 -0
- warp/tests/assets/test_vec_grid.nvdb +0 -0
- warp/tests/assets/torus.nvdb +0 -0
- warp/tests/assets/torus.usda +105 -0
- warp/tests/aux_test_class_kernel.py +34 -0
- warp/tests/aux_test_compile_consts_dummy.py +18 -0
- warp/tests/aux_test_conditional_unequal_types_kernels.py +29 -0
- warp/tests/aux_test_dependent.py +29 -0
- warp/tests/aux_test_grad_customs.py +29 -0
- warp/tests/aux_test_instancing_gc.py +26 -0
- warp/tests/aux_test_module_unload.py +23 -0
- warp/tests/aux_test_name_clash1.py +40 -0
- warp/tests/aux_test_name_clash2.py +40 -0
- warp/tests/aux_test_reference.py +9 -0
- warp/tests/aux_test_reference_reference.py +8 -0
- warp/tests/aux_test_square.py +16 -0
- warp/tests/aux_test_unresolved_func.py +22 -0
- warp/tests/aux_test_unresolved_symbol.py +22 -0
- warp/tests/cuda/__init__.py +0 -0
- warp/tests/cuda/test_async.py +676 -0
- warp/tests/cuda/test_ipc.py +124 -0
- warp/tests/cuda/test_mempool.py +233 -0
- warp/tests/cuda/test_multigpu.py +169 -0
- warp/tests/cuda/test_peer.py +139 -0
- warp/tests/cuda/test_pinned.py +84 -0
- warp/tests/cuda/test_streams.py +634 -0
- warp/tests/geometry/__init__.py +0 -0
- warp/tests/geometry/test_bvh.py +200 -0
- warp/tests/geometry/test_hash_grid.py +221 -0
- warp/tests/geometry/test_marching_cubes.py +74 -0
- warp/tests/geometry/test_mesh.py +316 -0
- warp/tests/geometry/test_mesh_query_aabb.py +399 -0
- warp/tests/geometry/test_mesh_query_point.py +932 -0
- warp/tests/geometry/test_mesh_query_ray.py +311 -0
- warp/tests/geometry/test_volume.py +1103 -0
- warp/tests/geometry/test_volume_write.py +346 -0
- warp/tests/interop/__init__.py +0 -0
- warp/tests/interop/test_dlpack.py +729 -0
- warp/tests/interop/test_jax.py +371 -0
- warp/tests/interop/test_paddle.py +800 -0
- warp/tests/interop/test_torch.py +1001 -0
- warp/tests/run_coverage_serial.py +39 -0
- warp/tests/sim/__init__.py +0 -0
- warp/tests/sim/disabled_kinematics.py +244 -0
- warp/tests/sim/flaky_test_sim_grad.py +290 -0
- warp/tests/sim/test_collision.py +604 -0
- warp/tests/sim/test_coloring.py +258 -0
- warp/tests/sim/test_model.py +224 -0
- warp/tests/sim/test_sim_grad_bounce_linear.py +212 -0
- warp/tests/sim/test_sim_kinematics.py +98 -0
- warp/tests/sim/test_vbd.py +597 -0
- warp/tests/test_adam.py +163 -0
- warp/tests/test_arithmetic.py +1096 -0
- warp/tests/test_array.py +2972 -0
- warp/tests/test_array_reduce.py +156 -0
- warp/tests/test_assert.py +250 -0
- warp/tests/test_atomic.py +153 -0
- warp/tests/test_bool.py +220 -0
- warp/tests/test_builtins_resolution.py +1298 -0
- warp/tests/test_closest_point_edge_edge.py +327 -0
- warp/tests/test_codegen.py +810 -0
- warp/tests/test_codegen_instancing.py +1495 -0
- warp/tests/test_compile_consts.py +215 -0
- warp/tests/test_conditional.py +252 -0
- warp/tests/test_context.py +42 -0
- warp/tests/test_copy.py +238 -0
- warp/tests/test_ctypes.py +638 -0
- warp/tests/test_dense.py +73 -0
- warp/tests/test_devices.py +97 -0
- warp/tests/test_examples.py +482 -0
- warp/tests/test_fabricarray.py +996 -0
- warp/tests/test_fast_math.py +74 -0
- warp/tests/test_fem.py +2003 -0
- warp/tests/test_fp16.py +136 -0
- warp/tests/test_func.py +454 -0
- warp/tests/test_future_annotations.py +98 -0
- warp/tests/test_generics.py +656 -0
- warp/tests/test_grad.py +893 -0
- warp/tests/test_grad_customs.py +339 -0
- warp/tests/test_grad_debug.py +341 -0
- warp/tests/test_implicit_init.py +411 -0
- warp/tests/test_import.py +45 -0
- warp/tests/test_indexedarray.py +1140 -0
- warp/tests/test_intersect.py +73 -0
- warp/tests/test_iter.py +76 -0
- warp/tests/test_large.py +177 -0
- warp/tests/test_launch.py +411 -0
- warp/tests/test_lerp.py +151 -0
- warp/tests/test_linear_solvers.py +193 -0
- warp/tests/test_lvalue.py +427 -0
- warp/tests/test_mat.py +2089 -0
- warp/tests/test_mat_lite.py +122 -0
- warp/tests/test_mat_scalar_ops.py +2913 -0
- warp/tests/test_math.py +178 -0
- warp/tests/test_mlp.py +282 -0
- warp/tests/test_module_hashing.py +258 -0
- warp/tests/test_modules_lite.py +44 -0
- warp/tests/test_noise.py +252 -0
- warp/tests/test_operators.py +299 -0
- warp/tests/test_options.py +129 -0
- warp/tests/test_overwrite.py +551 -0
- warp/tests/test_print.py +339 -0
- warp/tests/test_quat.py +2315 -0
- warp/tests/test_rand.py +339 -0
- warp/tests/test_reload.py +302 -0
- warp/tests/test_rounding.py +185 -0
- warp/tests/test_runlength_encode.py +196 -0
- warp/tests/test_scalar_ops.py +105 -0
- warp/tests/test_smoothstep.py +108 -0
- warp/tests/test_snippet.py +318 -0
- warp/tests/test_sparse.py +582 -0
- warp/tests/test_spatial.py +2229 -0
- warp/tests/test_special_values.py +361 -0
- warp/tests/test_static.py +592 -0
- warp/tests/test_struct.py +734 -0
- warp/tests/test_tape.py +204 -0
- warp/tests/test_transient_module.py +93 -0
- warp/tests/test_triangle_closest_point.py +145 -0
- warp/tests/test_types.py +562 -0
- warp/tests/test_utils.py +588 -0
- warp/tests/test_vec.py +1487 -0
- warp/tests/test_vec_lite.py +80 -0
- warp/tests/test_vec_scalar_ops.py +2327 -0
- warp/tests/test_verify_fp.py +100 -0
- warp/tests/tile/__init__.py +0 -0
- warp/tests/tile/test_tile.py +780 -0
- warp/tests/tile/test_tile_load.py +407 -0
- warp/tests/tile/test_tile_mathdx.py +208 -0
- warp/tests/tile/test_tile_mlp.py +402 -0
- warp/tests/tile/test_tile_reduce.py +447 -0
- warp/tests/tile/test_tile_shared_memory.py +247 -0
- warp/tests/tile/test_tile_view.py +173 -0
- warp/tests/unittest_serial.py +47 -0
- warp/tests/unittest_suites.py +427 -0
- warp/tests/unittest_utils.py +468 -0
- warp/tests/walkthrough_debug.py +93 -0
- warp/thirdparty/__init__.py +0 -0
- warp/thirdparty/appdirs.py +598 -0
- warp/thirdparty/dlpack.py +145 -0
- warp/thirdparty/unittest_parallel.py +570 -0
- warp/torch.py +391 -0
- warp/types.py +5230 -0
- warp/utils.py +1137 -0
- warp_lang-1.7.0.dist-info/METADATA +516 -0
- warp_lang-1.7.0.dist-info/RECORD +429 -0
- warp_lang-1.7.0.dist-info/WHEEL +5 -0
- warp_lang-1.7.0.dist-info/licenses/LICENSE.md +202 -0
- warp_lang-1.7.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: Copyright (c) 2023 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 numpy as np
|
|
19
|
+
|
|
20
|
+
import warp as wp
|
|
21
|
+
from warp.tests.unittest_utils import *
|
|
22
|
+
|
|
23
|
+
# fmt: off
|
|
24
|
+
|
|
25
|
+
POINT_POSITIONS = (
|
|
26
|
+
( 0.5, -0.5, 0.5),
|
|
27
|
+
(-0.5, -0.5, 0.5),
|
|
28
|
+
( 0.5, 0.5, 0.5),
|
|
29
|
+
(-0.5, 0.5, 0.5),
|
|
30
|
+
(-0.5, -0.5, -0.5),
|
|
31
|
+
( 0.5, -0.5, -0.5),
|
|
32
|
+
(-0.5, 0.5, -0.5),
|
|
33
|
+
( 0.5, 0.5, -0.5),
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
# Right-hand winding order. This corresponds to USD's (and others).
|
|
37
|
+
RIGHT_HANDED_FACE_VERTEX_INDICES = (
|
|
38
|
+
0, 3, 1,
|
|
39
|
+
0, 2, 3,
|
|
40
|
+
4, 7, 5,
|
|
41
|
+
4, 6, 7,
|
|
42
|
+
6, 2, 7,
|
|
43
|
+
6, 3, 2,
|
|
44
|
+
5, 1, 4,
|
|
45
|
+
5, 0, 1,
|
|
46
|
+
5, 2, 0,
|
|
47
|
+
5, 7, 2,
|
|
48
|
+
1, 6, 4,
|
|
49
|
+
1, 3, 6,
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
# Left-hand winding order. This corresponds to Houdini's (and others).
|
|
54
|
+
LEFT_HANDED_FACE_VERTEX_INDICES = (
|
|
55
|
+
0, 1, 3,
|
|
56
|
+
0, 3, 2,
|
|
57
|
+
4, 5, 7,
|
|
58
|
+
4, 7, 6,
|
|
59
|
+
6, 7, 2,
|
|
60
|
+
6, 2, 3,
|
|
61
|
+
5, 4, 1,
|
|
62
|
+
5, 1, 0,
|
|
63
|
+
5, 0, 2,
|
|
64
|
+
5, 2, 7,
|
|
65
|
+
1, 4, 6,
|
|
66
|
+
1, 6, 3,
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
# fmt: on
|
|
70
|
+
|
|
71
|
+
POINT_COUNT = 8
|
|
72
|
+
VERTEX_COUNT = 36
|
|
73
|
+
FACE_COUNT = 12
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
@wp.kernel(enable_backward=False)
|
|
77
|
+
def read_points_kernel(
|
|
78
|
+
mesh_id: wp.uint64,
|
|
79
|
+
out_points: wp.array(dtype=wp.vec3),
|
|
80
|
+
):
|
|
81
|
+
tid = wp.tid()
|
|
82
|
+
mesh = wp.mesh_get(mesh_id)
|
|
83
|
+
out_points[tid] = mesh.points[tid]
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
@wp.kernel(enable_backward=False)
|
|
87
|
+
def read_indices_kernel(
|
|
88
|
+
mesh_id: wp.uint64,
|
|
89
|
+
out_indices: wp.array(dtype=int),
|
|
90
|
+
):
|
|
91
|
+
tid = wp.tid()
|
|
92
|
+
mesh = wp.mesh_get(mesh_id)
|
|
93
|
+
out_indices[tid * 3 + 0] = mesh.indices[tid * 3 + 0]
|
|
94
|
+
out_indices[tid * 3 + 1] = mesh.indices[tid * 3 + 1]
|
|
95
|
+
out_indices[tid * 3 + 2] = mesh.indices[tid * 3 + 2]
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def test_mesh_read_properties(test, device):
|
|
99
|
+
if device.is_cpu:
|
|
100
|
+
constructors = ["sah", "median"]
|
|
101
|
+
else:
|
|
102
|
+
constructors = ["sah", "median", "lbvh"]
|
|
103
|
+
|
|
104
|
+
for constructor in constructors:
|
|
105
|
+
points = wp.array(POINT_POSITIONS, dtype=wp.vec3, device=device)
|
|
106
|
+
indices = wp.array(RIGHT_HANDED_FACE_VERTEX_INDICES, dtype=int, device=device)
|
|
107
|
+
mesh = wp.Mesh(points=points, indices=indices, bvh_constructor=constructor)
|
|
108
|
+
|
|
109
|
+
assert mesh.points.size == POINT_COUNT
|
|
110
|
+
assert mesh.indices.size == VERTEX_COUNT
|
|
111
|
+
assert int(mesh.indices.size / 3) == FACE_COUNT
|
|
112
|
+
|
|
113
|
+
out_points = wp.empty(POINT_COUNT, dtype=wp.vec3, device=device)
|
|
114
|
+
wp.launch(read_points_kernel, dim=POINT_COUNT, inputs=[mesh.id], outputs=[out_points], device=device)
|
|
115
|
+
assert_np_equal(out_points.numpy(), np.array(POINT_POSITIONS))
|
|
116
|
+
|
|
117
|
+
out_indices = wp.empty(VERTEX_COUNT, dtype=int, device=device)
|
|
118
|
+
wp.launch(read_indices_kernel, dim=FACE_COUNT, inputs=[mesh.id], outputs=[out_indices], device=device)
|
|
119
|
+
assert_np_equal(out_indices.numpy(), np.array(RIGHT_HANDED_FACE_VERTEX_INDICES))
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
@wp.kernel(enable_backward=False)
|
|
123
|
+
def query_point_kernel(
|
|
124
|
+
mesh_id: wp.uint64,
|
|
125
|
+
expected_sign: float,
|
|
126
|
+
):
|
|
127
|
+
point = wp.vec3(0.1, 0.2, 0.3)
|
|
128
|
+
expected_pos = wp.vec3(0.1, 0.2, 0.5)
|
|
129
|
+
|
|
130
|
+
sign = float(0.0)
|
|
131
|
+
face = int(0)
|
|
132
|
+
bary_u = float(0.0)
|
|
133
|
+
bary_v = float(0.0)
|
|
134
|
+
|
|
135
|
+
wp.mesh_query_point(mesh_id, point, 1e6, sign, face, bary_u, bary_v)
|
|
136
|
+
pos = wp.mesh_eval_position(mesh_id, face, bary_u, bary_v)
|
|
137
|
+
|
|
138
|
+
wp.expect_eq(wp.sign(sign), expected_sign)
|
|
139
|
+
wp.expect_eq(face, 1)
|
|
140
|
+
wp.expect_near(wp.length(pos - expected_pos), 0.0)
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def test_mesh_query_point(test, device):
|
|
144
|
+
if device.is_cpu:
|
|
145
|
+
constructors = ["sah", "median"]
|
|
146
|
+
else:
|
|
147
|
+
constructors = ["sah", "median", "lbvh"]
|
|
148
|
+
|
|
149
|
+
for constructor in constructors:
|
|
150
|
+
points = wp.array(POINT_POSITIONS, dtype=wp.vec3, device=device)
|
|
151
|
+
|
|
152
|
+
indices = wp.array(RIGHT_HANDED_FACE_VERTEX_INDICES, dtype=int, device=device)
|
|
153
|
+
mesh = wp.Mesh(points=points, indices=indices, bvh_constructor=constructor)
|
|
154
|
+
expected_sign = -1.0
|
|
155
|
+
wp.launch(query_point_kernel, dim=1, inputs=[mesh.id, expected_sign], device=device)
|
|
156
|
+
|
|
157
|
+
indices = wp.array(LEFT_HANDED_FACE_VERTEX_INDICES, dtype=int, device=device)
|
|
158
|
+
mesh = wp.Mesh(points=points, indices=indices)
|
|
159
|
+
expected_sign = 1.0
|
|
160
|
+
wp.launch(query_point_kernel, dim=1, inputs=[mesh.id, expected_sign], device=device)
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
@wp.kernel(enable_backward=False)
|
|
164
|
+
def query_ray_kernel(
|
|
165
|
+
mesh_id: wp.uint64,
|
|
166
|
+
expected_sign: float,
|
|
167
|
+
):
|
|
168
|
+
start = wp.vec3(0.1, 0.2, 0.3)
|
|
169
|
+
dir = wp.normalize(wp.vec3(-1.2, 2.3, -3.4))
|
|
170
|
+
expected_t = 0.557828
|
|
171
|
+
expected_pos = wp.vec3(-0.0565217, 0.5, -0.143478)
|
|
172
|
+
|
|
173
|
+
t = float(0.0)
|
|
174
|
+
bary_u = float(0.0)
|
|
175
|
+
bary_v = float(0.0)
|
|
176
|
+
sign = float(0.0)
|
|
177
|
+
normal = wp.vec3(0.0, 0.0, 0.0)
|
|
178
|
+
face = int(0)
|
|
179
|
+
|
|
180
|
+
wp.mesh_query_ray(
|
|
181
|
+
mesh_id,
|
|
182
|
+
start,
|
|
183
|
+
dir,
|
|
184
|
+
1e6,
|
|
185
|
+
t,
|
|
186
|
+
bary_u,
|
|
187
|
+
bary_v,
|
|
188
|
+
sign,
|
|
189
|
+
normal,
|
|
190
|
+
face,
|
|
191
|
+
)
|
|
192
|
+
pos = wp.mesh_eval_position(mesh_id, face, bary_u, bary_v)
|
|
193
|
+
|
|
194
|
+
wp.expect_near(t, expected_t)
|
|
195
|
+
wp.expect_near(t, wp.length(pos - start), 1e-6)
|
|
196
|
+
wp.expect_eq(wp.sign(sign), expected_sign)
|
|
197
|
+
wp.expect_eq(face, 4)
|
|
198
|
+
wp.expect_near(wp.length(pos - expected_pos), 0.0, 1e-6)
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
def test_mesh_query_ray(test, device):
|
|
202
|
+
if device.is_cpu:
|
|
203
|
+
constructors = ["sah", "median"]
|
|
204
|
+
else:
|
|
205
|
+
constructors = ["sah", "median", "lbvh"]
|
|
206
|
+
|
|
207
|
+
for constructor in constructors:
|
|
208
|
+
points = wp.array(POINT_POSITIONS, dtype=wp.vec3, device=device)
|
|
209
|
+
|
|
210
|
+
indices = wp.array(RIGHT_HANDED_FACE_VERTEX_INDICES, dtype=int, device=device)
|
|
211
|
+
mesh = wp.Mesh(points=points, indices=indices, bvh_constructor=constructor)
|
|
212
|
+
expected_sign = -1.0
|
|
213
|
+
wp.launch(
|
|
214
|
+
query_ray_kernel,
|
|
215
|
+
dim=1,
|
|
216
|
+
inputs=[
|
|
217
|
+
mesh.id,
|
|
218
|
+
expected_sign,
|
|
219
|
+
],
|
|
220
|
+
device=device,
|
|
221
|
+
)
|
|
222
|
+
|
|
223
|
+
indices = wp.array(LEFT_HANDED_FACE_VERTEX_INDICES, dtype=int, device=device)
|
|
224
|
+
mesh = wp.Mesh(points=points, indices=indices)
|
|
225
|
+
expected_sign = 1.0
|
|
226
|
+
wp.launch(
|
|
227
|
+
query_ray_kernel,
|
|
228
|
+
dim=1,
|
|
229
|
+
inputs=[
|
|
230
|
+
mesh.id,
|
|
231
|
+
expected_sign,
|
|
232
|
+
],
|
|
233
|
+
device=device,
|
|
234
|
+
)
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
def test_mesh_refit_graph(test, device):
|
|
238
|
+
if device.is_cpu:
|
|
239
|
+
constructors = ["sah", "median"]
|
|
240
|
+
else:
|
|
241
|
+
constructors = ["sah", "median", "lbvh"]
|
|
242
|
+
|
|
243
|
+
for constructor in constructors:
|
|
244
|
+
points = wp.array(POINT_POSITIONS, dtype=wp.vec3, device=device)
|
|
245
|
+
|
|
246
|
+
indices = wp.array(RIGHT_HANDED_FACE_VERTEX_INDICES, dtype=int, device=device)
|
|
247
|
+
mesh = wp.Mesh(points=points, indices=indices, bvh_constructor=constructor)
|
|
248
|
+
|
|
249
|
+
wp.capture_begin(device, force_module_load=False)
|
|
250
|
+
try:
|
|
251
|
+
mesh.refit()
|
|
252
|
+
finally:
|
|
253
|
+
graph = wp.capture_end(device)
|
|
254
|
+
|
|
255
|
+
# replay
|
|
256
|
+
num_iters = 10
|
|
257
|
+
for _ in range(num_iters):
|
|
258
|
+
wp.capture_launch(graph)
|
|
259
|
+
|
|
260
|
+
wp.synchronize_device(device)
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
def test_mesh_exceptions(test, device):
|
|
264
|
+
# points and indices must be on same device
|
|
265
|
+
with test.assertRaises(RuntimeError):
|
|
266
|
+
points = wp.array(POINT_POSITIONS, dtype=wp.vec3, device="cpu")
|
|
267
|
+
indices = wp.array(RIGHT_HANDED_FACE_VERTEX_INDICES, dtype=int, device=device)
|
|
268
|
+
wp.Mesh(points=points, indices=indices)
|
|
269
|
+
|
|
270
|
+
# points must be vec3
|
|
271
|
+
with test.assertRaises(RuntimeError):
|
|
272
|
+
points = wp.array(POINT_POSITIONS, dtype=wp.vec3d, device=device)
|
|
273
|
+
indices = wp.array(RIGHT_HANDED_FACE_VERTEX_INDICES, dtype=int, device=device)
|
|
274
|
+
wp.Mesh(points=points, indices=indices)
|
|
275
|
+
|
|
276
|
+
# velocities must be vec3
|
|
277
|
+
with test.assertRaises(RuntimeError):
|
|
278
|
+
points = wp.array(POINT_POSITIONS, dtype=wp.vec3, device=device)
|
|
279
|
+
velocities = wp.zeros(points.shape, dtype=wp.vec3d, device=device)
|
|
280
|
+
indices = wp.array(RIGHT_HANDED_FACE_VERTEX_INDICES, dtype=int, device=device)
|
|
281
|
+
wp.Mesh(points=points, indices=indices, velocities=velocities)
|
|
282
|
+
|
|
283
|
+
# indices must be int32
|
|
284
|
+
with test.assertRaises(RuntimeError):
|
|
285
|
+
points = wp.array(POINT_POSITIONS, dtype=wp.vec3, device=device)
|
|
286
|
+
indices = wp.array(RIGHT_HANDED_FACE_VERTEX_INDICES, dtype=wp.int64, device=device)
|
|
287
|
+
wp.Mesh(points=points, indices=indices)
|
|
288
|
+
|
|
289
|
+
# indices must be 1d
|
|
290
|
+
with test.assertRaises(RuntimeError):
|
|
291
|
+
points = wp.array(POINT_POSITIONS, dtype=wp.vec3, device=device)
|
|
292
|
+
indices = wp.array(RIGHT_HANDED_FACE_VERTEX_INDICES, dtype=int, device=device)
|
|
293
|
+
indices = indices.reshape((3, -1))
|
|
294
|
+
wp.Mesh(points=points, indices=indices)
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
devices = get_test_devices()
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
class TestMesh(unittest.TestCase):
|
|
301
|
+
def test_mesh_new_del(self):
|
|
302
|
+
# test the scenario in which a mesh is created but not initialized before gc
|
|
303
|
+
instance = wp.Mesh.__new__(wp.Mesh)
|
|
304
|
+
instance.__del__()
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
add_function_test(TestMesh, "test_mesh_read_properties", test_mesh_read_properties, devices=devices)
|
|
308
|
+
add_function_test(TestMesh, "test_mesh_query_point", test_mesh_query_point, devices=devices)
|
|
309
|
+
add_function_test(TestMesh, "test_mesh_query_ray", test_mesh_query_ray, devices=devices)
|
|
310
|
+
add_function_test(TestMesh, "test_mesh_refit_graph", test_mesh_refit_graph, devices=get_selected_cuda_test_devices())
|
|
311
|
+
add_function_test(TestMesh, "test_mesh_exceptions", test_mesh_exceptions, devices=get_selected_cuda_test_devices())
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
if __name__ == "__main__":
|
|
315
|
+
wp.clear_kernel_cache()
|
|
316
|
+
unittest.main(verbosity=2)
|
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: Copyright (c) 2022 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 os
|
|
17
|
+
import unittest
|
|
18
|
+
|
|
19
|
+
import numpy as np
|
|
20
|
+
|
|
21
|
+
import warp as wp
|
|
22
|
+
import warp.examples
|
|
23
|
+
from warp.tests.unittest_utils import *
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@wp.func
|
|
27
|
+
def min_vec3(a: wp.vec3, b: wp.vec3):
|
|
28
|
+
return wp.vec3(wp.min(a[0], b[0]), wp.min(a[1], b[1]), wp.min(a[2], b[2]))
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@wp.func
|
|
32
|
+
def max_vec3(a: wp.vec3, b: wp.vec3):
|
|
33
|
+
return wp.vec3(wp.max(a[0], b[0]), wp.max(a[1], b[1]), wp.max(a[2], b[2]))
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
@wp.kernel
|
|
37
|
+
def compute_bounds(
|
|
38
|
+
indices: wp.array(dtype=int),
|
|
39
|
+
positions: wp.array(dtype=wp.vec3),
|
|
40
|
+
lowers: wp.array(dtype=wp.vec3),
|
|
41
|
+
uppers: wp.array(dtype=wp.vec3),
|
|
42
|
+
):
|
|
43
|
+
tid = wp.tid()
|
|
44
|
+
i = indices[tid * 3 + 0]
|
|
45
|
+
j = indices[tid * 3 + 1]
|
|
46
|
+
k = indices[tid * 3 + 2]
|
|
47
|
+
|
|
48
|
+
x0 = positions[i] # point zero
|
|
49
|
+
x1 = positions[j] # point one
|
|
50
|
+
x2 = positions[k] # point two
|
|
51
|
+
|
|
52
|
+
lower = min_vec3(min_vec3(x0, x1), x2)
|
|
53
|
+
upper = max_vec3(max_vec3(x0, x1), x2)
|
|
54
|
+
|
|
55
|
+
lowers[tid] = lower
|
|
56
|
+
uppers[tid] = upper
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
@wp.kernel
|
|
60
|
+
def compute_num_contacts(
|
|
61
|
+
lowers: wp.array(dtype=wp.vec3), uppers: wp.array(dtype=wp.vec3), mesh_id: wp.uint64, counts: wp.array(dtype=int)
|
|
62
|
+
):
|
|
63
|
+
face_index = int(0)
|
|
64
|
+
face_u = float(0.0)
|
|
65
|
+
face_v = float(0.0)
|
|
66
|
+
sign = float(0.0)
|
|
67
|
+
|
|
68
|
+
tid = wp.tid()
|
|
69
|
+
|
|
70
|
+
upper = uppers[tid]
|
|
71
|
+
lower = lowers[tid]
|
|
72
|
+
|
|
73
|
+
query = wp.mesh_query_aabb(mesh_id, lower, upper)
|
|
74
|
+
count = int(0)
|
|
75
|
+
|
|
76
|
+
# index = int(-1)
|
|
77
|
+
# while wp.mesh_query_aabb_next(query, index):
|
|
78
|
+
|
|
79
|
+
for _index in query:
|
|
80
|
+
count = count + 1
|
|
81
|
+
|
|
82
|
+
counts[tid] = count
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def test_compute_bounds(test, device):
|
|
86
|
+
# create two touching triangles.
|
|
87
|
+
points = np.array([[0, 0, 0], [1, 0, 0], [0, 1, 0], [-1, -1, 1]])
|
|
88
|
+
indices = np.array([0, 1, 2, 1, 2, 3])
|
|
89
|
+
m = wp.Mesh(
|
|
90
|
+
points=wp.array(points, dtype=wp.vec3, device=device),
|
|
91
|
+
indices=wp.array(indices, dtype=int, device=device),
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
num_tris = int(len(indices) / 3)
|
|
95
|
+
|
|
96
|
+
# First compute bounds of each of the triangles.
|
|
97
|
+
lowers = wp.empty(n=num_tris, dtype=wp.vec3, device=device)
|
|
98
|
+
uppers = wp.empty_like(lowers)
|
|
99
|
+
wp.launch(
|
|
100
|
+
kernel=compute_bounds,
|
|
101
|
+
dim=num_tris,
|
|
102
|
+
inputs=[m.indices, m.points],
|
|
103
|
+
outputs=[lowers, uppers],
|
|
104
|
+
device=device,
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
lower_view = lowers.numpy()
|
|
108
|
+
upper_view = uppers.numpy()
|
|
109
|
+
|
|
110
|
+
# Confirm the bounds of each triangle are correct.
|
|
111
|
+
test.assertTrue(lower_view[0][0] == 0)
|
|
112
|
+
test.assertTrue(lower_view[0][1] == 0)
|
|
113
|
+
test.assertTrue(lower_view[0][2] == 0)
|
|
114
|
+
|
|
115
|
+
test.assertTrue(upper_view[0][0] == 1)
|
|
116
|
+
test.assertTrue(upper_view[0][1] == 1)
|
|
117
|
+
test.assertTrue(upper_view[0][2] == 0)
|
|
118
|
+
|
|
119
|
+
test.assertTrue(lower_view[1][0] == -1)
|
|
120
|
+
test.assertTrue(lower_view[1][1] == -1)
|
|
121
|
+
test.assertTrue(lower_view[1][2] == 0)
|
|
122
|
+
|
|
123
|
+
test.assertTrue(upper_view[1][0] == 1)
|
|
124
|
+
test.assertTrue(upper_view[1][1] == 1)
|
|
125
|
+
test.assertTrue(upper_view[1][2] == 1)
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def test_mesh_query_aabb_count_overlap(test, device):
|
|
129
|
+
# create two touching triangles.
|
|
130
|
+
points = np.array([[0, 0, 0], [1, 0, 0], [0, 1, 0], [-1, -1, 1]])
|
|
131
|
+
indices = np.array([0, 1, 2, 1, 2, 3])
|
|
132
|
+
m = wp.Mesh(
|
|
133
|
+
points=wp.array(points, dtype=wp.vec3, device=device),
|
|
134
|
+
indices=wp.array(indices, dtype=int, device=device),
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
num_tris = int(len(indices) / 3)
|
|
138
|
+
|
|
139
|
+
# Compute AABB of each of the triangles.
|
|
140
|
+
lowers = wp.empty(n=num_tris, dtype=wp.vec3, device=device)
|
|
141
|
+
uppers = wp.empty_like(lowers)
|
|
142
|
+
wp.launch(
|
|
143
|
+
kernel=compute_bounds,
|
|
144
|
+
dim=num_tris,
|
|
145
|
+
inputs=[m.indices, m.points],
|
|
146
|
+
outputs=[lowers, uppers],
|
|
147
|
+
device=device,
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
counts = wp.empty(n=num_tris, dtype=int, device=device)
|
|
151
|
+
|
|
152
|
+
wp.launch(
|
|
153
|
+
kernel=compute_num_contacts,
|
|
154
|
+
dim=num_tris,
|
|
155
|
+
inputs=[lowers, uppers, m.id],
|
|
156
|
+
outputs=[counts],
|
|
157
|
+
device=device,
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
view = counts.numpy()
|
|
161
|
+
|
|
162
|
+
# 2 triangles that share a vertex having overlapping AABBs.
|
|
163
|
+
for c in view:
|
|
164
|
+
test.assertTrue(c == 2)
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def test_mesh_query_aabb_count_nonoverlap(test, device):
|
|
168
|
+
# create two separate triangles.
|
|
169
|
+
points = np.array([[0, 0, 0], [1, 0, 0], [0, 1, 0], [10, 0, 0], [10, 1, 0], [10, 0, 1]])
|
|
170
|
+
indices = np.array([0, 1, 2, 3, 4, 5])
|
|
171
|
+
m = wp.Mesh(
|
|
172
|
+
points=wp.array(points, dtype=wp.vec3, device=device),
|
|
173
|
+
indices=wp.array(indices, dtype=int, device=device),
|
|
174
|
+
)
|
|
175
|
+
|
|
176
|
+
num_tris = int(len(indices) / 3)
|
|
177
|
+
|
|
178
|
+
lowers = wp.empty(n=num_tris, dtype=wp.vec3, device=device)
|
|
179
|
+
uppers = wp.empty_like(lowers)
|
|
180
|
+
wp.launch(
|
|
181
|
+
kernel=compute_bounds,
|
|
182
|
+
dim=num_tris,
|
|
183
|
+
inputs=[m.indices, m.points],
|
|
184
|
+
outputs=[lowers, uppers],
|
|
185
|
+
device=device,
|
|
186
|
+
)
|
|
187
|
+
|
|
188
|
+
counts = wp.empty(n=num_tris, dtype=int, device=device)
|
|
189
|
+
|
|
190
|
+
wp.launch(
|
|
191
|
+
kernel=compute_num_contacts,
|
|
192
|
+
dim=num_tris,
|
|
193
|
+
inputs=[lowers, uppers, m.id],
|
|
194
|
+
outputs=[counts],
|
|
195
|
+
device=device,
|
|
196
|
+
)
|
|
197
|
+
|
|
198
|
+
view = counts.numpy()
|
|
199
|
+
|
|
200
|
+
# AABB query only returns one triangle at a time, the triangles are not close enough to overlap.
|
|
201
|
+
for c in view:
|
|
202
|
+
test.assertTrue(c == 1)
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
@wp.kernel
|
|
206
|
+
def compute_num_contact_with_checksums(
|
|
207
|
+
lowers: wp.array(dtype=wp.vec3),
|
|
208
|
+
uppers: wp.array(dtype=wp.vec3),
|
|
209
|
+
mesh_id: wp.uint64,
|
|
210
|
+
counts: wp.array(dtype=int),
|
|
211
|
+
check_sums: wp.array(dtype=int),
|
|
212
|
+
):
|
|
213
|
+
face_index = int(0)
|
|
214
|
+
face_u = float(0.0)
|
|
215
|
+
face_v = float(0.0)
|
|
216
|
+
sign = float(0.0)
|
|
217
|
+
|
|
218
|
+
tid = wp.tid()
|
|
219
|
+
|
|
220
|
+
upper = uppers[tid]
|
|
221
|
+
lower = lowers[tid]
|
|
222
|
+
|
|
223
|
+
query = wp.mesh_query_aabb(mesh_id, lower, upper)
|
|
224
|
+
count = int(0)
|
|
225
|
+
|
|
226
|
+
check_sum = int(0)
|
|
227
|
+
for _index in query:
|
|
228
|
+
check_sum = check_sum ^ _index
|
|
229
|
+
count = count + 1
|
|
230
|
+
|
|
231
|
+
counts[tid] = count
|
|
232
|
+
check_sums[tid] = check_sum
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
@wp.func
|
|
236
|
+
def intersect_aabb_aabb(a_lower: wp.vec3, a_upper: wp.vec3, b_lower: wp.vec3, b_upper: wp.vec3):
|
|
237
|
+
if (
|
|
238
|
+
a_lower[0] > b_upper[0]
|
|
239
|
+
or a_lower[1] > b_upper[1]
|
|
240
|
+
or a_lower[2] > b_upper[2]
|
|
241
|
+
or a_upper[0] < b_lower[0]
|
|
242
|
+
or a_upper[1] < b_lower[1]
|
|
243
|
+
or a_upper[2] < b_lower[2]
|
|
244
|
+
):
|
|
245
|
+
return False
|
|
246
|
+
else:
|
|
247
|
+
return True
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
@wp.kernel
|
|
251
|
+
def compute_num_contact_with_checksums_brutal(
|
|
252
|
+
lowers: wp.array(dtype=wp.vec3),
|
|
253
|
+
uppers: wp.array(dtype=wp.vec3),
|
|
254
|
+
mesh_points: wp.array(dtype=wp.vec3),
|
|
255
|
+
mesh_indices: wp.array(dtype=int),
|
|
256
|
+
counts: wp.array(dtype=int),
|
|
257
|
+
check_sums: wp.array(dtype=int),
|
|
258
|
+
):
|
|
259
|
+
tid = wp.tid()
|
|
260
|
+
|
|
261
|
+
upper = uppers[tid]
|
|
262
|
+
lower = lowers[tid]
|
|
263
|
+
|
|
264
|
+
check_sum = int(0)
|
|
265
|
+
count = int(0)
|
|
266
|
+
num_faces = mesh_indices.shape[0] / 3
|
|
267
|
+
|
|
268
|
+
for face in range(num_faces):
|
|
269
|
+
i = mesh_indices[face * 3 + 0]
|
|
270
|
+
j = mesh_indices[face * 3 + 1]
|
|
271
|
+
k = mesh_indices[face * 3 + 2]
|
|
272
|
+
|
|
273
|
+
x0 = mesh_points[i] # point zero
|
|
274
|
+
x1 = mesh_points[j] # point one
|
|
275
|
+
x2 = mesh_points[k] # point two
|
|
276
|
+
|
|
277
|
+
tri_lower = min_vec3(min_vec3(x0, x1), x2)
|
|
278
|
+
tri_upper = max_vec3(max_vec3(x0, x1), x2)
|
|
279
|
+
|
|
280
|
+
if intersect_aabb_aabb(lower, upper, tri_lower, tri_upper):
|
|
281
|
+
check_sum = check_sum ^ face
|
|
282
|
+
count = count + 1
|
|
283
|
+
|
|
284
|
+
counts[tid] = count
|
|
285
|
+
check_sums[tid] = check_sum
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
def load_mesh():
|
|
289
|
+
from pxr import Usd, UsdGeom
|
|
290
|
+
|
|
291
|
+
usd_stage = Usd.Stage.Open(os.path.join(wp.examples.get_asset_directory(), "bunny.usd"))
|
|
292
|
+
usd_geom = UsdGeom.Mesh(usd_stage.GetPrimAtPath("/root/bunny"))
|
|
293
|
+
|
|
294
|
+
vertices = np.array(usd_geom.GetPointsAttr().Get())
|
|
295
|
+
faces = np.array(usd_geom.GetFaceVertexIndicesAttr().Get())
|
|
296
|
+
|
|
297
|
+
return vertices, faces
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
@unittest.skipUnless(USD_AVAILABLE, "Requires usd-core")
|
|
301
|
+
def test_mesh_query_aabb_count_overlap_with_checksum(test, device):
|
|
302
|
+
if device.is_cpu:
|
|
303
|
+
constructors = ["sah", "median"]
|
|
304
|
+
else:
|
|
305
|
+
constructors = ["sah", "median", "lbvh"]
|
|
306
|
+
|
|
307
|
+
points, indices = load_mesh()
|
|
308
|
+
points_wp = wp.array(points, dtype=wp.vec3, device=device)
|
|
309
|
+
indices_wp = wp.array(indices, dtype=int, device=device)
|
|
310
|
+
|
|
311
|
+
for constructor in constructors:
|
|
312
|
+
m = wp.Mesh(points=points_wp, indices=indices_wp, bvh_constructor=constructor)
|
|
313
|
+
|
|
314
|
+
num_test_bounds = 10000
|
|
315
|
+
test_bound_relative_size = 0.01
|
|
316
|
+
|
|
317
|
+
world_min = np.min(points, axis=0)
|
|
318
|
+
world_max = np.max(points, axis=0)
|
|
319
|
+
|
|
320
|
+
world_center = 0.5 * (world_min + world_max)
|
|
321
|
+
world_size = world_max - world_min
|
|
322
|
+
|
|
323
|
+
rng = np.random.default_rng(123)
|
|
324
|
+
|
|
325
|
+
centers = (
|
|
326
|
+
rng.uniform(-0.5, 0.5, size=num_test_bounds * 3).reshape(num_test_bounds, 3) * world_size + world_center
|
|
327
|
+
)
|
|
328
|
+
diffs = (
|
|
329
|
+
0.5 * test_bound_relative_size * rng.random(num_test_bounds * 3).reshape(num_test_bounds, 3) * world_size
|
|
330
|
+
)
|
|
331
|
+
|
|
332
|
+
lowers = wp.array(centers - diffs, dtype=wp.vec3, device=device)
|
|
333
|
+
uppers = wp.array(centers + diffs, dtype=wp.vec3, device=device)
|
|
334
|
+
|
|
335
|
+
counts = wp.empty(n=num_test_bounds, dtype=int, device=device)
|
|
336
|
+
checksums = wp.empty(n=num_test_bounds, dtype=int, device=device)
|
|
337
|
+
|
|
338
|
+
wp.launch(
|
|
339
|
+
kernel=compute_num_contact_with_checksums,
|
|
340
|
+
dim=num_test_bounds,
|
|
341
|
+
inputs=[lowers, uppers, m.id],
|
|
342
|
+
outputs=[counts, checksums],
|
|
343
|
+
device=device,
|
|
344
|
+
)
|
|
345
|
+
|
|
346
|
+
counts_brutal = wp.empty(n=num_test_bounds, dtype=int, device=device)
|
|
347
|
+
checksums_brutal = wp.empty(n=num_test_bounds, dtype=int, device=device)
|
|
348
|
+
|
|
349
|
+
wp.launch(
|
|
350
|
+
kernel=compute_num_contact_with_checksums_brutal,
|
|
351
|
+
dim=num_test_bounds,
|
|
352
|
+
inputs=[lowers, uppers, points_wp, indices_wp],
|
|
353
|
+
outputs=[counts_brutal, checksums_brutal],
|
|
354
|
+
device=device,
|
|
355
|
+
)
|
|
356
|
+
|
|
357
|
+
assert_array_equal(counts, counts_brutal)
|
|
358
|
+
assert_array_equal(checksums, checksums_brutal)
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
devices = get_test_devices()
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
class TestMeshQueryAABBMethods(unittest.TestCase):
|
|
365
|
+
def test_mesh_query_aabb_codegen_adjoints_with_select(self):
|
|
366
|
+
def kernel_fn(
|
|
367
|
+
mesh: wp.uint64,
|
|
368
|
+
):
|
|
369
|
+
v = wp.vec3(0.0, 0.0, 0.0)
|
|
370
|
+
|
|
371
|
+
if True:
|
|
372
|
+
query = wp.mesh_query_aabb(mesh, v, v)
|
|
373
|
+
else:
|
|
374
|
+
query = wp.mesh_query_aabb(mesh, v, v)
|
|
375
|
+
|
|
376
|
+
wp.Kernel(func=kernel_fn)
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
add_function_test(TestMeshQueryAABBMethods, "test_compute_bounds", test_compute_bounds, devices=devices)
|
|
380
|
+
add_function_test(
|
|
381
|
+
TestMeshQueryAABBMethods, "test_mesh_query_aabb_count_overlap", test_mesh_query_aabb_count_overlap, devices=devices
|
|
382
|
+
)
|
|
383
|
+
add_function_test(
|
|
384
|
+
TestMeshQueryAABBMethods,
|
|
385
|
+
"test_mesh_query_aabb_count_nonoverlap",
|
|
386
|
+
test_mesh_query_aabb_count_nonoverlap,
|
|
387
|
+
devices=devices,
|
|
388
|
+
)
|
|
389
|
+
add_function_test(
|
|
390
|
+
TestMeshQueryAABBMethods,
|
|
391
|
+
"test_mesh_query_aabb_count_overlap_with_checksum",
|
|
392
|
+
test_mesh_query_aabb_count_overlap_with_checksum,
|
|
393
|
+
devices=devices,
|
|
394
|
+
)
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
if __name__ == "__main__":
|
|
398
|
+
wp.clear_kernel_cache()
|
|
399
|
+
unittest.main(verbosity=2)
|