Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

from .fast64_internal.mk64.mk64_constants import mk64_world_defaults
from .fast64_internal.mk64 import mk64_register, mk64_unregister
from .fast64_internal.mk64.mk64_properties import MK64_ObjectProperties, MK64_CurveProperties, MK64_Properties
from .fast64_internal.mk64.mk64_properties import MK64_ObjectProperties, MK64_Properties

from .fast64_internal.f3d.f3d_material import (
F3D_MAT_CUR_VERSION,
Expand Down Expand Up @@ -396,6 +396,7 @@ def set_game_defaults(scene: bpy.types.Scene, set_ucode=True):
world_defaults = oot_world_defaults
elif scene.gameEditorMode == "MK64":
f3d_type = "F3DEX/LX"
world_defaults = mk64_world_defaults
elif scene.gameEditorMode == "Homebrew":
f3d_type = "F3D"
world_defaults = {} # This will set some pretty bad defaults, but trust the user
Expand Down
19 changes: 19 additions & 0 deletions fast64_internal/f3d/f3d_material_presets.py
Original file line number Diff line number Diff line change
Expand Up @@ -6444,4 +6444,23 @@
"sm64_vertex_colored_texture": sm64_vertex_colored_texture,
"sm64_vertex_colored_texture_transparent": sm64_vertex_colored_texture_transparent,
},
"mk64": { # DO NOT DELETE THIS SECTION (unless you tested and found an unsupported one)
"shaded_environment_mapped": shaded_environment_mapped,
"shaded_environment_mapped_transparent": shaded_environment_mapped_transparent,
"shaded_multitexture_lerp": shaded_multitexture_lerp,
"shaded_multitexture_lerp_transparent": shaded_multitexture_lerp_transparent,
"shaded_solid": shaded_solid,
"shaded_multitexture_lerp_transparent_vertex_alpha": shaded_multitexture_lerp_transparent_vertex_alpha,
"shaded_solid_transparent": shaded_solid_transparent,
"shaded_texture": shaded_texture,
"shaded_texture_cutout": shaded_texture_cutout,
"shaded_texture_transparent": shaded_texture_transparent,
"shaded_texture_transparent_vertex_alpha": shaded_texture_transparent_vertex_alpha,
"unlit_texture": unlit_texture,
"unlit_texture_cutout": unlit_texture_cutout,
"unlit_texture_transparent": unlit_texture_transparent,
"vertex_colored_texture": vertex_colored_texture,
"vertex_colored_texture_cutout": vertex_colored_texture_cutout,
"vertex_colored_texture_transparent": vertex_colored_texture_transparent,
},
}
48 changes: 45 additions & 3 deletions fast64_internal/mk64/mk64_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,53 @@
"RAMP": 255,
}

