mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-11-23 02:49:46 +00:00
upgrade entities frustum culling
This commit is contained in:
parent
414a0947ab
commit
c21871c3c9
9 changed files with 206 additions and 63 deletions
|
|
@ -88,6 +88,7 @@ void Skeleton::deserialize(const dv::value& root) {
|
||||||
dv::get_mat(posearr[i], pose.matrices[i]);
|
dv::get_mat(posearr[i], pose.matrices[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
boundsDirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Skeleton::setConfig(std::shared_ptr<const SkeletonConfig> rigConfig) {
|
void Skeleton::setConfig(std::shared_ptr<const SkeletonConfig> rigConfig) {
|
||||||
|
|
@ -105,6 +106,7 @@ void Skeleton::setConfig(std::shared_ptr<const SkeletonConfig> rigConfig) {
|
||||||
for (size_t i = 0; i < bonesCount; i++) {
|
for (size_t i = 0; i < bonesCount; i++) {
|
||||||
flags[i].visible = true;
|
flags[i].visible = true;
|
||||||
}
|
}
|
||||||
|
boundsDirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void get_all_nodes(std::vector<Bone*>& nodes, Bone* node) {
|
static void get_all_nodes(std::vector<Bone*>& nodes, Bone* node) {
|
||||||
|
|
@ -173,6 +175,76 @@ void SkeletonConfig::update(
|
||||||
update(0, skeleton, root.get(), build_matrix(rot, pos, scale));
|
update(0, skeleton, root.get(), build_matrix(rot, pos, scale));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static float max_component(const glm::vec3& v) {
|
||||||
|
return glm::max(glm::abs(v.x), glm::max(glm::abs(v.y), glm::abs(v.z)));
|
||||||
|
}
|
||||||
|
|
||||||
|
static float farthest_corner_distance(
|
||||||
|
const glm::mat4& matrix, const AABB& aabb, const glm::vec3& origin
|
||||||
|
) {
|
||||||
|
glm::vec3 center = glm::vec3(matrix * glm::vec4(aabb.center(), 1.0f));
|
||||||
|
glm::vec3 halfSize = aabb.size() * 0.5f;
|
||||||
|
glm::vec3 extent = glm::abs(glm::vec3(matrix[0])) * halfSize.x +
|
||||||
|
glm::abs(glm::vec3(matrix[1])) * halfSize.y +
|
||||||
|
glm::abs(glm::vec3(matrix[2])) * halfSize.z;
|
||||||
|
return glm::length(glm::abs(center - origin) + extent);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SkeletonConfig::processModels(
|
||||||
|
const Assets& assets,
|
||||||
|
Skeleton& skeleton,
|
||||||
|
const glm::vec3& position,
|
||||||
|
const glm::vec3& scale,
|
||||||
|
ModelBatch* batch,
|
||||||
|
ModelLightingMode lightingMode,
|
||||||
|
bool translucent
|
||||||
|
) const {
|
||||||
|
float radius = 0.0f;
|
||||||
|
bool pending = false;
|
||||||
|
for (size_t i = 0; i < nodes.size(); i++) {
|
||||||
|
auto* node = nodes[i];
|
||||||
|
if (!skeleton.flags[i].visible) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
node->model.refresh(assets);
|
||||||
|
auto model = node->model.model.lock(); // TODO: cache model pointer during frame
|
||||||
|
auto& modelOverride = skeleton.modelOverrides.at(i);
|
||||||
|
if (modelOverride.updateFlag) {
|
||||||
|
modelOverride.refresh(assets);
|
||||||
|
}
|
||||||
|
if (auto foundOverride = modelOverride.model.lock()) {
|
||||||
|
model = std::move(foundOverride);
|
||||||
|
}
|
||||||
|
if (model == nullptr) {
|
||||||
|
if (!node->model.name.empty()) {
|
||||||
|
node->model.updateFlag = true;
|
||||||
|
pending = true;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const auto& matrix = skeleton.calculated.matrices[i];
|
||||||
|
radius = glm::max(
|
||||||
|
radius, farthest_corner_distance(matrix, model->getBounds(), position)
|
||||||
|
);
|
||||||
|
if (batch == nullptr) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
batch->draw(
|
||||||
|
matrix,
|
||||||
|
skeleton.tint * skeleton.boneTints[i],
|
||||||
|
lightingMode == ModelLightingMode::SOLID
|
||||||
|
? position - glm::vec3(matrix * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f))
|
||||||
|
: glm::vec3(),
|
||||||
|
model,
|
||||||
|
&skeleton.textures,
|
||||||
|
translucent
|
||||||
|
);
|
||||||
|
}
|
||||||
|
float maxScale = max_component(scale);
|
||||||
|
skeleton.boundsRadius = maxScale > 0.0f ? radius / maxScale : radius;
|
||||||
|
skeleton.boundsDirty = pending;
|
||||||
|
}
|
||||||
|
|
||||||
void SkeletonConfig::render(
|
void SkeletonConfig::render(
|
||||||
const Assets& assets,
|
const Assets& assets,
|
||||||
ModelBatch& batch,
|
ModelBatch& batch,
|
||||||
|
|
@ -191,40 +263,31 @@ void SkeletonConfig::render(
|
||||||
if (!skeleton.visible) {
|
if (!skeleton.visible) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (size_t i = 0; i < nodes.size(); i++) {
|
processModels(
|
||||||
auto* node = nodes[i];
|
assets, skeleton, position, scale, &batch, lightingMode, translucent
|
||||||
if (!skeleton.flags[i].visible) {
|
);
|
||||||
continue;
|
}
|
||||||
}
|
|
||||||
node->model.refresh(assets);
|
void SkeletonConfig::updateBounds(
|
||||||
auto model = node->model.model.lock(); // TODO: cache model pointer during frame
|
const Assets& assets,
|
||||||
auto& modelOverride = skeleton.modelOverrides.at(i);
|
Skeleton& skeleton,
|
||||||
if (modelOverride.updateFlag) {
|
const glm::mat3& rotation,
|
||||||
modelOverride.refresh(assets);
|
const glm::vec3& position,
|
||||||
}
|
const glm::vec3& scale
|
||||||
if (auto foundOverride = modelOverride.model.lock()) {
|
) const {
|
||||||
model = std::move(foundOverride);
|
if (skeleton.config->root == nullptr) {
|
||||||
}
|
return;
|
||||||
if (model == nullptr) {
|
|
||||||
if (!node->model.name.empty()) {
|
|
||||||
node->model.updateFlag = true;
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
batch.draw(
|
|
||||||
skeleton.calculated.matrices[i],
|
|
||||||
skeleton.tint * skeleton.boneTints[i],
|
|
||||||
lightingMode == ModelLightingMode::SOLID
|
|
||||||
? position - glm::vec3(
|
|
||||||
skeleton.calculated.matrices[i] *
|
|
||||||
glm::vec4(0.0f, 0.0f, 0.0f, 1.0f)
|
|
||||||
)
|
|
||||||
: glm::vec3(),
|
|
||||||
model,
|
|
||||||
&skeleton.textures,
|
|
||||||
translucent
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
update(skeleton, rotation, position, scale);
|
||||||
|
processModels(
|
||||||
|
assets,
|
||||||
|
skeleton,
|
||||||
|
position,
|
||||||
|
scale,
|
||||||
|
nullptr,
|
||||||
|
ModelLightingMode::SOLID,
|
||||||
|
false
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const Bone* SkeletonConfig::find(std::string_view str) const {
|
const Bone* SkeletonConfig::find(std::string_view str) const {
|
||||||
|
|
|
||||||
|
|
@ -97,6 +97,10 @@ namespace rigging {
|
||||||
std::vector<ModelReference> modelOverrides;
|
std::vector<ModelReference> modelOverrides;
|
||||||
bool visible;
|
bool visible;
|
||||||
bool culled = false;
|
bool culled = false;
|
||||||
|
/// @brief Bounding radius of visible models around entity position,
|
||||||
|
/// divided by the largest scale component
|
||||||
|
float boundsRadius = 0.0f;
|
||||||
|
bool boundsDirty = true;
|
||||||
glm::vec4 tint {1.0f, 1.0f, 1.0f, 1.0f};
|
glm::vec4 tint {1.0f, 1.0f, 1.0f, 1.0f};
|
||||||
std::vector<glm::vec4> boneTints;
|
std::vector<glm::vec4> boneTints;
|
||||||
|
|
||||||
|
|
@ -127,6 +131,16 @@ namespace rigging {
|
||||||
size_t update(
|
size_t update(
|
||||||
size_t index, Skeleton& skeleton, Bone* node, const glm::mat4& matrix
|
size_t index, Skeleton& skeleton, Bone* node, const glm::mat4& matrix
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
|
void processModels(
|
||||||
|
const Assets& assets,
|
||||||
|
Skeleton& skeleton,
|
||||||
|
const glm::vec3& position,
|
||||||
|
const glm::vec3& scale,
|
||||||
|
ModelBatch* batch,
|
||||||
|
ModelLightingMode lightingMode,
|
||||||
|
bool translucent
|
||||||
|
) const;
|
||||||
public:
|
public:
|
||||||
SkeletonConfig(
|
SkeletonConfig(
|
||||||
const std::string& name,
|
const std::string& name,
|
||||||
|
|
@ -152,6 +166,14 @@ namespace rigging {
|
||||||
bool translucent = false
|
bool translucent = false
|
||||||
) const;
|
) const;
|
||||||
|
|
||||||
|
void updateBounds(
|
||||||
|
const Assets& assets,
|
||||||
|
Skeleton& skeleton,
|
||||||
|
const glm::mat3& rotation,
|
||||||
|
const glm::vec3& position,
|
||||||
|
const glm::vec3& scale
|
||||||
|
) const;
|
||||||
|
|
||||||
Skeleton instance() const {
|
Skeleton instance() const {
|
||||||
return Skeleton(shared_from_this());
|
return Skeleton(shared_from_this());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -134,6 +134,7 @@ public:
|
||||||
auto model = std::make_unique<Model>();
|
auto model = std::make_unique<Model>();
|
||||||
buildMeshes(*model);
|
buildMeshes(*model);
|
||||||
model->clean();
|
model->clean();
|
||||||
|
model->calcBounds();
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -469,6 +469,7 @@ static VcmModel load_model(const xmlelement& root) {
|
||||||
perform_element(*elem, builder, ctx);
|
perform_element(*elem, builder, ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
model.calcBounds();
|
||||||
vcmModel.parts["root"] = std::move(model);
|
vcmModel.parts["root"] = std::move(model);
|
||||||
vcmModel.skeleton = SkeletonConfig(
|
vcmModel.skeleton = SkeletonConfig(
|
||||||
"",
|
"",
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
#include "Model.hpp"
|
#include "Model.hpp"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <limits>
|
||||||
#include <glm/gtc/quaternion.hpp>
|
#include <glm/gtc/quaternion.hpp>
|
||||||
#include <glm/gtx/matrix_decompose.hpp>
|
#include <glm/gtx/matrix_decompose.hpp>
|
||||||
|
|
||||||
|
|
@ -168,6 +169,25 @@ void Mesh::translate(const glm::vec3& offset) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Model::calcBounds() {
|
||||||
|
glm::vec3 min(std::numeric_limits<float>::max());
|
||||||
|
glm::vec3 max(std::numeric_limits<float>::lowest());
|
||||||
|
for (const auto& mesh : meshes) {
|
||||||
|
for (const auto& vertex : mesh.vertices) {
|
||||||
|
min = glm::min(min, vertex.coord);
|
||||||
|
max = glm::max(max, vertex.coord);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (min.x > max.x) {
|
||||||
|
min = max = glm::vec3(0.0f);
|
||||||
|
}
|
||||||
|
bounds = AABB(min, max);
|
||||||
|
}
|
||||||
|
|
||||||
|
const AABB& Model::getBounds() const {
|
||||||
|
return bounds;
|
||||||
|
}
|
||||||
|
|
||||||
void Model::clean() {
|
void Model::clean() {
|
||||||
meshes.erase(
|
meshes.erase(
|
||||||
std::remove_if(meshes.begin(), meshes.end(),
|
std::remove_if(meshes.begin(), meshes.end(),
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
#include "maths/UVRegion.hpp"
|
#include "maths/UVRegion.hpp"
|
||||||
|
#include "maths/aabb.hpp"
|
||||||
|
|
||||||
namespace model {
|
namespace model {
|
||||||
struct Vertex {
|
struct Vertex {
|
||||||
|
|
@ -82,6 +83,7 @@ namespace model {
|
||||||
|
|
||||||
struct Model {
|
struct Model {
|
||||||
std::vector<Mesh> meshes;
|
std::vector<Mesh> meshes;
|
||||||
|
AABB bounds {glm::vec3(0.0f), glm::vec3(0.0f)};
|
||||||
|
|
||||||
/// @brief Add mesh to the model
|
/// @brief Add mesh to the model
|
||||||
/// @param texture texture name
|
/// @param texture texture name
|
||||||
|
|
@ -96,6 +98,9 @@ namespace model {
|
||||||
return meshes[meshes.size() - 1];
|
return meshes[meshes.size() - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void calcBounds();
|
||||||
|
const AABB& getBounds() const;
|
||||||
|
|
||||||
/// @brief Remove all empty meshes
|
/// @brief Remove all empty meshes
|
||||||
void clean();
|
void clean();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -187,6 +187,7 @@ model::Model ModelsGenerator::fromCustom(
|
||||||
mesh.vertices.push_back({v2, glm::vec2(reg.u2, reg.v2), norm});
|
mesh.vertices.push_back({v2, glm::vec2(reg.u2, reg.v2), norm});
|
||||||
mesh.vertices.push_back({v3, glm::vec2(reg.u1, reg.v2), norm});
|
mesh.vertices.push_back({v3, glm::vec2(reg.u1, reg.v2), norm});
|
||||||
}
|
}
|
||||||
|
model.calcBounds();
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -62,6 +62,7 @@ static int l_set_model(lua::State* L) {
|
||||||
} else {
|
} else {
|
||||||
modelOverride = {lua::require_string(L, 3), {}, true};
|
modelOverride = {lua::require_string(L, 3), {}, true};
|
||||||
}
|
}
|
||||||
|
skeleton->boundsDirty = true;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -85,6 +86,7 @@ static int l_set_matrix(lua::State* L) {
|
||||||
}
|
}
|
||||||
auto index = index_range_check(*skeleton, lua::tointeger(L, 2));
|
auto index = index_range_check(*skeleton, lua::tointeger(L, 2));
|
||||||
skeleton->pose.matrices[index] = lua::tomat4(L, 3);
|
skeleton->pose.matrices[index] = lua::tomat4(L, 3);
|
||||||
|
skeleton->boundsDirty = true;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -104,6 +106,7 @@ static int l_reset_pose(lua::State* L) {
|
||||||
if (auto skeleton = get_skeleton(L)) {
|
if (auto skeleton = get_skeleton(L)) {
|
||||||
auto& pose = skeleton->pose;
|
auto& pose = skeleton->pose;
|
||||||
std::fill(pose.matrices.begin(), pose.matrices.end(), glm::mat4(1.0f));
|
std::fill(pose.matrices.begin(), pose.matrices.end(), glm::mat4(1.0f));
|
||||||
|
skeleton->boundsDirty = true;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -157,6 +160,7 @@ static int l_set_visible(lua::State* L) {
|
||||||
} else {
|
} else {
|
||||||
skeleton->visible = lua::toboolean(L, 2);
|
skeleton->visible = lua::toboolean(L, 2);
|
||||||
}
|
}
|
||||||
|
skeleton->boundsDirty = true;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -345,6 +349,7 @@ static int l_apply_track(lua::State* L) {
|
||||||
return index > 0 && index <= MAX_TRACK_VALUES ? values[index] : fallback;
|
return index > 0 && index <= MAX_TRACK_VALUES ? values[index] : fallback;
|
||||||
};
|
};
|
||||||
auto& matrices = skeleton->pose.matrices;
|
auto& matrices = skeleton->pose.matrices;
|
||||||
|
skeleton->boundsDirty = true;
|
||||||
for (size_t i = 0; i < track.bones.size(); i++) {
|
for (size_t i = 0; i < track.bones.size(); i++) {
|
||||||
int index = track.indices[i];
|
int index = track.indices[i];
|
||||||
if (index < 0 || static_cast<size_t>(index) >= matrices.size()) {
|
if (index < 0 || static_cast<size_t>(index) >= matrices.size()) {
|
||||||
|
|
|
||||||
|
|
@ -427,24 +427,49 @@ static void debug_render_skeleton(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static glm::vec3 calc_extent(
|
||||||
|
const Transform& transform,
|
||||||
|
const Rigidbody& rigidbody,
|
||||||
|
const rigging::Skeleton& skeleton
|
||||||
|
) {
|
||||||
|
const auto& size = transform.size;
|
||||||
|
float scale = glm::max(
|
||||||
|
glm::abs(size.x), glm::max(glm::abs(size.y), glm::abs(size.z))
|
||||||
|
);
|
||||||
|
return glm::max(
|
||||||
|
rigidbody.hitbox.getHalfSize(), glm::vec3(skeleton.boundsRadius * scale)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool check_frustum(
|
||||||
|
const Frustum& frustum,
|
||||||
|
const Transform& transform,
|
||||||
|
const Rigidbody& rigidbody,
|
||||||
|
const rigging::Skeleton& skeleton
|
||||||
|
) {
|
||||||
|
glm::vec3 ext = calc_extent(transform, rigidbody, skeleton);
|
||||||
|
return frustum.isBoxVisible(transform.pos - ext, transform.pos + ext);
|
||||||
|
}
|
||||||
|
|
||||||
void Entities::renderDebug(
|
void Entities::renderDebug(
|
||||||
LineBatch& batch, const Frustum* frustum, const DrawContext& pctx, entityid_t fpsEntity
|
LineBatch& batch, const Frustum* frustum, const DrawContext& pctx, entityid_t fpsEntity
|
||||||
) {
|
) {
|
||||||
{
|
{
|
||||||
auto ctx = pctx.sub(&batch);
|
auto ctx = pctx.sub(&batch);
|
||||||
ctx.setLineWidth(1);
|
ctx.setLineWidth(1);
|
||||||
auto view = registry->view<Transform, Rigidbody>();
|
auto view = registry->view<Transform, Rigidbody, rigging::Skeleton>();
|
||||||
for (auto [entity, transform, rigidbody] : view.each()) {
|
for (auto [entity, transform, rigidbody, skeleton] : view.each()) {
|
||||||
const auto& hitbox = rigidbody.hitbox;
|
const auto& hitbox = rigidbody.hitbox;
|
||||||
const auto& pos = transform.pos;
|
if (frustum && !check_frustum(*frustum, transform, rigidbody, skeleton)) {
|
||||||
const auto& size = transform.size;
|
|
||||||
if (frustum && !frustum->isBoxVisible(pos - size, pos + size)) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
batch.box(
|
batch.box(
|
||||||
hitbox.position, hitbox.getHalfSize() * 2.0f, glm::vec4(1.0f)
|
hitbox.position, hitbox.getHalfSize() * 2.0f, glm::vec4(1.0f)
|
||||||
);
|
);
|
||||||
|
glm::vec3 ext = calc_extent(transform, rigidbody, skeleton);
|
||||||
|
batch.box(
|
||||||
|
transform.pos, ext * 2.0f, glm::vec4(0.0f, 0.0f, 1.0f, 1.0f)
|
||||||
|
);
|
||||||
for (auto& sensor : rigidbody.sensors) {
|
for (auto& sensor : rigidbody.sensors) {
|
||||||
if (sensor.type != SensorType::AABB) continue;
|
if (sensor.type != SensorType::AABB) continue;
|
||||||
batch.box(
|
batch.box(
|
||||||
|
|
@ -456,12 +481,12 @@ void Entities::renderDebug(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
auto view = registry->view<EntityId, Transform, rigging::Skeleton>();
|
auto view = registry->view<EntityId, Transform, Rigidbody, rigging::Skeleton>();
|
||||||
auto ctx = pctx.sub(&batch);
|
auto ctx = pctx.sub(&batch);
|
||||||
ctx.setDepthTest(false);
|
ctx.setDepthTest(false);
|
||||||
ctx.setDepthMask(false);
|
ctx.setDepthMask(false);
|
||||||
ctx.setLineWidth(2);
|
ctx.setLineWidth(2);
|
||||||
for (auto [entity, eid, transform, skeleton] : view.each()) {
|
for (auto [entity, eid, transform, rigidbody, skeleton] : view.each()) {
|
||||||
if (eid.uid == fpsEntity) {
|
if (eid.uid == fpsEntity) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
@ -469,9 +494,7 @@ void Entities::renderDebug(
|
||||||
if (config == nullptr) {
|
if (config == nullptr) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const auto& pos = transform.pos;
|
if (frustum && !check_frustum(*frustum, transform, rigidbody, skeleton)) {
|
||||||
const auto& size = transform.size;
|
|
||||||
if (frustum && !frustum->isBoxVisible(pos - size, pos + size)) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
auto bone = config->getRoot();
|
auto bone = config->getRoot();
|
||||||
|
|
@ -494,25 +517,29 @@ void Entities::render(
|
||||||
const auto& def = eid.def;
|
const auto& def = eid.def;
|
||||||
const auto& pos = transform.pos;
|
const auto& pos = transform.pos;
|
||||||
const auto& size = transform.size;
|
const auto& size = transform.size;
|
||||||
const auto& halfSize = rigidbody.hitbox.getHalfSize();
|
const auto& rigConfig = skeleton.config;
|
||||||
// todo: more correct frustum culling
|
if (rigConfig == nullptr) {
|
||||||
if (frustum && !frustum->isBoxVisible(pos - halfSize, pos + halfSize)) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (frustum && !check_frustum(*frustum, transform, rigidbody, skeleton)) {
|
||||||
const auto& rigConfig = skeleton.config;
|
if (!skeleton.boundsDirty || !skeleton.visible) {
|
||||||
if (rigConfig) {
|
continue;
|
||||||
rigConfig->render(
|
}
|
||||||
assets,
|
rigConfig->updateBounds(assets, skeleton, transform.rot, pos, size);
|
||||||
batch,
|
if (!check_frustum(*frustum, transform, rigidbody, skeleton)) {
|
||||||
skeleton,
|
continue;
|
||||||
def.lightingMode,
|
}
|
||||||
transform.rot,
|
|
||||||
pos,
|
|
||||||
size,
|
|
||||||
def.translucent
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
rigConfig->render(
|
||||||
|
assets,
|
||||||
|
batch,
|
||||||
|
skeleton,
|
||||||
|
def.lightingMode,
|
||||||
|
transform.rot,
|
||||||
|
pos,
|
||||||
|
size,
|
||||||
|
def.translucent
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -523,9 +550,7 @@ void Entities::updateCulling(const Frustum* frustum, entityid_t fpsEntity) {
|
||||||
skeleton.culled = false;
|
skeleton.culled = false;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const auto& pos = transform.pos;
|
skeleton.culled = !check_frustum(*frustum, transform, rigidbody, skeleton);
|
||||||
const auto& halfSize = rigidbody.hitbox.getHalfSize();
|
|
||||||
skeleton.culled = !frustum->isBoxVisible(pos - halfSize, pos + halfSize);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue