#include "plugin.h" // Triangle-stripdetection made simple. By Joost Bloemen, Copyright Vimana BV // If you can improve the algorithm, be sure to let me know you can reach me // at research@3dtop.com struct BMF_SURFACE{ USHORT p0, p1, p2; }; struct Hit{ USHORT hits; USHORT t[3]; UCHAR mask[3]; BMF_SURFACE p[3]; BOOL Stripped; }* HitList; // INPUT: //ilist is the list with indices of the original triangles, will be broken down to // only the triangles that can 't be stripped, at the end. //length is the number of triangles in ilist. // OUTPUT: //nr-strips is the number of strips we detected, they have a minimum of two triangles //strips_length contains an array[nr_strips] of strip-lengths, strip1, strip2 strip3 etc... //nr_indices is the total number of vertice-indices we have in the array "stripindex": //stripindex is a long list of strip1-indices, strip2-indices, strip3-indices etc... //return-value is the new number of seperate triangles in ilist. USHORT DetectStrips(BMF_SURFACE * ilist, USHORT length, USHORT * nr_strips, USHORT * strip_length, USHORT * nr_indices, USHORT * stripindex) { USHORT lastp0,lastp1,lastp2; USHORT n,nr,trynr; USHORT p0,p1,p2; USHORT i,k,next,p; UCHAR mask; BMF_SURFACE * temp, * tempEnd; struct Hit * tempHitList; // First part makes a hitlist per triangle, how many sides(hits) a triangle has shared, // the indexes of the hits, up to 3 masks that define wich points the triangles each share // and the points of each shared triangle. HitList=(struct Hit *)GlobalAlloc(GMEM_FIXED|GMEM_ZEROINIT,length*sizeof(struct Hit)); tempHitList=HitList; for(n=0;np0)==p0){mask|=0x11;nr--;} else {if (p==p1){mask|=0x12;nr--;} else {if (p==p2){mask|=0x14;nr--;}} } if ((p=temp->p1)==p0){mask|=0x21;nr--;} else {if (p==p1){mask|=0x22;nr--;} else {if (p==p2){mask|=0x24;nr--;}} } if ((p=temp->p2)==p0){mask|=0x41;nr--;} else {if (p==p1){mask|=0x42;nr--;} else {if (p==p2){mask|=0x44;nr--;}} } // That's it if(!nr) //this doesn't happen very often {USHORT nrs=tempHitList->hits; //Rotate and save points so that p0 and p1 point to points that are the same. // to check later, if we can make a strip of this switch (mask>>4){ case 5: tempHitList->p[nrs].p1=temp->p0; tempHitList->p[nrs].p0=temp->p2; tempHitList->p[nrs].p2=temp->p1; break; case 6: tempHitList->p[nrs].p0=temp->p1; tempHitList->p[nrs].p1=temp->p2; tempHitList->p[nrs].p2=temp->p0; break; case 3: tempHitList->p[nrs].p0=temp->p0; tempHitList->p[nrs].p1=temp->p1; tempHitList->p[nrs].p2=temp->p2; break; } tempHitList->t[nrs]=temp-ilist; // (temp-ilist) is actually the triangle-number tempHitList->mask[nrs]=mask; // mask is for later if(++tempHitList->hits==3)temp=tempEnd; // break while-loop if we have 3 hits } temp++; } } // Next: // Start with trying to make a strip of all triangles with 1 hit as a starting point, // then 2 , finally 3. // That's all. for(trynr=1;trynr<=3;trynr++) { for(p=0;p=10) // while found a triangle {for (k=0;k1)strip_length[(*nr_strips)++]=i+2; //actual strip-length (in indices) is traingles +2 } } } // Done. // Now keep all triangles that aren't stripped in original triangle-list and return // remaining number of triangles in original triangle-list. i=0; for(p=0;p