awacke1 commited on
Commit
b9204cd
1 Parent(s): c97e6a5

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +41 -19
index.html CHANGED
@@ -32,11 +32,18 @@
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
@@ -46,30 +53,45 @@
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
- }
 
 
 
 
 
 
 
 
 
 
 
 
62
 
63
- var scene = createScene();
64
 
65
- engine.runRenderLoop(function () {
66
- scene.render();
67
- });
68
 
69
- window.addEventListener('resize', function () {
70
- engine.resize();
71
- });
72
  });
73
- </script>
 
 
74
  </body>
75
  </html>
 
32
  // Create an array to hold the spheres
33
  var spheres = [];
34
 
35
+ // Load the texture and bump map
36
+ var texture = new BABYLON.Texture("https://www.babylonjs-playground.com/textures/floor.png", scene);
37
+ var bumpMap = new BABYLON.Texture("https://www.babylonjs-playground.com/textures/floor_n.jpg", scene);
38
+
39
  // Create a fountain of spheres that follow the mouse
40
  canvas.addEventListener('mousemove', function (event) {
41
  // Create a new sphere
42
+ var sphere = BABYLON.MeshBuilder.CreateSphere("sphere", {diameter: Math.random() * 2 + 0.5, segments: 16}, scene);
43
  sphere.position = new BABYLON.Vector3(Math.random() * 4 - 2, Math.random() * 4 - 2, Math.random() * 4 - 2);
44
+ sphere.material = new BABYLON.StandardMaterial("texture", scene);
45
+ sphere.material.diffuseTexture = texture;
46
+ sphere.material.bumpTexture = bumpMap;
47
  spheres.push(sphere);
48
 
49
  // Follow the mouse with the spheres
 
53
  sphere.position.copyFrom(pickInfo.pickedPoint);
54
  }
55
 
56
+ // Animate the texture of the spheres
57
+ var textureAnimation = new BABYLON.Animation("textureAnimation", "material.diffuseTexture.uOffset", 60, BABYLON.Animation.ANIMATIONTYPE_FLOAT, BABYLON.Animation.ANIMATIONLOOPMODE_CYCLE);
58
  var keys = [];
59
+ keys.push({frame: 0, value: 0});
60
+ keys.push({frame: 100, value: 1});
61
+ textureAnimation.setKeys(keys);
62
+ sphere.material.diffuseTexture.wrapU = BABYLON.Texture.WRAP_ADDRESSMODE;
63
+ sphere.material.diffuseTexture.wrapV = BABYLON.Texture.WRAP_ADDRESSMODE;
64
+ sphere.material.diffuseTexture.uScale = 10;
65
+ sphere.material.diffuseTexture.vScale = 10;
66
+ sphere.animations.push(textureAnimation);
67
  scene.beginAnimation(sphere, 0, 100, true);
 
68
 
69
+ // Animate the spheres
70
+ var animation = new BABYLON.Animation("myAnimation", "position.y", 30, BABYLON.Animation.ANIMATIONTYPE_FLOAT, BABYLON.Animation.ANIMATIONLOOPMODE_CYCLE);
71
+ var keys = [];
72
+ keys.push({frame: 0, value: sphere.position.y});
73
+ keys.push({frame: 50, value: sphere.position.y + 2});
74
+ keys.push({frame: 100, value: sphere.position.y});
75
+ animation.setKeys(keys);
76
+ sphere.animations.push(animation);
77
+ scene.beginAnimation(sphere, 0, 100, true);
78
+ });
79
+
80
+
81
+ return scene;
82
+ }
83
 
84
+ var scene = createScene();
85
 
86
+ engine.runRenderLoop(function () {
87
+ scene.render();
88
+ });
89
 
90
+ window.addEventListener('resize', function () {
91
+ engine.resize();
 
92
  });
93
+ });
94
+
95
+ </script>
96
  </body>
97
  </html>