2015-05-19 03:48:29 +00:00
|
|
|
/*
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
Open Asset Import Library (assimp)
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
2016-01-01 20:07:24 +00:00
|
|
|
Copyright (c) 2006-2016, assimp team
|
2015-05-19 03:48:29 +00:00
|
|
|
|
|
|
|
All rights reserved.
|
|
|
|
|
2015-05-19 03:52:10 +00:00
|
|
|
Redistribution and use of this software in source and binary forms,
|
|
|
|
with or without modification, are permitted provided that the following
|
2015-05-19 03:48:29 +00:00
|
|
|
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.
|
|
|
|
|
|
|
|
* Neither the name of the assimp team, nor the names of its
|
|
|
|
contributors may be used to endorse or promote products
|
|
|
|
derived from this software without specific prior
|
|
|
|
written permission of the assimp team.
|
|
|
|
|
2015-05-19 03:52:10 +00:00
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
2015-05-19 03:48:29 +00:00
|
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
2015-05-19 03:52:10 +00:00
|
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
2015-05-19 03:48:29 +00:00
|
|
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
2015-05-19 03:52:10 +00:00
|
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
2015-05-19 03:48:29 +00:00
|
|
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
2015-05-19 03:52:10 +00:00
|
|
|
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
|
2015-05-19 03:48:29 +00:00
|
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** @file Implementation of the PLY parser class */
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef ASSIMP_BUILD_NO_PLY_IMPORTER
|
|
|
|
|
|
|
|
#include "PlyLoader.h"
|
|
|
|
#include "fast_atof.h"
|
2016-06-06 20:04:29 +00:00
|
|
|
#include <assimp/DefaultLogger.hpp>
|
2015-05-19 03:48:29 +00:00
|
|
|
#include "ByteSwapper.h"
|
|
|
|
|
|
|
|
|
|
|
|
using namespace Assimp;
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2017-02-11 13:19:34 +00:00
|
|
|
PLY::EDataType PLY::Property::ParseDataType(const char* pCur,const char** pCurOut) {
|
|
|
|
ai_assert( NULL != pCur );
|
|
|
|
ai_assert( NULL != pCurOut );
|
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
PLY::EDataType eOut = PLY::EDT_INVALID;
|
|
|
|
|
|
|
|
if (TokenMatch(pCur,"char",4) ||
|
|
|
|
TokenMatch(pCur,"int8",4))
|
|
|
|
{
|
|
|
|
eOut = PLY::EDT_Char;
|
|
|
|
}
|
|
|
|
else if (TokenMatch(pCur,"uchar",5) ||
|
|
|
|
TokenMatch(pCur,"uint8",5))
|
|
|
|
{
|
|
|
|
eOut = PLY::EDT_UChar;
|
|
|
|
}
|
|
|
|
else if (TokenMatch(pCur,"short",5) ||
|
|
|
|
TokenMatch(pCur,"int16",5))
|
|
|
|
{
|
|
|
|
eOut = PLY::EDT_Short;
|
|
|
|
}
|
|
|
|
else if (TokenMatch(pCur,"ushort",6) ||
|
|
|
|
TokenMatch(pCur,"uint16",6))
|
|
|
|
{
|
|
|
|
eOut = PLY::EDT_UShort;
|
|
|
|
}
|
|
|
|
else if (TokenMatch(pCur,"int32",5) || TokenMatch(pCur,"int",3))
|
|
|
|
{
|
|
|
|
eOut = PLY::EDT_Int;
|
|
|
|
}
|
|
|
|
else if (TokenMatch(pCur,"uint32",6) || TokenMatch(pCur,"uint",4))
|
|
|
|
{
|
|
|
|
eOut = PLY::EDT_UInt;
|
|
|
|
}
|
|
|
|
else if (TokenMatch(pCur,"float",5) || TokenMatch(pCur,"float32",7))
|
|
|
|
{
|
|
|
|
eOut = PLY::EDT_Float;
|
|
|
|
}
|
|
|
|
else if (TokenMatch(pCur,"double64",8) || TokenMatch(pCur,"double",6) ||
|
|
|
|
TokenMatch(pCur,"float64",7))
|
|
|
|
{
|
|
|
|
eOut = PLY::EDT_Double;
|
|
|
|
}
|
|
|
|
if (PLY::EDT_INVALID == eOut)
|
|
|
|
{
|
|
|
|
DefaultLogger::get()->info("Found unknown data type in PLY file. This is OK");
|
|
|
|
}
|
|
|
|
*pCurOut = pCur;
|
2017-02-11 13:19:34 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
return eOut;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2017-02-11 13:19:34 +00:00
|
|
|
PLY::ESemantic PLY::Property::ParseSemantic(const char* pCur,const char** pCurOut) {
|
|
|
|
ai_assert (NULL != pCur );
|
|
|
|
ai_assert( NULL != pCurOut );
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
PLY::ESemantic eOut = PLY::EST_INVALID;
|
2017-02-11 13:19:34 +00:00
|
|
|
if (TokenMatch(pCur,"red",3)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
eOut = PLY::EST_Red;
|
2017-02-11 13:19:34 +00:00
|
|
|
} else if (TokenMatch(pCur,"green",5)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
eOut = PLY::EST_Green;
|
2017-02-11 13:19:34 +00:00
|
|
|
} else if (TokenMatch(pCur,"blue",4)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
eOut = PLY::EST_Blue;
|
2017-02-11 13:19:34 +00:00
|
|
|
} else if (TokenMatch(pCur,"alpha",5)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
eOut = PLY::EST_Alpha;
|
2017-02-11 13:19:34 +00:00
|
|
|
} else if (TokenMatch(pCur,"vertex_index",12) || TokenMatch(pCur,"vertex_indices",14)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
eOut = PLY::EST_VertexIndex;
|
|
|
|
}
|
|
|
|
else if (TokenMatch(pCur,"material_index",14))
|
|
|
|
{
|
|
|
|
eOut = PLY::EST_MaterialIndex;
|
|
|
|
}
|
|
|
|
else if (TokenMatch(pCur,"ambient_red",11))
|
|
|
|
{
|
|
|
|
eOut = PLY::EST_AmbientRed;
|
|
|
|
}
|
|
|
|
else if (TokenMatch(pCur,"ambient_green",13))
|
|
|
|
{
|
|
|
|
eOut = PLY::EST_AmbientGreen;
|
|
|
|
}
|
|
|
|
else if (TokenMatch(pCur,"ambient_blue",12))
|
|
|
|
{
|
|
|
|
eOut = PLY::EST_AmbientBlue;
|
|
|
|
}
|
|
|
|
else if (TokenMatch(pCur,"ambient_alpha",13))
|
|
|
|
{
|
|
|
|
eOut = PLY::EST_AmbientAlpha;
|
|
|
|
}
|
|
|
|
else if (TokenMatch(pCur,"diffuse_red",11))
|
|
|
|
{
|
|
|
|
eOut = PLY::EST_DiffuseRed;
|
|
|
|
}
|
|
|
|
else if (TokenMatch(pCur,"diffuse_green",13))
|
|
|
|
{
|
|
|
|
eOut = PLY::EST_DiffuseGreen;
|
|
|
|
}
|
|
|
|
else if (TokenMatch(pCur,"diffuse_blue",12))
|
|
|
|
{
|
|
|
|
eOut = PLY::EST_DiffuseBlue;
|
|
|
|
}
|
|
|
|
else if (TokenMatch(pCur,"diffuse_alpha",13))
|
|
|
|
{
|
|
|
|
eOut = PLY::EST_DiffuseAlpha;
|
|
|
|
}
|
|
|
|
else if (TokenMatch(pCur,"specular_red",12))
|
|
|
|
{
|
|
|
|
eOut = PLY::EST_SpecularRed;
|
|
|
|
}
|
|
|
|
else if (TokenMatch(pCur,"specular_green",14))
|
|
|
|
{
|
|
|
|
eOut = PLY::EST_SpecularGreen;
|
|
|
|
}
|
|
|
|
else if (TokenMatch(pCur,"specular_blue",13))
|
|
|
|
{
|
|
|
|
eOut = PLY::EST_SpecularBlue;
|
|
|
|
}
|
|
|
|
else if (TokenMatch(pCur,"specular_alpha",14))
|
|
|
|
{
|
|
|
|
eOut = PLY::EST_SpecularAlpha;
|
|
|
|
}
|
|
|
|
else if (TokenMatch(pCur,"opacity",7))
|
|
|
|
{
|
|
|
|
eOut = PLY::EST_Opacity;
|
|
|
|
}
|
|
|
|
else if (TokenMatch(pCur,"specular_power",14))
|
|
|
|
{
|
|
|
|
eOut = PLY::EST_PhongPower;
|
|
|
|
}
|
|
|
|
else if (TokenMatch(pCur,"r",1))
|
|
|
|
{
|
|
|
|
eOut = PLY::EST_Red;
|
|
|
|
}
|
|
|
|
else if (TokenMatch(pCur,"g",1))
|
|
|
|
{
|
|
|
|
eOut = PLY::EST_Green;
|
|
|
|
}
|
|
|
|
else if (TokenMatch(pCur,"b",1))
|
|
|
|
{
|
|
|
|
eOut = PLY::EST_Blue;
|
|
|
|
}
|
|
|
|
// NOTE: Blender3D exports texture coordinates as s,t tuples
|
|
|
|
else if (TokenMatch(pCur,"u",1) || TokenMatch(pCur,"s",1) || TokenMatch(pCur,"tx",2))
|
|
|
|
{
|
|
|
|
eOut = PLY::EST_UTextureCoord;
|
|
|
|
}
|
|
|
|
else if (TokenMatch(pCur,"v",1) || TokenMatch(pCur,"t",1) || TokenMatch(pCur,"ty",2))
|
|
|
|
{
|
|
|
|
eOut = PLY::EST_VTextureCoord;
|
|
|
|
}
|
|
|
|
else if (TokenMatch(pCur,"x",1))
|
|
|
|
{
|
|
|
|
eOut = PLY::EST_XCoord;
|
2017-02-27 19:11:59 +00:00
|
|
|
} else if (TokenMatch(pCur,"y",1)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
eOut = PLY::EST_YCoord;
|
2017-02-27 19:11:59 +00:00
|
|
|
} else if (TokenMatch(pCur,"z",1)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
eOut = PLY::EST_ZCoord;
|
2017-02-27 19:11:59 +00:00
|
|
|
} else if (TokenMatch(pCur,"nx",2)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
eOut = PLY::EST_XNormal;
|
2017-02-27 19:11:59 +00:00
|
|
|
} else if (TokenMatch(pCur,"ny",2)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
eOut = PLY::EST_YNormal;
|
2017-02-27 19:11:59 +00:00
|
|
|
} else if (TokenMatch(pCur,"nz",2)) {
|
2015-05-19 03:57:13 +00:00
|
|
|
eOut = PLY::EST_ZNormal;
|
2017-02-27 19:11:59 +00:00
|
|
|
} else {
|
2015-05-19 03:57:13 +00:00
|
|
|
DefaultLogger::get()->info("Found unknown property semantic in file. This is ok");
|
|
|
|
SkipLine(&pCur);
|
|
|
|
}
|
|
|
|
*pCurOut = pCur;
|
|
|
|
return eOut;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
bool PLY::Property::ParseProperty (const char* pCur,
|
2015-05-19 03:57:13 +00:00
|
|
|
const char** pCurOut,
|
|
|
|
PLY::Property* pOut)
|
2015-05-19 03:48:29 +00:00
|
|
|
{
|
2017-02-11 13:19:34 +00:00
|
|
|
ai_assert( NULL != pCur );
|
|
|
|
ai_assert( NULL != pCurOut );
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// Forms supported:
|
|
|
|
// "property float x"
|
|
|
|
// "property list uchar int vertex_index"
|
|
|
|
*pCurOut = pCur;
|
|
|
|
|
|
|
|
// skip leading spaces
|
2017-02-11 13:19:34 +00:00
|
|
|
if (!SkipSpaces(pCur,&pCur)) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// skip the "property" string at the beginning
|
|
|
|
if (!TokenMatch(pCur,"property",8))
|
|
|
|
{
|
|
|
|
// seems not to be a valid property entry
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// get next word
|
2017-02-11 13:19:34 +00:00
|
|
|
if (!SkipSpaces(pCur,&pCur)) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
if (TokenMatch(pCur,"list",4))
|
|
|
|
{
|
|
|
|
pOut->bIsList = true;
|
|
|
|
|
|
|
|
// seems to be a list.
|
|
|
|
if(EDT_INVALID == (pOut->eFirstType = PLY::Property::ParseDataType(pCur, &pCur)))
|
|
|
|
{
|
|
|
|
// unable to parse list size data type
|
|
|
|
SkipLine(pCur,&pCur);
|
|
|
|
*pCurOut = pCur;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!SkipSpaces(pCur,&pCur))return false;
|
|
|
|
if(EDT_INVALID == (pOut->eType = PLY::Property::ParseDataType(pCur, &pCur)))
|
|
|
|
{
|
|
|
|
// unable to parse list data type
|
|
|
|
SkipLine(pCur,&pCur);
|
|
|
|
*pCurOut = pCur;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(EDT_INVALID == (pOut->eType = PLY::Property::ParseDataType(pCur, &pCur)))
|
|
|
|
{
|
|
|
|
// unable to parse data type. Skip the property
|
|
|
|
SkipLine(pCur,&pCur);
|
|
|
|
*pCurOut = pCur;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!SkipSpaces(pCur,&pCur))return false;
|
|
|
|
const char* szCur = pCur;
|
|
|
|
pOut->Semantic = PLY::Property::ParseSemantic(pCur, &pCur);
|
|
|
|
|
|
|
|
if (PLY::EST_INVALID == pOut->Semantic)
|
|
|
|
{
|
|
|
|
// store the name of the semantic
|
|
|
|
uintptr_t iDiff = (uintptr_t)pCur - (uintptr_t)szCur;
|
|
|
|
|
|
|
|
DefaultLogger::get()->info("Found unknown semantic in PLY file. This is OK");
|
|
|
|
pOut->szName = std::string(szCur,iDiff);
|
|
|
|
}
|
|
|
|
|
|
|
|
SkipSpacesAndLineEnd(pCur,&pCur);
|
|
|
|
*pCurOut = pCur;
|
2017-02-11 13:19:34 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
return true;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
PLY::EElementSemantic PLY::Element::ParseSemantic(const char* pCur,
|
2015-05-19 03:57:13 +00:00
|
|
|
const char** pCurOut)
|
2015-05-19 03:48:29 +00:00
|
|
|
{
|
2015-05-19 03:57:13 +00:00
|
|
|
ai_assert(NULL != pCur && NULL != pCurOut);
|
|
|
|
PLY::EElementSemantic eOut = PLY::EEST_INVALID;
|
|
|
|
if (TokenMatch(pCur,"vertex",6))
|
|
|
|
{
|
|
|
|
eOut = PLY::EEST_Vertex;
|
|
|
|
}
|
|
|
|
else if (TokenMatch(pCur,"face",4))
|
|
|
|
{
|
|
|
|
eOut = PLY::EEST_Face;
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
#if 0
|
2015-05-19 03:57:13 +00:00
|
|
|
// TODO: maybe implement this?
|
|
|
|
else if (TokenMatch(pCur,"range_grid",10))
|
|
|
|
{
|
|
|
|
eOut = PLY::EEST_Face;
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
#endif
|
2015-05-19 03:57:13 +00:00
|
|
|
else if (TokenMatch(pCur,"tristrips",9))
|
|
|
|
{
|
|
|
|
eOut = PLY::EEST_TriStrip;
|
|
|
|
}
|
|
|
|
else if (TokenMatch(pCur,"edge",4))
|
|
|
|
{
|
|
|
|
eOut = PLY::EEST_Edge;
|
|
|
|
}
|
|
|
|
else if (TokenMatch(pCur,"material",8))
|
|
|
|
{
|
|
|
|
eOut = PLY::EEST_Material;
|
|
|
|
}
|
|
|
|
*pCurOut = pCur;
|
2017-02-11 13:19:34 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
return eOut;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-05-19 03:52:10 +00:00
|
|
|
bool PLY::Element::ParseElement (const char* pCur,
|
2015-05-19 03:57:13 +00:00
|
|
|
const char** pCurOut,
|
|
|
|
PLY::Element* pOut)
|
2015-05-19 03:48:29 +00:00
|
|
|
{
|
2017-02-11 13:19:34 +00:00
|
|
|
ai_assert( NULL != pCur );
|
|
|
|
ai_assert( NULL != pCurOut );
|
|
|
|
ai_assert( NULL != pOut );
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// Example format: "element vertex 8"
|
|
|
|
*pCurOut = pCur;
|
|
|
|
|
|
|
|
// skip leading spaces
|
2017-02-11 13:19:34 +00:00
|
|
|
if (!SkipSpaces(&pCur)) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// skip the "element" string at the beginning
|
|
|
|
if (!TokenMatch(pCur,"element",7))
|
|
|
|
{
|
|
|
|
// seems not to be a valid property entry
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// get next word
|
|
|
|
if (!SkipSpaces(&pCur))return false;
|
|
|
|
|
|
|
|
// parse the semantic of the element
|
|
|
|
const char* szCur = pCur;
|
|
|
|
pOut->eSemantic = PLY::Element::ParseSemantic(pCur,&pCur);
|
|
|
|
if (PLY::EEST_INVALID == pOut->eSemantic)
|
|
|
|
{
|
|
|
|
// if the exact semantic can't be determined, just store
|
|
|
|
// the original string identifier
|
|
|
|
uintptr_t iDiff = (uintptr_t)pCur - (uintptr_t)szCur;
|
|
|
|
pOut->szName = std::string(szCur,iDiff);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!SkipSpaces(&pCur))return false;
|
|
|
|
|
2016-04-03 00:38:00 +00:00
|
|
|
//parse the number of occurrences of this element
|
2015-05-19 03:57:13 +00:00
|
|
|
pOut->NumOccur = strtoul10(pCur,&pCur);
|
|
|
|
|
|
|
|
// go to the next line
|
|
|
|
SkipSpacesAndLineEnd(pCur,&pCur);
|
|
|
|
|
|
|
|
// now parse all properties of the element
|
|
|
|
while(true)
|
|
|
|
{
|
|
|
|
// skip all comments
|
|
|
|
PLY::DOM::SkipComments(pCur,&pCur);
|
|
|
|
|
|
|
|
PLY::Property prop;
|
|
|
|
if(!PLY::Property::ParseProperty(pCur,&pCur,&prop))break;
|
|
|
|
pOut->alProperties.push_back(prop);
|
|
|
|
}
|
|
|
|
*pCurOut = pCur;
|
2017-02-11 13:19:34 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
return true;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
bool PLY::DOM::SkipComments (const char* pCur,
|
2015-05-19 03:57:13 +00:00
|
|
|
const char** pCurOut)
|
2015-05-19 03:48:29 +00:00
|
|
|
{
|
2017-02-11 13:19:34 +00:00
|
|
|
ai_assert( NULL != pCur );
|
|
|
|
ai_assert( NULL != pCurOut );
|
2015-05-19 03:57:13 +00:00
|
|
|
*pCurOut = pCur;
|
|
|
|
|
|
|
|
// skip spaces
|
2017-02-11 13:19:34 +00:00
|
|
|
if (!SkipSpaces(pCur,&pCur)) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
if (TokenMatch(pCur,"comment",7))
|
|
|
|
{
|
2017-02-11 13:19:34 +00:00
|
|
|
if ( !IsLineEnd(pCur[-1]) )
|
|
|
|
{
|
|
|
|
SkipLine(pCur,&pCur);
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
SkipComments(pCur,&pCur);
|
|
|
|
*pCurOut = pCur;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
*pCurOut = pCur;
|
2017-02-11 13:19:34 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
return false;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2017-02-11 13:19:34 +00:00
|
|
|
bool PLY::DOM::ParseHeader (const char* pCur,const char** pCurOut,bool isBinary) {
|
|
|
|
ai_assert( NULL != pCur );
|
|
|
|
ai_assert( NULL != pCurOut );
|
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
DefaultLogger::get()->debug("PLY::DOM::ParseHeader() begin");
|
|
|
|
|
|
|
|
// after ply and format line
|
|
|
|
*pCurOut = pCur;
|
|
|
|
|
|
|
|
// parse all elements
|
|
|
|
while ((*pCur) != '\0')
|
|
|
|
{
|
|
|
|
// skip all comments
|
|
|
|
PLY::DOM::SkipComments(pCur,&pCur);
|
|
|
|
|
|
|
|
PLY::Element out;
|
|
|
|
if(PLY::Element::ParseElement(pCur,&pCur,&out))
|
|
|
|
{
|
|
|
|
// add the element to the list of elements
|
|
|
|
alElements.push_back(out);
|
|
|
|
}
|
|
|
|
else if (TokenMatch(pCur,"end_header",10))
|
|
|
|
{
|
|
|
|
// we have reached the end of the header
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// ignore unknown header elements
|
|
|
|
SkipLine(&pCur);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!isBinary)
|
|
|
|
{ // it would occur an error, if binary data start with values as space or line end.
|
|
|
|
SkipSpacesAndLineEnd(pCur,&pCur);
|
|
|
|
}
|
|
|
|
*pCurOut = pCur;
|
|
|
|
|
|
|
|
DefaultLogger::get()->debug("PLY::DOM::ParseHeader() succeeded");
|
|
|
|
return true;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
bool PLY::DOM::ParseElementInstanceLists (
|
2015-05-19 03:57:13 +00:00
|
|
|
const char* pCur,
|
|
|
|
const char** pCurOut)
|
2015-05-19 03:48:29 +00:00
|
|
|
{
|
2017-02-11 13:19:34 +00:00
|
|
|
ai_assert( NULL != pCur );
|
|
|
|
ai_assert( NULL != pCurOut );
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
DefaultLogger::get()->debug("PLY::DOM::ParseElementInstanceLists() begin");
|
|
|
|
*pCurOut = pCur;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
alElementData.resize(alElements.size());
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
std::vector<PLY::Element>::const_iterator i = alElements.begin();
|
|
|
|
std::vector<PLY::ElementInstanceList>::iterator a = alElementData.begin();
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// parse all element instances
|
|
|
|
for (;i != alElements.end();++i,++a)
|
|
|
|
{
|
|
|
|
(*a).alInstances.resize((*i).NumOccur);
|
|
|
|
PLY::ElementInstanceList::ParseInstanceList(pCur,&pCur,&(*i),&(*a));
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
DefaultLogger::get()->debug("PLY::DOM::ParseElementInstanceLists() succeeded");
|
|
|
|
*pCurOut = pCur;
|
|
|
|
return true;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
bool PLY::DOM::ParseElementInstanceListsBinary (
|
2015-05-19 03:57:13 +00:00
|
|
|
const char* pCur,
|
|
|
|
const char** pCurOut,
|
|
|
|
bool p_bBE)
|
2015-05-19 03:48:29 +00:00
|
|
|
{
|
2017-02-11 13:19:34 +00:00
|
|
|
ai_assert( NULL != pCur );
|
|
|
|
ai_assert( NULL != pCurOut);
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
DefaultLogger::get()->debug("PLY::DOM::ParseElementInstanceListsBinary() begin");
|
|
|
|
*pCurOut = pCur;
|
2015-05-19 03:52:10 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
alElementData.resize(alElements.size());
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
std::vector<PLY::Element>::const_iterator i = alElements.begin();
|
|
|
|
std::vector<PLY::ElementInstanceList>::iterator a = alElementData.begin();
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
// parse all element instances
|
|
|
|
for (;i != alElements.end();++i,++a)
|
|
|
|
{
|
|
|
|
(*a).alInstances.resize((*i).NumOccur);
|
|
|
|
PLY::ElementInstanceList::ParseInstanceListBinary(pCur,&pCur,&(*i),&(*a),p_bBE);
|
|
|
|
}
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
DefaultLogger::get()->debug("PLY::DOM::ParseElementInstanceListsBinary() succeeded");
|
|
|
|
*pCurOut = pCur;
|
|
|
|
return true;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
bool PLY::DOM::ParseInstanceBinary (const char* pCur,DOM* p_pcOut,bool p_bBE)
|
|
|
|
{
|
2017-02-11 13:19:34 +00:00
|
|
|
ai_assert( NULL != pCur );
|
|
|
|
ai_assert( NULL != p_pcOut );
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
DefaultLogger::get()->debug("PLY::DOM::ParseInstanceBinary() begin");
|
|
|
|
|
|
|
|
if(!p_pcOut->ParseHeader(pCur,&pCur,true))
|
|
|
|
{
|
|
|
|
DefaultLogger::get()->debug("PLY::DOM::ParseInstanceBinary() failure");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if(!p_pcOut->ParseElementInstanceListsBinary(pCur,&pCur,p_bBE))
|
|
|
|
{
|
|
|
|
DefaultLogger::get()->debug("PLY::DOM::ParseInstanceBinary() failure");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
DefaultLogger::get()->debug("PLY::DOM::ParseInstanceBinary() succeeded");
|
|
|
|
return true;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
bool PLY::DOM::ParseInstance (const char* pCur,DOM* p_pcOut)
|
|
|
|
{
|
2015-05-19 03:57:13 +00:00
|
|
|
ai_assert(NULL != pCur);
|
|
|
|
ai_assert(NULL != p_pcOut);
|
|
|
|
|
|
|
|
DefaultLogger::get()->debug("PLY::DOM::ParseInstance() begin");
|
|
|
|
|
|
|
|
|
|
|
|
if(!p_pcOut->ParseHeader(pCur,&pCur,false))
|
|
|
|
{
|
|
|
|
DefaultLogger::get()->debug("PLY::DOM::ParseInstance() failure");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if(!p_pcOut->ParseElementInstanceLists(pCur,&pCur))
|
|
|
|
{
|
|
|
|
DefaultLogger::get()->debug("PLY::DOM::ParseInstance() failure");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
DefaultLogger::get()->debug("PLY::DOM::ParseInstance() succeeded");
|
|
|
|
return true;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
bool PLY::ElementInstanceList::ParseInstanceList (
|
2015-05-19 03:57:13 +00:00
|
|
|
const char* pCur,
|
|
|
|
const char** pCurOut,
|
|
|
|
const PLY::Element* pcElement,
|
|
|
|
PLY::ElementInstanceList* p_pcOut)
|
2015-05-19 03:48:29 +00:00
|
|
|
{
|
2017-02-11 13:19:34 +00:00
|
|
|
ai_assert( NULL != pCur );
|
|
|
|
ai_assert( NULL != pCurOut );
|
|
|
|
ai_assert( NULL != pcElement );
|
|
|
|
ai_assert( NULL != p_pcOut );
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
if (EEST_INVALID == pcElement->eSemantic || pcElement->alProperties.empty())
|
|
|
|
{
|
|
|
|
// 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)
|
|
|
|
{
|
|
|
|
PLY::DOM::SkipComments(pCur,&pCur);
|
|
|
|
SkipLine(pCur,&pCur);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// be sure to have enough storage
|
|
|
|
for (unsigned int i = 0; i < pcElement->NumOccur;++i)
|
|
|
|
{
|
|
|
|
PLY::DOM::SkipComments(pCur,&pCur);
|
|
|
|
PLY::ElementInstance::ParseInstance(pCur, &pCur,pcElement,
|
|
|
|
&p_pcOut->alInstances[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*pCurOut = pCur;
|
|
|
|
return true;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
bool PLY::ElementInstanceList::ParseInstanceListBinary (
|
2015-05-19 03:57:13 +00:00
|
|
|
const char* pCur,
|
|
|
|
const char** pCurOut,
|
|
|
|
const PLY::Element* pcElement,
|
|
|
|
PLY::ElementInstanceList* p_pcOut,
|
|
|
|
bool p_bBE /* = false */)
|
2015-05-19 03:48:29 +00:00
|
|
|
{
|
2017-02-11 13:19:34 +00:00
|
|
|
ai_assert( NULL != pCur );
|
|
|
|
ai_assert( NULL != pCurOut );
|
|
|
|
ai_assert( NULL != pcElement );
|
|
|
|
ai_assert( NULL != p_pcOut );
|
2015-05-19 03:57:13 +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)
|
|
|
|
{
|
|
|
|
PLY::ElementInstance::ParseInstanceBinary(pCur, &pCur,pcElement,
|
|
|
|
&p_pcOut->alInstances[i], p_bBE);
|
|
|
|
}
|
|
|
|
*pCurOut = pCur;
|
|
|
|
return true;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
bool PLY::ElementInstance::ParseInstance (
|
2015-05-19 03:57:13 +00:00
|
|
|
const char* pCur,
|
|
|
|
const char** pCurOut,
|
|
|
|
const PLY::Element* pcElement,
|
|
|
|
PLY::ElementInstance* p_pcOut)
|
2015-05-19 03:48:29 +00:00
|
|
|
{
|
2017-02-11 13:19:34 +00:00
|
|
|
ai_assert( NULL != pCur );
|
|
|
|
ai_assert( NULL != pCurOut );
|
|
|
|
ai_assert( NULL != pcElement );
|
|
|
|
ai_assert( NULL != p_pcOut );
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2017-02-11 13:19:34 +00:00
|
|
|
if (!SkipSpaces(pCur, &pCur)) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// allocate enough storage
|
|
|
|
p_pcOut->alProperties.resize(pcElement->alProperties.size());
|
|
|
|
|
|
|
|
std::vector<PLY::PropertyInstance>::iterator i = p_pcOut->alProperties.begin();
|
|
|
|
std::vector<PLY::Property>::const_iterator a = pcElement->alProperties.begin();
|
|
|
|
for (;i != p_pcOut->alProperties.end();++i,++a)
|
|
|
|
{
|
|
|
|
if(!(PLY::PropertyInstance::ParseInstance(pCur, &pCur,&(*a),&(*i))))
|
|
|
|
{
|
|
|
|
DefaultLogger::get()->warn("Unable to parse property instance. "
|
|
|
|
"Skipping this element instance");
|
|
|
|
|
|
|
|
// skip the rest of the instance
|
|
|
|
SkipLine(pCur, &pCur);
|
|
|
|
|
|
|
|
PLY::PropertyInstance::ValueUnion v = PLY::PropertyInstance::DefaultValue((*a).eType);
|
|
|
|
(*i).avList.push_back(v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*pCurOut = pCur;
|
|
|
|
return true;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
bool PLY::ElementInstance::ParseInstanceBinary (
|
2015-05-19 03:57:13 +00:00
|
|
|
const char* pCur,
|
|
|
|
const char** pCurOut,
|
|
|
|
const PLY::Element* pcElement,
|
|
|
|
PLY::ElementInstance* p_pcOut,
|
|
|
|
bool p_bBE /* = false */)
|
2015-05-19 03:48:29 +00:00
|
|
|
{
|
2017-02-11 13:19:34 +00:00
|
|
|
ai_assert( NULL != pCur );
|
|
|
|
ai_assert( NULL != pCurOut );
|
|
|
|
ai_assert( NULL != pcElement );
|
|
|
|
ai_assert( NULL != p_pcOut );
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
// allocate enough storage
|
|
|
|
p_pcOut->alProperties.resize(pcElement->alProperties.size());
|
|
|
|
|
|
|
|
std::vector<PLY::PropertyInstance>::iterator i = p_pcOut->alProperties.begin();
|
|
|
|
std::vector<PLY::Property>::const_iterator a = pcElement->alProperties.begin();
|
|
|
|
for (;i != p_pcOut->alProperties.end();++i,++a)
|
|
|
|
{
|
|
|
|
if(!(PLY::PropertyInstance::ParseInstanceBinary(pCur, &pCur,&(*a),&(*i),p_bBE)))
|
|
|
|
{
|
|
|
|
DefaultLogger::get()->warn("Unable to parse binary property instance. "
|
|
|
|
"Skipping this element instance");
|
|
|
|
|
|
|
|
(*i).avList.push_back(PLY::PropertyInstance::DefaultValue((*a).eType));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*pCurOut = pCur;
|
|
|
|
return true;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
bool PLY::PropertyInstance::ParseInstance (const char* pCur,const char** pCurOut,
|
2015-05-19 03:57:13 +00:00
|
|
|
const PLY::Property* prop, PLY::PropertyInstance* p_pcOut)
|
2015-05-19 03:48:29 +00:00
|
|
|
{
|
2017-02-11 13:19:34 +00:00
|
|
|
ai_assert( NULL != pCur );
|
|
|
|
ai_assert( NULL != pCurOut );
|
|
|
|
ai_assert( NULL != prop );
|
|
|
|
ai_assert( NULL != p_pcOut );
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
*pCurOut = pCur;
|
|
|
|
|
|
|
|
// skip spaces at the beginning
|
2017-02-11 13:19:34 +00:00
|
|
|
if (!SkipSpaces(pCur, &pCur)) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
if (prop->bIsList)
|
|
|
|
{
|
|
|
|
// parse the number of elements in the list
|
|
|
|
PLY::PropertyInstance::ValueUnion v;
|
|
|
|
PLY::PropertyInstance::ParseValue(pCur, &pCur,prop->eFirstType,&v);
|
|
|
|
|
|
|
|
// convert to unsigned int
|
|
|
|
unsigned int iNum = PLY::PropertyInstance::ConvertTo<unsigned int>(v,prop->eFirstType);
|
|
|
|
|
|
|
|
// parse all list elements
|
|
|
|
p_pcOut->avList.resize(iNum);
|
|
|
|
for (unsigned int i = 0; i < iNum;++i)
|
|
|
|
{
|
|
|
|
if (!SkipSpaces(pCur, &pCur))return false;
|
|
|
|
PLY::PropertyInstance::ParseValue(pCur, &pCur,prop->eType,&p_pcOut->avList[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// parse the property
|
|
|
|
PLY::PropertyInstance::ValueUnion v;
|
|
|
|
|
|
|
|
PLY::PropertyInstance::ParseValue(pCur, &pCur,prop->eType,&v);
|
|
|
|
p_pcOut->avList.push_back(v);
|
|
|
|
}
|
|
|
|
SkipSpacesAndLineEnd(pCur, &pCur);
|
|
|
|
*pCurOut = pCur;
|
|
|
|
return true;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
bool PLY::PropertyInstance::ParseInstanceBinary (
|
2015-05-19 03:57:13 +00:00
|
|
|
const char* pCur,
|
|
|
|
const char** pCurOut,
|
|
|
|
const PLY::Property* prop,
|
|
|
|
PLY::PropertyInstance* p_pcOut,
|
|
|
|
bool p_bBE)
|
2015-05-19 03:48:29 +00:00
|
|
|
{
|
2017-02-11 13:19:34 +00:00
|
|
|
ai_assert( NULL != pCur );
|
|
|
|
ai_assert( NULL != pCurOut );
|
|
|
|
ai_assert( NULL != prop );
|
|
|
|
ai_assert( NULL != p_pcOut );
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
if (prop->bIsList)
|
|
|
|
{
|
|
|
|
// parse the number of elements in the list
|
|
|
|
PLY::PropertyInstance::ValueUnion v;
|
|
|
|
PLY::PropertyInstance::ParseValueBinary(pCur, &pCur,prop->eFirstType,&v,p_bBE);
|
|
|
|
|
|
|
|
// convert to unsigned int
|
|
|
|
unsigned int iNum = PLY::PropertyInstance::ConvertTo<unsigned int>(v,prop->eFirstType);
|
|
|
|
|
|
|
|
// parse all list elements
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// parse the property
|
|
|
|
PLY::PropertyInstance::ValueUnion v;
|
|
|
|
PLY::PropertyInstance::ParseValueBinary(pCur, &pCur,prop->eType,&v,p_bBE);
|
|
|
|
p_pcOut->avList.push_back(v);
|
|
|
|
}
|
|
|
|
*pCurOut = pCur;
|
|
|
|
return true;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2017-02-11 13:19:34 +00:00
|
|
|
PLY::PropertyInstance::ValueUnion PLY::PropertyInstance::DefaultValue( PLY::EDataType eType )
|
2015-05-19 03:48:29 +00:00
|
|
|
{
|
2015-05-19 03:57:13 +00:00
|
|
|
PLY::PropertyInstance::ValueUnion out;
|
|
|
|
|
|
|
|
switch (eType)
|
|
|
|
{
|
|
|
|
case EDT_Float:
|
|
|
|
out.fFloat = 0.f;
|
|
|
|
return out;
|
|
|
|
|
|
|
|
case EDT_Double:
|
|
|
|
out.fDouble = 0.;
|
|
|
|
return out;
|
|
|
|
|
|
|
|
default: ;
|
|
|
|
};
|
|
|
|
out.iUInt = 0;
|
|
|
|
return out;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
bool PLY::PropertyInstance::ParseValue(
|
2015-05-19 03:57:13 +00:00
|
|
|
const char* pCur,
|
|
|
|
const char** pCurOut,
|
|
|
|
PLY::EDataType eType,
|
|
|
|
PLY::PropertyInstance::ValueUnion* out)
|
2015-05-19 03:48:29 +00:00
|
|
|
{
|
2017-02-11 13:19:34 +00:00
|
|
|
ai_assert( NULL != pCur );
|
|
|
|
ai_assert( NULL != pCurOut );
|
|
|
|
ai_assert( NULL != out );
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
bool ret = true;
|
|
|
|
*pCurOut = pCur;
|
|
|
|
switch (eType)
|
|
|
|
{
|
|
|
|
case EDT_UInt:
|
|
|
|
case EDT_UShort:
|
|
|
|
case EDT_UChar:
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
out->iUInt = (uint32_t)strtoul10(pCur, &pCur);
|
|
|
|
break;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
case EDT_Int:
|
|
|
|
case EDT_Short:
|
|
|
|
case EDT_Char:
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
out->iInt = (int32_t)strtol10(pCur, &pCur);
|
|
|
|
break;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
case EDT_Float:
|
2016-07-16 08:22:01 +00:00
|
|
|
// technically this should cast to float, but people tend to use float descriptors for double data
|
2016-12-08 02:31:51 +00:00
|
|
|
// this is the best way to not risk losing precision on import and it doesn't hurt to do this
|
2016-07-16 08:22:01 +00:00
|
|
|
ai_real f;
|
|
|
|
pCur = fast_atoreal_move<ai_real>(pCur,f);
|
|
|
|
out->fFloat = (ai_real)f;
|
2015-05-19 03:57:13 +00:00
|
|
|
break;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
case EDT_Double:
|
2016-07-16 08:22:01 +00:00
|
|
|
double d;
|
|
|
|
pCur = fast_atoreal_move<double>(pCur,d);
|
|
|
|
out->fDouble = (double)d;
|
2015-05-19 03:57:13 +00:00
|
|
|
break;
|
2015-05-19 03:48:29 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
default:
|
|
|
|
ret = false;
|
2017-02-11 13:19:34 +00:00
|
|
|
break;
|
2015-05-19 03:57:13 +00:00
|
|
|
}
|
|
|
|
*pCurOut = pCur;
|
2017-02-11 13:19:34 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
return ret;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
bool PLY::PropertyInstance::ParseValueBinary(
|
2015-05-19 03:57:13 +00:00
|
|
|
const char* pCur,
|
|
|
|
const char** pCurOut,
|
|
|
|
PLY::EDataType eType,
|
|
|
|
PLY::PropertyInstance::ValueUnion* out,
|
|
|
|
bool p_bBE)
|
2015-05-19 03:48:29 +00:00
|
|
|
{
|
2017-02-11 13:19:34 +00:00
|
|
|
ai_assert( NULL != pCur );
|
|
|
|
ai_assert( NULL != pCurOut );
|
|
|
|
ai_assert( NULL != out );
|
2015-05-19 03:57:13 +00:00
|
|
|
|
|
|
|
bool ret = true;
|
|
|
|
switch (eType)
|
|
|
|
{
|
|
|
|
case EDT_UInt:
|
|
|
|
out->iUInt = (uint32_t)*((uint32_t*)pCur);
|
|
|
|
pCur += 4;
|
|
|
|
|
2016-04-03 00:38:00 +00:00
|
|
|
// Swap endianness
|
2015-05-19 03:57:13 +00:00
|
|
|
if (p_bBE)ByteSwap::Swap((int32_t*)&out->iUInt);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EDT_UShort:
|
|
|
|
{
|
2015-10-12 18:08:25 +00:00
|
|
|
uint16_t i = *((uint16_t*)pCur);
|
2015-05-19 03:57:13 +00:00
|
|
|
|
2016-04-03 00:38:00 +00:00
|
|
|
// Swap endianness
|
2015-05-19 03:57:13 +00:00
|
|
|
if (p_bBE)ByteSwap::Swap(&i);
|
|
|
|
out->iUInt = (uint32_t)i;
|
|
|
|
pCur += 2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case EDT_UChar:
|
|
|
|
{
|
|
|
|
out->iUInt = (uint32_t)(*((uint8_t*)pCur));
|
|
|
|
pCur ++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case EDT_Int:
|
|
|
|
out->iInt = *((int32_t*)pCur);
|
|
|
|
pCur += 4;
|
|
|
|
|
2016-04-03 00:38:00 +00:00
|
|
|
// Swap endianness
|
2015-05-19 03:57:13 +00:00
|
|
|
if (p_bBE)ByteSwap::Swap(&out->iInt);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EDT_Short:
|
|
|
|
{
|
|
|
|
int16_t i = *((int16_t*)pCur);
|
|
|
|
|
2016-04-03 00:38:00 +00:00
|
|
|
// Swap endianness
|
2015-05-19 03:57:13 +00:00
|
|
|
if (p_bBE)ByteSwap::Swap(&i);
|
|
|
|
out->iInt = (int32_t)i;
|
|
|
|
pCur += 2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case EDT_Char:
|
|
|
|
out->iInt = (int32_t)*((int8_t*)pCur);
|
|
|
|
pCur ++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EDT_Float:
|
|
|
|
{
|
|
|
|
out->fFloat = *((float*)pCur);
|
|
|
|
|
2016-04-03 00:38:00 +00:00
|
|
|
// Swap endianness
|
2015-05-19 03:57:13 +00:00
|
|
|
if (p_bBE)ByteSwap::Swap((int32_t*)&out->fFloat);
|
|
|
|
pCur += 4;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case EDT_Double:
|
|
|
|
{
|
|
|
|
out->fDouble = *((double*)pCur);
|
|
|
|
|
2016-04-03 00:38:00 +00:00
|
|
|
// Swap endianness
|
2015-05-19 03:57:13 +00:00
|
|
|
if (p_bBE)ByteSwap::Swap((int64_t*)&out->fDouble);
|
|
|
|
pCur += 8;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
ret = false;
|
|
|
|
}
|
|
|
|
*pCurOut = pCur;
|
2017-02-11 13:19:34 +00:00
|
|
|
|
2015-05-19 03:57:13 +00:00
|
|
|
return ret;
|
2015-05-19 03:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // !! ASSIMP_BUILD_NO_PLY_IMPORTER
|