awacke1 commited on
Commit
2ccc80c
·
1 Parent(s): aa537f9

Update index.html

Browse files
Files changed (1) hide show
  1. 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 a sphere
33
- var sphere = BABYLON.MeshBuilder.CreateSphere("sphere", {diameter: 2}, scene);
34
 
35
- // Add some texture to the sphere
36
- var material = new BABYLON.StandardMaterial("texture", scene);
37
- material.diffuseTexture = new BABYLON.Texture("https://www.babylonjs-playground.com/textures/grass.jpg", scene);
38
- sphere.material = material;
 
 
39
 
40
- // Animate the sphere
41
- var animation = new BABYLON.Animation("myAnimation", "position.x", 30, BABYLON.Animation.ANIMATIONTYPE_FLOAT, BABYLON.Animation.ANIMATIONLOOPMODE_CYCLE);
42
- var keys = [];
43
- keys.push({frame: 0, value: 0});
44
- keys.push({frame: 100, value: 10});
45
- animation.setKeys(keys);
46
- sphere.animations.push(animation);
47
- scene.beginAnimation(sphere, 0, 100, true);
 
 
 
 
 
 
 
 
 
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
  }