Skip to content

Commit

Permalink
add levelmain_to_gltf
Browse files Browse the repository at this point in the history
  • Loading branch information
PredatorCZ committed Aug 2, 2024
1 parent b2e1452 commit 97d2ee5
Show file tree
Hide file tree
Showing 23 changed files with 2,453 additions and 137 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ add_subdirectory(common)
target_link_libraries(spike_cli insomnia-objects)
add_spike_subdir(extract)
add_spike_subdir(effect)
add_spike_subdir(levelmain)

set(TPD_PATH ${CMAKE_CURRENT_SOURCE_DIR}/3rd_party/fragmented/3rd_party)
add_spike_subdir(3rd_party/fragmented/psarc)
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Head to this **[Wiki](https://github.com/PredatorCZ/Spike/wiki/Spike)** for more
<li><a href="#Extract-Assets">Extract Assets</a></li>
<li><a href="#Extract-Effect">Extract Effect</a></li>
<li><a href="#Extract-PSARC">Extract PSARC</a></li>
<li><a href="#Levelmain-to-GLTF">Levelmain to GLTF</a></li>
</ul>

## Extract Assets
Expand Down Expand Up @@ -53,7 +54,26 @@ Extracts and converts textures from `vfx_system_header.dat`.

Extracts psarc archives.

## Levelmain to GLTF

### Module command: levelmain_to_gltf

Converts level from Resistance: Fall of Man to GLTF.
Currently there are some missing features:

- detail textures
- scene lighting data (per vertex lightmaps, texel directional lightmaps)
- plant instances (unique meshes are stored in `plants.glb`)
- moby instances (individual mobys are converted to GLTF)
- Water(?)
- Skybox
- moby animations
- terrain texture blend

Textures are embedded in the GLTF file and converted to be up to GLTF standard.
Textures, that were unable to be linked to GLTFs are normally extracted, however unconverted (normal and template maps)

### Input file patterns: `^ps3levelmain.dat$`

## [Latest Release](https://github.com/PredatorCZ/InsomniaToolset/releases)

Expand Down
72 changes: 72 additions & 0 deletions common/include/insomnia/classes/foliage.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/* InsomniaLib
Copyright(C) 2021-2024 Lukas Cone
This program is free software : you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program.If not, see <https://www.gnu.org/licenses/>.
*/

#pragma once
#include "insomnia/internal/base.hpp"
#include "spike/type/matrix44.hpp"

struct FoliageBranchLod {
uint32 indexOffset;
uint16 numIndices;
uint16 unk;
};

struct SpriteLodRange {
uint32 indexBegin;
uint32 indexEnd;
uint32 unk0;
float unk1;
};

struct SpriteRange {
uint16 indexBegin;
uint16 indexEnd;
uint16 positionsOffset;
uint16 numSprites;
};

struct Foliage : CoreClass {
static constexpr uint32 ID = 0xc200;
uint32 unk0;
uint16 unk4;
uint16 unk6;
uint32 textureIndex;
uint32 unk5;
uint32 indexOffset;
uint32 null0;
uint32 branchVertexOffset;
uint32 unk1;
FoliageBranchLod branchLods[4];
uint32 spriteVertexOffset;
uint32 usedSpriteLods;
SpriteLodRange spriteLodRanges[6];
float unk2[4];
es::PointerX86<float> spritePositions;
uint32 usedSpriteRanges;
SpriteRange spriteRanges[8];
float unk3[8];
};

struct FoliageInstance : CoreClass {
static constexpr uint32 ID = 0x9700;

es::Matrix44 tm;
float unk0[33];
es::PointerX86<Foliage> foliage;
uint32 unk1[2];
uint32 unk[4];
};
51 changes: 47 additions & 4 deletions common/include/insomnia/classes/moby.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* InsomniaLib
Copyright(C) 2021-2023 Lukas Cone
Copyright(C) 2021-2024 Lukas Cone
This program is free software : you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -19,7 +19,7 @@
#include "insomnia/internal/base.hpp"
#include "spike/type/matrix44.hpp"

struct Primitive : CoreClass {
struct PrimitiveV2 : CoreClass {
static constexpr uint32 ID = 0xdd00;

uint32 indexOffset;
Expand All @@ -42,7 +42,7 @@ struct Primitive : CoreClass {
struct Mesh : CoreClass {
static constexpr uint32 ID = 0xd700;

es::PointerX86<Primitive> primitives;
es::PointerX86<PrimitiveV2> primitives;
uint32 numPrimitives;
};

Expand All @@ -67,7 +67,7 @@ struct Skeleton : CoreClass {
uint32 off2;
};

struct Moby : CoreClass {
struct MobyV2 : CoreClass {
static constexpr uint32 ID = 0xd100;

float unk00[4];
Expand Down Expand Up @@ -102,3 +102,46 @@ struct Moby : CoreClass {
es::PointerX86<char> unkData6;
uint32 null01[12];
};

struct PrimitiveV1 : CoreClass {
static constexpr uint32 ID = 0xdd00;

uint16 materialIndex;
uint16 numVertices;
uint16 numIndices;
uint8 numJoints;
uint8 vertexFormat;
uint32 indexOffset;
uint32 vertexBufferOffset;
es::PointerX86<uint16> joints;
uint32 unk[3];
};

struct MeshV1 : CoreClass {
es::PointerX86<PrimitiveV1> primitives;
uint32 numPrimitives;
};

struct MobyV1 : CoreClass {
static constexpr uint32 ID = 0xd100;

float unk00[4];
uint16 unk01;
uint16 unk02;
uint16 numBones;
uint16 unk03;
uint16 numMeshes;
uint16 mobyId;
uint16 null00;
uint8 anotherSet; // bool?
uint8 null01;
es::PointerX86<Skeleton> skeleton;
es::PointerX86<char> unkData0;
es::PointerX86<MeshV1> meshes;
es::PointerX86<char> unkData1;
uint32 null02;
uint32 indexBufferOffset;
int32 vertexBufferOffset;
float meshScale;
uint32 unkRest[32];
};
62 changes: 62 additions & 0 deletions common/include/insomnia/classes/plant.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/* InsomniaLib
Copyright(C) 2021-2024 Lukas Cone
This program is free software : you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program.If not, see <https://www.gnu.org/licenses/>.
*/

#pragma once
#include "insomnia/internal/base.hpp"
#include <span>

struct PlantPrimitive : CoreClass {
static constexpr uint32 ID = 0xC700;

uint32 vertexBufferOffset;
uint32 indexOffset;
uint32 numIndices;
uint32 unk0;
float unk1[4];
uint16 materialIndex;
uint32 unk2[3];
};


struct PlantClusterInstance {
es::Matrix44 tm;
uint32 unk0[2];
uint32 unk1;
uint32 unk2;
};

struct PlantClusters : CoreClass {
static constexpr uint32 ID = 0xC650;

uint32 unk0;
uint32 unkOffset;
uint32 numInstances;
uint32 instancesOffset;
uint32 unk4;
uint32 unk5;
uint32 null0[2];
float unk6[3];
uint32 unk7;
uint32 null1[20];
uint32 unk8[12];

std::span<PlantClusterInstance> Instances() {
return {reinterpret_cast<PlantClusterInstance *>(reinterpret_cast<char *>(this) +
instancesOffset),
numInstances};
}
};
26 changes: 25 additions & 1 deletion common/include/insomnia/classes/resource.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* InsomniaLib
Copyright(C) 2021 Lukas Cone
Copyright(C) 2021-2024 Lukas Cone
This program is free software : you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -47,6 +47,20 @@ static constexpr uint32 ResourceTiePathLookupId = 0x3410;
static constexpr uint32 ResourceShrubPathLookupId = 0xb700;
static constexpr uint32 ResourceCinematicPathLookupId = 0x17d00;

template <uint32 id_> struct ResourceNameLookup : CoreClass {
static constexpr uint32 ID = id_;
Hash hash;
es::PointerX86<char> path;
uint32 unk;

bool operator<(const Hash other) const { return hash < other; }
bool operator==(const Hash other) const { return hash == other; }
bool operator==(uint32 other) const { return hash.part2 == other; }
};

using ResourceMobyPath = ResourceNameLookup<0x9480>;
using ResourceTiePath = ResourceNameLookup<0x9280>;

struct EffectTextureBuffer : CoreClass {
static constexpr uint32 ID = 0x5300;
char data;
Expand All @@ -61,3 +75,13 @@ struct IndexBuffer : CoreClass {
static constexpr uint32 ID = 0xe100;
uint16 data;
};

struct LevelVertexBuffer : CoreClass {
static constexpr uint32 ID = 0x9000;
char data;
};

struct LevelIndexBuffer : CoreClass {
static constexpr uint32 ID = 0x9100;
uint16 data;
};
Loading

0 comments on commit 97d2ee5

Please sign in to comment.