Skip to content

Commit

Permalink
jak1, jak2: add get-texture macro (#3778)
Browse files Browse the repository at this point in the history
Ports the `get-texture` macro added in Jak 3 to Jak 1 and 2.
  • Loading branch information
Hat-Kid authored Nov 26, 2024
1 parent 9b393e2 commit 6a06291
Show file tree
Hide file tree
Showing 600 changed files with 34,100 additions and 13,995 deletions.
5 changes: 5 additions & 0 deletions common/util/gltf_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,11 @@ std::optional<int> find_single_skin(const tinygltf::Model& model,
return skin_index;
}

int get_joint_count(const tinygltf::Model& model, int skin_idx) {
const auto& skin = model.skins.at(skin_idx);
return skin.joints.size();
}

std::vector<float> extract_floats(const tinygltf::Model& model, int accessor_idx) {
const auto& accessor = model.accessors[accessor_idx];
const auto& buffer_view = model.bufferViews[accessor.bufferView];
Expand Down
1 change: 1 addition & 0 deletions common/util/gltf_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ EnvmapSettings envmap_settings_from_gltf(const tinygltf::Material& mat);
*/
std::optional<int> find_single_skin(const tinygltf::Model& model,
const std::vector<NodeWithTransform>& all_nodes);
int get_joint_count(const tinygltf::Model& model, int skin_idx);

template <typename T, int n>
std::vector<math::Vector<T, n>> extract_vec(const tinygltf::Model& model,
Expand Down
2 changes: 1 addition & 1 deletion decompiler/config/jak1/ntsc_v1/tex-info.min.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion decompiler/config/jak2/ntsc_v1/tex-info.min.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion decompiler/config/jak3/ntsc_v1/tex-info.min.json

Large diffs are not rendered by default.

18 changes: 13 additions & 5 deletions decompiler/level_extractor/merc_replacement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ void extract(const std::string& name,
int mesh_count = 0;
int prim_count = 0;
bool has_envmaps = false;
int joints = 1;
auto skin_idx = find_single_skin(model, all_nodes);
if (skin_idx) {
joints = get_joint_count(model, *skin_idx);
}

for (const auto& n : all_nodes) {
const auto& node = model.nodes[n.node_idx];
Expand Down Expand Up @@ -80,8 +85,8 @@ void extract(const std::string& name,
tfrag3::MercEffect e;
tfrag3::MercEffect envmap_eff;
out.new_model.name = name;
out.new_model.max_bones = 100; // idk
out.new_model.max_draws = 200;
out.new_model.max_bones = joints;
out.new_model.max_draws = 0;

auto process_normal_draw = [&](tfrag3::MercEffect& eff, int mat_idx, const tfrag3::MercDraw& d_) {
const auto& mat = model.materials[mat_idx];
Expand Down Expand Up @@ -170,9 +175,6 @@ void extract(const std::string& name,
}
}

lg::info("total of {} unique materials ({} normal, {} envmap)",
e.all_draws.size() + envmap_eff.all_draws.size(), e.all_draws.size(),
envmap_eff.all_draws.size());
// in case a model only has envmap draws, we don't push the normal merc effect
if (!e.all_draws.empty()) {
out.new_model.effects.push_back(e);
Expand All @@ -181,6 +183,12 @@ void extract(const std::string& name,
out.new_model.effects.push_back(envmap_eff);
}

for (auto& effect : out.new_model.effects) {
out.new_model.max_draws += effect.all_draws.size();
}

lg::info("total of {} unique materials ({} normal, {} envmap)", out.new_model.max_draws,
e.all_draws.size(), envmap_eff.all_draws.size());
lg::info("Merged {} meshes and {} prims into {} vertices", mesh_count, prim_count,
out.new_vertices.size());
}
Expand Down
Loading

0 comments on commit 6a06291

Please sign in to comment.