diff --git a/fast64_internal/mk64/mk64_constants.py b/fast64_internal/mk64/mk64_constants.py index 4fac1d64c..4503f554e 100644 --- a/fast64_internal/mk64/mk64_constants.py +++ b/fast64_internal/mk64/mk64_constants.py @@ -58,6 +58,36 @@ "RAMP": 255, } +enum_clip_types = [ + ("CLIP_NONE", "CLIP_NONE", "CLIP_NONE"), + ("CLIP_DEFAULT", "CLIP_DEFAULT", "CLIP_DEFAULT"), + ("CLIP_SINGLE_SIDED_WALL", "CLIP_SINGLE_SIDED_WALL", "CLIP_SINGLE_SIDED_WALL"), + ("CLIP_SURFACE", "CLIP_SURFACE", "CLIP_SURFACE"), + ("CLIP_DOUBLE_SIDED_WALL", "CLIP_DOUBLE_SIDED_WALL", "CLIP_DOUBLE_SIDED_WALL"), +] + +CLIP_TYPE_ENUM = { + "CLIP_NONE": 0, + "CLIP_DEFAULT": 1, + "CLIP_SINGLE_SIDED_WALL": 2, + "CLIP_SURFACE": 3, + "CLIP_DOUBLE_SIDED_WALL": 4, +} + +enum_draw_layer_types = [ + ("DRAW_INVISIBLE", "DRAW_INVISIBLE", "DRAW_INVISIBLE"), + ("DRAW_OPAQUE", "DRAW_OPAQUE", "DRAW_OPAQUE"), + ("DRAW_TRANSLUCENT", "DRAW_TRANSLUCENT", "DRAW_TRANSLUCENT"), + ("DRAW_TRANSLUCENT_NO_ZBUFFER", "DRAW_TRANSLUCENT_NO_ZBUFFER", "DRAW_TRANSLUCENT_NO_ZBUFFER"), +] + +DRAW_LAYER_ENUM = { + "DRAW_INVISIBLE": 0, + "DRAW_OPAQUE": 1, + "DRAW_TRANSLUCENT": 2, + "DRAW_TRANSLUCENT_NO_ZBUFFER": 3, +} + enum_actor_types = [ ("Piranha_Plant", "Piranha Plant", "Piranha Plant"), ("Other", "Other", "Other"), diff --git a/fast64_internal/mk64/mk64_course.py b/fast64_internal/mk64/mk64_course.py index bdbcf7723..266fa239f 100644 --- a/fast64_internal/mk64/mk64_course.py +++ b/fast64_internal/mk64/mk64_course.py @@ -3,6 +3,7 @@ # ------------------------------------------------------------------------ from __future__ import annotations +from bpy.props import FloatVectorProperty import bpy import os, struct, math @@ -10,7 +11,7 @@ from mathutils import Vector, Euler, Matrix from dataclasses import dataclass, fields -from .mk64_constants import MODEL_HEADER, SURFACE_TYPE_ENUM +from .mk64_constants import MODEL_HEADER, SURFACE_TYPE_ENUM, CLIP_TYPE_ENUM, DRAW_LAYER_ENUM from .mk64_properties import MK64_ObjectProperties, MK64_CurveProperties from ..f3d.f3d_writer import exportF3DCommon, getInfoDict, TriangleConverterInfo, saveStaticModel @@ -59,6 +60,7 @@ def make_mk64_course_from_bpy(self, context: bpy.Types.Context, scale: float, ma Creates a MK64_fModel class with all model data ready to exported to c also generates lists for items, pathing and collision (in future) """ + fModel = MK64_fModel(self.root, mat_write_method) # create duplicate objects to export from transform = Matrix.Diagonal(Vector((scale, scale, scale))).to_4x4() @@ -145,6 +147,7 @@ def add_path(self, obj: bpy.types.Object, transform: Matrix, fModel: FModel, log return points = [] + for v in mesh.vertices: world_pos = transform @ eval_obj.matrix_world @ v.co points.append(( @@ -165,11 +168,25 @@ def add_path(self, obj: bpy.types.Object, transform: Matrix, fModel: FModel, log def export_f3d_from_obj( self, context: bpy.Types.Context, obj: bpy.types.Object, fModel: MK64_fModel, transformMatrix: Matrix ): + mk64_props: MK64_ObjectProperties = obj.fast64.mk64 + mk_props: MK64_Properties = context.scene.fast64.mk64 if obj and obj.type == "MESH": + # Export as object + + + # Export as normal geometry try: with context.temp_override(active_object=obj, selected_objects=[obj]): bpy.ops.object.parent_clear(type="CLEAR_KEEP_TRANSFORM") - bpy.ops.object.transform_apply(location=True, rotation=True, scale=True, properties=False) + # Treat transparent objects like a normal object which means the position is exported. + # This is required for z-sort so that they are rendered over-top of each other correctly. + # Normal geometry is placed at 0,0,0 and the vertices are used for positionnig instead. + if mk64_props.draw_layer in {'DRAW_TRANSLUCENT', 'DRAW_TRANSLUCENT_NO_ZBUFFER'}: + mk64_props.location = obj.matrix_world.to_translation() * mk_props.scale + transformMatrix.translation = Vector((0.0, 0.0, 0.0)) + bpy.ops.object.transform_apply(location=False, rotation=True, scale=True, properties=False) + else: + bpy.ops.object.transform_apply(location=True, rotation=True, scale=True, properties=False) infoDict = getInfoDict(obj) triConverterInfo = TriangleConverterInfo(obj, None, fModel.f3d, transformMatrix, infoDict) fMeshes = saveStaticModel( @@ -206,18 +223,10 @@ def __init__(self, rt: bpy.types.Object, mat_write_method, name="mk64"): # parent override so I can keep track of original mesh data # to lookup collision data later def onAddMesh(self, fMesh: FMesh, obj: bpy.Types.Object): - if not self.has_mk64_collision(obj): - return mk64_props: MK64_ObjectProperties = obj.fast64.mk64 - self.track_sections.append(MK64_TrackSection(fMesh.draw.name, mk64_props.col_type, 255, 0)) + self.track_sections.append(MK64_TrackSection(fMesh.draw.name, mk64_props.surface_type, mk64_props.section_id, mk64_props.clip_type, mk64_props.draw_layer, mk64_props.location)) return - def has_mk64_collision(self, obj: bpy.Types.Object): - if obj.type != "MESH": - return False - mk64_props: MK64_ObjectProperties = obj.fast64.mk64 - return mk64_props.has_col - def to_c(self, *args): export_data = super().to_c(*args) export_data.staticData.append(self.to_c_track_actors()) @@ -311,7 +320,7 @@ def to_xml_track_sections(self, *args): for i, section in enumerate(self.track_sections): sections = "\n\t".join([ - f"
" + f"
" ]) lines.extend(( @@ -380,14 +389,16 @@ class MK64_TrackSection: gfx_list_name: str surface_type: str section_id: Int - flags: Int + clip: Int + drawLayer: Int + location: FloatVectorProperty def to_c(self): data = ( self.gfx_list_name, self.surface_type, f"0x{self.section_id:X}", - f"0x{self.flags:X}", + f"0x{self.clip:X}", ) return f"{{ {', '.join(data)} }}" diff --git a/fast64_internal/mk64/mk64_panels.py b/fast64_internal/mk64/mk64_panels.py index 27745723f..04dad9962 100644 --- a/fast64_internal/mk64/mk64_panels.py +++ b/fast64_internal/mk64/mk64_panels.py @@ -66,11 +66,10 @@ def draw(self, context): prop_split(box, props, "obj_type", "object type") def draw_mesh_props(self, layout: UILayout, props: MK64_ObjectProperties): - prop_split(layout, props, "has_col", "Has Collision") - if props.has_col: + prop_split(layout, props, "surface_type", "Surface Type") prop_split(layout, props, "section_id", "Section ID") - prop_split(layout, props, "col_type", "Collision Type") - + prop_split(layout, props, "clip_type", "Clip Type") + prop_split(layout, props, "draw_layer", "Draw Layer") class MK64_CurvePanel(MK64_Panel): bl_label = "MK64 Curve Inspector" diff --git a/fast64_internal/mk64/mk64_properties.py b/fast64_internal/mk64/mk64_properties.py index a65d7793f..5da0d3a4c 100644 --- a/fast64_internal/mk64/mk64_properties.py +++ b/fast64_internal/mk64/mk64_properties.py @@ -1,11 +1,11 @@ import bpy -from bpy.props import StringProperty, BoolProperty, EnumProperty, IntProperty, FloatProperty, PointerProperty +from bpy.props import StringProperty, BoolProperty, EnumProperty, IntProperty, FloatProperty, PointerProperty, FloatVectorProperty from bpy.types import PropertyGroup, UILayout from bpy.utils import register_class, unregister_class from ..utility import prop_split from ..f3d.f3d_material import ootEnumDrawLayers -from .mk64_constants import enum_surface_types, enum_actor_types +from .mk64_constants import enum_surface_types, enum_clip_types, enum_draw_layer_types, enum_actor_types from ..render_settings import on_update_render_settings @@ -118,9 +118,11 @@ class MK64_ObjectProperties(PropertyGroup): actor_type: EnumProperty(name="Actor Type", items=enum_actor_types) # for mesh objects - has_col: BoolProperty(name="Has Collision", default=True) - col_type: EnumProperty(name="Collision Type", items=enum_surface_types, default="SURFACE_DEFAULT") + surface_type: EnumProperty(name="Collision Type", items=enum_surface_types, default="SURFACE_DEFAULT") section_id: IntProperty(name="section_id", default=255, min=0, max=255) + clip_type: EnumProperty(name="clip_type", items=enum_clip_types, default="CLIP_DEFAULT") + draw_layer: EnumProperty(name="draw_layer", items=enum_draw_layer_types, default="DRAW_OPAQUE") + location: FloatVectorProperty(name="Location", default=(0,0,0), size=3, description="location") class MK64_CurveProperties(PropertyGroup):