Proper scroll speed units + scene fps accounted for

This commit is contained in:
William Herald Snyder 2022-10-03 08:38:13 -04:00
parent 188b270ad1
commit 69e959e7a3
1 changed files with 36 additions and 37 deletions

View File

@ -118,9 +118,10 @@ to provide an exact emulation"""
texture_input_nodes = [] texture_input_nodes = []
surface_output_nodes = [] surface_output_nodes = []
diffuse_texture_path = mat_props.diffuse_map diffuse_texture_path = mat_props.diffuse_map
if diffuse_texture_path and os.path.exists(diffuse_texture_path): if diffuse_texture_path and os.path.exists(diffuse_texture_path):
material.use_nodes = True material.use_nodes = True
material.node_tree.nodes.clear() material.node_tree.nodes.clear()
@ -161,56 +162,54 @@ to provide an exact emulation"""
surface_output_nodes.append(tuple(("Emission", emission))) surface_output_nodes.append(tuple(("Emission", emission)))
surfaces_output = None
if (len(surface_output_nodes) == 1):
surfaces_output = surface_output_nodes[0][1]
else:
mix = material.node_tree.nodes.new("ShaderNodeMixShader")
material.node_tree.links.new(mix.inputs[1], surface_output_nodes[0][1].outputs[0])
material.node_tree.links.new(mix.inputs[2], surface_output_nodes[1][1].outputs[0])
surfaces_output = None surfaces_output = mix
if (len(surface_output_nodes) == 1):
surfaces_output = surface_output_nodes[0][1]
else:
mix = material.node_tree.nodes.new("ShaderNodeMixShader")
material.node_tree.links.new(mix.inputs[1], surface_output_nodes[0][1].outputs[0])
material.node_tree.links.new(mix.inputs[2], surface_output_nodes[1][1].outputs[0])
surfaces_output = mix
output = material.node_tree.nodes.new("ShaderNodeOutputMaterial") output = material.node_tree.nodes.new("ShaderNodeOutputMaterial")
material.node_tree.links.new(output.inputs['Surface'], surfaces_output.outputs[0]) material.node_tree.links.new(output.inputs['Surface'], surfaces_output.outputs[0])
# Clear all anims in all cases # Clear all anims in all cases
if material.node_tree.animation_data: if material.node_tree.animation_data:
material.node_tree.animation_data.action.fcurves.clear() material.node_tree.animation_data.action.fcurves.clear()
if "SCROLL" in mat_props.rendertype: if "SCROLL" in mat_props.rendertype:
uv_input = material.node_tree.nodes.new("ShaderNodeUVMap") uv_input = material.node_tree.nodes.new("ShaderNodeUVMap")
vector_add = material.node_tree.nodes.new("ShaderNodeVectorMath") vector_add = material.node_tree.nodes.new("ShaderNodeVectorMath")
# Add keyframes # Add keyframes
scroll_speed_divisor = 360.0 scroll_per_sec_divisor = 255.0
for i in range(4): frame_step = 60.0
vector_add.inputs[1].default_value[0] = i * mat_props.scroll_speed_u fps = bpy.context.scene.render.fps
vector_add.inputs[1].keyframe_insert("default_value", index=0, frame=i * scroll_speed_divisor) for i in range(2):
vector_add.inputs[1].default_value[0] = i * mat_props.scroll_speed_u * frame_step / scroll_per_sec_divisor
vector_add.inputs[1].keyframe_insert("default_value", index=0, frame=i * frame_step * fps)
vector_add.inputs[1].default_value[1] = i * mat_props.scroll_speed_v vector_add.inputs[1].default_value[1] = i * mat_props.scroll_speed_v * frame_step / scroll_per_sec_divisor
vector_add.inputs[1].keyframe_insert("default_value", index=1, frame=i * scroll_speed_divisor) vector_add.inputs[1].keyframe_insert("default_value", index=1, frame=i * frame_step * fps)
material.node_tree.links.new(vector_add.inputs[0], uv_input.outputs[0]) material.node_tree.links.new(vector_add.inputs[0], uv_input.outputs[0])
for texture_node in texture_input_nodes:
material.node_tree.links.new(texture_node.inputs["Vector"], vector_add.outputs[0])
# Don't know how to set interpolation when adding keyframes
# so we must do it after the fact
if material.node_tree.animation_data:
for fcurve in material.node_tree.animation_data.action.fcurves:
for kf in fcurve.keyframe_points.values():
kf.interpolation = 'LINEAR'
for texture_node in texture_input_nodes:
material.node_tree.links.new(texture_node.inputs["Vector"], vector_add.outputs[0])
# Don't know how to set interpolation when adding keyframes
# so we must do it after the fact
if material.node_tree.animation_data:
for fcurve in material.node_tree.animation_data.action.fcurves:
for kf in fcurve.keyframe_points.values():
kf.interpolation = 'LINEAR'
''' '''
else: else: