Pose Library: Update to use the asset shelf (when enabled) #104546
@ -5,7 +5,7 @@
|
|||||||
bl_info = {
|
bl_info = {
|
||||||
"name": "Sapling Tree Gen",
|
"name": "Sapling Tree Gen",
|
||||||
"author": "Andrew Hale (TrumanBlending), Aaron Buchler, CansecoGPC",
|
"author": "Andrew Hale (TrumanBlending), Aaron Buchler, CansecoGPC",
|
||||||
"version": (0, 3, 4),
|
"version": (0, 3, 5),
|
||||||
"blender": (2, 80, 0),
|
"blender": (2, 80, 0),
|
||||||
"location": "View3D > Add > Curve",
|
"location": "View3D > Add > Curve",
|
||||||
"description": ("Adds a parametric tree. The method is presented by "
|
"description": ("Adds a parametric tree. The method is presented by "
|
||||||
@ -186,7 +186,7 @@ class ImportData(Operator):
|
|||||||
f = open(os.path.join(getPresetpaths()[1], self.filename), 'r')
|
f = open(os.path.join(getPresetpaths()[1], self.filename), 'r')
|
||||||
# Find the first non-comment, non-blank line, this must contain preset text (all on one line).
|
# Find the first non-comment, non-blank line, this must contain preset text (all on one line).
|
||||||
for settings in f:
|
for settings in f:
|
||||||
if settings and (not settings.startswith("#")):
|
if settings and (not settings.isspace()) and (not settings.startswith("#")):
|
||||||
break
|
break
|
||||||
f.close()
|
f.close()
|
||||||
# print(settings)
|
# print(settings)
|
||||||
|
@ -104,12 +104,18 @@ OBJECT_PARENT = 0x4F10 # Parent id of the object
|
|||||||
|
|
||||||
# >------ Sub defines of LIGHT
|
# >------ Sub defines of LIGHT
|
||||||
LIGHT_MULTIPLIER = 0x465B # The light energy factor
|
LIGHT_MULTIPLIER = 0x465B # The light energy factor
|
||||||
|
LIGHT_INNER_RANGE = 0x4659 # Light inner range value
|
||||||
|
LIGHT_OUTER_RANGE = 0x465A # Light outer range value
|
||||||
|
LIGHT_ATTENUATE = 0x4625 # Light attenuation flag
|
||||||
LIGHT_SPOTLIGHT = 0x4610 # The target of a spotlight
|
LIGHT_SPOTLIGHT = 0x4610 # The target of a spotlight
|
||||||
LIGHT_SPOT_ROLL = 0x4656 # Light spot roll angle
|
LIGHT_SPOT_ROLL = 0x4656 # Light spot roll angle
|
||||||
LIGHT_SPOT_SHADOWED = 0x4630 # Light spot shadow flag
|
LIGHT_SPOT_SHADOWED = 0x4630 # Light spot shadow flag
|
||||||
LIGHT_SPOT_LSHADOW = 0x4641 # Light spot shadow parameters
|
LIGHT_SPOT_LSHADOW = 0x4641 # Light spot shadow parameters
|
||||||
LIGHT_SPOT_SEE_CONE = 0x4650 # Light spot show cone flag
|
LIGHT_SPOT_SEE_CONE = 0x4650 # Light spot show cone flag
|
||||||
LIGHT_SPOT_RECTANGLE = 0x4651 # Light spot rectangle flag
|
LIGHT_SPOT_RECTANGLE = 0x4651 # Light spot rectangle flag
|
||||||
|
LIGHT_SPOT_OVERSHOOT = 0x4652 # Light spot overshoot flag
|
||||||
|
LIGHT_SPOT_PROJECTOR = 0x4653 # Light spot projection bitmap
|
||||||
|
LIGHT_SPOT_ASPECT = 0x4657 # Light spot aspect ratio
|
||||||
|
|
||||||
# >------ sub defines of CAMERA
|
# >------ sub defines of CAMERA
|
||||||
OBJECT_CAM_RANGES = 0x4720 # The camera range values
|
OBJECT_CAM_RANGES = 0x4720 # The camera range values
|
||||||
@ -1848,13 +1854,22 @@ def save(operator, context, filepath="", scale_factor=1.0, use_scene_unit=False,
|
|||||||
obj_light_chunk = _3ds_chunk(OBJECT_LIGHT)
|
obj_light_chunk = _3ds_chunk(OBJECT_LIGHT)
|
||||||
color_float_chunk = _3ds_chunk(RGB)
|
color_float_chunk = _3ds_chunk(RGB)
|
||||||
light_distance = translation[ob.name]
|
light_distance = translation[ob.name]
|
||||||
|
light_attenuate = _3ds_chunk(LIGHT_ATTENUATE)
|
||||||
|
light_inner_range = _3ds_chunk(LIGHT_INNER_RANGE)
|
||||||
|
light_outer_range = _3ds_chunk(LIGHT_OUTER_RANGE)
|
||||||
light_energy_factor = _3ds_chunk(LIGHT_MULTIPLIER)
|
light_energy_factor = _3ds_chunk(LIGHT_MULTIPLIER)
|
||||||
object_chunk.add_variable("light", _3ds_string(sane_name(ob.name)))
|
object_chunk.add_variable("light", _3ds_string(sane_name(ob.name)))
|
||||||
obj_light_chunk.add_variable("location", _3ds_point_3d(light_distance))
|
obj_light_chunk.add_variable("location", _3ds_point_3d(light_distance))
|
||||||
color_float_chunk.add_variable("color", _3ds_float_color(ob.data.color))
|
color_float_chunk.add_variable("color", _3ds_float_color(ob.data.color))
|
||||||
|
light_outer_range.add_variable("distance", _3ds_float(ob.data.cutoff_distance))
|
||||||
|
light_inner_range.add_variable("radius", _3ds_float(ob.data.shadow_soft_size))
|
||||||
light_energy_factor.add_variable("energy", _3ds_float(ob.data.energy * 0.001))
|
light_energy_factor.add_variable("energy", _3ds_float(ob.data.energy * 0.001))
|
||||||
obj_light_chunk.add_subchunk(color_float_chunk)
|
obj_light_chunk.add_subchunk(color_float_chunk)
|
||||||
|
obj_light_chunk.add_subchunk(light_outer_range)
|
||||||
|
obj_light_chunk.add_subchunk(light_inner_range)
|
||||||
obj_light_chunk.add_subchunk(light_energy_factor)
|
obj_light_chunk.add_subchunk(light_energy_factor)
|
||||||
|
if ob.data.use_custom_distance:
|
||||||
|
obj_light_chunk.add_subchunk(light_attenuate)
|
||||||
|
|
||||||
if ob.data.type == 'SPOT':
|
if ob.data.type == 'SPOT':
|
||||||
cone_angle = math.degrees(ob.data.spot_size)
|
cone_angle = math.degrees(ob.data.spot_size)
|
||||||
@ -1881,6 +1896,23 @@ def save(operator, context, filepath="", scale_factor=1.0, use_scene_unit=False,
|
|||||||
if ob.data.use_square:
|
if ob.data.use_square:
|
||||||
spot_square_chunk = _3ds_chunk(LIGHT_SPOT_RECTANGLE)
|
spot_square_chunk = _3ds_chunk(LIGHT_SPOT_RECTANGLE)
|
||||||
spotlight_chunk.add_subchunk(spot_square_chunk)
|
spotlight_chunk.add_subchunk(spot_square_chunk)
|
||||||
|
if ob.scale.x and ob.scale.y != 0.0:
|
||||||
|
spot_aspect_chunk = _3ds_chunk(LIGHT_SPOT_ASPECT)
|
||||||
|
spot_aspect_chunk.add_variable("aspect", _3ds_float(round((ob.scale.x / ob.scale.y),4)))
|
||||||
|
spotlight_chunk.add_subchunk(spot_aspect_chunk)
|
||||||
|
if ob.data.use_nodes:
|
||||||
|
links = ob.data.node_tree.links
|
||||||
|
bptype = 'EMISSION'
|
||||||
|
bpmix = 'MIX', 'MIX_RGB', 'EMISSION'
|
||||||
|
bptex = 'TEX_IMAGE', 'TEX_ENVIRONMENT'
|
||||||
|
bpout = 'ADD_SHADER', 'MIX_SHADER', 'OUTPUT_LIGHT'
|
||||||
|
bshade = next((lk.from_node.type for lk in links if lk.from_node.type == bptype and lk.to_node.type in bpout), None)
|
||||||
|
bpnode = next((lk.from_node.type for lk in links if lk.from_node.type in bpmix and lk.to_node.type == bshade), bshade)
|
||||||
|
bitmap = next((lk.from_node.image for lk in links if lk.from_node.type in bptex and lk.to_node.type == bpnode), False)
|
||||||
|
if bitmap and bitmap is not None:
|
||||||
|
spot_projector_chunk = _3ds_chunk(LIGHT_SPOT_PROJECTOR)
|
||||||
|
spot_projector_chunk.add_variable("image", _3ds_string(sane_name(bitmap.name)))
|
||||||
|
spotlight_chunk.add_subchunk(spot_projector_chunk)
|
||||||
obj_light_chunk.add_subchunk(spotlight_chunk)
|
obj_light_chunk.add_subchunk(spotlight_chunk)
|
||||||
|
|
||||||
# Add light to object chunk
|
# Add light to object chunk
|
||||||
|
@ -128,6 +128,7 @@ LIGHT_RAY_BIAS = 0x4658 # Light ray bias value
|
|||||||
LIGHT_INNER_RANGE = 0x4659 # The light inner range
|
LIGHT_INNER_RANGE = 0x4659 # The light inner range
|
||||||
LIGHT_OUTER_RANGE = 0x465A # The light outer range
|
LIGHT_OUTER_RANGE = 0x465A # The light outer range
|
||||||
LIGHT_MULTIPLIER = 0x465B # The light energy factor
|
LIGHT_MULTIPLIER = 0x465B # The light energy factor
|
||||||
|
LIGHT_ATTENUATE = 0x4625 # Light attenuation flag
|
||||||
LIGHT_AMBIENT_LIGHT = 0x4680 # Light ambient flag
|
LIGHT_AMBIENT_LIGHT = 0x4680 # Light ambient flag
|
||||||
|
|
||||||
# >------ sub defines of CAMERA
|
# >------ sub defines of CAMERA
|
||||||
@ -1128,8 +1129,14 @@ def process_next_chunk(context, file, previous_chunk, imported_objects, CONSTRAI
|
|||||||
contextMatrix = None # Reset matrix
|
contextMatrix = None # Reset matrix
|
||||||
elif CreateLightObject and new_chunk.ID == COLOR_F: # Color
|
elif CreateLightObject and new_chunk.ID == COLOR_F: # Color
|
||||||
contextLamp.data.color = read_float_array(new_chunk)
|
contextLamp.data.color = read_float_array(new_chunk)
|
||||||
|
elif CreateLightObject and new_chunk.ID == LIGHT_OUTER_RANGE: # Distance
|
||||||
|
contextLamp.data.cutoff_distance = read_float(new_chunk)
|
||||||
|
elif CreateLightObject and new_chunk.ID == LIGHT_INNER_RANGE: # Radius
|
||||||
|
contextLamp.data.shadow_soft_size = read_float(new_chunk)
|
||||||
elif CreateLightObject and new_chunk.ID == LIGHT_MULTIPLIER: # Intensity
|
elif CreateLightObject and new_chunk.ID == LIGHT_MULTIPLIER: # Intensity
|
||||||
contextLamp.data.energy = (read_float(new_chunk) * 1000)
|
contextLamp.data.energy = (read_float(new_chunk) * 1000)
|
||||||
|
elif CreateLightObject and new_chunk.ID == LIGHT_ATTENUATE: # Attenuation
|
||||||
|
contextLamp.data.use_custom_distance = True
|
||||||
|
|
||||||
# If spotlight chunk
|
# If spotlight chunk
|
||||||
elif CreateLightObject and new_chunk.ID == LIGHT_SPOTLIGHT: # Spotlight
|
elif CreateLightObject and new_chunk.ID == LIGHT_SPOTLIGHT: # Spotlight
|
||||||
@ -1137,14 +1144,14 @@ def process_next_chunk(context, file, previous_chunk, imported_objects, CONSTRAI
|
|||||||
contextLamp.data.use_shadow = False
|
contextLamp.data.use_shadow = False
|
||||||
spot = mathutils.Vector(read_float_array(new_chunk)) # Spot location
|
spot = mathutils.Vector(read_float_array(new_chunk)) # Spot location
|
||||||
aim = calc_target(contextLamp.location, spot) # Target
|
aim = calc_target(contextLamp.location, spot) # Target
|
||||||
contextLamp.rotation_euler[0] = aim[0]
|
contextLamp.rotation_euler.x = aim[0]
|
||||||
contextLamp.rotation_euler[2] = aim[1]
|
contextLamp.rotation_euler.z = aim[1]
|
||||||
hotspot = read_float(new_chunk) # Hotspot
|
hotspot = read_float(new_chunk) # Hotspot
|
||||||
beam_angle = read_float(new_chunk) # Beam angle
|
beam_angle = read_float(new_chunk) # Beam angle
|
||||||
contextLamp.data.spot_size = math.radians(beam_angle)
|
contextLamp.data.spot_size = math.radians(beam_angle)
|
||||||
contextLamp.data.spot_blend = 1.0 - (hotspot / beam_angle)
|
contextLamp.data.spot_blend = 1.0 - (hotspot / beam_angle)
|
||||||
elif CreateLightObject and new_chunk.ID == LIGHT_SPOT_ROLL: # Roll
|
elif CreateLightObject and new_chunk.ID == LIGHT_SPOT_ROLL: # Roll
|
||||||
contextLamp.rotation_euler[1] = read_float(new_chunk)
|
contextLamp.rotation_euler.y = read_float(new_chunk)
|
||||||
elif CreateLightObject and new_chunk.ID == LIGHT_SPOT_SHADOWED: # Shadow flag
|
elif CreateLightObject and new_chunk.ID == LIGHT_SPOT_SHADOWED: # Shadow flag
|
||||||
contextLamp.data.use_shadow = True
|
contextLamp.data.use_shadow = True
|
||||||
elif CreateLightObject and new_chunk.ID == LIGHT_LOCAL_SHADOW2: # Shadow parameters
|
elif CreateLightObject and new_chunk.ID == LIGHT_LOCAL_SHADOW2: # Shadow parameters
|
||||||
@ -1156,6 +1163,24 @@ def process_next_chunk(context, file, previous_chunk, imported_objects, CONSTRAI
|
|||||||
contextLamp.data.show_cone = True
|
contextLamp.data.show_cone = True
|
||||||
elif CreateLightObject and new_chunk.ID == LIGHT_SPOT_RECTANGLE: # Square flag
|
elif CreateLightObject and new_chunk.ID == LIGHT_SPOT_RECTANGLE: # Square flag
|
||||||
contextLamp.data.use_square = True
|
contextLamp.data.use_square = True
|
||||||
|
elif CreateLightObject and new_chunk.ID == LIGHT_SPOT_ASPECT: # Aspect
|
||||||
|
contextLamp.empty_display_size = read_float(new_chunk)
|
||||||
|
elif CreateLightObject and new_chunk.ID == LIGHT_SPOT_PROJECTOR: # Projection
|
||||||
|
contextLamp.data.use_nodes = True
|
||||||
|
nodes = contextLamp.data.node_tree.nodes
|
||||||
|
links = contextLamp.data.node_tree.links
|
||||||
|
gobo_name, read_str_len = read_string(file)
|
||||||
|
new_chunk.bytes_read += read_str_len
|
||||||
|
projection = nodes.new(type='ShaderNodeTexImage')
|
||||||
|
projection.label = gobo_name
|
||||||
|
projection.location = (-340, 360)
|
||||||
|
projection.image = load_image(gobo_name, dirname, place_holder=False, recursive=IMAGE_SEARCH, check_existing=True)
|
||||||
|
emitnode = next((node for node in nodes if node.type == 'EMISSION'), False)
|
||||||
|
emission = emitnode if emitnode else nodes.new(type='ShaderNodeEmission')
|
||||||
|
emission.label = "Projector"
|
||||||
|
emission.location = (0, 300)
|
||||||
|
links.new(emission.outputs['Emission'], nodes['Light Output'].inputs[0])
|
||||||
|
links.new(projection.outputs['Color'], emission.inputs[0])
|
||||||
elif CreateLightObject and new_chunk.ID == OBJECT_HIERARCHY: # Hierarchy
|
elif CreateLightObject and new_chunk.ID == OBJECT_HIERARCHY: # Hierarchy
|
||||||
child_id = get_hierarchy(new_chunk)
|
child_id = get_hierarchy(new_chunk)
|
||||||
elif CreateLightObject and new_chunk.ID == OBJECT_PARENT:
|
elif CreateLightObject and new_chunk.ID == OBJECT_PARENT:
|
||||||
@ -1177,9 +1202,9 @@ def process_next_chunk(context, file, previous_chunk, imported_objects, CONSTRAI
|
|||||||
contextCamera.location = read_float_array(new_chunk) # Position
|
contextCamera.location = read_float_array(new_chunk) # Position
|
||||||
focus = mathutils.Vector(read_float_array(new_chunk))
|
focus = mathutils.Vector(read_float_array(new_chunk))
|
||||||
direction = calc_target(contextCamera.location, focus) # Target
|
direction = calc_target(contextCamera.location, focus) # Target
|
||||||
contextCamera.rotation_euler[0] = direction[0]
|
contextCamera.rotation_euler.x = direction[0]
|
||||||
contextCamera.rotation_euler[1] = read_float(new_chunk) # Roll
|
contextCamera.rotation_euler.y = read_float(new_chunk) # Roll
|
||||||
contextCamera.rotation_euler[2] = direction[1]
|
contextCamera.rotation_euler.z = direction[1]
|
||||||
contextCamera.data.lens = read_float(new_chunk) # Focal length
|
contextCamera.data.lens = read_float(new_chunk) # Focal length
|
||||||
contextMatrix = None # Reset matrix
|
contextMatrix = None # Reset matrix
|
||||||
elif CreateCameraObject and new_chunk.ID == OBJECT_HIERARCHY: # Hierarchy
|
elif CreateCameraObject and new_chunk.ID == OBJECT_HIERARCHY: # Hierarchy
|
||||||
@ -1353,8 +1378,8 @@ def process_next_chunk(context, file, previous_chunk, imported_objects, CONSTRAI
|
|||||||
location = child.location
|
location = child.location
|
||||||
target = mathutils.Vector(read_track_data(new_chunk)[0])
|
target = mathutils.Vector(read_track_data(new_chunk)[0])
|
||||||
direction = calc_target(location, target)
|
direction = calc_target(location, target)
|
||||||
child.rotation_euler[0] = direction[0]
|
child.rotation_euler.x = direction[0]
|
||||||
child.rotation_euler[2] = direction[1]
|
child.rotation_euler.z = direction[1]
|
||||||
for keydata in keyframe_data.items():
|
for keydata in keyframe_data.items():
|
||||||
track = trackposition.get(keydata[0], child.location)
|
track = trackposition.get(keydata[0], child.location)
|
||||||
locate = mathutils.Vector(track)
|
locate = mathutils.Vector(track)
|
||||||
@ -1386,8 +1411,6 @@ def process_next_chunk(context, file, previous_chunk, imported_objects, CONSTRAI
|
|||||||
child.lock_rotation[1] = True
|
child.lock_rotation[1] = True
|
||||||
if tflags & 0x20: # Flag 0x20 locks Z axis
|
if tflags & 0x20: # Flag 0x20 locks Z axis
|
||||||
child.lock_rotation[2] = True
|
child.lock_rotation[2] = True
|
||||||
if nkeys == 0:
|
|
||||||
keyframe_rotation[0] = child.rotation_axis_angle[:]
|
|
||||||
for i in range(nkeys):
|
for i in range(nkeys):
|
||||||
nframe = read_long(new_chunk)
|
nframe = read_long(new_chunk)
|
||||||
nflags = read_short(new_chunk)
|
nflags = read_short(new_chunk)
|
||||||
@ -1434,10 +1457,10 @@ def process_next_chunk(context, file, previous_chunk, imported_objects, CONSTRAI
|
|||||||
|
|
||||||
elif KEYFRAME and new_chunk.ID == ROLL_TRACK_TAG and tracktype == 'OBJECT': # Roll angle
|
elif KEYFRAME and new_chunk.ID == ROLL_TRACK_TAG and tracktype == 'OBJECT': # Roll angle
|
||||||
keyframe_angle = {}
|
keyframe_angle = {}
|
||||||
default_value = child.rotation_euler[1]
|
default_value = child.rotation_euler.y
|
||||||
child.rotation_euler[1] = read_track_angle(new_chunk)[0]
|
child.rotation_euler.y = read_track_angle(new_chunk)[0]
|
||||||
for keydata in keyframe_angle.items():
|
for keydata in keyframe_angle.items():
|
||||||
child.rotation_euler[1] = keydata[1]
|
child.rotation_euler.y = keydata[1]
|
||||||
if hierarchy == ROOT_OBJECT:
|
if hierarchy == ROOT_OBJECT:
|
||||||
child.rotation_euler.rotate(CONVERSE)
|
child.rotation_euler.rotate(CONVERSE)
|
||||||
child.keyframe_insert(data_path="rotation_euler", index=1, frame=keydata[0])
|
child.keyframe_insert(data_path="rotation_euler", index=1, frame=keydata[0])
|
||||||
@ -1613,6 +1636,12 @@ def load_3ds(filepath, context, CONSTRAIN=10.0, UNITS=False, IMAGE_SEARCH=True,
|
|||||||
|
|
||||||
# Select all new objects
|
# Select all new objects
|
||||||
for ob in imported_objects:
|
for ob in imported_objects:
|
||||||
|
if ob.type == 'LIGHT' and ob.data.type == 'SPOT':
|
||||||
|
square = math.sqrt(pow(1.0,2) + pow(1.0,2))
|
||||||
|
aspect = ob.empty_display_size
|
||||||
|
ob.scale.x = (aspect * square / (math.sqrt(pow(aspect,2) + 1.0)))
|
||||||
|
ob.scale.y = (square / (math.sqrt(pow(aspect,2) + 1.0)))
|
||||||
|
ob.scale.z = 1.0
|
||||||
ob.select_set(True)
|
ob.select_set(True)
|
||||||
if not APPLY_MATRIX: # Reset transform
|
if not APPLY_MATRIX: # Reset transform
|
||||||
bpy.ops.object.rotation_clear()
|
bpy.ops.object.rotation_clear()
|
||||||
@ -1628,7 +1657,6 @@ def load_3ds(filepath, context, CONSTRAIN=10.0, UNITS=False, IMAGE_SEARCH=True,
|
|||||||
|
|
||||||
grp = Blender.Group.New(name)
|
grp = Blender.Group.New(name)
|
||||||
grp.objects = imported_objects
|
grp.objects = imported_objects
|
||||||
|
|
||||||
grp_ob = Object.New('Empty', name)
|
grp_ob = Object.New('Empty', name)
|
||||||
grp_ob.enableDupGroup = True
|
grp_ob.enableDupGroup = True
|
||||||
grp_ob.DupGroup = grp
|
grp_ob.DupGroup = grp
|
||||||
|
Loading…
Reference in New Issue
Block a user