Esempio n. 1
0
void CPicoModel::load( const char *name, const int frame ){
	CPicoSurface *surf;
	picoSurface_t *pSurface;
	int i;

	m_name = new char[strlen( name ) + 1];
	strcpy( m_name,name );

	m_frame = frame;

	if ( !( m_pModel = PicoLoadModel( m_name, frame ) ) ) {
		int len = strlen( m_name );

		// Try loading an mdc if md3 fails and vice-versa (fixme: only do this for games with mdc support)
		if ( !strcmp( m_name + len - 4, ".md3" ) ) {
			m_name[len - 1] = 'c';
			m_pModel = PicoLoadModel( m_name, frame );
		}
		else if ( !strcmp( m_name + len - 4, ".mdc" ) ) {
			m_name[len - 1] = '3';
			m_pModel = PicoLoadModel( m_name, frame );
		}
	}

	if ( m_pModel ) {
		m_children = g_ptr_array_new();
		aabb_clear( &m_BBox );
		for ( i = 0; i < PicoGetModelNumSurfaces( m_pModel ); i++ )
		{
			pSurface = PicoGetModelSurface( m_pModel,i );
			surf = new CPicoSurface( pSurface );
			g_ptr_array_add( m_children, surf );
			aabb_extend_by_aabb( &m_BBox, surf->GetAABB() );
		}
	}
	else
	{
		m_BBox.origin[0] = m_BBox.origin[1] = m_BBox.origin[2] = 0;
		m_BBox.extents[0] = m_BBox.extents[1] = m_BBox.extents[2] = 0;
	}

	m_parents = g_ptr_array_new();
}
Esempio n. 2
0
void CPicoModel::Reload( void ){
	CPicoSurface *surf;
	picoSurface_t *pSurface;
	int i;
	unsigned int j;

	// Get rid of the old model
	if ( m_pModel ) {
		for ( j = 0; j < m_children->len; j++ ) {
			( (CPicoSurface*)m_children->pdata[j] )->DecRef();
			g_ptr_array_remove_index_fast( m_children, j );
		}
	}

	// And reload it
	m_pModel = PicoLoadModel( m_name, m_frame );

	if ( m_pModel ) {
		m_children = g_ptr_array_new();
		aabb_clear( &m_BBox );
		for ( i = 0; i < PicoGetModelNumSurfaces( m_pModel ); i++ )
		{
			pSurface = PicoGetModelSurface( m_pModel,i );
			surf = new CPicoSurface( pSurface );
			g_ptr_array_add( m_children, surf );
			aabb_extend_by_aabb( &m_BBox, surf->GetAABB() );
		}
	}
	else
	{
		m_BBox.origin[0] = m_BBox.origin[1] = m_BBox.origin[2] = 0;
		m_BBox.extents[0] = m_BBox.extents[1] = m_BBox.extents[2] = 0;
	}

	for ( j = 0; j < m_parents->len; j++ ) {
		( (CPicoParent*)m_parents->pdata[j] )->UpdateShaders();
	}
}
Esempio n. 3
0
picoModel_t    *LoadModel(char *name, int frame)
{
	int             i;
	picoModel_t    *model, **pm;


	/* init */
	if(numPicoModels <= 0)
		memset(picoModels, 0, sizeof(picoModels));

	/* dummy check */
	if(name == NULL || name[0] == '\0')
		return NULL;

	/* try to find existing picoModel */
	model = FindModel(name, frame);
	if(model != NULL)
		return model;

	/* none found, so find first non-null picoModel */
	pm = NULL;
	for(i = 0; i < MAX_MODELS; i++)
	{
		if(picoModels[i] == NULL)
		{
			pm = &picoModels[i];
			break;
		}
	}

	/* too many picoModels? */
	if(pm == NULL)
		Error("MAX_MODELS (%d) exceeded, there are too many model files referenced by the map.", MAX_MODELS);

	/* attempt to parse model */
	*pm = PicoLoadModel((char *)name, frame);

	/* if loading failed, make a bogus model to silence the rest of the warnings */
	if(*pm == NULL)
	{
		/* allocate a new model */
		*pm = PicoNewModel();
		if(*pm == NULL)
			return NULL;

		/* set data */
		PicoSetModelName(*pm, name);
		PicoSetModelFrameNum(*pm, frame);
	}

	/* debug code */
#if 0
	{
		int             numSurfaces, numVertexes;
		picoSurface_t  *ps;


		Sys_Printf("Model %s\n", name);
		numSurfaces = PicoGetModelNumSurfaces(*pm);
		for(i = 0; i < numSurfaces; i++)
		{
			ps = PicoGetModelSurface(*pm, i);
			numVertexes = PicoGetSurfaceNumVertexes(ps);
			Sys_Printf("Surface %d has %d vertexes\n", i, numVertexes);
		}
	}
#endif

	/* set count */
	if(*pm != NULL)
		numPicoModels++;

	/* return the picoModel */
	return *pm;
}