Skip to content

Commit d9bb7cc

Browse files
authored
Merge pull request #125 from MichaelRelaxen/collision
Changes to collision view
2 parents 1145861 + 65436a1 commit d9bb7cc

8 files changed

Lines changed: 468 additions & 37 deletions

File tree

LibReplanetizer/Models/Collision.cs

Lines changed: 70 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,82 @@ public Collision(FileStream fs, int collisionPointer)
3939
// RaC 1 title screen has no collision
4040
if (collisionPointer == 0) return;
4141

42-
float div = 1024f;
42+
byte[] headBlock = ReadBlock(fs, collisionPointer, 0x08);
43+
int standardCollisionStart = ReadInt(headBlock, 0x00);
44+
int heroCollisionStart = ReadInt(headBlock, 0x04);
4345

46+
var vertexList = new List<float>();
47+
var indexList = new List<uint>();
48+
var colorList = new List<uint>();
4449
uint totalVertexCount = 0;
4550

46-
byte[] headBlock = ReadBlock(fs, collisionPointer, 0x08);
47-
int collisionStart = collisionPointer + ReadInt(headBlock, 0x00);
48-
int collisionLength = ReadInt(headBlock, 0x04);
49-
if (collisionLength == 0)
51+
if (standardCollisionStart > 0)
5052
{
51-
collisionLength = (int) fs.Length - collisionStart;
53+
int start = collisionPointer + standardCollisionStart;
54+
int length;
55+
56+
if (heroCollisionStart > 0)
57+
length = heroCollisionStart - standardCollisionStart;
58+
else
59+
length = (int) fs.Length - start;
60+
61+
byte[] data = ReadBlock(fs, start, length);
62+
ParseStandardCollision(data, vertexList, indexList, ref totalVertexCount);
5263
}
53-
byte[] collision = ReadBlock(fs, collisionStart, collisionLength);
5464

55-
var vertexList = new List<float>();
56-
var indexList = new List<uint>();
57-
var colorList = new List<uint>();
65+
if (heroCollisionStart > 0)
66+
{
67+
int start = collisionPointer + heroCollisionStart;
68+
int length = (int) fs.Length - start;
69+
70+
byte[] data = ReadBlock(fs, start, length);
71+
ParseHeroCollision(data, vertexList, indexList, ref totalVertexCount);
72+
}
73+
74+
vertexBuffer = vertexList.ToArray();
75+
indBuff = indexList.ToArray();
76+
}
77+
78+
private void ParseHeroCollision(byte[] hero, List<float> vertexList, List<uint> indexList, ref uint totalVertexCount)
79+
{
80+
int groupCount = ReadInt(hero, 0x00);
81+
82+
for (int i = 0; i < groupCount; i++)
83+
{
84+
int entryOffset = 0x10 + (i * 16);
85+
86+
ushort triCount = ReadUshort(hero, entryOffset + 8);
87+
ushort vertCount = ReadUshort(hero, entryOffset + 10);
88+
int dataOffset = (int) ReadUint(hero, entryOffset + 12);
89+
90+
// Wrench has hero collision as blue, so I figured I'll just... use that color as well...
91+
FloatColor fc = new FloatColor { r = 0, g = 0, b = 255, a = 255 };
92+
93+
for (int v = 0; v < vertCount; v++)
94+
{
95+
int vOff = dataOffset + (v * 8);
96+
vertexList.Add(ReadUshort(hero, vOff + 0) / 64.0f);
97+
vertexList.Add(ReadUshort(hero, vOff + 2) / 64.0f);
98+
vertexList.Add(ReadUshort(hero, vOff + 4) / 64.0f);
99+
vertexList.Add(fc.value);
100+
}
101+
102+
int triBase = dataOffset + (vertCount * 8);
103+
for (int t = 0; t < triCount; t++)
104+
{
105+
int tOff = triBase + (t * 4);
106+
indexList.Add(totalVertexCount + hero[tOff + 1]);
107+
indexList.Add(totalVertexCount + hero[tOff + 0]);
108+
indexList.Add(totalVertexCount + hero[tOff + 2]);
109+
}
110+
111+
totalVertexCount += vertCount;
112+
}
113+
}
114+
115+
private void ParseStandardCollision(byte[] collision, List<float> vertexList, List<uint> indexList, ref uint totalVertexCount)
116+
{
117+
float div = 1024f;
58118

59119
ushort zShift = ReadUshort(collision, 0);
60120
ushort zCount = ReadUshort(collision, 2);
@@ -152,8 +212,6 @@ public Collision(FileStream fs, int collisionPointer)
152212
}
153213
}
154214
}
155-
vertexBuffer = vertexList.ToArray();
156-
indBuff = indexList.ToArray();
157215
}
158216
}
159217
}

