Skip to content

Commit b47d79e

Browse files
authored
Merge pull request #61 from MHFU-ModKit/fix/pmo-clip
fix(mhfu-port): a ported PMO's clip is its largest scale component
2 parents a0e3d18 + 8a0df67 commit b47d79e

5 files changed

Lines changed: 10 additions & 9 deletions

File tree

‎docs/formats/pmo.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ from [mhff](https://github.com/svanheulen/mhff) by Seth VanHeulen.
2222
| 0x00 | `char[4]` | `pmo\0` |
2323
| 0x04 | `char[4]` | Version, `1.0\0` or `102\0` |
2424
| 0x08 | `u32` | Size: header, tables and geometry region. Bytes after it are the tail |
25-
| 0x0C | `f32` | Clip distance; MHFU sets the largest scale component |
25+
| 0x0C | `f32` | Cull-sphere radius before the entity's scale; MHFU sets the largest scale component, and 0 culls the model as a point |
2626
| 0x10 | `f32[3]` | Scale (MHFU): multiplies the dequantised positions |
2727
| 0x1C | `u16` | Mesh count |
2828
| 0x1E | `u16` | Material count |

‎packages/mhfu-port/src/mhfu_port/mesh.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
BLEND = 0
2626
SHADOW = 0
2727
COLOR = 0xFFFFFFFF
28-
CLIP = 0.0
2928
NO_NORMAL = (0.0, 0.0, 0.0)
3029
"""Written for a donor vertex that carries no normal."""
3130

@@ -162,7 +161,8 @@ def build(skinned: Sequence[Skinned], scale: Vec3) -> pmo.Pmo:
162161
groups = [group(s, scale, material_of[s.part.texture]) for s in skinned]
163162
mesh = pmo.Mesh(groups, list(range(len(textures))), lighting=LIGHTING, blend=BLEND)
164163
materials = [pmo.Material(color=COLOR, shadow=SHADOW, texture=t) for t in textures]
165-
return pmo.Pmo([mesh], materials, scale, CLIP)
164+
# the engine's cull sphere (Pmo.clip): 0 culls the model as a point near its feet
165+
return pmo.Pmo([mesh], materials, scale, max(scale))
166166

167167

168168
def group(skinned: Skinned, scale: Vec3, material: int = 0) -> pmo.Group:

‎packages/mhfu-port/tests/test_build.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
PORTS = Path(__file__).parents[3] / "ports"
1919
BUILT = {
20-
"brute_tigrex": "a882bf01daf07df844a07da32fd6ff87ed10c9ecb1fec7e1eb207172e6ca5e29",
21-
"zinogre": "3a0b11b7556678c66364d3357107a8ee130677d2c5fde9a43c7dfd5f82948f12",
20+
"brute_tigrex": "1082b88cfaeee3086020a6b02ff59101dec4af8653ff44a4b56373a90ae87fae",
21+
"zinogre": "830a4c15ed67a8760c0462fa8bcd5fc6548ca0b00b090089bb6d382c5e5e2256",
2222
}
2323
"""sha256 of each manifest's build: changes only with an intended change to the port."""
2424
HEAD = '[port]\nname = "t"\nhost_species = 75\npac = "t.bin"\n[source]\nmodel = 5248\n'

‎packages/mhfu-port/tests/test_mesh.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def test_build():
131131
joint_of = {4: 1, 7: 2, 9: 3}
132132
built = mesh.build(skin.source(parts, joint_of), SCALE)
133133
back = fu.Pmo.from_bytes(built.to_bytes())
134-
assert back == built and back.clip == mesh.CLIP and back.scale == SCALE
134+
assert back == built and back.clip == max(SCALE) and back.scale == SCALE
135135
assert [m.texture for m in back.materials] == [2, 6]
136136
assert {(m.color, m.shadow) for m in back.materials} == {(mesh.COLOR, mesh.SHADOW)}
137137
assert back.meshes[0].materials == [0, 1] and back.meshes[0].lighting == mesh.LIGHTING
@@ -163,8 +163,8 @@ def test_palette_limit():
163163

164164

165165
DONORS = { # model, geometry: groups, vertices, triangles, sha256 of our PMO on an identity map
166-
"brute": (5248, 5249, 88, 2862, 2973, "cb0d830eb6c61a09"),
167-
"zinogre": (5339, 5340, 181, 4336, 4426, "98b3869f594ce302"),
166+
"brute": (5248, 5249, 88, 2862, 2973, "ccc9f32546fdfcbb"),
167+
"zinogre": (5339, 5340, 181, 4336, 4426, "09fd2847cff33e01"),
168168
}
169169

170170

‎packages/mhp-formats/src/mhp_formats/pmo.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,8 @@ class Pmo:
536536
scale: Vec3 = (1.0, 1.0, 1.0)
537537
"""Multiplies the dequantised positions."""
538538
clip: float = 0.0
539-
"""Clipping distance; MHFU sets it to the largest scale component."""
539+
"""Cull-sphere radius before the entity's scale, centred half a `scale.y` up; MHFU sets it to
540+
the largest scale component, and 0 culls the model as a point."""
540541
tail: bytes = b""
541542
"""Bytes after the size the header declares (a standalone file pads to 0x800)."""
542543

0 commit comments

Comments
 (0)