enum_actor_types = [
("Piranha_Plant", "Piranha Plant", "Piranha Plant"),
("Other", "Other", "Other"),
enum_clip_types = [
("CLIP_NONE", "No Clip", "CLIP_NONE"),
("CLIP_DEFAULT", "Clip All", "CLIP_DEFAULT"),
("CLIP_SINGLE_SIDED_WALL", "Single-sided Wall", "CLIP_SINGLE_SIDED_WALL"),
("CLIP_SURFACE", "Surface", "CLIP_SURFACE"),
("CLIP_DOUBLE_SIDED_WALL", "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_path_type = [
("TRACK_PATH_1", "Track Path 1", "TRACK_PATH_1"),
("TRACK_PATH_2", "Track Path 2", "TRACK_PATH_2"),
("TRACK_PATH_3", "Track Path 3", "TRACK_PATH_3"),
("TRACK_PATH_4", "Track Path 4", "TRACK_PATH_4"),
("VEHICLE_PATH", "Vehicle Path", "VEHICLE_PATH"),
]

PATH_TYPE_ENUM = {
"TRACK_PATH_1": 0,
"TRACK_PATH_2": 1,
"TRACK_PATH_3": 2,
"TRACK_PATH_4": 3,
"VEHICLE_PATH": 4,
"ACTOR_PATH": 5,
}

mk64_world_defaults = {
"geometryMode": {
"zBuffer": True,
Expand Down
46 changes: 28 additions & 18 deletions fast64_internal/mk64/mk64_course.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
# ------------------------------------------------------------------------
from __future__ import annotations

from bpy.props import FloatVectorProperty
import bpy

import os, struct, math
from pathlib import Path
from mathutils import Vector, Euler, Matrix
from dataclasses import dataclass, fields

from .mk64_constants import MODEL_HEADER, SURFACE_TYPE_ENUM
from .mk64_properties import MK64_ObjectProperties, MK64_CurveProperties
from .mk64_constants import MODEL_HEADER, SURFACE_TYPE_ENUM, CLIP_TYPE_ENUM, DRAW_LAYER_ENUM, PATH_TYPE_ENUM
from .mk64_properties import MK64_ObjectProperties

from ..f3d.f3d_writer import exportF3DCommon, getInfoDict, TriangleConverterInfo, saveStaticModel
from ..f3d.f3d_bleed import BleedGraphics
Expand Down Expand Up @@ -110,6 +111,7 @@ def add_actor(self, obj: bpy.Types.Object, transform: Matrix, fModel: FModel):
return

def add_curve(self, obj: bpy.Types.Object, transform: Matrix, fModel: FModel):
mk64_props: MK64_ObjectProperties = obj.fast64.mk64
curve_data = obj.data

points = []
Expand All @@ -133,10 +135,11 @@ def add_curve(self, obj: bpy.Types.Object, transform: Matrix, fModel: FModel):
points.append(pos_int)

if points:
fModel.path.append(MK64_Path(points))
fModel.path.append(MK64_Path(points, mk64_props.path_type))
return

def add_path(self, obj: bpy.types.Object, transform: Matrix, fModel: FModel, logging_func):
mk64_props: MK64_ObjectProperties = obj.fast64.mk64
depsgraph = bpy.context.evaluated_depsgraph_get()

eval_obj = obj.evaluated_get(depsgraph)
Expand All @@ -145,6 +148,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((
Expand All @@ -157,19 +161,30 @@ def add_path(self, obj: bpy.types.Object, transform: Matrix, fModel: FModel, log
eval_obj.to_mesh_clear()

if points:
fModel.path.append(MK64_Path(points))
fModel.path.append(MK64_Path(points, mk64_props.path_type))

# look into speeding this up by calculating just the apprent
# transform using transformMatrix vs clearing parent and applying
# transform
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 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(
Expand Down Expand Up @@ -206,18 +221,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())
Expand Down Expand Up @@ -311,7 +318,7 @@ def to_xml_track_sections(self, *args):
for i, section in enumerate(self.track_sections):

sections = "\n\t".join([
f"<Section gfx_path=\"{internal_path}/{section.gfx_list_name}\" surface=\"{SURFACE_TYPE_ENUM[section.surface_type]}\" section=\"{section.section_id:#04x}\" flags=\"{section.flags:#04x}\" />"
f"<Section gfx_path=\"{internal_path}/{section.gfx_list_name}\" surface=\"{SURFACE_TYPE_ENUM[section.surface_type]}\" section=\"{section.section_id:#04x}\" flags=\"{CLIP_TYPE_ENUM[section.clip]}\" drawlayer=\"{DRAW_LAYER_ENUM[section.drawLayer]}\" x=\"{section.location[0]:.6f}\" y=\"{section.location[1]:.6f}\" z=\"{section.location[2]:.6f}\" />"
])

lines.extend((
Expand Down Expand Up @@ -359,7 +366,7 @@ def to_xml_path(self, *args):
waypoints = "\n\t\t".join([f"<Point X=\"{x}\" Y=\"{y}\" Z=\"{z}\" ID=\"{pid}\"/>" for x, y, z, pid in path.points])

lines.extend((
f"\t<TrackWaypoint>",
f"\t<TrackWaypoint type=\"{PATH_TYPE_ENUM[path.path_type]}\">",
f"\t\t{waypoints}",
f"\t\t<Point X=\"-32768\" Y=\"-32768\" Z=\"-32768\" ID=\"0\"/>",
f"\t</TrackWaypoint>"
Expand All @@ -380,14 +387,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)} }}"

Expand Down Expand Up @@ -422,6 +431,7 @@ class MK64_Path:

# List of {x, y, z, id},
points: List[Tuple[int, int, int, int]] # id is unsigned
path_type: Int

def to_c(self):
lines = []
Expand Down
10 changes: 5 additions & 5 deletions fast64_internal/mk64/mk64_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,11 @@ def execute(self, context):
selected_roots = [
obj for obj in selected
if obj.type == "EMPTY"
and obj.fast64.mk64.obj_type == "Course Root"
and obj.fast64.mk64.obj_type == "Track Root"
]

if len(selected_roots) > 1:
raise PluginError("Multiple Course Roots selected.")
raise PluginError("Multiple Track Roots selected.")

if selected_roots:
root = selected_roots[0]
Expand All @@ -147,18 +147,18 @@ def execute(self, context):
visited.add(current)
if (
current.type == "EMPTY"
and current.fast64.mk64.obj_type == "Course Root"
and current.fast64.mk64.obj_type == "Track Root"
):
course_roots.add(current)
break
current = current.parent

if not course_roots:
raise PluginError("No Course Root found.")
raise PluginError("No Track Root found.")

if len(course_roots) > 1:
raise PluginError(
"Multiple Course Roots found. Select one explicitly."
"Multiple Track Roots found. Select one."
)

root = course_roots.pop()
Expand Down
21 changes: 13 additions & 8 deletions fast64_internal/mk64/mk64_panels.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from ..utility import prop_split
from ..panels import MK64_Panel

from .mk64_properties import MK64_ImportProperties
from .mk64_properties import MK64_ImportProperties, MK64_ObjectProperties
from .mk64_operators import MK64_ImportCourseDL, MK64_ExportCourse


Expand Down Expand Up @@ -60,16 +60,21 @@ def draw(self, context):
box.label(text="MK64 Object Properties")
obj = context.object
props = obj.fast64.mk64
if obj.type == "MESH":
self.draw_mesh_props(box, props)
else:
if obj.type == "EMPTY":
prop_split(box, props, "obj_type", "object type")
elif obj.type == "MESH":
self.draw_mesh_props(box, props)
elif obj.type == "CURVE":
self.draw_curve_props(box, props)

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, "section_id", "Section ID")
prop_split(layout, props, "col_type", "Collision Type")
prop_split(layout, props, "section_id", "Section ID")
prop_split(layout, props, "surface_type", "Surface")
prop_split(layout, props, "clip_type", "Clip")
prop_split(layout, props, "draw_layer", "Draw Layer")

def draw_curve_props(self, layout: UILayout, props: MK64_ObjectProperties):
prop_split(layout, props, "path_type", "Path Type")


class MK64_CurvePanel(MK64_Panel):
Expand Down
30 changes: 14 additions & 16 deletions fast64_internal/mk64/mk64_properties.py
Original file line number Diff line number Diff line change
@@ -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_path_type

from ..render_settings import on_update_render_settings

Expand Down Expand Up @@ -111,32 +111,30 @@ class MK64_ObjectProperties(PropertyGroup):
obj_type: EnumProperty(
name="Object Type",
items=[
("Course Root", "Course Root", "Course Root"),
("Track Root", "Track Root", "Track Root"),
("Actor", "Actor", "Actor"),
],
)
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")
# For mesh objects
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")

# If you ever need properties for actors place them here
# Note that HM64 Actors should be custom actors that you make
# and then export into the game. Placing actors in the track should be done in the game editor
# actor_type: EnumProperty(name="Actor Type", items=enum_actor_types)

class MK64_CurveProperties(PropertyGroup):
"""
Properties for curve data, linked to curve objects
found under curve.fast64.mk64
"""

section_id: IntProperty(name="section_id", default=255, min=0, max=255)

# For path/curve objects
path_type: EnumProperty(name="Path Type", items=enum_path_type, default="TRACK_PATH_1")

mk64_property_classes = (
MK64_ImportProperties,
MK64_ExportProperties,
MK64_ObjectProperties,
MK64_CurveProperties,
MK64_Properties,
)

Expand Down
Loading