materials.js 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. var createScene = function () {
  2. var scene = new BABYLON.Scene(engine);
  3. //Create a light
  4. var light = new BABYLON.PointLight("Omni", new BABYLON.Vector3(-60, 60, 80), scene);
  5. //Create an Arc Rotate Camera - aimed negative z this time
  6. var camera = new BABYLON.ArcRotateCamera("Camera", Math.PI / 2, 1.0, 110, BABYLON.Vector3.Zero(), scene);
  7. camera.attachControl(canvas, true);
  8. //Creation of 6 spheres
  9. var sphere1 = BABYLON.Mesh.CreateSphere("Sphere1", 10.0, 9.0, scene);
  10. var sphere2 = BABYLON.Mesh.CreateSphere("Sphere2", 2.0, 9.0, scene);//Only two segments
  11. var sphere3 = BABYLON.Mesh.CreateSphere("Sphere3", 10.0, 9.0, scene);
  12. var sphere4 = BABYLON.Mesh.CreateSphere("Sphere4", 10.0, 9.0, scene);
  13. var sphere5 = BABYLON.Mesh.CreateSphere("Sphere5", 10.0, 9.0, scene);
  14. var sphere6 = BABYLON.Mesh.CreateSphere("Sphere6", 10.0, 9.0, scene);
  15. //Position the spheres
  16. sphere1.position.x = 40;
  17. sphere2.position.x = 25;
  18. sphere3.position.x = 10;
  19. sphere4.position.x = -5;
  20. sphere5.position.x = -20;
  21. sphere6.position.x = -35;
  22. //Creation of a plane
  23. var plane = BABYLON.Mesh.CreatePlane("plane", 120, scene);
  24. plane.position.y = -5;
  25. plane.rotation.x = Math.PI / 2;
  26. //Creation of a material with wireFrame
  27. var materialSphere1 = new BABYLON.StandardMaterial("texture1", scene);
  28. materialSphere1.wireframe = true;
  29. //Creation of a red material with alpha
  30. var materialSphere2 = new BABYLON.StandardMaterial("texture2", scene);
  31. materialSphere2.diffuseColor = new BABYLON.Color3(1, 0, 0); //Red
  32. materialSphere2.alpha = 0.3;
  33. //Creation of a material with an image texture
  34. var materialSphere3 = new BABYLON.StandardMaterial("texture3", scene);
  35. materialSphere3.diffuseTexture = new BABYLON.Texture("textures/misc.jpg", scene);
  36. //Creation of a material with translated texture
  37. var materialSphere4 = new BABYLON.StandardMaterial("texture4", scene);
  38. materialSphere4.diffuseTexture = new BABYLON.Texture("textures/misc.jpg", scene);
  39. materialSphere4.diffuseTexture.vOffset = 0.1;//Vertical offset of 10%
  40. materialSphere4.diffuseTexture.uOffset = 0.4;//Horizontal offset of 40%
  41. //Creation of a material with an alpha texture
  42. var materialSphere5 = new BABYLON.StandardMaterial("texture5", scene);
  43. materialSphere5.diffuseTexture = new BABYLON.Texture("textures/tree.png", scene);
  44. materialSphere5.diffuseTexture.hasAlpha = true;//Has an alpha
  45. //Creation of a material and show all the faces
  46. var materialSphere6 = new BABYLON.StandardMaterial("texture6", scene);
  47. materialSphere6.diffuseTexture = new BABYLON.Texture("textures/tree.png", scene);
  48. materialSphere6.diffuseTexture.hasAlpha = true;//Have an alpha
  49. materialSphere6.backFaceCulling = false;//Show all the faces of the element
  50. //Creation of a repeated textured material
  51. var materialPlane = new BABYLON.StandardMaterial("texturePlane", scene);
  52. materialPlane.diffuseTexture = new BABYLON.Texture("textures/grass.jpg", scene);
  53. materialPlane.diffuseTexture.uScale = 5.0;//Repeat 5 times on the Vertical Axes
  54. materialPlane.diffuseTexture.vScale = 5.0;//Repeat 5 times on the Horizontal Axes
  55. materialPlane.backFaceCulling = false;//Always show the front and the back of an element
  56. //Apply the materials to meshes
  57. sphere1.material = materialSphere1;
  58. sphere2.material = materialSphere2;
  59. sphere3.material = materialSphere3;
  60. sphere4.material = materialSphere4;
  61. sphere5.material = materialSphere5;
  62. sphere6.material = materialSphere6;
  63. plane.material = materialPlane;
  64. return scene;
  65. };