示例#1
0
文件: surface.c 项目: Elzair/q3map2
void lwFreeSurface( lwSurface *surf ){
	if ( surf ) {
		if ( surf->name ) {
			_pico_free( surf->name );
		}
		if ( surf->srcname ) {
			_pico_free( surf->srcname );
		}

		lwListFree( surf->shader, (void *) lwFreePlugin );

		lwListFree( surf->color.tex, (void *) lwFreeTexture );
		lwListFree( surf->luminosity.tex, (void *) lwFreeTexture );
		lwListFree( surf->diffuse.tex, (void *) lwFreeTexture );
		lwListFree( surf->specularity.tex, (void *) lwFreeTexture );
		lwListFree( surf->glossiness.tex, (void *) lwFreeTexture );
		lwListFree( surf->reflection.val.tex, (void *) lwFreeTexture );
		lwListFree( surf->transparency.val.tex, (void *) lwFreeTexture );
		lwListFree( surf->eta.tex, (void *) lwFreeTexture );
		lwListFree( surf->translucency.tex, (void *) lwFreeTexture );
		lwListFree( surf->bump.tex, (void *) lwFreeTexture );

		_pico_free( surf );
	}
}
示例#2
0
void PicoFreeVertexCombinationHashTable (picoVertexCombinationHash_t **hashTable)
{
	int i;
	picoVertexCombinationHash_t *vertexCombinationHash;
	picoVertexCombinationHash_t *nextVertexCombinationHash;

	/* dummy check */
	if (hashTable == NULL)
		return;

	for (i = 0; i < HASHTABLE_SIZE; i++) {
		if (hashTable[i]) {
			nextVertexCombinationHash = NULL;

			for (vertexCombinationHash = hashTable[i]; vertexCombinationHash; vertexCombinationHash
					= nextVertexCombinationHash) {
				nextVertexCombinationHash = vertexCombinationHash->next;
				if (vertexCombinationHash->data != NULL) {
					_pico_free(vertexCombinationHash->data);
				}
				_pico_free(vertexCombinationHash);
			}
		}
	}

	_pico_free(hashTable);
}
示例#3
0
/**
 * @brief frees a model and all associated data
 */
void PicoFreeModel (picoModel_t *model)
{
	int i;

	/* sanity check */
	if (model == NULL)
		return;

	/* free bits */
	if (model->name)
		_pico_free(model->name);

	if (model->fileName)
		_pico_free(model->fileName);

	/* free shaders */
	for (i = 0; i < model->numShaders; i++)
		PicoFreeShader(model->shader[i]);
	free(model->shader);

	/* free surfaces */
	for (i = 0; i < model->numSurfaces; i++)
		PicoFreeSurface(model->surface[i]);
	free(model->surface);

	/* free the model */
	_pico_free(model);
}
示例#4
0
void lwFreeEnvelope( lwEnvelope *env )
{
   if ( env ) {
      if ( env->name ) _pico_free( env->name );
      lwListFree( env->key, _pico_free );
      lwListFree( env->cfilter, (void (*)(void *))lwFreePlugin );
      _pico_free( env );
   }
}
示例#5
0
void lwFreeLayer( lwLayer *layer )
{
   if ( layer ) {
      if ( layer->name ) _pico_free( layer->name );
      lwFreePoints( &layer->point );
      lwFreePolygons( &layer->polygon );
      lwListFree( layer->vmap, (void *) lwFreeVMap );
      _pico_free( layer );
   }
}
示例#6
0
/**
 * @brief frees a surface and all associated data
 */
