trying to fix the clipping bugs
[meshfrac] / src / cmesh.c
index 3492ef2..249c69c 100644 (file)
@@ -11,7 +11,7 @@
 struct cmesh_vattrib {
        int nelem;      /* num elements per attribute [1, 4] */
        float *data;
-       unsigned int count;
+       unsigned int count;     /* number of floats in data */
        unsigned int vbo;
        int vbo_valid, data_valid;
 };
@@ -246,7 +246,7 @@ static int clone(struct cmesh *cmdest, const struct cmesh *cmsrc, struct submesh
                        nelem = cmsrc->vattr[i].nelem;
                        cmdest->vattr[i].nelem = nelem;
                        cmdest->vattr[i].data = varr[i];
-                       cmdest->vattr[i].count = vcount;
+                       cmdest->vattr[i].count = vcount * nelem;
                        vptr = cmsrc->vattr[i].data + vstart * nelem;
                        memcpy(cmdest->vattr[i].data, vptr, vcount * nelem * sizeof(float));
                        cmdest->vattr[i].data_valid = 1;
@@ -669,7 +669,7 @@ int cmesh_append(struct cmesh *cmdest, const struct cmesh *cmsrc)
                        assert(cmdest->vattr[i].nelem == cmsrc->vattr[i].nelem);
                        nelem = cmdest->vattr[i].nelem;
                        origsz = cmdest->nverts * nelem;
-                       newsz = cmdest->nverts + cmsrc->nverts * nelem;
+                       newsz = (cmdest->nverts + cmsrc->nverts) * nelem;
 
                        if(!(vptr = realloc(cmdest->vattr[i].data, newsz * sizeof *vptr))) {
                                return -1;
@@ -704,6 +704,9 @@ int cmesh_append(struct cmesh *cmdest, const struct cmesh *cmsrc)
                }
        }
 
+       cmdest->nverts += cmsrc->nverts;
+       cmdest->nfaces += cmsrc->nfaces;
+
        cmdest->wire_ibo_valid = 0;
        cmdest->aabb_valid = 0;
        cmdest->bsph_valid = 0;
@@ -930,6 +933,10 @@ void cmesh_apply_xform(struct cmesh *cm, float *xform, float *dir_xform)
        cgm_vec3 n, t;
        float *vptr;
 
+       if(!dir_xform) {
+               dir_xform = xform;
+       }
+
        for(i=0; i<cm->nverts; i++) {
                if(!(vptr = get_vec4(cm, CMESH_ATTR_VERTEX, i, &v))) {
                        return;