-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
135 lines (110 loc) · 3.85 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="http://cdn.babylonjs.com/babylon.max.js"></script>
<script src="https://cdn.babylonjs.com/gui/babylon.gui.min.js"></script>
<script src="meshloader.js"></script>
<script src="leap.js"></script>
<style>
#canvas {
width: 100%;
height: 80%;
}
</style>
</head>
<body>
<div id="info">
<h2>Dont Touch</h2>
<p >LeapJS Obj:</p><p id="leapobj"></p>
</div>
<canvas id="canvas"></canvas>
<script>
window.addEventListener('DOMContentLoaded', function() {
var leapobj = document.getElementById('leapobj');
var scene;
var canvas = document.getElementById('canvas');
var engine = new BABYLON.Engine(canvas, true);
var createScene = function() {
scene = new BABYLON.Scene(engine);
createCamera();
var light = new BABYLON.DirectionalLight("dir01", new BABYLON.Vector3(0, -0.5, -1.0), scene);
light.position = new BABYLON.Vector3(50, 250, 200);
light.shadowOrthoScale = 2.0;
CreateGround();
createBookshelf();
/*
BABYLON.SceneLoader.ImportMesh("Layer_0.001", "../models/book", "blank-book.babylon", scene, function(newMeshes) {
console.log("here");
var man = newMeshes[0];
man.position = new BABYLON.Vector3(0, 0, 0)
man.rotation.y = Math.PI;
man.scaling = new BABYLON.Vector3(10.0,10.0, 10.4);
console.log('man');
})
*/
return scene;
}
var createBookshelf = function() {
var book1 = loadbook(scene, -45);
var book2 = loadbook(scene, -40);
var book3 = loadbook(scene, -35);
var book4 = loadbook(scene, -30);
var book5 = loadbook(scene, -25);
var book6 = loadbook(scene, -20);
var book7 = loadbook(scene, -15);
var bookshelf = loadshelf(scene);
}
// Ground
var CreateGround = function() {
var ground = BABYLON.Mesh.CreateGround("ground", 1000, 1000, 1, scene, false);
var groundMaterial = new BABYLON.StandardMaterial("ground", scene);
groundMaterial.diffuseColor = new BABYLON.Color3(0.2, 0.2, 0.2);
groundMaterial.specularColor = new BABYLON.Color3(0, 0, 0);
ground.material = groundMaterial;
ground.receiveShadows = true;
}
var createCamera = function() {
if (navigator.getVRDisplays) {
camera = new BABYLON.WebVRFreeCamera("WebVRCamera", new BABYLON.Vector3(140, 50, -20), scene);
} else {
camera = new BABYLON.VRDeviceOrientationFreeCamera("WebVRCamera", new BABYLON.Vector3(170, 50, -20), scene);
}
camera.setTarget( new BABYLON.Vector3(0,21,0))
// Touch or click the rendering canvas to enter VR Mode
scene.onPointerDown = function() {
scene.onPointerDown = undefined
camera.attachControl(canvas, true);
};
};
var scene = createScene();
var sphere = BABYLON.Mesh.CreateSphere("sphere", 10.0, 10.0, scene);
var material = new BABYLON.StandardMaterial("mat", scene);
sphere.material = material;
material.diffuseColor = new BABYLON.Color3(1.5, 0, 0);
var alpha = 0;
sphere.scaling.y = 1.5;
sphere.position = new BABYLON.Vector3(-100, -100, -100);
var controller = Leap.loop({enableGestures:true}, function (frame) {
if (frame.hands.length > 0) {
leapobj.innerText = frame.hands[0].palmPosition;
var rightHand = 0;
var leftHand = 0;
if (frame.hands[0].type == "right") {
rightHand = frame.hands[0];
var move = rightHand.palmPosition;
sphere.position.z = move[0];
sphere.position.y = move[1] - 30;
sphere.position.x = move[2];
}
}
}
);
engine.runRenderLoop(function() {
scene.render();
});
});
</script>
</body>
</html>