Go back to randomizing the faces before adding to the BSP, rather
than sorting by area. I had hoped that would help with normal accuracy, but I don't think it helped much, and it sometimes became very slow. [git-p4: depot-paths = "//depot/solvespace/": change = 1850]solver
parent
7b7d2f92e9
commit
04141aa59d
27
bsp.cpp
27
bsp.cpp
|
@ -3,22 +3,6 @@
|
||||||
SBsp2 *SBsp2::Alloc(void) { return (SBsp2 *)AllocTemporary(sizeof(SBsp2)); }
|
SBsp2 *SBsp2::Alloc(void) { return (SBsp2 *)AllocTemporary(sizeof(SBsp2)); }
|
||||||
SBsp3 *SBsp3::Alloc(void) { return (SBsp3 *)AllocTemporary(sizeof(SBsp3)); }
|
SBsp3 *SBsp3::Alloc(void) { return (SBsp3 *)AllocTemporary(sizeof(SBsp3)); }
|
||||||
|
|
||||||
static int ByArea(const void *av, const void *bv) {
|
|
||||||
STriangle *a = (STriangle *)av;
|
|
||||||
STriangle *b = (STriangle *)bv;
|
|
||||||
|
|
||||||
double fa = a->Normal().Magnitude();
|
|
||||||
double fb = b->Normal().Magnitude();
|
|
||||||
|
|
||||||
if(fa > fb) {
|
|
||||||
return -1;
|
|
||||||
} else if(fa < fb) {
|
|
||||||
return 1;
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SBsp3 *SBsp3::FromMesh(SMesh *m) {
|
SBsp3 *SBsp3::FromMesh(SMesh *m) {
|
||||||
SBsp3 *bsp3 = NULL;
|
SBsp3 *bsp3 = NULL;
|
||||||
int i;
|
int i;
|
||||||
|
@ -28,10 +12,13 @@ SBsp3 *SBsp3::FromMesh(SMesh *m) {
|
||||||
mc.AddTriangle(&(m->l.elem[i]));
|
mc.AddTriangle(&(m->l.elem[i]));
|
||||||
}
|
}
|
||||||
|
|
||||||
// The larger-area triangles have more trustworthy normals. By inserting
|
srand(0); // Let's be deterministic, at least!
|
||||||
// those first, we hope to improve the numerical accuracy of our
|
int n = mc.l.n;
|
||||||
// split planes.
|
while(n > 1) {
|
||||||
qsort(mc.l.elem, mc.l.n, sizeof(mc.l.elem[0]), ByArea);
|
int k = rand() % n;
|
||||||
|
n--;
|
||||||
|
SWAP(STriangle, mc.l.elem[k], mc.l.elem[n]);
|
||||||
|
}
|
||||||
|
|
||||||
for(i = 0; i < mc.l.n; i++) {
|
for(i = 0; i < mc.l.n; i++) {
|
||||||
bsp3 = bsp3->Insert(&(mc.l.elem[i]), NULL);
|
bsp3 = bsp3->Insert(&(mc.l.elem[i]), NULL);
|
||||||
|
|
Loading…
Reference in New Issue