@antv/g-camera-api
Advanced tools
Comparing version 1.0.38 to 1.0.39
@@ -5,46 +5,7 @@ import { getAngle, CameraType, deg2rad, createVec3, runtime, Camera } from '@antv/g-lite'; | ||
function _classCallCheck(instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
function _inheritsLoose(subClass, superClass) { | ||
subClass.prototype = Object.create(superClass.prototype); | ||
subClass.prototype.constructor = subClass; | ||
_setPrototypeOf(subClass, superClass); | ||
} | ||
function _defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); | ||
} | ||
} | ||
function _createClass(Constructor, protoProps, staticProps) { | ||
if (protoProps) _defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) _defineProperties(Constructor, staticProps); | ||
Object.defineProperty(Constructor, "prototype", { | ||
writable: false | ||
}); | ||
return Constructor; | ||
} | ||
function _inherits(subClass, superClass) { | ||
if (typeof superClass !== "function" && superClass !== null) { | ||
throw new TypeError("Super expression must either be null or a function"); | ||
} | ||
subClass.prototype = Object.create(superClass && superClass.prototype, { | ||
constructor: { | ||
value: subClass, | ||
writable: true, | ||
configurable: true | ||
} | ||
}); | ||
Object.defineProperty(subClass, "prototype", { | ||
writable: false | ||
}); | ||
if (superClass) _setPrototypeOf(subClass, superClass); | ||
} | ||
function _getPrototypeOf(o) { | ||
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { | ||
return o.__proto__ || Object.getPrototypeOf(o); | ||
}; | ||
return _getPrototypeOf(o); | ||
} | ||
function _setPrototypeOf(o, p) { | ||
@@ -57,55 +18,2 @@ _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { | ||
} | ||
function _isNativeReflectConstruct() { | ||
if (typeof Reflect === "undefined" || !Reflect.construct) return false; | ||
if (Reflect.construct.sham) return false; | ||
if (typeof Proxy === "function") return true; | ||
try { | ||
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); | ||
return true; | ||
} catch (e) { | ||
return false; | ||
} | ||
} | ||
function _assertThisInitialized(self) { | ||
if (self === void 0) { | ||
throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); | ||
} | ||
return self; | ||
} | ||
function _possibleConstructorReturn(self, call) { | ||
if (call && (typeof call === "object" || typeof call === "function")) { | ||
return call; | ||
} else if (call !== void 0) { | ||
throw new TypeError("Derived constructors may only return object or undefined"); | ||
} | ||
return _assertThisInitialized(self); | ||
} | ||
function _createSuper(Derived) { | ||
var hasNativeReflectConstruct = _isNativeReflectConstruct(); | ||
return function _createSuperInternal() { | ||
var Super = _getPrototypeOf(Derived), | ||
result; | ||
if (hasNativeReflectConstruct) { | ||
var NewTarget = _getPrototypeOf(this).constructor; | ||
result = Reflect.construct(Super, arguments, NewTarget); | ||
} else { | ||
result = Super.apply(this, arguments); | ||
} | ||
return _possibleConstructorReturn(this, result); | ||
}; | ||
} | ||
function _toPrimitive(input, hint) { | ||
if (typeof input !== "object" || input === null) return input; | ||
var prim = input[Symbol.toPrimitive]; | ||
if (prim !== undefined) { | ||
var res = prim.call(input, hint || "default"); | ||
if (typeof res !== "object") return res; | ||
throw new TypeError("@@toPrimitive must return a primitive value."); | ||
} | ||
return (hint === "string" ? String : Number)(input); | ||
} | ||
function _toPropertyKey(arg) { | ||
var key = _toPrimitive(arg, "string"); | ||
return typeof key === "symbol" ? key : String(key); | ||
} | ||
@@ -116,11 +24,9 @@ /** | ||
var AdvancedCamera = /*#__PURE__*/function (_Camera) { | ||
_inherits(AdvancedCamera, _Camera); | ||
var _super = _createSuper(AdvancedCamera); | ||
_inheritsLoose(AdvancedCamera, _Camera); | ||
function AdvancedCamera() { | ||
var _this; | ||
_classCallCheck(this, AdvancedCamera); | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
_this = _super.call.apply(_super, [this].concat(args)); | ||
_this = _Camera.call.apply(_Camera, [this].concat(args)) || this; | ||
/** | ||
@@ -133,234 +39,224 @@ * switch between multiple landmarks | ||
} | ||
_createClass(AdvancedCamera, [{ | ||
key: "rotate", | ||
value: | ||
/** | ||
* Changes the azimuth and elevation with respect to the current camera axes | ||
* @param {Number} azimuth the relative azimuth | ||
* @param {Number} elevation the relative elevation | ||
* @param {Number} roll the relative roll | ||
*/ | ||
function rotate(azimuth, elevation, roll) { | ||
this.relElevation = getAngle(elevation); | ||
this.relAzimuth = getAngle(azimuth); | ||
this.relRoll = getAngle(roll); | ||
this.elevation += this.relElevation; | ||
this.azimuth += this.relAzimuth; | ||
this.roll += this.relRoll; | ||
if (this.type === CameraType.EXPLORING) { | ||
var rotX = quat.setAxisAngle(quat.create(), [1, 0, 0], deg2rad((this.rotateWorld ? 1 : -1) * this.relElevation)); | ||
var rotY = quat.setAxisAngle(quat.create(), [0, 1, 0], deg2rad((this.rotateWorld ? 1 : -1) * this.relAzimuth)); | ||
var rotZ = quat.setAxisAngle(quat.create(), [0, 0, 1], deg2rad(this.relRoll)); | ||
var rotQ = quat.multiply(quat.create(), rotY, rotX); | ||
rotQ = quat.multiply(quat.create(), rotQ, rotZ); | ||
var rotMatrix = mat4.fromQuat(mat4.create(), rotQ); | ||
mat4.translate(this.matrix, this.matrix, [0, 0, -this.distance]); | ||
mat4.multiply(this.matrix, this.matrix, rotMatrix); | ||
mat4.translate(this.matrix, this.matrix, [0, 0, this.distance]); | ||
} else { | ||
if (Math.abs(this.elevation) > 90) { | ||
return this; | ||
} | ||
this.computeMatrix(); | ||
var _proto = AdvancedCamera.prototype; | ||
/** | ||
* Changes the azimuth and elevation with respect to the current camera axes | ||
* @param {Number} azimuth the relative azimuth | ||
* @param {Number} elevation the relative elevation | ||
* @param {Number} roll the relative roll | ||
*/ | ||
_proto.rotate = function rotate(azimuth, elevation, roll) { | ||
this.relElevation = getAngle(elevation); | ||
this.relAzimuth = getAngle(azimuth); | ||
this.relRoll = getAngle(roll); | ||
this.elevation += this.relElevation; | ||
this.azimuth += this.relAzimuth; | ||
this.roll += this.relRoll; | ||
if (this.type === CameraType.EXPLORING) { | ||
var rotX = quat.setAxisAngle(quat.create(), [1, 0, 0], deg2rad((this.rotateWorld ? 1 : -1) * this.relElevation)); | ||
var rotY = quat.setAxisAngle(quat.create(), [0, 1, 0], deg2rad((this.rotateWorld ? 1 : -1) * this.relAzimuth)); | ||
var rotZ = quat.setAxisAngle(quat.create(), [0, 0, 1], deg2rad(this.relRoll)); | ||
var rotQ = quat.multiply(quat.create(), rotY, rotX); | ||
rotQ = quat.multiply(quat.create(), rotQ, rotZ); | ||
var rotMatrix = mat4.fromQuat(mat4.create(), rotQ); | ||
mat4.translate(this.matrix, this.matrix, [0, 0, -this.distance]); | ||
mat4.multiply(this.matrix, this.matrix, rotMatrix); | ||
mat4.translate(this.matrix, this.matrix, [0, 0, this.distance]); | ||
} else { | ||
if (Math.abs(this.elevation) > 90) { | ||
return this; | ||
} | ||
this._getAxes(); | ||
if (this.type === CameraType.ORBITING || this.type === CameraType.EXPLORING) { | ||
this._getPosition(); | ||
} else if (this.type === CameraType.TRACKING) { | ||
this._getFocalPoint(); | ||
} | ||
this._update(); | ||
return this; | ||
this.computeMatrix(); | ||
} | ||
/** | ||
* 沿水平(right) & 垂直(up)平移相机 | ||
*/ | ||
}, { | ||
key: "pan", | ||
value: function pan(tx, ty) { | ||
var coords = createVec3(tx, ty, 0); | ||
var pos = vec3.clone(this.position); | ||
vec3.add(pos, pos, vec3.scale(vec3.create(), this.right, coords[0])); | ||
vec3.add(pos, pos, vec3.scale(vec3.create(), this.up, coords[1])); | ||
this._setPosition(pos); | ||
this.triggerUpdate(); | ||
return this; | ||
this._getAxes(); | ||
if (this.type === CameraType.ORBITING || this.type === CameraType.EXPLORING) { | ||
this._getPosition(); | ||
} else if (this.type === CameraType.TRACKING) { | ||
this._getFocalPoint(); | ||
} | ||
/** | ||
* 沿 n 轴移动,当距离视点远时移动速度较快,离视点越近速度越慢 | ||
*/ | ||
}, { | ||
key: "dolly", | ||
value: function dolly(value) { | ||
var n = this.forward; | ||
var pos = vec3.clone(this.position); | ||
var step = value * this.dollyingStep; | ||
var updatedDistance = this.distance + value * this.dollyingStep; | ||
// 限制视点距离范围 | ||
step = Math.max(Math.min(updatedDistance, this.maxDistance), this.minDistance) - this.distance; | ||
pos[0] += step * n[0]; | ||
pos[1] += step * n[1]; | ||
pos[2] += step * n[2]; | ||
this._setPosition(pos); | ||
if (this.type === CameraType.ORBITING || this.type === CameraType.EXPLORING) { | ||
// 重新计算视点距离 | ||
this._getDistance(); | ||
} else if (this.type === CameraType.TRACKING) { | ||
// 保持视距,移动视点位置 | ||
vec3.add(this.focalPoint, pos, this.distanceVector); | ||
} | ||
this.triggerUpdate(); | ||
return this; | ||
this._update(); | ||
return this; | ||
} | ||
/** | ||
* 沿水平(right) & 垂直(up)平移相机 | ||
*/; | ||
_proto.pan = function pan(tx, ty) { | ||
var coords = createVec3(tx, ty, 0); | ||
var pos = vec3.clone(this.position); | ||
vec3.add(pos, pos, vec3.scale(vec3.create(), this.right, coords[0])); | ||
vec3.add(pos, pos, vec3.scale(vec3.create(), this.up, coords[1])); | ||
this._setPosition(pos); | ||
this.triggerUpdate(); | ||
return this; | ||
} | ||
/** | ||
* 沿 n 轴移动,当距离视点远时移动速度较快,离视点越近速度越慢 | ||
*/; | ||
_proto.dolly = function dolly(value) { | ||
var n = this.forward; | ||
var pos = vec3.clone(this.position); | ||
var step = value * this.dollyingStep; | ||
var updatedDistance = this.distance + value * this.dollyingStep; | ||
// 限制视点距离范围 | ||
step = Math.max(Math.min(updatedDistance, this.maxDistance), this.minDistance) - this.distance; | ||
pos[0] += step * n[0]; | ||
pos[1] += step * n[1]; | ||
pos[2] += step * n[2]; | ||
this._setPosition(pos); | ||
if (this.type === CameraType.ORBITING || this.type === CameraType.EXPLORING) { | ||
// 重新计算视点距离 | ||
this._getDistance(); | ||
} else if (this.type === CameraType.TRACKING) { | ||
// 保持视距,移动视点位置 | ||
vec3.add(this.focalPoint, pos, this.distanceVector); | ||
} | ||
}, { | ||
key: "cancelLandmarkAnimation", | ||
value: function cancelLandmarkAnimation() { | ||
if (this.landmarkAnimationID !== undefined) { | ||
this.canvas.cancelAnimationFrame(this.landmarkAnimationID); | ||
this.triggerUpdate(); | ||
return this; | ||
}; | ||
_proto.cancelLandmarkAnimation = function cancelLandmarkAnimation() { | ||
if (this.landmarkAnimationID !== undefined) { | ||
this.canvas.cancelAnimationFrame(this.landmarkAnimationID); | ||
} | ||
}; | ||
_proto.createLandmark = function createLandmark(name, params) { | ||
var _position$, _position$2, _focalPoint$, _focalPoint$2; | ||
if (params === void 0) { | ||
params = {}; | ||
} | ||
var _params = params, | ||
_params$position = _params.position, | ||
position = _params$position === void 0 ? this.position : _params$position, | ||
_params$focalPoint = _params.focalPoint, | ||
focalPoint = _params$focalPoint === void 0 ? this.focalPoint : _params$focalPoint, | ||
roll = _params.roll, | ||
zoom = _params.zoom; | ||
var camera = new runtime.CameraContribution(); | ||
camera.setType(this.type, undefined); | ||
camera.setPosition(position[0], (_position$ = position[1]) !== null && _position$ !== void 0 ? _position$ : this.position[1], (_position$2 = position[2]) !== null && _position$2 !== void 0 ? _position$2 : this.position[2]); | ||
camera.setFocalPoint(focalPoint[0], (_focalPoint$ = focalPoint[1]) !== null && _focalPoint$ !== void 0 ? _focalPoint$ : this.focalPoint[1], (_focalPoint$2 = focalPoint[2]) !== null && _focalPoint$2 !== void 0 ? _focalPoint$2 : this.focalPoint[2]); | ||
camera.setRoll(roll !== null && roll !== void 0 ? roll : this.roll); | ||
camera.setZoom(zoom !== null && zoom !== void 0 ? zoom : this.zoom); | ||
var landmark = { | ||
name: name, | ||
matrix: mat4.clone(camera.getWorldTransform()), | ||
right: vec3.clone(camera.right), | ||
up: vec3.clone(camera.up), | ||
forward: vec3.clone(camera.forward), | ||
position: vec3.clone(camera.getPosition()), | ||
focalPoint: vec3.clone(camera.getFocalPoint()), | ||
distanceVector: vec3.clone(camera.getDistanceVector()), | ||
distance: camera.getDistance(), | ||
dollyingStep: camera.getDollyingStep(), | ||
azimuth: camera.getAzimuth(), | ||
elevation: camera.getElevation(), | ||
roll: camera.getRoll(), | ||
relAzimuth: camera.relAzimuth, | ||
relElevation: camera.relElevation, | ||
relRoll: camera.relRoll, | ||
zoom: camera.getZoom() | ||
}; | ||
this.landmarks.push(landmark); | ||
return landmark; | ||
}; | ||
_proto.gotoLandmark = function gotoLandmark(name, options) { | ||
var _this2 = this; | ||
if (options === void 0) { | ||
options = {}; | ||
} | ||
var landmark = isString(name) ? this.landmarks.find(function (l) { | ||
return l.name === name; | ||
}) : name; | ||
if (landmark) { | ||
var _ref = isNumber(options) ? { | ||
duration: options | ||
} : options, | ||
_ref$easing = _ref.easing, | ||
easing = _ref$easing === void 0 ? 'linear' : _ref$easing, | ||
_ref$duration = _ref.duration, | ||
duration = _ref$duration === void 0 ? 100 : _ref$duration, | ||
_ref$easingFunction = _ref.easingFunction, | ||
easingFunction = _ref$easingFunction === void 0 ? undefined : _ref$easingFunction, | ||
_ref$onfinish = _ref.onfinish, | ||
onfinish = _ref$onfinish === void 0 ? undefined : _ref$onfinish; | ||
var epsilon = 0.01; | ||
if (duration === 0) { | ||
this.syncFromLandmark(landmark); | ||
if (onfinish) { | ||
onfinish(); | ||
} | ||
return; | ||
} | ||
} | ||
}, { | ||
key: "createLandmark", | ||
value: function createLandmark(name) { | ||
var _position$, _position$2, _focalPoint$, _focalPoint$2; | ||
var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var _params$position = params.position, | ||
position = _params$position === void 0 ? this.position : _params$position, | ||
_params$focalPoint = params.focalPoint, | ||
focalPoint = _params$focalPoint === void 0 ? this.focalPoint : _params$focalPoint, | ||
roll = params.roll, | ||
zoom = params.zoom; | ||
var camera = new runtime.CameraContribution(); | ||
camera.setType(this.type, undefined); | ||
camera.setPosition(position[0], (_position$ = position[1]) !== null && _position$ !== void 0 ? _position$ : this.position[1], (_position$2 = position[2]) !== null && _position$2 !== void 0 ? _position$2 : this.position[2]); | ||
camera.setFocalPoint(focalPoint[0], (_focalPoint$ = focalPoint[1]) !== null && _focalPoint$ !== void 0 ? _focalPoint$ : this.focalPoint[1], (_focalPoint$2 = focalPoint[2]) !== null && _focalPoint$2 !== void 0 ? _focalPoint$2 : this.focalPoint[2]); | ||
camera.setRoll(roll !== null && roll !== void 0 ? roll : this.roll); | ||
camera.setZoom(zoom !== null && zoom !== void 0 ? zoom : this.zoom); | ||
var landmark = { | ||
name: name, | ||
matrix: mat4.clone(camera.getWorldTransform()), | ||
right: vec3.clone(camera.right), | ||
up: vec3.clone(camera.up), | ||
forward: vec3.clone(camera.forward), | ||
position: vec3.clone(camera.getPosition()), | ||
focalPoint: vec3.clone(camera.getFocalPoint()), | ||
distanceVector: vec3.clone(camera.getDistanceVector()), | ||
distance: camera.getDistance(), | ||
dollyingStep: camera.getDollyingStep(), | ||
azimuth: camera.getAzimuth(), | ||
elevation: camera.getElevation(), | ||
roll: camera.getRoll(), | ||
relAzimuth: camera.relAzimuth, | ||
relElevation: camera.relElevation, | ||
relRoll: camera.relRoll, | ||
zoom: camera.getZoom() | ||
// cancel ongoing animation | ||
this.cancelLandmarkAnimation(); | ||
var destPosition = landmark.position; | ||
var destFocalPoint = landmark.focalPoint; | ||
var destZoom = landmark.zoom; | ||
var destRoll = landmark.roll; | ||
var easingFunc = easingFunction || runtime.EasingFunction(easing); | ||
var timeStart; | ||
var endAnimation = function endAnimation() { | ||
_this2.setFocalPoint(destFocalPoint); | ||
_this2.setPosition(destPosition); | ||
_this2.setRoll(destRoll); | ||
_this2.setZoom(destZoom); | ||
_this2.computeMatrix(); | ||
_this2.triggerUpdate(); | ||
if (onfinish) { | ||
onfinish(); | ||
} | ||
}; | ||
this.landmarks.push(landmark); | ||
return landmark; | ||
} | ||
}, { | ||
key: "gotoLandmark", | ||
value: function gotoLandmark(name) { | ||
var _this2 = this; | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var landmark = isString(name) ? this.landmarks.find(function (l) { | ||
return l.name === name; | ||
}) : name; | ||
if (landmark) { | ||
var _ref = isNumber(options) ? { | ||
duration: options | ||
} : options, | ||
_ref$easing = _ref.easing, | ||
easing = _ref$easing === void 0 ? 'linear' : _ref$easing, | ||
_ref$duration = _ref.duration, | ||
duration = _ref$duration === void 0 ? 100 : _ref$duration, | ||
_ref$easingFunction = _ref.easingFunction, | ||
easingFunction = _ref$easingFunction === void 0 ? undefined : _ref$easingFunction, | ||
_ref$onfinish = _ref.onfinish, | ||
onfinish = _ref$onfinish === void 0 ? undefined : _ref$onfinish; | ||
var epsilon = 0.01; | ||
if (duration === 0) { | ||
this.syncFromLandmark(landmark); | ||
if (onfinish) { | ||
onfinish(); | ||
} | ||
var animate = function animate(timestamp) { | ||
if (timeStart === undefined) { | ||
timeStart = timestamp; | ||
} | ||
var elapsed = timestamp - timeStart; | ||
if (elapsed > duration) { | ||
endAnimation(); | ||
return; | ||
} | ||
// cancel ongoing animation | ||
this.cancelLandmarkAnimation(); | ||
var destPosition = landmark.position; | ||
var destFocalPoint = landmark.focalPoint; | ||
var destZoom = landmark.zoom; | ||
var destRoll = landmark.roll; | ||
var easingFunc = easingFunction || runtime.EasingFunction(easing); | ||
var timeStart; | ||
var endAnimation = function endAnimation() { | ||
_this2.setFocalPoint(destFocalPoint); | ||
_this2.setPosition(destPosition); | ||
_this2.setRoll(destRoll); | ||
_this2.setZoom(destZoom); | ||
_this2.computeMatrix(); | ||
_this2.triggerUpdate(); | ||
if (onfinish) { | ||
onfinish(); | ||
} | ||
}; | ||
var animate = function animate(timestamp) { | ||
if (timeStart === undefined) { | ||
timeStart = timestamp; | ||
} | ||
var elapsed = timestamp - timeStart; | ||
if (elapsed > duration) { | ||
endAnimation(); | ||
return; | ||
} | ||
// use the same ease function in animation system | ||
var t = easingFunc(elapsed / duration); | ||
var interFocalPoint = vec3.create(); | ||
var interPosition = vec3.create(); | ||
var interZoom = 1; | ||
var interRoll = 0; | ||
vec3.lerp(interFocalPoint, _this2.focalPoint, destFocalPoint, t); | ||
vec3.lerp(interPosition, _this2.position, destPosition, t); | ||
interRoll = _this2.roll * (1 - t) + destRoll * t; | ||
interZoom = _this2.zoom * (1 - t) + destZoom * t; | ||
_this2.setFocalPoint(interFocalPoint); | ||
_this2.setPosition(interPosition); | ||
_this2.setRoll(interRoll); | ||
_this2.setZoom(interZoom); | ||
var dist = vec3.dist(interFocalPoint, destFocalPoint) + vec3.dist(interPosition, destPosition); | ||
if (dist <= epsilon && destZoom == undefined && destRoll == undefined) { | ||
endAnimation(); | ||
return; | ||
} | ||
_this2.computeMatrix(); | ||
_this2.triggerUpdate(); | ||
if (elapsed < duration) { | ||
_this2.landmarkAnimationID = _this2.canvas.requestAnimationFrame(animate); | ||
} | ||
}; | ||
this.canvas.requestAnimationFrame(animate); | ||
} | ||
// use the same ease function in animation system | ||
var t = easingFunc(elapsed / duration); | ||
var interFocalPoint = vec3.create(); | ||
var interPosition = vec3.create(); | ||
var interZoom = 1; | ||
var interRoll = 0; | ||
vec3.lerp(interFocalPoint, _this2.focalPoint, destFocalPoint, t); | ||
vec3.lerp(interPosition, _this2.position, destPosition, t); | ||
interRoll = _this2.roll * (1 - t) + destRoll * t; | ||
interZoom = _this2.zoom * (1 - t) + destZoom * t; | ||
_this2.setFocalPoint(interFocalPoint); | ||
_this2.setPosition(interPosition); | ||
_this2.setRoll(interRoll); | ||
_this2.setZoom(interZoom); | ||
var dist = vec3.dist(interFocalPoint, destFocalPoint) + vec3.dist(interPosition, destPosition); | ||
if (dist <= epsilon && destZoom == undefined && destRoll == undefined) { | ||
endAnimation(); | ||
return; | ||
} | ||
_this2.computeMatrix(); | ||
_this2.triggerUpdate(); | ||
if (elapsed < duration) { | ||
_this2.landmarkAnimationID = _this2.canvas.requestAnimationFrame(animate); | ||
} | ||
}; | ||
this.canvas.requestAnimationFrame(animate); | ||
} | ||
}, { | ||
key: "syncFromLandmark", | ||
value: function syncFromLandmark(landmark) { | ||
this.matrix = mat4.copy(this.matrix, landmark.matrix); | ||
this.right = vec3.copy(this.right, landmark.right); | ||
this.up = vec3.copy(this.up, landmark.up); | ||
this.forward = vec3.copy(this.forward, landmark.forward); | ||
this.position = vec3.copy(this.position, landmark.position); | ||
this.focalPoint = vec3.copy(this.focalPoint, landmark.focalPoint); | ||
this.distanceVector = vec3.copy(this.distanceVector, landmark.distanceVector); | ||
this.azimuth = landmark.azimuth; | ||
this.elevation = landmark.elevation; | ||
this.roll = landmark.roll; | ||
this.relAzimuth = landmark.relAzimuth; | ||
this.relElevation = landmark.relElevation; | ||
this.relRoll = landmark.relRoll; | ||
this.dollyingStep = landmark.dollyingStep; | ||
this.distance = landmark.distance; | ||
this.zoom = landmark.zoom; | ||
} | ||
}]); | ||
}; | ||
_proto.syncFromLandmark = function syncFromLandmark(landmark) { | ||
this.matrix = mat4.copy(this.matrix, landmark.matrix); | ||
this.right = vec3.copy(this.right, landmark.right); | ||
this.up = vec3.copy(this.up, landmark.up); | ||
this.forward = vec3.copy(this.forward, landmark.forward); | ||
this.position = vec3.copy(this.position, landmark.position); | ||
this.focalPoint = vec3.copy(this.focalPoint, landmark.focalPoint); | ||
this.distanceVector = vec3.copy(this.distanceVector, landmark.distanceVector); | ||
this.azimuth = landmark.azimuth; | ||
this.elevation = landmark.elevation; | ||
this.roll = landmark.roll; | ||
this.relAzimuth = landmark.relAzimuth; | ||
this.relElevation = landmark.relElevation; | ||
this.relRoll = landmark.relRoll; | ||
this.dollyingStep = landmark.dollyingStep; | ||
this.distance = landmark.distance; | ||
this.zoom = landmark.zoom; | ||
}; | ||
return AdvancedCamera; | ||
@@ -367,0 +263,0 @@ }(Camera); |
@@ -9,46 +9,7 @@ 'use strict'; | ||
function _classCallCheck(instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
function _inheritsLoose(subClass, superClass) { | ||
subClass.prototype = Object.create(superClass.prototype); | ||
subClass.prototype.constructor = subClass; | ||
_setPrototypeOf(subClass, superClass); | ||
} | ||
function _defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); | ||
} | ||
} | ||
function _createClass(Constructor, protoProps, staticProps) { | ||
if (protoProps) _defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) _defineProperties(Constructor, staticProps); | ||
Object.defineProperty(Constructor, "prototype", { | ||
writable: false | ||
}); | ||
return Constructor; | ||
} | ||
function _inherits(subClass, superClass) { | ||
if (typeof superClass !== "function" && superClass !== null) { | ||
throw new TypeError("Super expression must either be null or a function"); | ||
} | ||
subClass.prototype = Object.create(superClass && superClass.prototype, { | ||
constructor: { | ||
value: subClass, | ||
writable: true, | ||
configurable: true | ||
} | ||
}); | ||
Object.defineProperty(subClass, "prototype", { | ||
writable: false | ||
}); | ||
if (superClass) _setPrototypeOf(subClass, superClass); | ||
} | ||
function _getPrototypeOf(o) { | ||
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { | ||
return o.__proto__ || Object.getPrototypeOf(o); | ||
}; | ||
return _getPrototypeOf(o); | ||
} | ||
function _setPrototypeOf(o, p) { | ||
@@ -61,55 +22,2 @@ _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { | ||
} | ||
function _isNativeReflectConstruct() { | ||
if (typeof Reflect === "undefined" || !Reflect.construct) return false; | ||
if (Reflect.construct.sham) return false; | ||
if (typeof Proxy === "function") return true; | ||
try { | ||
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); | ||
return true; | ||
} catch (e) { | ||
return false; | ||
} | ||
} | ||
function _assertThisInitialized(self) { | ||
if (self === void 0) { | ||
throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); | ||
} | ||
return self; | ||
} | ||
function _possibleConstructorReturn(self, call) { | ||
if (call && (typeof call === "object" || typeof call === "function")) { | ||
return call; | ||
} else if (call !== void 0) { | ||
throw new TypeError("Derived constructors may only return object or undefined"); | ||
} | ||
return _assertThisInitialized(self); | ||
} | ||
function _createSuper(Derived) { | ||
var hasNativeReflectConstruct = _isNativeReflectConstruct(); | ||
return function _createSuperInternal() { | ||
var Super = _getPrototypeOf(Derived), | ||
result; | ||
if (hasNativeReflectConstruct) { | ||
var NewTarget = _getPrototypeOf(this).constructor; | ||
result = Reflect.construct(Super, arguments, NewTarget); | ||
} else { | ||
result = Super.apply(this, arguments); | ||
} | ||
return _possibleConstructorReturn(this, result); | ||
}; | ||
} | ||
function _toPrimitive(input, hint) { | ||
if (typeof input !== "object" || input === null) return input; | ||
var prim = input[Symbol.toPrimitive]; | ||
if (prim !== undefined) { | ||
var res = prim.call(input, hint || "default"); | ||
if (typeof res !== "object") return res; | ||
throw new TypeError("@@toPrimitive must return a primitive value."); | ||
} | ||
return (hint === "string" ? String : Number)(input); | ||
} | ||
function _toPropertyKey(arg) { | ||
var key = _toPrimitive(arg, "string"); | ||
return typeof key === "symbol" ? key : String(key); | ||
} | ||
@@ -120,11 +28,9 @@ /** | ||
var AdvancedCamera = /*#__PURE__*/function (_Camera) { | ||
_inherits(AdvancedCamera, _Camera); | ||
var _super = _createSuper(AdvancedCamera); | ||
_inheritsLoose(AdvancedCamera, _Camera); | ||
function AdvancedCamera() { | ||
var _this; | ||
_classCallCheck(this, AdvancedCamera); | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
_this = _super.call.apply(_super, [this].concat(args)); | ||
_this = _Camera.call.apply(_Camera, [this].concat(args)) || this; | ||
/** | ||
@@ -137,234 +43,224 @@ * switch between multiple landmarks | ||
} | ||
_createClass(AdvancedCamera, [{ | ||
key: "rotate", | ||
value: | ||
/** | ||
* Changes the azimuth and elevation with respect to the current camera axes | ||
* @param {Number} azimuth the relative azimuth | ||
* @param {Number} elevation the relative elevation | ||
* @param {Number} roll the relative roll | ||
*/ | ||
function rotate(azimuth, elevation, roll) { | ||
this.relElevation = gLite.getAngle(elevation); | ||
this.relAzimuth = gLite.getAngle(azimuth); | ||
this.relRoll = gLite.getAngle(roll); | ||
this.elevation += this.relElevation; | ||
this.azimuth += this.relAzimuth; | ||
this.roll += this.relRoll; | ||
if (this.type === gLite.CameraType.EXPLORING) { | ||
var rotX = glMatrix.quat.setAxisAngle(glMatrix.quat.create(), [1, 0, 0], gLite.deg2rad((this.rotateWorld ? 1 : -1) * this.relElevation)); | ||
var rotY = glMatrix.quat.setAxisAngle(glMatrix.quat.create(), [0, 1, 0], gLite.deg2rad((this.rotateWorld ? 1 : -1) * this.relAzimuth)); | ||
var rotZ = glMatrix.quat.setAxisAngle(glMatrix.quat.create(), [0, 0, 1], gLite.deg2rad(this.relRoll)); | ||
var rotQ = glMatrix.quat.multiply(glMatrix.quat.create(), rotY, rotX); | ||
rotQ = glMatrix.quat.multiply(glMatrix.quat.create(), rotQ, rotZ); | ||
var rotMatrix = glMatrix.mat4.fromQuat(glMatrix.mat4.create(), rotQ); | ||
glMatrix.mat4.translate(this.matrix, this.matrix, [0, 0, -this.distance]); | ||
glMatrix.mat4.multiply(this.matrix, this.matrix, rotMatrix); | ||
glMatrix.mat4.translate(this.matrix, this.matrix, [0, 0, this.distance]); | ||
} else { | ||
if (Math.abs(this.elevation) > 90) { | ||
return this; | ||
} | ||
this.computeMatrix(); | ||
var _proto = AdvancedCamera.prototype; | ||
/** | ||
* Changes the azimuth and elevation with respect to the current camera axes | ||
* @param {Number} azimuth the relative azimuth | ||
* @param {Number} elevation the relative elevation | ||
* @param {Number} roll the relative roll | ||
*/ | ||
_proto.rotate = function rotate(azimuth, elevation, roll) { | ||
this.relElevation = gLite.getAngle(elevation); | ||
this.relAzimuth = gLite.getAngle(azimuth); | ||
this.relRoll = gLite.getAngle(roll); | ||
this.elevation += this.relElevation; | ||
this.azimuth += this.relAzimuth; | ||
this.roll += this.relRoll; | ||
if (this.type === gLite.CameraType.EXPLORING) { | ||
var rotX = glMatrix.quat.setAxisAngle(glMatrix.quat.create(), [1, 0, 0], gLite.deg2rad((this.rotateWorld ? 1 : -1) * this.relElevation)); | ||
var rotY = glMatrix.quat.setAxisAngle(glMatrix.quat.create(), [0, 1, 0], gLite.deg2rad((this.rotateWorld ? 1 : -1) * this.relAzimuth)); | ||
var rotZ = glMatrix.quat.setAxisAngle(glMatrix.quat.create(), [0, 0, 1], gLite.deg2rad(this.relRoll)); | ||
var rotQ = glMatrix.quat.multiply(glMatrix.quat.create(), rotY, rotX); | ||
rotQ = glMatrix.quat.multiply(glMatrix.quat.create(), rotQ, rotZ); | ||
var rotMatrix = glMatrix.mat4.fromQuat(glMatrix.mat4.create(), rotQ); | ||
glMatrix.mat4.translate(this.matrix, this.matrix, [0, 0, -this.distance]); | ||
glMatrix.mat4.multiply(this.matrix, this.matrix, rotMatrix); | ||
glMatrix.mat4.translate(this.matrix, this.matrix, [0, 0, this.distance]); | ||
} else { | ||
if (Math.abs(this.elevation) > 90) { | ||
return this; | ||
} | ||
this._getAxes(); | ||
if (this.type === gLite.CameraType.ORBITING || this.type === gLite.CameraType.EXPLORING) { | ||
this._getPosition(); | ||
} else if (this.type === gLite.CameraType.TRACKING) { | ||
this._getFocalPoint(); | ||
} | ||
this._update(); | ||
return this; | ||
this.computeMatrix(); | ||
} | ||
/** | ||
* 沿水平(right) & 垂直(up)平移相机 | ||
*/ | ||
}, { | ||
key: "pan", | ||
value: function pan(tx, ty) { | ||
var coords = gLite.createVec3(tx, ty, 0); | ||
var pos = glMatrix.vec3.clone(this.position); | ||
glMatrix.vec3.add(pos, pos, glMatrix.vec3.scale(glMatrix.vec3.create(), this.right, coords[0])); | ||
glMatrix.vec3.add(pos, pos, glMatrix.vec3.scale(glMatrix.vec3.create(), this.up, coords[1])); | ||
this._setPosition(pos); | ||
this.triggerUpdate(); | ||
return this; | ||
this._getAxes(); | ||
if (this.type === gLite.CameraType.ORBITING || this.type === gLite.CameraType.EXPLORING) { | ||
this._getPosition(); | ||
} else if (this.type === gLite.CameraType.TRACKING) { | ||
this._getFocalPoint(); | ||
} | ||
/** | ||
* 沿 n 轴移动,当距离视点远时移动速度较快,离视点越近速度越慢 | ||
*/ | ||
}, { | ||
key: "dolly", | ||
value: function dolly(value) { | ||
var n = this.forward; | ||
var pos = glMatrix.vec3.clone(this.position); | ||
var step = value * this.dollyingStep; | ||
var updatedDistance = this.distance + value * this.dollyingStep; | ||
// 限制视点距离范围 | ||
step = Math.max(Math.min(updatedDistance, this.maxDistance), this.minDistance) - this.distance; | ||
pos[0] += step * n[0]; | ||
pos[1] += step * n[1]; | ||
pos[2] += step * n[2]; | ||
this._setPosition(pos); | ||
if (this.type === gLite.CameraType.ORBITING || this.type === gLite.CameraType.EXPLORING) { | ||
// 重新计算视点距离 | ||
this._getDistance(); | ||
} else if (this.type === gLite.CameraType.TRACKING) { | ||
// 保持视距,移动视点位置 | ||
glMatrix.vec3.add(this.focalPoint, pos, this.distanceVector); | ||
} | ||
this.triggerUpdate(); | ||
return this; | ||
this._update(); | ||
return this; | ||
} | ||
/** | ||
* 沿水平(right) & 垂直(up)平移相机 | ||
*/; | ||
_proto.pan = function pan(tx, ty) { | ||
var coords = gLite.createVec3(tx, ty, 0); | ||
var pos = glMatrix.vec3.clone(this.position); | ||
glMatrix.vec3.add(pos, pos, glMatrix.vec3.scale(glMatrix.vec3.create(), this.right, coords[0])); | ||
glMatrix.vec3.add(pos, pos, glMatrix.vec3.scale(glMatrix.vec3.create(), this.up, coords[1])); | ||
this._setPosition(pos); | ||
this.triggerUpdate(); | ||
return this; | ||
} | ||
/** | ||
* 沿 n 轴移动,当距离视点远时移动速度较快,离视点越近速度越慢 | ||
*/; | ||
_proto.dolly = function dolly(value) { | ||
var n = this.forward; | ||
var pos = glMatrix.vec3.clone(this.position); | ||
var step = value * this.dollyingStep; | ||
var updatedDistance = this.distance + value * this.dollyingStep; | ||
// 限制视点距离范围 | ||
step = Math.max(Math.min(updatedDistance, this.maxDistance), this.minDistance) - this.distance; | ||
pos[0] += step * n[0]; | ||
pos[1] += step * n[1]; | ||
pos[2] += step * n[2]; | ||
this._setPosition(pos); | ||
if (this.type === gLite.CameraType.ORBITING || this.type === gLite.CameraType.EXPLORING) { | ||
// 重新计算视点距离 | ||
this._getDistance(); | ||
} else if (this.type === gLite.CameraType.TRACKING) { | ||
// 保持视距,移动视点位置 | ||
glMatrix.vec3.add(this.focalPoint, pos, this.distanceVector); | ||
} | ||
}, { | ||
key: "cancelLandmarkAnimation", | ||
value: function cancelLandmarkAnimation() { | ||
if (this.landmarkAnimationID !== undefined) { | ||
this.canvas.cancelAnimationFrame(this.landmarkAnimationID); | ||
this.triggerUpdate(); | ||
return this; | ||
}; | ||
_proto.cancelLandmarkAnimation = function cancelLandmarkAnimation() { | ||
if (this.landmarkAnimationID !== undefined) { | ||
this.canvas.cancelAnimationFrame(this.landmarkAnimationID); | ||
} | ||
}; | ||
_proto.createLandmark = function createLandmark(name, params) { | ||
var _position$, _position$2, _focalPoint$, _focalPoint$2; | ||
if (params === void 0) { | ||
params = {}; | ||
} | ||
var _params = params, | ||
_params$position = _params.position, | ||
position = _params$position === void 0 ? this.position : _params$position, | ||
_params$focalPoint = _params.focalPoint, | ||
focalPoint = _params$focalPoint === void 0 ? this.focalPoint : _params$focalPoint, | ||
roll = _params.roll, | ||
zoom = _params.zoom; | ||
var camera = new gLite.runtime.CameraContribution(); | ||
camera.setType(this.type, undefined); | ||
camera.setPosition(position[0], (_position$ = position[1]) !== null && _position$ !== void 0 ? _position$ : this.position[1], (_position$2 = position[2]) !== null && _position$2 !== void 0 ? _position$2 : this.position[2]); | ||
camera.setFocalPoint(focalPoint[0], (_focalPoint$ = focalPoint[1]) !== null && _focalPoint$ !== void 0 ? _focalPoint$ : this.focalPoint[1], (_focalPoint$2 = focalPoint[2]) !== null && _focalPoint$2 !== void 0 ? _focalPoint$2 : this.focalPoint[2]); | ||
camera.setRoll(roll !== null && roll !== void 0 ? roll : this.roll); | ||
camera.setZoom(zoom !== null && zoom !== void 0 ? zoom : this.zoom); | ||
var landmark = { | ||
name: name, | ||
matrix: glMatrix.mat4.clone(camera.getWorldTransform()), | ||
right: glMatrix.vec3.clone(camera.right), | ||
up: glMatrix.vec3.clone(camera.up), | ||
forward: glMatrix.vec3.clone(camera.forward), | ||
position: glMatrix.vec3.clone(camera.getPosition()), | ||
focalPoint: glMatrix.vec3.clone(camera.getFocalPoint()), | ||
distanceVector: glMatrix.vec3.clone(camera.getDistanceVector()), | ||
distance: camera.getDistance(), | ||
dollyingStep: camera.getDollyingStep(), | ||
azimuth: camera.getAzimuth(), | ||
elevation: camera.getElevation(), | ||
roll: camera.getRoll(), | ||
relAzimuth: camera.relAzimuth, | ||
relElevation: camera.relElevation, | ||
relRoll: camera.relRoll, | ||
zoom: camera.getZoom() | ||
}; | ||
this.landmarks.push(landmark); | ||
return landmark; | ||
}; | ||
_proto.gotoLandmark = function gotoLandmark(name, options) { | ||
var _this2 = this; | ||
if (options === void 0) { | ||
options = {}; | ||
} | ||
var landmark = util.isString(name) ? this.landmarks.find(function (l) { | ||
return l.name === name; | ||
}) : name; | ||
if (landmark) { | ||
var _ref = util.isNumber(options) ? { | ||
duration: options | ||
} : options, | ||
_ref$easing = _ref.easing, | ||
easing = _ref$easing === void 0 ? 'linear' : _ref$easing, | ||
_ref$duration = _ref.duration, | ||
duration = _ref$duration === void 0 ? 100 : _ref$duration, | ||
_ref$easingFunction = _ref.easingFunction, | ||
easingFunction = _ref$easingFunction === void 0 ? undefined : _ref$easingFunction, | ||
_ref$onfinish = _ref.onfinish, | ||
onfinish = _ref$onfinish === void 0 ? undefined : _ref$onfinish; | ||
var epsilon = 0.01; | ||
if (duration === 0) { | ||
this.syncFromLandmark(landmark); | ||
if (onfinish) { | ||
onfinish(); | ||
} | ||
return; | ||
} | ||
} | ||
}, { | ||
key: "createLandmark", | ||
value: function createLandmark(name) { | ||
var _position$, _position$2, _focalPoint$, _focalPoint$2; | ||
var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var _params$position = params.position, | ||
position = _params$position === void 0 ? this.position : _params$position, | ||
_params$focalPoint = params.focalPoint, | ||
focalPoint = _params$focalPoint === void 0 ? this.focalPoint : _params$focalPoint, | ||
roll = params.roll, | ||
zoom = params.zoom; | ||
var camera = new gLite.runtime.CameraContribution(); | ||
camera.setType(this.type, undefined); | ||
camera.setPosition(position[0], (_position$ = position[1]) !== null && _position$ !== void 0 ? _position$ : this.position[1], (_position$2 = position[2]) !== null && _position$2 !== void 0 ? _position$2 : this.position[2]); | ||
camera.setFocalPoint(focalPoint[0], (_focalPoint$ = focalPoint[1]) !== null && _focalPoint$ !== void 0 ? _focalPoint$ : this.focalPoint[1], (_focalPoint$2 = focalPoint[2]) !== null && _focalPoint$2 !== void 0 ? _focalPoint$2 : this.focalPoint[2]); | ||
camera.setRoll(roll !== null && roll !== void 0 ? roll : this.roll); | ||
camera.setZoom(zoom !== null && zoom !== void 0 ? zoom : this.zoom); | ||
var landmark = { | ||
name: name, | ||
matrix: glMatrix.mat4.clone(camera.getWorldTransform()), | ||
right: glMatrix.vec3.clone(camera.right), | ||
up: glMatrix.vec3.clone(camera.up), | ||
forward: glMatrix.vec3.clone(camera.forward), | ||
position: glMatrix.vec3.clone(camera.getPosition()), | ||
focalPoint: glMatrix.vec3.clone(camera.getFocalPoint()), | ||
distanceVector: glMatrix.vec3.clone(camera.getDistanceVector()), | ||
distance: camera.getDistance(), | ||
dollyingStep: camera.getDollyingStep(), | ||
azimuth: camera.getAzimuth(), | ||
elevation: camera.getElevation(), | ||
roll: camera.getRoll(), | ||
relAzimuth: camera.relAzimuth, | ||
relElevation: camera.relElevation, | ||
relRoll: camera.relRoll, | ||
zoom: camera.getZoom() | ||
// cancel ongoing animation | ||
this.cancelLandmarkAnimation(); | ||
var destPosition = landmark.position; | ||
var destFocalPoint = landmark.focalPoint; | ||
var destZoom = landmark.zoom; | ||
var destRoll = landmark.roll; | ||
var easingFunc = easingFunction || gLite.runtime.EasingFunction(easing); | ||
var timeStart; | ||
var endAnimation = function endAnimation() { | ||
_this2.setFocalPoint(destFocalPoint); | ||
_this2.setPosition(destPosition); | ||
_this2.setRoll(destRoll); | ||
_this2.setZoom(destZoom); | ||
_this2.computeMatrix(); | ||
_this2.triggerUpdate(); | ||
if (onfinish) { | ||
onfinish(); | ||
} | ||
}; | ||
this.landmarks.push(landmark); | ||
return landmark; | ||
} | ||
}, { | ||
key: "gotoLandmark", | ||
value: function gotoLandmark(name) { | ||
var _this2 = this; | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var landmark = util.isString(name) ? this.landmarks.find(function (l) { | ||
return l.name === name; | ||
}) : name; | ||
if (landmark) { | ||
var _ref = util.isNumber(options) ? { | ||
duration: options | ||
} : options, | ||
_ref$easing = _ref.easing, | ||
easing = _ref$easing === void 0 ? 'linear' : _ref$easing, | ||
_ref$duration = _ref.duration, | ||
duration = _ref$duration === void 0 ? 100 : _ref$duration, | ||
_ref$easingFunction = _ref.easingFunction, | ||
easingFunction = _ref$easingFunction === void 0 ? undefined : _ref$easingFunction, | ||
_ref$onfinish = _ref.onfinish, | ||
onfinish = _ref$onfinish === void 0 ? undefined : _ref$onfinish; | ||
var epsilon = 0.01; | ||
if (duration === 0) { | ||
this.syncFromLandmark(landmark); | ||
if (onfinish) { | ||
onfinish(); | ||
} | ||
var animate = function animate(timestamp) { | ||
if (timeStart === undefined) { | ||
timeStart = timestamp; | ||
} | ||
var elapsed = timestamp - timeStart; | ||
if (elapsed > duration) { | ||
endAnimation(); | ||
return; | ||
} | ||
// cancel ongoing animation | ||
this.cancelLandmarkAnimation(); | ||
var destPosition = landmark.position; | ||
var destFocalPoint = landmark.focalPoint; | ||
var destZoom = landmark.zoom; | ||
var destRoll = landmark.roll; | ||
var easingFunc = easingFunction || gLite.runtime.EasingFunction(easing); | ||
var timeStart; | ||
var endAnimation = function endAnimation() { | ||
_this2.setFocalPoint(destFocalPoint); | ||
_this2.setPosition(destPosition); | ||
_this2.setRoll(destRoll); | ||
_this2.setZoom(destZoom); | ||
_this2.computeMatrix(); | ||
_this2.triggerUpdate(); | ||
if (onfinish) { | ||
onfinish(); | ||
} | ||
}; | ||
var animate = function animate(timestamp) { | ||
if (timeStart === undefined) { | ||
timeStart = timestamp; | ||
} | ||
var elapsed = timestamp - timeStart; | ||
if (elapsed > duration) { | ||
endAnimation(); | ||
return; | ||
} | ||
// use the same ease function in animation system | ||
var t = easingFunc(elapsed / duration); | ||
var interFocalPoint = glMatrix.vec3.create(); | ||
var interPosition = glMatrix.vec3.create(); | ||
var interZoom = 1; | ||
var interRoll = 0; | ||
glMatrix.vec3.lerp(interFocalPoint, _this2.focalPoint, destFocalPoint, t); | ||
glMatrix.vec3.lerp(interPosition, _this2.position, destPosition, t); | ||
interRoll = _this2.roll * (1 - t) + destRoll * t; | ||
interZoom = _this2.zoom * (1 - t) + destZoom * t; | ||
_this2.setFocalPoint(interFocalPoint); | ||
_this2.setPosition(interPosition); | ||
_this2.setRoll(interRoll); | ||
_this2.setZoom(interZoom); | ||
var dist = glMatrix.vec3.dist(interFocalPoint, destFocalPoint) + glMatrix.vec3.dist(interPosition, destPosition); | ||
if (dist <= epsilon && destZoom == undefined && destRoll == undefined) { | ||
endAnimation(); | ||
return; | ||
} | ||
_this2.computeMatrix(); | ||
_this2.triggerUpdate(); | ||
if (elapsed < duration) { | ||
_this2.landmarkAnimationID = _this2.canvas.requestAnimationFrame(animate); | ||
} | ||
}; | ||
this.canvas.requestAnimationFrame(animate); | ||
} | ||
// use the same ease function in animation system | ||
var t = easingFunc(elapsed / duration); | ||
var interFocalPoint = glMatrix.vec3.create(); | ||
var interPosition = glMatrix.vec3.create(); | ||
var interZoom = 1; | ||
var interRoll = 0; | ||
glMatrix.vec3.lerp(interFocalPoint, _this2.focalPoint, destFocalPoint, t); | ||
glMatrix.vec3.lerp(interPosition, _this2.position, destPosition, t); | ||
interRoll = _this2.roll * (1 - t) + destRoll * t; | ||
interZoom = _this2.zoom * (1 - t) + destZoom * t; | ||
_this2.setFocalPoint(interFocalPoint); | ||
_this2.setPosition(interPosition); | ||
_this2.setRoll(interRoll); | ||
_this2.setZoom(interZoom); | ||
var dist = glMatrix.vec3.dist(interFocalPoint, destFocalPoint) + glMatrix.vec3.dist(interPosition, destPosition); | ||
if (dist <= epsilon && destZoom == undefined && destRoll == undefined) { | ||
endAnimation(); | ||
return; | ||
} | ||
_this2.computeMatrix(); | ||
_this2.triggerUpdate(); | ||
if (elapsed < duration) { | ||
_this2.landmarkAnimationID = _this2.canvas.requestAnimationFrame(animate); | ||
} | ||
}; | ||
this.canvas.requestAnimationFrame(animate); | ||
} | ||
}, { | ||
key: "syncFromLandmark", | ||
value: function syncFromLandmark(landmark) { | ||
this.matrix = glMatrix.mat4.copy(this.matrix, landmark.matrix); | ||
this.right = glMatrix.vec3.copy(this.right, landmark.right); | ||
this.up = glMatrix.vec3.copy(this.up, landmark.up); | ||
this.forward = glMatrix.vec3.copy(this.forward, landmark.forward); | ||
this.position = glMatrix.vec3.copy(this.position, landmark.position); | ||
this.focalPoint = glMatrix.vec3.copy(this.focalPoint, landmark.focalPoint); | ||
this.distanceVector = glMatrix.vec3.copy(this.distanceVector, landmark.distanceVector); | ||
this.azimuth = landmark.azimuth; | ||
this.elevation = landmark.elevation; | ||
this.roll = landmark.roll; | ||
this.relAzimuth = landmark.relAzimuth; | ||
this.relElevation = landmark.relElevation; | ||
this.relRoll = landmark.relRoll; | ||
this.dollyingStep = landmark.dollyingStep; | ||
this.distance = landmark.distance; | ||
this.zoom = landmark.zoom; | ||
} | ||
}]); | ||
}; | ||
_proto.syncFromLandmark = function syncFromLandmark(landmark) { | ||
this.matrix = glMatrix.mat4.copy(this.matrix, landmark.matrix); | ||
this.right = glMatrix.vec3.copy(this.right, landmark.right); | ||
this.up = glMatrix.vec3.copy(this.up, landmark.up); | ||
this.forward = glMatrix.vec3.copy(this.forward, landmark.forward); | ||
this.position = glMatrix.vec3.copy(this.position, landmark.position); | ||
this.focalPoint = glMatrix.vec3.copy(this.focalPoint, landmark.focalPoint); | ||
this.distanceVector = glMatrix.vec3.copy(this.distanceVector, landmark.distanceVector); | ||
this.azimuth = landmark.azimuth; | ||
this.elevation = landmark.elevation; | ||
this.roll = landmark.roll; | ||
this.relAzimuth = landmark.relAzimuth; | ||
this.relElevation = landmark.relElevation; | ||
this.relRoll = landmark.relRoll; | ||
this.dollyingStep = landmark.dollyingStep; | ||
this.distance = landmark.distance; | ||
this.zoom = landmark.zoom; | ||
}; | ||
return AdvancedCamera; | ||
@@ -371,0 +267,0 @@ }(gLite.Camera); |
@@ -7,46 +7,7 @@ (function (global, factory) { | ||
function _classCallCheck(instance, Constructor) { | ||
if (!(instance instanceof Constructor)) { | ||
throw new TypeError("Cannot call a class as a function"); | ||
} | ||
function _inheritsLoose(subClass, superClass) { | ||
subClass.prototype = Object.create(superClass.prototype); | ||
subClass.prototype.constructor = subClass; | ||
_setPrototypeOf(subClass, superClass); | ||
} | ||
function _defineProperties(target, props) { | ||
for (var i = 0; i < props.length; i++) { | ||
var descriptor = props[i]; | ||
descriptor.enumerable = descriptor.enumerable || false; | ||
descriptor.configurable = true; | ||
if ("value" in descriptor) descriptor.writable = true; | ||
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); | ||
} | ||
} | ||
function _createClass(Constructor, protoProps, staticProps) { | ||
if (protoProps) _defineProperties(Constructor.prototype, protoProps); | ||
if (staticProps) _defineProperties(Constructor, staticProps); | ||
Object.defineProperty(Constructor, "prototype", { | ||
writable: false | ||
}); | ||
return Constructor; | ||
} | ||
function _inherits(subClass, superClass) { | ||
if (typeof superClass !== "function" && superClass !== null) { | ||
throw new TypeError("Super expression must either be null or a function"); | ||
} | ||
subClass.prototype = Object.create(superClass && superClass.prototype, { | ||
constructor: { | ||
value: subClass, | ||
writable: true, | ||
configurable: true | ||
} | ||
}); | ||
Object.defineProperty(subClass, "prototype", { | ||
writable: false | ||
}); | ||
if (superClass) _setPrototypeOf(subClass, superClass); | ||
} | ||
function _getPrototypeOf(o) { | ||
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { | ||
return o.__proto__ || Object.getPrototypeOf(o); | ||
}; | ||
return _getPrototypeOf(o); | ||
} | ||
function _setPrototypeOf(o, p) { | ||
@@ -59,55 +20,2 @@ _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { | ||
} | ||
function _isNativeReflectConstruct() { | ||
if (typeof Reflect === "undefined" || !Reflect.construct) return false; | ||
if (Reflect.construct.sham) return false; | ||
if (typeof Proxy === "function") return true; | ||
try { | ||
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); | ||
return true; | ||
} catch (e) { | ||
return false; | ||
} | ||
} | ||
function _assertThisInitialized(self) { | ||
if (self === void 0) { | ||
throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); | ||
} | ||
return self; | ||
} | ||
function _possibleConstructorReturn(self, call) { | ||
if (call && (typeof call === "object" || typeof call === "function")) { | ||
return call; | ||
} else if (call !== void 0) { | ||
throw new TypeError("Derived constructors may only return object or undefined"); | ||
} | ||
return _assertThisInitialized(self); | ||
} | ||
function _createSuper(Derived) { | ||
var hasNativeReflectConstruct = _isNativeReflectConstruct(); | ||
return function _createSuperInternal() { | ||
var Super = _getPrototypeOf(Derived), | ||
result; | ||
if (hasNativeReflectConstruct) { | ||
var NewTarget = _getPrototypeOf(this).constructor; | ||
result = Reflect.construct(Super, arguments, NewTarget); | ||
} else { | ||
result = Super.apply(this, arguments); | ||
} | ||
return _possibleConstructorReturn(this, result); | ||
}; | ||
} | ||
function _toPrimitive(input, hint) { | ||
if (typeof input !== "object" || input === null) return input; | ||
var prim = input[Symbol.toPrimitive]; | ||
if (prim !== undefined) { | ||
var res = prim.call(input, hint || "default"); | ||
if (typeof res !== "object") return res; | ||
throw new TypeError("@@toPrimitive must return a primitive value."); | ||
} | ||
return (hint === "string" ? String : Number)(input); | ||
} | ||
function _toPropertyKey(arg) { | ||
var key = _toPrimitive(arg, "string"); | ||
return typeof key === "symbol" ? key : String(key); | ||
} | ||
@@ -1047,11 +955,9 @@ /** | ||
var AdvancedCamera = /*#__PURE__*/function (_Camera) { | ||
_inherits(AdvancedCamera, _Camera); | ||
var _super = _createSuper(AdvancedCamera); | ||
_inheritsLoose(AdvancedCamera, _Camera); | ||
function AdvancedCamera() { | ||
var _this; | ||
_classCallCheck(this, AdvancedCamera); | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
_this = _super.call.apply(_super, [this].concat(args)); | ||
_this = _Camera.call.apply(_Camera, [this].concat(args)) || this; | ||
/** | ||
@@ -1064,234 +970,224 @@ * switch between multiple landmarks | ||
} | ||
_createClass(AdvancedCamera, [{ | ||
key: "rotate", | ||
value: | ||
/** | ||
* Changes the azimuth and elevation with respect to the current camera axes | ||
* @param {Number} azimuth the relative azimuth | ||
* @param {Number} elevation the relative elevation | ||
* @param {Number} roll the relative roll | ||
*/ | ||
function rotate(azimuth, elevation, roll) { | ||
this.relElevation = gLite.getAngle(elevation); | ||
this.relAzimuth = gLite.getAngle(azimuth); | ||
this.relRoll = gLite.getAngle(roll); | ||
this.elevation += this.relElevation; | ||
this.azimuth += this.relAzimuth; | ||
this.roll += this.relRoll; | ||
if (this.type === gLite.CameraType.EXPLORING) { | ||
var rotX = setAxisAngle(create$4(), [1, 0, 0], gLite.deg2rad((this.rotateWorld ? 1 : -1) * this.relElevation)); | ||
var rotY = setAxisAngle(create$4(), [0, 1, 0], gLite.deg2rad((this.rotateWorld ? 1 : -1) * this.relAzimuth)); | ||
var rotZ = setAxisAngle(create$4(), [0, 0, 1], gLite.deg2rad(this.relRoll)); | ||
var rotQ = multiply$1(create$4(), rotY, rotX); | ||
rotQ = multiply$1(create$4(), rotQ, rotZ); | ||
var rotMatrix = fromQuat(create$1(), rotQ); | ||
translate(this.matrix, this.matrix, [0, 0, -this.distance]); | ||
multiply(this.matrix, this.matrix, rotMatrix); | ||
translate(this.matrix, this.matrix, [0, 0, this.distance]); | ||
} else { | ||
if (Math.abs(this.elevation) > 90) { | ||
return this; | ||
} | ||
this.computeMatrix(); | ||
var _proto = AdvancedCamera.prototype; | ||
/** | ||
* Changes the azimuth and elevation with respect to the current camera axes | ||
* @param {Number} azimuth the relative azimuth | ||
* @param {Number} elevation the relative elevation | ||
* @param {Number} roll the relative roll | ||
*/ | ||
_proto.rotate = function rotate(azimuth, elevation, roll) { | ||
this.relElevation = gLite.getAngle(elevation); | ||
this.relAzimuth = gLite.getAngle(azimuth); | ||
this.relRoll = gLite.getAngle(roll); | ||
this.elevation += this.relElevation; | ||
this.azimuth += this.relAzimuth; | ||
this.roll += this.relRoll; | ||
if (this.type === gLite.CameraType.EXPLORING) { | ||
var rotX = setAxisAngle(create$4(), [1, 0, 0], gLite.deg2rad((this.rotateWorld ? 1 : -1) * this.relElevation)); | ||
var rotY = setAxisAngle(create$4(), [0, 1, 0], gLite.deg2rad((this.rotateWorld ? 1 : -1) * this.relAzimuth)); | ||
var rotZ = setAxisAngle(create$4(), [0, 0, 1], gLite.deg2rad(this.relRoll)); | ||
var rotQ = multiply$1(create$4(), rotY, rotX); | ||
rotQ = multiply$1(create$4(), rotQ, rotZ); | ||
var rotMatrix = fromQuat(create$1(), rotQ); | ||
translate(this.matrix, this.matrix, [0, 0, -this.distance]); | ||
multiply(this.matrix, this.matrix, rotMatrix); | ||
translate(this.matrix, this.matrix, [0, 0, this.distance]); | ||
} else { | ||
if (Math.abs(this.elevation) > 90) { | ||
return this; | ||
} | ||
this._getAxes(); | ||
if (this.type === gLite.CameraType.ORBITING || this.type === gLite.CameraType.EXPLORING) { | ||
this._getPosition(); | ||
} else if (this.type === gLite.CameraType.TRACKING) { | ||
this._getFocalPoint(); | ||
} | ||
this._update(); | ||
return this; | ||
this.computeMatrix(); | ||
} | ||
/** | ||
* 沿水平(right) & 垂直(up)平移相机 | ||
*/ | ||
}, { | ||
key: "pan", | ||
value: function pan(tx, ty) { | ||
var coords = gLite.createVec3(tx, ty, 0); | ||
var pos = clone$1(this.position); | ||
add(pos, pos, scale(create$2(), this.right, coords[0])); | ||
add(pos, pos, scale(create$2(), this.up, coords[1])); | ||
this._setPosition(pos); | ||
this.triggerUpdate(); | ||
return this; | ||
this._getAxes(); | ||
if (this.type === gLite.CameraType.ORBITING || this.type === gLite.CameraType.EXPLORING) { | ||
this._getPosition(); | ||
} else if (this.type === gLite.CameraType.TRACKING) { | ||
this._getFocalPoint(); | ||
} | ||
/** | ||
* 沿 n 轴移动,当距离视点远时移动速度较快,离视点越近速度越慢 | ||
*/ | ||
}, { | ||
key: "dolly", | ||
value: function dolly(value) { | ||
var n = this.forward; | ||
var pos = clone$1(this.position); | ||
var step = value * this.dollyingStep; | ||
var updatedDistance = this.distance + value * this.dollyingStep; | ||
// 限制视点距离范围 | ||
step = Math.max(Math.min(updatedDistance, this.maxDistance), this.minDistance) - this.distance; | ||
pos[0] += step * n[0]; | ||
pos[1] += step * n[1]; | ||
pos[2] += step * n[2]; | ||
this._setPosition(pos); | ||
if (this.type === gLite.CameraType.ORBITING || this.type === gLite.CameraType.EXPLORING) { | ||
// 重新计算视点距离 | ||
this._getDistance(); | ||
} else if (this.type === gLite.CameraType.TRACKING) { | ||
// 保持视距,移动视点位置 | ||
add(this.focalPoint, pos, this.distanceVector); | ||
} | ||
this.triggerUpdate(); | ||
return this; | ||
this._update(); | ||
return this; | ||
} | ||
/** | ||
* 沿水平(right) & 垂直(up)平移相机 | ||
*/; | ||
_proto.pan = function pan(tx, ty) { | ||
var coords = gLite.createVec3(tx, ty, 0); | ||
var pos = clone$1(this.position); | ||
add(pos, pos, scale(create$2(), this.right, coords[0])); | ||
add(pos, pos, scale(create$2(), this.up, coords[1])); | ||
this._setPosition(pos); | ||
this.triggerUpdate(); | ||
return this; | ||
} | ||
/** | ||
* 沿 n 轴移动,当距离视点远时移动速度较快,离视点越近速度越慢 | ||
*/; | ||
_proto.dolly = function dolly(value) { | ||
var n = this.forward; | ||
var pos = clone$1(this.position); | ||
var step = value * this.dollyingStep; | ||
var updatedDistance = this.distance + value * this.dollyingStep; | ||
// 限制视点距离范围 | ||
step = Math.max(Math.min(updatedDistance, this.maxDistance), this.minDistance) - this.distance; | ||
pos[0] += step * n[0]; | ||
pos[1] += step * n[1]; | ||
pos[2] += step * n[2]; | ||
this._setPosition(pos); | ||
if (this.type === gLite.CameraType.ORBITING || this.type === gLite.CameraType.EXPLORING) { | ||
// 重新计算视点距离 | ||
this._getDistance(); | ||
} else if (this.type === gLite.CameraType.TRACKING) { | ||
// 保持视距,移动视点位置 | ||
add(this.focalPoint, pos, this.distanceVector); | ||
} | ||
}, { | ||
key: "cancelLandmarkAnimation", | ||
value: function cancelLandmarkAnimation() { | ||
if (this.landmarkAnimationID !== undefined) { | ||
this.canvas.cancelAnimationFrame(this.landmarkAnimationID); | ||
this.triggerUpdate(); | ||
return this; | ||
}; | ||
_proto.cancelLandmarkAnimation = function cancelLandmarkAnimation() { | ||
if (this.landmarkAnimationID !== undefined) { | ||
this.canvas.cancelAnimationFrame(this.landmarkAnimationID); | ||
} | ||
}; | ||
_proto.createLandmark = function createLandmark(name, params) { | ||
var _position$, _position$2, _focalPoint$, _focalPoint$2; | ||
if (params === void 0) { | ||
params = {}; | ||
} | ||
var _params = params, | ||
_params$position = _params.position, | ||
position = _params$position === void 0 ? this.position : _params$position, | ||
_params$focalPoint = _params.focalPoint, | ||
focalPoint = _params$focalPoint === void 0 ? this.focalPoint : _params$focalPoint, | ||
roll = _params.roll, | ||
zoom = _params.zoom; | ||
var camera = new gLite.runtime.CameraContribution(); | ||
camera.setType(this.type, undefined); | ||
camera.setPosition(position[0], (_position$ = position[1]) !== null && _position$ !== void 0 ? _position$ : this.position[1], (_position$2 = position[2]) !== null && _position$2 !== void 0 ? _position$2 : this.position[2]); | ||
camera.setFocalPoint(focalPoint[0], (_focalPoint$ = focalPoint[1]) !== null && _focalPoint$ !== void 0 ? _focalPoint$ : this.focalPoint[1], (_focalPoint$2 = focalPoint[2]) !== null && _focalPoint$2 !== void 0 ? _focalPoint$2 : this.focalPoint[2]); | ||
camera.setRoll(roll !== null && roll !== void 0 ? roll : this.roll); | ||
camera.setZoom(zoom !== null && zoom !== void 0 ? zoom : this.zoom); | ||
var landmark = { | ||
name: name, | ||
matrix: clone(camera.getWorldTransform()), | ||
right: clone$1(camera.right), | ||
up: clone$1(camera.up), | ||
forward: clone$1(camera.forward), | ||
position: clone$1(camera.getPosition()), | ||
focalPoint: clone$1(camera.getFocalPoint()), | ||
distanceVector: clone$1(camera.getDistanceVector()), | ||
distance: camera.getDistance(), | ||
dollyingStep: camera.getDollyingStep(), | ||
azimuth: camera.getAzimuth(), | ||
elevation: camera.getElevation(), | ||
roll: camera.getRoll(), | ||
relAzimuth: camera.relAzimuth, | ||
relElevation: camera.relElevation, | ||
relRoll: camera.relRoll, | ||
zoom: camera.getZoom() | ||
}; | ||
this.landmarks.push(landmark); | ||
return landmark; | ||
}; | ||
_proto.gotoLandmark = function gotoLandmark(name, options) { | ||
var _this2 = this; | ||
if (options === void 0) { | ||
options = {}; | ||
} | ||
var landmark = isString(name) ? this.landmarks.find(function (l) { | ||
return l.name === name; | ||
}) : name; | ||
if (landmark) { | ||
var _ref = isNumber(options) ? { | ||
duration: options | ||
} : options, | ||
_ref$easing = _ref.easing, | ||
easing = _ref$easing === void 0 ? 'linear' : _ref$easing, | ||
_ref$duration = _ref.duration, | ||
duration = _ref$duration === void 0 ? 100 : _ref$duration, | ||
_ref$easingFunction = _ref.easingFunction, | ||
easingFunction = _ref$easingFunction === void 0 ? undefined : _ref$easingFunction, | ||
_ref$onfinish = _ref.onfinish, | ||
onfinish = _ref$onfinish === void 0 ? undefined : _ref$onfinish; | ||
var epsilon = 0.01; | ||
if (duration === 0) { | ||
this.syncFromLandmark(landmark); | ||
if (onfinish) { | ||
onfinish(); | ||
} | ||
return; | ||
} | ||
} | ||
}, { | ||
key: "createLandmark", | ||
value: function createLandmark(name) { | ||
var _position$, _position$2, _focalPoint$, _focalPoint$2; | ||
var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var _params$position = params.position, | ||
position = _params$position === void 0 ? this.position : _params$position, | ||
_params$focalPoint = params.focalPoint, | ||
focalPoint = _params$focalPoint === void 0 ? this.focalPoint : _params$focalPoint, | ||
roll = params.roll, | ||
zoom = params.zoom; | ||
var camera = new gLite.runtime.CameraContribution(); | ||
camera.setType(this.type, undefined); | ||
camera.setPosition(position[0], (_position$ = position[1]) !== null && _position$ !== void 0 ? _position$ : this.position[1], (_position$2 = position[2]) !== null && _position$2 !== void 0 ? _position$2 : this.position[2]); | ||
camera.setFocalPoint(focalPoint[0], (_focalPoint$ = focalPoint[1]) !== null && _focalPoint$ !== void 0 ? _focalPoint$ : this.focalPoint[1], (_focalPoint$2 = focalPoint[2]) !== null && _focalPoint$2 !== void 0 ? _focalPoint$2 : this.focalPoint[2]); | ||
camera.setRoll(roll !== null && roll !== void 0 ? roll : this.roll); | ||
camera.setZoom(zoom !== null && zoom !== void 0 ? zoom : this.zoom); | ||
var landmark = { | ||
name: name, | ||
matrix: clone(camera.getWorldTransform()), | ||
right: clone$1(camera.right), | ||
up: clone$1(camera.up), | ||
forward: clone$1(camera.forward), | ||
position: clone$1(camera.getPosition()), | ||
focalPoint: clone$1(camera.getFocalPoint()), | ||
distanceVector: clone$1(camera.getDistanceVector()), | ||
distance: camera.getDistance(), | ||
dollyingStep: camera.getDollyingStep(), | ||
azimuth: camera.getAzimuth(), | ||
elevation: camera.getElevation(), | ||
roll: camera.getRoll(), | ||
relAzimuth: camera.relAzimuth, | ||
relElevation: camera.relElevation, | ||
relRoll: camera.relRoll, | ||
zoom: camera.getZoom() | ||
// cancel ongoing animation | ||
this.cancelLandmarkAnimation(); | ||
var destPosition = landmark.position; | ||
var destFocalPoint = landmark.focalPoint; | ||
var destZoom = landmark.zoom; | ||
var destRoll = landmark.roll; | ||
var easingFunc = easingFunction || gLite.runtime.EasingFunction(easing); | ||
var timeStart; | ||
var endAnimation = function endAnimation() { | ||
_this2.setFocalPoint(destFocalPoint); | ||
_this2.setPosition(destPosition); | ||
_this2.setRoll(destRoll); | ||
_this2.setZoom(destZoom); | ||
_this2.computeMatrix(); | ||
_this2.triggerUpdate(); | ||
if (onfinish) { | ||
onfinish(); | ||
} | ||
}; | ||
this.landmarks.push(landmark); | ||
return landmark; | ||
} | ||
}, { | ||
key: "gotoLandmark", | ||
value: function gotoLandmark(name) { | ||
var _this2 = this; | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var landmark = isString(name) ? this.landmarks.find(function (l) { | ||
return l.name === name; | ||
}) : name; | ||
if (landmark) { | ||
var _ref = isNumber(options) ? { | ||
duration: options | ||
} : options, | ||
_ref$easing = _ref.easing, | ||
easing = _ref$easing === void 0 ? 'linear' : _ref$easing, | ||
_ref$duration = _ref.duration, | ||
duration = _ref$duration === void 0 ? 100 : _ref$duration, | ||
_ref$easingFunction = _ref.easingFunction, | ||
easingFunction = _ref$easingFunction === void 0 ? undefined : _ref$easingFunction, | ||
_ref$onfinish = _ref.onfinish, | ||
onfinish = _ref$onfinish === void 0 ? undefined : _ref$onfinish; | ||
var epsilon = 0.01; | ||
if (duration === 0) { | ||
this.syncFromLandmark(landmark); | ||
if (onfinish) { | ||
onfinish(); | ||
} | ||
var animate = function animate(timestamp) { | ||
if (timeStart === undefined) { | ||
timeStart = timestamp; | ||
} | ||
var elapsed = timestamp - timeStart; | ||
if (elapsed > duration) { | ||
endAnimation(); | ||
return; | ||
} | ||
// cancel ongoing animation | ||
this.cancelLandmarkAnimation(); | ||
var destPosition = landmark.position; | ||
var destFocalPoint = landmark.focalPoint; | ||
var destZoom = landmark.zoom; | ||
var destRoll = landmark.roll; | ||
var easingFunc = easingFunction || gLite.runtime.EasingFunction(easing); | ||
var timeStart; | ||
var endAnimation = function endAnimation() { | ||
_this2.setFocalPoint(destFocalPoint); | ||
_this2.setPosition(destPosition); | ||
_this2.setRoll(destRoll); | ||
_this2.setZoom(destZoom); | ||
_this2.computeMatrix(); | ||
_this2.triggerUpdate(); | ||
if (onfinish) { | ||
onfinish(); | ||
} | ||
}; | ||
var animate = function animate(timestamp) { | ||
if (timeStart === undefined) { | ||
timeStart = timestamp; | ||
} | ||
var elapsed = timestamp - timeStart; | ||
if (elapsed > duration) { | ||
endAnimation(); | ||
return; | ||
} | ||
// use the same ease function in animation system | ||
var t = easingFunc(elapsed / duration); | ||
var interFocalPoint = create$2(); | ||
var interPosition = create$2(); | ||
var interZoom = 1; | ||
var interRoll = 0; | ||
lerp(interFocalPoint, _this2.focalPoint, destFocalPoint, t); | ||
lerp(interPosition, _this2.position, destPosition, t); | ||
interRoll = _this2.roll * (1 - t) + destRoll * t; | ||
interZoom = _this2.zoom * (1 - t) + destZoom * t; | ||
_this2.setFocalPoint(interFocalPoint); | ||
_this2.setPosition(interPosition); | ||
_this2.setRoll(interRoll); | ||
_this2.setZoom(interZoom); | ||
var dist$1 = dist(interFocalPoint, destFocalPoint) + dist(interPosition, destPosition); | ||
if (dist$1 <= epsilon && destZoom == undefined && destRoll == undefined) { | ||
endAnimation(); | ||
return; | ||
} | ||
_this2.computeMatrix(); | ||
_this2.triggerUpdate(); | ||
if (elapsed < duration) { | ||
_this2.landmarkAnimationID = _this2.canvas.requestAnimationFrame(animate); | ||
} | ||
}; | ||
this.canvas.requestAnimationFrame(animate); | ||
} | ||
// use the same ease function in animation system | ||
var t = easingFunc(elapsed / duration); | ||
var interFocalPoint = create$2(); | ||
var interPosition = create$2(); | ||
var interZoom = 1; | ||
var interRoll = 0; | ||
lerp(interFocalPoint, _this2.focalPoint, destFocalPoint, t); | ||
lerp(interPosition, _this2.position, destPosition, t); | ||
interRoll = _this2.roll * (1 - t) + destRoll * t; | ||
interZoom = _this2.zoom * (1 - t) + destZoom * t; | ||
_this2.setFocalPoint(interFocalPoint); | ||
_this2.setPosition(interPosition); | ||
_this2.setRoll(interRoll); | ||
_this2.setZoom(interZoom); | ||
var dist$1 = dist(interFocalPoint, destFocalPoint) + dist(interPosition, destPosition); | ||
if (dist$1 <= epsilon && destZoom == undefined && destRoll == undefined) { | ||
endAnimation(); | ||
return; | ||
} | ||
_this2.computeMatrix(); | ||
_this2.triggerUpdate(); | ||
if (elapsed < duration) { | ||
_this2.landmarkAnimationID = _this2.canvas.requestAnimationFrame(animate); | ||
} | ||
}; | ||
this.canvas.requestAnimationFrame(animate); | ||
} | ||
}, { | ||
key: "syncFromLandmark", | ||
value: function syncFromLandmark(landmark) { | ||
this.matrix = copy(this.matrix, landmark.matrix); | ||
this.right = copy$1(this.right, landmark.right); | ||
this.up = copy$1(this.up, landmark.up); | ||
this.forward = copy$1(this.forward, landmark.forward); | ||
this.position = copy$1(this.position, landmark.position); | ||
this.focalPoint = copy$1(this.focalPoint, landmark.focalPoint); | ||
this.distanceVector = copy$1(this.distanceVector, landmark.distanceVector); | ||
this.azimuth = landmark.azimuth; | ||
this.elevation = landmark.elevation; | ||
this.roll = landmark.roll; | ||
this.relAzimuth = landmark.relAzimuth; | ||
this.relElevation = landmark.relElevation; | ||
this.relRoll = landmark.relRoll; | ||
this.dollyingStep = landmark.dollyingStep; | ||
this.distance = landmark.distance; | ||
this.zoom = landmark.zoom; | ||
} | ||
}]); | ||
}; | ||
_proto.syncFromLandmark = function syncFromLandmark(landmark) { | ||
this.matrix = copy(this.matrix, landmark.matrix); | ||
this.right = copy$1(this.right, landmark.right); | ||
this.up = copy$1(this.up, landmark.up); | ||
this.forward = copy$1(this.forward, landmark.forward); | ||
this.position = copy$1(this.position, landmark.position); | ||
this.focalPoint = copy$1(this.focalPoint, landmark.focalPoint); | ||
this.distanceVector = copy$1(this.distanceVector, landmark.distanceVector); | ||
this.azimuth = landmark.azimuth; | ||
this.elevation = landmark.elevation; | ||
this.roll = landmark.roll; | ||
this.relAzimuth = landmark.relAzimuth; | ||
this.relElevation = landmark.relElevation; | ||
this.relRoll = landmark.relRoll; | ||
this.dollyingStep = landmark.dollyingStep; | ||
this.distance = landmark.distance; | ||
this.zoom = landmark.zoom; | ||
}; | ||
return AdvancedCamera; | ||
@@ -1298,0 +1194,0 @@ }(gLite.Camera); |
@@ -1,1 +0,1 @@ | ||
!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?i(exports,require("@antv/g-lite")):"function"==typeof define&&define.amd?define(["exports","@antv/g-lite"],i):i(((t="undefined"!=typeof globalThis?globalThis:t||self).G=t.G||{},t.G.CameraAPI={}),t.window.G)}(this,(function(t,i){"use strict";function e(t,i){for(var e=0;i.length>e;e++){var n=i[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,(r=void 0,"symbol"==typeof(r=function(t,i){if("object"!=typeof t||null===t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,i||"default");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===i?String:Number)(t)}(n.key,"string"))?r:r+""),n)}var r}function n(t){return n=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},n(t)}function r(t,i){return r=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,i){return t.__proto__=i,t},r(t,i)}function o(t,i){if(i&&("object"==typeof i||"function"==typeof i))return i;if(void 0!==i)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}function a(t){var i=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var e,r=n(t);if(i){var a=n(this).constructor;e=Reflect.construct(r,arguments,a)}else e=r.apply(this,arguments);return o(this,e)}}var s="undefined"!=typeof Float32Array?Float32Array:Array;function l(t){var i=new s(16);return i[0]=t[0],i[1]=t[1],i[2]=t[2],i[3]=t[3],i[4]=t[4],i[5]=t[5],i[6]=t[6],i[7]=t[7],i[8]=t[8],i[9]=t[9],i[10]=t[10],i[11]=t[11],i[12]=t[12],i[13]=t[13],i[14]=t[14],i[15]=t[15],i}function u(t,i,e){var n,r,o,a,s,l,u,c,h,f,d,p,m=e[0],v=e[1],y=e[2];return i===t?(t[12]=i[0]*m+i[4]*v+i[8]*y+i[12],t[13]=i[1]*m+i[5]*v+i[9]*y+i[13],t[14]=i[2]*m+i[6]*v+i[10]*y+i[14],t[15]=i[3]*m+i[7]*v+i[11]*y+i[15]):(r=i[1],o=i[2],a=i[3],s=i[4],l=i[5],u=i[6],c=i[7],h=i[8],f=i[9],d=i[10],p=i[11],t[0]=n=i[0],t[1]=r,t[2]=o,t[3]=a,t[4]=s,t[5]=l,t[6]=u,t[7]=c,t[8]=h,t[9]=f,t[10]=d,t[11]=p,t[12]=n*m+s*v+h*y+i[12],t[13]=r*m+l*v+f*y+i[13],t[14]=o*m+u*v+d*y+i[14],t[15]=a*m+c*v+p*y+i[15]),t}function c(){var t=new s(3);return s!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t}function h(t){var i=new s(3);return i[0]=t[0],i[1]=t[1],i[2]=t[2],i}function f(t,i,e){var n=new s(3);return n[0]=t,n[1]=i,n[2]=e,n}function d(t,i){return t[0]=i[0],t[1]=i[1],t[2]=i[2],t}function p(t,i,e){return t[0]=i[0]+e[0],t[1]=i[1]+e[1],t[2]=i[2]+e[2],t}function m(t,i,e){return t[0]=i[0]*e,t[1]=i[1]*e,t[2]=i[2]*e,t}function v(t,i,e){var n=i[0],r=i[1],o=i[2],a=e[0],s=e[1],l=e[2];return t[0]=r*l-o*s,t[1]=o*a-n*l,t[2]=n*s-r*a,t}function y(t,i,e,n){var r=i[0],o=i[1],a=i[2];return t[0]=r+n*(e[0]-r),t[1]=o+n*(e[1]-o),t[2]=a+n*(e[2]-a),t}Math.hypot||(Math.hypot=function(){for(var t=0,i=arguments.length;i--;)t+=arguments[i]*arguments[i];return Math.sqrt(t)});var g,P=function(t,i){return Math.hypot(i[0]-t[0],i[1]-t[1],i[2]-t[2])},b=function(t){return Math.hypot(t[0],t[1],t[2])};g=c();!function(){var t,i=(t=new s(4),s!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0,t[3]=0),t)}();function A(){var t=new s(4);return s!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t[3]=1,t}function w(t,i,e){var n=Math.sin(e*=.5);return t[0]=n*i[0],t[1]=n*i[1],t[2]=n*i[2],t[3]=Math.cos(e),t}function R(t,i,e){var n=i[0],r=i[1],o=i[2],a=i[3],s=e[0],l=e[1],u=e[2],c=e[3];return t[0]=n*c+a*s+r*u-o*l,t[1]=r*c+a*l+o*s-n*u,t[2]=o*c+a*u+n*l-r*s,t[3]=a*c-n*s-r*l-o*u,t}function k(t,i,e,n){var r,o,a,s,l,u=i[0],c=i[1],h=i[2],f=i[3],d=e[0],p=e[1],m=e[2],v=e[3];return 0>(o=u*d+c*p+h*m+f*v)&&(o=-o,d=-d,p=-p,m=-m,v=-v),1-o>1e-6?(a=Math.sin(r=Math.acos(o)),s=Math.sin((1-n)*r)/a,l=Math.sin(n*r)/a):(s=1-n,l=n),t[0]=s*u+l*d,t[1]=s*c+l*p,t[2]=s*h+l*m,t[3]=s*f+l*v,t}var x,O,z,F,M,T,C,E=function(t,i){var e=i[0],n=i[1],r=i[2],o=i[3],a=e*e+n*n+r*r+o*o;return a>0&&(a=1/Math.sqrt(a)),t[0]=e*a,t[1]=n*a,t[2]=r*a,t[3]=o*a,t},_=(x=c(),O=f(1,0,0),z=f(0,1,0),F=A(),M=A(),T=new s(9),s!=Float32Array&&(T[1]=0,T[2]=0,T[3]=0,T[5]=0,T[6]=0,T[7]=0),T[0]=1,T[4]=1,T[8]=1,C=T,{}.toString),j=function(t,i){return _.call(t)==="[object "+i+"]"},I=function(t){!function(t,i){if("function"!=typeof i&&null!==i)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(i&&i.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),i&&r(t,i)}(g,t);var n,o,f,v=a(g);function g(){var t;!function(t,i){if(!(t instanceof i))throw new TypeError("Cannot call a class as a function")}(this,g);for(var i=arguments.length,e=Array(i),n=0;i>n;n++)e[n]=arguments[n];return(t=v.call.apply(v,[this].concat(e))).landmarks=[],t.landmarkAnimationID=void 0,t}return n=g,o=[{key:"rotate",value:function(t,e,n){if(this.relElevation=i.getAngle(e),this.relAzimuth=i.getAngle(t),this.relRoll=i.getAngle(n),this.elevation+=this.relElevation,this.azimuth+=this.relAzimuth,this.roll+=this.relRoll,this.type===i.CameraType.EXPLORING){var r=w(A(),[1,0,0],i.deg2rad((this.rotateWorld?1:-1)*this.relElevation)),o=w(A(),[0,1,0],i.deg2rad((this.rotateWorld?1:-1)*this.relAzimuth)),a=w(A(),[0,0,1],i.deg2rad(this.relRoll)),l=R(A(),o,r);l=R(A(),l,a);var c=function(t,i){var e=i[0],n=i[1],r=i[2],o=i[3],a=e+e,s=n+n,l=r+r,u=e*a,c=n*a,h=n*s,f=r*a,d=r*s,p=r*l,m=o*a,v=o*s,y=o*l;return t[0]=1-h-p,t[1]=c+y,t[2]=f-v,t[3]=0,t[4]=c-y,t[5]=1-u-p,t[6]=d+m,t[7]=0,t[8]=f+v,t[9]=d-m,t[10]=1-u-h,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}(function(){var t=new s(16);return s!=Float32Array&&(t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0),t[0]=1,t[5]=1,t[10]=1,t[15]=1,t}(),l);u(this.matrix,this.matrix,[0,0,-this.distance]),function(t,i,e){var n=i[0],r=i[1],o=i[2],a=i[3],s=i[4],l=i[5],u=i[6],c=i[7],h=i[8],f=i[9],d=i[10],p=i[11],m=i[12],v=i[13],y=i[14],g=i[15],P=e[0],b=e[1],A=e[2],w=e[3];t[0]=P*n+b*s+A*h+w*m,t[1]=P*r+b*l+A*f+w*v,t[2]=P*o+b*u+A*d+w*y,t[3]=P*a+b*c+A*p+w*g,t[4]=(P=e[4])*n+(b=e[5])*s+(A=e[6])*h+(w=e[7])*m,t[5]=P*r+b*l+A*f+w*v,t[6]=P*o+b*u+A*d+w*y,t[7]=P*a+b*c+A*p+w*g,t[8]=(P=e[8])*n+(b=e[9])*s+(A=e[10])*h+(w=e[11])*m,t[9]=P*r+b*l+A*f+w*v,t[10]=P*o+b*u+A*d+w*y,t[11]=P*a+b*c+A*p+w*g,t[12]=(P=e[12])*n+(b=e[13])*s+(A=e[14])*h+(w=e[15])*m,t[13]=P*r+b*l+A*f+w*v,t[14]=P*o+b*u+A*d+w*y,t[15]=P*a+b*c+A*p+w*g}(this.matrix,this.matrix,c),u(this.matrix,this.matrix,[0,0,this.distance])}else{if(Math.abs(this.elevation)>90)return this;this.computeMatrix()}return this._getAxes(),this.type===i.CameraType.ORBITING||this.type===i.CameraType.EXPLORING?this._getPosition():this.type===i.CameraType.TRACKING&&this._getFocalPoint(),this._update(),this}},{key:"pan",value:function(t,e){var n=i.createVec3(t,e,0),r=h(this.position);return p(r,r,m(c(),this.right,n[0])),p(r,r,m(c(),this.up,n[1])),this._setPosition(r),this.triggerUpdate(),this}},{key:"dolly",value:function(t){var e,n=this.forward,r=h(this.position);return r[0]+=(e=Math.max(Math.min(this.distance+t*this.dollyingStep,this.maxDistance),this.minDistance)-this.distance)*n[0],r[1]+=e*n[1],r[2]+=e*n[2],this._setPosition(r),this.type===i.CameraType.ORBITING||this.type===i.CameraType.EXPLORING?this._getDistance():this.type===i.CameraType.TRACKING&&p(this.focalPoint,r,this.distanceVector),this.triggerUpdate(),this}},{key:"cancelLandmarkAnimation",value:function(){void 0!==this.landmarkAnimationID&&this.canvas.cancelAnimationFrame(this.landmarkAnimationID)}},{key:"createLandmark",value:function(t){var e,n,r,o,a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},s=a.position,u=void 0===s?this.position:s,c=a.focalPoint,f=void 0===c?this.focalPoint:c,d=a.roll,p=a.zoom,m=new i.runtime.CameraContribution;m.setType(this.type,void 0),m.setPosition(u[0],null!==(e=u[1])&&void 0!==e?e:this.position[1],null!==(n=u[2])&&void 0!==n?n:this.position[2]),m.setFocalPoint(f[0],null!==(r=f[1])&&void 0!==r?r:this.focalPoint[1],null!==(o=f[2])&&void 0!==o?o:this.focalPoint[2]),m.setRoll(null!=d?d:this.roll),m.setZoom(null!=p?p:this.zoom);var v={name:t,matrix:l(m.getWorldTransform()),right:h(m.right),up:h(m.up),forward:h(m.forward),position:h(m.getPosition()),focalPoint:h(m.getFocalPoint()),distanceVector:h(m.getDistanceVector()),distance:m.getDistance(),dollyingStep:m.getDollyingStep(),azimuth:m.getAzimuth(),elevation:m.getElevation(),roll:m.getRoll(),relAzimuth:m.relAzimuth,relElevation:m.relElevation,relRoll:m.relRoll,zoom:m.getZoom()};return this.landmarks.push(v),v}},{key:"gotoLandmark",value:function(t){var e=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=j(t,"String")?this.landmarks.find((function(i){return i.name===t})):t;if(r){var o=j(n,"Number")?{duration:n}:n,a=o.easing,s=void 0===a?"linear":a,l=o.duration,u=void 0===l?100:l,h=o.easingFunction,f=void 0===h?void 0:h,d=o.onfinish,p=void 0===d?void 0:d;if(0===u)return this.syncFromLandmark(r),void(p&&p());this.cancelLandmarkAnimation();var m,v=r.position,g=r.focalPoint,b=r.zoom,A=r.roll,w=f||i.runtime.EasingFunction(s),R=function(){e.setFocalPoint(g),e.setPosition(v),e.setRoll(A),e.setZoom(b),e.computeMatrix(),e.triggerUpdate(),p&&p()};this.canvas.requestAnimationFrame((function t(i){void 0===m&&(m=i);var n=i-m;if(n>u)R();else{var r,o,a=w(n/u),s=c(),l=c();y(s,e.focalPoint,g,a),y(l,e.position,v,a),o=e.roll*(1-a)+A*a,r=e.zoom*(1-a)+b*a,e.setFocalPoint(s),e.setPosition(l),e.setRoll(o),e.setZoom(r),P(s,g)+P(l,v)>.01||null!=b||null!=A?(e.computeMatrix(),e.triggerUpdate(),u>n&&(e.landmarkAnimationID=e.canvas.requestAnimationFrame(t))):R()}}))}}},{key:"syncFromLandmark",value:function(t){this.matrix=function(t,i){return t[0]=i[0],t[1]=i[1],t[2]=i[2],t[3]=i[3],t[4]=i[4],t[5]=i[5],t[6]=i[6],t[7]=i[7],t[8]=i[8],t[9]=i[9],t[10]=i[10],t[11]=i[11],t[12]=i[12],t[13]=i[13],t[14]=i[14],t[15]=i[15],t}(this.matrix,t.matrix),this.right=d(this.right,t.right),this.up=d(this.up,t.up),this.forward=d(this.forward,t.forward),this.position=d(this.position,t.position),this.focalPoint=d(this.focalPoint,t.focalPoint),this.distanceVector=d(this.distanceVector,t.distanceVector),this.azimuth=t.azimuth,this.elevation=t.elevation,this.roll=t.roll,this.relAzimuth=t.relAzimuth,this.relElevation=t.relElevation,this.relRoll=t.relRoll,this.dollyingStep=t.dollyingStep,this.distance=t.distance,this.zoom=t.zoom}}],o&&e(n.prototype,o),f&&e(n,f),Object.defineProperty(n,"prototype",{writable:!1}),g}(i.Camera);i.runtime.CameraContribution=I,t.AdvancedCamera=I,Object.defineProperty(t,"__esModule",{value:!0})})); | ||
!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?i(exports,require("@antv/g-lite")):"function"==typeof define&&define.amd?define(["exports","@antv/g-lite"],i):i(((t="undefined"!=typeof globalThis?globalThis:t||self).G=t.G||{},t.G.CameraAPI={}),t.window.G)}(this,(function(t,i){"use strict";function n(t,i){return n=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,i){return t.__proto__=i,t},n(t,i)}var o="undefined"!=typeof Float32Array?Float32Array:Array;function e(t){var i=new o(16);return i[0]=t[0],i[1]=t[1],i[2]=t[2],i[3]=t[3],i[4]=t[4],i[5]=t[5],i[6]=t[6],i[7]=t[7],i[8]=t[8],i[9]=t[9],i[10]=t[10],i[11]=t[11],i[12]=t[12],i[13]=t[13],i[14]=t[14],i[15]=t[15],i}function r(t,i,n){var o,e,r,a,s,l,h,u,c,d,m,f,p=n[0],v=n[1],g=n[2];return i===t?(t[12]=i[0]*p+i[4]*v+i[8]*g+i[12],t[13]=i[1]*p+i[5]*v+i[9]*g+i[13],t[14]=i[2]*p+i[6]*v+i[10]*g+i[14],t[15]=i[3]*p+i[7]*v+i[11]*g+i[15]):(e=i[1],r=i[2],a=i[3],s=i[4],l=i[5],h=i[6],u=i[7],c=i[8],d=i[9],m=i[10],f=i[11],t[0]=o=i[0],t[1]=e,t[2]=r,t[3]=a,t[4]=s,t[5]=l,t[6]=h,t[7]=u,t[8]=c,t[9]=d,t[10]=m,t[11]=f,t[12]=o*p+s*v+c*g+i[12],t[13]=e*p+l*v+d*g+i[13],t[14]=r*p+h*v+m*g+i[14],t[15]=a*p+u*v+f*g+i[15]),t}function a(){var t=new o(3);return o!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t}function s(t){var i=new o(3);return i[0]=t[0],i[1]=t[1],i[2]=t[2],i}function l(t,i,n){var e=new o(3);return e[0]=t,e[1]=i,e[2]=n,e}function h(t,i){return t[0]=i[0],t[1]=i[1],t[2]=i[2],t}function u(t,i,n){return t[0]=i[0]+n[0],t[1]=i[1]+n[1],t[2]=i[2]+n[2],t}function c(t,i,n){return t[0]=i[0]*n,t[1]=i[1]*n,t[2]=i[2]*n,t}function d(t,i,n){var o=i[0],e=i[1],r=i[2],a=n[0],s=n[1],l=n[2];return t[0]=e*l-r*s,t[1]=r*a-o*l,t[2]=o*s-e*a,t}function m(t,i,n,o){var e=i[0],r=i[1],a=i[2];return t[0]=e+o*(n[0]-e),t[1]=r+o*(n[1]-r),t[2]=a+o*(n[2]-a),t}Math.hypot||(Math.hypot=function(){for(var t=0,i=arguments.length;i--;)t+=arguments[i]*arguments[i];return Math.sqrt(t)});var f,p=function(t,i){return Math.hypot(i[0]-t[0],i[1]-t[1],i[2]-t[2])},v=function(t){return Math.hypot(t[0],t[1],t[2])};f=a();!function(){var t,i=(t=new o(4),o!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0,t[3]=0),t)}();function g(){var t=new o(4);return o!=Float32Array&&(t[0]=0,t[1]=0,t[2]=0),t[3]=1,t}function y(t,i,n){var o=Math.sin(n*=.5);return t[0]=o*i[0],t[1]=o*i[1],t[2]=o*i[2],t[3]=Math.cos(n),t}function A(t,i,n){var o=i[0],e=i[1],r=i[2],a=i[3],s=n[0],l=n[1],h=n[2],u=n[3];return t[0]=o*u+a*s+e*h-r*l,t[1]=e*u+a*l+r*s-o*h,t[2]=r*u+a*h+o*l-e*s,t[3]=a*u-o*s-e*l-r*h,t}function P(t,i,n,o){var e,r,a,s,l,h=i[0],u=i[1],c=i[2],d=i[3],m=n[0],f=n[1],p=n[2],v=n[3];return 0>(r=h*m+u*f+c*p+d*v)&&(r=-r,m=-m,f=-f,p=-p,v=-v),1-r>1e-6?(a=Math.sin(e=Math.acos(r)),s=Math.sin((1-o)*e)/a,l=Math.sin(o*e)/a):(s=1-o,l=o),t[0]=s*h+l*m,t[1]=s*u+l*f,t[2]=s*c+l*p,t[3]=s*d+l*v,t}var x,z,F,M,R,w,C,T=function(t,i){var n=i[0],o=i[1],e=i[2],r=i[3],a=n*n+o*o+e*e+r*r;return a>0&&(a=1/Math.sqrt(a)),t[0]=n*a,t[1]=o*a,t[2]=e*a,t[3]=r*a,t},I=(x=a(),z=l(1,0,0),F=l(0,1,0),M=g(),R=g(),w=new o(9),o!=Float32Array&&(w[1]=0,w[2]=0,w[3]=0,w[5]=0,w[6]=0,w[7]=0),w[0]=1,w[4]=1,w[8]=1,C=w,{}.toString),b=function(t,i){return I.call(t)==="[object "+i+"]"},k=function(t){var l,d;function f(){for(var i,n=arguments.length,o=Array(n),e=0;n>e;e++)o[e]=arguments[e];return(i=t.call.apply(t,[this].concat(o))||this).landmarks=[],i.landmarkAnimationID=void 0,i}(l=f).prototype=Object.create((d=t).prototype),l.prototype.constructor=l,n(l,d);var v=f.prototype;return v.rotate=function(t,n,e){if(this.relElevation=i.getAngle(n),this.relAzimuth=i.getAngle(t),this.relRoll=i.getAngle(e),this.elevation+=this.relElevation,this.azimuth+=this.relAzimuth,this.roll+=this.relRoll,this.type===i.CameraType.EXPLORING){var a=y(g(),[1,0,0],i.deg2rad((this.rotateWorld?1:-1)*this.relElevation)),s=y(g(),[0,1,0],i.deg2rad((this.rotateWorld?1:-1)*this.relAzimuth)),l=y(g(),[0,0,1],i.deg2rad(this.relRoll)),h=A(g(),s,a);h=A(g(),h,l);var u=function(t,i){var n=i[0],o=i[1],e=i[2],r=i[3],a=n+n,s=o+o,l=e+e,h=n*a,u=o*a,c=o*s,d=e*a,m=e*s,f=e*l,p=r*a,v=r*s,g=r*l;return t[0]=1-c-f,t[1]=u+g,t[2]=d-v,t[3]=0,t[4]=u-g,t[5]=1-h-f,t[6]=m+p,t[7]=0,t[8]=d+v,t[9]=m-p,t[10]=1-h-c,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}(function(){var t=new o(16);return o!=Float32Array&&(t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0),t[0]=1,t[5]=1,t[10]=1,t[15]=1,t}(),h);r(this.matrix,this.matrix,[0,0,-this.distance]),function(t,i,n){var o=i[0],e=i[1],r=i[2],a=i[3],s=i[4],l=i[5],h=i[6],u=i[7],c=i[8],d=i[9],m=i[10],f=i[11],p=i[12],v=i[13],g=i[14],y=i[15],A=n[0],P=n[1],x=n[2],z=n[3];t[0]=A*o+P*s+x*c+z*p,t[1]=A*e+P*l+x*d+z*v,t[2]=A*r+P*h+x*m+z*g,t[3]=A*a+P*u+x*f+z*y,t[4]=(A=n[4])*o+(P=n[5])*s+(x=n[6])*c+(z=n[7])*p,t[5]=A*e+P*l+x*d+z*v,t[6]=A*r+P*h+x*m+z*g,t[7]=A*a+P*u+x*f+z*y,t[8]=(A=n[8])*o+(P=n[9])*s+(x=n[10])*c+(z=n[11])*p,t[9]=A*e+P*l+x*d+z*v,t[10]=A*r+P*h+x*m+z*g,t[11]=A*a+P*u+x*f+z*y,t[12]=(A=n[12])*o+(P=n[13])*s+(x=n[14])*c+(z=n[15])*p,t[13]=A*e+P*l+x*d+z*v,t[14]=A*r+P*h+x*m+z*g,t[15]=A*a+P*u+x*f+z*y}(this.matrix,this.matrix,u),r(this.matrix,this.matrix,[0,0,this.distance])}else{if(Math.abs(this.elevation)>90)return this;this.computeMatrix()}return this._getAxes(),this.type===i.CameraType.ORBITING||this.type===i.CameraType.EXPLORING?this._getPosition():this.type===i.CameraType.TRACKING&&this._getFocalPoint(),this._update(),this},v.pan=function(t,n){var o=i.createVec3(t,n,0),e=s(this.position);return u(e,e,c(a(),this.right,o[0])),u(e,e,c(a(),this.up,o[1])),this._setPosition(e),this.triggerUpdate(),this},v.dolly=function(t){var n,o=this.forward,e=s(this.position);return e[0]+=(n=Math.max(Math.min(this.distance+t*this.dollyingStep,this.maxDistance),this.minDistance)-this.distance)*o[0],e[1]+=n*o[1],e[2]+=n*o[2],this._setPosition(e),this.type===i.CameraType.ORBITING||this.type===i.CameraType.EXPLORING?this._getDistance():this.type===i.CameraType.TRACKING&&u(this.focalPoint,e,this.distanceVector),this.triggerUpdate(),this},v.cancelLandmarkAnimation=function(){void 0!==this.landmarkAnimationID&&this.canvas.cancelAnimationFrame(this.landmarkAnimationID)},v.createLandmark=function(t,n){var o,r,a,l;void 0===n&&(n={});var h=n.position,u=void 0===h?this.position:h,c=n.focalPoint,d=void 0===c?this.focalPoint:c,m=n.roll,f=n.zoom,p=new i.runtime.CameraContribution;p.setType(this.type,void 0),p.setPosition(u[0],null!==(o=u[1])&&void 0!==o?o:this.position[1],null!==(r=u[2])&&void 0!==r?r:this.position[2]),p.setFocalPoint(d[0],null!==(a=d[1])&&void 0!==a?a:this.focalPoint[1],null!==(l=d[2])&&void 0!==l?l:this.focalPoint[2]),p.setRoll(null!=m?m:this.roll),p.setZoom(null!=f?f:this.zoom);var v={name:t,matrix:e(p.getWorldTransform()),right:s(p.right),up:s(p.up),forward:s(p.forward),position:s(p.getPosition()),focalPoint:s(p.getFocalPoint()),distanceVector:s(p.getDistanceVector()),distance:p.getDistance(),dollyingStep:p.getDollyingStep(),azimuth:p.getAzimuth(),elevation:p.getElevation(),roll:p.getRoll(),relAzimuth:p.relAzimuth,relElevation:p.relElevation,relRoll:p.relRoll,zoom:p.getZoom()};return this.landmarks.push(v),v},v.gotoLandmark=function(t,n){var o=this;void 0===n&&(n={});var e=b(t,"String")?this.landmarks.find((function(i){return i.name===t})):t;if(e){var r=b(n,"Number")?{duration:n}:n,s=r.easing,l=void 0===s?"linear":s,h=r.duration,u=void 0===h?100:h,c=r.easingFunction,d=void 0===c?void 0:c,f=r.onfinish,v=void 0===f?void 0:f;if(0===u)return this.syncFromLandmark(e),void(v&&v());this.cancelLandmarkAnimation();var g,y=e.position,A=e.focalPoint,P=e.zoom,x=e.roll,z=d||i.runtime.EasingFunction(l),F=function(){o.setFocalPoint(A),o.setPosition(y),o.setRoll(x),o.setZoom(P),o.computeMatrix(),o.triggerUpdate(),v&&v()};this.canvas.requestAnimationFrame((function t(i){void 0===g&&(g=i);var n=i-g;if(u<n)F();else{var e,r,s=z(n/u),l=a(),h=a();m(l,o.focalPoint,A,s),m(h,o.position,y,s),r=o.roll*(1-s)+x*s,e=o.zoom*(1-s)+P*s,o.setFocalPoint(l),o.setPosition(h),o.setRoll(r),o.setZoom(e),p(l,A)+p(h,y)>.01||null!=P||null!=x?(o.computeMatrix(),o.triggerUpdate(),u>n&&(o.landmarkAnimationID=o.canvas.requestAnimationFrame(t))):F()}}))}},v.syncFromLandmark=function(t){this.matrix=function(t,i){return t[0]=i[0],t[1]=i[1],t[2]=i[2],t[3]=i[3],t[4]=i[4],t[5]=i[5],t[6]=i[6],t[7]=i[7],t[8]=i[8],t[9]=i[9],t[10]=i[10],t[11]=i[11],t[12]=i[12],t[13]=i[13],t[14]=i[14],t[15]=i[15],t}(this.matrix,t.matrix),this.right=h(this.right,t.right),this.up=h(this.up,t.up),this.forward=h(this.forward,t.forward),this.position=h(this.position,t.position),this.focalPoint=h(this.focalPoint,t.focalPoint),this.distanceVector=h(this.distanceVector,t.distanceVector),this.azimuth=t.azimuth,this.elevation=t.elevation,this.roll=t.roll,this.relAzimuth=t.relAzimuth,this.relElevation=t.relElevation,this.relRoll=t.relRoll,this.dollyingStep=t.dollyingStep,this.distance=t.distance,this.zoom=t.zoom},f}(i.Camera);i.runtime.CameraContribution=k,t.AdvancedCamera=k,Object.defineProperty(t,"__esModule",{value:!0})})); |
{ | ||
"name": "@antv/g-camera-api", | ||
"version": "1.0.38", | ||
"version": "1.0.39", | ||
"description": "A simple implementation of Camera API.", | ||
@@ -44,3 +44,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "059286bbeff21a63e75a41811b89623c37f511f4" | ||
"gitHead": "b9efa0d349c3cb699065f407e45f6aa7e0a3336d" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
69566
1704