Skip to content

Commit

Permalink
Version 28/11/2018
Browse files Browse the repository at this point in the history
  • Loading branch information
lgeertsen committed Nov 28, 2018
1 parent 9896df3 commit 3e337bb
Show file tree
Hide file tree
Showing 3 changed files with 867 additions and 8,506 deletions.
8 changes: 6 additions & 2 deletions export_shader_network_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ def testButton(objects, *args):
isInterruptable=True )
exporting = True
#shaders_to_json(objA=objects, file_path=path[0])
shaders_to_json(objA=['BATIMENT_PAUVRE_01'], file_path=path[0])
#shaders_to_json(objA=['BATIMENT_PAUVRE_01'], file_path=path[0])
shaders_to_json(objA=['pSphere1'], file_path=path[0])
# while exporting:
# if cmds.progressWindow( query=True, isCancelled=True ) :
# exporting = False
Expand Down Expand Up @@ -74,6 +75,7 @@ def getAllNodes(nodes, shaderNetwork):
# print("__________________________________")
# print(cmds.getAttr(n + "." + a, type=True))
# print("__________________________________")

try:
type = cmds.getAttr(n + "." + a, type=True)
if type != "TdataCompound":
Expand Down Expand Up @@ -116,6 +118,8 @@ def getAllNodes(nodes, shaderNetwork):
shaderNetwork["nodes"][n]["data"][a]["type"] = "TdataCompound"
except:
pass


cmds.delete(tempNode)


Expand Down Expand Up @@ -200,7 +204,7 @@ def shaders_to_json(objA=None, file_path=None):
for shader in shaderGroups:
type = cmds.objectType(shader)
if(type == "shadingEngine"):
print(eachChild)
#print(eachChild)
if(shader not in treatedShaders):
shaders = []
print(shader)
Expand Down
158 changes: 109 additions & 49 deletions import_shader_network_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,17 @@ def createNodes(self):
#texture = "project://scene/" + str(material)
elif type:
#texture = createNode(node, type, default_path)
n = Node(node, value["type"], type[1], value["data"])
self.nodes[n.name] = n
if(isinstance(type[1], dict)):
if(type[1]["key"] in value["data"]):
n = Node(node, value["type"], type[1][str(value["data"][type[1]["key"]])], value["data"])
self.nodes[n.name] = n
else:
n = Node(node, value["type"], type[1]["default"], value["data"])
self.nodes[n.name] = n
else:
n = Node(node, value["type"], type[1], value["data"])
self.nodes[n.name] = n

#print(texture.name)

# if texture:
Expand Down Expand Up @@ -80,8 +89,8 @@ def linkNodes(self):
def replaceTriplanars(self):
for name, node in self.nodes.items():
if(node.typeM == "aiTriplanar"):
print("Triplanar")
print(node.name)
#print("Triplanar")
#print(node.name)
files = []
for input in node.input:
for output in node.output:
Expand All @@ -90,20 +99,26 @@ def replaceTriplanars(self):

node.output = []
files = self.getLinkedFiles(node.input)

index = 1

for file in files:
print(file.output)
#print(file.output)
doDuplicate = True

for output in file.output:
if output["to"].typeM == "aiTriplanar":
print(output["to"].typeM)
#print(output["to"].typeM)
doDuplicate = False

if not doDuplicate:
continue

duplicate = self.duplicateTriplanar(node)
duplicate.name = duplicate.name + str(index)
index += 1
duplicate.output = file.output
duplicate.input.append(file)
connection = ["right", "left", "top", "bottom", "front", "back"]
file.output = [{"to": duplicate, "connection": connection}]
self.nodes[duplicate.name] = duplicate
Expand All @@ -113,7 +128,7 @@ def replaceTriplanars(self):
for c in output["connection"]:
ix.cmds.SetTexture([str(output["to"].path) + "." + str(c)], str(duplicate.path))

self.addNodeValue()
self.addNodeValues()


