mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2026-06-06 08:42:35 +00:00
feat: trigger_use and trigger_multiple can now be loaded through GLTF
This commit is contained in:
@@ -103,9 +103,14 @@ namespace gltf
|
|||||||
std::optional<std::string> spawnpoint_group; // value: zone zspawner group name
|
std::optional<std::string> spawnpoint_group; // value: zone zspawner group name
|
||||||
|
|
||||||
std::optional<std::string> zspawner; // value: zspawner group name
|
std::optional<std::string> zspawner; // value: zspawner group name
|
||||||
|
|
||||||
|
// scripting
|
||||||
|
std::optional<std::string> trigger_use;
|
||||||
|
std::optional<std::string> trigger_multiple;
|
||||||
};
|
};
|
||||||
|
|
||||||
NLOHMANN_DEFINE_TYPE_EXTENSION(JsonNodeExtras, xmodel, spawnpoint, flags, pathnode, zone, zspawner_group, spawnpoint_group, zspawner);
|
NLOHMANN_DEFINE_TYPE_EXTENSION(
|
||||||
|
JsonNodeExtras, xmodel, spawnpoint, flags, pathnode, zone, zspawner_group, spawnpoint_group, zspawner, trigger_use, trigger_multiple);
|
||||||
|
|
||||||
class JsonNode
|
class JsonNode
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -160,6 +160,13 @@ namespace BSP
|
|||||||
size_t brushIndex;
|
size_t brushIndex;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct BSPTriggerBox
|
||||||
|
{
|
||||||
|
vec3_t origin;
|
||||||
|
size_t modelIndex;
|
||||||
|
std::string triggerName;
|
||||||
|
};
|
||||||
|
|
||||||
struct BSPData
|
struct BSPData
|
||||||
{
|
{
|
||||||
std::string name;
|
std::string name;
|
||||||
@@ -177,6 +184,9 @@ namespace BSP
|
|||||||
std::vector<BSPZSpawnerZM> zSpawners;
|
std::vector<BSPZSpawnerZM> zSpawners;
|
||||||
std::vector<BSPZoneZM> zZones;
|
std::vector<BSPZoneZM> zZones;
|
||||||
|
|
||||||
|
std::vector<BSPTriggerBox> useTriggers;
|
||||||
|
std::vector<BSPTriggerBox> triggerMultiples;
|
||||||
|
|
||||||
std::vector<BSPModel> models;
|
std::vector<BSPModel> models;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -866,6 +866,54 @@ namespace
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool addTriggerUseNode(const JsonRoot& jRoot, const gltf::JsonNode& node)
|
||||||
|
{
|
||||||
|
assert(node.extras);
|
||||||
|
assert(node.extras->trigger_use);
|
||||||
|
|
||||||
|
Eigen::Matrix4f nodeMatrix = createNodeMatrix(node);
|
||||||
|
|
||||||
|
Eigen::Vector4f position(0, 0, 0, 1.0f);
|
||||||
|
Eigen::Vector4f transformedPosition = nodeMatrix * position;
|
||||||
|
vec3_t origin;
|
||||||
|
origin.x = transformedPosition.x();
|
||||||
|
origin.y = transformedPosition.y();
|
||||||
|
origin.z = transformedPosition.z();
|
||||||
|
RhcToLhcCoordinates(origin.v);
|
||||||
|
|
||||||
|
BSPTriggerBox trigger;
|
||||||
|
trigger.origin = origin;
|
||||||
|
trigger.triggerName = *node.extras->trigger_use;
|
||||||
|
trigger.modelIndex = addScriptBrushModel(jRoot, node);
|
||||||
|
m_bsp->useTriggers.emplace_back(trigger);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool addTriggerMultipleNode(const JsonRoot& jRoot, const gltf::JsonNode& node)
|
||||||
|
{
|
||||||
|
assert(node.extras);
|
||||||
|
assert(node.extras->trigger_multiple);
|
||||||
|
|
||||||
|
Eigen::Matrix4f nodeMatrix = createNodeMatrix(node);
|
||||||
|
|
||||||
|
Eigen::Vector4f position(0, 0, 0, 1.0f);
|
||||||
|
Eigen::Vector4f transformedPosition = nodeMatrix * position;
|
||||||
|
vec3_t origin;
|
||||||
|
origin.x = transformedPosition.x();
|
||||||
|
origin.y = transformedPosition.y();
|
||||||
|
origin.z = transformedPosition.z();
|
||||||
|
RhcToLhcCoordinates(origin.v);
|
||||||
|
|
||||||
|
BSPTriggerBox trigger;
|
||||||
|
trigger.origin = origin;
|
||||||
|
trigger.triggerName = *node.extras->trigger_multiple;
|
||||||
|
trigger.modelIndex = addScriptBrushModel(jRoot, node);
|
||||||
|
m_bsp->triggerMultiples.emplace_back(trigger);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool addNodeToBSP(const JsonRoot& jRoot, const gltf::JsonNode& node)
|
bool addNodeToBSP(const JsonRoot& jRoot, const gltf::JsonNode& node)
|
||||||
{
|
{
|
||||||
if (m_is_world_gfx && node.extensions && node.extensions->KHR_lights_punctual)
|
if (m_is_world_gfx && node.extensions && node.extensions->KHR_lights_punctual)
|
||||||
@@ -882,6 +930,12 @@ namespace
|
|||||||
if (!m_is_world_gfx && node.extras->pathnode)
|
if (!m_is_world_gfx && node.extras->pathnode)
|
||||||
return addPathNode_Node(node);
|
return addPathNode_Node(node);
|
||||||
|
|
||||||
|
if (!m_is_world_gfx && node.extras->trigger_use)
|
||||||
|
return addTriggerUseNode(jRoot, node);
|
||||||
|
|
||||||
|
if (!m_is_world_gfx && node.extras->trigger_multiple)
|
||||||
|
return addTriggerMultipleNode(jRoot, node);
|
||||||
|
|
||||||
if (!m_is_world_gfx && m_bsp->isZombiesMap)
|
if (!m_is_world_gfx && m_bsp->isZombiesMap)
|
||||||
{
|
{
|
||||||
if (node.extras->zone)
|
if (node.extras->zone)
|
||||||
|
|||||||
@@ -173,6 +173,29 @@ namespace
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void addScriptingToEntString(BSP::BSPData* bsp, std::string& entityString)
|
||||||
|
{
|
||||||
|
for (auto& useTrigger : bsp->useTriggers)
|
||||||
|
{
|
||||||
|
entityString.append("{\n");
|
||||||
|
entityString.append("\"classname\" \"trigger_use\"\n");
|
||||||
|
entityString.append(std::format("\"targetname\" \"{}\"\n", useTrigger.triggerName));
|
||||||
|
entityString.append(std::format("\"origin\" \"{}\"\n", BSP::BSPUtil::convertVec3ToString(useTrigger.origin)));
|
||||||
|
entityString.append(std::format("\"model\" \"*{}\"\n", useTrigger.modelIndex));
|
||||||
|
entityString.append("}\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto& useTrigger : bsp->triggerMultiples)
|
||||||
|
{
|
||||||
|
entityString.append("{\n");
|
||||||
|
entityString.append("\"classname\" \"trigger_multiple\"\n");
|
||||||
|
entityString.append(std::format("\"targetname\" \"{}\"\n", useTrigger.triggerName));
|
||||||
|
entityString.append(std::format("\"origin\" \"{}\"\n", BSP::BSPUtil::convertVec3ToString(useTrigger.origin)));
|
||||||
|
entityString.append(std::format("\"model\" \"*{}\"\n", useTrigger.modelIndex));
|
||||||
|
entityString.append("}\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
constexpr const char* DEFAULT_MAP_ENTS_STRING = R"({
|
constexpr const char* DEFAULT_MAP_ENTS_STRING = R"({
|
||||||
"entities": [
|
"entities": [
|
||||||
{
|
{
|
||||||
@@ -229,6 +252,8 @@ namespace BSP
|
|||||||
if (bsp->isZombiesMap)
|
if (bsp->isZombiesMap)
|
||||||
addZombiesEntitiesToEntString(bsp, entityString);
|
addZombiesEntitiesToEntString(bsp, entityString);
|
||||||
|
|
||||||
|
addScriptingToEntString(bsp, entityString);
|
||||||
|
|
||||||
MapEnts* mapEnts = m_memory.Alloc<MapEnts>();
|
MapEnts* mapEnts = m_memory.Alloc<MapEnts>();
|
||||||
mapEnts->name = m_memory.Dup(bsp->bspName.c_str());
|
mapEnts->name = m_memory.Dup(bsp->bspName.c_str());
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user