mirror of
https://github.com/devZoGok/vb01.git
synced 2026-08-26 19:43:30 +00:00
3 types of lights
supported number of n lights
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
#include"root.h"
|
||||
#include"node.h"
|
||||
#include"mesh.h"
|
||||
#include"light.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace vb01{
|
||||
Node::Node(Vector3 pos){
|
||||
@@ -11,16 +15,40 @@ namespace vb01{
|
||||
void Node::update(){
|
||||
if(mesh)
|
||||
mesh->update();
|
||||
for(Light *l : lights)
|
||||
l->update();
|
||||
for(Node *c : children)
|
||||
c->update();
|
||||
}
|
||||
|
||||
void Node::attachChild(Node *child){
|
||||
Node *parent=getParent();
|
||||
while(parent){
|
||||
parent->getDescendants().push_back(child);
|
||||
parent=parent->getParent();
|
||||
}
|
||||
children.push_back(child);
|
||||
descendants.push_back(child);
|
||||
}
|
||||
|
||||
void Node::setObject(Mesh *mesh){
|
||||
this->mesh=mesh;
|
||||
mesh->setNode(this);
|
||||
}
|
||||
|
||||
void Node::addLight(Light *light){
|
||||
lights.push_back(light);
|
||||
light->setNode(this);
|
||||
|
||||
Node *rootNode=Root::getSingleton()->getRootNode();
|
||||
vector<Node*> descendants=rootNode->getDescendants();
|
||||
descendants.push_back(rootNode);
|
||||
int numLights=0;
|
||||
for(Node *n : descendants)
|
||||
numLights+=n->getNumLights();
|
||||
for(Node *n : descendants)
|
||||
if(n->getMesh())
|
||||
if(n->getMesh()->getMaterial())
|
||||
n->getMesh()->getMaterial()->getShader()->setNumLights(numLights>0?numLights:1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user