void PicoFreeSurface (picoSurface_t *surface)
{
	int i;

	/* dummy check */
	if (surface == NULL)
		return;

	/* free bits */
	_pico_free(surface->xyz);
	_pico_free(surface->normal);
	_pico_free(surface->smoothingGroup);
	_pico_free(surface->index);
	_pico_free(surface->faceNormal);

	if (surface->name)
		_pico_free(surface->name);

	/* free arrays */
	for (i = 0; i < surface->numSTArrays; i++)
		_pico_free(surface->st[i]);
	free(surface->st);
	for (i = 0; i < surface->numColorArrays; i++)
		_pico_free(surface->color[i]);
	free(surface->color);

	/* free the surface */
	_pico_free(surface);
}
示例#7
0
void lwFreeTags( lwTagList *tlist )
{
   int i;

   if ( tlist ) {
      if ( tlist->tag ) {
         for ( i = 0; i < tlist->count; i++ )
            if ( tlist->tag[ i ] ) _pico_free( tlist->tag[ i ] );
         _pico_free( tlist->tag );
      }
      memset( tlist, 0, sizeof( lwTagList ));
   }
}
示例#8
0
int lwGetTags( picoMemStream_t *fp, int cksize, lwTagList *tlist ){
	char *buf, *bp;
	int i, len, ntags;

	if ( cksize == 0 ) {
		return 1;
	}

	/* read the whole chunk */

	set_flen( 0 );
	buf = getbytes( fp, cksize );
	if ( !buf ) {
		return 0;
	}

	/* count the strings */

	ntags = 0;
	bp = buf;
	while ( bp < buf + cksize ) {
		len = strlen( bp ) + 1;
		len += len & 1;
		bp += len;
		++ntags;
	}

	/* expand the string array to hold the new tags */

	tlist->offset = tlist->count;
	tlist->count += ntags;
	if ( !_pico_realloc( (void *) &tlist->tag, ( tlist->count - ntags ) * sizeof( char * ), tlist->count * sizeof( char * ) ) ) {
		goto Fail;
	}
	memset( &tlist->tag[ tlist->offset ], 0, ntags * sizeof( char * ) );

	/* copy the new tags to the tag array */

	bp = buf;
	for ( i = 0; i < ntags; i++ )
		tlist->tag[ i + tlist->offset ] = sgetS0( &bp );

	_pico_free( buf );
	return 1;

Fail:
	if ( buf ) {
		_pico_free( buf );
	}
	return 0;
}
示例#9
0
文件: surface.c 项目: Elzair/q3map2
void lwFreePlugin( lwPlugin *p ){
	if ( p ) {
		if ( p->ord ) {
			_pico_free( p->ord );
		}
		if ( p->name ) {
			_pico_free( p->name );
		}
		if ( p->data ) {
			_pico_free( p->data );
		}
		_pico_free( p );
	}
}
示例#10
0
文件: surface.c 项目: Elzair/q3map2
void lwFreeTexture( lwTexture *t ){
	if ( t ) {
		if ( t->ord ) {
			_pico_free( t->ord );
		}
		switch ( t->type ) {
		case ID_IMAP:
			if ( t->param.imap.vmap_name ) {
				_pico_free( t->param.imap.vmap_name );
			}
			if ( t->tmap.ref_object ) {
				_pico_free( t->tmap.ref_object );
			}
			break;
		case ID_PROC:
			if ( t->param.proc.name ) {
				_pico_free( t->param.proc.name );
			}
			if ( t->param.proc.data ) {
				_pico_free( t->param.proc.data );
			}
			break;
		case ID_GRAD:
			if ( t->param.grad.key ) {
				_pico_free( t->param.grad.key );
			}
			if ( t->param.grad.ikey ) {
				_pico_free( t->param.grad.ikey );
			}
			break;
		}
		_pico_free( t );
	}
}
示例#11
0
void lwFreePoints( lwPointList *point )
{
   int i;

   if ( point ) {
      if ( point->pt ) {
         for ( i = 0; i < point->count; i++ ) {
            if ( point->pt[ i ].pol ) _pico_free( point->pt[ i ].pol );
            if ( point->pt[ i ].vm ) _pico_free( point->pt[ i ].vm );
         }
         _pico_free( point->pt );
      }
      memset( point, 0, sizeof( lwPointList ));
   }
}
示例#12
0
/**
 * @brief frees a shader and all associated data -sea
 */
void PicoFreeShader (picoShader_t *shader)
{
	/* dummy check */
	if (shader == NULL)
		return;

	/* free bits */
	if (shader->name)
		_pico_free(shader->name);
	if (shader->mapName)
		_pico_free(shader->mapName);

	/* free the shader */
	_pico_free(shader);
}
示例#13
0
/**
 * @brief creates a new pico surface
 */
