2008-05-09 17:24:28 +00:00
|
|
|
/*
|
|
|
|
---------------------------------------------------------------------------
|
2012-02-03 03:38:30 +00:00
|
|
|
Open Asset Import Library (assimp)
|
2008-05-09 17:24:28 +00:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
2012-02-03 03:38:30 +00:00
|
|
|
Copyright (c) 2006-2012, assimp team
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use of this software in source and binary forms,
|
|
|
|
with or without modification, are permitted provided that the following
|
|
|
|
conditions are met:
|
|
|
|
|
|
|
|
* Redistributions of source code must retain the above
|
|
|
|
copyright notice, this list of conditions and the
|
|
|
|
following disclaimer.
|
|
|
|
|
|
|
|
* Redistributions in binary form must reproduce the above
|
|
|
|
copyright notice, this list of conditions and the
|
|
|
|
following disclaimer in the documentation and/or other
|
|
|
|
materials provided with the distribution.
|
|
|
|
|
2012-02-03 03:38:30 +00:00
|
|
|
* Neither the name of the assimp team, nor the names of its
|
2008-05-09 17:24:28 +00:00
|
|
|
contributors may be used to endorse or promote products
|
|
|
|
derived from this software without specific prior
|
2012-02-03 03:38:30 +00:00
|
|
|
written permission of the assimp team.
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2009-01-18 23:48:25 +00:00
|
|
|
/** @file PlyLoader.cpp
|
|
|
|
* @brief Implementation of the PLY importer class
|
|
|
|
*/
|
2008-08-28 17:35:36 +00:00
|
|
|
|
2008-10-13 16:45:48 +00:00
|
|
|
#include "AssimpPCH.h"
|
2009-01-18 23:48:25 +00:00
|
|
|
#ifndef ASSIMP_BUILD_NO_PLY_IMPORTER
|
2008-10-13 16:45:48 +00:00
|
|
|
|
2008-08-28 17:35:36 +00:00
|
|
|
// internal headers
|
2008-05-27 18:58:36 +00:00
|
|
|
#include "PlyLoader.h"
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
using namespace Assimp;
|
|
|
|
|
2012-04-22 22:26:26 +00:00
|
|
|
static const aiImporterDesc desc = {
|
|
|
|
"Stanford Polygon Library (PLY) Importer",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
aiImporterFlags_SupportBinaryFlavour | aiImporterFlags_SupportTextFlavour,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
"ply"
|
|
|
|
};
|
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Constructor to be privately used by Importer
|
|
|
|
PLYImporter::PLYImporter()
|
2009-01-18 23:48:25 +00:00
|
|
|
{}
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Destructor, private as well
|
|
|
|
PLYImporter::~PLYImporter()
|
2009-01-18 23:48:25 +00:00
|
|
|
{}
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Returns whether the class can handle the format of the given file.
|
General
- Added format auto-detection to most loaders
- Simplified BaseImporter::CanRead() with some utility methods
- improved fast_atof -> no overruns anymore. Fuck you, irrlicht.
- added assimp_cmd tool to allow command line model processing. Mainly adebugging tool for internal purposes, but others might find it useful, too.
- vc8/vc9: revision number is now written to DLL version header
- mkutil: some batch scripts to simplify tagging & building of release versions
- some API cleanup
- fixing some doxygen markup (+now explicit use of @file <filename>)
- Icon for assimp_view and assimp_cmd
3DS
- Normal vectors are not anymore inverted in some cases
- Improved pivot handling
- Improved handling of x-flipped meshes
Collada
- fixed a minor bug (visual_scene element)
LWS
- WIP implementation. No animations yet, some bugs and crashes.
- Animation system remains disabled, WIP code
- many test files for LWS, but most of them test the anim support, which is, read above, currently disabled.
STL
- fixing a log warning which appears for every model
- added binary&ascii test spider, exported from truespace
MD3
- Cleaning up output tags for automatically joined player models.
IRR
- Fixing coordinate system issues.
- Instance handling improved.
- Some of the reported crashes not yet fixed.
PretransformVertices
- Numerous performance improvements.
- Added config option to preserve the hierarchy during the step.
RemoveRedundantMaterials
- Added config option to specify a list of materials which are kept in every case.
UNREAL
- Added support for the old unreal data format (*.a,*.d,*.uc)
- tested only with exports from Milkshape
- more Unreal stuff to come soon
git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@356 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
2009-03-05 22:32:13 +00:00
|
|
|
bool PLYImporter::CanRead( const std::string& pFile, IOSystem* pIOHandler, bool checkSig) const
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
General
- Added format auto-detection to most loaders
- Simplified BaseImporter::CanRead() with some utility methods
- improved fast_atof -> no overruns anymore. Fuck you, irrlicht.
- added assimp_cmd tool to allow command line model processing. Mainly adebugging tool for internal purposes, but others might find it useful, too.
- vc8/vc9: revision number is now written to DLL version header
- mkutil: some batch scripts to simplify tagging & building of release versions
- some API cleanup
- fixing some doxygen markup (+now explicit use of @file <filename>)
- Icon for assimp_view and assimp_cmd
3DS
- Normal vectors are not anymore inverted in some cases
- Improved pivot handling
- Improved handling of x-flipped meshes
Collada
- fixed a minor bug (visual_scene element)
LWS
- WIP implementation. No animations yet, some bugs and crashes.
- Animation system remains disabled, WIP code
- many test files for LWS, but most of them test the anim support, which is, read above, currently disabled.
STL
- fixing a log warning which appears for every model
- added binary&ascii test spider, exported from truespace
MD3
- Cleaning up output tags for automatically joined player models.
IRR
- Fixing coordinate system issues.
- Instance handling improved.
- Some of the reported crashes not yet fixed.
PretransformVertices
- Numerous performance improvements.
- Added config option to preserve the hierarchy during the step.
RemoveRedundantMaterials
- Added config option to specify a list of materials which are kept in every case.
UNREAL
- Added support for the old unreal data format (*.a,*.d,*.uc)
- tested only with exports from Milkshape
- more Unreal stuff to come soon
git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@356 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
2009-03-05 22:32:13 +00:00
|
|
|
const std::string extension = GetExtension(pFile);
|
|
|
|
|
|
|
|
if (extension == "ply")
|
|
|
|
return true;
|
|
|
|
else if (!extension.length() || checkSig)
|
|
|
|
{
|
|
|
|
if (!pIOHandler)return true;
|
|
|
|
const char* tokens[] = {"ply"};
|
|
|
|
return SearchFileHeaderForToken(pIOHandler,pFile,tokens,1);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2012-04-22 22:26:26 +00:00
|
|
|
const aiImporterDesc* PLYImporter::GetInfo () const
|
General
- Added format auto-detection to most loaders
- Simplified BaseImporter::CanRead() with some utility methods
- improved fast_atof -> no overruns anymore. Fuck you, irrlicht.
- added assimp_cmd tool to allow command line model processing. Mainly adebugging tool for internal purposes, but others might find it useful, too.
- vc8/vc9: revision number is now written to DLL version header
- mkutil: some batch scripts to simplify tagging & building of release versions
- some API cleanup
- fixing some doxygen markup (+now explicit use of @file <filename>)
- Icon for assimp_view and assimp_cmd
3DS
- Normal vectors are not anymore inverted in some cases
- Improved pivot handling
- Improved handling of x-flipped meshes
Collada
- fixed a minor bug (visual_scene element)
LWS
- WIP implementation. No animations yet, some bugs and crashes.
- Animation system remains disabled, WIP code
- many test files for LWS, but most of them test the anim support, which is, read above, currently disabled.
STL
- fixing a log warning which appears for every model
- added binary&ascii test spider, exported from truespace
MD3
- Cleaning up output tags for automatically joined player models.
IRR
- Fixing coordinate system issues.
- Instance handling improved.
- Some of the reported crashes not yet fixed.
PretransformVertices
- Numerous performance improvements.
- Added config option to preserve the hierarchy during the step.
RemoveRedundantMaterials
- Added config option to specify a list of materials which are kept in every case.
UNREAL
- Added support for the old unreal data format (*.a,*.d,*.uc)
- tested only with exports from Milkshape
- more Unreal stuff to come soon
git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@356 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
2009-03-05 22:32:13 +00:00
|
|
|
{
|
2012-04-22 22:26:26 +00:00
|
|
|
return &desc;
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
2009-01-18 23:48:25 +00:00
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
// Imports the given file into the given scene structure.
|
2009-08-21 22:49:58 +00:00
|
|
|
void PLYImporter::InternReadFile( const std::string& pFile,
|
|
|
|
aiScene* pScene, IOSystem* pIOHandler)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
boost::scoped_ptr<IOStream> file( pIOHandler->Open( pFile));
|
|
|
|
|
|
|
|
// Check whether we can read from the file
|
2009-08-21 22:49:58 +00:00
|
|
|
if( file.get() == NULL) {
|
2010-03-18 17:00:12 +00:00
|
|
|
throw DeadlyImportError( "Failed to open PLY file " + pFile + ".");
|
2009-08-21 22:49:58 +00:00
|
|
|
}
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
// allocate storage and copy the contents of the file to a memory buffer
|
2009-08-21 22:49:58 +00:00
|
|
|
std::vector<char> mBuffer2;
|
|
|
|
TextFileToBuffer(file.get(),mBuffer2);
|
|
|
|
mBuffer = (unsigned char*)&mBuffer2[0];
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2009-01-18 23:48:25 +00:00
|
|
|
// the beginning of the file must be PLY - magic, magic
|
2010-02-06 23:52:41 +00:00
|
|
|
if ((mBuffer[0] != 'P' && mBuffer[0] != 'p') ||
|
|
|
|
(mBuffer[1] != 'L' && mBuffer[1] != 'l') ||
|
|
|
|
(mBuffer[2] != 'Y' && mBuffer[2] != 'y')) {
|
2010-03-18 17:00:12 +00:00
|
|
|
throw DeadlyImportError( "Invalid .ply file: Magic number \'ply\' is no there");
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
2009-01-18 23:48:25 +00:00
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
char* szMe = (char*)&this->mBuffer[3];
|
|
|
|
SkipSpacesAndLineEnd(szMe,(const char**)&szMe);
|
|
|
|
|
|
|
|
// determine the format of the file data
|
|
|
|
PLY::DOM sPlyDom;
|
2008-10-13 16:45:48 +00:00
|
|
|
if (TokenMatch(szMe,"format",6))
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
if (TokenMatch(szMe,"ascii",5))
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
SkipLine(szMe,(const char**)&szMe);
|
2008-07-10 16:49:01 +00:00
|
|
|
if(!PLY::DOM::ParseInstance(szMe,&sPlyDom))
|
2010-03-18 17:00:12 +00:00
|
|
|
throw DeadlyImportError( "Invalid .ply file: Unable to build DOM (#1)");
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
else if (!::strncmp(szMe,"binary_",7))
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
bool bIsBE = false;
|
2008-10-13 16:45:48 +00:00
|
|
|
szMe+=7;
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
// binary_little_endian
|
|
|
|
// binary_big_endian
|
|
|
|
#if (defined AI_BUILD_BIG_ENDIAN)
|
|
|
|
if ('l' == *szMe || 'L' == *szMe)bIsBE = true;
|
|
|
|
#else
|
|
|
|
if ('b' == *szMe || 'B' == *szMe)bIsBE = true;
|
|
|
|
#endif // ! AI_BUILD_BIG_ENDIAN
|
|
|
|
|
|
|
|
// skip the line, parse the rest of the header and build the DOM
|
|
|
|
SkipLine(szMe,(const char**)&szMe);
|
2008-07-10 16:49:01 +00:00
|
|
|
if(!PLY::DOM::ParseInstanceBinary(szMe,&sPlyDom,bIsBE))
|
2010-03-18 17:00:12 +00:00
|
|
|
throw DeadlyImportError( "Invalid .ply file: Unable to build DOM (#2)");
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
2010-03-18 17:00:12 +00:00
|
|
|
else throw DeadlyImportError( "Invalid .ply file: Unknown file format");
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-08-07 20:52:25 +00:00
|
|
|
AI_DEBUG_INVALIDATE_PTR(this->mBuffer);
|
2010-03-18 17:00:12 +00:00
|
|
|
throw DeadlyImportError( "Invalid .ply file: Missing format specification");
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
|
|
|
this->pcDOM = &sPlyDom;
|
|
|
|
|
|
|
|
// now load a list of vertices. This must be sucessfull in order to procede
|
|
|
|
std::vector<aiVector3D> avPositions;
|
|
|
|
this->LoadVertices(&avPositions,false);
|
|
|
|
|
|
|
|
if (avPositions.empty())
|
2010-03-18 17:00:12 +00:00
|
|
|
throw DeadlyImportError( "Invalid .ply file: No vertices found. "
|
2008-08-28 17:35:36 +00:00
|
|
|
"Unable to parse the data format of the PLY file.");
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
// now load a list of normals.
|
|
|
|
std::vector<aiVector3D> avNormals;
|
2009-01-18 23:48:25 +00:00
|
|
|
LoadVertices(&avNormals,true);
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
// load the face list
|
|
|
|
std::vector<PLY::Face> avFaces;
|
2009-01-18 23:48:25 +00:00
|
|
|
LoadFaces(&avFaces);
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
// if no face list is existing we assume that the vertex
|
|
|
|
// list is containing a list of triangles
|
|
|
|
if (avFaces.empty())
|
|
|
|
{
|
|
|
|
if (avPositions.size() < 3)
|
|
|
|
{
|
2010-03-18 17:00:12 +00:00
|
|
|
throw DeadlyImportError( "Invalid .ply file: Not enough "
|
2009-01-18 23:48:25 +00:00
|
|
|
"vertices to build a proper face list. ");
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
|
|
|
|
2009-01-18 23:48:25 +00:00
|
|
|
const unsigned int iNum = (unsigned int)avPositions.size() / 3;
|
2008-05-05 12:36:31 +00:00
|
|
|
for (unsigned int i = 0; i< iNum;++i)
|
|
|
|
{
|
|
|
|
PLY::Face sFace;
|
|
|
|
sFace.mIndices.push_back((iNum*3));
|
|
|
|
sFace.mIndices.push_back((iNum*3)+1);
|
|
|
|
sFace.mIndices.push_back((iNum*3)+2);
|
|
|
|
avFaces.push_back(sFace);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// now load a list of all materials
|
2011-08-22 20:22:51 +00:00
|
|
|
std::vector<aiMaterial*> avMaterials;
|
2009-01-18 23:48:25 +00:00
|
|
|
LoadMaterial(&avMaterials);
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
// now load a list of all vertex color channels
|
|
|
|
std::vector<aiColor4D> avColors;
|
2009-01-18 23:48:25 +00:00
|
|
|
avColors.reserve(avPositions.size());
|
|
|
|
LoadVertexColor(&avColors);
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
// now try to load texture coordinates
|
|
|
|
std::vector<aiVector2D> avTexCoords;
|
2009-01-18 23:48:25 +00:00
|
|
|
avTexCoords.reserve(avPositions.size());
|
|
|
|
LoadTextureCoordinates(&avTexCoords);
|
2008-05-09 17:24:28 +00:00
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
// now replace the default material in all faces and validate all material indices
|
2009-01-18 23:48:25 +00:00
|
|
|
ReplaceDefaultMaterial(&avFaces,&avMaterials);
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
// now convert this to a list of aiMesh instances
|
|
|
|
std::vector<aiMesh*> avMeshes;
|
2009-01-18 23:48:25 +00:00
|
|
|
avMeshes.reserve(avMaterials.size()+1);
|
|
|
|
ConvertMeshes(&avFaces,&avPositions,&avNormals,
|
2008-05-09 17:24:28 +00:00
|
|
|
&avColors,&avTexCoords,&avMaterials,&avMeshes);
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
if (avMeshes.empty())
|
2010-03-18 17:00:12 +00:00
|
|
|
throw DeadlyImportError( "Invalid .ply file: Unable to extract mesh data ");
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
// now generate the output scene object. Fill the material list
|
2008-06-01 12:46:17 +00:00
|
|
|
pScene->mNumMaterials = (unsigned int)avMaterials.size();
|
2008-05-05 12:36:31 +00:00
|
|
|
pScene->mMaterials = new aiMaterial*[pScene->mNumMaterials];
|
|
|
|
for (unsigned int i = 0; i < pScene->mNumMaterials;++i)
|
|
|
|
pScene->mMaterials[i] = avMaterials[i];
|
|
|
|
|
|
|
|
// fill the mesh list
|
2008-06-01 12:46:17 +00:00
|
|
|
pScene->mNumMeshes = (unsigned int)avMeshes.size();
|
2008-05-05 12:36:31 +00:00
|
|
|
pScene->mMeshes = new aiMesh*[pScene->mNumMeshes];
|
|
|
|
for (unsigned int i = 0; i < pScene->mNumMeshes;++i)
|
|
|
|
pScene->mMeshes[i] = avMeshes[i];
|
|
|
|
|
|
|
|
// generate a simple node structure
|
|
|
|
pScene->mRootNode = new aiNode();
|
|
|
|
pScene->mRootNode->mNumMeshes = pScene->mNumMeshes;
|
|
|
|
pScene->mRootNode->mMeshes = new unsigned int[pScene->mNumMeshes];
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < pScene->mRootNode->mNumMeshes;++i)
|
|
|
|
pScene->mRootNode->mMeshes[i] = i;
|
|
|
|
}
|
2009-01-18 23:48:25 +00:00
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2009-01-18 23:48:25 +00:00
|
|
|
// Split meshes by material IDs
|
2008-05-05 12:36:31 +00:00
|
|
|
void PLYImporter::ConvertMeshes(std::vector<PLY::Face>* avFaces,
|
|
|
|
const std::vector<aiVector3D>* avPositions,
|
|
|
|
const std::vector<aiVector3D>* avNormals,
|
|
|
|
const std::vector<aiColor4D>* avColors,
|
2008-05-09 17:24:28 +00:00
|
|
|
const std::vector<aiVector2D>* avTexCoords,
|
2011-08-22 20:22:51 +00:00
|
|
|
const std::vector<aiMaterial*>* avMaterials,
|
2008-05-05 12:36:31 +00:00
|
|
|
std::vector<aiMesh*>* avOut)
|
|
|
|
{
|
|
|
|
ai_assert(NULL != avFaces);
|
|
|
|
ai_assert(NULL != avPositions);
|
|
|
|
ai_assert(NULL != avMaterials);
|
|
|
|
|
|
|
|
// split by materials
|
2009-01-18 23:48:25 +00:00
|
|
|
std::vector<unsigned int>* aiSplit = new std::vector<unsigned int>[avMaterials->size()];
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
unsigned int iNum = 0;
|
2009-01-18 23:48:25 +00:00
|
|
|
for (std::vector<PLY::Face>::const_iterator i = avFaces->begin();i != avFaces->end();++i,++iNum)
|
2008-05-05 12:36:31 +00:00
|
|
|
aiSplit[(*i).iMaterialIndex].push_back(iNum);
|
2009-01-18 23:48:25 +00:00
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
// now generate submeshes
|
|
|
|
for (unsigned int p = 0; p < avMaterials->size();++p)
|
|
|
|
{
|
|
|
|
if (aiSplit[p].size() != 0)
|
|
|
|
{
|
|
|
|
// allocate the mesh object
|
|
|
|
aiMesh* p_pcOut = new aiMesh();
|
|
|
|
p_pcOut->mMaterialIndex = p;
|
|
|
|
|
2008-06-01 12:46:17 +00:00
|
|
|
p_pcOut->mNumFaces = (unsigned int)aiSplit[p].size();
|
2008-05-05 12:36:31 +00:00
|
|
|
p_pcOut->mFaces = new aiFace[aiSplit[p].size()];
|
|
|
|
|
|
|
|
// at first we need to determine the size of the output vector array
|
|
|
|
unsigned int iNum = 0;
|
|
|
|
for (unsigned int i = 0; i < aiSplit[p].size();++i)
|
|
|
|
{
|
2008-06-01 12:46:17 +00:00
|
|
|
iNum += (unsigned int)(*avFaces)[aiSplit[p][i]].mIndices.size();
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
|
|
|
p_pcOut->mNumVertices = iNum;
|
|
|
|
p_pcOut->mVertices = new aiVector3D[iNum];
|
|
|
|
|
|
|
|
if (!avColors->empty())
|
|
|
|
p_pcOut->mColors[0] = new aiColor4D[iNum];
|
2008-05-09 17:24:28 +00:00
|
|
|
if (!avTexCoords->empty())
|
|
|
|
{
|
|
|
|
p_pcOut->mNumUVComponents[0] = 2;
|
|
|
|
p_pcOut->mTextureCoords[0] = new aiVector3D[iNum];
|
|
|
|
}
|
2008-05-05 12:36:31 +00:00
|
|
|
if (!avNormals->empty())
|
|
|
|
p_pcOut->mNormals = new aiVector3D[iNum];
|
|
|
|
|
|
|
|
// add all faces
|
|
|
|
iNum = 0;
|
|
|
|
unsigned int iVertex = 0;
|
2009-01-18 23:48:25 +00:00
|
|
|
for (std::vector<unsigned int>::const_iterator i = aiSplit[p].begin();
|
2008-05-05 12:36:31 +00:00
|
|
|
i != aiSplit[p].end();++i,++iNum)
|
|
|
|
{
|
2008-06-01 12:46:17 +00:00
|
|
|
p_pcOut->mFaces[iNum].mNumIndices = (unsigned int)(*avFaces)[*i].mIndices.size();
|
2008-05-05 12:36:31 +00:00
|
|
|
p_pcOut->mFaces[iNum].mIndices = new unsigned int[p_pcOut->mFaces[iNum].mNumIndices];
|
|
|
|
|
|
|
|
// build an unique set of vertices/colors for this face
|
2008-05-09 17:24:28 +00:00
|
|
|
for (unsigned int q = 0; q < p_pcOut->mFaces[iNum].mNumIndices;++q)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
2008-05-09 17:24:28 +00:00
|
|
|
p_pcOut->mFaces[iNum].mIndices[q] = iVertex;
|
|
|
|
p_pcOut->mVertices[iVertex] = (*avPositions)[(*avFaces)[*i].mIndices[q]];
|
|
|
|
|
|
|
|
if (!avColors->empty())
|
|
|
|
p_pcOut->mColors[0][iVertex] = (*avColors)[(*avFaces)[*i].mIndices[q]];
|
|
|
|
|
|
|
|
if (!avTexCoords->empty())
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
2008-05-09 17:24:28 +00:00
|
|
|
const aiVector2D& vec = (*avTexCoords)[(*avFaces)[*i].mIndices[q]];
|
|
|
|
p_pcOut->mTextureCoords[0][iVertex].x = vec.x;
|
|
|
|
p_pcOut->mTextureCoords[0][iVertex].y = vec.y;
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
2008-05-09 17:24:28 +00:00
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
if (!avNormals->empty())
|
2008-05-09 17:24:28 +00:00
|
|
|
p_pcOut->mNormals[iVertex] = (*avNormals)[(*avFaces)[*i].mIndices[q]];
|
|
|
|
iVertex++;
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
2008-05-09 17:24:28 +00:00
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
|
|
|
// add the mesh to the output list
|
|
|
|
avOut->push_back(p_pcOut);
|
|
|
|
}
|
|
|
|
}
|
2009-01-18 23:48:25 +00:00
|
|
|
delete[] aiSplit; // cleanup
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
2009-01-18 23:48:25 +00:00
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2009-01-18 23:48:25 +00:00
|
|
|
// Generate a default material if none was specified and apply it to all vanilla faces
|
2008-05-05 12:36:31 +00:00
|
|
|
void PLYImporter::ReplaceDefaultMaterial(std::vector<PLY::Face>* avFaces,
|
2011-08-22 20:22:51 +00:00
|
|
|
std::vector<aiMaterial*>* avMaterials)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
bool bNeedDefaultMat = false;
|
|
|
|
|
2009-03-15 00:40:30 +00:00
|
|
|
for (std::vector<PLY::Face>::iterator i = avFaces->begin();i != avFaces->end();++i) {
|
|
|
|
if (0xFFFFFFFF == (*i).iMaterialIndex) {
|
2008-05-05 12:36:31 +00:00
|
|
|
bNeedDefaultMat = true;
|
2008-06-01 12:46:17 +00:00
|
|
|
(*i).iMaterialIndex = (unsigned int)avMaterials->size();
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
2009-03-15 00:40:30 +00:00
|
|
|
else if ((*i).iMaterialIndex >= avMaterials->size() ) {
|
2008-05-05 12:36:31 +00:00
|
|
|
// clamp the index
|
2008-06-01 12:46:17 +00:00
|
|
|
(*i).iMaterialIndex = (unsigned int)avMaterials->size()-1;
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-15 00:40:30 +00:00
|
|
|
if (bNeedDefaultMat) {
|
2008-05-05 12:36:31 +00:00
|
|
|
// generate a default material
|
2011-08-22 20:22:51 +00:00
|
|
|
aiMaterial* pcHelper = new aiMaterial();
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
// fill in a default material
|
|
|
|
int iMode = (int)aiShadingMode_Gouraud;
|
|
|
|
pcHelper->AddProperty<int>(&iMode, 1, AI_MATKEY_SHADING_MODEL);
|
|
|
|
|
|
|
|
aiColor3D clr;
|
|
|
|
clr.b = clr.g = clr.r = 0.6f;
|
|
|
|
pcHelper->AddProperty<aiColor3D>(&clr, 1,AI_MATKEY_COLOR_DIFFUSE);
|
|
|
|
pcHelper->AddProperty<aiColor3D>(&clr, 1,AI_MATKEY_COLOR_SPECULAR);
|
|
|
|
|
|
|
|
clr.b = clr.g = clr.r = 0.05f;
|
|
|
|
pcHelper->AddProperty<aiColor3D>(&clr, 1,AI_MATKEY_COLOR_AMBIENT);
|
|
|
|
|
2009-03-15 00:40:30 +00:00
|
|
|
// The face order is absolutely undefined for PLY, so we have to
|
|
|
|
// use two-sided rendering to be sure it's ok.
|
|
|
|
const int two_sided = 1;
|
|
|
|
pcHelper->AddProperty(&two_sided,1,AI_MATKEY_TWOSIDED);
|
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
avMaterials->push_back(pcHelper);
|
|
|
|
}
|
|
|
|
}
|
2009-01-18 23:48:25 +00:00
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2008-05-09 17:24:28 +00:00
|
|
|
void PLYImporter::LoadTextureCoordinates(std::vector<aiVector2D>* pvOut)
|
|
|
|
{
|
|
|
|
ai_assert(NULL != pvOut);
|
|
|
|
|
|
|
|
unsigned int aiPositions[2] = {0xFFFFFFFF,0xFFFFFFFF};
|
2010-02-06 23:52:41 +00:00
|
|
|
PLY::EDataType aiTypes[2] = {EDT_Char,EDT_Char};
|
2008-05-09 17:24:28 +00:00
|
|
|
PLY::ElementInstanceList* pcList = NULL;
|
|
|
|
unsigned int cnt = 0;
|
|
|
|
|
|
|
|
// serach in the DOM for a vertex entry
|
|
|
|
unsigned int _i = 0;
|
2009-01-18 23:48:25 +00:00
|
|
|
for (std::vector<PLY::Element>::const_iterator i = pcDOM->alElements.begin();
|
|
|
|
i != pcDOM->alElements.end();++i,++_i)
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
if (PLY::EEST_Vertex == (*i).eSemantic)
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
pcList = &this->pcDOM->alElementData[_i];
|
2008-05-09 17:24:28 +00:00
|
|
|
|
|
|
|
// now check whether which normal components are available
|
|
|
|
unsigned int _a = 0;
|
2009-01-18 23:48:25 +00:00
|
|
|
for (std::vector<PLY::Property>::const_iterator a = (*i).alProperties.begin();
|
2008-10-13 16:45:48 +00:00
|
|
|
a != (*i).alProperties.end();++a,++_a)
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
if ((*a).bIsList)continue;
|
|
|
|
if (PLY::EST_UTextureCoord == (*a).Semantic)
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
|
|
|
cnt++;
|
|
|
|
aiPositions[0] = _a;
|
2008-10-13 16:45:48 +00:00
|
|
|
aiTypes[0] = (*a).eType;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
else if (PLY::EST_VTextureCoord == (*a).Semantic)
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
|
|
|
cnt++;
|
|
|
|
aiPositions[1] = _a;
|
2008-10-13 16:45:48 +00:00
|
|
|
aiTypes[1] = (*a).eType;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// check whether we have a valid source for the texture coordinates data
|
|
|
|
if (NULL != pcList && 0 != cnt)
|
|
|
|
{
|
|
|
|
pvOut->reserve(pcList->alInstances.size());
|
2009-01-18 23:48:25 +00:00
|
|
|
for (std::vector<ElementInstance>::const_iterator i = pcList->alInstances.begin();
|
2008-05-09 17:24:28 +00:00
|
|
|
i != pcList->alInstances.end();++i)
|
|
|
|
{
|
|
|
|
// convert the vertices to sp floats
|
|
|
|
aiVector2D vOut;
|
|
|
|
|
|
|
|
if (0xFFFFFFFF != aiPositions[0])
|
|
|
|
{
|
|
|
|
vOut.x = PLY::PropertyInstance::ConvertTo<float>(
|
2008-10-13 16:45:48 +00:00
|
|
|
(*i).alProperties[aiPositions[0]].avList.front(),aiTypes[0]);
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (0xFFFFFFFF != aiPositions[1])
|
|
|
|
{
|
|
|
|
vOut.y = PLY::PropertyInstance::ConvertTo<float>(
|
2008-10-13 16:45:48 +00:00
|
|
|
(*i).alProperties[aiPositions[1]].avList.front(),aiTypes[1]);
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
|
|
|
// and add them to our nice list
|
|
|
|
pvOut->push_back(vOut);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-01-18 23:48:25 +00:00
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2009-01-18 23:48:25 +00:00
|
|
|
// Try to extract vertices from the PLY DOM
|
2008-05-05 12:36:31 +00:00
|
|
|
void PLYImporter::LoadVertices(std::vector<aiVector3D>* pvOut, bool p_bNormals)
|
|
|
|
{
|
2008-05-09 17:24:28 +00:00
|
|
|
ai_assert(NULL != pvOut);
|
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
unsigned int aiPositions[3] = {0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF};
|
2010-02-06 23:52:41 +00:00
|
|
|
PLY::EDataType aiTypes[3] = {EDT_Char,EDT_Char,EDT_Char};
|
2008-05-05 12:36:31 +00:00
|
|
|
PLY::ElementInstanceList* pcList = NULL;
|
|
|
|
unsigned int cnt = 0;
|
|
|
|
|
|
|
|
// serach in the DOM for a vertex entry
|
|
|
|
unsigned int _i = 0;
|
2009-01-18 23:48:25 +00:00
|
|
|
for (std::vector<PLY::Element>::const_iterator i = pcDOM->alElements.begin();
|
|
|
|
i != pcDOM->alElements.end();++i,++_i)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
if (PLY::EEST_Vertex == (*i).eSemantic)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
2009-01-18 23:48:25 +00:00
|
|
|
pcList = &pcDOM->alElementData[_i];
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
// load normal vectors?
|
|
|
|
if (p_bNormals)
|
|
|
|
{
|
|
|
|
// now check whether which normal components are available
|
|
|
|
unsigned int _a = 0;
|
2009-01-18 23:48:25 +00:00
|
|
|
for (std::vector<PLY::Property>::const_iterator a = (*i).alProperties.begin();
|
2008-10-13 16:45:48 +00:00
|
|
|
a != (*i).alProperties.end();++a,++_a)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
if ((*a).bIsList)continue;
|
|
|
|
if (PLY::EST_XNormal == (*a).Semantic)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
cnt++;
|
|
|
|
aiPositions[0] = _a;
|
2008-10-13 16:45:48 +00:00
|
|
|
aiTypes[0] = (*a).eType;
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
else if (PLY::EST_YNormal == (*a).Semantic)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
cnt++;
|
|
|
|
aiPositions[1] = _a;
|
2008-10-13 16:45:48 +00:00
|
|
|
aiTypes[1] = (*a).eType;
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
else if (PLY::EST_ZNormal == (*a).Semantic)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
cnt++;
|
|
|
|
aiPositions[2] = _a;
|
2008-10-13 16:45:48 +00:00
|
|
|
aiTypes[2] = (*a).eType;
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// load vertex coordinates
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// now check whether which coordinate sets are available
|
|
|
|
unsigned int _a = 0;
|
2009-01-18 23:48:25 +00:00
|
|
|
for (std::vector<PLY::Property>::const_iterator a = (*i).alProperties.begin();
|
2008-10-13 16:45:48 +00:00
|
|
|
a != (*i).alProperties.end();++a,++_a)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
if ((*a).bIsList)continue;
|
|
|
|
if (PLY::EST_XCoord == (*a).Semantic)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
cnt++;
|
|
|
|
aiPositions[0] = _a;
|
2008-10-13 16:45:48 +00:00
|
|
|
aiTypes[0] = (*a).eType;
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
else if (PLY::EST_YCoord == (*a).Semantic)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
cnt++;
|
|
|
|
aiPositions[1] = _a;
|
2008-10-13 16:45:48 +00:00
|
|
|
aiTypes[1] = (*a).eType;
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
else if (PLY::EST_ZCoord == (*a).Semantic)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
cnt++;
|
|
|
|
aiPositions[2] = _a;
|
2008-10-13 16:45:48 +00:00
|
|
|
aiTypes[2] = (*a).eType;
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
|
|
|
if (3 == cnt)break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// check whether we have a valid source for the vertex data
|
|
|
|
if (NULL != pcList && 0 != cnt)
|
|
|
|
{
|
|
|
|
pvOut->reserve(pcList->alInstances.size());
|
2008-10-13 16:45:48 +00:00
|
|
|
for (std::vector<ElementInstance>::const_iterator
|
2008-05-05 12:36:31 +00:00
|
|
|
i = pcList->alInstances.begin();
|
|
|
|
i != pcList->alInstances.end();++i)
|
|
|
|
{
|
|
|
|
// convert the vertices to sp floats
|
|
|
|
aiVector3D vOut;
|
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
if (0xFFFFFFFF != aiPositions[0])
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
vOut.x = PLY::PropertyInstance::ConvertTo<float>(
|
2008-10-13 16:45:48 +00:00
|
|
|
(*i).alProperties[aiPositions[0]].avList.front(),aiTypes[0]);
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
if (0xFFFFFFFF != aiPositions[1])
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
vOut.y = PLY::PropertyInstance::ConvertTo<float>(
|
2008-10-13 16:45:48 +00:00
|
|
|
(*i).alProperties[aiPositions[1]].avList.front(),aiTypes[1]);
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
if (0xFFFFFFFF != aiPositions[2])
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
vOut.z = PLY::PropertyInstance::ConvertTo<float>(
|
2008-10-13 16:45:48 +00:00
|
|
|
(*i).alProperties[aiPositions[2]].avList.front(),aiTypes[2]);
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// and add them to our nice list
|
|
|
|
pvOut->push_back(vOut);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-01-18 23:48:25 +00:00
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2009-01-18 23:48:25 +00:00
|
|
|
// Convert a color component to [0...1]
|
2008-05-09 17:24:28 +00:00
|
|
|
float PLYImporter::NormalizeColorValue (PLY::PropertyInstance::ValueUnion val,
|
|
|
|
PLY::EDataType eType)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
switch (eType)
|
|
|
|
{
|
|
|
|
case EDT_Float:
|
|
|
|
return val.fFloat;
|
|
|
|
case EDT_Double:
|
|
|
|
return (float)val.fDouble;
|
|
|
|
|
|
|
|
case EDT_UChar:
|
|
|
|
return (float)val.iUInt / (float)0xFF;
|
|
|
|
case EDT_Char:
|
|
|
|
return (float)(val.iInt+(0xFF/2)) / (float)0xFF;
|
|
|
|
case EDT_UShort:
|
|
|
|
return (float)val.iUInt / (float)0xFFFF;
|
|
|
|
case EDT_Short:
|
|
|
|
return (float)(val.iInt+(0xFFFF/2)) / (float)0xFFFF;
|
|
|
|
case EDT_UInt:
|
|
|
|
return (float)val.iUInt / (float)0xFFFF;
|
|
|
|
case EDT_Int:
|
|
|
|
return ((float)val.iInt / (float)0xFF) + 0.5f;
|
2008-09-12 20:25:11 +00:00
|
|
|
default: ;
|
2008-05-05 12:36:31 +00:00
|
|
|
};
|
|
|
|
return 0.0f;
|
|
|
|
}
|
2009-01-18 23:48:25 +00:00
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2009-01-18 23:48:25 +00:00
|
|
|
// Try to extract proper vertex colors from the PLY DOM
|
2008-05-05 12:36:31 +00:00
|
|
|
void PLYImporter::LoadVertexColor(std::vector<aiColor4D>* pvOut)
|
|
|
|
{
|
2008-05-09 17:24:28 +00:00
|
|
|
ai_assert(NULL != pvOut);
|
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
unsigned int aiPositions[4] = {0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF};
|
2010-02-06 23:52:41 +00:00
|
|
|
PLY::EDataType aiTypes[4] = {EDT_Char, EDT_Char, EDT_Char, EDT_Char}; // silencing gcc
|
2008-05-05 12:36:31 +00:00
|
|
|
unsigned int cnt = 0;
|
|
|
|
PLY::ElementInstanceList* pcList = NULL;
|
|
|
|
|
|
|
|
// serach in the DOM for a vertex entry
|
|
|
|
unsigned int _i = 0;
|
2009-01-18 23:48:25 +00:00
|
|
|
for (std::vector<PLY::Element>::const_iterator i = pcDOM->alElements.begin();
|
|
|
|
i != pcDOM->alElements.end();++i,++_i)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
if (PLY::EEST_Vertex == (*i).eSemantic)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
pcList = &this->pcDOM->alElementData[_i];
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
// now check whether which coordinate sets are available
|
|
|
|
unsigned int _a = 0;
|
2008-10-13 16:45:48 +00:00
|
|
|
for (std::vector<PLY::Property>::const_iterator
|
|
|
|
a = (*i).alProperties.begin();
|
|
|
|
a != (*i).alProperties.end();++a,++_a)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
if ((*a).bIsList)continue;
|
|
|
|
if (PLY::EST_Red == (*a).Semantic)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
cnt++;
|
|
|
|
aiPositions[0] = _a;
|
2008-10-13 16:45:48 +00:00
|
|
|
aiTypes[0] = (*a).eType;
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
else if (PLY::EST_Green == (*a).Semantic)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
cnt++;
|
|
|
|
aiPositions[1] = _a;
|
2008-10-13 16:45:48 +00:00
|
|
|
aiTypes[1] = (*a).eType;
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
else if (PLY::EST_Blue == (*a).Semantic)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
cnt++;
|
|
|
|
aiPositions[2] = _a;
|
2008-10-13 16:45:48 +00:00
|
|
|
aiTypes[2] = (*a).eType;
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
else if (PLY::EST_Alpha == (*a).Semantic)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
cnt++;
|
|
|
|
aiPositions[3] = _a;
|
2008-10-13 16:45:48 +00:00
|
|
|
aiTypes[3] = (*a).eType;
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
|
|
|
if (4 == cnt)break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// check whether we have a valid source for the vertex data
|
|
|
|
if (NULL != pcList && 0 != cnt)
|
|
|
|
{
|
|
|
|
pvOut->reserve(pcList->alInstances.size());
|
2009-01-18 23:48:25 +00:00
|
|
|
for (std::vector<ElementInstance>::const_iterator i = pcList->alInstances.begin();
|
2008-05-05 12:36:31 +00:00
|
|
|
i != pcList->alInstances.end();++i)
|
|
|
|
{
|
|
|
|
// convert the vertices to sp floats
|
|
|
|
aiColor4D vOut;
|
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
if (0xFFFFFFFF != aiPositions[0])
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
vOut.r = NormalizeColorValue((*i).alProperties[
|
2008-05-05 12:36:31 +00:00
|
|
|
aiPositions[0]].avList.front(),aiTypes[0]);
|
|
|
|
}
|
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
if (0xFFFFFFFF != aiPositions[1])
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
vOut.g = NormalizeColorValue((*i).alProperties[
|
2008-05-05 12:36:31 +00:00
|
|
|
aiPositions[1]].avList.front(),aiTypes[1]);
|
|
|
|
}
|
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
if (0xFFFFFFFF != aiPositions[2])
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
vOut.b = NormalizeColorValue((*i).alProperties[
|
2008-05-05 12:36:31 +00:00
|
|
|
aiPositions[2]].avList.front(),aiTypes[2]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// assume 1.0 for the alpha channel ifit is not set
|
|
|
|
if (0xFFFFFFFF == aiPositions[3])vOut.a = 1.0f;
|
|
|
|
else
|
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
vOut.a = NormalizeColorValue((*i).alProperties[
|
2008-05-05 12:36:31 +00:00
|
|
|
aiPositions[3]].avList.front(),aiTypes[3]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// and add them to our nice list
|
|
|
|
pvOut->push_back(vOut);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2009-01-18 23:48:25 +00:00
|
|
|
// Try to extract proper faces from the PLY DOM
|
2008-05-05 12:36:31 +00:00
|
|
|
void PLYImporter::LoadFaces(std::vector<PLY::Face>* pvOut)
|
|
|
|
{
|
2008-05-09 17:24:28 +00:00
|
|
|
ai_assert(NULL != pvOut);
|
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
PLY::ElementInstanceList* pcList = NULL;
|
|
|
|
bool bOne = false;
|
|
|
|
|
|
|
|
// index of the vertex index list
|
|
|
|
unsigned int iProperty = 0xFFFFFFFF;
|
2010-02-06 23:52:41 +00:00
|
|
|
PLY::EDataType eType = EDT_Char;
|
2008-05-05 12:36:31 +00:00
|
|
|
bool bIsTristrip = false;
|
|
|
|
|
|
|
|
// index of the material index property
|
|
|
|
unsigned int iMaterialIndex = 0xFFFFFFFF;
|
2010-02-06 23:52:41 +00:00
|
|
|
PLY::EDataType eType2 = EDT_Char;
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
// serach in the DOM for a face entry
|
|
|
|
unsigned int _i = 0;
|
2009-01-18 23:48:25 +00:00
|
|
|
for (std::vector<PLY::Element>::const_iterator i = pcDOM->alElements.begin();
|
|
|
|
i != pcDOM->alElements.end();++i,++_i)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
// face = unique number of vertex indices
|
2008-10-13 16:45:48 +00:00
|
|
|
if (PLY::EEST_Face == (*i).eSemantic)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
2009-01-18 23:48:25 +00:00
|
|
|
pcList = &pcDOM->alElementData[_i];
|
2008-05-05 12:36:31 +00:00
|
|
|
unsigned int _a = 0;
|
2009-01-18 23:48:25 +00:00
|
|
|
for (std::vector<PLY::Property>::const_iterator a = (*i).alProperties.begin();
|
2008-10-13 16:45:48 +00:00
|
|
|
a != (*i).alProperties.end();++a,++_a)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
if (PLY::EST_VertexIndex == (*a).Semantic)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
// must be a dynamic list!
|
2008-10-13 16:45:48 +00:00
|
|
|
if (!(*a).bIsList)continue;
|
2008-05-05 12:36:31 +00:00
|
|
|
iProperty = _a;
|
|
|
|
bOne = true;
|
2008-10-13 16:45:48 +00:00
|
|
|
eType = (*a).eType;
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
else if (PLY::EST_MaterialIndex == (*a).Semantic)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
if ((*a).bIsList)continue;
|
2008-05-05 12:36:31 +00:00
|
|
|
iMaterialIndex = _a;
|
|
|
|
bOne = true;
|
2008-10-13 16:45:48 +00:00
|
|
|
eType2 = (*a).eType;
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// triangle strip
|
|
|
|
// TODO: triangle strip and material index support???
|
2008-10-13 16:45:48 +00:00
|
|
|
else if (PLY::EEST_TriStrip == (*i).eSemantic)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
// find a list property in this ...
|
2008-10-13 16:45:48 +00:00
|
|
|
pcList = &this->pcDOM->alElementData[_i];
|
2008-05-05 12:36:31 +00:00
|
|
|
unsigned int _a = 0;
|
2009-01-18 23:48:25 +00:00
|
|
|
for (std::vector<PLY::Property>::const_iterator a = (*i).alProperties.begin();
|
2008-10-13 16:45:48 +00:00
|
|
|
a != (*i).alProperties.end();++a,++_a)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
// must be a dynamic list!
|
2008-10-13 16:45:48 +00:00
|
|
|
if (!(*a).bIsList)continue;
|
2008-05-05 12:36:31 +00:00
|
|
|
iProperty = _a;
|
|
|
|
bOne = true;
|
|
|
|
bIsTristrip = true;
|
2008-10-13 16:45:48 +00:00
|
|
|
eType = (*a).eType;
|
2008-05-05 12:36:31 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// check whether we have at least one per-face information set
|
|
|
|
if (pcList && bOne)
|
|
|
|
{
|
|
|
|
if (!bIsTristrip)
|
|
|
|
{
|
|
|
|
pvOut->reserve(pcList->alInstances.size());
|
2009-01-18 23:48:25 +00:00
|
|
|
for (std::vector<ElementInstance>::const_iterator i = pcList->alInstances.begin();
|
2008-05-05 12:36:31 +00:00
|
|
|
i != pcList->alInstances.end();++i)
|
|
|
|
{
|
|
|
|
PLY::Face sFace;
|
|
|
|
|
|
|
|
// parse the list of vertex indices
|
|
|
|
if (0xFFFFFFFF != iProperty)
|
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
const unsigned int iNum = (unsigned int)(*i).alProperties[iProperty].avList.size();
|
2008-05-05 12:36:31 +00:00
|
|
|
sFace.mIndices.resize(iNum);
|
|
|
|
|
2008-10-13 16:45:48 +00:00
|
|
|
std::vector<PLY::PropertyInstance::ValueUnion>::const_iterator p =
|
|
|
|
(*i).alProperties[iProperty].avList.begin();
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
for (unsigned int a = 0; a < iNum;++a,++p)
|
|
|
|
{
|
|
|
|
sFace.mIndices[a] = PLY::PropertyInstance::ConvertTo<unsigned int>(*p,eType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// parse the material index
|
|
|
|
if (0xFFFFFFFF != iMaterialIndex)
|
|
|
|
{
|
|
|
|
sFace.iMaterialIndex = PLY::PropertyInstance::ConvertTo<unsigned int>(
|
2008-10-13 16:45:48 +00:00
|
|
|
(*i).alProperties[iMaterialIndex].avList.front(),eType2);
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
|
|
|
pvOut->push_back(sFace);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else // triangle strips
|
|
|
|
{
|
|
|
|
// normally we have only one triangle strip instance where
|
|
|
|
// a value of -1 indicates a restart of the strip
|
2009-05-28 11:32:54 +00:00
|
|
|
bool flip = false;
|
|
|
|
for (std::vector<ElementInstance>::const_iterator i = pcList->alInstances.begin();i != pcList->alInstances.end();++i) {
|
General
- Added format auto-detection to most loaders
- Simplified BaseImporter::CanRead() with some utility methods
- improved fast_atof -> no overruns anymore. Fuck you, irrlicht.
- added assimp_cmd tool to allow command line model processing. Mainly adebugging tool for internal purposes, but others might find it useful, too.
- vc8/vc9: revision number is now written to DLL version header
- mkutil: some batch scripts to simplify tagging & building of release versions
- some API cleanup
- fixing some doxygen markup (+now explicit use of @file <filename>)
- Icon for assimp_view and assimp_cmd
3DS
- Normal vectors are not anymore inverted in some cases
- Improved pivot handling
- Improved handling of x-flipped meshes
Collada
- fixed a minor bug (visual_scene element)
LWS
- WIP implementation. No animations yet, some bugs and crashes.
- Animation system remains disabled, WIP code
- many test files for LWS, but most of them test the anim support, which is, read above, currently disabled.
STL
- fixing a log warning which appears for every model
- added binary&ascii test spider, exported from truespace
MD3
- Cleaning up output tags for automatically joined player models.
IRR
- Fixing coordinate system issues.
- Instance handling improved.
- Some of the reported crashes not yet fixed.
PretransformVertices
- Numerous performance improvements.
- Added config option to preserve the hierarchy during the step.
RemoveRedundantMaterials
- Added config option to specify a list of materials which are kept in every case.
UNREAL
- Added support for the old unreal data format (*.a,*.d,*.uc)
- tested only with exports from Milkshape
- more Unreal stuff to come soon
git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@356 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
2009-03-05 22:32:13 +00:00
|
|
|
const std::vector<PLY::PropertyInstance::ValueUnion>& quak = (*i).alProperties[iProperty].avList;
|
|
|
|
pvOut->reserve(pvOut->size() + quak.size() + (quak.size()>>2u));
|
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
int aiTable[2] = {-1,-1};
|
General
- Added format auto-detection to most loaders
- Simplified BaseImporter::CanRead() with some utility methods
- improved fast_atof -> no overruns anymore. Fuck you, irrlicht.
- added assimp_cmd tool to allow command line model processing. Mainly adebugging tool for internal purposes, but others might find it useful, too.
- vc8/vc9: revision number is now written to DLL version header
- mkutil: some batch scripts to simplify tagging & building of release versions
- some API cleanup
- fixing some doxygen markup (+now explicit use of @file <filename>)
- Icon for assimp_view and assimp_cmd
3DS
- Normal vectors are not anymore inverted in some cases
- Improved pivot handling
- Improved handling of x-flipped meshes
Collada
- fixed a minor bug (visual_scene element)
LWS
- WIP implementation. No animations yet, some bugs and crashes.
- Animation system remains disabled, WIP code
- many test files for LWS, but most of them test the anim support, which is, read above, currently disabled.
STL
- fixing a log warning which appears for every model
- added binary&ascii test spider, exported from truespace
MD3
- Cleaning up output tags for automatically joined player models.
IRR
- Fixing coordinate system issues.
- Instance handling improved.
- Some of the reported crashes not yet fixed.
PretransformVertices
- Numerous performance improvements.
- Added config option to preserve the hierarchy during the step.
RemoveRedundantMaterials
- Added config option to specify a list of materials which are kept in every case.
UNREAL
- Added support for the old unreal data format (*.a,*.d,*.uc)
- tested only with exports from Milkshape
- more Unreal stuff to come soon
git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@356 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
2009-03-05 22:32:13 +00:00
|
|
|
for (std::vector<PLY::PropertyInstance::ValueUnion>::const_iterator a = quak.begin();a != quak.end();++a) {
|
|
|
|
const int p = PLY::PropertyInstance::ConvertTo<int>(*a,eType);
|
2009-05-28 11:32:54 +00:00
|
|
|
|
|
|
|
if (-1 == p) {
|
2008-05-05 12:36:31 +00:00
|
|
|
// restart the strip ...
|
|
|
|
aiTable[0] = aiTable[1] = -1;
|
2009-05-28 11:32:54 +00:00
|
|
|
flip = false;
|
2008-05-05 12:36:31 +00:00
|
|
|
continue;
|
|
|
|
}
|
2009-05-28 11:32:54 +00:00
|
|
|
if (-1 == aiTable[0]) {
|
2008-05-05 12:36:31 +00:00
|
|
|
aiTable[0] = p;
|
|
|
|
continue;
|
|
|
|
}
|
2009-05-28 11:32:54 +00:00
|
|
|
if (-1 == aiTable[1]) {
|
2008-05-05 12:36:31 +00:00
|
|
|
aiTable[1] = p;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
General
- Added format auto-detection to most loaders
- Simplified BaseImporter::CanRead() with some utility methods
- improved fast_atof -> no overruns anymore. Fuck you, irrlicht.
- added assimp_cmd tool to allow command line model processing. Mainly adebugging tool for internal purposes, but others might find it useful, too.
- vc8/vc9: revision number is now written to DLL version header
- mkutil: some batch scripts to simplify tagging & building of release versions
- some API cleanup
- fixing some doxygen markup (+now explicit use of @file <filename>)
- Icon for assimp_view and assimp_cmd
3DS
- Normal vectors are not anymore inverted in some cases
- Improved pivot handling
- Improved handling of x-flipped meshes
Collada
- fixed a minor bug (visual_scene element)
LWS
- WIP implementation. No animations yet, some bugs and crashes.
- Animation system remains disabled, WIP code
- many test files for LWS, but most of them test the anim support, which is, read above, currently disabled.
STL
- fixing a log warning which appears for every model
- added binary&ascii test spider, exported from truespace
MD3
- Cleaning up output tags for automatically joined player models.
IRR
- Fixing coordinate system issues.
- Instance handling improved.
- Some of the reported crashes not yet fixed.
PretransformVertices
- Numerous performance improvements.
- Added config option to preserve the hierarchy during the step.
RemoveRedundantMaterials
- Added config option to specify a list of materials which are kept in every case.
UNREAL
- Added support for the old unreal data format (*.a,*.d,*.uc)
- tested only with exports from Milkshape
- more Unreal stuff to come soon
git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@356 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
2009-03-05 22:32:13 +00:00
|
|
|
pvOut->push_back(PLY::Face());
|
|
|
|
PLY::Face& sFace = pvOut->back();
|
2009-05-28 11:32:54 +00:00
|
|
|
sFace.mIndices[0] = aiTable[0];
|
|
|
|
sFace.mIndices[1] = aiTable[1];
|
|
|
|
sFace.mIndices[2] = p;
|
|
|
|
if ((flip = !flip)) {
|
|
|
|
std::swap(sFace.mIndices[0],sFace.mIndices[1]);
|
|
|
|
}
|
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
aiTable[0] = aiTable[1];
|
|
|
|
aiTable[1] = p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-01-18 23:48:25 +00:00
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2009-01-18 23:48:25 +00:00
|
|
|
// Get a RGBA color in [0...1] range
|
2008-05-09 17:24:28 +00:00
|
|
|
void PLYImporter::GetMaterialColor(const std::vector<PLY::PropertyInstance>& avList,
|
|
|
|
unsigned int aiPositions[4],
|
|
|
|
PLY::EDataType aiTypes[4],
|
|
|
|
aiColor4D* clrOut)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
ai_assert(NULL != clrOut);
|
|
|
|
|
|
|
|
if (0xFFFFFFFF == aiPositions[0])clrOut->r = 0.0f;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
clrOut->r = NormalizeColorValue(avList[
|
|
|
|
aiPositions[0]].avList.front(),aiTypes[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (0xFFFFFFFF == aiPositions[1])clrOut->g = 0.0f;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
clrOut->g = NormalizeColorValue(avList[
|
|
|
|
aiPositions[1]].avList.front(),aiTypes[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (0xFFFFFFFF == aiPositions[2])clrOut->b = 0.0f;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
clrOut->b = NormalizeColorValue(avList[
|
|
|
|
aiPositions[2]].avList.front(),aiTypes[2]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// assume 1.0 for the alpha channel ifit is not set
|
|
|
|
if (0xFFFFFFFF == aiPositions[3])clrOut->a = 1.0f;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
clrOut->a = NormalizeColorValue(avList[
|
|
|
|
aiPositions[3]].avList.front(),aiTypes[3]);
|
|
|
|
}
|
|
|
|
}
|
2009-01-18 23:48:25 +00:00
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2009-01-18 23:48:25 +00:00
|
|
|
// Extract a material from the PLY DOM
|
2011-08-22 20:22:51 +00:00
|
|
|
void PLYImporter::LoadMaterial(std::vector<aiMaterial*>* pvOut)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
2008-05-09 17:24:28 +00:00
|
|
|
ai_assert(NULL != pvOut);
|
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
// diffuse[4], specular[4], ambient[4]
|
|
|
|
// rgba order
|
|
|
|
unsigned int aaiPositions[3][4] = {
|
|
|
|
|
|
|
|
{0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF},
|
|
|
|
{0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF},
|
|
|
|
{0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF},
|
|
|
|
};
|
|
|
|
|
2010-02-06 23:52:41 +00:00
|
|
|
PLY::EDataType aaiTypes[3][4] = {
|
|
|
|
{EDT_Char,EDT_Char,EDT_Char,EDT_Char},
|
|
|
|
{EDT_Char,EDT_Char,EDT_Char,EDT_Char},
|
|
|
|
{EDT_Char,EDT_Char,EDT_Char,EDT_Char}
|
|
|
|
};
|
2008-05-05 12:36:31 +00:00
|
|
|
PLY::ElementInstanceList* pcList = NULL;
|
|
|
|
|
|
|
|
unsigned int iPhong = 0xFFFFFFFF;
|
2010-02-06 23:52:41 +00:00
|
|
|
PLY::EDataType ePhong = EDT_Char;
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
unsigned int iOpacity = 0xFFFFFFFF;
|
2010-02-06 23:52:41 +00:00
|
|
|
PLY::EDataType eOpacity = EDT_Char;
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
// serach in the DOM for a vertex entry
|
|
|
|
unsigned int _i = 0;
|
2009-01-18 23:48:25 +00:00
|
|
|
for (std::vector<PLY::Element>::const_iterator i = this->pcDOM->alElements.begin();
|
2008-05-05 12:36:31 +00:00
|
|
|
i != this->pcDOM->alElements.end();++i,++_i)
|
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
if (PLY::EEST_Material == (*i).eSemantic)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
pcList = &this->pcDOM->alElementData[_i];
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
// now check whether which coordinate sets are available
|
|
|
|
unsigned int _a = 0;
|
2008-10-13 16:45:48 +00:00
|
|
|
for (std::vector<PLY::Property>::const_iterator
|
|
|
|
a = (*i).alProperties.begin();
|
|
|
|
a != (*i).alProperties.end();++a,++_a)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
if ((*a).bIsList)continue;
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
// pohng specularity -----------------------------------
|
2008-10-13 16:45:48 +00:00
|
|
|
if (PLY::EST_PhongPower == (*a).Semantic)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
iPhong = _a;
|
2008-10-13 16:45:48 +00:00
|
|
|
ePhong = (*a).eType;
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// general opacity -----------------------------------
|
2008-10-13 16:45:48 +00:00
|
|
|
if (PLY::EST_Opacity == (*a).Semantic)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
iOpacity = _a;
|
2008-10-13 16:45:48 +00:00
|
|
|
eOpacity = (*a).eType;
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// diffuse color channels -----------------------------------
|
2008-10-13 16:45:48 +00:00
|
|
|
if (PLY::EST_DiffuseRed == (*a).Semantic)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
aaiPositions[0][0] = _a;
|
2008-10-13 16:45:48 +00:00
|
|
|
aaiTypes[0][0] = (*a).eType;
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
else if (PLY::EST_DiffuseGreen == (*a).Semantic)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
aaiPositions[0][1] = _a;
|
2008-10-13 16:45:48 +00:00
|
|
|
aaiTypes[0][1] = (*a).eType;
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
else if (PLY::EST_DiffuseBlue == (*a).Semantic)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
aaiPositions[0][2] = _a;
|
2008-10-13 16:45:48 +00:00
|
|
|
aaiTypes[0][2] = (*a).eType;
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
else if (PLY::EST_DiffuseAlpha == (*a).Semantic)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
aaiPositions[0][3] = _a;
|
2008-10-13 16:45:48 +00:00
|
|
|
aaiTypes[0][3] = (*a).eType;
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
|
|
|
// specular color channels -----------------------------------
|
2008-10-13 16:45:48 +00:00
|
|
|
else if (PLY::EST_SpecularRed == (*a).Semantic)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
aaiPositions[1][0] = _a;
|
2008-10-13 16:45:48 +00:00
|
|
|
aaiTypes[1][0] = (*a).eType;
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
else if (PLY::EST_SpecularGreen == (*a).Semantic)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
aaiPositions[1][1] = _a;
|
2008-10-13 16:45:48 +00:00
|
|
|
aaiTypes[1][1] = (*a).eType;
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
else if (PLY::EST_SpecularBlue == (*a).Semantic)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
aaiPositions[1][2] = _a;
|
2008-10-13 16:45:48 +00:00
|
|
|
aaiTypes[1][2] = (*a).eType;
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
else if (PLY::EST_SpecularAlpha == (*a).Semantic)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
aaiPositions[1][3] = _a;
|
2008-10-13 16:45:48 +00:00
|
|
|
aaiTypes[1][3] = (*a).eType;
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
|
|
|
// ambient color channels -----------------------------------
|
2008-10-13 16:45:48 +00:00
|
|
|
else if (PLY::EST_AmbientRed == (*a).Semantic)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
aaiPositions[2][0] = _a;
|
2008-10-13 16:45:48 +00:00
|
|
|
aaiTypes[2][0] = (*a).eType;
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
else if (PLY::EST_AmbientGreen == (*a).Semantic)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
aaiPositions[2][1] = _a;
|
2008-10-13 16:45:48 +00:00
|
|
|
aaiTypes[2][1] = (*a).eType;
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
else if (PLY::EST_AmbientBlue == (*a).Semantic)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
2010-01-19 16:32:41 +00:00
|
|
|
aaiPositions[2][2] = _a;
|
2008-10-13 16:45:48 +00:00
|
|
|
aaiTypes[2][2] = (*a).eType;
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
else if (PLY::EST_AmbientAlpha == (*a).Semantic)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
aaiPositions[2][3] = _a;
|
2008-10-13 16:45:48 +00:00
|
|
|
aaiTypes[2][3] = (*a).eType;
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// check whether we have a valid source for the material data
|
2009-03-15 00:40:30 +00:00
|
|
|
if (NULL != pcList) {
|
|
|
|
for (std::vector<ElementInstance>::const_iterator i = pcList->alInstances.begin();i != pcList->alInstances.end();++i) {
|
2008-05-05 12:36:31 +00:00
|
|
|
aiColor4D clrOut;
|
2011-08-22 20:22:51 +00:00
|
|
|
aiMaterial* pcHelper = new aiMaterial();
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
// build the diffuse material color
|
2008-10-13 16:45:48 +00:00
|
|
|
GetMaterialColor((*i).alProperties,aaiPositions[0],aaiTypes[0],&clrOut);
|
2008-05-05 12:36:31 +00:00
|
|
|
pcHelper->AddProperty<aiColor4D>(&clrOut,1,AI_MATKEY_COLOR_DIFFUSE);
|
|
|
|
|
|
|
|
// build the specular material color
|
2008-10-13 16:45:48 +00:00
|
|
|
GetMaterialColor((*i).alProperties,aaiPositions[1],aaiTypes[1],&clrOut);
|
2008-05-05 12:36:31 +00:00
|
|
|
pcHelper->AddProperty<aiColor4D>(&clrOut,1,AI_MATKEY_COLOR_SPECULAR);
|
|
|
|
|
|
|
|
// build the ambient material color
|
2008-10-13 16:45:48 +00:00
|
|
|
GetMaterialColor((*i).alProperties,aaiPositions[2],aaiTypes[2],&clrOut);
|
2008-05-05 12:36:31 +00:00
|
|
|
pcHelper->AddProperty<aiColor4D>(&clrOut,1,AI_MATKEY_COLOR_AMBIENT);
|
|
|
|
|
|
|
|
// handle phong power and shading mode
|
|
|
|
int iMode;
|
2009-03-15 00:40:30 +00:00
|
|
|
if (0xFFFFFFFF != iPhong) {
|
|
|
|
float fSpec = PLY::PropertyInstance::ConvertTo<float>((*i).alProperties[iPhong].avList.front(),ePhong);
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
// if shininess is 0 (and the pow() calculation would therefore always
|
2009-03-15 00:40:30 +00:00
|
|
|
// become 1, not depending on the angle), use gouraud lighting
|
|
|
|
if (fSpec) {
|
2008-05-05 12:36:31 +00:00
|
|
|
// scale this with 15 ... hopefully this is correct
|
2008-05-09 17:24:28 +00:00
|
|
|
fSpec *= 15;
|
2008-05-05 12:36:31 +00:00
|
|
|
pcHelper->AddProperty<float>(&fSpec, 1, AI_MATKEY_SHININESS);
|
|
|
|
|
|
|
|
iMode = (int)aiShadingMode_Phong;
|
|
|
|
}
|
|
|
|
else iMode = (int)aiShadingMode_Gouraud;
|
|
|
|
}
|
|
|
|
else iMode = (int)aiShadingMode_Gouraud;
|
|
|
|
pcHelper->AddProperty<int>(&iMode, 1, AI_MATKEY_SHADING_MODEL);
|
|
|
|
|
|
|
|
// handle opacity
|
2009-03-15 00:40:30 +00:00
|
|
|
if (0xFFFFFFFF != iOpacity) {
|
|
|
|
float fOpacity = PLY::PropertyInstance::ConvertTo<float>((*i).alProperties[iPhong].avList.front(),eOpacity);
|
2008-05-05 12:36:31 +00:00
|
|
|
pcHelper->AddProperty<float>(&fOpacity, 1, AI_MATKEY_OPACITY);
|
|
|
|
}
|
|
|
|
|
2009-03-15 00:40:30 +00:00
|
|
|
// The face order is absolutely undefined for PLY, so we have to
|
|
|
|
// use two-sided rendering to be sure it's ok.
|
|
|
|
const int two_sided = 1;
|
|
|
|
pcHelper->AddProperty(&two_sided,1,AI_MATKEY_TWOSIDED);
|
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
// add the newly created material instance to the list
|
|
|
|
pvOut->push_back(pcHelper);
|
|
|
|
}
|
|
|
|
}
|
2008-09-12 20:25:11 +00:00
|
|
|
}
|
2009-01-18 23:48:25 +00:00
|
|
|
|
General
- Added format auto-detection to most loaders
- Simplified BaseImporter::CanRead() with some utility methods
- improved fast_atof -> no overruns anymore. Fuck you, irrlicht.
- added assimp_cmd tool to allow command line model processing. Mainly adebugging tool for internal purposes, but others might find it useful, too.
- vc8/vc9: revision number is now written to DLL version header
- mkutil: some batch scripts to simplify tagging & building of release versions
- some API cleanup
- fixing some doxygen markup (+now explicit use of @file <filename>)
- Icon for assimp_view and assimp_cmd
3DS
- Normal vectors are not anymore inverted in some cases
- Improved pivot handling
- Improved handling of x-flipped meshes
Collada
- fixed a minor bug (visual_scene element)
LWS
- WIP implementation. No animations yet, some bugs and crashes.
- Animation system remains disabled, WIP code
- many test files for LWS, but most of them test the anim support, which is, read above, currently disabled.
STL
- fixing a log warning which appears for every model
- added binary&ascii test spider, exported from truespace
MD3
- Cleaning up output tags for automatically joined player models.
IRR
- Fixing coordinate system issues.
- Instance handling improved.
- Some of the reported crashes not yet fixed.
PretransformVertices
- Numerous performance improvements.
- Added config option to preserve the hierarchy during the step.
RemoveRedundantMaterials
- Added config option to specify a list of materials which are kept in every case.
UNREAL
- Added support for the old unreal data format (*.a,*.d,*.uc)
- tested only with exports from Milkshape
- more Unreal stuff to come soon
git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@356 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
2009-03-05 22:32:13 +00:00
|
|
|
#endif // !! ASSIMP_BUILD_NO_PLY_IMPORTER
|