Skip to content

Commit c70d602

Browse files
committed
2.2.3
fix to iClone 8.06 accessory export error.
1 parent fddf935 commit c70d602

File tree

4 files changed

+143
-126
lines changed

4 files changed

+143
-126
lines changed

utp/cc.py

Lines changed: 74 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1725,14 +1725,23 @@ def get_extended_skin_bones(obj, skin_bones: list=None, ignore_pivot=False):
17251725
objects.extend(child_objects)
17261726
skin_bones = []
17271727
for obj in objects:
1728-
SC = obj.GetSkeletonComponent()
1729-
skin_bones = SC.GetSkinBones()
1730-
for bone in skin_bones:
1731-
if bone not in skin_bones:
1732-
skin_bones.append(bone)
1728+
SC = safe_get_skeleton_component(obj)
1729+
if SC:
1730+
skin_bones = SC.GetSkinBones()
1731+
for bone in skin_bones:
1732+
if bone not in skin_bones:
1733+
skin_bones.append(bone)
17331734
return skin_bones
17341735

17351736

1737+
def safe_get_skeleton_component(obj: RIObject) -> RISkeletonComponent:
1738+
try:
1739+
if hasattr(obj, "GetSkeletonComponent"):
1740+
return obj.GetSkeletonComponent()
1741+
return None
1742+
except:
1743+
return None
1744+
17361745
def get_extended_skin_bones_tree(avatar_or_prop: RIObject):
17371746

17381747
child_objects: list = RScene.FindChildObjects(avatar_or_prop, EObjectType_Prop | EObjectType_Accessory)
@@ -1742,33 +1751,34 @@ def get_extended_skin_bones_tree(avatar_or_prop: RIObject):
17421751
bone_defs = {}
17431752
defs = []
17441753
for obj in objects:
1745-
SC = obj.GetSkeletonComponent()
1746-
root = SC.GetRootBone()
1747-
skin_bones = SC.GetSkinBones()
1748-
if skin_bones:
1749-
num_bones = 0
1750-
for bone in skin_bones:
1751-
if bone.GetName():
1752-
num_bones += 1
1753-
bone: RINode
1754-
if num_bones > 0:
1755-
link_id = get_link_id(obj, add_if_missing=True)
1756-
for bone in skin_bones:
1757-
if bone.GetID() not in bone_defs:
1758-
bone_name = bone.GetName()
1759-
if bone_name:
1760-
bone_def = {
1761-
"bone": bone,
1762-
"id": bone.GetID(),
1763-
"object": obj,
1764-
"root": bone.GetID() == root.GetID(),
1765-
"name": bone_name,
1766-
"children": [],
1767-
"parent": bone.GetParent(),
1768-
"SC": SC,
1769-
}
1770-
bone_defs[bone.GetID()] = bone_def
1771-
defs.append(bone_def)
1754+
SC = safe_get_skeleton_component(obj)
1755+
if SC:
1756+
root = SC.GetRootBone()
1757+
skin_bones = SC.GetSkinBones()
1758+
if skin_bones:
1759+
num_bones = 0
1760+
for bone in skin_bones:
1761+
if bone.GetName():
1762+
num_bones += 1
1763+
bone: RINode
1764+
if num_bones > 0:
1765+
link_id = get_link_id(obj, add_if_missing=True)
1766+
for bone in skin_bones:
1767+
if bone.GetID() not in bone_defs:
1768+
bone_name = bone.GetName()
1769+
if bone_name:
1770+
bone_def = {
1771+
"bone": bone,
1772+
"id": bone.GetID(),
1773+
"object": obj,
1774+
"root": bone.GetID() == root.GetID(),
1775+
"name": bone_name,
1776+
"children": [],
1777+
"parent": bone.GetParent(),
1778+
"SC": SC,
1779+
}
1780+
bone_defs[bone.GetID()] = bone_def
1781+
defs.append(bone_def)
17721782

