Some strange shit happens
This commit is contained in:
1 parent
4d9a5b0a6e
commit
c655678486
10 files changed
+148
-36
No files matched your search
@@ -6,15 +6,18 @@
|
||||
#include "render/TextureManager.h"
|
||||
#include "utils/Utils.h"
|
||||
#include <Eigen/Geometry>
|
||||
|
||||
#include "../Character.h"
|
||||
namespace ZL {
|
||||
|
||||
void set_Texture(Character& npc, TextureDataStruct& texture);
|
||||
void set_Texture(Character& npc, const std::string& meshName, TextureDataStruct& texture);
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
std::vector<GameObjectData> GameObjectLoader::loadFromJson(const std::string& jsonPath, const std::string& zipPath)
|
||||
{
|
||||
std::vector<GameObjectData> objects;
|
||||
|
||||
|
||||
std::string content;
|
||||
try {
|
||||
if (zipPath.empty()) {
|
||||
@@ -34,6 +37,7 @@ namespace ZL {
|
||||
throw std::runtime_error("Failed to load UI file: " + jsonPath);
|
||||
}
|
||||
|
||||
|
||||
json j;
|
||||
try {
|
||||
j = json::parse(content);
|
||||
@@ -340,6 +344,13 @@ namespace ZL {
|
||||
data.id = item.value("id", "npc_unknown");
|
||||
data.name = item.value("name", "Unknown NPC");
|
||||
data.texturePath = item.value("texturePath", "");
|
||||
if (item.contains("meshTextures") && item["meshTextures"].is_object()) {
|
||||
for (auto it = item["meshTextures"].begin(); it != item["meshTextures"].end(); ++it) {
|
||||
if (it.value().is_string()) {
|
||||
data.meshTextures[it.key()] = it.value().get<std::string>();
|
||||
}
|
||||
}
|
||||
}
|
||||
data.interactionRadius = item.value("interactionRadius", 0.0f);
|
||||
data.animationIdlePath = item.value("animationIdlePath", "");
|
||||
data.animationWalkPath = item.value("animationWalkPath", "");
|
||||
@@ -378,7 +389,7 @@ namespace ZL {
|
||||
return npcs;
|
||||
}
|
||||
|
||||
std::vector<std::unique_ptr<Character>> GameObjectLoader::loadAndCreateNpcs(
|
||||
std::vector<std::unique_ptr<Character>> GameObjectLoader::loadAndCreate_Npcs(
|
||||
const std::string& jsonPath,
|
||||
const std::string& zipPath)
|
||||
{
|
||||
@@ -424,11 +435,31 @@ namespace ZL {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Load texture
|
||||
// Load textures: per-mesh map takes precedence; fall back to single texturePath.
|
||||
try {
|
||||
auto texture = std::make_shared<Texture>(CreateTextureDataFromPng(npcData.texturePath, zipPath.c_str()));
|
||||
npc->setTexture(texture);
|
||||
std::cout << " Loaded texture: " << npcData.texturePath << std::endl;
|
||||
if (!npcData.meshTextures.empty()) {
|
||||
std::unordered_map<std::string, std::shared_ptr<Texture>> cache;
|
||||
for (const auto& entry : npcData.meshTextures) {
|
||||
const std::string& meshName = entry.first;
|
||||
const std::string& path = entry.second;
|
||||
/*auto cit = cache.find(path);
|
||||
if (cit == cache.end()) {
|
||||
auto tex = std::make_shared<Texture>(CreateTextureDataFromPng(path, zipPath.c_str()));
|
||||
cit = cache.emplace(path, std::move(tex)).first;
|
||||
std::cout << " Loaded texture: " << path << std::endl;
|
||||
}*/
|
||||
//npc->setTexture(meshName, std::make_shared<Texture>(CreateTextureDataFromPng(path, zipPath.c_str())));
|
||||
set_Texture(*npc, meshName, CreateTextureDataFromPng(path, zipPath.c_str()));
|
||||
//std::cout << xxa(*npc, CreateTextureDataFromPng(path, zipPath.c_str())) << std::endl;
|
||||
std::cout << " -> mesh '" << meshName << "'" << std::endl;
|
||||
}
|
||||
}
|
||||
else {
|
||||
//auto texture = std::make_shared<Texture>(CreateTextureDataFromPng(npcData.texturePath, zipPath.c_str()));
|
||||
set_Texture(*npc, CreateTextureDataFromPng(npcData.texturePath, zipPath.c_str()));
|
||||
//std::cout << xxa(*npc, CreateTextureDataFromPng(npcData.texturePath, zipPath.c_str())) << std::endl;
|
||||
std::cout << " Loaded texture: " << npcData.texturePath << std::endl;
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
std::cerr << "GameObjectLoader: Failed to load texture for '" << npcData.name << "': " << e.what() << std::endl;
|
||||
|
||||
@@ -3,15 +3,18 @@
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <unordered_map>
|
||||
#include <map>
|
||||
#include "external/nlohmann/json.hpp"
|
||||
#include "TextModel.h"
|
||||
#include "InteractiveObject.h"
|
||||
#include "Character.h"
|
||||
namespace ZL {
|
||||
//#include "Character.h"
|
||||
//#include "render/TextureManager.h"
|
||||
|
||||
struct Texture;
|
||||
struct VertexRenderStruct;
|
||||
class Renderer;
|
||||
namespace ZL {
|
||||
|
||||
//struct Texture;
|
||||
//struct VertexRenderStruct;
|
||||
//class Renderer;
|
||||
class Character;
|
||||
|
||||
struct GameObjectData {
|
||||
@@ -45,6 +48,7 @@ namespace ZL {
|
||||
std::string id;
|
||||
std::string name;
|
||||
std::string texturePath;
|
||||
std::map<std::string, std::string> meshTextures;
|
||||
std::string animationIdlePath;
|
||||
std::string animationWalkPath;
|
||||
float positionX = 0.0f;
|
||||
@@ -82,7 +86,7 @@ namespace ZL {
|
||||
const std::string& zipPath = ""
|
||||
);
|
||||
|
||||
static std::vector<std::unique_ptr<Character>> loadAndCreateNpcs(
|
||||
static std::vector<std::unique_ptr<ZL::Character>> loadAndCreate_Npcs(
|
||||
const std::string& jsonPath,
|
||||
const std::string& zipPath = ""
|
||||
);
|
||||
@@ -90,4 +94,5 @@ namespace ZL {
|
||||
static std::vector<NpcData> loadNpcsFromJson(const std::string& jsonPath, const std::string& zipPath = "");
|
||||
};
|
||||
|
||||
} // namespace ZL
|
||||
} // namespace ZL
|
||||
|
||||
Reference in new issue
Block a user