Added KRMeshManager::GetMaxLODModel helper function.
Refactored KRMeshManager::GetModel call sites to use GetMaxLODModel where only the maximum LOD is used.
This commit is contained in:
@@ -127,8 +127,8 @@ void KRAmbientZone::render(RenderInfo& ri)
|
||||
bool bVisualize = ri.camera->settings.debug_display == KRRenderSettings::KRENGINE_DEBUG_DISPLAY_SIREN_AMBIENT_ZONES;
|
||||
|
||||
if(ri.renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT && bVisualize) {
|
||||
std::vector<KRMesh*> sphereModels = getContext().getMeshManager()->getModel("__sphere");
|
||||
if (sphereModels.size()) {
|
||||
KRMesh* sphereModel = getContext().getMeshManager()->getMaxLODModel("__sphere");
|
||||
if (sphereModel) {
|
||||
|
||||
Matrix4 sphereModelMatrix = getModelMatrix();
|
||||
|
||||
@@ -141,14 +141,14 @@ void KRAmbientZone::render(RenderInfo& ri)
|
||||
info.spot_lights = &ri.spot_lights;
|
||||
info.renderPass = ri.renderPass;
|
||||
info.rasterMode = PipelineInfo::RasterMode::kAdditive;
|
||||
info.modelFormat = sphereModels[0]->getModelFormat();
|
||||
info.vertexAttributes = sphereModels[0]->getVertexAttributes();
|
||||
info.modelFormat = sphereModel->getModelFormat();
|
||||
info.vertexAttributes = sphereModel->getVertexAttributes();
|
||||
|
||||
KRPipeline *pPipeline = getContext().getPipelineManager()->getPipeline(*ri.surface, info);
|
||||
pPipeline->bind(*ri.camera, ri.viewport, sphereModelMatrix, &ri.point_lights, &ri.directional_lights, &ri.spot_lights, ri.renderPass, Vector3::Zero(), 0.0f, Vector4::Zero());
|
||||
|
||||
sphereModels[0]->renderNoMaterials(ri.commandBuffer, ri.renderPass, getName(), "visualize_overlay", 1.0f);
|
||||
} // sphereModels.size()
|
||||
sphereModel->renderNoMaterials(ri.commandBuffer, ri.renderPass, getName(), "visualize_overlay", 1.0f);
|
||||
} // sphereModel
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -194,8 +194,8 @@ void KRAudioSource::render(RenderInfo& ri)
|
||||
bool bVisualize = false;
|
||||
|
||||
if(ri.renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT && bVisualize) {
|
||||
std::vector<KRMesh*> sphereModels = getContext().getMeshManager()->getModel("__sphere");
|
||||
if (sphereModels.size()) {
|
||||
KRMesh* sphereModel = getContext().getMeshManager()->getMaxLODModel("__sphere");
|
||||
if (sphereModel) {
|
||||
Matrix4 sphereModelMatrix = getModelMatrix();
|
||||
|
||||
PipelineInfo info{};
|
||||
@@ -207,13 +207,13 @@ void KRAudioSource::render(RenderInfo& ri)
|
||||
info.spot_lights = &ri.spot_lights;
|
||||
info.renderPass = ri.renderPass;
|
||||
info.rasterMode = PipelineInfo::RasterMode::kAdditive;
|
||||
info.modelFormat = sphereModels[0]->getModelFormat();
|
||||
info.vertexAttributes = sphereModels[0]->getVertexAttributes();
|
||||
info.modelFormat = sphereModel->getModelFormat();
|
||||
info.vertexAttributes = sphereModel->getVertexAttributes();
|
||||
|
||||
KRPipeline* pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info);
|
||||
pShader->bind(*ri.camera, ri.viewport, sphereModelMatrix, &ri.point_lights, &ri.directional_lights, &ri.spot_lights, ri.renderPass, Vector3::Zero(), 0.0f, Vector4::Zero());
|
||||
|
||||
sphereModels[0]->renderNoMaterials(ri.commandBuffer, ri.renderPass, getName(), "visualize_overlay", 1.0f);
|
||||
sphereModel->renderNoMaterials(ri.commandBuffer, ri.renderPass, getName(), "visualize_overlay", 1.0f);
|
||||
} // sphereModels.size()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,8 +78,8 @@ void KRBone::render(RenderInfo& ri)
|
||||
bool bVisualize = ri.camera->settings.debug_display == KRRenderSettings::KRENGINE_DEBUG_DISPLAY_BONES;
|
||||
|
||||
if(ri.renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT && bVisualize) {
|
||||
std::vector<KRMesh*> sphereModels = getContext().getMeshManager()->getModel("__sphere");
|
||||
if (sphereModels.size()) {
|
||||
KRMesh* sphereModel = getContext().getMeshManager()->getMaxLODModel("__sphere");
|
||||
if (sphereModel) {
|
||||
Matrix4 sphereModelMatrix = getModelMatrix();
|
||||
|
||||
PipelineInfo info{};
|
||||
@@ -91,14 +91,14 @@ void KRBone::render(RenderInfo& ri)
|
||||
info.spot_lights = &ri.spot_lights;
|
||||
info.renderPass = ri.renderPass;
|
||||
info.rasterMode = PipelineInfo::RasterMode::kAdditiveNoTest;
|
||||
info.modelFormat = sphereModels[0]->getModelFormat();
|
||||
info.vertexAttributes = sphereModels[0]->getVertexAttributes();
|
||||
info.modelFormat = sphereModel->getModelFormat();
|
||||
info.vertexAttributes = sphereModel->getVertexAttributes();
|
||||
|
||||
KRPipeline *pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info);
|
||||
pShader->bind(*ri.camera, ri.viewport, sphereModelMatrix, &ri.point_lights, &ri.directional_lights, &ri.spot_lights, ri.renderPass, Vector3::Zero(), 0.0f, Vector4::Zero());
|
||||
|
||||
sphereModels[0]->renderNoMaterials(ri.commandBuffer, ri.renderPass, getName(), "visualize_overlay", 1.0f);
|
||||
} // sphereModels.size()
|
||||
sphereModel->renderNoMaterials(ri.commandBuffer, ri.renderPass, getName(), "visualize_overlay", 1.0f);
|
||||
} // sphereModel
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -47,6 +47,7 @@ KRCollider::KRCollider(KRScene &scene, std::string collider_name, std::string mo
|
||||
m_model_name = model_name;
|
||||
m_layer_mask = layer_mask;
|
||||
m_audio_occlusion = audio_occlusion;
|
||||
m_model = nullptr;
|
||||
}
|
||||
|
||||
KRCollider::~KRCollider() {
|
||||
@@ -83,28 +84,28 @@ void KRCollider::loadXML(tinyxml2::XMLElement *e) {
|
||||
}
|
||||
|
||||
void KRCollider::loadModel() {
|
||||
if(m_models.size() == 0) {
|
||||
m_models = m_pContext->getMeshManager()->getModel(m_model_name.c_str()); // The model manager returns the LOD levels in sorted order, with the highest detail first
|
||||
if(m_models.size() > 0) {
|
||||
if(m_model == nullptr) {
|
||||
m_model = m_pContext->getMeshManager()->getMaxLODModel(m_model_name.c_str());
|
||||
if(m_model) {
|
||||
getScene().notify_sceneGraphModify(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AABB KRCollider::getBounds() {
|
||||
loadModel();
|
||||
if(m_models.size() > 0) {
|
||||
return AABB::Create(m_models[0]->getMinPoint(), m_models[0]->getMaxPoint(), getModelMatrix());
|
||||
} else {
|
||||
return AABB::Infinite();
|
||||
}
|
||||
loadModel();
|
||||
if(m_model) {
|
||||
return AABB::Create(m_model->getMinPoint(), m_model->getMaxPoint(), getModelMatrix());
|
||||
} else {
|
||||
return AABB::Infinite();
|
||||
}
|
||||
}
|
||||
|
||||
bool KRCollider::lineCast(const Vector3 &v0, const Vector3 &v1, HitInfo &hitinfo, unsigned int layer_mask)
|
||||
{
|
||||
if(layer_mask & m_layer_mask ) { // Only test if layer masks have a common bit set
|
||||
loadModel();
|
||||
if(m_models.size()) {
|
||||
if(m_model) {
|
||||
if(getBounds().intersectsLine(v0, v1)) {
|
||||
Vector3 v0_model_space = Matrix4::Dot(getInverseModelMatrix(), v0);
|
||||
Vector3 v1_model_space = Matrix4::Dot(getInverseModelMatrix(), v1);
|
||||
@@ -114,7 +115,7 @@ bool KRCollider::lineCast(const Vector3 &v0, const Vector3 &v1, HitInfo &hitinfo
|
||||
hitinfo_model_space = HitInfo(hit_position_model_space, Matrix4::DotNoTranslate(getInverseModelMatrix(), hitinfo.getNormal()), (hit_position_model_space - v0_model_space).magnitude(), hitinfo.getNode());
|
||||
}
|
||||
|
||||
if(m_models[0]->lineCast(v0_model_space, v1_model_space, hitinfo_model_space)) {
|
||||
if(m_model->lineCast(v0_model_space, v1_model_space, hitinfo_model_space)) {
|
||||
Vector3 hit_position_world_space = Matrix4::Dot(getModelMatrix(), hitinfo_model_space.getPosition());
|
||||
hitinfo = HitInfo(hit_position_world_space, Vector3::Normalize(Matrix4::DotNoTranslate(getModelMatrix(), hitinfo_model_space.getNormal())), (hit_position_world_space - v0).magnitude(), this);
|
||||
return true;
|
||||
@@ -129,7 +130,7 @@ bool KRCollider::rayCast(const Vector3 &v0, const Vector3 &dir, HitInfo &hitinfo
|
||||
{
|
||||
if(layer_mask & m_layer_mask) { // Only test if layer masks have a common bit set
|
||||
loadModel();
|
||||
if(m_models.size()) {
|
||||
if(m_model) {
|
||||
if(getBounds().intersectsRay(v0, dir)) {
|
||||
Vector3 v0_model_space = Matrix4::Dot(getInverseModelMatrix(), v0);
|
||||
Vector3 dir_model_space = Vector3::Normalize(Matrix4::DotNoTranslate(getInverseModelMatrix(), dir));
|
||||
@@ -139,7 +140,7 @@ bool KRCollider::rayCast(const Vector3 &v0, const Vector3 &dir, HitInfo &hitinfo
|
||||
hitinfo_model_space = HitInfo(hit_position_model_space, Vector3::Normalize(Matrix4::DotNoTranslate(getInverseModelMatrix(), hitinfo.getNormal())), (hit_position_model_space - v0_model_space).magnitude(), hitinfo.getNode());
|
||||
}
|
||||
|
||||
if(m_models[0]->rayCast(v0_model_space, dir_model_space, hitinfo_model_space)) {
|
||||
if(m_model->rayCast(v0_model_space, dir_model_space, hitinfo_model_space)) {
|
||||
Vector3 hit_position_world_space = Matrix4::Dot(getModelMatrix(), hitinfo_model_space.getPosition());
|
||||
hitinfo = HitInfo(hit_position_world_space, Vector3::Normalize(Matrix4::DotNoTranslate(getModelMatrix(), hitinfo_model_space.getNormal())), (hit_position_world_space - v0).magnitude(), this);
|
||||
return true;
|
||||
@@ -154,14 +155,14 @@ bool KRCollider::sphereCast(const Vector3 &v0, const Vector3 &v1, float radius,
|
||||
{
|
||||
if(layer_mask & m_layer_mask) { // Only test if layer masks have a common bit set
|
||||
loadModel();
|
||||
if(m_models.size()) {
|
||||
if(m_model) {
|
||||
AABB sphereCastBounds = AABB::Create( // TODO - Need to cache this; perhaps encasulate within a "spherecast" class to be passed through these functions
|
||||
Vector3::Create(KRMIN(v0.x, v1.x) - radius, KRMIN(v0.y, v1.y) - radius, KRMIN(v0.z, v1.z) - radius),
|
||||
Vector3::Create(KRMAX(v0.x, v1.x) + radius, KRMAX(v0.y, v1.y) + radius, KRMAX(v0.z, v1.z) + radius)
|
||||
);
|
||||
|
||||
if(getBounds().intersects(sphereCastBounds)) {
|
||||
if(m_models[0]->sphereCast(getModelMatrix(), v0, v1, radius, hitinfo)) {
|
||||
if(m_model->sphereCast(getModelMatrix(), v0, v1, radius, hitinfo)) {
|
||||
hitinfo = HitInfo(hitinfo.getPosition(), hitinfo.getNormal(), hitinfo.getDistance(), this);
|
||||
return true;
|
||||
}
|
||||
@@ -200,7 +201,7 @@ void KRCollider::render(RenderInfo& ri)
|
||||
|
||||
if(ri.renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT && ri.camera->settings.debug_display == KRRenderSettings::KRENGINE_DEBUG_DISPLAY_COLLIDERS) {
|
||||
loadModel();
|
||||
if(m_models.size()) {
|
||||
if(m_model) {
|
||||
|
||||
GL_PUSH_GROUP_MARKER("Debug Overlays");
|
||||
|
||||
@@ -213,14 +214,14 @@ void KRCollider::render(RenderInfo& ri)
|
||||
info.spot_lights = &ri.spot_lights;
|
||||
info.renderPass = ri.renderPass;
|
||||
info.rasterMode = PipelineInfo::RasterMode::kAdditive;
|
||||
info.modelFormat = m_models[0]->getModelFormat();
|
||||
info.vertexAttributes = m_models[0]->getVertexAttributes();
|
||||
info.modelFormat = m_model->getModelFormat();
|
||||
info.vertexAttributes = m_model->getVertexAttributes();
|
||||
|
||||
KRPipeline *pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info);
|
||||
|
||||
pShader->bind(*ri.camera, ri.viewport, getModelMatrix(), &ri.point_lights, &ri.directional_lights, &ri.spot_lights, ri.renderPass, Vector3::Zero(), 0.0f, Vector4::Zero());
|
||||
|
||||
m_models[0]->renderNoMaterials(ri.commandBuffer, ri.renderPass, getName(), "visualize_overlay", 1.0f);
|
||||
m_model->renderNoMaterials(ri.commandBuffer, ri.renderPass, getName(), "visualize_overlay", 1.0f);
|
||||
|
||||
GL_POP_GROUP_MARKER;
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ public:
|
||||
void render(RenderInfo& ri);
|
||||
|
||||
private:
|
||||
std::vector<KRMesh *> m_models;
|
||||
KRMesh* m_model;
|
||||
std::string m_model_name;
|
||||
|
||||
unsigned int m_layer_mask;
|
||||
|
||||
@@ -343,8 +343,8 @@ void KRLight::render(RenderInfo& ri) {
|
||||
|
||||
if(ri.renderPass == KRNode::RENDER_PASS_PARTICLE_OCCLUSION) {
|
||||
if(m_flareTexture.size() && m_flareSize > 0.0f) {
|
||||
std::vector<KRMesh*> sphereModels = getContext().getMeshManager()->getModel("__sphere");
|
||||
if (sphereModels.size()) {
|
||||
KRMesh* sphereModel = getContext().getMeshManager()->getMaxLODModel("__sphere");
|
||||
if (sphereModel) {
|
||||
|
||||
Matrix4 occlusion_test_sphere_matrix = Matrix4();
|
||||
occlusion_test_sphere_matrix.scale(m_localScale * m_flareOcclusionSize);
|
||||
@@ -363,8 +363,8 @@ void KRLight::render(RenderInfo& ri) {
|
||||
info.renderPass = ri.renderPass;
|
||||
info.rasterMode = PipelineInfo::RasterMode::kAdditive;
|
||||
info.cullMode = PipelineInfo::CullMode::kCullNone;
|
||||
info.modelFormat = sphereModels[0]->getModelFormat();
|
||||
info.vertexAttributes = sphereModels[0]->getVertexAttributes();
|
||||
info.modelFormat = sphereModel->getModelFormat();
|
||||
info.vertexAttributes = sphereModel->getVertexAttributes();
|
||||
|
||||
KRPipeline* pPipeline = getContext().getPipelineManager()->getPipeline(*ri.surface, info);
|
||||
pPipeline->bind(*info.pCamera, ri.viewport, occlusion_test_sphere_matrix, info.point_lights, info.directional_lights, info.spot_lights, info.renderPass, Vector3::Zero(), 0.0f, Vector4::Zero());
|
||||
@@ -376,7 +376,7 @@ void KRLight::render(RenderInfo& ri) {
|
||||
GLDEBUG(glBeginQuery(GL_SAMPLES_PASSED, m_occlusionQuery));
|
||||
#endif
|
||||
|
||||
sphereModels[0]->renderNoMaterials(ri.commandBuffer, ri.renderPass, getName(), "occlusion_test", 1.0f);
|
||||
sphereModel->renderNoMaterials(ri.commandBuffer, ri.renderPass, getName(), "occlusion_test", 1.0f);
|
||||
|
||||
#if TARGET_OS_IPHONE || defined(ANDROID)
|
||||
GLDEBUG(glEndQueryEXT(GL_ANY_SAMPLES_PASSED_EXT));
|
||||
|
||||
@@ -151,6 +151,15 @@ void KRMeshManager::addModel(KRMesh *model) {
|
||||
m_models.insert(std::pair<std::string, KRMesh *>(lowerName, model));
|
||||
}
|
||||
|
||||
KRMesh* KRMeshManager::getMaxLODModel(const char* szName) {
|
||||
std::vector<KRMesh*> models = getModel(szName);
|
||||
// models are always in order of highest LOD first
|
||||
if (models.size()) {
|
||||
return models[0];
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::vector<KRMesh *> KRMeshManager::getModel(const char *szName) {
|
||||
std::string lowerName = szName;
|
||||
std::transform(lowerName.begin(), lowerName.end(),
|
||||
|
||||
@@ -59,6 +59,7 @@ public:
|
||||
|
||||
KRMesh *loadModel(const char *szName, KRDataBlock *pData);
|
||||
std::vector<KRMesh *> getModel(const char *szName);
|
||||
KRMesh* KRMeshManager::getMaxLODModel(const char* szName);
|
||||
void addModel(KRMesh *model);
|
||||
|
||||
std::vector<std::string> getModelNames();
|
||||
|
||||
@@ -126,8 +126,8 @@ void KRReverbZone::render(RenderInfo& ri)
|
||||
bool bVisualize = ri.camera->settings.debug_display == KRRenderSettings::KRENGINE_DEBUG_DISPLAY_SIREN_REVERB_ZONES;
|
||||
|
||||
if(ri.renderPass == KRNode::RENDER_PASS_FORWARD_TRANSPARENT && bVisualize) {
|
||||
std::vector<KRMesh*> sphereModels = getContext().getMeshManager()->getModel("__sphere");
|
||||
if (sphereModels.size()) {
|
||||
KRMesh* sphereModel = getContext().getMeshManager()->getMaxLODModel("__sphere");
|
||||
if (sphereModel) {
|
||||
Matrix4 sphereModelMatrix = getModelMatrix();
|
||||
PipelineInfo info{};
|
||||
std::string shader_name("visualize_overlay");
|
||||
@@ -138,15 +138,15 @@ void KRReverbZone::render(RenderInfo& ri)
|
||||
info.spot_lights = &ri.spot_lights;
|
||||
info.renderPass = ri.renderPass;
|
||||
info.rasterMode = PipelineInfo::RasterMode::kAlphaBlend;
|
||||
info.modelFormat = sphereModels[0]->getModelFormat();
|
||||
info.vertexAttributes = sphereModels[0]->getVertexAttributes();
|
||||
info.modelFormat = sphereModel->getModelFormat();
|
||||
info.vertexAttributes = sphereModel->getVertexAttributes();
|
||||
|
||||
KRPipeline *pShader = getContext().getPipelineManager()->getPipeline(*ri.surface, info);
|
||||
|
||||
pShader->bind(*ri.camera, ri.viewport, sphereModelMatrix, &ri.point_lights, &ri.directional_lights, &ri.spot_lights, ri.renderPass, Vector3::Zero(), 0.0f, Vector4::Zero());
|
||||
|
||||
sphereModels[0]->renderNoMaterials(ri.commandBuffer, ri.renderPass, getName(), "visualize_overlay", 1.0f);
|
||||
} // sphereModels.size()
|
||||
sphereModel->renderNoMaterials(ri.commandBuffer, ri.renderPass, getName(), "visualize_overlay", 1.0f);
|
||||
} // sphereModel
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user