@@ -171,7 +171,7 @@ pub fn contact_manifolds_voxels_shape<ManifoldData, ContactData>(
171171 timestamp : new_timestamp,
172172 } ;
173173
174- let vid = vox1. linear_id ;
174+ let vid = vox1. linear_id . flat_id ( ) as u32 ;
175175 let ( id1, id2) = if flipped { ( 0 , vid) } else { ( vid, 0 ) } ;
176176 manifolds. push ( ContactManifold :: with_data (
177177 id1,
@@ -329,6 +329,7 @@ impl CanonicalVoxelShape {
329329 // detection).
330330 let mins = voxels. domain ( ) [ 0 ] - Vector :: repeat ( 1 ) ;
331331 let maxs = voxels. domain ( ) [ 1 ] ;
332+ let counts = maxs - mins;
332333 let mask1 = vox. state . free_faces ( ) ;
333334
334335 let adjust_canon = |axis : AxisMask , i : usize , key : & mut Point < i32 > , val : i32 | {
@@ -348,12 +349,21 @@ impl CanonicalVoxelShape {
348349 adjust_canon ( AxisMask :: Z_NEG , 2 , & mut key_low, mins[ 2 ] ) ;
349350 }
350351
352+ #[ cfg( feature = "dim2" ) ]
353+ let workspace_id = |vox : Point < i32 > | {
354+ let local = vox - mins;
355+ ( local. x + local. y * counts. x ) as u32
356+ } ;
357+
358+ #[ cfg( feature = "dim3" ) ]
359+ let workspace_id = |vox : Point < i32 > | {
360+ let local = vox - mins;
361+ ( local. x + local. y * counts. x + local. z * counts. x * counts. y ) as u32
362+ } ;
363+
351364 Self {
352365 range : [ key_low, key_high] ,
353- workspace_key : Vector2 :: new (
354- voxels. linear_index ( key_low) ,
355- voxels. linear_index ( key_high) ,
356- ) ,
366+ workspace_key : Vector2 :: new ( workspace_id ( key_low) , workspace_id ( key_high) ) ,
357367 }
358368 }
359369
0 commit comments