You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
76 lines
2.7 KiB
76 lines
2.7 KiB
|
4 months ago
|
"use strict";
|
||
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||
|
|
exports.CameraSetting = void 0;
|
||
|
|
const constants_1 = require("../constants");
|
||
|
|
const base_plugin_1 = require("./base-plugin");
|
||
|
|
/**
|
||
|
|
* <zh/> 配置相机参数
|
||
|
|
*
|
||
|
|
* <en/> Configure camera parameters
|
||
|
|
*/
|
||
|
|
class CameraSetting extends base_plugin_1.BasePlugin {
|
||
|
|
constructor(context, options) {
|
||
|
|
super(context, options);
|
||
|
|
this.setOptions = (options) => {
|
||
|
|
const caller = {
|
||
|
|
cameraType: 'setType',
|
||
|
|
near: 'setNear',
|
||
|
|
far: 'setFar',
|
||
|
|
fov: 'setFov',
|
||
|
|
aspect: 'setAspect',
|
||
|
|
// 确保 projectionMode 在 near/far/fov/aspect 之后设置
|
||
|
|
// Ensure that projectionMode is set after near/far/fov/aspect
|
||
|
|
projectionMode: 'setProjectionMode',
|
||
|
|
distance: 'setDistance',
|
||
|
|
minDistance: 'setMinDistance',
|
||
|
|
maxDistance: 'setMaxDistance',
|
||
|
|
roll: 'setRoll',
|
||
|
|
elevation: 'setElevation',
|
||
|
|
azimuth: 'setAzimuth',
|
||
|
|
};
|
||
|
|
const valueMapper = (key, value) => {
|
||
|
|
switch (key) {
|
||
|
|
case 'projectionMode':
|
||
|
|
return value === 'perspective' ? 1 : 0;
|
||
|
|
case 'cameraType':
|
||
|
|
return { orbiting: 0, exploring: 1, tracking: 2 }[value];
|
||
|
|
case 'aspect':
|
||
|
|
if (typeof value === 'number')
|
||
|
|
return value;
|
||
|
|
return this.getCanvasAspect();
|
||
|
|
default:
|
||
|
|
return value;
|
||
|
|
}
|
||
|
|
};
|
||
|
|
Object.entries(caller).forEach(([key, method]) => {
|
||
|
|
const value = options[key];
|
||
|
|
if (value !== undefined) {
|
||
|
|
const actualValue = valueMapper(key, value);
|
||
|
|
// @ts-expect-error incorrect ts type check
|
||
|
|
this.context.canvas.getCamera()[method](actualValue);
|
||
|
|
}
|
||
|
|
});
|
||
|
|
};
|
||
|
|
this.bindEvents();
|
||
|
|
}
|
||
|
|
/**
|
||
|
|
* <zh/> 更新相机参数
|
||
|
|
*
|
||
|
|
* <en/> Update camera parameters
|
||
|
|
* @param options - <zh/> 相机配置项 | <en/> Camera configuration options
|
||
|
|
* @internal
|
||
|
|
*/
|
||
|
|
update(options) {
|
||
|
|
this.setOptions(options);
|
||
|
|
super.update(options);
|
||
|
|
}
|
||
|
|
bindEvents() {
|
||
|
|
this.context.graph.once(constants_1.GraphEvent.BEFORE_DRAW, () => this.setOptions(this.options));
|
||
|
|
}
|
||
|
|
getCanvasAspect() {
|
||
|
|
const [width, height] = this.context.viewport.getCanvasSize();
|
||
|
|
return width / height;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
exports.CameraSetting = CameraSetting;
|
||
|
|
//# sourceMappingURL=camera-setting.js.map
|