warp-lang 1.0.0b2__py3-none-win_amd64.whl → 1.0.0b6__py3-none-win_amd64.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.

Files changed (271) hide show
  1. docs/conf.py +17 -5
  2. examples/env/env_ant.py +1 -1
  3. examples/env/env_cartpole.py +1 -1
  4. examples/env/env_humanoid.py +1 -1
  5. examples/env/env_usd.py +4 -1
  6. examples/env/environment.py +8 -9
  7. examples/example_dem.py +34 -33
  8. examples/example_diffray.py +364 -337
  9. examples/example_fluid.py +32 -23
  10. examples/example_jacobian_ik.py +97 -93
  11. examples/example_marching_cubes.py +6 -16
  12. examples/example_mesh.py +6 -16
  13. examples/example_mesh_intersect.py +16 -14
  14. examples/example_nvdb.py +14 -16
  15. examples/example_raycast.py +14 -13
  16. examples/example_raymarch.py +16 -23
  17. examples/example_render_opengl.py +19 -10
  18. examples/example_sim_cartpole.py +82 -78
  19. examples/example_sim_cloth.py +45 -48
  20. examples/example_sim_fk_grad.py +51 -44
  21. examples/example_sim_fk_grad_torch.py +47 -40
  22. examples/example_sim_grad_bounce.py +108 -133
  23. examples/example_sim_grad_cloth.py +99 -113
  24. examples/example_sim_granular.py +5 -6
  25. examples/{example_sim_sdf_shape.py → example_sim_granular_collision_sdf.py} +37 -26
  26. examples/example_sim_neo_hookean.py +51 -55
  27. examples/example_sim_particle_chain.py +4 -4
  28. examples/example_sim_quadruped.py +126 -81
  29. examples/example_sim_rigid_chain.py +54 -61
  30. examples/example_sim_rigid_contact.py +66 -70
  31. examples/example_sim_rigid_fem.py +3 -3
  32. examples/example_sim_rigid_force.py +1 -1
  33. examples/example_sim_rigid_gyroscopic.py +3 -4
  34. examples/example_sim_rigid_kinematics.py +28 -39
  35. examples/example_sim_trajopt.py +112 -110
  36. examples/example_sph.py +9 -8
  37. examples/example_wave.py +7 -7
  38. examples/fem/bsr_utils.py +30 -17
  39. examples/fem/example_apic_fluid.py +85 -69
  40. examples/fem/example_convection_diffusion.py +97 -93
  41. examples/fem/example_convection_diffusion_dg.py +142 -149
  42. examples/fem/example_convection_diffusion_dg0.py +141 -136
  43. examples/fem/example_deformed_geometry.py +146 -0
  44. examples/fem/example_diffusion.py +115 -84
  45. examples/fem/example_diffusion_3d.py +116 -86
  46. examples/fem/example_diffusion_mgpu.py +102 -79
  47. examples/fem/example_mixed_elasticity.py +139 -100
  48. examples/fem/example_navier_stokes.py +175 -162
  49. examples/fem/example_stokes.py +143 -111
  50. examples/fem/example_stokes_transfer.py +186 -157
  51. examples/fem/mesh_utils.py +59 -97
  52. examples/fem/plot_utils.py +138 -17
  53. tools/ci/publishing/build_nodes_info.py +54 -0
  54. warp/__init__.py +4 -3
  55. warp/__init__.pyi +1 -0
  56. warp/bin/warp-clang.dll +0 -0
  57. warp/bin/warp.dll +0 -0
  58. warp/build.py +5 -3
  59. warp/build_dll.py +29 -9
  60. warp/builtins.py +836 -492
  61. warp/codegen.py +864 -553
  62. warp/config.py +3 -1
  63. warp/context.py +389 -172
  64. warp/fem/__init__.py +24 -6
  65. warp/fem/cache.py +318 -25
  66. warp/fem/dirichlet.py +7 -3
  67. warp/fem/domain.py +14 -0
  68. warp/fem/field/__init__.py +30 -38
  69. warp/fem/field/field.py +149 -0
  70. warp/fem/field/nodal_field.py +244 -138
  71. warp/fem/field/restriction.py +8 -6
  72. warp/fem/field/test.py +127 -59
  73. warp/fem/field/trial.py +117 -60
  74. warp/fem/geometry/__init__.py +5 -1
  75. warp/fem/geometry/deformed_geometry.py +271 -0
  76. warp/fem/geometry/element.py +24 -1
  77. warp/fem/geometry/geometry.py +86 -14
  78. warp/fem/geometry/grid_2d.py +112 -54
  79. warp/fem/geometry/grid_3d.py +134 -65
  80. warp/fem/geometry/hexmesh.py +953 -0
  81. warp/fem/geometry/partition.py +85 -33
  82. warp/fem/geometry/quadmesh_2d.py +532 -0
  83. warp/fem/geometry/tetmesh.py +451 -115
  84. warp/fem/geometry/trimesh_2d.py +197 -92
  85. warp/fem/integrate.py +534 -268
  86. warp/fem/operator.py +58 -31
  87. warp/fem/polynomial.py +11 -0
  88. warp/fem/quadrature/__init__.py +1 -1
  89. warp/fem/quadrature/pic_quadrature.py +150 -58
  90. warp/fem/quadrature/quadrature.py +209 -57
  91. warp/fem/space/__init__.py +230 -53
  92. warp/fem/space/basis_space.py +489 -0
  93. warp/fem/space/collocated_function_space.py +105 -0
  94. warp/fem/space/dof_mapper.py +49 -2
  95. warp/fem/space/function_space.py +90 -39
  96. warp/fem/space/grid_2d_function_space.py +149 -496
  97. warp/fem/space/grid_3d_function_space.py +173 -538
  98. warp/fem/space/hexmesh_function_space.py +352 -0
  99. warp/fem/space/partition.py +129 -76
  100. warp/fem/space/quadmesh_2d_function_space.py +369 -0
  101. warp/fem/space/restriction.py +46 -34
  102. warp/fem/space/shape/__init__.py +15 -0
  103. warp/fem/space/shape/cube_shape_function.py +738 -0
  104. warp/fem/space/shape/shape_function.py +103 -0
  105. warp/fem/space/shape/square_shape_function.py +611 -0
  106. warp/fem/space/shape/tet_shape_function.py +567 -0
  107. warp/fem/space/shape/triangle_shape_function.py +429 -0
  108. warp/fem/space/tetmesh_function_space.py +132 -1039
  109. warp/fem/space/topology.py +295 -0
  110. warp/fem/space/trimesh_2d_function_space.py +104 -742
  111. warp/fem/types.py +13 -11
  112. warp/fem/utils.py +335 -60
  113. warp/native/array.h +120 -34
  114. warp/native/builtin.h +101 -72
  115. warp/native/bvh.cpp +73 -325
  116. warp/native/bvh.cu +406 -23
  117. warp/native/bvh.h +22 -40
  118. warp/native/clang/clang.cpp +1 -0
  119. warp/native/crt.h +2 -0
  120. warp/native/cuda_util.cpp +8 -3
  121. warp/native/cuda_util.h +1 -0
  122. warp/native/exports.h +1522 -1243
  123. warp/native/intersect.h +19 -4
  124. warp/native/intersect_adj.h +8 -8
  125. warp/native/mat.h +76 -17
  126. warp/native/mesh.cpp +33 -108
  127. warp/native/mesh.cu +114 -18
  128. warp/native/mesh.h +395 -40
  129. warp/native/noise.h +272 -329
  130. warp/native/quat.h +51 -8
  131. warp/native/rand.h +44 -34
  132. warp/native/reduce.cpp +1 -1
  133. warp/native/sparse.cpp +4 -4
  134. warp/native/sparse.cu +163 -155
  135. warp/native/spatial.h +2 -2
  136. warp/native/temp_buffer.h +18 -14
  137. warp/native/vec.h +103 -21
  138. warp/native/warp.cpp +2 -1
  139. warp/native/warp.cu +28 -3
  140. warp/native/warp.h +4 -3
  141. warp/render/render_opengl.py +261 -109
  142. warp/sim/__init__.py +1 -2
  143. warp/sim/articulation.py +385 -185
  144. warp/sim/import_mjcf.py +59 -48
  145. warp/sim/import_urdf.py +15 -15
  146. warp/sim/import_usd.py +174 -102
  147. warp/sim/inertia.py +17 -18
  148. warp/sim/integrator_xpbd.py +4 -3
  149. warp/sim/model.py +330 -250
  150. warp/sim/render.py +1 -1
  151. warp/sparse.py +625 -152
  152. warp/stubs.py +341 -309
  153. warp/tape.py +9 -6
  154. warp/tests/__main__.py +3 -6
  155. warp/tests/assets/curlnoise_golden.npy +0 -0
  156. warp/tests/assets/pnoise_golden.npy +0 -0
  157. warp/tests/{test_class_kernel.py → aux_test_class_kernel.py} +9 -1
  158. warp/tests/aux_test_conditional_unequal_types_kernels.py +21 -0
  159. warp/tests/{test_dependent.py → aux_test_dependent.py} +2 -2
  160. warp/tests/{test_reference.py → aux_test_reference.py} +1 -1
  161. warp/tests/aux_test_unresolved_func.py +14 -0
  162. warp/tests/aux_test_unresolved_symbol.py +14 -0
  163. warp/tests/disabled_kinematics.py +239 -0
  164. warp/tests/run_coverage_serial.py +31 -0
  165. warp/tests/test_adam.py +103 -106
  166. warp/tests/test_arithmetic.py +94 -74
  167. warp/tests/test_array.py +82 -101
  168. warp/tests/test_array_reduce.py +57 -23
  169. warp/tests/test_atomic.py +64 -28
  170. warp/tests/test_bool.py +22 -12
  171. warp/tests/test_builtins_resolution.py +1292 -0
  172. warp/tests/test_bvh.py +18 -18
  173. warp/tests/test_closest_point_edge_edge.py +54 -57
  174. warp/tests/test_codegen.py +165 -134
  175. warp/tests/test_compile_consts.py +28 -20
  176. warp/tests/test_conditional.py +108 -24
  177. warp/tests/test_copy.py +10 -12
  178. warp/tests/test_ctypes.py +112 -88
  179. warp/tests/test_dense.py +21 -14
  180. warp/tests/test_devices.py +98 -0
  181. warp/tests/test_dlpack.py +75 -75
  182. warp/tests/test_examples.py +237 -0
  183. warp/tests/test_fabricarray.py +22 -24
  184. warp/tests/test_fast_math.py +15 -11
  185. warp/tests/test_fem.py +1034 -124
  186. warp/tests/test_fp16.py +23 -16
  187. warp/tests/test_func.py +187 -86
  188. warp/tests/test_generics.py +194 -49
  189. warp/tests/test_grad.py +123 -181
  190. warp/tests/test_grad_customs.py +176 -0
  191. warp/tests/test_hash_grid.py +35 -34
  192. warp/tests/test_import.py +10 -23
  193. warp/tests/test_indexedarray.py +24 -25
  194. warp/tests/test_intersect.py +18 -9
  195. warp/tests/test_large.py +141 -0
  196. warp/tests/test_launch.py +14 -41
  197. warp/tests/test_lerp.py +64 -65
  198. warp/tests/test_lvalue.py +493 -0
  199. warp/tests/test_marching_cubes.py +12 -13
  200. warp/tests/test_mat.py +517 -2898
  201. warp/tests/test_mat_lite.py +115 -0
  202. warp/tests/test_mat_scalar_ops.py +2889 -0
  203. warp/tests/test_math.py +103 -9
  204. warp/tests/test_matmul.py +304 -69
  205. warp/tests/test_matmul_lite.py +410 -0
  206. warp/tests/test_mesh.py +60 -22
  207. warp/tests/test_mesh_query_aabb.py +21 -25
  208. warp/tests/test_mesh_query_point.py +111 -22
  209. warp/tests/test_mesh_query_ray.py +12 -24
  210. warp/tests/test_mlp.py +30 -22
  211. warp/tests/test_model.py +92 -89
  212. warp/tests/test_modules_lite.py +39 -0
  213. warp/tests/test_multigpu.py +88 -114
  214. warp/tests/test_noise.py +12 -11
  215. warp/tests/test_operators.py +16 -20
  216. warp/tests/test_options.py +11 -11
  217. warp/tests/test_pinned.py +17 -18
  218. warp/tests/test_print.py +32 -11
  219. warp/tests/test_quat.py +275 -129
  220. warp/tests/test_rand.py +18 -16
  221. warp/tests/test_reload.py +38 -34
  222. warp/tests/test_rounding.py +50 -43
  223. warp/tests/test_runlength_encode.py +168 -20
  224. warp/tests/test_smoothstep.py +9 -11
  225. warp/tests/test_snippet.py +143 -0
  226. warp/tests/test_sparse.py +261 -63
  227. warp/tests/test_spatial.py +276 -243
  228. warp/tests/test_streams.py +110 -85
  229. warp/tests/test_struct.py +268 -63
  230. warp/tests/test_tape.py +39 -21
  231. warp/tests/test_torch.py +90 -86
  232. warp/tests/test_transient_module.py +10 -12
  233. warp/tests/test_types.py +363 -0
  234. warp/tests/test_utils.py +451 -0
  235. warp/tests/test_vec.py +354 -2050
  236. warp/tests/test_vec_lite.py +73 -0
  237. warp/tests/test_vec_scalar_ops.py +2099 -0
  238. warp/tests/test_volume.py +418 -376
  239. warp/tests/test_volume_write.py +124 -134
  240. warp/tests/unittest_serial.py +35 -0
  241. warp/tests/unittest_suites.py +291 -0
  242. warp/tests/unittest_utils.py +342 -0
  243. warp/tests/{test_misc.py → unused_test_misc.py} +13 -5
  244. warp/tests/{test_debug.py → walkthough_debug.py} +3 -17
  245. warp/thirdparty/appdirs.py +36 -45
  246. warp/thirdparty/unittest_parallel.py +589 -0
  247. warp/types.py +622 -211
  248. warp/utils.py +54 -393
  249. warp_lang-1.0.0b6.dist-info/METADATA +238 -0
  250. warp_lang-1.0.0b6.dist-info/RECORD +409 -0
  251. {warp_lang-1.0.0b2.dist-info → warp_lang-1.0.0b6.dist-info}/WHEEL +1 -1
  252. examples/example_cache_management.py +0 -40
  253. examples/example_multigpu.py +0 -54
  254. examples/example_struct.py +0 -65
  255. examples/fem/example_stokes_transfer_3d.py +0 -210
  256. warp/bin/warp-clang.so +0 -0
  257. warp/bin/warp.so +0 -0
  258. warp/fem/field/discrete_field.py +0 -80
  259. warp/fem/space/nodal_function_space.py +0 -233
  260. warp/tests/test_all.py +0 -223
  261. warp/tests/test_array_scan.py +0 -60
  262. warp/tests/test_base.py +0 -208
  263. warp/tests/test_unresolved_func.py +0 -7
  264. warp/tests/test_unresolved_symbol.py +0 -7
  265. warp_lang-1.0.0b2.dist-info/METADATA +0 -26
  266. warp_lang-1.0.0b2.dist-info/RECORD +0 -380
  267. /warp/tests/{test_compile_consts_dummy.py → aux_test_compile_consts_dummy.py} +0 -0
  268. /warp/tests/{test_reference_reference.py → aux_test_reference_reference.py} +0 -0
  269. /warp/tests/{test_square.py → aux_test_square.py} +0 -0
  270. {warp_lang-1.0.0b2.dist-info → warp_lang-1.0.0b6.dist-info}/LICENSE.md +0 -0
  271. {warp_lang-1.0.0b2.dist-info → warp_lang-1.0.0b6.dist-info}/top_level.txt +0 -0