picoSurface_t *PicoNewSurface (picoModel_t *model)
{
	/* allocate and clear */
	picoSurface_t *surface = _pico_alloc(sizeof(*surface));
	if (surface == NULL)
		return NULL;

	/* attach it to the model */
	if (model != NULL) {
		char surfaceName[64];
		/* adjust model */
		if (!PicoAdjustModel(model, 0, model->numSurfaces + 1)) {
			_pico_free(surface);
			return NULL;
		}

		/* attach */
		model->surface[model->numSurfaces - 1] = surface;
		surface->model = model;

		/* set default name */
		sprintf(surfaceName, "Unnamed_%d", model->numSurfaces);
		PicoSetSurfaceName(surface, surfaceName);
	}

	/* return */
	return surface;
}
示例#14
0
/**
 * @brief creates a new pico shader and returns its index. -sea
 */
picoShader_t *PicoNewShader (picoModel_t *model)
{
	picoShader_t *shader;

	/* allocate and clear */
	shader = _pico_alloc(sizeof(*shader));
	if (shader == NULL)
		return NULL;

	/* attach it to the model */
	if (model != NULL) {
		/* adjust model */
		if (!PicoAdjustModel(model, model->numShaders + 1, 0)) {
			_pico_free(shader);
			return NULL;
		}

		/* attach */
		model->shader[model->numShaders - 1] = shader;
		shader->model = model;
	}

	/* setup default shader colors */
	_pico_set_color(shader->ambientColor, 0, 0, 0, 0);
	_pico_set_color(shader->diffuseColor, 255, 255, 255, 1);
	_pico_set_color(shader->specularColor, 0, 0, 0, 0);

	/* no need to do this, but i do it anyway */
	shader->transparency = 0;
	shader->shininess = 0;

	/* return the newly created shader */
	return shader;
}
示例#15
0
void lwFreeClip( lwClip *clip ){
	if ( clip ) {
		lwListFree( (void*) clip->ifilter, lwFreePlugin );
		lwListFree( (void*) clip->pfilter, lwFreePlugin );
		_pico_free( clip );
	}
}
示例#16
0
picoModel_t *PicoModuleLoadModelStream (const picoModule_t* module, const char *fileName, void* inputStream,
		PicoInputStreamReadFunc inputStreamRead, size_t streamLength, int frameNum)
{
	picoModel_t *model;
	picoByte_t *buffer;
	int bufSize;

	/* init */
	model = NULL;

	if (inputStream == NULL) {
		_pico_printf(PICO_ERROR, "PicoLoadModel: invalid input stream (inputStream == NULL)");
		return NULL;
	}

	if (inputStreamRead == NULL) {
		_pico_printf(PICO_ERROR, "PicoLoadModel: invalid input stream (inputStreamRead == NULL)");
		return NULL;
	}

	buffer = _pico_alloc(streamLength + 1);

	bufSize = (int) inputStreamRead(inputStream, buffer, streamLength);
	buffer[bufSize] = '\0';

	model = PicoModuleLoadModel(module, fileName, buffer, bufSize, frameNum);
	if (model != 0)
		_pico_free(buffer);

	/* return */
	return model;
}
示例#17
0
int lwGetPoints( picoMemStream_t *fp, int cksize, lwPointList *point )
{
   float *f;
   int np, i, j;

   if ( cksize == 1 ) return 1;

   /* extend the point array to hold the new points */

   np = cksize / 12;
   point->offset = point->count;
   point->count += np;
   if ( !_pico_realloc( (void *) &point->pt, (point->count - np) * sizeof( lwPoint ), point->count * sizeof( lwPoint )) )
      return 0;
   memset( &point->pt[ point->offset ], 0, np * sizeof( lwPoint ));

   /* read the whole chunk */

   f = ( float * ) getbytes( fp, cksize );
   if ( !f ) return 0;
   revbytes( f, 4, np * 3 );

   /* assign position values */

   for ( i = 0, j = 0; i < np; i++, j += 3 ) {
      point->pt[ i ].pos[ 0 ] = f[ j ];
      point->pt[ i ].pos[ 1 ] = f[ j + 1 ];
      point->pt[ i ].pos[ 2 ] = f[ j + 2 ];
   }

   _pico_free( f );
   return 1;
}
示例#18
0
static lwTexture *get_texture( char *s )
{
   lwTexture *tex;

   tex = _pico_calloc( 1, sizeof( lwTexture ));
   if ( !tex ) return NULL;

   tex->tmap.size.val[ 0 ] =
   tex->tmap.size.val[ 1 ] =
   tex->tmap.size.val[ 2 ] = 1.0f;
   tex->opacity.val = 1.0f;
   tex->enabled = 1;

   if ( strstr( s, "Image Map" )) {
      tex->type = ID_IMAP;
      if ( strstr( s, "Planar" ))           tex->param.imap.projection = 0;
      else if ( strstr( s, "Cylindrical" )) tex->param.imap.projection = 1;
      else if ( strstr( s, "Spherical" ))   tex->param.imap.projection = 2;
      else if ( strstr( s, "Cubic" ))       tex->param.imap.projection = 3;
      else if ( strstr( s, "Front" ))       tex->param.imap.projection = 4;
      tex->param.imap.aa_strength = 1.0f;
      tex->param.imap.amplitude.val = 1.0f;
      _pico_free( s );
   }
   else {
      tex->type = ID_PROC;
      tex->param.proc.name = s;
   }

   return tex;
}
示例#19
0
void PicoSetModelName (picoModel_t *model, const char *name)
{
	if (model == NULL || name == NULL)
		return;
	if (model->name != NULL)
		_pico_free(model->name);

	model->name = _pico_clone_alloc(name);
}
示例#20
0
void PicoSetModelFileName (picoModel_t *model, const char *fileName)
{
	if (model == NULL || fileName == NULL)
		return;
	if (model->fileName != NULL)
		_pico_free(model->fileName);

	model->fileName = _pico_clone_alloc(fileName);
}
示例#21
0
void PicoSetShaderName (picoShader_t *shader, const char *name)
{
	if (shader == NULL || name == NULL)
		return;
	if (shader->name != NULL)
		_pico_free(shader->name);

	shader->name = _pico_clone_alloc(name);
}
示例#22
0
void PicoSetShaderMapName (picoShader_t *shader, char *mapName)
{
	if (shader == NULL || mapName == NULL)
		return;
	if (shader->mapName != NULL)
		_pico_free(shader->mapName);

	shader->mapName = _pico_clone_alloc(mapName);
}
示例#23
0
void PicoSetSurfaceName (picoSurface_t *surface, char *name)
{
	if (surface == NULL || name == NULL)
		return;
	if (surface->name != NULL)
		_pico_free(surface->name);

	surface->name = _pico_clone_alloc(name);
}
示例#24
0
文件: lwo2.c 项目: ArtanAhmeti/lab
void lwFreeObject( lwObject *object ){
	if ( object ) {
		lwListFree( object->layer, (ListFreeFunc) lwFreeLayer );
		lwListFree( object->env, (ListFreeFunc) lwFreeEnvelope );
		lwListFree( object->clip, (ListFreeFunc) lwFreeClip );
		lwListFree( object->surf, (ListFreeFunc) lwFreeSurface );
		lwFreeTags( &object->taglist );
		_pico_free( object );
	}
}
示例#25
0
void lwFreePolygons( lwPolygonList *plist )
{
   int i, j;

   if ( plist ) {
      if ( plist->pol ) {
         for ( i = 0; i < plist->count; i++ ) {
            if ( plist->pol[ i ].v ) {
               for ( j = 0; j < plist->pol[ i ].nverts; j++ )
                  if ( plist->pol[ i ].v[ j ].vm )
                     _pico_free( plist->pol[ i ].v[ j ].vm );
            }
         }
         if ( plist->pol[ 0 ].v )
            _pico_free( plist->pol[ 0 ].v );
         _pico_free( plist->pol );
      }
      memset( plist, 0, sizeof( lwPolygonList ));
   }
}
示例#26
0
static picoShader_t *_obj_default_shader (picoModel_t *model)
{
	picoShader_t *picoShader = PicoNewShader(model);
	char *skinname = _pico_clone_alloc(model->fileName);
	_pico_setfext(skinname, "");

	PicoSetShaderName(picoShader, skinname);

	_pico_free(skinname);

	return picoShader;
}
示例#27
0
static void _ase_free_materials( aseMaterial_t **list )
{
	aseMaterial_t* mtl = *list;
	aseSubMaterial_t* subMtl = NULL;

	aseMaterial_t* mtlTemp = NULL;
	aseSubMaterial_t* subMtlTemp = NULL;

	while ( mtl )
	{
		subMtl = mtl->subMtls;
		while ( subMtl )
		{
			subMtlTemp = subMtl->next;
			_pico_free ( subMtl );
			subMtl = subMtlTemp;
		}
		mtlTemp = mtl->next;
		_pico_free ( mtl );
		mtl = mtlTemp;
	}
	(*list) = NULL;
}
示例#28
0
int lwResolvePolySurfaces( lwPolygonList *polygon, lwTagList *tlist,
						   lwSurface **surf, int *nsurfs ){
	lwSurface **s, *st;
	int i, index;

	if ( tlist->count == 0 ) {
		return 1;
	}

	s = _pico_calloc( tlist->count, sizeof( lwSurface * ) );
	if ( !s ) {
		return 0;
	}

	for ( i = 0; i < tlist->count; i++ ) {
		st = *surf;
		while ( st ) {
			if ( !strcmp( st->name, tlist->tag[ i ] ) ) {
				s[ i ] = st;
				break;
			}
			st = st->next;
		}
	}

	for ( i = 0; i < polygon->count; i++ ) {
		index = ( int ) ( (size_t)polygon->pol[ i ].surf );
		if ( index < 0 || index > tlist->count ) {
			return 0;
		}
		if ( !s[ index ] ) {
			s[ index ] = lwDefaultSurface();
			if ( !s[ index ] ) {
				return 0;
			}
			s[ index ]->name = _pico_alloc( strlen( tlist->tag[ index ] ) + 1 );
			if ( !s[ index ]->name ) {
				return 0;
			}
			strcpy( s[ index ]->name, tlist->tag[ index ] );
			lwListAdd( (void **) surf, s[ index ] );
			*nsurfs = *nsurfs + 1;
		}
		polygon->pol[ i ].surf = s[ index ];
	}

	_pico_free( s );
	return 1;
}
示例#29
0
void PicoFixSurfaceNormals (picoSurface_t* surface)
{
	picoVec3_t* normals = (picoVec3_t*) _pico_calloc(surface->numVertexes, sizeof(picoVec3_t));

	_pico_normals_zero(normals, normals + surface->numVertexes);

	_pico_triangles_generate_weighted_normals(surface->index, surface->index + surface->numIndexes, surface->xyz,
			normals);
	_pico_vertices_combine_shared_normals(surface->xyz, surface->smoothingGroup, normals, surface->numVertexes);

	_pico_normals_normalize(normals, normals + surface->numVertexes);

	_pico_normals_assign_generated_normals(surface->normal, surface->normal + surface->numVertexes, normals);

	_pico_free(normals);
}
示例#30
0
lwTexture *lwGetTexture( picoMemStream_t *fp, int bloksz, unsigned int type ) {
    lwTexture *tex;
    unsigned short sz;
    int ok;

    tex = _pico_calloc( 1, sizeof( lwTexture ) );
    if ( !tex ) {
        return NULL;
    }

    tex->type = type;
    tex->tmap.size.val[ 0 ] =
        tex->tmap.size.val[ 1 ] =
            tex->tmap.size.val[ 2 ] = 1.0f;
    tex->opacity.val = 1.0f;
    tex->enabled = 1;

    sz = getU2( fp );
    if ( !lwGetTHeader( fp, sz, tex ) ) {
        _pico_free( tex );
        return NULL;
    }

    sz = bloksz - sz - 6;
    switch ( type ) {
    case ID_IMAP:
        ok = lwGetImageMap( fp, sz, tex );
        break;
    case ID_PROC:
        ok = lwGetProcedural( fp, sz, tex );
        break;
    case ID_GRAD:
        ok = lwGetGradient( fp, sz, tex );
        break;
    default:
        ok = !_pico_memstream_seek( fp, sz, PICO_SEEK_CUR );
    }

    if ( !ok ) {
        lwFreeTexture( tex );
        return NULL;
    }

    set_flen( bloksz );
    return tex;
}