ThreeCSG
ThreeCSG copied to clipboard
Call Stack problems
Using three.min.js rev 73
Method used: var roomBSP = new ThreeBSP(_RoomShape); // HUGE SHAPE
Info gathered from a TryCatch: "number : -2146828260" "Error: Out of stack space at ThreeBSP.Vertex.prototype.dot (/ThreeCSG.js) at ThreeBSP.Polygon.prototype.classifyVertex (/ThreeCSG.js) at ThreeBSP.Polygon.prototype.classifySide (/ThreeCSG.js) at ThreeBSP.Polygon.prototype.splitPolygon (/ThreeCSG.js) at ThreeBSP.Node (/ThreeCSG.js) at ThreeBSP.Node (/ThreeCSG.js) at ThreeBSP.Node (/ThreeCSG.js) at ThreeBSP.Node (/ThreeCSG.js) at ThreeBSP.Node (/ThreeCSG.js) at ThreeBSP.Node (/ThreeCSG.js)"
Using the OUTDATED csg-wrapper from kraag22/csg-wrapper it doesn't happen but his wrapper is way outdated and needs an update.
Might this occur when using high values/numbers?
Another example: var intersect = shape1.intersect(shape2); // Small shapes
Info gathered from a TryCatch: "number : -2146828260" -:-
I have an updated fork here
Your fork is exactly the same except missing the face.vertexNormal fix
Owh, sorry. I thought that there were more fixes in my fork...
I provided the vertex normal fix... But I accidently pointed to the master, and that fix was in this patch1 branch.
Your branch is fully up-to-date with Chandlers and you both provide exact same ThreeCSG.js files. I've just compared with a SVN program. No changes.
@Yenza Yes, you are right. He recently merged my patch1...
Maximum call stack happens with complex geometry for two reasons:
- ThreeCSG doesn't use any heuristic for picking a good divider
- Even if a great divider is selected it is still possible to reach maximum recursion. The proper fix would be to change the recursion into one function that keeps a local stack queue and while() loops over it.
Solving either of these would gain large speed improvements, especially for complex geometries. There are many white papers / thesis on CSG which provide ideas for selecting a good divider. Unfortunately I won't have time for a while to actively look into implementing.
@Wilt Do you think you could try to fix this issue?
@chandlerprall But it isn't that very complex! It's two round shapes! It's two identical "almost" circle-wise shapes on the same height. The thing is that if I move any of them like 1 unit in any direction.. then it works! I have an image of the red area when using the intersect method that causes an error: http://i.imgur.com/NW0AOUU.png
Also this problem doesn't seem to be occurring when you use the old csg wrapper but that might just be because it's heavily outdated.
So this is what I did to fix this for now... I dunno why it works but it does. The "var test = new ThreeBSP(shape)" doesn't though x.x
var intersection;
try {
// If it doesn't work the first time...
intersection= shapeBSP.intersect(shapeBSP_2);
}
catch (e) {
// Then try again..
var newShape = shapeBSP_2.toMesh(_Material);
newShape.position.x += 1;
newShape = new ThreeBSP(newShape );
intersection= shapeBSP.intersect(newShape);
// console.warn("Works!");
}
FYI this new CSG repo using Octree data structure overcomes a lot of the performance issues with ThreeCSG and other CSG tools. See this SO thread for up to date information.