Update index.html
Browse files- index.html +25 -14
index.html
CHANGED
|
@@ -29,22 +29,33 @@
|
|
| 29 |
// Create a light
|
| 30 |
var light = new BABYLON.HemisphericLight("light1", new BABYLON.Vector3(0, 1, 0), scene);
|
| 31 |
|
| 32 |
-
// Create
|
| 33 |
-
var
|
| 34 |
|
| 35 |
-
//
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
|
|
|
|
|
|
| 39 |
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
return scene;
|
| 50 |
}
|
|
|
|
| 29 |
// Create a light
|
| 30 |
var light = new BABYLON.HemisphericLight("light1", new BABYLON.Vector3(0, 1, 0), scene);
|
| 31 |
|
| 32 |
+
// Create an array to hold the spheres
|
| 33 |
+
var spheres = [];
|
| 34 |
|
| 35 |
+
// Create a fountain of spheres that follow the mouse
|
| 36 |
+
canvas.addEventListener('mousemove', function (event) {
|
| 37 |
+
// Create a new sphere
|
| 38 |
+
var sphere = BABYLON.MeshBuilder.CreateSphere("sphere", {diameter: Math.random() * 2 + 0.5}, scene);
|
| 39 |
+
sphere.position = new BABYLON.Vector3(Math.random() * 4 - 2, Math.random() * 4 - 2, Math.random() * 4 - 2);
|
| 40 |
+
spheres.push(sphere);
|
| 41 |
|
| 42 |
+
// Follow the mouse with the spheres
|
| 43 |
+
var ray = scene.createPickingRay(event.clientX, event.clientY, BABYLON.Matrix.Identity(), camera);
|
| 44 |
+
var pickInfo = scene.pickWithRay(ray, function (mesh) { return mesh == sphere; });
|
| 45 |
+
if (pickInfo.hit) {
|
| 46 |
+
sphere.position.copyFrom(pickInfo.pickedPoint);
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
// Animate the spheres
|
| 50 |
+
var animation = new BABYLON.Animation("myAnimation", "position.y", 30, BABYLON.Animation.ANIMATIONTYPE_FLOAT, BABYLON.Animation.ANIMATIONLOOPMODE_CYCLE);
|
| 51 |
+
var keys = [];
|
| 52 |
+
keys.push({frame: 0, value: sphere.position.y});
|
| 53 |
+
keys.push({frame: 50, value: sphere.position.y + 2});
|
| 54 |
+
keys.push({frame: 100, value: sphere.position.y});
|
| 55 |
+
animation.setKeys(keys);
|
| 56 |
+
sphere.animations.push(animation);
|
| 57 |
+
scene.beginAnimation(sphere, 0, 100, true);
|
| 58 |
+
});
|
| 59 |
|
| 60 |
return scene;
|
| 61 |
}
|