awacke1 commited on
Commit
17eef08
·
1 Parent(s): ab110b8

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +37 -9
index.html CHANGED
@@ -39,28 +39,56 @@
39
  sphere.material = new BABYLON.StandardMaterial("texture", scene);
40
  sphere.material.diffuseTexture = texture;
41
  sphere.material.bumpTexture = bumpMap;
42
- const textureAnimation = new BABYLON.Animation("textureAnimation", "material.diffuseTexture.uOffset", 60, BABYLON.Animation.ANIMATIONTYPE_FLOAT, BABYLON.Animation.ANIMATIONLOOPMODE_CYCLE, true);
43
  textureAnimation.setKeys([{ frame: 0, value: 0 }, { frame: 100, value: 1 }]);
44
  sphere.material.diffuseTexture.wrapU = sphere.material.diffuseTexture.wrapV = BABYLON.Texture.WRAP_ADDRESSMODE;
45
  sphere.material.diffuseTexture.uScale = sphere.material.diffuseTexture.vScale = 10;
46
  sphere.animations.push(textureAnimation);
47
  scene.beginAnimation(sphere, 0, 100, true);
48
- const animation = new BABYLON.Animation("myAnimation", "position", 30, BABYLON.Animation.ANIMATIONTYPE_VECTOR3, BABYLON.Animation.ANIMATIONLOOPMODE_CYCLE, true);
49
  animation.setKeys([{ frame: 0, value: position.clone() }, { frame: 100, value: position.addInPlace(direction.scale(length)).clone() }]);
50
  sphere.animations.push(animation);
51
  scene.beginAnimation(sphere, 0, 100, true);
52
  } else if (char === "+") {
53
- direction.rotateByQuaternionToRef(BABYLON.Quaternion.RotationAxis(BABYLON.Vector3.Up(), -angle), direction);
54
  } else if (char === "-") {
55
  direction.rotateByQuaternionToRef(BABYLON.Quaternion.RotationAxis(BABYLON.Vector3.Up(), angle), direction);
56
  }
57
  }
58
- return scene;
59
- };
60
- const scene = createScene();
61
- engine.runRenderLoop(() => scene.render());
62
- window.addEventListener('resize', () => engine.resize());
63
- </script>
64
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  </body>
66
  </html>
 
 
 
 
39
  sphere.material = new BABYLON.StandardMaterial("texture", scene);
40
  sphere.material.diffuseTexture = texture;
41
  sphere.material.bumpTexture = bumpMap;
42
+ const textureAnimation = new BABYLON.Animation("textureAnimation", "material.diffuseTexture.uOffset", 60, BABYLON.Animation.ANIMATIONTYPE_FLOAT, BABYLON.Animation.ANIMATIONLOOPMODE_CYCLE);
43
  textureAnimation.setKeys([{ frame: 0, value: 0 }, { frame: 100, value: 1 }]);
44
  sphere.material.diffuseTexture.wrapU = sphere.material.diffuseTexture.wrapV = BABYLON.Texture.WRAP_ADDRESSMODE;
45
  sphere.material.diffuseTexture.uScale = sphere.material.diffuseTexture.vScale = 10;
46
  sphere.animations.push(textureAnimation);
47
  scene.beginAnimation(sphere, 0, 100, true);
48
+ const animation = new BABYLON.Animation("myAnimation", "position", 30, BABYLON.Animation.ANIMATIONTYPE_VECTOR3, BABYLON.Animation.ANIMATIONLOOPMODE_CYCLE);
49
  animation.setKeys([{ frame: 0, value: position.clone() }, { frame: 100, value: position.addInPlace(direction.scale(length)).clone() }]);
50
  sphere.animations.push(animation);
51
  scene.beginAnimation(sphere, 0, 100, true);
52
  } else if (char === "+") {
53
+ direction.rotateByQuaternionToref(BABYLON.Quaternion.RotationAxis(BABYLON.Vector3.Up(), -angle), direction);
54
  } else if (char === "-") {
55
  direction.rotateByQuaternionToRef(BABYLON.Quaternion.RotationAxis(BABYLON.Vector3.Up(), angle), direction);
56
  }
57
  }
 
 
 
 
 
 
58
 
59
+ // Add the 3D animation
60
+ const animate = () => {
61
+ const sphere = BABYLON.MeshBuilder.CreateSphere("animationSphere", { diameter: 1 }, scene);
62
+ sphere.position = new BABYLON.Vector3(0, 0, 0);
63
+ sphere.material = new BABYLON.StandardMaterial("animationMaterial", scene);
64
+ sphere.material.diffuseColor = new BABYLON.Color3(1, 0, 0);
65
+
66
+ const animation = new BABYLON.Animation(
67
+ "sphereAnimation",
68
+ "position.y",
69
+ 30,
70
+ BABYLON.Animation.ANIMATIONTYPE_FLOAT,
71
+ BABYLON.Animation.ANIMATIONLOOPMODE_CYCLE
72
+ );
73
+ const keys = [];
74
+ keys.push({ frame: 0, value: 0 });
75
+ keys.push({ frame: 50, value: 2 });
76
+ keys.push({ frame: 100, value: 0 });
77
+ animation.setKeys(keys);
78
+ sphere.animations.push(animation);
79
+
80
+ scene.beginAnimation(sphere, 0, 100, true);
81
+ };
82
+ animate();
83
+
84
+ return scene;
85
+ };
86
+ const scene = createScene();
87
+ engine.runRenderLoop(() => scene.render());
88
+ window.addEventListener('resize', () => engine.resize());
89
+ </script>
90
  </body>
91
  </html>
92
+
93
+
94
+