Skip to content

Commit

Permalink
Version 2.2.0: GMDL now imports .tga textures as exported by GmdlExpo…
Browse files Browse the repository at this point in the history
…rt mod
  • Loading branch information
emd4600 committed Feb 3, 2020
1 parent bee7840 commit 218dba2
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 3 deletions.
4 changes: 2 additions & 2 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"name": "SporeModder Add-ons",
"author": "emd4600",
"blender": (2, 80, 0),
"version": (2, 1, 0),
"version": (2, 2, 0),
"location": "File > Import-Export",
"description": "Import Spore .gmdl and .rw4 model formats. Export .rw4 format.",
"wiki_url": "https://github.com/emd4600/SporeModder-Blender-Addons#features",
Expand Down Expand Up @@ -68,7 +68,7 @@ def execute(self, context):
from .gmdl_importer import import_gmdl

with open(self.filepath, 'br') as file:
return import_gmdl(file, False)
return import_gmdl(file, False, self.filepath)


class ImportRW4(bpy.types.Operator, ImportHelper):
Expand Down
54 changes: 53 additions & 1 deletion gmdl_importer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import bpy
import ntpath
import os
from .file_io import FileReader, ResourceKey
from . import rw4_enums

Expand Down Expand Up @@ -183,7 +184,56 @@ def read(self, file: FileReader, import_skeleton):
print(file.tell())


def import_gmdl(file, import_skeleton):
def import_textures(b_mesh, filepath):
diffuse_path = f"{filepath[:filepath.rindex('.')]}__diffuse.tga"
if os.path.isfile(diffuse_path):
gmdl_name = os.path.split(filepath)[-1]
gmdl_name = gmdl_name[:gmdl_name.rindex('.')]

material = bpy.data.materials.new(gmdl_name)
material.use_nodes = True
b_mesh.materials.append(material)

# Diffuse
image = bpy.data.images.load(diffuse_path)
image.alpha_mode = 'NONE'
texture_node = material.node_tree.nodes.new("ShaderNodeTexImage")
texture_node.image = image
texture_node.location = (-524, 256)
material.node_tree.links.new(material.node_tree.nodes["Principled BSDF"].inputs["Base Color"],
texture_node.outputs["Color"])

normal_path = f"{filepath[:filepath.rindex('.')]}__normal.tga"
if os.path.isfile(normal_path):
image = bpy.data.images.load(normal_path)
image.colorspace_settings.name = 'Non-Color'

texture_node = material.node_tree.nodes.new("ShaderNodeTexImage")
texture_node.image = image
texture_node.location = (-524, -37)

normal_map_node = material.node_tree.nodes.new("ShaderNodeNormalMap")
normal_map_node.location = (-216, -86)

material.node_tree.links.new(normal_map_node.inputs["Color"],
texture_node.outputs["Color"])

material.node_tree.links.new(material.node_tree.nodes["Principled BSDF"].inputs["Normal"],
normal_map_node.outputs["Normal"])

specular_path = f"{filepath[:filepath.rindex('.')]}__specular.tga"
if os.path.isfile(normal_path):
image = bpy.data.images.load(specular_path)

texture_node = material.node_tree.nodes.new("ShaderNodeTexImage")
texture_node.image = image
texture_node.location = (-524, -322)

material.node_tree.links.new(material.node_tree.nodes["Principled BSDF"].inputs["Specular"],
texture_node.outputs["Color"])


def import_gmdl(file, import_skeleton, filepath):
result = {'FINISHED'}

gmdl = SporeGameModel()
Expand Down Expand Up @@ -254,4 +304,6 @@ def import_gmdl(file, import_skeleton):

b_mesh.validate()

import_textures(b_mesh, filepath)

return result

0 comments on commit 218dba2

Please sign in to comment.