jak-project/goalc/build_level/common/gltf_mesh_extract.h
Hat Kid c64eea6337
[buildactor] support generating collide-meshes for custom models (#3540)
This adds support for generating collide meshes when importing custom
models. A couple of things to keep in mind:

- A single `collide-mesh` may only have up to 255 vertices.
- When exporting a GLTF file in Blender, a `collide-mesh` will be
generated for every mesh object that has collision properties applied
(ideally, you would set all visual meshes to `ignore` and your collision
meshes to `invisible` in the OpenGOAL plugin's custom properties).
- Ensure that your actor using the model properly allocates enough
`collide-shape-prim-mesh`es for each `collide-mesh` ([example from the
original game that uses multiple
meshes](f6688659f2/goal_src/jak1/levels/finalboss/robotboss.gc (L2628-L2806))).

~One annoying problem that I haven't fully figured out yet (unrelated to
the actual functionality):
`collide-mesh`es are stored in art groups as an `(array collide-mesh)`
in the `art-joint-geo`'s `extra`, so I had to add a new `Res` type to
support this. The way that `array`s are stored in `res-lump`s is a bit
of a hack right now. The lump only stores a pointer to the array, so the
size of that is 4 bytes, but because we have to generate all the actual
array data too, the current `ResLump` code in C++ doesn't handle this
case well and would assert, so I decided to omit the asserts if an
`array` tag is present and "fake" the size so the object file is
generated more closely to how the game expects it until we figure out
something better.~
This was fixed by generating the array data beforehand and creating a
`ResRef` class that takes the pointer to the array data and adds it to
the lump.
2024-05-29 06:09:20 +02:00

50 lines
1 KiB
C++

#pragma once
#include <string>
#include "common/custom_data/Tfrag3Data.h"
#include "goalc/build_level/collide/common/collide_common.h"
#include "third-party/tiny_gltf/tiny_gltf.h"
namespace gltf_util {
struct TexturePool;
}
namespace gltf_mesh_extract {
struct Input {
std::string filename;
gltf_util::TexturePool* tex_pool = nullptr;
bool get_colors = true;
bool auto_wall_enable = true;
float auto_wall_angle = 30.f;
bool double_sided_collide = false;
};
struct TfragOutput {
std::vector<tfrag3::StripDraw> strip_draws;
std::vector<tfrag3::PreloadedVertex> vertices;
std::vector<math::Vector<u8, 4>> color_palette;
};
struct CollideOutput {
std::vector<jak1::CollideFace> faces;
};
struct Output {
TfragOutput tfrag;
CollideOutput collide;
};
struct PatResult {
bool set = false;
bool ignore = false;
jak1::PatSurface pat;
};
PatResult custom_props_to_pat(const tinygltf::Value& val, const std::string& /*debug_name*/);
void extract(const Input& in, Output& out);
} // namespace gltf_mesh_extract