Import::Import(const char* pathName, Interface* ip, ImpInterface* impip) { // set the path for textures char* ptr = NULL; sprintf (m_path, "%s", pathName); for (int i = 0; m_path[i]; i ++) { if ((m_path[i] == '\\') || (m_path[i] == '/') ) { ptr = &m_path[i]; } } *ptr = 0; m_ip = ip; m_impip = impip; m_succes = TRUE; MaterialCache materialCache (NewDefaultMultiMtl()); SetSceneParameters(); dFloat scale; scale = float (GetMasterScale(UNITS_METERS)); dMatrix scaleMatrix (GetIdentityMatrix()); scaleMatrix[0][0] = 1.0f / scale; scaleMatrix[1][1] = 1.0f / scale; scaleMatrix[2][2] = 1.0f / scale; dMatrix globalRotation (scaleMatrix * dPitchMatrix(3.14159265f * 0.5f) * dRollMatrix(3.14159265f * 0.5f)); NewtonWorld* newton = NewtonCreate(); dScene scene (newton); scene.Deserialize (pathName); // dScene::Iterator iter (scene); // for (iter.Begin(); iter; iter ++) { // dScene::dTreeNode* node = iter.GetNode(); // dNodeInfo* info = scene.GetInfoFromNode(node); // if (info->GetTypeId() == dMeshNodeInfo::GetRttiType()) { // dMeshNodeInfo* mesh = (dMeshNodeInfo*) scene.GetInfoFromNode(node); // mesh->ConvertToTriangles(); // } // } scene.BakeTransform (globalRotation); GeometryCache geometryCache; MaxNodeChache maxNodeCache; LoadMaterials (scene, materialCache); LoadGeometries (scene, geometryCache, materialCache); LoadNodes (scene, geometryCache, materialCache.m_multiMat, maxNodeCache); ApplyModifiers (scene, maxNodeCache); scene.CleanUp(); NewtonDestroy(newton); }
void CheckAndReloadFacade() { if (CURRENT_LAYOUT != data_timestamp_ptr->layout || CURRENT_DATA != data_timestamp_ptr->data || CURRENT_TIMESTAMP != data_timestamp_ptr->timestamp) { // release the previous shared memory segments SharedMemory::Remove(CURRENT_LAYOUT); SharedMemory::Remove(CURRENT_DATA); CURRENT_LAYOUT = data_timestamp_ptr->layout; CURRENT_DATA = data_timestamp_ptr->data; CURRENT_TIMESTAMP = data_timestamp_ptr->timestamp; m_layout_memory.reset(SharedMemoryFactory::Get(CURRENT_LAYOUT)); data_layout = (SharedDataLayout *)(m_layout_memory->Ptr()); m_large_memory.reset(SharedMemoryFactory::Get(CURRENT_DATA)); shared_memory = (char *)(m_large_memory->Ptr()); const char *file_index_ptr = data_layout->GetBlockPtr<char>(shared_memory, SharedDataLayout::FILE_INDEX_PATH); file_index_path = boost::filesystem::path(file_index_ptr); if (!boost::filesystem::exists(file_index_path)) { SimpleLogger().Write(logDEBUG) << "Leaf file name " << file_index_path.string(); throw osrm::exception("Could not load leaf index file." "Is any data loaded into shared memory?"); } LoadGraph(); LoadChecksum(); LoadNodeAndEdgeInformation(); LoadGeometries(); LoadTimestamp(); LoadViaNodeList(); LoadNames(); data_layout->PrintInformation(); SimpleLogger().Write() << "number of geometries: " << m_coordinate_list->size(); for (unsigned i = 0; i < m_coordinate_list->size(); ++i) { if (!GetCoordinateOfNode(i).is_valid()) { SimpleLogger().Write() << "coordinate " << i << " not valid"; } } } }
void ColladaDoc::Load( lpxmlnode pNode) { lpxmlnode pCurrNode = pNode; std::string Name = pCurrNode->name(); if(Name == "COLLADA") { // COLLADA header found pCurrNode = pCurrNode->first_node(); while(pCurrNode != NULL) { Name = pCurrNode->name(); if(Name == "library_images") LoadImages(pCurrNode->first_node()); else if(Name == "library_effects") LoadEffects(pCurrNode->first_node()); else if(Name == "library_materials") LoadMaterials(pCurrNode->first_node()); else if(Name == "library_geometries") LoadGeometries(pCurrNode->first_node()); else if(Name == "library_animations") LoadAnimations(pCurrNode->first_node()); else if(Name =="library_controllers") LoadControllers(pCurrNode->first_node()); else if(Name == "library_visual_scenes") LoadVisualScenes(pCurrNode->first_node()); else if(Name == "asset") LoadAssets(pCurrNode->first_node()); pCurrNode = pCurrNode->next_sibling(); }; } }
void ConvexApproximationObject::BuildMesh() { // since max does no provide the iNode that will own this mesh I have no choice bu to apply the root matrix to all vertex ConvexApproximationClassDesc* const desc = (ConvexApproximationClassDesc*) ConvexApproximationClassDesc::GetDescriptor(); INode* const sourceNode = desc->m_sourceNode; //dMatrix rootMatrix1 (GetMatrixFromMaxMatrix (sourceNode->GetNodeTM (0))); dMatrix rootMatrix (GetMatrixFromMaxMatrix (sourceNode->GetObjectTM(0))); dVector scale; dMatrix stretchAxis; dMatrix orthogonalRootTransform; rootMatrix.PolarDecomposition (orthogonalRootTransform, scale, stretchAxis); orthogonalRootTransform = orthogonalRootTransform.Inverse(); // create a Newton world, as a manager of everything Newton related stuff NewtonWorld* const world = NewtonCreate (); // create an empty mesh and load the max mesh to it NewtonMesh* const sourceMesh = NewtonMeshCreate (world); // load all faces NewtonMeshBeginFace(sourceMesh); LoadGeometries (sourceMesh, orthogonalRootTransform); NewtonMeshEndFace(sourceMesh); // make a convex approximation form this newton mesh effect desc->m_progress = -1; Interface* const inteface = desc->m_currentInterface; inteface->ProgressStart("Creation Convex approx ...", TRUE, ConvexApproximationClassDesc::ReportMaxProgress, NULL); NewtonMesh* approximationMesh = NewtonMeshApproximateConvexDecomposition (sourceMesh, m_currentConcavity, 0.2f, m_currentMaxCount, 1000, ConvexApproximationClassDesc::ReportProgress); inteface->ProgressEnd(); NewtonMeshDestroy (sourceMesh); // now convert the new mesh to a max poly Object MNMesh& maxMesh = GetMesh(); maxMesh.ClearAndFree(); int faceCount = 0; int vertexCount = NewtonMeshGetVertexCount(approximationMesh); for (void* face = NewtonMeshGetFirstFace(approximationMesh); face; face = NewtonMeshGetNextFace(approximationMesh, face)) { if (!NewtonMeshIsFaceOpen(approximationMesh, face)) { faceCount ++; } } //maxMesh.Clear(); maxMesh.setNumVerts(vertexCount); maxMesh.setNumFaces(faceCount); // add all vertex int vertexStride = NewtonMeshGetVertexStrideInByte(approximationMesh) / sizeof (dFloat64); dFloat64* const vertex = NewtonMeshGetVertexArray (approximationMesh); for (int j = 0; j < vertexCount; j ++) { dVector p (orthogonalRootTransform.TransformVector(dVector (float (vertex[vertexStride * j + 0]), float (vertex[vertexStride * j + 1]), float (vertex[vertexStride * j + 2]), float(1.0f)))); maxMesh.P(j) = Point3 (p.m_x, p.m_y, p.m_z); } // count the number of face and make a face map int faceIndex = 0; for (void* face = NewtonMeshGetFirstFace(approximationMesh); face; face = NewtonMeshGetNextFace(approximationMesh, face)) { if (!NewtonMeshIsFaceOpen(approximationMesh, face)) { int faceIndices[256]; int indexCount = NewtonMeshGetFaceIndexCount (approximationMesh, face); NewtonMeshGetFaceIndices (approximationMesh, face, faceIndices); MNFace* const face = maxMesh.F(faceIndex); face->MakePoly(indexCount, faceIndices, NULL, NULL); face->material = 0; faceIndex ++; } } maxMesh.InvalidateGeomCache(); maxMesh.InvalidateTopoCache(); maxMesh.FillInMesh(); maxMesh.AutoSmooth(45.0f * 3.1416f / 160.0f, false, false); NewtonMeshDestroy (approximationMesh); NewtonDestroy (world); }
void CheckAndReloadFacade() { if (CURRENT_LAYOUT != data_timestamp_ptr->layout || CURRENT_DATA != data_timestamp_ptr->data || CURRENT_TIMESTAMP != data_timestamp_ptr->timestamp) { // Get exclusive lock SimpleLogger().Write(logDEBUG) << "Updates available, getting exclusive lock"; boost::unique_lock<boost::shared_mutex> lock(data_mutex); if (CURRENT_LAYOUT != data_timestamp_ptr->layout || CURRENT_DATA != data_timestamp_ptr->data) { // release the previous shared memory segments SharedMemory::Remove(CURRENT_LAYOUT); SharedMemory::Remove(CURRENT_DATA); CURRENT_LAYOUT = data_timestamp_ptr->layout; CURRENT_DATA = data_timestamp_ptr->data; CURRENT_TIMESTAMP = 0; // Force trigger a reload SimpleLogger().Write(logDEBUG) << "Current layout was different to new layout, swapping"; } else { SimpleLogger().Write(logDEBUG) << "Current layout was same to new layout, not swapping"; } if (CURRENT_TIMESTAMP != data_timestamp_ptr->timestamp) { CURRENT_TIMESTAMP = data_timestamp_ptr->timestamp; SimpleLogger().Write(logDEBUG) << "Performing data reload"; m_layout_memory.reset(SharedMemoryFactory::Get(CURRENT_LAYOUT)); data_layout = (SharedDataLayout *) (m_layout_memory->Ptr()); m_large_memory.reset(SharedMemoryFactory::Get(CURRENT_DATA)); shared_memory = (char *) (m_large_memory->Ptr()); const char *file_index_ptr = data_layout->GetBlockPtr<char>(shared_memory, SharedDataLayout::FILE_INDEX_PATH); file_index_path = boost::filesystem::path(file_index_ptr); if (!boost::filesystem::exists(file_index_path)) { SimpleLogger().Write(logDEBUG) << "Leaf file name " << file_index_path.string(); throw osrm::exception("Could not load leaf index file. " "Is any data loaded into shared memory?"); } LoadGraph(); LoadChecksum(); LoadNodeAndEdgeInformation(); LoadGeometries(); LoadTimestamp(); LoadViaNodeList(); LoadNames(); LoadCoreInformation(); data_layout->PrintInformation(); SimpleLogger().Write() << "number of geometries: " << m_coordinate_list->size(); for (unsigned i = 0; i < m_coordinate_list->size(); ++i) { if (!GetCoordinateOfNode(i).is_valid()) { SimpleLogger().Write() << "coordinate " << i << " not valid"; } } } SimpleLogger().Write(logDEBUG) << "Releasing exclusive lock"; } }