Exemplo n.º 1
0
void CRender::LoadVisuals(IReader *fs)
{
	IReader*		chunk	= 0;
	u32			index	= 0;
	dxRender_Visual*		V		= 0;
	ogf_header		H;

	while ((chunk=fs->open_chunk(index))!=0)
	{
		chunk->r_chunk_safe			(OGF_HEADER,&H,sizeof(H));
		V = Models->Instance_Create	(H.type);
		V->Load(0,chunk,0);
		Visuals.push_back(V);

		chunk->close();
		index++;
	}
}
Exemplo n.º 2
0
dxRender_Visual*	CModelPool::Instance_Load		(const char* N, BOOL allow_register)
{
	dxRender_Visual	*V;
	string_path		fn;
	string_path		name;

	// Add default ext if no ext at all
	if (0==strext(N))	strconcat	(sizeof(name),name,N,".ogf");
	else				strcpy_s	(name,sizeof(name),N);

	// Load data from MESHES or LEVEL
	if (!FS.exist(N))	{
		if (!FS.exist(fn, "$level$", name))
			if (!FS.exist(fn, "$game_meshes$", name)){
#ifdef _EDITOR
				Msg("! Can't find model file '%s'.",name);
                return 0;
#else            
				xrDebug::Fatal(DEBUG_INFO,"Can't find model file '%s'.",name);
#endif
			}
	} else {
		strcpy_s			(fn,N);
	}
	
	// Actual loading
#ifdef DEBUG
	if (bLogging)		Msg		("- Uncached model loading: %s",fn);
#endif // DEBUG

	IReader*			data	= FS.r_open(fn);
	ogf_header			H;
	data->r_chunk_safe	(OGF_HEADER,&H,sizeof(H));
	V = Instance_Create (H.type);
	V->Load				(N,data,0);
	FS.r_close			(data);
	g_pGamePersistent->RegisterModel(V);

	// Registration
	if (allow_register) Instance_Register(N,V);

	return V;
}
Exemplo n.º 3
0
//-----------------------------------------------------------------------
BOOL motions_value::load		(LPCSTR N, IReader *data, vecBones* bones)
{

	m_id						= N;

	bool bRes					= true;
	// Load definitions
	U16Vec rm_bones				(bones->size(),BI_NONE);
	IReader* MP 				= data->open_chunk(OGF_S_SMPARAMS);

	if (MP)
	{
		u16 vers 				= MP->r_u16();
		u16 part_bone_cnt		= 0;
		string128 				buf;
		R_ASSERT3				(vers<=xrOGF_SMParamsVersion,"Invalid OGF/OMF version:",N);
		
		// partitions
		u16						part_count;
		part_count 				= MP->r_u16();

		for (u16 part_i=0; part_i<part_count; part_i++)
		{
			CPartDef& PART		= m_partition[part_i];
			MP->r_stringZ		(buf,sizeof(buf));
			PART.Name			= _strlwr(buf);
			PART.bones.resize	(MP->r_u16());

			for (xr_vector<u32>::iterator b_it=PART.bones.begin(); b_it<PART.bones.end(); b_it++)
			{
				MP->r_stringZ	(buf,sizeof(buf));
				u16 m_idx 		= u16			(MP->r_u32());
				*b_it			= find_bone_id	(bones,buf);
#ifdef _EDITOR
				if (*b_it==BI_NONE )
                {
					bRes		= false;
					Msg			("! Can't find bone: '%s'", buf);
				}

				if (rm_bones.size() <= m_idx)
                {
					bRes		= false;
					Msg			("! Can't load: '%s' invalid bones count", N);
				}
#else
				VERIFY3			(*b_it!=BI_NONE,"Can't find bone:", buf);
#endif
				if (bRes)		rm_bones[m_idx] = u16(*b_it);
			}
			part_bone_cnt		= u16(part_bone_cnt + (u16)PART.bones.size());
		}

#ifdef _EDITOR
		if (part_bone_cnt!=(u16)bones->size()){
			bRes = false;
			Msg("! Different bone count[%s] [Object: '%d' <-> Motions: '%d']", N, bones->size(),part_bone_cnt);
		}
#else
		VERIFY3(part_bone_cnt==(u16)bones->size(),"Different bone count '%s'",N);
#endif
		if (bRes)
		{
			// motion defs (cycle&fx)
			u16 mot_count			= MP->r_u16();
            m_mdefs.resize			(mot_count);

			for (u16 mot_i=0; mot_i<mot_count; mot_i++)
			{
				MP->r_stringZ		(buf,sizeof(buf));
				shared_str nm		= _strlwr		(buf);
				u32 dwFlags			= MP->r_u32		();
				CMotionDef&	D		= m_mdefs[mot_i];
                D.Load				(MP,dwFlags,vers);
//.             m_mdefs.push_back	(D);
				
				if (dwFlags&esmFX)	
					m_fx.insert		(mk_pair(nm,mot_i));
				else				
					m_cycle.insert	(mk_pair(nm,mot_i));

                m_motion_map.insert	(mk_pair(nm,mot_i));
			}
		}
		MP->close();
	}else
	{
		xrDebug::Fatal	(DEBUG_INFO,"Old skinned model version unsupported! (%s)",N);
	}
	if (!bRes)	return false;

	// Load animation
	IReader*	MS		= data->open_chunk(OGF_S_MOTIONS);
	if (!MS) 			return false;

	u32			dwCNT	= 0;
	MS->r_chunk_safe	(0,&dwCNT,sizeof(dwCNT));
    VERIFY		(dwCNT<0x3FFF); // MotionID 2 bit - slot, 14 bit - motion index

	// set per bone motion size
	for (u32 i=0; i<bones->size(); i++)
		m_motions[bones->at(i)->name].resize(dwCNT);

	// load motions
	for (u16 m_idx=0; m_idx<(u16)dwCNT; m_idx++){
		string128			mname;
		R_ASSERT			(MS->find_chunk(m_idx+1));             
		MS->r_stringZ		(mname,sizeof(mname));
#ifdef _DEBUG        
		// sanity check
		xr_strlwr			(mname);
        accel_map::iterator I= m_motion_map.find(mname); 
        VERIFY3				(I!=m_motion_map.end(),"Can't find motion:",mname);
        VERIFY3				(I->second==m_idx,"Invalid motion index:",mname);
#endif
		u32 dwLen			= MS->r_u32();
		for (u32 i=0; i<bones->size(); i++){
			u16 bone_id		= rm_bones[i];
			VERIFY2			(bone_id!=BI_NONE,"Invalid remap index.");
			CMotion&		M	= m_motions[bones->at(bone_id)->name][m_idx];
			M.set_count			(dwLen);
			M.set_flags			(MS->r_u8());
            
            if (M.test_flag(flRKeyAbsent))	{
                CKeyQR* r 		= (CKeyQR*)MS->pointer();
				u32 crc_q		= crc32(r,sizeof(CKeyQR));
				M._keysR.create	(crc_q,1,r);
                MS->advance		(1 * sizeof(CKeyQR));
            }else{
                u32 crc_q		= MS->r_u32	();
                M._keysR.create	(crc_q,dwLen,(CKeyQR*)MS->pointer());
                MS->advance		(dwLen * sizeof(CKeyQR));
            }
            if (M.test_flag(flTKeyPresent))	
            {
                u32 crc_t		= MS->r_u32	();
                if(M.test_flag(flTKey16IsBit))
                {
                    M._keysT16.create	(crc_t,dwLen,(CKeyQT16*)MS->pointer());
                    MS->advance			(dwLen * sizeof(CKeyQT16));
                }else
                {
                    M._keysT8.create	(crc_t,dwLen,(CKeyQT8*)MS->pointer());
                    MS->advance			(dwLen * sizeof(CKeyQT8));
                };
                
                MS->r_fvector3	(M._sizeT);
                MS->r_fvector3	(M._initT);
            }else
            {
                MS->r_fvector3	(M._initT);
            }
		}
	}
//	Msg("Motions %d/%d %4d/%4d/%d, %s",p_cnt,m_cnt, m_load,m_total,m_r,N);
	MS->close();

	return bRes;
}