Asset Pipeline v2 #145
@ -8,6 +8,8 @@ from .asset_mapping import AssetTransferMapping
|
||||
|
||||
from . import constants, util
|
||||
|
||||
from rigify.utils.misc import copy_attributes
|
||||
|
||||
|
||||
def ownership_transfer_data_cleanup(
|
||||
obj: bpy.types.Object, task_layer_name: str
|
||||
@ -339,3 +341,54 @@ def import_data_from_lib(
|
||||
)
|
||||
|
||||
return eval(f"bpy.data.{data_category}['{data_name}']")
|
||||
|
||||
|
||||
## DRIVERS
|
||||
|
||||
|
||||
def copy_driver(from_fcurve, obj, data_path=None, index=None):
|
||||
if not data_path:
|
||||
data_path = from_fcurve.data_path
|
||||
|
||||
new_fc = None
|
||||
if index:
|
||||
new_fc = obj.driver_add(data_path, index)
|
||||
else:
|
||||
new_fc = obj.driver_add(data_path)
|
||||
|
||||
copy_attributes(from_fcurve, new_fc)
|
||||
copy_attributes(from_fcurve.driver, new_fc.driver)
|
||||
|
||||
# Remove default modifiers, variables, etc.
|
||||
for m in new_fc.modifiers:
|
||||
new_fc.modifiers.remove(m)
|
||||
for v in new_fc.driver.variables:
|
||||
new_fc.driver.variables.remove(v)
|
||||
|
||||
# Copy modifiers
|
||||
for m1 in from_fcurve.modifiers:
|
||||
m2 = new_fc.modifiers.new(type=m1.type)
|
||||
copy_attributes(m1, m2)
|
||||
|
||||
# Copy variables
|
||||
for v1 in from_fcurve.driver.variables:
|
||||
v2 = new_fc.driver.variables.new()
|
||||
copy_attributes(v1, v2)
|
||||
for i in range(len(v1.targets)):
|
||||
copy_attributes(v1.targets[i], v2.targets[i])
|
||||
|
||||
return new_fc
|
||||
|
||||
|
||||
def find_drivers(obj, target_type, target_name):
|
||||
drivers = []
|
||||
for driver in obj.animation_data.drivers:
|
||||
if f'{target_type}["{target_name}"]' in driver.data_path:
|
||||
drivers.append(driver)
|
||||
return drivers
|
||||
|
||||
|
||||
def copy_all_drivers(source_obj, target_obj, driver_target_type, driver_target_name):
|
||||
fcurves = find_drivers(source_obj, driver_target_type, driver_target_name)
|
||||
for fcurve in fcurves:
|
||||
copy_driver(from_fcurve=fcurve, obj=target_obj)
|
||||
|
@ -1,7 +1,7 @@
|
||||
import bpy
|
||||
from bpy import context
|
||||
from . import transfer_core
|
||||
from .. import asset_suffix, constants, util
|
||||
from .. import asset_suffix, constants, util, core
|
||||
import mathutils
|
||||
import bmesh
|
||||
import numpy as np
|
||||
@ -224,6 +224,7 @@ def transfer_modifier(modifier_name, target_obj, source_obj):
|
||||
{"object": target_obj, "active_object": target_obj},
|
||||
modifier=mod.name,
|
||||
)
|
||||
core.copy_all_drivers(source_obj, target_obj, 'modifiers', modifier_name)
|
||||
|
||||
|
||||
# CONSTRAINTS
|
||||
|
Loading…
Reference in New Issue
Block a user