set camera FOV as parameter

This commit is contained in:
2026-04-16 18:47:29 +03:00
parent 16d027b0e6
commit aa1fcb121f
3 changed files with 15 additions and 10 deletions
+6 -1
View File
@@ -27,15 +27,17 @@ THREE.Cache.enabled = true
const assetPath = '/asset/default/'; const assetPath = '/asset/default/';
const defaultLightIntensity = 11; const defaultLightIntensity = 11;
const defaultInteractionDistance = 10; const defaultInteractionDistance = 10;
const defaultCameraFov = 50;
const sceneScale = 1.33; const sceneScale = 1.33;
class GameEngine extends EventManager{ class GameEngine extends EventManager{
async initScene(){ async initScene(){
this.perspectiveCamera = new THREE.PerspectiveCamera(45, this.aspect, 0.001, 99); this.perspectiveCamera = new THREE.PerspectiveCamera(defaultCameraFov, this.aspect, 0.001, 399);
//this.perspectiveCamera.position.set(0, 0, 10); //this.perspectiveCamera.position.set(0, 0, 10);
this.camera = this.perspectiveCamera; this.camera = this.perspectiveCamera;
this.defaultCameraFov = defaultCameraFov;
this.frustumSize = 50; this.frustumSize = 50;
this.orthographicCamera = new THREE.OrthographicCamera( this.orthographicCamera = new THREE.OrthographicCamera(
@@ -371,6 +373,9 @@ class GameEngine extends EventManager{
} }
disposeXr(){ disposeXr(){
if (this.renderer.xr.isPresenting){
this.renderer.xr.getSession().end();
}
[this.xrController1, this.xrController2].forEach(c=>{ [this.xrController1, this.xrController2].forEach(c=>{
c.removeEventListener('select', this.xrHandlers.onSelect); c.removeEventListener('select', this.xrHandlers.onSelect);
c.removeEventListener('selectstart', this.xrHandlers.onControllerEvent); c.removeEventListener('selectstart', this.xrHandlers.onControllerEvent);
+6 -6
View File
@@ -81,9 +81,9 @@ class Hero{
this.size = engine.meshUtils.getBoundingBoxSize(bb); this.size = engine.meshUtils.getBoundingBoxSize(bb);
//console.log('Hero size is', this.size); //console.log('Hero size is', this.size);
this.cameraYBase = this.size.y / this.engine.scale; this.cameraYBase = this.size.y / this.engine.scale;
this.cameraZMin = 1 / this.engine.scale; this.cameraZMin = 0.25 / this.engine.scale;
this.cameraZMax = 12 / this.engine.scale; this.cameraZMax = 12 / this.engine.scale;
this.#cameraZ = this.cameraZDefault = 4 / this.engine.scale; this.#cameraZ = this.cameraZDefault = 2 / this.engine.scale;
// let center = getBoundingBoxCenterPoint(bb, io.object.position) // let center = getBoundingBoxCenterPoint(bb, io.object.position)
@@ -107,7 +107,7 @@ class Hero{
//this.characterController.setMaxSlopeClimbAngle(90 * Math.PI / 180); //this.characterController.setMaxSlopeClimbAngle(90 * Math.PI / 180);
// Automatically slide down on slopes smaller than 30 degrees. // Automatically slide down on slopes smaller than 30 degrees.
// this.characterController.setMinSlopeSlideAngle(30 * Math.PI / 180); // this.characterController.setMinSlopeSlideAngle(30 * Math.PI / 180);
// this.characterController.enableAutostep(0.5, 0.2, true); //this.characterController.enableAutostep(0.5, 0.002, true);
//this.characterController.setApplyImpulsesToDynamicBodies(true); //this.characterController.setApplyImpulsesToDynamicBodies(true);
// this.characterController.setCharacterMass(50); // this.characterController.setCharacterMass(50);
@@ -134,7 +134,7 @@ class Hero{
if (this.engine.renderer.xr.isPresenting && !this.fpv){ if (this.engine.renderer.xr.isPresenting && !this.fpv){
this.cameraMode = 'fixed' this.cameraMode = 'fixed'
this.engine.cameraRig.position.y = -this.engine.camera.position.y; this.engine.cameraRig.position.y = -this.engine.camera.position.y;
this.engine.dashboard.object.position.y = this.engine.camera.position.y; //this.engine.dashboard.object.position.y = this.engine.camera.position.y;
//this.cameraY = this.size.y * 1; //this.cameraY = this.size.y * 1;
//this.camera = this.engine.cameraWorld; //this.camera = this.engine.cameraWorld;
// this.engine.activeObjects.position.x = -this.camera.position.x; // this.engine.activeObjects.position.x = -this.camera.position.x;
@@ -143,7 +143,7 @@ class Hero{
this.cameraMode = 'rotate' this.cameraMode = 'rotate'
this.cameraDelta = 0; this.cameraDelta = 0;
this.engine.cameraRig.position.y = - this.engine.camera.position.y; this.engine.cameraRig.position.y = - this.engine.camera.position.y;
this.engine.dashboard.object.position.y = this.engine.camera.position.y; //this.engine.dashboard.object.position.y = this.engine.camera.position.y;
}else{ }else{
this.cameraMode = 'rotate' this.cameraMode = 'rotate'
this.engine.cameraRig.position.y = 0; this.engine.cameraRig.position.y = 0;
@@ -168,7 +168,7 @@ class Hero{
if (!this.fpv && !this.model.visible){ if (!this.fpv && !this.model.visible){
this.model.visible = true; this.model.visible = true;
this.#cameraZ = this.cameraZDefault; this.#cameraZ = this.cameraZDefault;
this.engine.camera.fov = 45; this.engine.camera.fov = this.engine.defaultCameraFov;
this.engine.camera.updateProjectionMatrix(); this.engine.camera.updateProjectionMatrix();
} }
let input = pc.input; let input = pc.input;
+3 -3
View File
@@ -204,9 +204,9 @@ function onMouseMove( event ) {
function onMouseWheel( event ){ function onMouseWheel( event ){
if (this.isLocked){ if (this.isLocked){
this.engine.camera.fov += event.deltaY / 100; this.engine.camera.fov += event.deltaY / 100;
this.engine.camera.fov = Math.min(Math.max(this.engine.camera.fov, 0.01), 45); this.engine.camera.fov = Math.min(Math.max(this.engine.camera.fov, 0.01), this.engine.defaultCameraFov);
this.engine.camera.updateProjectionMatrix(); this.engine.camera.updateProjectionMatrix();
if (this.engine.camera.fov >= 45){ if (this.engine.camera.fov >= this.engine.defaultCameraFov){
this.unlock(); this.unlock();
} }
this.engine.dashboard?.orient(); this.engine.dashboard?.orient();
@@ -221,7 +221,7 @@ function onPointerlockChange() {
this.isLocked = false; this.isLocked = false;
this.dispatchEvent( { type: 'unlock' } ); this.dispatchEvent( { type: 'unlock' } );
} }
this.engine.camera.fov = 45; this.engine.camera.fov = this.engine.defaultCameraFov;
this.engine.camera.updateProjectionMatrix(); this.engine.camera.updateProjectionMatrix();
this.engine.dashboard?.orient(); this.engine.dashboard?.orient();
//this.engine.cameraRig.rotation.y = this.isLocked ? 0 : Math.PI; //this.engine.cameraRig.rotation.y = this.isLocked ? 0 : Math.PI;