Skip to content

Commit

Permalink
Merge branch 'WolvenKit:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
Simarilius-uk authored Mar 5, 2024
2 parents e1921ee + fba897a commit ae4ea5b
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 15 deletions.
13 changes: 10 additions & 3 deletions i_scene_cp77_gltf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@

bl_info = {
"name": "Cyberpunk 2077 IO Suite",
"author": "HitmanHimself, Turk, Jato, dragonzkiller, kwekmaster, glitchered, Simarilius, Doctor Presto, shotlastc, Rudolph2109",
"version": (1, 5, 2, 3),
"author": "HitmanHimself, Turk, Jato, dragonzkiller, kwekmaster, glitchered, Simarilius, Doctor Presto, shotlastc, Rudolph2109, Holopointz",
"version": (1, 5, 3),
"blender": (3, 6, 0),
"location": "File > Import-Export",
"description": "Import and Export WolvenKit Cyberpunk2077 gLTF models with materials, Import .streamingsector and .ent from .json",
Expand Down Expand Up @@ -749,6 +749,11 @@ class CP77RigLoader(Operator):
bl_label = "Load rigs from .glb"
bl_description = "Load Cyberpunk 2077 deform rigs from plugin resources"

files: CollectionProperty(type=OperatorFileListElement)
appearances: StringProperty(name="Appearances", default="")
directory: StringProperty(name="Directory", default="")
filepath: StringProperty(name="Filepath", default="")

def execute(self, context):
props = context.scene.cp77_panel_props
selected_rig_name = props.body_list
Expand All @@ -757,7 +762,9 @@ def execute(self, context):
if selected_rig_name in rig_names:
# Find the corresponding .glb file and load it
selected_rig = rig_files[rig_names.index(selected_rig_name)]
bpy.ops.import_scene.gltf(filepath=selected_rig)
self.filepath = selected_rig
CP77GLBimport(self, exclude_unused_mats=True, image_format='PNG', with_materials=False,
filepath=selected_rig, hide_armatures=False, import_garmentsupport=False, files=[], directory='', appearances="ALL")
if props.fbx_rot:
rotate_quat_180(self,context)
return {'FINISHED'}
Expand Down
4 changes: 2 additions & 2 deletions i_scene_cp77_gltf/importers/entity_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def importEnt( filepath='', appearances=[], exclude_meshes=[], with_materials=Tr
j=json.load(f)
valid_json=json_ver_validate(j)
if not valid_json:
bpy.ops.cp77.message_box('INVOKE_DEFAULT', message="Incompatible entity json file detected. This add-on version requires materials generated WolvenKit 8.9.1 or higher.")
bpy.ops.cp77.message_box('INVOKE_DEFAULT', message="Incompatible entity json file detected. This add-on version requires files generated by WolvenKit 8.9.1 or higher.")
return {'CANCELLED'}

ent_apps= j['Data']['RootChunk']['appearances']
Expand Down Expand Up @@ -728,4 +728,4 @@ def importEnt( filepath='', appearances=[], exclude_meshes=[], with_materials=Tr
if os.path.basename(e)== ent_name+'.json' :
filepath=e

importEnt( filepath, appearances )
importEnt( filepath, appearances )
15 changes: 12 additions & 3 deletions i_scene_cp77_gltf/main/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,13 @@ def CreateShaderNodeNormalMap(curMat,path = None, x = 0, y = 0, name = None,imag

return nMap

def image_has_alpha(img):
b = 32 if img.is_float else 8
return (
img.depth == 2*b or # Grayscale+Alpha
img.depth == 4*b # RGB+Alpha
)

def CreateShaderNodeRGB(curMat, color,x = 0, y = 0,name = None, isVector = False):
rgbNode = curMat.nodes.new("ShaderNodeRGB")
rgbNode.location = (x, y)
Expand Down Expand Up @@ -508,11 +515,13 @@ def CreateGradMapRamp(CurMat, grad_image_node, location=(-400, 250)):
row_index = 0
# Get colors from the row
colors = []
alphas = []
for x in range(image_width):
pixel_data = grad_image_node.image.pixels[(row_index * image_width + x) * 4: (row_index * image_width + x) * 4 + 3]
pixel_data = grad_image_node.image.pixels[(row_index * image_width + x) * 4: (row_index * image_width + x) * 4 + 4]
color = Color()
color.r, color.g, color.b = pixel_data
color.r, color.g, color.b = pixel_data[0:3]
colors.append(color)
alphas.append(pixel_data[3])
# Create ColorRamp node
color_ramp_node = CurMat.nodes.new('ShaderNodeValToRGB')
color_ramp_node.location = location
Expand All @@ -528,7 +537,7 @@ def CreateGradMapRamp(CurMat, grad_image_node, location=(-400, 250)):
element = color_ramp_node.color_ramp.elements.new(i / (len(colors) ))
else:
element = color_ramp_node.color_ramp.elements[0]
element.color = (color.r, color.g, color.b, 1.0)
element.color = (color.r, color.g, color.b, alphas[i])
element.position = stop_positions[i]

color_ramp_node.color_ramp.interpolation = 'CONSTANT'
Expand Down
8 changes: 5 additions & 3 deletions i_scene_cp77_gltf/main/meshtools.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,8 @@ def CP77RefitList(context):
SoloArmsAddon = os.path.join(refit_dir, "SoloArmsAddon.zip")
Adonis = os.path.join(refit_dir, "Adonis.zip")
VanillaFemToMasc = os.path.join(refit_dir, "f2m.zip")
VanillaFem_BigBoobs = os.path.join(refit_dir, "f_normal_to_big_boobs.zip")
VanillaFem_SmallBoobs = os.path.join(refit_dir, "f_normal_to_small_boobs.zip")
VanillaMascToFem = os.path.join(refit_dir, "m2f.zip")
Lush = os.path.join(refit_dir, "lush.zip")
Hyst_RB = os.path.join(refit_dir, "hyst_rb.zip")
Expand All @@ -286,11 +288,11 @@ def CP77RefitList(context):
Solo_Ultimate = os.path.join(refit_dir, "solo_ultimate.zip")
Gymfiend = os.path.join(refit_dir, "gymfiend.zip")
Freyja = os.path.join(refit_dir, "freyja.zip")
Hyst_EBBP_Addon = os.path.join(refit_dir, "hyst_ebbp_addon.zip")
# Hyst_EBBP_Addon = os.path.join(refit_dir, "hyst_ebbp_addon.zip")

# Return the list of variable names
target_body_paths = [Hyst_EBBP_Addon, Freyja, Gymfiend,SoloArmsAddon, Solo_Ultimate, Adonis, Flat_Chest, Hyst_EBB_RB, Hyst_EBB, Hyst_RB, Lush, VanillaFemToMasc, VanillaMascToFem]
target_body_names = ['Hyst_EBBP_Addon', 'Freyja', 'Gymfiend','SoloArmsAddon', 'Solo_Ultimate', 'Adonis', 'Flat_Chest', 'Hyst_EBB_RB', 'Hyst_EBB', 'Hyst_RB', 'Lush', 'VanillaFemToMasc', 'VanillaMascToFem' ]
target_body_paths = [ Gymfiend, Freyja, SoloArmsAddon, Solo_Ultimate, Adonis, Flat_Chest, Hyst_EBB_RB, Hyst_EBB, Hyst_RB, Lush, VanillaFemToMasc, VanillaMascToFem, VanillaFem_BigBoobs, VanillaFem_SmallBoobs ]
target_body_names = [ 'Gymfiend', 'Freyja', 'SoloArmsAddon', 'Solo_Ultimate', 'Adonis', 'Flat_Chest', 'Hyst_EBB_RB', 'Hyst_EBB', 'Hyst_RB', 'Lush', 'VanillaFemToMasc', 'VanillaMascToFem', 'VanillaFem_BigBoobs', 'VanillaFem_SmallBoobs' ]

# Return the list of tuples
return target_body_paths, target_body_names
Expand Down
3 changes: 2 additions & 1 deletion i_scene_cp77_gltf/main/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ def create(self,materialIndex):
skin = Skin(self.BasePath, self.image_format, self.ProjPath)
skin.create(rawMat["Data"],bpyMat)

case "engine\\materials\\metal_base.remt" | "engine\\materials\\metal_base_proxy.mt" |'base\\materials\\metal_base_parallax.mt':
case "engine\\materials\\metal_base.remt" | "engine\\materials\\metal_base_proxy.mt" |\
'base\\materials\\metal_base_parallax.mt' | 'base\materials\metal_base_gradientmap_recolor.mt':
if 'EnableMask' in rawMat.keys():
enableMask=rawMat['EnableMask']
else:
Expand Down
14 changes: 11 additions & 3 deletions i_scene_cp77_gltf/material_types/metalbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ def create(self,Data,Mat):
metNode = create_node(CurMat.nodes,"ShaderNodeTexImage", (-800,-550), label="Metalness", image=mImg)
CurMat.links.new(metNode.outputs[0],pBSDF.inputs['Metallic'])

if 'GradientMap' in Data:
gradmap = Data["GradientMap"]
gradImg = imageFromRelPath(gradmap,self.image_format, DepotPath=self.BasePath, ProjPath=self.ProjPath)
grad_image_node = create_node(CurMat.nodes,"ShaderNodeTexImage", (-800,0), label="GradientMap", image=gradImg)
color_ramp_node=CreateGradMapRamp(CurMat, grad_image_node)
CurMat.links.new(mixRGB.outputs[0], color_ramp_node.inputs[0])
CurMat.links.new(color_ramp_node.outputs[0], pBSDF.inputs['Base Color'])

if 'MetalnessScale' in Data:
mScale = CreateShaderNodeValue(CurMat,Data["MetalnessScale"],-1000, -100,"MetalnessScale")

Expand Down Expand Up @@ -67,7 +75,7 @@ def create(self,Data,Mat):
CurMat.links.new(bColNode.outputs[1],alphclamp.inputs['Value'])
else:
CurMat.links.new(bColNode.outputs[0],alphclamp.inputs['Value'])


Clamp2 = create_node(CurMat.nodes,"ShaderNodeClamp",(-538., 476.))

Expand All @@ -76,12 +84,10 @@ def create(self,Data,Mat):

CurMat.links.new(alphclamp.outputs[0],Clamp2.inputs['Value'])


if "Normal" in Data:
nMap = CreateShaderNodeNormalMap(CurMat,self.BasePath + Data["Normal"],-200,-300,'Normal',self.image_format)
CurMat.links.new(nMap.outputs[0],pBSDF.inputs['Normal'])


mulNode = CurMat.nodes.new("ShaderNodeMixRGB")
mulNode.inputs[0].default_value = 1
mulNode.blend_type = 'MULTIPLY'
Expand Down Expand Up @@ -114,6 +120,8 @@ def create(self,Data,Mat):
CurMat.links.new(Math.outputs['Value'], Clamp001.inputs[1]) # Inverted value into clamp min, so if 1 its always solic, if 0 will use BaseColor alpha
CurMat.links.new(bColNode.outputs['Alpha'], Clamp001.inputs[0]) # alpha into one thats clamped by enableMask value
CurMat.links.new(Clamp001.outputs['Result'], pBSDF.inputs['Alpha'])
if not image_has_alpha(bcolImg): # if the image doesnt have alpha stick the color in instead
CurMat.links.new(bColNode.outputs['Color'],Clamp001.inputs['Value'])



Expand Down
Binary file not shown.
Binary file not shown.
Binary file modified i_scene_cp77_gltf/resources/refitters/freyja.zip
Binary file not shown.
Binary file modified i_scene_cp77_gltf/resources/refitters/hyst_ebb.zip
Binary file not shown.
Binary file modified i_scene_cp77_gltf/resources/refitters/hyst_ebb_rb.zip
Binary file not shown.

0 comments on commit ae4ea5b

Please sign in to comment.