Merge remote-tracking branch 'official/master' into contrib
Conflicts: code/ColladaParser.cpp include/assimp/config.h
This commit is contained in:
@@ -144,7 +144,7 @@ namespace {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Worker function for exporting a scene to 3DS. Prototyped and registered in Exporter.cpp
|
||||
void ExportScene3DS(const char* pFile, IOSystem* pIOSystem, const aiScene* pScene)
|
||||
void ExportScene3DS(const char* pFile, IOSystem* pIOSystem, const aiScene* pScene, const ExportProperties* pProperties)
|
||||
{
|
||||
boost::shared_ptr<IOStream> outfile (pIOSystem->Open(pFile, "wb"));
|
||||
if(!outfile) {
|
||||
@@ -188,8 +188,8 @@ Discreet3DSExporter:: Discreet3DSExporter(boost::shared_ptr<IOStream> outfile, c
|
||||
|
||||
{
|
||||
ChunkWriter chunk(writer, Discreet3DS::CHUNK_OBJMESH);
|
||||
WriteMeshes();
|
||||
WriteMaterials();
|
||||
WriteMeshes();
|
||||
|
||||
{
|
||||
ChunkWriter chunk(writer, Discreet3DS::CHUNK_MASTER_SCALE);
|
||||
|
||||
@@ -754,7 +754,7 @@ inline size_t WriteArray(IOStream * stream, const T* in, unsigned int size)
|
||||
}
|
||||
};
|
||||
|
||||
void ExportSceneAssbin(const char* pFile, IOSystem* pIOSystem, const aiScene* pScene)
|
||||
void ExportSceneAssbin(const char* pFile, IOSystem* pIOSystem, const aiScene* pScene, const ExportProperties* pProperties)
|
||||
{
|
||||
AssbinExport exporter;
|
||||
exporter.WriteBinaryDump( pFile, pIOSystem, pScene );
|
||||
|
||||
@@ -621,7 +621,7 @@ void WriteDump(const aiScene* scene, IOStream* io, bool shortened)
|
||||
|
||||
} // end of namespace AssxmlExport
|
||||
|
||||
void ExportSceneAssxml(const char* pFile, IOSystem* pIOSystem, const aiScene* pScene)
|
||||
void ExportSceneAssxml(const char* pFile, IOSystem* pIOSystem, const aiScene* pScene, const ExportProperties* pProperties)
|
||||
{
|
||||
IOStream * out = pIOSystem->Open( pFile, "wt" );
|
||||
if (!out) return;
|
||||
|
||||
@@ -118,6 +118,16 @@ namespace Blender {
|
||||
#ifdef _MSC_VER
|
||||
# pragma warning(disable:4351)
|
||||
#endif
|
||||
|
||||
struct ObjectCompare {
|
||||
bool operator() (const Object* left, const Object* right) const {
|
||||
return strcmp(left->id.name, right->id.name) == -1;
|
||||
}
|
||||
};
|
||||
|
||||
// When keeping objects in sets, sort them by their name.
|
||||
typedef std::set<const Object*, ObjectCompare> ObjectSet;
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
/** ConversionData acts as intermediate storage location for
|
||||
* the various ConvertXXX routines in BlenderImporter.*/
|
||||
@@ -130,7 +140,13 @@ namespace Blender {
|
||||
, db(db)
|
||||
{}
|
||||
|
||||
std::set<const Object*> objects;
|
||||
struct ObjectCompare {
|
||||
bool operator() (const Object* left, const Object* right) const {
|
||||
return strcmp(left->id.name, right->id.name) == -1;
|
||||
}
|
||||
};
|
||||
|
||||
ObjectSet objects;
|
||||
|
||||
TempArray <std::vector, aiMesh> meshes;
|
||||
TempArray <std::vector, aiCamera> cameras;
|
||||
|
||||
@@ -559,24 +559,26 @@ void BlenderImporter::BuildMaterials(ConversionData& conv_data)
|
||||
if (mesh->mMaterialIndex == static_cast<unsigned int>( -1 )) {
|
||||
|
||||
if (index == static_cast<unsigned int>( -1 )) {
|
||||
|
||||
// ok, we need to add a dedicated default material for some poor material-less meshes
|
||||
// Setup a default material.
|
||||
boost::shared_ptr<Material> p(new Material());
|
||||
ai_assert(::strlen(AI_DEFAULT_MATERIAL_NAME) < sizeof(p->id.name)-2);
|
||||
strcpy( p->id.name+2, AI_DEFAULT_MATERIAL_NAME );
|
||||
|
||||
// Note: MSVC11 does not zero-initialize Material here, although it should.
|
||||
// Thus all relevant fields should be explicitly initialized. We cannot add
|
||||
// a default constructor to Material since the DNA codegen does not support
|
||||
// parsing it.
|
||||
p->r = p->g = p->b = 0.6f;
|
||||
p->specr = p->specg = p->specb = 0.6f;
|
||||
p->ambr = p->ambg = p->ambb = 0.0f;
|
||||
p->mirr = p->mirg = p->mirb = 0.0f;
|
||||
p->emit = 0.f;
|
||||
p->alpha = 0.f;
|
||||
|
||||
// XXX add more / or add default c'tor to Material
|
||||
p->har = 0;
|
||||
|
||||
index = static_cast<unsigned int>( conv_data.materials_raw.size() );
|
||||
conv_data.materials_raw.push_back(p);
|
||||
|
||||
LogInfo("Adding default material ...");
|
||||
LogInfo("Adding default material");
|
||||
}
|
||||
mesh->mMaterialIndex = index;
|
||||
}
|
||||
@@ -591,6 +593,7 @@ void BlenderImporter::BuildMaterials(ConversionData& conv_data)
|
||||
|
||||
aiMaterial* mout = new aiMaterial();
|
||||
conv_data.materials->push_back(mout);
|
||||
// For any new material field handled here, the default material above must be updated with an appropriate default value.
|
||||
|
||||
// set material name
|
||||
aiString name = aiString(mat->id.name+2); // skip over the name prefix 'MA'
|
||||
@@ -1044,7 +1047,7 @@ aiLight* BlenderImporter::ConvertLight(const Scene& /*in*/, const Object* obj, c
|
||||
aiNode* BlenderImporter::ConvertNode(const Scene& in, const Object* obj, ConversionData& conv_data, const aiMatrix4x4& parentTransform)
|
||||
{
|
||||
std::deque<const Object*> children;
|
||||
for(std::set<const Object*>::iterator it = conv_data.objects.begin(); it != conv_data.objects.end() ;) {
|
||||
for(ObjectSet::iterator it = conv_data.objects.begin(); it != conv_data.objects.end() ;) {
|
||||
const Object* object = *it;
|
||||
if (object->parent == obj) {
|
||||
children.push_back(object);
|
||||
|
||||
@@ -120,9 +120,11 @@ public:
|
||||
{
|
||||
case aiOrigin_CUR:
|
||||
cursor += pOffset;
|
||||
break;
|
||||
|
||||
case aiOrigin_END:
|
||||
cursor = file_size - pOffset;
|
||||
break;
|
||||
|
||||
case aiOrigin_SET:
|
||||
cursor = pOffset;
|
||||
|
||||
@@ -42,6 +42,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
* @brief Implementation of the Cinema4D importer class.
|
||||
*/
|
||||
#include "AssimpPCH.h"
|
||||
#ifndef ASSIMP_BUILD_NO_C4D_IMPORTER
|
||||
|
||||
// no #ifdefing here, Cinema4D support is carried out in a branch of assimp
|
||||
// where it is turned on in the CMake settings.
|
||||
@@ -639,3 +640,5 @@ unsigned int C4DImporter::ResolveMaterial(PolygonObject* obj)
|
||||
ai_assert((*it).second < mat_count);
|
||||
return (*it).second;
|
||||
}
|
||||
|
||||
#endif // ASSIMP_BUILD_NO_C4D_IMPORTER
|
||||
|
||||
@@ -265,8 +265,6 @@ SET( LWS_SRCS
|
||||
)
|
||||
SOURCE_GROUP( LWS FILES ${LWS_SRCS})
|
||||
|
||||
|
||||
|
||||
SET( MD2_SRCS
|
||||
MD2FileData.h
|
||||
MD2Loader.cpp
|
||||
@@ -360,6 +358,13 @@ SET( Ogre_SRCS
|
||||
)
|
||||
SOURCE_GROUP( Ogre FILES ${Ogre_SRCS})
|
||||
|
||||
SET( OpenGEX_SRCS
|
||||
OpenGEXImporter.cpp
|
||||
OpenGEXImporter.h
|
||||
OpenGEXStructs.h
|
||||
)
|
||||
SOURCE_GROUP( OpenGEX FILES ${OpenGEX_SRCS})
|
||||
|
||||
SET( Ply_SRCS
|
||||
PlyLoader.cpp
|
||||
PlyLoader.h
|
||||
@@ -635,6 +640,17 @@ SET( unzip_SRCS
|
||||
)
|
||||
SOURCE_GROUP( unzip FILES ${unzip_SRCS})
|
||||
|
||||
SET ( openddl_parser_SRCS
|
||||
../contrib/openddlparser/code/OpenDDLParser.cpp
|
||||
../contrib/openddlparser/code/DDLNode.cpp
|
||||
../contrib/openddlparser/code/Value.cpp
|
||||
../contrib/openddlparser/include/openddlparser/OpenDDLParser.h
|
||||
../contrib/openddlparser/include/openddlparser/OpenDDLParserUtils.h
|
||||
../contrib/openddlparser/include/openddlparser/OpenDDLCommon.h
|
||||
../contrib/openddlparser/include/openddlparser/DDLNode.h
|
||||
../contrib/openddlparser/include/openddlparser/Value.h
|
||||
)
|
||||
SOURCE_GROUP( openddl_parser FILES ${openddl_parser_SRCS})
|
||||
|
||||
# VC2010 fixes
|
||||
if(MSVC10)
|
||||
@@ -690,6 +706,7 @@ SET( assimp_src
|
||||
${OFFFormat_SRCS}
|
||||
${Obj_SRCS}
|
||||
${Ogre_SRCS}
|
||||
${OpenGEX_SRCS}
|
||||
${Ply_SRCS}
|
||||
${Q3D_SRCS}
|
||||
${Q3BSP_SRCS}
|
||||
@@ -714,6 +731,7 @@ SET( assimp_src
|
||||
${unzip_compile_SRCS}
|
||||
${Poly2Tri_SRCS}
|
||||
${Clipper_SRCS}
|
||||
${openddl_parser_SRCS}
|
||||
# Necessary to show the headers in the project when using the VC++ generator:
|
||||
${Boost_SRCS}
|
||||
|
||||
@@ -725,6 +743,11 @@ SET( assimp_src
|
||||
# Moreover it's a drag to recompile assimp entirely each time a modification is made to one of the included header, which is definitely counter-productive.)
|
||||
AssimpPCH.cpp
|
||||
)
|
||||
add_definitions( -DOPENDDLPARSER_BUILD )
|
||||
|
||||
INCLUDE_DIRECTORIES(
|
||||
../contrib/openddlparser/include
|
||||
)
|
||||
|
||||
IF (ASSIMP_BUILD_NONFREE_C4D_IMPORTER)
|
||||
SET( assimp_src ${assimp_src} ${C4D_SRCS})
|
||||
@@ -735,7 +758,7 @@ ENDIF (ASSIMP_BUILD_NONFREE_C4D_IMPORTER)
|
||||
|
||||
ADD_LIBRARY( assimp ${assimp_src} )
|
||||
|
||||
TARGET_LINK_LIBRARIES(assimp ${ZLIB_LIBRARIES})
|
||||
TARGET_LINK_LIBRARIES(assimp ${ZLIB_LIBRARIES} ${OPENDDL_PARSER_LIBRARIES} )
|
||||
|
||||
if(ANDROID AND ASSIMP_ANDROID_JNIIOSYSTEM)
|
||||
set(ASSIMP_ANDROID_JNIIOSYSTEM_PATH port/AndroidJNI)
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace Assimp
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Worker function for exporting a scene to Collada. Prototyped and registered in Exporter.cpp
|
||||
void ExportSceneCollada(const char* pFile, IOSystem* pIOSystem, const aiScene* pScene)
|
||||
void ExportSceneCollada(const char* pFile, IOSystem* pIOSystem, const aiScene* pScene, const ExportProperties* pProperties)
|
||||
{
|
||||
std::string path = "";
|
||||
std::string file = pFile;
|
||||
|
||||
@@ -1989,10 +1989,12 @@ void ColladaParser::ReadIndexData( Mesh* pMesh)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// small sanity check
|
||||
if (primType != Prim_TriFans && primType != Prim_TriStrips)
|
||||
ai_assert(actualPrimitives == numPrimitives)
|
||||
|
||||
#ifdef ASSIMP_BUILD_DEBUG
|
||||
if (primType != Prim_TriFans && primType != Prim_TriStrips) {
|
||||
ai_assert(actualPrimitives == numPrimitives);
|
||||
}
|
||||
#endif
|
||||
|
||||
// only when we're done reading all <p> tags (and thus know the final vertex count) can we commit the submesh
|
||||
subgroup.mNumFaces = actualPrimitives;
|
||||
|
||||
@@ -72,16 +72,16 @@ void GetPostProcessingStepInstanceList(std::vector< BaseProcess* >& out);
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Exporter worker function prototypes. Should not be necessary to #ifndef them, it's just a prototype
|
||||
// do not use const, because some exporter need to convert the scene temporary
|
||||
void ExportSceneCollada(const char*,IOSystem*, const aiScene*);
|
||||
void ExportSceneXFile(const char*,IOSystem*, const aiScene*);
|
||||
void ExportSceneObj(const char*,IOSystem*, const aiScene*);
|
||||
void ExportSceneSTL(const char*,IOSystem*, const aiScene*);
|
||||
void ExportSceneSTLBinary(const char*,IOSystem*, const aiScene*);
|
||||
void ExportScenePly(const char*,IOSystem*, const aiScene*);
|
||||
void ExportScenePlyBinary(const char*, IOSystem*, const aiScene*);
|
||||
void ExportScene3DS(const char*, IOSystem*, const aiScene*);
|
||||
void ExportSceneAssbin(const char*, IOSystem*, const aiScene*);
|
||||
void ExportSceneAssxml(const char*, IOSystem*, const aiScene*);
|
||||
void ExportSceneCollada(const char*,IOSystem*, const aiScene*, const ExportProperties*);
|
||||
void ExportSceneXFile(const char*,IOSystem*, const aiScene*, const ExportProperties*);
|
||||
void ExportSceneObj(const char*,IOSystem*, const aiScene*, const ExportProperties*);
|
||||
void ExportSceneSTL(const char*,IOSystem*, const aiScene*, const ExportProperties*);
|
||||
void ExportSceneSTLBinary(const char*,IOSystem*, const aiScene*, const ExportProperties*);
|
||||
void ExportScenePly(const char*,IOSystem*, const aiScene*, const ExportProperties*);
|
||||
void ExportScenePlyBinary(const char*, IOSystem*, const aiScene*, const ExportProperties*);
|
||||
void ExportScene3DS(const char*, IOSystem*, const aiScene*, const ExportProperties*);
|
||||
void ExportSceneAssbin(const char*, IOSystem*, const aiScene*, const ExportProperties*);
|
||||
void ExportSceneAssxml(const char*, IOSystem*, const aiScene*, const ExportProperties*);
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// global array of all export formats which Assimp supports in its current build
|
||||
@@ -91,7 +91,7 @@ Exporter::ExportFormatEntry gExporters[] =
|
||||
Exporter::ExportFormatEntry( "collada", "COLLADA - Digital Asset Exchange Schema", "dae", &ExportSceneCollada),
|
||||
#endif
|
||||
|
||||
#ifndef ASSIMP_BUILD_NO_FXILE_EXPORTER
|
||||
#ifndef ASSIMP_BUILD_NO_XFILE_EXPORTER
|
||||
Exporter::ExportFormatEntry( "x", "X Files", "x", &ExportSceneXFile,
|
||||
aiProcess_MakeLeftHanded | aiProcess_FlipWindingOrder | aiProcess_FlipUVs),
|
||||
#endif
|
||||
@@ -226,7 +226,7 @@ bool Exporter :: IsDefaultIOHandler() const
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
const aiExportDataBlob* Exporter :: ExportToBlob( const aiScene* pScene, const char* pFormatId, unsigned int )
|
||||
const aiExportDataBlob* Exporter :: ExportToBlob( const aiScene* pScene, const char* pFormatId, unsigned int, const ExportProperties* pProperties)
|
||||
{
|
||||
if (pimpl->blob) {
|
||||
delete pimpl->blob;
|
||||
@@ -282,7 +282,7 @@ bool IsVerboseFormat(const aiScene* pScene)
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
aiReturn Exporter :: Export( const aiScene* pScene, const char* pFormatId, const char* pPath, unsigned int pPreprocessing )
|
||||
aiReturn Exporter :: Export( const aiScene* pScene, const char* pFormatId, const char* pPath, unsigned int pPreprocessing, const ExportProperties* pProperties)
|
||||
{
|
||||
ASSIMP_BEGIN_EXCEPTION_REGION();
|
||||
|
||||
@@ -290,7 +290,7 @@ aiReturn Exporter :: Export( const aiScene* pScene, const char* pFormatId, const
|
||||
// format. They will likely not be aware that there is a flag in the scene to indicate
|
||||
// this, however. To avoid surprises and bug reports, we check for duplicates in
|
||||
// meshes upfront.
|
||||
const bool is_verbose_format = !(pScene->mFlags & AI_SCENE_FLAGS_NON_VERBOSE_FORMAT) || IsVerboseFormat(pScene);
|
||||
const bool is_verbose_format = !(pScene->mFlags & AI_SCENE_FLAGS_NON_VERBOSE_FORMAT) || IsVerboseFormat(pScene);
|
||||
|
||||
pimpl->mError = "";
|
||||
for (size_t i = 0; i < pimpl->mExporters.size(); ++i) {
|
||||
@@ -397,7 +397,8 @@ aiReturn Exporter :: Export( const aiScene* pScene, const char* pFormatId, const
|
||||
proc.Execute(scenecopy.get());
|
||||
}
|
||||
|
||||
exp.mExportFunction(pPath,pimpl->mIOSystem.get(),scenecopy.get());
|
||||
ExportProperties emptyProperties; // Never pass NULL ExportProperties so Exporters don't have to worry.
|
||||
exp.mExportFunction(pPath,pimpl->mIOSystem.get(),scenecopy.get(), pProperties ? pProperties : &emptyProperties);
|
||||
}
|
||||
catch (DeadlyExportError& err) {
|
||||
pimpl->mError = err.what();
|
||||
@@ -492,4 +493,116 @@ void Exporter :: UnregisterExporter(const char* id)
|
||||
}
|
||||
}
|
||||
|
||||
ExportProperties :: ExportProperties() {}
|
||||
|
||||
ExportProperties::ExportProperties(const ExportProperties &other)
|
||||
: mIntProperties(other.mIntProperties),
|
||||
mFloatProperties(other.mFloatProperties),
|
||||
mStringProperties(other.mStringProperties),
|
||||
mMatrixProperties(other.mMatrixProperties)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Set a configuration property
|
||||
void ExportProperties :: SetPropertyInteger(const char* szName, int iValue,
|
||||
bool* bWasExisting /*= NULL*/)
|
||||
{
|
||||
SetGenericProperty<int>(mIntProperties, szName,iValue,bWasExisting);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Set a configuration property
|
||||
void ExportProperties :: SetPropertyFloat(const char* szName, float iValue,
|
||||
bool* bWasExisting /*= NULL*/)
|
||||
{
|
||||
SetGenericProperty<float>(mFloatProperties, szName,iValue,bWasExisting);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Set a configuration property
|
||||
void ExportProperties :: SetPropertyString(const char* szName, const std::string& value,
|
||||
bool* bWasExisting /*= NULL*/)
|
||||
{
|
||||
SetGenericProperty<std::string>(mStringProperties, szName,value,bWasExisting);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Set a configuration property
|
||||
void ExportProperties :: SetPropertyMatrix(const char* szName, const aiMatrix4x4& value,
|
||||
bool* bWasExisting /*= NULL*/)
|
||||
{
|
||||
SetGenericProperty<aiMatrix4x4>(mMatrixProperties, szName,value,bWasExisting);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Get a configuration property
|
||||
int ExportProperties :: GetPropertyInteger(const char* szName,
|
||||
int iErrorReturn /*= 0xffffffff*/) const
|
||||
{
|
||||
return GetGenericProperty<int>(mIntProperties,szName,iErrorReturn);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Get a configuration property
|
||||
float ExportProperties :: GetPropertyFloat(const char* szName,
|
||||
float iErrorReturn /*= 10e10*/) const
|
||||
{
|
||||
return GetGenericProperty<float>(mFloatProperties,szName,iErrorReturn);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Get a configuration property
|
||||
const std::string ExportProperties :: GetPropertyString(const char* szName,
|
||||
const std::string& iErrorReturn /*= ""*/) const
|
||||
{
|
||||
return GetGenericProperty<std::string>(mStringProperties,szName,iErrorReturn);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Has a configuration property
|
||||
const aiMatrix4x4 ExportProperties :: GetPropertyMatrix(const char* szName,
|
||||
const aiMatrix4x4& iErrorReturn /*= aiMatrix4x4()*/) const
|
||||
{
|
||||
return GetGenericProperty<aiMatrix4x4>(mMatrixProperties,szName,iErrorReturn);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Has a configuration property
|
||||
bool ExportProperties :: HasPropertyInteger(const char* szName) const
|
||||
{
|
||||
return HasGenericProperty<int>(mIntProperties, szName);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Has a configuration property
|
||||
bool ExportProperties :: HasPropertyBool(const char* szName) const
|
||||
{
|
||||
return HasGenericProperty<int>(mIntProperties, szName);
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Has a configuration property
|
||||
bool ExportProperties :: HasPropertyFloat(const char* szName) const
|
||||
{
|
||||
return HasGenericProperty<float>(mFloatProperties, szName);
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Has a configuration property
|
||||
bool ExportProperties :: HasPropertyString(const char* szName) const
|
||||
{
|
||||
return HasGenericProperty<std::string>(mStringProperties, szName);
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Has a configuration property
|
||||
bool ExportProperties :: HasPropertyMatrix(const char* szName) const
|
||||
{
|
||||
return HasGenericProperty<aiMatrix4x4>(mMatrixProperties, szName);
|
||||
};
|
||||
|
||||
|
||||
#endif // !ASSIMP_BUILD_NO_EXPORT
|
||||
|
||||
@@ -108,5 +108,18 @@ inline void SetGenericPropertyPtr(std::map< unsigned int, T* >& list,
|
||||
*bWasExisting = true;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
template <class T>
|
||||
inline const bool HasGenericProperty(const std::map< unsigned int, T >& list,
|
||||
const char* szName)
|
||||
{
|
||||
ai_assert(NULL != szName);
|
||||
const uint32_t hash = SuperFastHash(szName);
|
||||
|
||||
typename std::map<unsigned int, T>::const_iterator it = list.find(hash);
|
||||
if (it == list.end()) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif // !! AI_GENERIC_PROPERTY_H_INCLUDED
|
||||
|
||||
@@ -648,10 +648,10 @@ void Curve :: SampleDiscrete(TempMesh& out,IfcFloat a, IfcFloat b) const
|
||||
ai_assert(InRange(a) && InRange(b));
|
||||
|
||||
const size_t cnt = std::max(static_cast<size_t>(0),EstimateSampleCount(a,b));
|
||||
out.verts.reserve( out.verts.size() + cnt );
|
||||
out.verts.reserve( out.verts.size() + cnt + 1);
|
||||
|
||||
IfcFloat p = a, delta = (b-a)/cnt;
|
||||
for(size_t i = 0; i < cnt; ++i, p += delta) {
|
||||
for(size_t i = 0; i <= cnt; ++i, p += delta) {
|
||||
out.verts.push_back(Eval(p));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -677,10 +677,11 @@ aiNode* ProcessSpatialStructure(aiNode* parent, const IfcProduct& el, Conversion
|
||||
const STEP::DB::RefMap& refs = conv.db.GetRefs();
|
||||
|
||||
// skip over space and annotation nodes - usually, these have no meaning in Assimp's context
|
||||
bool skipGeometry = false;
|
||||
if(conv.settings.skipSpaceRepresentations) {
|
||||
if(const IfcSpace* const space = el.ToPtr<IfcSpace>()) {
|
||||
IFCImporter::LogDebug("skipping IfcSpace entity due to importer settings");
|
||||
return NULL;
|
||||
skipGeometry = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -850,8 +851,10 @@ aiNode* ProcessSpatialStructure(aiNode* parent, const IfcProduct& el, Conversion
|
||||
conv.apply_openings = &openings;
|
||||
}
|
||||
|
||||
ProcessProductRepresentation(el,nd.get(),subnodes,conv);
|
||||
conv.apply_openings = conv.collect_openings = NULL;
|
||||
if (!skipGeometry) {
|
||||
ProcessProductRepresentation(el,nd.get(),subnodes,conv);
|
||||
conv.apply_openings = conv.collect_openings = NULL;
|
||||
}
|
||||
|
||||
if (subnodes.size()) {
|
||||
nd->mChildren = new aiNode*[subnodes.size()]();
|
||||
|
||||
@@ -236,7 +236,7 @@ IfcVector3 TempMesh::ComputeLastPolygonNormal(bool normalize) const
|
||||
|
||||
struct CompareVector
|
||||
{
|
||||
bool operator () (const IfcVector3& a, const IfcVector3& b)
|
||||
bool operator () (const IfcVector3& a, const IfcVector3& b) const
|
||||
{
|
||||
IfcVector3 d = a - b;
|
||||
IfcFloat eps = 1e-6;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
Open Asset Import Library (assimp)
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2012, assimp team
|
||||
Copyright (c) 2006-2015, assimp team
|
||||
|
||||
All rights reserved.
|
||||
|
||||
@@ -142,6 +142,9 @@ corresponding preprocessor flag to selectively disable formats.
|
||||
#ifndef ASSIMP_BUILD_NO_OGRE_IMPORTER
|
||||
# include "OgreImporter.h"
|
||||
#endif
|
||||
#ifndef ASSIMP_BUILD_NO_OPENGEX_IMPORTER
|
||||
# include "OpenGEXImporter.h"
|
||||
#endif
|
||||
#ifndef ASSIMP_BUILD_NO_MS3D_IMPORTER
|
||||
# include "MS3DLoader.h"
|
||||
#endif
|
||||
@@ -179,132 +182,135 @@ namespace Assimp {
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
void GetImporterInstanceList(std::vector< BaseImporter* >& out)
|
||||
{
|
||||
// ----------------------------------------------------------------------------
|
||||
// Add an instance of each worker class here
|
||||
// (register_new_importers_here)
|
||||
// ----------------------------------------------------------------------------
|
||||
out.reserve(64);
|
||||
// ----------------------------------------------------------------------------
|
||||
// Add an instance of each worker class here
|
||||
// (register_new_importers_here)
|
||||
// ----------------------------------------------------------------------------
|
||||
out.reserve(64);
|
||||
#if (!defined ASSIMP_BUILD_NO_X_IMPORTER)
|
||||
out.push_back( new XFileImporter());
|
||||
out.push_back( new XFileImporter());
|
||||
#endif
|
||||
#if (!defined ASSIMP_BUILD_NO_OBJ_IMPORTER)
|
||||
out.push_back( new ObjFileImporter());
|
||||
out.push_back( new ObjFileImporter());
|
||||
#endif
|
||||
#if (!defined ASSIMP_BUILD_NO_3DS_IMPORTER)
|
||||
out.push_back( new Discreet3DSImporter());
|
||||
out.push_back( new Discreet3DSImporter());
|
||||
#endif
|
||||
#if (!defined ASSIMP_BUILD_NO_MD3_IMPORTER)
|
||||
out.push_back( new MD3Importer());
|
||||
out.push_back( new MD3Importer());
|
||||
#endif
|
||||
#if (!defined ASSIMP_BUILD_NO_MD2_IMPORTER)
|
||||
out.push_back( new MD2Importer());
|
||||
out.push_back( new MD2Importer());
|
||||
#endif
|
||||
#if (!defined ASSIMP_BUILD_NO_PLY_IMPORTER)
|
||||
out.push_back( new PLYImporter());
|
||||
out.push_back( new PLYImporter());
|
||||
#endif
|
||||
#if (!defined ASSIMP_BUILD_NO_MDL_IMPORTER)
|
||||
out.push_back( new MDLImporter());
|
||||
out.push_back( new MDLImporter());
|
||||
#endif
|
||||
#if (!defined ASSIMP_BUILD_NO_ASE_IMPORTER)
|
||||
out.push_back( new ASEImporter());
|
||||
out.push_back( new ASEImporter());
|
||||
#endif
|
||||
#if (!defined ASSIMP_BUILD_NO_HMP_IMPORTER)
|
||||
out.push_back( new HMPImporter());
|
||||
out.push_back( new HMPImporter());
|
||||
#endif
|
||||
#if (!defined ASSIMP_BUILD_NO_SMD_IMPORTER)
|
||||
out.push_back( new SMDImporter());
|
||||
out.push_back( new SMDImporter());
|
||||
#endif
|
||||
#if (!defined ASSIMP_BUILD_NO_MDC_IMPORTER)
|
||||
out.push_back( new MDCImporter());
|
||||
out.push_back( new MDCImporter());
|
||||
#endif
|
||||
#if (!defined ASSIMP_BUILD_NO_MD5_IMPORTER)
|
||||
out.push_back( new MD5Importer());
|
||||
out.push_back( new MD5Importer());
|
||||
#endif
|
||||
#if (!defined ASSIMP_BUILD_NO_STL_IMPORTER)
|
||||
out.push_back( new STLImporter());
|
||||
out.push_back( new STLImporter());
|
||||
#endif
|
||||
#if (!defined ASSIMP_BUILD_NO_LWO_IMPORTER)
|
||||
out.push_back( new LWOImporter());
|
||||
out.push_back( new LWOImporter());
|
||||
#endif
|
||||
#if (!defined ASSIMP_BUILD_NO_DXF_IMPORTER)
|
||||
out.push_back( new DXFImporter());
|
||||
out.push_back( new DXFImporter());
|
||||
#endif
|
||||
#if (!defined ASSIMP_BUILD_NO_NFF_IMPORTER)
|
||||
out.push_back( new NFFImporter());
|
||||
out.push_back( new NFFImporter());
|
||||
#endif
|
||||
#if (!defined ASSIMP_BUILD_NO_RAW_IMPORTER)
|
||||
out.push_back( new RAWImporter());
|
||||
out.push_back( new RAWImporter());
|
||||
#endif
|
||||
#if (!defined ASSIMP_BUILD_NO_OFF_IMPORTER)
|
||||
out.push_back( new OFFImporter());
|
||||
out.push_back( new OFFImporter());
|
||||
#endif
|
||||
#if (!defined ASSIMP_BUILD_NO_AC_IMPORTER)
|
||||
out.push_back( new AC3DImporter());
|
||||
out.push_back( new AC3DImporter());
|
||||
#endif
|
||||
#if (!defined ASSIMP_BUILD_NO_BVH_IMPORTER)
|
||||
out.push_back( new BVHLoader());
|
||||
out.push_back( new BVHLoader());
|
||||
#endif
|
||||
#if (!defined ASSIMP_BUILD_NO_IRRMESH_IMPORTER)
|
||||
out.push_back( new IRRMeshImporter());
|
||||
out.push_back( new IRRMeshImporter());
|
||||
#endif
|
||||
#if (!defined ASSIMP_BUILD_NO_IRR_IMPORTER)
|
||||
out.push_back( new IRRImporter());
|
||||
out.push_back( new IRRImporter());
|
||||
#endif
|
||||
#if (!defined ASSIMP_BUILD_NO_Q3D_IMPORTER)
|
||||
out.push_back( new Q3DImporter());
|
||||
out.push_back( new Q3DImporter());
|
||||
#endif
|
||||
#if (!defined ASSIMP_BUILD_NO_B3D_IMPORTER)
|
||||
out.push_back( new B3DImporter());
|
||||
out.push_back( new B3DImporter());
|
||||
#endif
|
||||
#if (!defined ASSIMP_BUILD_NO_COLLADA_IMPORTER)
|
||||
out.push_back( new ColladaLoader());
|
||||
out.push_back( new ColladaLoader());
|
||||
#endif
|
||||
#if (!defined ASSIMP_BUILD_NO_TERRAGEN_IMPORTER)
|
||||
out.push_back( new TerragenImporter());
|
||||
out.push_back( new TerragenImporter());
|
||||
#endif
|
||||
#if (!defined ASSIMP_BUILD_NO_CSM_IMPORTER)
|
||||
out.push_back( new CSMImporter());
|
||||
out.push_back( new CSMImporter());
|
||||
#endif
|
||||
#if (!defined ASSIMP_BUILD_NO_3D_IMPORTER)
|
||||
out.push_back( new UnrealImporter());
|
||||
out.push_back( new UnrealImporter());
|
||||
#endif
|
||||
#if (!defined ASSIMP_BUILD_NO_LWS_IMPORTER)
|
||||
out.push_back( new LWSImporter());
|
||||
out.push_back( new LWSImporter());
|
||||
#endif
|
||||
#if (!defined ASSIMP_BUILD_NO_OGRE_IMPORTER)
|
||||
out.push_back( new Ogre::OgreImporter());
|
||||
out.push_back( new Ogre::OgreImporter());
|
||||
#endif
|
||||
#if (!defined ASSIMP_BUILD_NO_OPENGEX_IMPORTER )
|
||||
out.push_back( new OpenGEX::OpenGEXImporter() );
|
||||
#endif
|
||||
#if (!defined ASSIMP_BUILD_NO_MS3D_IMPORTER)
|
||||
out.push_back( new MS3DImporter());
|
||||
out.push_back( new MS3DImporter());
|
||||
#endif
|
||||
#if (!defined ASSIMP_BUILD_NO_COB_IMPORTER)
|
||||
out.push_back( new COBImporter());
|
||||
out.push_back( new COBImporter());
|
||||
#endif
|
||||
#if (!defined ASSIMP_BUILD_NO_BLEND_IMPORTER)
|
||||
out.push_back( new BlenderImporter());
|
||||
out.push_back( new BlenderImporter());
|
||||
#endif
|
||||
#if (!defined ASSIMP_BUILD_NO_Q3BSP_IMPORTER)
|
||||
out.push_back( new Q3BSPFileImporter() );
|
||||
out.push_back( new Q3BSPFileImporter() );
|
||||
#endif
|
||||
#if (!defined ASSIMP_BUILD_NO_NDO_IMPORTER)
|
||||
out.push_back( new NDOImporter() );
|
||||
out.push_back( new NDOImporter() );
|
||||
#endif
|
||||
#if (!defined ASSIMP_BUILD_NO_IFC_IMPORTER)
|
||||
out.push_back( new IFCImporter() );
|
||||
out.push_back( new IFCImporter() );
|
||||
#endif
|
||||
#if ( !defined ASSIMP_BUILD_NO_XGL_IMPORTER )
|
||||
out.push_back( new XGLImporter() );
|
||||
out.push_back( new XGLImporter() );
|
||||
#endif
|
||||
#if ( !defined ASSIMP_BUILD_NO_FBX_IMPORTER )
|
||||
out.push_back( new FBXImporter() );
|
||||
out.push_back( new FBXImporter() );
|
||||
#endif
|
||||
#if ( !defined ASSIMP_BUILD_NO_ASSBIN_IMPORTER )
|
||||
out.push_back( new AssbinImporter() );
|
||||
out.push_back( new AssbinImporter() );
|
||||
#endif
|
||||
|
||||
#ifndef ASSIMP_BUILD_NO_C4D_IMPORTER
|
||||
out.push_back( new C4DImporter() );
|
||||
out.push_back( new C4DImporter() );
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace Assimp
|
||||
|
||||
@@ -51,7 +51,7 @@ namespace Assimp {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Worker function for exporting a scene to Wavefront OBJ. Prototyped and registered in Exporter.cpp
|
||||
void ExportSceneObj(const char* pFile,IOSystem* pIOSystem, const aiScene* pScene)
|
||||
void ExportSceneObj(const char* pFile,IOSystem* pIOSystem, const aiScene* pScene, const ExportProperties* pProperties)
|
||||
{
|
||||
// invoke the exporter
|
||||
ObjExporter exporter(pFile, pScene);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -64,57 +64,57 @@ struct Model;
|
||||
class ObjFileImporter : public BaseImporter
|
||||
{
|
||||
public:
|
||||
/// \brief Default constructor
|
||||
ObjFileImporter();
|
||||
/// \brief Default constructor
|
||||
ObjFileImporter();
|
||||
|
||||
/// \brief Destructor
|
||||
~ObjFileImporter();
|
||||
/// \brief Destructor
|
||||
~ObjFileImporter();
|
||||
|
||||
public:
|
||||
/// \brief Returns whether the class can handle the format of the given file.
|
||||
/// \remark See BaseImporter::CanRead() for details.
|
||||
bool CanRead( const std::string& pFile, IOSystem* pIOHandler, bool checkSig) const;
|
||||
/// \brief Returns whether the class can handle the format of the given file.
|
||||
/// \remark See BaseImporter::CanRead() for details.
|
||||
bool CanRead( const std::string& pFile, IOSystem* pIOHandler, bool checkSig) const;
|
||||
|
||||
private:
|
||||
|
||||
//! \brief Appends the supported extension.
|
||||
const aiImporterDesc* GetInfo () const;
|
||||
//! \brief Appends the supported extension.
|
||||
const aiImporterDesc* GetInfo () const;
|
||||
|
||||
//! \brief File import implementation.
|
||||
void InternReadFile(const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler);
|
||||
|
||||
//! \brief Create the data from imported content.
|
||||
void CreateDataFromImport(const ObjFile::Model* pModel, aiScene* pScene);
|
||||
|
||||
//! \brief Creates all nodes stored in imported content.
|
||||
aiNode *createNodes(const ObjFile::Model* pModel, const ObjFile::Object* pData,
|
||||
aiNode *pParent, aiScene* pScene, std::vector<aiMesh*> &MeshArray);
|
||||
//! \brief File import implementation.
|
||||
void InternReadFile(const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler);
|
||||
|
||||
//! \brief Create the data from imported content.
|
||||
void CreateDataFromImport(const ObjFile::Model* pModel, aiScene* pScene);
|
||||
|
||||
//! \brief Creates all nodes stored in imported content.
|
||||
aiNode *createNodes(const ObjFile::Model* pModel, const ObjFile::Object* pData,
|
||||
aiNode *pParent, aiScene* pScene, std::vector<aiMesh*> &MeshArray);
|
||||
|
||||
//! \brief Creates topology data like faces and meshes for the geometry.
|
||||
//! \brief Creates topology data like faces and meshes for the geometry.
|
||||
aiMesh *createTopology( const ObjFile::Model* pModel, const ObjFile::Object* pData,
|
||||
unsigned int uiMeshIndex );
|
||||
|
||||
//! \brief Creates vertices from model.
|
||||
void createVertexArray(const ObjFile::Model* pModel, const ObjFile::Object* pCurrentObject,
|
||||
unsigned int uiMeshIndex, aiMesh* pMesh,unsigned int uiIdxCount);
|
||||
unsigned int uiMeshIndex );
|
||||
|
||||
//! \brief Creates vertices from model.
|
||||
void createVertexArray(const ObjFile::Model* pModel, const ObjFile::Object* pCurrentObject,
|
||||
unsigned int uiMeshIndex, aiMesh* pMesh,unsigned int uiIdxCount);
|
||||
|
||||
//! \brief Object counter helper method.
|
||||
void countObjects(const std::vector<ObjFile::Object*> &rObjects, int &iNumMeshes);
|
||||
//! \brief Object counter helper method.
|
||||
void countObjects(const std::vector<ObjFile::Object*> &rObjects, int &iNumMeshes);
|
||||
|
||||
//! \brief Material creation.
|
||||
void createMaterials(const ObjFile::Model* pModel, aiScene* pScene);
|
||||
void addTextureMappingModeProperty(aiMaterial* mat, aiTextureType type, int clampMode = 1);
|
||||
//! \brief Material creation.
|
||||
void createMaterials(const ObjFile::Model* pModel, aiScene* pScene);
|
||||
void addTextureMappingModeProperty(aiMaterial* mat, aiTextureType type, int clampMode = 1);
|
||||
|
||||
//! \brief Appends a child node to a parent node and updates the data structures.
|
||||
void appendChildToParentNode(aiNode *pParent, aiNode *pChild);
|
||||
//! \brief Appends a child node to a parent node and updates the data structures.
|
||||
void appendChildToParentNode(aiNode *pParent, aiNode *pChild);
|
||||
|
||||
private:
|
||||
//! Data buffer
|
||||
std::vector<char> m_Buffer;
|
||||
//! Pointer to root object instance
|
||||
ObjFile::Object *m_pRootObject;
|
||||
//! Absolute pathname of model in file system
|
||||
std::string m_strAbsPath;
|
||||
//! Data buffer
|
||||
std::vector<char> m_Buffer;
|
||||
//! Pointer to root object instance
|
||||
ObjFile::Object *m_pRootObject;
|
||||
//! Absolute pathname of model in file system
|
||||
std::string m_strAbsPath;
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -63,76 +63,76 @@ class IOSystem;
|
||||
class ObjFileParser
|
||||
{
|
||||
public:
|
||||
static const size_t BUFFERSIZE = 4096;
|
||||
typedef std::vector<char> DataArray;
|
||||
typedef std::vector<char>::iterator DataArrayIt;
|
||||
typedef std::vector<char>::const_iterator ConstDataArrayIt;
|
||||
static const size_t BUFFERSIZE = 4096;
|
||||
typedef std::vector<char> DataArray;
|
||||
typedef std::vector<char>::iterator DataArrayIt;
|
||||
typedef std::vector<char>::const_iterator ConstDataArrayIt;
|
||||
|
||||
public:
|
||||
/// \brief Constructor with data array.
|
||||
ObjFileParser(std::vector<char> &Data,const std::string &strModelName, IOSystem* io);
|
||||
/// \brief Destructor
|
||||
~ObjFileParser();
|
||||
/// \brief Model getter.
|
||||
ObjFile::Model *GetModel() const;
|
||||
/// \brief Constructor with data array.
|
||||
ObjFileParser(std::vector<char> &Data,const std::string &strModelName, IOSystem* io);
|
||||
/// \brief Destructor
|
||||
~ObjFileParser();
|
||||
/// \brief Model getter.
|
||||
ObjFile::Model *GetModel() const;
|
||||
|
||||
private:
|
||||
/// Parse the loaded file
|
||||
void parseFile();
|
||||
/// Method to copy the new delimited word in the current line.
|
||||
void copyNextWord(char *pBuffer, size_t length);
|
||||
/// Method to copy the new line.
|
||||
void copyNextLine(char *pBuffer, size_t length);
|
||||
/// Parse the loaded file
|
||||
void parseFile();
|
||||
/// Method to copy the new delimited word in the current line.
|
||||
void copyNextWord(char *pBuffer, size_t length);
|
||||
/// Method to copy the new line.
|
||||
void copyNextLine(char *pBuffer, size_t length);
|
||||
/// Stores the vector
|
||||
void getVector( std::vector<aiVector3D> &point3d_array );
|
||||
/// Stores the following 3d vector.
|
||||
void getVector3( std::vector<aiVector3D> &point3d_array );
|
||||
/// Stores the following 3d vector.
|
||||
void getVector2(std::vector<aiVector2D> &point2d_array);
|
||||
void getVector3( std::vector<aiVector3D> &point3d_array );
|
||||
/// Stores the following 3d vector.
|
||||
void getVector2(std::vector<aiVector2D> &point2d_array);
|
||||
/// Stores the following face.
|
||||
void getFace(aiPrimitiveType type);
|
||||
/// Reads the material description.
|
||||
void getFace(aiPrimitiveType type);
|
||||
/// Reads the material description.
|
||||
void getMaterialDesc();
|
||||
/// Gets a comment.
|
||||
void getComment();
|
||||
/// Gets a a material library.
|
||||
void getMaterialLib();
|
||||
/// Creates a new material.
|
||||
void getNewMaterial();
|
||||
/// Gets the group name from file.
|
||||
void getGroupName();
|
||||
/// Gets the group number from file.
|
||||
void getGroupNumber();
|
||||
/// Gets the group number and resolution from file.
|
||||
void getGroupNumberAndResolution();
|
||||
/// Returns the index of the material. Is -1 if not material was found.
|
||||
int getMaterialIndex( const std::string &strMaterialName );
|
||||
/// Parse object name
|
||||
void getObjectName();
|
||||
/// Creates a new object.
|
||||
void createObject(const std::string &strObjectName);
|
||||
/// Creates a new mesh.
|
||||
void createMesh();
|
||||
/// Returns true, if a new mesh instance must be created.
|
||||
bool needsNewMesh( const std::string &rMaterialName );
|
||||
/// Error report in token
|
||||
void reportErrorTokenInFace();
|
||||
/// Gets a comment.
|
||||
void getComment();
|
||||
/// Gets a a material library.
|
||||
void getMaterialLib();
|
||||
/// Creates a new material.
|
||||
void getNewMaterial();
|
||||
/// Gets the group name from file.
|
||||
void getGroupName();
|
||||
/// Gets the group number from file.
|
||||
void getGroupNumber();
|
||||
/// Gets the group number and resolution from file.
|
||||
void getGroupNumberAndResolution();
|
||||
/// Returns the index of the material. Is -1 if not material was found.
|
||||
int getMaterialIndex( const std::string &strMaterialName );
|
||||
/// Parse object name
|
||||
void getObjectName();
|
||||
/// Creates a new object.
|
||||
void createObject(const std::string &strObjectName);
|
||||
/// Creates a new mesh.
|
||||
void createMesh();
|
||||
/// Returns true, if a new mesh instance must be created.
|
||||
bool needsNewMesh( const std::string &rMaterialName );
|
||||
/// Error report in token
|
||||
void reportErrorTokenInFace();
|
||||
|
||||
private:
|
||||
/// Default material name
|
||||
static const std::string DEFAULT_MATERIAL;
|
||||
//! Iterator to current position in buffer
|
||||
DataArrayIt m_DataIt;
|
||||
//! Iterator to end position of buffer
|
||||
DataArrayIt m_DataItEnd;
|
||||
//! Pointer to model instance
|
||||
ObjFile::Model *m_pModel;
|
||||
//! Current line (for debugging)
|
||||
unsigned int m_uiLine;
|
||||
//! Helper buffer
|
||||
char m_buffer[BUFFERSIZE];
|
||||
/// Pointer to IO system instance.
|
||||
IOSystem *m_pIO;
|
||||
/// Default material name
|
||||
static const std::string DEFAULT_MATERIAL;
|
||||
//! Iterator to current position in buffer
|
||||
DataArrayIt m_DataIt;
|
||||
//! Iterator to end position of buffer
|
||||
DataArrayIt m_DataItEnd;
|
||||
//! Pointer to model instance
|
||||
ObjFile::Model *m_pModel;
|
||||
//! Current line (for debugging)
|
||||
unsigned int m_uiLine;
|
||||
//! Helper buffer
|
||||
char m_buffer[BUFFERSIZE];
|
||||
/// Pointer to IO system instance.
|
||||
IOSystem *m_pIO;
|
||||
};
|
||||
|
||||
} // Namespace Assimp
|
||||
|
||||
@@ -36,63 +36,63 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
----------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
*/
|
||||
|
||||
#ifndef AI_OGREIMPORTER_H_INC
|
||||
#define AI_OGREIMPORTER_H_INC
|
||||
|
||||
#ifndef ASSIMP_BUILD_NO_OGRE_IMPORTER
|
||||
|
||||
#include "BaseImporter.h"
|
||||
|
||||
#include "OgreStructs.h"
|
||||
#include "OgreParsingUtils.h"
|
||||
|
||||
namespace Assimp
|
||||
{
|
||||
namespace Ogre
|
||||
{
|
||||
|
||||
|
||||
#include "BaseImporter.h"
|
||||
|
||||
#include "OgreStructs.h"
|
||||
#include "OgreParsingUtils.h"
|
||||
|
||||
namespace Assimp
|
||||
{
|
||||
namespace Ogre
|
||||
{
|
||||
|
||||
/** Importer for Ogre mesh, skeleton and material formats.
|
||||
@todo Support vertex colors.
|
||||
@todo Support poses/animations from the mesh file.
|
||||
Currently only skeleton file animations are supported. */
|
||||
class OgreImporter : public BaseImporter
|
||||
{
|
||||
public:
|
||||
/// BaseImporter override.
|
||||
virtual bool CanRead(const std::string &pFile, IOSystem *pIOHandler, bool checkSig) const;
|
||||
|
||||
/// BaseImporter override.
|
||||
@todo Support vertex colors.
|
||||
@todo Support poses/animations from the mesh file.
|
||||
Currently only skeleton file animations are supported. */
|
||||
class OgreImporter : public BaseImporter
|
||||
{
|
||||
public:
|
||||
/// BaseImporter override.
|
||||
virtual bool CanRead(const std::string &pFile, IOSystem *pIOHandler, bool checkSig) const;
|
||||
|
||||
/// BaseImporter override.
|
||||
virtual void InternReadFile(const std::string &pFile, aiScene *pScene, IOSystem *pIOHandler);
|
||||
|
||||
/// BaseImporter override.
|
||||
virtual const aiImporterDesc *GetInfo() const;
|
||||
|
||||
/// BaseImporter override.
|
||||
virtual void SetupProperties(const Importer *pImp);
|
||||
|
||||
private:
|
||||
/// Read materials referenced by the @c mesh to @c pScene.
|
||||
void ReadMaterials(const std::string &pFile, Assimp::IOSystem *pIOHandler, aiScene *pScene, Mesh *mesh);
|
||||
void ReadMaterials(const std::string &pFile, Assimp::IOSystem *pIOHandler, aiScene *pScene, MeshXml *mesh);
|
||||
void AssignMaterials(aiScene *pScene, std::vector<aiMaterial*> &materials);
|
||||
|
||||
/// Reads material
|
||||
aiMaterial* ReadMaterial(const std::string &pFile, Assimp::IOSystem *pIOHandler, const std::string MaterialName);
|
||||
|
||||
// These functions parse blocks from a material file from @c ss. Starting parsing from "{" and ending it to "}".
|
||||
bool ReadTechnique(const std::string &techniqueName, std::stringstream &ss, aiMaterial *material);
|
||||
bool ReadPass(const std::string &passName, std::stringstream &ss, aiMaterial *material);
|
||||
bool ReadTextureUnit(const std::string &textureUnitName, std::stringstream &ss, aiMaterial *material);
|
||||
|
||||
std::string m_userDefinedMaterialLibFile;
|
||||
bool m_detectTextureTypeFromFilename;
|
||||
|
||||
std::map<aiTextureType, unsigned int> m_textures;
|
||||
};
|
||||
} // Ogre
|
||||
} // Assimp
|
||||
|
||||
virtual const aiImporterDesc *GetInfo() const;
|
||||
|
||||
/// BaseImporter override.
|
||||
virtual void SetupProperties(const Importer *pImp);
|
||||
|
||||
private:
|
||||
/// Read materials referenced by the @c mesh to @c pScene.
|
||||
void ReadMaterials(const std::string &pFile, Assimp::IOSystem *pIOHandler, aiScene *pScene, Mesh *mesh);
|
||||
void ReadMaterials(const std::string &pFile, Assimp::IOSystem *pIOHandler, aiScene *pScene, MeshXml *mesh);
|
||||
void AssignMaterials(aiScene *pScene, std::vector<aiMaterial*> &materials);
|
||||
|
||||
/// Reads material
|
||||
aiMaterial* ReadMaterial(const std::string &pFile, Assimp::IOSystem *pIOHandler, const std::string MaterialName);
|
||||
|
||||
// These functions parse blocks from a material file from @c ss. Starting parsing from "{" and ending it to "}".
|
||||
bool ReadTechnique(const std::string &techniqueName, std::stringstream &ss, aiMaterial *material);
|
||||
bool ReadPass(const std::string &passName, std::stringstream &ss, aiMaterial *material);
|
||||
bool ReadTextureUnit(const std::string &textureUnitName, std::stringstream &ss, aiMaterial *material);
|
||||
|
||||
std::string m_userDefinedMaterialLibFile;
|
||||
bool m_detectTextureTypeFromFilename;
|
||||
|
||||
std::map<aiTextureType, unsigned int> m_textures;
|
||||
};
|
||||
} // Ogre
|
||||
} // Assimp
|
||||
|
||||
#endif // ASSIMP_BUILD_NO_OGRE_IMPORTER
|
||||
#endif // AI_OGREIMPORTER_H_INC
|
||||
|
||||
691
code/OpenGEXImporter.cpp
Normal file
691
code/OpenGEXImporter.cpp
Normal file
@@ -0,0 +1,691 @@
|
||||
/*
|
||||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2014, assimp team
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use of this software in source and binary forms,
|
||||
with or without modification, are permitted provided that the
|
||||
following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above
|
||||
copyright notice, this list of conditions and the
|
||||
following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the
|
||||
following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
* 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.
|
||||
|
||||
----------------------------------------------------------------------
|
||||
*/
|
||||
#ifndef ASSIMP_BUILD_NO_OPENGEX_IMPORTER
|
||||
|
||||
#include "AssimpPCH.h"
|
||||
#include "OpenGEXImporter.h"
|
||||
#include "DefaultIOSystem.h"
|
||||
|
||||
#include <openddlparser/OpenDDLParser.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
static const aiImporterDesc desc = {
|
||||
"Open Game Engine Exchange",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
aiImporterFlags_SupportTextFlavour,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
"ogex"
|
||||
};
|
||||
|
||||
namespace Grammar {
|
||||
static const char *MetricType = "Metric";
|
||||
static const char *Metric_DistanceType = "distance";
|
||||
static const char *Metric_AngleType = "angle";
|
||||
static const char *Metric_TimeType = "time";
|
||||
static const char *Metric_UpType = "up";
|
||||
static const char *NameType = "Name";
|
||||
static const char *ObjectRefType = "ObjectRef";
|
||||
static const char *MaterialRefType = "MaterialRef";
|
||||
static const char *MetricKeyType = "key";
|
||||
static const char *GeometryNodeType = "GeometryNode";
|
||||
static const char *GeometryObjectType = "GeometryObject";
|
||||
static const char *TransformType = "Transform";
|
||||
static const char *MeshType = "Mesh";
|
||||
static const char *VertexArrayType = "VertexArray";
|
||||
static const char *IndexArrayType = "IndexArray";
|
||||
static const char *MaterialType = "Material";
|
||||
static const char *ColorType = "Color";
|
||||
static const char *TextureType = "Texture";
|
||||
|
||||
enum TokenType {
|
||||
NoneType = -1,
|
||||
MetricToken,
|
||||
NameToken,
|
||||
ObjectRefToken,
|
||||
MaterialRefToken,
|
||||
MetricKeyToken,
|
||||
GeometryNodeToken,
|
||||
GeometryObjectToken,
|
||||
TransformToken,
|
||||
MeshToken,
|
||||
VertexArrayToken,
|
||||
IndexArrayToken,
|
||||
MaterialToken,
|
||||
ColorToken,
|
||||
TextureToken
|
||||
};
|
||||
|
||||
static const char *ValidMetricToken[ 4 ] = {
|
||||
Metric_DistanceType,
|
||||
Metric_AngleType,
|
||||
Metric_TimeType,
|
||||
Metric_UpType
|
||||
};
|
||||
|
||||
static int isValidMetricType( const char *token ) {
|
||||
if( NULL == token ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int idx( -1 );
|
||||
for( size_t i = 0; i < 4; i++ ) {
|
||||
if( 0 == strncmp( ValidMetricToken[ i ], token, strlen( token ) ) ) {
|
||||
idx = (int) i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return idx;
|
||||
}
|
||||
|
||||
static TokenType matchTokenType( const char *tokenType ) {
|
||||
if( 0 == strncmp( MetricType, tokenType, strlen( MetricType ) ) ) {
|
||||
return MetricToken;
|
||||
} else if( 0 == strncmp( NameType, tokenType, strlen( NameType ) ) ) {
|
||||
return NameToken;
|
||||
}
|
||||
else if( 0 == strncmp( ObjectRefType, tokenType, strlen( ObjectRefType ) ) ) {
|
||||
return ObjectRefToken;
|
||||
}
|
||||
else if( 0 == strncmp( MaterialRefType, tokenType, strlen( MaterialRefType ) ) ) {
|
||||
return MaterialRefToken;
|
||||
}
|
||||
else if( 0 == strncmp( MetricKeyType, tokenType, strlen( MetricKeyType ) ) ) {
|
||||
return MetricKeyToken;
|
||||
}
|
||||
else if( 0 == strncmp( GeometryNodeType, tokenType, strlen( GeometryNodeType ) ) ) {
|
||||
return GeometryNodeToken;
|
||||
}
|
||||
else if( 0 == strncmp( GeometryObjectType, tokenType, strlen( GeometryObjectType ) ) ) {
|
||||
return GeometryObjectToken;
|
||||
}
|
||||
else if( 0 == strncmp( TransformType, tokenType, strlen( TransformType ) ) ) {
|
||||
return TransformToken;
|
||||
}
|
||||
else if( 0 == strncmp( MeshType, tokenType, strlen( MeshType ) ) ) {
|
||||
return MeshToken;
|
||||
}
|
||||
else if( 0 == strncmp( VertexArrayType, tokenType, strlen( VertexArrayType ) ) ) {
|
||||
return VertexArrayToken;
|
||||
}
|
||||
else if( 0 == strncmp( IndexArrayType, tokenType, strlen( IndexArrayType ) ) ) {
|
||||
return IndexArrayToken;
|
||||
}
|
||||
else if( 0 == strncmp( MaterialType, tokenType, strlen( MaterialType ) ) ) {
|
||||
return MaterialToken;
|
||||
}
|
||||
else if( 0 == strncmp( ColorType, tokenType, strlen( ColorType ) ) ) {
|
||||
return ColorToken;
|
||||
}
|
||||
else if( 0 == strncmp( TextureType, tokenType, strlen( TextureType ) ) ) {
|
||||
return TextureToken;
|
||||
}
|
||||
|
||||
return NoneType;
|
||||
}
|
||||
|
||||
} // Namespace Grammar
|
||||
|
||||
namespace Assimp {
|
||||
namespace OpenGEX {
|
||||
|
||||
USE_ODDLPARSER_NS
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
OpenGEXImporter::RefInfo::RefInfo( aiNode *node, Type type, std::vector<std::string> &names )
|
||||
: m_node( node )
|
||||
, m_type( type )
|
||||
, m_Names( names ) {
|
||||
// empty
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
OpenGEXImporter::RefInfo::~RefInfo() {
|
||||
// empty
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
OpenGEXImporter::OpenGEXImporter()
|
||||
: m_meshCache()
|
||||
, m_mesh2refMap()
|
||||
, m_ctx( NULL )
|
||||
, m_currentNode( NULL )
|
||||
, m_currentMesh( NULL )
|
||||
, m_nodeStack()
|
||||
, m_unresolvedRefStack() {
|
||||
// empty
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
OpenGEXImporter::~OpenGEXImporter() {
|
||||
m_ctx = NULL;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
bool OpenGEXImporter::CanRead( const std::string &file, IOSystem *pIOHandler, bool checkSig ) const {
|
||||
bool canRead( false );
|
||||
if( !checkSig ) {
|
||||
canRead = SimpleExtensionCheck( file, "ogex" );
|
||||
} else {
|
||||
static const char *token[] = { "Metric", "GeometryNode", "VertexArray (attrib", "IndexArray" };
|
||||
canRead = BaseImporter::SearchFileHeaderForToken( pIOHandler, file, token, 4 );
|
||||
}
|
||||
|
||||
return canRead;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
void OpenGEXImporter::InternReadFile( const std::string &filename, aiScene *pScene, IOSystem *pIOHandler ) {
|
||||
// open source file
|
||||
IOStream *file = pIOHandler->Open( filename, "rb" );
|
||||
if( !file ) {
|
||||
throw DeadlyImportError( "Failed to open file " + filename );
|
||||
}
|
||||
|
||||
std::vector<char> buffer;
|
||||
TextFileToBuffer( file, buffer );
|
||||
|
||||
OpenDDLParser myParser;
|
||||
myParser.setBuffer( &buffer[ 0 ], buffer.size() );
|
||||
bool success( myParser.parse() );
|
||||
if( success ) {
|
||||
m_ctx = myParser.getContext();
|
||||
pScene->mRootNode = new aiNode;
|
||||
pScene->mRootNode->mName.Set( filename );
|
||||
handleNodes( m_ctx->m_root, pScene );
|
||||
}
|
||||
|
||||
resolveReferences();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
const aiImporterDesc *OpenGEXImporter::GetInfo() const {
|
||||
return &desc;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
void OpenGEXImporter::SetupProperties( const Importer *pImp ) {
|
||||
if( NULL == pImp ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
void OpenGEXImporter::handleNodes( DDLNode *node, aiScene *pScene ) {
|
||||
if( NULL == node ) {
|
||||
return;
|
||||
}
|
||||
|
||||
DDLNode::DllNodeList childs = node->getChildNodeList();
|
||||
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::GeometryObjectToken:
|
||||
handleGeometryObject( *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::TextureToken:
|
||||
handleTextureNode( *it, pScene );
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
void OpenGEXImporter::handleMetricNode( DDLNode *node, aiScene *pScene ) {
|
||||
if( NULL == node || NULL == m_ctx ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if( m_ctx->m_root != node->getParent() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
Property *prop( node->getProperties() );
|
||||
while( NULL != prop ) {
|
||||
if( NULL != prop->m_id ) {
|
||||
if( Value::ddl_string == prop->m_primData->m_type ) {
|
||||
std::string valName( (char*) prop->m_primData->m_data );
|
||||
int type( Grammar::isValidMetricType( valName.c_str() ) );
|
||||
if( Grammar::NoneType != type ) {
|
||||
Value *val( node->getValue() );
|
||||
if( NULL != val ) {
|
||||
if( Value::ddl_float == val->m_type ) {
|
||||
m_metrics[ type ].m_floatValue = val->getFloat();
|
||||
} else if( Value::ddl_int32 == val->m_type ) {
|
||||
m_metrics[ type ].m_intValue = val->getInt32();
|
||||
} else if( Value::ddl_string == val->m_type ) {
|
||||
m_metrics[type].m_stringValue = std::string( val->getString() );
|
||||
} else {
|
||||
throw DeadlyImportError( "OpenGEX: invalid data type for Metric node." );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
prop = prop->m_next;
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
void OpenGEXImporter::handleNameNode( DDLNode *node, aiScene *pScene ) {
|
||||
if( NULL == m_currentNode ) {
|
||||
throw DeadlyImportError( "No parent node for name." );
|
||||
return;
|
||||
}
|
||||
|
||||
Value *val( node->getValue() );
|
||||
if( NULL != val ) {
|
||||
if( Value::ddl_string != val->m_type ) {
|
||||
throw DeadlyImportError( "OpenGEX: invalid data type for value in node name." );
|
||||
return;
|
||||
}
|
||||
|
||||
const std::string name( val->getString() );
|
||||
m_currentNode->mName.Set( name.c_str() );
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
static void getRefNames( DDLNode *node, std::vector<std::string> &names ) {
|
||||
ai_assert( NULL != node );
|
||||
|
||||
Reference *ref = node->getReferences();
|
||||
if( NULL != ref ) {
|
||||
for( size_t i = 0; i < ref->m_numRefs; i++ ) {
|
||||
Name *currentName( ref->m_referencedName[ i ] );
|
||||
if( NULL != currentName && NULL != currentName->m_id ) {
|
||||
const std::string name( currentName->m_id->m_buffer );
|
||||
if( !name.empty() ) {
|
||||
names.push_back( name );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
void OpenGEXImporter::handleObjectRefNode( DDLNode *node, aiScene *pScene ) {
|
||||
if( NULL == m_currentNode ) {
|
||||
throw DeadlyImportError( "No parent node for name." );
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<std::string> objRefNames;
|
||||
getRefNames( node, objRefNames );
|
||||
m_currentNode->mNumMeshes = objRefNames.size();
|
||||
m_currentNode->mMeshes = new unsigned int[ objRefNames.size() ];
|
||||
if( !objRefNames.empty() ) {
|
||||
m_unresolvedRefStack.push_back( new RefInfo( m_currentNode, RefInfo::MeshRef, objRefNames ) );
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
void OpenGEXImporter::handleMaterialRefNode( ODDLParser::DDLNode *node, aiScene *pScene ) {
|
||||
if( NULL == m_currentNode ) {
|
||||
throw DeadlyImportError( "No parent node for name." );
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<std::string> matRefNames;
|
||||
getRefNames( node, matRefNames );
|
||||
if( !matRefNames.empty() ) {
|
||||
m_unresolvedRefStack.push_back( new RefInfo( m_currentNode, RefInfo::MaterialRef, matRefNames ) );
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
void OpenGEXImporter::handleGeometryNode( DDLNode *node, aiScene *pScene ) {
|
||||
aiNode *newNode = new aiNode;
|
||||
pushNode( newNode, pScene );
|
||||
m_currentNode = newNode;
|
||||
handleNodes( node, pScene );
|
||||
|
||||
popNode();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
void OpenGEXImporter::handleGeometryObject( DDLNode *node, aiScene *pScene ) {
|
||||
aiMesh *currentMesh( new aiMesh );
|
||||
const size_t idx( m_meshCache.size() );
|
||||
m_meshCache.push_back( currentMesh );
|
||||
|
||||
// store name to reference relation
|
||||
m_mesh2refMap[ node->getName() ] = idx;
|
||||
|
||||
// todo: child nodes?
|
||||
|
||||
handleNodes( node, pScene );
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
static void setMatrix( aiNode *node, DataArrayList *transformData ) {
|
||||
ai_assert( NULL != node );
|
||||
ai_assert( NULL != transformData );
|
||||
|
||||
float m[ 16 ];
|
||||
size_t i( 1 );
|
||||
Value *next( transformData->m_dataList->m_next );
|
||||
m[ 0 ] = transformData->m_dataList->getFloat();
|
||||
while( next != NULL ) {
|
||||
m[ i ] = next->getFloat();
|
||||
next = next->m_next;
|
||||
i++;
|
||||
}
|
||||
|
||||
node->mTransformation.a1 = m[ 0 ];
|
||||
node->mTransformation.a2 = m[ 1 ];
|
||||
node->mTransformation.a3 = m[ 2 ];
|
||||
node->mTransformation.a4 = m[ 3 ];
|
||||
|
||||
node->mTransformation.b1 = m[ 4 ];
|
||||
node->mTransformation.b2 = m[ 5 ];
|
||||
node->mTransformation.b3 = m[ 6 ];
|
||||
node->mTransformation.b4 = m[ 7 ];
|
||||
|
||||
node->mTransformation.c1 = m[ 8 ];
|
||||
node->mTransformation.c2 = m[ 9 ];
|
||||
node->mTransformation.c3 = m[ 10 ];
|
||||
node->mTransformation.c4 = m[ 11 ];
|
||||
|
||||
node->mTransformation.d1 = m[ 12 ];
|
||||
node->mTransformation.d2 = m[ 13 ];
|
||||
node->mTransformation.d3 = m[ 14 ];
|
||||
node->mTransformation.d4 = m[ 15 ];
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
void OpenGEXImporter::handleTransformNode( ODDLParser::DDLNode *node, aiScene *pScene ) {
|
||||
if( NULL == m_currentNode ) {
|
||||
throw DeadlyImportError( "No parent node for name." );
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
DataArrayList *transformData( node->getDataArrayList() );
|
||||
if( NULL != transformData ) {
|
||||
if( transformData->m_numItems != 16 ) {
|
||||
throw DeadlyImportError( "Invalid number of data for transform matrix." );
|
||||
return;
|
||||
}
|
||||
setMatrix( m_currentNode, transformData );
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
static void propId2StdString( Property *prop, std::string &name, std::string &key ) {
|
||||
name = key = "";
|
||||
if( NULL == prop ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if( NULL != prop->m_id ) {
|
||||
name = prop->m_id->m_buffer;
|
||||
if( Value::ddl_string == prop->m_primData->m_type ) {
|
||||
key = prop->m_primData->getString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
void OpenGEXImporter::handleMeshNode( ODDLParser::DDLNode *node, aiScene *pScene ) {
|
||||
Property *prop = node->getProperties();
|
||||
m_currentMesh = new aiMesh;
|
||||
m_meshCache.push_back( m_currentMesh );
|
||||
|
||||
if( NULL != prop ) {
|
||||
std::string propName, propKey;
|
||||
propId2StdString( prop, propName, propKey );
|
||||
if( "triangles" == propName ) {
|
||||
m_currentMesh->mPrimitiveTypes |= aiPrimitiveType_TRIANGLE;
|
||||
}
|
||||
}
|
||||
|
||||
handleNodes( node, pScene );
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
enum MeshAttribute {
|
||||
None,
|
||||
Position,
|
||||
Normal,
|
||||
TexCoord
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
static MeshAttribute getAttributeByName( const char *attribName ) {
|
||||
ai_assert( NULL != attribName );
|
||||
|
||||
if( 0 == strncmp( "position", attribName, strlen( "position" ) ) ) {
|
||||
return Position;
|
||||
} else if( 0 == strncmp( "normal", attribName, strlen( "normal" ) ) ) {
|
||||
return Normal;
|
||||
} else if( 0 == strncmp( "texcoord", attribName, strlen( "texcoord" ) ) ) {
|
||||
return TexCoord;
|
||||
}
|
||||
|
||||
return None;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
void OpenGEXImporter::handleVertexArrayNode( ODDLParser::DDLNode *node, aiScene *pScene ) {
|
||||
if( NULL == node ) {
|
||||
throw DeadlyImportError( "No parent node for name." );
|
||||
return;
|
||||
}
|
||||
|
||||
Property *prop( node->getProperties() );
|
||||
if( NULL != prop ) {
|
||||
std::string propName, propKey;
|
||||
propId2StdString( prop, propName, propKey );
|
||||
MeshAttribute attribType( getAttributeByName( propName.c_str() ) );
|
||||
if( None == attribType ) {
|
||||
return;
|
||||
}
|
||||
|
||||
DataArrayList *vaList = node->getDataArrayList();
|
||||
if( NULL == vaList ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if( Position == attribType ) {
|
||||
aiVector3D *pos = new aiVector3D[ vaList->m_numItems ];
|
||||
Value *next( vaList->m_dataList );
|
||||
for( size_t i = 0; i < vaList->m_numItems; i++ ) {
|
||||
|
||||
}
|
||||
} else if( Normal == attribType ) {
|
||||
aiVector3D *normal = new aiVector3D[ vaList->m_numItems ];
|
||||
} else if( TexCoord == attribType ) {
|
||||
aiVector3D *tex = new aiVector3D[ vaList->m_numItems ];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
void OpenGEXImporter::handleIndexArrayNode( ODDLParser::DDLNode *node, aiScene *pScene ) {
|
||||
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
void OpenGEXImporter::handleMaterialNode( ODDLParser::DDLNode *node, aiScene *pScene ) {
|
||||
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
void OpenGEXImporter::resolveReferences() {
|
||||
if( m_unresolvedRefStack.empty() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
RefInfo *currentRefInfo( NULL );
|
||||
for( std::vector<RefInfo*>::iterator it = m_unresolvedRefStack.begin(); it != m_unresolvedRefStack.end(); ++it ) {
|
||||
currentRefInfo = *it;
|
||||
if( NULL != 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 ] );
|
||||
unsigned int meshIdx = m_mesh2refMap[ name ];
|
||||
node->mMeshes[ i ] = meshIdx;
|
||||
}
|
||||
} else if( RefInfo::MaterialRef == currentRefInfo->m_type ) {
|
||||
// ToDo
|
||||
} else {
|
||||
throw DeadlyImportError( "Unknown reference info to resolve." );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
void OpenGEXImporter::handleColorNode( ODDLParser::DDLNode *node, aiScene *pScene ) {
|
||||
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
void OpenGEXImporter::handleTextureNode( ODDLParser::DDLNode *node, aiScene *pScene ) {
|
||||
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
void OpenGEXImporter::pushNode( aiNode *node, aiScene *pScene ) {
|
||||
ai_assert( NULL != pScene );
|
||||
|
||||
if( NULL != node ) {
|
||||
if( m_nodeStack.empty() ) {
|
||||
node->mParent = pScene->mRootNode;
|
||||
} else {
|
||||
aiNode *parent( m_nodeStack.back() );
|
||||
ai_assert( NULL != parent );
|
||||
node->mParent = parent;
|
||||
}
|
||||
m_nodeStack.push_back( node );
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
aiNode *OpenGEXImporter::popNode() {
|
||||
if( m_nodeStack.empty() ) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
aiNode *node( top() );
|
||||
m_nodeStack.pop_back();
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
aiNode *OpenGEXImporter::top() const {
|
||||
if( m_nodeStack.empty() ) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return m_nodeStack.back();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
void OpenGEXImporter::clearNodeStack() {
|
||||
m_nodeStack.clear();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------------------------
|
||||
|
||||
} // Namespace OpenGEX
|
||||
} // Namespace Assimp
|
||||
|
||||
#endif // ASSIMP_BUILD_NO_OPENGEX_IMPORTER
|
||||
158
code/OpenGEXImporter.h
Normal file
158
code/OpenGEXImporter.h
Normal file
@@ -0,0 +1,158 @@
|
||||
/*
|
||||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2014, assimp team
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use of this software in source and binary forms,
|
||||
with or without modification, are permitted provided that the
|
||||
following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above
|
||||
copyright notice, this list of conditions and the
|
||||
following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the
|
||||
following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
* 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.
|
||||
|
||||
----------------------------------------------------------------------
|
||||
*/
|
||||
#ifndef AI_OPENGEX_IMPORTER_H
|
||||
#define AI_OPENGEX_IMPORTER_H
|
||||
|
||||
#ifndef ASSIMP_BUILD_NO_OPENGEX_IMPORTER
|
||||
|
||||
#include "BaseImporter.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace ODDLParser {
|
||||
class DDLNode;
|
||||
struct Context;
|
||||
}
|
||||
|
||||
namespace Assimp {
|
||||
namespace OpenGEX {
|
||||
|
||||
struct MetricInfo {
|
||||
enum Type {
|
||||
Distance = 0,
|
||||
Angle,
|
||||
Time,
|
||||
Up,
|
||||
Max
|
||||
};
|
||||
|
||||
std::string m_stringValue;
|
||||
float m_floatValue;
|
||||
int m_intValue;
|
||||
|
||||
MetricInfo()
|
||||
: m_stringValue( "" )
|
||||
, m_floatValue( 0.0f )
|
||||
, m_intValue( -1 ) {
|
||||
// empty
|
||||
}
|
||||
};
|
||||
|
||||
/** @brief This class is used to implement the OpenGEX importer
|
||||
*
|
||||
* See http://opengex.org/OpenGEX.pdf for spec.
|
||||
*/
|
||||
class OpenGEXImporter : public BaseImporter {
|
||||
public:
|
||||
/// The class constructor.
|
||||
OpenGEXImporter();
|
||||
|
||||
/// The class destructor.
|
||||
virtual ~OpenGEXImporter();
|
||||
|
||||
/// BaseImporter override.
|
||||
virtual bool CanRead( const std::string &file, IOSystem *pIOHandler, bool checkSig ) const;
|
||||
|
||||
/// BaseImporter override.
|
||||
virtual void InternReadFile( const std::string &file, aiScene *pScene, IOSystem *pIOHandler );
|
||||
|
||||
/// BaseImporter override.
|
||||
virtual const aiImporterDesc *GetInfo() const;
|
||||
|
||||
/// BaseImporter override.
|
||||
virtual void SetupProperties( const Importer *pImp );
|
||||
|
||||
protected:
|
||||
void handleNodes( ODDLParser::DDLNode *node, aiScene *pScene );
|
||||
void handleMetricNode( ODDLParser::DDLNode *node, aiScene *pScene );
|
||||
void handleNameNode( ODDLParser::DDLNode *node, aiScene *pScene );
|
||||
void handleObjectRefNode( ODDLParser::DDLNode *node, aiScene *pScene );
|
||||
void handleMaterialRefNode( ODDLParser::DDLNode *node, aiScene *pScene );
|
||||
void handleGeometryNode( ODDLParser::DDLNode *node, aiScene *pScene );
|
||||
void handleGeometryObject( ODDLParser::DDLNode *node, aiScene *pScene );
|
||||
void handleTransformNode( ODDLParser::DDLNode *node, aiScene *pScene );
|
||||
void handleMeshNode( ODDLParser::DDLNode *node, aiScene *pScene );
|
||||
void handleVertexArrayNode( ODDLParser::DDLNode *node, aiScene *pScene );
|
||||
void handleIndexArrayNode( ODDLParser::DDLNode *node, aiScene *pScene );
|
||||
void handleMaterialNode( ODDLParser::DDLNode *node, aiScene *pScene );
|
||||
void handleColorNode( ODDLParser::DDLNode *node, aiScene *pScene );
|
||||
void handleTextureNode( ODDLParser::DDLNode *node, aiScene *pScene );
|
||||
void resolveReferences();
|
||||
void pushNode( aiNode *node, aiScene *pScene );
|
||||
aiNode *popNode();
|
||||
aiNode *top() const;
|
||||
void clearNodeStack();
|
||||
|
||||
private:
|
||||
struct RefInfo {
|
||||
enum Type {
|
||||
MeshRef,
|
||||
MaterialRef
|
||||
};
|
||||
|
||||
aiNode *m_node;
|
||||
Type m_type;
|
||||
std::vector<std::string> m_Names;
|
||||
|
||||
RefInfo( aiNode *node, Type type, std::vector<std::string> &names );
|
||||
~RefInfo();
|
||||
|
||||
private:
|
||||
RefInfo( const RefInfo & );
|
||||
RefInfo &operator = ( const RefInfo & );
|
||||
};
|
||||
|
||||
std::vector<aiMesh*> m_meshCache;
|
||||
std::map<std::string, size_t> m_mesh2refMap;
|
||||
|
||||
ODDLParser::Context *m_ctx;
|
||||
MetricInfo m_metrics[ MetricInfo::Max ];
|
||||
aiNode *m_currentNode;
|
||||
aiMesh *m_currentMesh;
|
||||
std::vector<aiNode*> m_nodeStack;
|
||||
std::vector<RefInfo*> m_unresolvedRefStack;
|
||||
};
|
||||
|
||||
} // Namespace OpenGEX
|
||||
} // Namespace Assimp
|
||||
|
||||
#endif // ASSIMP_BUILD_NO_OPENGEX_IMPORTER
|
||||
|
||||
#endif // AI_OPENGEX_IMPORTER_H
|
||||
265
code/OpenGEXStructs.h
Normal file
265
code/OpenGEXStructs.h
Normal file
@@ -0,0 +1,265 @@
|
||||
/*
|
||||
Open Asset Import Library (assimp)
|
||||
----------------------------------------------------------------------
|
||||
|
||||
Copyright (c) 2006-2014, assimp team
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use of this software in source and binary forms,
|
||||
with or without modification, are permitted provided that the
|
||||
following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above
|
||||
copyright notice, this list of conditions and the
|
||||
following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the
|
||||
following disclaimer in the documentation and/or other
|
||||
materials provided with the distribution.
|
||||
|
||||
* 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.
|
||||
|
||||
----------------------------------------------------------------------
|
||||
*/
|
||||
#ifndef AI_OPENGEXSTRUCTS_H_INC
|
||||
#define AI_OPENGEXSTRUCTS_H_INC
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
namespace Assimp {
|
||||
namespace OpenGEX {
|
||||
|
||||
struct Skin;
|
||||
struct Object;
|
||||
struct LightObject;
|
||||
struct CameraObject;
|
||||
struct Material;
|
||||
struct BoneNode;
|
||||
struct BoneCountArray;
|
||||
struct BoneIndexArray;
|
||||
struct BoneWeightArray;
|
||||
|
||||
struct Metric {
|
||||
float m_distance;
|
||||
float m_angle;
|
||||
float m_time;
|
||||
float m_up;
|
||||
};
|
||||
|
||||
struct VertexArray {
|
||||
std::string arrayAttrib;
|
||||
unsigned int morphIndex;
|
||||
};
|
||||
|
||||
struct IndexArray {
|
||||
unsigned int materialIndex;
|
||||
unsigned int restartIndex;
|
||||
std::string frontFace;
|
||||
};
|
||||
|
||||
struct Mesh {
|
||||
unsigned int meshLevel;
|
||||
std::string meshPrimitive;
|
||||
Skin *skinStructure;
|
||||
};
|
||||
|
||||
struct Node {
|
||||
std::string nodeName;
|
||||
};
|
||||
|
||||
struct GeometryNode {
|
||||
bool visibleFlag[ 2 ];
|
||||
bool shadowFlag[ 2 ];
|
||||
bool motionBlurFlag[ 2 ];
|
||||
};
|
||||
|
||||
struct LightNode {
|
||||
bool shadowFlag[ 2 ];
|
||||
const LightObject *lightObjectStructure;
|
||||
};
|
||||
|
||||
struct CameraNode {
|
||||
const CameraObject *cameraObjectStructure;
|
||||
};
|
||||
|
||||
struct GeometryObject {
|
||||
Object *object;
|
||||
bool visibleFlag;
|
||||
bool shadowFlag;
|
||||
bool motionBlurFlag;
|
||||
std::map<std::string, Mesh*> meshMap;
|
||||
};
|
||||
|
||||
struct LightObject {
|
||||
Object *object;
|
||||
std::string typeString;
|
||||
bool shadowFlag;
|
||||
};
|
||||
|
||||
|
||||
struct CameraObject {
|
||||
float focalLength;
|
||||
float nearDepth;
|
||||
float farDepth;
|
||||
};
|
||||
|
||||
struct Matrix {
|
||||
bool objectFlag;
|
||||
};
|
||||
|
||||
struct Transform {
|
||||
Matrix *matrix;
|
||||
int transformCount;
|
||||
const float *transformArray;
|
||||
};
|
||||
|
||||
struct Translation {
|
||||
std::string translationKind;
|
||||
};
|
||||
|
||||
struct Rotation {
|
||||
std::string rotationKind;
|
||||
};
|
||||
|
||||
struct Scale {
|
||||
std::string scaleKind;
|
||||
};
|
||||
|
||||
struct Name {
|
||||
std::string name;
|
||||
};
|
||||
|
||||
|
||||
struct ObjectRef {
|
||||
Object *targetStructure;
|
||||
};
|
||||
|
||||
struct MaterialRef {
|
||||
unsigned int materialIndex;
|
||||
const Material *targetStructure;
|
||||
};
|
||||
|
||||
struct BoneRefArray {
|
||||
int boneCount;
|
||||
const BoneNode **boneNodeArray;
|
||||
};
|
||||
|
||||
struct BoneCount {
|
||||
int vertexCount;
|
||||
const unsigned short *boneCountArray;
|
||||
unsigned short *arrayStorage;
|
||||
};
|
||||
|
||||
struct BoneIndex {
|
||||
int boneIndexCount;
|
||||
const unsigned short *boneIndexArray;
|
||||
unsigned short *arrayStorage;
|
||||
};
|
||||
|
||||
|
||||
struct BoneWeight {
|
||||
int boneWeightCount;
|
||||
const float *boneWeightArray;
|
||||
};
|
||||
|
||||
struct Skeleton {
|
||||
const BoneRefArray *boneRefArrayStructure;
|
||||
const Transform *transformStructure;
|
||||
};
|
||||
|
||||
struct Skin {
|
||||
const Skeleton *skeletonStructure;
|
||||
const BoneCountArray *boneCountArrayStructure;
|
||||
const BoneIndexArray *boneIndexArrayStructure;
|
||||
const BoneWeightArray *boneWeightArrayStructure;
|
||||
};
|
||||
|
||||
struct Material {
|
||||
bool twoSidedFlag;
|
||||
const char *materialName;
|
||||
};
|
||||
|
||||
struct Attrib {
|
||||
std::string attribString;
|
||||
};
|
||||
|
||||
struct Param {
|
||||
float param;
|
||||
};
|
||||
|
||||
struct Color {
|
||||
float color[ 4 ];
|
||||
};
|
||||
|
||||
struct Texture {
|
||||
std::string textureName;
|
||||
unsigned int texcoordIndex;
|
||||
};
|
||||
|
||||
struct Atten {
|
||||
std::string attenKind;
|
||||
std::string curveType;
|
||||
|
||||
float beginParam;
|
||||
float endParam;
|
||||
|
||||
float scaleParam;
|
||||
float offsetParam;
|
||||
|
||||
float constantParam;
|
||||
float linearParam;
|
||||
float quadraticParam;
|
||||
|
||||
float powerParam;
|
||||
};
|
||||
|
||||
struct Key {
|
||||
std::string keyKind;
|
||||
bool scalarFlag;
|
||||
};
|
||||
|
||||
struct Curve {
|
||||
std::string curveType;
|
||||
const Key *keyValueStructure;
|
||||
const Key *keyControlStructure[ 2 ];
|
||||
const Key *keyTensionStructure;
|
||||
const Key *keyContinuityStructure;
|
||||
const Key *keyBiasStructure;
|
||||
};
|
||||
|
||||
struct Animation {
|
||||
int clipIndex;
|
||||
bool beginFlag;
|
||||
bool endFlag;
|
||||
float beginTime;
|
||||
float endTime;
|
||||
};
|
||||
|
||||
struct OpenGexDataDescription {
|
||||
float distanceScale;
|
||||
float angleScale;
|
||||
float timeScale;
|
||||
int upDirection;
|
||||
};
|
||||
|
||||
} // Namespace OpenGEX
|
||||
} // Namespace Assimp
|
||||
|
||||
#endif // AI_OPENGEXSTRUCTS_H_INC
|
||||
@@ -50,7 +50,7 @@ namespace Assimp {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Worker function for exporting a scene to PLY. Prototyped and registered in Exporter.cpp
|
||||
void ExportScenePly(const char* pFile,IOSystem* pIOSystem, const aiScene* pScene)
|
||||
void ExportScenePly(const char* pFile,IOSystem* pIOSystem, const aiScene* pScene, const ExportProperties* pProperties)
|
||||
{
|
||||
// invoke the exporter
|
||||
PlyExporter exporter(pFile, pScene);
|
||||
@@ -64,7 +64,7 @@ void ExportScenePly(const char* pFile,IOSystem* pIOSystem, const aiScene* pScene
|
||||
outfile->Write( exporter.mOutput.str().c_str(), static_cast<size_t>(exporter.mOutput.tellp()),1);
|
||||
}
|
||||
|
||||
void ExportScenePlyBinary(const char* pFile, IOSystem* pIOSystem, const aiScene* pScene)
|
||||
void ExportScenePlyBinary(const char* pFile, IOSystem* pIOSystem, const aiScene* pScene, const ExportProperties* pProperties)
|
||||
{
|
||||
// invoke the exporter
|
||||
PlyExporter exporter(pFile, pScene, true);
|
||||
|
||||
@@ -64,6 +64,25 @@ static const aiImporterDesc desc = {
|
||||
"ply"
|
||||
};
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Internal stuff
|
||||
namespace
|
||||
{
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Checks that property index is within range
|
||||
template <class T>
|
||||
const T &GetProperty(const std::vector<T> &props, int idx)
|
||||
{
|
||||
if( static_cast< size_t >( idx ) >= props.size() ) {
|
||||
throw DeadlyImportError( "Invalid .ply file: Property index is out of range." );
|
||||
}
|
||||
|
||||
return props[idx];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Constructor to be privately used by Importer
|
||||
PLYImporter::PLYImporter()
|
||||
@@ -431,13 +450,13 @@ void PLYImporter::LoadTextureCoordinates(std::vector<aiVector2D>* pvOut)
|
||||
if (0xFFFFFFFF != aiPositions[0])
|
||||
{
|
||||
vOut.x = PLY::PropertyInstance::ConvertTo<float>(
|
||||
(*i).alProperties[aiPositions[0]].avList.front(),aiTypes[0]);
|
||||
GetProperty((*i).alProperties, aiPositions[0]).avList.front(),aiTypes[0]);
|
||||
}
|
||||
|
||||
if (0xFFFFFFFF != aiPositions[1])
|
||||
{
|
||||
vOut.y = PLY::PropertyInstance::ConvertTo<float>(
|
||||
(*i).alProperties[aiPositions[1]].avList.front(),aiTypes[1]);
|
||||
GetProperty((*i).alProperties, aiPositions[1]).avList.front(),aiTypes[1]);
|
||||
}
|
||||
// and add them to our nice list
|
||||
pvOut->push_back(vOut);
|
||||
@@ -541,19 +560,19 @@ void PLYImporter::LoadVertices(std::vector<aiVector3D>* pvOut, bool p_bNormals)
|
||||
if (0xFFFFFFFF != aiPositions[0])
|
||||
{
|
||||
vOut.x = PLY::PropertyInstance::ConvertTo<float>(
|
||||
(*i).alProperties[aiPositions[0]].avList.front(),aiTypes[0]);
|
||||
GetProperty((*i).alProperties, aiPositions[0]).avList.front(),aiTypes[0]);
|
||||
}
|
||||
|
||||
if (0xFFFFFFFF != aiPositions[1])
|
||||
{
|
||||
vOut.y = PLY::PropertyInstance::ConvertTo<float>(
|
||||
(*i).alProperties[aiPositions[1]].avList.front(),aiTypes[1]);
|
||||
GetProperty((*i).alProperties, aiPositions[1]).avList.front(),aiTypes[1]);
|
||||
}
|
||||
|
||||
if (0xFFFFFFFF != aiPositions[2])
|
||||
{
|
||||
vOut.z = PLY::PropertyInstance::ConvertTo<float>(
|
||||
(*i).alProperties[aiPositions[2]].avList.front(),aiTypes[2]);
|
||||
GetProperty((*i).alProperties, aiPositions[2]).avList.front(),aiTypes[2]);
|
||||
}
|
||||
|
||||
// and add them to our nice list
|
||||
@@ -659,28 +678,28 @@ void PLYImporter::LoadVertexColor(std::vector<aiColor4D>* pvOut)
|
||||
|
||||
if (0xFFFFFFFF != aiPositions[0])
|
||||
{
|
||||
vOut.r = NormalizeColorValue((*i).alProperties[
|
||||
aiPositions[0]].avList.front(),aiTypes[0]);
|
||||
vOut.r = NormalizeColorValue(GetProperty((*i).alProperties,
|
||||
aiPositions[0]).avList.front(),aiTypes[0]);
|
||||
}
|
||||
|
||||
if (0xFFFFFFFF != aiPositions[1])
|
||||
{
|
||||
vOut.g = NormalizeColorValue((*i).alProperties[
|
||||
aiPositions[1]].avList.front(),aiTypes[1]);
|
||||
vOut.g = NormalizeColorValue(GetProperty((*i).alProperties,
|
||||
aiPositions[1]).avList.front(),aiTypes[1]);
|
||||
}
|
||||
|
||||
if (0xFFFFFFFF != aiPositions[2])
|
||||
{
|
||||
vOut.b = NormalizeColorValue((*i).alProperties[
|
||||
aiPositions[2]].avList.front(),aiTypes[2]);
|
||||
vOut.b = NormalizeColorValue(GetProperty((*i).alProperties,
|
||||
aiPositions[2]).avList.front(),aiTypes[2]);
|
||||
}
|
||||
|
||||
// assume 1.0 for the alpha channel ifit is not set
|
||||
if (0xFFFFFFFF == aiPositions[3])vOut.a = 1.0f;
|
||||
else
|
||||
{
|
||||
vOut.a = NormalizeColorValue((*i).alProperties[
|
||||
aiPositions[3]].avList.front(),aiTypes[3]);
|
||||
vOut.a = NormalizeColorValue(GetProperty((*i).alProperties,
|
||||
aiPositions[3]).avList.front(),aiTypes[3]);
|
||||
}
|
||||
|
||||
// and add them to our nice list
|
||||
@@ -773,11 +792,11 @@ void PLYImporter::LoadFaces(std::vector<PLY::Face>* pvOut)
|
||||
// parse the list of vertex indices
|
||||
if (0xFFFFFFFF != iProperty)
|
||||
{
|
||||
const unsigned int iNum = (unsigned int)(*i).alProperties[iProperty].avList.size();
|
||||
const unsigned int iNum = (unsigned int)GetProperty((*i).alProperties, iProperty).avList.size();
|
||||
sFace.mIndices.resize(iNum);
|
||||
|
||||
std::vector<PLY::PropertyInstance::ValueUnion>::const_iterator p =
|
||||
(*i).alProperties[iProperty].avList.begin();
|
||||
GetProperty((*i).alProperties, iProperty).avList.begin();
|
||||
|
||||
for (unsigned int a = 0; a < iNum;++a,++p)
|
||||
{
|
||||
@@ -789,7 +808,7 @@ void PLYImporter::LoadFaces(std::vector<PLY::Face>* pvOut)
|
||||
if (0xFFFFFFFF != iMaterialIndex)
|
||||
{
|
||||
sFace.iMaterialIndex = PLY::PropertyInstance::ConvertTo<unsigned int>(
|
||||
(*i).alProperties[iMaterialIndex].avList.front(),eType2);
|
||||
GetProperty((*i).alProperties, iMaterialIndex).avList.front(),eType2);
|
||||
}
|
||||
pvOut->push_back(sFace);
|
||||
}
|
||||
@@ -800,7 +819,7 @@ void PLYImporter::LoadFaces(std::vector<PLY::Face>* pvOut)
|
||||
// a value of -1 indicates a restart of the strip
|
||||
bool flip = false;
|
||||
for (std::vector<ElementInstance>::const_iterator i = pcList->alInstances.begin();i != pcList->alInstances.end();++i) {
|
||||
const std::vector<PLY::PropertyInstance::ValueUnion>& quak = (*i).alProperties[iProperty].avList;
|
||||
const std::vector<PLY::PropertyInstance::ValueUnion>& quak = GetProperty((*i).alProperties, iProperty).avList;
|
||||
pvOut->reserve(pvOut->size() + quak.size() + (quak.size()>>2u));
|
||||
|
||||
int aiTable[2] = {-1,-1};
|
||||
@@ -851,30 +870,30 @@ void PLYImporter::GetMaterialColor(const std::vector<PLY::PropertyInstance>& avL
|
||||
if (0xFFFFFFFF == aiPositions[0])clrOut->r = 0.0f;
|
||||
else
|
||||
{
|
||||
clrOut->r = NormalizeColorValue(avList[
|
||||
aiPositions[0]].avList.front(),aiTypes[0]);
|
||||
clrOut->r = NormalizeColorValue(GetProperty(avList,
|
||||
aiPositions[0]).avList.front(),aiTypes[0]);
|
||||
}
|
||||
|
||||
if (0xFFFFFFFF == aiPositions[1])clrOut->g = 0.0f;
|
||||
else
|
||||
{
|
||||
clrOut->g = NormalizeColorValue(avList[
|
||||
aiPositions[1]].avList.front(),aiTypes[1]);
|
||||
clrOut->g = NormalizeColorValue(GetProperty(avList,
|
||||
aiPositions[1]).avList.front(),aiTypes[1]);
|
||||
}
|
||||
|
||||
if (0xFFFFFFFF == aiPositions[2])clrOut->b = 0.0f;
|
||||
else
|
||||
{
|
||||
clrOut->b = NormalizeColorValue(avList[
|
||||
aiPositions[2]].avList.front(),aiTypes[2]);
|
||||
clrOut->b = NormalizeColorValue(GetProperty(avList,
|
||||
aiPositions[2]).avList.front(),aiTypes[2]);
|
||||
}
|
||||
|
||||
// assume 1.0 for the alpha channel ifit is not set
|
||||
if (0xFFFFFFFF == aiPositions[3])clrOut->a = 1.0f;
|
||||
else
|
||||
{
|
||||
clrOut->a = NormalizeColorValue(avList[
|
||||
aiPositions[3]].avList.front(),aiTypes[3]);
|
||||
clrOut->a = NormalizeColorValue(GetProperty(avList,
|
||||
aiPositions[3]).avList.front(),aiTypes[3]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1025,7 +1044,7 @@ void PLYImporter::LoadMaterial(std::vector<aiMaterial*>* pvOut)
|
||||
// handle phong power and shading mode
|
||||
int iMode;
|
||||
if (0xFFFFFFFF != iPhong) {
|
||||
float fSpec = PLY::PropertyInstance::ConvertTo<float>((*i).alProperties[iPhong].avList.front(),ePhong);
|
||||
float fSpec = PLY::PropertyInstance::ConvertTo<float>(GetProperty((*i).alProperties, iPhong).avList.front(),ePhong);
|
||||
|
||||
// if shininess is 0 (and the pow() calculation would therefore always
|
||||
// become 1, not depending on the angle), use gouraud lighting
|
||||
@@ -1043,7 +1062,7 @@ void PLYImporter::LoadMaterial(std::vector<aiMaterial*>* pvOut)
|
||||
|
||||
// handle opacity
|
||||
if (0xFFFFFFFF != iOpacity) {
|
||||
float fOpacity = PLY::PropertyInstance::ConvertTo<float>((*i).alProperties[iPhong].avList.front(),eOpacity);
|
||||
float fOpacity = PLY::PropertyInstance::ConvertTo<float>(GetProperty((*i).alProperties, iPhong).avList.front(),eOpacity);
|
||||
pcHelper->AddProperty<float>(&fOpacity, 1, AI_MATKEY_OPACITY);
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ namespace Assimp {
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Worker function for exporting a scene to Stereolithograpy. Prototyped and registered in Exporter.cpp
|
||||
void ExportSceneSTL(const char* pFile,IOSystem* pIOSystem, const aiScene* pScene)
|
||||
void ExportSceneSTL(const char* pFile,IOSystem* pIOSystem, const aiScene* pScene, const ExportProperties* pProperties)
|
||||
{
|
||||
// invoke the exporter
|
||||
STLExporter exporter(pFile, pScene);
|
||||
@@ -63,7 +63,7 @@ void ExportSceneSTL(const char* pFile,IOSystem* pIOSystem, const aiScene* pScene
|
||||
|
||||
outfile->Write( exporter.mOutput.str().c_str(), static_cast<size_t>(exporter.mOutput.tellp()),1);
|
||||
}
|
||||
void ExportSceneSTLBinary(const char* pFile,IOSystem* pIOSystem, const aiScene* pScene)
|
||||
void ExportSceneSTLBinary(const char* pFile,IOSystem* pIOSystem, const aiScene* pScene, const ExportProperties* pProperties)
|
||||
{
|
||||
// invoke the exporter
|
||||
STLExporter exporter(pFile, pScene, true);
|
||||
|
||||
@@ -59,7 +59,7 @@ namespace Assimp
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Worker function for exporting a scene to Collada. Prototyped and registered in Exporter.cpp
|
||||
void ExportSceneXFile(const char* pFile,IOSystem* pIOSystem, const aiScene* pScene)
|
||||
void ExportSceneXFile(const char* pFile,IOSystem* pIOSystem, const aiScene* pScene, const ExportProperties* pProperties)
|
||||
{
|
||||
std::string path = "";
|
||||
std::string file = pFile;
|
||||
@@ -78,13 +78,19 @@ void ExportSceneXFile(const char* pFile,IOSystem* pIOSystem, const aiScene* pSce
|
||||
}
|
||||
}
|
||||
|
||||
// create/copy Properties
|
||||
ExportProperties props(*pProperties);
|
||||
|
||||
// set standard properties if not set
|
||||
if (!props.HasPropertyBool(AI_CONFIG_EXPORT_XFILE_64BIT)) props.SetPropertyBool(AI_CONFIG_EXPORT_XFILE_64BIT, false);
|
||||
|
||||
// invoke the exporter
|
||||
XFileExporter iDoTheExportThing( pScene, pIOSystem, path, file);
|
||||
XFileExporter iDoTheExportThing( pScene, pIOSystem, path, file, &props);
|
||||
|
||||
// we're still here - export successfully completed. Write result to the given IOSYstem
|
||||
boost::scoped_ptr<IOStream> outfile (pIOSystem->Open(pFile,"wt"));
|
||||
if(outfile == NULL) {
|
||||
throw DeadlyExportError("could not open output .dae file: " + std::string(pFile));
|
||||
throw DeadlyExportError("could not open output .x file: " + std::string(pFile));
|
||||
}
|
||||
|
||||
// XXX maybe use a small wrapper around IOStream that behaves like std::stringstream in order to avoid the extra copy.
|
||||
@@ -96,7 +102,7 @@ void ExportSceneXFile(const char* pFile,IOSystem* pIOSystem, const aiScene* pSce
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Constructor for a specific scene to export
|
||||
XFileExporter::XFileExporter(const aiScene* pScene, IOSystem* pIOSystem, const std::string& path, const std::string& file) : mIOSystem(pIOSystem), mPath(path), mFile(file)
|
||||
XFileExporter::XFileExporter(const aiScene* pScene, IOSystem* pIOSystem, const std::string& path, const std::string& file, const ExportProperties* pProperties) : mIOSystem(pIOSystem), mPath(path), mFile(file), mProperties(pProperties)
|
||||
{
|
||||
// make sure that all formatting happens using the standard, C locale and not the user's current locale
|
||||
mOutput.imbue( std::locale("C") );
|
||||
@@ -126,7 +132,7 @@ void XFileExporter::WriteFile()
|
||||
{
|
||||
// note, that all realnumber values must be comma separated in x files
|
||||
mOutput.setf(std::ios::fixed);
|
||||
mOutput.precision(6); // precission for float
|
||||
mOutput.precision(16); // precission for double
|
||||
|
||||
// entry of writing the file
|
||||
WriteHeader();
|
||||
@@ -148,7 +154,10 @@ void XFileExporter::WriteFile()
|
||||
// Writes the asset header
|
||||
void XFileExporter::WriteHeader()
|
||||
{
|
||||
mOutput << startstr << "xof 0303txt 0032" << endstr;
|
||||
if (mProperties->GetPropertyBool(AI_CONFIG_EXPORT_XFILE_64BIT) == true)
|
||||
mOutput << startstr << "xof 0303txt 0064" << endstr;
|
||||
else
|
||||
mOutput << startstr << "xof 0303txt 0032" << endstr;
|
||||
mOutput << endstr;
|
||||
mOutput << startstr << "template Frame {" << endstr;
|
||||
PushTag();
|
||||
@@ -298,7 +307,7 @@ void XFileExporter::WriteNode( aiNode* pNode)
|
||||
ss << "Node_" << pNode;
|
||||
pNode->mName.Set(ss.str());
|
||||
}
|
||||
mOutput << startstr << "Frame " << pNode->mName.C_Str() << " {" << endstr;
|
||||
mOutput << startstr << "Frame " << toXFileString(pNode->mName) << " {" << endstr;
|
||||
|
||||
PushTag();
|
||||
|
||||
@@ -318,9 +327,9 @@ void XFileExporter::WriteNode( aiNode* pNode)
|
||||
mOutput << startstr << "}" << endstr << endstr;
|
||||
}
|
||||
|
||||
void XFileExporter::WriteMesh(const aiMesh* mesh)
|
||||
void XFileExporter::WriteMesh(aiMesh* mesh)
|
||||
{
|
||||
mOutput << startstr << "Mesh " << mesh->mName.C_Str() << "_mShape" << " {" << endstr;
|
||||
mOutput << startstr << "Mesh " << toXFileString(mesh->mName) << "_mShape" << " {" << endstr;
|
||||
|
||||
PushTag();
|
||||
|
||||
@@ -496,6 +505,16 @@ void XFileExporter::WriteMesh(const aiMesh* mesh)
|
||||
|
||||
}
|
||||
|
||||
std::string XFileExporter::toXFileString(aiString &name)
|
||||
{
|
||||
std::string str = std::string(name.C_Str());
|
||||
std::replace(str.begin(), str.end(), '<', '_');
|
||||
std::replace(str.begin(), str.end(), '>', '_');
|
||||
std::replace(str.begin(), str.end(), '{', '_');
|
||||
std::replace(str.begin(), str.end(), '}', '_');
|
||||
std::replace(str.begin(), str.end(), '$', '_');
|
||||
return str;
|
||||
}
|
||||
|
||||
void XFileExporter::writePath(aiString path)
|
||||
{
|
||||
|
||||
@@ -61,7 +61,7 @@ class XFileExporter
|
||||
{
|
||||
public:
|
||||
/// Constructor for a specific scene to export
|
||||
XFileExporter(const aiScene* pScene, IOSystem* pIOSystem, const std::string& path, const std::string& file);
|
||||
XFileExporter(const aiScene* pScene, IOSystem* pIOSystem, const std::string& path, const std::string& file, const ExportProperties* pProperties);
|
||||
|
||||
/// Destructor
|
||||
virtual ~XFileExporter();
|
||||
@@ -80,7 +80,7 @@ protected:
|
||||
void WriteNode( aiNode* pNode );
|
||||
|
||||
/// write a mesh entry of the scene
|
||||
void WriteMesh(const aiMesh* mesh);
|
||||
void WriteMesh( aiMesh* mesh);
|
||||
|
||||
/// Enters a new xml element, which increases the indentation
|
||||
void PushTag() { startstr.append( " "); }
|
||||
@@ -94,6 +94,12 @@ public:
|
||||
|
||||
protected:
|
||||
|
||||
/// normalize the name to be accepted by xfile readers
|
||||
std::string toXFileString(aiString &name);
|
||||
|
||||
/// hold the properties pointer
|
||||
const ExportProperties* mProperties;
|
||||
|
||||
/// write a path
|
||||
void writePath(aiString path);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user