Bladeren bron

treat oculus go as gearVR controller and position it where a persons hand would be

Trevor Baron 7 jaren geleden
bovenliggende
commit
85decdfccc

+ 67 - 28
Playground/scripts/webvr.js

@@ -1,35 +1,74 @@
-var createScene = function () {
+var createScene = function() {
+    // Create scene
+	var scene = new BABYLON.Scene(engine);
 
-    // This creates a basic Babylon Scene object (non-mesh)
-    var scene = new BABYLON.Scene(engine);
-    scene.createDefaultVRExperience();
+    // Create simple sphere
+    var sphere = BABYLON.Mesh.CreateIcoSphere("sphere", {radius:0.2, flat:true, subdivisions: 1}, this.scene);
+    sphere.position.y = 3;
+    sphere.material = new BABYLON.StandardMaterial("sphere material",scene)
 
-    // This creates a light, aiming 0,1,0 - to the sky (non-mesh)
-    var light = new BABYLON.HemisphericLight("light1", new BABYLON.Vector3(0, 1, 0), scene);
+    // Lights and camera
+    var light = new BABYLON.DirectionalLight("light", new BABYLON.Vector3(0, -0.5, 1.0), scene);
+    light.position = new BABYLON.Vector3(0, 5, -2);
+    var camera = new BABYLON.ArcRotateCamera("camera", -Math.PI / 2, Math.PI / 4, 3, new BABYLON.Vector3(0, 3, 0), scene);
+    camera.attachControl(canvas, true);
+    scene.activeCamera.beta += 0.8;
 
-    // Default intensity is 1. Let's dim the light a small amount
-    light.intensity = 0.7;
+    // Default Environment
+    var environment = scene.createDefaultEnvironment({ enableGroundShadow: true, groundYBias: 1 });
+    environment.setMainColor(BABYLON.Color3.FromHexString("#74b9ff"))
+    
+    // Shadows
+    var shadowGenerator = new BABYLON.ShadowGenerator(1024, light);
+    shadowGenerator.useBlurExponentialShadowMap = true;
+    shadowGenerator.blurKernel = 32;
+    shadowGenerator.addShadowCaster(sphere, true);
 
-    // Create some spheres at the default eye level (2m)
-    createSphereBox(scene, 2, 2);
-    createSphereBox(scene, 3, 2);
-        
-    // Our built-in 'ground' shape. Params: name, width, depth, subdivs, scene
-    var ground = BABYLON.Mesh.CreateGround("ground1", 6, 6, 2, scene);
+    // Enable VR
+    var vrHelper = scene.createDefaultVRExperience({createDeviceOrientationCamera:false});
+    vrHelper.enableTeleportation({floorMeshes: [environment.ground]});
 
-    return scene;
+    // Runs every frame to rotate the sphere
+    scene.onBeforeRenderObservable.add(()=>{
+        sphere.rotation.y += 0.0001*scene.getEngine().getDeltaTime();
+        sphere.rotation.x += 0.0001*scene.getEngine().getDeltaTime();
+    })
+
+    // GUI
+    var plane = BABYLON.Mesh.CreatePlane("plane", 1);
+    plane.position = new BABYLON.Vector3(0.4, 4, 0.4)
+    var advancedTexture = BABYLON.GUI.AdvancedDynamicTexture.CreateForMesh(plane);
+    var panel = new BABYLON.GUI.StackPanel();    
+    advancedTexture.addControl(panel);  
+    var header = new BABYLON.GUI.TextBlock();
+    header.text = "Color GUI";
+    header.height = "100px";
+    header.color = "white";
+    header.textHorizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_CENTER;
+    header.fontSize = "120"
+    panel.addControl(header); 
+    var picker = new BABYLON.GUI.ColorPicker();
+    picker.value = sphere.material.diffuseColor;
+    picker.horizontalAlignment = BABYLON.GUI.Control.HORIZONTAL_ALIGNMENT_CENTER;
+    picker.height = "350px";
+    picker.width = "350px";
+    picker.onValueChangedObservable.add(function(value) {
+        sphere.material.diffuseColor.copyFrom(value);
+    });
+    panel.addControl(picker);
+    
+	return scene;
 };
 
-function createSphereBox(scene, distance, height) {    
-    createSphere(scene,  distance, height,  distance);
-    createSphere(scene,  distance, height, -distance);
-    createSphere(scene, -distance, height,  distance);
-    createSphere(scene, -distance, height, -distance);    
-}
-function createSphere(scene, x, y, z) {
-    // Our built-in 'sphere' shape. Params: name, subdivs, size, scene
-    var sphere = BABYLON.Mesh.CreateSphere("sphere1", 4, 0.4, scene);
-    sphere.position.x = x;
-    sphere.position.y = y;
-    sphere.position.z = z;
-}
+var colors = {
+        seaFoam: BABYLON.Color3.FromHexString("#16a085"),
+        green: BABYLON.Color3.FromHexString("#27ae60"),
+        blue: BABYLON.Color3.FromHexString("#2980b9"),
+        purple: BABYLON.Color3.FromHexString("#8e44ad"),
+        navy: BABYLON.Color3.FromHexString("#2c3e50"),
+        yellow: BABYLON.Color3.FromHexString("#f39c12"),
+        orange: BABYLON.Color3.FromHexString("#d35400"),
+        red: BABYLON.Color3.FromHexString("#c0392b"),
+        white: BABYLON.Color3.FromHexString("#bdc3c7"),
+        gray: BABYLON.Color3.FromHexString("#7f8c8d")
+    }

+ 2 - 0
src/Gamepad/Controllers/babylon.gearVRController.ts

@@ -29,6 +29,8 @@ module BABYLON {
         constructor(vrGamepad: any) {
             super(vrGamepad);
             this.controllerType = PoseEnabledControllerType.GEAR_VR;
+            // Initial starting position defaults to where hand would be (incase of only 3dof controller)
+            this._calculatedPosition = new Vector3(this.hand == "left" ? -0.15 : 0.15,-0.5, 0.4)
         }
 
         /**

+ 3 - 3
src/Gamepad/Controllers/babylon.poseEnabledController.ts

@@ -88,8 +88,8 @@ module BABYLON {
             else if (vrGamepad.id.toLowerCase().indexOf('openvr') !== -1) {
                 return new ViveController(vrGamepad);
             }
-            // Samsung/Oculus Gear VR
-            else if (vrGamepad.id.indexOf(GearVRController.GAMEPAD_ID_PREFIX) === 0) {
+            // Samsung/Oculus Gear VR or Oculus Go
+            else if (vrGamepad.id.indexOf(GearVRController.GAMEPAD_ID_PREFIX) === 0 || vrGamepad.id.indexOf('Oculus Go') !== -1) {
                 return new GearVRController(vrGamepad);
             }
             // Google Daydream
@@ -137,7 +137,7 @@ module BABYLON {
          */
         public controllerType: PoseEnabledControllerType;
 
-        private _calculatedPosition: Vector3;
+        protected _calculatedPosition: Vector3;
         private _calculatedRotation: Quaternion;
 
         /**