1
0
mirror of https://github.com/DarklightGames/io_scene_psk_psa.git synced 2024-11-30 17:34:28 +01:00

Minor naming changes and refactoring

This commit is contained in:
Colin Basnett 2024-02-06 13:26:48 -08:00
parent 44100a50f0
commit c2d7eecb4f
3 changed files with 25 additions and 22 deletions

View File

@ -1,5 +1,8 @@
from typing import Optional
import bmesh
import bpy
import numpy as np
from bpy.types import Armature
from .data import *
@ -9,7 +12,7 @@ from ..helpers import *
class PskInputObjects(object):
def __init__(self):
self.mesh_objects = []
self.armature_object = None
self.armature_object: Optional[Object] = None
class PskBuildOptions(object):
@ -61,7 +64,7 @@ def get_psk_input_objects(context) -> PskInputObjects:
class PskBuildResult(object):
def __init__(self):
self.psk = None
self.warnings = []
self.warnings: List[str] = []
def build_psk(context, options: PskBuildOptions) -> PskBuildResult:
@ -217,11 +220,11 @@ def build_psk(context, options: PskBuildOptions) -> PskBuildResult:
# Build a list of non-unique wedges.
wedges = []
for loop_index, loop in enumerate(mesh_data.loops):
wedge = Psk.Wedge()
wedge.point_index = loop.vertex_index + vertex_offset
wedge.u, wedge.v = uv_layer[loop_index].uv
wedge.v = 1.0 - wedge.v
wedges.append(wedge)
wedges.append(Psk.Wedge(
point_index=loop.vertex_index + vertex_offset,
u=uv_layer[loop_index].uv[0],
v=1.0 - uv_layer[loop_index].uv[1]
))
# Assign material indices to the wedges.
for triangle in mesh_data.loop_triangles:
@ -229,8 +232,8 @@ def build_psk(context, options: PskBuildOptions) -> PskBuildResult:
wedges[loop_index].material_index = material_indices[triangle.material_index]
# Populate the list of wedges with unique wedges & build a look-up table of loop indices to wedge indices
wedge_indices = {}
loop_wedge_indices = [-1] * len(mesh_data.loops)
wedge_indices = dict()
loop_wedge_indices = np.full(len(mesh_data.loops), -1)
for loop_index, wedge in enumerate(wedges):
wedge_hash = hash(wedge)
if wedge_hash in wedge_indices:

View File

@ -5,11 +5,11 @@ from ..data import *
class Psk(object):
class Wedge(object):
def __init__(self):
self.point_index: int = 0
self.u: float = 0.0
self.v: float = 0.0
self.material_index: int = 0
def __init__(self, point_index: int, u: float, v: float, material_index: int = 0):
self.point_index: int = point_index
self.u: float = u
self.v: float = v
self.material_index = material_index
def __hash__(self):
return hash(f'{self.point_index}-{self.u}-{self.v}-{self.material_index}')

View File

@ -166,38 +166,38 @@ def import_psk(psk: Psk, context, options: PskImportOptions) -> PskImportResult:
bm.to_mesh(mesh_data)
# TEXTURE COORDINATES
data_index = 0
uv_layer_data_index = 0
uv_layer = mesh_data.uv_layers.new(name='VTXW0000')
for face_index, face in enumerate(psk.faces):
if face_index in invalid_face_indices:
continue
face_wedges = [psk.wedges[i] for i in reversed(face.wedge_indices)]
for wedge in face_wedges:
uv_layer.data[data_index].uv = wedge.u, 1.0 - wedge.v
data_index += 1
uv_layer.data[uv_layer_data_index].uv = wedge.u, 1.0 - wedge.v
uv_layer_data_index += 1
# EXTRA UVS
if psk.has_extra_uvs and options.should_import_extra_uvs:
extra_uv_channel_count = int(len(psk.extra_uvs) / len(psk.wedges))
wedge_index_offset = 0
for extra_uv_index in range(extra_uv_channel_count):
data_index = 0
uv_layer_data_index = 0
uv_layer = mesh_data.uv_layers.new(name=f'EXTRAUV{extra_uv_index}')
for face_index, face in enumerate(psk.faces):
if face_index in invalid_face_indices:
continue
for wedge_index in reversed(face.wedge_indices):
u, v = psk.extra_uvs[wedge_index_offset + wedge_index]
uv_layer.data[data_index].uv = u, 1.0 - v
data_index += 1
uv_layer.data[uv_layer_data_index].uv = u, 1.0 - v
uv_layer_data_index += 1
wedge_index_offset += len(psk.wedges)
# VERTEX COLORS
if psk.has_vertex_colors and options.should_import_vertex_colors:
# Convert vertex colors to sRGB if necessary.
psk_vertex_colors = np.zeros((len(psk.vertex_colors), 4))
for i in range(len(psk.vertex_colors)):
psk_vertex_colors[i,:] = psk.vertex_colors[i].normalized()
for vertex_color_index in range(len(psk.vertex_colors)):
psk_vertex_colors[vertex_color_index,:] = psk.vertex_colors[vertex_color_index].normalized()
match options.vertex_color_space:
case 'SRGBA':
for i in range(psk_vertex_colors.shape[0]):