@@ -176,18 +176,18 @@ def _kernel_add_vverts_to_solver(
176176 self .solver .vverts_info .support_idxs [i_vv ][j ] = support_idxs_local [i_vv_ , j ] + self ._particle_start
177177
178178 kdtree = KDTree (self ._particles )
179- _ , support_idxs = kdtree .query (self ._vverts , k = self .solver ._n_vvert_supports )
179+ _ , support_idxs = kdtree .query (self ._vverts , k = self .solver ._n_vvert_supports ). astype ( gs . np_int , copy = False )
180180 support_idxs = np .clip (support_idxs , 0 , len (self ._particles ) - 1 )
181181 all_ps = self ._particles [support_idxs ]
182- Ps = np .stack ([ all_ps [:, i , :] for i in range ( self . solver . _n_vvert_supports - 1 )], axis = 2 ) - np . expand_dims (
183- all_ps [:, - 1 , :], axis = 2
184- )
182+ Ps = np .stack (
183+ [ all_ps [:, i , :] for i in range ( self . solver . _n_vvert_supports - 1 )] , axis = 2 , dtype = gs . np_float
184+ ) - np . expand_dims ( all_ps [:, - 1 , :], axis = 2 )
185185
186186 _kernel_add_vverts_to_solver (
187- vverts = self ._vverts . astype ( gs . np_float ) ,
188- particles = self ._particles . astype ( gs . np_float ) ,
189- P_invs = np .linalg .pinv (Ps ). astype ( gs . np_float ) ,
190- support_idxs_local = support_idxs . astype ( gs . np_int ) ,
187+ vverts = self ._vverts ,
188+ particles = self ._particles ,
189+ P_invs = np .linalg .pinv (Ps ),
190+ support_idxs_local = support_idxs ,
191191 )
192192
193193 def sample (self ):
@@ -232,7 +232,9 @@ def sample(self):
232232 particles .append (particles_i )
233233
234234 elif isinstance (self ._morph , (gs .options .morphs .Primitive , gs .options .morphs .Mesh )):
235- particles = self ._vmesh .particlize (self ._particle_size , self .sampler )
235+ particles = self ._vmesh .particlize (self ._particle_size , self .sampler ).astype (
236+ gs .np_float , order = "C" , copy = False
237+ )
236238
237239 elif isinstance (self ._morph , gs .options .morphs .Nowhere ):
238240 particles = pu .nowhere_particles (self ._morph .n_particles )
@@ -244,14 +246,14 @@ def sample(self):
244246 gs .raise_exception ("Entity has zero particles." )
245247
246248 if isinstance (self ._morph , gs .options .morphs .Nowhere ):
247- origin = gu .nowhere (). astype ( gs . np_float )
248- self ._vverts = np .array ([])
249- self ._vfaces = np .array ([])
249+ origin = gu .nowhere ()
250+ self ._vverts = np .array ([], dtype = gs . np_float )
251+ self ._vfaces = np .array ([], dtype = gs . np_float )
250252
251253 elif isinstance (self ._morph , gs .options .morphs .MeshSet ):
252254 for i in range (len (self ._morph .files )):
253- pos_i = np .array (self ._morph .poss [i ])
254- quat_i = np . array ( gu . euler_to_quat ( self . _morph . eulers [ i ]) )
255+ pos_i , euler_i = map ( np .asarray , (self ._morph .poss [i ], self . _morph . eulers [ i ]) )
256+ quat_i = gs . utils . geom . xyz_to_quat ( euler_i , rpy = True , degrees = True )
255257 self ._vmesh [i ].apply_transform (gu .trans_quat_to_T (pos_i , quat_i ))
256258
257259 # NOTE: particles are transformed already
@@ -260,7 +262,7 @@ def sample(self):
260262 self .mesh_set_group_ids = np .concatenate (
261263 [np .ones ((v .shape [0 ],), dtype = gs .np_int ) * i for i , v in enumerate (particles )]
262264 )
263- particles = np .concatenate (particles )
265+ particles = np .concatenate (particles , dtype = gs . np_float )
264266 if not self ._solver .boundary .is_inside (particles ): # HACK no check
265267 gs .raise_exception (
266268 f"Entity has particles outside solver boundary. Note that for MPMSolver, boundary is slightly tighter than the specified domain due to safety padding.\n \n Current boundary:\n { self ._solver .boundary } \n \n Entity to be added:\n min: { particles .min (0 )} \n max: { particles .max (0 )} \n "
@@ -277,35 +279,43 @@ def sample(self):
277279 vertex_normals = combined_vert_normals ,
278280 )
279281 self ._vmesh = mu .trimesh_to_mesh (combined_tmesh , 1 , self ._surface )
282+
280283 if self ._need_skinning :
281- self ._vverts = np .array (self ._vmesh .verts )
282- self ._vfaces = np .array (self ._vmesh .faces )
284+ self ._vverts = np .asarray (self ._vmesh .verts , dtype = gs . np_float )
285+ self ._vfaces = np .asarray (self ._vmesh .faces , dtype = gs . np_float )
283286 else :
284- self ._vverts = np .array ([])
285- self ._vfaces = np .array ([])
287+ self ._vverts = np .asarray ([], dtype = gs . np_float )
288+ self ._vfaces = np .asarray ([], dtype = gs . np_float )
286289 origin = np .mean (self ._morph .poss , dtype = gs .np_float )
287290
288291 else :
289292 # transform vmesh
290- self ._vmesh .apply_transform (gu .trans_quat_to_T (np .array (self ._morph .pos ), np .array (self ._morph .quat )))
293+ pos , quat = map (np .asarray , (self ._morph .pos , self ._morph .quat ))
294+ self ._vmesh .apply_transform (gu .trans_quat_to_T (pos , quat ))
291295 # transform particles
292- origin = np .array (self ._morph .pos , dtype = gs .np_float )
293- particles = gu .transform_by_trans_quat (particles , np .array (self ._morph .pos ), np .array (self ._morph .quat ))
294- # rotate
296+ particles = gu .transform_by_trans_quat (
297+ particles ,
298+ np .asarray (self ._morph .pos , dtype = gs .np_float ),
299+ np .asarray (self ._morph .quat , dtype = gs .np_float ),
300+ )
295301
296302 if not self ._solver .boundary .is_inside (particles ):
297303 gs .raise_exception (
298- f"Entity has particles outside solver boundary. Note that for MPMSolver, boundary is slightly tighter than the specified domain due to safety padding.\n \n Current boundary:\n { self ._solver .boundary } \n \n Entity to be added:\n min: { particles .min (0 )} \n max: { particles .max (0 )} \n "
304+ "Entity has particles outside solver boundary. Note that for MPMSolver, boundary is slightly "
305+ "tighter than the specified domain due to safety padding.\n \n "
306+ "Current boundary:\n {self._solver.boundary}\n \n Entity to be added:\n min: {particles.min(0)}\n "
307+ "max: {particles.max(0)}\n "
299308 )
300309
301310 if self ._need_skinning :
302- self ._vverts = np .array (self ._vmesh .verts )
303- self ._vfaces = np .array (self ._vmesh .faces )
311+ self ._vverts = np .asarray (self ._vmesh .verts , dtype = gs . np_float )
312+ self ._vfaces = np .asarray (self ._vmesh .faces , dtype = gs . np_float )
304313 else :
305- self ._vverts = np .array ([])
306- self ._vfaces = np .array ([])
314+ self ._vverts = np .asarray ([], dtype = gs .np_float )
315+ self ._vfaces = np .asarray ([], dtype = gs .np_float )
316+ origin = np .array (self ._morph .pos , dtype = gs .np_float )
307317
308- self ._particles = particles . astype ( gs . np_float , order = "C" , copy = False )
318+ self ._particles = particles
309319 self ._init_particles_offset = gs .tensor (self ._particles ) - gs .tensor (origin )
310320 self ._n_particles = len (self ._particles )
311321
0 commit comments