removable lights and skybox

This commit is contained in:
devZoGok
2021-10-19 19:06:40 +03:00
parent c44d178766
commit 52c59d6879
5 changed files with 41 additions and 36 deletions
+29 -36
View File
@@ -26,9 +26,7 @@ namespace vb01{
for(Text *t : texts)
delete t;
for(Node *c : children){
Node *par=c->getParent();
if(par)
par->dettachChild(c);
//dettachChild(c);
delete c;
}
}
@@ -49,27 +47,11 @@ namespace vb01{
}
void Node::attachChild(Node *child){
/*
Node *parent=getParent();
while(parent){
parent->getDescendants().push_back(child);
parent=parent->getParent();
}
descendants.push_back(child);
*/
child->setParent(this);
children.push_back(child);
}
void Node::dettachChild(Node *child){
/*
Node *parent=getParent();
while(parent){
parent->getDescendants().push_back(child);
parent=parent->getParent();
}
descendants.push_back(child);
*/
child->setParent(nullptr);
int id=-1;
for(int i=0;i<children.size()&&id==-1;i++)
@@ -89,26 +71,18 @@ namespace vb01{
}
void Node::addLight(Light *light){
Root::getSingleton()->numLights++;
lights.push_back(light);
light->setNode(this);
Root *root=Root::getSingleton();
updateShaders();
}
Node *rootNode=Root::getSingleton()->getRootNode();
vector<Node*> descendants;
rootNode->getDescendants(rootNode,descendants);
descendants.push_back(rootNode);
root->numLights++;
for(Node *n : descendants){
vector<Mesh*> meshes=n->getMeshes();
for(Mesh *m : meshes){
Material *mat=m->getMaterial();
string str=to_string(root->numLights>0?root->numLights:1);
if(mat){
//mat->getShader()->editShader(true,'=',';',str);
mat->getShader()->editShader(false,'=',';',str);
}
}
}
void Node::removeLight(int id){
Root::getSingleton()->numLights--;
Light *light=lights[id];
light->setNode(nullptr);
lights.erase(lights.begin()+id);
updateShaders();
}
void Node::addText(Text *text){
@@ -242,4 +216,23 @@ namespace vb01{
return p;
}
void Node::updateShaders(){
Root *root=Root::getSingleton();
Node *rootNode=Root::getSingleton()->getRootNode();
vector<Node*> descendants;
rootNode->getDescendants(rootNode,descendants);
descendants.push_back(rootNode);
for(Node *n : descendants){
vector<Mesh*> meshes=n->getMeshes();
for(Mesh *m : meshes){
Material *mat=m->getMaterial();
string str=to_string(root->numLights>0?root->numLights:1);
if(mat){
//mat->getShader()->editShader(true,'=',';',str);
mat->getShader()->editShader(false,'=',';',str);
}
}
}
}
}