add custom-models in hand support
This commit is contained in:
@@ -80,3 +80,56 @@ glm::vec4 MainBatch::sampleLight(
|
||||
glm::max(Lightmap::extract(light, 3), minIntensity) / 15.0f
|
||||
);
|
||||
}
|
||||
|
||||
inline glm::vec4 do_tint(float value) {
|
||||
return glm::vec4(value, value, value, 1.0f);
|
||||
}
|
||||
|
||||
void MainBatch::cube(
|
||||
const glm::vec3& coord,
|
||||
const glm::vec3& size,
|
||||
const UVRegion(&texfaces)[6],
|
||||
const glm::vec4& tint,
|
||||
bool shading
|
||||
) {
|
||||
const glm::vec3 X(1.0f, 0.0f, 0.0f);
|
||||
const glm::vec3 Y(0.0f, 1.0f, 0.0f);
|
||||
const glm::vec3 Z(0.0f, 0.0f, 1.0f);
|
||||
|
||||
quad(
|
||||
coord + glm::vec3(0.0f, 0.0f, 0.0f),
|
||||
X, Y, glm::vec2(size.x, size.y),
|
||||
(shading ? do_tint(0.8) * tint : tint),
|
||||
glm::vec3(1.0f), texfaces[5]
|
||||
);
|
||||
quad(
|
||||
coord + glm::vec3(size.x, 0.0f, -size.z),
|
||||
-X, Y, glm::vec2(size.x, size.y),
|
||||
(shading ? do_tint(0.8) * tint : tint),
|
||||
glm::vec3(1.0f), texfaces[4]
|
||||
);
|
||||
quad(
|
||||
coord + glm::vec3(0.0f, size.y, 0.0f),
|
||||
X, -Z, glm::vec2(size.x, size.z),
|
||||
(shading ? do_tint(1.0f) * tint : tint),
|
||||
glm::vec3(1.0f), texfaces[3]
|
||||
);
|
||||
quad(
|
||||
coord + glm::vec3(0.0f, 0.0f, -size.z),
|
||||
X, Z, glm::vec2(size.x, size.z),
|
||||
(shading ? do_tint(0.7f) * tint : tint),
|
||||
glm::vec3(1.0f), texfaces[2]
|
||||
);
|
||||
quad(
|
||||
coord + glm::vec3(0.0f, 0.0f, -size.z),
|
||||
Z, Y, glm::vec2(size.z, size.y),
|
||||
(shading ? do_tint(0.9f) * tint : tint),
|
||||
glm::vec3(1.0f), texfaces[0]
|
||||
);
|
||||
quad(
|
||||
coord + glm::vec3(size.x, 0.0f, 0.0f),
|
||||
-Z, Y, glm::vec2(size.z, size.y),
|
||||
(shading ? do_tint(0.9f) * tint : tint),
|
||||
glm::vec3(1.0f), texfaces[1]
|
||||
);
|
||||
}
|
||||
|
||||
@@ -118,4 +118,12 @@ public:
|
||||
tint
|
||||
);
|
||||
}
|
||||
|
||||
void cube(
|
||||
const glm::vec3& coord,
|
||||
const glm::vec3& size,
|
||||
const UVRegion(&texfaces)[6],
|
||||
const glm::vec4& tint,
|
||||
bool shading
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "ModelsGenerator.hpp"
|
||||
|
||||
#include "assets/Assets.hpp"
|
||||
#include "assets/assets_util.hpp"
|
||||
#include "items/ItemDef.hpp"
|
||||
#include "voxels/Block.hpp"
|
||||
#include "content/Content.hpp"
|
||||
@@ -40,6 +41,13 @@ static model::Model create_flat_model(
|
||||
return model;
|
||||
}
|
||||
|
||||
static inline UVRegion get_region_for(
|
||||
const std::string& texture, const Assets& assets
|
||||
) {
|
||||
auto texreg = util::get_texture_region(assets, "blocks:" + texture, "");
|
||||
return texreg.region;
|
||||
}
|
||||
|
||||
model::Model ModelsGenerator::generate(
|
||||
const ItemDef& def, const Content& content, const Assets& assets
|
||||
) {
|
||||
@@ -50,6 +58,56 @@ model::Model ModelsGenerator::generate(
|
||||
return create_flat_model(
|
||||
"blocks:" + blockDef.textureFaces.at(0), assets
|
||||
);
|
||||
} else if (blockDef.model == BlockModel::custom) {
|
||||
model = model::Model();
|
||||
for (size_t i = 0; i < blockDef.modelBoxes.size(); i++) {
|
||||
auto& mesh =
|
||||
model.addMesh("blocks:" + blockDef.modelTextures[i * 6]);
|
||||
mesh.lighting = !def.rt.emissive;
|
||||
const UVRegion (&boxtexfaces)[6] = {
|
||||
get_region_for(blockDef.modelTextures[i * 6], assets),
|
||||
get_region_for(blockDef.modelTextures[i * 6 + 1], assets),
|
||||
get_region_for(blockDef.modelTextures[i * 6 + 2], assets),
|
||||
get_region_for(blockDef.modelTextures[i * 6 + 3], assets),
|
||||
get_region_for(blockDef.modelTextures[i * 6 + 4], assets),
|
||||
get_region_for(blockDef.modelTextures[i * 6 + 5], assets)
|
||||
};
|
||||
mesh.addBox(
|
||||
blockDef.modelBoxes[i].center(),
|
||||
blockDef.modelBoxes[i].size()*0.5f, boxtexfaces
|
||||
);
|
||||
}
|
||||
const auto& points = blockDef.modelExtraPoints;
|
||||
glm::vec3 poff = glm::vec3(0.0f, 0.0f, 1.0f);
|
||||
glm::vec3 norm {0, 1, 0};
|
||||
for (size_t i = 0; i < blockDef.modelExtraPoints.size() / 4; i++) {
|
||||
auto texture =
|
||||
"blocks:" +
|
||||
blockDef.modelTextures[blockDef.modelBoxes.size() * 6 + i];
|
||||
|
||||
auto& mesh = model.addMesh(texture);
|
||||
mesh.lighting = !def.rt.emissive;
|
||||
|
||||
auto reg = get_region_for(texture, assets);
|
||||
mesh.vertices.push_back(
|
||||
{points[i * 4 + 0] - poff, glm::vec2(reg.u1, reg.v1), norm}
|
||||
);
|
||||
mesh.vertices.push_back(
|
||||
{points[i * 4 + 1] - poff, glm::vec2(reg.u2, reg.v1), norm}
|
||||
);
|
||||
mesh.vertices.push_back(
|
||||
{points[i * 4 + 2] - poff, glm::vec2(reg.u2, reg.v2), norm}
|
||||
);
|
||||
mesh.vertices.push_back(
|
||||
{points[i * 4 + 3] - poff, glm::vec2(reg.u1, reg.v1), norm}
|
||||
);
|
||||
mesh.vertices.push_back(
|
||||
{points[i * 4 + 4] - poff, glm::vec2(reg.u2, reg.v2), norm}
|
||||
);
|
||||
mesh.vertices.push_back(
|
||||
{points[i * 4 + 0] - poff, glm::vec2(reg.u1, reg.v2), norm}
|
||||
);
|
||||
}
|
||||
}
|
||||
for (auto& mesh : model.meshes) {
|
||||
switch (blockDef.model) {
|
||||
|
||||
Reference in New Issue
Block a user