Commit 3d52dd23 authored by Rene Engelhard's avatar Rene Engelhard

Imported Upstream version 20140924

parents

Too many changes to show.

To preserve performance only 244 of 244+ files are displayed.

cmake_minimum_required(VERSION 2.8)
project(COLLADA2GLTF)
if (NOT WIN32)
#http://www.guyrutenberg.com/2014/01/05/enabling-c11-c0x-in-cmake/
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if(COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
message("-- C++11 Enabled")
elseif(COMPILER_SUPPORTS_CXX0X)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
message("-- C++0x Enabled")
else()
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
endif()
endif()
set(USE_OPEN3DGC "ON")
set(WITH_IN_SOURCE_BUILD "ON")
set(COLLADA2GLTF_BINARY_DIR, COLLADA2GLTF_SOURCE_DIR)
set(BUILD_SHARED_LIBS "OFF")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(GetGitRevisionDescription)
get_git_head_revision(GIT_REFSPEC GIT_SHA1)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/GitSHA1.cpp.in" "${CMAKE_CURRENT_BINARY_DIR}/GitSHA1.cpp" @ONLY)
set(TARGET_LIBS GeneratedSaxParser_static OpenCOLLADABaseUtils_static UTF_static ftoa_static MathMLSolver_static OpenCOLLADASaxFrameworkLoader_static OpenCOLLADAFramework_static buffer_static)
if (NOT WIN32)
set(CMAKE_FIND_LIBRARY_SUFFIXES .so .a .dylib)
endif()
# Lets libxml2 work in a shared library
add_definitions(-DLIBXML_STATIC_FOR_DLL)
IF(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")
ADD_DEFINITIONS(-fPIC)
ENDIF(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")
include_directories(${COLLADA2GLTF_SOURCE_DIR})
include_directories(${COLLADA2GLTF_SOURCE_DIR}/GLTF)
include_directories(${COLLADA2GLTF_SOURCE_DIR}/JSON)
include_directories(${COLLADA2GLTF_SOURCE_DIR}/shaders)
include_directories(${COLLADA2GLTF_SOURCE_DIR}/helpers)
include_directories(${COLLADA2GLTF_SOURCE_DIR}/convert)
include_directories(${COLLADA2GLTF_SOURCE_DIR}/assetModifiers)
include_directories(${COLLADA2GLTF_SOURCE_DIR}/dependencies/json/include/rapidjson)
include_directories(${COLLADA2GLTF_SOURCE_DIR}/dependencies/OpenCOLLADA/COLLADAFramework/include)
include_directories(${COLLADA2GLTF_SOURCE_DIR}/dependencies/OpenCOLLADA/COLLADABaseUtils/include)
include_directories(${COLLADA2GLTF_SOURCE_DIR}/dependencies/OpenCOLLADA/COLLADASaxFrameworkLoader/include)
include_directories(${COLLADA2GLTF_SOURCE_DIR}/dependencies/OpenCOLLADA/GeneratedSaxParser/include)
if (WIN32)
include_directories(${COLLADA2GLTF_SOURCE_DIR}/dependencies/misc)
endif()
if (USE_OPEN3DGC)
add_definitions( -DUSE_OPEN3DGC )
include_directories(${COLLADA2GLTF_SOURCE_DIR}/extensions/o3dgc-compression)
include_directories(${COLLADA2GLTF_SOURCE_DIR}/dependencies/o3dgc/src)
include_directories(${COLLADA2GLTF_SOURCE_DIR}/dependencies/o3dgc/src/o3dgc_common_lib/inc)
include_directories(${COLLADA2GLTF_SOURCE_DIR}/dependencies/o3dgc/src/o3dgc_encode_lib/inc)
include_directories(${COLLADA2GLTF_SOURCE_DIR}/dependencies/o3dgc/src/o3dgc_decode_lib/inc)
endif()
find_package(PNG)
if (PNG_FOUND)
include_directories(${PNG_INCLUDE_DIR})
include_directories(${ZLIB_INCLUDE_DIR})
add_definitions(-DUSE_LIBPNG)
else()
message(WARNING "libpng or one of its dependencies couldn't be found. Transparency may not be correctly detected.")
endif()
link_directories(${COLLADA2GLTF_BINARY_DIR}/lib)
if (WIN32)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
add_definitions(-DWIN32)
add_definitions(-EHsc)
endif()
add_subdirectory(dependencies/OpenCOLLADA)
if (USE_OPEN3DGC)
add_subdirectory(dependencies/o3dgc/src)
endif()
set(GLTF_SOURCES
COLLADA2GLTFWriter.h
COLLADA2GLTFWriter.cpp
GLTFOpenCOLLADA.h
GLTFOpenCOLLADAUtils.h
GLTFOpenCOLLADAUtils.cpp
GLTF/GLTFAccessorCache.cpp
GLTF/GLTFAccessorCache.h
GLTF/GLTFAsset.cpp
GLTF/GLTFAnimation.cpp
GLTF/GLTFAccessor.cpp
GLTF/GLTFBuffer.cpp
GLTF/GLTFEffect.cpp
GLTF/GLTFExtras.cpp
GLTF/GLTFMesh.cpp
GLTF/GLTFPrimitive.cpp
GLTF/GLTFUtils.cpp
GLTF/GLTFWriter.cpp
GLTF/GLTFSkin.cpp
GLTF/GLTF.h
GLTF/GLTFTypesAndConstants.h
GLTF/GLTFAsset.h
GLTF/GLTFAnimation.h
GLTF/GLTFAccessor.h
GLTF/GLTFBuffer.h
GLTF/GLTFEffect.h
GLTF/GLTFExtras.h
GLTF/GLTFMesh.h
GLTF/GLTFPrimitive.h
GLTF/GLTFUtils.h
GLTF/GLTFWriter.h
GLTF/GLTFSkin.h
GLTF/GLTFExtraDataHandler.h
GLTF/GLTFExtraDataHandler.cpp
GLTF/GLTFProfile.h
GLTF/GLTFProfile.cpp
GLTF/GLTFInputStream.h
GLTF/GLTFInputStream.cpp
GLTF/GLTFOutputStream.h
GLTF/GLTFOutputStream.cpp
GLTF/GLTFConfig.cpp
GLTF/GLTFConfig.h
profiles/webgl-1.0/webgl-idl.h
profiles/webgl-1.0/GLTFWebGL_1_0_Profile.cpp
profiles/webgl-1.0/GLTFWebGL_1_0_Profile.h
shaders/commonProfileShaders.h
shaders/commonProfileShaders.cpp
helpers/geometryHelpers.h
helpers/geometryHelpers.cpp
helpers/mathHelpers.h
helpers/mathHelpers.cpp
helpers/encodingHelpers.h
helpers/encodingHelpers.cpp
convert/meshConverter.cpp
convert/meshConverter.h
convert/animationConverter.cpp
convert/animationConverter.h
JSON/JSONArray.cpp
JSON/JSONNumber.cpp
JSON/JSONObject.cpp
JSON/JSONString.cpp
JSON/JSONValue.cpp
JSON/JSONArray.h
JSON/JSONNumber.h
JSON/JSONObject.h
JSON/JSONString.h
JSON/JSONValue.h
assetModifiers/GLTFAssetModifier.h
assetModifiers/GLTFFlipUVModifier.h
assetModifiers/GLTFFlipUVModifier.cpp
${CMAKE_CURRENT_BINARY_DIR}/GitSHA1.cpp
GitSHA1.h)
if (USE_OPEN3DGC)
LIST(APPEND GLTF_SOURCES
extensions/o3dgc-compression/GLTF-Open3DGC.cpp
extensions/o3dgc-compression/GLTF-Open3DGC.h)
endif()
option(CONVERT_SHARED "CONVERT_SHARED" OFF)
if (CONVERT_SHARED)
add_library(collada2gltfConvert SHARED ${GLTF_SOURCES})
#Make sure the dll is in the same directory as the executable
if (WIN32)
set_target_properties(collada2gltfConvert PROPERTIES RUNTIME_OUTPUT_DIRECTORY "bin")
endif()
else()
add_library(collada2gltfConvert STATIC ${GLTF_SOURCES})
add_definitions(-DSTATIC_COLLADA2GLTF)
endif()
if (PNG_FOUND)
LIST(APPEND TARGET_LIBS ${PNG_LIBRARY} ${ZLIB_LIBRARY})
endif()
if (USE_OPEN3DGC)
LIST(APPEND TARGET_LIBS o3dgc_common_lib o3dgc_enc_lib o3dgc_dec_lib)
endif()
IF("${CMAKE_SYSTEM}" MATCHES "Linux")
LIST(APPEND TARGET_LIBS rt)
endif("${CMAKE_SYSTEM}" MATCHES "Linux")
target_link_libraries (collada2gltfConvert ${TARGET_LIBS})
set(GLTF_EXE_SOURCES main.cpp
${CMAKE_CURRENT_BINARY_DIR}/GitSHA1.cpp
GitSHA1.h)
if (WIN32)
LIST(APPEND GLTF_EXE_SOURCES ${COLLADA2GLTF_SOURCE_DIR}/dependencies/misc/getopt_long.c ${COLLADA2GLTF_SOURCE_DIR}/dependencies/misc/getopt.c ${COLLADA2GLTF_SOURCE_DIR}/dependencies/misc/getopt.h)
endif()
add_executable(collada2gltf ${GLTF_EXE_SOURCES})
target_link_libraries (collada2gltf collada2gltfConvert)
// Copyright (c) 2012, Motorola Mobility, Inc.
// All rights reserved.
//
// Redistribution and use 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 Motorola Mobility, Inc. nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// 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 <COPYRIGHT HOLDER> BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef __COLLADA2GLTFEXPORT_H__
#define __COLLADA2GLTFEXPORT_H__
#ifdef STATIC_COLLADA2GLTF
# define COLLADA2GLTF_EXPORT
#else
# ifdef WIN32
# ifdef collada2gltfConvert_EXPORTS
# define COLLADA2GLTF_EXPORT __declspec(dllexport)
# else
# define COLLADA2GLTF_EXPORT __declspec(dllimport)
# endif
# else
# define COLLADA2GLTF_EXPORT
# endif // WIN32
#endif // STATIC_COLLADA2GLTF
#endif
\ No newline at end of file
// Copyright (c) 2012, Motorola Mobility, Inc.
// All rights reserved.
//
// Redistribution and use 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 Motorola Mobility, Inc. nor the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// 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 <COPYRIGHT HOLDER> 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.
// reminder; to run recursively against all dae files: find . -name '*.dae' -exec dae2json {} \;
#include "COLLADA2GLTFWriter.h"
#include "GLTFOpenCOLLADAUtils.h"
#include "GLTFExtraDataHandler.h"
#include "COLLADASaxFWLLoader.h"
#include "COLLADAFWFileInfo.h"
#include "GLTF-Open3DGC.h"
#include "profiles/webgl-1.0/GLTFWebGL_1_0_Profile.h"
#include "GitSHA1.h"
#include <algorithm>
#include "commonProfileShaders.h"
#include "helpers/encodingHelpers.h"
#include "COLLADAFWFileInfo.h"
#if __cplusplus <= 199711L
using namespace std::tr1;
#endif
using namespace std;
using namespace COLLADAFW;
using namespace COLLADABU;
using namespace COLLADASaxFWL;
using namespace rapidjson;
namespace GLTF
{
/*
*/
COLLADA2GLTFWriter::COLLADA2GLTFWriter(shared_ptr<GLTFAsset> asset):
_asset(asset),
_visualScene(0){
}
/*
*/
COLLADA2GLTFWriter::~COLLADA2GLTFWriter() {
}
/*
*/
void COLLADA2GLTFWriter::reportError( const std::string& method, const std::string& message) {
printf("ERROR: method:%s message:%s\n", method.c_str(), message.c_str());
}
/*
*/
bool COLLADA2GLTFWriter::write() {
this->_extraDataHandler = new ExtraDataHandler();
//To comply with macro to access config
GLTFAsset *asset = this->_asset.get();
asset->setExtras(this->_extraDataHandler->allExtras());
asset->prepareForProfile(shared_ptr <GLTFWebGL_1_0_Profile> (new GLTFWebGL_1_0_Profile()));
COLLADAFW::Root root(&this->_loader, this);
this->_loader.registerExtraDataCallbackHandler(this->_extraDataHandler);
if (!root.loadDocument(asset->getInputFilePath())) {
delete _extraDataHandler;
return false;
}
asset->write();
// Cleanup IDs and Technique cache in case we have another conversion
GLTFUtils::resetIDCount();
clearCommonProfileTechniqueCache();
delete _extraDataHandler;
return true;
}
//--------------------------------------------------------------------
void COLLADA2GLTFWriter::cancel( const std::string& errorMessage ) {
printf("CONVERTION ABORTED: message:%s\n", errorMessage.c_str());
}
//--------------------------------------------------------------------
void COLLADA2GLTFWriter::start() {
}
//--------------------------------------------------------------------
void COLLADA2GLTFWriter::finish() {
}
//--------------------------------------------------------------------
bool COLLADA2GLTFWriter::writeGlobalAsset( const COLLADAFW::FileInfo* globalAsset ) {
GLTFAsset* asset = this->_asset.get();
shared_ptr<JSONObject> assetObject = asset->root()->createObjectIfNeeded(kAsset);
std::string version = "collada2gltf@"+std::string(g_GIT_SHA1);
assetObject->setString("generator",version);
assetObject->setBool(kPremultipliedAlpha, CONFIG_BOOL(asset, kPremultipliedAlpha));
assetObject->setString(kProfile, asset->profile()->id());
assetObject->setDouble(kVersion, glTFVersion);
_metersPerUnit = globalAsset->getUnit().getLinearUnitMeter();
if (globalAsset->getUpAxisType() == COLLADAFW::FileInfo::X_UP ||
globalAsset->getUpAxisType() == COLLADAFW::FileInfo::Z_UP)
{
COLLADABU::Math::Matrix4 matrix = COLLADABU::Math::Matrix4::IDENTITY;
if (globalAsset->getUpAxisType() == COLLADAFW::FileInfo::X_UP)
{
// Rotate -90 deg around Z
matrix.setElement(0, 0, 0.0f);
matrix.setElement(0, 1, -1.0f);
matrix.setElement(1, 0, 1.0f);
matrix.setElement(1, 1, 0.0f);
}
else // Z_UP
{
// Rotate 90 deg around X
matrix.setElement(1, 1, 0.0f);
matrix.setElement(1, 2, 1.0f);
matrix.setElement(2, 1, -1.0f);
matrix.setElement(2, 2, 0.0f);
}
_rootTransform = std::shared_ptr<GLTF::JSONObject>(new GLTF::JSONObject());
_rootTransform->setString(kName, "Y_UP_Transform");
_rootTransform->setValue("matrix", serializeOpenCOLLADAMatrix4(matrix));
shared_ptr <GLTF::JSONArray> childrenArray(new GLTF::JSONArray());
_rootTransform->setValue(kChildren, childrenArray);
}
asset->setDistanceScale(globalAsset->getUnit().getLinearUnitMeter());
return true;
}
//--------------------------------------------------------------------
float COLLADA2GLTFWriter::getTransparency(const COLLADAFW::EffectCommon* effectCommon) {
GLTFAsset* asset = this->_asset.get();
//super naive for now, also need to check sketchup work-around
if (effectCommon->getOpacity().isTexture()) {
return 1;
}
float transparency = static_cast<float>(effectCommon->getOpacity().getColor().getAlpha());
return CONFIG_BOOL(asset, "invertTransparency") ? 1 - transparency : transparency;
}
float COLLADA2GLTFWriter::isOpaque(const COLLADAFW::EffectCommon* effectCommon) {
return getTransparency(effectCommon) >= 1;
}
void COLLADA2GLTFWriter::registerObjectWithOriginalUID(std::string originalId, shared_ptr <JSONObject> obj, shared_ptr <JSONObject> objLib) {
if (this->_asset->_originalIDToTrackedObject.count(originalId) == 0) {
if (!objLib->contains(originalId)) {
objLib->setValue(originalId, obj);
this->_asset->_originalIDToTrackedObject[originalId] = obj;
} else {
this->_asset->log("WARNING:Object with id:%s is already tracked, failed attempt to add object\n", originalId.c_str());
}
} else {
this->_asset->log("WARNING:Object with id:%s is already tracked, failed attempt to add object\n", originalId.c_str());
}
}
void COLLADA2GLTFWriter::_storeMaterialBindingArray(const std::string& prefix,
const std::string& nodeUID,
const std::string& meshUID,
MaterialBindingArray &materialBindings) {
if (this->_asset->containsValueForUniqueId(meshUID) == false) {
return;
}
shared_ptr <GLTFMesh> mesh = static_pointer_cast<GLTFMesh>(this->_asset->getValueForUniqueId(meshUID));
this->_asset->setOriginalId(meshUID, mesh->getID());
MaterialBindingsForNodeUID& mb = this->_asset->materialBindingsForNodeUID();
shared_ptr <MaterialBindingsForMeshUID> materialBindingsMap;
if (mb.count(nodeUID) == 0) {
materialBindingsMap = shared_ptr<MaterialBindingsForMeshUID>(new MaterialBindingsForMeshUID());
mb[nodeUID] = materialBindingsMap;
} else {
materialBindingsMap = mb[nodeUID];
}
//apply prefix on MeshUID
std::string prefixedMeshUID = prefix + meshUID;
shared_ptr <MaterialBindingsPrimitiveMap> materialBindingsPrimitiveMap;
if (materialBindingsMap->count(prefixedMeshUID) == 0) {
materialBindingsPrimitiveMap = shared_ptr<MaterialBindingsPrimitiveMap> (new MaterialBindingsPrimitiveMap());
(*materialBindingsMap)[prefixedMeshUID] = materialBindingsPrimitiveMap;
} else {
materialBindingsPrimitiveMap = (*materialBindingsMap)[prefixedMeshUID];
}
GLTF::JSONValueVector primitives = mesh->getPrimitives()->values();
for (size_t j = 0 ; j < primitives.size() ; j++) {
shared_ptr <GLTF::GLTFPrimitive> primitive = static_pointer_cast<GLTFPrimitive>(primitives[j]);
//FIXME: consider optimizing this with a hashtable, would be better if it was coming that way from OpenCOLLADA
int materialBindingIndex = -1;
for (size_t k = 0; k < materialBindings.getCount() ; k++) {
if (materialBindings[k].getMaterialId() == primitive->getMaterialObjectID()) {
materialBindingIndex = (int)k;
}
}
if (materialBindingIndex != -1) {
shared_ptr <COLLADAFW::MaterialBinding> materialBinding(new COLLADAFW::MaterialBinding(materialBindings[materialBindingIndex]));
(*materialBindingsPrimitiveMap)[primitive->getMaterialObjectID()] = materialBinding;
}
}
return;
}
bool COLLADA2GLTFWriter::writeNode( const COLLADAFW::Node* node,
shared_ptr <GLTF::JSONObject> nodesObject,
COLLADABU::Math::Matrix4 parentMatrix,
SceneFlatteningInfo* sceneFlatteningInfo) {
GLTFAsset *asset = this->_asset.get();
bool shouldExportTRS = CONFIG_BOOL(asset, "alwaysExportTRS");
const NodePointerArray& nodes = node->getChildNodes();
std::string nodeOriginalID = node->getOriginalId();
if (nodeOriginalID.length() == 0) {
nodeOriginalID = uniqueIdWithType(kNode, node->getUniqueId());
}
std::string uniqueUID = node->getUniqueId().toAscii();
COLLADABU::Math::Matrix4 matrix = COLLADABU::Math::Matrix4::IDENTITY;
shared_ptr <GLTF::JSONObject> nodeObject(new GLTF::JSONObject());
nodeObject->setString(kName,node->getName());
this->_asset->_uniqueIDToOpenCOLLADAObject[uniqueUID] = shared_ptr <COLLADAFW::Object> (node->clone());
this->_asset->setOriginalId(uniqueUID, nodeOriginalID);
this->_asset->setValueForUniqueId(uniqueUID, nodeObject);
if (node->getType() == COLLADAFW::Node::JOINT) {
const string& sid = node->getSid();
nodeObject->setString(kJointName,sid);
}
bool nodeContainsLookAtTr = false;
const InstanceCameraPointerArray& instanceCameras = node->getInstanceCameras();
size_t camerasCount = instanceCameras.getCount();
if (camerasCount > 0) {
InstanceCamera* instanceCamera = instanceCameras[0];
shared_ptr <GLTF::JSONObject> cameraObject(new GLTF::JSONObject());
std::string cameraId = uniqueIdWithType(kCamera, instanceCamera->getInstanciatedObjectId());
nodeObject->setString(kCamera, cameraId);
//FIXME: just handle the first camera within a node now
//for (size_t i = 0 ; i < camerasCount ; i++) {
//}
//Checks if we have a "look at" transformm because it is not handled by getTransformationMatrix when baking the matrix. (TODO: file a OpenCOLLADA issue for that).
const TransformationPointerArray& transformations = node->getTransformations();
size_t transformationsCount = transformations.getCount();
for (size_t i = 0 ; i < transformationsCount ; i++) {
const Transformation* tr = transformations[i];
if (tr->getTransformationType() == Transformation::LOOKAT) {
Lookat* lookAt = (Lookat*)tr;
buildLookAtMatrix(lookAt, matrix);
nodeContainsLookAtTr = true;
break;
}
}
if (nodeContainsLookAtTr && (transformationsCount > 1)) {
//FIXME: handle warning/error
this->_asset->log("WARNING: node contains a look at transform combined with other transforms\n");
}
}
if (!nodeContainsLookAtTr) {
node->getTransformationMatrix(matrix);
}
float scale[3];
float translation[3];
float rotation[4];
const TransformationPointerArray& transformations = node->getTransformations();
size_t transformationsCount = transformations.getCount();
for (size_t i = 0 ; i < transformationsCount ; i++) {
const Transformation* tr = transformations[i];
const UniqueId& animationListID = tr->getAnimationList();
if (!animationListID.isValid())
continue;
shared_ptr<AnimatedTargets> animatedTargets(new AnimatedTargets());
this->_asset->_uniqueIDToAnimatedTargets[animationListID.toAscii()] = animatedTargets;
shared_ptr <JSONObject> animatedTarget(new JSONObject());
std::string animationID = animationListID.toAscii();
animatedTarget->setString(kTarget, uniqueUID);
animatedTarget->setString("transformId", animationID);
if (tr->getTransformationType() == COLLADAFW::Transformation::MATRIX) {
animatedTarget->setString("path", "MATRIX");
animatedTargets->push_back(animatedTarget);
shouldExportTRS = true;
}
if (tr->getTransformationType() == COLLADAFW::Transformation::TRANSLATE) {
animatedTarget->setString("path", "translation");
animatedTargets->push_back(animatedTarget);
shouldExportTRS = true;
}
if (tr->getTransformationType() == COLLADAFW::Transformation::ROTATE) {
animatedTarget->setString("path", "rotation");
animatedTargets->push_back(animatedTarget);
shouldExportTRS = true;
}
if (tr->getTransformationType() == COLLADAFW::Transformation::SCALE) {
animatedTarget->setString("path", "scale");
animatedTargets->push_back(animatedTarget);
shouldExportTRS = true;
}
}
const COLLADABU::Math::Matrix4 worldMatrix = parentMatrix * matrix;
if (shouldExportTRS) {
GLTF::decomposeMatrix(matrix, translation, rotation, scale);
// Scale distance units if we need to
translation[0] *= (float)_asset->getDistanceScale();
translation[1] *= (float)_asset->getDistanceScale();
translation[2] *= (float)_asset->getDistanceScale();
bool exportDefaultValues = CONFIG_BOOL(asset, "exportDefaultValues");
bool exportTranslation = !(!exportDefaultValues &&
((translation[0] == 0) && (translation[1] == 0) && (translation[2] == 0)));
if (exportTranslation)
nodeObject->setValue("translation", serializeVec3(translation[0], translation[1], translation[2]));