UC2 PC static mesh extraction fixes + OBJ export#339
Open
jf1shh wants to merge 5 commits into
Open
Conversation
- Widen UC2 game detection to ArVer 140-151 (was only 151) to cover PC packages - Split Xbox (ArLicenseeVer=1) and PC (ArLicenseeVer=0) serialization paths in FStaticMeshVertexStream, FRawColorStream, and FStaticMeshUVStream: Xbox streams are guarded by a Flag field, PC streams store data directly - On PC, FStaticMeshVertexStream deserializes vertices one at a time to handle the packed int[3] format used by FUC2Vector/FUC2Normal - LoadExternalUC2Data() is now Xbox-only; PC packages store all geometry inline - Fix FStaticMeshSection::NumFaces on PC: the field holds the last index value, not a face count, so divide by 3 after load - Remove the assert in LoadExternalUC2Data that fired when IndexStream1 was already populated (valid on PC)
On PC (ArLicenseeVer==0) the FPackedPosition serializer writes vertex positions as FVector (3 floats, 12 bytes each) rather than the Xbox int16 triplet (6 bytes). Normals are stored as 3 ints (12 bytes). The previous fix iterated over FStaticMeshVertexUC2 elements one by one which advanced the archive by the right byte count but left V.X/V.Y/V.Z at zero (local read vars were never stored), causing all vertices to collapse to a single deduplicated point in the PSK output. The new PC path bypasses FStaticMeshVertexUC2 entirely and reads directly into FStaticMeshVertex: FVector for position (world-space floats, no GUC2VectorScale/Base transform needed) and int[3] for the normal (consumed but not yet decoded). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
ArVer=140 packages (6 out of 45 UC2 PC static mesh packages) use compact AR_INDEX encoding for export table fields that later versions store as full int32. This matches the FName serialization version threshold already in UnPackage.cpp (ArVer >= 145 uses int32). - UnPackage2.cpp: Serialize2X() now branches on ArVer<145: use AR_INDEX for ClassIndex, SuperIndex, SerialSize, SerialOffset (ArVer>=145 path unchanged - still uses full int32 with int16 truncation) - UnMesh2.h: UC2 PC vertex stream count also stored as AR_INDEX for ArVer<145; use AR_INDEX(Count) when reading vertex count in that path Before: 6 packages failed with "wrong name index" errors because misaligned export table reads produced OOB name indices. After: all 45 UC2 PC static mesh packages export cleanly (2,095 files). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds ExportStaticMeshOBJ() producing .obj + .mtl per mesh LOD, selected via -obj on the command line or the Settings dialog. Per-section material groups are named from UUnrealMaterial names. Targeting UT2004 mod import (raw UE coordinate space, no axis transform). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The 3 ints following each vertex position are float bits, not integer normals. Reinterpret via bitcast. Previously set to (0,0,0). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
UC2 PC static mesh support
Three fixes to extract static meshes from Unreal Championship 2 (PC version, ArVer 140-151):
Fix 1 – Widen UC2 detection range
GameDatabase.cpp: UC2 was only detected at ArVer==151 (Xbox). PC packages use ArVer 140-151, so widened the range to coverboth.
Fix 2 – Split Xbox/PC vertex stream paths
UnMesh2.h: Xbox (ArLicenseeVer=1) has a Flag guard before each vertex array; PC (ArLicenseeVer=0) does not. PC vertexstream reads FVector (3 floats) per vertex, then 3 ints for the packed normal.
Fix 3 – Fix export table and vertex count for ArVer<145 packages
UnPackage2.cpp/UnMesh2.h: Below ArVer=145, ClassIndex/SuperIndex/SerialSize/SerialOffset and TArray counts use AR_INDEXcompact encoding rather than int32. Matches the FName threshold already in UnPackage.cpp.
Also skips LODs with 0 vertices to avoid crashing on
_EMemissive props with no geometry.Tested against all 45 UC2 PC static mesh packages — 2,093 meshes extract cleanly.
OBJ export for static meshes (
-objflag)Adds
ExportStaticMeshOBJ()producing.obj+.mtlper mesh/LOD, selectable via-objon the command line or the StaticMesh format dropdown in Settings. Per-section material groups are named from
UUnrealMaterialnames. Useful for importinginto UE2-era editors (e.g. UT2004 UnrealEd).