46 #include "AssimpPlugin.hh"
54 aiMaterial::aiMaterial() {
59 aiMaterial::~aiMaterial() {
60 for (
unsigned int i = 0; i < mNumProperties; ++i)
61 delete mProperties[i];
84 for (
unsigned int i = 0; i < mNumMeshes; ++i)
88 for (
unsigned int i = 0; i < mNumMaterials; ++i)
92 for (
unsigned int i = 0; i < mNumAnimations; ++i)
93 delete mAnimations[i];
96 for (
unsigned int i = 0; i < mNumTextures; ++i)
100 for (
unsigned int i = 0; i < mNumLights; ++i)
104 for (
unsigned int i = 0; i < mNumCameras; ++i)
110 AssimpPlugin::AssimpPlugin()
118 void AssimpPlugin::initializePlugin() {
121 " Copyright (c) 2006-2012 assimp team<br>"
122 " All rights reserved.<br>"
123 " Redistribution and use in source and binary forms, with or without modification, are "
124 " permitted provided that the following conditions are met: <br> "
126 " Redistributions of source code must retain the above copyright notice, this list of "
127 " conditions and the following disclaimer.<br> "
129 " Redistributions in binary form must reproduce the above copyright notice, this list "
130 " of conditions and the following disclaimer in the documentation and/or other "
131 " materials provided with the distribution.<br> "
133 " Neither the name of the assimp team nor the names of its contributors may be used to "
134 " endorse or promote products derived from this software without specific prior written "
137 " THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND ANY "
138 " EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF"
139 " MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL "
140 " THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, "
141 " SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, "
142 " PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS"
143 " INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, "
144 " STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF"
145 " THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. "
148 emit addAboutInfo(info,
"File-Assimp Plugin");
153 std::vector<int> ids;
155 if (_scene->mNumMeshes == 0)
156 emit log(
LOGWARN, tr(
"aiScene contains no meshes"));
158 for (
unsigned int i = 0; i < _scene->mNumMeshes; ++i) {
160 emit addEmptyObject(type_, objectId);
164 emit log(
LOGERR, tr(
"Could not create new object!"));
171 object->setName(_objectName);
181 ids.push_back(object->
id());
182 }
else if (triMeshObj) {
187 ids.push_back(object->
id());
190 emit openedFile( object->
id() );
193 if (_scene->mNumMeshes > 1) {
194 bool dataControlExists =
false;
195 pluginExists(
"datacontrol", dataControlExists );
197 if ( dataControlExists ){
198 returnId = RPC::callFunctionValue<int>(
"datacontrol",
"groupObjects", ids, _objectName);
206 _scene->mMeshes =
new aiMesh*[1];
207 _scene->mMeshes[0] =
new aiMesh();
208 _scene->mNumMeshes = 1;
209 _scene->mRootNode =
new aiNode();
210 _scene->mRootNode->mNumChildren = 0;
211 _scene->mRootNode->mNumMeshes = 1;
212 _scene->mRootNode->mMeshes =
new unsigned int[1];
213 _scene->mRootNode->mMeshes[0] = 0;
216 _scene->mMaterials =
new aiMaterial*[1];
217 _scene->mMaterials[0] =
new aiMaterial();
218 _scene->mNumMaterials = 1;
227 emit log(
LOGERR, tr(
"Unable to save (object is not a compatible mesh type)"));
235 std::vector<OpenMesh::VertexHandle> vhandles;
236 for (
unsigned int i = 0; i < _mesh->mNumFaces; ++i) {
237 aiFace& face = _mesh->mFaces[i];
238 for (
unsigned int j = 0; j < face.mNumIndices; ++j) {
240 if (_mesh->HasNormals()) {
241 aiVector3D& aiNormal = _mesh->mNormals[face.mIndices[j]];
242 _polyMesh->set_normal(vhandles.back(),
ACG::Vec3d(aiNormal.x, aiNormal.y, aiNormal.z));
246 _polyMesh->add_face(vhandles);
250 if (!_mesh->HasNormals())
251 _polyMesh->update_normals();
253 _polyMesh->update_face_normals();
259 std::vector<OpenMesh::VertexHandle> vhandles;
260 for (
unsigned int i = 0; i < _mesh->mNumFaces; ++i) {
261 aiFace& face = _mesh->mFaces[i];
262 for (
unsigned int j = 0; j < face.mNumIndices; ++j) {
264 if (_mesh->HasNormals()) {
265 aiVector3D& aiNormal = _mesh->mNormals[face.mIndices[j]];
266 _triMesh->set_normal(vhandles.back(),
ACG::Vec3d(aiNormal.x, aiNormal.y, aiNormal.z));
270 _triMesh->add_face(vhandles);
274 if (!_mesh->HasNormals())
275 _triMesh->update_normals();
277 _triMesh->update_face_normals();
281 _mesh->mPrimitiveTypes = aiPrimitiveType_POLYGON;
282 _mesh->mNumVertices = _polyMesh->n_vertices();
283 _mesh->mNumFaces = _polyMesh->n_faces();
285 _mesh->mVertices =
new aiVector3D[_mesh->mNumVertices];
286 _mesh->mNormals =
new aiVector3D[_mesh->mNumVertices];
287 _mesh->mFaces =
new aiFace[_mesh->mNumFaces];
289 std::map<OpenMesh::VertexHandle, int> vertexHandles;
291 for (PolyMesh::ConstVertexIter v_it = _polyMesh->vertices_begin(); v_it != _polyMesh->vertices_end(); ++v_it, ++i) {
294 _mesh->mVertices[i] = aiVector3D(pos[0], pos[1], pos[2]);
295 _mesh->mNormals[i] = aiVector3D(normal[0], normal[1], normal[2]);
296 vertexHandles[*v_it] = i;
300 for (PolyMesh::ConstFaceIter f_it = _polyMesh->faces_begin(); f_it != _polyMesh->faces_end(); ++f_it, ++i) {
306 _mesh->mFaces[i].mNumIndices = nVertices;
307 _mesh->mFaces[i].mIndices =
new unsigned int[nVertices];
310 _mesh->mFaces[i].mIndices[j] = vertexHandles[*fv_it];
318 _mesh->mPrimitiveTypes = aiPrimitiveType_TRIANGLE;
319 _mesh->mNumVertices = _triMesh->n_vertices();
320 _mesh->mNumFaces = _triMesh->n_faces();
322 _mesh->mVertices =
new aiVector3D[_mesh->mNumVertices];
323 _mesh->mNormals =
new aiVector3D[_mesh->mNumVertices];
324 _mesh->mFaces =
new aiFace[_mesh->mNumFaces];
326 std::map<OpenMesh::VertexHandle, int> vertexHandles;
328 for (TriMesh::ConstVertexIter v_it = _triMesh->vertices_begin(); v_it != _triMesh->vertices_end(); ++v_it, ++i) {
331 _mesh->mVertices[i] = aiVector3D(pos[0], pos[1], pos[2]);
332 _mesh->mNormals[i] = aiVector3D(normal[0], normal[1], normal[2]);
333 vertexHandles[*v_it] = i;
337 for (TriMesh::ConstFaceIter f_it = _triMesh->faces_begin(); f_it != _triMesh->faces_end(); ++f_it, ++i) {
338 _mesh->mFaces[i].mNumIndices = 3;
339 _mesh->mFaces[i].mIndices =
new unsigned int[3];
342 _mesh->mFaces[i].mIndices[j] = vertexHandles[*fv_it];
352 for (
unsigned int i = 0; i < _mesh->mNumVertices; ++i) {
353 vertexHandles_[i] = _polyMesh->add_vertex(
ACG::Vec3d(_mesh->mVertices[i].x, _mesh->mVertices[i].y, _mesh->mVertices[i].z));
360 for (
unsigned int i = 0; i < _mesh->mNumVertices; ++i) {
361 vertexHandles_[i] = _triMesh->add_vertex(
ACG::Vec3d(_mesh->mVertices[i].x, _mesh->mVertices[i].y, _mesh->mVertices[i].z));
372 return QString( tr(
"Alias/Wavefront ( *.obj );;Collada ( *.dae );;Stereolithography files ( *.stl );;Polygon File Format files ( *.ply )" ) );
376 return QString( tr(
"Alias/Wavefront ( *.obj );;AutoCAD DXF ( *.dxf );;Collada ( *.dae );;Stereolithography files ( *.stl );;Polygon File Format files ( *.ply );;Blender 3D( *.blend );;3ds Max 3DS ( *.3ds );;3ds Max ASE( *.ase );;Industry Foundation Classes ( *.ifc );;XGL ( *.xgl *.zgl );;Lightwave ( *.lwo );;Lightwave Scene ( *.lws );;Modo ( *.lxo );;DirectX X ( *.x );;AC3D ( *.ac );;Milkshape 3D ( *.ms3d );;TrueSpace ( *.cob *.scn )") );
381 saveOptions_ =
new QWidget();
389 loadOptions_ =
new QWidget();
396 Assimp::Importer importer;
398 const aiScene* scene = NULL;
400 scene = importer.ReadFile(_filename.toStdString(), aiProcess_JoinIdenticalVertices | aiProcess_Triangulate);
402 scene = importer.ReadFile(_filename.toStdString(), aiProcess_JoinIdenticalVertices);
405 emit log(
LOGERR, tr(importer.GetErrorString()));
409 QFileInfo f(_filename);
419 bool AssimpPlugin::saveObject(
int _id, QString _filename) {
424 emit log(
LOGERR, tr(
"Could not get the object with the given id"));
428 object->setFromFileName(_filename);
429 object->setName(object->
filename());
436 Assimp::Exporter exporter;
438 QFileInfo f(_filename);
440 std::string formatId = (f.suffix() ==
"dae") ?
"collada" : f.suffix().toStdString();
441 bool ok = exporter.Export(&scene, formatId, _filename.toStdString()) == AI_SUCCESS;
443 emit log(
LOGERR, exporter.GetErrorString());
448 #if QT_VERSION < 0x050000
bool dataType(DataType _type) const
bool convertPolyMeshToAiMesh(PolyMesh *_polyMesh, aiMesh *_mesh)
converts a polymesh to an aiMesh
int loadObject(QString _filename)
Loads Object and converts it to a triangle mesh if possible.
bool getObject(int _identifier, BSplineCurveObject *&_object)
bool convertOpenMeshToAiScene(aiScene *_scene, BaseObjectData *_object)
converts a polymesh or trimesh to an aiScene
Type for a MeshObject containing a triangle mesh.
Type for a Meshobject containing a poly mesh.
int convertAiSceneToOpenMesh(const aiScene *_scene, QString _objectName)
converts an aiScene to a polymesh or trimesh
std::map< unsigned int, OpenMesh::VertexHandle > vertexHandles_
maps indices of vertices in an aiMesh to OpenMesh VertexHandles
QWidget * loadOptionsWidget(QString)
QString filename() const
return the filename of the object
QWidget * saveOptionsWidget(QString)
void convertAiMeshToTriMesh(TriMesh *_triMesh, aiMesh *_mesh)
converts _mesh into _triMesh
#define DATA_TRIANGLE_MESH
bool convertTriMeshToAiMesh(TriMesh *_triMesh, aiMesh *_mesh)
converts a trimesh to an aiMesh
DataType supportedType()
Return your supported object type( e.g. DATA_TRIANGLE_MESH )
const DataType DATA_GROUP(1)
Items used for Grouping.
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
void convertAiMeshToPolyMesh(PolyMesh *_polyMesh, aiMesh *_mesh)
converts _mesh into _polyMesh
VectorT< double, 3 > Vec3d
MeshT * mesh()
return a pointer to the mesh
Kernel::ConstFaceVertexIter ConstFaceVertexIter
Circulator.
void mapVertices(PolyMesh *_polyMesh, aiMesh *_mesh)
add a vertex from _mesh to _polyMesh and stores the index to handle mapping