mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-15 07:51:50 +00:00
feat: 'region', 'region-scale' support for 'tri' primitive
This commit is contained in:
parent
3e0ef334d4
commit
331215e783
2 changed files with 24 additions and 16 deletions
|
|
@ -36,8 +36,12 @@
|
||||||
- `c` - точка С. Пример: `c (1,1,0)`
|
- `c` - точка С. Пример: `c (1,1,0)`
|
||||||
- `uv` - нормализованные текстурные координаты точек (6 чисел, по 2 на точку). Пример: `uv (0,0, 1,0, 1,1)`
|
- `uv` - нормализованные текстурные координаты точек (6 чисел, по 2 на точку). Пример: `uv (0,0, 1,0, 1,1)`
|
||||||
- `texture` - отображаемая текстура. По-умолчанию: `$0`. Пример: `texture "blocks:sand"`
|
- `texture` - отображаемая текстура. По-умолчанию: `$0`. Пример: `texture "blocks:sand"`
|
||||||
|
- `region` - UV регион в границах выбранной текстуры, определяется позициями противоположных углов квадрата нормализованных текстурных координат. Пример: `region (0,0,1,1)`
|
||||||
|
- `region-scale` вектор-множитель для UV региона. Пример: `region-scale (0.5,1)`
|
||||||
- `shading` определяет возможность затенения на примитиве. Пример: `shading off`
|
- `shading` определяет возможность затенения на примитиве. Пример: `shading off`
|
||||||
|
|
||||||
|
Текстурные координаты по-умолчанию не зависят от формы из размера, в отличие от других примитивов.
|
||||||
|
|
||||||
### Свойства `rect`
|
### Свойства `rect`
|
||||||
|
|
||||||
Примитив описывает параллелограмм через векторы right и up.
|
Примитив описывает параллелограмм через векторы right и up.
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <glm/gtc/quaternion.hpp>
|
#include <glm/gtc/quaternion.hpp>
|
||||||
#include <glm/gtc/matrix_transform.hpp>
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
|
#include <glm/gtc/type_ptr.hpp>
|
||||||
|
|
||||||
#include "xml.hpp"
|
#include "xml.hpp"
|
||||||
#include "util/stringutil.hpp"
|
#include "util/stringutil.hpp"
|
||||||
|
|
@ -76,32 +77,35 @@ static void perform_triangle(const xmlelement& root, model::Model& model) {
|
||||||
auto pointB = root.attr("b").asVec3();
|
auto pointB = root.attr("b").asVec3();
|
||||||
auto pointC = root.attr("c").asVec3();
|
auto pointC = root.attr("c").asVec3();
|
||||||
|
|
||||||
float uvs[6] {0, 0, 1, 0, 1, 1};
|
glm::vec2 uvs[3] {{0, 0}, {1, 0}, {1, 1}};
|
||||||
|
|
||||||
bool shading = true;
|
bool shading = true;
|
||||||
if (root.has("shading")) {
|
if (root.has("shading")) {
|
||||||
shading = to_boolean(root.attr("shading"));
|
shading = to_boolean(root.attr("shading"));
|
||||||
}
|
}
|
||||||
if (root.has("uv")) {
|
|
||||||
root.attr("uv").asNumbers(uvs, sizeof(uvs) / sizeof(float));
|
|
||||||
}
|
|
||||||
|
|
||||||
glm::vec3 ba = pointB - pointA;
|
glm::vec3 ba = pointB - pointA;
|
||||||
glm::vec3 ca = pointC - pointA;
|
glm::vec3 ca = pointC - pointA;
|
||||||
glm::vec3 normal = glm::normalize(glm::cross(ba, ca));
|
glm::vec3 normal = glm::normalize(glm::cross(ba, ca));
|
||||||
|
|
||||||
|
if (root.has("uv")) {
|
||||||
|
root.attr("uv").asNumbers(glm::value_ptr(uvs[0]), 6);
|
||||||
|
} else {
|
||||||
|
UVRegion region {};
|
||||||
|
if (root.has("region")) {
|
||||||
|
region.set(root.attr("region").asVec4());
|
||||||
|
}
|
||||||
|
if (root.has("region-scale")) {
|
||||||
|
region.scale(root.attr("region-scale").asVec2());
|
||||||
|
}
|
||||||
|
for (auto& uv : uvs) {
|
||||||
|
uv = region.apply(uv);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::string texture = root.attr("texture", "$0").getText();
|
std::string texture = root.attr("texture", "$0").getText();
|
||||||
auto& mesh = model.addMesh(texture, shading);
|
auto& mesh = model.addMesh(texture, shading);
|
||||||
|
mesh.addTriangle(pointA, pointB, pointC, normal, uvs[0], uvs[1], uvs[2]);
|
||||||
mesh.addTriangle(
|
|
||||||
pointA,
|
|
||||||
pointB,
|
|
||||||
pointC,
|
|
||||||
normal,
|
|
||||||
{uvs[0], uvs[1]},
|
|
||||||
{uvs[2], uvs[3]},
|
|
||||||
{uvs[4], uvs[5]}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void perform_box(const xmlelement& root, model::Model& model) {
|
static void perform_box(const xmlelement& root, model::Model& model) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue