コード例 #1
0
ファイル: MeshManager.cpp プロジェクト: zc5872061/wonderland
void MeshManager::createMesh(const std::string& name,
					const FloatDataContainer& vertices,
					const FloatDataContainer& uvs,
					const FloatDataContainer& normals,
					const ShortDataContainer& indices,
					CollisionShape type
					)
{
	assert(m_meshes.find(name) == m_meshes.end());
	BasicMesh* result = new BasicMesh();

	result->m_name = name;
	_copyData(vertices, result->m_vertices);
	result->m_verticesCount = vertices.size() / 3;
	_copyData(indices, result->m_indices);
	_copyData(uvs, result->m_uvs);
	_copyData(normals, result->m_normals);
	_copyData(indices, result->m_indices);
	result->m_indicesCount = indices.size() / 3;
	result->setCollisionType(type);

	m_meshes[name] = result;
}
コード例 #2
0
ファイル: MeshManager.cpp プロジェクト: zc5872061/wonderland
BasicMesh* MeshManager::loadMesh(const std::string& fileName, const std::string meshName)
{
	shared_ptr<GameFile> file = GameFile::openFile(fileName, "r");
	std::string readLine;
	BasicMesh* result = new BasicMesh();
	std::string collisionLine;

	while(!(file->eof()))
	{
		readLine = file->readLine();
		if(readLine.size() == 0 || readLine == "\n")
		{
			continue;
		}
		if(readLine.find(NAME_SECTION) == 0)
		{
			loadName(result, readLine);
			continue;
		}
		else if(readLine.find(VERTICES_SECTION) == 0)
		{
			loadVertices(result, readLine, file.get());
			continue;
		}
		else if(readLine.find(UVS_SECTION) == 0)
		{
			loadUvs(result, readLine, file.get());
			continue;
		}
		else if(readLine.find(NORMALS_SECTION) == 0)
		{
			loadNormals(result, readLine, file.get());
			continue;
		}
		else if(readLine.find(INDICES_SECTION) == 0)
		{
			loadIndices(result, readLine, file.get());
			continue;
		}
		else if(readLine.find(COLLISION_SECTION) == 0)
		{
			collisionLine = readLine; // it has to be calculated after all the geometry
			continue;
		}
		else
		{
			Log("Skipping unknown line in mesh file - %s", readLine.c_str());
		}
	}

	if(collisionLine.size() != 0)
	{
		setCollision(result, collisionLine);
	}
	else
	{
		// by default create box collision
		result->setCollisionType(CS_BOX);
		result->m_collisionShape = createCollisionShape(result);
	}

	return result;
}