From 8b6c6613f9b1408f43f2e411789401966941624d Mon Sep 17 00:00:00 2001 From: twhittock Date: Tue, 4 Dec 2018 14:44:49 +0000 Subject: [PATCH] collada export: Use Camera local coordinate system Fixes #2255 --- code/ColladaExporter.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/code/ColladaExporter.cpp b/code/ColladaExporter.cpp index 96421a532..0d5bdd46d 100644 --- a/code/ColladaExporter.cpp +++ b/code/ColladaExporter.cpp @@ -1533,7 +1533,23 @@ void ColladaExporter::WriteNode( const aiScene* pScene, aiNode* pNode) // write transformation - we can directly put the matrix there // TODO: (thom) decompose into scale - rot - quad to allow addressing it by animations afterwards - const aiMatrix4x4& mat = pNode->mTransformation; + aiMatrix4x4 mat = pNode->mTransformation; + + // If this node is a Camera node, the camera coordinate system needs to be multiplied in. + // When importing from Collada, the mLookAt is set to 0, 0, -1, and the node transform is unchanged. + // When importing from a different format, mLookAt is set to 0, 0, 1. Therefore, the local camera + // coordinate system must be changed to matche the Collada specification. + for (size_t i = 0; imNumCameras; i++){ + if (mScene->mCameras[i]->mName == pNode->mName){ + aiMatrix4x4 sourceView; + mScene->mCameras[i]->GetCameraMatrix(sourceView); + + aiMatrix4x4 colladaView; + colladaView.a1 = colladaView.c3 = -1; // move into -z space. + mat *= (sourceView * colladaView); + break; + } + } // customized, sid should be 'matrix' to match with loader code. //mOutput << startstr << "";