Skip to content

Commit 9e54591

Browse files
committed
Merge pull request sugiany#36 from lordscales91/0.5-pre-release
Fixed Tail location issue
2 parents 3e06f29 + 9a0193c commit 9e54591

File tree

3 files changed

+40
-5
lines changed

3 files changed

+40
-5
lines changed

mmd_tools/core/pmx/exporter.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,19 +248,29 @@ def __exportBones(self):
248248

249249
if p_bone.mmd_bone.is_tip:
250250
pmx_bone.displayConnection = -1
251+
elif p_bone.mmd_bone.use_tail_location:
252+
tail_loc = world_mat * mathutils.Vector(bone.tail) * self.__scale * self.TO_PMX_MATRIX
253+
pmx_bone.displayConnection = tail_loc - pmx_bone.location
251254
else:
252255
for child in bone.children:
253256
if child.use_connect:
254257
pmx_bone.displayConnection = child
255258
break
256-
if not pmx_bone.displayConnection:
257-
pmx_bone.displayConnection = bone.tail - bone.head
259+
#if not pmx_bone.displayConnection: #I think this wasn't working properly
260+
#pmx_bone.displayConnection = bone.tail - bone.head
258261

262+
#add fixed and local axes
263+
if mmd_bone.enabled_fixed_axis:
264+
pmx_bone.axis = mmd_bone.fixed_axis
259265

260-
for i in pmx_bones:
266+
if mmd_bone.enabled_local_axes:
267+
pmx_bone.localCoordinate = pmx.Coordinate(
268+
mmd_bone.local_axis_x, mmd_bone.local_axis_z)
269+
270+
for idx, i in enumerate(pmx_bones):
261271
if i.parent is not None:
262272
i.parent = pmx_bones.index(boneMap[i.parent])
263-
logging.debug('the parent of %s: %s', i.name, i.parent)
273+
logging.debug('the parent of %s:%s: %s', idx, i.name, i.parent)
264274
if isinstance(i.displayConnection, pmx.Bone):
265275
i.displayConnection = pmx_bones.index(i.displayConnection)
266276
elif isinstance(i.displayConnection, bpy.types.EditBone):

mmd_tools/core/pmx/importer.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,12 @@ def __importBones(self):
240240
b_bone.mmd_bone.transform_order = p_bone.transform_order
241241
b_bone.mmd_bone.is_visible = p_bone.visible
242242
b_bone.mmd_bone.is_controllable = p_bone.isControllable
243-
b_bone.mmd_bone.is_tip = (p_bone.displayConnection == -1)
243+
244+
if isinstance(p_bone.displayConnection, int):
245+
b_bone.mmd_bone.is_tip = (p_bone.displayConnection == -1)
246+
else:
247+
b_bone.mmd_bone.use_tail_location = True
248+
244249
b_bone.bone.hide = b_bone.mmd_bone.is_tip or not p_bone.visible
245250

246251
if not p_bone.isRotatable:
@@ -266,6 +271,10 @@ def __importBones(self):
266271
b_bone.mmd_bone.local_axis_x = p_bone.localCoordinate.x_axis
267272
b_bone.mmd_bone.local_axis_z = p_bone.localCoordinate.z_axis
268273

274+
if p_bone.axis is not None:
275+
b_bone.mmd_bone.enabled_fixed_axis = True
276+
b_bone.mmd_bone.fixed_axis=p_bone.axis
277+
269278
if b_bone.mmd_bone.is_tip:
270279
b_bone.lock_rotation = [True, True, True]
271280
b_bone.lock_location = [True, True, True]

mmd_tools/properties/bone.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,22 @@ class MMDBone(PropertyGroup):
6767
default=False,
6868
)
6969

70+
use_tail_location = BoolProperty(
71+
name='Use Tail Location',
72+
default=False,
73+
)
74+
75+
enabled_fixed_axis = BoolProperty(
76+
name='Use Fixed Axis',
77+
default=False,
78+
)
79+
80+
fixed_axis = FloatVectorProperty(
81+
name='Fixed Axis',
82+
size=3,
83+
default=[0, 0, 0],
84+
)
85+
7086
enabled_local_axes = BoolProperty(
7187
name='Use Local Axes',
7288
default=False,

0 commit comments

Comments
 (0)