17731783
orphaned = []
17741784
for bone_def in defs:
@@ -1886,37 +1896,38 @@ def get_extended_skin_bones_tree_debug(prop: RIObject):
18861896
utils.log_always(f"loc: {[t.x, t.y, t.z]}")
18871897
utils.log_always(f"rot: {[r.x, r.y, r.z, r.w]}")
18881898
utils.log_always(f"sca: {[s.x, s.y, s.z]}")
1889-
SC = obj.GetSkeletonComponent()
1890-
root = SC.GetRootBone()
1891-
skin_bones = SC.GetSkinBones()
1892-
if skin_bones:
1893-
num_bones = 0
1894-
for bone in skin_bones:
1895-
if bone.GetName():
1896-
num_bones += 1
1897-
bone: RINode
1898-
if num_bones > 0:
1899-
link_id = get_link_id(obj, add_if_missing=True)
1900-
for bone in skin_bones:
1901-
if bone.GetID() not in bone_defs:
1902-
bone_name = bone.GetName()
1903-
T: RTransform = bone.WorldTransform()
1904-
t: RVector3 = T.T()
1905-
r: RQuaternion = T.R()
1906-
s: RVector3 = T.S()
1907-
if bone_name:
1908-
bone_def = {
1909-
"bone": bone,
1910-
"object": obj.GetName(),
1911-
"root": bone.GetID() == root.GetID(),
1912-
"name": bone_name,
1913-
"loc": [t.x, t.y, t.z],
1914-
"rot": [r.x, r.y, r.z, r.w],
1915-
"sca": [s.x, s.y, s.z],
1916-
"children": [],
1917-
}
1918-
bone_defs[bone.GetID()] = bone_def
1919-
defs.append(bone_def)
1899+
SC = safe_get_skeleton_component(obj)
1900+
if SC:
1901+
root = SC.GetRootBone()
1902+
skin_bones = SC.GetSkinBones()
1903+
if skin_bones:
1904+
num_bones = 0
1905+
for bone in skin_bones:
1906+
if bone.GetName():
1907+
num_bones += 1
1908+
bone: RINode
1909+
if num_bones > 0:
1910+
link_id = get_link_id(obj, add_if_missing=True)
1911+
for bone in skin_bones:
1912+
if bone.GetID() not in bone_defs:
1913+
bone_name = bone.GetName()
1914+
T: RTransform = bone.WorldTransform()
1915+
t: RVector3 = T.T()
1916+
r: RQuaternion = T.R()
1917+
s: RVector3 = T.S()
1918+
if bone_name:
1919+
bone_def = {
1920+
"bone": bone,
1921+
"object": obj.GetName(),
1922+
"root": bone.GetID() == root.GetID(),
1923+
"name": bone_name,
1924+
"loc": [t.x, t.y, t.z],
1925+
"rot": [r.x, r.y, r.z, r.w],
1926+
"sca": [s.x, s.y, s.z],
1927+
"children": [],
1928+
}
1929+
bone_defs[bone.GetID()] = bone_def
1930+
defs.append(bone_def)
19201931
for bone_def in defs:
19211932
bone = bone_def["bone"]
19221933
bone_name = bone_def["name"]

utp/exporter.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -963,22 +963,23 @@ def export_extra_data(self):
963963
root_json["Root Bones"] = cc.extract_root_bones_from_tree(root_def)
964964
for obj in objects:
965965
obj_name = obj.GetName()
966-
SC: RISkeletonComponent = obj.GetSkeletonComponent()
967-
root_bone = SC.GetRootBone()
968-
root_name = root_bone.GetName() if root_bone else ""
969-
skin_bones = SC.GetSkinBones()
970-
skin_bone_names = [ b.GetName() for b in skin_bones if b.GetName() ] if skin_bones else []
971-
obj_type = cc.get_object_type(obj)
972-
if obj_type != "NONE" and skin_bone_names:
973-
id = cc.get_link_id(obj, add_if_missing=True)
974-
info_obj_json = {
975-
"Link_ID": id,
976-
"Name": obj_name,
977-
"Type": obj_type,
978-
"Root": root_name,
979-
"Bones": skin_bone_names,
980-
}
981-
info_json.append(info_obj_json)
966+
SC = cc.safe_get_skeleton_component(obj)
967+
if SC:
968+
root_bone = SC.GetRootBone()
969+
root_name = root_bone.GetName() if root_bone else ""
970+
skin_bones = SC.GetSkinBones()
971+
skin_bone_names = [ b.GetName() for b in skin_bones if b.GetName() ] if skin_bones else []
972+
obj_type = cc.get_object_type(obj)
973+
if obj_type != "NONE" and skin_bone_names:
974+
id = cc.get_link_id(obj, add_if_missing=True)
975+
info_obj_json = {
976+
"Link_ID": id,
977+
"Name": obj_name,
978+
"Type": obj_type,
979+
"Root": root_name,
980+
"Bones": skin_bone_names,
981+
}
982+
info_json.append(info_obj_json)
982983
root_json["Object_Info"] = info_json
983984

984985
# Update JSON data

utp/link.py

Lines changed: 51 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,7 @@ def end_editing(self, time):
211211

212212
def get_skeleton_component(self) -> RISkeletonComponent:
213213
if self.object:
214-
if cc.is_avatar(self.object) or cc.is_prop(self.object):
215-
return self.object.GetSkeletonComponent()
214+
return cc.safe_get_skeleton_component(self.object)
216215
return None
217216

218217
def get_face_component(self) -> RIFaceComponent:
@@ -573,37 +572,41 @@ def set_project_range(end_time: RTime):
573572