def getLinkedFiles(self, n):
Expand All @@ -134,35 +149,56 @@ def duplicateTriplanar(self, node):
duplicate = Node(node.name, node.typeM, node.typeC, node.data)
return duplicate

def addNodeValues(self, node, data):
def addNodeValues(self):
for name, node in self.nodes.items():
if(node.typeM == "remapHsv"):
ix.cmds.SetValues([str(node.path) + ".output_color_model"], ["1"])
continue
elif(node.typeM == "aiNoise"):
ix.cmds.SetValues([str(node.path) + ".color1"], ["0.0", "0.0", "0.0"])
ix.cmds.SetValues([str(node.path) + ".color2"], ["1", "1", "1"])

for parameter, value in node.data.items():
# print("----------------" + node + "ADD NODE VALUES----------------")
#print(str(data["type"]) + ": " + str(data["data"]))
for parameter, value in data["data"].items():
#for parameter, value in data["data"].items():
# print(str(parameter) + ": " + str(value))
type = parameterSwitch.get(parameter)
type = parameterLibrary.get(parameter)

if not type:
continue
if not type:
continue

# if(isinstance(type, list) and isinstance(type[0], str)):
# type[1](data, value, type[2])
# continue
if(isinstance(type, dict)):
if(node.typeM == "aiTriplanar" and value["type"] == "float3"):
type["aiTriplanar"](node, value["value"])
continue
if(node.typeM == "aiNoise"):
type["aiNoise"][0]([str(node.path) + "." + str(type["aiNoise"][1])], [str(value["value"][0][0]), str(value["value"][0][1]), str(value["value"][0][2])])
continue
elif(isinstance(type, list)):
if(value["type"] == "string"):
type[0]([str(node.path) + "." + str(type[1])], [str(value["value"])])
#ix.cmds.SetValues([str(data["type"]) + "." + str(type)], [str(value["value"])])
continue
elif(value["type"] == "float" or value["type"] == "long"):
type[0]([str(node.path) + "." + str(type[1])], [str(value["value"])])
continue
elif(value["type"] == "float3" and parameter != "scale"):
type[0]([str(node.path) + "." + str(type[1])], [str(value["value"][0][0]), str(value["value"][0][1]), str(value["value"][0][2])])
continue
elif(value["type"] == "bool"):
if(value["value"]):
type[0]([str(node.path) + "." + str(type[1])], ["1"])
continue
elif(value["type"] == "TdataCompound" and node.typeC == "TextureRemap"):
type(node.path, value["value"])
continue
elif(value["type"] == "string" or value["type"] == "float"):
type(node, value["value"])

# if(isinstance(type, list) and isinstance(type[0], str)):
# type[1](data, value, type[2])
# continue
if(value["type"] == "string"):
type[0]([str(data["type"]) + "." + str(type[1])], [str(value["value"])])
#ix.cmds.SetValues([str(data["type"]) + "." + str(type)], [str(value["value"])])
continue
if(value["type"] == "float"):
type[0]([str(data["type"]) + "." + str(type[1])], [str(value["value"])])
continue
if(value["type"] == "float3"):
type[0]([str(data["type"]) + "." + str(type[1])], [str(value["value"][0][0]), str(value["value"][0][1]), str(value["value"][0][2])])
continue
if(value["type"] == "bool"):
if(value["value"]):
type[0]([str(data["type"]) + "." + str(type[1])], ["1"])
continue
if(value["type"] == "TdataCompound"):
type(data["type"], value["value"])

self.attributeMaterials()

Expand All @@ -171,7 +207,7 @@ def attributeMaterials(self):
return
#print(mat)
for object in self.jsonObjects:
print self.material
#print self.material
ix.cmds.SetValues([str(self.object) + "/" + str(object) + ".materials[0]"], [str(self.material.path)])


Expand Down Expand Up @@ -210,7 +246,7 @@ def __init__(self, name, typeM, typeC, data):


