Fix transparancy check for nodes

The previous method tried to read from meshes which had been freed from memory
This commit is contained in:
Peder Bergebakken Sundt 2019-03-22 18:01:42 +01:00
parent b4e66809cb
commit 84cbd5e5c7
3 changed files with 13 additions and 10 deletions

View File

@ -14,7 +14,7 @@ void SceneNode::setMesh(const Mesh* mesh) {
vertexArrayObjectID = cache[mesh];
VAOIndexCount = mesh->indices.size();
isVertexColored = ! mesh->colors.empty();
m_gemoetry = mesh;
mesh_has_transparancy = mesh->has_transparancy;
}
void SceneNode::setTexture(
const PNGImage* diffuse,
@ -28,7 +28,7 @@ void SceneNode::setTexture(
isNormalMapped = false;
isDisplacementMapped = false;
isReflectionMapped = false;
t_diffuse = nullptr;
tex_has_transparancy = false;
}
if (diffuse) {
@ -36,7 +36,7 @@ void SceneNode::setTexture(
cache[diffuse] = generateTexture(*diffuse);
diffuseTextureID = cache[diffuse];
isTextured = true;
t_diffuse = diffuse;
tex_has_transparancy = diffuse->has_transparancy;
}
if (normal) {
@ -84,9 +84,9 @@ bool SceneNode::has_no_transforms() const {
}
bool SceneNode::has_transparancy() const {
return opacity < 1.0
|| t_diffuse && t_diffuse->has_transparancy
|| m_gemoetry && m_gemoetry->has_transparancy;
return mesh_has_transparancy
|| tex_has_transparancy
|| opacity < 0.98;
}
SceneNode* SceneNode::clone() const {

View File

@ -82,9 +82,9 @@ struct SceneNode {
float displacementCoefficient = 0.1; // in units
uint reflectionTextureID;
// has_transparancy
const Mesh* m_gemoetry = nullptr;
const PNGImage* t_diffuse = nullptr;
// has_transparancy check
bool mesh_has_transparancy = false;
bool tex_has_transparancy = false;
// shader flags
bool isTextured = false;

View File

@ -176,6 +176,7 @@ SceneNode* loadModelScene(const std::string& dirname, const std::string& filenam
});
}
mesh.has_transparancy = false;
if (aimesh->GetNumColorChannels() >= 1)
for (uint i=0; i < aimesh->mNumVertices; i++){
mesh.colors.push_back({
@ -184,6 +185,8 @@ SceneNode* loadModelScene(const std::string& dirname, const std::string& filenam
aimesh->mColors[0][i].b,
aimesh->mColors[0][i].a,
});
if (aimesh->mColors[0][i].a < 255)
mesh.has_transparancy = true;
}
for (uint i=0; i < aimesh->mNumFaces; i++){