From 4fbf2f296c0dc5f6e82d459e922b25a1a71900ed Mon Sep 17 00:00:00 2001 From: Peder Bergebakken Sundt Date: Tue, 19 Mar 2019 20:25:23 +0100 Subject: [PATCH] Move implementation of function from scenenode hpp file to cpp file --- src/sceneGraph.cpp | 74 ++++++++++++++++++++++++++++++++++++++++++++++ src/sceneGraph.hpp | 70 +++---------------------------------------- 2 files changed, 78 insertions(+), 66 deletions(-) diff --git a/src/sceneGraph.cpp b/src/sceneGraph.cpp index dad2ac6..822c874 100644 --- a/src/sceneGraph.cpp +++ b/src/sceneGraph.cpp @@ -1,6 +1,80 @@ #include "sceneGraph.hpp" #include +SceneNode::SceneNode(SceneNodeType type = GEOMETRY) { + nodeType = type; +} + +void SceneNode::setMesh(const Mesh* mesh) { + static map cache; + + if (cache.find(mesh) == cache.end()) + cache[mesh] = generateBuffer(*mesh, isNormalMapped || isDisplacementMapped); + + vertexArrayObjectID = cache[mesh]; + VAOIndexCount = mesh->indices.size(); + isVertexColored = ! mesh->colors.empty(); +} +void SceneNode::setTexture( + const PNGImage* diffuse, + const PNGImage* normal=nullptr, + const PNGImage* displacement=nullptr, + const PNGImage* reflection=nullptr, + bool texture_reset=true) { + static map cache; + if (texture_reset){ + isTextured = false; + isNormalMapped = false; + isDisplacementMapped = false; + isReflectionMapped = false; + } + + if (diffuse) { + if (cache.find(diffuse) == cache.end()) + cache[diffuse] = generateTexture(*diffuse); + diffuseTextureID = cache[diffuse]; + isTextured = true; + } + + if (normal) { + if (cache.find(normal) == cache.end()) + cache[normal] = generateTexture(*normal); + normalTextureID = cache[normal]; + isNormalMapped = true; + } + + if (displacement) { + if (cache.find(displacement) == cache.end()) + cache[displacement] = generateTexture(*displacement); + displacementTextureID = cache[displacement]; + isDisplacementMapped = true; + } + + if (reflection) { + if (cache.find(reflection) == cache.end()) + cache[reflection] = generateTexture(*reflection); + reflectionTextureID = cache[reflection]; + isReflectionMapped = true; + } +} +void SceneNode::setMaterial(const Material& mat, bool recursive=false) { + reflexiveness = mat.reflexiveness; + if (!mat.ignore_diffuse) diffuse_color = mat.diffuse_color; + if (!mat.ignore_emissive) emissive_color = mat.emissive_color; + if (!mat.ignore_specular) specular_color = mat.specular_color; + if (!mat.ignore_specular) shininess = mat.shininess; + setTexture( + mat.diffuse_texture, + mat.normal_texture, + mat.displacement_texture, + mat.reflection_texture, + mat.texture_reset + ); + if (recursive) for (SceneNode* child : children) + child->setMaterial(mat, true); +} + + SceneNode* createSceneNode() { return new SceneNode(); } diff --git a/src/sceneGraph.hpp b/src/sceneGraph.hpp index 769cb00..ded089f 100644 --- a/src/sceneGraph.hpp +++ b/src/sceneGraph.hpp @@ -32,78 +32,16 @@ enum SceneNodeType { }; struct SceneNode { - SceneNode(SceneNodeType type = GEOMETRY) { - nodeType = type; - } + SceneNode(SceneNodeType type = GEOMETRY); - void setMesh(const Mesh* mesh) { - static map cache; - - if (cache.find(mesh) == cache.end()) - cache[mesh] = generateBuffer(*mesh, isNormalMapped || isDisplacementMapped); - - vertexArrayObjectID = cache[mesh]; - VAOIndexCount = mesh->indices.size(); - isVertexColored = ! mesh->colors.empty(); - } + void setMesh(const Mesh* mesh); void setTexture( const PNGImage* diffuse, const PNGImage* normal=nullptr, const PNGImage* displacement=nullptr, const PNGImage* reflection=nullptr, - bool texture_reset=true) { - static map cache; - if (texture_reset){ - isTextured = false; - isNormalMapped = false; - isDisplacementMapped = false; - isReflectionMapped = false; - } - - if (diffuse) { - if (cache.find(diffuse) == cache.end()) - cache[diffuse] = generateTexture(*diffuse); - diffuseTextureID = cache[diffuse]; - isTextured = true; - } - - if (normal) { - if (cache.find(normal) == cache.end()) - cache[normal] = generateTexture(*normal); - normalTextureID = cache[normal]; - isNormalMapped = true; - } - - if (displacement) { - if (cache.find(displacement) == cache.end()) - cache[displacement] = generateTexture(*displacement); - displacementTextureID = cache[displacement]; - isDisplacementMapped = true; - } - - if (reflection) { - if (cache.find(reflection) == cache.end()) - cache[reflection] = generateTexture(*reflection); - reflectionTextureID = cache[reflection]; - isReflectionMapped = true; - } - } - void setMaterial(const Material& mat, bool recursive=false) { - reflexiveness = mat.reflexiveness; - if (!mat.ignore_diffuse) diffuse_color = mat.diffuse_color; - if (!mat.ignore_emissive) emissive_color = mat.emissive_color; - if (!mat.ignore_specular) specular_color = mat.specular_color; - if (!mat.ignore_specular) shininess = mat.shininess; - setTexture( - mat.diffuse_texture, - mat.normal_texture, - mat.displacement_texture, - mat.reflection_texture, - mat.texture_reset - ); - if (recursive) for (SceneNode* child : children) - child->setMaterial(mat, true); - } + bool texture_reset=true); + void setMaterial(const Material& mat, bool recursive=false); // this node SceneNodeType nodeType;