TEST(RepoBSONFactoryTest, MakeMaterialNodeTest) { repo_material_t mat_struct; mat_struct.ambient.resize(4); mat_struct.diffuse.resize(4); mat_struct.specular.resize(4); mat_struct.emissive.resize(4); mat_struct.opacity = 0.9; mat_struct.shininess = 1.0; mat_struct.shininessStrength = 0.5; mat_struct.isWireframe = true; mat_struct.isTwoSided = false; std::string name = "MatTest"; MaterialNode material = RepoBSONFactory::makeMaterialNode(mat_struct, name); EXPECT_FALSE(material.isEmpty()); EXPECT_EQ(name, material.getName()); EXPECT_EQ(material.getTypeAsEnum(), NodeType::MATERIAL); auto matOut = material.getMaterialStruct(); compareMaterialStructs(mat_struct, matOut); repo_material_t emptyStruct; //See if it breaks if the vectors in the struct is never filled MaterialNode material2 = RepoBSONFactory::makeMaterialNode(emptyStruct, name); EXPECT_FALSE(material2.isEmpty()); EXPECT_EQ(name, material2.getName()); EXPECT_EQ(material2.getTypeAsEnum(), NodeType::MATERIAL); }
MaterialNode *SceneGraph::findMaterialNode(char *name) { if (!name || strlen(name) <= 0) return NULL; for (MaterialNode *node = findMaterialNode(); node; node = node->nextTraversal()) { const char *nodeName = node->getName(); if (nodeName && strlen(nodeName)) { if (!strcmp(name, nodeName)) return node; } } return NULL; }
void AppearanceNode::outputContext(ostream &printStream, const char *indentString) { MaterialNode *material = getMaterialNodes(); if (material != NULL) { if (material->isInstanceNode() == false) { if (material->getName() != NULL && strlen(material->getName())) printStream << indentString << "\t" << "material " << "DEF " << material->getName() << " Material {" << endl; else printStream << indentString << "\t" << "material Material {" << endl; material->Node::outputContext(printStream, indentString, "\t"); printStream << indentString << "\t" << "}" << endl; } else printStream << indentString << "\t" << "material USE " << material->getName() << endl; } TextureNode *texture = getTextureNode(); if (texture != NULL) { if (texture->isInstanceNode() == false) { if (texture->getName() != NULL && strlen(texture->getName())) printStream << indentString << "\t" << "texture " << "DEF " << texture->getName() << " " << texture->Node::getType() << " {" << endl; else printStream << indentString << "\t" << "texture " << texture->Node::getType() << " {" << endl; texture->Node::outputContext(printStream, indentString, "\t"); printStream << indentString << "\t" << "}" << endl; } else printStream << indentString << "\t" << "texture USE " << texture->getName() << endl; } TextureTransformNode *textureTransform = getTextureTransformNodes(); if (textureTransform != NULL) { if (textureTransform->isInstanceNode() == false) { if (textureTransform->getName() != NULL && strlen(textureTransform->getName())) printStream << indentString << "\t" << "textureTransform " << "DEF " << textureTransform->getName() << " TextureTransform {" << endl; else printStream << indentString << "\t" << "textureTransform TextureTransform {" << endl; textureTransform->Node::outputContext(printStream, indentString, "\t"); printStream << indentString << "\t" << "}" << endl; } else printStream << indentString << "\t" << "textureTransform USE " << textureTransform->getName() << endl; } }
void MaterialNode::receiveFragmentDestroy(void* user, VNodeID nodeID, VNMFragmentID fragmentID) { Session* session = Session::getCurrent(); MaterialNode* node = dynamic_cast<MaterialNode*>(session->getNodeByID(nodeID)); if (!node) return; //Fragment* fragment = node->getFragmentByID(fragmentID); //if (fragment) for (MaterialNode::FragmentList::iterator f = node->mFragments.begin(); f != node->mFragments.end(); f++) { if ((*f)->getID() == fragmentID) { // Notify fragment observers. const Fragment::ObserverList& fObservers = (*f)->getObservers(); for (Fragment::ObserverList::const_iterator i = fObservers.begin(); i != fObservers.end(); i++) { if (FragmentObserver* observer = dynamic_cast<FragmentObserver*>(*i)) observer->onDestroy(*(*f)); } // Notify node observers. const MaterialNode::ObserverList& nObservers = node->getObservers(); for (MaterialNode::ObserverList::const_iterator i = nObservers.begin(); i != nObservers.end(); i++) { if (MaterialNodeObserver* observer = dynamic_cast<MaterialNodeObserver*>(*i)) observer->onDestroyFragment(*node, *(*f)); } delete *f; node->mFragments.erase(f); node->updateStructureVersion(); //delete *f; SLAS::TMP // Fragment* frag = *f; // SLAS::TMP /* for (Fragment::ObserverList::const_iterator i = fObservers.begin(); i != fObservers.end(); i++) { if (FragmentObserver* observer = dynamic_cast<FragmentObserver*>(*i)) observer->postDestroy(*frag); } for (MaterialNode::ObserverList::const_iterator i = nObservers.begin(); i != nObservers.end(); i++) { if (MaterialNodeObserver* observer = dynamic_cast<MaterialNodeObserver*>(*i)) observer->postDestroyFragment(*node, *frag); } */ //delete frag; // SLAS::TMP break; } } }
void MaterialNode::receiveFragmentCreate(void* user, VNodeID nodeID, VNMFragmentID fragmentID, VNMFragmentType type, const VMatFrag* value) { Session* session = Session::getCurrent(); MaterialNode* node = dynamic_cast<MaterialNode*>(session->getNodeByID(nodeID)); if (!node) return; Fragment* fragment = node->getFragmentByID(fragmentID); if (fragment) { if (type != fragment->mType) { const Fragment::ObserverList& observers = fragment->getObservers(); for (Fragment::ObserverList::const_iterator i = observers.begin(); i != observers.end(); i++) (*i)->onSetType(*fragment, type); fragment->mType = type; fragment->mValue = *value; fragment->updateStructureVersion(); //for (Fragment::ObserverList::const_iterator i = observers.begin(); i != observers.end(); i++) // (*i)->postSetType(*fragment, type); } else { const Fragment::ObserverList& observers = fragment->getObservers(); for (Fragment::ObserverList::const_iterator i = observers.begin(); i != observers.end(); i++) (*i)->onSetValue(*fragment, *value); fragment->mValue = *value; fragment->updateDataVersion(); //for (Fragment::ObserverList::const_iterator i = observers.begin(); i != observers.end(); i++) // (*i)->postFragChange(*fragment, frag); } } else { fragment = new Fragment(fragmentID, *node, type, *value); // Notify node observers. const MaterialNode::ObserverList& nObservers = node->getObservers(); for (MaterialNode::ObserverList::const_iterator i = nObservers.begin(); i != nObservers.end(); i++) { if (MaterialNodeObserver* observer = dynamic_cast<MaterialNodeObserver*>(*i)) observer->onCreateFragment(*node, *fragment); } node->mFragments.push_back(fragment); node->updateStructureVersion(); //for (MaterialNode::ObserverList::const_iterator i = nObservers.begin(); i != nObservers.end(); i++) //{ // if (MaterialNodeObserver* observer = dynamic_cast<MaterialNodeObserver*>(*i)) // observer->postCreateFragment(*node, *fragment); //} } }