UNPKG

awv3

Version:
23 lines (18 loc) 890 B
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.calcSketchPos = calcSketchPos; var _three = require('three'); var THREE = _interopRequireWildcard(_three); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } function calcSketchPos(ray, sketch) { //transform line from world to sketch coords var worldToLocal = new THREE.Matrix4().getInverse(sketch.matrixWorld); ray.applyMatrix4(worldToLocal); //calculate intersection of line with z = 0 plane var param = (0 - ray.origin.z) / ray.direction.z; var sketchPoint = ray.at(param); sketchPoint.z = 0; //ensure it is exactly zero return sketchPoint; }