rotation and scaling.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. var createScene = function () {
  2. var scene = new BABYLON.Scene(engine);
  3. var camera = new BABYLON.ArcRotateCamera("Camera", Math.PI, Math.PI / 8, 150, BABYLON.Vector3.Zero(), scene);
  4. camera.attachControl(canvas, true);
  5. var light = new BABYLON.HemisphericLight("hemi", new BABYLON.Vector3(0, 1, 0), scene);
  6. //Creation of 3 boxes and 2 spheres
  7. var box1 = BABYLON.Mesh.CreateBox("Box1", 6.0, scene);
  8. var box2 = BABYLON.Mesh.CreateBox("Box2", 6.0, scene);
  9. var box3 = BABYLON.Mesh.CreateBox("Box3", 6.0, scene);
  10. var box4 = BABYLON.Mesh.CreateBox("Box4", 6.0, scene);
  11. var box5 = BABYLON.Mesh.CreateBox("Box5", 6.0, scene);
  12. var box6 = BABYLON.Mesh.CreateBox("Box6", 6.0, scene);
  13. var box7 = BABYLON.Mesh.CreateBox("Box7", 6.0, scene);
  14. //Moving boxes on the x axis
  15. box1.position.x = -20;
  16. box2.position.x = -10;
  17. box3.position.x = 0;
  18. box4.position.x = 15;
  19. box5.position.x = 30;
  20. box6.position.x = 45;
  21. //Rotate box around the x axis
  22. box1.rotation.x = Math.PI / 6;
  23. //Rotate box around the y axis
  24. box2.rotation.y = Math.PI / 3;
  25. //Scaling on the x axis
  26. box4.scaling.x = 2;
  27. //Scaling on the y axis
  28. box5.scaling.y = 2;
  29. //Scaling on the z axis
  30. box6.scaling.z = 2;
  31. //Moving box7 relatively to box1
  32. box7.parent = box1;
  33. box7.position.z = -10;
  34. return scene;
  35. }