只取这个模块
modules/camera/FirstPersonCameraRig.js连同其内部依赖一并复制,保留相对目录结构。
相机机位
three自动行驶展示,无需操作。
源码
import { BaseCameraRig, CAMERA_HEIGHT_SOURCES, CAMERA_ROTATION_MODES } from './BaseCameraRig.js';
import { toVec3 } from '../math/Vector3Utils.js';
import { DEFAULT_WORLD_BASIS } from '../math/WorldBasis.js';
export class FirstPersonCameraRig extends BaseCameraRig {
constructor({
eyeHeight = 1.72,
lookDistance = 1,
heightVectorSource = CAMERA_HEIGHT_SOURCES.frameUp,
basis = DEFAULT_WORLD_BASIS,
}) {
super({ basis, rotationMode: CAMERA_ROTATION_MODES.lookAt });
this.eyeHeight = eyeHeight;
this.lookDistance = lookDistance;
this.heightVectorSource = heightVectorSource;
}
step({
targetPosition,
targetFrame,
camera = null,
}) {
const frame = this.resolveTargetFrame(targetFrame);
const heightVector = this.vectorFromSource(this.heightVectorSource, frame);
const position = toVec3(targetPosition)
.addScaledVector(heightVector, this.eyeHeight);
this.setLookAtPose({
position,
lookAt: position.clone().addScaledVector(frame.forward, this.lookDistance),
up: frame.up,
});
const pose = this.getPose();
this.applyToCamera(camera, pose);
return pose;
}
}