void processSceneRecursive(const aiScene *scene, cJSON *list, const aiMatrix4x4 &transform, aiNode *nodes) { for(unsigned i = 0; i < nodes->mNumMeshes; i++) { aiMesh *mesh = scene->mMeshes[nodes->mMeshes[i]]; std::string meshname = processMesh(i, nodes, mesh); std::string occlusionName = createOcclusionGeometry(meshname, nodes, mesh); // Format mesh name std::string n(nodes->mName.data, nodes->mName.length); std::stringstream ss; ss << n << "_" << i; std::string materialfile = processMaterial(i, scene->mMaterials[mesh->mMaterialIndex]); std::string entity = outputJsonEntityFile(ss.str(), transform, meshname, materialfile, occlusionName); //outputJsonMeshFile(materialfile, meshname, outdir + "/Meshes/" + ss.str()); cJSON_AddStringToArray(list, entity.c_str()); } aiMatrix4x4 t = nodes->mTransformation * transform; for(unsigned i = 0; i < nodes->mNumChildren; i++) { processSceneRecursive(scene, list, t, nodes->mChildren[i]); } }
//---------------------------------------------------------------------------- // Init //---------------------------------------------------------------------------- bool MatInstance::init( const FeatureSet &features, const GFXVertexFormat *vertexFormat ) { AssertFatal( vertexFormat, "MatInstance::init - Got null vertex format!" ); mFeatureList = features; mVertexFormat = vertexFormat; SAFE_DELETE(mProcessedMaterial); mIsValid = processMaterial(); return mIsValid; }
//---------------------------------------------------------------------------- // reInitialize //---------------------------------------------------------------------------- bool MatInstance::reInit() { SAFE_DELETE(mProcessedMaterial); deleteAllHooks(); mIsValid = processMaterial(); if ( mIsValid ) { for (U32 i = 0; i < mCurrentHandles.size(); i++) mCurrentHandles[i]->loadHandle(mProcessedMaterial); for (U32 i = 0; i < mCurrentParameters.size(); i++) mCurrentParameters[i]->loadParameters(mProcessedMaterial); } return mIsValid; }
static Material *getMaterial( Obj *child, const mmap& bindings ) { string tfield = child->getTypeName(); if( tfield == "id" ) { mmap::const_iterator i = bindings.find( child->getID() ); if( i != bindings.end() ) { return (*i).second; } } else if( tfield == "string" ) { mmap::const_iterator i = bindings.find( child->getString() ); if( i != bindings.end() ) { return (*i).second; } } // Don't allow binding. return processMaterial( child ); }
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; }
bool PropertyWindow::processField(EditorComponentField& field) { ImGuiInputTextFlags flags = ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_CharsNoBlank; flags |= field._readOnly ? ImGuiInputTextFlags_ReadOnly : 0; bool ret = false; switch (field._type) { case EditorComponentFieldType::PUSH_TYPE: { ret = processBasicField(field); }break; case EditorComponentFieldType::BOUNDING_BOX: { BoundingBox bb = *static_cast<BoundingBox*>(field.data()); F32* bbMin = Attorney::BoundingBoxEditor::min(bb); F32* bbMax = Attorney::BoundingBoxEditor::max(bb); ret = ImGui::InputFloat3("- Min ", bbMin, "%.3f", flags) || ImGui::InputFloat3("- Max ", bbMax, "%.3f", flags); if (ret) { field.data(bb); } }break; case EditorComponentFieldType::BOUNDING_SPHERE: { BoundingSphere bs = *static_cast<BoundingSphere*>(field.data()); F32* center = Attorney::BoundingSphereEditor::center(bs); F32& radius = Attorney::BoundingSphereEditor::radius(bs); ret = ImGui::InputFloat3("- Center ", center, "%.3f", flags) || ImGui::InputFloat("- Radius ", &radius, 0.0f, 0.0f, -1, flags); if (ret) { field.data(bs); } }break; case EditorComponentFieldType::TRANSFORM: { assert(!field._dataSetter && "Need direct access to memory"); ret = processTransform(static_cast<TransformComponent*>(field.data()), field._readOnly); }break; case EditorComponentFieldType::MATERIAL: { assert(!field._dataSetter && "Need direct access to memory"); ret = processMaterial(static_cast<Material*>(field.data()), field._readOnly); }break; }; return ret; }
//---------------------------------------------------------------------------- // Process stages //---------------------------------------------------------------------------- bool MatInstance::processMaterial() { AssertFatal( mMaterial, "MatInstance::processMaterial - Got null material!" ); //AssertFatal( mVertexFormat, "MatInstance::processMaterial - Got null vertex format!" ); if ( !mMaterial || !mVertexFormat ) return false; SAFE_DELETE(mDefaultParameters); CustomMaterial *custMat = NULL; if( dynamic_cast<CustomMaterial*>(mMaterial) ) { F32 pixVersion = GFX->getPixelShaderVersion(); custMat = static_cast<CustomMaterial*>(mMaterial); if ((custMat->mVersion > pixVersion) || (custMat->mVersion == 0.0)) { if(custMat->mFallback) { mMaterial = custMat->mFallback; return processMaterial(); } else { AssertWarn(custMat->mVersion == 0.0f, avar("Can't load CustomMaterial %s for %s, using generic FF fallback", String(mMaterial->getName()).isEmpty() ? "Unknown" : mMaterial->getName(), custMat->mMapTo.c_str())); mProcessedMaterial = new ProcessedFFMaterial(*mMaterial); } } else mProcessedMaterial = new ProcessedCustomMaterial(*mMaterial); } else if(GFX->getPixelShaderVersion() > 0.001) mProcessedMaterial = getShaderMaterial(); else mProcessedMaterial = new ProcessedFFMaterial(*mMaterial); if (mProcessedMaterial) { mProcessedMaterial->addStateBlockDesc( mUserDefinedState ); mProcessedMaterial->setShaderMacros( mUserMacros ); mProcessedMaterial->setUserObject( mUserObject ); FeatureSet features( mFeatureList ); features.exclude( MATMGR->getExclusionFeatures() ); if( !mProcessedMaterial->init(features, mVertexFormat, mFeaturesDelegate) ) { Con::errorf( "Failed to initialize material '%s'", getMaterial()->getName() ); SAFE_DELETE( mProcessedMaterial ); return false; } mDefaultParameters = new MatInstParameters(mProcessedMaterial->getDefaultMaterialParameters()); mActiveParameters = mDefaultParameters; const FeatureSet &finalFeatures = mProcessedMaterial->getFeatures(); mHasNormalMaps = finalFeatures.hasFeature( MFT_NormalMap ); mIsForwardLit = ( custMat && custMat->mForwardLit ) || ( !finalFeatures.hasFeature( MFT_IsEmissive ) && finalFeatures.hasFeature( MFT_ForwardShading ) ); return true; } return false; }
static void processObject( Obj *obj, Scene *scene, mmap& materials ) { // Assume the object is named. string name; Obj *child; if( obj->getTypeName() == "id" ) { name = obj->getID(); child = NULL; } else if( obj->getTypeName() == "named" ) { name = obj->getName(); child = obj->getChild(); } else { ostrstream oss; oss << "Unknown input object "; obj->printOn( oss ); throw ParseError( string( oss.str() ) ); } if( name == "directional_light" ) { if( child == NULL ) { throw ParseError( "No info for directional_light" ); } scene->add( new DirectionalLight( scene, tupleToVec( getField( child, "direction" ) ).normalize(), tupleToVec( getColorField( child ) ) ) ); } else if( name == "point_light" ) { if( child == NULL ) { throw ParseError( "No info for point_light" ); } PointLight* pointLight = new PointLight(scene, tupleToVec(getField(child, "position")), tupleToVec(getColorField(child))); scene->add(pointLight); if (hasField(child, "constant_attenuation_coeff") && hasField(child, "linear_attenuation_coeff") && hasField(child, "quadratic_attenuation_coeff")) { pointLight->setAttenuationCoefficients( getField(child, "constant_attenuation_coeff")->getScalar(), getField(child, "linear_attenuation_coeff")->getScalar(), getField(child, "quadratic_attenuation_coeff")->getScalar()); } } else if (name == "ambient_light") { if (child == NULL) { throw ParseError("No info for ambient_light"); } AmbientLight* ambientLight = new AmbientLight(scene, tupleToVec(getColorField(child))); scene->add(ambientLight); } else if( name == "sphere" || name == "box" || name == "cylinder" || name == "cone" || name == "square" || name == "translate" || name == "rotate" || name == "scale" || name == "transform" || name == "trimesh" || name == "polymesh") { // polymesh is for backwards compatibility. processGeometry( name, child, scene, materials, &scene->transformRoot); //scene->add( geo ); } else if( name == "material" ) { processMaterial( child, &materials ); } else if( name == "camera" ) { processCamera( child, scene ); } else { throw ParseError( string( "Unrecognized object: " ) + name ); } }
void MATMLReader::read(QIODevice *source) { if (!document_.setContent(source)) return; NQLog("MATMLReader", NQLog::Message) << "void read(QIODevice *destination)"; QDomElement docElem = document_.documentElement(); QDomElement matmlElem; bool found = false; findMatMLDocElement(docElem, matmlElem, found); if (!found) return; QDomNodeList materialsElemList = matmlElem.elementsByTagName("Material"); QDomNodeList metadataElemList = matmlElem.elementsByTagName("Metadata"); if (metadataElemList.count()!=1) return; PropertyDetailMap_.clear(); ParameterDetailMap_.clear(); QDomNodeList propertydetailsList = metadataElemList.at(0).toElement().elementsByTagName("PropertyDetails"); for (int i=0;i<propertydetailsList.count();++i) { QDomElement e = propertydetailsList.at(i).toElement(); processPropertyDetail(e); } QDomNodeList parameterdetailsList = metadataElemList.at(0).toElement().elementsByTagName("ParameterDetails"); for (int i=0;i<parameterdetailsList.count();++i) { QDomElement e = parameterdetailsList.at(i).toElement(); processParameterDetail(e); } for (int i=0;i<materialsElemList.count();++i) { QDomElement e = materialsElemList.at(i).toElement(); QDomElement bulk = e.elementsByTagName("BulkDetails").at(0).toElement(); QDomElement name = bulk.elementsByTagName("Name").at(0).toElement(); Material * mat = new Material(); mat->setName(name.text()); if (!bulk.elementsByTagName("UUID").isEmpty()) { QDomElement uuid = bulk.elementsByTagName("UUID").at(0).toElement(); mat->setUUID(uuid.text()); } else { mat->setUUID(QUuid::createUuid().toString()); } if (!bulk.elementsByTagName("Category").isEmpty()) { QDomElement category = bulk.elementsByTagName("Category").at(0).toElement(); mat->setCategory(categoryModel_->getCategory(category.text())); } QDomNodeList tagList = bulk.elementsByTagName("Tag"); QStringList tags; if (!tagList.isEmpty()) { for (int i=0;i<tagList.size();++i) { QDomElement tagElement = tagList.at(i).toElement(); tags << tagElement.text(); } } mat->setTags(tags); if (!bulk.elementsByTagName("Description").isEmpty()) { QDomElement description = bulk.elementsByTagName("Description").at(0).toElement(); mat->setDescription(description.text()); } QString notes; QDomNodeList notesList = bulk.elementsByTagName("Notes"); if (!notesList.isEmpty()) { for (int i=0;i<notesList.size();++i) { QDomElement notesElement = notesList.at(i).toElement(); notes += notesElement.text(); notes += "\n"; } } mat->setNotes(notes); processMaterial(bulk, mat); model_->addMaterial(mat); } model_->sort(); }
bool ObjParser::parse( std::istream& input ) { reset(); // Read each line of the .obj file while ( readNextLine( input ) && !hasErrors() ) { // Skip lines that are empty if ( isCurrentLineEmpty() ) { continue; } // Split the input line into "words' that are separated by // spaces. The first word is the next obj file command, the others // that follow are arguments to that command std::vector<std::string> tokens; tokenizeCommandString( lineText(), tokens ); assert( tokens.size() > 0 ); // What kind of command is this? if ( tokens[0] == "v" ) { processVertexPosition( tokens ); } else if ( tokens[0] == "vt" ) { processVertexTexCoord( tokens ); } else if ( tokens[0] == "vn" ) { processVertexNormal( tokens ); } else if ( tokens[0] == "g" ) { processGroup( tokens ); } else if ( tokens[0] == "f" ) { processFace( tokens ); } else if ( tokens[0] == "usemtl" ) { processMaterial( tokens ); } else if ( tokens[0] == "mtllib" ) { processMaterialLib( tokens ); } else if ( tokens[0] == "s" ) { // ignore smoothing groups } else { raiseError("Unknown .obj command encountered"); continue; } } // Make sure the last group has at least one face in it if ( m_objdata->currentGroup.empty() == false ) { if ( m_objdata->groups[ m_objdata->currentGroupIndex ].count == 0 ) { raiseError("The last active group didn't have any faces"); } } // Now we're done, make sure to return if the parsing was successful or // not return !hasErrors(); }