$(slp_platform_abstraction_src_dir)/resource-loader/resource-loader.cpp \
$(slp_platform_abstraction_src_dir)/resource-loader/resource-requester-base.cpp \
$(slp_platform_abstraction_src_dir)/resource-loader/resource-bitmap-requester.cpp \
- $(slp_platform_abstraction_src_dir)/resource-loader/resource-model-requester.cpp \
$(slp_platform_abstraction_src_dir)/resource-loader/resource-shader-requester.cpp \
$(slp_platform_abstraction_src_dir)/resource-loader/resource-text-requester.cpp \
\
$(slp_platform_abstraction_src_dir)/resource-loader/resource-thread-base.cpp \
$(slp_platform_abstraction_src_dir)/resource-loader/resource-thread-image.cpp \
- $(slp_platform_abstraction_src_dir)/resource-loader/resource-thread-model.cpp \
$(slp_platform_abstraction_src_dir)/resource-loader/resource-thread-shader.cpp \
$(slp_platform_abstraction_src_dir)/resource-loader/resource-thread-text.cpp \
\
- $(slp_platform_abstraction_src_dir)/resource-loader/binary-model-builder.cpp \
\
$(slp_platform_abstraction_src_dir)/resource-loader/debug/resource-loader-debug.cpp \
\
slp_jpeg_loader = \
$(slp_platform_abstraction_src_dir)/image-loaders/loader-jpeg.cpp
-slp_assimp_src_files = \
- $(slp_platform_abstraction_src_dir)/resource-loader/assimp-proxy.cpp \
- $(slp_platform_abstraction_src_dir)/resource-loader/assimp-model-builder.cpp \
- $(slp_platform_abstraction_src_dir)/resource-loader/left-hand-convertor.cpp
-
-slp_assimp_stub_src_files = \
- $(slp_platform_abstraction_src_dir)/resource-loader/assimp-stubs.cpp
-
# Add public headers here:
# platform_abstraction_header_files =
+++ /dev/null
-/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-
-#include "assimp-loader.h"
-#include <assimp/assimp.hpp>
-#include <stdio.h>
-
-
-namespace Dali
-{
-namespace SlpPlatform
-{
-
-AssimpIOStream::AssimpIOStream()
-: Assimp::IOStream(),
- mLoader(NULL)
-{
-}
-
-AssimpIOStream::AssimpIOStream(FILE* loader)
-: Assimp::IOStream(),
- mLoader(loader)
-{
-}
-
-AssimpIOStream::~AssimpIOStream()
-{
- if (NULL != mLoader)
- {
- fclose(mLoader);
- mLoader = NULL;
- }
-}
-
-size_t AssimpIOStream::Read(void *pvBuffer, size_t pSize, size_t pCount)
-{
- int elementCount = 0;
-
- if (NULL != mLoader && 0 != pSize && 0 != pCount)
- {
- elementCount = fread(pvBuffer, pSize, pCount, mLoader);
- }
-
- return elementCount;
-}
-
-size_t AssimpIOStream::Write(const void *pvBuffer, size_t pSize, size_t pCount)
-{
- return 0;
-}
-
-aiReturn AssimpIOStream::Seek(size_t pOffset, aiOrigin pOrigin)
-{
- aiReturn status = aiReturn_FAILURE;
- if (NULL != mLoader)
- {
- if( 0 <= fseek(mLoader, pOffset, aiOrigin_SET == pOrigin ? SEEK_SET :
- (aiOrigin_CUR == pOrigin ? SEEK_CUR : SEEK_END)) )
- {
- status = aiReturn_SUCCESS;
- }
- }
- return status;
-}
-
-size_t AssimpIOStream::Tell() const
-{
- size_t filePosition = 0;
-
- if (NULL != mLoader)
- {
- long positionIndicator = ftell( mLoader );
- if( positionIndicator > -1L )
- {
- filePosition = static_cast<unsigned int>(positionIndicator);
- }
- else
- {
- DALI_LOG_ERROR("Error finding the current file offset\n");
- }
- }
-
- return filePosition;
-}
-
-size_t AssimpIOStream::FileSize() const
-{
- size_t fileSize = 0;
-
- if (NULL != mLoader)
- {
- size_t pos = 0u;
-
- long positionIndicator = ftell( mLoader );
- if( positionIndicator > -1L )
- {
- pos = static_cast<unsigned int>(positionIndicator);
- }
- else
- {
- DALI_LOG_ERROR("Error finding the current file offset\n");
- }
-
- if (0 == fseek(mLoader, 0, SEEK_END) )
- {
- positionIndicator = ftell( mLoader );
- if ( positionIndicator > -1L )
- {
- fileSize = static_cast<unsigned int>(positionIndicator);
- }
- else
- {
- DALI_LOG_ERROR("Error finding file size\n");
- }
- }
-
- if( fseek(mLoader, pos, SEEK_SET) )
- {
- DALI_LOG_ERROR("Error seeking to previous position\n");
- }
- }
-
- return fileSize;
-}
-
-void AssimpIOStream::Flush()
-{
- fflush(mLoader);
-}
-
-AssimpIOSystem::AssimpIOSystem()
-: Assimp::IOSystem()
-{
-}
-
-AssimpIOSystem::~AssimpIOSystem()
-{
-}
-
-bool AssimpIOSystem::Exists(const std::string& pFile) const
-{
- return Exists(pFile.c_str());
-}
-
-bool AssimpIOSystem::Exists(const char* pFile) const
-{
- FILE* fp;
-
- fp = fopen(pFile, "rb");
- if (fp)
- {
- fclose(fp);
- }
-
- return NULL != fp;
-}
-
-char AssimpIOSystem::getOsSeparator() const
-{
- return '/';
-}
-
-Assimp::IOStream* AssimpIOSystem::Open(const char* pFile, const char* pMode)
-{
- Assimp::IOStream* stream = NULL;
- FILE* fp = NULL;
-
- fp = fopen(pFile, pMode);
- if (NULL != fp)
- {
- stream = new AssimpIOStream(fp);
- }
-
- return stream;
-}
-
-Assimp::IOStream* AssimpIOSystem::Open(const std::string& pFile, const std::string& pMode)
-{
- return Open(pFile.c_str(), pMode);
-}
-
-void AssimpIOSystem::Close( Assimp::IOStream* pFile)
-{
- delete pFile;
-}
-
-} // namespace SlpPlatform
-} // namespace Dali
-
+++ /dev/null
-#ifndef __DALI_SLP_PLATFORM_ASSIMP_LOADER_H__
-#define __DALI_SLP_PLATFORM_ASSIMP_LOADER_H__
-
-/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <stdio.h>
-
-#include <assimp/IOStream.h>
-#include <assimp/IOSystem.h>
-
-
-namespace Dali
-{
-namespace SlpPlatform
-{
-
-class AssetLoader;
-
-/**
- * Adaptor class to allow assimp to use platform specific loader
- * on current slp platform it is a thin wrapper over the stdio functions
- */
-class AssimpIOStream : public Assimp::IOStream
-{
-protected:
- /**
- * Constructor
- */
- AssimpIOStream();
-
-public:
- /**
- * Constructor
- * @param[in] loader An AssetLoader
- */
- AssimpIOStream(FILE* loader);
-
- /**
- * Destructor.
- */
- virtual ~AssimpIOStream();
-
- /**
- * Read from the file.
- * @param pvBuffer Destination buffer
- * @param pSize Size of each element in bytes
- * @param pCount Number of elements
- * @return Number of element read.
- */
- size_t Read(void *pvBuffer, size_t pSize, size_t pCount);
-
- /**
- * Write to the file.
- * @param pvBuffer Source buffer
- * @param pSize Size of each element in bytes
- * @param pCount Number of elements
- * @return Number of element written.
- */
- size_t Write(const void *pvBuffer, size_t pSize, size_t pCount);
-
- /**
- * Set the read/write cursor of the file.
- * @param pOffset The amount to move the cursor
- * @param pOrigin Specifies the origin, start of stream, current position or end of stream
- * @return 0 if successful.
- */
- aiReturn Seek(size_t pOffset, aiOrigin pOrigin);
-
- /**
- * Get the current position of the read/write cursor.
- * @return The current position of the read/write cursor.
- */
- size_t Tell() const;
-
- /**
- * Returns file size.
- * @return The file size.
- */
- size_t FileSize() const;
-
- /**
- * Flush the contents of the file buffer (for writers) See fflush() for more details.
- */
- void Flush();
-
-private:
- FILE* mLoader;
-
-}; // class AssimpIOStream
-
-/**
- * Interface to the file system.
- */
-class AssimpIOSystem : public Assimp::IOSystem
-{
-public:
- /**
- * Default constructor.
- * Create an instance and assign it to on Assimp::Importer using
- * Assimp::Importer::SetIOHandler
- */
- AssimpIOSystem();
-
- /**
- * Virtual destructor.
- */
- virtual ~AssimpIOSystem();
-public:
-
- /**
- * Tests for the existence of a file at the given path.
- * @param pFile The file name and path.
- * @return true if the file exists.
- */
- bool Exists(const std::string& pFile) const;
-
- /**
- * @copydoc Exists(const std::string&)const
- */
- bool Exists(const char* pFile) const;
-
- /**
- * Returns the system specific directory separator
- * @return System specific directory separator
- */
- char getOsSeparator() const;
-
- /**
- * Open a file with a given path.
- * @param pFile Path to the file
- * @param pMode Desired file I/O mode.
- * @return new AssimpIOStream
- */
- Assimp::IOStream* Open(const char* pFile, const char* pMode = "rb");
-
- /**
- * @copydoc Open(const char*,const char*)
- */
- Assimp::IOStream* Open(const std::string& pFile, const std::string& pMode = std::string("rb"));
-
- /**
- * Closes the given file and releases all resources associated with it.
- * @param pFile The file instance previously created by Open().
- */
- void Close(Assimp::IOStream* pFile);
-}; // class AssimpIOSystem
-
-} // namespace SlpPlatform
-} // namespace Dali
-
-#endif // __DALI_SLP_PLATFORM_ASSIMP_LOADER_H__
+++ /dev/null
-/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-// CLASS HEADER
-#include "assimp-model-builder.h"
-
-// EXTERNAL INCLUDES
-#include <libgen.h>
-#include <assimp/assimp.hpp>
-#include <assimp/aiScene.h>
-#include <assimp/aiPostProcess.h> // Post processing flags
-#include <cstdio>
-
-#include <dali/public-api/common/light.h>
-#include <dali/public-api/math/matrix.h>
-#include <dali/public-api/math/vector2.h>
-#include <dali/public-api/geometry/mesh-data.h>
-#include <dali/public-api/modeling/bone.h>
-#include <dali/public-api/modeling/entity.h>
-#include <dali/public-api/modeling/entity-animator-map.h>
-#include <dali/public-api/modeling/model-data.h>
-#include <dali/public-api/modeling/model-animation-map.h>
-#include <dali/public-api/animation/key-frames.h>
-#include <dali/integration-api/debug.h>
-
-// INTERNAL INCLUDES
-#include "assimp-proxy.h"
-#include "left-hand-convertor.h"
-
-namespace Dali
-{
-namespace SlpPlatform
-{
-
-struct BoneWeight
-{
- size_t boneIdx;
- float weight;
- BoneWeight(size_t aBoneIdx, float aWeight) : boneIdx(aBoneIdx), weight(aWeight) {}
-};
-
-typedef std::vector<std::vector<BoneWeight> > VertexWeights;
-
-/********************************************************************************
- *
- */
-AssimpModelBuilder::AssimpModelBuilder(AssimpProxy* importer, const std::string& name)
- : mFilename(name), mModelName(), mModelImporter(importer)
-{
-}
-
-/********************************************************************************
- *
- */
-AssimpModelBuilder::~AssimpModelBuilder()
-{
-}
-
-/********************************************************************************
- * Return the base name of the model filename
- */
-const std::string& AssimpModelBuilder::GetModelName()
-{
- char* filename;
- if( 0 != asprintf(&filename, "%s", mFilename.c_str()) )
- {
- mModelName = basename( filename );
- free( filename );
- }
- return mModelName;
-}
-
-/********************************************************************************
- * Build the internal model
- */
-bool AssimpModelBuilder::Build(ModelData model)
-{
- bool built = false;
-
- if (mFilename.empty())
- {
- DALI_LOG_ERROR("empty filename");
- return built;
- }
-
- unsigned int ppSteps =
- aiProcess_FlipUVs | // Flip all UV coordinates along the y-axis
- aiProcess_Triangulate | // Make triangular faces
- aiProcess_JoinIdenticalVertices | // Join identical vertices / optimize indexing
- aiProcess_FixInfacingNormals | // Inverts all in-facing normals.
- aiProcess_ValidateDataStructure | // perform a full validation of the loader's output
- aiProcess_ImproveCacheLocality | // improve the cache locality of the output vertices
- aiProcess_RemoveRedundantMaterials | // remove redundant materials
- aiProcess_FindInvalidData | // detect invalid model data, such as invalid normal vectors
- aiProcess_GenUVCoords | // convert spherical, cylindrical, box and planar mapping to proper UVs
- aiProcess_TransformUVCoords | // preprocess UV transformations (scaling, translation ...)
- aiProcess_FindInstances | // search for instanced meshes and remove them by references to one master
- aiProcess_LimitBoneWeights | // limit bone weights to 4 per vertex
- aiProcess_OptimizeMeshes | // join small meshes, if possible;
- aiProcess_SortByPType |
- 0;
-
- //------------- Load/Parse model file -------------//
-
- AssimpScene scene(mModelImporter, mFilename, ppSteps);
- const aiScene* ai_scene = scene.GetScene();
- if (!ai_scene)
- {
- return false;
- }
-
- // Translate from X right, Y up, Z forward to X right, Y down, Z foward
- LeftHandConvertor lhConvertor(ai_scene);
- lhConvertor.ProcessScene();
-
- //------------- Load Materials - before meshes -------------//
- if (ai_scene->HasMaterials())
- {
- for( unsigned int materialIdx = 0; materialIdx < ai_scene->mNumMaterials; ++materialIdx)
- {
- std::string sBasePath;
- std::string::size_type position = mFilename.rfind('/', mFilename.length() - 1);
-
- if( position != std::string::npos)
- {
- sBasePath = mFilename.substr(0, position + 1);
- }
-
- Material material( BuildMaterial(ai_scene->mMaterials[materialIdx], sBasePath) );
- if (material)
- {
- model.AddMaterial(material);
- }
- }
- }
-
- //------------- Load Meshes - (Requires materials) -------------//
- if (ai_scene->HasMeshes())
- {
- for( unsigned int i = 0; i < ai_scene->mNumMeshes; ++i)
- {
- MeshData meshData;
- BuildMeshData(meshData, ai_scene, i, model);
- model.AddMesh(meshData);
- }
- }
-
- //------------- Create entities from nodes in the scene -------------//
- Matrix identityMatrix;
- identityMatrix.SetIdentity();
-
- Entity rootEntity = BuildEntity(ai_scene, ai_scene->mRootNode, &model, identityMatrix);
- model.SetRootEntity(rootEntity);
-
- //------------- Load Animations. (Requiries entities) -------------//
- if(ai_scene->HasAnimations())
- {
- ModelAnimationMapContainer& mapContainer( model.GetAnimationMapContainer() );
- mapContainer.reserve( ai_scene->mNumAnimations );
- for(unsigned int i = 0; i < ai_scene->mNumAnimations; ++i)
- {
- const aiAnimation *aiAnim = ai_scene->mAnimations[i];
-
- ModelAnimationMap animationMap(BuildAnimation(aiAnim, &model));
- mapContainer.push_back(animationMap);
- }
- }
-
- //------------- Load lights -------------//
- if (ai_scene->HasLights())
- {
- for( unsigned int i = 0; i < ai_scene->mNumLights; ++i)
- {
- Light light = BuildLight(ai_scene, i);
- model.AddLight(light);
-
- Entity entity = rootEntity.Find(light.GetName());
-
- // TODO: Could also save the entity handle in the light.
- if (entity)
- {
- entity.SetType(Entity::LIGHT);
- }
- }
- }
-
- return true;
-}
-
-
-/********************************************************************************
- * Build the mesh
- */
-void AssimpModelBuilder::BuildMeshData(MeshData& meshData, const aiScene* ai_scene, unsigned int meshIndex, ModelData& model)
-{
- if (NULL != ai_scene && meshIndex < ai_scene->mNumMeshes)
- {
- aiMesh* ai_mesh = ai_scene->mMeshes[meshIndex];
- if (NULL != ai_mesh)
- {
- unsigned int vertexCount = ai_mesh->mNumVertices;
- VertexWeights vertexWeights(vertexCount);
-
- if( ai_mesh->HasBones())
- {
- // Need to convert from bones containing vertex indices to
- // vertices containing bone indices
- for( unsigned int boneIdx = 0; boneIdx < ai_mesh->mNumBones; boneIdx++)
- {
- const aiBone* ai_bone = ai_mesh->mBones[boneIdx];
- for( unsigned int weightIdx = 0; weightIdx < ai_bone->mNumWeights; weightIdx++)
- {
- size_t vertexIdx = ai_bone->mWeights[weightIdx].mVertexId;
- vertexWeights[vertexIdx].push_back(BoneWeight(boneIdx, ai_bone->mWeights[weightIdx].mWeight));
- }
- }
- }
-
- MeshData::VertexContainer vertices( vertexCount );
- MeshData::FaceIndices faces;
- BoneContainer bones;
- for (unsigned int vertexIdx = 0; vertexIdx < vertexCount; ++vertexIdx)
- {
- MeshData::Vertex& vertex = vertices.at(vertexIdx);
- aiVector3D* ai_vector = &ai_mesh->mVertices[vertexIdx];
-
- vertex.x = ai_vector->x;
- vertex.y = ai_vector->y;
- vertex.z = ai_vector->z;
-
- if (ai_mesh->HasTextureCoords(0))
- {
- ai_vector = ai_mesh->mTextureCoords[0];
- ai_vector += vertexIdx;
- vertex.u = ai_vector->x;
- vertex.v = ai_vector->y;
- }
-
- if (ai_mesh->HasNormals())
- {
- ai_vector = &ai_mesh->mNormals[vertexIdx];
- vertex.nX = ai_vector->x;
- vertex.nY = ai_vector->y;
- vertex.nZ = ai_vector->z;
- }
-
- memset(&vertex.boneIndices[0], 0, sizeof(unsigned char) * MeshData::Vertex::MAX_BONE_INFLUENCE);
- memset(&vertex.boneWeights[0], 0, sizeof(float) * MeshData::Vertex::MAX_BONE_INFLUENCE);
-
- if( ai_mesh->HasBones())
- {
- for(size_t boneIdx=0;
- boneIdx < vertexWeights[vertexIdx].size() && boneIdx < MeshData::Vertex::MAX_BONE_INFLUENCE;
- boneIdx++)
- {
- vertex.boneIndices[boneIdx] = vertexWeights[vertexIdx][boneIdx].boneIdx;
- vertex.boneWeights[boneIdx] = vertexWeights[vertexIdx][boneIdx].weight;
- }
- }
- }
-
- if (ai_mesh->HasFaces() && ai_mesh->mPrimitiveTypes == aiPrimitiveType_TRIANGLE)
- {
- faces.resize( ai_mesh->mNumFaces * 3 );
-
- unsigned short* pIndex = &(faces)[0];
- for( unsigned int i = 0; i < ai_mesh->mNumFaces; ++i)
- {
- *pIndex++ = ai_mesh->mFaces[i].mIndices[0];
- *pIndex++ = ai_mesh->mFaces[i].mIndices[1];
- *pIndex++ = ai_mesh->mFaces[i].mIndices[2];
- }
- }
- else
- {
- DALI_LOG_ERROR("Not triangles\n");
- }
-
- if (ai_mesh->HasBones())
- {
- for(size_t boneIdx = 0; boneIdx < ai_mesh->mNumBones; ++boneIdx)
- {
- aiBone& ai_bone = *ai_mesh->mBones[boneIdx];
-
- Matrix offsetMatrix( ai_bone.mOffsetMatrix[0] );
- offsetMatrix.Transpose();
- bones.push_back( Bone( ai_bone.mName.data, offsetMatrix ) );
- }
- }
-
- meshData.SetHasTextureCoords(ai_mesh->HasTextureCoords(0));
- meshData.SetHasNormals(ai_mesh->HasNormals());
- meshData.SetData(vertices, faces, bones, model.GetMaterial(ai_mesh->mMaterialIndex));
- }
- }
-}
-
-
-/********************************************************************************
- * Build the entity
- */
-Entity AssimpModelBuilder::BuildEntity(
- const aiScene* ai_scene,
- aiNode* ai_node,
- ModelData* model,
- const Matrix& transform)
-{
- std::string name;
- if( 0 != ai_node->mName.length )
- {
- name = ai_node->mName.data;
- }
-
- Entity entity = Entity::New(name);
- if (entity)
- {
- aiMatrix4x4& m = ai_node->mTransformation;
-
- float assimpMatrix[16] = { m.a1, m.a2, m.a3, m.a4,
- m.b1, m.b2, m.b3, m.b4,
- m.c1, m.c2, m.c3, m.c4,
- m.d1, m.d2, m.d3, m.d4 };
-
- Matrix entityMatrix = Matrix( assimpMatrix );
- entityMatrix.Transpose();
- entity.SetTransformMatrix(entityMatrix);
-
- Matrix tempMatrix( false ); // Don't initialize.
- Matrix::Multiply( tempMatrix, transform, entityMatrix );
-
- if (ai_node->mNumMeshes)
- {
- entity.SetMeshCapacity(ai_node->mNumMeshes);
-
- for( unsigned int i = 0; i < ai_node->mNumMeshes; ++i)
- {
- MeshData& mesh = model->GetMesh(ai_node->mMeshes[i]);
- entity.AddMeshIndex(ai_node->mMeshes[i]);
-
- Vector4 lowerBounds( entity.GetLowerBounds() );
- Vector4 upperBounds( entity.GetUpperBounds() );
- mesh.AddToBoundingVolume( lowerBounds,
- upperBounds,
- tempMatrix );
- entity.AddToBounds( Vector3(lowerBounds), Vector3(upperBounds) );
- }
- }
-
- if (ai_node->mNumChildren)
- {
- for (unsigned int childIdx = 0; childIdx < ai_node->mNumChildren; ++childIdx)
- {
- Entity child = BuildEntity(ai_scene, ai_node->mChildren[childIdx], model, tempMatrix);
- entity.Add(child);
- entity.AddToBounds(child);
- }
- }
- }
- return entity;
-}
-
-
-
-
-/********************************************************************************
- * Create an EntityAnimatorMap
- */
-EntityAnimatorMap AssimpModelBuilder::CreateAnimator(
- aiNodeAnim* aiNode,
- float duration,
- const std::string& entityName,
- Entity animatedEntity)
-{
- Dali::KeyFrames positionKeyFrames = Dali::KeyFrames::New();
- Dali::KeyFrames scaleKeyFrames = Dali::KeyFrames::New();
- Dali::KeyFrames rotationKeyFrames = Dali::KeyFrames::New();
-
- for(unsigned int aiKeyIdx = 0; aiKeyIdx < aiNode->mNumPositionKeys; aiKeyIdx++)
- {
- aiVectorKey* position = aiNode->mPositionKeys + aiKeyIdx;
- float progress = position->mTime / duration;
- Property::Value value(Vector3(position->mValue.x, position->mValue.y, position->mValue.z));
- positionKeyFrames.Add(progress, value);
- }
-
- for(unsigned int aiKeyIdx = 0; aiKeyIdx < aiNode->mNumScalingKeys; aiKeyIdx++)
- {
- aiVectorKey* scale = aiNode->mScalingKeys + aiKeyIdx;
- float progress = scale->mTime / duration;
- Property::Value value(Vector3(scale->mValue.x, scale->mValue.y, scale->mValue.z));
- scaleKeyFrames.Add(progress, value);
- }
-
- for(unsigned int aiKeyIdx = 0; aiKeyIdx < aiNode->mNumRotationKeys; aiKeyIdx++)
- {
- aiQuatKey* rotation = aiNode->mRotationKeys + aiKeyIdx;
- float progress = rotation->mTime / duration;
- aiQuaternion* ai_rotation = & rotation->mValue;
- Quaternion quat(ai_rotation->w, ai_rotation->x, ai_rotation->y, ai_rotation->z);
- Property::Value value(quat);
- rotationKeyFrames.Add(progress, value);
- }
-
- EntityAnimatorMap entityAnim(entityName);
-
- if(aiNode->mNumPositionKeys > 0)
- {
- entityAnim.SetPositionKeyFrames(positionKeyFrames);
- }
-
- if(aiNode->mNumScalingKeys > 0)
- {
- entityAnim.SetScaleKeyFrames(scaleKeyFrames);
- }
-
- if(aiNode->mNumRotationKeys > 0)
- {
- entityAnim.SetRotationKeyFrames(rotationKeyFrames);
- }
-
- entityAnim.SetDuration(duration);
- return entityAnim;
-}
-
-/********************************************************************************
- * Build the animation. This finds each entity that each channel animates, and
- * creates a relation between them
- */
-ModelAnimationMap AssimpModelBuilder::BuildAnimation(const aiAnimation* ai_anim, ModelData* model)
-{
- ModelAnimationMap animation;
-
- animation.name = ai_anim->mName.data;
- animation.duration = ai_anim->mDuration;
- animation.repeats = 0;
-
- for(unsigned int nodeIdx = 0; nodeIdx < ai_anim->mNumChannels; nodeIdx++)
- {
- // Each node corresponds to an animation, and named after the entity it's
- // animating.
- aiNodeAnim* aiNode = ai_anim->mChannels[nodeIdx];
-
- std::string nodeName;
- if (aiNode->mNodeName.length > 0)
- {
- nodeName.assign(aiNode->mNodeName.data, aiNode->mNodeName.length);
- }
-
- Entity rootEntity = model->GetRootEntity();
- Entity animatedEntity = rootEntity.Find(nodeName);
- if(animatedEntity)
- {
- EntityAnimatorMap entityAnimator(CreateAnimator(aiNode, ai_anim->mDuration, nodeName, animatedEntity));
- animation.animators.push_back(entityAnimator);
- }
- }
-
- return animation;
-}
-
-
-/********************************************************************************
- * Build material. This loads the material attributes from the model, and loads
- * all appropriate textures.
- */
-Material AssimpModelBuilder::BuildMaterial(
- const aiMaterial* ai_material,
- const std::string& sBasePath)
-{
- Material material;
-
- if (NULL != ai_material)
- {
- aiString temporaryString;
- mModelImporter->GetMaterialString(ai_material, AI_MATKEY_NAME, &temporaryString);
-
- // create material object
- material = Material::New(temporaryString.data);
-
- float value;
- if (AI_SUCCESS == mModelImporter->GetMaterialFloat(ai_material, AI_MATKEY_OPACITY, &value))
- {
- material.SetOpacity(value);
- }
-
- if (AI_SUCCESS == mModelImporter->GetMaterialFloat(ai_material, AI_MATKEY_SHININESS, &value))
- {
- material.SetShininess(value);
- }
-
- aiColor4D tmpAiColor;
-
- if (AI_SUCCESS == mModelImporter->GetMaterialColor(ai_material, AI_MATKEY_COLOR_AMBIENT, &tmpAiColor))
- {
- material.SetAmbientColor(Vector4(tmpAiColor.r, tmpAiColor.g, tmpAiColor.b, tmpAiColor.a));
- }
-
- if (AI_SUCCESS == mModelImporter->GetMaterialColor(ai_material, AI_MATKEY_COLOR_DIFFUSE, &tmpAiColor))
- {
- material.SetDiffuseColor(Vector4(tmpAiColor.r, tmpAiColor.g, tmpAiColor.b, tmpAiColor.a));
- }
-
- if (AI_SUCCESS == mModelImporter->GetMaterialColor(ai_material, AI_MATKEY_COLOR_SPECULAR, &tmpAiColor))
- {
- material.SetSpecularColor(Vector4(tmpAiColor.r, tmpAiColor.g, tmpAiColor.b, tmpAiColor.a));
- }
-
- if (AI_SUCCESS == mModelImporter->GetMaterialColor(ai_material, AI_MATKEY_COLOR_EMISSIVE, &tmpAiColor))
- {
- material.SetEmissiveColor(Vector4(tmpAiColor.r, tmpAiColor.g, tmpAiColor.b, tmpAiColor.a));
- }
-
- std::string sPath;
-
- // Check for a diffuse texture
- if(AI_SUCCESS == mModelImporter->GetMaterialString(ai_material, AI_MATKEY_TEXTURE_DIFFUSE(0), &temporaryString))
- {
- sPath = temporaryString.data;
- if (sPath.find("Procedural") == std::string::npos)
- {
- sPath = sBasePath;
- sPath += temporaryString.data;
- material.SetDiffuseTextureFileName(sPath);
-
- int mapU, mapV;
- mModelImporter->GetMaterialInteger(ai_material, AI_MATKEY_MAPPINGMODE_U_DIFFUSE(0), &mapU);
- mModelImporter->GetMaterialInteger(ai_material, AI_MATKEY_MAPPINGMODE_V_DIFFUSE(0), &mapV);
- material.SetMapU(mapU);
- material.SetMapV(mapV);
- }
- }
-
- // Check for an opacity texture
- if(AI_SUCCESS == mModelImporter->GetMaterialString(ai_material, AI_MATKEY_TEXTURE_OPACITY(0), &temporaryString))
- {
- sPath = sBasePath;
- sPath += temporaryString.data;
- material.SetOpacityTextureFileName(sPath);
- }
-
- // Check for a normal map
- if(AI_SUCCESS == mModelImporter->GetMaterialString(ai_material, AI_MATKEY_TEXTURE_NORMALS(0), &temporaryString))
- {
- sPath = sBasePath;
- sPath += temporaryString.data;
- material.SetNormalMapFileName(sPath);
- }
- else
- {
- // Check for a height map
- if(AI_SUCCESS == mModelImporter->GetMaterialString(ai_material, AI_MATKEY_TEXTURE_HEIGHT(0), &temporaryString))
- {
- sPath = sBasePath;
- sPath += temporaryString.data;
- material.SetNormalMapFileName(sPath);
- material.SetHasHeightMap(true);
- }
- }
- }
- return material;
-}
-
-/********************************************************************************
- * Build the light from the model
- */
-Light AssimpModelBuilder::BuildLight(const aiScene* ai_scene, const unsigned int lightIndex)
-{
- Light light;
-
- if (NULL != ai_scene && lightIndex < ai_scene->mNumLights)
- {
- aiLight* ai_light = ai_scene->mLights[lightIndex];
-
- light = Light::New(ai_light->mName.data);
- light.SetSpotAngle(Vector2(ai_light->mAngleInnerCone, ai_light->mAngleOuterCone));
- light.SetAmbientColor(Vector3(ai_light->mColorAmbient.r, ai_light->mColorAmbient.g, ai_light->mColorAmbient.b));
- light.SetDiffuseColor(Vector3(ai_light->mColorDiffuse.r, ai_light->mColorDiffuse.g, ai_light->mColorDiffuse.b));
- light.SetSpecularColor(Vector3(ai_light->mColorSpecular.r, ai_light->mColorSpecular.g, ai_light->mColorSpecular.b));
- light.SetDirection(Vector3(ai_light->mDirection.x, ai_light->mDirection.y, ai_light->mDirection.z));
- }
- return light;
-}
-
-}//SlpPlatform
-
-}//Dali
+++ /dev/null
-#ifndef __DALI_SLP_PLATFORM_ASSIMP_MODEL_BUILDER_H__
-#define __DALI_SLP_PLATFORM_ASSIMP_MODEL_BUILDER_H__
-
-/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include "model-builder.h"
-
-#include <string>
-#include <assimp/assimp.hpp>
-#include <assimp/aiScene.h>
-
-#include <dali/public-api/modeling/model-data.h>
-
-namespace Dali
-{
-class Bone;
-class Mesh;
-class Entity;
-class ModelAnimationMap;
-class EntityAnimatorMap;
-
-class MeshData;
-
-namespace SlpPlatform
-{
-
-class AssimpProxy;
-
-class AssimpModelBuilder : public ModelBuilder
-{
-public:
- /**
- * Construct a Builder object with the filename of the Model to import
- * @param[in] name - the filename of the model
- */
- AssimpModelBuilder(AssimpProxy* importer, const std::string& name);
-
- /**
- * Destructor
- */
- virtual ~AssimpModelBuilder();
-
-public: // ModelBuilder Interface
-
- /**
- * Build a model structure from the Assimp scene
- * @param[inout] Model - the model to build
- */
- virtual bool Build(ModelData model);
-
- virtual const std::string& GetModelName();
-
-private:
- /**
- * Build this mesh from the assimp model.
- * @param[out] meshData - object to which the data will be written into
- * @param[in] ai_scene - the Assimp scene with the data
- * @param[in] meshIndex - the index within the ai_scene of the mesh data
- * @param[in] model - the current model
- */
- void BuildMeshData(MeshData& meshData, const aiScene* ai_scene, unsigned int meshIndex, ModelData& model);
-
- /**
- * Build this entity from the assimp model
- * @pre The internal model should already contain the assimp mesh data
- * @param[in] ai_scene - the assimp scene with the data
- * @param[in] ai_node - the assimp node to which this entity corresponds
- * @param[in] model - the current model
- * @param[in] transform - the current transform matrix to apply
- * @return An Entity object.
- */
- Entity BuildEntity(const aiScene* ai_scene, aiNode* ai_node, ModelData* model, const Matrix& transform);
-
- /**
- * Create a key frame animator from the given node.
- * @param[in] node - assimp animation node
- * @param[in] duration - length of animation in seconds
- * @return the animator data for the node
- */
- EntityAnimatorMap CreateAnimator(aiNodeAnim* aiNode, float duration, const std::string& name, Entity animatedEntity);
-
- /**
- * Build this animation from the assimp model
- * @pre The internal model should already contain all the entities of the scene, and they
- * should have an entity id set (so that the animation can be referenced back to them)
- * @param[in] ai_anim - the assimp animation
- * @param[in] model - the current internal model
- * @return The animation
- */
- ModelAnimationMap BuildAnimation(const aiAnimation *ai_anim, ModelData *model);
-
- /**
- * Build this light from the assimp model
- * @param[in] ai_scene - The assimp scene with the data
- * @param[in] lightIndex - The index of the light within the assimp scene
- * @return A valid Dali::Light handle or false on failure
- */
- Light BuildLight(const aiScene* ai_scene, const unsigned int lightIndex);
-
- /**
- * Build this material from the assimp model, and load all appropriate textures
- * @param[in] ai_material A pointer to an <a href="http://assimp.sourceforge.net/lib_html/structai_material.html">Assimp Material</a>.
- * @param[in] sBasePath The base path for any texture filenames referenced by the material
- * @return A pointer to a Material or false.
- */
- Material BuildMaterial(const aiMaterial* ai_material, const std::string& sBasePath);
-
- /**
- * Match up the bone names to entities. Goes through each mesh, and assigns the correct
- * entity onto each bone.
- * @model - the model to update
- */
- void MatchBonesToEntities(ModelData* model);
-
-
-private: // Attributes
- const std::string mFilename;
- std::string mModelName;
- AssimpProxy* mModelImporter;
-};
-
-}//SlpPlatform
-}//Dali
-
-#endif // __DALI_SLP_PLATFORM_ASSIMP_MODEL_BUILDER_H__
+++ /dev/null
-/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-#include "assimp-proxy.h"
-
-#include <stdio.h>
-#include <dlfcn.h>
-
-#include <dali/integration-api/debug.h>
-
-
-namespace Dali
-{
-namespace SlpPlatform
-{
-
-// Private typedefs for function pointers returned from dlsym().
-
-typedef const struct aiScene* PFImportFile(const char*, size_t);
-typedef void PFReleaseImport(const aiScene*);
-typedef const char* PFGetErrorString();
-
-typedef enum aiReturn PFGetMaterialColor(
- const C_STRUCT aiMaterial* pMaterial,
- const char* pKey,
- unsigned int type,
- unsigned int index,
- C_STRUCT aiColor4D* pOut);
-
-typedef enum aiReturn PFGetMaterialIntegerArray(
- const C_STRUCT aiMaterial* pMaterial,
- const char* pKey,
- unsigned int type,
- unsigned int index,
- int* pOut,
- unsigned int* pMax);
-
-typedef enum aiReturn PFGetMaterialFloatArray(
- const C_STRUCT aiMaterial* pMaterial,
- const char* pKey,
- unsigned int type,
- unsigned int index,
- float* pOut,
- unsigned int* pMax);
-
-typedef enum aiReturn PFGetMaterialString(
- const C_STRUCT aiMaterial* pMaterial,
- const char* pKey,
- unsigned int type,
- unsigned int index,
- C_STRUCT aiString* pOut);
-
-
-/**
- * Class to proxy the Assimp importer. This will allow us to dynamically load the assimp
- * library when required.
- */
-AssimpProxy::AssimpProxy()
- : mLibHandle(NULL)
-{
- mLibHandle = dlopen("libassimp.so", RTLD_LAZY);
- if(!mLibHandle)
- {
- fprintf(stderr, "Cannot load assimp library: %s\n", dlerror());
- mLibHandle = NULL;
- }
- else
- {
- // reset errors
- dlerror();
- }
-}
-
-AssimpProxy::~AssimpProxy()
-{
- if(mLibHandle != NULL)
- {
- if(dlclose(mLibHandle))
- {
- fprintf(stderr, "Error closing assimp library: %s\n", dlerror());
- }
- }
-}
-
-
-const struct aiScene* AssimpProxy::ImportFile(std::string fileName, unsigned int postProcessFlags)
-{
- const struct aiScene* scene = NULL;
- PFImportFile* aiImportFile = (PFImportFile*) dlsym(mLibHandle, "aiImportFile");
- if(aiImportFile == NULL)
- {
- fprintf(stderr, "Cannot get aiImportFile symbol from library: %s\n", dlerror());
- }
- else
- {
- dlerror();
- scene = aiImportFile(fileName.c_str(), postProcessFlags);
- }
- return scene;
-}
-
-
-void AssimpProxy::ReleaseImport(const aiScene* scene)
-{
- PFReleaseImport* aiReleaseImport = (PFReleaseImport*) dlsym(mLibHandle, "aiReleaseImport");
- if(aiReleaseImport == NULL)
- {
- fprintf(stderr, "Cannot get aiReleaseImport symbol from library: %s\n", dlerror());
- }
- else
- {
- dlerror();
- aiReleaseImport(scene);
- }
-}
-
-
-const char* AssimpProxy::GetErrorString()
-{
- const char* errorString=NULL;
-
- PFGetErrorString* aiGetErrorString = (PFGetErrorString*) dlsym(mLibHandle, "aiGetErrorString");
- if(aiGetErrorString == NULL)
- {
- fprintf(stderr, "Cannot get aiGetErrorString symbol from library: %s\n", dlerror());
- }
- else
- {
- dlerror();
- errorString = aiGetErrorString();
- }
-
- return errorString;
-}
-
-
-enum aiReturn AssimpProxy::GetMaterialColor(
- const C_STRUCT aiMaterial* material,
- const char* key,
- unsigned int type,
- unsigned int index,
- C_STRUCT aiColor4D* data)
-{
- enum aiReturn status = aiReturn_FAILURE;
-
- PFGetMaterialColor* aiGetMaterialColor = (PFGetMaterialColor*) dlsym(mLibHandle, "aiGetMaterialColor");
- if(aiGetMaterialColor == NULL)
- {
- fprintf(stderr, "Cannot get aiGetMaterialColor symbol from library: %s\n", dlerror());
- }
- else
- {
- dlerror();
- status = aiGetMaterialColor(material, key, type, index, data);
- }
-
- return status;
-}
-
-
-enum aiReturn AssimpProxy::GetMaterialInteger(
- const C_STRUCT aiMaterial* material,
- const char* key,
- unsigned int type,
- unsigned int index,
- int* data)
-{
- enum aiReturn status = aiReturn_FAILURE;
-
- PFGetMaterialIntegerArray* aiGetMaterialIntegerArray = (PFGetMaterialIntegerArray*) dlsym(mLibHandle, "aiGetMaterialIntegerArray");
- if(aiGetMaterialIntegerArray == NULL)
- {
- fprintf(stderr, "Cannot get aiGetMaterialIntegerArray symbol from library: %s\n", dlerror());
- }
- else
- {
- dlerror();
- status = aiGetMaterialIntegerArray(material, key, type, index, data, NULL);
- }
-
- return status;
-}
-
-enum aiReturn AssimpProxy::GetMaterialFloat(
- const C_STRUCT aiMaterial* material,
- const char* key,
- unsigned int type,
- unsigned int index,
- float* data)
-{
- enum aiReturn status = aiReturn_FAILURE;
-
- PFGetMaterialFloatArray* aiGetMaterialFloatArray = (PFGetMaterialFloatArray*) dlsym(mLibHandle, "aiGetMaterialFloatArray");
- if(aiGetMaterialFloatArray == NULL)
- {
- fprintf(stderr, "Cannot get aiGetMaterialFloatArray symbol from library: %s\n", dlerror());
- }
- else
- {
- dlerror();
- status = aiGetMaterialFloatArray(material, key, type, index, data, NULL);
- }
-
- return status;
-}
-
-
-enum aiReturn AssimpProxy::GetMaterialString(
- const C_STRUCT aiMaterial* material,
- const char* key,
- unsigned int type,
- unsigned int index,
- C_STRUCT aiString* data)
-{
- enum aiReturn status = aiReturn_FAILURE;
-
- PFGetMaterialString* aiGetMaterialString = (PFGetMaterialString*) dlsym(mLibHandle, "aiGetMaterialString");
- if(aiGetMaterialString == NULL)
- {
- fprintf(stderr, "Cannot get aiGetMaterialString symbol from library: %s\n", dlerror());
- }
- else
- {
- dlerror();
- status = aiGetMaterialString(material, key, type, index, data);
- }
-
- return status;
-}
-
-
-
-AssimpScene::AssimpScene(AssimpProxy* importer,
- std::string fileName,
- unsigned int postProcessFlags)
- : mModelImporter(importer)
-{
- mScene = importer->ImportFile(fileName, postProcessFlags);
- if(!mScene)
- {
- DALI_LOG_ERROR("%s", importer->GetErrorString());
- }
-}
-
-AssimpScene::~AssimpScene()
-{
- // Ensure the imported model data is released
- mModelImporter->ReleaseImport(mScene);
-}
-
-const aiScene* AssimpScene::GetScene()
-{
- return mScene;
-}
-
-
-}
-}
+++ /dev/null
-#ifndef __DALI_SLP_PLATFORM_ASSIMP_PROXY_H__
-#define __DALI_SLP_PLATFORM_ASSIMP_PROXY_H__
-
-/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <assimp/assimp.h>
-
-struct aiScene;
-struct aiMaterial;
-struct aiColor4D;
-struct aiString;
-
-namespace Dali
-{
-namespace SlpPlatform
-{
-
-/**
- * Class to proxy the Assimp importer. This will allow us to dynamically load the assimp
- * library when required.
- */
-class AssimpProxy
-{
-public:
- /**
- * Constructor. Dynamically loads the assimp library
- */
- AssimpProxy();
-
- /**
- * Destructor. Closes the loaded assimp library.
- */
- ~AssimpProxy();
-
- /**
- * Import a model file into a scene object. Should call ReleaseImport when
- * finished with the scene.
- * @param[in] fileName Filename of the model
- * @param[in] postProcessFlags How Assimp will process the scene after it has loaded.
- * @return aiScene The scene data, or NULL if it has failed to load.
- */
- const aiScene* ImportFile(std::string fileName, unsigned int postProcessFlags);
-
- /**
- * Release the scene data. Destroys the resources loaded with ImportFile.
- * @param[in] scene The scene data
- */
- void ReleaseImport(const aiScene* scene);
-
- /**
- * Get the error string. Useful if ImportFile fails.
- * @return the error string
- */
- const char* GetErrorString();
-
- /**
- * Get the color from the material for the given query.
- * @param[in] material The material structure to query
- * @param[in] key The query key
- * @param[in] type The query type
- * @param[in] index The query index
- * @param[out] data The output data
- * @return the return status.
- */
- enum aiReturn GetMaterialColor(
- const C_STRUCT aiMaterial* material,
- const char* key,
- unsigned int type,
- unsigned int index,
- C_STRUCT aiColor4D* data);
-
- /**
- * Get an integer from the material for the given query.
- * @param[in] material The material structure to query
- * @param[in] key The query key
- * @param[in] type The query type
- * @param[in] index The query index
- * @param[out] data The output integer
- * @return the return status.
- */
- enum aiReturn GetMaterialInteger(
- const C_STRUCT aiMaterial* material,
- const char* key,
- unsigned int type,
- unsigned int index,
- int* data);
-
- /**
- * Get a float from the material for the given query.
- * @param[in] material The material structure to query
- * @param[in] key The query key
- * @param[in] type The query type
- * @param[in] index The query index
- * @param[out] data The output float
- * @return the return status.
- */
- enum aiReturn GetMaterialFloat(
- const C_STRUCT aiMaterial* material,
- const char* key,
- unsigned int type,
- unsigned int index,
- float* data);
-
- /**
- * Get a string from the material for the given query.
- * @param[in] material The material structure to query
- * @param[in] key The query key
- * @param[in] type The query type
- * @param[in] index The query index
- * @param[out] data The output data
- * @return the return status.
- */
- enum aiReturn GetMaterialString(
- const C_STRUCT aiMaterial* material,
- const char* key,
- unsigned int type,
- unsigned int index,
- C_STRUCT aiString* data);
-
-
-private:
- void* mLibHandle; // The dynamically loaded libary handle
-};
-
-
-/**
- * Class that loads and releases scene data.
- */
-class AssimpScene
-{
-public:
- /**
- * Create the scene from the model
- */
- AssimpScene(AssimpProxy* importer, std::string fileName, unsigned int postProcessFlags);
-
- /**
- * Destroy the scene and release the imported data
- */
- ~AssimpScene();
-
- /**
- * Get the scene data
- */
- const aiScene* GetScene();
-
-private:
- const aiScene* mScene; ///< the scene data
- AssimpProxy* mModelImporter; ///< the model importer
-};
-
-}
-}
-
-#endif // __DALI_SLP_PLATFORM_ASSIMP_PROXY_H__
\ No newline at end of file
+++ /dev/null
-#ifndef __DALI_SLP_PLATFORM_ASSIMP_STUBS_H__
-#define __DALI_SLP_PLATFORM_ASSIMP_STUBS_H__
-
-/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#if !defined(ASSIMP_ENABLED)
-namespace Dali
-{
-
-namespace SlpPlatform
-{
-// Stubbed out assimp classes
-
-class AssimpProxy
-{
-public:
- AssimpProxy()
- {
- }
-
- ~AssimpProxy()
- {
- }
-};
-
-class AssimpModelBuilder : public ModelBuilder
-{
-public:
- AssimpModelBuilder(AssimpProxy* importer, const std::string& name)
- {
- }
-
- virtual ~AssimpModelBuilder()
- {
- }
-
- virtual bool Build(ModelData model)
- {
- return false;
- }
-
- virtual const std::string& GetModelName()
- {
- static std::string s;
- return s;
- }
-};
-
-} // namespace SlpPlatform
-
-} // namespace Dali
-
-#endif // ! defined(ASSIMP_ENABLED)
-#endif // __DALI_SLP_PLATFORM_ASSIMP_STUBS_H__
+++ /dev/null
-/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <libgen.h>
-#include <string.h>
-#include <iostream>
-#include <fstream>
-
-#include "binary-model-builder.h"
-
-namespace
-{
-
-/**
- * Calculate a checksum for a block of data
- * @param[in] buffer A pointer to a data block
- * @param[in] length The number of items in the data block
- * @return A checksum for the data block
- */
-unsigned short CalculateChecksum(unsigned short* buffer, unsigned int length)
-{
- unsigned short checkSum = 0;
- for( unsigned int i = 0; i < length; ++i)
- {
- checkSum += *buffer++;
- }
-
- return (~checkSum) + 1;
-}
-
-} // namespace
-
-namespace Dali
-{
-
-namespace SlpPlatform
-{
-
-BinaryModelBuilder::BinaryModelBuilder(const std::string& name)
-: mFilename(name)
-{
-}
-
-BinaryModelBuilder::~BinaryModelBuilder()
-{
-}
-
-bool BinaryModelBuilder::Build(ModelData model)
-{
- std::filebuf buf;
- buf.open(mFilename.c_str(), std::ios::in | std::ios::binary);
-
- {
- std::istream stream(&buf);
-
- // determine data length
- stream.seekg(0, std::ios_base::end);
- unsigned int length = static_cast<unsigned int>(stream.tellg());
- stream.seekg(0, std::ios_base::beg);
-
- // allocate a buffer
- unsigned short* buffer = new unsigned short[length / 2];
- // read data into buffer
- stream.read(reinterpret_cast<char*>(buffer), length);
- // calculate a checksum
- unsigned short checkSum = CalculateChecksum(buffer, length / 2);
- // finished with buffer, delete it
- delete [] buffer;
-
- if( checkSum != 0 )
- {
- return false;
- }
-
- // return read pointer to beginning of the file
- stream.seekg(0, std::ios_base::beg);
- }
-
- return model.Read(buf);
-}
-
-const std::string& BinaryModelBuilder::GetModelName()
-{
- char* modelName = strdup(mFilename.c_str());
-
- mModelName.assign(basename(modelName));
-
- free(modelName);
-
- return mModelName;
-}
-
-bool BinaryModelBuilder::Write(ModelData model)
-{
- bool status = false;
-
- // open file
- std::filebuf buf;
- buf.open(mFilename.c_str(), std::ios::out | std::ios::binary);
-
- // write model to file
- status = model.Write(buf);
- buf.close();
-
- // if model write was successfull, calculate
- // a checksum and append to the file
- if( status )
- {
- // reopen file for read/write
- buf.open(mFilename.c_str(), std::ios::in | std::ios::out | std::ios::binary);
- std::iostream stream(&buf);
-
- // determine data length
- stream.seekg(0, std::ios_base::end);
- unsigned int length = static_cast<unsigned int>(stream.tellg());
- stream.seekg(0, std::ios_base::beg);
-
- // allocate a buffer
- unsigned short* buffer = new unsigned short[length / 2];
- // read data into buffer
- stream.read(reinterpret_cast<char*>(buffer), length);
- // calculate a checksum
- unsigned short checkSum = CalculateChecksum(buffer, length / 2);
- // finished with buffer, delete it
- delete [] buffer;
-
- // Append checksum to file
- stream.seekp(0, std::ios_base::end);
- stream.write(reinterpret_cast<char*>(&checkSum), sizeof(unsigned short));
- }
-
- return status;
-}
-
-
-} // namespace SlpPlatform
-
-} // namespace Dali
-
+++ /dev/null
-#ifndef __DALI_SLP_PLATFORM_BINARY_MODEL_BUILDER_H__
-#define __DALI_SLP_PLATFORM_BINARY_MODEL_BUILDER_H__
-
-/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <string>
-
-#include <dali/public-api/modeling/model-data.h>
-#include "model-builder.h"
-
-namespace Dali
-{
-
-namespace SlpPlatform
-{
-
-/**
- * ModelBuilder specialization, creates a Model object from DALI specific binary model format.
- */
-class BinaryModelBuilder : public ModelBuilder
-{
-public:
- /**
- * Construct a Builder object with the filename of the Model to import
- * @param[in] name - the filename of the model
- */
- BinaryModelBuilder(const std::string& name);
-
- /**
- * Destructor
- */
- virtual ~BinaryModelBuilder();
-
-public: // ModelBuilder Interface
-
- /**
- * @copydoc ModelBuilder::Build()
- */
- virtual bool Build(ModelData model);
-
- /**
- * @copydoc ModelBuilder::GetModelName()
- */
- virtual const std::string& GetModelName();
-
-public: // public interface
-
- /**
- * Write out an internal format binary representation of the model data
- * @param[in] model The model data for output.
- */
- bool Write(ModelData model);
-
-private:
- const std::string mFilename;
- std::string mModelName;
-}; // class BinaryModelBuilder
-
-} //namespace SlpPlatform
-
-} // Dali
-
-#endif // __DALI_SLP_PLATFORM_BINARY_MODEL_BUILDER_H__
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include "left-hand-convertor.h"
-
-#include <dali/public-api/common/light.h>
-#include <dali/public-api/math/matrix.h>
-#include <dali/public-api/math/vector2.h>
-#include <dali/public-api/modeling/bone.h>
-#include <dali/public-api/modeling/entity-animator-map.h>
-#include <dali/public-api/modeling/model-animation-map.h>
-#include <dali/public-api/modeling/entity.h>
-#include <dali/public-api/modeling/model-data.h>
-
-namespace Dali
-{
-namespace SlpPlatform
-{
-
-LeftHandConvertor::LeftHandConvertor(const aiScene* aiScene)
-: mAssimpScene(aiScene)
-{
-}
-
-LeftHandConvertor::~LeftHandConvertor()
-{
-}
-
-void LeftHandConvertor::ProcessScene()
-{
- ConvertNode( mAssimpScene->mRootNode );
-
- for( std::size_t i=0; i < mAssimpScene->mNumMeshes; ++i )
- {
- ConvertMesh( mAssimpScene->mMeshes[i] );
- }
-
- for( std::size_t i=0; i < mAssimpScene->mNumMaterials; ++i )
- {
- ConvertMaterial( mAssimpScene->mMaterials[i] );
- }
-
- for ( std::size_t i=0; i < mAssimpScene->mNumAnimations; ++i )
- {
- aiAnimation* animation = mAssimpScene->mAnimations[i];
- for( std::size_t j=0; j < animation->mNumChannels; ++j )
- {
- aiNodeAnim* nodeAnimation = animation->mChannels[j];
- ConvertAnimation( nodeAnimation );
- }
- }
-}
-
-void LeftHandConvertor::ConvertNode( aiNode* node )
-{
- node->mTransformation.b1 = -node->mTransformation.b1;
- node->mTransformation.b3 = -node->mTransformation.b3;
- node->mTransformation.b4 = -node->mTransformation.b4;
- node->mTransformation.a2 = -node->mTransformation.a2;
- node->mTransformation.c2 = -node->mTransformation.c2;
- node->mTransformation.d2 = -node->mTransformation.d2;
-
- for( std::size_t i=0; i < node->mNumChildren; ++i )
- {
- ConvertNode( node->mChildren[i] );
- }
-}
-
-void LeftHandConvertor::ConvertMesh( aiMesh* mesh )
-{
- for( std::size_t i=0; i < mesh->mNumVertices; ++i )
- {
- mesh->mVertices[i].y *= -1.0f;
-
- if( mesh->HasNormals() )
- {
- mesh->mNormals[i].y *= -1.0f;
- }
-
- if( mesh->HasTangentsAndBitangents() )
- {
- mesh->mTangents[i].y *= -1.0f;
- mesh->mBitangents[i].y *= -1.0f;
- mesh->mBitangents[i] *= -1.0f; // Assimp does both of these - is this required?
- }
- }
-
- for( std::size_t i=0; i < mesh->mNumBones; ++i )
- {
- aiBone* bone = mesh->mBones[i];
- bone->mOffsetMatrix.a2 = -bone->mOffsetMatrix.a2;
- bone->mOffsetMatrix.c2 = -bone->mOffsetMatrix.c2;
- bone->mOffsetMatrix.d2 = -bone->mOffsetMatrix.d2;
- bone->mOffsetMatrix.b1 = -bone->mOffsetMatrix.b1;
- bone->mOffsetMatrix.b3 = -bone->mOffsetMatrix.b3;
- bone->mOffsetMatrix.b4 = -bone->mOffsetMatrix.b4;
- }
-}
-
-
-void LeftHandConvertor::ConvertMaterial( aiMaterial* material )
-{
- // No conversion needed
-}
-
-void LeftHandConvertor::ConvertAnimation( aiNodeAnim* animation )
-{
- // Convert position channel
- for( std::size_t i=0; i < animation->mNumPositionKeys; ++i )
- {
- animation->mPositionKeys[i].mValue.y *= -1.0f;
- }
-
- for( std::size_t i=0; i < animation->mNumRotationKeys; ++i )
- {
- // Quick and dirty
- animation->mRotationKeys[i].mValue.x *= -1.0f;
- animation->mRotationKeys[i].mValue.z *= -1.0f;
- }
-}
-
-} // SlpPlatform
-} // Dali
+++ /dev/null
-#ifndef __DALI_SLP_PLATFORM_LEFT_HAND_CONVERTOR_H__
-#define __DALI_SLP_PLATFORM_LEFT_HAND_CONVERTOR_H__
-
-/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <assimp/assimp.hpp>
-#include <assimp/aiScene.h>
-
-namespace Dali
-{
-namespace SlpPlatform
-{
-
-/**
- * Converts right handed assimp scene into our left handed coordinate system
- * (X right, Y up, Z forward) --> (X right, Y down, Z forward)
- */
-class LeftHandConvertor
-{
-public:
- /**
- * Constructor
- * @param[in] aiScene The loaded assimp scene
- */
- LeftHandConvertor(const aiScene* aiScene);
-
- /**
- * Destructor
- */
- ~LeftHandConvertor();
-
- /**
- * Convert the scene
- */
- void ProcessScene();
-
-private:
- /**
- * Convert nodes & children
- * @param[in] node The node
- */
- void ConvertNode( aiNode* node );
-
- /**
- * Convert meshes
- * @param[in] mesh The mesh
- */
- void ConvertMesh( aiMesh* mesh );
-
- /**
- * Convert material
- * @param[in] material The material
- */
- void ConvertMaterial( aiMaterial* material );
-
- /**
- * Convert animations
- * @param[in] nodeAnimation The node animation
- */
- void ConvertAnimation( aiNodeAnim* nodeAnimation );
-
-private:
- const aiScene* mAssimpScene; ///< The assimp scene
-};
-
-} // SlpPlatform
-} // Dali
-
-#endif //__DALI_SLP_PLATFORM_LEFT_HAND_CONVERTOR_H__
+++ /dev/null
-#ifndef __DALI_SLP_PLATFORM_MODEL_BUILDER_H__
-#define __DALI_SLP_PLATFORM_MODEL_BUILDER_H__
-
-/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <dali/public-api/modeling/model-data.h>
-
-namespace Dali
-{
-namespace SlpPlatform
-{
-
-/**
- * @brief Provides a means of creating a Model object.
- *
- * @sa ResourceThreadModel::CreateModelBuilder
- */
-class ModelBuilder
-{
-public:
- /**
- * @brief Allow implementing classes to be deleted through a pointer to this interface.
- */
- virtual ~ModelBuilder() {}
-
- /**
- * @brief Build the given model
- * @param[in] model - the model to build
- */
- virtual bool Build( ModelData model ) = 0;
-
- /**
- * @brief Get the model name (usually the basename of the file resource)
- */
- virtual const std::string& GetModelName() = 0;
-};
-
-}//SlpPlatform
-}//Dali
-
-#endif // __DALI_SLP_PLATFORM_MODEL_BUILDER_H__
#include <dali/public-api/common/scoped-pointer.h>
#include "resource-requester-base.h"
#include "resource-bitmap-requester.h"
-#include "resource-model-requester.h"
#include "resource-shader-requester.h"
#include "resource-text-requester.h"
#include "debug/resource-loader-debug.h"
mRequestHandlers.insert(std::make_pair(ResourceBitmap, new ResourceBitmapRequester(*loader)));
mRequestHandlers.insert(std::make_pair(ResourceShader, new ResourceShaderRequester(*loader)));
- mRequestHandlers.insert(std::make_pair(ResourceModel, new ResourceModelRequester(*loader)));
mRequestHandlers.insert(std::make_pair(ResourceText, new ResourceTextRequester(*loader)));
}
+++ /dev/null
-/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include "resource-model-requester.h"
-
-using namespace Dali::Integration;
-
-namespace Dali
-{
-namespace SlpPlatform
-{
-
-ResourceModelRequester::ResourceModelRequester( ResourceLoader& resourceLoader )
-: ResourceRequesterBase( resourceLoader ),
- mThreadModel(NULL)
-{
-}
-
-ResourceModelRequester::~ResourceModelRequester()
-{
- delete mThreadModel;
-}
-
-void ResourceModelRequester::Pause()
-{
- if( mThreadModel )
- {
- mThreadModel->Pause();
- }
-}
-
-void ResourceModelRequester::Resume()
-{
- if( mThreadModel )
- {
- mThreadModel->Resume();
- }
-}
-
-void ResourceModelRequester::LoadResource( Integration::ResourceRequest& request )
-{
- if( ! mThreadModel )
- {
- mThreadModel = new ResourceThreadModel( mResourceLoader );
- }
-
- mThreadModel->AddRequest(request, ResourceThreadBase::RequestLoad);
-}
-
-ResourcePointer ResourceModelRequester::LoadResourceSynchronously( const Integration::ResourceType& type, const std::string& path )
-{
- DALI_ASSERT_ALWAYS( false && "Cannot load models synchronously" );
-}
-
-LoadStatus ResourceModelRequester::LoadFurtherResources( ResourceRequest& request, LoadedResource partialResource )
-{
- // Nothing to do
- return RESOURCE_COMPLETELY_LOADED;
-}
-
-void ResourceModelRequester::SaveResource(const ResourceRequest& request )
-{
- if( ! mThreadModel )
- {
- mThreadModel = new ResourceThreadModel( mResourceLoader );
- }
-
- // Nothing to do
- mThreadModel->AddRequest(request, ResourceThreadBase::RequestSave);
-}
-
-void ResourceModelRequester::CancelLoad( ResourceId id, ResourceTypeId typeId)
-{
- mThreadModel->CancelRequest(id);
-}
-
-} // SlpPlatform
-} // Dali
+++ /dev/null
-#ifndef __DALI_SLP_PLATFORM_RESOURCE_MODEL_REQUESTER_H__
-#define __DALI_SLP_PLATFORM_RESOURCE_MODEL_REQUESTER_H__
-
-/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include "resource-requester-base.h"
-#include "resource-thread-model.h"
-
-namespace Dali
-{
-namespace SlpPlatform
-{
-
-/**
- * Class to own request thread and manage resource requests for model
- */
-class ResourceModelRequester : public ResourceRequesterBase
-{
-public:
- /**
- * Constructor
- * @param[in] resourceLoader The resource loader with which to communicate results
- */
- ResourceModelRequester( ResourceLoader& resourceLoader );
-
- /**
- * Destructor
- */
- virtual ~ResourceModelRequester();
-
- /**
- * @copydoc ResourceRequester::Pause()
- */
- virtual void Pause();
-
- /**
- * @copydoc ResourceRequester::Resume()
- */
- virtual void Resume();
-
- /**
- * @copydoc ResourceRequester::LoadResource()
- */
- virtual void LoadResource( Integration::ResourceRequest& request );
-
- /**
- * @copydoc ResourceRequester::LoadResourceSynchronously()
- */
- virtual Integration::ResourcePointer LoadResourceSynchronously( const Integration::ResourceType& type, const std::string& path );
-
- /**
- * @copydoc ResourceRequester::LoadFurtherResources()
- */
- virtual Integration::LoadStatus LoadFurtherResources( Integration::ResourceRequest& request, LoadedResource partialResource );
-
- /**
- * @copydoc ResourceRequester::SaveResource()
- */
- virtual void SaveResource(const Integration::ResourceRequest& request );
-
- /**
- * @copydoc ResourceRequester::CancelLoad()
- */
- virtual void CancelLoad(Integration::ResourceId id, Integration::ResourceTypeId typeId);
-
-protected:
- /** Thread to process resource requests. Created lazily, so check for null
- * before using. */
- ResourceThreadModel* mThreadModel;
-};
-
-} // SlpPlatform
-} // Dali
-
-#endif // __DALI_SLP_PLATFORM_RESOURCE_MODEL_REQUESTER_H__
+++ /dev/null
-/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <iostream>
-#include <fstream>
-
-#include "resource-thread-model.h"
-
-#include <dali/integration-api/bitmap.h>
-#include <dali/integration-api/debug.h>
-#include <dali/public-api/dali-core.h>
-#include <dali/public-api/object/ref-object.h>
-#include <dali/public-api/object/base-object.h>
-#include <dali/public-api/common/scoped-pointer.h>
-
-#include "binary-model-builder.h"
-
-#if defined(ASSIMP_ENABLED)
-#include "assimp-model-builder.h"
-#include "assimp-proxy.h"
-#else
-#include "assimp-stubs.h"
-#endif
-
-using namespace Dali::Integration;
-using boost::mutex;
-using boost::unique_lock;
-
-namespace Dali
-{
-
-namespace SlpPlatform
-{
-
-ResourceThreadModel::ResourceThreadModel(ResourceLoader& resourceLoader)
-: ResourceThreadBase(resourceLoader),
- mModelImporter(NULL)
-{
-}
-
-ResourceThreadModel::~ResourceThreadModel()
-{
- TerminateThread();
-
- if( mModelImporter)
- {
- // Closes dynamic library
- delete mModelImporter;
- }
-}
-
-void ResourceThreadModel::Load(const ResourceRequest& request)
-{
- DALI_ASSERT_DEBUG(request.GetType()->id == ResourceModel);
-
- DALI_LOG_INFO(mLogFilter, Debug::Verbose, "%s(%s)\n", __PRETTY_FUNCTION__, request.GetPath().c_str());
-
- bool success(false);
- ModelData modelData;
-
- ScopedPointer<ModelBuilder> modelBuilder( CreateModelBuilder(request.GetPath()) );
-
- if( modelBuilder.Get() != 0 )
- {
- modelData = ModelData::New(modelBuilder->GetModelName());
- success = modelBuilder->Build(modelData);
- }
-
- if( success )
- {
- // Construct LoadedResource and ResourcePointer for model data
- LoadedResource resource( request.GetId(), request.GetType()->id, ResourcePointer(&(modelData.GetBaseObject())));
-
- // Queue the loaded resource
- mResourceLoader.AddLoadedResource(resource);
- }
- else
- {
- // add to the failed queue
- FailedResource resource(request.GetId(), FailureUnknown);
- mResourceLoader.AddFailedLoad(resource);
- }
-}
-
-void ResourceThreadModel::Save(const ResourceRequest& request)
-{
- DALI_ASSERT_DEBUG(request.GetType()->id == ResourceModel);
-
- DALI_LOG_INFO(mLogFilter, Debug::Verbose, "%s(%s)\n", __PRETTY_FUNCTION__, request.GetPath().c_str());
-
- bool success(false);
-
- BaseObject* baseObject = dynamic_cast<BaseObject*>(request.GetResource().Get());
- if( baseObject != NULL )
- {
- BaseHandle baseHandle(baseObject);
- ModelData modelData = ModelData::DownCast(baseHandle);
- if( modelData )
- {
- ScopedPointer<BinaryModelBuilder> modelBuilder (new BinaryModelBuilder(request.GetPath().c_str()));
- if ( modelBuilder->Write(modelData) )
- {
- success = true;
-
- // Construct SavedResource
- SavedResource resource( request.GetId(), request.GetType()->id);
-
- // Queue the loaded resource
- mResourceLoader.AddSavedResource(resource);
- }
- }
- }
- if( ! success )
- {
- // add to the failed queue
- FailedResource resource(request.GetId(), FailureUnknown);
- mResourceLoader.AddFailedSave(resource);
- }
-}
-
-ModelBuilder* ResourceThreadModel::CreateModelBuilder(const std::string& modelFileName)
-{
- ModelBuilder* modelBuilder = NULL;
- char fileMagic[4]={0,};
-
- // read first 4 bytes of file
- {
- std::filebuf buf;
- if( &buf == buf.open(modelFileName.c_str(), std::ios::in | std::ios::binary) )
- {
- std::iostream stream(&buf);
- stream.read(fileMagic, 4);
- }
- }
-
- // if file starts with a 'DALI' tag/marker create a binary builder
- if( fileMagic[0] == 'D' &&
- fileMagic[1] == 'A' &&
- fileMagic[2] == 'L' &&
- fileMagic[3] == 'I' )
- {
- modelBuilder = new BinaryModelBuilder(modelFileName);
- }
-#if defined(ASSIMP_ENABLED)
- else if( fileMagic[0] != '\0' &&
- fileMagic[1] != '\0' &&
- fileMagic[2] != '\0' &&
- fileMagic[3] != '\0' )
- {
- if(!mModelImporter)
- {
- // Loads assimp library only when needed
- mModelImporter = new AssimpProxy;
- }
- modelBuilder = new AssimpModelBuilder(mModelImporter, modelFileName);
- }
-#endif
- return modelBuilder;
-}
-
-} // namespace SlpPlatform
-
-} // namespace Dali
+++ /dev/null
-#ifndef __DALI_SLP_PLATFORM_RESOURCE_THREAD_MODEL_H__
-#define __DALI_SLP_PLATFORM_RESOURCE_THREAD_MODEL_H__
-
-/*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <dali/integration-api/resource-cache.h>
-
-#include "resource-thread-base.h"
-#include "model-builder.h"
-
-namespace Dali
-{
-
-namespace Integration
-{
-namespace Log
-{
-class Filter;
-}
-}
-
-namespace SlpPlatform
-{
-
-class AssimpProxy;
-
-class ResourceThreadModel : public ResourceThreadBase
-{
-public:
- /**
- * Constructor
- * @param[in] resourceLoader A reference to the ResourceLoader
- */
- ResourceThreadModel(ResourceLoader& resourceLoader);
-
- /**
- * Destructor
- */
- virtual ~ResourceThreadModel();
-
-private:
- /**
- * @copydoc ResourceThreadBase::Load
- */
- virtual void Load(const Integration::ResourceRequest& request);
-
- /**
- *@copydoc ResourceThreadBase::Save
- */
- virtual void Save(const Integration::ResourceRequest& request);
-
- /**
- * Create a platform specific ModelBuilder to load a model file
- * param[in] modelFileName The filename of the model
- */
- ModelBuilder* CreateModelBuilder(const std::string& modelFileName);
-
-private:
- AssimpProxy* mModelImporter; ///< Used for loading models
-
-}; // class ResourceThreadModel
-
-} // namespace SlpPlatform
-
-} // namespace Dali
-
-#endif // __DALI_SLP_PLATFORM_RESOURCE_THREAD_MODEL_H__