2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://floralicense.org/license/
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
16 #include "assimp-proxy.h"
21 #include <dali/integration-api/debug.h>
29 // Private typedefs for function pointers returned from dlsym().
31 typedef const struct aiScene* PFImportFile(const char*, size_t);
32 typedef void PFReleaseImport(const aiScene*);
33 typedef const char* PFGetErrorString();
35 typedef enum aiReturn PFGetMaterialColor(
36 const C_STRUCT aiMaterial* pMaterial,
40 C_STRUCT aiColor4D* pOut);
42 typedef enum aiReturn PFGetMaterialIntegerArray(
43 const C_STRUCT aiMaterial* pMaterial,
50 typedef enum aiReturn PFGetMaterialFloatArray(
51 const C_STRUCT aiMaterial* pMaterial,
58 typedef enum aiReturn PFGetMaterialString(
59 const C_STRUCT aiMaterial* pMaterial,
63 C_STRUCT aiString* pOut);
67 * Class to proxy the Assimp importer. This will allow us to dynamically load the assimp
68 * library when required.
70 AssimpProxy::AssimpProxy()
73 mLibHandle = dlopen("libassimp.so", RTLD_LAZY);
76 fprintf(stderr, "Cannot load assimp library: %s\n", dlerror());
86 AssimpProxy::~AssimpProxy()
88 if(mLibHandle != NULL)
90 if(dlclose(mLibHandle))
92 fprintf(stderr, "Error closing assimp library: %s\n", dlerror());
98 const struct aiScene* AssimpProxy::ImportFile(std::string fileName, unsigned int postProcessFlags)
100 const struct aiScene* scene = NULL;
101 PFImportFile* aiImportFile = (PFImportFile*) dlsym(mLibHandle, "aiImportFile");
102 if(aiImportFile == NULL)
104 fprintf(stderr, "Cannot get aiImportFile symbol from library: %s\n", dlerror());
109 scene = aiImportFile(fileName.c_str(), postProcessFlags);
115 void AssimpProxy::ReleaseImport(const aiScene* scene)
117 PFReleaseImport* aiReleaseImport = (PFReleaseImport*) dlsym(mLibHandle, "aiReleaseImport");
118 if(aiReleaseImport == NULL)
120 fprintf(stderr, "Cannot get aiReleaseImport symbol from library: %s\n", dlerror());
125 aiReleaseImport(scene);
130 const char* AssimpProxy::GetErrorString()
132 const char* errorString=NULL;
134 PFGetErrorString* aiGetErrorString = (PFGetErrorString*) dlsym(mLibHandle, "aiGetErrorString");
135 if(aiGetErrorString == NULL)
137 fprintf(stderr, "Cannot get aiGetErrorString symbol from library: %s\n", dlerror());
142 errorString = aiGetErrorString();
149 enum aiReturn AssimpProxy::GetMaterialColor(
150 const C_STRUCT aiMaterial* material,
154 C_STRUCT aiColor4D* data)
156 enum aiReturn status = aiReturn_FAILURE;
158 PFGetMaterialColor* aiGetMaterialColor = (PFGetMaterialColor*) dlsym(mLibHandle, "aiGetMaterialColor");
159 if(aiGetMaterialColor == NULL)
161 fprintf(stderr, "Cannot get aiGetMaterialColor symbol from library: %s\n", dlerror());
166 status = aiGetMaterialColor(material, key, type, index, data);
173 enum aiReturn AssimpProxy::GetMaterialInteger(
174 const C_STRUCT aiMaterial* material,
180 enum aiReturn status = aiReturn_FAILURE;
182 PFGetMaterialIntegerArray* aiGetMaterialIntegerArray = (PFGetMaterialIntegerArray*) dlsym(mLibHandle, "aiGetMaterialIntegerArray");
183 if(aiGetMaterialIntegerArray == NULL)
185 fprintf(stderr, "Cannot get aiGetMaterialIntegerArray symbol from library: %s\n", dlerror());
190 status = aiGetMaterialIntegerArray(material, key, type, index, data, NULL);
196 enum aiReturn AssimpProxy::GetMaterialFloat(
197 const C_STRUCT aiMaterial* material,
203 enum aiReturn status = aiReturn_FAILURE;
205 PFGetMaterialFloatArray* aiGetMaterialFloatArray = (PFGetMaterialFloatArray*) dlsym(mLibHandle, "aiGetMaterialFloatArray");
206 if(aiGetMaterialFloatArray == NULL)
208 fprintf(stderr, "Cannot get aiGetMaterialFloatArray symbol from library: %s\n", dlerror());
213 status = aiGetMaterialFloatArray(material, key, type, index, data, NULL);
220 enum aiReturn AssimpProxy::GetMaterialString(
221 const C_STRUCT aiMaterial* material,
225 C_STRUCT aiString* data)
227 enum aiReturn status = aiReturn_FAILURE;
229 PFGetMaterialString* aiGetMaterialString = (PFGetMaterialString*) dlsym(mLibHandle, "aiGetMaterialString");
230 if(aiGetMaterialString == NULL)
232 fprintf(stderr, "Cannot get aiGetMaterialString symbol from library: %s\n", dlerror());
237 status = aiGetMaterialString(material, key, type, index, data);
245 AssimpScene::AssimpScene(AssimpProxy* importer,
246 std::string fileName,
247 unsigned int postProcessFlags)
248 : mModelImporter(importer)
250 mScene = importer->ImportFile(fileName, postProcessFlags);
253 DALI_LOG_ERROR("%s", importer->GetErrorString());
257 AssimpScene::~AssimpScene()
259 // Ensure the imported model data is released
260 mModelImporter->ReleaseImport(mScene);
263 const aiScene* AssimpScene::GetScene()