Merge branch 'master' into FBXParser_check_inputlength_fix
commit
af9705e3d1
|
@ -1,2 +1,2 @@
|
||||||
patreon: assimp
|
patreon: assimp
|
||||||
ko_fi: kimkulling
|
Paypal: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=4JRJVPXC4QJM4
|
||||||
|
|
|
@ -46,607 +46,20 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#ifndef ASSIMP_BUILD_NO_EXPORT
|
#ifndef ASSIMP_BUILD_NO_EXPORT
|
||||||
#ifndef ASSIMP_BUILD_NO_ASSXML_EXPORTER
|
#ifndef ASSIMP_BUILD_NO_ASSXML_EXPORTER
|
||||||
|
|
||||||
#include "PostProcessing/ProcessHelper.h"
|
#include "AssxmlFileWriter.h"
|
||||||
|
|
||||||
#include <assimp/version.h>
|
|
||||||
#include <assimp/IOStream.hpp>
|
|
||||||
#include <assimp/IOSystem.hpp>
|
#include <assimp/IOSystem.hpp>
|
||||||
#include <assimp/Exporter.hpp>
|
#include <assimp/Exporter.hpp>
|
||||||
|
|
||||||
#include <stdarg.h>
|
|
||||||
|
|
||||||
#ifdef ASSIMP_BUILD_NO_OWN_ZLIB
|
|
||||||
# include <zlib.h>
|
|
||||||
#else
|
|
||||||
# include <contrib/zlib/zlib.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <time.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
using namespace Assimp;
|
|
||||||
|
|
||||||
namespace Assimp {
|
namespace Assimp {
|
||||||
|
|
||||||
namespace AssxmlExport {
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
|
||||||
static int ioprintf( IOStream * io, const char *format, ... ) {
|
|
||||||
using namespace std;
|
|
||||||
if ( nullptr == io ) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const int Size = 4096;
|
|
||||||
char sz[ Size ];
|
|
||||||
::memset( sz, '\0', Size );
|
|
||||||
va_list va;
|
|
||||||
va_start( va, format );
|
|
||||||
const unsigned int nSize = vsnprintf( sz, Size-1, format, va );
|
|
||||||
ai_assert( nSize < Size );
|
|
||||||
va_end( va );
|
|
||||||
|
|
||||||
io->Write( sz, sizeof(char), nSize );
|
|
||||||
|
|
||||||
return nSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
|
||||||
// Convert a name to standard XML format
|
|
||||||
static void ConvertName(aiString& out, const aiString& in) {
|
|
||||||
out.length = 0;
|
|
||||||
for (unsigned int i = 0; i < in.length; ++i) {
|
|
||||||
switch (in.data[i]) {
|
|
||||||
case '<':
|
|
||||||
out.Append("<");break;
|
|
||||||
case '>':
|
|
||||||
out.Append(">");break;
|
|
||||||
case '&':
|
|
||||||
out.Append("&");break;
|
|
||||||
case '\"':
|
|
||||||
out.Append(""");break;
|
|
||||||
case '\'':
|
|
||||||
out.Append("'");break;
|
|
||||||
default:
|
|
||||||
out.data[out.length++] = in.data[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
out.data[out.length] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
|
||||||
// Write a single node as text dump
|
|
||||||
static void WriteNode(const aiNode* node, IOStream * io, unsigned int depth) {
|
|
||||||
char prefix[512];
|
|
||||||
for (unsigned int i = 0; i < depth;++i)
|
|
||||||
prefix[i] = '\t';
|
|
||||||
prefix[depth] = '\0';
|
|
||||||
|
|
||||||
const aiMatrix4x4& m = node->mTransformation;
|
|
||||||
|
|
||||||
aiString name;
|
|
||||||
ConvertName(name,node->mName);
|
|
||||||
ioprintf(io,"%s<Node name=\"%s\"> \n"
|
|
||||||
"%s\t<Matrix4> \n"
|
|
||||||
"%s\t\t%0 6f %0 6f %0 6f %0 6f\n"
|
|
||||||
"%s\t\t%0 6f %0 6f %0 6f %0 6f\n"
|
|
||||||
"%s\t\t%0 6f %0 6f %0 6f %0 6f\n"
|
|
||||||
"%s\t\t%0 6f %0 6f %0 6f %0 6f\n"
|
|
||||||
"%s\t</Matrix4> \n",
|
|
||||||
prefix,name.data,prefix,
|
|
||||||
prefix,m.a1,m.a2,m.a3,m.a4,
|
|
||||||
prefix,m.b1,m.b2,m.b3,m.b4,
|
|
||||||
prefix,m.c1,m.c2,m.c3,m.c4,
|
|
||||||
prefix,m.d1,m.d2,m.d3,m.d4,prefix);
|
|
||||||
|
|
||||||
if (node->mNumMeshes) {
|
|
||||||
ioprintf(io, "%s\t<MeshRefs num=\"%i\">\n%s\t",
|
|
||||||
prefix,node->mNumMeshes,prefix);
|
|
||||||
|
|
||||||
for (unsigned int i = 0; i < node->mNumMeshes;++i) {
|
|
||||||
ioprintf(io,"%i ",node->mMeshes[i]);
|
|
||||||
}
|
|
||||||
ioprintf(io,"\n%s\t</MeshRefs>\n",prefix);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (node->mNumChildren) {
|
|
||||||
ioprintf(io,"%s\t<NodeList num=\"%i\">\n",
|
|
||||||
prefix,node->mNumChildren);
|
|
||||||
|
|
||||||
for (unsigned int i = 0; i < node->mNumChildren;++i) {
|
|
||||||
WriteNode(node->mChildren[i],io,depth+2);
|
|
||||||
}
|
|
||||||
ioprintf(io,"%s\t</NodeList>\n",prefix);
|
|
||||||
}
|
|
||||||
ioprintf(io,"%s</Node>\n",prefix);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
|
||||||
// Some chuncks of text will need to be encoded for XML
|
|
||||||
// http://stackoverflow.com/questions/5665231/most-efficient-way-to-escape-xml-html-in-c-string#5665377
|
|
||||||
static std::string encodeXML(const std::string& data) {
|
|
||||||
std::string buffer;
|
|
||||||
buffer.reserve(data.size());
|
|
||||||
for(size_t pos = 0; pos != data.size(); ++pos) {
|
|
||||||
switch(data[pos]) {
|
|
||||||
case '&': buffer.append("&"); break;
|
|
||||||
case '\"': buffer.append("""); break;
|
|
||||||
case '\'': buffer.append("'"); break;
|
|
||||||
case '<': buffer.append("<"); break;
|
|
||||||
case '>': buffer.append(">"); break;
|
|
||||||
default: buffer.append(&data[pos], 1); break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return buffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
|
||||||
// Write a text model dump
|
|
||||||
static
|
|
||||||
void WriteDump(const aiScene* scene, IOStream* io, bool shortened) {
|
|
||||||
time_t tt = ::time( NULL );
|
|
||||||
#if _WIN32
|
|
||||||
tm* p = gmtime(&tt);
|
|
||||||
#else
|
|
||||||
struct tm now;
|
|
||||||
tm* p = gmtime_r(&tt, &now);
|
|
||||||
#endif
|
|
||||||
ai_assert(nullptr != p);
|
|
||||||
|
|
||||||
// write header
|
|
||||||
std::string header(
|
|
||||||
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
|
|
||||||
"<ASSIMP format_id=\"1\">\n\n"
|
|
||||||
"<!-- XML Model dump produced by assimp dump\n"
|
|
||||||
" Library version: %i.%i.%i\n"
|
|
||||||
" %s\n"
|
|
||||||
"-->"
|
|
||||||
" \n\n"
|
|
||||||
"<Scene flags=\"%d\" postprocessing=\"%i\">\n"
|
|
||||||
);
|
|
||||||
|
|
||||||
const unsigned int majorVersion( aiGetVersionMajor() );
|
|
||||||
const unsigned int minorVersion( aiGetVersionMinor() );
|
|
||||||
const unsigned int rev( aiGetVersionRevision() );
|
|
||||||
const char *curtime( asctime( p ) );
|
|
||||||
ioprintf( io, header.c_str(), majorVersion, minorVersion, rev, curtime, scene->mFlags, 0 );
|
|
||||||
|
|
||||||
// write the node graph
|
|
||||||
WriteNode(scene->mRootNode, io, 0);
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
// write cameras
|
|
||||||
for (unsigned int i = 0; i < scene->mNumCameras;++i) {
|
|
||||||
aiCamera* cam = scene->mCameras[i];
|
|
||||||
ConvertName(name,cam->mName);
|
|
||||||
|
|
||||||
// camera header
|
|
||||||
ioprintf(io,"\t<Camera parent=\"%s\">\n"
|
|
||||||
"\t\t<Vector3 name=\"up\" > %0 8f %0 8f %0 8f </Vector3>\n"
|
|
||||||
"\t\t<Vector3 name=\"lookat\" > %0 8f %0 8f %0 8f </Vector3>\n"
|
|
||||||
"\t\t<Vector3 name=\"pos\" > %0 8f %0 8f %0 8f </Vector3>\n"
|
|
||||||
"\t\t<Float name=\"fov\" > %f </Float>\n"
|
|
||||||
"\t\t<Float name=\"aspect\" > %f </Float>\n"
|
|
||||||
"\t\t<Float name=\"near_clip\" > %f </Float>\n"
|
|
||||||
"\t\t<Float name=\"far_clip\" > %f </Float>\n"
|
|
||||||
"\t</Camera>\n",
|
|
||||||
name.data,
|
|
||||||
cam->mUp.x,cam->mUp.y,cam->mUp.z,
|
|
||||||
cam->mLookAt.x,cam->mLookAt.y,cam->mLookAt.z,
|
|
||||||
cam->mPosition.x,cam->mPosition.y,cam->mPosition.z,
|
|
||||||
cam->mHorizontalFOV,cam->mAspect,cam->mClipPlaneNear,cam->mClipPlaneFar,i);
|
|
||||||
}
|
|
||||||
|
|
||||||
// write lights
|
|
||||||
for (unsigned int i = 0; i < scene->mNumLights;++i) {
|
|
||||||
aiLight* l = scene->mLights[i];
|
|
||||||
ConvertName(name,l->mName);
|
|
||||||
|
|
||||||
// light header
|
|
||||||
ioprintf(io,"\t<Light parent=\"%s\"> type=\"%s\"\n"
|
|
||||||
"\t\t<Vector3 name=\"diffuse\" > %0 8f %0 8f %0 8f </Vector3>\n"
|
|
||||||
"\t\t<Vector3 name=\"specular\" > %0 8f %0 8f %0 8f </Vector3>\n"
|
|
||||||
"\t\t<Vector3 name=\"ambient\" > %0 8f %0 8f %0 8f </Vector3>\n",
|
|
||||||
name.data,
|
|
||||||
(l->mType == aiLightSource_DIRECTIONAL ? "directional" :
|
|
||||||
(l->mType == aiLightSource_POINT ? "point" : "spot" )),
|
|
||||||
l->mColorDiffuse.r, l->mColorDiffuse.g, l->mColorDiffuse.b,
|
|
||||||
l->mColorSpecular.r,l->mColorSpecular.g,l->mColorSpecular.b,
|
|
||||||
l->mColorAmbient.r, l->mColorAmbient.g, l->mColorAmbient.b);
|
|
||||||
|
|
||||||
if (l->mType != aiLightSource_DIRECTIONAL) {
|
|
||||||
ioprintf(io,
|
|
||||||
"\t\t<Vector3 name=\"pos\" > %0 8f %0 8f %0 8f </Vector3>\n"
|
|
||||||
"\t\t<Float name=\"atten_cst\" > %f </Float>\n"
|
|
||||||
"\t\t<Float name=\"atten_lin\" > %f </Float>\n"
|
|
||||||
"\t\t<Float name=\"atten_sqr\" > %f </Float>\n",
|
|
||||||
l->mPosition.x,l->mPosition.y,l->mPosition.z,
|
|
||||||
l->mAttenuationConstant,l->mAttenuationLinear,l->mAttenuationQuadratic);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (l->mType != aiLightSource_POINT) {
|
|
||||||
ioprintf(io,
|
|
||||||
"\t\t<Vector3 name=\"lookat\" > %0 8f %0 8f %0 8f </Vector3>\n",
|
|
||||||
l->mDirection.x,l->mDirection.y,l->mDirection.z);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (l->mType == aiLightSource_SPOT) {
|
|
||||||
ioprintf(io,
|
|
||||||
"\t\t<Float name=\"cone_out\" > %f </Float>\n"
|
|
||||||
"\t\t<Float name=\"cone_inn\" > %f </Float>\n",
|
|
||||||
l->mAngleOuterCone,l->mAngleInnerCone);
|
|
||||||
}
|
|
||||||
ioprintf(io,"\t</Light>\n");
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
aiString name;
|
|
||||||
|
|
||||||
// write textures
|
|
||||||
if (scene->mNumTextures) {
|
|
||||||
ioprintf(io,"<TextureList num=\"%i\">\n",scene->mNumTextures);
|
|
||||||
for (unsigned int i = 0; i < scene->mNumTextures;++i) {
|
|
||||||
aiTexture* tex = scene->mTextures[i];
|
|
||||||
bool compressed = (tex->mHeight == 0);
|
|
||||||
|
|
||||||
// mesh header
|
|
||||||
ioprintf(io,"\t<Texture width=\"%i\" height=\"%i\" compressed=\"%s\"> \n",
|
|
||||||
(compressed ? -1 : tex->mWidth),(compressed ? -1 : tex->mHeight),
|
|
||||||
(compressed ? "true" : "false"));
|
|
||||||
|
|
||||||
if (compressed) {
|
|
||||||
ioprintf(io,"\t\t<Data length=\"%i\"> \n",tex->mWidth);
|
|
||||||
|
|
||||||
if (!shortened) {
|
|
||||||
for (unsigned int n = 0; n < tex->mWidth;++n) {
|
|
||||||
ioprintf(io,"\t\t\t%2x",reinterpret_cast<uint8_t*>(tex->pcData)[n]);
|
|
||||||
if (n && !(n % 50)) {
|
|
||||||
ioprintf(io,"\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (!shortened){
|
|
||||||
ioprintf(io,"\t\t<Data length=\"%i\"> \n",tex->mWidth*tex->mHeight*4);
|
|
||||||
|
|
||||||
// const unsigned int width = (unsigned int)std::log10((double)std::max(tex->mHeight,tex->mWidth))+1;
|
|
||||||
for (unsigned int y = 0; y < tex->mHeight;++y) {
|
|
||||||
for (unsigned int x = 0; x < tex->mWidth;++x) {
|
|
||||||
aiTexel* tx = tex->pcData + y*tex->mWidth+x;
|
|
||||||
unsigned int r = tx->r,g=tx->g,b=tx->b,a=tx->a;
|
|
||||||
ioprintf(io,"\t\t\t%2x %2x %2x %2x",r,g,b,a);
|
|
||||||
|
|
||||||
// group by four for readability
|
|
||||||
if ( 0 == ( x + y*tex->mWidth ) % 4 ) {
|
|
||||||
ioprintf( io, "\n" );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ioprintf(io,"\t\t</Data>\n\t</Texture>\n");
|
|
||||||
}
|
|
||||||
ioprintf(io,"</TextureList>\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
// write materials
|
|
||||||
if (scene->mNumMaterials) {
|
|
||||||
ioprintf(io,"<MaterialList num=\"%i\">\n",scene->mNumMaterials);
|
|
||||||
for (unsigned int i = 0; i< scene->mNumMaterials; ++i) {
|
|
||||||
const aiMaterial* mat = scene->mMaterials[i];
|
|
||||||
|
|
||||||
ioprintf(io,"\t<Material>\n");
|
|
||||||
ioprintf(io,"\t\t<MatPropertyList num=\"%i\">\n",mat->mNumProperties);
|
|
||||||
for (unsigned int n = 0; n < mat->mNumProperties;++n) {
|
|
||||||
|
|
||||||
const aiMaterialProperty* prop = mat->mProperties[n];
|
|
||||||
const char* sz = "";
|
|
||||||
if (prop->mType == aiPTI_Float) {
|
|
||||||
sz = "float";
|
|
||||||
}
|
|
||||||
else if (prop->mType == aiPTI_Integer) {
|
|
||||||
sz = "integer";
|
|
||||||
}
|
|
||||||
else if (prop->mType == aiPTI_String) {
|
|
||||||
sz = "string";
|
|
||||||
}
|
|
||||||
else if (prop->mType == aiPTI_Buffer) {
|
|
||||||
sz = "binary_buffer";
|
|
||||||
}
|
|
||||||
|
|
||||||
ioprintf(io,"\t\t\t<MatProperty key=\"%s\" \n\t\t\ttype=\"%s\" tex_usage=\"%s\" tex_index=\"%i\"",
|
|
||||||
prop->mKey.data, sz,
|
|
||||||
::TextureTypeToString((aiTextureType)prop->mSemantic),prop->mIndex);
|
|
||||||
|
|
||||||
if (prop->mType == aiPTI_Float) {
|
|
||||||
ioprintf(io," size=\"%i\">\n\t\t\t\t",
|
|
||||||
static_cast<int>(prop->mDataLength/sizeof(float)));
|
|
||||||
|
|
||||||
for (unsigned int p = 0; p < prop->mDataLength/sizeof(float);++p) {
|
|
||||||
ioprintf(io,"%f ",*((float*)(prop->mData+p*sizeof(float))));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (prop->mType == aiPTI_Integer) {
|
|
||||||
ioprintf(io," size=\"%i\">\n\t\t\t\t",
|
|
||||||
static_cast<int>(prop->mDataLength/sizeof(int)));
|
|
||||||
|
|
||||||
for (unsigned int p = 0; p < prop->mDataLength/sizeof(int);++p) {
|
|
||||||
ioprintf(io,"%i ",*((int*)(prop->mData+p*sizeof(int))));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (prop->mType == aiPTI_Buffer) {
|
|
||||||
ioprintf(io," size=\"%i\">\n\t\t\t\t",
|
|
||||||
static_cast<int>(prop->mDataLength));
|
|
||||||
|
|
||||||
for (unsigned int p = 0; p < prop->mDataLength;++p) {
|
|
||||||
ioprintf(io,"%2x ",prop->mData[p]);
|
|
||||||
if (p && 0 == p%30) {
|
|
||||||
ioprintf(io,"\n\t\t\t\t");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (prop->mType == aiPTI_String) {
|
|
||||||
ioprintf(io,">\n\t\t\t\t\"%s\"",encodeXML(prop->mData+4).c_str() /* skip length */);
|
|
||||||
}
|
|
||||||
ioprintf(io,"\n\t\t\t</MatProperty>\n");
|
|
||||||
}
|
|
||||||
ioprintf(io,"\t\t</MatPropertyList>\n");
|
|
||||||
ioprintf(io,"\t</Material>\n");
|
|
||||||
}
|
|
||||||
ioprintf(io,"</MaterialList>\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
// write animations
|
|
||||||
if (scene->mNumAnimations) {
|
|
||||||
ioprintf(io,"<AnimationList num=\"%i\">\n",scene->mNumAnimations);
|
|
||||||
for (unsigned int i = 0; i < scene->mNumAnimations;++i) {
|
|
||||||
aiAnimation* anim = scene->mAnimations[i];
|
|
||||||
|
|
||||||
// anim header
|
|
||||||
ConvertName(name,anim->mName);
|
|
||||||
ioprintf(io,"\t<Animation name=\"%s\" duration=\"%e\" tick_cnt=\"%e\">\n",
|
|
||||||
name.data, anim->mDuration, anim->mTicksPerSecond);
|
|
||||||
|
|
||||||
// write bone animation channels
|
|
||||||
if (anim->mNumChannels) {
|
|
||||||
ioprintf(io,"\t\t<NodeAnimList num=\"%i\">\n",anim->mNumChannels);
|
|
||||||
for (unsigned int n = 0; n < anim->mNumChannels;++n) {
|
|
||||||
aiNodeAnim* nd = anim->mChannels[n];
|
|
||||||
|
|
||||||
// node anim header
|
|
||||||
ConvertName(name,nd->mNodeName);
|
|
||||||
ioprintf(io,"\t\t\t<NodeAnim node=\"%s\">\n",name.data);
|
|
||||||
|
|
||||||
if (!shortened) {
|
|
||||||
// write position keys
|
|
||||||
if (nd->mNumPositionKeys) {
|
|
||||||
ioprintf(io,"\t\t\t\t<PositionKeyList num=\"%i\">\n",nd->mNumPositionKeys);
|
|
||||||
for (unsigned int a = 0; a < nd->mNumPositionKeys;++a) {
|
|
||||||
aiVectorKey* vc = nd->mPositionKeys+a;
|
|
||||||
ioprintf(io,"\t\t\t\t\t<PositionKey time=\"%e\">\n"
|
|
||||||
"\t\t\t\t\t\t%0 8f %0 8f %0 8f\n\t\t\t\t\t</PositionKey>\n",
|
|
||||||
vc->mTime,vc->mValue.x,vc->mValue.y,vc->mValue.z);
|
|
||||||
}
|
|
||||||
ioprintf(io,"\t\t\t\t</PositionKeyList>\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
// write scaling keys
|
|
||||||
if (nd->mNumScalingKeys) {
|
|
||||||
ioprintf(io,"\t\t\t\t<ScalingKeyList num=\"%i\">\n",nd->mNumScalingKeys);
|
|
||||||
for (unsigned int a = 0; a < nd->mNumScalingKeys;++a) {
|
|
||||||
aiVectorKey* vc = nd->mScalingKeys+a;
|
|
||||||
ioprintf(io,"\t\t\t\t\t<ScalingKey time=\"%e\">\n"
|
|
||||||
"\t\t\t\t\t\t%0 8f %0 8f %0 8f\n\t\t\t\t\t</ScalingKey>\n",
|
|
||||||
vc->mTime,vc->mValue.x,vc->mValue.y,vc->mValue.z);
|
|
||||||
}
|
|
||||||
ioprintf(io,"\t\t\t\t</ScalingKeyList>\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
// write rotation keys
|
|
||||||
if (nd->mNumRotationKeys) {
|
|
||||||
ioprintf(io,"\t\t\t\t<RotationKeyList num=\"%i\">\n",nd->mNumRotationKeys);
|
|
||||||
for (unsigned int a = 0; a < nd->mNumRotationKeys;++a) {
|
|
||||||
aiQuatKey* vc = nd->mRotationKeys+a;
|
|
||||||
ioprintf(io,"\t\t\t\t\t<RotationKey time=\"%e\">\n"
|
|
||||||
"\t\t\t\t\t\t%0 8f %0 8f %0 8f %0 8f\n\t\t\t\t\t</RotationKey>\n",
|
|
||||||
vc->mTime,vc->mValue.x,vc->mValue.y,vc->mValue.z,vc->mValue.w);
|
|
||||||
}
|
|
||||||
ioprintf(io,"\t\t\t\t</RotationKeyList>\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ioprintf(io,"\t\t\t</NodeAnim>\n");
|
|
||||||
}
|
|
||||||
ioprintf(io,"\t\t</NodeAnimList>\n");
|
|
||||||
}
|
|
||||||
ioprintf(io,"\t</Animation>\n");
|
|
||||||
}
|
|
||||||
ioprintf(io,"</AnimationList>\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
// write meshes
|
|
||||||
if (scene->mNumMeshes) {
|
|
||||||
ioprintf(io,"<MeshList num=\"%i\">\n",scene->mNumMeshes);
|
|
||||||
for (unsigned int i = 0; i < scene->mNumMeshes;++i) {
|
|
||||||
aiMesh* mesh = scene->mMeshes[i];
|
|
||||||
// const unsigned int width = (unsigned int)std::log10((double)mesh->mNumVertices)+1;
|
|
||||||
|
|
||||||
// mesh header
|
|
||||||
ioprintf(io,"\t<Mesh types=\"%s %s %s %s\" material_index=\"%i\">\n",
|
|
||||||
(mesh->mPrimitiveTypes & aiPrimitiveType_POINT ? "points" : ""),
|
|
||||||
(mesh->mPrimitiveTypes & aiPrimitiveType_LINE ? "lines" : ""),
|
|
||||||
(mesh->mPrimitiveTypes & aiPrimitiveType_TRIANGLE ? "triangles" : ""),
|
|
||||||
(mesh->mPrimitiveTypes & aiPrimitiveType_POLYGON ? "polygons" : ""),
|
|
||||||
mesh->mMaterialIndex);
|
|
||||||
|
|
||||||
// bones
|
|
||||||
if (mesh->mNumBones) {
|
|
||||||
ioprintf(io,"\t\t<BoneList num=\"%i\">\n",mesh->mNumBones);
|
|
||||||
|
|
||||||
for (unsigned int n = 0; n < mesh->mNumBones;++n) {
|
|
||||||
aiBone* bone = mesh->mBones[n];
|
|
||||||
|
|
||||||
ConvertName(name,bone->mName);
|
|
||||||
// bone header
|
|
||||||
ioprintf(io,"\t\t\t<Bone name=\"%s\">\n"
|
|
||||||
"\t\t\t\t<Matrix4> \n"
|
|
||||||
"\t\t\t\t\t%0 6f %0 6f %0 6f %0 6f\n"
|
|
||||||
"\t\t\t\t\t%0 6f %0 6f %0 6f %0 6f\n"
|
|
||||||
"\t\t\t\t\t%0 6f %0 6f %0 6f %0 6f\n"
|
|
||||||
"\t\t\t\t\t%0 6f %0 6f %0 6f %0 6f\n"
|
|
||||||
"\t\t\t\t</Matrix4> \n",
|
|
||||||
name.data,
|
|
||||||
bone->mOffsetMatrix.a1,bone->mOffsetMatrix.a2,bone->mOffsetMatrix.a3,bone->mOffsetMatrix.a4,
|
|
||||||
bone->mOffsetMatrix.b1,bone->mOffsetMatrix.b2,bone->mOffsetMatrix.b3,bone->mOffsetMatrix.b4,
|
|
||||||
bone->mOffsetMatrix.c1,bone->mOffsetMatrix.c2,bone->mOffsetMatrix.c3,bone->mOffsetMatrix.c4,
|
|
||||||
bone->mOffsetMatrix.d1,bone->mOffsetMatrix.d2,bone->mOffsetMatrix.d3,bone->mOffsetMatrix.d4);
|
|
||||||
|
|
||||||
if (!shortened && bone->mNumWeights) {
|
|
||||||
ioprintf(io,"\t\t\t\t<WeightList num=\"%i\">\n",bone->mNumWeights);
|
|
||||||
|
|
||||||
// bone weights
|
|
||||||
for (unsigned int a = 0; a < bone->mNumWeights;++a) {
|
|
||||||
aiVertexWeight* wght = bone->mWeights+a;
|
|
||||||
|
|
||||||
ioprintf(io,"\t\t\t\t\t<Weight index=\"%i\">\n\t\t\t\t\t\t%f\n\t\t\t\t\t</Weight>\n",
|
|
||||||
wght->mVertexId,wght->mWeight);
|
|
||||||
}
|
|
||||||
ioprintf(io,"\t\t\t\t</WeightList>\n");
|
|
||||||
}
|
|
||||||
ioprintf(io,"\t\t\t</Bone>\n");
|
|
||||||
}
|
|
||||||
ioprintf(io,"\t\t</BoneList>\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
// faces
|
|
||||||
if (!shortened && mesh->mNumFaces) {
|
|
||||||
ioprintf(io,"\t\t<FaceList num=\"%i\">\n",mesh->mNumFaces);
|
|
||||||
for (unsigned int n = 0; n < mesh->mNumFaces; ++n) {
|
|
||||||
aiFace& f = mesh->mFaces[n];
|
|
||||||
ioprintf(io,"\t\t\t<Face num=\"%i\">\n"
|
|
||||||
"\t\t\t\t",f.mNumIndices);
|
|
||||||
|
|
||||||
for (unsigned int j = 0; j < f.mNumIndices;++j)
|
|
||||||
ioprintf(io,"%i ",f.mIndices[j]);
|
|
||||||
|
|
||||||
ioprintf(io,"\n\t\t\t</Face>\n");
|
|
||||||
}
|
|
||||||
ioprintf(io,"\t\t</FaceList>\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
// vertex positions
|
|
||||||
if (mesh->HasPositions()) {
|
|
||||||
ioprintf(io,"\t\t<Positions num=\"%i\" set=\"0\" num_components=\"3\"> \n",mesh->mNumVertices);
|
|
||||||
if (!shortened) {
|
|
||||||
for (unsigned int n = 0; n < mesh->mNumVertices; ++n) {
|
|
||||||
ioprintf(io,"\t\t%0 8f %0 8f %0 8f\n",
|
|
||||||
mesh->mVertices[n].x,
|
|
||||||
mesh->mVertices[n].y,
|
|
||||||
mesh->mVertices[n].z);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ioprintf(io,"\t\t</Positions>\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
// vertex normals
|
|
||||||
if (mesh->HasNormals()) {
|
|
||||||
ioprintf(io,"\t\t<Normals num=\"%i\" set=\"0\" num_components=\"3\"> \n",mesh->mNumVertices);
|
|
||||||
if (!shortened) {
|
|
||||||
for (unsigned int n = 0; n < mesh->mNumVertices; ++n) {
|
|
||||||
ioprintf(io,"\t\t%0 8f %0 8f %0 8f\n",
|
|
||||||
mesh->mNormals[n].x,
|
|
||||||
mesh->mNormals[n].y,
|
|
||||||
mesh->mNormals[n].z);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ioprintf(io,"\t\t</Normals>\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
// vertex tangents and bitangents
|
|
||||||
if (mesh->HasTangentsAndBitangents()) {
|
|
||||||
ioprintf(io,"\t\t<Tangents num=\"%i\" set=\"0\" num_components=\"3\"> \n",mesh->mNumVertices);
|
|
||||||
if (!shortened) {
|
|
||||||
for (unsigned int n = 0; n < mesh->mNumVertices; ++n) {
|
|
||||||
ioprintf(io,"\t\t%0 8f %0 8f %0 8f\n",
|
|
||||||
mesh->mTangents[n].x,
|
|
||||||
mesh->mTangents[n].y,
|
|
||||||
mesh->mTangents[n].z);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ioprintf(io,"\t\t</Tangents>\n");
|
|
||||||
|
|
||||||
ioprintf(io,"\t\t<Bitangents num=\"%i\" set=\"0\" num_components=\"3\"> \n",mesh->mNumVertices);
|
|
||||||
if (!shortened) {
|
|
||||||
for (unsigned int n = 0; n < mesh->mNumVertices; ++n) {
|
|
||||||
ioprintf(io,"\t\t%0 8f %0 8f %0 8f\n",
|
|
||||||
mesh->mBitangents[n].x,
|
|
||||||
mesh->mBitangents[n].y,
|
|
||||||
mesh->mBitangents[n].z);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ioprintf(io,"\t\t</Bitangents>\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
// texture coordinates
|
|
||||||
for (unsigned int a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++a) {
|
|
||||||
if (!mesh->mTextureCoords[a])
|
|
||||||
break;
|
|
||||||
|
|
||||||
ioprintf(io,"\t\t<TextureCoords num=\"%i\" set=\"%i\" num_components=\"%i\"> \n",mesh->mNumVertices,
|
|
||||||
a,mesh->mNumUVComponents[a]);
|
|
||||||
|
|
||||||
if (!shortened) {
|
|
||||||
if (mesh->mNumUVComponents[a] == 3) {
|
|
||||||
for (unsigned int n = 0; n < mesh->mNumVertices; ++n) {
|
|
||||||
ioprintf(io,"\t\t%0 8f %0 8f %0 8f\n",
|
|
||||||
mesh->mTextureCoords[a][n].x,
|
|
||||||
mesh->mTextureCoords[a][n].y,
|
|
||||||
mesh->mTextureCoords[a][n].z);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
for (unsigned int n = 0; n < mesh->mNumVertices; ++n) {
|
|
||||||
ioprintf(io,"\t\t%0 8f %0 8f\n",
|
|
||||||
mesh->mTextureCoords[a][n].x,
|
|
||||||
mesh->mTextureCoords[a][n].y);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ioprintf(io,"\t\t</TextureCoords>\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
// vertex colors
|
|
||||||
for (unsigned int a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS; ++a) {
|
|
||||||
if (!mesh->mColors[a])
|
|
||||||
break;
|
|
||||||
ioprintf(io,"\t\t<Colors num=\"%i\" set=\"%i\" num_components=\"4\"> \n",mesh->mNumVertices,a);
|
|
||||||
if (!shortened) {
|
|
||||||
for (unsigned int n = 0; n < mesh->mNumVertices; ++n) {
|
|
||||||
ioprintf(io,"\t\t%0 8f %0 8f %0 8f %0 8f\n",
|
|
||||||
mesh->mColors[a][n].r,
|
|
||||||
mesh->mColors[a][n].g,
|
|
||||||
mesh->mColors[a][n].b,
|
|
||||||
mesh->mColors[a][n].a);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ioprintf(io,"\t\t</Colors>\n");
|
|
||||||
}
|
|
||||||
ioprintf(io,"\t</Mesh>\n");
|
|
||||||
}
|
|
||||||
ioprintf(io,"</MeshList>\n");
|
|
||||||
}
|
|
||||||
ioprintf(io,"</Scene>\n</ASSIMP>");
|
|
||||||
}
|
|
||||||
|
|
||||||
} // end of namespace AssxmlExport
|
|
||||||
|
|
||||||
void ExportSceneAssxml(const char* pFile, IOSystem* pIOSystem, const aiScene* pScene, const ExportProperties* /*pProperties*/)
|
void ExportSceneAssxml(const char* pFile, IOSystem* pIOSystem, const aiScene* pScene, const ExportProperties* /*pProperties*/)
|
||||||
{
|
{
|
||||||
IOStream * out = pIOSystem->Open( pFile, "wt" );
|
DumpSceneToAssxml(
|
||||||
if (!out) return;
|
pFile,
|
||||||
|
"\0", // command(s)
|
||||||
bool shortened = false;
|
pIOSystem,
|
||||||
AssxmlExport::WriteDump( pScene, out, shortened );
|
pScene,
|
||||||
|
false); // shortened?
|
||||||
pIOSystem->Close( out );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // end of namespace Assimp
|
} // end of namespace Assimp
|
||||||
|
|
|
@ -0,0 +1,664 @@
|
||||||
|
/*
|
||||||
|
Open Asset Import Library (assimp)
|
||||||
|
----------------------------------------------------------------------
|
||||||
|
|
||||||
|
Copyright (c) 2006-2020, 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.
|
||||||
|
|
||||||
|
----------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @file AssxmlFileWriter.cpp
|
||||||
|
* @brief Implementation of Assxml file writer.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "AssxmlFileWriter.h"
|
||||||
|
|
||||||
|
#include "PostProcessing/ProcessHelper.h"
|
||||||
|
|
||||||
|
#include <assimp/version.h>
|
||||||
|
#include <assimp/IOStream.hpp>
|
||||||
|
#include <assimp/IOSystem.hpp>
|
||||||
|
#include <assimp/Exporter.hpp>
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
#ifdef ASSIMP_BUILD_NO_OWN_ZLIB
|
||||||
|
# include <zlib.h>
|
||||||
|
#else
|
||||||
|
# include <contrib/zlib/zlib.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <time.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
using namespace Assimp;
|
||||||
|
|
||||||
|
namespace Assimp {
|
||||||
|
|
||||||
|
namespace AssxmlFileWriter {
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------------
|
||||||
|
static int ioprintf( IOStream * io, const char *format, ... ) {
|
||||||
|
using namespace std;
|
||||||
|
if ( nullptr == io ) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const int Size = 4096;
|
||||||
|
char sz[ Size ];
|
||||||
|
::memset( sz, '\0', Size );
|
||||||
|
va_list va;
|
||||||
|
va_start( va, format );
|
||||||
|
const unsigned int nSize = vsnprintf( sz, Size-1, format, va );
|
||||||
|
ai_assert( nSize < Size );
|
||||||
|
va_end( va );
|
||||||
|
|
||||||
|
io->Write( sz, sizeof(char), nSize );
|
||||||
|
|
||||||
|
return nSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------------
|
||||||
|
// Convert a name to standard XML format
|
||||||
|
static void ConvertName(aiString& out, const aiString& in) {
|
||||||
|
out.length = 0;
|
||||||
|
for (unsigned int i = 0; i < in.length; ++i) {
|
||||||
|
switch (in.data[i]) {
|
||||||
|
case '<':
|
||||||
|
out.Append("<");break;
|
||||||
|
case '>':
|
||||||
|
out.Append(">");break;
|
||||||
|
case '&':
|
||||||
|
out.Append("&");break;
|
||||||
|
case '\"':
|
||||||
|
out.Append(""");break;
|
||||||
|
case '\'':
|
||||||
|
out.Append("'");break;
|
||||||
|
default:
|
||||||
|
out.data[out.length++] = in.data[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
out.data[out.length] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------------
|
||||||
|
// Write a single node as text dump
|
||||||
|
static void WriteNode(const aiNode* node, IOStream * io, unsigned int depth) {
|
||||||
|
char prefix[512];
|
||||||
|
for (unsigned int i = 0; i < depth;++i)
|
||||||
|
prefix[i] = '\t';
|
||||||
|
prefix[depth] = '\0';
|
||||||
|
|
||||||
|
const aiMatrix4x4& m = node->mTransformation;
|
||||||
|
|
||||||
|
aiString name;
|
||||||
|
ConvertName(name,node->mName);
|
||||||
|
ioprintf(io,"%s<Node name=\"%s\"> \n"
|
||||||
|
"%s\t<Matrix4> \n"
|
||||||
|
"%s\t\t%0 6f %0 6f %0 6f %0 6f\n"
|
||||||
|
"%s\t\t%0 6f %0 6f %0 6f %0 6f\n"
|
||||||
|
"%s\t\t%0 6f %0 6f %0 6f %0 6f\n"
|
||||||
|
"%s\t\t%0 6f %0 6f %0 6f %0 6f\n"
|
||||||
|
"%s\t</Matrix4> \n",
|
||||||
|
prefix,name.data,prefix,
|
||||||
|
prefix,m.a1,m.a2,m.a3,m.a4,
|
||||||
|
prefix,m.b1,m.b2,m.b3,m.b4,
|
||||||
|
prefix,m.c1,m.c2,m.c3,m.c4,
|
||||||
|
prefix,m.d1,m.d2,m.d3,m.d4,prefix);
|
||||||
|
|
||||||
|
if (node->mNumMeshes) {
|
||||||
|
ioprintf(io, "%s\t<MeshRefs num=\"%u\">\n%s\t",
|
||||||
|
prefix,node->mNumMeshes,prefix);
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < node->mNumMeshes;++i) {
|
||||||
|
ioprintf(io,"%u ",node->mMeshes[i]);
|
||||||
|
}
|
||||||
|
ioprintf(io,"\n%s\t</MeshRefs>\n",prefix);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (node->mNumChildren) {
|
||||||
|
ioprintf(io,"%s\t<NodeList num=\"%u\">\n",
|
||||||
|
prefix,node->mNumChildren);
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < node->mNumChildren;++i) {
|
||||||
|
WriteNode(node->mChildren[i],io,depth+2);
|
||||||
|
}
|
||||||
|
ioprintf(io,"%s\t</NodeList>\n",prefix);
|
||||||
|
}
|
||||||
|
ioprintf(io,"%s</Node>\n",prefix);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------------
|
||||||
|
// Some chuncks of text will need to be encoded for XML
|
||||||
|
// http://stackoverflow.com/questions/5665231/most-efficient-way-to-escape-xml-html-in-c-string#5665377
|
||||||
|
static std::string encodeXML(const std::string& data) {
|
||||||
|
std::string buffer;
|
||||||
|
buffer.reserve(data.size());
|
||||||
|
for(size_t pos = 0; pos != data.size(); ++pos) {
|
||||||
|
switch(data[pos]) {
|
||||||
|
case '&': buffer.append("&"); break;
|
||||||
|
case '\"': buffer.append("""); break;
|
||||||
|
case '\'': buffer.append("'"); break;
|
||||||
|
case '<': buffer.append("<"); break;
|
||||||
|
case '>': buffer.append(">"); break;
|
||||||
|
default: buffer.append(&data[pos], 1); break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------------
|
||||||
|
// Write a text model dump
|
||||||
|
static
|
||||||
|
void WriteDump(const char* pFile, const char* cmd, const aiScene* scene, IOStream* io, bool shortened) {
|
||||||
|
time_t tt = ::time( NULL );
|
||||||
|
#if _WIN32
|
||||||
|
tm* p = gmtime(&tt);
|
||||||
|
#else
|
||||||
|
struct tm now;
|
||||||
|
tm* p = gmtime_r(&tt, &now);
|
||||||
|
#endif
|
||||||
|
ai_assert(nullptr != p);
|
||||||
|
|
||||||
|
std::string c = cmd;
|
||||||
|
std::string::size_type s;
|
||||||
|
|
||||||
|
// https://sourceforge.net/tracker/?func=detail&aid=3167364&group_id=226462&atid=1067632
|
||||||
|
// -- not allowed in XML comments
|
||||||
|
while((s = c.find("--")) != std::string::npos) {
|
||||||
|
c[s] = '?';
|
||||||
|
}
|
||||||
|
|
||||||
|
// write header
|
||||||
|
std::string header(
|
||||||
|
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
|
||||||
|
"<ASSIMP format_id=\"1\">\n\n"
|
||||||
|
"<!-- XML Model dump produced by assimp dump\n"
|
||||||
|
" Library version: %u.%u.%u\n"
|
||||||
|
" Source: %s\n"
|
||||||
|
" Command line: %s\n"
|
||||||
|
" %s\n"
|
||||||
|
"-->"
|
||||||
|
" \n\n"
|
||||||
|
"<Scene flags=\"%u\" postprocessing=\"%u\">\n"
|
||||||
|
);
|
||||||
|
|
||||||
|
const unsigned int majorVersion( aiGetVersionMajor() );
|
||||||
|
const unsigned int minorVersion( aiGetVersionMinor() );
|
||||||
|
const unsigned int rev( aiGetVersionRevision() );
|
||||||
|
const char *curtime( asctime( p ) );
|
||||||
|
ioprintf( io, header.c_str(), majorVersion, minorVersion, rev, pFile, c.c_str(), curtime, scene->mFlags, 0u );
|
||||||
|
|
||||||
|
// write the node graph
|
||||||
|
WriteNode(scene->mRootNode, io, 0);
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
// write cameras
|
||||||
|
for (unsigned int i = 0; i < scene->mNumCameras;++i) {
|
||||||
|
aiCamera* cam = scene->mCameras[i];
|
||||||
|
ConvertName(name,cam->mName);
|
||||||
|
|
||||||
|
// camera header
|
||||||
|
ioprintf(io,"\t<Camera parent=\"%s\">\n"
|
||||||
|
"\t\t<Vector3 name=\"up\" > %0 8f %0 8f %0 8f </Vector3>\n"
|
||||||
|
"\t\t<Vector3 name=\"lookat\" > %0 8f %0 8f %0 8f </Vector3>\n"
|
||||||
|
"\t\t<Vector3 name=\"pos\" > %0 8f %0 8f %0 8f </Vector3>\n"
|
||||||
|
"\t\t<Float name=\"fov\" > %f </Float>\n"
|
||||||
|
"\t\t<Float name=\"aspect\" > %f </Float>\n"
|
||||||
|
"\t\t<Float name=\"near_clip\" > %f </Float>\n"
|
||||||
|
"\t\t<Float name=\"far_clip\" > %f </Float>\n"
|
||||||
|
"\t</Camera>\n",
|
||||||
|
name.data,
|
||||||
|
cam->mUp.x,cam->mUp.y,cam->mUp.z,
|
||||||
|
cam->mLookAt.x,cam->mLookAt.y,cam->mLookAt.z,
|
||||||
|
cam->mPosition.x,cam->mPosition.y,cam->mPosition.z,
|
||||||
|
cam->mHorizontalFOV,cam->mAspect,cam->mClipPlaneNear,cam->mClipPlaneFar,i);
|
||||||
|
}
|
||||||
|
|
||||||
|
// write lights
|
||||||
|
for (unsigned int i = 0; i < scene->mNumLights;++i) {
|
||||||
|
aiLight* l = scene->mLights[i];
|
||||||
|
ConvertName(name,l->mName);
|
||||||
|
|
||||||
|
// light header
|
||||||
|
ioprintf(io,"\t<Light parent=\"%s\"> type=\"%s\"\n"
|
||||||
|
"\t\t<Vector3 name=\"diffuse\" > %0 8f %0 8f %0 8f </Vector3>\n"
|
||||||
|
"\t\t<Vector3 name=\"specular\" > %0 8f %0 8f %0 8f </Vector3>\n"
|
||||||
|
"\t\t<Vector3 name=\"ambient\" > %0 8f %0 8f %0 8f </Vector3>\n",
|
||||||
|
name.data,
|
||||||
|
(l->mType == aiLightSource_DIRECTIONAL ? "directional" :
|
||||||
|
(l->mType == aiLightSource_POINT ? "point" : "spot" )),
|
||||||
|
l->mColorDiffuse.r, l->mColorDiffuse.g, l->mColorDiffuse.b,
|
||||||
|
l->mColorSpecular.r,l->mColorSpecular.g,l->mColorSpecular.b,
|
||||||
|
l->mColorAmbient.r, l->mColorAmbient.g, l->mColorAmbient.b);
|
||||||
|
|
||||||
|
if (l->mType != aiLightSource_DIRECTIONAL) {
|
||||||
|
ioprintf(io,
|
||||||
|
"\t\t<Vector3 name=\"pos\" > %0 8f %0 8f %0 8f </Vector3>\n"
|
||||||
|
"\t\t<Float name=\"atten_cst\" > %f </Float>\n"
|
||||||
|
"\t\t<Float name=\"atten_lin\" > %f </Float>\n"
|
||||||
|
"\t\t<Float name=\"atten_sqr\" > %f </Float>\n",
|
||||||
|
l->mPosition.x,l->mPosition.y,l->mPosition.z,
|
||||||
|
l->mAttenuationConstant,l->mAttenuationLinear,l->mAttenuationQuadratic);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (l->mType != aiLightSource_POINT) {
|
||||||
|
ioprintf(io,
|
||||||
|
"\t\t<Vector3 name=\"lookat\" > %0 8f %0 8f %0 8f </Vector3>\n",
|
||||||
|
l->mDirection.x,l->mDirection.y,l->mDirection.z);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (l->mType == aiLightSource_SPOT) {
|
||||||
|
ioprintf(io,
|
||||||
|
"\t\t<Float name=\"cone_out\" > %f </Float>\n"
|
||||||
|
"\t\t<Float name=\"cone_inn\" > %f </Float>\n",
|
||||||
|
l->mAngleOuterCone,l->mAngleInnerCone);
|
||||||
|
}
|
||||||
|
ioprintf(io,"\t</Light>\n");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
aiString name;
|
||||||
|
|
||||||
|
// write textures
|
||||||
|
if (scene->mNumTextures) {
|
||||||
|
ioprintf(io,"<TextureList num=\"%u\">\n",scene->mNumTextures);
|
||||||
|
for (unsigned int i = 0; i < scene->mNumTextures;++i) {
|
||||||
|
aiTexture* tex = scene->mTextures[i];
|
||||||
|
bool compressed = (tex->mHeight == 0);
|
||||||
|
|
||||||
|
// mesh header
|
||||||
|
ioprintf(io,"\t<Texture width=\"%u\" height=\"%u\" compressed=\"%s\"> \n",
|
||||||
|
(compressed ? -1 : tex->mWidth),(compressed ? -1 : tex->mHeight),
|
||||||
|
(compressed ? "true" : "false"));
|
||||||
|
|
||||||
|
if (compressed) {
|
||||||
|
ioprintf(io,"\t\t<Data length=\"%u\"> \n",tex->mWidth);
|
||||||
|
|
||||||
|
if (!shortened) {
|
||||||
|
for (unsigned int n = 0; n < tex->mWidth;++n) {
|
||||||
|
ioprintf(io,"\t\t\t%2x",reinterpret_cast<uint8_t*>(tex->pcData)[n]);
|
||||||
|
if (n && !(n % 50)) {
|
||||||
|
ioprintf(io,"\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (!shortened){
|
||||||
|
ioprintf(io,"\t\t<Data length=\"%u\"> \n",tex->mWidth*tex->mHeight*4);
|
||||||
|
|
||||||
|
// const unsigned int width = (unsigned int)std::log10((double)std::max(tex->mHeight,tex->mWidth))+1;
|
||||||
|
for (unsigned int y = 0; y < tex->mHeight;++y) {
|
||||||
|
for (unsigned int x = 0; x < tex->mWidth;++x) {
|
||||||
|
aiTexel* tx = tex->pcData + y*tex->mWidth+x;
|
||||||
|
unsigned int r = tx->r,g=tx->g,b=tx->b,a=tx->a;
|
||||||
|
ioprintf(io,"\t\t\t%2x %2x %2x %2x",r,g,b,a);
|
||||||
|
|
||||||
|
// group by four for readability
|
||||||
|
if ( 0 == ( x + y*tex->mWidth ) % 4 ) {
|
||||||
|
ioprintf( io, "\n" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ioprintf(io,"\t\t</Data>\n\t</Texture>\n");
|
||||||
|
}
|
||||||
|
ioprintf(io,"</TextureList>\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
// write materials
|
||||||
|
if (scene->mNumMaterials) {
|
||||||
|
ioprintf(io,"<MaterialList num=\"%u\">\n",scene->mNumMaterials);
|
||||||
|
for (unsigned int i = 0; i< scene->mNumMaterials; ++i) {
|
||||||
|
const aiMaterial* mat = scene->mMaterials[i];
|
||||||
|
|
||||||
|
ioprintf(io,"\t<Material>\n");
|
||||||
|
ioprintf(io,"\t\t<MatPropertyList num=\"%u\">\n",mat->mNumProperties);
|
||||||
|
for (unsigned int n = 0; n < mat->mNumProperties;++n) {
|
||||||
|
|
||||||
|
const aiMaterialProperty* prop = mat->mProperties[n];
|
||||||
|
const char* sz = "";
|
||||||
|
if (prop->mType == aiPTI_Float) {
|
||||||
|
sz = "float";
|
||||||
|
}
|
||||||
|
else if (prop->mType == aiPTI_Integer) {
|
||||||
|
sz = "integer";
|
||||||
|
}
|
||||||
|
else if (prop->mType == aiPTI_String) {
|
||||||
|
sz = "string";
|
||||||
|
}
|
||||||
|
else if (prop->mType == aiPTI_Buffer) {
|
||||||
|
sz = "binary_buffer";
|
||||||
|
}
|
||||||
|
|
||||||
|
ioprintf(io,"\t\t\t<MatProperty key=\"%s\" \n\t\t\ttype=\"%s\" tex_usage=\"%s\" tex_index=\"%u\"",
|
||||||
|
prop->mKey.data, sz,
|
||||||
|
::TextureTypeToString((aiTextureType)prop->mSemantic),prop->mIndex);
|
||||||
|
|
||||||
|
if (prop->mType == aiPTI_Float) {
|
||||||
|
ioprintf(io," size=\"%i\">\n\t\t\t\t",
|
||||||
|
static_cast<int>(prop->mDataLength/sizeof(float)));
|
||||||
|
|
||||||
|
for (unsigned int p = 0; p < prop->mDataLength/sizeof(float);++p) {
|
||||||
|
ioprintf(io,"%f ",*((float*)(prop->mData+p*sizeof(float))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (prop->mType == aiPTI_Integer) {
|
||||||
|
ioprintf(io," size=\"%i\">\n\t\t\t\t",
|
||||||
|
static_cast<int>(prop->mDataLength/sizeof(int)));
|
||||||
|
|
||||||
|
for (unsigned int p = 0; p < prop->mDataLength/sizeof(int);++p) {
|
||||||
|
ioprintf(io,"%i ",*((int*)(prop->mData+p*sizeof(int))));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (prop->mType == aiPTI_Buffer) {
|
||||||
|
ioprintf(io," size=\"%i\">\n\t\t\t\t",
|
||||||
|
static_cast<int>(prop->mDataLength));
|
||||||
|
|
||||||
|
for (unsigned int p = 0; p < prop->mDataLength;++p) {
|
||||||
|
ioprintf(io,"%2x ",prop->mData[p]);
|
||||||
|
if (p && 0 == p%30) {
|
||||||
|
ioprintf(io,"\n\t\t\t\t");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (prop->mType == aiPTI_String) {
|
||||||
|
ioprintf(io,">\n\t\t\t\t\"%s\"",encodeXML(prop->mData+4).c_str() /* skip length */);
|
||||||
|
}
|
||||||
|
ioprintf(io,"\n\t\t\t</MatProperty>\n");
|
||||||
|
}
|
||||||
|
ioprintf(io,"\t\t</MatPropertyList>\n");
|
||||||
|
ioprintf(io,"\t</Material>\n");
|
||||||
|
}
|
||||||
|
ioprintf(io,"</MaterialList>\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
// write animations
|
||||||
|
if (scene->mNumAnimations) {
|
||||||
|
ioprintf(io,"<AnimationList num=\"%u\">\n",scene->mNumAnimations);
|
||||||
|
for (unsigned int i = 0; i < scene->mNumAnimations;++i) {
|
||||||
|
aiAnimation* anim = scene->mAnimations[i];
|
||||||
|
|
||||||
|
// anim header
|
||||||
|
ConvertName(name,anim->mName);
|
||||||
|
ioprintf(io,"\t<Animation name=\"%s\" duration=\"%e\" tick_cnt=\"%e\">\n",
|
||||||
|
name.data, anim->mDuration, anim->mTicksPerSecond);
|
||||||
|
|
||||||
|
// write bone animation channels
|
||||||
|
if (anim->mNumChannels) {
|
||||||
|
ioprintf(io,"\t\t<NodeAnimList num=\"%u\">\n",anim->mNumChannels);
|
||||||
|
for (unsigned int n = 0; n < anim->mNumChannels;++n) {
|
||||||
|
aiNodeAnim* nd = anim->mChannels[n];
|
||||||
|
|
||||||
|
// node anim header
|
||||||
|
ConvertName(name,nd->mNodeName);
|
||||||
|
ioprintf(io,"\t\t\t<NodeAnim node=\"%s\">\n",name.data);
|
||||||
|
|
||||||
|
if (!shortened) {
|
||||||
|
// write position keys
|
||||||
|
if (nd->mNumPositionKeys) {
|
||||||
|
ioprintf(io,"\t\t\t\t<PositionKeyList num=\"%u\">\n",nd->mNumPositionKeys);
|
||||||
|
for (unsigned int a = 0; a < nd->mNumPositionKeys;++a) {
|
||||||
|
aiVectorKey* vc = nd->mPositionKeys+a;
|
||||||
|
ioprintf(io,"\t\t\t\t\t<PositionKey time=\"%e\">\n"
|
||||||
|
"\t\t\t\t\t\t%0 8f %0 8f %0 8f\n\t\t\t\t\t</PositionKey>\n",
|
||||||
|
vc->mTime,vc->mValue.x,vc->mValue.y,vc->mValue.z);
|
||||||
|
}
|
||||||
|
ioprintf(io,"\t\t\t\t</PositionKeyList>\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
// write scaling keys
|
||||||
|
if (nd->mNumScalingKeys) {
|
||||||
|
ioprintf(io,"\t\t\t\t<ScalingKeyList num=\"%u\">\n",nd->mNumScalingKeys);
|
||||||
|
for (unsigned int a = 0; a < nd->mNumScalingKeys;++a) {
|
||||||
|
aiVectorKey* vc = nd->mScalingKeys+a;
|
||||||
|
ioprintf(io,"\t\t\t\t\t<ScalingKey time=\"%e\">\n"
|
||||||
|
"\t\t\t\t\t\t%0 8f %0 8f %0 8f\n\t\t\t\t\t</ScalingKey>\n",
|
||||||
|
vc->mTime,vc->mValue.x,vc->mValue.y,vc->mValue.z);
|
||||||
|
}
|
||||||
|
ioprintf(io,"\t\t\t\t</ScalingKeyList>\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
// write rotation keys
|
||||||
|
if (nd->mNumRotationKeys) {
|
||||||
|
ioprintf(io,"\t\t\t\t<RotationKeyList num=\"%u\">\n",nd->mNumRotationKeys);
|
||||||
|
for (unsigned int a = 0; a < nd->mNumRotationKeys;++a) {
|
||||||
|
aiQuatKey* vc = nd->mRotationKeys+a;
|
||||||
|
ioprintf(io,"\t\t\t\t\t<RotationKey time=\"%e\">\n"
|
||||||
|
"\t\t\t\t\t\t%0 8f %0 8f %0 8f %0 8f\n\t\t\t\t\t</RotationKey>\n",
|
||||||
|
vc->mTime,vc->mValue.x,vc->mValue.y,vc->mValue.z,vc->mValue.w);
|
||||||
|
}
|
||||||
|
ioprintf(io,"\t\t\t\t</RotationKeyList>\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ioprintf(io,"\t\t\t</NodeAnim>\n");
|
||||||
|
}
|
||||||
|
ioprintf(io,"\t\t</NodeAnimList>\n");
|
||||||
|
}
|
||||||
|
ioprintf(io,"\t</Animation>\n");
|
||||||
|
}
|
||||||
|
ioprintf(io,"</AnimationList>\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
// write meshes
|
||||||
|
if (scene->mNumMeshes) {
|
||||||
|
ioprintf(io,"<MeshList num=\"%u\">\n",scene->mNumMeshes);
|
||||||
|
for (unsigned int i = 0; i < scene->mNumMeshes;++i) {
|
||||||
|
aiMesh* mesh = scene->mMeshes[i];
|
||||||
|
// const unsigned int width = (unsigned int)std::log10((double)mesh->mNumVertices)+1;
|
||||||
|
|
||||||
|
// mesh header
|
||||||
|
ioprintf(io,"\t<Mesh types=\"%s %s %s %s\" material_index=\"%u\">\n",
|
||||||
|
(mesh->mPrimitiveTypes & aiPrimitiveType_POINT ? "points" : ""),
|
||||||
|
(mesh->mPrimitiveTypes & aiPrimitiveType_LINE ? "lines" : ""),
|
||||||
|
(mesh->mPrimitiveTypes & aiPrimitiveType_TRIANGLE ? "triangles" : ""),
|
||||||
|
(mesh->mPrimitiveTypes & aiPrimitiveType_POLYGON ? "polygons" : ""),
|
||||||
|
mesh->mMaterialIndex);
|
||||||
|
|
||||||
|
// bones
|
||||||
|
if (mesh->mNumBones) {
|
||||||
|
ioprintf(io,"\t\t<BoneList num=\"%u\">\n",mesh->mNumBones);
|
||||||
|
|
||||||
|
for (unsigned int n = 0; n < mesh->mNumBones;++n) {
|
||||||
|
aiBone* bone = mesh->mBones[n];
|
||||||
|
|
||||||
|
ConvertName(name,bone->mName);
|
||||||
|
// bone header
|
||||||
|
ioprintf(io,"\t\t\t<Bone name=\"%s\">\n"
|
||||||
|
"\t\t\t\t<Matrix4> \n"
|
||||||
|
"\t\t\t\t\t%0 6f %0 6f %0 6f %0 6f\n"
|
||||||
|
"\t\t\t\t\t%0 6f %0 6f %0 6f %0 6f\n"
|
||||||
|
"\t\t\t\t\t%0 6f %0 6f %0 6f %0 6f\n"
|
||||||
|
"\t\t\t\t\t%0 6f %0 6f %0 6f %0 6f\n"
|
||||||
|
"\t\t\t\t</Matrix4> \n",
|
||||||
|
name.data,
|
||||||
|
bone->mOffsetMatrix.a1,bone->mOffsetMatrix.a2,bone->mOffsetMatrix.a3,bone->mOffsetMatrix.a4,
|
||||||
|
bone->mOffsetMatrix.b1,bone->mOffsetMatrix.b2,bone->mOffsetMatrix.b3,bone->mOffsetMatrix.b4,
|
||||||
|
bone->mOffsetMatrix.c1,bone->mOffsetMatrix.c2,bone->mOffsetMatrix.c3,bone->mOffsetMatrix.c4,
|
||||||
|
bone->mOffsetMatrix.d1,bone->mOffsetMatrix.d2,bone->mOffsetMatrix.d3,bone->mOffsetMatrix.d4);
|
||||||
|
|
||||||
|
if (!shortened && bone->mNumWeights) {
|
||||||
|
ioprintf(io,"\t\t\t\t<WeightList num=\"%u\">\n",bone->mNumWeights);
|
||||||
|
|
||||||
|
// bone weights
|
||||||
|
for (unsigned int a = 0; a < bone->mNumWeights;++a) {
|
||||||
|
aiVertexWeight* wght = bone->mWeights+a;
|
||||||
|
|
||||||
|
ioprintf(io,"\t\t\t\t\t<Weight index=\"%u\">\n\t\t\t\t\t\t%f\n\t\t\t\t\t</Weight>\n",
|
||||||
|
wght->mVertexId,wght->mWeight);
|
||||||
|
}
|
||||||
|
ioprintf(io,"\t\t\t\t</WeightList>\n");
|
||||||
|
}
|
||||||
|
ioprintf(io,"\t\t\t</Bone>\n");
|
||||||
|
}
|
||||||
|
ioprintf(io,"\t\t</BoneList>\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
// faces
|
||||||
|
if (!shortened && mesh->mNumFaces) {
|
||||||
|
ioprintf(io,"\t\t<FaceList num=\"%u\">\n",mesh->mNumFaces);
|
||||||
|
for (unsigned int n = 0; n < mesh->mNumFaces; ++n) {
|
||||||
|
aiFace& f = mesh->mFaces[n];
|
||||||
|
ioprintf(io,"\t\t\t<Face num=\"%u\">\n"
|
||||||
|
"\t\t\t\t",f.mNumIndices);
|
||||||
|
|
||||||
|
for (unsigned int j = 0; j < f.mNumIndices;++j)
|
||||||
|
ioprintf(io,"%u ",f.mIndices[j]);
|
||||||
|
|
||||||
|
ioprintf(io,"\n\t\t\t</Face>\n");
|
||||||
|
}
|
||||||
|
ioprintf(io,"\t\t</FaceList>\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
// vertex positions
|
||||||
|
if (mesh->HasPositions()) {
|
||||||
|
ioprintf(io,"\t\t<Positions num=\"%u\" set=\"0\" num_components=\"3\"> \n",mesh->mNumVertices);
|
||||||
|
if (!shortened) {
|
||||||
|
for (unsigned int n = 0; n < mesh->mNumVertices; ++n) {
|
||||||
|
ioprintf(io,"\t\t%0 8f %0 8f %0 8f\n",
|
||||||
|
mesh->mVertices[n].x,
|
||||||
|
mesh->mVertices[n].y,
|
||||||
|
mesh->mVertices[n].z);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ioprintf(io,"\t\t</Positions>\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
// vertex normals
|
||||||
|
if (mesh->HasNormals()) {
|
||||||
|
ioprintf(io,"\t\t<Normals num=\"%u\" set=\"0\" num_components=\"3\"> \n",mesh->mNumVertices);
|
||||||
|
if (!shortened) {
|
||||||
|
for (unsigned int n = 0; n < mesh->mNumVertices; ++n) {
|
||||||
|
ioprintf(io,"\t\t%0 8f %0 8f %0 8f\n",
|
||||||
|
mesh->mNormals[n].x,
|
||||||
|
mesh->mNormals[n].y,
|
||||||
|
mesh->mNormals[n].z);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ioprintf(io,"\t\t</Normals>\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
// vertex tangents and bitangents
|
||||||
|
if (mesh->HasTangentsAndBitangents()) {
|
||||||
|
ioprintf(io,"\t\t<Tangents num=\"%u\" set=\"0\" num_components=\"3\"> \n",mesh->mNumVertices);
|
||||||
|
if (!shortened) {
|
||||||
|
for (unsigned int n = 0; n < mesh->mNumVertices; ++n) {
|
||||||
|
ioprintf(io,"\t\t%0 8f %0 8f %0 8f\n",
|
||||||
|
mesh->mTangents[n].x,
|
||||||
|
mesh->mTangents[n].y,
|
||||||
|
mesh->mTangents[n].z);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ioprintf(io,"\t\t</Tangents>\n");
|
||||||
|
|
||||||
|
ioprintf(io,"\t\t<Bitangents num=\"%u\" set=\"0\" num_components=\"3\"> \n",mesh->mNumVertices);
|
||||||
|
if (!shortened) {
|
||||||
|
for (unsigned int n = 0; n < mesh->mNumVertices; ++n) {
|
||||||
|
ioprintf(io,"\t\t%0 8f %0 8f %0 8f\n",
|
||||||
|
mesh->mBitangents[n].x,
|
||||||
|
mesh->mBitangents[n].y,
|
||||||
|
mesh->mBitangents[n].z);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ioprintf(io,"\t\t</Bitangents>\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
// texture coordinates
|
||||||
|
for (unsigned int a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++a) {
|
||||||
|
if (!mesh->mTextureCoords[a])
|
||||||
|
break;
|
||||||
|
|
||||||
|
ioprintf(io,"\t\t<TextureCoords num=\"%u\" set=\"%u\" num_components=\"%u\"> \n",mesh->mNumVertices,
|
||||||
|
a,mesh->mNumUVComponents[a]);
|
||||||
|
|
||||||
|
if (!shortened) {
|
||||||
|
if (mesh->mNumUVComponents[a] == 3) {
|
||||||
|
for (unsigned int n = 0; n < mesh->mNumVertices; ++n) {
|
||||||
|
ioprintf(io,"\t\t%0 8f %0 8f %0 8f\n",
|
||||||
|
mesh->mTextureCoords[a][n].x,
|
||||||
|
mesh->mTextureCoords[a][n].y,
|
||||||
|
mesh->mTextureCoords[a][n].z);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
for (unsigned int n = 0; n < mesh->mNumVertices; ++n) {
|
||||||
|
ioprintf(io,"\t\t%0 8f %0 8f\n",
|
||||||
|
mesh->mTextureCoords[a][n].x,
|
||||||
|
mesh->mTextureCoords[a][n].y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ioprintf(io,"\t\t</TextureCoords>\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
// vertex colors
|
||||||
|
for (unsigned int a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS; ++a) {
|
||||||
|
if (!mesh->mColors[a])
|
||||||
|
break;
|
||||||
|
ioprintf(io,"\t\t<Colors num=\"%u\" set=\"%u\" num_components=\"4\"> \n",mesh->mNumVertices,a);
|
||||||
|
if (!shortened) {
|
||||||
|
for (unsigned int n = 0; n < mesh->mNumVertices; ++n) {
|
||||||
|
ioprintf(io,"\t\t%0 8f %0 8f %0 8f %0 8f\n",
|
||||||
|
mesh->mColors[a][n].r,
|
||||||
|
mesh->mColors[a][n].g,
|
||||||
|
mesh->mColors[a][n].b,
|
||||||
|
mesh->mColors[a][n].a);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ioprintf(io,"\t\t</Colors>\n");
|
||||||
|
}
|
||||||
|
ioprintf(io,"\t</Mesh>\n");
|
||||||
|
}
|
||||||
|
ioprintf(io,"</MeshList>\n");
|
||||||
|
}
|
||||||
|
ioprintf(io,"</Scene>\n</ASSIMP>");
|
||||||
|
}
|
||||||
|
|
||||||
|
} // end of namespace AssxmlFileWriter
|
||||||
|
|
||||||
|
void DumpSceneToAssxml(
|
||||||
|
const char* pFile, const char* cmd, IOSystem* pIOSystem,
|
||||||
|
const aiScene* pScene, bool shortened) {
|
||||||
|
std::unique_ptr<IOStream> file(pIOSystem->Open(pFile, "wt"));
|
||||||
|
if (!file.get()) {
|
||||||
|
throw std::runtime_error("Unable to open output file " + std::string(pFile) + '\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
AssxmlFileWriter::WriteDump(pFile, cmd, pScene, file.get(), shortened);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // end of namespace Assimp
|
|
@ -0,0 +1,65 @@
|
||||||
|
/*
|
||||||
|
Open Asset Import Library (assimp)
|
||||||
|
----------------------------------------------------------------------
|
||||||
|
|
||||||
|
Copyright (c) 2006-2020, 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.
|
||||||
|
|
||||||
|
----------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @file AssxmlFileWriter.h
|
||||||
|
* @brief Declaration of Assxml file writer.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef AI_ASSXMLFILEWRITER_H_INC
|
||||||
|
#define AI_ASSXMLFILEWRITER_H_INC
|
||||||
|
|
||||||
|
#include <assimp/defs.h>
|
||||||
|
#include <assimp/scene.h>
|
||||||
|
#include <assimp/IOSystem.hpp>
|
||||||
|
|
||||||
|
namespace Assimp {
|
||||||
|
|
||||||
|
void ASSIMP_API DumpSceneToAssxml(
|
||||||
|
const char* pFile,
|
||||||
|
const char* cmd,
|
||||||
|
IOSystem* pIOSystem,
|
||||||
|
const aiScene* pScene,
|
||||||
|
bool shortened);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // AI_ASSXMLFILEWRITER_H_INC
|
|
@ -338,6 +338,8 @@ ADD_ASSIMP_EXPORTER( ASSBIN
|
||||||
ADD_ASSIMP_EXPORTER( ASSXML
|
ADD_ASSIMP_EXPORTER( ASSXML
|
||||||
Assxml/AssxmlExporter.h
|
Assxml/AssxmlExporter.h
|
||||||
Assxml/AssxmlExporter.cpp
|
Assxml/AssxmlExporter.cpp
|
||||||
|
Assxml/AssxmlFileWriter.h
|
||||||
|
Assxml/AssxmlFileWriter.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
ADD_ASSIMP_IMPORTER( B3D
|
ADD_ASSIMP_IMPORTER( B3D
|
||||||
|
|
|
@ -250,7 +250,7 @@ aiNode* COBImporter::BuildNodes(const Node& root,const Scene& scin,aiScene* fill
|
||||||
const Mesh& ndmesh = (const Mesh&)(root);
|
const Mesh& ndmesh = (const Mesh&)(root);
|
||||||
if (ndmesh.vertex_positions.size() && ndmesh.texture_coords.size()) {
|
if (ndmesh.vertex_positions.size() && ndmesh.texture_coords.size()) {
|
||||||
|
|
||||||
typedef std::pair<unsigned int,Mesh::FaceRefList> Entry;
|
typedef std::pair<const unsigned int,Mesh::FaceRefList> Entry;
|
||||||
for(const Entry& reflist : ndmesh.temp_map) {
|
for(const Entry& reflist : ndmesh.temp_map) {
|
||||||
{ // create mesh
|
{ // create mesh
|
||||||
size_t n = 0;
|
size_t n = 0;
|
||||||
|
|
|
@ -1312,7 +1312,6 @@ void SceneCombiner::Copy(aiMetadata** _dest, const aiMetadata* src) {
|
||||||
aiMetadata* dest = *_dest = aiMetadata::Alloc( src->mNumProperties );
|
aiMetadata* dest = *_dest = aiMetadata::Alloc( src->mNumProperties );
|
||||||
std::copy(src->mKeys, src->mKeys + src->mNumProperties, dest->mKeys);
|
std::copy(src->mKeys, src->mKeys + src->mNumProperties, dest->mKeys);
|
||||||
|
|
||||||
dest->mValues = new aiMetadataEntry[src->mNumProperties];
|
|
||||||
for (unsigned int i = 0; i < src->mNumProperties; ++i) {
|
for (unsigned int i = 0; i < src->mNumProperties; ++i) {
|
||||||
aiMetadataEntry& in = src->mValues[i];
|
aiMetadataEntry& in = src->mValues[i];
|
||||||
aiMetadataEntry& out = dest->mValues[i];
|
aiMetadataEntry& out = dest->mValues[i];
|
||||||
|
|
|
@ -37,7 +37,7 @@ The ASSBIN file format is composed of chunks to represent the hierarchical aiSce
|
||||||
This makes the format extensible and allows backward-compatibility with future data structure
|
This makes the format extensible and allows backward-compatibility with future data structure
|
||||||
versions. The <tt><root>/code/assbin_chunks.h</tt> header contains some magic constants
|
versions. The <tt><root>/code/assbin_chunks.h</tt> header contains some magic constants
|
||||||
for use by stand-alone ASSBIN loaders. Also, Assimp's own file writer can be found
|
for use by stand-alone ASSBIN loaders. Also, Assimp's own file writer can be found
|
||||||
in <tt><root>/tools/assimp_cmd/WriteDumb.cpp</tt> (yes, the 'b' is no typo ...).
|
in <tt><root>/tools/assimp_cmd/WriteDump.cpp</tt> (yes, the 'b' is no typo ...).
|
||||||
|
|
||||||
@verbatim
|
@verbatim
|
||||||
|
|
||||||
|
|
|
@ -448,6 +448,12 @@ void ResolveVertexDataArray(std::vector<T>& data_out, const Scope& source,
|
||||||
std::vector<T> tempData;
|
std::vector<T> tempData;
|
||||||
ParseVectorDataArray(tempData, GetRequiredElement(source, dataElementName));
|
ParseVectorDataArray(tempData, GetRequiredElement(source, dataElementName));
|
||||||
|
|
||||||
|
if (tempData.size() != vertex_count) {
|
||||||
|
FBXImporter::LogError(Formatter::format("length of input data unexpected for ByVertice mapping: ")
|
||||||
|
<< tempData.size() << ", expected " << vertex_count);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
data_out.resize(vertex_count);
|
data_out.resize(vertex_count);
|
||||||
for (size_t i = 0, e = tempData.size(); i < e; ++i) {
|
for (size_t i = 0, e = tempData.size(); i < e; ++i) {
|
||||||
|
|
||||||
|
@ -461,10 +467,17 @@ void ResolveVertexDataArray(std::vector<T>& data_out, const Scope& source,
|
||||||
std::vector<T> tempData;
|
std::vector<T> tempData;
|
||||||
ParseVectorDataArray(tempData, GetRequiredElement(source, dataElementName));
|
ParseVectorDataArray(tempData, GetRequiredElement(source, dataElementName));
|
||||||
|
|
||||||
data_out.resize(vertex_count);
|
|
||||||
|
|
||||||
std::vector<int> uvIndices;
|
std::vector<int> uvIndices;
|
||||||
ParseVectorDataArray(uvIndices,GetRequiredElement(source,indexDataElementName));
|
ParseVectorDataArray(uvIndices,GetRequiredElement(source,indexDataElementName));
|
||||||
|
|
||||||
|
if (uvIndices.size() != vertex_count) {
|
||||||
|
FBXImporter::LogError(Formatter::format("length of input data unexpected for ByVertice mapping: ")
|
||||||
|
<< uvIndices.size() << ", expected " << vertex_count);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
data_out.resize(vertex_count);
|
||||||
|
|
||||||
for (size_t i = 0, e = uvIndices.size(); i < e; ++i) {
|
for (size_t i = 0, e = uvIndices.size(); i < e; ++i) {
|
||||||
|
|
||||||
const unsigned int istart = mapping_offsets[i], iend = istart + mapping_counts[i];
|
const unsigned int istart = mapping_offsets[i], iend = istart + mapping_counts[i];
|
||||||
|
@ -493,16 +506,17 @@ void ResolveVertexDataArray(std::vector<T>& data_out, const Scope& source,
|
||||||
std::vector<T> tempData;
|
std::vector<T> tempData;
|
||||||
ParseVectorDataArray(tempData, GetRequiredElement(source, dataElementName));
|
ParseVectorDataArray(tempData, GetRequiredElement(source, dataElementName));
|
||||||
|
|
||||||
data_out.resize(vertex_count);
|
|
||||||
|
|
||||||
std::vector<int> uvIndices;
|
std::vector<int> uvIndices;
|
||||||
ParseVectorDataArray(uvIndices,GetRequiredElement(source,indexDataElementName));
|
ParseVectorDataArray(uvIndices,GetRequiredElement(source,indexDataElementName));
|
||||||
|
|
||||||
if (uvIndices.size() != vertex_count) {
|
if (uvIndices.size() != vertex_count) {
|
||||||
FBXImporter::LogError("length of input data unexpected for ByPolygonVertex mapping");
|
FBXImporter::LogError(Formatter::format("length of input data unexpected for ByPolygonVertex mapping: ")
|
||||||
|
<< uvIndices.size() << ", expected " << vertex_count);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
data_out.resize(vertex_count);
|
||||||
|
|
||||||
const T empty;
|
const T empty;
|
||||||
unsigned int next = 0;
|
unsigned int next = 0;
|
||||||
for(int i : uvIndices) {
|
for(int i : uvIndices) {
|
||||||
|
|
|
@ -323,7 +323,7 @@ public:
|
||||||
// oh well.
|
// oh well.
|
||||||
bool have_param = false, have_point = false;
|
bool have_param = false, have_point = false;
|
||||||
IfcVector3 point;
|
IfcVector3 point;
|
||||||
for(const Entry sel :entity.Trim1) {
|
for(const Entry& sel :entity.Trim1) {
|
||||||
if (const ::Assimp::STEP::EXPRESS::REAL* const r = sel->ToPtr<::Assimp::STEP::EXPRESS::REAL>()) {
|
if (const ::Assimp::STEP::EXPRESS::REAL* const r = sel->ToPtr<::Assimp::STEP::EXPRESS::REAL>()) {
|
||||||
range.first = *r;
|
range.first = *r;
|
||||||
have_param = true;
|
have_param = true;
|
||||||
|
@ -340,7 +340,7 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
have_param = false, have_point = false;
|
have_param = false, have_point = false;
|
||||||
for(const Entry sel :entity.Trim2) {
|
for(const Entry& sel :entity.Trim2) {
|
||||||
if (const ::Assimp::STEP::EXPRESS::REAL* const r = sel->ToPtr<::Assimp::STEP::EXPRESS::REAL>()) {
|
if (const ::Assimp::STEP::EXPRESS::REAL* const r = sel->ToPtr<::Assimp::STEP::EXPRESS::REAL>()) {
|
||||||
range.second = *r;
|
range.second = *r;
|
||||||
have_param = true;
|
have_param = true;
|
||||||
|
|
|
@ -340,39 +340,13 @@ void HL1MDLLoader::load_sequence_groups_files() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
/** @brief Read an MDL texture.
|
// Read an MDL texture.
|
||||||
*
|
|
||||||
* @note This method is taken from HL1 source code.
|
|
||||||
* source: file: studio_utils.c
|
|
||||||
* function(s): UploadTexture
|
|
||||||
*/
|
|
||||||
void HL1MDLLoader::read_texture(const Texture_HL1 *ptexture,
|
void HL1MDLLoader::read_texture(const Texture_HL1 *ptexture,
|
||||||
uint8_t *data, uint8_t *pal, aiTexture *pResult,
|
uint8_t *data, uint8_t *pal, aiTexture *pResult,
|
||||||
aiColor3D &last_palette_color) {
|
aiColor3D &last_palette_color) {
|
||||||
int outwidth, outheight;
|
|
||||||
int i, j;
|
|
||||||
static const size_t BuffenLen = 256;
|
|
||||||
int row1[BuffenLen], row2[BuffenLen], col1[BuffenLen], col2[BuffenLen];
|
|
||||||
unsigned char *pix1, *pix2, *pix3, *pix4;
|
|
||||||
|
|
||||||
// convert texture to power of 2
|
|
||||||
for (outwidth = 1; outwidth < ptexture->width; outwidth <<= 1)
|
|
||||||
;
|
|
||||||
|
|
||||||
if ( outwidth > static_cast<int>(BuffenLen)) {
|
|
||||||
outwidth = BuffenLen;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (outheight = 1; outheight < ptexture->height; outheight <<= 1)
|
|
||||||
;
|
|
||||||
|
|
||||||
if (static_cast<size_t>(outheight) > BuffenLen) {
|
|
||||||
outheight = BuffenLen;
|
|
||||||
}
|
|
||||||
|
|
||||||
pResult->mFilename = ptexture->name;
|
pResult->mFilename = ptexture->name;
|
||||||
pResult->mWidth = outwidth;
|
pResult->mWidth = static_cast<unsigned int>(ptexture->width);
|
||||||
pResult->mHeight = outheight;
|
pResult->mHeight = static_cast<unsigned int>(ptexture->height);
|
||||||
pResult->achFormatHint[0] = 'r';
|
pResult->achFormatHint[0] = 'r';
|
||||||
pResult->achFormatHint[1] = 'g';
|
pResult->achFormatHint[1] = 'g';
|
||||||
pResult->achFormatHint[2] = 'b';
|
pResult->achFormatHint[2] = 'b';
|
||||||
|
@ -383,31 +357,15 @@ void HL1MDLLoader::read_texture(const Texture_HL1 *ptexture,
|
||||||
pResult->achFormatHint[7] = '8';
|
pResult->achFormatHint[7] = '8';
|
||||||
pResult->achFormatHint[8] = '\0';
|
pResult->achFormatHint[8] = '\0';
|
||||||
|
|
||||||
aiTexel *out = pResult->pcData = new aiTexel[outwidth * outheight];
|
const size_t num_pixels = pResult->mWidth * pResult->mHeight;
|
||||||
|
aiTexel *out = pResult->pcData = new aiTexel[num_pixels];
|
||||||
|
|
||||||
for (i = 0; i < outwidth; i++) {
|
// Convert indexed 8 bit to 32 bit RGBA.
|
||||||
col1[i] = (int)((i + 0.25) * (ptexture->width / (float)outwidth));
|
for (size_t i = 0; i < num_pixels; ++i, ++out) {
|
||||||
col2[i] = (int)((i + 0.75) * (ptexture->width / (float)outwidth));
|
out->r = pal[data[i] * 3];
|
||||||
}
|
out->g = pal[data[i] * 3 + 1];
|
||||||
|
out->b = pal[data[i] * 3 + 2];
|
||||||
for (i = 0; i < outheight; i++) {
|
out->a = 255;
|
||||||
row1[i] = (int)((i + 0.25) * (ptexture->height / (float)outheight)) * ptexture->width;
|
|
||||||
row2[i] = (int)((i + 0.75) * (ptexture->height / (float)outheight)) * ptexture->width;
|
|
||||||
}
|
|
||||||
|
|
||||||
// scale down and convert to 32bit RGB
|
|
||||||
for (i = 0; i < outheight; i++) {
|
|
||||||
for (j = 0; j < outwidth; j++, out++) {
|
|
||||||
pix1 = &pal[data[row1[i] + col1[j]] * 3];
|
|
||||||
pix2 = &pal[data[row1[i] + col2[j]] * 3];
|
|
||||||
pix3 = &pal[data[row2[i] + col1[j]] * 3];
|
|
||||||
pix4 = &pal[data[row2[i] + col2[j]] * 3];
|
|
||||||
|
|
||||||
out->r = (pix1[0] + pix2[0] + pix3[0] + pix4[0]) >> 2;
|
|
||||||
out->g = (pix1[1] + pix2[1] + pix3[1] + pix4[1]) >> 2;
|
|
||||||
out->b = (pix1[2] + pix2[2] + pix3[2] + pix4[2]) >> 2;
|
|
||||||
out->a = 0xFF;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the last palette color.
|
// Get the last palette color.
|
||||||
|
|
|
@ -1421,11 +1421,11 @@ void MDLImporter::InternReadFile_3DGS_MDL7( )
|
||||||
avOutList[i].reserve(3);
|
avOutList[i].reserve(3);
|
||||||
|
|
||||||
// buffer to held the names of all groups in the file
|
// buffer to held the names of all groups in the file
|
||||||
const size_t buffersize( AI_MDL7_MAX_GROUPNAMESIZE*pcHeader->groups_num );
|
const size_t buffersize(AI_MDL7_MAX_GROUPNAMESIZE*pcHeader->groups_num);
|
||||||
char* aszGroupNameBuffer = new char[ buffersize ];
|
char* aszGroupNameBuffer = new char[ buffersize ];
|
||||||
|
|
||||||
// read all groups
|
// read all groups
|
||||||
for (unsigned int iGroup = 0; iGroup < (unsigned int)pcHeader->groups_num;++iGroup) {
|
for (unsigned int iGroup = 0; iGroup < (unsigned int)pcHeader->groups_num; ++iGroup) {
|
||||||
MDL::IntGroupInfo_MDL7 groupInfo((BE_NCONST MDL::Group_MDL7*)szCurrent,iGroup);
|
MDL::IntGroupInfo_MDL7 groupInfo((BE_NCONST MDL::Group_MDL7*)szCurrent,iGroup);
|
||||||
szCurrent = (const unsigned char*)(groupInfo.pcGroup+1);
|
szCurrent = (const unsigned char*)(groupInfo.pcGroup+1);
|
||||||
|
|
||||||
|
|
|
@ -685,7 +685,7 @@ bool XGLImporter::ReadMesh(TempScope& scope)
|
||||||
}
|
}
|
||||||
|
|
||||||
// finally extract output meshes and add them to the scope
|
// finally extract output meshes and add them to the scope
|
||||||
typedef std::pair<unsigned int, TempMaterialMesh> pairt;
|
typedef std::pair<const unsigned int, TempMaterialMesh> pairt;
|
||||||
for(const pairt& p : bymat) {
|
for(const pairt& p : bymat) {
|
||||||
aiMesh* const m = ToOutputMesh(p.second);
|
aiMesh* const m = ToOutputMesh(p.second);
|
||||||
scope.meshes_linear.push_back(m);
|
scope.meshes_linear.push_back(m);
|
||||||
|
|
|
@ -54,7 +54,7 @@ ADD_EXECUTABLE( assimp_cmd
|
||||||
Main.cpp
|
Main.cpp
|
||||||
Main.h
|
Main.h
|
||||||
resource.h
|
resource.h
|
||||||
WriteDumb.cpp
|
WriteDump.cpp
|
||||||
Info.cpp
|
Info.cpp
|
||||||
Export.cpp
|
Export.cpp
|
||||||
)
|
)
|
||||||
|
|
|
@ -168,7 +168,7 @@ bool ExportModel(const aiScene* pOut,
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------
|
||||||
/** assimp_dump utility
|
/** assimp_dump utility
|
||||||
* @param params Command line parameters to 'assimp dumb'
|
* @param params Command line parameters to 'assimp dump'
|
||||||
* @param Number of params
|
* @param Number of params
|
||||||
* @return An #AssimpCmdError value.*/
|
* @return An #AssimpCmdError value.*/
|
||||||
int Assimp_Dump (
|
int Assimp_Dump (
|
||||||
|
|
|
@ -1,774 +0,0 @@
|
||||||
/*
|
|
||||||
---------------------------------------------------------------------------
|
|
||||||
Open Asset Import Library (assimp)
|
|
||||||
---------------------------------------------------------------------------
|
|
||||||
|
|
||||||
Copyright (c) 2006-2020, 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.
|
|
||||||
---------------------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
|
|
||||||
/** @file WriteTextDumb.cpp
|
|
||||||
* @brief Implementation of the 'assimp dump' utility
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "Main.h"
|
|
||||||
#include "PostProcessing/ProcessHelper.h"
|
|
||||||
|
|
||||||
const char* AICMD_MSG_DUMP_HELP =
|
|
||||||
"assimp dump <model> [<out>] [-b] [-s] [-z] [common parameters]\n"
|
|
||||||
"\t -b Binary output \n"
|
|
||||||
"\t -s Shortened \n"
|
|
||||||
"\t -z Compressed \n"
|
|
||||||
"\t[See the assimp_cmd docs for a full list of all common parameters] \n"
|
|
||||||
"\t -cfast Fast post processing preset, runs just a few important steps \n"
|
|
||||||
"\t -cdefault Default post processing: runs all recommended steps\n"
|
|
||||||
"\t -cfull Fires almost all post processing steps \n"
|
|
||||||
;
|
|
||||||
|
|
||||||
#include "Common/assbin_chunks.h"
|
|
||||||
#include <assimp/DefaultIOSystem.h>
|
|
||||||
#include <code/Assbin/AssbinFileWriter.h>
|
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
FILE* out = NULL;
|
|
||||||
bool shortened = false;
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
|
||||||
// Convert a name to standard XML format
|
|
||||||
void ConvertName(aiString& out, const aiString& in)
|
|
||||||
{
|
|
||||||
out.length = 0;
|
|
||||||
for (unsigned int i = 0; i < in.length; ++i) {
|
|
||||||
switch (in.data[i]) {
|
|
||||||
case '<':
|
|
||||||
out.Append("<");break;
|
|
||||||
case '>':
|
|
||||||
out.Append(">");break;
|
|
||||||
case '&':
|
|
||||||
out.Append("&");break;
|
|
||||||
case '\"':
|
|
||||||
out.Append(""");break;
|
|
||||||
case '\'':
|
|
||||||
out.Append("'");break;
|
|
||||||
default:
|
|
||||||
out.data[out.length++] = in.data[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
out.data[out.length] = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
|
||||||
// Write a single node as text dump
|
|
||||||
void WriteNode(const aiNode* node, FILE* out, unsigned int depth)
|
|
||||||
{
|
|
||||||
char prefix[512];
|
|
||||||
for (unsigned int i = 0; i < depth;++i)
|
|
||||||
prefix[i] = '\t';
|
|
||||||
prefix[depth] = '\0';
|
|
||||||
|
|
||||||
const aiMatrix4x4& m = node->mTransformation;
|
|
||||||
|
|
||||||
aiString name;
|
|
||||||
ConvertName(name,node->mName);
|
|
||||||
fprintf(out,"%s<Node name=\"%s\"> \n"
|
|
||||||
"%s\t<Matrix4> \n"
|
|
||||||
"%s\t\t%0 6f %0 6f %0 6f %0 6f\n"
|
|
||||||
"%s\t\t%0 6f %0 6f %0 6f %0 6f\n"
|
|
||||||
"%s\t\t%0 6f %0 6f %0 6f %0 6f\n"
|
|
||||||
"%s\t\t%0 6f %0 6f %0 6f %0 6f\n"
|
|
||||||
"%s\t</Matrix4> \n",
|
|
||||||
prefix,name.data,prefix,
|
|
||||||
prefix,m.a1,m.a2,m.a3,m.a4,
|
|
||||||
prefix,m.b1,m.b2,m.b3,m.b4,
|
|
||||||
prefix,m.c1,m.c2,m.c3,m.c4,
|
|
||||||
prefix,m.d1,m.d2,m.d3,m.d4,prefix);
|
|
||||||
|
|
||||||
if (node->mNumMeshes) {
|
|
||||||
fprintf(out, "%s\t<MeshRefs num=\"%u\">\n%s\t",
|
|
||||||
prefix,node->mNumMeshes,prefix);
|
|
||||||
|
|
||||||
for (unsigned int i = 0; i < node->mNumMeshes;++i) {
|
|
||||||
fprintf(out,"%u ",node->mMeshes[i]);
|
|
||||||
}
|
|
||||||
fprintf(out,"\n%s\t</MeshRefs>\n",prefix);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (node->mNumChildren) {
|
|
||||||
fprintf(out,"%s\t<NodeList num=\"%u\">\n",
|
|
||||||
prefix,node->mNumChildren);
|
|
||||||
|
|
||||||
for (unsigned int i = 0; i < node->mNumChildren;++i) {
|
|
||||||
WriteNode(node->mChildren[i],out,depth+2);
|
|
||||||
}
|
|
||||||
fprintf(out,"%s\t</NodeList>\n",prefix);
|
|
||||||
}
|
|
||||||
fprintf(out,"%s</Node>\n",prefix);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// -------------------------------------------------------------------------------
|
|
||||||
const char* TextureTypeToString(aiTextureType in)
|
|
||||||
{
|
|
||||||
switch (in)
|
|
||||||
{
|
|
||||||
case aiTextureType_NONE:
|
|
||||||
return "n/a";
|
|
||||||
case aiTextureType_DIFFUSE:
|
|
||||||
return "Diffuse";
|
|
||||||
case aiTextureType_SPECULAR:
|
|
||||||
return "Specular";
|
|
||||||
case aiTextureType_AMBIENT:
|
|
||||||
return "Ambient";
|
|
||||||
case aiTextureType_EMISSIVE:
|
|
||||||
return "Emissive";
|
|
||||||
case aiTextureType_OPACITY:
|
|
||||||
return "Opacity";
|
|
||||||
case aiTextureType_NORMALS:
|
|
||||||
return "Normals";
|
|
||||||
case aiTextureType_HEIGHT:
|
|
||||||
return "Height";
|
|
||||||
case aiTextureType_SHININESS:
|
|
||||||
return "Shininess";
|
|
||||||
case aiTextureType_DISPLACEMENT:
|
|
||||||
return "Displacement";
|
|
||||||
case aiTextureType_LIGHTMAP:
|
|
||||||
return "Lightmap";
|
|
||||||
case aiTextureType_REFLECTION:
|
|
||||||
return "Reflection";
|
|
||||||
case aiTextureType_UNKNOWN:
|
|
||||||
return "Unknown";
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
ai_assert(false);
|
|
||||||
return "BUG";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
|
||||||
// Some chuncks of text will need to be encoded for XML
|
|
||||||
// http://stackoverflow.com/questions/5665231/most-efficient-way-to-escape-xml-html-in-c-string#5665377
|
|
||||||
static std::string encodeXML(const std::string& data) {
|
|
||||||
std::string buffer;
|
|
||||||
buffer.reserve(data.size());
|
|
||||||
for(size_t pos = 0; pos != data.size(); ++pos) {
|
|
||||||
switch(data[pos]) {
|
|
||||||
case '&': buffer.append("&"); break;
|
|
||||||
case '\"': buffer.append("""); break;
|
|
||||||
case '\'': buffer.append("'"); break;
|
|
||||||
case '<': buffer.append("<"); break;
|
|
||||||
case '>': buffer.append(">"); break;
|
|
||||||
default: buffer.append(&data[pos], 1); break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return buffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
|
||||||
// Write a text model dump
|
|
||||||
void WriteDump(const aiScene* scene, FILE* out, const char* src, const char* cmd, bool shortened)
|
|
||||||
{
|
|
||||||
time_t tt = ::time(NULL);
|
|
||||||
#if _WIN32
|
|
||||||
tm* p = gmtime(&tt);
|
|
||||||
#else
|
|
||||||
struct tm now;
|
|
||||||
tm* p = gmtime_r(&tt, &now);
|
|
||||||
#endif
|
|
||||||
ai_assert(nullptr != p);
|
|
||||||
|
|
||||||
std::string c = cmd;
|
|
||||||
std::string::size_type s;
|
|
||||||
|
|
||||||
// https://sourceforge.net/tracker/?func=detail&aid=3167364&group_id=226462&atid=1067632
|
|
||||||
// -- not allowed in XML comments
|
|
||||||
while((s = c.find("--")) != std::string::npos) {
|
|
||||||
c[s] = '?';
|
|
||||||
}
|
|
||||||
aiString name;
|
|
||||||
|
|
||||||
// write header
|
|
||||||
fprintf(out,
|
|
||||||
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
|
|
||||||
"<ASSIMP format_id=\"1\">\n\n"
|
|
||||||
|
|
||||||
"<!-- XML Model dump produced by assimp dump\n"
|
|
||||||
" Library version: %u.%u.%u\n"
|
|
||||||
" Source: %s\n"
|
|
||||||
" Command line: %s\n"
|
|
||||||
" %s\n"
|
|
||||||
"-->"
|
|
||||||
" \n\n"
|
|
||||||
"<Scene flags=\"%u\" postprocessing=\"%i\">\n",
|
|
||||||
|
|
||||||
aiGetVersionMajor(),aiGetVersionMinor(),aiGetVersionRevision(),src,c.c_str(),asctime(p),
|
|
||||||
scene->mFlags,
|
|
||||||
0 /*globalImporter->GetEffectivePostProcessing()*/);
|
|
||||||
|
|
||||||
// write the node graph
|
|
||||||
WriteNode(scene->mRootNode, out, 0);
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
// write cameras
|
|
||||||
for (unsigned int i = 0; i < scene->mNumCameras;++i) {
|
|
||||||
aiCamera* cam = scene->mCameras[i];
|
|
||||||
ConvertName(name,cam->mName);
|
|
||||||
|
|
||||||
// camera header
|
|
||||||
fprintf(out,"\t<Camera parent=\"%s\">\n"
|
|
||||||
"\t\t<Vector3 name=\"up\" > %0 8f %0 8f %0 8f </Vector3>\n"
|
|
||||||
"\t\t<Vector3 name=\"lookat\" > %0 8f %0 8f %0 8f </Vector3>\n"
|
|
||||||
"\t\t<Vector3 name=\"pos\" > %0 8f %0 8f %0 8f </Vector3>\n"
|
|
||||||
"\t\t<Float name=\"fov\" > %f </Float>\n"
|
|
||||||
"\t\t<Float name=\"aspect\" > %f </Float>\n"
|
|
||||||
"\t\t<Float name=\"near_clip\" > %f </Float>\n"
|
|
||||||
"\t\t<Float name=\"far_clip\" > %f </Float>\n"
|
|
||||||
"\t</Camera>\n",
|
|
||||||
name.data,
|
|
||||||
cam->mUp.x,cam->mUp.y,cam->mUp.z,
|
|
||||||
cam->mLookAt.x,cam->mLookAt.y,cam->mLookAt.z,
|
|
||||||
cam->mPosition.x,cam->mPosition.y,cam->mPosition.z,
|
|
||||||
cam->mHorizontalFOV,cam->mAspect,cam->mClipPlaneNear,cam->mClipPlaneFar,i);
|
|
||||||
}
|
|
||||||
|
|
||||||
// write lights
|
|
||||||
for (unsigned int i = 0; i < scene->mNumLights;++i) {
|
|
||||||
aiLight* l = scene->mLights[i];
|
|
||||||
ConvertName(name,l->mName);
|
|
||||||
|
|
||||||
// light header
|
|
||||||
fprintf(out,"\t<Light parent=\"%s\"> type=\"%s\"\n"
|
|
||||||
"\t\t<Vector3 name=\"diffuse\" > %0 8f %0 8f %0 8f </Vector3>\n"
|
|
||||||
"\t\t<Vector3 name=\"specular\" > %0 8f %0 8f %0 8f </Vector3>\n"
|
|
||||||
"\t\t<Vector3 name=\"ambient\" > %0 8f %0 8f %0 8f </Vector3>\n",
|
|
||||||
name.data,
|
|
||||||
(l->mType == aiLightSource_DIRECTIONAL ? "directional" :
|
|
||||||
(l->mType == aiLightSource_POINT ? "point" : "spot" )),
|
|
||||||
l->mColorDiffuse.r, l->mColorDiffuse.g, l->mColorDiffuse.b,
|
|
||||||
l->mColorSpecular.r,l->mColorSpecular.g,l->mColorSpecular.b,
|
|
||||||
l->mColorAmbient.r, l->mColorAmbient.g, l->mColorAmbient.b);
|
|
||||||
|
|
||||||
if (l->mType != aiLightSource_DIRECTIONAL) {
|
|
||||||
fprintf(out,
|
|
||||||
"\t\t<Vector3 name=\"pos\" > %0 8f %0 8f %0 8f </Vector3>\n"
|
|
||||||
"\t\t<Float name=\"atten_cst\" > %f </Float>\n"
|
|
||||||
"\t\t<Float name=\"atten_lin\" > %f </Float>\n"
|
|
||||||
"\t\t<Float name=\"atten_sqr\" > %f </Float>\n",
|
|
||||||
l->mPosition.x,l->mPosition.y,l->mPosition.z,
|
|
||||||
l->mAttenuationConstant,l->mAttenuationLinear,l->mAttenuationQuadratic);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (l->mType != aiLightSource_POINT) {
|
|
||||||
fprintf(out,
|
|
||||||
"\t\t<Vector3 name=\"lookat\" > %0 8f %0 8f %0 8f </Vector3>\n",
|
|
||||||
l->mDirection.x,l->mDirection.y,l->mDirection.z);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (l->mType == aiLightSource_SPOT) {
|
|
||||||
fprintf(out,
|
|
||||||
"\t\t<Float name=\"cone_out\" > %f </Float>\n"
|
|
||||||
"\t\t<Float name=\"cone_inn\" > %f </Float>\n",
|
|
||||||
l->mAngleOuterCone,l->mAngleInnerCone);
|
|
||||||
}
|
|
||||||
fprintf(out,"\t</Light>\n");
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// write textures
|
|
||||||
if (scene->mNumTextures) {
|
|
||||||
fprintf(out,"<TextureList num=\"%u\">\n",scene->mNumTextures);
|
|
||||||
for (unsigned int i = 0; i < scene->mNumTextures;++i) {
|
|
||||||
aiTexture* tex = scene->mTextures[i];
|
|
||||||
bool compressed = (tex->mHeight == 0);
|
|
||||||
|
|
||||||
// mesh header
|
|
||||||
fprintf(out,"\t<Texture width=\"%i\" height=\"%i\" compressed=\"%s\"> \n",
|
|
||||||
(compressed ? -1 : tex->mWidth),(compressed ? -1 : tex->mHeight),
|
|
||||||
(compressed ? "true" : "false"));
|
|
||||||
|
|
||||||
if (compressed) {
|
|
||||||
fprintf(out,"\t\t<Data length=\"%u\"> \n",tex->mWidth);
|
|
||||||
|
|
||||||
if (!shortened) {
|
|
||||||
for (unsigned int n = 0; n < tex->mWidth;++n) {
|
|
||||||
fprintf(out,"\t\t\t%2x",reinterpret_cast<uint8_t*>(tex->pcData)[n]);
|
|
||||||
if (n && !(n % 50)) {
|
|
||||||
fprintf(out,"\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (!shortened){
|
|
||||||
fprintf(out,"\t\t<Data length=\"%i\"> \n",tex->mWidth*tex->mHeight*4);
|
|
||||||
|
|
||||||
// const unsigned int width = (unsigned int)log10((double)std::max(tex->mHeight,tex->mWidth))+1;
|
|
||||||
for (unsigned int y = 0; y < tex->mHeight;++y) {
|
|
||||||
for (unsigned int x = 0; x < tex->mWidth;++x) {
|
|
||||||
aiTexel* tx = tex->pcData + y*tex->mWidth+x;
|
|
||||||
unsigned int r = tx->r,g=tx->g,b=tx->b,a=tx->a;
|
|
||||||
fprintf(out,"\t\t\t%2x %2x %2x %2x",r,g,b,a);
|
|
||||||
|
|
||||||
// group by four for readibility
|
|
||||||
if (0 == (x+y*tex->mWidth) % 4)
|
|
||||||
fprintf(out,"\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fprintf(out,"\t\t</Data>\n\t</Texture>\n");
|
|
||||||
}
|
|
||||||
fprintf(out,"</TextureList>\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
// write materials
|
|
||||||
if (scene->mNumMaterials) {
|
|
||||||
fprintf(out,"<MaterialList num=\"%u\">\n",scene->mNumMaterials);
|
|
||||||
for (unsigned int i = 0; i< scene->mNumMaterials; ++i) {
|
|
||||||
const aiMaterial* mat = scene->mMaterials[i];
|
|
||||||
|
|
||||||
fprintf(out,"\t<Material>\n");
|
|
||||||
fprintf(out,"\t\t<MatPropertyList num=\"%u\">\n",mat->mNumProperties);
|
|
||||||
for (unsigned int n = 0; n < mat->mNumProperties;++n) {
|
|
||||||
|
|
||||||
const aiMaterialProperty* prop = mat->mProperties[n];
|
|
||||||
const char* sz = "";
|
|
||||||
if (prop->mType == aiPTI_Float) {
|
|
||||||
sz = "float";
|
|
||||||
}
|
|
||||||
else if (prop->mType == aiPTI_Integer) {
|
|
||||||
sz = "integer";
|
|
||||||
}
|
|
||||||
else if (prop->mType == aiPTI_String) {
|
|
||||||
sz = "string";
|
|
||||||
}
|
|
||||||
else if (prop->mType == aiPTI_Buffer) {
|
|
||||||
sz = "binary_buffer";
|
|
||||||
}
|
|
||||||
|
|
||||||
fprintf(out,"\t\t\t<MatProperty key=\"%s\" \n\t\t\ttype=\"%s\" tex_usage=\"%s\" tex_index=\"%u\"",
|
|
||||||
prop->mKey.data, sz,
|
|
||||||
::TextureTypeToString((aiTextureType)prop->mSemantic),prop->mIndex);
|
|
||||||
|
|
||||||
if (prop->mType == aiPTI_Float) {
|
|
||||||
fprintf(out," size=\"%i\">\n\t\t\t\t",
|
|
||||||
static_cast<int>(prop->mDataLength/sizeof(float)));
|
|
||||||
|
|
||||||
for (unsigned int p = 0; p < prop->mDataLength/sizeof(float);++p) {
|
|
||||||
fprintf(out,"%f ",*((float*)(prop->mData+p*sizeof(float))));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (prop->mType == aiPTI_Integer) {
|
|
||||||
fprintf(out," size=\"%i\">\n\t\t\t\t",
|
|
||||||
static_cast<int>(prop->mDataLength/sizeof(int)));
|
|
||||||
|
|
||||||
for (unsigned int p = 0; p < prop->mDataLength/sizeof(int);++p) {
|
|
||||||
fprintf(out,"%i ",*((int*)(prop->mData+p*sizeof(int))));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (prop->mType == aiPTI_Buffer) {
|
|
||||||
fprintf(out," size=\"%i\">\n\t\t\t\t",
|
|
||||||
static_cast<int>(prop->mDataLength));
|
|
||||||
|
|
||||||
for (unsigned int p = 0; p < prop->mDataLength;++p) {
|
|
||||||
fprintf(out,"%2x ",prop->mData[p]);
|
|
||||||
if (p && 0 == p%30) {
|
|
||||||
fprintf(out,"\n\t\t\t\t");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (prop->mType == aiPTI_String) {
|
|
||||||
fprintf(out,">\n\t\t\t\t\"%s\"",encodeXML(prop->mData+4).c_str() /* skip length */);
|
|
||||||
}
|
|
||||||
fprintf(out,"\n\t\t\t</MatProperty>\n");
|
|
||||||
}
|
|
||||||
fprintf(out,"\t\t</MatPropertyList>\n");
|
|
||||||
fprintf(out,"\t</Material>\n");
|
|
||||||
}
|
|
||||||
fprintf(out,"</MaterialList>\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
// write animations
|
|
||||||
if (scene->mNumAnimations) {
|
|
||||||
fprintf(out,"<AnimationList num=\"%u\">\n",scene->mNumAnimations);
|
|
||||||
for (unsigned int i = 0; i < scene->mNumAnimations;++i) {
|
|
||||||
aiAnimation* anim = scene->mAnimations[i];
|
|
||||||
|
|
||||||
// anim header
|
|
||||||
ConvertName(name,anim->mName);
|
|
||||||
fprintf(out,"\t<Animation name=\"%s\" duration=\"%e\" tick_cnt=\"%e\">\n",
|
|
||||||
name.data, anim->mDuration, anim->mTicksPerSecond);
|
|
||||||
|
|
||||||
// write bone animation channels
|
|
||||||
if (anim->mNumChannels) {
|
|
||||||
fprintf(out,"\t\t<NodeAnimList num=\"%u\">\n",anim->mNumChannels);
|
|
||||||
for (unsigned int n = 0; n < anim->mNumChannels;++n) {
|
|
||||||
aiNodeAnim* nd = anim->mChannels[n];
|
|
||||||
|
|
||||||
// node anim header
|
|
||||||
ConvertName(name,nd->mNodeName);
|
|
||||||
fprintf(out,"\t\t\t<NodeAnim node=\"%s\">\n",name.data);
|
|
||||||
|
|
||||||
if (!shortened) {
|
|
||||||
// write position keys
|
|
||||||
if (nd->mNumPositionKeys) {
|
|
||||||
fprintf(out,"\t\t\t\t<PositionKeyList num=\"%u\">\n",nd->mNumPositionKeys);
|
|
||||||
for (unsigned int a = 0; a < nd->mNumPositionKeys;++a) {
|
|
||||||
aiVectorKey* vc = nd->mPositionKeys+a;
|
|
||||||
fprintf(out,"\t\t\t\t\t<PositionKey time=\"%e\">\n"
|
|
||||||
"\t\t\t\t\t\t%0 8f %0 8f %0 8f\n\t\t\t\t\t</PositionKey>\n",
|
|
||||||
vc->mTime,vc->mValue.x,vc->mValue.y,vc->mValue.z);
|
|
||||||
}
|
|
||||||
fprintf(out,"\t\t\t\t</PositionKeyList>\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
// write scaling keys
|
|
||||||
if (nd->mNumScalingKeys) {
|
|
||||||
fprintf(out,"\t\t\t\t<ScalingKeyList num=\"%u\">\n",nd->mNumScalingKeys);
|
|
||||||
for (unsigned int a = 0; a < nd->mNumScalingKeys;++a) {
|
|
||||||
aiVectorKey* vc = nd->mScalingKeys+a;
|
|
||||||
fprintf(out,"\t\t\t\t\t<ScalingKey time=\"%e\">\n"
|
|
||||||
"\t\t\t\t\t\t%0 8f %0 8f %0 8f\n\t\t\t\t\t</ScalingKey>\n",
|
|
||||||
vc->mTime,vc->mValue.x,vc->mValue.y,vc->mValue.z);
|
|
||||||
}
|
|
||||||
fprintf(out,"\t\t\t\t</ScalingKeyList>\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
// write rotation keys
|
|
||||||
if (nd->mNumRotationKeys) {
|
|
||||||
fprintf(out,"\t\t\t\t<RotationKeyList num=\"%u\">\n",nd->mNumRotationKeys);
|
|
||||||
for (unsigned int a = 0; a < nd->mNumRotationKeys;++a) {
|
|
||||||
aiQuatKey* vc = nd->mRotationKeys+a;
|
|
||||||
fprintf(out,"\t\t\t\t\t<RotationKey time=\"%e\">\n"
|
|
||||||
"\t\t\t\t\t\t%0 8f %0 8f %0 8f %0 8f\n\t\t\t\t\t</RotationKey>\n",
|
|
||||||
vc->mTime,vc->mValue.x,vc->mValue.y,vc->mValue.z,vc->mValue.w);
|
|
||||||
}
|
|
||||||
fprintf(out,"\t\t\t\t</RotationKeyList>\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fprintf(out,"\t\t\t</NodeAnim>\n");
|
|
||||||
}
|
|
||||||
fprintf(out,"\t\t</NodeAnimList>\n");
|
|
||||||
}
|
|
||||||
fprintf(out,"\t</Animation>\n");
|
|
||||||
}
|
|
||||||
fprintf(out,"</AnimationList>\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
// write meshes
|
|
||||||
if (scene->mNumMeshes) {
|
|
||||||
fprintf(out,"<MeshList num=\"%u\">\n",scene->mNumMeshes);
|
|
||||||
for (unsigned int i = 0; i < scene->mNumMeshes;++i) {
|
|
||||||
aiMesh* mesh = scene->mMeshes[i];
|
|
||||||
// const unsigned int width = (unsigned int)log10((double)mesh->mNumVertices)+1;
|
|
||||||
|
|
||||||
// mesh header
|
|
||||||
fprintf(out,"\t<Mesh types=\"%s %s %s %s\" material_index=\"%u\">\n",
|
|
||||||
(mesh->mPrimitiveTypes & aiPrimitiveType_POINT ? "points" : ""),
|
|
||||||
(mesh->mPrimitiveTypes & aiPrimitiveType_LINE ? "lines" : ""),
|
|
||||||
(mesh->mPrimitiveTypes & aiPrimitiveType_TRIANGLE ? "triangles" : ""),
|
|
||||||
(mesh->mPrimitiveTypes & aiPrimitiveType_POLYGON ? "polygons" : ""),
|
|
||||||
mesh->mMaterialIndex);
|
|
||||||
|
|
||||||
// bones
|
|
||||||
if (mesh->mNumBones) {
|
|
||||||
fprintf(out,"\t\t<BoneList num=\"%u\">\n",mesh->mNumBones);
|
|
||||||
|
|
||||||
for (unsigned int n = 0; n < mesh->mNumBones;++n) {
|
|
||||||
aiBone* bone = mesh->mBones[n];
|
|
||||||
|
|
||||||
ConvertName(name,bone->mName);
|
|
||||||
// bone header
|
|
||||||
fprintf(out,"\t\t\t<Bone name=\"%s\">\n"
|
|
||||||
"\t\t\t\t<Matrix4> \n"
|
|
||||||
"\t\t\t\t\t%0 6f %0 6f %0 6f %0 6f\n"
|
|
||||||
"\t\t\t\t\t%0 6f %0 6f %0 6f %0 6f\n"
|
|
||||||
"\t\t\t\t\t%0 6f %0 6f %0 6f %0 6f\n"
|
|
||||||
"\t\t\t\t\t%0 6f %0 6f %0 6f %0 6f\n"
|
|
||||||
"\t\t\t\t</Matrix4> \n",
|
|
||||||
name.data,
|
|
||||||
bone->mOffsetMatrix.a1,bone->mOffsetMatrix.a2,bone->mOffsetMatrix.a3,bone->mOffsetMatrix.a4,
|
|
||||||
bone->mOffsetMatrix.b1,bone->mOffsetMatrix.b2,bone->mOffsetMatrix.b3,bone->mOffsetMatrix.b4,
|
|
||||||
bone->mOffsetMatrix.c1,bone->mOffsetMatrix.c2,bone->mOffsetMatrix.c3,bone->mOffsetMatrix.c4,
|
|
||||||
bone->mOffsetMatrix.d1,bone->mOffsetMatrix.d2,bone->mOffsetMatrix.d3,bone->mOffsetMatrix.d4);
|
|
||||||
|
|
||||||
if (!shortened && bone->mNumWeights) {
|
|
||||||
fprintf(out,"\t\t\t\t<WeightList num=\"%u\">\n",bone->mNumWeights);
|
|
||||||
|
|
||||||
// bone weights
|
|
||||||
for (unsigned int a = 0; a < bone->mNumWeights;++a) {
|
|
||||||
aiVertexWeight* wght = bone->mWeights+a;
|
|
||||||
|
|
||||||
fprintf(out,"\t\t\t\t\t<Weight index=\"%u\">\n\t\t\t\t\t\t%f\n\t\t\t\t\t</Weight>\n",
|
|
||||||
wght->mVertexId,wght->mWeight);
|
|
||||||
}
|
|
||||||
fprintf(out,"\t\t\t\t</WeightList>\n");
|
|
||||||
}
|
|
||||||
fprintf(out,"\t\t\t</Bone>\n");
|
|
||||||
}
|
|
||||||
fprintf(out,"\t\t</BoneList>\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
// faces
|
|
||||||
if (!shortened && mesh->mNumFaces) {
|
|
||||||
fprintf(out,"\t\t<FaceList num=\"%u\">\n",mesh->mNumFaces);
|
|
||||||
for (unsigned int n = 0; n < mesh->mNumFaces; ++n) {
|
|
||||||
aiFace& f = mesh->mFaces[n];
|
|
||||||
fprintf(out,"\t\t\t<Face num=\"%u\">\n"
|
|
||||||
"\t\t\t\t",f.mNumIndices);
|
|
||||||
|
|
||||||
for (unsigned int j = 0; j < f.mNumIndices;++j)
|
|
||||||
fprintf(out,"%u ",f.mIndices[j]);
|
|
||||||
|
|
||||||
fprintf(out,"\n\t\t\t</Face>\n");
|
|
||||||
}
|
|
||||||
fprintf(out,"\t\t</FaceList>\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
// vertex positions
|
|
||||||
if (mesh->HasPositions()) {
|
|
||||||
fprintf(out,"\t\t<Positions num=\"%u\" set=\"0\" num_components=\"3\"> \n",mesh->mNumVertices);
|
|
||||||
if (!shortened) {
|
|
||||||
for (unsigned int n = 0; n < mesh->mNumVertices; ++n) {
|
|
||||||
fprintf(out,"\t\t%0 8f %0 8f %0 8f\n",
|
|
||||||
mesh->mVertices[n].x,
|
|
||||||
mesh->mVertices[n].y,
|
|
||||||
mesh->mVertices[n].z);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fprintf(out,"\t\t</Positions>\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
// vertex normals
|
|
||||||
if (mesh->HasNormals()) {
|
|
||||||
fprintf(out,"\t\t<Normals num=\"%u\" set=\"0\" num_components=\"3\"> \n",mesh->mNumVertices);
|
|
||||||
if (!shortened) {
|
|
||||||
for (unsigned int n = 0; n < mesh->mNumVertices; ++n) {
|
|
||||||
fprintf(out,"\t\t%0 8f %0 8f %0 8f\n",
|
|
||||||
mesh->mNormals[n].x,
|
|
||||||
mesh->mNormals[n].y,
|
|
||||||
mesh->mNormals[n].z);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
}
|
|
||||||
fprintf(out,"\t\t</Normals>\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
// vertex tangents and bitangents
|
|
||||||
if (mesh->HasTangentsAndBitangents()) {
|
|
||||||
fprintf(out,"\t\t<Tangents num=\"%u\" set=\"0\" num_components=\"3\"> \n",mesh->mNumVertices);
|
|
||||||
if (!shortened) {
|
|
||||||
for (unsigned int n = 0; n < mesh->mNumVertices; ++n) {
|
|
||||||
fprintf(out,"\t\t%0 8f %0 8f %0 8f\n",
|
|
||||||
mesh->mTangents[n].x,
|
|
||||||
mesh->mTangents[n].y,
|
|
||||||
mesh->mTangents[n].z);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fprintf(out,"\t\t</Tangents>\n");
|
|
||||||
|
|
||||||
fprintf(out,"\t\t<Bitangents num=\"%u\" set=\"0\" num_components=\"3\"> \n",mesh->mNumVertices);
|
|
||||||
if (!shortened) {
|
|
||||||
for (unsigned int n = 0; n < mesh->mNumVertices; ++n) {
|
|
||||||
fprintf(out,"\t\t%0 8f %0 8f %0 8f\n",
|
|
||||||
mesh->mBitangents[n].x,
|
|
||||||
mesh->mBitangents[n].y,
|
|
||||||
mesh->mBitangents[n].z);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fprintf(out,"\t\t</Bitangents>\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
// texture coordinates
|
|
||||||
for (unsigned int a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++a) {
|
|
||||||
if (!mesh->mTextureCoords[a])
|
|
||||||
break;
|
|
||||||
|
|
||||||
fprintf(out,"\t\t<TextureCoords num=\"%u\" set=\"%u\" num_components=\"%u\"> \n",mesh->mNumVertices,
|
|
||||||
a,mesh->mNumUVComponents[a]);
|
|
||||||
|
|
||||||
if (!shortened) {
|
|
||||||
if (mesh->mNumUVComponents[a] == 3) {
|
|
||||||
for (unsigned int n = 0; n < mesh->mNumVertices; ++n) {
|
|
||||||
fprintf(out,"\t\t%0 8f %0 8f %0 8f\n",
|
|
||||||
mesh->mTextureCoords[a][n].x,
|
|
||||||
mesh->mTextureCoords[a][n].y,
|
|
||||||
mesh->mTextureCoords[a][n].z);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
for (unsigned int n = 0; n < mesh->mNumVertices; ++n) {
|
|
||||||
fprintf(out,"\t\t%0 8f %0 8f\n",
|
|
||||||
mesh->mTextureCoords[a][n].x,
|
|
||||||
mesh->mTextureCoords[a][n].y);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fprintf(out,"\t\t</TextureCoords>\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
// vertex colors
|
|
||||||
for (unsigned int a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS; ++a) {
|
|
||||||
if (!mesh->mColors[a])
|
|
||||||
break;
|
|
||||||
fprintf(out,"\t\t<Colors num=\"%u\" set=\"%u\" num_components=\"4\"> \n",mesh->mNumVertices,a);
|
|
||||||
if (!shortened) {
|
|
||||||
for (unsigned int n = 0; n < mesh->mNumVertices; ++n) {
|
|
||||||
fprintf(out,"\t\t%0 8f %0 8f %0 8f %0 8f\n",
|
|
||||||
mesh->mColors[a][n].r,
|
|
||||||
mesh->mColors[a][n].g,
|
|
||||||
mesh->mColors[a][n].b,
|
|
||||||
mesh->mColors[a][n].a);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fprintf(out,"\t\t</Colors>\n");
|
|
||||||
}
|
|
||||||
fprintf(out,"\t</Mesh>\n");
|
|
||||||
}
|
|
||||||
fprintf(out,"</MeshList>\n");
|
|
||||||
}
|
|
||||||
fprintf(out,"</Scene>\n</ASSIMP>");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------------
|
|
||||||
int Assimp_Dump (const char* const* params, unsigned int num)
|
|
||||||
{
|
|
||||||
const char* fail = "assimp dump: Invalid number of arguments. "
|
|
||||||
"See \'assimp dump --help\'\r\n";
|
|
||||||
|
|
||||||
// --help
|
|
||||||
if (!strcmp( params[0], "-h") || !strcmp( params[0], "--help") || !strcmp( params[0], "-?") ) {
|
|
||||||
printf("%s",AICMD_MSG_DUMP_HELP);
|
|
||||||
return AssimpCmdError::Success;
|
|
||||||
}
|
|
||||||
|
|
||||||
// asssimp dump in out [options]
|
|
||||||
if (num < 1) {
|
|
||||||
printf("%s", fail);
|
|
||||||
return AssimpCmdError::InvalidNumberOfArguments;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string in = std::string(params[0]);
|
|
||||||
std::string out = (num > 1 ? std::string(params[1]) : std::string("-"));
|
|
||||||
|
|
||||||
// store full command line
|
|
||||||
std::string cmd;
|
|
||||||
for (unsigned int i = (out[0] == '-' ? 1 : 2); i < num;++i) {
|
|
||||||
if (!params[i])continue;
|
|
||||||
cmd.append(params[i]);
|
|
||||||
cmd.append(" ");
|
|
||||||
}
|
|
||||||
|
|
||||||
// get import flags
|
|
||||||
ImportData import;
|
|
||||||
ProcessStandardArguments(import,params+1,num-1);
|
|
||||||
|
|
||||||
bool binary = false, shortened = false,compressed=false;
|
|
||||||
|
|
||||||
// process other flags
|
|
||||||
for (unsigned int i = 1; i < num;++i) {
|
|
||||||
if (!params[i])continue;
|
|
||||||
if (!strcmp( params[i], "-b") || !strcmp( params[i], "--binary")) {
|
|
||||||
binary = true;
|
|
||||||
}
|
|
||||||
else if (!strcmp( params[i], "-s") || !strcmp( params[i], "--short")) {
|
|
||||||
shortened = true;
|
|
||||||
}
|
|
||||||
else if (!strcmp( params[i], "-z") || !strcmp( params[i], "--compressed")) {
|
|
||||||
compressed = true;
|
|
||||||
}
|
|
||||||
#if 0
|
|
||||||
else if (i > 2 || params[i][0] == '-') {
|
|
||||||
::printf("Unknown parameter: %s\n",params[i]);
|
|
||||||
return 10;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
if (out[0] == '-') {
|
|
||||||
// take file name from input file
|
|
||||||
std::string::size_type s = in.find_last_of('.');
|
|
||||||
if (s == std::string::npos) {
|
|
||||||
s = in.length();
|
|
||||||
}
|
|
||||||
|
|
||||||
out = in.substr(0,s);
|
|
||||||
out.append((binary ? ".assbin" : ".assxml"));
|
|
||||||
if (shortened && binary) {
|
|
||||||
out.append(".regress");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// import the main model
|
|
||||||
const aiScene* scene = ImportModel(import,in);
|
|
||||||
if (!scene) {
|
|
||||||
printf("assimp dump: Unable to load input file %s\n",in.c_str());
|
|
||||||
return AssimpCmdError::FailedToLoadInputFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (binary) {
|
|
||||||
try {
|
|
||||||
std::unique_ptr<IOSystem> pIOSystem(new DefaultIOSystem());
|
|
||||||
DumpSceneToAssbin(out.c_str(), cmd.c_str(), pIOSystem.get(),
|
|
||||||
scene, shortened, compressed);
|
|
||||||
}
|
|
||||||
catch (const std::exception& e) {
|
|
||||||
printf("%s", ("assimp dump: " + std::string(e.what())).c_str());
|
|
||||||
return AssimpCmdError::ExceptionWasRaised;
|
|
||||||
}
|
|
||||||
catch (...) {
|
|
||||||
printf("assimp dump: An unknown exception occured.\n");
|
|
||||||
return AssimpCmdError::ExceptionWasRaised;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
FILE* o = ::fopen(out.c_str(), "wt");
|
|
||||||
if (!o) {
|
|
||||||
printf("assimp dump: Unable to open output file %s\n",out.c_str());
|
|
||||||
return AssimpCmdError::FailedToOpenOutputFile;
|
|
||||||
}
|
|
||||||
WriteDump (scene,o,in.c_str(),cmd.c_str(),shortened);
|
|
||||||
fclose(o);
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("assimp dump: Wrote output dump %s\n",out.c_str());
|
|
||||||
return AssimpCmdError::Success;
|
|
||||||
}
|
|
||||||
|
|
|
@ -0,0 +1,210 @@
|
||||||
|
/*
|
||||||
|
---------------------------------------------------------------------------
|
||||||
|
Open Asset Import Library (assimp)
|
||||||
|
---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Copyright (c) 2006-2020, 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.
|
||||||
|
---------------------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @file WriteDump.cpp
|
||||||
|
* @brief Implementation of the 'assimp dump' utility
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "Main.h"
|
||||||
|
#include "PostProcessing/ProcessHelper.h"
|
||||||
|
|
||||||
|
const char* AICMD_MSG_DUMP_HELP =
|
||||||
|
"assimp dump <model> [<out>] [-b] [-s] [-z] [common parameters]\n"
|
||||||
|
"\t -b Binary output \n"
|
||||||
|
"\t -s Shortened \n"
|
||||||
|
"\t -z Compressed \n"
|
||||||
|
"\t[See the assimp_cmd docs for a full list of all common parameters] \n"
|
||||||
|
"\t -cfast Fast post processing preset, runs just a few important steps \n"
|
||||||
|
"\t -cdefault Default post processing: runs all recommended steps\n"
|
||||||
|
"\t -cfull Fires almost all post processing steps \n"
|
||||||
|
;
|
||||||
|
|
||||||
|
#include "Common/assbin_chunks.h"
|
||||||
|
#include <assimp/DefaultIOSystem.h>
|
||||||
|
#include <code/Assbin/AssbinFileWriter.h>
|
||||||
|
#include <code/Assxml/AssxmlFileWriter.h>
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
FILE* out = NULL;
|
||||||
|
bool shortened = false;
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------------------
|
||||||
|
const char* TextureTypeToString(aiTextureType in)
|
||||||
|
{
|
||||||
|
switch (in)
|
||||||
|
{
|
||||||
|
case aiTextureType_NONE:
|
||||||
|
return "n/a";
|
||||||
|
case aiTextureType_DIFFUSE:
|
||||||
|
return "Diffuse";
|
||||||
|
case aiTextureType_SPECULAR:
|
||||||
|
return "Specular";
|
||||||
|
case aiTextureType_AMBIENT:
|
||||||
|
return "Ambient";
|
||||||
|
case aiTextureType_EMISSIVE:
|
||||||
|
return "Emissive";
|
||||||
|
case aiTextureType_OPACITY:
|
||||||
|
return "Opacity";
|
||||||
|
case aiTextureType_NORMALS:
|
||||||
|
return "Normals";
|
||||||
|
case aiTextureType_HEIGHT:
|
||||||
|
return "Height";
|
||||||
|
case aiTextureType_SHININESS:
|
||||||
|
return "Shininess";
|
||||||
|
case aiTextureType_DISPLACEMENT:
|
||||||
|
return "Displacement";
|
||||||
|
case aiTextureType_LIGHTMAP:
|
||||||
|
return "Lightmap";
|
||||||
|
case aiTextureType_REFLECTION:
|
||||||
|
return "Reflection";
|
||||||
|
case aiTextureType_UNKNOWN:
|
||||||
|
return "Unknown";
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
ai_assert(false);
|
||||||
|
return "BUG";
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------------------------------------------------------------
|
||||||
|
int Assimp_Dump (const char* const* params, unsigned int num)
|
||||||
|
{
|
||||||
|
const char* fail = "assimp dump: Invalid number of arguments. "
|
||||||
|
"See \'assimp dump --help\'\r\n";
|
||||||
|
|
||||||
|
// --help
|
||||||
|
if (!strcmp( params[0], "-h") || !strcmp( params[0], "--help") || !strcmp( params[0], "-?") ) {
|
||||||
|
printf("%s",AICMD_MSG_DUMP_HELP);
|
||||||
|
return AssimpCmdError::Success;
|
||||||
|
}
|
||||||
|
|
||||||
|
// asssimp dump in out [options]
|
||||||
|
if (num < 1) {
|
||||||
|
printf("%s", fail);
|
||||||
|
return AssimpCmdError::InvalidNumberOfArguments;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string in = std::string(params[0]);
|
||||||
|
std::string out = (num > 1 ? std::string(params[1]) : std::string("-"));
|
||||||
|
|
||||||
|
// store full command line
|
||||||
|
std::string cmd;
|
||||||
|
for (unsigned int i = (out[0] == '-' ? 1 : 2); i < num;++i) {
|
||||||
|
if (!params[i])continue;
|
||||||
|
cmd.append(params[i]);
|
||||||
|
cmd.append(" ");
|
||||||
|
}
|
||||||
|
|
||||||
|
// get import flags
|
||||||
|
ImportData import;
|
||||||
|
ProcessStandardArguments(import,params+1,num-1);
|
||||||
|
|
||||||
|
bool binary = false, shortened = false,compressed=false;
|
||||||
|
|
||||||
|
// process other flags
|
||||||
|
for (unsigned int i = 1; i < num;++i) {
|
||||||
|
if (!params[i])continue;
|
||||||
|
if (!strcmp( params[i], "-b") || !strcmp( params[i], "--binary")) {
|
||||||
|
binary = true;
|
||||||
|
}
|
||||||
|
else if (!strcmp( params[i], "-s") || !strcmp( params[i], "--short")) {
|
||||||
|
shortened = true;
|
||||||
|
}
|
||||||
|
else if (!strcmp( params[i], "-z") || !strcmp( params[i], "--compressed")) {
|
||||||
|
compressed = true;
|
||||||
|
}
|
||||||
|
#if 0
|
||||||
|
else if (i > 2 || params[i][0] == '-') {
|
||||||
|
::printf("Unknown parameter: %s\n",params[i]);
|
||||||
|
return 10;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
if (out[0] == '-') {
|
||||||
|
// take file name from input file
|
||||||
|
std::string::size_type s = in.find_last_of('.');
|
||||||
|
if (s == std::string::npos) {
|
||||||
|
s = in.length();
|
||||||
|
}
|
||||||
|
|
||||||
|
out = in.substr(0,s);
|
||||||
|
out.append((binary ? ".assbin" : ".assxml"));
|
||||||
|
if (shortened && binary) {
|
||||||
|
out.append(".regress");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// import the main model
|
||||||
|
const aiScene* scene = ImportModel(import,in);
|
||||||
|
if (!scene) {
|
||||||
|
printf("assimp dump: Unable to load input file %s\n",in.c_str());
|
||||||
|
return AssimpCmdError::FailedToLoadInputFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Dump the main model, using the appropriate method.
|
||||||
|
std::unique_ptr<IOSystem> pIOSystem(new DefaultIOSystem());
|
||||||
|
if (binary) {
|
||||||
|
DumpSceneToAssbin(out.c_str(), cmd.c_str(), pIOSystem.get(),
|
||||||
|
scene, shortened, compressed);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
DumpSceneToAssxml(out.c_str(), cmd.c_str(), pIOSystem.get(),
|
||||||
|
scene, shortened);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (const std::exception& e) {
|
||||||
|
printf("%s", ("assimp dump: " + std::string(e.what())).c_str());
|
||||||
|
return AssimpCmdError::ExceptionWasRaised;
|
||||||
|
}
|
||||||
|
catch (...) {
|
||||||
|
printf("assimp dump: An unknown exception occured.\n");
|
||||||
|
return AssimpCmdError::ExceptionWasRaised;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("assimp dump: Wrote output dump %s\n",out.c_str());
|
||||||
|
return AssimpCmdError::Success;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue