Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
mauserzjeh committed Feb 18, 2024
2 parents 3413762 + 8500de4 commit fca498c
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 75 deletions.
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"python.analysis.extraPaths": [
"${workspaceFolder}\\python\\cod_asset_importer",
"D:\\CODING\\PERSONAL\\blender_autocomplete\\3.4",
"D:\\PROGRAMS\\STEAM\\steamapps\\common\\Blender\\3.6\\scripts\\modules"
"D:\\CODING\\PERSONAL\\blender_autocomplete\\4.0",
"D:\\PROGRAMS\\STEAM\\steamapps\\common\\Blender\\4.0\\scripts\\modules"
],
"rust-analyzer.linkedProjects": [
".\\rust\\cod_asset_importer\\Cargo.toml",
Expand Down
4 changes: 2 additions & 2 deletions python/cod_asset_importer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"name": "Call of Duty Asset Importer",
"description": "Import Call of Duty assets",
"author": "Soma Rádóczi",
"version": (3, 2, 0),
"blender": (3, 0, 0),
"version": (3, 3, 0),
"blender": (4, 0, 0),
"location": "File > Import -> CoD Asset Importer",
"category": "Import-Export",
"warning": "This addon is still in development",
Expand Down
2 changes: 1 addition & 1 deletion python/cod_asset_importer/addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class CodAssetImporterMenu(bpy.types.Menu):

def draw(self: bpy.types.Menu, context: bpy.types.Context):
self.layout.operator(
operator=operators.MapImporter.bl_idname, text="Import map"
operator=operators.MapImporter.bl_idname, text="Import map",
)
self.layout.operator(
operator=operators.ModelImporter.bl_idname, text="Import model"
Expand Down
73 changes: 37 additions & 36 deletions python/cod_asset_importer/blender_shadernodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,60 +3,61 @@

class BLENDER_SHADERNODES(metaclass=base_enum.BaseEnum):
SHADERNODE_OUTPUTMATERIAL = "ShaderNodeOutputMaterial"
INPUT_OUTPUTMATERIAL_SURFACE = 0
INPUT_OUTPUTMATERIAL_SURFACE = "Surface"
# ------------------------------------------------
SHADERNODE_MIXSHADER = "ShaderNodeMixShader"
INPUT_MIXSHADER_FAC = 0
INPUT_MIXSHADER_SHADER1 = 1
INPUT_MIXSHADER_SHADER2 = 2
OUTPUT_MIXSHADER_SHADER = 0
INPUT_MIXSHADER_FAC = "Fac"
INPUT_MIXSHADER_SHADER1 = 1 # Shader
INPUT_MIXSHADER_SHADER2 = 2 # Shader
OUTPUT_MIXSHADER_SHADER = "Shader"
# ------------------------------------------------
SHADERNODE_BSDFTRANSPARENT = "ShaderNodeBsdfTransparent"
OUTPUT_BSDFTRANSPARENT_BSDF = 0
OUTPUT_BSDFTRANSPARENT_BSDF = "BSDF"
# ------------------------------------------------
SHADERNODE_BSDFPRINCIPLED = "ShaderNodeBsdfPrincipled"
INPUT_BSDFPRINCIPLED_BASECOLOR = 0
INPUT_BSDFPRINCIPLED_SPECULAR = 7
INPUT_BSDFPRINCIPLED_NORMAL = 22
OUTPUT_BSDFPRINCIPLED_BSDF = 0
INPUT_BSDFPRINCIPLED_BASECOLOR = "Base Color"
INPUT_BSDFPRINCIPLED_ROUGHNESS = "Roughness"
INPUT_BSDFPRINCIPLED_SPECULAR = "Specular IOR Level"
INPUT_BSDFPRINCIPLED_NORMAL = "Normal"
OUTPUT_BSDFPRINCIPLED_BSDF = "BSDF"
# ------------------------------------------------
SHADERNODE_TEXIMAGE = "ShaderNodeTexImage"
OUTPUT_TEXIMAGE_COLOR = 0
OUTPUT_TEXIMAGE_ALPHA = 1
TEXIMAGE_COLORSPACE_LINEAR = "Linear"
OUTPUT_TEXIMAGE_COLOR = "Color"
OUTPUT_TEXIMAGE_ALPHA = "Alpha"
TEXIMAGE_COLORSPACE_SRGB = "sRGB"
# ------------------------------------------------
SHADERNODE_NORMALMAP = "ShaderNodeNormalMap"
INPUT_NORMALMAP_STRENGTH = 0
INPUT_NORMALMAP_COLOR = 1
OUTPUT_NORMALMAP_NORMAL = 0
NORMALMAP_SPACE_TANGENT = "TANGENT"
INPUT_NORMALMAP_STRENGTH = "Strength"
INPUT_NORMALMAP_COLOR = "Color"
OUTPUT_NORMALMAP_NORMAL = "Normal"
NORMALMAP_SPACE_OBJECT = "OBJECT"
# ------------------------------------------------
SHADERNODE_COMBINERGB = "ShaderNodeCombineRGB"
INPUT_COMBINERGB_R = 0
INPUT_COMBINERGB_G = 1
INPUT_COMBINERGB_B = 2
OUTPUT_COMBINERGB_IMAGE = 0
SHADERNODE_COMBINECOLOR = "ShaderNodeCombineColor"
INPUT_COMBINECOLOR_R = "Red"
INPUT_COMBINECOLOR_G = "Green"
INPUT_COMBINECOLOR_B = "Blue"
OUTPUT_COMBINECOLOR_COLOR = "Color"
# ------------------------------------------------
SHADERNODE_MATH = "ShaderNodeMath"
OUTPUT_MATH_VALUE = 0
OUTPUT_MATH_VALUE = "Value"
OPERATION_MATH_SQRT = "SQRT"
INPUT_MATH_SQRT_VALUE = 0
INPUT_MATH_SQRT_VALUE = "Value"
# ------------------------------------------------
OPERATION_MATH_SUBTRACT = "SUBTRACT"
INPUT_MATH_SUBTRACT_VALUE1 = 0
INPUT_MATH_SUBTRACT_VALUE2 = 1
INPUT_MATH_SUBTRACT_VALUE1 = 0 # Value
INPUT_MATH_SUBTRACT_VALUE2 = 1 # Value
# ------------------------------------------------
OPERATION_MATH_POWER = "POWER"
INPUT_MATH_POWER_BASE = 0
INPUT_MATH_POWER_EXPONENT = 1
INPUT_MATH_POWER_BASE = 0 # Value
INPUT_MATH_POWER_EXPONENT = 1 # Value
# ------------------------------------------------
SHADERNODE_SEPARATERGB = "ShaderNodeSeparateRGB"
INPUT_SEPARATERGB_IMAGE = 0
OUTPUT_SEPARATERGB_R = 0
OUTPUT_SEPARATERGB_G = 1
OUTPUT_SEPARATERGB_B = 2
SHADERNODE_SEPARATECOLOR = "ShaderNodeSeparateColor"
INPUT_SEPARATECOLOR_COLOR = "Color"
OUTPUT_SEPARATECOLOR_R = "Red"
OUTPUT_SEPARATECOLOR_G = "Green"
OUTPUT_SEPARATECOLOR_B = "Blue"
# ------------------------------------------------
SHADERNODE_INVERT = "ShaderNodeInvert"
INPUT_INVERT_FAC = 0
INPUT_INVERT_COLOR = 1
OUTPUT_INVERT_COLOR = 0
INPUT_INVERT_FAC = "Fac"
INPUT_INVERT_COLOR = "Color"
OUTPUT_INVERT_COLOR = "Color"
95 changes: 61 additions & 34 deletions python/cod_asset_importer/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ def material(
else:
self._import_material_v20_v25(loaded_material=loaded_material)

# TODO
def _import_material_v14(
self, loaded_material: LoadedMaterial, has_ext: bool, append_asset_path: str
) -> None:
Expand Down Expand Up @@ -339,9 +338,9 @@ def _import_material_v14(
invert_fac_default_value = 1.0
break

invert_node.inputs[
BLENDER_SHADERNODES.INPUT_INVERT_FAC
].default_value = invert_fac_default_value
invert_node.inputs[BLENDER_SHADERNODES.INPUT_INVERT_FAC].default_value = (
invert_fac_default_value
)

links.new(
invert_node.outputs[BLENDER_SHADERNODES.OUTPUT_INVERT_COLOR],
Expand All @@ -354,7 +353,6 @@ def _import_material_v14(
except:
return

# TODO
def _import_material_v20_v25(self, loaded_material: LoadedMaterial) -> None:
material_name = loaded_material.name()

Expand Down Expand Up @@ -422,7 +420,7 @@ def _import_material_v20_v25(self, loaded_material: LoadedMaterial) -> None:

texture_node = nodes.new(BLENDER_SHADERNODES.SHADERNODE_TEXIMAGE)
texture_node.label = str(loaded_texture_type)
texture_node.location = (-700, -255 * i)
texture_node.location = (-900, 600 - (255 * i))
texture_node.image = texture_image

if loaded_texture_type == TEXTURE_TYPE.Color:
Expand All @@ -444,18 +442,27 @@ def _import_material_v20_v25(self, loaded_material: LoadedMaterial) -> None:
],
)
texture_node.image.colorspace_settings.name = (
BLENDER_SHADERNODES.TEXIMAGE_COLORSPACE_LINEAR
BLENDER_SHADERNODES.TEXIMAGE_COLORSPACE_SRGB
)
elif loaded_texture_type == TEXTURE_TYPE.Roughness:
links.new(
texture_node.outputs[BLENDER_SHADERNODES.OUTPUT_TEXIMAGE_COLOR],
principled_bsdf_node.inputs[
BLENDER_SHADERNODES.INPUT_BSDFPRINCIPLED_ROUGHNESS
],
)
texture_node.image.colorspace_settings.name = (
BLENDER_SHADERNODES.TEXIMAGE_COLORSPACE_SRGB
)
texture_node.location = (-700, -255)
elif loaded_texture_type == TEXTURE_TYPE.Normal:
texture_node.image.colorspace_settings.name = (
BLENDER_SHADERNODES.TEXIMAGE_COLORSPACE_LINEAR
BLENDER_SHADERNODES.TEXIMAGE_COLORSPACE_SRGB
)
texture_node.location = (-1900, -655)

normal_map_node = nodes.new(BLENDER_SHADERNODES.SHADERNODE_NORMALMAP)
normal_map_node.location = (-450, -650)
normal_map_node.space = BLENDER_SHADERNODES.NORMALMAP_SPACE_TANGENT
normal_map_node.space = BLENDER_SHADERNODES.NORMALMAP_SPACE_OBJECT
normal_map_node.inputs[
BLENDER_SHADERNODES.INPUT_NORMALMAP_STRENGTH
].default_value = 0.3
Expand All @@ -468,11 +475,13 @@ def _import_material_v20_v25(self, loaded_material: LoadedMaterial) -> None:
],
)

combine_rgb_node = nodes.new(BLENDER_SHADERNODES.SHADERNODE_COMBINERGB)
combine_rgb_node = nodes.new(
BLENDER_SHADERNODES.SHADERNODE_COMBINECOLOR
)
combine_rgb_node.location = (-650, -750)
links.new(
combine_rgb_node.outputs[
BLENDER_SHADERNODES.OUTPUT_COMBINERGB_IMAGE
BLENDER_SHADERNODES.OUTPUT_COMBINECOLOR_COLOR
],
normal_map_node.inputs[BLENDER_SHADERNODES.INPUT_NORMALMAP_COLOR],
)
Expand All @@ -482,7 +491,7 @@ def _import_material_v20_v25(self, loaded_material: LoadedMaterial) -> None:
math_sqrt_node.operation = BLENDER_SHADERNODES.OPERATION_MATH_SQRT
links.new(
math_sqrt_node.outputs[BLENDER_SHADERNODES.OUTPUT_MATH_VALUE],
combine_rgb_node.inputs[BLENDER_SHADERNODES.INPUT_COMBINERGB_B],
combine_rgb_node.inputs[BLENDER_SHADERNODES.INPUT_COMBINECOLOR_B],
)

math_subtract_node = nodes.new(BLENDER_SHADERNODES.SHADERNODE_MATH)
Expand Down Expand Up @@ -541,21 +550,25 @@ def _import_material_v20_v25(self, loaded_material: LoadedMaterial) -> None:
)

separate_rgb_node = nodes.new(
BLENDER_SHADERNODES.SHADERNODE_SEPARATERGB
BLENDER_SHADERNODES.SHADERNODE_SEPARATECOLOR
)
separate_rgb_node.location = (-1500, -450)
links.new(
separate_rgb_node.outputs[BLENDER_SHADERNODES.OUTPUT_SEPARATERGB_G],
combine_rgb_node.inputs[BLENDER_SHADERNODES.INPUT_COMBINERGB_G],
separate_rgb_node.outputs[
BLENDER_SHADERNODES.OUTPUT_SEPARATECOLOR_G
],
combine_rgb_node.inputs[BLENDER_SHADERNODES.INPUT_COMBINECOLOR_G],
)
links.new(
separate_rgb_node.outputs[BLENDER_SHADERNODES.OUTPUT_SEPARATERGB_G],
separate_rgb_node.outputs[
BLENDER_SHADERNODES.OUTPUT_SEPARATECOLOR_G
],
math_power_node.inputs[BLENDER_SHADERNODES.INPUT_MATH_POWER_BASE],
)
links.new(
texture_node.outputs[BLENDER_SHADERNODES.OUTPUT_TEXIMAGE_COLOR],
separate_rgb_node.inputs[
BLENDER_SHADERNODES.INPUT_SEPARATERGB_IMAGE
BLENDER_SHADERNODES.INPUT_SEPARATECOLOR_COLOR
],
)
links.new(
Expand All @@ -564,10 +577,9 @@ def _import_material_v20_v25(self, loaded_material: LoadedMaterial) -> None:
)
links.new(
texture_node.outputs[BLENDER_SHADERNODES.OUTPUT_TEXIMAGE_ALPHA],
combine_rgb_node.inputs[BLENDER_SHADERNODES.INPUT_COMBINERGB_R],
combine_rgb_node.inputs[BLENDER_SHADERNODES.INPUT_COMBINECOLOR_R],
)

# TODO
def _import_material_v62(self, loaded_material: LoadedMaterial) -> None:
material_name = loaded_material.name()

Expand Down Expand Up @@ -635,7 +647,7 @@ def _import_material_v62(self, loaded_material: LoadedMaterial) -> None:

texture_node = nodes.new(BLENDER_SHADERNODES.SHADERNODE_TEXIMAGE)
texture_node.label = str(loaded_texture_type)
texture_node.location = (-700, -255 * i)
texture_node.location = (-900, 600 - (255 * i))
texture_node.image = texture_image

if loaded_texture_type == TEXTURE_TYPE.Color:
Expand All @@ -657,18 +669,27 @@ def _import_material_v62(self, loaded_material: LoadedMaterial) -> None:
],
)
texture_node.image.colorspace_settings.name = (
BLENDER_SHADERNODES.TEXIMAGE_COLORSPACE_LINEAR
BLENDER_SHADERNODES.TEXIMAGE_COLORSPACE_SRGB
)
elif loaded_texture_type == TEXTURE_TYPE.Roughness:
links.new(
texture_node.outputs[BLENDER_SHADERNODES.OUTPUT_TEXIMAGE_COLOR],
principled_bsdf_node.inputs[
BLENDER_SHADERNODES.INPUT_BSDFPRINCIPLED_ROUGHNESS
],
)
texture_node.image.colorspace_settings.name = (
BLENDER_SHADERNODES.TEXIMAGE_COLORSPACE_SRGB
)
texture_node.location = (-700, -255)
elif loaded_texture_type == TEXTURE_TYPE.Normal:
texture_node.image.colorspace_settings.name = (
BLENDER_SHADERNODES.TEXIMAGE_COLORSPACE_LINEAR
BLENDER_SHADERNODES.TEXIMAGE_COLORSPACE_SRGB
)
texture_node.location = (-1900, -655)

