Skip to content

Commit

Permalink
Update for WK 8.5
Browse files Browse the repository at this point in the history
-Updated to support new json format from WolvenKit 8.5
- Added normal detail and microblend preview for skin.mt
  • Loading branch information
ja-to committed Mar 9, 2022
1 parent f5c19ad commit 9cbfec5
Show file tree
Hide file tree
Showing 7 changed files with 226 additions and 114 deletions.
2 changes: 1 addition & 1 deletion i_scene_cp77_gltf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "Cyberpunk 2077 glTF Importer",
"author": "HitmanHimself, Turk, Jato",
"version": (1, 0, 5),
"blender": (2, 93, 0),
"blender": (3, 0, 0),
"location": "File > Import-Export",
"description": "Import WolvenKit Cyberpunk2077 glTF Models With Materials",
"warning": "",
Expand Down
5 changes: 2 additions & 3 deletions i_scene_cp77_gltf/main/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ def CreateRebildNormalGroup(curMat, x = 0, y = 0,name = 'Rebuild Normal Z'):
group.links.new(VMup.outputs[0],VSub.inputs[0])
group.links.new(VSub.outputs[0],VDot.inputs[0])
group.links.new(VSub.outputs[0],VDot.inputs[1])
group.links.new(VDot.outputs["Value"],Sub.inputs[1])
group.links.new(Sub.outputs[0],SQR.inputs[0])
group.links.new(SQR.outputs[0],Range.inputs[0])
group.links.new(GroupInN.outputs[0],Sep.inputs[0])
Expand Down Expand Up @@ -125,7 +126,7 @@ def CreateShaderNodeNormalMap(curMat,path = None, x = 0, y = 0, name = None,imag
Img = imageFromPath(path,image_format,nonCol)
ImgNode.image = Img

NormalRebuildGroup = CreateRebildNormalGroup(curMat, x - 200, y, name + ' Rebuilt')
NormalRebuildGroup = CreateRebildNormalGroup(curMat, x - 150, y, name + ' Rebuilt')

curMat.links.new(ImgNode.outputs[0],NormalRebuildGroup.inputs[0])
curMat.links.new(NormalRebuildGroup.outputs[0],nMap.inputs[1])
Expand Down Expand Up @@ -159,11 +160,9 @@ def crop_image(orig_img,outname, cropped_min_x, cropped_max_x, cropped_min_y, cr
if you put cropped_min_x = 2 and cropped_max_x = 6,
you would get back a cropped image with width 4, and
pixels ranging from the 2 to 5 in the x-coordinate
Note: here y increasing as you down the image. So,
if cropped_min_x and cropped_min_y are both zero,
you'll get the top-left of the image (as in GIMP).
Returns: An image of type <class 'bpy.types.Image'>
'''

Expand Down
28 changes: 14 additions & 14 deletions i_scene_cp77_gltf/material_types/hair.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def __init__(self, BasePath,image_format):
def create(self,hair,Mat):

file = open(self.BasePath + hair["HairProfile"] + ".json",mode='r')
profile = json.loads(file.read())["Chunks"]["0"]["Properties"]
profile = json.loads(file.read())["Data"]["RootChunk"]["Properties"]
file.close()

CurMat = Mat.node_tree
Expand All @@ -32,13 +32,13 @@ def create(self,hair,Mat):
counter = 0
for Entry in profile["gradientEntriesRootToTip"]:
if counter is 0:
RootToTip.color_ramp.elements[0].position = Entry.get("value",0)
colr = Entry.get("color","255, 255, 255").split(', ')
RootToTip.color_ramp.elements[0].color = (float(colr[0])/255,float(colr[1])/255,float(colr[2])/255,float(1))
RootToTip.color_ramp.elements[0].position = Entry["Properties"].get("value",0)
colr = Entry["Properties"]["color"].get("Properties")
RootToTip.color_ramp.elements[0].color = (float(colr["Red"])/255,float(colr["Green"])/255,float(colr["Blue"])/255,float(1))
else:
element = RootToTip.color_ramp.elements.new(Entry.get("value",0))
colr = Entry.get("color","255, 255, 255").split(', ')
element.color = (float(colr[0])/255,float(colr[1])/255,float(colr[2])/255,float(1))
element = RootToTip.color_ramp.elements.new(Entry["Properties"].get("value",0))
colr = Entry["Properties"]["color"].get("Properties")
element.color = (float(colr["Red"])/255,float(colr["Green"])/255,float(colr["Blue"])/255,float(1))
counter = counter + 1

CurMat.links.new(gImgNode.outputs[0],RootToTip.inputs[0])
Expand All @@ -54,15 +54,15 @@ def create(self,hair,Mat):
counter = 0
for Entry in profile["gradientEntriesID"]:
if counter is 0:
ID.color_ramp.elements[0].position = Entry.get("value",0)
colr = Entry.get("color","255, 255, 255").split(', ')
ID.color_ramp.elements[0].color = (float(colr[0])/255,float(colr[1])/255,float(colr[2])/255,float(1))
ID.color_ramp.elements[0].position = Entry["Properties"].get("value",0)
colr = Entry["Properties"]["color"].get("Properties")
ID.color_ramp.elements[0].color = (float(colr["Red"])/255,float(colr["Green"])/255,float(colr["Blue"])/255,float(1))
else:
element = ID.color_ramp.elements.new(Entry.get("value",0))
colr = Entry.get("color","255, 255, 255").split(', ')
element.color = (float(colr[0])/255,float(colr[1])/255,float(colr[2])/255,float(1))
element = ID.color_ramp.elements.new(Entry["Properties"].get("value",0))
colr = Entry["Properties"]["color"].get("Properties")
element.color = (float(colr["Red"])/255,float(colr["Green"])/255,float(colr["Blue"])/255,float(1))
counter = counter + 1

CurMat.links.new(idImgNode.outputs[0],ID.inputs[0])

mulNode = CurMat.nodes.new("ShaderNodeMixRGB")
Expand Down
63 changes: 32 additions & 31 deletions i_scene_cp77_gltf/material_types/multilayered.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ def __init__(self, BasePath,image_format):
self.BasePath = str(BasePath)
self.image_format = image_format
def createBaseMaterial(self,matTemplateObj,name):
CT = imageFromPath(self.BasePath + matTemplateObj["colorTexture"],self.image_format)
NT = imageFromPath(self.BasePath + matTemplateObj["normalTexture"],self.image_format,isNormal = True)
RT = imageFromPath(self.BasePath + matTemplateObj["roughnessTexture"],self.image_format,isNormal = True)
MT = imageFromPath(self.BasePath + matTemplateObj["metalnessTexture"],self.image_format,isNormal = True)
CT = imageFromPath(self.BasePath + matTemplateObj["colorTexture"]["DepotPath"],self.image_format)
NT = imageFromPath(self.BasePath + matTemplateObj["normalTexture"]["DepotPath"],self.image_format,isNormal = True)
RT = imageFromPath(self.BasePath + matTemplateObj["roughnessTexture"]["DepotPath"],self.image_format,isNormal = True)
MT = imageFromPath(self.BasePath + matTemplateObj["metalnessTexture"]["DepotPath"],self.image_format,isNormal = True)

TileMult = float(matTemplateObj.get("tilingMultiplier",1))

Expand Down Expand Up @@ -95,7 +95,7 @@ def createBaseMaterial(self,matTemplateObj,name):
return

def createOverrideTable(self,matTemplateObj):
OverList = matTemplateObj.get("overrides")
OverList = matTemplateObj["overrides"].get("Properties")
if OverList is None:
OverList = matTemplateObj.get("Overrides")
Output = {}
Expand All @@ -104,27 +104,27 @@ def createOverrideTable(self,matTemplateObj):
Output["RoughLevelsOut"] = {}
Output["MetalLevelsOut"] = {}
for x in OverList["colorScale"]:
tmpName = x["n"]
tmpR = float(x["v"][0])
tmpG = float(x["v"][1])
tmpB = float(x["v"][2])
tmpName = x["Properties"]["n"]
tmpR = float(x["Properties"]["v"]["Elements"][0])
tmpG = float(x["Properties"]["v"]["Elements"][1])
tmpB = float(x["Properties"]["v"]["Elements"][2])
Output["ColorScale"][tmpName] = (tmpR,tmpG,tmpB,1)
for x in OverList["normalStrength"]:
tmpName = x["n"]
tmpName = x["Properties"]["n"]
tmpStrength = 0
if x.get("v") is not None:
tmpStrength = float(x["v"])
tmpStrength = float(x["Properties"]["v"])
Output["NormalStrength"][tmpName] = tmpStrength
for x in OverList["roughLevelsOut"]:
tmpName = x["n"]
tmpStrength0 = float(x["v"][0])
tmpStrength1 = float(x["v"][1])
tmpName = x["Properties"]["n"]
tmpStrength0 = float(x["Properties"]["v"]["Elements"][0])
tmpStrength1 = float(x["Properties"]["v"]["Elements"][1])
Output["RoughLevelsOut"][tmpName] = [(tmpStrength0,tmpStrength0,tmpStrength0,1),(tmpStrength1,tmpStrength1,tmpStrength1,1)]
for x in OverList["metalLevelsOut"]:
tmpName = x["n"]
tmpName = x["Properties"]["n"]
if x.get("v") is not None:
tmpStrength0 = float(x["v"][0])
tmpStrength1 = float(x["v"][1])
tmpStrength0 = float(x["Properties"]["v"]["Elements"][0])
tmpStrength1 = float(x["Properties"]["v"]["Elements"][1])
else:
tmpStrength0 = 0
tmpStrength1 = 1
Expand Down Expand Up @@ -281,7 +281,7 @@ def createLayerMaterial(self,LayerName,LayerCount,CurMat,mlmaskpath,normalimgpat
def create(self,Data,Mat):

file = open(self.BasePath + Data["MultilayerSetup"] + ".json",mode='r')
mlsetup = json.loads(file.read())["Chunks"]["0"]["Properties"]
mlsetup = json.loads(file.read())["Data"]["RootChunk"]["Properties"]
file.close()
xllay = mlsetup.get("layers")
if xllay is None:
Expand All @@ -291,54 +291,55 @@ def create(self,Data,Mat):
LayerIndex = 0
CurMat = Mat.node_tree
for x in (xllay):
MatTile = x.get("matTile")
MatTile = x["Properties"].get("matTile")
if MatTile is None:
MatTile = x.get("MatTile")
MbTile = x.get("mbTile")
MbTile = x["Properties"].get("mbTile")
if MbTile is None:
MbTile = x.get("MbTile")
MbTile = x["Properties"].get("MbTile")

MbScale = 1
if MatTile != None:
MbScale = float(MatTile)
if MbTile != None:
MbScale = float(MbTile)

Microblend = x.get("microblend")
Microblend = x["Properties"]["microblend"].get("DepotPath")
if Microblend is None:
Microblend = x.get("Microblend")
MicroblendContrast = x.get("microblendContrast")
MicroblendContrast = x["Properties"].get("microblendContrast")
if MicroblendContrast is None:
MicroblendContrast = x.get("Microblend",1)
microblendNormalStrength = x.get("microblendNormalStrength")
microblendNormalStrength = x["Properties"].get("microblendNormalStrength")
if microblendNormalStrength is None:
microblendNormalStrength = x.get("MicroblendNormalStrength")
opacity = x.get("opacity")
opacity = x["Properties"].get("opacity")
if opacity is None:
opacity = x.get("Opacity")
material = x.get("material")

material = x["Properties"]["material"].get("DepotPath")
if material is None:
material = x.get("Material")
colorScale = x.get("colorScale")
colorScale = x["Properties"].get("colorScale")
if colorScale is None:
colorScale = x.get("ColorScale")
normalStrength = x.get("normalStrength")
normalStrength = x["Properties"].get("normalStrength")
if normalStrength is None:
normalStrength = x.get("NormalStrength")
#roughLevelsIn = x["roughLevelsIn"]
roughLevelsOut = x.get("roughLevelsOut")
roughLevelsOut = x["Properties"].get("roughLevelsOut")
if roughLevelsOut is None:
roughLevelsOut = x.get("RoughLevelsOut")
#metalLevelsIn = x["metalLevelsIn"]
metalLevelsOut = x.get("metalLevelsOut")
metalLevelsOut = x["Properties"].get("metalLevelsOut")
if metalLevelsOut is None:
metalLevelsOut = x.get("MetalLevelsOut")

if Microblend != "null":
MBI = imageFromPath(self.BasePath+Microblend,self.image_format,True)

file = open(self.BasePath + material + ".json",mode='r')
mltemplate = json.loads(file.read())["Chunks"]["0"]["Properties"]
mltemplate = json.loads(file.read())["Data"]["RootChunk"]["Properties"]
file.close()
OverrideTable = self.createOverrideTable(mltemplate)#get override info for colors and what not

Expand Down
Loading

0 comments on commit 9cbfec5

Please sign in to comment.