Closed mightymarcus closed 8 years ago
Ok, i found the error. It's not because the camera is inside the mesh, but sometimes when the mouse cursor picks the mesh the intersects function is called with positions => null. Checking for null and breaking the loop helps.
SubMesh.hx Line 166
inline public function intersects(ray:Ray, positions:Array<Vector3>, indices:Array<Int>, fastCheck:Bool = false):IntersectionInfo {
var intersectInfo:IntersectionInfo = null;
// Triangles test
var index:Int = this.indexStart;
while (index < this.indexStart + this.indexCount) {
if (positions == null) break; <---- BYPASS ERROR
var p0 = positions[indices[index]];
var p1 = positions[indices[index + 1]];
var p2 = positions[indices[index + 2]];
var currentIntersectInfo = ray.intersectsTriangle(p0, p1, p2);
if (currentIntersectInfo != null) {
if(currentIntersectInfo.distance < 0 ) continue;
if (fastCheck || intersectInfo == null || currentIntersectInfo.distance < intersectInfo.distance) {
intersectInfo = currentIntersectInfo;
intersectInfo.faceId = Std.int(index / 3);
if (fastCheck) {
break;
}
}
}
index += 3;
}
return intersectInfo;
}
Btw. commenting out the pickingInfo functions in Scene.hx onMouseMove etc. gives much better performance. I have 200 Boxes falling down, and when the mouse pointer moves over just one of them its getting to be a slideshow.
Hi, you should move that if() out of while loop as it shouldn't enter the loop if positions is null. another (temp) solution would be to set for your meshes isPickable = false (or make if false for them all in AbstractMesh class, right now its true), it will prevent intersects() function to be called. At least until I fix the problem.
Good to know, thanks. Makes sense.
If the camera (freecamera) is inside of a Mesh, it often results in an endless loop (freezing). I did not notice this on earlier versions. I tried with box and sphere.
Both cpp target and html5.