3mf-importer: fix parsing of base-material color.
parent
7cd1a66c8b
commit
1d901f075c
|
@ -45,6 +45,7 @@ namespace Assimp {
|
||||||
namespace D3MF {
|
namespace D3MF {
|
||||||
|
|
||||||
namespace XmlTag {
|
namespace XmlTag {
|
||||||
|
// Model-data specific tags
|
||||||
static const std::string model = "model";
|
static const std::string model = "model";
|
||||||
static const std::string model_unit = "unit";
|
static const std::string model_unit = "unit";
|
||||||
static const std::string metadata = "metadata";
|
static const std::string metadata = "metadata";
|
||||||
|
@ -63,6 +64,7 @@ namespace XmlTag {
|
||||||
static const std::string v3 = "v3";
|
static const std::string v3 = "v3";
|
||||||
static const std::string id = "id";
|
static const std::string id = "id";
|
||||||
static const std::string pid = "pid";
|
static const std::string pid = "pid";
|
||||||
|
static const std::string p1 = "p1";
|
||||||
static const std::string name = "name";
|
static const std::string name = "name";
|
||||||
static const std::string type = "type";
|
static const std::string type = "type";
|
||||||
static const std::string build = "build";
|
static const std::string build = "build";
|
||||||
|
@ -76,6 +78,7 @@ namespace XmlTag {
|
||||||
static const std::string basematerials_name = "name";
|
static const std::string basematerials_name = "name";
|
||||||
static const std::string basematerials_displaycolor = "displaycolor";
|
static const std::string basematerials_displaycolor = "displaycolor";
|
||||||
|
|
||||||
|
// Meta info tags
|
||||||
static const std::string CONTENT_TYPES_ARCHIVE = "[Content_Types].xml";
|
static const std::string CONTENT_TYPES_ARCHIVE = "[Content_Types].xml";
|
||||||
static const std::string ROOT_RELATIONSHIPS_ARCHIVE = "_rels/.rels";
|
static const std::string ROOT_RELATIONSHIPS_ARCHIVE = "_rels/.rels";
|
||||||
static const std::string SCHEMA_CONTENTTYPES = "http://schemas.openxmlformats.org/package/2006/content-types";
|
static const std::string SCHEMA_CONTENTTYPES = "http://schemas.openxmlformats.org/package/2006/content-types";
|
||||||
|
|
|
@ -61,6 +61,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include <unzip.h>
|
#include <unzip.h>
|
||||||
#include <assimp/irrXMLWrapper.h>
|
#include <assimp/irrXMLWrapper.h>
|
||||||
#include "3MFXmlTags.h"
|
#include "3MFXmlTags.h"
|
||||||
|
#include <assimp/fast_atof.h>
|
||||||
|
|
||||||
|
#include <iomanip>
|
||||||
|
|
||||||
namespace Assimp {
|
namespace Assimp {
|
||||||
namespace D3MF {
|
namespace D3MF {
|
||||||
|
@ -175,10 +178,8 @@ private:
|
||||||
void ImportVertices(aiMesh* mesh) {
|
void ImportVertices(aiMesh* mesh) {
|
||||||
std::vector<aiVector3D> vertices;
|
std::vector<aiVector3D> vertices;
|
||||||
|
|
||||||
while(ReadToEndElement(D3MF::XmlTag::vertices))
|
while(ReadToEndElement(D3MF::XmlTag::vertices)) {
|
||||||
{
|
if(xmlReader->getNodeName() == D3MF::XmlTag::vertex) {
|
||||||
if(xmlReader->getNodeName() == D3MF::XmlTag::vertex)
|
|
||||||
{
|
|
||||||
vertices.push_back(ReadVertex());
|
vertices.push_back(ReadVertex());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -205,7 +206,7 @@ private:
|
||||||
const std::string nodeName( xmlReader->getNodeName() );
|
const std::string nodeName( xmlReader->getNodeName() );
|
||||||
if(xmlReader->getNodeName() == D3MF::XmlTag::triangle) {
|
if(xmlReader->getNodeName() == D3MF::XmlTag::triangle) {
|
||||||
faces.push_back(ReadTriangle());
|
faces.push_back(ReadTriangle());
|
||||||
const char *pidToken( xmlReader->getAttributeValue( D3MF::XmlTag::pid.c_str() ) );
|
const char *pidToken( xmlReader->getAttributeValue( D3MF::XmlTag::p1.c_str() ) );
|
||||||
if ( nullptr != pidToken ) {
|
if ( nullptr != pidToken ) {
|
||||||
int matIdx( std::atoi( pidToken ) );
|
int matIdx( std::atoi( pidToken ) );
|
||||||
mesh->mMaterialIndex = matIdx;
|
mesh->mMaterialIndex = matIdx;
|
||||||
|
@ -253,92 +254,85 @@ private:
|
||||||
if ( '#' != *buf ) {
|
if ( '#' != *buf ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
char comp[ 2 ] = { 0,0 };
|
|
||||||
comp[ 0 ] = *buf;
|
|
||||||
++buf;
|
++buf;
|
||||||
comp[ 1 ] = *buf;
|
char comp[ 3 ] = { 0,0,'\0' };
|
||||||
++buf;
|
|
||||||
diffuse.r = static_cast<ai_real>( std::atoi( comp ) );
|
|
||||||
|
|
||||||
comp[ 0 ] = *buf;
|
comp[ 0 ] = *buf;
|
||||||
++buf;
|
++buf;
|
||||||
comp[ 1 ] = *buf;
|
comp[ 1 ] = *buf;
|
||||||
++buf;
|
++buf;
|
||||||
diffuse.g = static_cast<ai_real>( std::atoi( comp ) );
|
diffuse.r = static_cast<ai_real>( strtol( comp, NULL, 16 ) );
|
||||||
|
|
||||||
|
|
||||||
comp[ 0 ] = *buf;
|
comp[ 0 ] = *buf;
|
||||||
++buf;
|
++buf;
|
||||||
comp[ 1 ] = *buf;
|
comp[ 1 ] = *buf;
|
||||||
++buf;
|
++buf;
|
||||||
diffuse.b = static_cast<ai_real>( std::atoi( comp ) );
|
diffuse.g = static_cast< ai_real >( strtol( comp, NULL, 16 ) );
|
||||||
|
|
||||||
comp[ 0 ] = *buf;
|
comp[ 0 ] = *buf;
|
||||||
++buf;
|
++buf;
|
||||||
comp[ 1 ] = *buf;
|
comp[ 1 ] = *buf;
|
||||||
++buf;
|
++buf;
|
||||||
diffuse.a = static_cast<ai_real>( std::atoi( comp ) );
|
diffuse.b = static_cast< ai_real >( strtol( comp, NULL, 16 ) );
|
||||||
|
|
||||||
|
comp[ 0 ] = *buf;
|
||||||
|
++buf;
|
||||||
|
comp[ 1 ] = *buf;
|
||||||
|
++buf;
|
||||||
|
diffuse.a = static_cast< ai_real >( strtol( comp, NULL, 16 ) );
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
aiMaterial *readMaterialDef() {
|
aiMaterial *readMaterialDef() {
|
||||||
aiMaterial *mat( nullptr );
|
aiMaterial *mat( nullptr );
|
||||||
//while ( ReadToEndElement( D3MF::XmlTag::basematerials_base ) ) {
|
const char *name( nullptr );
|
||||||
const char *name( nullptr );
|
const char *color( nullptr );
|
||||||
const char *color( nullptr );
|
const std::string nodeName( xmlReader->getNodeName() );
|
||||||
const std::string nodeName( xmlReader->getNodeName() );
|
if ( nodeName == D3MF::XmlTag::basematerials_base ) {
|
||||||
if ( nodeName == D3MF::XmlTag::basematerials_base ) {
|
name = xmlReader->getAttributeValue( D3MF::XmlTag::basematerials_name.c_str() );
|
||||||
name = xmlReader->getAttributeValue( D3MF::XmlTag::basematerials_name.c_str() );
|
|
||||||
|
|
||||||
aiString matName;
|
aiString matName;
|
||||||
matName.Set( name );
|
matName.Set( name );
|
||||||
mat = new aiMaterial;
|
mat = new aiMaterial;
|
||||||
mat->AddProperty( &matName, AI_MATKEY_NAME );
|
mat->AddProperty( &matName, AI_MATKEY_NAME );
|
||||||
|
|
||||||
color = xmlReader->getAttributeValue( D3MF::XmlTag::basematerials_displaycolor.c_str() );
|
color = xmlReader->getAttributeValue( D3MF::XmlTag::basematerials_displaycolor.c_str() );
|
||||||
aiColor4D diffuse;
|
aiColor4D diffuse;
|
||||||
if ( parseColor( color, diffuse ) ) {
|
if ( parseColor( color, diffuse ) ) {
|
||||||
mat->AddProperty<aiColor4D>( &diffuse, 1, AI_MATKEY_COLOR_DIFFUSE );
|
mat->AddProperty<aiColor4D>( &diffuse, 1, AI_MATKEY_COLOR_DIFFUSE );
|
||||||
}
|
|
||||||
}
|
}
|
||||||
//}
|
}
|
||||||
|
|
||||||
return mat;
|
return mat;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool ReadToStartElement(const std::string& startTag)
|
bool ReadToStartElement(const std::string& startTag) {
|
||||||
{
|
while(xmlReader->read()) {
|
||||||
while(xmlReader->read())
|
const std::string &nodeName( xmlReader->getNodeName() );
|
||||||
{
|
if (xmlReader->getNodeType() == irr::io::EXN_ELEMENT && nodeName == startTag) {
|
||||||
if (xmlReader->getNodeType() == irr::io::EXN_ELEMENT && xmlReader->getNodeName() == startTag)
|
|
||||||
{
|
|
||||||
return true;
|
return true;
|
||||||
}
|
} else if (xmlReader->getNodeType() == irr::io::EXN_ELEMENT_END && nodeName == startTag) {
|
||||||
else if (xmlReader->getNodeType() == irr::io::EXN_ELEMENT_END &&
|
|
||||||
xmlReader->getNodeName() == startTag)
|
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//DefaultLogger::get()->error("unexpected EOF, expected closing <" + closeTag + "> tag");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ReadToEndElement(const std::string& closeTag) {
|
bool ReadToEndElement(const std::string& closeTag) {
|
||||||
while(xmlReader->read())
|
while(xmlReader->read()) {
|
||||||
{
|
const std::string &nodeName( xmlReader->getNodeName() );
|
||||||
if (xmlReader->getNodeType() == irr::io::EXN_ELEMENT) {
|
if (xmlReader->getNodeType() == irr::io::EXN_ELEMENT) {
|
||||||
return true;
|
return true;
|
||||||
}
|
} else if (xmlReader->getNodeType() == irr::io::EXN_ELEMENT_END && nodeName == closeTag) {
|
||||||
else if (xmlReader->getNodeType() == irr::io::EXN_ELEMENT_END
|
|
||||||
&& xmlReader->getNodeName() == closeTag)
|
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DefaultLogger::get()->error("unexpected EOF, expected closing <" + closeTag + "> tag");
|
DefaultLogger::get()->error("unexpected EOF, expected closing <" + closeTag + "> tag");
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -66,49 +66,50 @@ static const unsigned int BufferSize = 4096;
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------------
|
||||||
template <class char_t>
|
template <class char_t>
|
||||||
AI_FORCE_INLINE char_t ToLower( char_t in)
|
AI_FORCE_INLINE
|
||||||
{
|
char_t ToLower( char_t in ) {
|
||||||
return (in >= (char_t)'A' && in <= (char_t)'Z') ? (char_t)(in+0x20) : in;
|
return (in >= (char_t)'A' && in <= (char_t)'Z') ? (char_t)(in+0x20) : in;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------------
|
||||||
template <class char_t>
|
template <class char_t>
|
||||||
AI_FORCE_INLINE char_t ToUpper( char_t in) {
|
AI_FORCE_INLINE
|
||||||
|
char_t ToUpper( char_t in) {
|
||||||
return (in >= (char_t)'a' && in <= (char_t)'z') ? (char_t)(in-0x20) : in;
|
return (in >= (char_t)'a' && in <= (char_t)'z') ? (char_t)(in-0x20) : in;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------------
|
||||||
template <class char_t>
|
template <class char_t>
|
||||||
AI_FORCE_INLINE bool IsUpper( char_t in)
|
AI_FORCE_INLINE
|
||||||
{
|
bool IsUpper( char_t in) {
|
||||||
return (in >= (char_t)'A' && in <= (char_t)'Z');
|
return (in >= (char_t)'A' && in <= (char_t)'Z');
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------------
|
||||||
template <class char_t>
|
template <class char_t>
|
||||||
AI_FORCE_INLINE bool IsLower( char_t in)
|
AI_FORCE_INLINE
|
||||||
{
|
bool IsLower( char_t in) {
|
||||||
return (in >= (char_t)'a' && in <= (char_t)'z');
|
return (in >= (char_t)'a' && in <= (char_t)'z');
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------------
|
||||||
template <class char_t>
|
template <class char_t>
|
||||||
AI_FORCE_INLINE bool IsSpace( char_t in)
|
AI_FORCE_INLINE
|
||||||
{
|
bool IsSpace( char_t in) {
|
||||||
return (in == (char_t)' ' || in == (char_t)'\t');
|
return (in == (char_t)' ' || in == (char_t)'\t');
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------------
|
||||||
template <class char_t>
|
template <class char_t>
|
||||||
AI_FORCE_INLINE bool IsLineEnd( char_t in)
|
AI_FORCE_INLINE
|
||||||
{
|
bool IsLineEnd( char_t in) {
|
||||||
return (in==(char_t)'\r'||in==(char_t)'\n'||in==(char_t)'\0'||in==(char_t)'\f');
|
return (in==(char_t)'\r'||in==(char_t)'\n'||in==(char_t)'\0'||in==(char_t)'\f');
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------------
|
||||||
template <class char_t>
|
template <class char_t>
|
||||||
AI_FORCE_INLINE bool IsSpaceOrNewLine( char_t in)
|
AI_FORCE_INLINE
|
||||||
{
|
bool IsSpaceOrNewLine( char_t in) {
|
||||||
return IsSpace<char_t>(in) || IsLineEnd<char_t>(in);
|
return IsSpace<char_t>(in) || IsLineEnd<char_t>(in);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -129,8 +129,8 @@ inline unsigned int strtoul16( const char* in, const char** out=0)
|
||||||
// Convert just one hex digit
|
// Convert just one hex digit
|
||||||
// Return value is UINT_MAX if the input character is not a hex digit.
|
// Return value is UINT_MAX if the input character is not a hex digit.
|
||||||
// ------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------
|
||||||
inline unsigned int HexDigitToDecimal(char in)
|
inline
|
||||||
{
|
unsigned int HexDigitToDecimal(char in) {
|
||||||
unsigned int out = UINT_MAX;
|
unsigned int out = UINT_MAX;
|
||||||
if (in >= '0' && in <= '9')
|
if (in >= '0' && in <= '9')
|
||||||
out = in - '0';
|
out = in - '0';
|
||||||
|
|
Loading…
Reference in New Issue