Ejemplo n.º 1
0
void Model::loaded(FS::IFile& file, bool success, FS::FileSystem& fs)
{
	PROFILE_FUNCTION();
	if (success)
	{
		FileHeader header;
		file.read(&header, sizeof(header));
		if (header.m_magic == FILE_MAGIC &&
			header.m_version <= (uint32_t)FileVersion::LATEST &&
			parseMeshes(file) && parseGeometry(file) && parseBones(file) &&
			parseLODs(file))
		{
			m_size = file.size();
			decrementDepCount();
		}
		else
		{
			g_log_warning.log("renderer") << "Error loading model "
										  << m_path.c_str();
			onFailure();
			return;
		}
	}
	else
	{
		g_log_warning.log("renderer") << "Error loading model "
									  << m_path.c_str();
		onFailure();
	}
}
Ejemplo n.º 2
0
        // http://tfc.duke.free.fr/old/models/md2.htm
        Assets::EntityModel* Md2Parser::doParseModel() {
            const char* cursor = m_begin;
            const int ident = readInt<int32_t>(cursor);
            const int version = readInt<int32_t>(cursor);
            
            if (ident != Md2Layout::Ident)
                throw AssetException() << "Unknown MD2 model ident: " << ident;
            if (version != Md2Layout::Version)
                throw AssetException() << "Unknown MD2 model version: " << version;
            
            /*const size_t skinWidth =*/ readSize<int32_t>(cursor);
            /*const size_t skinHeight =*/ readSize<int32_t>(cursor);
            /*const size_t frameSize =*/ readSize<int32_t>(cursor);
            
            const size_t skinCount = readSize<int32_t>(cursor);
            const size_t frameVertexCount = readSize<int32_t>(cursor);
            /* const size_t texCoordCount =*/ readSize<int32_t>(cursor);
            /* const size_t triangleCount =*/ readSize<int32_t>(cursor);
            const size_t commandCount = readSize<int32_t>(cursor);
            const size_t frameCount = readSize<int32_t>(cursor);
            
            const size_t skinOffset = readSize<int32_t>(cursor);
            /* const size_t texCoordOffset =*/ readSize<int32_t>(cursor);
            /* const size_t triangleOffset =*/ readSize<int32_t>(cursor);
            const size_t frameOffset = readSize<int32_t>(cursor);
            const size_t commandOffset = readSize<int32_t>(cursor);

            const Md2SkinList skins = parseSkins(m_begin + skinOffset, skinCount);
            const Md2FrameList frames = parseFrames(m_begin + frameOffset, frameCount, frameVertexCount);
            const Md2MeshList meshes = parseMeshes(m_begin + commandOffset, commandCount);
            
            return buildModel(skins, frames, meshes);
        }
Ejemplo n.º 3
0
bool Model::load(FS::IFile& file)
{
	PROFILE_FUNCTION();
	FileHeader header;
	file.read(&header, sizeof(header));
	if (header.m_magic == FILE_MAGIC 
		&& header.m_version <= (uint32)FileVersion::LATEST 
		&& parseMeshes(file) 
		&& parseGeometry(file) 
		&& parseBones(file) 
		&& parseLODs(file))
	{
		m_size = file.size();
		return true;
	}

	g_log_warning.log("renderer") << "Error loading model " << getPath().c_str();
	return false;
}
Ejemplo n.º 4
0
bool Model::load(FS::IFile& file)
{
	PROFILE_FUNCTION();
	FileHeader header;
	file.read(&header, sizeof(header));

	if (header.magic != FILE_MAGIC)
	{
		g_log_warning.log("Renderer") << "Corrupted model " << getPath().c_str();
		return false;
	}

	if(header.version > (u32)FileVersion::LATEST)
	{
		g_log_warning.log("Renderer") << "Unsupported version of model " << getPath().c_str();
		return false;
	}

	u32 global_flags = 0; // backward compatibility
	if(header.version > (u32)FileVersion::WITH_FLAGS)
	{
		file.read(&global_flags, sizeof(global_flags));
	}

	bgfx::VertexDecl global_vertex_decl;
	if (header.version > (u32)FileVersion::SINGLE_VERTEX_DECL && header.version <= (u32)FileVersion::MULTIPLE_VERTEX_DECLS)
	{
		parseVertexDeclEx(file, &global_vertex_decl);
	}

	if (parseMeshes(global_vertex_decl, file, (FileVersion)header.version, global_flags)
		&& parseBones(file)
		&& parseLODs(file))
	{
		m_size = file.size();
		return true;
	}

	g_log_error.log("Renderer") << "Error loading model " << getPath().c_str();
	return false;
}