normal_map_node = nodes.new(BLENDER_SHADERNODES.SHADERNODE_NORMALMAP)
normal_map_node.location = (-450, -650)
normal_map_node.space = BLENDER_SHADERNODES.NORMALMAP_SPACE_TANGENT
normal_map_node.space = BLENDER_SHADERNODES.NORMALMAP_SPACE_OBJECT
normal_map_node.inputs[
BLENDER_SHADERNODES.INPUT_NORMALMAP_STRENGTH
].default_value = 0.3
Expand All @@ -681,11 +702,13 @@ def _import_material_v62(self, loaded_material: LoadedMaterial) -> None:
],
)

combine_rgb_node = nodes.new(BLENDER_SHADERNODES.SHADERNODE_COMBINERGB)
combine_rgb_node = nodes.new(
BLENDER_SHADERNODES.SHADERNODE_COMBINECOLOR
)
combine_rgb_node.location = (-650, -750)
links.new(
combine_rgb_node.outputs[
BLENDER_SHADERNODES.OUTPUT_COMBINERGB_IMAGE
BLENDER_SHADERNODES.OUTPUT_COMBINECOLOR_COLOR
],
normal_map_node.inputs[BLENDER_SHADERNODES.INPUT_NORMALMAP_COLOR],
)
Expand All @@ -695,7 +718,7 @@ def _import_material_v62(self, loaded_material: LoadedMaterial) -> None:
math_sqrt_node.operation = BLENDER_SHADERNODES.OPERATION_MATH_SQRT
links.new(
math_sqrt_node.outputs[BLENDER_SHADERNODES.OUTPUT_MATH_VALUE],
combine_rgb_node.inputs[BLENDER_SHADERNODES.INPUT_COMBINERGB_B],
combine_rgb_node.inputs[BLENDER_SHADERNODES.INPUT_COMBINECOLOR_B],
)