warp/native/mesh.h CHANGED
@@ -26,7 +26,9 @@ struct Mesh
26
26
 
27
27
  array_t<int> indices;
28
28
 
29
- bounds3* bounds;
29
+ vec3* lowers;
30
+ vec3* uppers;
31
+
30
32
  SolidAngleProps* solid_angle_props;
31
33
 
32
34
  int num_points;
@@ -40,7 +42,8 @@ struct Mesh
40
42
  inline CUDA_CALLABLE Mesh(int id = 0)
41
43
  {
42
44
  // for backward a = 0 initialization syntax
43
- bounds = nullptr;
45
+ lowers = nullptr;
46
+ uppers = nullptr;
44
47
  num_points = 0;
45
48
  num_tris = 0;
46
49
  context = nullptr;
@@ -57,7 +60,8 @@ struct Mesh
57
60
  void* context = nullptr
58
61
  ) : points(points), velocities(velocities), indices(indices), num_points(num_points), num_tris(num_tris), context(context)
59
62
  {
60
- bounds = nullptr;
63
+ lowers = nullptr;
64
+ uppers = nullptr;
61
65
  solid_angle_props = nullptr;
62
66
  average_edge_length = 0.0f;
63
67
  }
@@ -81,6 +85,55 @@ CUDA_CALLABLE inline float distance_to_aabb_sq(const vec3& p, const vec3& lower,
81
85
  return length_sq(p-cp);
82
86
  }