574573
def get_clip_at_or_before(avatar: RIAvatar, time: RTime):
575574
fps = get_local_fps()
576-
SC: RISkeletonComponent = avatar.GetSkeletonComponent()
577-
num_clips = SC.GetClipCount()
578575
found_clip: RIClip = None
579-
nearest_end_time: RTime = None
580-
for i in range(0, num_clips):
581-
clip:RIClip = SC.GetClip(i)
582-
clip_start = clip.ClipTimeToSceneTime(fps.IndexedFrameTime(0))
583-
length = clip.GetClipLength()
584-
clip_end = clip.ClipTimeToSceneTime(length)
585-
if time >= clip_start and time <= clip_end:
586-
found_clip = clip
587-
return found_clip
588-
elif time > clip_end:
589-
if not found_clip or clip_end > nearest_end_time:
576+
SC = cc.safe_get_skeleton_component(avatar)
577+
if SC:
578+
num_clips = SC.GetClipCount()
579+
nearest_end_time: RTime = None
580+
for i in range(0, num_clips):
581+
clip:RIClip = SC.GetClip(i)
582+
clip_start = clip.ClipTimeToSceneTime(fps.IndexedFrameTime(0))
583+
length = clip.GetClipLength()
584+
clip_end = clip.ClipTimeToSceneTime(length)
585+
if time >= clip_start and time <= clip_end:
590586
found_clip = clip
591-
nearest_end_time = clip_end
587+
return found_clip
588+
elif time > clip_end:
589+
if not found_clip or clip_end > nearest_end_time:
590+
found_clip = clip
591+
nearest_end_time = clip_end
592592
return found_clip
593593

594594

595595
def make_avatar_clip(avatar, start_time, num_frames):
596596
fps = get_local_fps()
597-
SC: RISkeletonComponent = avatar.GetSkeletonComponent()
598-
clip: RIClip = SC.AddClip(start_time)
599-
length = fps.IndexedFrameTime(num_frames)
600-
clip.SetLength(length)
597+
SC = cc.safe_get_skeleton_component(avatar)
598+
clip: RIClip = None
599+
if SC:
600+
clip = SC.AddClip(start_time)
601+
length = fps.IndexedFrameTime(num_frames)
602+
clip.SetLength(length)
601603
return clip
602604

603605

604606
def finalize_avatar_clip(avatar, clip):
605-
SC: RISkeletonComponent = avatar.GetSkeletonComponent()
606-
SC.BakeFkToIk(RTime.FromValue(0), True)
607+
SC = cc.safe_get_skeleton_component(avatar)
608+
if SC:
609+
SC.BakeFkToIk(RTime.FromValue(0), True)
607610

608611

609612
def decompose_transform(T: RTransform):
@@ -634,36 +637,38 @@ def apply_pose(actor: LinkActor, time: RTime, pose_data, shape_data, t_pose_data
634637

635638

636639
def get_pose_local(avatar: RIAvatar):
637-
SC: RISkeletonComponent = avatar.GetSkeletonComponent()
638-
skin_bones = SC.GetSkinBones()
640+
SC = cc.safe_get_skeleton_component(avatar)
639641
pose = {}
640-
for bone in skin_bones:
641-
T: RTransform = bone.LocalTransform()
642-
t: RVector3 = T.T()
643-
r: RQuaternion = T.R()
644-
s: RVector3 = T.S()
645-
pose[bone.GetName()] = [
646-
t.x, t.y, t.z,
647-
r.x, r.y, r.z, r.w,
648-
s.x, s.y, s.z,
649-
]
642+
if SC:
643+
skin_bones = SC.GetSkinBones()
644+
for bone in skin_bones:
645+
T: RTransform = bone.LocalTransform()
646+
t: RVector3 = T.T()
647+
r: RQuaternion = T.R()
648+
s: RVector3 = T.S()
649+
pose[bone.GetName()] = [
650+
t.x, t.y, t.z,
651+
r.x, r.y, r.z, r.w,
652+
s.x, s.y, s.z,
653+
]
650654
return pose
651655

652656

653657
def get_pose_world(avatar: RIAvatar):
654-
SC: RISkeletonComponent = avatar.GetSkeletonComponent()
655-
skin_bones = SC.GetSkinBones()
658+
SC = cc.safe_get_skeleton_component(avatar)
656659
pose = {}
657-
for bone in skin_bones:
658-
T: RTransform = bone.WorldTransform()
659-
t: RVector3 = T.T()
660-
r: RQuaternion = T.R()
661-
s: RVector3 = T.S()
662-
pose[bone.GetName()] = [
663-
t.x, t.y, t.z,
664-
r.x, r.y, r.z, r.w,
665-
s.x, s.y, s.z,
666-
]
660+
if SC:
661+
skin_bones = SC.GetSkinBones()
662+
for bone in skin_bones:
663+
T: RTransform = bone.WorldTransform()
664+
t: RVector3 = T.T()
665+
r: RQuaternion = T.R()
666+
s: RVector3 = T.S()
667+
pose[bone.GetName()] = [
668+
t.x, t.y, t.z,
669+
r.x, r.y, r.z, r.w,
670+
s.x, s.y, s.z,
671+
]
667672
return pose
668673

669674

utp/vars.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
from RLPy import *
1818

19-
VERSION = "2.2.2"
19+
VERSION = "2.2.3"
2020
DEV = False
2121
DEV_NAME = "SOUPDEV"
2222
AVATAR_TYPES = {

0 commit comments

Comments
 (0)