jak-project/goalc/build_actor/main.cpp
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

66 lines
2 KiB
C++

#include "common/log/log.h"
#include "common/util/Assert.h"
#include "common/util/FileUtil.h"
#include "goalc/build_actor/jak1/build_actor.h"
#include "third-party/CLI11.hpp"
int main(int argc, char** argv) {
// logging
lg::set_stdout_level(lg::level::info);
lg::set_flush_level(lg::level::info);
lg::initialize();
// game version
std::string game, mdl_name, output_file;
bool gen_collide_mesh;
fs::path project_path_override;
// path
if (!file_util::setup_project_path(std::nullopt)) {
return 1;
}
lg::info("Build Actor Tool", versions::GOAL_VERSION_MAJOR, versions::GOAL_VERSION_MINOR);
CLI::App app{"OpenGOAL Compiler / REPL"};
app.add_option("input-model", mdl_name,
"Input model file (for example: custom_assets/jak1/models/test.glb)")
->required();
app.add_option("output-file", output_file,
"Output *-ag.go file (for example: out/jak1/obj/test-ag.go)")
->required();
app.add_option("-g,--game", game, "Game version (only jak1 for now)")->required();
app.add_option("--proj-path", project_path_override,
"Specify the location of the 'data/' folder");
app.add_flag("-m,--mesh", gen_collide_mesh, "Whether to generate a collide-mesh for this model");
app.validate_positionals();
CLI11_PARSE(app, argc, argv)
GameVersion game_version = game_name_to_version(game);
if (!project_path_override.empty()) {
if (!fs::exists(project_path_override)) {
lg::error("Error: project path override '{}' does not exist", project_path_override.string());
return 1;
}
if (!file_util::setup_project_path(project_path_override)) {
lg::error("Could not setup project path!");
return 1;
}
} else if (!file_util::setup_project_path(std::nullopt)) {
return 1;
}
switch (game_version) {
case GameVersion::Jak1:
jak1::run_build_actor(mdl_name, output_file, gen_collide_mesh);
break;
default:
ASSERT_NOT_REACHED_MSG("unsupported game version");
}
return 0;
}