geodesicBuilder.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import { CreatePolyhedron } from "./polyhedronBuilder.js";
  2. import { Logger } from "../../Misc/logger.js";
  3. import { _PrimaryIsoTriangle, GeodesicData } from "../geodesicMesh.js";
  4. /**
  5. * Creates the Mesh for a Geodesic Polyhedron
  6. * @see https://en.wikipedia.org/wiki/Geodesic_polyhedron
  7. * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/polyhedra/geodesic_poly
  8. * @param name defines the name of the mesh
  9. * @param options an object used to set the following optional parameters for the polyhedron, required but can be empty
  10. * * m number of horizontal steps along an isogrid
  11. * * n number of angled steps along an isogrid
  12. * * size the size of the Geodesic, optional default 1
  13. * * sizeX allows stretching in the x direction, optional, default size
  14. * * sizeY allows stretching in the y direction, optional, default size
  15. * * sizeZ allows stretching in the z direction, optional, default size
  16. * * faceUV an array of Vector4 elements used to set different images to the top, rings and bottom respectively
  17. * * faceColors an array of Color3 elements used to set different colors to the top, rings and bottom respectively
  18. * * flat when true creates a flat shaded mesh, optional, default true
  19. * * subdivisions increasing the subdivisions increases the number of faces, optional, default 4
  20. * * sideOrientation optional and takes the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE
  21. * * frontUvs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the front side, optional, default vector4 (0, 0, 1, 1)
  22. * * backUVs only usable when you create a double-sided mesh, used to choose what parts of the texture image to crop and apply on the back side, optional, default vector4 (0, 0, 1, 1)
  23. * @param scene defines the hosting scene
  24. * @returns Geodesic mesh
  25. */
  26. export function CreateGeodesic(name, options, scene = null) {
  27. let m = options.m || 1;
  28. if (m !== Math.floor(m)) {
  29. m === Math.floor(m);
  30. Logger.Warn("m not an integer only floor(m) used");
  31. }
  32. let n = options.n || 0;
  33. if (n !== Math.floor(n)) {
  34. n === Math.floor(n);
  35. Logger.Warn("n not an integer only floor(n) used");
  36. }
  37. if (n > m) {
  38. const temp = n;
  39. n = m;
  40. m = temp;
  41. Logger.Warn("n > m therefore m and n swapped");
  42. }
  43. const primTri = new _PrimaryIsoTriangle();
  44. primTri.build(m, n);
  45. const geodesicData = GeodesicData.BuildGeodesicData(primTri);
  46. const geoOptions = {
  47. custom: geodesicData,
  48. size: options.size,
  49. sizeX: options.sizeX,
  50. sizeY: options.sizeY,
  51. sizeZ: options.sizeZ,
  52. faceUV: options.faceUV,
  53. faceColors: options.faceColors,
  54. flat: options.flat,
  55. updatable: options.updatable,
  56. sideOrientation: options.sideOrientation,
  57. frontUVs: options.frontUVs,
  58. backUVs: options.backUVs,
  59. };
  60. const geodesic = CreatePolyhedron(name, geoOptions, scene);
  61. return geodesic;
  62. }
  63. //# sourceMappingURL=geodesicBuilder.js.map