2121import inspect
2222from pathlib import Path
2323from typing import *
24- from mathutils import Matrix
24+ from mathutils import Matrix , Vector
2525
2626from ..helpers import TemporaryObject
2727from ..korlib import ConsoleToggler
@@ -258,15 +258,17 @@ def _export_actor(self, so, bo):
258258 """Exports a Coordinate Interface if we need one"""
259259 parent = bo .parent
260260 parent_bone_name = bo .parent_bone if parent is not None else None
261- offset_matrix = None
261+ offset_matrix_local = None
262+ offset_matrix_world = None
262263 if parent_bone_name and parent .plasma_object .enabled :
263264 # Object is parented to a bone, so use it instead.
264265 parent_bone = parent .data .bones [parent_bone_name ]
265266 parent = bpy .context .scene .objects [ArmatureConverter .get_bone_name (parent , parent_bone )]
266267 # ...Actually, it's parented to the bone's /tip/. So we need to offset the child...
267- offset_matrix = Matrix .Translation (bo .matrix_local .row [1 ].xyz * parent_bone .length )
268+ offset_matrix_local = Matrix .Translation (Vector ((0 , parent_bone .length , 0 )))
269+ offset_matrix_world = Matrix .Translation (bo .matrix_world .row [1 ].xyz * parent_bone .length )
268270 if self .has_coordiface (bo ):
269- self ._export_coordinate_interface (so , bo , offset_matrix )
271+ self ._export_coordinate_interface (so , bo , offset_matrix_local , offset_matrix_world )
270272
271273 # If this object has a parent, then we will need to go upstream and add ourselves to the
272274 # parent's CoordinateInterface... Because life just has to be backwards.
@@ -285,21 +287,22 @@ def _export_actor(self, so, bo):
285287 The object may not appear in the correct location or animate properly." .format (
286288 bo .name , parent .name ))
287289
288- def _export_coordinate_interface (self , so , bl , matrix : Matrix = None ):
290+ def _export_coordinate_interface (self , so , bl , offset_matrix_local : Matrix = None , offset_matrix_world : Matrix = None ):
289291 """Ensures that the SceneObject has a CoordinateInterface"""
290292 if so is None :
291293 so = self .mgr .find_create_object (plSceneObject , bl = bl )
292294 ci = None
293295 if so .coord is None :
294296 ci_cls = bl .plasma_object .ci_type
295297 ci = self .mgr .add_object (ci_cls , bl = bl , so = so )
296- if ci is not None or matrix is not None :
298+ if ci is not None or offset_matrix_local is not None or offset_matrix_world is not None :
297299 # We just created the CI, or we have an extra transform that we may have previously skipped.
298300 matrix_local = bl .matrix_local
299301 matrix_world = bl .matrix_world
300- if matrix is not None :
301- matrix_local = matrix_local * matrix
302- matrix_world = matrix_world * matrix
302+ if offset_matrix_local is not None :
303+ matrix_local = offset_matrix_local * matrix_local
304+ if offset_matrix_world is not None :
305+ matrix_world = offset_matrix_world * matrix_world
303306 # Now we have the "fun" work of filling in the CI
304307 ci .localToWorld = utils .matrix44 (matrix_world )
305308 ci .worldToLocal = ci .localToWorld .inverse ()
0 commit comments