Ver código fonte

VR configuration extended
new Optional parameters:
Camera reposition, disable experimental rotation with controllers, and a new height compensation value for the model when in VR,

Raanan Weber 7 anos atrás
pai
commit
eebf6e4933

+ 3 - 0
Viewer/src/configuration/interfaces/vrConfiguration.ts

@@ -7,4 +7,7 @@ export interface IVRConfiguration {
     disableTeleportation?: boolean;
     overrideFloorMeshName?: string;
     vrOptions?: VRExperienceHelperOptions;
+    modelHeightCorrection?: number | boolean;
+    rotateUsingControllers?: boolean; // experimental feature
+    cameraPosition?: { x: number, y: number, z: number }
 }

+ 24 - 22
Viewer/src/managers/sceneManager.ts

@@ -812,31 +812,33 @@ export class SceneManager {
                 floorMeshName
             });
         }
-        let rotationOffset: Quaternion | null;
-        this._vrHelper.onControllerMeshLoadedObservable.add((controller) => {
-            controller.onTriggerStateChangedObservable.add((data) => {
-                if (controller.mesh && controller.mesh.rotationQuaternion) {
-                    if (data.pressed) {
-                        if (!rotationOffset) {
-                            this.models[0].rootMesh.rotationQuaternion = this.models[0].rootMesh.rotationQuaternion || new Quaternion();
-                            rotationOffset = controller.mesh.rotationQuaternion.conjugate().multiply(this.models[0].rootMesh.rotationQuaternion!);
+        if (vrConfig.rotateUsingControllers) {
+            let rotationOffset: Quaternion | null;
+            this._vrHelper.onControllerMeshLoadedObservable.add((controller) => {
+                controller.onTriggerStateChangedObservable.add((data) => {
+                    if (controller.mesh && controller.mesh.rotationQuaternion) {
+                        if (data.pressed) {
+                            if (!rotationOffset) {
+                                this.models[0].rootMesh.rotationQuaternion = this.models[0].rootMesh.rotationQuaternion || new Quaternion();
+                                rotationOffset = controller.mesh.rotationQuaternion.conjugate().multiply(this.models[0].rootMesh.rotationQuaternion!);
+                            }
+                        } else {
+                            rotationOffset = null;
                         }
-                    } else {
-                        rotationOffset = null;
-                    }
-                }
-            });
-            this.scene.registerBeforeRender(() => {
-                if (this.models[0]) {
-                    if (rotationOffset && controller.mesh && controller.mesh.rotationQuaternion) {
-                        this.models[0].rootMesh.rotationQuaternion!.copyFrom(controller.mesh.rotationQuaternion).multiplyInPlace(rotationOffset);
-                    } else {
-                        this.models[0].rootMesh.rotationQuaternion = null;
                     }
+                });
+                this.scene.registerBeforeRender(() => {
+                    if (this.models[0]) {
+                        if (rotationOffset && controller.mesh && controller.mesh.rotationQuaternion) {
+                            this.models[0].rootMesh.rotationQuaternion!.copyFrom(controller.mesh.rotationQuaternion).multiplyInPlace(rotationOffset);
+                        } else {
+                            this.models[0].rootMesh.rotationQuaternion = null;
+                        }
 
-                }
-            })
-        })
+                    }
+                });
+            });
+        }
         this.onVRConfiguredObservable.notifyObservers({
             sceneManager: this,
             object: this._vrHelper,

+ 14 - 7
Viewer/src/viewer/viewer.ts

@@ -1,7 +1,7 @@
 import { viewerManager } from './viewerManager';
 import { SceneManager } from '../managers/sceneManager';
 import { ConfigurationLoader } from '../configuration/loader';
-import { Effect, Observable, Engine, Scene, Database, SceneLoaderProgressEvent, ISceneLoaderPlugin, ISceneLoaderPluginAsync, Tools, RenderingManager, TargetCamera, WebVRFreeCamera } from 'babylonjs';
+import { Effect, Observable, Engine, Scene, Database, SceneLoaderProgressEvent, ISceneLoaderPlugin, ISceneLoaderPluginAsync, Tools, RenderingManager, TargetCamera, WebVRFreeCamera, Vector3 } from 'babylonjs';
 import { ViewerConfiguration, IObserversConfiguration, IModelConfiguration } from '../configuration/';
 
 import { ViewerModel } from '../model/viewerModel';
@@ -280,13 +280,20 @@ export abstract class AbstractViewer {
 
             // position the vr camera to be in front of the object
             if (this.sceneManager.vrHelper.currentVRCamera) {
-                this.sceneManager.vrHelper.currentVRCamera.position.copyFromFloats(0, this.sceneManager.vrHelper.currentVRCamera.position.y, -1);
+                if (this.configuration.vr && this.configuration.vr.cameraPosition !== undefined) {
+                    this.sceneManager.vrHelper.currentVRCamera.position.copyFrom(this.configuration.vr.cameraPosition as Vector3);
+                } else {
+                    this.sceneManager.vrHelper.currentVRCamera.position.copyFromFloats(0, this.sceneManager.vrHelper.currentVRCamera.position.y, -1);
+                }
                 (<TargetCamera>this.sceneManager.vrHelper.currentVRCamera).rotationQuaternion && (<TargetCamera>this.sceneManager.vrHelper.currentVRCamera).rotationQuaternion.copyFromFloats(0, 0, 0, 1);
-                this._vrModelRepositioning = this.sceneManager.vrHelper.currentVRCamera.position.y / 2;
-
-                // enable rotation using the axels
-                // check if the camera is a webvr camera
-                if (this.sceneManager.vrHelper.currentVRCamera.getClassName() === "WebVRFreeCamera") {
+                if (this.configuration.vr && this.configuration.vr.modelHeightCorrection !== undefined) {
+                    if (typeof this.configuration.vr.modelHeightCorrection === 'number') {
+                        this._vrModelRepositioning = this.configuration.vr.modelHeightCorrection
+                    } else if (this.configuration.vr.modelHeightCorrection) {
+                        this._vrModelRepositioning = this.sceneManager.vrHelper.currentVRCamera.position.y / 2;
+                    } else {
+                        this._vrModelRepositioning = 0;
+                    }
                 }
             } else {
                 this._vrModelRepositioning = 0;