2017-10-10 09:57:23 +02:00
|
|
|
import bpy
|
|
|
|
|
2019-01-09 11:31:40 +01:00
|
|
|
def proxy_sync_loc(self, context):
|
|
|
|
if context.object == None or context.object.proxy == None:
|
|
|
|
return
|
|
|
|
if context.object.arm_proxy_sync_loc:
|
|
|
|
sync_location(context.object)
|
|
|
|
|
|
|
|
def proxy_sync_rot(self, context):
|
|
|
|
if context.object == None or context.object.proxy == None:
|
|
|
|
return
|
|
|
|
if context.object.arm_proxy_sync_rot:
|
|
|
|
sync_rotation(context.object)
|
|
|
|
|
|
|
|
def proxy_sync_scale(self, context):
|
|
|
|
if context.object == None or context.object.proxy == None:
|
|
|
|
return
|
|
|
|
if context.object.arm_proxy_sync_scale:
|
|
|
|
sync_scale(context.object)
|
|
|
|
|
|
|
|
def proxy_sync_materials(self, context):
|
|
|
|
if context.object == None or context.object.proxy == None:
|
|
|
|
return
|
|
|
|
if context.object.arm_proxy_sync_materials:
|
|
|
|
sync_materials(context.object)
|
|
|
|
|
|
|
|
def proxy_sync_modifiers(self, context):
|
|
|
|
if context.object == None or context.object.proxy == None:
|
|
|
|
return
|
|
|
|
if context.object.arm_proxy_sync_modifiers:
|
|
|
|
sync_modifiers(context.object)
|
|
|
|
|
|
|
|
def proxy_sync_traits(self, context):
|
|
|
|
if context.object == None or context.object.proxy == None:
|
|
|
|
return
|
|
|
|
if context.object.arm_proxy_sync_traits:
|
|
|
|
sync_traits(context.object)
|
|
|
|
|
2017-10-10 09:57:23 +02:00
|
|
|
def make(obj):
|
2017-10-17 14:24:29 +02:00
|
|
|
traverse(obj, is_parent=True)
|
2017-10-10 11:57:41 +02:00
|
|
|
|
2017-10-17 14:24:29 +02:00
|
|
|
def traverse(obj, is_parent=False):
|
2017-10-10 11:57:41 +02:00
|
|
|
if obj == None or obj.library == None or obj.proxy != None:
|
|
|
|
return
|
|
|
|
|
|
|
|
# Make proxy for all linked children
|
|
|
|
for c in obj.children:
|
|
|
|
traverse(c)
|
|
|
|
|
|
|
|
override = bpy.context.copy()
|
|
|
|
override['object'] = obj
|
2019-01-08 13:27:21 +01:00
|
|
|
bpy.context.view_layer.objects.active = obj
|
2017-10-10 11:57:41 +02:00
|
|
|
bpy.ops.object.proxy_make(override)
|
|
|
|
|
|
|
|
# Reparent created proxies
|
|
|
|
for c in obj.children:
|
|
|
|
if c.proxy != None:
|
2019-01-08 13:27:21 +01:00
|
|
|
c.parent = bpy.context.view_layer.objects.active
|
|
|
|
c.matrix_parent_inverse = bpy.context.view_layer.objects.active.matrix_world.inverted()
|
2017-10-16 21:10:33 +02:00
|
|
|
|
2019-01-08 13:27:21 +01:00
|
|
|
active = bpy.context.view_layer.objects.active
|
2017-10-17 14:24:29 +02:00
|
|
|
sync_modifiers(active)
|
|
|
|
# No transform sync for parent
|
|
|
|
if is_parent:
|
|
|
|
active.arm_proxy_sync_loc = False
|
|
|
|
active.arm_proxy_sync_rot = False
|
|
|
|
active.arm_proxy_sync_scale = False
|
2017-10-17 13:39:50 +02:00
|
|
|
|
|
|
|
def sync_location(obj):
|
2017-10-16 21:10:33 +02:00
|
|
|
obj.location = obj.proxy.location
|
|
|
|
|
2017-10-17 13:39:50 +02:00
|
|
|
def sync_rotation(obj):
|
2017-10-16 21:10:33 +02:00
|
|
|
obj.rotation_euler = obj.proxy.rotation_euler
|
|
|
|
|
2017-10-17 13:39:50 +02:00
|
|
|
def sync_scale(obj):
|
2017-10-16 21:10:33 +02:00
|
|
|
obj.scale = obj.proxy.scale
|
|
|
|
|
|
|
|
# https://blender.stackexchange.com/questions/4878
|
2017-10-17 13:39:50 +02:00
|
|
|
def sync_modifiers(obj):
|
2017-10-16 21:10:33 +02:00
|
|
|
proxy = obj.proxy
|
|
|
|
obj.modifiers.clear()
|
|
|
|
for mSrc in obj.proxy.modifiers:
|
|
|
|
mDst = obj.modifiers.get(mSrc.name, None)
|
|
|
|
if not mDst:
|
|
|
|
mDst = obj.modifiers.new(mSrc.name, mSrc.type)
|
|
|
|
|
|
|
|
# collect names of writable properties
|
|
|
|
properties = [p.identifier for p in mSrc.bl_rna.properties
|
|
|
|
if not p.is_readonly]
|
|
|
|
|
|
|
|
# copy those properties
|
|
|
|
for prop in properties:
|
|
|
|
setattr(mDst, prop, getattr(mSrc, prop))
|
|
|
|
|
|
|
|
def sync_collection(cSrc, cDst):
|
|
|
|
cDst.clear()
|
|
|
|
for mSrc in cSrc:
|
|
|
|
mDst = cDst.get(mSrc.name, None)
|
|
|
|
if not mDst:
|
|
|
|
mDst = cDst.add()
|
|
|
|
|
|
|
|
# collect names of writable properties
|
|
|
|
properties = [p.identifier for p in mSrc.bl_rna.properties
|
|
|
|
if not p.is_readonly]
|
|
|
|
|
|
|
|
# copy those properties
|
|
|
|
for prop in properties:
|
|
|
|
setattr(mDst, prop, getattr(mSrc, prop))
|
|
|
|
|
2017-10-17 13:39:50 +02:00
|
|
|
def sync_traits(obj):
|
2017-10-16 21:10:33 +02:00
|
|
|
sync_collection(obj.proxy.arm_traitlist, obj.arm_traitlist)
|
|
|
|
for i in range(0, len(obj.arm_traitlist)):
|
|
|
|
sync_collection(obj.proxy.arm_traitlist[i].arm_traitpropslist, obj.arm_traitlist[i].arm_traitpropslist)
|
|
|
|
|
2017-10-17 13:39:50 +02:00
|
|
|
def sync_materials(obj):
|
2017-10-16 21:10:33 +02:00
|
|
|
# Blender likes to crash here:(
|
2019-01-08 22:49:21 +01:00
|
|
|
pass
|
|
|
|
# proxy_mats = []
|
|
|
|
# for slot in obj.proxy.material_slots:
|
|
|
|
# proxy_mats.append(slot.name)
|
|
|
|
# override = bpy.context.copy()
|
|
|
|
# override['object'] = obj
|
|
|
|
# obj.active_material_index = 0
|
|
|
|
# for i in range(len(obj.material_slots)):
|
|
|
|
# bpy.ops.object.material_slot_remove(override)
|
|
|
|
# for slot in proxy_mats:
|
|
|
|
# bpy.ops.object.material_slot_add(override)
|
|
|
|
# obj.material_slots[-1].material = bpy.data.materials[slot]
|