CADViewComponent/dist/PlaneExt.js
2018-05-28 09:49:45 +08:00

36 lines
1.4 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const THREE = require("three");
const three_1 = require("three");
class PlaneExt extends THREE.Plane {
constructor(normal, constant) {
super(normal, constant);
}
intersectLine(line, optionalTarget, extendLine) {
let v1 = new three_1.Vector3();
let result = optionalTarget || new three_1.Vector3();
let direction = line.delta(v1);
let denominator = this.normal.dot(direction);
if (denominator === 0) {
// line is coplanar, return origin
if (this.distanceToPoint(line.start) === 0) {
return result.copy(line.start);
}
// Unsure if this is the correct method to handle this case.
return undefined;
}
let t = -(line.start.dot(this.normal) + this.constant) / denominator;
//If you not extendLine,check intersect point in Line
if (!extendLine && (t < 0 || t > 1)) {
return undefined;
}
return result.copy(direction).multiplyScalar(t).add(line.start);
}
intersectRay(ray, optionalTarget, extendLine) {
// 从射线初始位置
let line = new THREE.Line3(ray.origin.clone(), ray.origin.clone().add(ray.direction));
return this.intersectLine(line, optionalTarget, extendLine);
}
}
exports.PlaneExt = PlaneExt;
//# sourceMappingURL=PlaneExt.js.map