const string& Configuration::GetExecutableDirectory() { if (mDirectoryPtr == NULL) { string* path = &GetDirectoryPath(GetExecutableFullPath()); // DEBUG: kludge for when developing: MS regularly cleans Debug dir. if (Strings::EndsWith(*path,"debug")) { string* tmp = path; path = &GetDirectoryPath(*path); delete tmp; } mDirectoryPtr = path; } return *mDirectoryPtr; }
LEVELSELECT::LEVELSELECT() { if (_instance != NULL) { delete _instance; _instance = NULL; } _instance = this; currentLevel = NULL; currentDirectory = NULL; char levelPath[MAX_PATH]; GetDirectoryPath(levelPath, ""); if (FILESYSTEMUTILITY::EnumerateDirectories(levelPath, &directoryCount, &addDirectoryListEntry)) { SwitchDirectory(0); } else { error("LEVELSELECT::ctor()", "FATAL: FILESYSTEMUTILITY::EnumerateDirectories() failed"); exit(1); } }
/* * The caller is supposed to free the memory. */ char* nsFolderSpec::toString() { char* path = GetDirectoryPath(); char* copyPath = NULL; if (path != NULL) { copyPath = XP_STRDUP(path); } return copyPath; }
bool reProjectAssets::DeleteModel(const wxString& name) { if (_manifest.RemoveByName(rAssetType::Model, name.c_str().AsChar())) { _component->GetEngine()->content->Models()->Delete(name.c_str().AsChar()); wxString assetPath = GetAssetPath(rAssetType::Model, name); wxString modelFile = GetDirectoryPath() + assetPath; wxRemoveFile(modelFile); return true; } return false; }
/** * Returns full path to a file. Makes sure that the full path is bellow * this directory (security measure) * * Caller should free the returned string * * @param relativePath relative path * @return full path to a file */ char* nsFolderSpec::MakeFullPath(char* relativePath, char* *errorMsg) { // Security check. Make sure that we do not have '.. in the name // if ( (GetSecurityTargetID() == SoftwareUpdate.LIMITED_INSTALL) && // ( relativePath.regionMatches(0, "..", 0, 2))) // throw new SoftUpdateException(Strings.error_IllegalPath(), SoftwareUpdate.ILLEGAL_RELATIVE_PATH ); char *fullPath=NULL; char *dir_path; *errorMsg = NULL; dir_path = GetDirectoryPath(); if (dir_path == NULL) { return NULL; } fullPath = XP_Cat(dir_path, GetNativePath(relativePath)); return fullPath; }
//Loads current directory (including all levels it contains) void LEVELSELECT::LoadDirectory() { char levelPath[MAX_PATH]; GetDirectoryPath(&levelPath[0], ""); if (strlen(levelPath)+strlen(currentDirectory->name)>=MAX_PATH) { error("LEVELSELECT::SwitchDirectory", "FATAL: Path too long."); exit (1); } strcat(levelPath, currentDirectory->name); levelCount = 0; FreeLevelList(currentLevel); currentLevel = NULL; if (FILESYSTEMUTILITY::EnumerateFiles(levelPath, &levelCount, &addLevelListEntry)) { SwitchLevel(0); } else { logger(true, "WARN: No levels available (Got false from FILESYSTEMUTILITY::EnumerateFiles)"); } }
Scene::Scene(std::string filepath): isLoaded(false), isImported(false), activeCamera(0) { this->filepath = filepath; this->directory = GetDirectoryPath(filepath); }
//----------------------------------------------------------------------- // Name : LoadOBJFile() // Desc : OBJファイルの読み込み //----------------------------------------------------------------------- bool OBJMESH::LoadOBJFile(const char *filename) { ifstream file; char buf[OBJ_BUFFER_LENGTH] = {0}; vector<OBJVEC3> positions; vector<OBJVEC3> normals; vector<OBJVEC2> texcoords; vector<OBJVERTEX> t_vertices; vector<OBJSUBSET> t_subsets; vector<unsigned int> t_indices; bool initBox = false; int prevSize = 0; unsigned long total = 0; OBJMATERIAL material; unsigned int dwFaceIndex = 0; unsigned int dwFaceCount = 0; unsigned int dwCurSubset = 0; // ディレクトリを切り取り strcpy( m_directoryPath, GetDirectoryPath( filename ) ); // ファイルを開く file.open( filename, ios::in ); // チェック if ( !file.is_open() ) { printf("失敗\n"); ERROR_MESSAGE("OBJファイルのオープンに失敗しました。\n"\ "「Resource/Model」フォルダに格納されていますか?\n"\ "ファイル名が間違っていませんか?"); return false; } // ループ for( ;; ) { file >> buf; if ( !file ) break; // コメント if ( 0 == strcmp( buf, "#" ) ) { file.ignore(OBJ_BUFFER_LENGTH, '\n'); } // 頂点座標 else if ( 0 == strcmp( buf, "v" ) ) { float x, y, z; file >> x >> y >> z; OBJVEC3 v( x, y, z ); positions.push_back( v ); // バウンディングボックスの初期化 if ( !initBox ) { m_Box = OBJBOUNDINGBOX( v ); initBox = true; } // バウンディングボックスの算出 m_Box.Merge( v ); file.ignore(OBJ_BUFFER_LENGTH, '\n'); } // テクスチャ座標 else if ( 0 == strcmp( buf, "vt" ) )
bool Model::Load(char* filePath){ if (myVBO.GetID() == 0){ myVBO.Create(); textures.reserve(50); } Assimp::Importer importer; std::cout << filePath << std::endl; const aiScene* scene = importer.ReadFile(filePath, aiProcess_CalcTangentSpace | aiProcess_Triangulate | aiProcess_JoinIdenticalVertices | aiProcess_SortByPType); if (!scene){ std::cout << "Error Loading Model" << std::endl; return false; } else{ std::cout << "Loaded Model" << std::endl; } const int vertexTotalSize = sizeof(aiVector3D)* 2 + sizeof(aiVector2D); int totalVertices = 0; for (int x = 0; x < scene->mNumMeshes; x++){ std::cout << "Working with Mesh #: " << std::to_string(x) << std::endl; aiMesh* mesh = scene->mMeshes[x]; int faceCount = mesh->mNumFaces; materialIndices.push_back(mesh->mMaterialIndex); int sizeBefore = myVBO.GetSize(); meshStartIndices.push_back(sizeBefore / vertexTotalSize); for (int y = 0; y < faceCount; y++){ const aiFace& face = mesh->mFaces[y]; for (int z = 0; z < 3; z++){ aiVector3D pos = mesh->mVertices[face.mIndices[z]]; aiVector3D uv = mesh->mTextureCoords[0][face.mIndices[z]]; aiVector3D normal = mesh->HasNormals() ? mesh->mNormals[face.mIndices[z]] : aiVector3D(1.0f, 1.0f, 1.0f); myVBO.AddData(&pos, sizeof(aiVector3D)); myVBO.AddData(&uv, sizeof(aiVector2D)); myVBO.AddData(&normal, sizeof(aiVector3D)); } } int meshVertices = mesh->mNumVertices; totalVertices += meshVertices; meshSizes.push_back((myVBO.GetSize() - sizeBefore) / vertexTotalSize); } numberOfMaterials = scene->mNumMaterials; std::vector<int> materialRemap(numberOfMaterials); for (int x = 0; x < numberOfMaterials; x++){ const aiMaterial* material = scene->mMaterials[x]; int a = 5; int texIndex = 0; aiString path; if (material->GetTexture(aiTextureType_DIFFUSE, texIndex, &path) == AI_SUCCESS){ std::string dir = GetDirectoryPath(filePath); std::string textureName = path.data; std::string fullPath = dir + textureName; std::cout << "Loaded Material: " << fullPath << std::endl; int texFound = -1; int size = textures.size(); for (int y = 0; y < size; y++){ if (fullPath == textures[y].GetPath()){ texFound = y; break; } } if (texFound != -1) materialRemap[x] = texFound; else{ Texture newTexture; newTexture.Load(fullPath, true); newTexture.SetFiltering(TEXTURE_FILTER_MAG_BILINEAR, TEXTURE_FILTER_MIN_BILINEAR_MIPMAP); materialRemap[x] = textures.size(); textures.push_back(newTexture); } } } int size = meshSizes.size(); for (int x = 0; x < size; x++){ int oldIndex = materialIndices[x]; materialIndices[x] = materialRemap[oldIndex]; } std::cout << "Loaded Model Successfully (probobly)" << std::endl; isLoaded = true; return true; };
std::string GetThemePath() { auto context = GetContext(); auto env = context->GetPlatformEnvironment(); return env->GetDirectoryPath(DIRBASE::USER, DIRID::THEME); }
BIT_UINT32 ModelOBJ::ReadMaterialFile( const char * p_pFilePath, const char * p_pMainFilePath ) { // Open the main .obj file std::string DirectoryPath = GetDirectoryPath( p_pMainFilePath ) + "/"; std::string FullPath = DirectoryPath + std::string( p_pFilePath ); std::ifstream fin( FullPath.c_str( ), std::fstream::binary ); // Could we open the file? if( !fin.is_open( ) ) { return BIT_ERROR_OPEN_FILE; } // Get the file size fin.seekg( 0, std::fstream::end ); const BIT_UINT32 FileSize = static_cast<BIT_UINT32>(fin.tellg( ) ); fin.seekg( 0, std::fstream::beg ); // Allocate and read the data SmartArray< BIT_SCHAR8 > Data( FileSize ); fin.read( (char*)Data.Get( ), FileSize ); fin.close( ); // Useful variables BIT_UINT32 CurrentPosition = 0; BIT_UINT32 LinePosition = 0; BIT_SCHAR8 LineBuffer[ 128 ]; BIT_UINT32 UnknowDataCount = 0; std::vector< std::string > m_UnknownData; BIT_SCHAR8 TextBuffer64[ 64 ]; BIT_SCHAR8 TextBuffer128[ 128 ]; Material * pMaterial = BIT_NULL; // Keep on reading until we reach any stream flag while( CurrentPosition < FileSize ) { // Get the current line CurrentPosition += GetLine( LineBuffer, 128, &Data[ CurrentPosition ] ); // Ignore spaces and tabs, Have been seen in material files for( BIT_MEMSIZE i = 0; i < 128; i++ ) { if( LineBuffer[ i ] != ' ' && LineBuffer[ i ] != '\t' ) { LinePosition = i; break; } } // Scan for the data if( sscanf_s( (const char *)&LineBuffer[ LinePosition ], "newmtl %s", TextBuffer64, sizeof( TextBuffer64 ) ) == 1 ) { // Create a new material and add it to the vector pMaterial = new Material; pMaterial->Name = std::string( (char *)TextBuffer64 ); m_Materials.push_back( pMaterial ); continue; } // Scan for diffuse texture else if( sscanf_s( (const char *)&LineBuffer[ LinePosition ], "map_Kd %s", TextBuffer128, sizeof( TextBuffer128 ) ) == 1 ) { // Continue if we don't have any material yet. if( !pMaterial ) { continue; } // Set the diffuse texture path pMaterial->DiffuseTexture = DirectoryPath + std::string( (char *)TextBuffer128 ); } // Scan for bump texture else if( sscanf_s( (const char *)&LineBuffer[ LinePosition ], "map_Disp %s", TextBuffer128, sizeof( TextBuffer128 ) ) == 1 ) { // Continue if we don't have any material yet. if( !pMaterial ) { continue; } // Set the diffuse texture path pMaterial->NormalTexture = DirectoryPath + std::string( (char *)TextBuffer128 ); } } return BIT_OK; }