Skip to content
Open
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
23 changes: 20 additions & 3 deletions fast64_internal/z64/exporter/collision/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ def getCollisionData(dataHolder: Optional[Object], transform: Matrix, useMacros:
for i, face in enumerate(meshObj.data.loop_triangles):
material = meshObj.material_slots[face.material_index].material
colProp = material.ootCollisionProperty
raise_error = False

# get bounds and vertices data
planePoint = transform @ meshObj.data.vertices[face.vertices[0]].co
Expand All @@ -119,13 +120,29 @@ def getCollisionData(dataHolder: Optional[Object], transform: Matrix, useMacros:
)
distance = convertIntTo2sComplement(distance, 2, True)

def sq(val):
return val * val

nx = (y2 - y1) * (z3 - z2) - (z2 - z1) * (y3 - y2)
ny = (z2 - z1) * (x3 - x2) - (x2 - x1) * (z3 - z2)
nz = (x2 - x1) * (y3 - y2) - (y2 - y1) * (x3 - x2)
magSqr = nx * nx + ny * ny + nz * nz
magSqr = sq(nx) + sq(ny) + sq(nz)
if magSqr <= 0:
print("INFO: Ignore denormalized triangle.")
continue
raise_error = True

# for walls only, see https://github.com/zeldaret/oot/blob/eb5dac74d6435baf85ced9158d3ff915ba8872ca/src/code/z_bgcheck.c#L751
if normal[1] >= -0.8 and normal[1] <= 0.5:
normal_xz = math.sqrt(sq(normal[0]) + sq(normal[2]))
if math.fabs(normal_xz) < 0.008:
raise_error = True

if raise_error:
raise PluginError(
f"degenerate triangle detected on mesh object '{meshObj.name}' (material name is '{material.name}')"
)

if normal[0] == 0 and normal[2] == 0:
raise PluginError("unexpected degenerate triangle")

indices: list[int] = []
for pos in [(x1, y1, z1), (x2, y2, z2), (x3, y3, z3)]:
Expand Down