*
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
#include <boost/iostreams/filter/zlib.hpp>
|
||||
#include <cstddef>
|
||||
#include <endian.h>
|
||||
#include <print>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
@@ -981,6 +982,7 @@ PreparedNodeState::PreparedNodeState(const std::u8string& data) {
|
||||
}
|
||||
}
|
||||
|
||||
lr.checkUnreaded();
|
||||
}
|
||||
|
||||
std::u8string PreparedNodeState::dump() const {
|
||||
@@ -1502,7 +1504,7 @@ std::pair<float, std::variant<PreparedNodeState::Model, PreparedNodeState::Vecto
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<PreparedNodeState::Transformation> PreparedNodeState::parseTransormations(const js::array& arr) {
|
||||
std::vector<Transformation> PreparedNodeState::parseTransormations(const js::array& arr) {
|
||||
std::vector<Transformation> result;
|
||||
|
||||
for(const js::value& js_value : arr) {
|
||||
@@ -1721,21 +1723,23 @@ PreparedModel::PreparedModel(const std::string_view modid, const js::object& pro
|
||||
}
|
||||
|
||||
if(key == "x")
|
||||
result.Transformations.emplace_back(Transformation::MoveX, f_value);
|
||||
result.Trs.OPs.emplace_back(Transformation::MoveX, f_value);
|
||||
else if(key == "y")
|
||||
result.Transformations.emplace_back(Transformation::MoveY, f_value);
|
||||
result.Trs.OPs.emplace_back(Transformation::MoveY, f_value);
|
||||
else if(key == "z")
|
||||
result.Transformations.emplace_back(Transformation::MoveZ, f_value);
|
||||
result.Trs.OPs.emplace_back(Transformation::MoveZ, f_value);
|
||||
else if(key == "rx")
|
||||
result.Transformations.emplace_back(Transformation::RotateX, f_value);
|
||||
result.Trs.OPs.emplace_back(Transformation::RotateX, f_value);
|
||||
else if(key == "ry")
|
||||
result.Transformations.emplace_back(Transformation::RotateY, f_value);
|
||||
result.Trs.OPs.emplace_back(Transformation::RotateY, f_value);
|
||||
else if(key == "rz")
|
||||
result.Transformations.emplace_back(Transformation::RotateZ, f_value);
|
||||
result.Trs.OPs.emplace_back(Transformation::RotateZ, f_value);
|
||||
else
|
||||
MAKE_ERROR("Неизвестный ключ трансформации");
|
||||
}
|
||||
}
|
||||
|
||||
Cuboids.emplace_back(std::move(result));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1771,6 +1775,8 @@ PreparedModel::PreparedModel(const std::string_view modid, const sol::table& pro
|
||||
PreparedModel::PreparedModel(const std::u8string& data) {
|
||||
Net::LinearReader lr(data);
|
||||
|
||||
lr.read<uint16_t>();
|
||||
|
||||
if(lr.read<uint8_t>()) {
|
||||
GuiLight = (EnumGuiLight) lr.read<uint8_t>();
|
||||
}
|
||||
@@ -1811,8 +1817,8 @@ PreparedModel::PreparedModel(const std::u8string& data) {
|
||||
lr >> size;
|
||||
Textures.reserve(size);
|
||||
for(int counter = 0; counter < size; counter++) {
|
||||
std::string tkey, pipeline;
|
||||
lr >> tkey >> pipeline;
|
||||
std::string tkey;
|
||||
lr >> tkey;
|
||||
TexturePipeline pipe;
|
||||
|
||||
uint16_t size;
|
||||
@@ -1852,9 +1858,9 @@ PreparedModel::PreparedModel(const std::u8string& data) {
|
||||
|
||||
lr >> face.Texture;
|
||||
uint8_t val = lr.read<uint8_t>();
|
||||
if(val != uint8_t(-1)) {
|
||||
face.Cullface = EnumFace(val);
|
||||
}
|
||||
face.Cullface = EnumFace(val);
|
||||
if((int) face.Cullface > (int) EnumFace::None)
|
||||
MAKE_ERROR("Unknown face");
|
||||
|
||||
lr >> face.TintIndex >> face.Rotation;
|
||||
|
||||
@@ -1863,21 +1869,22 @@ PreparedModel::PreparedModel(const std::u8string& data) {
|
||||
|
||||
uint16_t transformationsSize;
|
||||
lr >> transformationsSize;
|
||||
cuboid.Transformations.reserve(transformationsSize);
|
||||
cuboid.Trs.OPs.reserve(transformationsSize);
|
||||
|
||||
for(int counter2 = 0; counter2 < transformationsSize; counter2++) {
|
||||
Transformation tsf;
|
||||
tsf.Op = (Transformation::EnumTransform) lr.read<uint8_t>();
|
||||
lr >> tsf.Value;
|
||||
cuboid.Transformations.emplace_back(tsf);
|
||||
cuboid.Trs.OPs.emplace_back(tsf);
|
||||
}
|
||||
|
||||
Cuboids.emplace_back(std::move(cuboid));
|
||||
}
|
||||
|
||||
lr >> size;
|
||||
SubModels.reserve(size);
|
||||
for(int counter = 0; counter < size; counter++) {
|
||||
uint8_t size8;
|
||||
lr >> size8;
|
||||
SubModels.reserve(size8);
|
||||
for(int counter = 0; counter < size8; counter++) {
|
||||
SubModel sub;
|
||||
lr >> sub.Domain >> sub.Key;
|
||||
uint16_t val = lr.read<uint16_t>();
|
||||
@@ -1887,6 +1894,8 @@ PreparedModel::PreparedModel(const std::u8string& data) {
|
||||
|
||||
SubModels.push_back(std::move(sub));
|
||||
}
|
||||
|
||||
lr.checkUnreaded();
|
||||
}
|
||||
|
||||
std::u8string PreparedModel::dump() const {
|
||||
@@ -1964,17 +1973,14 @@ std::u8string PreparedModel::dump() const {
|
||||
result << face.UV[iter];
|
||||
|
||||
result << face.Texture;
|
||||
if(face.Cullface)
|
||||
result << uint8_t(*face.Cullface);
|
||||
else
|
||||
result << uint8_t(-1);
|
||||
result << uint8_t(face.Cullface);
|
||||
|
||||
result << face.TintIndex << face.Rotation;
|
||||
}
|
||||
|
||||
assert(cuboid.Transformations.size() < 256);
|
||||
result << uint8_t(cuboid.Transformations.size());
|
||||
for(const auto& [op, value] : cuboid.Transformations) {
|
||||
assert(cuboid.Trs.OPs.size() < 256);
|
||||
result << uint8_t(cuboid.Trs.OPs.size());
|
||||
for(const auto& [op, value] : cuboid.Trs.OPs) {
|
||||
result << uint8_t(op) << value;
|
||||
}
|
||||
}
|
||||
@@ -2014,6 +2020,7 @@ PreparedGLTF::PreparedGLTF(const std::string_view modid, Resource glb) {
|
||||
|
||||
PreparedGLTF::PreparedGLTF(std::u8string_view data) {
|
||||
|
||||
// lr.checkUnreaded();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <vector>
|
||||
#include <boost/json.hpp>
|
||||
#include <boost/container/small_vector.hpp>
|
||||
#include <execution>
|
||||
|
||||
|
||||
namespace LV {
|
||||
@@ -539,6 +540,68 @@ struct NodestateEntry {
|
||||
std::vector<std::string> ValueNames; // Имена состояний, если имеются
|
||||
};
|
||||
|
||||
struct Vertex {
|
||||
glm::vec3 Pos;
|
||||
glm::vec2 UV;
|
||||
uint32_t TexId;
|
||||
};
|
||||
|
||||
struct Transformation {
|
||||
enum EnumTransform {
|
||||
MoveX, MoveY, MoveZ,
|
||||
RotateX, RotateY, RotateZ,
|
||||
ScaleX, ScaleY, ScaleZ,
|
||||
MAX_ENUM
|
||||
} Op;
|
||||
|
||||
float Value;
|
||||
};
|
||||
|
||||
struct Transformations {
|
||||
std::vector<Transformation> OPs;
|
||||
|
||||
void apply(std::vector<Vertex>& vertices) const {
|
||||
if (vertices.empty() || OPs.empty())
|
||||
return;
|
||||
|
||||
glm::mat4 transform(1.0f);
|
||||
|
||||
for (const auto& op : OPs) {
|
||||
switch (op.Op) {
|
||||
case Transformation::MoveX: transform = glm::translate(transform, glm::vec3(op.Value, 0.0f, 0.0f)); break;
|
||||
case Transformation::MoveY: transform = glm::translate(transform, glm::vec3(0.0f, op.Value, 0.0f)); break;
|
||||
case Transformation::MoveZ: transform = glm::translate(transform, glm::vec3(0.0f, 0.0f, op.Value)); break;
|
||||
case Transformation::ScaleX: transform = glm::scale(transform, glm::vec3(op.Value, 1.0f, 1.0f)); break;
|
||||
case Transformation::ScaleY: transform = glm::scale(transform, glm::vec3(1.0f, op.Value, 1.0f)); break;
|
||||
case Transformation::ScaleZ: transform = glm::scale(transform, glm::vec3(1.0f, 1.0f, op.Value)); break;
|
||||
case Transformation::RotateX: transform = glm::rotate(transform, op.Value, glm::vec3(1.0f, 0.0f, 0.0f)); break;
|
||||
case Transformation::RotateY: transform = glm::rotate(transform, op.Value, glm::vec3(0.0f, 1.0f, 0.0f)); break;
|
||||
case Transformation::RotateZ: transform = glm::rotate(transform, op.Value, glm::vec3(0.0f, 0.0f, 1.0f)); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
std::transform(
|
||||
std::execution::unseq,
|
||||
vertices.begin(),
|
||||
vertices.end(),
|
||||
vertices.begin(),
|
||||
[transform](Vertex v) -> Vertex {
|
||||
glm::vec4 pos_h(v.Pos, 1.0f);
|
||||
pos_h = transform * pos_h;
|
||||
v.Pos = glm::vec3(pos_h) / pos_h.w;
|
||||
return v;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
std::vector<Vertex> apply(const std::vector<Vertex>& vertices) const {
|
||||
std::vector<Vertex> result = vertices;
|
||||
apply(result);
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
Хранит распаршенное определение состояний нод.
|
||||
Не привязано ни к какому окружению.
|
||||
@@ -559,16 +622,6 @@ struct PreparedNodeState {
|
||||
std::variant<Num, Var, Unary, Binary> v;
|
||||
};
|
||||
|
||||
struct Transformation {
|
||||
enum EnumTransform {
|
||||
MoveX, MoveY, MoveZ,
|
||||
RotateX, RotateY, RotateZ,
|
||||
MAX_ENUM
|
||||
} Op;
|
||||
|
||||
float Value;
|
||||
};
|
||||
|
||||
struct Model {
|
||||
uint16_t Id;
|
||||
bool UVLock = false;
|
||||
@@ -628,17 +681,6 @@ enum class EnumFace {
|
||||
Down, Up, North, South, West, East, None
|
||||
};
|
||||
|
||||
struct Transformation {
|
||||
enum EnumTransform {
|
||||
MoveX, MoveY, MoveZ,
|
||||
RotateX, RotateY, RotateZ,
|
||||
ScaleX, ScaleY, ScaleZ,
|
||||
MAX_ENUM
|
||||
} Op;
|
||||
|
||||
float Value;
|
||||
};
|
||||
|
||||
/*
|
||||
Парсит json модель
|
||||
*/
|
||||
@@ -668,14 +710,14 @@ struct PreparedModel {
|
||||
struct Face {
|
||||
glm::vec4 UV;
|
||||
std::string Texture;
|
||||
std::optional<EnumFace> Cullface;
|
||||
EnumFace Cullface = EnumFace::None;
|
||||
int TintIndex = -1;
|
||||
int16_t Rotation = 0;
|
||||
};
|
||||
|
||||
std::unordered_map<EnumFace, Face> Faces;
|
||||
|
||||
std::vector<Transformation> Transformations;
|
||||
Transformations Trs;
|
||||
};
|
||||
|
||||
std::vector<Cuboid> Cuboids;
|
||||
@@ -706,12 +748,6 @@ private:
|
||||
void load(std::u8string_view data);
|
||||
};
|
||||
|
||||
struct Vertex {
|
||||
glm::vec3 Pos;
|
||||
glm::vec2 UV;
|
||||
uint32_t TexId;
|
||||
};
|
||||
|
||||
struct PreparedGLTF {
|
||||
std::vector<std::string> TextureKey;
|
||||
std::unordered_map<std::string, PrecompiledTexturePipeline> Textures;
|
||||
|
||||
Reference in New Issue
Block a user