def createNode(self):
node = ix.cmds.CreateObject(str(self.name) + "_tx", str(self.typeC), "Global", path)
node = ix.cmds.CreateObject(str(self.name), str(self.typeC), "Global", path)
return node


Expand Down Expand Up @@ -299,30 +335,48 @@ def addAllCurves(node, data):
# print(node)
# print(data)
# print(str(node) + ".output")
ix.cmds.RemoveCurveValue([str(node) + ".output"], [2, 1, 2, 2, 1, 2, 2, 1, 2, 2, 1, 2])
for point in data:
# print(point)
ix.cmds.AddCurveValue([str(node) + ".output"], [
1.0,
0.0, point[0], point[1],
1.0,
0.0, point[0], point[1],
1.0,
0.0, point[0], point[1],
1.0,
0.0, point[0], point[1],
])
try:
ix.cmds.RemoveCurveValue([str(node) + ".output"], [2, 1, 2, 2, 1, 2, 2, 1, 2, 2, 1, 2])
for point in data:
# print(point)
ix.cmds.AddCurveValue([str(node) + ".output"], [
1.0,
0.0, point[0], point[1],
1.0,
0.0, point[0], point[1],
1.0,
0.0, point[0], point[1],
1.0,
0.0, point[0], point[1],
])
except:
pass

def triplanarScaleToFile(node, data):
#print("triplanarScaleToFile")
#print(node.path)
if node.input:

#print(node.input[0].path)
#print(data)
ix.cmds.SetValues([str(node.input[0].path) + ".uv_scale"], [str(data[0][0]), str(data[0][1]), str(data[0][2])])

def setFileColorSpace(node, data):
if(data == "Raw"):
ix.cmds.SetValues([str(node.path) + ".use_raw_data"], ["1"])

def setFrequency(node, data):
ix.cmds.SetValues([str(node.path) + ".frequency"], [str(data / 100)])



nodeLibrary = {
"aiStandardSurface" : ["Material", "MaterialPhysicalStandard"],
"remapColor" : ["Node", "TextureRemap"],
"file" : ["Node", "TextureMapFile"],
"bump2d" : ["Node", "TextureNormalMap"],
"bump2d" : ["Node", {"key": "bumpInterp", "1": "TextureNormalMap", "default": "TextureBumpMap"}],
"reverse" : ["Node", "TextureInvert"],
"remapValue" : ["Node", "TextureRescale"],
"remapValue" : ["Node", "TextureRemap"],
"aiTriplanar" : ["Node", "TextureTriplanar"],
"blendColors" : ["Node", "TextureBlend"],
"remapHsv" : ["Node", "TextureColorModel"],
Expand All @@ -349,12 +403,18 @@ def addAllCurves(node, data):
"red": addCurveRed,
"green": addCurveGreen,
"blue": addCurveBlue,
"value": addAllCurves,
"specularColor": [ix.cmds.SetValues, "specular_1_color"],
"specularRoughness": [ix.cmds.SetValues, "specular_1_roughness"],
"specularIOR": [ix.cmds.SetValues, "specular_1_index_of_refraction"],
"baseColor": [ix.cmds.SetValues, "diffuse_front_color"],
"base": [ix.cmds.SetValues, "diffuse_front_strength"],
"alphaIsLuminance": [ix.cmds.SetValues, "single_channel_file_behavior"]
"alphaIsLuminance": [ix.cmds.SetValues, "single_channel_file_behavior"],
"scale": {"aiTriplanar": triplanarScaleToFile, "aiNoise": [ix.cmds.SetValues, "uv_scale"]},
"octaves": [ix.cmds.SetValues, "octaves"],
"lacunarity": [ix.cmds.SetValues, "lacunarity"],
"colorSpace": setFileColorSpace,
"frequency": setFrequency
}


Expand Down
Loading

0 comments on commit 3e337bb

Please sign in to comment.