add custom-models in hand support
This commit is contained in:
@@ -8,7 +8,12 @@ inline constexpr glm::vec3 X(1, 0, 0);
|
||||
inline constexpr glm::vec3 Y(0, 1, 0);
|
||||
inline constexpr glm::vec3 Z(0, 0, 1);
|
||||
|
||||
void Mesh::addPlane(glm::vec3 pos, glm::vec3 right, glm::vec3 up, glm::vec3 norm) {
|
||||
void Mesh::addPlane(
|
||||
const glm::vec3& pos,
|
||||
const glm::vec3& right,
|
||||
const glm::vec3& up,
|
||||
const glm::vec3& norm
|
||||
) {
|
||||
vertices.push_back({pos-right-up, {0,0}, norm});
|
||||
vertices.push_back({pos+right-up, {1,0}, norm});
|
||||
vertices.push_back({pos+right+up, {1,1}, norm});
|
||||
@@ -18,7 +23,23 @@ void Mesh::addPlane(glm::vec3 pos, glm::vec3 right, glm::vec3 up, glm::vec3 norm
|
||||
vertices.push_back({pos-right+up, {0,1}, norm});
|
||||
}
|
||||
|
||||
void Mesh::addBox(glm::vec3 pos, glm::vec3 size) {
|
||||
void Mesh::addPlane(
|
||||
const glm::vec3& pos,
|
||||
const glm::vec3& right,
|
||||
const glm::vec3& up,
|
||||
const glm::vec3& norm,
|
||||
const UVRegion& uv
|
||||
) {
|
||||
vertices.push_back({pos-right-up, {uv.u1, uv.v1}, norm});
|
||||
vertices.push_back({pos+right-up, {uv.u2, uv.v1}, norm});
|
||||
vertices.push_back({pos+right+up, {uv.u2, uv.v2}, norm});
|
||||
|
||||
vertices.push_back({pos-right-up, {uv.u1, uv.v1}, norm});
|
||||
vertices.push_back({pos+right+up, {uv.u2, uv.v2}, norm});
|
||||
vertices.push_back({pos-right+up, {uv.u1, uv.u2}, norm});
|
||||
}
|
||||
|
||||
void Mesh::addBox(const glm::vec3& pos, const glm::vec3& size) {
|
||||
addPlane(pos+Z*size, X*size, Y*size, Z);
|
||||
addPlane(pos-Z*size, -X*size, Y*size, -Z);
|
||||
|
||||
@@ -29,6 +50,19 @@ void Mesh::addBox(glm::vec3 pos, glm::vec3 size) {
|
||||
addPlane(pos-X*size, Z*size, Y*size, -X);
|
||||
}
|
||||
|
||||
void Mesh::addBox(
|
||||
const glm::vec3& pos, const glm::vec3& size, const UVRegion (&uvs)[6]
|
||||
) {
|
||||
addPlane(pos+Z*size, X*size, Y*size, Z, uvs[0]);
|
||||
addPlane(pos-Z*size, -X*size, Y*size, -Z, uvs[1]);
|
||||
|
||||
addPlane(pos+Y*size, X*size, -Z*size, Y, uvs[2]);
|
||||
addPlane(pos-Y*size, X*size, Z*size, -Y, uvs[3]);
|
||||
|
||||
addPlane(pos+X*size, -Z*size, Y*size, X, uvs[4]);
|
||||
addPlane(pos-X*size, Z*size, Y*size, -X, uvs[5]);
|
||||
}
|
||||
|
||||
void Mesh::scale(const glm::vec3& size) {
|
||||
for (auto& vertex : vertices) {
|
||||
vertex.coord *= size;
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
#include <vector>
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
#include "maths/UVRegion.hpp"
|
||||
|
||||
namespace model {
|
||||
struct Vertex {
|
||||
glm::vec3 coord;
|
||||
@@ -14,9 +16,27 @@ namespace model {
|
||||
struct Mesh {
|
||||
std::string texture;
|
||||
std::vector<Vertex> vertices;
|
||||
|
||||
void addPlane(glm::vec3 pos, glm::vec3 right, glm::vec3 up, glm::vec3 norm);
|
||||
void addBox(glm::vec3 pos, glm::vec3 size);
|
||||
bool lighting = true;
|
||||
|
||||
void addPlane(
|
||||
const glm::vec3& pos,
|
||||
const glm::vec3& right,
|
||||
const glm::vec3& up,
|
||||
const glm::vec3& norm
|
||||
);
|
||||
void addPlane(
|
||||
const glm::vec3& pos,
|
||||
const glm::vec3& right,
|
||||
const glm::vec3& up,
|
||||
const glm::vec3& norm,
|
||||
const UVRegion& region
|
||||
);
|
||||
void addBox(const glm::vec3& pos, const glm::vec3& size);
|
||||
void addBox(
|
||||
const glm::vec3& pos,
|
||||
const glm::vec3& size,
|
||||
const UVRegion (&texfaces)[6]
|
||||
);
|
||||
void scale(const glm::vec3& size);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user