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); }
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; } }
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; }