scenefile

diff src/mesh.c @ 3:b30f83409769

foo
author John Tsiombikas <nuclear@mutantstargoat.com>
date Sat, 21 Jan 2012 04:14:24 +0200
parents 38489ad82bf4
children
line diff
     1.1 --- a/src/mesh.c	Sun Jan 15 08:32:19 2012 +0200
     1.2 +++ b/src/mesh.c	Sat Jan 21 04:14:24 2012 +0200
     1.3 @@ -94,6 +94,14 @@
     1.4  	return ma->elem_sz;
     1.5  }
     1.6  
     1.7 +void *vattr_elem(struct mesh_vertattr *ma, int elem)
     1.8 +{
     1.9 +	int count = dynarr_size(ma->data);
    1.10 +	if(elem >= count) {
    1.11 +		return 0;
    1.12 +	}
    1.13 +	return (char*)ma->data + elem * ma->elem_sz;
    1.14 +}
    1.15  
    1.16  
    1.17  /* -------- mesh -------- */
    1.18 @@ -116,7 +124,7 @@
    1.19  
    1.20  void mesh_destroy(struct mesh *m)
    1.21  {
    1.22 -	int i, nattr = mesh_attr_count(m);
    1.23 +	int i, nattr = mesh_num_attribs(m);
    1.24  
    1.25  	for(i=0; i<nattr; i++) {
    1.26  		vattr_destroy(m->attr + i);
    1.27 @@ -148,6 +156,11 @@
    1.28  	return m->name ? m->name : "<unnamed mesh>";
    1.29  }
    1.30  
    1.31 +int mesh_poly_type(struct mesh *m)
    1.32 +{
    1.33 +	return m->poly_nverts;
    1.34 +}
    1.35 +
    1.36  int mesh_add_attrib(struct mesh *m, struct mesh_vertattr *attr)
    1.37  {
    1.38  	struct mesh_polyidx pidx;
    1.39 @@ -171,9 +184,14 @@
    1.40  	return 0;
    1.41  }
    1.42  
    1.43 +int mesh_num_attribs(struct mesh *m)
    1.44 +{
    1.45 +	return dynarr_size(m->attr);
    1.46 +}
    1.47 +
    1.48  int mesh_find_attrib(struct mesh *m, const char *name)
    1.49  {
    1.50 -	int i, nattr = mesh_attr_count(m);
    1.51 +	int i, nattr = mesh_num_attribs(m);
    1.52  
    1.53  	for(i=0; i<nattr; i++) {
    1.54  		if(m->attr[i].name && strcmp(m->attr[i].name, name) == 0) {
    1.55 @@ -183,14 +201,30 @@
    1.56  	return -1;
    1.57  }
    1.58  
    1.59 -int mesh_attr_count(struct mesh *m)
    1.60 +struct mesh_vertattr *mesh_attrib(struct mesh *m, int loc)
    1.61  {
    1.62 -	return dynarr_size(m->attr);
    1.63 +	return loc >= 0 ? m->attr + loc : 0;
    1.64 +}
    1.65 +
    1.66 +void *mesh_attrib_data(struct mesh *m, int loc)
    1.67 +{
    1.68 +	return loc >= 0 ? m->attr[loc].data : 0;
    1.69 +}
    1.70 +
    1.71 +int *mesh_poly_data(struct mesh *m, int loc)
    1.72 +{
    1.73 +	return loc >= 0 ? m->polyidx[loc].data : 0;
    1.74 +}
    1.75 +
    1.76 +
    1.77 +int mesh_attrib_count(struct mesh *m, int loc)
    1.78 +{
    1.79 +	return loc >= 0 ? vattr_count(m->attr + loc) : 0;
    1.80  }
    1.81  
    1.82  int mesh_poly_count(struct mesh *m)
    1.83  {
    1.84 -	int i, nattr = mesh_attr_count(m);
    1.85 +	int i, nattr = mesh_num_attribs(m);
    1.86  
    1.87  	for(i=0; i<nattr; i++) {
    1.88  		int count = dynarr_empty(m->polyidx[i].data);
    1.89 @@ -201,9 +235,19 @@
    1.90  	return 0;
    1.91  }
    1.92  
    1.93 +void *mesh_attrib_elem(struct mesh *m, int loc, int elem)
    1.94 +{
    1.95 +	return loc >= 0 ? vattr_elem(m->attr + loc, elem) : 0;
    1.96 +}
    1.97 +
    1.98 +int mesh_attrib_elem_size(struct mesh *m, int loc)
    1.99 +{
   1.100 +	return loc >= 0 ? m->attr[loc].elem_sz : 0;
   1.101 +}
   1.102 +
   1.103  int mesh_add_polyref(struct mesh *m, int attr_loc, ...)
   1.104  {
   1.105 -	int i, nattr = mesh_attr_count(m);
   1.106 +	int i, nattr = mesh_num_attribs(m);
   1.107  	int *poly = alloca(m->poly_nverts * sizeof *poly);
   1.108  	va_list ap;
   1.109  	void *tmp;