math_subtract_node = nodes.new(BLENDER_SHADERNODES.SHADERNODE_MATH)
Expand Down Expand Up @@ -754,21 +777,25 @@ def _import_material_v62(self, loaded_material: LoadedMaterial) -> None:
)

separate_rgb_node = nodes.new(
BLENDER_SHADERNODES.SHADERNODE_SEPARATERGB
BLENDER_SHADERNODES.SHADERNODE_SEPARATECOLOR
)
separate_rgb_node.location = (-1500, -450)
links.new(
separate_rgb_node.outputs[BLENDER_SHADERNODES.OUTPUT_SEPARATERGB_G],
combine_rgb_node.inputs[BLENDER_SHADERNODES.INPUT_COMBINERGB_G],
separate_rgb_node.outputs[
BLENDER_SHADERNODES.OUTPUT_SEPARATECOLOR_G
],
combine_rgb_node.inputs[BLENDER_SHADERNODES.INPUT_COMBINECOLOR_G],
)
links.new(
separate_rgb_node.outputs[BLENDER_SHADERNODES.OUTPUT_SEPARATERGB_G],
separate_rgb_node.outputs[
BLENDER_SHADERNODES.OUTPUT_SEPARATECOLOR_G
],
math_power_node.inputs[BLENDER_SHADERNODES.INPUT_MATH_POWER_BASE],
)
links.new(
texture_node.outputs[BLENDER_SHADERNODES.OUTPUT_TEXIMAGE_COLOR],
separate_rgb_node.inputs[
BLENDER_SHADERNODES.INPUT_SEPARATERGB_IMAGE
BLENDER_SHADERNODES.INPUT_SEPARATECOLOR_COLOR
],
)
links.new(
Expand All @@ -777,7 +804,7 @@ def _import_material_v62(self, loaded_material: LoadedMaterial) -> None:
)
links.new(
texture_node.outputs[BLENDER_SHADERNODES.OUTPUT_TEXIMAGE_ALPHA],
combine_rgb_node.inputs[BLENDER_SHADERNODES.INPUT_COMBINERGB_R],
combine_rgb_node.inputs[BLENDER_SHADERNODES.INPUT_COMBINECOLOR_R],
)

def _import_texture(
Expand Down
2 changes: 2 additions & 0 deletions python/cod_asset_importer/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class MapImporter(bpy.types.Operator):
bl_idname = "cod_asset_importer.map_importer"
bl_label = "Import"
bl_options = {"UNDO"}
bl_description = "Import a map file"

filepath: bpy.props.StringProperty(subtype="FILE_PATH")
filename_ext = ".d3dbsp"
Expand All @@ -37,6 +38,7 @@ class ModelImporter(bpy.types.Operator):
bl_idname = "cod_asset_importer.model_importer"
bl_label = "Import"
bl_options = {"UNDO"}
bl_description = "Import a model file"

filepath: bpy.props.StringProperty(subtype="FILE_PATH")
version: bpy.props.EnumProperty(
Expand Down

0 comments on commit fca498c

Please sign in to comment.