2014-08-27 21:00:19 +00:00
|
|
|
/*
|
|
|
|
Open Asset Import Library (assimp)
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
|
2021-02-28 11:17:54 +00:00
|
|
|
Copyright (c) 2006-2021, assimp team
|
2018-01-28 18:42:05 +00:00
|
|
|
|
2014-08-27 21:00:19 +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
|
2016-05-25 08:18:24 +00:00
|
|
|
materials provided with the distribution
|
2014-08-27 21:00:19 +00:00
|
|
|
|
|
|
|
* 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.
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
----------------------------------------------------------------------
|
|
|
|
*/
|
2015-03-19 10:37:11 +00:00
|
|
|
#ifndef ASSIMP_BUILD_NO_OPENGEX_IMPORTER
|
2014-08-27 21:00:19 +00:00
|
|
|
|
2020-05-02 13:14:38 +00:00
|
|
|
#include "AssetLib/OpenGEX/OpenGEXImporter.h"
|
2019-06-10 21:26:00 +00:00
|
|
|
#include "PostProcessing/MakeVerboseFormat.h"
|
|
|
|
|
2017-02-28 02:31:56 +00:00
|
|
|
#include <assimp/DefaultIOSystem.h>
|
2018-01-06 00:18:33 +00:00
|
|
|
#include <assimp/StringComparison.h>
|
2020-10-26 20:35:44 +00:00
|
|
|
#include <assimp/DefaultLogger.hpp>
|
2014-09-12 10:00:03 +00:00
|
|
|
|
2015-04-30 11:47:33 +00:00
|
|
|
#include <assimp/ai_assert.h>
|
2017-02-22 16:20:26 +00:00
|
|
|
#include <assimp/importerdesc.h>
|
2020-10-26 20:35:44 +00:00
|
|
|
#include <assimp/scene.h>
|
|
|
|
#include <openddlparser/OpenDDLParser.h>
|
2015-02-07 11:47:53 +00:00
|
|
|
|
2014-09-12 10:00:03 +00:00
|
|
|
#include <vector>
|
2014-08-27 21:00:19 +00:00
|
|
|
|
|
|
|
static const aiImporterDesc desc = {
|
|
|
|
"Open Game Engine Exchange",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
aiImporterFlags_SupportTextFlavour,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
2017-05-01 13:11:22 +00:00
|
|
|
"ogex"
|
2014-08-27 21:00:19 +00:00
|
|
|
};
|
|
|
|
|
2015-02-07 18:52:06 +00:00
|
|
|
namespace Grammar {
|
2020-10-26 20:35:44 +00:00
|
|
|
static const std::string MetricType = "Metric";
|
|
|
|
static const std::string Metric_DistanceType = "distance";
|
|
|
|
static const std::string Metric_AngleType = "angle";
|
|
|
|
static const std::string Metric_TimeType = "time";
|
|
|
|
static const std::string Metric_UpType = "up";
|
|
|
|
static const std::string NameType = "Name";
|
|
|
|
static const std::string ObjectRefType = "ObjectRef";
|
|
|
|
static const std::string MaterialRefType = "MaterialRef";
|
|
|
|
static const std::string MetricKeyType = "key";
|
|
|
|
static const std::string GeometryNodeType = "GeometryNode";
|
|
|
|
static const std::string CameraNodeType = "CameraNode";
|
|
|
|
static const std::string LightNodeType = "LightNode";
|
|
|
|
static const std::string GeometryObjectType = "GeometryObject";
|
|
|
|
static const std::string CameraObjectType = "CameraObject";
|
|
|
|
static const std::string LightObjectType = "LightObject";
|
|
|
|
static const std::string TransformType = "Transform";
|
|
|
|
static const std::string MeshType = "Mesh";
|
|
|
|
static const std::string VertexArrayType = "VertexArray";
|
|
|
|
static const std::string IndexArrayType = "IndexArray";
|
|
|
|
static const std::string MaterialType = "Material";
|
|
|
|
static const std::string ColorType = "Color";
|
|
|
|
static const std::string ParamType = "Param";
|
|
|
|
static const std::string TextureType = "Texture";
|
|
|
|
static const std::string AttenType = "Atten";
|
|
|
|
|
|
|
|
static const std::string DiffuseColorToken = "diffuse";
|
|
|
|
static const std::string SpecularColorToken = "specular";
|
|
|
|
static const std::string EmissionColorToken = "emission";
|
|
|
|
|
|
|
|
static const std::string DiffuseTextureToken = "diffuse";
|
|
|
|
static const std::string DiffuseSpecularTextureToken = "specular";
|
|
|
|
static const std::string SpecularPowerTextureToken = "specular_power";
|
|
|
|
static const std::string EmissionTextureToken = "emission";
|
|
|
|
static const std::string OpacyTextureToken = "opacity";
|
|
|
|
static const std::string TransparencyTextureToken = "transparency";
|
|
|
|
static const std::string NormalTextureToken = "normal";
|
|
|
|
|
|
|
|
enum TokenType {
|
|
|
|
NoneType = -1,
|
|
|
|
MetricToken,
|
|
|
|
NameToken,
|
|
|
|
ObjectRefToken,
|
|
|
|
MaterialRefToken,
|
|
|
|
MetricKeyToken,
|
|
|
|
GeometryNodeToken,
|
|
|
|
CameraNodeToken,
|
|
|
|
LightNodeToken,
|
|
|
|
GeometryObjectToken,
|
|
|
|
CameraObjectToken,
|
|
|
|
LightObjectToken,
|
|
|
|
TransformToken,
|
|
|
|
MeshToken,
|
|
|
|
VertexArrayToken,
|
|
|
|
IndexArrayToken,
|
|
|
|
MaterialToken,
|
|
|
|
ColorToken,
|
|
|
|
ParamToken,
|
|
|
|
TextureToken,
|
|
|
|
AttenToken
|
|
|
|
};
|
2015-02-10 19:09:26 +00:00
|
|
|
|
2020-10-26 20:35:44 +00:00
|
|
|
static const std::string ValidMetricToken[4] = {
|
|
|
|
Metric_DistanceType,
|
|
|
|
Metric_AngleType,
|
|
|
|
Metric_TimeType,
|
|
|
|
Metric_UpType
|
|
|
|
};
|
2015-02-10 19:09:26 +00:00
|
|
|
|
2020-10-26 20:35:44 +00:00
|
|
|
static int isValidMetricType(const char *token) {
|
|
|
|
if (nullptr == token) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-02-10 19:09:26 +00:00
|
|
|
|
2020-10-26 20:35:44 +00:00
|
|
|
int idx(-1);
|
|
|
|
for (size_t i = 0; i < 4; i++) {
|
|
|
|
if (ValidMetricToken[i] == token) {
|
|
|
|
idx = (int)i;
|
|
|
|
break;
|
|
|
|
}
|
2015-02-10 19:09:26 +00:00
|
|
|
}
|
2020-10-26 20:35:44 +00:00
|
|
|
|
|
|
|
return idx;
|
|
|
|
}
|
|
|
|
|
|
|
|
static TokenType matchTokenType(const char *tokenType) {
|
|
|
|
if (MetricType == tokenType) {
|
|
|
|
return MetricToken;
|
|
|
|
} else if (NameType == tokenType) {
|
|
|
|
return NameToken;
|
|
|
|
} else if (ObjectRefType == tokenType) {
|
|
|
|
return ObjectRefToken;
|
|
|
|
} else if (MaterialRefType == tokenType) {
|
|
|
|
return MaterialRefToken;
|
|
|
|
} else if (MetricKeyType == tokenType) {
|
|
|
|
return MetricKeyToken;
|
|
|
|
} else if (GeometryNodeType == tokenType) {
|
|
|
|
return GeometryNodeToken;
|
|
|
|
} else if (CameraNodeType == tokenType) {
|
|
|
|
return CameraNodeToken;
|
|
|
|
} else if (LightNodeType == tokenType) {
|
|
|
|
return LightNodeToken;
|
|
|
|
} else if (GeometryObjectType == tokenType) {
|
|
|
|
return GeometryObjectToken;
|
|
|
|
} else if (CameraObjectType == tokenType) {
|
|
|
|
return CameraObjectToken;
|
|
|
|
} else if (LightObjectType == tokenType) {
|
|
|
|
return LightObjectToken;
|
|
|
|
} else if (TransformType == tokenType) {
|
|
|
|
return TransformToken;
|
|
|
|
} else if (MeshType == tokenType) {
|
|
|
|
return MeshToken;
|
|
|
|
} else if (VertexArrayType == tokenType) {
|
|
|
|
return VertexArrayToken;
|
|
|
|
} else if (IndexArrayType == tokenType) {
|
|
|
|
return IndexArrayToken;
|
|
|
|
} else if (MaterialType == tokenType) {
|
|
|
|
return MaterialToken;
|
|
|
|
} else if (ColorType == tokenType) {
|
|
|
|
return ColorToken;
|
|
|
|
} else if (ParamType == tokenType) {
|
|
|
|
return ParamToken;
|
|
|
|
} else if (TextureType == tokenType) {
|
|
|
|
return TextureToken;
|
|
|
|
} else if (AttenType == tokenType) {
|
|
|
|
return AttenToken;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NoneType;
|
|
|
|
}
|
2015-02-07 18:52:06 +00:00
|
|
|
} // Namespace Grammar
|
|
|
|
|
2014-08-27 21:00:19 +00:00
|
|
|
namespace Assimp {
|
|
|
|
namespace OpenGEX {
|
|
|
|
|
2015-02-10 19:09:26 +00:00
|
|
|
USE_ODDLPARSER_NS
|
2015-02-07 11:47:53 +00:00
|
|
|
|
2016-05-08 09:09:53 +00:00
|
|
|
//------------------------------------------------------------------------------------------------
|
2020-10-26 20:35:44 +00:00
|
|
|
static void propId2StdString(Property *prop, std::string &name, std::string &key) {
|
2021-04-16 21:43:56 +00:00
|
|
|
name = key = std::string();
|
2020-10-26 20:35:44 +00:00
|
|
|
if (nullptr == prop) {
|
2016-05-08 09:09:53 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-26 20:35:44 +00:00
|
|
|
if (nullptr != prop->m_key) {
|
2019-05-24 21:03:42 +00:00
|
|
|
#ifdef ASSIMP_USE_HUNTER
|
|
|
|
name = prop->m_key->m_text.m_buffer;
|
|
|
|
#else
|
2016-05-08 09:09:53 +00:00
|
|
|
name = prop->m_key->m_buffer;
|
2019-05-24 21:03:42 +00:00
|
|
|
#endif
|
2020-10-26 20:35:44 +00:00
|
|
|
if (Value::ValueType::ddl_string == prop->m_value->m_type) {
|
2016-05-08 09:09:53 +00:00
|
|
|
key = prop->m_value->getString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-06 12:56:12 +00:00
|
|
|
//------------------------------------------------------------------------------------------------
|
2020-10-26 20:35:44 +00:00
|
|
|
OpenGEXImporter::VertexContainer::VertexContainer() :
|
|
|
|
m_numColors(0), m_colors(nullptr), m_numUVComps(), m_textureCoords() {
|
2016-01-16 14:01:53 +00:00
|
|
|
// empty
|
2015-04-04 16:52:59 +00:00
|
|
|
}
|
|
|
|
|
2015-04-06 12:56:12 +00:00
|
|
|
//------------------------------------------------------------------------------------------------
|
2015-04-04 16:52:59 +00:00
|
|
|
OpenGEXImporter::VertexContainer::~VertexContainer() {
|
2016-09-27 17:40:06 +00:00
|
|
|
delete[] m_colors;
|
2016-10-15 19:45:09 +00:00
|
|
|
|
2020-10-26 20:35:44 +00:00
|
|
|
for (auto &texcoords : m_textureCoords) {
|
|
|
|
delete[] texcoords;
|
2015-04-04 16:52:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-17 13:25:40 +00:00
|
|
|
//------------------------------------------------------------------------------------------------
|
2020-10-26 20:35:44 +00:00
|
|
|
OpenGEXImporter::RefInfo::RefInfo(aiNode *node, Type type, std::vector<std::string> &names) :
|
|
|
|
m_node(node),
|
|
|
|
m_type(type),
|
|
|
|
m_Names(names) {
|
2015-03-17 13:25:40 +00:00
|
|
|
// empty
|
2015-03-19 10:38:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------------------
|
|
|
|
OpenGEXImporter::RefInfo::~RefInfo() {
|
|
|
|
// empty
|
2015-03-17 13:25:40 +00:00
|
|
|
}
|
|
|
|
|
2014-08-27 21:00:19 +00:00
|
|
|
//------------------------------------------------------------------------------------------------
|
2020-10-26 20:35:44 +00:00
|
|
|
OpenGEXImporter::OpenGEXImporter() :
|
|
|
|
m_root(nullptr),
|
|
|
|
m_nodeChildMap(),
|
|
|
|
m_meshCache(),
|
|
|
|
m_mesh2refMap(),
|
|
|
|
m_material2refMap(),
|
|
|
|
m_ctx(nullptr),
|
|
|
|
m_metrics(),
|
|
|
|
m_currentNode(nullptr),
|
|
|
|
m_currentVertices(),
|
|
|
|
m_currentMesh(nullptr),
|
|
|
|
m_currentMaterial(nullptr),
|
|
|
|
m_currentLight(nullptr),
|
|
|
|
m_currentCamera(nullptr),
|
|
|
|
m_tokenType(Grammar::NoneType),
|
|
|
|
m_materialCache(),
|
|
|
|
m_cameraCache(),
|
|
|
|
m_lightCache(),
|
|
|
|
m_nodeStack(),
|
|
|
|
m_unresolvedRefStack() {
|
2016-02-07 16:58:28 +00:00
|
|
|
// empty
|
2014-08-27 21:00:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------------------
|
|
|
|
OpenGEXImporter::~OpenGEXImporter() {
|
2016-09-27 17:47:27 +00:00
|
|
|
m_ctx = nullptr;
|
2014-08-27 21:00:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------------------
|
2020-10-26 20:35:44 +00:00
|
|
|
bool OpenGEXImporter::CanRead(const std::string &file, IOSystem *pIOHandler, bool checkSig) const {
|
|
|
|
bool canRead(false);
|
|
|
|
if (!checkSig) {
|
|
|
|
canRead = SimpleExtensionCheck(file, "ogex");
|
2014-09-12 10:00:03 +00:00
|
|
|
} else {
|
|
|
|
static const char *token[] = { "Metric", "GeometryNode", "VertexArray (attrib", "IndexArray" };
|
2020-10-26 20:35:44 +00:00
|
|
|
canRead = BaseImporter::SearchFileHeaderForToken(pIOHandler, file, token, 4);
|
2014-09-12 10:00:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return canRead;
|
2014-08-27 21:00:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------------------
|
2020-10-26 20:35:44 +00:00
|
|
|
void OpenGEXImporter::InternReadFile(const std::string &filename, aiScene *pScene, IOSystem *pIOHandler) {
|
2014-09-12 10:00:03 +00:00
|
|
|
// open source file
|
2020-10-26 20:35:44 +00:00
|
|
|
IOStream *file = pIOHandler->Open(filename, "rb");
|
|
|
|
if (!file) {
|
|
|
|
throw DeadlyImportError("Failed to open file ", filename);
|
2014-09-12 10:00:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<char> buffer;
|
2020-10-26 20:35:44 +00:00
|
|
|
TextFileToBuffer(file, buffer);
|
|
|
|
pIOHandler->Close(file);
|
2015-02-07 11:47:53 +00:00
|
|
|
|
|
|
|
OpenDDLParser myParser;
|
2020-10-26 20:35:44 +00:00
|
|
|
myParser.setBuffer(&buffer[0], buffer.size());
|
|
|
|
bool success(myParser.parse());
|
|
|
|
if (success) {
|
2015-02-10 19:09:26 +00:00
|
|
|
m_ctx = myParser.getContext();
|
2015-03-18 20:37:57 +00:00
|
|
|
pScene->mRootNode = new aiNode;
|
2020-10-26 20:35:44 +00:00
|
|
|
pScene->mRootNode->mName.Set(filename);
|
|
|
|
handleNodes(m_ctx->m_root, pScene);
|
2015-02-07 11:47:53 +00:00
|
|
|
}
|
2015-03-16 19:34:42 +00:00
|
|
|
|
2020-10-26 20:35:44 +00:00
|
|
|
copyMeshes(pScene);
|
|
|
|
copyCameras(pScene);
|
|
|
|
copyLights(pScene);
|
|
|
|
copyMaterials(pScene);
|
2015-03-16 19:34:42 +00:00
|
|
|
resolveReferences();
|
2020-10-26 20:35:44 +00:00
|
|
|
createNodeTree(pScene);
|
2014-08-27 21:00:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------------------
|
|
|
|
const aiImporterDesc *OpenGEXImporter::GetInfo() const {
|
|
|
|
return &desc;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------------------
|
2020-10-26 20:35:44 +00:00
|
|
|
void OpenGEXImporter::SetupProperties(const Importer *pImp) {
|
|
|
|
if (nullptr == pImp) {
|
2015-02-07 18:52:06 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2014-09-12 10:00:03 +00:00
|
|
|
|
2015-02-07 18:52:06 +00:00
|
|
|
//------------------------------------------------------------------------------------------------
|
2020-10-26 20:35:44 +00:00
|
|
|
void OpenGEXImporter::handleNodes(DDLNode *node, aiScene *pScene) {
|
|
|
|
if (nullptr == node) {
|
2015-02-07 18:52:06 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DDLNode::DllNodeList childs = node->getChildNodeList();
|
2020-10-26 20:35:44 +00:00
|
|
|
for (DDLNode::DllNodeList::iterator it = childs.begin(); it != childs.end(); ++it) {
|
|
|
|
Grammar::TokenType tokenType(Grammar::matchTokenType((*it)->getType().c_str()));
|
|
|
|
switch (tokenType) {
|
|
|
|
case Grammar::MetricToken:
|
|
|
|
handleMetricNode(*it, pScene);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Grammar::NameToken:
|
|
|
|
handleNameNode(*it, pScene);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Grammar::ObjectRefToken:
|
|
|
|
handleObjectRefNode(*it, pScene);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Grammar::MaterialRefToken:
|
|
|
|
handleMaterialRefNode(*it, pScene);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Grammar::MetricKeyToken:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Grammar::GeometryNodeToken:
|
|
|
|
handleGeometryNode(*it, pScene);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Grammar::CameraNodeToken:
|
|
|
|
handleCameraNode(*it, pScene);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Grammar::LightNodeToken:
|
|
|
|
handleLightNode(*it, pScene);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Grammar::GeometryObjectToken:
|
|
|
|
handleGeometryObject(*it, pScene);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Grammar::CameraObjectToken:
|
|
|
|
handleCameraObject(*it, pScene);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Grammar::LightObjectToken:
|
|
|
|
handleLightObject(*it, pScene);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Grammar::TransformToken:
|
|
|
|
handleTransformNode(*it, pScene);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Grammar::MeshToken:
|
|
|
|
handleMeshNode(*it, pScene);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Grammar::VertexArrayToken:
|
|
|
|
handleVertexArrayNode(*it, pScene);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Grammar::IndexArrayToken:
|
|
|
|
handleIndexArrayNode(*it, pScene);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Grammar::MaterialToken:
|
|
|
|
handleMaterialNode(*it, pScene);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Grammar::ColorToken:
|
|
|
|
handleColorNode(*it, pScene);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Grammar::ParamToken:
|
|
|
|
handleParamNode(*it, pScene);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Grammar::TextureToken:
|
|
|
|
handleTextureNode(*it, pScene);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2015-02-07 18:52:06 +00:00
|
|
|
}
|
|
|
|
}
|
2014-08-27 21:00:19 +00:00
|
|
|
}
|
|
|
|
|
2015-02-07 11:47:53 +00:00
|
|
|
//------------------------------------------------------------------------------------------------
|
2020-10-26 20:35:44 +00:00
|
|
|
void OpenGEXImporter::handleMetricNode(DDLNode *node, aiScene * /*pScene*/) {
|
|
|
|
if (nullptr == node || nullptr == m_ctx) {
|
2015-02-10 19:09:26 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-26 20:35:44 +00:00
|
|
|
if (m_ctx->m_root != node->getParent()) {
|
2015-02-07 11:47:53 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-02-07 18:52:06 +00:00
|
|
|
|
2020-10-26 20:35:44 +00:00
|
|
|
Property *prop(node->getProperties());
|
|
|
|
while (nullptr != prop) {
|
|
|
|
if (nullptr != prop->m_key) {
|
|
|
|
if (Value::ValueType::ddl_string == prop->m_value->m_type) {
|
|
|
|
std::string valName((char *)prop->m_value->m_data);
|
|
|
|
int type(Grammar::isValidMetricType(valName.c_str()));
|
|
|
|
if (Grammar::NoneType != type) {
|
|
|
|
Value *val(node->getValue());
|
|
|
|
if (nullptr != val) {
|
|
|
|
if (Value::ValueType::ddl_float == val->m_type) {
|
|
|
|
m_metrics[type].m_floatValue = val->getFloat();
|
|
|
|
} else if (Value::ValueType::ddl_int32 == val->m_type) {
|
|
|
|
m_metrics[type].m_intValue = val->getInt32();
|
|
|
|
} else if (Value::ValueType::ddl_string == val->m_type) {
|
|
|
|
m_metrics[type].m_stringValue = std::string(val->getString());
|
2015-02-10 19:09:26 +00:00
|
|
|
} else {
|
2020-10-26 20:35:44 +00:00
|
|
|
throw DeadlyImportError("OpenGEX: invalid data type for Metric node.");
|
2015-02-10 19:09:26 +00:00
|
|
|
}
|
|
|
|
}
|
2015-02-07 18:52:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
prop = prop->m_next;
|
|
|
|
}
|
2015-02-07 11:47:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------------------
|
2020-10-26 20:35:44 +00:00
|
|
|
void OpenGEXImporter::handleNameNode(DDLNode *node, aiScene * /*pScene*/) {
|
|
|
|
if (nullptr == m_currentNode) {
|
|
|
|
throw DeadlyImportError("No current node for name.");
|
2015-02-14 15:12:09 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-26 20:35:44 +00:00
|
|
|
Value *val(node->getValue());
|
|
|
|
if (nullptr != val) {
|
|
|
|
if (Value::ValueType::ddl_string != val->m_type) {
|
|
|
|
throw DeadlyImportError("OpenGEX: invalid data type for value in node name.");
|
2015-03-25 20:35:32 +00:00
|
|
|
return;
|
2015-02-14 15:12:09 +00:00
|
|
|
}
|
2015-02-07 11:47:53 +00:00
|
|
|
|
2020-10-26 20:35:44 +00:00
|
|
|
const std::string name(val->getString());
|
|
|
|
if (m_tokenType == Grammar::GeometryNodeToken || m_tokenType == Grammar::LightNodeToken || m_tokenType == Grammar::CameraNodeToken) {
|
|
|
|
m_currentNode->mName.Set(name.c_str());
|
|
|
|
} else if (m_tokenType == Grammar::MaterialToken) {
|
2017-10-02 07:33:51 +00:00
|
|
|
aiString aiName;
|
2020-10-26 20:35:44 +00:00
|
|
|
aiName.Set(name);
|
|
|
|
m_currentMaterial->AddProperty(&aiName, AI_MATKEY_NAME);
|
|
|
|
m_material2refMap[name] = m_materialCache.size() - 1;
|
2015-05-05 20:27:05 +00:00
|
|
|
}
|
2015-02-14 15:12:09 +00:00
|
|
|
}
|
2015-02-07 11:47:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------------------
|
2020-10-26 20:35:44 +00:00
|
|
|
static void getRefNames(DDLNode *node, std::vector<std::string> &names) {
|
|
|
|
ai_assert(nullptr != node);
|
2015-03-16 19:34:42 +00:00
|
|
|
|
|
|
|
Reference *ref = node->getReferences();
|
2020-10-26 20:35:44 +00:00
|
|
|
if (nullptr != ref) {
|
|
|
|
for (size_t i = 0; i < ref->m_numRefs; i++) {
|
|
|
|
Name *currentName(ref->m_referencedName[i]);
|
|
|
|
if (nullptr != currentName && nullptr != currentName->m_id) {
|
2019-05-24 21:03:42 +00:00
|
|
|
#ifdef ASSIMP_USE_HUNTER
|
2020-10-26 20:35:44 +00:00
|
|
|
const std::string name(currentName->m_id->m_text.m_buffer);
|
2019-05-24 21:03:42 +00:00
|
|
|
#else
|
2020-10-26 20:35:44 +00:00
|
|
|
const std::string name(currentName->m_id->m_buffer);
|
2019-05-24 21:03:42 +00:00
|
|
|
#endif
|
2020-10-26 20:35:44 +00:00
|
|
|
if (!name.empty()) {
|
|
|
|
names.push_back(name);
|
2015-03-17 13:25:40 +00:00
|
|
|
}
|
|
|
|
}
|
2015-03-16 19:34:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-17 13:25:40 +00:00
|
|
|
//------------------------------------------------------------------------------------------------
|
2020-10-26 20:35:44 +00:00
|
|
|
void OpenGEXImporter::handleObjectRefNode(DDLNode *node, aiScene * /*pScene*/) {
|
|
|
|
if (nullptr == m_currentNode) {
|
|
|
|
throw DeadlyImportError("No parent node for name.");
|
2015-03-17 13:25:40 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::string> objRefNames;
|
2020-10-26 20:35:44 +00:00
|
|
|
getRefNames(node, objRefNames);
|
2016-10-15 19:45:09 +00:00
|
|
|
|
2016-05-08 20:31:16 +00:00
|
|
|
// when we are dealing with a geometry node prepare the mesh cache
|
2020-10-26 20:35:44 +00:00
|
|
|
if (m_tokenType == Grammar::GeometryNodeToken) {
|
2016-11-20 02:02:26 +00:00
|
|
|
m_currentNode->mNumMeshes = static_cast<unsigned int>(objRefNames.size());
|
2020-10-26 20:35:44 +00:00
|
|
|
m_currentNode->mMeshes = new unsigned int[objRefNames.size()];
|
|
|
|
if (!objRefNames.empty()) {
|
|
|
|
m_unresolvedRefStack.push_back(std::unique_ptr<RefInfo>(new RefInfo(m_currentNode, RefInfo::MeshRef, objRefNames)));
|
2016-05-08 20:31:16 +00:00
|
|
|
}
|
2020-10-26 20:35:44 +00:00
|
|
|
} else if (m_tokenType == Grammar::LightNodeToken) {
|
2017-05-16 19:07:20 +00:00
|
|
|
// TODO!
|
2020-10-26 20:35:44 +00:00
|
|
|
} else if (m_tokenType == Grammar::CameraNodeToken) {
|
2017-05-16 19:07:20 +00:00
|
|
|
// TODO!
|
2015-03-17 13:25:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------------------
|
2020-10-26 20:35:44 +00:00
|
|
|
void OpenGEXImporter::handleMaterialRefNode(ODDLParser::DDLNode *node, aiScene * /*pScene*/) {
|
|
|
|
if (nullptr == m_currentNode) {
|
|
|
|
throw DeadlyImportError("No parent node for name.");
|
2015-03-17 13:25:40 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::string> matRefNames;
|
2020-10-26 20:35:44 +00:00
|
|
|
getRefNames(node, matRefNames);
|
|
|
|
if (!matRefNames.empty()) {
|
|
|
|
m_unresolvedRefStack.push_back(std::unique_ptr<RefInfo>(new RefInfo(m_currentNode, RefInfo::MaterialRef, matRefNames)));
|
2015-03-17 13:25:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-16 19:34:42 +00:00
|
|
|
//------------------------------------------------------------------------------------------------
|
2020-10-26 20:35:44 +00:00
|
|
|
void OpenGEXImporter::handleGeometryNode(DDLNode *node, aiScene *pScene) {
|
2015-03-18 20:37:57 +00:00
|
|
|
aiNode *newNode = new aiNode;
|
2020-10-26 20:35:44 +00:00
|
|
|
pushNode(newNode, pScene);
|
2015-05-05 20:27:05 +00:00
|
|
|
m_tokenType = Grammar::GeometryNodeToken;
|
2015-03-18 20:37:57 +00:00
|
|
|
m_currentNode = newNode;
|
2020-10-26 20:35:44 +00:00
|
|
|
handleNodes(node, pScene);
|
2015-05-19 03:52:10 +00:00
|
|
|
|
2015-03-18 20:37:57 +00:00
|
|
|
popNode();
|
2015-02-07 11:47:53 +00:00
|
|
|
}
|
|
|
|
|
2016-04-28 18:20:40 +00:00
|
|
|
//------------------------------------------------------------------------------------------------
|
2020-10-26 20:35:44 +00:00
|
|
|
void OpenGEXImporter::handleCameraNode(DDLNode *node, aiScene *pScene) {
|
|
|
|
aiCamera *camera(new aiCamera);
|
|
|
|
m_cameraCache.push_back(camera);
|
2016-05-08 09:09:53 +00:00
|
|
|
m_currentCamera = camera;
|
|
|
|
|
|
|
|
aiNode *newNode = new aiNode;
|
2020-10-26 20:35:44 +00:00
|
|
|
pushNode(newNode, pScene);
|
2016-05-08 09:09:53 +00:00
|
|
|
m_tokenType = Grammar::CameraNodeToken;
|
|
|
|
m_currentNode = newNode;
|
|
|
|
|
2020-10-26 20:35:44 +00:00
|
|
|
handleNodes(node, pScene);
|
2016-04-28 18:20:40 +00:00
|
|
|
|
2016-05-08 09:09:53 +00:00
|
|
|
popNode();
|
|
|
|
|
2020-10-26 20:35:44 +00:00
|
|
|
m_currentCamera->mName.Set(newNode->mName.C_Str());
|
2016-04-28 18:20:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------------------
|
2020-10-26 20:35:44 +00:00
|
|
|
void OpenGEXImporter::handleLightNode(ODDLParser::DDLNode *node, aiScene *pScene) {
|
|
|
|
aiLight *light(new aiLight);
|
|
|
|
m_lightCache.push_back(light);
|
2016-05-08 09:09:53 +00:00
|
|
|
m_currentLight = light;
|
2016-04-28 18:20:40 +00:00
|
|
|
|
|
|
|
aiNode *newNode = new aiNode;
|
|
|
|
m_tokenType = Grammar::LightNodeToken;
|
|
|
|
m_currentNode = newNode;
|
2020-10-26 20:35:44 +00:00
|
|
|
pushNode(newNode, pScene);
|
2016-04-28 18:20:40 +00:00
|
|
|
|
2020-10-26 20:35:44 +00:00
|
|
|
handleNodes(node, pScene);
|
2016-04-28 18:20:40 +00:00
|
|
|
|
|
|
|
popNode();
|
|
|
|
|
2020-10-26 20:35:44 +00:00
|
|
|
m_currentLight->mName.Set(newNode->mName.C_Str());
|
2016-04-28 18:20:40 +00:00
|
|
|
}
|
|
|
|
|
2015-03-16 19:34:42 +00:00
|
|
|
//------------------------------------------------------------------------------------------------
|
2020-10-26 20:35:44 +00:00
|
|
|
void OpenGEXImporter::handleGeometryObject(DDLNode *node, aiScene *pScene) {
|
2016-04-28 18:20:40 +00:00
|
|
|
// parameters will be parsed normally in the tree, so just go for it
|
2020-10-26 20:35:44 +00:00
|
|
|
handleNodes(node, pScene);
|
2016-04-28 18:20:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------------------
|
2020-10-26 20:35:44 +00:00
|
|
|
void OpenGEXImporter::handleCameraObject(ODDLParser::DDLNode *node, aiScene *pScene) {
|
2016-04-28 18:20:40 +00:00
|
|
|
// parameters will be parsed normally in the tree, so just go for it
|
2016-10-15 19:45:09 +00:00
|
|
|
|
2020-10-26 20:35:44 +00:00
|
|
|
handleNodes(node, pScene);
|
2016-04-28 18:20:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------------------
|
2020-10-26 20:35:44 +00:00
|
|
|
void OpenGEXImporter::handleLightObject(ODDLParser::DDLNode *node, aiScene *pScene) {
|
|
|
|
aiLight *light(new aiLight);
|
|
|
|
m_lightCache.push_back(light);
|
2017-05-16 19:07:20 +00:00
|
|
|
std::string objName = node->getName();
|
2020-10-26 20:35:44 +00:00
|
|
|
if (!objName.empty()) {
|
|
|
|
light->mName.Set(objName);
|
2017-05-16 19:07:20 +00:00
|
|
|
}
|
|
|
|
m_currentLight = light;
|
2016-05-09 18:43:22 +00:00
|
|
|
|
2020-10-26 20:35:44 +00:00
|
|
|
Property *prop(node->findPropertyByName("type"));
|
|
|
|
if (nullptr != prop) {
|
|
|
|
if (nullptr != prop->m_value) {
|
|
|
|
std::string typeStr(prop->m_value->getString());
|
|
|
|
if ("point" == typeStr) {
|
2016-05-09 18:43:22 +00:00
|
|
|
m_currentLight->mType = aiLightSource_POINT;
|
2020-10-26 20:35:44 +00:00
|
|
|
} else if ("spot" == typeStr) {
|
2016-05-09 18:43:22 +00:00
|
|
|
m_currentLight->mType = aiLightSource_SPOT;
|
2020-10-26 20:35:44 +00:00
|
|
|
} else if ("infinite" == typeStr) {
|
2016-05-09 18:43:22 +00:00
|
|
|
m_currentLight->mType = aiLightSource_DIRECTIONAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-28 18:20:40 +00:00
|
|
|
// parameters will be parsed normally in the tree, so just go for it
|
2020-10-26 20:35:44 +00:00
|
|
|
handleNodes(node, pScene);
|
2015-03-17 13:25:40 +00:00
|
|
|
}
|
|
|
|
|
2015-03-23 23:08:42 +00:00
|
|
|
//------------------------------------------------------------------------------------------------
|
2020-10-26 20:35:44 +00:00
|
|
|
static void setMatrix(aiNode *node, DataArrayList *transformData) {
|
|
|
|
ai_assert(nullptr != node);
|
|
|
|
ai_assert(nullptr != transformData);
|
|
|
|
|
|
|
|
float m[16];
|
|
|
|
size_t i(1);
|
|
|
|
Value *next(transformData->m_dataList->m_next);
|
|
|
|
m[0] = transformData->m_dataList->getFloat();
|
|
|
|
while (next != nullptr) {
|
|
|
|
m[i] = next->getFloat();
|
2015-03-23 23:08:42 +00:00
|
|
|
next = next->m_next;
|
|
|
|
i++;
|
|
|
|
}
|
2015-05-19 03:52:10 +00:00
|
|
|
|
2017-11-14 16:46:27 +00:00
|
|
|
ai_assert(i == 16);
|
|
|
|
|
2020-10-26 20:35:44 +00:00
|
|
|
node->mTransformation.a1 = m[0];
|
|
|
|
node->mTransformation.a2 = m[4];
|
|
|
|
node->mTransformation.a3 = m[8];
|
|
|
|
node->mTransformation.a4 = m[12];
|
|
|
|
|
|
|
|
node->mTransformation.b1 = m[1];
|
|
|
|
node->mTransformation.b2 = m[5];
|
|
|
|
node->mTransformation.b3 = m[9];
|
|
|
|
node->mTransformation.b4 = m[13];
|
|
|
|
|
|
|
|
node->mTransformation.c1 = m[2];
|
|
|
|
node->mTransformation.c2 = m[6];
|
|
|
|
node->mTransformation.c3 = m[10];
|
|
|
|
node->mTransformation.c4 = m[14];
|
|
|
|
|
|
|
|
node->mTransformation.d1 = m[3];
|
|
|
|
node->mTransformation.d2 = m[7];
|
|
|
|
node->mTransformation.d3 = m[11];
|
|
|
|
node->mTransformation.d4 = m[15];
|
2015-03-23 23:08:42 +00:00
|
|
|
}
|
|
|
|
|
2015-03-17 13:25:40 +00:00
|
|
|
//------------------------------------------------------------------------------------------------
|
2020-10-26 20:35:44 +00:00
|
|
|
void OpenGEXImporter::handleTransformNode(ODDLParser::DDLNode *node, aiScene * /*pScene*/) {
|
|
|
|
if (nullptr == m_currentNode) {
|
|
|
|
throw DeadlyImportError("No parent node for name.");
|
2015-03-23 23:08:42 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-26 20:35:44 +00:00
|
|
|
DataArrayList *transformData(node->getDataArrayList());
|
|
|
|
if (nullptr != transformData) {
|
|
|
|
if (transformData->m_numItems != 16) {
|
|
|
|
throw DeadlyImportError("Invalid number of data for transform matrix.");
|
2015-03-23 23:08:42 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-10-26 20:35:44 +00:00
|
|
|
setMatrix(m_currentNode, transformData);
|
2015-05-19 03:52:10 +00:00
|
|
|
}
|
2015-03-20 15:56:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------------------
|
2020-10-26 20:35:44 +00:00
|
|
|
void OpenGEXImporter::handleMeshNode(ODDLParser::DDLNode *node, aiScene *pScene) {
|
2015-03-26 19:17:26 +00:00
|
|
|
m_currentMesh = new aiMesh;
|
2020-10-26 20:35:44 +00:00
|
|
|
const size_t meshidx(m_meshCache.size());
|
2018-05-13 14:35:03 +00:00
|
|
|
// ownership is transferred but a reference remains in m_currentMesh
|
2020-10-26 20:35:44 +00:00
|
|
|
m_meshCache.emplace_back(m_currentMesh);
|
2015-05-19 03:52:10 +00:00
|
|
|
|
2015-04-04 16:52:59 +00:00
|
|
|
Property *prop = node->getProperties();
|
2020-10-26 20:35:44 +00:00
|
|
|
if (nullptr != prop) {
|
2015-03-26 19:17:26 +00:00
|
|
|
std::string propName, propKey;
|
2020-10-26 20:35:44 +00:00
|
|
|
propId2StdString(prop, propName, propKey);
|
|
|
|
if ("primitive" == propName) {
|
|
|
|
if ("points" == propKey) {
|
2016-04-28 18:20:40 +00:00
|
|
|
m_currentMesh->mPrimitiveTypes |= aiPrimitiveType_POINT;
|
2020-10-26 20:35:44 +00:00
|
|
|
} else if ("lines" == propKey) {
|
2016-04-28 18:20:40 +00:00
|
|
|
m_currentMesh->mPrimitiveTypes |= aiPrimitiveType_LINE;
|
2020-10-26 20:35:44 +00:00
|
|
|
} else if ("triangles" == propKey) {
|
2015-03-28 11:08:59 +00:00
|
|
|
m_currentMesh->mPrimitiveTypes |= aiPrimitiveType_TRIANGLE;
|
2020-10-26 20:35:44 +00:00
|
|
|
} else if ("quads" == propKey) {
|
2016-04-28 18:20:40 +00:00
|
|
|
m_currentMesh->mPrimitiveTypes |= aiPrimitiveType_POLYGON;
|
|
|
|
} else {
|
2020-10-26 20:35:44 +00:00
|
|
|
ASSIMP_LOG_WARN_F(propKey, " is not supported primitive type.");
|
2015-03-28 11:08:59 +00:00
|
|
|
}
|
2015-03-26 19:17:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-26 20:35:44 +00:00
|
|
|
handleNodes(node, pScene);
|
2015-04-06 12:56:12 +00:00
|
|
|
|
2020-10-26 20:35:44 +00:00
|
|
|
DDLNode *parent(node->getParent());
|
|
|
|
if (nullptr != parent) {
|
2015-04-06 12:56:12 +00:00
|
|
|
const std::string &name = parent->getName();
|
2020-10-26 20:35:44 +00:00
|
|
|
m_mesh2refMap[name] = meshidx;
|
2015-04-06 12:56:12 +00:00
|
|
|
}
|
2015-03-26 19:17:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------------------
|
|
|
|
enum MeshAttribute {
|
|
|
|
None,
|
|
|
|
Position,
|
2016-09-27 17:40:06 +00:00
|
|
|
Color,
|
2015-03-26 19:17:26 +00:00
|
|
|
Normal,
|
|
|
|
TexCoord
|
|
|
|
};
|
2015-03-20 15:56:28 +00:00
|
|
|
|
2018-02-13 19:36:22 +00:00
|
|
|
static const std::string PosToken = "position";
|
|
|
|
static const std::string ColToken = "color";
|
|
|
|
static const std::string NormalToken = "normal";
|
|
|
|
static const std::string TexCoordToken = "texcoord";
|
|
|
|
|
2015-03-26 19:17:26 +00:00
|
|
|
//------------------------------------------------------------------------------------------------
|
2020-10-26 20:35:44 +00:00
|
|
|
static MeshAttribute getAttributeByName(const char *attribName) {
|
|
|
|
ai_assert(nullptr != attribName);
|
2015-03-26 19:17:26 +00:00
|
|
|
|
2020-10-26 20:35:44 +00:00
|
|
|
if (0 == strncmp(PosToken.c_str(), attribName, PosToken.size())) {
|
2015-03-26 19:17:26 +00:00
|
|
|
return Position;
|
2020-10-26 20:35:44 +00:00
|
|
|
} else if (0 == strncmp(ColToken.c_str(), attribName, ColToken.size())) {
|
2016-09-27 17:40:06 +00:00
|
|
|
return Color;
|
2020-10-26 20:35:44 +00:00
|
|
|
} else if (0 == strncmp(NormalToken.c_str(), attribName, NormalToken.size())) {
|
2015-03-26 19:17:26 +00:00
|
|
|
return Normal;
|
2020-10-26 20:35:44 +00:00
|
|
|
} else if (0 == strncmp(TexCoordToken.c_str(), attribName, TexCoordToken.size())) {
|
2015-03-26 19:17:26 +00:00
|
|
|
return TexCoord;
|
|
|
|
}
|
|
|
|
|
|
|
|
return None;
|
2015-03-20 15:56:28 +00:00
|
|
|
}
|
|
|
|
|
2015-03-29 16:53:23 +00:00
|
|
|
//------------------------------------------------------------------------------------------------
|
2020-10-26 20:35:44 +00:00
|
|
|
static void fillVector3(aiVector3D *vec3, Value *vals) {
|
|
|
|
ai_assert(nullptr != vec3);
|
|
|
|
ai_assert(nullptr != vals);
|
2015-03-29 16:53:23 +00:00
|
|
|
|
2020-10-26 20:35:44 +00:00
|
|
|
float x(0.0f), y(0.0f), z(0.0f);
|
|
|
|
Value *next(vals);
|
2015-03-29 16:53:23 +00:00
|
|
|
x = next->getFloat();
|
|
|
|
next = next->m_next;
|
|
|
|
y = next->getFloat();
|
|
|
|
next = next->m_next;
|
2020-10-26 20:35:44 +00:00
|
|
|
if (nullptr != next) {
|
2015-03-29 16:53:23 +00:00
|
|
|
z = next->getFloat();
|
|
|
|
}
|
|
|
|
|
2020-10-26 20:35:44 +00:00
|
|
|
vec3->Set(x, y, z);
|
2015-03-29 16:53:23 +00:00
|
|
|
}
|
|
|
|
|
2016-09-27 17:40:06 +00:00
|
|
|
//------------------------------------------------------------------------------------------------
|
2020-10-26 20:35:44 +00:00
|
|
|
static void fillColor4(aiColor4D *col4, Value *vals) {
|
|
|
|
ai_assert(nullptr != col4);
|
|
|
|
ai_assert(nullptr != vals);
|
2016-09-27 17:40:06 +00:00
|
|
|
|
2020-10-26 20:35:44 +00:00
|
|
|
Value *next(vals);
|
2016-09-27 17:40:06 +00:00
|
|
|
col4->r = next->getFloat();
|
|
|
|
next = next->m_next;
|
2017-12-24 12:57:14 +00:00
|
|
|
if (!next) {
|
2020-10-26 20:35:44 +00:00
|
|
|
throw DeadlyImportError("OpenGEX: Not enough values to fill 4-element color, only 1");
|
2017-12-24 12:57:14 +00:00
|
|
|
}
|
|
|
|
|
2016-09-27 17:40:06 +00:00
|
|
|
col4->g = next->getFloat();
|
|
|
|
next = next->m_next;
|
2017-12-24 12:57:14 +00:00
|
|
|
if (!next) {
|
2020-10-26 20:35:44 +00:00
|
|
|
throw DeadlyImportError("OpenGEX: Not enough values to fill 4-element color, only 2");
|
2017-12-24 12:57:14 +00:00
|
|
|
}
|
|
|
|
|
2016-09-27 17:40:06 +00:00
|
|
|
col4->b = next->getFloat();
|
|
|
|
next = next->m_next;
|
2017-12-24 12:57:14 +00:00
|
|
|
if (!next) {
|
2020-10-26 20:35:44 +00:00
|
|
|
throw DeadlyImportError("OpenGEX: Not enough values to fill 4-element color, only 3");
|
2017-12-24 12:57:14 +00:00
|
|
|
}
|
|
|
|
|
2016-09-27 17:40:06 +00:00
|
|
|
col4->a = next->getFloat();
|
|
|
|
}
|
|
|
|
|
2015-03-29 16:53:23 +00:00
|
|
|
//------------------------------------------------------------------------------------------------
|
2020-10-26 20:35:44 +00:00
|
|
|
static size_t countDataArrayListItems(DataArrayList *vaList) {
|
|
|
|
size_t numItems(0);
|
|
|
|
if (nullptr == vaList) {
|
2015-03-29 16:53:23 +00:00
|
|
|
return numItems;
|
|
|
|
}
|
|
|
|
|
2020-10-26 20:35:44 +00:00
|
|
|
DataArrayList *next(vaList);
|
|
|
|
while (nullptr != next) {
|
|
|
|
if (nullptr != vaList->m_dataList) {
|
2015-03-29 16:53:23 +00:00
|
|
|
numItems++;
|
|
|
|
}
|
|
|
|
next = next->m_next;
|
|
|
|
}
|
|
|
|
|
|
|
|
return numItems;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------------------
|
2020-10-26 20:35:44 +00:00
|
|
|
static void copyVectorArray(size_t numItems, DataArrayList *vaList, aiVector3D *vectorArray) {
|
|
|
|
for (size_t i = 0; i < numItems; i++) {
|
|
|
|
Value *next(vaList->m_dataList);
|
|
|
|
fillVector3(&vectorArray[i], next);
|
2015-03-29 16:53:23 +00:00
|
|
|
vaList = vaList->m_next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-27 17:40:06 +00:00
|
|
|
//------------------------------------------------------------------------------------------------
|
2020-10-26 20:35:44 +00:00
|
|
|
static void copyColor4DArray(size_t numItems, DataArrayList *vaList, aiColor4D *colArray) {
|
|
|
|
for (size_t i = 0; i < numItems; i++) {
|
|
|
|
Value *next(vaList->m_dataList);
|
|
|
|
fillColor4(&colArray[i], next);
|
2016-09-27 17:40:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-20 15:56:28 +00:00
|
|
|
//------------------------------------------------------------------------------------------------
|
2020-10-26 20:35:44 +00:00
|
|
|
void OpenGEXImporter::handleVertexArrayNode(ODDLParser::DDLNode *node, aiScene * /*pScene*/) {
|
|
|
|
if (nullptr == node) {
|
|
|
|
throw DeadlyImportError("No parent node for name.");
|
2015-03-26 19:17:26 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-03-20 15:56:28 +00:00
|
|
|
|
2020-10-26 20:35:44 +00:00
|
|
|
Property *prop(node->getProperties());
|
|
|
|
if (nullptr != prop) {
|
2015-03-26 19:17:26 +00:00
|
|
|
std::string propName, propKey;
|
2020-10-26 20:35:44 +00:00
|
|
|
propId2StdString(prop, propName, propKey);
|
|
|
|
MeshAttribute attribType(getAttributeByName(propKey.c_str()));
|
|
|
|
if (None == attribType) {
|
2015-03-26 19:17:26 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DataArrayList *vaList = node->getDataArrayList();
|
2020-10-26 20:35:44 +00:00
|
|
|
if (nullptr == vaList) {
|
2015-03-26 19:17:26 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-26 20:35:44 +00:00
|
|
|
const size_t numItems(countDataArrayListItems(vaList));
|
2016-01-16 14:01:53 +00:00
|
|
|
|
2020-10-26 20:35:44 +00:00
|
|
|
if (Position == attribType) {
|
|
|
|
m_currentVertices.m_vertices.resize(numItems);
|
|
|
|
copyVectorArray(numItems, vaList, m_currentVertices.m_vertices.data());
|
|
|
|
} else if (Color == attribType) {
|
2016-09-27 17:40:06 +00:00
|
|
|
m_currentVertices.m_numColors = numItems;
|
2020-10-26 20:35:44 +00:00
|
|
|
m_currentVertices.m_colors = new aiColor4D[numItems];
|
|
|
|
copyColor4DArray(numItems, vaList, m_currentVertices.m_colors);
|
|
|
|
} else if (Normal == attribType) {
|
|
|
|
m_currentVertices.m_normals.resize(numItems);
|
|
|
|
copyVectorArray(numItems, vaList, m_currentVertices.m_normals.data());
|
|
|
|
} else if (TexCoord == attribType) {
|
|
|
|
m_currentVertices.m_numUVComps[0] = numItems;
|
|
|
|
m_currentVertices.m_textureCoords[0] = new aiVector3D[numItems];
|
|
|
|
copyVectorArray(numItems, vaList, m_currentVertices.m_textureCoords[0]);
|
2015-03-26 19:17:26 +00:00
|
|
|
}
|
|
|
|
}
|
2015-03-20 15:56:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------------------
|
2020-10-26 20:35:44 +00:00
|
|
|
void OpenGEXImporter::handleIndexArrayNode(ODDLParser::DDLNode *node, aiScene * /*pScene*/) {
|
|
|
|
if (nullptr == node) {
|
|
|
|
throw DeadlyImportError("No parent node for name.");
|
2015-03-30 09:55:57 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-03-20 15:56:28 +00:00
|
|
|
|
2020-10-26 20:35:44 +00:00
|
|
|
if (nullptr == m_currentMesh) {
|
|
|
|
throw DeadlyImportError("No current mesh for index data found.");
|
2015-04-04 16:52:59 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-03-30 09:55:57 +00:00
|
|
|
DataArrayList *vaList = node->getDataArrayList();
|
2020-10-26 20:35:44 +00:00
|
|
|
if (nullptr == vaList) {
|
2015-03-30 09:55:57 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-26 20:35:44 +00:00
|
|
|
const size_t numItems(countDataArrayListItems(vaList));
|
2016-11-20 02:02:26 +00:00
|
|
|
m_currentMesh->mNumFaces = static_cast<unsigned int>(numItems);
|
2020-10-26 20:35:44 +00:00
|
|
|
m_currentMesh->mFaces = new aiFace[numItems];
|
2016-11-20 02:02:26 +00:00
|
|
|
m_currentMesh->mNumVertices = static_cast<unsigned int>(numItems * 3);
|
2020-10-26 20:35:44 +00:00
|
|
|
m_currentMesh->mVertices = new aiVector3D[m_currentMesh->mNumVertices];
|
|
|
|
bool hasColors(false);
|
|
|
|
if (m_currentVertices.m_numColors > 0) {
|
|
|
|
m_currentMesh->mColors[0] = new aiColor4D[m_currentVertices.m_numColors];
|
2016-09-27 17:40:06 +00:00
|
|
|
hasColors = true;
|
|
|
|
}
|
2020-10-26 20:35:44 +00:00
|
|
|
bool hasNormalCoords(false);
|
|
|
|
if (!m_currentVertices.m_normals.empty()) {
|
|
|
|
m_currentMesh->mNormals = new aiVector3D[m_currentMesh->mNumVertices];
|
2016-05-08 09:09:53 +00:00
|
|
|
hasNormalCoords = true;
|
|
|
|
}
|
2020-10-26 20:35:44 +00:00
|
|
|
bool hasTexCoords(false);
|
|
|
|
if (m_currentVertices.m_numUVComps[0] > 0) {
|
|
|
|
m_currentMesh->mTextureCoords[0] = new aiVector3D[m_currentMesh->mNumVertices];
|
2016-05-08 09:09:53 +00:00
|
|
|
hasTexCoords = true;
|
|
|
|
}
|
2015-04-04 16:52:59 +00:00
|
|
|
|
2020-10-26 20:35:44 +00:00
|
|
|
unsigned int index(0);
|
|
|
|
for (size_t i = 0; i < m_currentMesh->mNumFaces; i++) {
|
|
|
|
aiFace ¤t(m_currentMesh->mFaces[i]);
|
2015-04-04 16:52:59 +00:00
|
|
|
current.mNumIndices = 3;
|
2020-10-26 20:35:44 +00:00
|
|
|
current.mIndices = new unsigned int[current.mNumIndices];
|
|
|
|
Value *next(vaList->m_dataList);
|
|
|
|
for (size_t indices = 0; indices < current.mNumIndices; indices++) {
|
|
|
|
const int idx(next->getUnsignedInt32());
|
|
|
|
ai_assert(static_cast<size_t>(idx) <= m_currentVertices.m_vertices.size());
|
|
|
|
ai_assert(index < m_currentMesh->mNumVertices);
|
|
|
|
aiVector3D &pos = (m_currentVertices.m_vertices[idx]);
|
|
|
|
m_currentMesh->mVertices[index].Set(pos.x, pos.y, pos.z);
|
|
|
|
if (hasColors) {
|
|
|
|
aiColor4D &col = m_currentVertices.m_colors[idx];
|
|
|
|
m_currentMesh->mColors[0][index] = col;
|
2016-09-27 17:40:06 +00:00
|
|
|
}
|
2020-10-26 20:35:44 +00:00
|
|
|
if (hasNormalCoords) {
|
|
|
|
aiVector3D &normal = (m_currentVertices.m_normals[idx]);
|
|
|
|
m_currentMesh->mNormals[index].Set(normal.x, normal.y, normal.z);
|
2016-05-08 09:09:53 +00:00
|
|
|
}
|
2020-10-26 20:35:44 +00:00
|
|
|
if (hasTexCoords) {
|
|
|
|
aiVector3D &tex = (m_currentVertices.m_textureCoords[0][idx]);
|
|
|
|
m_currentMesh->mTextureCoords[0][index].Set(tex.x, tex.y, tex.z);
|
2016-05-08 09:09:53 +00:00
|
|
|
}
|
2020-10-26 20:35:44 +00:00
|
|
|
current.mIndices[indices] = index;
|
2015-04-04 16:52:59 +00:00
|
|
|
index++;
|
2015-05-19 03:52:10 +00:00
|
|
|
|
2015-03-30 09:55:57 +00:00
|
|
|
next = next->m_next;
|
|
|
|
}
|
|
|
|
vaList = vaList->m_next;
|
|
|
|
}
|
2015-03-20 15:56:28 +00:00
|
|
|
}
|
|
|
|
|
2015-04-16 09:10:12 +00:00
|
|
|
//------------------------------------------------------------------------------------------------
|
2020-10-26 20:35:44 +00:00
|
|
|
static void getColorRGB3(aiColor3D *pColor, DataArrayList *colList) {
|
|
|
|
if (nullptr == pColor || nullptr == colList) {
|
2015-04-16 09:10:12 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-05-19 03:52:10 +00:00
|
|
|
|
2020-10-26 20:35:44 +00:00
|
|
|
ai_assert(3 == colList->m_numItems);
|
|
|
|
Value *val(colList->m_dataList);
|
2015-04-30 10:54:59 +00:00
|
|
|
pColor->r = val->getFloat();
|
|
|
|
val = val->getNext();
|
|
|
|
pColor->g = val->getFloat();
|
|
|
|
val = val->getNext();
|
|
|
|
pColor->b = val->getFloat();
|
2015-04-16 09:10:12 +00:00
|
|
|
}
|
|
|
|
|
2017-05-16 19:45:23 +00:00
|
|
|
//------------------------------------------------------------------------------------------------
|
2020-10-26 20:35:44 +00:00
|
|
|
static void getColorRGB4(aiColor4D *pColor, DataArrayList *colList) {
|
|
|
|
if (nullptr == pColor || nullptr == colList) {
|
2017-05-16 19:45:23 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-26 20:35:44 +00:00
|
|
|
ai_assert(4 == colList->m_numItems);
|
|
|
|
Value *val(colList->m_dataList);
|
2017-05-16 19:45:23 +00:00
|
|
|
pColor->r = val->getFloat();
|
|
|
|
val = val->getNext();
|
|
|
|
pColor->g = val->getFloat();
|
|
|
|
val = val->getNext();
|
|
|
|
pColor->b = val->getFloat();
|
|
|
|
val = val->getNext();
|
|
|
|
pColor->a = val->getFloat();
|
|
|
|
}
|
|
|
|
|
2015-04-16 09:10:12 +00:00
|
|
|
//------------------------------------------------------------------------------------------------
|
|
|
|
enum ColorType {
|
|
|
|
NoneColor = 0,
|
2015-04-29 09:57:39 +00:00
|
|
|
DiffuseColor,
|
|
|
|
SpecularColor,
|
2016-05-09 18:43:22 +00:00
|
|
|
EmissionColor,
|
|
|
|
LightColor
|
2015-04-16 09:10:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------------------
|
2020-10-26 20:35:44 +00:00
|
|
|
static ColorType getColorType(Text *id) {
|
|
|
|
if (nullptr == id) {
|
2016-02-07 16:58:28 +00:00
|
|
|
return NoneColor;
|
|
|
|
}
|
|
|
|
|
2020-10-26 20:35:44 +00:00
|
|
|
if (*id == Grammar::DiffuseColorToken) {
|
2015-04-16 09:10:12 +00:00
|
|
|
return DiffuseColor;
|
2020-10-26 20:35:44 +00:00
|
|
|
} else if (*id == Grammar::SpecularColorToken) {
|
2015-04-29 09:57:39 +00:00
|
|
|
return SpecularColor;
|
2020-10-26 20:35:44 +00:00
|
|
|
} else if (*id == Grammar::EmissionColorToken) {
|
2015-04-29 09:57:39 +00:00
|
|
|
return EmissionColor;
|
2020-10-26 20:35:44 +00:00
|
|
|
} else if (*id == "light") {
|
2016-05-09 18:43:22 +00:00
|
|
|
return LightColor;
|
2015-04-16 09:10:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NoneColor;
|
|
|
|
}
|
|
|
|
|
2015-03-20 15:56:28 +00:00
|
|
|
//------------------------------------------------------------------------------------------------
|
2020-10-26 20:35:44 +00:00
|
|
|
void OpenGEXImporter::handleMaterialNode(ODDLParser::DDLNode *node, aiScene *pScene) {
|
2015-04-16 09:10:12 +00:00
|
|
|
m_currentMaterial = new aiMaterial;
|
2020-10-26 20:35:44 +00:00
|
|
|
m_materialCache.push_back(m_currentMaterial);
|
2015-05-05 20:27:05 +00:00
|
|
|
m_tokenType = Grammar::MaterialToken;
|
2020-10-26 20:35:44 +00:00
|
|
|
handleNodes(node, pScene);
|
2015-03-16 19:34:42 +00:00
|
|
|
}
|
|
|
|
|
2015-04-08 18:43:55 +00:00
|
|
|
//------------------------------------------------------------------------------------------------
|
2020-10-26 20:35:44 +00:00
|
|
|
void OpenGEXImporter::handleColorNode(ODDLParser::DDLNode *node, aiScene * /*pScene*/) {
|
|
|
|
if (nullptr == node) {
|
2015-04-16 09:10:12 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-04-08 18:43:55 +00:00
|
|
|
|
2020-10-26 20:35:44 +00:00
|
|
|
Property *prop = node->findPropertyByName("attrib");
|
|
|
|
if (nullptr != prop) {
|
|
|
|
if (nullptr != prop->m_value) {
|
|
|
|
DataArrayList *colList(node->getDataArrayList());
|
|
|
|
if (nullptr == colList) {
|
2015-04-30 10:54:59 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-04-29 09:57:39 +00:00
|
|
|
aiColor3D col;
|
2020-10-26 20:35:44 +00:00
|
|
|
if (3 == colList->m_numItems) {
|
2017-05-16 19:45:23 +00:00
|
|
|
aiColor3D col3;
|
2020-10-26 20:35:44 +00:00
|
|
|
getColorRGB3(&col3, colList);
|
2017-05-16 19:45:23 +00:00
|
|
|
col = col3;
|
|
|
|
} else {
|
|
|
|
aiColor4D col4;
|
2020-10-26 20:35:44 +00:00
|
|
|
getColorRGB4(&col4, colList);
|
2017-05-16 19:45:23 +00:00
|
|
|
col.r = col4.r;
|
|
|
|
col.g = col4.g;
|
|
|
|
col.b = col4.b;
|
|
|
|
}
|
2019-05-24 21:03:42 +00:00
|
|
|
#ifdef ASSIMP_USE_HUNTER
|
2020-10-26 20:35:44 +00:00
|
|
|
const ColorType colType(getColorType(&prop->m_key->m_text));
|
2019-05-24 21:03:42 +00:00
|
|
|
#else
|
2020-10-26 20:35:44 +00:00
|
|
|
const ColorType colType(getColorType(prop->m_key));
|
2019-05-24 21:03:42 +00:00
|
|
|
#endif
|
2020-10-26 20:35:44 +00:00
|
|
|
if (DiffuseColor == colType) {
|
|
|
|
m_currentMaterial->AddProperty(&col, 1, AI_MATKEY_COLOR_DIFFUSE);
|
|
|
|
} else if (SpecularColor == colType) {
|
|
|
|
m_currentMaterial->AddProperty(&col, 1, AI_MATKEY_COLOR_SPECULAR);
|
|
|
|
} else if (EmissionColor == colType) {
|
|
|
|
m_currentMaterial->AddProperty(&col, 1, AI_MATKEY_COLOR_EMISSIVE);
|
|
|
|
} else if (LightColor == colType) {
|
2016-05-09 18:43:22 +00:00
|
|
|
m_currentLight->mColorDiffuse = col;
|
2015-04-29 09:57:39 +00:00
|
|
|
}
|
2015-04-16 09:10:12 +00:00
|
|
|
}
|
|
|
|
}
|
2015-04-08 18:43:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------------------
|
2020-10-26 20:35:44 +00:00
|
|
|
void OpenGEXImporter::handleTextureNode(ODDLParser::DDLNode *node, aiScene * /*pScene*/) {
|
|
|
|
if (nullptr == node) {
|
2015-05-29 18:45:31 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-04-08 18:43:55 +00:00
|
|
|
|
2020-10-26 20:35:44 +00:00
|
|
|
Property *prop = node->findPropertyByName("attrib");
|
|
|
|
if (nullptr != prop) {
|
|
|
|
if (nullptr != prop->m_value) {
|
|
|
|
Value *val(node->getValue());
|
|
|
|
if (nullptr != val) {
|
2015-05-29 18:45:31 +00:00
|
|
|
aiString tex;
|
2020-10-26 20:35:44 +00:00
|
|
|
tex.Set(val->getString());
|
|
|
|
if (prop->m_value->getString() == Grammar::DiffuseTextureToken) {
|
|
|
|
m_currentMaterial->AddProperty(&tex, AI_MATKEY_TEXTURE_DIFFUSE(0));
|
|
|
|
} else if (prop->m_value->getString() == Grammar::SpecularPowerTextureToken) {
|
|
|
|
m_currentMaterial->AddProperty(&tex, AI_MATKEY_TEXTURE_SPECULAR(0));
|
|
|
|
} else if (prop->m_value->getString() == Grammar::EmissionTextureToken) {
|
|
|
|
m_currentMaterial->AddProperty(&tex, AI_MATKEY_TEXTURE_EMISSIVE(0));
|
|
|
|
} else if (prop->m_value->getString() == Grammar::OpacyTextureToken) {
|
|
|
|
m_currentMaterial->AddProperty(&tex, AI_MATKEY_TEXTURE_OPACITY(0));
|
|
|
|
} else if (prop->m_value->getString() == Grammar::TransparencyTextureToken) {
|
2015-05-31 18:36:55 +00:00
|
|
|
// ToDo!
|
|
|
|
// m_currentMaterial->AddProperty( &tex, AI_MATKEY_TEXTURE_DIFFUSE( 0 ) );
|
2020-10-26 20:35:44 +00:00
|
|
|
} else if (prop->m_value->getString() == Grammar::NormalTextureToken) {
|
|
|
|
m_currentMaterial->AddProperty(&tex, AI_MATKEY_TEXTURE_NORMALS(0));
|
2016-04-28 18:20:40 +00:00
|
|
|
} else {
|
2020-10-26 20:35:44 +00:00
|
|
|
ai_assert(false);
|
2015-05-29 18:45:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-04-08 18:43:55 +00:00
|
|
|
}
|
|
|
|
|
2016-05-08 09:09:53 +00:00
|
|
|
//------------------------------------------------------------------------------------------------
|
2020-10-26 20:35:44 +00:00
|
|
|
void OpenGEXImporter::handleParamNode(ODDLParser::DDLNode *node, aiScene * /*pScene*/) {
|
|
|
|
if (nullptr == node) {
|
2016-05-08 09:09:53 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-26 20:35:44 +00:00
|
|
|
Property *prop = node->findPropertyByName("attrib");
|
|
|
|
if (nullptr == prop) {
|
2016-05-14 08:10:05 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-26 20:35:44 +00:00
|
|
|
if (nullptr != prop->m_value) {
|
|
|
|
Value *val(node->getValue());
|
|
|
|
if (nullptr == val) {
|
2016-05-14 08:10:05 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-10-26 20:35:44 +00:00
|
|
|
const float floatVal(val->getFloat());
|
|
|
|
if (0 == ASSIMP_strincmp("fov", prop->m_value->getString(), 3)) {
|
2018-02-13 19:36:22 +00:00
|
|
|
m_currentCamera->mHorizontalFOV = floatVal;
|
2020-10-26 20:35:44 +00:00
|
|
|
} else if (0 == ASSIMP_strincmp("near", prop->m_value->getString(), 4)) {
|
2018-02-13 19:36:22 +00:00
|
|
|
m_currentCamera->mClipPlaneNear = floatVal;
|
2020-10-26 20:35:44 +00:00
|
|
|
} else if (0 == ASSIMP_strincmp("far", prop->m_value->getString(), 3)) {
|
2018-02-13 19:36:22 +00:00
|
|
|
m_currentCamera->mClipPlaneFar = floatVal;
|
2016-05-08 09:09:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-09 18:43:22 +00:00
|
|
|
//------------------------------------------------------------------------------------------------
|
2020-10-26 20:35:44 +00:00
|
|
|
void OpenGEXImporter::handleAttenNode(ODDLParser::DDLNode *node, aiScene * /*pScene*/) {
|
|
|
|
if (nullptr == node) {
|
2016-05-09 18:43:22 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-26 20:35:44 +00:00
|
|
|
Property *prop = node->findPropertyByName("curve");
|
|
|
|
if (nullptr != prop) {
|
|
|
|
if (nullptr != prop->m_value) {
|
|
|
|
Value *val(node->getValue());
|
|
|
|
const float floatVal(val->getFloat());
|
|
|
|
if (0 == strncmp("scale", prop->m_value->getString(), strlen("scale"))) {
|
2016-05-09 18:43:22 +00:00
|
|
|
m_currentLight->mAttenuationQuadratic = floatVal;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-30 21:54:32 +00:00
|
|
|
//------------------------------------------------------------------------------------------------
|
2020-10-26 20:35:44 +00:00
|
|
|
void OpenGEXImporter::copyMeshes(aiScene *pScene) {
|
|
|
|
ai_assert(nullptr != pScene);
|
2016-05-08 20:31:16 +00:00
|
|
|
|
2020-10-26 20:35:44 +00:00
|
|
|
if (m_meshCache.empty()) {
|
2015-03-30 21:54:32 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-05-19 03:52:10 +00:00
|
|
|
|
2016-11-20 02:02:26 +00:00
|
|
|
pScene->mNumMeshes = static_cast<unsigned int>(m_meshCache.size());
|
2020-10-26 20:35:44 +00:00
|
|
|
pScene->mMeshes = new aiMesh *[pScene->mNumMeshes];
|
2018-02-06 18:08:49 +00:00
|
|
|
for (unsigned int i = 0; i < pScene->mNumMeshes; i++) {
|
2018-02-06 18:20:16 +00:00
|
|
|
pScene->mMeshes[i] = m_meshCache[i].release();
|
2018-02-06 18:08:49 +00:00
|
|
|
}
|
2015-03-30 21:54:32 +00:00
|
|
|
}
|
|
|
|
|
2016-05-08 20:31:16 +00:00
|
|
|
//------------------------------------------------------------------------------------------------
|
2020-10-26 20:35:44 +00:00
|
|
|
void OpenGEXImporter::copyCameras(aiScene *pScene) {
|
|
|
|
ai_assert(nullptr != pScene);
|
2016-05-08 20:31:16 +00:00
|
|
|
|
2020-10-26 20:35:44 +00:00
|
|
|
if (m_cameraCache.empty()) {
|
2016-05-08 20:31:16 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-11-20 02:02:26 +00:00
|
|
|
pScene->mNumCameras = static_cast<unsigned int>(m_cameraCache.size());
|
2020-10-26 20:35:44 +00:00
|
|
|
pScene->mCameras = new aiCamera *[pScene->mNumCameras];
|
|
|
|
std::copy(m_cameraCache.begin(), m_cameraCache.end(), pScene->mCameras);
|
2016-05-08 20:31:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------------------
|
2020-10-26 20:35:44 +00:00
|
|
|
void OpenGEXImporter::copyLights(aiScene *pScene) {
|
|
|
|
ai_assert(nullptr != pScene);
|
2016-05-08 20:31:16 +00:00
|
|
|
|
2020-10-26 20:35:44 +00:00
|
|
|
if (m_lightCache.empty()) {
|
2016-05-08 20:31:16 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-11-20 02:02:26 +00:00
|
|
|
pScene->mNumLights = static_cast<unsigned int>(m_lightCache.size());
|
2020-10-26 20:35:44 +00:00
|
|
|
pScene->mLights = new aiLight *[pScene->mNumLights];
|
|
|
|
std::copy(m_lightCache.begin(), m_lightCache.end(), pScene->mLights);
|
2016-05-08 20:31:16 +00:00
|
|
|
}
|
|
|
|
|
2017-10-05 09:51:08 +00:00
|
|
|
//------------------------------------------------------------------------------------------------
|
2020-10-26 20:35:44 +00:00
|
|
|
void OpenGEXImporter::copyMaterials(aiScene *pScene) {
|
|
|
|
ai_assert(nullptr != pScene);
|
2017-10-05 09:51:08 +00:00
|
|
|
|
2020-10-26 20:35:44 +00:00
|
|
|
if (m_materialCache.empty()) {
|
2017-10-05 09:51:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
pScene->mNumMaterials = static_cast<unsigned int>(m_materialCache.size());
|
2020-10-26 20:35:44 +00:00
|
|
|
pScene->mMaterials = new aiMaterial *[pScene->mNumMaterials];
|
|
|
|
std::copy(m_materialCache.begin(), m_materialCache.end(), pScene->mMaterials);
|
2017-10-05 09:51:08 +00:00
|
|
|
}
|
|
|
|
|
2015-03-16 19:34:42 +00:00
|
|
|
//------------------------------------------------------------------------------------------------
|
|
|
|
void OpenGEXImporter::resolveReferences() {
|
2020-10-26 20:35:44 +00:00
|
|
|
if (m_unresolvedRefStack.empty()) {
|
2015-03-17 13:25:40 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-03-16 19:34:42 +00:00
|
|
|
|
2020-10-26 20:35:44 +00:00
|
|
|
RefInfo *currentRefInfo(nullptr);
|
|
|
|
for (auto it = m_unresolvedRefStack.begin(); it != m_unresolvedRefStack.end(); ++it) {
|
2017-10-05 09:43:49 +00:00
|
|
|
currentRefInfo = it->get();
|
2020-10-26 20:35:44 +00:00
|
|
|
if (nullptr != currentRefInfo) {
|
|
|
|
aiNode *node(currentRefInfo->m_node);
|
|
|
|
if (RefInfo::MeshRef == currentRefInfo->m_type) {
|
|
|
|
for (size_t i = 0; i < currentRefInfo->m_Names.size(); ++i) {
|
|
|
|
const std::string &name(currentRefInfo->m_Names[i]);
|
|
|
|
ReferenceMap::const_iterator curIt(m_mesh2refMap.find(name));
|
2020-03-01 12:15:45 +00:00
|
|
|
if (m_mesh2refMap.end() != curIt) {
|
2020-10-26 20:35:44 +00:00
|
|
|
unsigned int meshIdx = static_cast<unsigned int>(m_mesh2refMap[name]);
|
|
|
|
node->mMeshes[i] = meshIdx;
|
2015-04-06 12:56:12 +00:00
|
|
|
}
|
2015-03-17 13:25:40 +00:00
|
|
|
}
|
2020-10-26 20:35:44 +00:00
|
|
|
} else if (RefInfo::MaterialRef == currentRefInfo->m_type) {
|
|
|
|
for (size_t i = 0; i < currentRefInfo->m_Names.size(); ++i) {
|
|
|
|
const std::string name(currentRefInfo->m_Names[i]);
|
2020-03-01 12:15:45 +00:00
|
|
|
ReferenceMap::const_iterator curIt(m_material2refMap.find(name));
|
|
|
|
if (m_material2refMap.end() != curIt) {
|
2020-10-26 20:35:44 +00:00
|
|
|
if (nullptr != m_currentMesh) {
|
|
|
|
unsigned int matIdx = static_cast<unsigned int>(m_material2refMap[name]);
|
|
|
|
if (m_currentMesh->mMaterialIndex != 0) {
|
|
|
|
ASSIMP_LOG_WARN("Override of material reference in current mesh by material reference.");
|
2017-10-02 07:41:01 +00:00
|
|
|
}
|
|
|
|
m_currentMesh->mMaterialIndex = matIdx;
|
2020-10-26 20:35:44 +00:00
|
|
|
} else {
|
|
|
|
ASSIMP_LOG_WARN("Cannot resolve material reference, because no current mesh is there.");
|
2017-10-02 07:41:01 +00:00
|
|
|
}
|
2017-10-02 07:33:51 +00:00
|
|
|
}
|
|
|
|
}
|
2015-03-25 20:35:32 +00:00
|
|
|
} else {
|
2020-10-26 20:35:44 +00:00
|
|
|
throw DeadlyImportError("Unknown reference info to resolve.");
|
2015-03-17 13:25:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-03-16 19:34:42 +00:00
|
|
|
}
|
|
|
|
|
2015-03-20 15:56:28 +00:00
|
|
|
//------------------------------------------------------------------------------------------------
|
2020-10-26 20:35:44 +00:00
|
|
|
void OpenGEXImporter::createNodeTree(aiScene *pScene) {
|
|
|
|
if (nullptr == m_root) {
|
2015-04-08 18:43:55 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-03-20 15:56:28 +00:00
|
|
|
|
2020-10-26 20:35:44 +00:00
|
|
|
if (m_root->m_children.empty()) {
|
2015-04-08 18:43:55 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-04-29 09:57:39 +00:00
|
|
|
|
2016-11-20 02:02:26 +00:00
|
|
|
pScene->mRootNode->mNumChildren = static_cast<unsigned int>(m_root->m_children.size());
|
2020-10-26 20:35:44 +00:00
|
|
|
pScene->mRootNode->mChildren = new aiNode *[pScene->mRootNode->mNumChildren];
|
|
|
|
std::copy(m_root->m_children.begin(), m_root->m_children.end(), pScene->mRootNode->mChildren);
|
2015-03-20 15:56:28 +00:00
|
|
|
}
|
|
|
|
|
2015-03-18 20:37:57 +00:00
|
|
|
//------------------------------------------------------------------------------------------------
|
2020-10-26 20:35:44 +00:00
|
|
|
void OpenGEXImporter::pushNode(aiNode *node, aiScene *pScene) {
|
|
|
|
ai_assert(nullptr != pScene);
|
2015-03-18 20:37:57 +00:00
|
|
|
|
2020-10-26 20:35:44 +00:00
|
|
|
if (nullptr == node) {
|
2016-05-08 20:31:16 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-10-15 19:45:09 +00:00
|
|
|
|
2020-10-26 20:35:44 +00:00
|
|
|
ChildInfo *info(nullptr);
|
|
|
|
if (m_nodeStack.empty()) {
|
2016-05-08 20:31:16 +00:00
|
|
|
node->mParent = pScene->mRootNode;
|
2020-10-26 20:35:44 +00:00
|
|
|
NodeChildMap::iterator it(m_nodeChildMap.find(node->mParent));
|
|
|
|
if (m_nodeChildMap.end() == it) {
|
2016-05-08 20:31:16 +00:00
|
|
|
info = new ChildInfo;
|
|
|
|
m_root = info;
|
2020-10-26 20:35:44 +00:00
|
|
|
m_nodeChildMap[node->mParent] = std::unique_ptr<ChildInfo>(info);
|
2015-03-18 20:37:57 +00:00
|
|
|
} else {
|
2017-10-05 09:35:17 +00:00
|
|
|
info = it->second.get();
|
2016-05-08 20:31:16 +00:00
|
|
|
}
|
2020-10-26 20:35:44 +00:00
|
|
|
info->m_children.push_back(node);
|
2016-05-08 20:31:16 +00:00
|
|
|
} else {
|
2020-10-26 20:35:44 +00:00
|
|
|
aiNode *parent(m_nodeStack.back());
|
|
|
|
ai_assert(nullptr != parent);
|
2016-05-08 20:31:16 +00:00
|
|
|
node->mParent = parent;
|
2020-10-26 20:35:44 +00:00
|
|
|
NodeChildMap::iterator it(m_nodeChildMap.find(node->mParent));
|
|
|
|
if (m_nodeChildMap.end() == it) {
|
2016-05-08 20:31:16 +00:00
|
|
|
info = new ChildInfo;
|
2020-10-26 20:35:44 +00:00
|
|
|
m_nodeChildMap[node->mParent] = std::unique_ptr<ChildInfo>(info);
|
2016-05-08 20:31:16 +00:00
|
|
|
} else {
|
2017-10-05 09:35:17 +00:00
|
|
|
info = it->second.get();
|
2015-03-18 20:37:57 +00:00
|
|
|
}
|
2020-10-26 20:35:44 +00:00
|
|
|
info->m_children.push_back(node);
|
2015-03-18 20:37:57 +00:00
|
|
|
}
|
2020-10-26 20:35:44 +00:00
|
|
|
m_nodeStack.push_back(node);
|
2015-03-18 20:37:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------------------
|
|
|
|
aiNode *OpenGEXImporter::popNode() {
|
2020-10-26 20:35:44 +00:00
|
|
|
if (m_nodeStack.empty()) {
|
2016-05-15 16:57:10 +00:00
|
|
|
return nullptr;
|
2015-03-18 20:37:57 +00:00
|
|
|
}
|
2015-05-19 03:52:10 +00:00
|
|
|
|
2020-10-26 20:35:44 +00:00
|
|
|
aiNode *node(top());
|
2015-03-18 20:37:57 +00:00
|
|
|
m_nodeStack.pop_back();
|
2015-05-19 03:52:10 +00:00
|
|
|
|
2015-03-18 20:37:57 +00:00
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------------------
|
|
|
|
aiNode *OpenGEXImporter::top() const {
|
2020-10-26 20:35:44 +00:00
|
|
|
if (m_nodeStack.empty()) {
|
2016-05-15 16:57:10 +00:00
|
|
|
return nullptr;
|
2015-03-18 20:37:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return m_nodeStack.back();
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------------------------
|
|
|
|
void OpenGEXImporter::clearNodeStack() {
|
|
|
|
m_nodeStack.clear();
|
|
|
|
}
|
|
|
|
|
2014-08-27 21:00:19 +00:00
|
|
|
//------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
} // Namespace OpenGEX
|
|
|
|
} // Namespace Assimp
|
|
|
|
|
2015-03-19 10:37:11 +00:00
|
|
|
#endif // ASSIMP_BUILD_NO_OPENGEX_IMPORTER
|