bool Parser::processScene() { std::string strEtiqueta; bool bFinBloque = false; if(m_pGlobals->pScene == NULL) { m_pGlobals->pScene = new Scene; while(!bFinBloque) { // Buscamos etiqueta. if(!ignorarChars()) return false; if(!readToken(strEtiqueta)) return false; if(strEtiqueta == "/scene") bFinBloque = true; else { if(strEtiqueta == "texture") { if(!processTexture()) return false; } else if(strEtiqueta == "material") { if(!processMaterial()) return false; } else if(strEtiqueta == "object") { if(!processObject()) return false; } else // Etiqueta desconocida, no perteneciente a la seccion config. return false; } } } else // Scene ya creada, error. return false; return true; }
void processLine( const char *line ) { char temp[256]; strcpy( temp, line ); char *token = strtok( temp, " " ); if( strcmp( token, "v" ) == 0 ) { processVertex( line ); } else if( strcmp( token, "vn" ) == 0 ) { processNormal( line ); } else if( strcmp( token, "vt" ) == 0 ) { processTexture( line ); } else if( strcmp( token, "f" ) == 0 ) { processFace( line ); } }
bool processColorOrTextureType( domCommon_color_or_texture_type *cot, mat_type_t mt ) { if (cot == NULL ) { return false; } bool retVal = false; std::string texCoordSet; std::shared_ptr<TextureParameters> p = nullptr; if (cot->getTexture() != NULL) { p = processTexture( cot->getTexture()); retVal = true; } if(p){ auto tex = xml_helper::currentMaterial().append_child("texture"); tex.append_attribute("unit") = stringify(mt); tex.append_attribute("path") = p->filename.c_str(); tex.append_attribute("wrap_s") = stringify(p->wrap_s).c_str(); tex.append_attribute("wrap_t") = stringify(p->wrap_t).c_str(); } //TODO: Make all channels process <param ref=""> type of value //if (channel == osg::Material::EMISSION ) //{ // if (cot->getColor() != NULL ) // { // domFloat4 &f4 = cot->getColor()->getValue(); // mat->setEmission( osg::Material::FRONT_AND_BACK, osg::Vec4( f4[0], f4[1], f4[2], (f4.getCount()==4)? f4[3] : 1.0 ) ); // retVal = true; // } // else if (cot->getParam() != NULL) // { // domFloat4 f4; // if (GetFloat4Param(cot->getParam()->getRef(), f4)) // { // mat->setEmission( osg::Material::FRONT_AND_BACK, osg::Vec4( f4[0], f4[1], f4[2], f4[3] ) ); // retVal = true; // } // } // else if (cot->getTexture() != NULL) // { // if (sa != NULL) // { // *sa = processTexture( cot->getTexture(), ss, MAIN_TEXTURE_UNIT); // retVal = true; // } // else // OSG_WARN << "Currently no support for <texture> in Emission channel " << std::endl; // } // else // { // OSG_WARN << "Missing <color>, <param> or <texture> in Emission channel " << std::endl; // } //} //else if (channel == osg::Material::AMBIENT ) //{ // if (cot->getColor() != NULL ) // { // domFloat4 &f4 = cot->getColor()->getValue(); // mat->setAmbient( osg::Material::FRONT_AND_BACK, osg::Vec4( f4[0], f4[1], f4[2], (f4.getCount()==4)? f4[3] : 1.0 ) ); // retVal = true; // } // else if (cot->getParam() != NULL) // { // domFloat4 f4; // if (cot->getParam()->getRef() != 0 && GetFloat4Param(cot->getParam()->getRef(), f4)) // { // mat->setAmbient( osg::Material::FRONT_AND_BACK, osg::Vec4( f4[0], f4[1], f4[2], f4[3] ) ); // retVal = true; // } // } // else if (cot->getTexture() != NULL) // { // if (sa != NULL) // *sa = processTexture( cot->getTexture(), ss, AMBIENT_OCCLUSION_UNIT); // else // { // OSG_WARN << "Currently no support for <texture> in Ambient channel " << std::endl; // mat->setAmbient( osg::Material::FRONT_AND_BACK, osg::Vec4( 0.2f, 0.2f, 0.2f, 1.0f ) ); // } // retVal = true; // } // else // { // OSG_WARN << "Missing <color>, <param> or <texture> in Ambient channel " << std::endl; // } //} //else if (channel == osg::Material::DIFFUSE ) //{ // if (cot->getColor() != NULL) // { // domFloat4 &f4 = cot->getColor()->getValue(); // mat->setDiffuse( osg::Material::FRONT_AND_BACK, osg::Vec4( f4[0], f4[1], f4[2], (f4.getCount()==4)? f4[3] : 1.0 ) ); // retVal = true; // } // else if (cot->getTexture() != NULL) // { // if (sa != NULL) // *sa = processTexture( cot->getTexture(), ss, MAIN_TEXTURE_UNIT); // else // { // OSG_WARN << "Currently no support for <texture> in Diffuse channel " << std::endl; // mat->setDiffuse( osg::Material::FRONT_AND_BACK, osg::Vec4( 0.8f, 0.8f, 0.8f, 1.0f ) ); // } // domExtra *extra = cot->getTexture()->getExtra(); // if (extra != NULL && extra->getType() != NULL && strcmp( extra->getType(), "color" ) == 0 ) // { // //the extra data for osg. Diffuse color can happen with a texture. // for ( unsigned int i = 0; i < extra->getTechnique_array().getCount(); i++ ) // { // domTechnique *teq = extra->getTechnique_array()[i]; // if (strcmp( teq->getProfile(), "SCEI" ) == 0 ) // { // osg::Vec4 col; // domAny *dcol = (domAny*)(daeElement*)teq->getContents()[0]; // std::istringstream diffuse_colour((const char *)dcol->getValue()); // diffuse_colour >> col.r() >> col.g() >> col.b() >> col.a(); // mat->setDiffuse( osg::Material::FRONT_AND_BACK, col ); // break; // } // } // } // retVal = true; // } // else if (cot->getParam() != NULL) // { // domFloat4 f4; // if (GetFloat4Param(cot->getParam()->getRef(), f4)) // { // mat->setDiffuse( osg::Material::FRONT_AND_BACK, osg::Vec4( f4[0], f4[1], f4[2], f4[3] ) ); // retVal = true; // } // } // else // { // OSG_WARN << "Missing <color>, <param> or <texture> in Diffuse channel " << std::endl; // } //} //else if (channel == osg::Material::SPECULAR ) //{ // if (cot->getColor() != NULL ) // { // domFloat4 &f4 = cot->getColor()->getValue(); // mat->setSpecular( osg::Material::FRONT_AND_BACK, osg::Vec4( f4[0], f4[1], f4[2], (f4.getCount()==4)? f4[3] : 1.0 ) ); // retVal = true; // } // else if (cot->getParam() != NULL) // { // domFloat4 f4; // if (GetFloat4Param(cot->getParam()->getRef(), f4)) // { // mat->setSpecular( osg::Material::FRONT_AND_BACK, osg::Vec4( f4[0], f4[1], f4[2], f4[3] ) ); // retVal = true; // } // } // else if (cot->getTexture() != NULL) // { // OSG_WARN << "Currently no support for <texture> in Specular channel " << std::endl; // } // else // { // OSG_WARN << "Missing <color>, <param> or <texture> in Specular channel " << std::endl; // } // if (fop != NULL && fop->getFloat() != NULL ) // { // float shininess = fop->getFloat()->getValue(); // if (blinn) // { // // If the blinn mode is in the range [0,1] rescale it to [0,128] // if (shininess < 1) // shininess *= 128.0f; // } // mat->setShininess( osg::Material::FRONT_AND_BACK, shininess ); // } //} return retVal; }
void ResourcePool::Config() { for (vector<Branch>::iterator branch = resourceBranch.childBranches.begin(); branch != resourceBranch.childBranches.end(); ++branch) { if (branch->branchName == "MeshContainer") { for (vector<Attribute>::iterator attri = branch->attributes.begin(); attri != branch->attributes.end(); ++attri) { Attribute tempAttri = *attri; string attriName = tempAttri.name; string attriValue = tempAttri.value; if (attriName == "Directory") { processMesh(attriValue); } } } else if (branch->branchName == "TextureContainer") { for (vector<Attribute>::iterator attri = branch->attributes.begin(); attri != branch->attributes.end(); ++attri) { Attribute tempAttri = *attri; string attriName = tempAttri.name; string attriValue = tempAttri.value; if (attriName == "Directory") { processTexture(attriValue); } } } else if (branch->branchName == "ColorContainer") { for (vector<Attribute>::iterator attri = branch->attributes.begin(); attri != branch->attributes.end(); ++attri) { Attribute tempAttri = *attri; string attriName = tempAttri.name; string attriValue = tempAttri.value; if (attriName == "Directory") { processColor(attriValue); } } } else if (branch->branchName == "ShaderContainer") { for (vector<Attribute>::iterator attri = branch->attributes.begin(); attri != branch->attributes.end(); ++attri) { Attribute tempAttri = *attri; string attriName = tempAttri.name; string attriValue = tempAttri.value; if (attriName == "Directory") { processShader(attriValue); } } } else if (branch->branchName == "SoundContainer") { for (vector<Attribute>::iterator attri = branch->attributes.begin(); attri != branch->attributes.end(); ++attri) { Attribute tempAttri = *attri; string attriName = tempAttri.name; string attriValue = tempAttri.value; if (attriName == "Directory") { soundPool->processSound(attriValue); } } } } }