Fix material move (fill opacity problem comes from blender 4.3 itself)
This commit is contained in:
@@ -10,14 +10,80 @@ from math import sqrt
|
||||
from mathutils import Vector
|
||||
from sys import platform
|
||||
|
||||
## constants values
|
||||
|
||||
|
||||
""" def get_gp_parent(layer) :
|
||||
if layer.parent_type == "BONE" and layer.parent_bone :
|
||||
return layer.parent.pose.bones.get(layer.parent_bone)
|
||||
else :
|
||||
return layer.parent
|
||||
"""
|
||||
## Default stroke and points attributes
|
||||
stroke_attr = [
|
||||
'start_cap',
|
||||
'end_cap',
|
||||
'softness',
|
||||
'material_index',
|
||||
'fill_opacity',
|
||||
'fill_color',
|
||||
'cyclic',
|
||||
'aspect_ratio',
|
||||
'time_start',
|
||||
# 'curve_type', # read-only
|
||||
]
|
||||
|
||||
point_attr = [
|
||||
'position',
|
||||
'radius',
|
||||
'rotation',
|
||||
'opacity',
|
||||
'vertex_color',
|
||||
'delta_time',
|
||||
# 'select',
|
||||
]
|
||||
|
||||
### Attribute value, types and shape
|
||||
|
||||
attribute_value_string = {
|
||||
'FLOAT': "value",
|
||||
'INT': "value",
|
||||
'FLOAT_VECTOR': "vector",
|
||||
'FLOAT_COLOR': "color",
|
||||
'BYTE_COLOR': "color",
|
||||
'STRING': "value",
|
||||
'BOOLEAN': "value",
|
||||
'FLOAT2': "value",
|
||||
'INT8': "value",
|
||||
'INT32_2D': "value",
|
||||
'QUATERNION': "value",
|
||||
'FLOAT4X4': "value",
|
||||
}
|
||||
|
||||
attribute_value_dtype = {
|
||||
'FLOAT': np.float32,
|
||||
'INT': np.dtype('int'),
|
||||
'FLOAT_VECTOR': np.float32,
|
||||
'FLOAT_COLOR': np.float32,
|
||||
'BYTE_COLOR': np.int8,
|
||||
'STRING': np.dtype('str'),
|
||||
'BOOLEAN': np.dtype('bool'),
|
||||
'FLOAT2': np.float32,
|
||||
'INT8': np.int8,
|
||||
'INT32_2D': np.dtype('int'),
|
||||
'QUATERNION': np.float32,
|
||||
'FLOAT4X4': np.float32,
|
||||
}
|
||||
|
||||
attribute_value_shape = {
|
||||
'FLOAT': (),
|
||||
'INT': (),
|
||||
'FLOAT_VECTOR': (3,),
|
||||
'FLOAT_COLOR': (4,),
|
||||
'BYTE_COLOR': (4,),
|
||||
'STRING': (),
|
||||
'BOOLEAN': (),
|
||||
'FLOAT2':(2,),
|
||||
'INT8': (),
|
||||
'INT32_2D': (2,),
|
||||
'QUATERNION': (4,),
|
||||
'FLOAT4X4': (4,4),
|
||||
}
|
||||
|
||||
|
||||
def translate_range(OldValue, OldMin, OldMax, NewMax, NewMin):
|
||||
return (((OldValue - OldMin) * (NewMax - NewMin)) / (OldMax - OldMin)) + NewMin
|
||||
@@ -557,64 +623,30 @@ def copy_stroke_to_frame(s, frame, select=True):
|
||||
return created stroke
|
||||
'''
|
||||
|
||||
ns = frame.drawing.strokes.new()
|
||||
|
||||
## Set strokes attr
|
||||
stroke_attr = [
|
||||
'line_width',
|
||||
'material_index',
|
||||
'draw_cyclic',
|
||||
'use_cyclic',
|
||||
'uv_scale',
|
||||
'uv_rotation',
|
||||
'hardness',
|
||||
'uv_translation',
|
||||
'vertex_color_fill',
|
||||
]
|
||||
frame.drawing.add_strokes([len(s.points)])
|
||||
ns = frame.drawing.strokes[-1]
|
||||
# print(len(s.points), 'new:', len(ns.points))
|
||||
#ns.material_index
|
||||
|
||||
## replicate attributes (simple loop)
|
||||
## TODO : might need to create atribute domain if does not exists in destination
|
||||
for attr in stroke_attr:
|
||||
if not hasattr(s, attr):
|
||||
continue
|
||||
# print(f'transfer stroke {attr}') # Dbg
|
||||
setattr(ns, attr, getattr(s, attr))
|
||||
|
||||
## create points
|
||||
point_count = len(s.points)
|
||||
ns.points.add(len(s.points))
|
||||
|
||||
## Set points attr
|
||||
# for p, np in zip(s.points, ns.points):
|
||||
flat_list = [0.0] * point_count
|
||||
flat_uv_fill_list = [0.0, 0.0] * point_count
|
||||
flat_vector_list = [0.0, 0.0, 0.0] * point_count
|
||||
flat_color_list = [0.0, 0.0, 0.0, 0.0] * point_count
|
||||
|
||||
single_attr = [
|
||||
'pressure',
|
||||
'strength',
|
||||
'uv_factor',
|
||||
'uv_rotation',
|
||||
]
|
||||
for src_p, dest_p in zip(s.points, ns.points):
|
||||
for attr in point_attr:
|
||||
setattr(dest_p, attr, getattr(src_p, attr))
|
||||
## Define selection
|
||||
dest_p.select=select
|
||||
|
||||
for attr in single_attr:
|
||||
# print(f'transfer point {attr}') # Dbg
|
||||
s.points.foreach_get(attr, flat_list)
|
||||
ns.points.foreach_set(attr, flat_list)
|
||||
## Direcly iterate over attribute ?
|
||||
# src_start = src_dr.curve_offsets[0].value
|
||||
# src_end = src_start + data_size
|
||||
# dst_start = dst_dr.curve_offsets[0].value
|
||||
# dst_end = dst_start + data_size
|
||||
# for src_idx, dest_idx in zip(range(src_start, src_end),range(dst_start, dst_end)):
|
||||
# setattr(dest_attr.data[dest_idx], val_type, getattr(source_attr.data[src_idx], val_type))
|
||||
|
||||
# print(f'transfer point co') # Dbg
|
||||
s.points.foreach_get('co', flat_vector_list)
|
||||
ns.points.foreach_set('co', flat_vector_list)
|
||||
|
||||
# print(f'transfer point uv_fill') # Dbg
|
||||
s.points.foreach_get('uv_fill', flat_uv_fill_list)
|
||||
ns.points.foreach_set('uv_fill', flat_uv_fill_list)
|
||||
|
||||
# print(f'transfer point vertex_color') # Dbg
|
||||
s.points.foreach_get('vertex_color', flat_color_list)
|
||||
ns.points.foreach_set('vertex_color', flat_color_list)
|
||||
|
||||
ns.select = select
|
||||
ns.points.update()
|
||||
return ns
|
||||
|
||||
"""## Works, but do not copy all attributes type (probably ok for GP though)
|
||||
@@ -657,52 +689,6 @@ def bulk_frame_copy_attributes(source_attr, target_attr):
|
||||
# setattr(dest_attr.data[dest_idx], val_type, getattr(source_attr.data[src_idx], val_type))
|
||||
"""
|
||||
|
||||
attribute_value_string = {
|
||||
'FLOAT': "value",
|
||||
'INT': "value",
|
||||
'FLOAT_VECTOR': "vector",
|
||||
'FLOAT_COLOR': "color",
|
||||
'BYTE_COLOR': "color",
|
||||
'STRING': "value",
|
||||
'BOOLEAN': "value",
|
||||
'FLOAT2': "value",
|
||||
'INT8': "value",
|
||||
'INT32_2D': "value",
|
||||
'QUATERNION': "value",
|
||||
'FLOAT4X4': "value",
|
||||
}
|
||||
|
||||
attribute_value_dtype = {
|
||||
'FLOAT': np.float32,
|
||||
'INT': np.dtype('int'),
|
||||
'FLOAT_VECTOR': np.float32,
|
||||
'FLOAT_COLOR': np.float32,
|
||||
'BYTE_COLOR': np.int8,
|
||||
'STRING': np.dtype('str'),
|
||||
'BOOLEAN': np.dtype('bool'),
|
||||
'FLOAT2': np.float32,
|
||||
'INT8': np.int8,
|
||||
'INT32_2D': np.dtype('int'),
|
||||
'QUATERNION': np.float32,
|
||||
'FLOAT4X4': np.float32,
|
||||
}
|
||||
|
||||
attribute_value_shape = {
|
||||
'FLOAT': (),
|
||||
'INT': (),
|
||||
'FLOAT_VECTOR': (3,),
|
||||
'FLOAT_COLOR': (4,),
|
||||
'BYTE_COLOR': (4,),
|
||||
'STRING': (),
|
||||
'BOOLEAN': (),
|
||||
'FLOAT2':(2,),
|
||||
'INT8': (),
|
||||
'INT32_2D': (2,),
|
||||
'QUATERNION': (4,),
|
||||
'FLOAT4X4': (4,4),
|
||||
}
|
||||
|
||||
|
||||
def bulk_copy_attributes(source_attr, target_attr):
|
||||
'''Get and apply data as flat numpy array based on attribute type'''
|
||||
value_string = attribute_value_string[source_attr.data_type]
|
||||
|
||||
Reference in New Issue
Block a user