|
@@ -87,7 +87,7 @@
|
|
|
//the rendering mesh's bounding info can be used, it is the standard submesh for all indices.
|
|
|
extend = { minimum: this._renderingMesh.getBoundingInfo().minimum.clone(), maximum: this._renderingMesh.getBoundingInfo().maximum.clone() };
|
|
|
} else {
|
|
|
- extend = Tools.ExtractMinAndMaxIndexed(data, indices, this.indexStart, this.indexCount);
|
|
|
+ extend = Tools.ExtractMinAndMaxIndexed(data, indices, this.indexStart, this.indexCount, this._renderingMesh.geometry.boundingBias);
|
|
|
}
|
|
|
this._boundingInfo = new BoundingInfo(extend.minimum, extend.maximum);
|
|
|
}
|
|
@@ -134,22 +134,22 @@
|
|
|
public intersects(ray: Ray, positions: Vector3[], indices: number[] | Int32Array, fastCheck?: boolean): IntersectionInfo {
|
|
|
var intersectInfo: IntersectionInfo = null;
|
|
|
|
|
|
- // Triangles test
|
|
|
- for (var index = this.indexStart; index < this.indexStart + this.indexCount; index += 3) {
|
|
|
- var p0 = positions[indices[index]];
|
|
|
- var p1 = positions[indices[index + 1]];
|
|
|
- var p2 = positions[indices[index + 2]];
|
|
|
+ // LineMesh first as it's also a Mesh...
|
|
|
+ if (this._mesh instanceof LinesMesh) {
|
|
|
+ var lineMesh = <LinesMesh>this._mesh;
|
|
|
|
|
|
- var currentIntersectInfo = ray.intersectsTriangle(p0, p1, p2);
|
|
|
+ // Line test
|
|
|
+ for (var index = this.indexStart; index < this.indexStart + this.indexCount; index += 2) {
|
|
|
+ var p0 = positions[indices[index]];
|
|
|
+ var p1 = positions[indices[index + 1]];
|
|
|
|
|
|
- if (currentIntersectInfo) {
|
|
|
- if (currentIntersectInfo.distance < 0) {
|
|
|
+ var length = ray.intersectionSegment(p0, p1, lineMesh.intersectionThreshold);
|
|
|
+ if (!length) {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- if (fastCheck || !intersectInfo || currentIntersectInfo.distance < intersectInfo.distance) {
|
|
|
- intersectInfo = currentIntersectInfo;
|
|
|
- intersectInfo.faceId = index / 3;
|
|
|
+ if (fastCheck || !intersectInfo || length < intersectInfo.distance) {
|
|
|
+ intersectInfo = new IntersectionInfo(null, null, length);
|
|
|
|
|
|
if (fastCheck) {
|
|
|
break;
|
|
@@ -157,6 +157,31 @@
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ else if (this._mesh instanceof Mesh) {
|
|
|
+ // Triangles test
|
|
|
+ for (var index = this.indexStart; index < this.indexStart + this.indexCount; index += 3) {
|
|
|
+ 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) {
|
|
|
+ if (currentIntersectInfo.distance < 0) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (fastCheck || !intersectInfo || currentIntersectInfo.distance < intersectInfo.distance) {
|
|
|
+ intersectInfo = currentIntersectInfo;
|
|
|
+ intersectInfo.faceId = index / 3;
|
|
|
+
|
|
|
+ if (fastCheck) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
return intersectInfo;
|
|
|
}
|