index.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /// <reference path="../../dist/preview release/babylon.d.ts"/>
  2. var scramble = function(data) {
  3. for (index = 0; index < data.length; index ++) {
  4. data[index] += 0.1 * Math.random();
  5. }
  6. }
  7. // Playground like creation of the scene
  8. var createScene = function () {
  9. // This creates a basic Babylon Scene object (non-mesh)
  10. var scene = new BABYLON.Scene(engine);
  11. // This creates and positions a free camera (non-mesh)
  12. var camera = new BABYLON.ArcRotateCamera("camera1", 1.14, 1.13, 10, BABYLON.Vector3.Zero(), scene);
  13. // This targets the camera to scene origin
  14. camera.setTarget(BABYLON.Vector3.Zero());
  15. // This attaches the camera to the canvas
  16. camera.attachControl(canvas, true);
  17. // This creates a light, aiming 0,1,0 - to the sky (non-mesh)
  18. var light = new BABYLON.HemisphericLight("light1", new BABYLON.Vector3(0, 1, 0), scene);
  19. // Default intensity is 1. Let's dim the light a small amount
  20. light.intensity = 0.7;
  21. // Our built-in 'sphere' shape. Params: name, subdivs, size, scene
  22. var sphere = BABYLON.Mesh.CreateSphere("sphere1", 16, 2, scene);
  23. var sphere2 = BABYLON.Mesh.CreateSphere("sphere2", 16, 2, scene);
  24. sphere2.setEnabled(false);
  25. sphere2.updateMeshPositions(scramble);
  26. var sphere3 = BABYLON.Mesh.CreateSphere("sphere3", 16, 2, scene);
  27. sphere3.setEnabled(false);
  28. sphere3.scaling = new BABYLON.Vector3(2.1, 3.5, 1.0);
  29. sphere3.bakeCurrentTransformIntoVertices();
  30. var sphere4 = BABYLON.Mesh.CreateSphere("sphere4", 16, 2, scene);
  31. sphere4.setEnabled(false);
  32. sphere4.updateMeshPositions(scramble);
  33. var sphere5 = BABYLON.Mesh.CreateSphere("sphere5", 16, 2, scene);
  34. sphere5.setEnabled(false);
  35. sphere5.scaling = new BABYLON.Vector3(1.0, 0.1, 1.0);
  36. sphere5.bakeCurrentTransformIntoVertices();
  37. var manager = new BABYLON.MorphTargetManager();
  38. sphere.morphTargetManager = manager;
  39. var target0 = BABYLON.MorphTarget.FromMesh(sphere2, "sphere2", 0.25);
  40. manager.addTarget(target0);
  41. var target1 = BABYLON.MorphTarget.FromMesh(sphere3, "sphere3", 0.25);
  42. manager.addTarget(target1);
  43. var target2 = BABYLON.MorphTarget.FromMesh(sphere4, "sphere4", 0.25);
  44. manager.addTarget(target2);
  45. var target3 = BABYLON.MorphTarget.FromMesh(sphere5, "sphere5", 0.25);
  46. manager.addTarget(target3);
  47. var gui = new dat.GUI();
  48. var options = {
  49. influence0: 0.25,
  50. influence1: 0.25,
  51. influence2: 0.25,
  52. influence3: 0.25,
  53. }
  54. gui.add(options, "influence0", 0, 1).onChange(function(value) {
  55. target0.influence = value;
  56. });
  57. gui.add(options, "influence1", 0, 1).onChange(function(value) {
  58. target1.influence = value;
  59. });
  60. gui.add(options, "influence2", 0, 1).onChange(function(value) {
  61. target2.influence = value;
  62. });
  63. gui.add(options, "influence3", 0, 1).onChange(function(value) {
  64. target3.influence = value;
  65. });
  66. var button = { switch:function(){
  67. if (sphere.morphTargetManager) {
  68. sphere.morphTargetManager = null;
  69. } else {
  70. sphere.morphTargetManager = manager;
  71. }
  72. }};
  73. gui.add(button,'switch');
  74. var disposeButton = { dispose:function(){
  75. sphere.dispose();
  76. }};
  77. gui.add(disposeButton,'dispose');
  78. var removeButton = { removeLast:function(){
  79. manager.removeTarget(target3);
  80. }};
  81. gui.add(removeButton,'removeLast');
  82. return scene;
  83. };