add the ability to export cameras information in a collada file
parent
a1268bf864
commit
fb4eb83e84
|
@ -127,6 +127,7 @@ void ColladaExporter::WriteFile()
|
|||
WriteTextures();
|
||||
WriteHeader();
|
||||
|
||||
WriteCamerasLibrary();
|
||||
WriteMaterials();
|
||||
WriteGeometryLibrary();
|
||||
|
||||
|
@ -286,6 +287,61 @@ void ColladaExporter::WriteTextures() {
|
|||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Write the embedded textures
|
||||
void ColladaExporter::WriteCamerasLibrary() {
|
||||
if(mScene->HasCameras()) {
|
||||
|
||||
mOutput << startstr << "<library_cameras>" << endstr;
|
||||
PushTag();
|
||||
|
||||
for( size_t a = 0; a < mScene->mNumCameras; ++a)
|
||||
WriteCamera( a);
|
||||
|
||||
PopTag();
|
||||
mOutput << startstr << "</library_cameras>" << endstr;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void ColladaExporter::WriteCamera(size_t pIndex){
|
||||
|
||||
const aiCamera *cam = mScene->mCameras[pIndex];
|
||||
const std::string idstrEscaped = XMLEscape(cam->mName.C_Str());
|
||||
|
||||
mOutput << startstr << "<camera id=\"" << idstrEscaped << "-camera\" name=\"" << idstrEscaped << "_name\" >" << endstr;
|
||||
PushTag();
|
||||
mOutput << startstr << "<optics>" << endstr;
|
||||
PushTag();
|
||||
mOutput << startstr << "<technique_common>" << endstr;
|
||||
PushTag();
|
||||
//assimp doesn't support the import of orthographic cameras! se we write
|
||||
//always perspective
|
||||
mOutput << startstr << "<perspective>" << endstr;
|
||||
PushTag();
|
||||
mOutput << startstr << "<xfov sid=\"xfov\">"<<
|
||||
AI_RAD_TO_DEG(cam->mHorizontalFOV)
|
||||
<<"</xfov>" << endstr;
|
||||
mOutput << startstr << "<aspect_ratio>"
|
||||
<< cam->mAspect
|
||||
<< "</aspect_ratio>" << endstr;
|
||||
mOutput << startstr << "<znear sid=\"znear\">"
|
||||
<< cam->mClipPlaneNear
|
||||
<< "</znear>" << endstr;
|
||||
mOutput << startstr << "<zfar sid=\"zfar\">"
|
||||
<< cam->mClipPlaneFar
|
||||
<< "</zfar>" << endstr;
|
||||
PopTag();
|
||||
mOutput << startstr << "</perspective>" << endstr;
|
||||
PopTag();
|
||||
mOutput << startstr << "</technique_common>" << endstr;
|
||||
PopTag();
|
||||
mOutput << startstr << "</optics>" << endstr;
|
||||
PopTag();
|
||||
mOutput << startstr << "</camera>" << endstr;
|
||||
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// Reads a single surface entry from the given material keys
|
||||
void ColladaExporter::ReadMaterialSurface( Surface& poSurface, const aiMaterial* pSrcMat, aiTextureType pTexture, const char* pKey, size_t pType, size_t pIndex)
|
||||
|
@ -847,6 +903,9 @@ void ColladaExporter::WriteNode(aiNode* pNode)
|
|||
mOutput << mat.d1 << " " << mat.d2 << " " << mat.d3 << " " << mat.d4;
|
||||
mOutput << "</matrix>" << endstr;
|
||||
|
||||
if(pNode->mNumMeshes==0){
|
||||
mOutput << startstr <<"<instance_camera url=\"#" << node_name_escaped << "-camera\">" << endstr;
|
||||
}else
|
||||
// instance every geometry
|
||||
for( size_t a = 0; a < pNode->mNumMeshes; ++a )
|
||||
{
|
||||
|
@ -854,9 +913,8 @@ void ColladaExporter::WriteNode(aiNode* pNode)
|
|||
// do not instanciate mesh if empty. I wonder how this could happen
|
||||
if( mesh->mNumFaces == 0 || mesh->mNumVertices == 0 )
|
||||
continue;
|
||||
|
||||
mOutput << startstr << "<instance_geometry url=\"#" << XMLEscape(GetMeshId( pNode->mMeshes[a])) << "\">" << endstr;
|
||||
PushTag();
|
||||
mOutput << startstr << "<instance_geometry url=\"#" << XMLEscape(GetMeshId( pNode->mMeshes[a])) << "\">" << endstr;
|
||||
PushTag();
|
||||
mOutput << startstr << "<bind_material>" << endstr;
|
||||
PushTag();
|
||||
mOutput << startstr << "<technique_common>" << endstr;
|
||||
|
|
|
@ -83,6 +83,11 @@ protected:
|
|||
/// Writes the material setup
|
||||
void WriteMaterials();
|
||||
|
||||
/// Writes the cameras library
|
||||
void WriteCamerasLibrary();
|
||||
|
||||
void WriteCamera(size_t pIndex);
|
||||
|
||||
/// Writes the geometry library
|
||||
void WriteGeometryLibrary();
|
||||
|
||||
|
|
|
@ -40,6 +40,7 @@ SET( TEST_SRCS
|
|||
unit/utTriangulate.cpp
|
||||
unit/utVertexTriangleAdjacency.cpp
|
||||
unit/utNoBoostTest.cpp
|
||||
unit/utColladaExportCamera.cpp
|
||||
)
|
||||
|
||||
SOURCE_GROUP( tests FILES ${TEST_SRCS} )
|
||||
|
|
|
@ -0,0 +1,93 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<COLLADA xmlns="http://www.collada.org/2005/11/COLLADASchema" version="1.4.1">
|
||||
<asset>
|
||||
<contributor>
|
||||
<author>Blender User</author>
|
||||
<authoring_tool>Blender 2.74.0 commit date:2015-03-31, commit time:13:39, hash:000dfc0</authoring_tool>
|
||||
</contributor>
|
||||
<created>2015-05-17T19:24:51</created>
|
||||
<modified>2015-05-17T19:24:51</modified>
|
||||
<unit name="meter" meter="1"/>
|
||||
<up_axis>Z_UP</up_axis>
|
||||
</asset>
|
||||
<library_cameras>
|
||||
<camera id="Camera-camera" name="Camera.001">
|
||||
<optics>
|
||||
<technique_common>
|
||||
<perspective>
|
||||
<xfov sid="xfov">49.13434</xfov>
|
||||
<aspect_ratio>1.777778</aspect_ratio>
|
||||
<znear sid="znear">0.1</znear>
|
||||
<zfar sid="zfar">100</zfar>
|
||||
</perspective>
|
||||
</technique_common>
|
||||
</optics>
|
||||
<extra>
|
||||
<technique profile="blender">
|
||||
<YF_dofdist>0</YF_dofdist>
|
||||
<shiftx>0</shiftx>
|
||||
<shifty>0</shifty>
|
||||
</technique>
|
||||
</extra>
|
||||
</camera>
|
||||
<camera id="Camera_002-camera" name="Camera.002">
|
||||
<optics>
|
||||
<technique_common>
|
||||
<orthographic>
|
||||
<xmag sid="xmag">3</xmag>
|
||||
<aspect_ratio>1.777778</aspect_ratio>
|
||||
<znear sid="znear">0.1</znear>
|
||||
<zfar sid="zfar">100</zfar>
|
||||
</orthographic>
|
||||
</technique_common>
|
||||
</optics>
|
||||
<extra>
|
||||
<technique profile="blender">
|
||||
<YF_dofdist>0</YF_dofdist>
|
||||
<shiftx>0</shiftx>
|
||||
<shifty>0</shifty>
|
||||
</technique>
|
||||
</extra>
|
||||
</camera>
|
||||
<camera id="Camera_003-camera" name="Camera.003">
|
||||
<optics>
|
||||
<technique_common>
|
||||
<perspective>
|
||||
<xfov sid="xfov">29.86284</xfov>
|
||||
<aspect_ratio>1.777778</aspect_ratio>
|
||||
<znear sid="znear">0.1</znear>
|
||||
<zfar sid="zfar">50</zfar>
|
||||
</perspective>
|
||||
</technique_common>
|
||||
</optics>
|
||||
<extra>
|
||||
<technique profile="blender">
|
||||
<YF_dofdist>0</YF_dofdist>
|
||||
<shiftx>0</shiftx>
|
||||
<shifty>0</shifty>
|
||||
</technique>
|
||||
</extra>
|
||||
</camera>
|
||||
</library_cameras>
|
||||
<library_images/>
|
||||
<library_controllers/>
|
||||
<library_visual_scenes>
|
||||
<visual_scene id="Scene" name="Scene">
|
||||
<node id="Camera" name="Camera" type="NODE">
|
||||
<matrix sid="transform">7.54979e-8 0 1 10 0 1 0 0 -1 0 7.54979e-8 0 0 0 0 1</matrix>
|
||||
<instance_camera url="#Camera-camera"/>
|
||||
</node>
|
||||
<node id="Camera_002" name="Camera_002" type="NODE">
|
||||
<matrix sid="transform">7.54979e-8 0 -1 -10 0 1 0 0 1 0 7.54979e-8 0 0 0 0 1</matrix>
|
||||
<instance_camera url="#Camera_002-camera"/>
|
||||
</node>
|
||||
<node id="Camera_003" name="Camera_003" type="NODE">
|
||||
<matrix sid="transform">3.09086e-8 -1 1.58933e-8 0 -3.09086e-8 1.58933e-8 1 5 -1 -3.09086e-8 -3.09086e-8 0 0 0 0 1</matrix>
|
||||
<instance_camera url="#Camera_003-camera"/>
|
||||
</node>
|
||||
</visual_scene>
|
||||
</library_visual_scenes>
|
||||
<scene>
|
||||
<instance_visual_scene url="#Scene"/>
|
||||
</scene>
|
||||
</COLLADA>
|
Loading…
Reference in New Issue