ソースを参照

Adding default lightning on VR controllers

davrous 8 年 前
コミット
9100deea1e

ファイルの差分が大きいため隠しています
+ 30 - 29
dist/preview release/babylon.core.js


ファイルの差分が大きいため隠しています
+ 3427 - 3425
dist/preview release/babylon.d.ts


ファイルの差分が大きいため隠しています
+ 42 - 40
dist/preview release/babylon.js


ファイルの差分が大きいため隠しています
+ 23 - 5
dist/preview release/babylon.max.js


ファイルの差分が大きいため隠しています
+ 3427 - 3425
dist/preview release/babylon.module.d.ts


ファイルの差分が大きいため隠しています
+ 40 - 39
dist/preview release/babylon.noworker.js


+ 16 - 1
src/Cameras/VR/babylon.webVRCamera.ts

@@ -35,6 +35,7 @@ module BABYLON {
         positionScale?: number;
         displayName?: string; //if there are more than one VRDisplays.
         controllerMeshes?: boolean; // should the native controller meshes be initialized
+        defaultLightningOnControllers?: boolean; // creating a default HemiLight only on controllers
     }
 
     export class WebVRFreeCamera extends FreeCamera implements PoseControlled {
@@ -63,6 +64,8 @@ module BABYLON {
 
         public rigParenting: boolean = true; // should the rig cameras be used as parent instead of this camera.
 
+        private _lightOnControllers: BABYLON.HemisphericLight;
+
         constructor(name: string, position: Vector3, scene: Scene, private webVROptions: WebVROptions = {}) {
             super(name, position, scene);
 
@@ -78,6 +81,9 @@ module BABYLON {
             if (this.webVROptions.controllerMeshes == undefined) {
                 this.webVROptions.controllerMeshes = true;
             }
+            if (this.webVROptions.defaultLightningOnControllers == undefined) {
+                this.webVROptions.defaultLightningOnControllers = true;
+            }
 
             this.rotationQuaternion = new Quaternion();
             this.deviceRotationQuaternion = new Quaternion();
@@ -298,7 +304,16 @@ module BABYLON {
                 if (gp.type === BABYLON.Gamepad.POSE_ENABLED) {
                     let webVrController: WebVRController = <WebVRController>gp;
                     if (this.webVROptions.controllerMeshes) {
-                        webVrController.initControllerMesh(this.getScene());
+                        webVrController.initControllerMesh(this.getScene(), (loadedMesh) => {
+                            if (this.webVROptions.defaultLightningOnControllers) {
+                                if (!this._lightOnControllers) {
+                                    this._lightOnControllers = new BABYLON.HemisphericLight("vrControllersLight", new BABYLON.Vector3(0, 1, 0), this.getScene());
+                                }
+                                loadedMesh.getChildren().forEach((mesh) => {
+                                    this._lightOnControllers.includedOnlyMeshes.push(<AbstractMesh>mesh);
+                                });
+                            }
+                        });
                     }
                     webVrController.attachToPoseControlledCamera(this);
 

+ 9 - 3
src/Tools/babylon.extendedGamepad.ts

@@ -205,7 +205,7 @@ module BABYLON {
 
         protected abstract handleButtonChange(buttonIdx: number, value: ExtendedGamepadButton, changes: GamepadButtonChanges);
 
-        public abstract initControllerMesh(scene: Scene)
+        public abstract initControllerMesh(scene: Scene, meshLoaded?: (mesh: AbstractMesh) => void)
 
         private _setButtonValue(newState: ExtendedGamepadButton, currentState: ExtendedGamepadButton, buttonIndex: number) {
             if (!currentState) {
@@ -259,7 +259,7 @@ module BABYLON {
             this.controllerType = PoseEnabledControllerType.OCULUS;
         }
 
-        public initControllerMesh(scene: Scene) {
+        public initControllerMesh(scene: Scene, meshLoaded?: (mesh: AbstractMesh) => void) {
             let meshName = this.hand === 'right' ? 'RightTouch.babylon' : 'LeftTouch.babylon';
             SceneLoader.ImportMesh("", "http://yoda.blob.core.windows.net/models/", meshName, scene, (newMeshes) => {
                 /*
@@ -276,6 +276,9 @@ module BABYLON {
                 this._defaultModel = newMeshes[1];
                 this._hlButtonA = new BABYLON.HighlightLayer("hlButtonA", scene);
                 this._hlButtonB = new BABYLON.HighlightLayer("hlButtonB", scene);
+                if (meshLoaded) {
+                    meshLoaded(this._defaultModel);
+                }
                 this.attachToMesh(this._defaultModel);
             });
         }
@@ -393,7 +396,7 @@ module BABYLON {
             this.controllerType = PoseEnabledControllerType.VIVE;
         }
 
-        public initControllerMesh(scene: Scene) {
+        public initControllerMesh(scene: Scene, meshLoaded?: (mesh: AbstractMesh) => void) {
             SceneLoader.ImportMesh("", "http://yoda.blob.core.windows.net/models/", "ViveWand.babylon", scene, (newMeshes) => {
                 /*
                 Parent Mesh name: ViveWand
@@ -408,6 +411,9 @@ module BABYLON {
                 */
                 this._defaultModel = newMeshes[1];
                 this._hlButtonMenu = new BABYLON.HighlightLayer("hlButtonMenu", scene);
+                if (meshLoaded) {
+                    meshLoaded(this._defaultModel);
+                }
                 this.attachToMesh(this._defaultModel);
             });
         }