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.
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
/** @file Implementation of the PLY parser class */
|
2008-05-09 17:24:28 +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-05-27 18:58:36 +00:00
|
|
|
#include "PlyLoader.h"
|
2008-05-05 12:36:31 +00:00
|
|
|
#include "fast_atof.h"
|
|
|
|
|
|
|
|
using namespace Assimp;
|
2009-01-18 23:48:25 +00:00
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2008-10-13 16:45:48 +00:00
|
|
|
PLY::EDataType PLY::Property::ParseDataType(const char* pCur,const char** pCurOut)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
ai_assert(NULL != pCur && NULL != pCurOut);
|
2008-05-05 12:36:31 +00:00
|
|
|
PLY::EDataType eOut = PLY::EDT_INVALID;
|
|
|
|
|
2008-10-13 16:45:48 +00:00
|
|
|
if (TokenMatch(pCur,"char",4) ||
|
|
|
|
TokenMatch(pCur,"int8",4))
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
eOut = PLY::EDT_Char;
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
else if (TokenMatch(pCur,"uchar",5) ||
|
|
|
|
TokenMatch(pCur,"uint8",5))
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
eOut = PLY::EDT_UChar;
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
else if (TokenMatch(pCur,"short",5) ||
|
|
|
|
TokenMatch(pCur,"int16",5))
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
eOut = PLY::EDT_Short;
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
else if (TokenMatch(pCur,"ushort",6) ||
|
|
|
|
TokenMatch(pCur,"uint16",6))
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
eOut = PLY::EDT_UShort;
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
else if (TokenMatch(pCur,"int32",5) || TokenMatch(pCur,"int",3))
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
eOut = PLY::EDT_Int;
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
else if (TokenMatch(pCur,"uint32",6) || TokenMatch(pCur,"uint",4))
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
eOut = PLY::EDT_UInt;
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
else if (TokenMatch(pCur,"float",5) || TokenMatch(pCur,"float32",7))
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
eOut = PLY::EDT_Float;
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
else if (TokenMatch(pCur,"double64",8) || TokenMatch(pCur,"double",6) ||
|
|
|
|
TokenMatch(pCur,"float64",7))
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
eOut = PLY::EDT_Double;
|
|
|
|
}
|
2008-05-13 23:26:52 +00:00
|
|
|
if (PLY::EDT_INVALID == eOut)
|
|
|
|
{
|
|
|
|
DefaultLogger::get()->info("Found unknown data type in PLY file. This is OK");
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
*pCurOut = pCur;
|
2008-05-05 12:36:31 +00:00
|
|
|
return eOut;
|
|
|
|
}
|
2009-01-18 23:48:25 +00:00
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2008-10-13 16:45:48 +00:00
|
|
|
PLY::ESemantic PLY::Property::ParseSemantic(const char* pCur,const char** pCurOut)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
ai_assert(NULL != pCur && NULL != pCurOut);
|
2008-05-13 23:26:52 +00:00
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
PLY::ESemantic eOut = PLY::EST_INVALID;
|
2008-10-13 16:45:48 +00:00
|
|
|
if (TokenMatch(pCur,"red",3))
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
eOut = PLY::EST_Red;
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
else if (TokenMatch(pCur,"green",5))
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
eOut = PLY::EST_Green;
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
else if (TokenMatch(pCur,"blue",4))
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
eOut = PLY::EST_Blue;
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
else if (TokenMatch(pCur,"alpha",5))
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
eOut = PLY::EST_Alpha;
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
else if (TokenMatch(pCur,"vertex_index",12) || TokenMatch(pCur,"vertex_indices",14))
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
eOut = PLY::EST_VertexIndex;
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
else if (TokenMatch(pCur,"material_index",14))
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
eOut = PLY::EST_MaterialIndex;
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
else if (TokenMatch(pCur,"ambient_red",11))
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
eOut = PLY::EST_AmbientRed;
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
else if (TokenMatch(pCur,"ambient_green",13))
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
eOut = PLY::EST_AmbientGreen;
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
else if (TokenMatch(pCur,"ambient_blue",12))
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
eOut = PLY::EST_AmbientBlue;
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
else if (TokenMatch(pCur,"ambient_alpha",13))
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
eOut = PLY::EST_AmbientAlpha;
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
else if (TokenMatch(pCur,"diffuse_red",11))
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
eOut = PLY::EST_DiffuseRed;
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
else if (TokenMatch(pCur,"diffuse_green",13))
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
eOut = PLY::EST_DiffuseGreen;
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
else if (TokenMatch(pCur,"diffuse_blue",12))
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
eOut = PLY::EST_DiffuseBlue;
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
else if (TokenMatch(pCur,"diffuse_alpha",13))
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
eOut = PLY::EST_DiffuseAlpha;
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
else if (TokenMatch(pCur,"specular_red",12))
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
eOut = PLY::EST_SpecularRed;
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
else if (TokenMatch(pCur,"specular_green",14))
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
eOut = PLY::EST_SpecularGreen;
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
else if (TokenMatch(pCur,"specular_blue",13))
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
eOut = PLY::EST_SpecularBlue;
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
else if (TokenMatch(pCur,"specular_alpha",14))
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
eOut = PLY::EST_SpecularAlpha;
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
else if (TokenMatch(pCur,"opacity",7))
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
eOut = PLY::EST_Opacity;
|
|
|
|
}
|
2014-12-16 22:41:10 +00:00
|
|
|
else if (TokenMatch(pCur,"specular_power",14))
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
eOut = PLY::EST_PhongPower;
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
else if (TokenMatch(pCur,"r",1))
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
eOut = PLY::EST_Red;
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
else if (TokenMatch(pCur,"g",1))
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
eOut = PLY::EST_Green;
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
else if (TokenMatch(pCur,"b",1))
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
eOut = PLY::EST_Blue;
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
// NOTE: Blender3D exports texture coordinates as s,t tuples
|
|
|
|
else if (TokenMatch(pCur,"u",1) || TokenMatch(pCur,"s",1) || TokenMatch(pCur,"tx",2))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
|
|
|
eOut = PLY::EST_UTextureCoord;
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
else if (TokenMatch(pCur,"v",1) || TokenMatch(pCur,"t",1) || TokenMatch(pCur,"ty",2))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
|
|
|
eOut = PLY::EST_VTextureCoord;
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
else if (TokenMatch(pCur,"x",1))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
eOut = PLY::EST_XCoord;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
else if (TokenMatch(pCur,"y",1))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
eOut = PLY::EST_YCoord;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
else if (TokenMatch(pCur,"z",1))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
eOut = PLY::EST_ZCoord;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
else if (TokenMatch(pCur,"nx",2))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
eOut = PLY::EST_XNormal;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
else if (TokenMatch(pCur,"ny",2))
|
2008-05-09 17:24:28 +00:00
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
eOut = PLY::EST_YNormal;
|
2008-05-09 17:24:28 +00:00
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
else if (TokenMatch(pCur,"nz",2))
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
eOut = PLY::EST_ZNormal;
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
else
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
DefaultLogger::get()->info("Found unknown property semantic in file. This is ok");
|
|
|
|
SkipLine(&pCur);
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
*pCurOut = pCur;
|
2008-05-05 12:36:31 +00:00
|
|
|
return eOut;
|
|
|
|
}
|
2009-01-18 23:48:25 +00:00
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2008-10-13 16:45:48 +00:00
|
|
|
bool PLY::Property::ParseProperty (const char* pCur,
|
|
|
|
const char** pCurOut,
|
2008-05-09 17:24:28 +00:00
|
|
|
PLY::Property* pOut)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
ai_assert(NULL != pCur && NULL != pCurOut);
|
2008-05-13 23:26:52 +00:00
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
// Forms supported:
|
|
|
|
// "property float x"
|
|
|
|
// "property list uchar int vertex_index"
|
2008-10-13 16:45:48 +00:00
|
|
|
*pCurOut = pCur;
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
// skip leading spaces
|
2008-10-13 16:45:48 +00:00
|
|
|
if (!SkipSpaces(pCur,&pCur))return false;
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
// skip the "property" string at the beginning
|
2008-10-13 16:45:48 +00:00
|
|
|
if (!TokenMatch(pCur,"property",8))
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
// seems not to be a valid property entry
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// get next word
|
2008-10-13 16:45:48 +00:00
|
|
|
if (!SkipSpaces(pCur,&pCur))return false;
|
|
|
|
if (TokenMatch(pCur,"list",4))
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
pOut->bIsList = true;
|
|
|
|
|
|
|
|
// seems to be a list.
|
2008-10-13 16:45:48 +00:00
|
|
|
if(EDT_INVALID == (pOut->eFirstType = PLY::Property::ParseDataType(pCur, &pCur)))
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
// unable to parse list size data type
|
2008-10-13 16:45:48 +00:00
|
|
|
SkipLine(pCur,&pCur);
|
|
|
|
*pCurOut = pCur;
|
2008-05-05 12:36:31 +00:00
|
|
|
return false;
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
if (!SkipSpaces(pCur,&pCur))return false;
|
|
|
|
if(EDT_INVALID == (pOut->eType = PLY::Property::ParseDataType(pCur, &pCur)))
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
// unable to parse list data type
|
2008-10-13 16:45:48 +00:00
|
|
|
SkipLine(pCur,&pCur);
|
|
|
|
*pCurOut = pCur;
|
2008-05-05 12:36:31 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
if(EDT_INVALID == (pOut->eType = PLY::Property::ParseDataType(pCur, &pCur)))
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
// unable to parse data type. Skip the property
|
2008-10-13 16:45:48 +00:00
|
|
|
SkipLine(pCur,&pCur);
|
|
|
|
*pCurOut = pCur;
|
2008-05-05 12:36:31 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-13 16:45:48 +00:00
|
|
|
if (!SkipSpaces(pCur,&pCur))return false;
|
|
|
|
const char* szCur = pCur;
|
|
|
|
pOut->Semantic = PLY::Property::ParseSemantic(pCur, &pCur);
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
if (PLY::EST_INVALID == pOut->Semantic)
|
|
|
|
{
|
|
|
|
// store the name of the semantic
|
2008-10-13 16:45:48 +00:00
|
|
|
uintptr_t iDiff = (uintptr_t)pCur - (uintptr_t)szCur;
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2008-05-13 23:26:52 +00:00
|
|
|
DefaultLogger::get()->info("Found unknown semantic in PLY file. This is OK");
|
2008-05-05 12:36:31 +00:00
|
|
|
pOut->szName = std::string(szCur,iDiff);
|
|
|
|
}
|
|
|
|
|
2008-10-13 16:45:48 +00:00
|
|
|
SkipSpacesAndLineEnd(pCur,&pCur);
|
|
|
|
*pCurOut = pCur;
|
2008-05-05 12:36:31 +00:00
|
|
|
return true;
|
|
|
|
}
|
2009-01-18 23:48:25 +00:00
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2008-10-13 16:45:48 +00:00
|
|
|
PLY::EElementSemantic PLY::Element::ParseSemantic(const char* pCur,
|
|
|
|
const char** pCurOut)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
ai_assert(NULL != pCur && NULL != pCurOut);
|
2008-05-05 12:36:31 +00:00
|
|
|
PLY::EElementSemantic eOut = PLY::EEST_INVALID;
|
2008-10-13 16:45:48 +00:00
|
|
|
if (TokenMatch(pCur,"vertex",6))
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
eOut = PLY::EEST_Vertex;
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
else if (TokenMatch(pCur,"face",4))
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
eOut = PLY::EEST_Face;
|
|
|
|
}
|
|
|
|
#if 0
|
2008-10-13 16:45:48 +00:00
|
|
|
// TODO: maybe implement this?
|
|
|
|
else if (TokenMatch(pCur,"range_grid",10))
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
eOut = PLY::EEST_Face;
|
|
|
|
}
|
|
|
|
#endif
|
2008-10-13 16:45:48 +00:00
|
|
|
else if (TokenMatch(pCur,"tristrips",9))
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
eOut = PLY::EEST_TriStrip;
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
else if (TokenMatch(pCur,"edge",4))
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
eOut = PLY::EEST_Edge;
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
else if (TokenMatch(pCur,"material",8))
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
eOut = PLY::EEST_Material;
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
*pCurOut = pCur;
|
2008-05-05 12:36:31 +00:00
|
|
|
return eOut;
|
|
|
|
}
|
2009-01-18 23:48:25 +00:00
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2008-10-13 16:45:48 +00:00
|
|
|
bool PLY::Element::ParseElement (const char* pCur,
|
|
|
|
const char** pCurOut,
|
2008-05-09 17:24:28 +00:00
|
|
|
PLY::Element* pOut)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
ai_assert(NULL != pCur && NULL != pCurOut && NULL != pOut);
|
2008-05-13 23:26:52 +00:00
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
// Example format: "element vertex 8"
|
2008-10-13 16:45:48 +00:00
|
|
|
*pCurOut = pCur;
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
// skip leading spaces
|
2008-10-13 16:45:48 +00:00
|
|
|
if (!SkipSpaces(&pCur))return false;
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
// skip the "element" string at the beginning
|
2008-10-13 16:45:48 +00:00
|
|
|
if (!TokenMatch(pCur,"element",7))
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
// seems not to be a valid property entry
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// get next word
|
2008-10-13 16:45:48 +00:00
|
|
|
if (!SkipSpaces(&pCur))return false;
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
// parse the semantic of the element
|
2008-10-13 16:45:48 +00:00
|
|
|
const char* szCur = pCur;
|
|
|
|
pOut->eSemantic = PLY::Element::ParseSemantic(pCur,&pCur);
|
2008-05-05 12:36:31 +00:00
|
|
|
if (PLY::EEST_INVALID == pOut->eSemantic)
|
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
// if the exact semantic can't be determined, just store
|
|
|
|
// the original string identifier
|
|
|
|
uintptr_t iDiff = (uintptr_t)pCur - (uintptr_t)szCur;
|
2008-05-05 12:36:31 +00:00
|
|
|
pOut->szName = std::string(szCur,iDiff);
|
|
|
|
}
|
|
|
|
|
2008-10-13 16:45:48 +00:00
|
|
|
if (!SkipSpaces(&pCur))return false;
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
//parse the number of occurences of this element
|
2011-03-23 14:26:19 +00:00
|
|
|
pOut->NumOccur = strtoul10(pCur,&pCur);
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
// go to the next line
|
2008-10-13 16:45:48 +00:00
|
|
|
SkipSpacesAndLineEnd(pCur,&pCur);
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
// now parse all properties of the element
|
|
|
|
while(true)
|
|
|
|
{
|
|
|
|
// skip all comments
|
2008-10-13 16:45:48 +00:00
|
|
|
PLY::DOM::SkipComments(pCur,&pCur);
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2008-10-13 16:45:48 +00:00
|
|
|
PLY::Property prop;
|
|
|
|
if(!PLY::Property::ParseProperty(pCur,&pCur,&prop))break;
|
2008-05-05 12:36:31 +00:00
|
|
|
pOut->alProperties.push_back(prop);
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
*pCurOut = pCur;
|
2008-05-05 12:36:31 +00:00
|
|
|
return true;
|
|
|
|
}
|
2009-01-18 23:48:25 +00:00
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2008-10-13 16:45:48 +00:00
|
|
|
bool PLY::DOM::SkipComments (const char* pCur,
|
|
|
|
const char** pCurOut)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
ai_assert(NULL != pCur && NULL != pCurOut);
|
|
|
|
*pCurOut = pCur;
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
// skip spaces
|
2008-10-13 16:45:48 +00:00
|
|
|
if (!SkipSpaces(pCur,&pCur))return false;
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2008-10-13 16:45:48 +00:00
|
|
|
if (TokenMatch(pCur,"comment",7))
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
SkipLine(pCur,&pCur);
|
|
|
|
SkipComments(pCur,&pCur);
|
|
|
|
*pCurOut = pCur;
|
2008-05-05 12:36:31 +00:00
|
|
|
return true;
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
*pCurOut = pCur;
|
2008-05-05 12:36:31 +00:00
|
|
|
return false;
|
|
|
|
}
|
2009-01-18 23:48:25 +00:00
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2014-02-17 17:14:07 +00:00
|
|
|
bool PLY::DOM::ParseHeader (const char* pCur,const char** pCurOut,bool isBinary)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
ai_assert(NULL != pCur && NULL != pCurOut);
|
2008-05-13 23:26:52 +00:00
|
|
|
DefaultLogger::get()->debug("PLY::DOM::ParseHeader() begin");
|
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
// after ply and format line
|
2008-10-13 16:45:48 +00:00
|
|
|
*pCurOut = pCur;
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
// parse all elements
|
2015-01-31 22:22:32 +00:00
|
|
|
while ((*pCur) != '\0')
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
// skip all comments
|
2008-10-13 16:45:48 +00:00
|
|
|
PLY::DOM::SkipComments(pCur,&pCur);
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2008-10-13 16:45:48 +00:00
|
|
|
PLY::Element out;
|
|
|
|
if(PLY::Element::ParseElement(pCur,&pCur,&out))
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
// add the element to the list of elements
|
2008-10-13 16:45:48 +00:00
|
|
|
alElements.push_back(out);
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
else if (TokenMatch(pCur,"end_header",10))
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
// we have reached the end of the header
|
|
|
|
break;
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// ignore unknown header elements
|
|
|
|
SkipLine(&pCur);
|
|
|
|
}
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
2014-02-17 17:14:07 +00:00
|
|
|
if(!isBinary)
|
2014-02-07 01:38:49 +00:00
|
|
|
{ // it would occur an error, if binary data start with values as space or line end.
|
|
|
|
SkipSpacesAndLineEnd(pCur,&pCur);
|
|
|
|
}
|
2014-03-01 11:34:57 +00:00
|
|
|
*pCurOut = pCur;
|
2008-05-13 23:26:52 +00:00
|
|
|
|
|
|
|
DefaultLogger::get()->debug("PLY::DOM::ParseHeader() succeeded");
|
2008-05-05 12:36:31 +00:00
|
|
|
return true;
|
|
|
|
}
|
2009-01-18 23:48:25 +00:00
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2008-05-09 17:24:28 +00:00
|
|
|
bool PLY::DOM::ParseElementInstanceLists (
|
2008-10-13 16:45:48 +00:00
|
|
|
const char* pCur,
|
|
|
|
const char** pCurOut)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
ai_assert(NULL != pCur && NULL != pCurOut);
|
2008-05-13 23:26:52 +00:00
|
|
|
|
|
|
|
DefaultLogger::get()->debug("PLY::DOM::ParseElementInstanceLists() begin");
|
2008-10-13 16:45:48 +00:00
|
|
|
*pCurOut = pCur;
|
2008-05-13 23:26:52 +00:00
|
|
|
|
2008-10-13 16:45:48 +00:00
|
|
|
alElementData.resize(alElements.size());
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2008-10-13 16:45:48 +00:00
|
|
|
std::vector<PLY::Element>::const_iterator i = alElements.begin();
|
|
|
|
std::vector<PLY::ElementInstanceList>::iterator a = alElementData.begin();
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
// parse all element instances
|
2008-10-13 16:45:48 +00:00
|
|
|
for (;i != alElements.end();++i,++a)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
(*a).alInstances.resize((*i).NumOccur);
|
|
|
|
PLY::ElementInstanceList::ParseInstanceList(pCur,&pCur,&(*i),&(*a));
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
2008-05-13 23:26:52 +00:00
|
|
|
|
|
|
|
DefaultLogger::get()->debug("PLY::DOM::ParseElementInstanceLists() succeeded");
|
2008-10-13 16:45:48 +00:00
|
|
|
*pCurOut = pCur;
|
2008-05-05 12:36:31 +00:00
|
|
|
return true;
|
|
|
|
}
|
2009-01-18 23:48:25 +00:00
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2008-05-09 17:24:28 +00:00
|
|
|
bool PLY::DOM::ParseElementInstanceListsBinary (
|
2008-10-13 16:45:48 +00:00
|
|
|
const char* pCur,
|
|
|
|
const char** pCurOut,
|
2008-05-09 17:24:28 +00:00
|
|
|
bool p_bBE)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
ai_assert(NULL != pCur && NULL != pCurOut);
|
2008-05-13 23:26:52 +00:00
|
|
|
|
|
|
|
DefaultLogger::get()->debug("PLY::DOM::ParseElementInstanceListsBinary() begin");
|
2008-10-13 16:45:48 +00:00
|
|
|
*pCurOut = pCur;
|
2008-05-13 23:26:52 +00:00
|
|
|
|
2008-10-13 16:45:48 +00:00
|
|
|
alElementData.resize(alElements.size());
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2008-10-13 16:45:48 +00:00
|
|
|
std::vector<PLY::Element>::const_iterator i = alElements.begin();
|
|
|
|
std::vector<PLY::ElementInstanceList>::iterator a = alElementData.begin();
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
// parse all element instances
|
2008-10-13 16:45:48 +00:00
|
|
|
for (;i != alElements.end();++i,++a)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
(*a).alInstances.resize((*i).NumOccur);
|
|
|
|
PLY::ElementInstanceList::ParseInstanceListBinary(pCur,&pCur,&(*i),&(*a),p_bBE);
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
2008-05-13 23:26:52 +00:00
|
|
|
|
|
|
|
DefaultLogger::get()->debug("PLY::DOM::ParseElementInstanceListsBinary() succeeded");
|
2008-10-13 16:45:48 +00:00
|
|
|
*pCurOut = pCur;
|
2008-05-05 12:36:31 +00:00
|
|
|
return true;
|
|
|
|
}
|
2009-01-18 23:48:25 +00:00
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2008-10-13 16:45:48 +00:00
|
|
|
bool PLY::DOM::ParseInstanceBinary (const char* pCur,DOM* p_pcOut,bool p_bBE)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
ai_assert(NULL != pCur && NULL != p_pcOut);
|
2008-05-13 23:26:52 +00:00
|
|
|
|
|
|
|
DefaultLogger::get()->debug("PLY::DOM::ParseInstanceBinary() begin");
|
|
|
|
|
2014-02-17 17:14:07 +00:00
|
|
|
if(!p_pcOut->ParseHeader(pCur,&pCur,true))
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
2008-05-13 23:26:52 +00:00
|
|
|
DefaultLogger::get()->debug("PLY::DOM::ParseInstanceBinary() failure");
|
2008-05-05 12:36:31 +00:00
|
|
|
return false;
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
if(!p_pcOut->ParseElementInstanceListsBinary(pCur,&pCur,p_bBE))
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
2008-05-13 23:26:52 +00:00
|
|
|
DefaultLogger::get()->debug("PLY::DOM::ParseInstanceBinary() failure");
|
2008-05-05 12:36:31 +00:00
|
|
|
return false;
|
|
|
|
}
|
2008-05-13 23:26:52 +00:00
|
|
|
DefaultLogger::get()->debug("PLY::DOM::ParseInstanceBinary() succeeded");
|
2008-05-05 12:36:31 +00:00
|
|
|
return true;
|
|
|
|
}
|
2009-01-18 23:48:25 +00:00
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2008-10-13 16:45:48 +00:00
|
|
|
bool PLY::DOM::ParseInstance (const char* pCur,DOM* p_pcOut)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
ai_assert(NULL != pCur);
|
2008-05-13 23:26:52 +00:00
|
|
|
ai_assert(NULL != p_pcOut);
|
|
|
|
|
|
|
|
DefaultLogger::get()->debug("PLY::DOM::ParseInstance() begin");
|
|
|
|
|
2008-07-10 16:49:01 +00:00
|
|
|
|
2014-02-07 01:38:49 +00:00
|
|
|
if(!p_pcOut->ParseHeader(pCur,&pCur,false))
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
2008-05-13 23:26:52 +00:00
|
|
|
DefaultLogger::get()->debug("PLY::DOM::ParseInstance() failure");
|
2008-05-05 12:36:31 +00:00
|
|
|
return false;
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
if(!p_pcOut->ParseElementInstanceLists(pCur,&pCur))
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
2008-05-13 23:26:52 +00:00
|
|
|
DefaultLogger::get()->debug("PLY::DOM::ParseInstance() failure");
|
2008-05-05 12:36:31 +00:00
|
|
|
return false;
|
|
|
|
}
|
2008-05-13 23:26:52 +00:00
|
|
|
DefaultLogger::get()->debug("PLY::DOM::ParseInstance() succeeded");
|
2008-05-05 12:36:31 +00:00
|
|
|
return true;
|
|
|
|
}
|
2009-01-18 23:48:25 +00:00
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2008-05-13 23:26:52 +00:00
|
|
|
bool PLY::ElementInstanceList::ParseInstanceList (
|
2008-10-13 16:45:48 +00:00
|
|
|
const char* pCur,
|
|
|
|
const char** pCurOut,
|
2008-05-13 23:26:52 +00:00
|
|
|
const PLY::Element* pcElement,
|
|
|
|
PLY::ElementInstanceList* p_pcOut)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
ai_assert(NULL != pCur && NULL != pCurOut && NULL != pcElement && NULL != p_pcOut);
|
2008-05-13 23:26:52 +00:00
|
|
|
|
2008-10-13 16:45:48 +00:00
|
|
|
if (EEST_INVALID == pcElement->eSemantic || pcElement->alProperties.empty())
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
|
|
|
// if the element has an unknown semantic we can skip all lines
|
|
|
|
// However, there could be comments
|
|
|
|
for (unsigned int i = 0; i < pcElement->NumOccur;++i)
|
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
PLY::DOM::SkipComments(pCur,&pCur);
|
|
|
|
SkipLine(pCur,&pCur);
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// be sure to have enough storage
|
|
|
|
for (unsigned int i = 0; i < pcElement->NumOccur;++i)
|
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
PLY::DOM::SkipComments(pCur,&pCur);
|
|
|
|
PLY::ElementInstance::ParseInstance(pCur, &pCur,pcElement,
|
|
|
|
&p_pcOut->alInstances[i]);
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
*pCurOut = pCur;
|
2008-05-05 12:36:31 +00:00
|
|
|
return true;
|
|
|
|
}
|
2009-01-18 23:48:25 +00:00
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2008-05-09 17:24:28 +00:00
|
|
|
bool PLY::ElementInstanceList::ParseInstanceListBinary (
|
2008-10-13 16:45:48 +00:00
|
|
|
const char* pCur,
|
|
|
|
const char** pCurOut,
|
2008-05-09 17:24:28 +00:00
|
|
|
const PLY::Element* pcElement,
|
|
|
|
PLY::ElementInstanceList* p_pcOut,
|
|
|
|
bool p_bBE /* = false */)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
ai_assert(NULL != pCur && NULL != pCurOut && NULL != pcElement && NULL != p_pcOut);
|
2008-05-13 23:26:52 +00:00
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
// we can add special handling code for unknown element semantics since
|
|
|
|
// we can't skip it as a whole block (we don't know its exact size
|
|
|
|
// due to the fact that lists could be contained in the property list
|
|
|
|
// of the unknown element)
|
|
|
|
for (unsigned int i = 0; i < pcElement->NumOccur;++i)
|
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
PLY::ElementInstance::ParseInstanceBinary(pCur, &pCur,pcElement,
|
|
|
|
&p_pcOut->alInstances[i], p_bBE);
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
*pCurOut = pCur;
|
2008-05-05 12:36:31 +00:00
|
|
|
return true;
|
|
|
|
}
|
2009-01-18 23:48:25 +00:00
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2008-05-09 17:24:28 +00:00
|
|
|
bool PLY::ElementInstance::ParseInstance (
|
2008-10-13 16:45:48 +00:00
|
|
|
const char* pCur,
|
|
|
|
const char** pCurOut,
|
2008-05-09 17:24:28 +00:00
|
|
|
const PLY::Element* pcElement,
|
|
|
|
PLY::ElementInstance* p_pcOut)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
ai_assert(NULL != pCur && NULL != pCurOut && NULL != pcElement && NULL != p_pcOut);
|
2008-05-13 23:26:52 +00:00
|
|
|
|
2008-10-13 16:45:48 +00:00
|
|
|
if (!SkipSpaces(pCur, &pCur))return false;
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
// allocate enough storage
|
2008-05-05 12:36:31 +00:00
|
|
|
p_pcOut->alProperties.resize(pcElement->alProperties.size());
|
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
std::vector<PLY::PropertyInstance>::iterator i = p_pcOut->alProperties.begin();
|
2008-10-13 16:45:48 +00:00
|
|
|
std::vector<PLY::Property>::const_iterator a = pcElement->alProperties.begin();
|
2008-05-05 12:36:31 +00:00
|
|
|
for (;i != p_pcOut->alProperties.end();++i,++a)
|
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
if(!(PLY::PropertyInstance::ParseInstance(pCur, &pCur,&(*a),&(*i))))
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
2008-05-13 23:26:52 +00:00
|
|
|
DefaultLogger::get()->warn("Unable to parse property instance. "
|
|
|
|
"Skipping this element instance");
|
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
// skip the rest of the instance
|
2008-10-13 16:45:48 +00:00
|
|
|
SkipLine(pCur, &pCur);
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2008-10-13 16:45:48 +00:00
|
|
|
PLY::PropertyInstance::ValueUnion v = PLY::PropertyInstance::DefaultValue((*a).eType);
|
2008-05-05 12:36:31 +00:00
|
|
|
(*i).avList.push_back(v);
|
|
|
|
}
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
*pCurOut = pCur;
|
2008-05-05 12:36:31 +00:00
|
|
|
return true;
|
|
|
|
}
|
2009-01-18 23:48:25 +00:00
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2008-05-09 17:24:28 +00:00
|
|
|
bool PLY::ElementInstance::ParseInstanceBinary (
|
2008-10-13 16:45:48 +00:00
|
|
|
const char* pCur,
|
|
|
|
const char** pCurOut,
|
2008-05-09 17:24:28 +00:00
|
|
|
const PLY::Element* pcElement,
|
|
|
|
PLY::ElementInstance* p_pcOut,
|
|
|
|
bool p_bBE /* = false */)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
ai_assert(NULL != pCur && NULL != pCurOut && NULL != pcElement && NULL != p_pcOut);
|
2008-05-13 23:26:52 +00:00
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
// allocate enough storage
|
2008-05-05 12:36:31 +00:00
|
|
|
p_pcOut->alProperties.resize(pcElement->alProperties.size());
|
|
|
|
|
2008-05-09 17:24:28 +00:00
|
|
|
std::vector<PLY::PropertyInstance>::iterator i = p_pcOut->alProperties.begin();
|
2008-10-13 16:45:48 +00:00
|
|
|
std::vector<PLY::Property>::const_iterator a = pcElement->alProperties.begin();
|
2008-05-05 12:36:31 +00:00
|
|
|
for (;i != p_pcOut->alProperties.end();++i,++a)
|
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
if(!(PLY::PropertyInstance::ParseInstanceBinary(pCur, &pCur,&(*a),&(*i),p_bBE)))
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
2008-05-13 23:26:52 +00:00
|
|
|
DefaultLogger::get()->warn("Unable to parse binary property instance. "
|
|
|
|
"Skipping this element instance");
|
|
|
|
|
2008-10-13 16:45:48 +00:00
|
|
|
(*i).avList.push_back(PLY::PropertyInstance::DefaultValue((*a).eType));
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
*pCurOut = pCur;
|
2008-05-05 12:36:31 +00:00
|
|
|
return true;
|
|
|
|
}
|
2009-01-18 23:48:25 +00:00
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2008-10-13 16:45:48 +00:00
|
|
|
bool PLY::PropertyInstance::ParseInstance (const char* pCur,const char** pCurOut,
|
2008-05-05 12:36:31 +00:00
|
|
|
const PLY::Property* prop, PLY::PropertyInstance* p_pcOut)
|
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
ai_assert(NULL != pCur && NULL != pCurOut && NULL != prop && NULL != p_pcOut);
|
2008-05-13 23:26:52 +00:00
|
|
|
|
2008-10-13 16:45:48 +00:00
|
|
|
*pCurOut = pCur;
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
// skip spaces at the beginning
|
2008-10-13 16:45:48 +00:00
|
|
|
if (!SkipSpaces(pCur, &pCur))return false;
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
if (prop->bIsList)
|
|
|
|
{
|
|
|
|
// parse the number of elements in the list
|
|
|
|
PLY::PropertyInstance::ValueUnion v;
|
2008-10-13 16:45:48 +00:00
|
|
|
PLY::PropertyInstance::ParseValue(pCur, &pCur,prop->eFirstType,&v);
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
// convert to unsigned int
|
|
|
|
unsigned int iNum = PLY::PropertyInstance::ConvertTo<unsigned int>(v,prop->eFirstType);
|
|
|
|
|
|
|
|
// parse all list elements
|
2008-10-31 19:32:00 +00:00
|
|
|
p_pcOut->avList.resize(iNum);
|
2008-05-05 12:36:31 +00:00
|
|
|
for (unsigned int i = 0; i < iNum;++i)
|
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
if (!SkipSpaces(pCur, &pCur))return false;
|
|
|
|
PLY::PropertyInstance::ParseValue(pCur, &pCur,prop->eType,&p_pcOut->avList[i]);
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// parse the property
|
|
|
|
PLY::PropertyInstance::ValueUnion v;
|
2008-05-13 23:26:52 +00:00
|
|
|
|
2008-10-13 16:45:48 +00:00
|
|
|
PLY::PropertyInstance::ParseValue(pCur, &pCur,prop->eType,&v);
|
2008-05-05 12:36:31 +00:00
|
|
|
p_pcOut->avList.push_back(v);
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
SkipSpacesAndLineEnd(pCur, &pCur);
|
|
|
|
*pCurOut = pCur;
|
2008-05-05 12:36:31 +00:00
|
|
|
return true;
|
|
|
|
}
|
2009-01-18 23:48:25 +00:00
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2008-10-13 16:45:48 +00:00
|
|
|
bool PLY::PropertyInstance::ParseInstanceBinary (
|
|
|
|
const char* pCur,
|
|
|
|
const char** pCurOut,
|
|
|
|
const PLY::Property* prop,
|
|
|
|
PLY::PropertyInstance* p_pcOut,
|
|
|
|
bool p_bBE)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
ai_assert(NULL != pCur && NULL != pCurOut && NULL != prop && NULL != p_pcOut);
|
2008-05-13 23:26:52 +00:00
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
if (prop->bIsList)
|
|
|
|
{
|
|
|
|
// parse the number of elements in the list
|
|
|
|
PLY::PropertyInstance::ValueUnion v;
|
2008-10-13 16:45:48 +00:00
|
|
|
PLY::PropertyInstance::ParseValueBinary(pCur, &pCur,prop->eFirstType,&v,p_bBE);
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
// convert to unsigned int
|
|
|
|
unsigned int iNum = PLY::PropertyInstance::ConvertTo<unsigned int>(v,prop->eFirstType);
|
|
|
|
|
|
|
|
// parse all list elements
|
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
|
|
|
p_pcOut->avList.resize(iNum);
|
|
|
|
for (unsigned int i = 0; i < iNum;++i){
|
|
|
|
PLY::PropertyInstance::ParseValueBinary(pCur, &pCur,prop->eType,&p_pcOut->avList[i],p_bBE);
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// parse the property
|
|
|
|
PLY::PropertyInstance::ValueUnion v;
|
2008-10-13 16:45:48 +00:00
|
|
|
PLY::PropertyInstance::ParseValueBinary(pCur, &pCur,prop->eType,&v,p_bBE);
|
2008-05-05 12:36:31 +00:00
|
|
|
p_pcOut->avList.push_back(v);
|
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
*pCurOut = pCur;
|
2008-05-05 12:36:31 +00:00
|
|
|
return true;
|
|
|
|
}
|
2009-01-18 23:48:25 +00:00
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
PLY::PropertyInstance::ValueUnion PLY::PropertyInstance::DefaultValue(
|
|
|
|
PLY::EDataType eType)
|
|
|
|
{
|
|
|
|
PLY::PropertyInstance::ValueUnion out;
|
|
|
|
|
|
|
|
switch (eType)
|
|
|
|
{
|
|
|
|
case EDT_Float:
|
2008-10-13 16:45:48 +00:00
|
|
|
out.fFloat = 0.f;
|
2008-05-05 12:36:31 +00:00
|
|
|
return out;
|
|
|
|
|
|
|
|
case EDT_Double:
|
2008-10-13 16:45:48 +00:00
|
|
|
out.fDouble = 0.;
|
2008-05-05 12:36:31 +00:00
|
|
|
return out;
|
2008-09-12 20:25:11 +00:00
|
|
|
|
|
|
|
default: ;
|
2008-05-05 12:36:31 +00:00
|
|
|
};
|
|
|
|
out.iUInt = 0;
|
|
|
|
return out;
|
|
|
|
}
|
2009-01-18 23:48:25 +00:00
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2008-10-13 16:45:48 +00:00
|
|
|
bool PLY::PropertyInstance::ParseValue(
|
|
|
|
const char* pCur,
|
|
|
|
const char** pCurOut,
|
|
|
|
PLY::EDataType eType,
|
|
|
|
PLY::PropertyInstance::ValueUnion* out)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
ai_assert(NULL != pCur && NULL != pCurOut && NULL != out);
|
2008-05-13 23:26:52 +00:00
|
|
|
|
2008-10-13 16:45:48 +00:00
|
|
|
register bool ret = true;
|
|
|
|
*pCurOut = pCur;
|
2008-05-05 12:36:31 +00:00
|
|
|
switch (eType)
|
|
|
|
{
|
|
|
|
case EDT_UInt:
|
|
|
|
case EDT_UShort:
|
|
|
|
case EDT_UChar:
|
|
|
|
|
2011-03-23 14:26:19 +00:00
|
|
|
out->iUInt = (uint32_t)strtoul10(pCur, &pCur);
|
2008-05-05 12:36:31 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EDT_Int:
|
|
|
|
case EDT_Short:
|
|
|
|
case EDT_Char:
|
|
|
|
|
2011-03-23 14:26:19 +00:00
|
|
|
out->iInt = (int32_t)strtol10(pCur, &pCur);
|
2008-05-05 12:36:31 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EDT_Float:
|
|
|
|
|
2012-01-31 16:18:32 +00:00
|
|
|
pCur = fast_atoreal_move<float>(pCur,out->fFloat);
|
2008-05-05 12:36:31 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EDT_Double:
|
|
|
|
|
|
|
|
float f;
|
2012-01-31 16:18:32 +00:00
|
|
|
pCur = fast_atoreal_move<float>(pCur,f);
|
2008-05-05 12:36:31 +00:00
|
|
|
out->fDouble = (double)f;
|
2008-09-12 20:25:11 +00:00
|
|
|
break;
|
2008-05-05 12:36:31 +00:00
|
|
|
|
|
|
|
default:
|
2008-10-13 16:45:48 +00:00
|
|
|
ret = false;
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
*pCurOut = pCur;
|
|
|
|
return ret;
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
2009-01-18 23:48:25 +00:00
|
|
|
|
2008-05-05 12:36:31 +00:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2008-05-13 23:26:52 +00:00
|
|
|
bool PLY::PropertyInstance::ParseValueBinary(
|
2008-10-13 16:45:48 +00:00
|
|
|
const char* pCur,
|
|
|
|
const char** pCurOut,
|
2008-05-13 23:26:52 +00:00
|
|
|
PLY::EDataType eType,
|
|
|
|
PLY::PropertyInstance::ValueUnion* out,
|
|
|
|
bool p_bBE)
|
2008-05-05 12:36:31 +00:00
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
ai_assert(NULL != pCur && NULL != pCurOut && NULL != out);
|
2008-05-13 23:26:52 +00:00
|
|
|
|
2008-10-13 16:45:48 +00:00
|
|
|
register bool ret = true;
|
2008-05-05 12:36:31 +00:00
|
|
|
switch (eType)
|
|
|
|
{
|
|
|
|
case EDT_UInt:
|
2008-10-13 16:45:48 +00:00
|
|
|
out->iUInt = (uint32_t)*((uint32_t*)pCur);
|
|
|
|
pCur += 4;
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2008-10-13 16:45:48 +00:00
|
|
|
// Swap endianess
|
2009-01-18 23:48:25 +00:00
|
|
|
if (p_bBE)ByteSwap::Swap((int32_t*)&out->iUInt);
|
2008-05-05 12:36:31 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EDT_UShort:
|
|
|
|
{
|
2009-01-18 23:48:25 +00:00
|
|
|
int16_t i = *((uint16_t*)pCur);
|
2008-10-13 16:45:48 +00:00
|
|
|
|
|
|
|
// Swap endianess
|
2009-01-18 23:48:25 +00:00
|
|
|
if (p_bBE)ByteSwap::Swap(&i);
|
2008-05-05 12:36:31 +00:00
|
|
|
out->iUInt = (uint32_t)i;
|
2008-10-13 16:45:48 +00:00
|
|
|
pCur += 2;
|
2008-05-05 12:36:31 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case EDT_UChar:
|
|
|
|
{
|
2009-01-18 23:48:25 +00:00
|
|
|
out->iUInt = (uint32_t)(*((uint8_t*)pCur));
|
2008-10-13 16:45:48 +00:00
|
|
|
pCur ++;
|
2008-05-05 12:36:31 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case EDT_Int:
|
2008-10-13 16:45:48 +00:00
|
|
|
out->iInt = *((int32_t*)pCur);
|
|
|
|
pCur += 4;
|
2008-05-05 12:36:31 +00:00
|
|
|
|
2008-10-13 16:45:48 +00:00
|
|
|
// Swap endianess
|
2009-01-18 23:48:25 +00:00
|
|
|
if (p_bBE)ByteSwap::Swap(&out->iInt);
|
2008-05-05 12:36:31 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EDT_Short:
|
|
|
|
{
|
2008-10-13 16:45:48 +00:00
|
|
|
int16_t i = *((int16_t*)pCur);
|
|
|
|
|
|
|
|
// Swap endianess
|
2009-01-18 23:48:25 +00:00
|
|
|
if (p_bBE)ByteSwap::Swap(&i);
|
2008-05-05 12:36:31 +00:00
|
|
|
out->iInt = (int32_t)i;
|
2008-10-13 16:45:48 +00:00
|
|
|
pCur += 2;
|
2008-05-05 12:36:31 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case EDT_Char:
|
2008-10-13 16:45:48 +00:00
|
|
|
out->iInt = (int32_t)*((int8_t*)pCur);
|
|
|
|
pCur ++;
|
2008-05-05 12:36:31 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EDT_Float:
|
2008-05-13 23:26:52 +00:00
|
|
|
{
|
2009-01-18 23:48:25 +00:00
|
|
|
out->fFloat = *((float*)pCur);
|
2008-10-13 16:45:48 +00:00
|
|
|
|
|
|
|
// Swap endianess
|
2009-01-18 23:48:25 +00:00
|
|
|
if (p_bBE)ByteSwap::Swap((int32_t*)&out->fFloat);
|
2008-10-13 16:45:48 +00:00
|
|
|
pCur += 4;
|
2008-05-05 12:36:31 +00:00
|
|
|
break;
|
2008-05-13 23:26:52 +00:00
|
|
|
}
|
2008-05-05 12:36:31 +00:00
|
|
|
case EDT_Double:
|
2008-05-13 23:26:52 +00:00
|
|
|
{
|
2009-01-18 23:48:25 +00:00
|
|
|
out->fDouble = *((double*)pCur);
|
2008-10-13 16:45:48 +00:00
|
|
|
|
|
|
|
// Swap endianess
|
2009-01-18 23:48:25 +00:00
|
|
|
if (p_bBE)ByteSwap::Swap((int64_t*)&out->fDouble);
|
2008-10-13 16:45:48 +00:00
|
|
|
pCur += 8;
|
2008-05-05 12:36:31 +00:00
|
|
|
break;
|
2008-05-13 23:26:52 +00:00
|
|
|
}
|
2008-05-05 12:36:31 +00:00
|
|
|
default:
|
2008-10-13 16:45:48 +00:00
|
|
|
ret = false;
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
2008-10-13 16:45:48 +00:00
|
|
|
*pCurOut = pCur;
|
|
|
|
return ret;
|
2008-05-05 12:36:31 +00:00
|
|
|
}
|
2009-01-18 23:48:25 +00:00
|
|
|
|
|
|
|
#endif // !! ASSIMP_BUILD_NO_PLY_IMPORTER
|