mirror of
https://github.com/DarklightGames/io_scene_psk_psa.git
synced 2025-02-25 21:18:01 +01:00
Minor naming changes and refactoring
This commit is contained in:
parent
44100a50f0
commit
c2d7eecb4f
@ -1,5 +1,8 @@
|
|||||||
|
from typing import Optional
|
||||||
|
|
||||||
import bmesh
|
import bmesh
|
||||||
import bpy
|
import bpy
|
||||||
|
import numpy as np
|
||||||
from bpy.types import Armature
|
from bpy.types import Armature
|
||||||
|
|
||||||
from .data import *
|
from .data import *
|
||||||
@ -9,7 +12,7 @@ from ..helpers import *
|
|||||||
class PskInputObjects(object):
|
class PskInputObjects(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.mesh_objects = []
|
self.mesh_objects = []
|
||||||
self.armature_object = None
|
self.armature_object: Optional[Object] = None
|
||||||
|
|
||||||
|
|
||||||
class PskBuildOptions(object):
|
class PskBuildOptions(object):
|
||||||
@ -61,7 +64,7 @@ def get_psk_input_objects(context) -> PskInputObjects:
|
|||||||
class PskBuildResult(object):
|
class PskBuildResult(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.psk = None
|
self.psk = None
|
||||||
self.warnings = []
|
self.warnings: List[str] = []
|
||||||
|
|
||||||
|
|
||||||
def build_psk(context, options: PskBuildOptions) -> PskBuildResult:
|
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.
|
# Build a list of non-unique wedges.
|
||||||
wedges = []
|
wedges = []
|
||||||
for loop_index, loop in enumerate(mesh_data.loops):
|
for loop_index, loop in enumerate(mesh_data.loops):
|
||||||
wedge = Psk.Wedge()
|
wedges.append(Psk.Wedge(
|
||||||
wedge.point_index = loop.vertex_index + vertex_offset
|
point_index=loop.vertex_index + vertex_offset,
|
||||||
wedge.u, wedge.v = uv_layer[loop_index].uv
|
u=uv_layer[loop_index].uv[0],
|
||||||
wedge.v = 1.0 - wedge.v
|
v=1.0 - uv_layer[loop_index].uv[1]
|
||||||
wedges.append(wedge)
|
))
|
||||||
|
|
||||||
# Assign material indices to the wedges.
|
# Assign material indices to the wedges.
|
||||||
for triangle in mesh_data.loop_triangles:
|
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]
|
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
|
# Populate the list of wedges with unique wedges & build a look-up table of loop indices to wedge indices
|
||||||
wedge_indices = {}
|
wedge_indices = dict()
|
||||||
loop_wedge_indices = [-1] * len(mesh_data.loops)
|
loop_wedge_indices = np.full(len(mesh_data.loops), -1)
|
||||||
for loop_index, wedge in enumerate(wedges):
|
for loop_index, wedge in enumerate(wedges):
|
||||||
wedge_hash = hash(wedge)
|
wedge_hash = hash(wedge)
|
||||||
if wedge_hash in wedge_indices:
|
if wedge_hash in wedge_indices:
|
||||||
|
@ -5,11 +5,11 @@ from ..data import *
|
|||||||
|
|
||||||
class Psk(object):
|
class Psk(object):
|
||||||
class Wedge(object):
|
class Wedge(object):
|
||||||
def __init__(self):
|
def __init__(self, point_index: int, u: float, v: float, material_index: int = 0):
|
||||||
self.point_index: int = 0
|
self.point_index: int = point_index
|
||||||
self.u: float = 0.0
|
self.u: float = u
|
||||||
self.v: float = 0.0
|
self.v: float = v
|
||||||
self.material_index: int = 0
|
self.material_index = material_index
|
||||||
|
|
||||||
def __hash__(self):
|
def __hash__(self):
|
||||||
return hash(f'{self.point_index}-{self.u}-{self.v}-{self.material_index}')
|
return hash(f'{self.point_index}-{self.u}-{self.v}-{self.material_index}')
|
||||||
|
@ -166,38 +166,38 @@ def import_psk(psk: Psk, context, options: PskImportOptions) -> PskImportResult:
|
|||||||
bm.to_mesh(mesh_data)
|
bm.to_mesh(mesh_data)
|
||||||
|
|
||||||
# TEXTURE COORDINATES
|
# TEXTURE COORDINATES
|
||||||
data_index = 0
|
uv_layer_data_index = 0
|
||||||
uv_layer = mesh_data.uv_layers.new(name='VTXW0000')
|
uv_layer = mesh_data.uv_layers.new(name='VTXW0000')
|
||||||
for face_index, face in enumerate(psk.faces):
|
for face_index, face in enumerate(psk.faces):
|
||||||
if face_index in invalid_face_indices:
|
if face_index in invalid_face_indices:
|
||||||
continue
|
continue
|
||||||
face_wedges = [psk.wedges[i] for i in reversed(face.wedge_indices)]
|
face_wedges = [psk.wedges[i] for i in reversed(face.wedge_indices)]
|
||||||
for wedge in face_wedges:
|
for wedge in face_wedges:
|
||||||
uv_layer.data[data_index].uv = wedge.u, 1.0 - wedge.v
|
uv_layer.data[uv_layer_data_index].uv = wedge.u, 1.0 - wedge.v
|
||||||
data_index += 1
|
uv_layer_data_index += 1
|
||||||
|
|
||||||
# EXTRA UVS
|
# EXTRA UVS
|
||||||
if psk.has_extra_uvs and options.should_import_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))
|
extra_uv_channel_count = int(len(psk.extra_uvs) / len(psk.wedges))
|
||||||
wedge_index_offset = 0
|
wedge_index_offset = 0
|
||||||
for extra_uv_index in range(extra_uv_channel_count):
|
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}')
|
uv_layer = mesh_data.uv_layers.new(name=f'EXTRAUV{extra_uv_index}')
|
||||||
for face_index, face in enumerate(psk.faces):
|
for face_index, face in enumerate(psk.faces):
|
||||||
if face_index in invalid_face_indices:
|
if face_index in invalid_face_indices:
|
||||||
continue
|
continue
|
||||||
for wedge_index in reversed(face.wedge_indices):
|
for wedge_index in reversed(face.wedge_indices):
|
||||||
u, v = psk.extra_uvs[wedge_index_offset + wedge_index]
|
u, v = psk.extra_uvs[wedge_index_offset + wedge_index]
|
||||||
uv_layer.data[data_index].uv = u, 1.0 - v
|
uv_layer.data[uv_layer_data_index].uv = u, 1.0 - v
|
||||||
data_index += 1
|
uv_layer_data_index += 1
|
||||||
wedge_index_offset += len(psk.wedges)
|
wedge_index_offset += len(psk.wedges)
|
||||||
|
|
||||||
# VERTEX COLORS
|
# VERTEX COLORS
|
||||||
if psk.has_vertex_colors and options.should_import_vertex_colors:
|
if psk.has_vertex_colors and options.should_import_vertex_colors:
|
||||||
# Convert vertex colors to sRGB if necessary.
|
# Convert vertex colors to sRGB if necessary.
|
||||||
psk_vertex_colors = np.zeros((len(psk.vertex_colors), 4))
|
psk_vertex_colors = np.zeros((len(psk.vertex_colors), 4))
|
||||||
for i in range(len(psk.vertex_colors)):
|
for vertex_color_index in range(len(psk.vertex_colors)):
|
||||||
psk_vertex_colors[i,:] = psk.vertex_colors[i].normalized()
|
psk_vertex_colors[vertex_color_index,:] = psk.vertex_colors[vertex_color_index].normalized()
|
||||||
match options.vertex_color_space:
|
match options.vertex_color_space:
|
||||||
case 'SRGBA':
|
case 'SRGBA':
|
||||||
for i in range(psk_vertex_colors.shape[0]):
|
for i in range(psk_vertex_colors.shape[0]):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user