def __call__(cls, bdata, armature=None):
if bdata is None:
return None
dup_mat = None
if isinstance(bdata, Object):
key = get_blenderID_key(bdata)
elif isinstance(bdata, DupliObject):
key = "|".join((get_blenderID_key((bdata.id_data, bdata.object)), cls._get_dup_num_id(bdata)))
dup_mat = bdata.matrix.copy()
else: # isinstance(bdata, (Bone, PoseBone)):
if isinstance(bdata, PoseBone):
bdata = armature.data.bones[bdata.name]
key = get_blenderID_key((armature, bdata))
cache = getattr(cls, "_cache", None)
if cache is None:
cache = cls._cache = {}
instance = cache.get(key)
if instance is not None:
# Duplis hack: since duplis are not persistent in Blender (we have to re-create them to get updated
# info like matrix...), we *always* need to reset that matrix when calling ObjectWrapper() (all
# other data is supposed valid during whole cache live, so we can skip resetting it).
instance._dupli_matrix = dup_mat
return instance
instance = cls.__new__(cls, bdata, armature)
instance.__init__(bdata, armature)
instance.key = key
instance._dupli_matrix = dup_mat
cache[key] = instance
return instance
评论列表
文章目录