Removed ContainerNode and LightNode

This commit is contained in:
Anselme 2018-01-30 17:44:34 +01:00
parent bed507b501
commit 0015acb84c
32 changed files with 289 additions and 334 deletions

View File

@ -23,12 +23,12 @@ Editor::Editor() :
m_selectedMesh(nullptr),
m_editedResourcePack(nullptr),
m_objectEditor(nullptr),
m_pickerEnabled(false),
m_materialEditorEnabled(false),
m_editorEnabled(false)
{
m_objectEditor = new ObjectEditor();
m_children.push_back(m_pickerNode);
addChild(m_pickerNode);
m_pickerNode->setEnabled(false);
m_pickerNode->setVisible(false);
}
@ -39,15 +39,11 @@ Editor::~Editor()
void Editor::update()
{
// no automatic update of children, we want to update them manually
// ContainerNode::update();
SceneNode::update();
if(m_editorEnabled)
gui();
if(m_pickerEnabled)
m_pickerNode->update();
if(m_materialEditorEnabled)
materialGui();
@ -68,7 +64,7 @@ void Editor::gui()
{
ImGui::MenuItem("Material editor", NULL, &m_materialEditorEnabled);
DeferredPipeline* pipeline = dynamic_cast<DeferredPipeline*>(m_scene->getPipeline());
DeferredPipeline* pipeline = dynamic_cast<DeferredPipeline*>(getScene()->getPipeline());
bool pipeline_gui_status = pipeline->isDebugGuiVisible();
if(ImGui::MenuItem("Rendering pipeline debug gui", NULL, &pipeline_gui_status))
pipeline->toggleDebugGui();
@ -77,7 +73,7 @@ void Editor::gui()
if(ImGui::MenuItem("Resource pack editor editor", NULL, &resroucePackEditorStatus))
toggleResourcePackGui();
bool pickerStatus = m_pickerEnabled;
bool pickerStatus = m_pickerNode->isEnabled();
if(ImGui::MenuItem("Picker", NULL, &pickerStatus))
togglePicker();
@ -97,7 +93,7 @@ void Editor::materialGui()
options += "None\n";
meshes.push_back(nullptr);
int i = 1;
for(SceneIterator<GeometryNode*>* geometryIt = m_scene->getGeometry(); geometryIt->isValid(); geometryIt->next())
for(SceneIterator<GeometryNode*>* geometryIt = getScene()->getGeometry(); geometryIt->isValid(); geometryIt->next())
{
options += geometryIt->getItem()->mesh->getName();
options += '\n';
@ -170,8 +166,9 @@ void Editor::toggleEditor()
void Editor::togglePicker()
{
m_pickerEnabled = !m_pickerEnabled;
m_pickerNode->setVisible(m_pickerEnabled);
bool pickerEnabled = m_pickerNode->isEnabled();
m_pickerNode->setEnabled(!pickerEnabled);
m_pickerNode->setVisible(!pickerEnabled);
}
void Editor::toggleMaterialEditor()
@ -181,7 +178,7 @@ void Editor::toggleMaterialEditor()
void Editor::toggleRenderingPipelineGui()
{
DeferredPipeline* pipeline = dynamic_cast<DeferredPipeline*>(m_scene->getPipeline());
DeferredPipeline* pipeline = dynamic_cast<DeferredPipeline*>(getScene()->getPipeline());
pipeline->toggleDebugGui();
}

View File

@ -1,7 +1,7 @@
#ifndef EDITOR_H
#define EDITOR_H
#include "scene/containernode.h"
#include "scene/scenenode.h"
class Engine;
class ScenePicker;
@ -9,13 +9,12 @@ class ResourcePack;
class ObjectEditor;
class Mesh;
class Editor : public ContainerNode
class Editor : public SceneNode
{
ScenePicker* m_pickerNode;
Mesh* m_selectedMesh;
ResourcePack* m_editedResourcePack;
ObjectEditor* m_objectEditor;
bool m_pickerEnabled;
bool m_materialEditorEnabled;
bool m_editorEnabled;

View File

@ -198,7 +198,7 @@ void Engine::enablePhysicsDebug()
{
m_physicsDebugNode = new PhysicsDebugNode();
getScene()->addToIndex(m_physicsDebugNode);
getScene()->registerMeshType(m_physicsDebugNode->getGeometryNode()->mesh->getFlags());
getScene()->registerMeshType(m_physicsDebugNode->getMesh()->getFlags());
getScene()->getPhysics()->setDebugDrawer(m_physicsDebugNode);
getScene()->getPhysics()->getDebugDrawer()->setDebugMode(btIDebugDraw::DBG_DrawWireframe);
}

View File

@ -1,12 +1,12 @@
#ifndef KEYMAPPER_H
#define KEYMAPPER_H
#include "scene/containernode.h"
#include "scene/scenenode.h"
#include "SparrowInput/keybindings.h"
#include <map>
#include <set>
class KeyMapper : public ContainerNode
class KeyMapper : public SceneNode
{
bool m_enabled;
int m_selected_context;

View File

@ -1,73 +0,0 @@
#include "containernode.h"
#include "scenetree.h"
ContainerNode::~ContainerNode()
{
setSceneTree(nullptr);
for(SceneNode* child : m_children)
delete child;
}
void ContainerNode::update()
{
for(SceneNode* node : m_nodesToRemove)
{
for(auto it = m_children.begin(); it != m_children.end();)
{
if(*it == node)
{
it = m_children.erase(it);
node->setSceneTree(nullptr);
node->setParent(nullptr);
}
else
++it;
}
}
m_nodesToRemove.clear();
for(SceneNode* node : m_nodesToAdd)
{
if(m_scene != nullptr)
node->setSceneTree(m_scene);
m_children.push_back(node);
node->setParent(this);
node->setParentTransform(m_transform);
node->setParentVisible(isVisible());
}
m_nodesToAdd.clear();
if(m_transformChanged)
m_combinedTransform = m_transform * m_parentTransform;
for(SceneNode* child : m_children)
{
if(m_transformChanged)
child->setParentTransform(m_combinedTransform);
child->update();
}
}
void ContainerNode::setSceneTree(SceneTree* tree)
{
SceneNode::setSceneTree(tree);
for(SceneNode* child : m_children)
child->setSceneTree(tree);
}
void ContainerNode::addChild(SceneNode *node)
{
if(node != nullptr)
m_nodesToAdd.push_back(node);
}
void ContainerNode::removeChild(SceneNode *node)
{
if(node != nullptr)
m_nodesToRemove.push_back(node);
}
void ContainerNode::updateVisibility(bool visible)
{
for(SceneNode* child : m_children)
child->setParentVisible(visible);
}

View File

@ -1,31 +0,0 @@
#ifndef CONTAINERNODE_H
#define CONTAINERNODE_H
#include "scenenode.h"
#include "glm/vec2.hpp"
#include "glm/mat4x4.hpp"
#include <vector>
class ContainerNode : public SceneNode
{
std::vector<SceneNode*> m_nodesToRemove;
std::vector<SceneNode*> m_nodesToAdd;
protected:
std::vector<SceneNode*> m_children;
glm::mat4 m_combinedTransform;
public:
virtual ~ContainerNode();
virtual void update();
virtual void setSceneTree(SceneTree* tree);
virtual void updateVisibility(bool visible);
void addChild(SceneNode* node);
void removeChild(SceneNode* node);
};
#endif // CONTAINERNODE_H

View File

@ -11,7 +11,7 @@ void GibGeneratorNode::createGib(SceneNode* graphicalPart,
const glm::vec3 &velocity,
unsigned int lifeSpan)
{
if(m_scene != nullptr)
if(getScene() != nullptr)
{
graphicalPart->moveTo(pos);
@ -23,7 +23,7 @@ void GibGeneratorNode::createGib(SceneNode* graphicalPart,
body->setLinearVelocity(btVector3(velocity.x, velocity.y, velocity.z));
body->setUserPointer(graphicalPart);
getEngine().getScene()->getPhysics()->addRigidBody(body);
getScene()->getPhysics()->addRigidBody(body);
m_gibs.push_back(new Gib(body, graphicalPart, getEngine().getTime()+lifeSpan));
addChild(graphicalPart);
@ -38,7 +38,7 @@ void GibGeneratorNode::update()
Gib *g = *it;
if(g->expiration < getEngine().getTime())
{
getEngine().getScene()->getPhysics()->removeCollisionObject(g->body);
getScene()->getPhysics()->removeCollisionObject(g->body);
g->graphics->destroyWhenOrphan();
removeChild(g->graphics);
it = m_gibs.erase(it);
@ -48,5 +48,5 @@ void GibGeneratorNode::update()
++it;
}
ContainerNode::update();
SceneNode::update();
}

View File

@ -1,7 +1,7 @@
#ifndef GIBGENERATORNODE_H
#define GIBGENERATORNODE_H
#include "containernode.h"
#include "scenenode.h"
#include <glm/vec3.hpp>
#include <BulletDynamics/Dynamics/btRigidBody.h>
@ -9,7 +9,7 @@ class btCollisionShape;
class btRigidBody;
class SceneNode;
class GibGeneratorNode : public ContainerNode
class GibGeneratorNode : public SceneNode
{
struct Gib
{

View File

@ -25,18 +25,18 @@ BackGroundNode::BackGroundNode(glm::vec2 dimension, glm::vec3 color, float opaci
mesh->setDepth(depth);
mesh->initGL();
m_mesh = new SceneNode();
m_mesh->getGeometryNode()->mesh = mesh;
m_mesh->setMesh(mesh);
addChild(m_mesh);
}
void BackGroundNode::update(){
if(m_color_updated){
PBRMaterial* mat = (PBRMaterial*) m_mesh->getGeometryNode()->mesh->getMaterial();
PBRMaterial* mat = (PBRMaterial*) m_mesh->getMesh()->getMaterial();
mat->albedo = m_color;
m_color_updated = false;
}
if(m_opacity_updated){
PBRMaterial* mat = (PBRMaterial*) m_mesh->getGeometryNode()->mesh->getMaterial();
PBRMaterial* mat = (PBRMaterial*) m_mesh->getMesh()->getMaterial();
mat->opacity = m_opacity;
m_opacity_updated = false;
}

View File

@ -10,9 +10,9 @@ void GUINode::setPosition(glm::vec2 position){
}
glm::vec2 GUINode::getPosition(){
return glm::vec2(m_transform[3].x,m_transform[3].y);
return glm::vec2(getTransform()[3].x, getTransform()[3].y);
}
void GUINode::update(){
ContainerNode::update();
SceneNode::update();
}

View File

@ -1,9 +1,9 @@
#ifndef GUINODE_H
#define GUINODE_H
#include "scene/containernode.h"
#include "scene/scenenode.h"
class GUINode : public ContainerNode
class GUINode : public SceneNode
{
public:
GUINode();

View File

@ -57,7 +57,7 @@ void LabelNode::update(){
Font* font = RESOURCE_GET(Font,"shellfont");
m_text = font->getTextNode(m_string,m_color,32);
m_text->setDepth(LABEL_TEXT_DEPTH);
m_text->getGeometryNode()->mesh->setName("labelText");
m_text->getMesh()->setName("labelText");
addChild(m_text);
m_string_updated= false;
m_color_updated=false;
@ -65,7 +65,7 @@ void LabelNode::update(){
}
if(m_color_updated){
if(m_text){
PBRMaterial* mat = (PBRMaterial*) m_text->m_geometry.mesh->getMaterial();
PBRMaterial* mat = (PBRMaterial*) m_text->getMesh()->getMaterial();
mat->albedo = m_color;
m_color_updated = false;
}

View File

@ -27,7 +27,7 @@ ScrollBarNode::ScrollBarNode(glm::vec2 dimension, glm::vec3 bar_color):
mesh->setDepth(SparrowShell::SHELL_DEPTH+1);
mesh->initGL();
m_bar = new SceneNode();
m_bar->getGeometryNode()->mesh = mesh;
m_bar->setMesh(mesh);
addChild(m_bar);
}
@ -62,7 +62,7 @@ void ScrollBarNode::update()
}
if(m_bar_color_updated)
{
PBRMaterial* mat = (PBRMaterial*) m_bar->getGeometryNode()->mesh->getMaterial();
PBRMaterial* mat = (PBRMaterial*) m_bar->getMesh()->getMaterial();
mat->albedo = m_bar_color;
m_bar_color_updated = false;
}

View File

@ -34,7 +34,7 @@ TextInputNode::TextInputNode(glm::vec2 dimension):
mesh->setDepth(30);
mesh->initGL();
m_cursor_mesh = new SceneNode(false);
m_cursor_mesh->getGeometryNode()->mesh = mesh;
m_cursor_mesh->setMesh(mesh);
addChild(m_cursor_mesh);
}

View File

@ -1,46 +0,0 @@
#include "lightnode.h"
#include "scenetree.h"
#include <SparrowRenderer/light.h>
#include <glm/mat3x3.hpp>
void LightNode::setSceneTree(SceneTree *tree)
{
SceneNode::setSceneTree(tree);
if(m_scene != nullptr)
m_scene->registerLightType(m_light->getFlags());
}
void LightNode::update()
{
if(m_transformChanged)
{
glm::mat4 combinedTransform(m_parentTransform * m_transform);
switch(m_light->getType())
{
case Light::DIRECTIONNAL :
{
DirectionnalLight *l = (DirectionnalLight*)m_light;
l->setDir(glm::mat3(combinedTransform) * l->getDir());
if(l->isShadowCaster())
l->updateShadowMap(m_scene);
}
break;
case Light::POINT :
{
PointLight *l = (PointLight*)m_light;
l->setPos(l->getPos() + glm::vec3(combinedTransform[3]));
}
break;
case Light::SPOT :
// TODO
break;
case Light::AMBIENT :
default:
break;
}
}
}

View File

@ -1,21 +0,0 @@
#ifndef LIGHTNODE_H
#define LIGHTNODE_H
#include "scenenode.h"
#include "glm/mat4x4.hpp"
#include "SparrowRenderer/scene.h"
class LightNode : public SceneNode
{
Light *m_light;
public:
LightNode(Light* light) : m_light(light) {}
virtual void setSceneTree(SceneTree* tree);
virtual void update();
virtual Light* getLight() { return m_light; }
};
#endif // LIGHTNODE_H

View File

@ -6,39 +6,40 @@
PhysicsDebugNode::PhysicsDebugNode()
{
m_geometry.mesh = new Mesh();
m_geometry.mesh->setMaterial(new PBRMaterial());
m_geometry.mesh->setPrimitiveType(GL_LINES);
m_geometry.mesh->setWireframe(true);
Mesh* mesh = new Mesh();
setMesh(mesh);
mesh->setMaterial(new PBRMaterial());
mesh->setPrimitiveType(GL_LINES);
mesh->setWireframe(true);
glm::vec3 pos1(0, 1, 0);
glm::vec3 pos2(0, 0, 0);
glm::vec3 color(1, 0, 0);
m_geometry.mesh->addVertex(pos1, color);
m_geometry.mesh->addVertex(pos2, color);
m_geometry.mesh->updateFlags();
mesh->addVertex(pos1, color);
mesh->addVertex(pos2, color);
mesh->updateFlags();
}
PhysicsDebugNode::~PhysicsDebugNode()
{
delete m_geometry.mesh;
delete getMesh();
}
void PhysicsDebugNode::drawLine(const btVector3& from, const btVector3& to, const btVector3& color)
{
glm::vec3 glColor(color.x(), color.y(), color.z());
m_geometry.mesh->addVertex(glm::vec3(from.x(), from.y(), from.z()), glColor);
m_geometry.mesh->addVertex(glm::vec3(to.x(), to.y(), to.z()), glColor);
getMesh()->addVertex(glm::vec3(from.x(), from.y(), from.z()), glColor);
getMesh()->addVertex(glm::vec3(to.x(), to.y(), to.z()), glColor);
}
void PhysicsDebugNode::flushLines()
{
// a little heavy, but it's a debug mode so it shouldn't be a problem
m_geometry.mesh->initGL();
getMesh()->initGL();
}
void PhysicsDebugNode::clearBuffers()
{
m_geometry.mesh->m_positions3D.clear();
m_geometry.mesh->m_normals.clear();
getMesh()->m_positions3D.clear();
getMesh()->m_normals.clear();
}

View File

@ -27,7 +27,7 @@ public:
virtual void setDebugMode(int debugMode) { m_debugMode = debugMode; }
virtual int getDebugMode() const { return m_debugMode; }
unsigned int getFlags() { m_geometry.mesh->getFlags(); }
unsigned int getFlags() { getMesh()->getFlags(); }
void clearBuffers();
};

View File

@ -9,7 +9,6 @@
#include "scene/physicsdebugnode.h"
#include "scenetree.h"
#include "lightnode.h"
#include <SFML/System.hpp>
#include <SFML/Audio.hpp>
@ -309,9 +308,3 @@ void PlayerCharacterNode::toggleNoClip()
m_noclipMode = !m_noclipMode;
m_noclip_pos = m_rigidBody->getCenterOfMassPosition();
}
void PlayerCharacterNode::setSceneTree(SceneTree* tree)
{
m_scene = tree;
// m_playerLightNode->setSceneTree(tree);
}

View File

@ -69,8 +69,6 @@ public:
btRigidBody* getRigidbody() { return m_rigidBody; }
virtual Camera *getCamera() { return &m_fpsCamera; }
virtual void setSceneTree(SceneTree* tree);
};
#endif // PLAYERCHARACTERNODE_H

View File

@ -22,21 +22,102 @@ void SceneNode::setParent(SceneNode* parent)
SceneNode::SceneNode(bool visible) :
m_toDestroy(false),
m_parentVisible(true),
m_visible(visible),
m_enabled(true),
m_transformChanged(true),
m_parent(nullptr),
m_scene(nullptr),
m_geometry(nullptr, glm::mat4()),
m_transform(m_geometry.modelMatrix),
m_light(nullptr),
m_transform(glm::mat4()),
m_rigidBody(nullptr),
m_parentVisible(true),
m_visible(visible),
m_transformChanged(true),
m_motionState(this)
{}
SceneNode::~SceneNode()
{
setVisible(false);
setSceneTree(nullptr);
for(SceneNode* child : m_children)
delete child;
}
void SceneNode::updateLightSource()
{
switch(m_light->getType())
{
case Light::DIRECTIONNAL :
{
DirectionnalLight *l = (DirectionnalLight*)m_light;
l->setDir(glm::mat3(m_geometry.modelMatrix) * l->getDir());
if(l->isShadowCaster())
l->updateShadowMap(getScene());
}
break;
case Light::POINT :
{
PointLight *l = (PointLight*)m_light;
l->setPos(l->getPos() + glm::vec3(m_geometry.modelMatrix[3]));
}
break;
case Light::SPOT :
// TODO
break;
case Light::AMBIENT :
default:
break;
}
}
void SceneNode::update()
{
if(m_transformChanged)
m_geometry.modelMatrix = m_parentTransform * m_transform;
for(SceneNode* node : m_nodesToRemove)
{
for(auto it = m_children.begin(); it != m_children.end();)
{
if(*it == node)
{
it = m_children.erase(it);
node->setSceneTree(nullptr);
node->setParent(nullptr);
}
else
++it;
}
}
m_nodesToRemove.clear();
for(SceneNode* node : m_nodesToAdd)
{
if(m_scene != nullptr)
node->setSceneTree(m_scene);
m_children.push_back(node);
node->setParent(this);
node->setParentTransform(m_transform);
node->setParentVisible(isVisible());
}
m_nodesToAdd.clear();
if(m_enabled)
{
if(m_transformChanged)
{
m_geometry.modelMatrix = m_parentTransform * m_transform;
if(m_light != nullptr)
updateLightSource();
}
// TODO : add script execution here
for(SceneNode* child : m_children)
{
if(m_transformChanged)
child->setParentTransform(m_geometry.modelMatrix);
child->update();
}
}
}
void SceneNode::setSceneTree(SceneTree *tree)
@ -51,6 +132,10 @@ void SceneNode::setSceneTree(SceneTree *tree)
m_scene = tree;
if(m_scene != nullptr && m_geometry.mesh != nullptr)
m_scene->registerMeshType(m_geometry.mesh->getFlags());
if(m_scene != nullptr && m_light != nullptr)
m_scene->registerLightType(m_light->getFlags());
for(SceneNode* child : m_children)
child->setSceneTree(tree);
}
void SceneNode::resetTransform()
@ -138,14 +223,29 @@ void SceneNode::setParentVisible(bool visible)
m_parentVisible = visible;
}
void SceneNode::addChild(SceneNode *node)
{
if(node != nullptr)
m_nodesToAdd.push_back(node);
}
void SceneNode::removeChild(SceneNode *node)
{
if(node != nullptr)
m_nodesToRemove.push_back(node);
}
void SceneNode::updateVisibility(bool visible)
{
if(!m_scene)
return;
if(visible)
m_scene->addToIndex(this);
else
m_scene->removeFromIndex(this);
for(SceneNode* child : m_children)
child->setParentVisible(visible);
if(m_scene != nullptr)
{
if(visible)
m_scene->addToIndex(this);
else
m_scene->removeFromIndex(this);
}
}
void SceneNode::SparrowMotionState::getWorldTransform(btTransform& worldTrans ) const

View File

@ -14,9 +14,6 @@ class btRigidBody;
class SceneNode
{
private:
bool m_toDestroy;
public:
class SparrowMotionState : public btMotionState
{
@ -32,55 +29,82 @@ public:
virtual void setWorldTransform(const btTransform& worldTrans);
};
protected:
SceneNode* m_parent;
SceneTree* m_scene;
private:
bool m_toDestroy;
/// contains the mesh if this node has one
GeometryNode m_geometry;
/// m_parentTransform is the base transform for this element
glm::mat4 m_parentTransform;
/// m_transform is the relative transformation matrix of this node
glm::mat4 m_transform;
/// bullet physics rigidbody
btRigidBody *m_rigidBody;
std::vector<SceneNode*> m_nodesToRemove;
std::vector<SceneNode*> m_nodesToAdd;
bool m_parentVisible;
bool m_visible;
bool m_enabled;
bool m_transformChanged;
SceneNode* m_parent;
SceneTree* m_scene;
// contains the mesh if this node has one
GeometryNode m_geometry;
// contains the light source if the node has one
Light* m_light;
// m_transform is the relative transformation matrix of this node
glm::mat4 m_transform;
// m_parentTransform is the base transform for this element
glm::mat4 m_parentTransform;
// bullet physics rigidbody
btRigidBody *m_rigidBody;
// bullet physics handle for our transformation matrix
SparrowMotionState m_motionState;
virtual void updateVisibility(bool visible);
// node's children
std::vector<SceneNode*> m_children;
Engine& getEngine();
void updateVisibility(bool visible);
void setParent(SceneNode* parent);
void updateLightSource();
public:
// constructor/destructor
SceneNode(bool visible = true);
virtual ~SceneNode() { setVisible(false); }
virtual ~SceneNode();
// game logic methods
/// @brief update this method is called every tick
/// @brief update this method is called every tick by the engine
virtual void update();
// methods called by the renderer
virtual Light* getLight() { return nullptr; }
virtual GeometryNode* getGeometryNode() { return &m_geometry; }
bool isEnabled() { return m_enabled; }
void setEnabled(bool isEnabled) { m_enabled = isEnabled; }
// methods called to access the graphic propeties of the node
void setMesh(Mesh* mesh) { m_geometry.mesh = mesh; }
Mesh* getMesh() { return m_geometry.mesh; }
GeometryNode* getGeometryNode() { return &m_geometry; }
void setLight(Light* light) { m_light = light; }
Light* getLight() { return m_light; }
// scene tree structure methods
/// @brief setSceneTree this method can be used to change the scene of the node
virtual void setSceneTree(SceneTree* tree);
/// @brief setParent this method can be used to modify the scene tree
virtual void setParent(SceneNode *parent);
/// @brief getScene this method returns the scene this node is in
SceneTree* getScene() { return m_scene; }
/// @brief addChild this method can be used to add a child to a node
void addChild(SceneNode* node);
/// @brief removeChild this method can be used to remove a child from a node
void removeChild(SceneNode* node);
/// @brief getParent returns the parent of this node, or nullptr if this node is the scene tree root
virtual SceneNode* getParent() { return m_parent; }
/// @brief killWhenOrphan this method can be called if you wish to delete this object as soon as it has no parent.
virtual void destroyWhenOrphan() { m_toDestroy = true; }
/// @brief getChildren returns a vector containing all this node's children
const std::vector<SceneNode*> getChildren() { return m_children; }
// transform methods
void setTransform(const Transform& t);
@ -114,12 +138,14 @@ public:
void setDepth(float depth);
// physics methods
/// @brief getMotionState this is used to synchronize a bullet rigidbody's transform with a GraphicalNode transform
SparrowMotionState* getMotionState() { return &m_motionState; }
/// @brief setRigidBody sets a rigidbody to the node
void setRigidBody(btRigidBody* body);
btRigidBody* getRigidBody() { return m_rigidBody; }
// global engine methods
Engine& getEngine();
};
#endif // SCENENODE_H

View File

@ -5,7 +5,7 @@
#include <string>
#include <unordered_set>
#include "SparrowRenderer/scene.h"
#include "containernode.h"
#include "scenenode.h"
#include "engine.h"
class Light;
@ -32,7 +32,7 @@ public:
void setMainCamera(Camera *camera);
Camera* getCamera() const { return m_camera; }
ContainerNode* getRootObject(){return &m_root;}
SceneNode* getRootObject(){return &m_root;}
btDiscreteDynamicsWorld* getPhysics() const {return m_world;}
void initPhysics();
void registerMeshType(unsigned int meshType);
@ -50,7 +50,7 @@ private:
SceneTree(Engine &engine);
Engine &m_engine;
ContainerNode m_root;
SceneNode m_root;
btDiscreteDynamicsWorld* m_world;
std::vector<Light*> m_lights;
std::vector<GeometryNode*> m_geometries;

View File

@ -17,12 +17,12 @@ private:
friend class LabelNode;
public:
TextNode(Mesh* mesh,std::wstring s,float fontSize,bool visible = true) : SceneNode(visible),m_string(s),m_fontSize(fontSize) { m_geometry.mesh = mesh; }
TextNode(Mesh* mesh,std::wstring s,float fontSize,bool visible = true) : SceneNode(visible),m_string(s),m_fontSize(fontSize) { setMesh(mesh); }
TextNode(Mesh* mesh,std::string s,float fontSize,bool visible = true) : SceneNode(visible),m_fontSize(fontSize) {
m_geometry.mesh = mesh;
setMesh(mesh);
m_string.assign(s.begin(),s.end());
}
~TextNode(){delete m_geometry.mesh;}
~TextNode(){delete getMesh();}
void setDimension(glm::vec2 dim){m_dimension = dim;}
glm::vec2 getDimension(){return m_dimension;}

View File

@ -39,7 +39,7 @@ ScriptNode::ScriptNode()
void ScriptNode::update(){
static bool test = true;
if(test && m_scene!= nullptr){
if(test && getScene() != nullptr){
m_script["engine"] = getEngine();
test=false;
}

View File

@ -9,7 +9,7 @@ void ShellBuffer::update()
TextNode* tnode;
glm::vec2 text_pos(0,0);
SparrowShell* shell = dynamic_cast<SparrowShell*>(m_parent);
SparrowShell* shell = dynamic_cast<SparrowShell*>(getParent());
if(shell->isEnabled() && m_buffer_modified)
{
for(unsigned int i = 0; i< size();i++)
@ -32,18 +32,19 @@ void ShellBuffer::update()
void ShellBuffer::push(TextNode* tnode){
if(tnode != nullptr)
{
if(m_scene != nullptr)
tnode->setSceneTree(m_scene);
if(getScene() != nullptr)
tnode->setSceneTree(getScene());
if (m_children.size() >= m_max_size){
(m_children[m_zero_offset])->setVisible(false);
m_children[m_zero_offset++] = tnode;
if (m_bufferLines.size() >= m_max_size){
removeChild(m_bufferLines[m_zero_offset]);
m_bufferLines[m_zero_offset++] = tnode;
addChild(tnode);
m_zero_offset %= m_max_size;
}else
m_children.push_back(tnode);
tnode->setParent(this);
tnode->setParentTransform(m_transform);
tnode->setParentVisible(isVisible());
{
m_bufferLines.push_back(tnode);
addChild(tnode);
}
m_buffer_modified = true;
}
}
@ -54,10 +55,9 @@ glm::vec2 ShellBuffer::getDimension(){
}
void ShellBuffer::clear(){
for(auto it = m_children.begin(); it != m_children.end();){
for(auto it = m_bufferLines.begin(); it != m_bufferLines.end();){
TextNode* child = (TextNode*) *it;
m_scene->removeFromIndex(child);
it = m_children.erase(it);
it = m_bufferLines.erase(it);
delete child;
}
m_index = 0;

View File

@ -12,6 +12,8 @@ private:
float m_font_size;
unsigned int m_index = 0;
bool m_buffer_modified;
std::vector<TextNode*> m_bufferLines;
public:
ShellBuffer(int buffer_size):
m_max_size(buffer_size),
@ -22,9 +24,9 @@ public:
setVisible(true);
moveTo2D(glm::vec2(0));
}
SceneNode* operator[](int i){return m_children[(m_zero_offset+i)%m_max_size];}
TextNode* operator[](int i){return m_bufferLines[(m_zero_offset+i)%m_max_size];}
void push(TextNode*);
unsigned int size(){return m_children.size();}
unsigned int size(){return m_bufferLines.size();}
void update();

View File

@ -120,7 +120,7 @@ void SparrowShell::out(std::string str,glm::vec3 color)
TextNode* tnode = shellfont->getTextNode(str,color,m_buffer->getFontSize(),false);
std::string name = "shellTextLine";
name += m_buffer->size();
tnode->getGeometryNode()->mesh->setName(name);
tnode->getMesh()->setName(name);
tnode->setDepth(SHELL_DEPTH+1);
m_buffer->push(tnode);
scrollDown();

View File

@ -6,7 +6,7 @@
#include "glm/vec2.hpp"
#include "scene/scenetree.h"
#include "scene/containernode.h"
#include "scene/scenenode.h"
#include "scene/gui/guinode.h"
#include "scene/gui/callback.h"

View File

@ -14,8 +14,7 @@
#include <scene/scenetree.h>
#include <scene/textnode.h>
#include <scene/playercharacternode.h>
#include <scene/lightnode.h>
#include <scene/containernode.h>
#include <scene/scenenode.h>
#include <tools/graph.h>
#include <tools/pathfinder.h>
#include <tools/loader.h>
@ -84,7 +83,7 @@ public:
void generateTerrain(SceneTree *scene, btDiscreteDynamicsWorld *world)
{
ContainerNode* terrainContainer = new ContainerNode();
SceneNode* terrainContainer = new SceneNode();
scene->getRootObject()->addChild(terrainContainer);
TestGen gen;
PBRMaterial *mat = new PBRMaterial();
@ -106,7 +105,7 @@ void generateTerrain(SceneTree *scene, btDiscreteDynamicsWorld *world)
chunk->mesh->setMaterial(mat);
chunk->mesh->initGL();
SceneNode *node = new SceneNode();
node->getGeometryNode()->mesh = chunk->mesh;
node->setMesh(chunk->mesh);
node->getGeometryNode()->modelMatrix = glm::translate(glm::scale(glm::mat4(), glm::vec3(2.f)), pos*8.f);
node->setTransform(node->getGeometryNode()->modelMatrix);
terrainContainer->addChild(node);
@ -119,7 +118,7 @@ void generateTerrain(SceneTree *scene, btDiscreteDynamicsWorld *world)
void generateSponza(SceneTree *scene, btDiscreteDynamicsWorld *world)
{
ContainerNode* sponzaContainer = new ContainerNode();
SceneNode* sponzaContainer = new SceneNode();
scene->getRootObject()->addChild(sponzaContainer);
Loader::setTexDirectory("data/sponza/");
std::vector<Mesh*> meshes = Loader::loadMesh("sponza.obj");
@ -132,7 +131,7 @@ void generateSponza(SceneTree *scene, btDiscreteDynamicsWorld *world)
{
m->initGL();
SceneNode *node = new SceneNode();
node->getGeometryNode()->mesh = m;
node->setMesh(m);
node->getGeometryNode()->modelMatrix = glm::scale(glm::mat4(), glm::vec3(0.01f));
node->setTransform(node->getGeometryNode()->modelMatrix);
sponzaContainer->addChild(node);
@ -213,13 +212,15 @@ public:
//lighting
Texture* skyboxTexture = RESOURCE_GET(Texture, "radiance");
Texture* ambientTexture = RESOURCE_GET(Texture, "irradiance");
LightNode *ambientLight = new LightNode(new AmbientLight(ambientTexture, skyboxTexture));
SceneNode *ambientLight = new SceneNode();
ambientLight->setLight(new AmbientLight(ambientTexture, skyboxTexture));
DeferredPipeline* pipeline = dynamic_cast<DeferredPipeline*>(scene->getPipeline());
pipeline->setSkybox(RESOURCE_GET(Texture, "skybox"));
DirectionnalLight* sun = new DirectionnalLight(glm::vec3(5, 8, -2), glm::vec3(4.f));
LightNode *sunLight = new LightNode(sun);
SceneNode *sunLight = new SceneNode();
sunLight->setLight(sun);
scene->getRootObject()->addChild(ambientLight);
@ -229,8 +230,12 @@ public:
{
sun->initShadowMap(4096);
generateSponza(scene, m_engine->getScene()->getPhysics());
scene->getRootObject()->addChild(new LightNode(new PointLight(glm::vec3(-3.5, 2, 1.8), 15, glm::vec3(0.35f))));
scene->getRootObject()->addChild(new LightNode(new PointLight(glm::vec3(-5, 6, 2), 15, glm::vec3(0.35f))));
SceneNode* light_1 = new SceneNode();
light_1->setLight(new PointLight(glm::vec3(-3.5, 2, 1.8), 15, glm::vec3(0.35f)));
scene->getRootObject()->addChild(light_1);
SceneNode* light_2 = new SceneNode();
light_2->setLight(new PointLight(glm::vec3(-5, 6, 2), 15, glm::vec3(0.35f)));
scene->getRootObject()->addChild(light_2);
m_player->setPosition(0.f, 2.f, 0.f);
sun->setShadowView(glm::vec3(30, 30, 50));
}
@ -244,14 +249,14 @@ public:
else if(m_config->scene == "sandbox")
{
sun->initShadowMap(4096);
ContainerNode* sandboxContainer = new ContainerNode();
SceneNode* sandboxContainer = new SceneNode();
scene->getRootObject()->addChild(sandboxContainer);
std::vector<Mesh*> meshes = Loader::loadMesh("sandbox.obj");
for(Mesh* m : meshes)
{
m->initGL();
SceneNode *node = new SceneNode();
node->getGeometryNode()->mesh = m;
node->setMesh(m);
sandboxContainer->addChild(node);
btRigidBody* body = utils::buildStaticCollider(node->getGeometryNode());
node->setRigidBody(body);

View File

@ -8,7 +8,7 @@
#include "tools/loader.h"
#include "tools/loadingthread.h"
#include "SparrowRenderer/texture.h"
#include "scene/containernode.h"
#include "scene/scenenode.h"
#include "resourcemanager.h"
#include <imgui/imgui.h>
@ -89,11 +89,11 @@ void Potator::throwShield()
}
float throwForce = 5.f;
ContainerNode *node = new ContainerNode();
SceneNode *node = new SceneNode();
for(Mesh * m : m_shieldMeshes)
{
SceneNode* meshNode = new SceneNode();
meshNode->getGeometryNode()->mesh = m;
meshNode->setMesh(m);
node->addChild(meshNode);
}
createGib(node, m_shieldShape, m_shieldMass, pos, dir*throwForce, 30000);
@ -110,11 +110,11 @@ void Potator::throwBottle()
}
float throwForce = 5.f;
ContainerNode *node = new ContainerNode();
SceneNode *node = new SceneNode();
for(Mesh * m : m_bottleMeshes)
{
SceneNode* meshNode = new SceneNode();
meshNode->getGeometryNode()->mesh = m;
meshNode->setMesh(m);
node->addChild(meshNode);
}
createGib(node, m_bottleShape, m_bottleMass, pos, dir*throwForce, 30000);
@ -131,11 +131,11 @@ void Potator::throwSword()
}
float throwForce = 5.f;
ContainerNode *node = new ContainerNode();
SceneNode *node = new SceneNode();
for(Mesh * m : m_swordMeshes)
{
SceneNode* meshNode = new SceneNode();
meshNode->getGeometryNode()->mesh = m;
meshNode->setMesh(m);
node->addChild(meshNode);
}
createGib(node, m_swordShape, m_swordMass, pos, dir*throwForce, 30000);

View File

@ -34,37 +34,42 @@ Mesh* ScenePicker::generateMesh()
ScenePicker::ScenePicker() :
m_pickSucceeded(false)
{
m_geometry.mesh = generateMesh();
setMesh(generateMesh());
}
ScenePicker::~ScenePicker()
{
delete m_geometry.mesh->getMaterial();
delete m_geometry.mesh;
delete getMesh()->getMaterial();
delete getMesh();
}
void ScenePicker::update()
{
pick();
SceneNode::update();
bool isEnabled = true;
ImGui::Begin("Picker", &isEnabled);
if(m_pickSucceeded)
if(isEnabled())
{
ImGui::Text("Intersection : ( %.3f, %.3f, %.3f )", m_pickedPos.x, m_pickedPos.y, m_pickedPos.z);
if(!isVisible()) setVisible(m_pickSucceeded);
}
else
{
ImGui::Text("No intesection");
if(isVisible()) setVisible(m_pickSucceeded);
}
// if(ImGui::Button("Teleport"))
//move player to target coordinate
ImGui::End();
pick();
if(!isEnabled)
getEngine().getEditor()->togglePicker();
bool isEnabled = true;
ImGui::Begin("Picker", &isEnabled);
if(m_pickSucceeded)
{
ImGui::Text("Intersection : ( %.3f, %.3f, %.3f )", m_pickedPos.x, m_pickedPos.y, m_pickedPos.z);
if(!isVisible()) setVisible(m_pickSucceeded);
}
else
{
ImGui::Text("No intesection");
if(isVisible()) setVisible(m_pickSucceeded);
}
// if(ImGui::Button("Teleport"))
//move player to target coordinate
ImGui::End();
if(!isEnabled)
getEngine().getEditor()->togglePicker();
}
}
void ScenePicker::pick()
@ -89,7 +94,7 @@ void ScenePicker::pick()
m_pickedNode = static_cast<SceneNode*>(rayCallback.m_collisionObject->getUserPointer());
btVector3 target = rayCallback.m_hitPointWorld;
m_pickedPos = glm::vec3(target.x(), target.y(), target.z());
m_geometry.modelMatrix = glm::translate(glm::mat4(), m_pickedPos);
getGeometryNode()->modelMatrix = glm::translate(glm::mat4(), m_pickedPos);
}
}
else