Beispiel #1
0
		void ExtractFileName(String::Vector& p, const bool systemDependant)
		{
			for(String::Vector::iterator i = p.begin() ; i != p.end() ; ++i)
			{
				String out;
				Yuni::Core::IO::ExtractFileName(out, *i, systemDependant);
				*i = out;
			}
		}
Beispiel #2
0
		bool MakeDir(const String& p)
		{
			if (p.empty())
				return true;
			// TODO Use the boost library, which has a better implementation that this one
			String::Vector parts;
			p.explode(parts, SeparatorAsString, false);
			String pth;
			bool hasBeenCreated(false);
			if (p[0] == '/' || p[0] == '\\')
				pth += Separator;

			for (String::Vector::const_iterator i = parts.begin(); i != parts.end(); ++i)
			{
				pth += *i;
# ifndef TA3D_PLATFORM_WINDOWS
				pth += Separator;
# endif
				if (!Exists(pth))
				{
					LOG_DEBUG(LOG_PREFIX_PATHS << "`" << pth << "` does not exist !");
# ifdef TA3D_PLATFORM_WINDOWS
					if (mkdir(pth.c_str()))
# else
                        if (mkdir(pth.c_str(), 0755))
# endif
						{
							// TODO Use the logging system instead
							LOG_ERROR(LOG_PREFIX_PATHS << "Impossible to create the folder `" << pth << "`");
							return false;
						}
						else
							hasBeenCreated = true;
				}
# ifdef TA3D_PLATFORM_WINDOWS
				pth += Separator;
# endif
			}
			if (hasBeenCreated)
				LOG_INFO(LOG_PREFIX_PATHS << "Created folder: `" << p << "`");
			return true;
		}
Beispiel #3
0
	void MeshOBJ::load(File *file, const String &filename)
	{
		destroy3DM();

		MeshOBJ *cur = this;
		name = "default";
		bool firstObject = true;
		vector<Vector3D>	lVertex;
		vector<Vector2D>	lTcoord;
		vector<int>			face;
		HashMap<Material>::Dense	mtllib;
		Material                    currentMtl;

		while (!file->eof()) // Reads the whole file
		{
			String line;
			file->readLine(line);
			line.trim();
			String::Vector args;
			line.explode(args, ' ', false, false, true);
			if (!args.empty())
			{
				if ( (args[0] == "o" || args[0] == "g") && args.size() > 1)      // Creates a new object
				{
					if (!face.empty())
					{
						if (firstObject && cur->name.empty())
							cur->name = "default";
						cur->obj_finalize( filename, face, lVertex, lTcoord, &currentMtl );
						face.clear();
						cur->child = new MeshOBJ();
						cur = static_cast<MeshOBJ*>(cur->child);
					}
					firstObject = false;
					cur->name = args[1];
				}
				else if (args[0] == "mtllib" && args.size() > 1)        // Read given material libraries
				{
					for(String::Vector::iterator s = args.begin() + 1 ; s != args.end() ; ++s)
					{
						File *src_mtl = VFS::Instance()->readFile(String("objects3d/") << *s);
						if (!src_mtl)
							continue;
						Material mtl;
						while (!src_mtl->eof())
						{
							String line0;
							src_mtl->readLine(line0);
							line0.trim();
							String::Vector args0;
							line0.explode(args0, ' ', false, false, true);
							if (!args0.empty())
							{
								if (args0[0] == "newmtl")
									mtl.name = args0[1];
								else
								{
									if (args0[0] == "map_Kd")
									{
										mtl.textureName = String("textures/") << args0[1];
										mtllib[mtl.name] = mtl;
									}
								}
							}
						}
						delete src_mtl;
					}
				}
				else
				{
					if (args[0] == "usemtl" && args.size() > 1)        // Change current material
					{
						if (mtllib.count(args[1]))
							currentMtl = mtllib[args[1]];
						else
							currentMtl.textureName.clear();
					}
					else if (args[0] == "v" && args.size() > 3)  // Add a vertex to current object
						lVertex.push_back( Vector3D(args[1].to<float>(), args[2].to<float>(), args[3].to<float>()));
					else if (args[0] == "vn" && args.size() > 3)  // Add a normal vector to current object
					{}
					else if (args[0] == "vt" && args.size() > 2)  // Add a texture coordinate vector to current object
						lTcoord.push_back( Vector2D( args[1].to<float>(), args[2].to<float>()));
					else if (args[0] == "f" && args.size() > 1)  // Add a face to current object
					{
						vector<int>  vertex_idx;
						vector<int>  tcoord_idx;
						bool first_string = true;
						for(String::Vector::iterator s = args.begin() ; s != args.end() ; ++s)
						{
							// The first string is crap if we read it as vertex data !!
							if (first_string)
							{
								first_string = false;
								continue;
							}

							String::Vector data;
							s->trim();
							s->explode(data, '/', false, false, true);

							if (!data.empty())
							{
								vertex_idx.push_back( data[0].to<int>() - 1);
								if (vertex_idx.back() < 0)
								{	LOG_DEBUG(LOG_PREFIX_OBJ << "parser : " << line << " -> " << *s << " -> " << vertex_idx.back());	}
								if (data.size() >= 2)
									tcoord_idx.push_back(data[1].to<int>() - 1);
								else
									tcoord_idx.push_back(-1);
							}
						}

						for (uint32 i = 2; i < vertex_idx.size(); ++i) // Make triangles (FAN method)
						{
							face.push_back(vertex_idx[0]);
							face.push_back(tcoord_idx[0]);

							face.push_back(vertex_idx[i-1]);
							face.push_back(tcoord_idx[i-1]);

							face.push_back(vertex_idx[i]);
							face.push_back(tcoord_idx[i]);
						}
					}
				}
			}
		}

		cur->obj_finalize(filename, face, lVertex, lTcoord, &currentMtl);
	}