Replanetizer/Frames/TextureFrame.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public static void RenderTextureList(List<Texture> textures, float itemSizeX, Di
4444
if (ImGui.BeginChild("imageChild_" + prefix + i, ITEM_SIZE, ImGuiChildFlags.None))
4545
{
4646
ImGui.Image((IntPtr) textureIds[t].textureID, IMAGE_SIZE);
47-
string idText = prefix + t.id;
47+
string idText = t.id.ToString();
4848
float idWidth = ImGui.CalcTextSize(idText).X;
4949
ImGui.SetCursorPosX(ITEM_SIZE.X - idWidth);
5050
ImGui.Text(idText);
@@ -100,11 +100,11 @@ public override void Render(float deltaTime)
100100
{
101101
if (ImGui.CollapsingHeader("Level textures"))
102102
{
103-
RenderTextureList(level.textures, itemSizeX, levelFrame.textureIds);
103+
RenderTextureList(level.textures, itemSizeX, levelFrame.textureIds, "levelTextures");
104104
}
105105
if (ImGui.CollapsingHeader("Gadget textures"))
106106
{
107-
RenderTextureList(level.gadgetTextures, itemSizeX, levelFrame.textureIds);
107+
RenderTextureList(level.gadgetTextures, itemSizeX, levelFrame.textureIds, "gadgetTextures");
108108
}
109109
if (ImGui.CollapsingHeader("Armor textures"))
110110
{

Replanetizer/ModelLists/MobyModelsRC1.txt

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@
255255
024A=Thruster Pack Lock (Red)
256256
024B=Floating Platform
257257
0259=Clank (Backpack)
258-
025D=UNKNOWN (Usually underground)
258+
025D=Metal Detector Spot (meshless)
259259
025F=Helipack
260260
025C=Sandmouse house
261261
0260=Thrusterpack
@@ -345,12 +345,14 @@
345345
02FA=Rocks
346346
02FD=Statue
347347
02FE=Plant
348+
02FF=Plant
348349
0300=Door Left
349350
0301=Door Right
350351
0302=Helipack
351352
0306=Plumber
352353
0307=Splash Effect
353354
030A=Pipe
355+
030B=Broken Pipe
354356
030C=Bridge Platform
355357
030D=Crane Top
356358
0312=Skidd's Agent
@@ -380,10 +382,14 @@
380382
0343=Mine
381383
0346=Electric Gate
382384
034A=Broken Button
385+
034B=Door
383386
034C=Drain Cover
384387
034E=Underwater Gate
385388
0351=Suckcannon
386389
0353=Qwark
390+
0354=Bridge Part
391+
0355=Bridge Pile
392+
0357=Sewer Pipe With Sludge
387393
0359=Gadgebot
388394
035F=Test Dummy Bomb Glove
389395
0361=Medium Slime
@@ -397,6 +403,8 @@
397403
0374=Test Dummy Walloper
398404
0376=Timed Activation Pads
399405
037A=Helga
406+
037D=Hydrodisplacer Puzzle Door
407+
037F=Grill Door
400408
0382=Ceiling
401409
0386=Water
402410
0387=Platform
@@ -444,29 +452,47 @@
444452
03F4=Taxi
445453
03F7=Door
446454
03F8=Hydrodisplacer
455+
03FD=Circular Door Part
447456
03FF=Blarg Paratrooper
448457
0401=Blarg Gun
458+
0404=Platform
449459
0407=Button
450460
0409=Platform
451461
040A=Rocket
462+
040B=Circular Electric Gate
452463
040E=Energy Sphere Holder
453464
0410=Energy Sphere
454465
0411=Bomb-o-matic
455466
0412=Mushroom Underside
456467
0418=Alien Snapper
457468
041B=Alien Queen
458469
041C=Bridge
470+
041E=Warship Door (High Part)
471+
041F=Warship Door (Low Part)
459472
0420=Transport Pod Ring
460473
0421=Teleport Tube
461474
0422=Teleport Tube
462475
0423=Sharkigator
463476
0424=Red Orb
477+
0425=Circular Elevator With Button
478+
042A=Frog Spawner
464479
042C=Blarg Space Commando
465480
042F=Qwark Statue
466481
0433=Boat
482+
043B=Alien Snapper Cage
483+
043C=Alien Snapper Cage (Damaged)
484+
0443=Warship (Top)
485+
0444=Warship (Wing)
486+
0445=Warship (Gunner)
487+
0446=Warship (Gunner)
488+
0447=Warship (Base)
489+
0448=Warship (Thing)
490+
0449=Warship (Front)
491+
044A=Warship (Wing)
467492
044B=Quark's Trailer
468493
044D=Upper Door
469494
044E=Lower Door
495+
044F=Destroyable Ship (Left Wing)
470496
0451=Fred
471497
0452=Blargian Snagglebeast
472498
0455=Shuttle
@@ -475,6 +501,8 @@
475501
045D=Platform
476502
045E=Red Button
477503
0460=Suck Cannon
504+
0463=Electric Gate Poles
505+
0465=Glass
478506
0466=Machinegun Turret
479507
046A=Batalia Commando
480508
046E=Gold Bolt
@@ -485,6 +513,7 @@
485513
0475=Elevator
486514
0477=Vendor Orb
487515
0478=Batalia Deserter
516+
0479=Button Cover
488517
047A=Helipack
489518
047C=Taunter
490519
047E=Elevator
@@ -646,7 +675,22 @@
646675
065E=Thruster Pack (Backpack)
647676
0663=Fake Boltcrate
648677
0672=Mushroom
678+
0677=Computer with Dan Johnson
679+
0678=Computer (Damaged)
680+
0679=Computer Part (Damaged)
681+
067A=Computer Part (Damaged)
682+
067B=Computer Part (Damaged)
683+
067C=Orange Light
684+
067D=Orange Light (Damaged)
685+
067E=Orange Light (Damaged)
649686
067F=Robot Head
687+
0680=Green Light
688+
0681=Green Light
689+
0688=Power Unit
690+
0689=Power Unit (Damaged)
691+
068A=Power Unit (Damaged)
692+
068B=Power Unit (Damaged)
693+
068C=Power Unit (Damaged)
650694
0696=Seashell
651695
06C5=Spawner Leg (Damaged)
652696
06C6=Spawner Leg (Damaged)
@@ -670,6 +714,7 @@
670714
0725=Lightpost Top (Damaged)
671715
0726=Lightpost Sphere (Damaged)
672716
072A=Pipe
717+
072B=Broken Pipe
673718
0730=Fireplug
674719
0733=Blarg Ship
675720
0739=Lamp

0 commit comments

Comments
 (0)