Skip to content

Commit

Permalink
Update ShaderTag & ShaderParamString
Browse files Browse the repository at this point in the history
  • Loading branch information
sawich committed Oct 26, 2023
1 parent e1bb0c8 commit cebb53b
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 30 deletions.
4 changes: 2 additions & 2 deletions io_soulworker/core/binary_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ def read_quaternion(self) -> Quaternion:
x = self.read_float()
y = self.read_float()
z = self.read_float()
w = BinaryReader.fxor(self.read_float(), BinaryReader.FLOAT_MASK)
w = BinaryReader.__fxor__(self.read_float(), BinaryReader.FLOAT_MASK)

return Quaternion((w, x, y, z))

@staticmethod
def fxor(a: float, b: int) -> float:
def __fxor__(a: float, b: int) -> float:

value = unpack('<I', pack('<f', a))[0]
value ^= b
Expand Down
36 changes: 20 additions & 16 deletions io_soulworker/core/materials_xml/shader_param_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ def __init__(self, line: str):
rows = line.split(';')

for row in rows:
if (row == ''):
continue

[name, value] = row.split('=')

match name:
Expand All @@ -28,53 +31,54 @@ def __init__(self, line: str):

# MaterialParams=0,2,-0.03,-0.015
case 'MaterialParams':
self['material_params'] = Vector(value.split(','))
values = [float(v) for v in value.split(',')]
self['material_params'] = Vector(values)

# AlphaThreshold=0.25
case 'AlphaThreshold':
self['alpha_threshold'] = float(value)

# ToonTexture=Character\Common_Textures\ToonTexture.dds
case 'ToonTexture':
self['ToonTexture'] = value
self['toon_texture'] = value

# OutlineThickness=0.012
case 'OutlineThickness':
self['OutlineThickness'] = float(value)
self['outline_thickness'] = float(value)

# OutlineColor=0,0,0,1
case 'OutlineColor':
[r, g, b, a] = value.split(',')
self['OutlineColor'] = VisColor(r, g, b, a)
values = [int(v) for v in value.split(',')]
self['outline_color'] = VisColor(*values)

# DiffuseHue=1.2
case 'DiffuseHue':
self['DiffuseHue'] = float(value)
self['diffuse_hue'] = float(value)

# HairColor=0.9411765,0.7921569,0.5490196,1
case 'HairColor':
[r, g, b, a] = value.split(',')
self['HairColor'] = VisColor(r, g, b, a)
values = [float(v) for v in value.split(',')]
self['hair_color'] = VisColor(*values)

# ShadowColor=0.8039216,0.09803922,0.09803922,0.254902
case 'ShadowColor':
[r, g, b, a] = value.split(',')
self['ShadowColor'] = VisColor(r, g, b, a)
values = [float(v) for v in value.split(',')]
self['shadow_color'] = VisColor(*values)

# HairDarknessColor=0.7843137,0.5176471,0.3647059,1
case 'HairDarknessColor':
[r, g, b, a] = value.split(',')
self['HairDarknessColor'] = VisColor(r, g, b, a)
values = [float(v) for v in value.split(',')]
self['hair_darkness_color'] = VisColor(*values)

# MaskTexture=Character\Player\PC_A\Textures\PC_A_Parts_Default_Hair_01_Mask_01.dds
case 'MaskTexture':
self['MaskTexture'] = value
self['mask_texture'] = value

# globalAlpha=1
case 'globalAlpha':
self['globalAlpha'] = value
self['global_alpha'] = value

# LightVec=-1,1,-1
case 'LightVec':
self['LightVec'] = Vector(value.split(','))
pass
values = [int(v) for v in value.split(',')]
self['light_vec'] = Vector(values)
6 changes: 4 additions & 2 deletions io_soulworker/core/materials_xml/shader_tag.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@


from xml.etree.ElementTree import Element

from io_soulworker.core.materials_xml.shader_param_string import ShaderParamString


class ShaderTag:

def __init__(self, xml):
def __init__(self, node: Element):

self.paramstring = ShaderParamString(xml['Shader'])
self.paramstring = ShaderParamString(node.attrib['paramstring'])
3 changes: 3 additions & 0 deletions io_soulworker/out/model_file_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from io_soulworker.chunks.subm_chunk import SubmChunk
from io_soulworker.chunks.vmsh_chunk import VMshChunk
from io_soulworker.core.binary_reader import BinaryReader
from io_soulworker.core.materials_xml.shader_tag import ShaderTag
from io_soulworker.core.vis_chunk_file import VisChunkFileReader
from io_soulworker.core.vis_chunk_id import VisChunkId
from io_soulworker.core.vis_material import VisMaterial
Expand Down Expand Up @@ -116,6 +117,8 @@ def create(node: Element) -> tuple[str, VisMaterial]:
material = VisMaterial()
material.name = node.attrib["name"]

shader = ShaderTag(node.find('Shader'))

material.ambient = __color("ambient", node)

material.diffuse = node.attrib["diffuse"]
Expand Down
38 changes: 28 additions & 10 deletions io_soulworker/out/model_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
from io_soulworker.out.model_file_reader import ModelFileReader


class NodesHelper:

@staticmethod
def create_hair_nodes():
pass


class ModelImporter(ModelFileReader):

mesh: Mesh
Expand All @@ -47,6 +54,19 @@ def on_surface(self, chunk: MtrsChunk):

def create_blender_nodes(material: Material):

def get_texture_path(path: Path):
if path.exists() and path.is_file():
return path

error("FILE NOT FOUND %s", path)

path = self.path.parent / 'Textures' / path.name
if path.exists() and path.is_file():
return path

error("FILE NOT FOUND %s", path)
return None

node_tree = material.node_tree
nodes = node_tree.nodes

Expand All @@ -68,15 +88,10 @@ def create_blender_nodes(material: Material):
# )
# else:

path = self.path.parent / chunk.diffuse_map

if not path.exists() or not path.is_file():
error("FILE NOT FOUND %s", path)

path = self.path.parent / 'Textures' / path.name
if not path.exists() or not path.is_file():
error("FILE NOT FOUND %s", path)
return
path = get_texture_path(self.path.parent / chunk.diffuse_map)
if path is None:
error("No textures found for material: %s", material.name)
return

texture_node: ShaderNodeTexImage = nodes.new("ShaderNodeTexImage")
debug("texture path: %s", path)
Expand All @@ -94,6 +109,9 @@ def create_blender_nodes(material: Material):

node_tree.links.new(input, output)

if "MO_HAIR" in material.name:
NodesHelper.create_hair_nodes()

if "GLOW" in material.name:
debug("has glow")

Expand Down Expand Up @@ -228,7 +246,7 @@ def set_material(vertex_group_name: str, material_id: int):
def on_skeleton_weights(self, reader: WGHTChunkReader):

count = len(self.mesh.vertices)
reader.all_of(count)
values = reader.all_of(count)


# https://youtu.be/UXQGKfCWCBc
Expand Down

0 comments on commit cebb53b

Please sign in to comment.