83
87
 
88
+ CUDA_CALLABLE inline float furthest_distance_to_aabb_sq(const vec3& p, const vec3& lower, const vec3& upper)
89
+ {
90
+ vec3 c0 = vec3(lower[0], lower[1], lower[2]);
91
+ vec3 c1 = vec3(lower[0], lower[1], upper[2]);
92
+ vec3 c2 = vec3(lower[0], upper[1], lower[2]);
93
+ vec3 c3 = vec3(lower[0], upper[1], upper[2]);
94
+ vec3 c4 = vec3(upper[0], lower[1], lower[2]);
95
+ vec3 c5 = vec3(upper[0], lower[1], upper[2]);
96
+ vec3 c6 = vec3(upper[0], upper[1], lower[2]);
97
+ vec3 c7 = vec3(upper[0], upper[1], upper[2]);
98
+
99
+ float max_dist_sq = 0.0;
100
+ float d;
101
+
102
+ d = length_sq(p-c0);
103
+ if (d > max_dist_sq)
104
+ max_dist_sq = d;
105
+
106
+ d = length_sq(p-c1);
107
+ if (d > max_dist_sq)
108
+ max_dist_sq = d;
109
+
110
+ d = length_sq(p-c2);
111
+ if (d > max_dist_sq)
112
+ max_dist_sq = d;
113
+
114
+ d = length_sq(p-c3);
115
+ if (d > max_dist_sq)
116
+ max_dist_sq = d;
117
+
118
+ d = length_sq(p-c4);
119
+ if (d > max_dist_sq)
120
+ max_dist_sq = d;
121
+
122
+ d = length_sq(p-c5);
123
+ if (d > max_dist_sq)
124
+ max_dist_sq = d;
125
+
126
+ d = length_sq(p-c6);
127
+ if (d > max_dist_sq)
128
+ max_dist_sq = d;
129
+
130
+ d = length_sq(p-c7);
131
+ if (d > max_dist_sq)
132
+ max_dist_sq = d;
133
+
134
+ return max_dist_sq;
135
+ }
136
+
84
137
  CUDA_CALLABLE inline float mesh_query_inside(uint64_t id, const vec3& p);
