GLC_3DRep GLC_Factory::createPointCloud(const QList<GLC_Point3df>& pointList, const QColor& color) { GLC_PointCloud* pPointCloud= new GLC_PointCloud(); pPointCloud->addPoint(pointList); pPointCloud->setWireColor(color); return GLC_3DRep(pPointCloud); }
GLC_3DRep GLC_Factory::createPointCloud(const GLfloatVector& data, const QColor& color) { GLC_PointCloud* pPointCloud= new GLC_PointCloud(); pPointCloud->addPoint(data); pPointCloud->setWireColor(color); return GLC_3DRep(pPointCloud); }
//! Create 3DRep from a Lib3dsNode GLC_3DRep GLC_3dsToWorld::create3DRep(Lib3dsMesh* p3dsMesh) { QString meshName(p3dsMesh->name); if (m_LoadedMeshes.contains(meshName)) { // This mesh as been already loaded QList<GLC_3DViewInstance*> instancesList(m_pWorld->collection()->instancesHandle()); GLC_3DViewInstance* pCurrentInstance= NULL; int currentIndex= -1; do { pCurrentInstance= instancesList[++currentIndex]; } while (pCurrentInstance->name() != meshName); // return an instance. //qDebug() << "instance"; return pCurrentInstance->representation(); } GLC_Mesh * pMesh= new GLC_Mesh(); pMesh->setName(p3dsMesh->name); // The mesh normals const int normalsNumber= p3dsMesh->faces * 3; Lib3dsVector *normalL= new Lib3dsVector[normalsNumber]; lib3ds_mesh_calculate_normals(p3dsMesh, normalL); // Position vector QVector<float> position(normalsNumber * 3); // Normal Vector QVector<float> normal(normalsNumber * 3); memcpy((void*)normal.data(), normalL, normalsNumber * 3 * sizeof(float)); // Texel Vector QVector<float> texel; if (p3dsMesh->texels > 0) { texel.resize(normalsNumber * 2); } int normalIndex= 0; for (unsigned int i= 0; i < p3dsMesh->faces; ++i) { IndexList triangleIndex; Lib3dsFace *p3dsFace=&p3dsMesh->faceL[i]; for (int i=0; i < 3; ++i) { triangleIndex.append(normalIndex); // Add vertex coordinate memcpy((void*)&(position.data()[normalIndex * 3]), &p3dsMesh->pointL[p3dsFace->points[i]], 3 * sizeof(float)); // Add texel if (p3dsMesh->texels > 0) { memcpy((void*)&(texel.data()[normalIndex * 2]), &p3dsMesh->texelL[p3dsFace->points[i]], 2 * sizeof(float)); } ++normalIndex; } // Load the material // The material current face index GLC_Material* pCurMaterial= NULL; if (p3dsFace->material[0]) { Lib3dsMaterial* p3dsMat=lib3ds_file_material_by_name(m_pLib3dsFile, p3dsFace->material); if (NULL != p3dsMat) { // Check it this material as already been loaded const QString materialName(p3dsFace->material); if (!m_Materials.contains(materialName)) { // Material not already loaded, load it loadMaterial(p3dsMat); } pCurMaterial= m_Materials.value(materialName); } } pMesh->addTriangles(pCurMaterial, triangleIndex); } pMesh->addVertice(position); pMesh->addNormals(normal); if (p3dsMesh->texels > 0) { pMesh->addTexels(texel); } // free normal memmory delete[] normalL; // Compute loading progress ++m_CurrentMeshNumber; m_CurrentQuantumValue = static_cast<int>((static_cast<double>(m_CurrentMeshNumber) / m_NumberOfMeshes) * (100 - m_InitQuantumValue)) + m_InitQuantumValue; if (m_CurrentQuantumValue > m_PreviousQuantumValue) { emit currentQuantum(m_CurrentQuantumValue); } m_PreviousQuantumValue= m_CurrentQuantumValue; pMesh->finish(); return GLC_3DRep(pMesh); }