GameInit::GameInit(Renderer& r) { Shader* s = new Shader("basicvert.glsl", "basicFrag.glsl"); Shader* os = new Shader("OutlineVert.glsl", "OutlineFrag.glsl"); populateEntities(); createMeshes(s, os); addToScreen(r); }
// Create an GLC_World from an input 3DS File GLC_World* GLC_3dsToWorld::CreateWorldFrom3ds(QFile &file) { clear(); m_FileName= file.fileName(); ////////////////////////////////////////////////////////////////// // Test if the file exist and can be opened ////////////////////////////////////////////////////////////////// if (!file.open(QIODevice::ReadOnly)) { QString message(QString("GLC_3dsToWorld::CreateWorldFrom3ds File ") + m_FileName + QString(" doesn't exist")); GLC_FileFormatException fileFormatException(message, m_FileName, GLC_FileFormatException::FileNotFound); throw(fileFormatException); } // Close the file before open it with lib3ds file.close(); ////////////////////////////////////////////////////////////////// // Init member ////////////////////////////////////////////////////////////////// m_pWorld= new GLC_World; //Load 3ds File m_pLib3dsFile=lib3ds_file_load(m_FileName.toLocal8Bit().data()); if (!m_pLib3dsFile) { QString message= "GLC_3dsToWorld::CreateWorldFrom3ds : Loading Failed"; GLC_FileFormatException fileFormatException(message, m_FileName, GLC_FileFormatException::FileNotSupported); clear(); throw(fileFormatException); } // Evaluate Nodes Matrix for the first frame (Needed by instances) lib3ds_file_eval(m_pLib3dsFile, 0.0); m_CurrentQuantumValue= m_InitQuantumValue; m_PreviousQuantumValue= m_CurrentQuantumValue; emit currentQuantum(m_CurrentQuantumValue); // Count the number of meshes for(Lib3dsMesh *pMesh= m_pLib3dsFile->meshes; pMesh != NULL; pMesh = pMesh->next) { ++m_NumberOfMeshes; } // Check if there is some meshes in the 3ds file if (0 == m_NumberOfMeshes) { QString message= "GLC_3dsToWorld::CreateWorldFrom3ds : No mesh found !"; GLC_FileFormatException fileFormatException(message, m_FileName, GLC_FileFormatException::NoMeshFound); clear(); throw(fileFormatException); } // Create GLC_3DViewInstance with Node for (Lib3dsNode *pNode=m_pLib3dsFile->nodes; pNode!=0; pNode=pNode->next) { createMeshes(m_pWorld->rootOccurence(), pNode); } // Load unloaded mesh name for(Lib3dsMesh *pMesh= m_pLib3dsFile->meshes; pMesh != NULL; pMesh = pMesh->next) { if (!m_LoadedMeshes.contains(QString(pMesh->name))) { //qDebug() << "Mesh without parent found" << QString(pMesh->name); Lib3dsNode *pNode= lib3ds_node_new_object(); strcpy(pNode->name, pMesh->name); pNode->parent_id= LIB3DS_NO_PARENT; lib3ds_file_insert_node(m_pLib3dsFile, pNode); createMeshes(m_pWorld->rootOccurence(), pNode); } } // Free Lib3dsFile and all its ressources lib3ds_file_free(m_pLib3dsFile); m_pLib3dsFile= NULL; emit currentQuantum(100); // Create the world bounding box m_pWorld->collection()->boundingBox(); return m_pWorld; }
//------------------------------------------------------------------------------ static void rebuildOsdMeshes() { createMeshes(g_shapes[ g_currentShape ], g_level); }
// Create meshes from the 3ds File void GLC_3dsToWorld::createMeshes(GLC_StructOccurence* pProduct, Lib3dsNode* pFatherNode) { GLC_StructOccurence* pChildProduct= NULL; Lib3dsMesh *pMesh= NULL; if (pFatherNode->type == LIB3DS_OBJECT_NODE) { //qDebug() << "Node type LIB3DS_OBJECT_NODE is named : " << QString(pFatherNode->name); //qDebug() << "Node Matrix :"; //qDebug() << GLC_Matrix4x4(&(pFatherNode->matrix[0][0])).toString(); // Check if the node is a mesh or dummy if (!(strcmp(pFatherNode->name,"$$$DUMMY")==0)) { pMesh = lib3ds_file_mesh_by_name(m_pLib3dsFile, pFatherNode->name); if( pMesh != NULL ) { GLC_3DRep representation(create3DRep(pMesh)); // Test if there is vertex in the mesh if (0 != representation.vertexCount()) { m_LoadedMeshes.insert(representation.name()); // Load node matrix GLC_Matrix4x4 nodeMat(&(pFatherNode->matrix[0][0])); // The mesh matrix to inverse GLC_Matrix4x4 matInv(&(pMesh->matrix[0][0])); matInv.invert(); // Get the node pivot Lib3dsObjectData *pObjectData; pObjectData= &pFatherNode->data.object; GLC_Matrix4x4 trans(-pObjectData->pivot[0], -pObjectData->pivot[1], -pObjectData->pivot[2]); // Compute the part matrix nodeMat= nodeMat * trans * matInv; // I don't know why... nodeMat.optimise(); // move the part by the matrix pProduct->addChild((new GLC_StructInstance(new GLC_3DRep(representation)))->move(nodeMat)); } else { // the instance will be deleted, check material usage QSet<GLC_Material*> meshMaterials= representation.materialSet(); QSet<GLC_Material*>::const_iterator iMat= meshMaterials.constBegin(); while (iMat != meshMaterials.constEnd()) { if ((*iMat)->numberOfUsage() == 1) { m_Materials.remove((*iMat)->name()); } ++iMat; } } } } // End If DUMMY } else return; // If there is a child, create a child product if (NULL != pFatherNode->childs) { pChildProduct= new GLC_StructOccurence(); pProduct->addChild(pChildProduct); pChildProduct->setName(QString("Product") + QString::number(pFatherNode->node_id)); //pChildProduct->move(GLC_Matrix4x4(&(pFatherNode->matrix[0][0]))); // Create Childs meshes if exists for (Lib3dsNode* pNode= pFatherNode->childs; pNode!=0; pNode= pNode->next) { createMeshes(pChildProduct, pNode); } } }