*/}}
Browse Source

Fixed mesh join face loop references.

YimingWu 1 year ago
parent
commit
3f56c1c73f
3 changed files with 9 additions and 5 deletions
  1. 1 1
      la_tns_kernel.c
  2. 5 1
      la_tns_mesh.c
  3. 3 3
      resources/la_properties.c

+ 1 - 1
la_tns_kernel.c

@@ -3502,7 +3502,7 @@ void tnsDestroyObject(tnsObject *o){
 
     if(o->Type==TNS_OBJECT_MESH){ tnsMeshObject* mo=o;
         if(mo->v) arrFree(&mo->v, &mo->maxv); if(mo->e) arrFree(&mo->e, &mo->maxe);
-        if(mo->f){ for(int i=0;i<mo->totf;i++){ free(mo->f[i].loop); } arrFree(&mo->f, &mo->maxf); }
+        if(mo->f){ for(int i=0;i<mo->totf;i++){ free(mo->f[i].loop); mo->f[i].loop=0; } arrFree(&mo->f, &mo->maxf); }
         mo->totv=mo->tote=mo->totf=0;
         tnsInvalidateMeshBatch(o);
     }

+ 5 - 1
la_tns_mesh.c

@@ -94,7 +94,11 @@ int tnsMergeMeshObjects(tnsMeshObject* into, tnsMeshObject* mo){
     into->totv+=mo->totv; into->tote+=mo->tote; into->totf+=mo->totf;
     arrEnsureLength(&into->v, into->totv, &into->maxv, sizeof(tnsVert)); if(mo->totv) memcpy(&into->v[origv],mo->v,sizeof(tnsVert)*mo->totv);
     arrEnsureLength(&into->e, into->tote, &into->maxe, sizeof(tnsEdge)); if(mo->tote) memcpy(&into->e[orige],mo->e,sizeof(tnsEdge)*mo->tote);
-    arrEnsureLength(&into->f, into->totf, &into->maxf, sizeof(tnsFace)); if(mo->totf) memcpy(&into->f[origf],mo->f,sizeof(tnsFace)*mo->totf);
+    arrEnsureLength(&into->f, into->totf, &into->maxf, sizeof(tnsFace)); if(mo->totf){ memcpy(&into->f[origf],mo->f,sizeof(tnsFace)*mo->totf);
+        for(int i=origf;i<into->totf;i++){ into->f[i].loop=0; arrInitLength(&into->f[i].loop, into->f[i].looplen, &into->f[i].looplen, sizeof(int));
+            for(int l=0;l<into->f[i].looplen;l++){ into->f[i].loop[l]=mo->f[i-origf].loop[l]; }
+        }
+    }
     tnsDestroyObject(mo); return 1;
 }
 tnsMeshObject* tnsDuplicateMeshObjects(tnsMeshObject* from){

+ 3 - 3
resources/la_properties.c

@@ -1494,12 +1494,12 @@ void la_RegisterInternalProps(){
         laAddIntProperty(p, "totmv", "MVert Count", "Total MVert", 0,0,0,0,0,0,0,0,offsetof(tnsMeshObject, totmv),0,0,0,0,0,0,0,0,0,0,LA_READ_ONLY);
         laAddIntProperty(p, "totme", "MEdge Count", "Total MEdge", 0,0,0,0,0,0,0,0,offsetof(tnsMeshObject, totme),0,0,0,0,0,0,0,0,0,0,LA_READ_ONLY);
         laAddIntProperty(p, "totmf", "MFace Count", "Total MFace", 0,0,0,0,0,0,0,0,offsetof(tnsMeshObject, totmf),0,0,0,0,0,0,0,0,0,0,LA_READ_ONLY);
-        laAddRawProperty(p, "v", "Verts", "Verts", offsetof(tnsMeshObject, v), tnsget_MeshObjectVertSize, 0,0,LA_READ_ONLY);
-        laAddRawProperty(p, "e", "Edges", "Edges", offsetof(tnsMeshObject, e), tnsget_MeshObjectEdgeSize, 0,0,LA_READ_ONLY);
-        laAddRawProperty(p, "f", "Faces", "Faces", offsetof(tnsMeshObject, f), 0,tnsget_MeshObjectFaceRaw, tnsset_MeshObjectFaceRaw, LA_READ_ONLY);
         laAddIntProperty(p, "totv", "Vert Count", "Total Vert", 0,0,0,0,0,0,0,0,offsetof(tnsMeshObject, totv),0,0,0,0,0,0,0,0,0,0,LA_READ_ONLY);
         laAddIntProperty(p, "tote", "Edge Count", "Total Edge", 0,0,0,0,0,0,0,0,offsetof(tnsMeshObject, tote),0,0,0,0,0,0,0,0,0,0,LA_READ_ONLY);
         laAddIntProperty(p, "totf", "Face Count", "Total Face", 0,0,0,0,0,0,0,0,offsetof(tnsMeshObject, totf),0,0,0,0,0,0,0,0,0,0,LA_READ_ONLY);
+        laAddRawProperty(p, "v", "Verts", "Verts", offsetof(tnsMeshObject, v), tnsget_MeshObjectVertSize, 0,0,LA_READ_ONLY);
+        laAddRawProperty(p, "e", "Edges", "Edges", offsetof(tnsMeshObject, e), tnsget_MeshObjectEdgeSize, 0,0,LA_READ_ONLY);
+        laAddRawProperty(p, "f", "Faces", "Faces", offsetof(tnsMeshObject, f), 0,tnsget_MeshObjectFaceRaw, tnsset_MeshObjectFaceRaw, LA_READ_ONLY);
         //laAddIntProperty(p, "maxv", "Max Vert", "Max Vert count", 0,0,0,0,0,0,0,0,offsetof(tnsMeshObject, maxv),0,0,0,0,0,0,0,0,0,0,LA_READ_ONLY);
         //laAddIntProperty(p, "maxe", "Max Edge", "Max Edge count", 0,0,0,0,0,0,0,0,offsetof(tnsMeshObject, maxe),0,0,0,0,0,0,0,0,0,0,LA_READ_ONLY);
         //laAddIntProperty(p, "maxf", "Max Face", "Max Face count", 0,0,0,0,0,0,0,0,offsetof(tnsMeshObject, maxf),0,0,0,0,0,0,0,0,0,0,LA_READ_ONLY);