Compare commits
6 Commits
6.1.2
...
ut-poly-fl
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ead1e3c793 | ||
|
|
ce1a411200 | ||
|
|
82eaddf1cb | ||
|
|
eb8cee6973 | ||
|
|
c2d7eecb4f | ||
|
|
44100a50f0 |
@@ -24,6 +24,8 @@ if 'bpy' in locals():
|
|||||||
importlib.reload(psk_writer)
|
importlib.reload(psk_writer)
|
||||||
importlib.reload(psk_builder)
|
importlib.reload(psk_builder)
|
||||||
importlib.reload(psk_importer)
|
importlib.reload(psk_importer)
|
||||||
|
importlib.reload(psk_properties)
|
||||||
|
importlib.reload(psk_ui)
|
||||||
importlib.reload(psk_export_properties)
|
importlib.reload(psk_export_properties)
|
||||||
importlib.reload(psk_export_operators)
|
importlib.reload(psk_export_operators)
|
||||||
importlib.reload(psk_export_ui)
|
importlib.reload(psk_export_ui)
|
||||||
@@ -50,6 +52,8 @@ else:
|
|||||||
from .psk import writer as psk_writer
|
from .psk import writer as psk_writer
|
||||||
from .psk import builder as psk_builder
|
from .psk import builder as psk_builder
|
||||||
from .psk import importer as psk_importer
|
from .psk import importer as psk_importer
|
||||||
|
from .psk import properties as psk_properties
|
||||||
|
from .psk import ui as psk_ui
|
||||||
from .psk.export import properties as psk_export_properties
|
from .psk.export import properties as psk_export_properties
|
||||||
from .psk.export import operators as psk_export_operators
|
from .psk.export import operators as psk_export_operators
|
||||||
from .psk.export import ui as psk_export_ui
|
from .psk.export import ui as psk_export_ui
|
||||||
@@ -72,6 +76,8 @@ import bpy
|
|||||||
from bpy.props import PointerProperty
|
from bpy.props import PointerProperty
|
||||||
|
|
||||||
classes = psx_types.classes +\
|
classes = psx_types.classes +\
|
||||||
|
psk_properties.classes +\
|
||||||
|
psk_ui.classes +\
|
||||||
psk_import_operators.classes +\
|
psk_import_operators.classes +\
|
||||||
psk_export_properties.classes +\
|
psk_export_properties.classes +\
|
||||||
psk_export_operators.classes +\
|
psk_export_operators.classes +\
|
||||||
@@ -107,6 +113,7 @@ def register():
|
|||||||
bpy.types.TOPBAR_MT_file_import.append(psk_import_menu_func)
|
bpy.types.TOPBAR_MT_file_import.append(psk_import_menu_func)
|
||||||
bpy.types.TOPBAR_MT_file_export.append(psa_export_menu_func)
|
bpy.types.TOPBAR_MT_file_export.append(psa_export_menu_func)
|
||||||
bpy.types.TOPBAR_MT_file_import.append(psa_import_menu_func)
|
bpy.types.TOPBAR_MT_file_import.append(psa_import_menu_func)
|
||||||
|
bpy.types.Material.psk = PointerProperty(type=psk_properties.PSX_PG_material)
|
||||||
bpy.types.Scene.psa_import = PointerProperty(type=psa_import_properties.PSA_PG_import)
|
bpy.types.Scene.psa_import = PointerProperty(type=psa_import_properties.PSA_PG_import)
|
||||||
bpy.types.Scene.psa_export = PointerProperty(type=psa_export_properties.PSA_PG_export)
|
bpy.types.Scene.psa_export = PointerProperty(type=psa_export_properties.PSA_PG_export)
|
||||||
bpy.types.Scene.psk_export = PointerProperty(type=psk_export_properties.PSK_PG_export)
|
bpy.types.Scene.psk_export = PointerProperty(type=psk_export_properties.PSK_PG_export)
|
||||||
@@ -114,6 +121,7 @@ def register():
|
|||||||
|
|
||||||
|
|
||||||
def unregister():
|
def unregister():
|
||||||
|
del bpy.types.Material.psk
|
||||||
del bpy.types.Scene.psa_import
|
del bpy.types.Scene.psa_import
|
||||||
del bpy.types.Scene.psa_export
|
del bpy.types.Scene.psa_export
|
||||||
del bpy.types.Scene.psk_export
|
del bpy.types.Scene.psk_export
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ def update_actions_and_timeline_markers(context: Context, armature: Armature):
|
|||||||
if not is_action_for_armature(armature, action):
|
if not is_action_for_armature(armature, action):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if not action.name.startswith('#'):
|
if action.name != '' and not action.name.startswith('#'):
|
||||||
for (name, frame_start, frame_end) in get_sequences_from_action(action):
|
for (name, frame_start, frame_end) in get_sequences_from_action(action):
|
||||||
item = pg.action_list.add()
|
item = pg.action_list.add()
|
||||||
item.action = action
|
item.action = action
|
||||||
@@ -60,7 +60,7 @@ def update_actions_and_timeline_markers(context: Context, armature: Armature):
|
|||||||
# Pose markers are not guaranteed to be in frame-order, so make sure that they are.
|
# Pose markers are not guaranteed to be in frame-order, so make sure that they are.
|
||||||
pose_markers = sorted(action.pose_markers, key=lambda x: x.frame)
|
pose_markers = sorted(action.pose_markers, key=lambda x: x.frame)
|
||||||
for pose_marker_index, pose_marker in enumerate(pose_markers):
|
for pose_marker_index, pose_marker in enumerate(pose_markers):
|
||||||
if pose_marker.name.startswith('#'):
|
if pose_marker.name.strip() == '' or pose_marker.name.startswith('#'):
|
||||||
continue
|
continue
|
||||||
for (name, frame_start, frame_end) in get_sequences_from_action_pose_marker(action, pose_markers, pose_marker, pose_marker_index):
|
for (name, frame_start, frame_end) in get_sequences_from_action_pose_marker(action, pose_markers, pose_marker, pose_marker_index):
|
||||||
item = pg.action_list.add()
|
item = pg.action_list.add()
|
||||||
@@ -78,7 +78,7 @@ def update_actions_and_timeline_markers(context: Context, armature: Armature):
|
|||||||
for marker_name in marker_names:
|
for marker_name in marker_names:
|
||||||
if marker_name not in sequence_frame_ranges:
|
if marker_name not in sequence_frame_ranges:
|
||||||
continue
|
continue
|
||||||
if marker_name.startswith('#'):
|
if marker_name.strip() == '' or marker_name.startswith('#'):
|
||||||
continue
|
continue
|
||||||
frame_start, frame_end = sequence_frame_ranges[marker_name]
|
frame_start, frame_end = sequence_frame_ranges[marker_name]
|
||||||
sequences = get_sequences_from_name_and_frame_range(marker_name, frame_start, frame_end)
|
sequences = get_sequences_from_name_and_frame_range(marker_name, frame_start, frame_end)
|
||||||
@@ -110,7 +110,7 @@ def get_animation_data_object(context: Context) -> Object:
|
|||||||
if active_object.type != 'ARMATURE':
|
if active_object.type != 'ARMATURE':
|
||||||
raise RuntimeError('Selected object must be an Armature')
|
raise RuntimeError('Selected object must be an Armature')
|
||||||
|
|
||||||
if pg.should_override_animation_data:
|
if pg.sequence_source != 'ACTIONS' and pg.should_override_animation_data:
|
||||||
animation_data_object = pg.animation_data_override
|
animation_data_object = pg.animation_data_override
|
||||||
else:
|
else:
|
||||||
animation_data_object = active_object
|
animation_data_object = active_object
|
||||||
|
|||||||
@@ -1,15 +1,19 @@
|
|||||||
|
from typing import Optional
|
||||||
|
|
||||||
import bmesh
|
import bmesh
|
||||||
import bpy
|
import bpy
|
||||||
from bpy.types import Armature
|
import numpy as np
|
||||||
|
from bpy.types import Armature, Material
|
||||||
|
|
||||||
from .data import *
|
from .data import *
|
||||||
|
from .properties import get_poly_flags
|
||||||
from ..helpers import *
|
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):
|
||||||
@@ -17,7 +21,7 @@ class PskBuildOptions(object):
|
|||||||
self.bone_filter_mode = 'ALL'
|
self.bone_filter_mode = 'ALL'
|
||||||
self.bone_collection_indices: List[int] = []
|
self.bone_collection_indices: List[int] = []
|
||||||
self.use_raw_mesh_data = True
|
self.use_raw_mesh_data = True
|
||||||
self.material_names: List[str] = []
|
self.materials: List[Material] = []
|
||||||
self.should_enforce_bone_name_restrictions = False
|
self.should_enforce_bone_name_restrictions = False
|
||||||
|
|
||||||
|
|
||||||
@@ -61,7 +65,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:
|
||||||
@@ -135,21 +139,25 @@ def build_psk(context, options: PskBuildOptions) -> PskBuildResult:
|
|||||||
psk.bones.append(psk_bone)
|
psk.bones.append(psk_bone)
|
||||||
|
|
||||||
# MATERIALS
|
# MATERIALS
|
||||||
material_names = options.material_names
|
for material in options.materials:
|
||||||
|
|
||||||
for material_name in material_names:
|
|
||||||
psk_material = Psk.Material()
|
psk_material = Psk.Material()
|
||||||
try:
|
try:
|
||||||
psk_material.name = bytes(material_name, encoding='windows-1252')
|
psk_material.name = bytes(material.name, encoding='windows-1252')
|
||||||
except UnicodeEncodeError:
|
except UnicodeEncodeError:
|
||||||
raise RuntimeError(f'Material name "{material_name}" contains characters that cannot be encoded in the Windows-1252 codepage')
|
raise RuntimeError(f'Material name "{material.name}" contains characters that cannot be encoded in the Windows-1252 codepage')
|
||||||
psk_material.texture_index = len(psk.materials)
|
psk_material.texture_index = len(psk.materials)
|
||||||
|
psk_material.poly_flags = get_poly_flags(material.psk)
|
||||||
|
print(psk_material.name, psk_material.poly_flags)
|
||||||
psk.materials.append(psk_material)
|
psk.materials.append(psk_material)
|
||||||
|
|
||||||
context.window_manager.progress_begin(0, len(input_objects.mesh_objects))
|
context.window_manager.progress_begin(0, len(input_objects.mesh_objects))
|
||||||
|
|
||||||
|
material_names = [m.name for m in options.materials]
|
||||||
|
|
||||||
for object_index, input_mesh_object in enumerate(input_objects.mesh_objects):
|
for object_index, input_mesh_object in enumerate(input_objects.mesh_objects):
|
||||||
|
|
||||||
|
should_flip_normals = False
|
||||||
|
|
||||||
# MATERIALS
|
# MATERIALS
|
||||||
material_indices = [material_names.index(material_slot.material.name) for material_slot in input_mesh_object.material_slots]
|
material_indices = [material_names.index(material_slot.material.name) for material_slot in input_mesh_object.material_slots]
|
||||||
|
|
||||||
@@ -177,8 +185,16 @@ def build_psk(context, options: PskBuildOptions) -> PskBuildResult:
|
|||||||
mesh_object.matrix_world = input_mesh_object.matrix_world
|
mesh_object.matrix_world = input_mesh_object.matrix_world
|
||||||
|
|
||||||
scale = (input_mesh_object.scale.x, input_mesh_object.scale.y, input_mesh_object.scale.z)
|
scale = (input_mesh_object.scale.x, input_mesh_object.scale.y, input_mesh_object.scale.z)
|
||||||
if any(map(lambda x: x < 0, scale)):
|
|
||||||
result.warnings.append(f'Mesh "{input_mesh_object.name}" has negative scaling which may result in inverted normals.')
|
# Negative scaling in Blender results in inverted normals after the scale is applied. However, if the scale
|
||||||
|
# is not applied, the normals will appear unaffected in the viewport. The evaluated mesh data used in the
|
||||||
|
# export will have the scale applied, but this behavior is not obvious to the user.
|
||||||
|
#
|
||||||
|
# In order to have the exporter be as WYSIWYG as possible, we need to check for negative scaling and invert
|
||||||
|
# the normals if necessary. If two axes have negative scaling and the third has positive scaling, the
|
||||||
|
# normals will be correct. We can detect this by checking if the number of negative scaling axes is odd. If
|
||||||
|
# it is, we need to invert the normals of the mesh by swapping the order of the vertices in each face.
|
||||||
|
should_flip_normals = sum(1 for x in scale if x < 0) % 2 == 1
|
||||||
|
|
||||||
# Copy the vertex groups
|
# Copy the vertex groups
|
||||||
for vertex_group in input_mesh_object.vertex_groups:
|
for vertex_group in input_mesh_object.vertex_groups:
|
||||||
@@ -207,11 +223,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:
|
||||||
@@ -219,8 +235,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:
|
||||||
@@ -233,6 +249,7 @@ def build_psk(context, options: PskBuildOptions) -> PskBuildResult:
|
|||||||
|
|
||||||
# FACES
|
# FACES
|
||||||
poly_groups, groups = mesh_data.calc_smooth_groups(use_bitflags=True)
|
poly_groups, groups = mesh_data.calc_smooth_groups(use_bitflags=True)
|
||||||
|
psk_face_start_index = len(psk.faces)
|
||||||
for f in mesh_data.loop_triangles:
|
for f in mesh_data.loop_triangles:
|
||||||
face = Psk.Face()
|
face = Psk.Face()
|
||||||
face.material_index = material_indices[f.material_index]
|
face.material_index = material_indices[f.material_index]
|
||||||
@@ -242,6 +259,11 @@ def build_psk(context, options: PskBuildOptions) -> PskBuildResult:
|
|||||||
face.smoothing_groups = poly_groups[f.polygon_index]
|
face.smoothing_groups = poly_groups[f.polygon_index]
|
||||||
psk.faces.append(face)
|
psk.faces.append(face)
|
||||||
|
|
||||||
|
if should_flip_normals:
|
||||||
|
# Invert the normals of the faces.
|
||||||
|
for face in psk.faces[psk_face_start_index:]:
|
||||||
|
face.wedge_indices[0], face.wedge_indices[2] = face.wedge_indices[2], face.wedge_indices[0]
|
||||||
|
|
||||||
# WEIGHTS
|
# WEIGHTS
|
||||||
if armature_object is not None:
|
if armature_object is not None:
|
||||||
armature_data = typing.cast(Armature, armature_object.data)
|
armature_data = typing.cast(Armature, armature_object.data)
|
||||||
|
|||||||
@@ -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}')
|
||||||
|
|||||||
@@ -20,19 +20,19 @@ def is_bone_filter_mode_item_available(context, identifier):
|
|||||||
def populate_material_list(mesh_objects, material_list):
|
def populate_material_list(mesh_objects, material_list):
|
||||||
material_list.clear()
|
material_list.clear()
|
||||||
|
|
||||||
material_names = []
|
materials = []
|
||||||
for mesh_object in mesh_objects:
|
for mesh_object in mesh_objects:
|
||||||
for i, material_slot in enumerate(mesh_object.material_slots):
|
for i, material_slot in enumerate(mesh_object.material_slots):
|
||||||
material = material_slot.material
|
material = material_slot.material
|
||||||
# TODO: put this in the poll arg?
|
# TODO: put this in the poll arg?
|
||||||
if material is None:
|
if material is None:
|
||||||
raise RuntimeError('Material slot cannot be empty (index ' + str(i) + ')')
|
raise RuntimeError('Material slot cannot be empty (index ' + str(i) + ')')
|
||||||
if material.name not in material_names:
|
if material not in materials:
|
||||||
material_names.append(material.name)
|
materials.append(material)
|
||||||
|
|
||||||
for index, material_name in enumerate(material_names):
|
for index, material in enumerate(materials):
|
||||||
m = material_list.add()
|
m = material_list.add()
|
||||||
m.material_name = material_name
|
m.material = material
|
||||||
m.index = index
|
m.index = index
|
||||||
|
|
||||||
|
|
||||||
@@ -159,9 +159,9 @@ class PSK_OT_export(Operator, ExportHelper):
|
|||||||
options.bone_filter_mode = pg.bone_filter_mode
|
options.bone_filter_mode = pg.bone_filter_mode
|
||||||
options.bone_collection_indices = [x.index for x in pg.bone_collection_list if x.is_selected]
|
options.bone_collection_indices = [x.index for x in pg.bone_collection_list if x.is_selected]
|
||||||
options.use_raw_mesh_data = pg.use_raw_mesh_data
|
options.use_raw_mesh_data = pg.use_raw_mesh_data
|
||||||
options.material_names = [m.material_name for m in pg.material_list]
|
options.materials = [m.material for m in pg.material_list]
|
||||||
options.should_enforce_bone_name_restrictions = pg.should_enforce_bone_name_restrictions
|
options.should_enforce_bone_name_restrictions = pg.should_enforce_bone_name_restrictions
|
||||||
|
|
||||||
try:
|
try:
|
||||||
result = build_psk(context, options)
|
result = build_psk(context, options)
|
||||||
for warning in result.warnings:
|
for warning in result.warnings:
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
from bpy.props import EnumProperty, CollectionProperty, IntProperty, BoolProperty, StringProperty
|
from bpy.props import EnumProperty, CollectionProperty, IntProperty, BoolProperty, PointerProperty
|
||||||
from bpy.types import PropertyGroup
|
from bpy.types import PropertyGroup, Material
|
||||||
|
|
||||||
from ...types import PSX_PG_bone_collection_list_item
|
from ...types import PSX_PG_bone_collection_list_item
|
||||||
|
|
||||||
|
|
||||||
class PSK_PG_material_list_item(PropertyGroup):
|
class PSK_PG_material_list_item(PropertyGroup):
|
||||||
material_name: StringProperty()
|
material: PointerProperty(type=Material)
|
||||||
index: IntProperty()
|
index: IntProperty()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ from bpy.types import UIList
|
|||||||
class PSK_UL_materials(UIList):
|
class PSK_UL_materials(UIList):
|
||||||
def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
|
def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
|
||||||
row = layout.row()
|
row = layout.row()
|
||||||
row.label(text=str(getattr(item, 'material_name')), icon='MATERIAL')
|
row.prop(item.material, 'name', text='', emboss=False, icon_value=layout.icon(item.material))
|
||||||
|
|
||||||
|
|
||||||
classes = (
|
classes = (
|
||||||
|
|||||||
@@ -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]):
|
||||||
|
|||||||
38
io_scene_psk_psa/psk/properties.py
Normal file
38
io_scene_psk_psa/psk/properties.py
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
from bpy.props import EnumProperty
|
||||||
|
from bpy.types import PropertyGroup
|
||||||
|
|
||||||
|
mesh_triangle_types_items = (
|
||||||
|
('MTT_Normal', 'Normal', 'Normal one-sided', 0),
|
||||||
|
('MTT_NormalTwoSided', 'Normal Two-Sided', 'Normal but two-sided', 1),
|
||||||
|
('MTT_Translucent', 'Translucent', 'Translucent two-sided', 2),
|
||||||
|
('MTT_Masked', 'Masked', 'Masked two-sided', 3),
|
||||||
|
('MTT_Modulate', 'Modulate', 'Modulation blended two-sided', 4),
|
||||||
|
('MTT_Placeholder', 'Placeholder', 'Placeholder triangle for positioning weapon. Invisible', 8),
|
||||||
|
)
|
||||||
|
|
||||||
|
mesh_triangle_bit_flags_items = (
|
||||||
|
('MTT_Unlit', 'Unlit', 'Full brightness, no lighting', 16),
|
||||||
|
('MTT_Flat', 'Flat', 'Flat surface, don\'t do bMeshCurvy thing', 32),
|
||||||
|
('MTT_Environment', 'Environment', 'Environment mapped', 64),
|
||||||
|
('MTT_NoSmooth', 'No Smooth', 'No bilinear filtering on this poly\'s texture', 128),
|
||||||
|
)
|
||||||
|
|
||||||
|
class PSX_PG_material(PropertyGroup):
|
||||||
|
mesh_triangle_type: EnumProperty(items=mesh_triangle_types_items, name='Triangle Type')
|
||||||
|
mesh_triangle_bit_flags: EnumProperty(items=mesh_triangle_bit_flags_items, name='Triangle Bit Flags',
|
||||||
|
options={'ENUM_FLAG'})
|
||||||
|
|
||||||
|
mesh_triangle_types_items_dict = {item[0]: item[3] for item in mesh_triangle_types_items}
|
||||||
|
mesh_triangle_bit_flags_items_dict = {item[0]: item[3] for item in mesh_triangle_bit_flags_items}
|
||||||
|
|
||||||
|
|
||||||
|
def get_poly_flags(material: PSX_PG_material) -> int:
|
||||||
|
poly_flags = 0
|
||||||
|
poly_flags |= mesh_triangle_types_items_dict[material.mesh_triangle_type]
|
||||||
|
for flag in material.mesh_triangle_bit_flags:
|
||||||
|
poly_flags |= mesh_triangle_bit_flags_items_dict[flag]
|
||||||
|
return poly_flags
|
||||||
|
|
||||||
|
classes = (
|
||||||
|
PSX_PG_material,
|
||||||
|
)
|
||||||
28
io_scene_psk_psa/psk/ui.py
Normal file
28
io_scene_psk_psa/psk/ui.py
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
from bpy.types import Panel
|
||||||
|
|
||||||
|
|
||||||
|
class PSK_PT_material(Panel):
|
||||||
|
bl_label = 'PSK Material'
|
||||||
|
bl_idname = 'PSK_PT_material'
|
||||||
|
bl_space_type = 'PROPERTIES'
|
||||||
|
bl_region_type = 'WINDOW'
|
||||||
|
bl_context = 'material'
|
||||||
|
bl_options = {'DEFAULT_CLOSED'}
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def poll(cls, context):
|
||||||
|
return context.material is not None
|
||||||
|
|
||||||
|
def draw(self, context):
|
||||||
|
layout = self.layout
|
||||||
|
layout.use_property_split = True
|
||||||
|
layout.use_property_decorate = False
|
||||||
|
material = context.material
|
||||||
|
layout.prop(material.psk, 'mesh_triangle_type')
|
||||||
|
col = layout.column()
|
||||||
|
col.prop(material.psk, 'mesh_triangle_bit_flags', expand=True, text='Flags')
|
||||||
|
|
||||||
|
|
||||||
|
classes = (
|
||||||
|
PSK_PT_material,
|
||||||
|
)
|
||||||
@@ -6,7 +6,7 @@ from ..data import Section, Vector3
|
|||||||
|
|
||||||
MAX_WEDGE_COUNT = 65536
|
MAX_WEDGE_COUNT = 65536
|
||||||
MAX_POINT_COUNT = 4294967296
|
MAX_POINT_COUNT = 4294967296
|
||||||
MAX_BONE_COUNT = 256
|
MAX_BONE_COUNT = 2147483647
|
||||||
MAX_MATERIAL_COUNT = 256
|
MAX_MATERIAL_COUNT = 256
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -51,5 +51,5 @@ classes = (
|
|||||||
PSX_PG_action_export,
|
PSX_PG_action_export,
|
||||||
PSX_PG_bone_collection_list_item,
|
PSX_PG_bone_collection_list_item,
|
||||||
PSX_UL_bone_collection_list,
|
PSX_UL_bone_collection_list,
|
||||||
PSX_PT_action
|
PSX_PT_action,
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user