85
138
 
86
139
  // returns true if there is a point (strictly) < distance max_dist
@@ -88,11 +141,8 @@ CUDA_CALLABLE inline bool mesh_query_point(uint64_t id, const vec3& point, float
88
141
  {
89
142
  Mesh mesh = mesh_get(id);
90
143
 
91
- if (mesh.bvh.num_nodes == 0)
92
- return false;
93
-
94
144
  int stack[32];
95
- stack[0] = mesh.bvh.root;
145
+ stack[0] = *mesh.bvh.root;
96
146
 
97
147
  int count = 1;
98
148
 
@@ -276,11 +326,8 @@ CUDA_CALLABLE inline bool mesh_query_point_no_sign(uint64_t id, const vec3& poin
276
326
  {
277
327
  Mesh mesh = mesh_get(id);
278
328
 
279
- if (mesh.bvh.num_nodes == 0)
280
- return false;
281
-
282
329
  int stack[32];
283
- stack[0] = mesh.bvh.root;
330
+ stack[0] = *mesh.bvh.root;
284
331
 
285
332
  int count = 1;
286
333
 
@@ -456,14 +503,197 @@ CUDA_CALLABLE inline bool mesh_query_point_no_sign(uint64_t id, const vec3& poin
456
503
  }
457
504
  }
458
505
 
506
+ // returns true if there is a point (strictly) > distance min_dist
507
+ CUDA_CALLABLE inline bool mesh_query_furthest_point_no_sign(uint64_t id, const vec3& point, float min_dist, int& face, float& u, float& v)
508
+ {
509
+ Mesh mesh = mesh_get(id);
510
+
511
+ int stack[32];
512
+ stack[0] = *mesh.bvh.root;
513
+
514
+ int count = 1;
515
+
516
+ float max_dist_sq = min_dist*min_dist;
517
+ int min_face;
518
+ float min_v;
519
+ float min_w;
520
+
521
+ #if BVH_DEBUG
522
+ int tests = 0;
523
+ int secondary_culls = 0;
524
+
525
+ std::vector<int> test_history;
526
+ std::vector<vec3> test_centers;
527
+ std::vector<vec3> test_extents;
528
+ #endif
529
+
530
+ while (count)
531
+ {
532
+ const int nodeIndex = stack[--count];
533
+
534
+ BVHPackedNodeHalf lower = mesh.bvh.node_lowers[nodeIndex];
535
+ BVHPackedNodeHalf upper = mesh.bvh.node_uppers[nodeIndex];
536
+
537
+ // re-test distance
538
+ float node_dist_sq = furthest_distance_to_aabb_sq(point, vec3(lower.x, lower.y, lower.z), vec3(upper.x, upper.y, upper.z));
539
+
540
+ // if maximum distance to this node is less than our existing furthest max then skip
541
+ if (node_dist_sq < max_dist_sq)
542
+ {
543
+ #if BVH_DEBUG
544
+ secondary_culls++;
545
+ #endif
546
+ continue;
547
+ }
548
+
549
+ const int left_index = lower.i;
550
+ const int right_index = upper.i;
551
+
552
+ if (lower.b)
553
+ {
554
+ // compute closest point on tri
555
+ int i = mesh.indices[left_index*3+0];
556
+ int j = mesh.indices[left_index*3+1];
557
+ int k = mesh.indices[left_index*3+2];
558
+
559
+ vec3 p = mesh.points[i];
560
+ vec3 q = mesh.points[j];
561
+ vec3 r = mesh.points[k];
562
+
563
+ vec3 e0 = q-p;
564
+ vec3 e1 = r-p;
565
+ vec3 e2 = r-q;
566
+ vec3 normal = cross(e0, e1);
567
+
568
+ // sliver detection
569
+ if (length(normal)/(dot(e0,e0) + dot(e1,e1) + dot(e2,e2)) < 1.e-6f)
570
+ continue;
571
+
572
+ vec2 barycentric = furthest_point_to_triangle(p, q, r, point);
573
+ float u = barycentric[0];
574
+ float v = barycentric[1];
575
+ float w = 1.f - u - v;
576
+ vec3 c = u*p + v*q + w*r;
577
+
578
+ float dist_sq = length_sq(c-point);
579
+
580
+ if (dist_sq > max_dist_sq)
581
+ {
582
+ max_dist_sq = dist_sq;
583
+ min_v = v;
584
+ min_w = w;
585
+ min_face = left_index;
586
+ }
587
+
588
+ #if BVH_DEBUG
589
+
590
+ tests++;
591
+
592
+ bounds3 b;
593
+ b = bounds_union(b, p);
594
+ b = bounds_union(b, q);
595
+ b = bounds_union(b, r);
596
+
597
+ if (distance_to_aabb_sq(point, b.lower, b.upper) > max_dist*max_dist)
598
+ {
599
+ //if (dist_sq < max_dist*max_dist)
600
+ test_history.push_back(left_index);
601
+ test_centers.push_back(b.center());
602
+ test_extents.push_back(b.edges());
603
+ }
604
+ #endif
605
+
606
+ }
607
+ else
608
+ {
609
+ BVHPackedNodeHalf left_lower = mesh.bvh.node_lowers[left_index];
610
+ BVHPackedNodeHalf left_upper = mesh.bvh.node_uppers[left_index];
611
+
612
+ BVHPackedNodeHalf right_lower = mesh.bvh.node_lowers[right_index];
613
+ BVHPackedNodeHalf right_upper = mesh.bvh.node_uppers[right_index];
614
+
615
+ float left_dist_sq = furthest_distance_to_aabb_sq(point, vec3(left_lower.x, left_lower.y, left_lower.z), vec3(left_upper.x, left_upper.y, left_upper.z));
616
+ float right_dist_sq = furthest_distance_to_aabb_sq(point, vec3(right_lower.x, right_lower.y, right_lower.z), vec3(right_upper.x, right_upper.y, right_upper.z));
617
+
618
+ float left_score = left_dist_sq;
619
+ float right_score = right_dist_sq;
620
+
621
+ if (left_score > right_score)
622
+ {
623
+ // put left on top of the stack
624
+ if (right_dist_sq > max_dist_sq)
625
+ stack[count++] = right_index;
626
+
627
+ if (left_dist_sq > max_dist_sq)
628
+ stack[count++] = left_index;
629
+ }
630
+ else
631
+ {
632
+ // put right on top of the stack
633
+ if (left_dist_sq > max_dist_sq)
634
+ stack[count++] = left_index;
635
+
636
+ if (right_dist_sq > max_dist_sq)
637
+ stack[count++] = right_index;
638
+ }
639
+ }
640
+ }
641
+
642
+
643
+ #if BVH_DEBUG
644
+ printf("%d\n", tests);
645
+
646
+ static int max_tests = 0;
647
+ static vec3 max_point;
648
+ static float max_point_dist = 0.0f;
649
+ static int max_secondary_culls = 0;
650
+
651
+ if (secondary_culls > max_secondary_culls)
652
+ max_secondary_culls = secondary_culls;
653
+
654
+ if (tests > max_tests)
655
+ {
656
+ max_tests = tests;
657
+ max_point = point;
658
+ max_point_dist = sqrtf(max_dist_sq);
659
+
660
+ printf("max_tests: %d max_point: %f %f %f max_point_dist: %f max_second_culls: %d\n", max_tests, max_point[0], max_point[1], max_point[2], max_point_dist, max_secondary_culls);
661
+
662
+ FILE* f = fopen("test_history.txt", "w");
663
+ for (int i=0; i < test_history.size(); ++i)
664
+ {
665
+ fprintf(f, "%d, %f, %f, %f, %f, %f, %f\n",
666
+ test_history[i],
667
+ test_centers[i][0], test_centers[i][1], test_centers[i][2],
668
+ test_extents[i][0], test_extents[i][1], test_extents[i][2]);
669
+ }
670
+
671
+ fclose(f);
672
+ }
673
+ #endif
674
+
675
+ // check if we found a point, and write outputs
676
+ if (max_dist_sq > min_dist*min_dist)
677
+ {
678
+ u = 1.0f - min_v - min_w;
679
+ v = min_v;
680
+ face = min_face;
681
+
682
+ return true;
683
+ }
684
+ else
685
+ {
686
+ return false;
687
+ }
688
+ }
689
+
459
690
  // returns true if there is a point (strictly) < distance max_dist
460
691
  CUDA_CALLABLE inline bool mesh_query_point_sign_normal(uint64_t id, const vec3& point, float max_dist, float& inside, int& face, float& u, float& v, const float epsilon = 1e-3f)
461
692
  {
462
693
  Mesh mesh = mesh_get(id);
463
- if (mesh.bvh.num_nodes == 0)
464
- return false;
694
+
465
695
  int stack[32];
466
- stack[0] = mesh.bvh.root;
696
+ stack[0] = *mesh.bvh.root;
467
697
  int count = 1;
468
698
  float min_dist = max_dist;
469
699
  int min_face;
@@ -685,12 +915,11 @@ CUDA_CALLABLE inline bool mesh_query_point_sign_normal(uint64_t id, const vec3&
685
915
  CUDA_CALLABLE inline float solid_angle_iterative(uint64_t id, const vec3& p, const float accuracy_sq)
686
916
  {
687
917
  Mesh mesh = mesh_get(id);
688
- if (mesh.bvh.num_nodes == 0)
689
- return 0.0f;
918
+
690
919
  int stack[32];
691
920
  int at_child[32]; // 0 for left, 1 for right, 2 for done
692
921
  float angle[32];
693
- stack[0] = mesh.bvh.root;
922
+ stack[0] = *mesh.bvh.root;
694
923
  at_child[0] = 0;
695
924
 
696
925
  int count = 1;
@@ -766,11 +995,8 @@ CUDA_CALLABLE inline bool mesh_query_point_sign_winding_number(uint64_t id, cons
766
995
  {
767
996
  Mesh mesh = mesh_get(id);
768
997
 
769
- if (mesh.bvh.num_nodes == 0)
770
- return false;
771
-
772
998
  int stack[32];
773
- stack[0] = mesh.bvh.root;
999
+ stack[0] = *mesh.bvh.root;
774
1000
 
775
1001
  int count = 1;
776
1002
 
@@ -955,7 +1181,7 @@ CUDA_CALLABLE inline bool mesh_query_point_sign_winding_number(uint64_t id, cons
955
1181
  }
956
1182
  }
957
1183
 
958
- CUDA_CALLABLE inline void adj_mesh_query_point_no_sign(uint64_t id, const vec3& point, float max_dist, int& face, float& u, float& v,
1184
+ CUDA_CALLABLE inline void adj_mesh_query_point_no_sign(uint64_t id, const vec3& point, float max_dist, const int& face, const float& u, const float& v,
959
1185
  uint64_t adj_id, vec3& adj_point, float& adj_max_dist, int& adj_face, float& adj_u, float& adj_v, bool& adj_ret)
960
1186
  {
961
1187
  Mesh mesh = mesh_get(id);
@@ -976,33 +1202,143 @@ CUDA_CALLABLE inline void adj_mesh_query_point_no_sign(uint64_t id, const vec3&
976
1202
  adj_closest_point_to_triangle(p, q, r, point, adj_p, adj_q, adj_r, adj_point, adj_uv);
977
1203
  }
978
1204
 
979
- CUDA_CALLABLE inline void adj_mesh_query_point(uint64_t id, const vec3& point, float max_dist, float& inside, int& face, float& u, float& v,
1205
+ CUDA_CALLABLE inline void adj_mesh_query_furthest_point_no_sign(uint64_t id, const vec3& point, float min_dist, const int& face, const float& u, const float& v,
1206
+ uint64_t adj_id, vec3& adj_point, float& adj_min_dist, int& adj_face, float& adj_u, float& adj_v, bool& adj_ret)
1207
+ {
1208
+ Mesh mesh = mesh_get(id);
1209
+
1210
+ // face is determined by BVH in forward pass
1211
+ int i = mesh.indices[face*3+0];
1212
+ int j = mesh.indices[face*3+1];
1213
+ int k = mesh.indices[face*3+2];
1214
+
1215
+ vec3 p = mesh.points[i];
1216
+ vec3 q = mesh.points[j];
1217
+ vec3 r = mesh.points[k];
1218
+
1219
+ vec3 adj_p, adj_q, adj_r;
1220
+
1221
+ vec2 adj_uv(adj_u, adj_v);
1222
+
1223
+ adj_closest_point_to_triangle(p, q, r, point, adj_p, adj_q, adj_r, adj_point, adj_uv); // Todo for Miles :>
1224
+ }
1225
+
1226
+ CUDA_CALLABLE inline void adj_mesh_query_point(uint64_t id, const vec3& point, float max_dist, const float& inside, const int& face, const float& u, const float& v,
980
1227
  uint64_t adj_id, vec3& adj_point, float& adj_max_dist, float& adj_inside, int& adj_face, float& adj_u, float& adj_v, bool& adj_ret)
981
1228
  {
982
1229
  adj_mesh_query_point_no_sign(id, point, max_dist, face, u, v, adj_id, adj_point, adj_max_dist, adj_face, adj_u, adj_v, adj_ret);
983
1230
  }
984
1231
 
985
- CUDA_CALLABLE inline void adj_mesh_query_point_sign_normal(uint64_t id, const vec3& point, float max_dist, float& inside, int& face, float& u, float& v, const float epsilon,
1232
+ CUDA_CALLABLE inline void adj_mesh_query_point_sign_normal(uint64_t id, const vec3& point, float max_dist, const float& inside, const int& face, const float& u, const float& v, const float epsilon,
986
1233
  uint64_t adj_id, vec3& adj_point, float& adj_max_dist, float& adj_inside, int& adj_face, float& adj_u, float& adj_v, float& adj_epsilon, bool& adj_ret)
987
1234
  {
988
1235
  adj_mesh_query_point_no_sign(id, point, max_dist, face, u, v, adj_id, adj_point, adj_max_dist, adj_face, adj_u, adj_v, adj_ret);
989
1236
  }
990
1237
 
991
- CUDA_CALLABLE inline void adj_mesh_query_point_sign_winding_number(uint64_t id, const vec3& point, float max_dist, float& inside, int& face, float& u, float& v, const float accuracy, const float winding_number_threshold,
1238
+ CUDA_CALLABLE inline void adj_mesh_query_point_sign_winding_number(uint64_t id, const vec3& point, float max_dist, const float& inside, const int& face, const float& u, const float& v, const float accuracy, const float winding_number_threshold,
992
1239
  uint64_t adj_id, vec3& adj_point, float& adj_max_dist, float& adj_inside, int& adj_face, float& adj_u, float& adj_v, float& adj_accuracy, float& adj_winding_number_threshold, bool& adj_ret)
993
1240
  {
994
1241
  adj_mesh_query_point_no_sign(id, point, max_dist, face, u, v, adj_id, adj_point, adj_max_dist, adj_face, adj_u, adj_v, adj_ret);
995
1242
  }
996
1243
 
1244
+
1245
+ // Stores the result of querying the closest point on a mesh.
1246
+ struct mesh_query_point_t
1247
+ {
1248
+ CUDA_CALLABLE mesh_query_point_t()
1249
+ {
1250
+ }
1251
+
1252
+ CUDA_CALLABLE mesh_query_point_t(int)
1253
+ {
1254
+ // For backward pass.
1255
+ }
1256
+
1257
+ bool result;
1258
+ float sign;
1259
+ int face;
1260
+ float u;
1261
+ float v;
1262
+ };
1263
+
1264
+ CUDA_CALLABLE inline mesh_query_point_t mesh_query_point(uint64_t id, const vec3& point, float max_dist)
1265
+ {
1266
+ mesh_query_point_t query;
1267
+ query.result = mesh_query_point(id, point, max_dist, query.sign, query.face, query.u, query.v);
1268
+ return query;
1269
+ }
1270
+
1271
+ CUDA_CALLABLE inline mesh_query_point_t mesh_query_point_no_sign(uint64_t id, const vec3& point, float max_dist)
1272
+ {
1273
+ mesh_query_point_t query;
1274
+ query.sign = 0.0;
1275
+ query.result = mesh_query_point_no_sign(id, point, max_dist, query.face, query.u, query.v);
1276
+ return query;
1277
+ }
1278
+
1279
+ CUDA_CALLABLE inline mesh_query_point_t mesh_query_furthest_point_no_sign(uint64_t id, const vec3& point, float min_dist)
1280
+ {
1281
+ mesh_query_point_t query;
1282
+ query.sign = 0.0;
1283
+ query.result = mesh_query_furthest_point_no_sign(id, point, min_dist, query.face, query.u, query.v);
1284
+ return query;
1285
+ }
1286
+
1287
+ CUDA_CALLABLE inline mesh_query_point_t mesh_query_point_sign_normal(uint64_t id, const vec3& point, float max_dist, const float epsilon = 1e-3f)
1288
+ {
1289
+ mesh_query_point_t query;
1290
+ query.result = mesh_query_point_sign_normal(id, point, max_dist, query.sign, query.face, query.u, query.v, epsilon);
1291
+ return query;
1292
+ }
1293
+
1294
+ CUDA_CALLABLE inline mesh_query_point_t mesh_query_point_sign_winding_number(uint64_t id, const vec3& point, float max_dist, float accuracy, float winding_number_threshold)
1295
+ {
1296
+ mesh_query_point_t query;
1297
+ query.result = mesh_query_point_sign_winding_number(id, point, max_dist, query.sign, query.face, query.u, query.v, accuracy, winding_number_threshold);
1298
+ return query;
1299
+ }
1300
+
1301
+ CUDA_CALLABLE inline void adj_mesh_query_point(uint64_t id, const vec3& point, float max_dist, const mesh_query_point_t& ret,
1302
+ uint64_t adj_id, vec3& adj_point, float& adj_max_dist, mesh_query_point_t& adj_ret)
1303
+ {
1304
+ adj_mesh_query_point(id, point, max_dist, ret.sign, ret.face, ret.u, ret.v,
1305
+ adj_id, adj_point, adj_max_dist, adj_ret.sign, adj_ret.face, adj_ret.u, adj_ret.v, adj_ret.result);
1306
+ }
1307
+
1308
+ CUDA_CALLABLE inline void adj_mesh_query_point_no_sign(uint64_t id, const vec3& point, float max_dist, const mesh_query_point_t& ret,
1309
+ uint64_t adj_id, vec3& adj_point, float& adj_max_dist, mesh_query_point_t& adj_ret)
1310
+ {
1311
+ adj_mesh_query_point_no_sign(id, point, max_dist, ret.face, ret.u, ret.v,
1312
+ adj_id, adj_point, adj_max_dist, adj_ret.face, adj_ret.u, adj_ret.v, adj_ret.result);
1313
+ }
1314
+
1315
+ CUDA_CALLABLE inline void adj_mesh_query_furthest_point_no_sign(uint64_t id, const vec3& point, float min_dist, const mesh_query_point_t& ret,
1316
+ uint64_t adj_id, vec3& adj_point, float& adj_min_dist, mesh_query_point_t& adj_ret)
1317
+ {
1318
+ adj_mesh_query_furthest_point_no_sign(id, point, min_dist, ret.face, ret.u, ret.v,
1319
+ adj_id, adj_point, adj_min_dist, adj_ret.face, adj_ret.u, adj_ret.v, adj_ret.result);
1320
+ }
1321
+
1322
+ CUDA_CALLABLE inline void adj_mesh_query_point_sign_normal(uint64_t id, const vec3& point, float max_dist, float epsilon, const mesh_query_point_t& ret,
1323
+ uint64_t adj_id, vec3& adj_point, float& adj_max_dist, float& adj_epsilon, mesh_query_point_t& adj_ret)
1324
+ {
1325
+ adj_mesh_query_point_sign_normal(id, point, max_dist, ret.sign, ret.face, ret.u, ret.v, epsilon,
1326
+ adj_id, adj_point, adj_max_dist, adj_ret.sign, adj_ret.face, adj_ret.u, adj_ret.v, epsilon, adj_ret.result);
1327
+ }
1328
+
1329
+ CUDA_CALLABLE inline void adj_mesh_query_point_sign_winding_number(uint64_t id, const vec3& point, float max_dist, float accuracy, float winding_number_threshold, const mesh_query_point_t& ret,
1330
+ uint64_t adj_id, vec3& adj_point, float& adj_max_dist, float& adj_accuracy, float& adj_winding_number_threshold, mesh_query_point_t& adj_ret)
1331
+ {
1332
+ adj_mesh_query_point_sign_winding_number(id, point, max_dist, ret.sign, ret.face, ret.u, ret.v, accuracy, winding_number_threshold,
1333
+ adj_id, adj_point, adj_max_dist, adj_ret.sign, adj_ret.face, adj_ret.u, adj_ret.v, adj_accuracy, adj_winding_number_threshold, adj_ret.result);
1334
+ }
1335
+
997
1336
  CUDA_CALLABLE inline bool mesh_query_ray(uint64_t id, const vec3& start, const vec3& dir, float max_t, float& t, float& u, float& v, float& sign, vec3& normal, int& face)
998
1337
  {
999
1338
  Mesh mesh = mesh_get(id);
1000
1339
 
1001
- if (mesh.bvh.num_nodes == 0)
1002
- return false;
1003
-
1004
1340
  int stack[32];
1005
- stack[0] = mesh.bvh.root;
1341
+ stack[0] = *mesh.bvh.root;
1006
1342
  int count = 1;
1007
1343
 
1008
1344
  vec3 rcp_dir = vec3(1.0f/dir[0], 1.0f/dir[1], 1.0f/dir[2]);
@@ -1109,6 +1445,35 @@ CUDA_CALLABLE inline void adj_mesh_query_ray(
1109
1445
  }
1110
1446
 
1111
1447
 
1448
+ // Stores the result of querying the closest point on a mesh.
1449
+ struct mesh_query_ray_t
1450
+ {
1451
+ CUDA_CALLABLE mesh_query_ray_t()
1452
+ {
1453
+ }
1454
+
1455
+ CUDA_CALLABLE mesh_query_ray_t(int)
1456
+ {
1457
+ // For backward pass.
1458
+ }
1459
+
1460
+ bool result;
1461
+ float sign;
1462
+ int face;
1463
+ float t;
1464
+ float u;
1465
+ float v;
1466
+ vec3 normal;
1467
+ };
1468
+
1469
+ CUDA_CALLABLE inline mesh_query_ray_t mesh_query_ray(uint64_t id, const vec3& start, const vec3& dir, float max_t)
1470
+ {
1471
+ mesh_query_ray_t query;
1472
+ query.result = mesh_query_ray(id, start, dir, max_t, query.t, query.u, query.v, query.sign, query.normal, query.face);
1473
+ return query;
1474
+ }
1475
+
1476
+
1112
1477
  // determine if a point is inside (ret < 0 ) or outside the mesh (ret > 0)
1113
1478
  CUDA_CALLABLE inline float mesh_query_inside(uint64_t id, const vec3& p)
1114
1479
  {
@@ -1170,19 +1535,9 @@ CUDA_CALLABLE inline mesh_query_aabb_t mesh_query_aabb(
1170
1535
  query.face = -1;
1171
1536
 
1172
1537
  Mesh mesh = mesh_get(id);
1173
-
1174
1538
  query.mesh = mesh;
1175
1539
 
1176
- // if no bvh nodes, return empty query.
1177
- if (mesh.bvh.num_nodes == 0)
1178
- {
1179
- query.count = 0;
1180
- return query;
1181
- }
1182
-
1183
- // optimization: make the latest
1184
-
1185
- query.stack[0] = mesh.bvh.root;
1540
+ query.stack[0] = *mesh.bvh.root;
1186
1541
  query.count = 1;
1187
1542
  query.input_lower = lower;
1188
1543
  query.input_upper = upper;