From 3cb336ff7d87851e6b1a120745ee8cfe76e7bf33 Mon Sep 17 00:00:00 2001 From: jonathanklein Date: Sat, 5 Sep 2009 15:49:23 +0000 Subject: [PATCH] - Uv coords are no flipped so that they are correct now - Custom Materials can be read (see Ogre importer documentation) - Blender Ogre Exporter Material Template File added git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@477 67173fc5-114c-0410-ac8e-9d2fd5bffc1f --- code/OgreImporter.cpp | 42 +++++++++++++++++++++++++++------ doc/dox.h | 11 ++++++++- scripts/OgreImporter/assimp.tpl | 10 ++++++++ 3 files changed, 55 insertions(+), 8 deletions(-) create mode 100644 scripts/OgreImporter/assimp.tpl diff --git a/code/OgreImporter.cpp b/code/OgreImporter.cpp index cf80f2b32..8f7a60d03 100644 --- a/code/OgreImporter.cpp +++ b/code/OgreImporter.cpp @@ -55,7 +55,7 @@ void OgreImporter::InternReadFile(const std::string &pFile, aiScene *pScene, Ass throw new ImportErrorException("Failed to create XML Reader for "+pFile); - DefaultLogger::get()->info("Mesh File opened"); + DefaultLogger::get()->debug("Mesh File opened"); //Read root Node: if(!(XmlRead(MeshFile) && string(MeshFile->getNodeName())=="mesh")) @@ -76,7 +76,7 @@ void OgreImporter::InternReadFile(const std::string &pFile, aiScene *pScene, Ass { SubMesh NewSubMesh; NewSubMesh.MaterialName=GetAttribute(MeshFile, "material"); - DefaultLogger::get()->info("Loading Submehs with Material: "+NewSubMesh.MaterialName); + DefaultLogger::get()->debug("Loading Submehs with Material: "+NewSubMesh.MaterialName); ReadSubMesh(NewSubMesh, MeshFile); } //_______________________________________________________________- @@ -124,7 +124,7 @@ void OgreImporter::ReadSubMesh(SubMesh &theSubMesh, XmlReader *Reader) //some info logging: unsigned int NumFaces=GetAttribute(Reader, "count"); stringstream ss; ss <<"Submesh has " << NumFaces << " Faces."; - DefaultLogger::get()->info(ss.str()); + DefaultLogger::get()->debug(ss.str()); while(XmlRead(Reader) && Reader->getNodeName()==string("face")) { @@ -145,7 +145,7 @@ void OgreImporter::ReadSubMesh(SubMesh &theSubMesh, XmlReader *Reader) //some info logging: unsigned int NumVertices=GetAttribute(Reader, "vertexcount"); stringstream ss; ss<<"VertexCount: "<info(ss.str()); + DefaultLogger::get()->debug(ss.str()); //General Informations about vertices XmlRead(Reader); @@ -193,7 +193,7 @@ void OgreImporter::ReadSubMesh(SubMesh &theSubMesh, XmlReader *Reader) XmlRead(Reader); aiVector3D NewUv; NewUv.x=GetAttribute(Reader, "u"); - NewUv.y=GetAttribute(Reader, "v"); + NewUv.y=GetAttribute(Reader, "v")*(-1)+1;//flip the uv vertikal, blender exports them so! Uvs.push_back(NewUv); } XmlRead(Reader); @@ -201,7 +201,7 @@ void OgreImporter::ReadSubMesh(SubMesh &theSubMesh, XmlReader *Reader) } } - DefaultLogger::get()->info(str(format("Positionen: %1% Normale: %2% TexCoords: %3%") % Positions.size() % Normals.size() % Uvs.size())); + DefaultLogger::get()->debug(str(format("Positionen: %1% Normale: %2% TexCoords: %3%") % Positions.size() % Normals.size() % Uvs.size())); //Make all Vertexes unique: (this is required by assimp) @@ -407,8 +407,36 @@ aiMaterial* OgreImporter::LoadMaterial(std::string MaterialName) } } }//end of technique + + } - + + + DefaultLogger::get()->info(Line); + //read informations from a custom material: + if(Line=="set") + { + ss >> Line; + if(Line=="$specular")//todo load this values: + { + } + if(Line=="$diffuse") + { + } + if(Line=="$ambient") + { + } + if(Line=="$colormap") + { + ss >> Line; + NewMaterial->AddProperty(&aiString(Line.c_str()), AI_MATKEY_TEXTURE(aiTextureType_DIFFUSE, 0)); + } + if(Line=="$normalmap") + { + ss >> Line; + NewMaterial->AddProperty(&aiString(Line.c_str()), AI_MATKEY_TEXTURE(aiTextureType_NORMALS, 0)); + } + } }//end of material } else {} //this is the wrong material, proceed the file until we reach the next material diff --git a/doc/dox.h b/doc/dox.h index 566bffbe2..d65afe9ad 100644 --- a/doc/dox.h +++ b/doc/dox.h @@ -804,6 +804,9 @@ DefaultLogger::create("AssimpLog.txt",Logger::VERBOSE) Implement the Assimp::BaseImporter::CanRead(), Assimp::BaseImporter::InternReadFile() and Assimp::BaseImporter::GetExtensionList(). Just copy'n'paste the template from Appendix A and adapt it for your needs. +
  • For error handling, throw a dynamic allocated ImportErrorException (see Appendix A) for critical errors, and log errors, warnings, infos and debuginfos +with DefaultLogger::get()->[error, warn, debug, info]. +
  • Make sure the loader compiles against all build configurations on all supported platforms. This includes -noboost! To avoid problems, see the boost section on this page for a list of all 'allowed' boost classes (again, this grew historically when we had to accept that boost @@ -1429,12 +1432,18 @@ the name of the material file. This is especially usefull if multiply materials The importer will first try to load the material with the same name as the mesh and only if this can't be open try to load the alternate material file. The default material filename is "Scene.material". +We suggest that you use custom materials, because they support multiple textures (like colormap and normalmap). First of all you +should read the custom material sektion in the Ogre Blender exporter Help File, and than use the assimp.tlp template, which you +can find in scripts/OgreImpoter/Assimp.tlp. If you don't set all values, don't worry, they will be ignored during import. + +If you want more propertiesin custom materials, you can easily expand the ogre material loader, it will be just a few lines for each property. + What will be loaded? Mesh: Faces, Positions, Normals and one Uv pair. The Materialname will be used to load the material Material: The right material in the file will be searched, the importer should work with materials who -have 1 technique and 1 pass in this technique. From there, the texturename will be loaded. Also, the +have 1 technique and 1 pass in this technique. From there, the texturename (for 1 color- and 1 normalmap) will be loaded. Also, the materialname will be set. Skeleton: Nothing, yet. diff --git a/scripts/OgreImporter/assimp.tpl b/scripts/OgreImporter/assimp.tpl new file mode 100644 index 000000000..a7954c7f1 --- /dev/null +++ b/scripts/OgreImporter/assimp.tpl @@ -0,0 +1,10 @@ + +material %_materialName +{ + set $specular %_specular + set $diffuse %_diffuse + set $ambient %_ambient + + set $colormap %color._texture + set $normalmap %normal._texture +}