Skip to content

Commit

Permalink
Updated to use the OffsetU and OffsetV values for
Browse files Browse the repository at this point in the history
the base material
  • Loading branch information
Simarilius-uk committed Jan 16, 2025
1 parent 891dd2c commit c542e6e
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion i_scene_cp77_gltf/material_types/multilayered.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
import os
from ..main.common import *
from ..jsontool import openJSON
import numpy as np

def np_array_from_image(img_name):
img = bpy.data.images[img_name]
return np.array(img.pixels[:])

def _getOrCreateLayerBlend():
if "Layer_Blend" in bpy.data.node_groups:
Expand Down Expand Up @@ -97,12 +101,16 @@ def createBaseMaterial(self,matTemplateObj,mltemplate):
vers=bpy.app.version
if vers[0]<4:
TMI = NG.inputs.new('NodeSocketVector','Tile Multiplier')
OffU = NG.inputs.new('NodeSocketFloat','OffsetU')
OffV = NG.inputs.new('NodeSocketFloat','OffsetV')
NG.outputs.new('NodeSocketColor','Color')
NG.outputs.new('NodeSocketFloat','Metalness')
NG.outputs.new('NodeSocketFloat','Roughness')
NG.outputs.new('NodeSocketColor','Normal')
else:
TMI = NG.interface.new_socket(name="Tile Multiplier",socket_type='NodeSocketVector', in_out='INPUT')
OffU = NG.interface.new_socket(name="OffsetU",socket_type='NodeSocketFloat', in_out='INPUT')
OffV = NG.interface.new_socket(name="OffsetV",socket_type='NodeSocketFloat', in_out='INPUT')
NG.interface.new_socket(name="Color", socket_type='NodeSocketColor', in_out='OUTPUT')
NG.interface.new_socket(name="Metalness", socket_type='NodeSocketFloat', in_out='OUTPUT')
NG.interface.new_socket(name="Roughness", socket_type='NodeSocketFloat', in_out='OUTPUT')
Expand All @@ -121,6 +129,10 @@ def createBaseMaterial(self,matTemplateObj,mltemplate):

TexCordN = create_node( NG.nodes, "ShaderNodeTexCoord",(-500,-64))


combine = create_node(NG.nodes,"ShaderNodeCombineXYZ", (-600,-60))


TileMultN = create_node( NG.nodes, "ShaderNodeValue", (-700,-45*2))
TileMultN.outputs[0].default_value = TileMult

Expand All @@ -146,11 +158,14 @@ def createBaseMaterial(self,matTemplateObj,mltemplate):
NG.links.new(MapN.outputs['Vector'],MTN.inputs['Vector'])
NG.links.new(TileMultN.outputs[0],VecMathN.inputs[0])
NG.links.new(GroupInN.outputs[0],VecMathN.inputs[1])
NG.links.new(GroupInN.outputs[1],combine.inputs[0])
NG.links.new(GroupInN.outputs[2],combine.inputs[1])
NG.links.new(CTN.outputs[0],GroupOutN.inputs[0])
NG.links.new(MTN.outputs[0],GroupOutN.inputs[1])
NG.links.new(RTN.outputs[0],GroupOutN.inputs[2])
NG.links.new(NTN.outputs[0],RGBCurvesConvert.inputs[1])
NG.links.new(RGBCurvesConvert.outputs[0],GroupOutN.inputs[3])
NG.links.new(combine.outputs[0],MapN.inputs[1])

return

Expand Down Expand Up @@ -313,6 +328,14 @@ def create(self,Data,Mat):
if MicroblendOffsetV is None:
MicroblendOffsetV = x.get("MicroblendOffsetV")

OffsetU = x.get("offsetU")
if OffsetU is None:
OffsetU = x.get("OffsetU")

OffsetV = x.get("offsetV")
if OffsetV is None:
OffsetV = x.get("OffsetV")

opacity = x.get("opacity")
if opacity is None:
opacity = x.get("Opacity")
Expand Down Expand Up @@ -365,6 +388,8 @@ def create(self,Data,Mat):
NG.outputs.new('NodeSocketFloat','Roughness')
NG.outputs.new('NodeSocketVector','Normal')
NG.outputs.new('NodeSocketFloat','Layer Mask')
NG.inputs.new('NodeSocketFloat','OffsetU')
NG.inputs.new('NodeSocketFloat','OffsetV')
NG_inputs=NG.inputs

else:
Expand All @@ -383,6 +408,8 @@ def create(self,Data,Mat):
NG.interface.new_socket(name="Roughness", socket_type='NodeSocketFloat', in_out='OUTPUT')
NG.interface.new_socket(name="Normal", socket_type='NodeSocketVector', in_out='OUTPUT')
NG.interface.new_socket(name="Layer Mask", socket_type='NodeSocketFloat', in_out='OUTPUT')
NG.interface.new_socket(name="OffsetU", socket_type='NodeSocketFloat', in_out='INPUT')
NG.interface.new_socket(name="OffsetV", socket_type='NodeSocketFloat', in_out='INPUT')
NG_inputs=get_inputs(NG)

NG_inputs[4].min_value = 0
Expand All @@ -409,7 +436,7 @@ def create(self,Data,Mat):
if BaseMat:
BMN = create_node(NG.nodes,"ShaderNodeGroup", (-2000,0))
BMN.width = 300
BMN.node_tree = BaseMat
BMN.node_tree = BaseMat

# SET LAYER GROUP DEFAULT VALUES

Expand Down Expand Up @@ -460,13 +487,25 @@ def create(self,Data,Mat):
LayerGroupN.inputs[8].default_value = 1


if OffsetU !=None:
LayerGroupN.inputs[10].default_value=OffsetU
else:
LayerGroupN.inputs[10].default_value=0

if OffsetV !=None:
LayerGroupN.inputs[11].default_value=OffsetV
else:
LayerGroupN.inputs[11].default_value=0

# DEFINES MAIN MULTILAYERED PROPERTIES

# Node for blending colorscale color with diffuse texture of mltemplate
# Changed from multiply to overlay because multiply is a darkening blend mode, and colors appear too dark. Overlay is still probably wrong - jato
if colorScale != "null":
ColorScaleMixN = create_node(NG.nodes,"ShaderNodeMixRGB",(-1400,100),blend_type='MIX')
ColorScaleMixN.inputs[0].default_value=1
if 'logos' in BaseMat.name:
ColorScaleMixN.blend_type='MULTIPLY'

# Microblend texture node
MBN = create_node(NG.nodes,"ShaderNodeTexImage",(-2300,-800),image = MBI,label = "Microblend")
Expand Down Expand Up @@ -597,6 +636,8 @@ def create(self,Data,Mat):
NG.links.new(GroupInN.outputs[9],MaskMultiply.inputs[0])
NG.links.new(GroupInN.outputs[9],MaskLinearBurnAdd.inputs[0])
NG.links.new(GroupInN.outputs[9],MBNormSubtractMask.inputs[1])
NG.links.new(GroupInN.outputs[10],BMN.inputs[1])
NG.links.new(GroupInN.outputs[11],BMN.inputs[2])

NG.links.new(MBCMicroOffset.outputs[0],MBCSubtract.inputs[1])
NG.links.new(MBCMicroOffset.outputs[0],MBCMultiply.inputs[0])
Expand Down

0 comments on commit c542e6e

Please sign in to comment.