2b4063e7d9b1c93bee4be4b69988585070caeb8e37eb1d55b59ecee7eb3ec4d9.json 16 KB

1
  1. {"ast":null,"code":"import { Matrix, Vector3, Vector2 } from \"../../Maths/math.vector.js\";\nimport { Mesh } from \"../mesh.js\";\nimport { VertexData } from \"../mesh.vertexData.js\";\nimport { useOpenGLOrientationForUV } from \"../../Compat/compatibilityOptions.js\";\n/**\n * Creates the VertexData for a torus\n * @param options an object used to set the following optional parameters for the box, required but can be empty\n * * diameter the diameter of the torus, optional default 1\n * * thickness the diameter of the tube forming the torus, optional default 0.5\n * * tessellation the number of prism sides, 3 for a triangular prism, optional, default 24\n * * sideOrientation optional and takes the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\n * * 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)\n * * 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)\n * @param options.diameter\n * @param options.thickness\n * @param options.tessellation\n * @param options.sideOrientation\n * @param options.frontUVs\n * @param options.backUVs\n * @returns the VertexData of the torus\n */\nexport function CreateTorusVertexData(options) {\n const indices = [];\n const positions = [];\n const normals = [];\n const uvs = [];\n const diameter = options.diameter || 1;\n const thickness = options.thickness || 0.5;\n const tessellation = (options.tessellation || 16) | 0;\n const sideOrientation = options.sideOrientation === 0 ? 0 : options.sideOrientation || VertexData.DEFAULTSIDE;\n const stride = tessellation + 1;\n for (let i = 0; i <= tessellation; i++) {\n const u = i / tessellation;\n const outerAngle = i * Math.PI * 2.0 / tessellation - Math.PI / 2.0;\n const transform = Matrix.Translation(diameter / 2.0, 0, 0).multiply(Matrix.RotationY(outerAngle));\n for (let j = 0; j <= tessellation; j++) {\n const v = 1 - j / tessellation;\n const innerAngle = j * Math.PI * 2.0 / tessellation + Math.PI;\n const dx = Math.cos(innerAngle);\n const dy = Math.sin(innerAngle);\n // Create a vertex.\n let normal = new Vector3(dx, dy, 0);\n let position = normal.scale(thickness / 2);\n const textureCoordinate = new Vector2(u, v);\n position = Vector3.TransformCoordinates(position, transform);\n normal = Vector3.TransformNormal(normal, transform);\n positions.push(position.x, position.y, position.z);\n normals.push(normal.x, normal.y, normal.z);\n uvs.push(textureCoordinate.x, useOpenGLOrientationForUV ? 1.0 - textureCoordinate.y : textureCoordinate.y);\n // And create indices for two triangles.\n const nextI = (i + 1) % stride;\n const nextJ = (j + 1) % stride;\n indices.push(i * stride + j);\n indices.push(i * stride + nextJ);\n indices.push(nextI * stride + j);\n indices.push(i * stride + nextJ);\n indices.push(nextI * stride + nextJ);\n indices.push(nextI * stride + j);\n }\n }\n // Sides\n VertexData._ComputeSides(sideOrientation, positions, indices, normals, uvs, options.frontUVs, options.backUVs);\n // Result\n const vertexData = new VertexData();\n vertexData.indices = indices;\n vertexData.positions = positions;\n vertexData.normals = normals;\n vertexData.uvs = uvs;\n return vertexData;\n}\n/**\n * Creates a torus mesh\n * * The parameter `diameter` sets the diameter size (float) of the torus (default 1)\n * * The parameter `thickness` sets the diameter size of the tube of the torus (float, default 0.5)\n * * The parameter `tessellation` sets the number of torus sides (positive integer, default 16)\n * * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE\n * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4). Detail here : https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.\n * @param name defines the name of the mesh\n * @param options defines the options used to create the mesh\n * @param options.diameter\n * @param options.thickness\n * @param options.tessellation\n * @param options.updatable\n * @param options.sideOrientation\n * @param options.frontUVs\n * @param options.backUVs\n * @param scene defines the hosting scene\n * @returns the torus mesh\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#torus\n */\nexport function CreateTorus(name, options = {}, scene) {\n const torus = new Mesh(name, scene);\n options.sideOrientation = Mesh._GetDefaultSideOrientation(options.sideOrientation);\n torus._originalBuilderSideOrientation = options.sideOrientation;\n const vertexData = CreateTorusVertexData(options);\n vertexData.applyToMesh(torus, options.updatable);\n return torus;\n}\n/**\n * Class containing static functions to help procedurally build meshes\n * @deprecated use CreateTorus instead\n */\nexport const TorusBuilder = {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n CreateTorus\n};\nVertexData.CreateTorus = CreateTorusVertexData;\nMesh.CreateTorus = (name, diameter, thickness, tessellation, scene, updatable, sideOrientation) => {\n const options = {\n diameter,\n thickness,\n tessellation,\n sideOrientation,\n updatable\n };\n return CreateTorus(name, options, scene);\n};","map":{"version":3,"names":["Matrix","Vector3","Vector2","Mesh","VertexData","useOpenGLOrientationForUV","CreateTorusVertexData","options","indices","positions","normals","uvs","diameter","thickness","tessellation","sideOrientation","DEFAULTSIDE","stride","i","u","outerAngle","Math","PI","transform","Translation","multiply","RotationY","j","v","innerAngle","dx","cos","dy","sin","normal","position","scale","textureCoordinate","TransformCoordinates","TransformNormal","push","x","y","z","nextI","nextJ","_ComputeSides","frontUVs","backUVs","vertexData","CreateTorus","name","scene","torus","_GetDefaultSideOrientation","_originalBuilderSideOrientation","applyToMesh","updatable","TorusBuilder"],"sources":["F:/workspace/202226701027/huinongbao-app/node_modules/@babylonjs/core/Meshes/Builders/torusBuilder.js"],"sourcesContent":["import { Matrix, Vector3, Vector2 } from \"../../Maths/math.vector.js\";\nimport { Mesh } from \"../mesh.js\";\nimport { VertexData } from \"../mesh.vertexData.js\";\nimport { useOpenGLOrientationForUV } from \"../../Compat/compatibilityOptions.js\";\n/**\n * Creates the VertexData for a torus\n * @param options an object used to set the following optional parameters for the box, required but can be empty\n * * diameter the diameter of the torus, optional default 1\n * * thickness the diameter of the tube forming the torus, optional default 0.5\n * * tessellation the number of prism sides, 3 for a triangular prism, optional, default 24\n * * sideOrientation optional and takes the values : Mesh.FRONTSIDE (default), Mesh.BACKSIDE or Mesh.DOUBLESIDE\n * * 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)\n * * 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)\n * @param options.diameter\n * @param options.thickness\n * @param options.tessellation\n * @param options.sideOrientation\n * @param options.frontUVs\n * @param options.backUVs\n * @returns the VertexData of the torus\n */\nexport function CreateTorusVertexData(options) {\n const indices = [];\n const positions = [];\n const normals = [];\n const uvs = [];\n const diameter = options.diameter || 1;\n const thickness = options.thickness || 0.5;\n const tessellation = (options.tessellation || 16) | 0;\n const sideOrientation = options.sideOrientation === 0 ? 0 : options.sideOrientation || VertexData.DEFAULTSIDE;\n const stride = tessellation + 1;\n for (let i = 0; i <= tessellation; i++) {\n const u = i / tessellation;\n const outerAngle = (i * Math.PI * 2.0) / tessellation - Math.PI / 2.0;\n const transform = Matrix.Translation(diameter / 2.0, 0, 0).multiply(Matrix.RotationY(outerAngle));\n for (let j = 0; j <= tessellation; j++) {\n const v = 1 - j / tessellation;\n const innerAngle = (j * Math.PI * 2.0) / tessellation + Math.PI;\n const dx = Math.cos(innerAngle);\n const dy = Math.sin(innerAngle);\n // Create a vertex.\n let normal = new Vector3(dx, dy, 0);\n let position = normal.scale(thickness / 2);\n const textureCoordinate = new Vector2(u, v);\n position = Vector3.TransformCoordinates(position, transform);\n normal = Vector3.TransformNormal(normal, transform);\n positions.push(position.x, position.y, position.z);\n normals.push(normal.x, normal.y, normal.z);\n uvs.push(textureCoordinate.x, useOpenGLOrientationForUV ? 1.0 - textureCoordinate.y : textureCoordinate.y);\n // And create indices for two triangles.\n const nextI = (i + 1) % stride;\n const nextJ = (j + 1) % stride;\n indices.push(i * stride + j);\n indices.push(i * stride + nextJ);\n indices.push(nextI * stride + j);\n indices.push(i * stride + nextJ);\n indices.push(nextI * stride + nextJ);\n indices.push(nextI * stride + j);\n }\n }\n // Sides\n VertexData._ComputeSides(sideOrientation, positions, indices, normals, uvs, options.frontUVs, options.backUVs);\n // Result\n const vertexData = new VertexData();\n vertexData.indices = indices;\n vertexData.positions = positions;\n vertexData.normals = normals;\n vertexData.uvs = uvs;\n return vertexData;\n}\n/**\n * Creates a torus mesh\n * * The parameter `diameter` sets the diameter size (float) of the torus (default 1)\n * * The parameter `thickness` sets the diameter size of the tube of the torus (float, default 0.5)\n * * The parameter `tessellation` sets the number of torus sides (positive integer, default 16)\n * * You can also set the mesh side orientation with the values : BABYLON.Mesh.FRONTSIDE (default), BABYLON.Mesh.BACKSIDE or BABYLON.Mesh.DOUBLESIDE\n * * If you create a double-sided mesh, you can choose what parts of the texture image to crop and stick respectively on the front and the back sides with the parameters `frontUVs` and `backUVs` (Vector4). Detail here : https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#side-orientation\n * * The mesh can be set to updatable with the boolean parameter `updatable` (default false) if its internal geometry is supposed to change once created.\n * @param name defines the name of the mesh\n * @param options defines the options used to create the mesh\n * @param options.diameter\n * @param options.thickness\n * @param options.tessellation\n * @param options.updatable\n * @param options.sideOrientation\n * @param options.frontUVs\n * @param options.backUVs\n * @param scene defines the hosting scene\n * @returns the torus mesh\n * @see https://doc.babylonjs.com/features/featuresDeepDive/mesh/creation/set#torus\n */\nexport function CreateTorus(name, options = {}, scene) {\n const torus = new Mesh(name, scene);\n options.sideOrientation = Mesh._GetDefaultSideOrientation(options.sideOrientation);\n torus._originalBuilderSideOrientation = options.sideOrientation;\n const vertexData = CreateTorusVertexData(options);\n vertexData.applyToMesh(torus, options.updatable);\n return torus;\n}\n/**\n * Class containing static functions to help procedurally build meshes\n * @deprecated use CreateTorus instead\n */\nexport const TorusBuilder = {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n CreateTorus,\n};\nVertexData.CreateTorus = CreateTorusVertexData;\nMesh.CreateTorus = (name, diameter, thickness, tessellation, scene, updatable, sideOrientation) => {\n const options = {\n diameter,\n thickness,\n tessellation,\n sideOrientation,\n updatable,\n };\n return CreateTorus(name, options, scene);\n};\n"],"mappings":"AAAA,SAASA,MAAM,EAAEC,OAAO,EAAEC,OAAO,QAAQ,4BAA4B;AACrE,SAASC,IAAI,QAAQ,YAAY;AACjC,SAASC,UAAU,QAAQ,uBAAuB;AAClD,SAASC,yBAAyB,QAAQ,sCAAsC;AAChF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,qBAAqBA,CAACC,OAAO,EAAE;EAC3C,MAAMC,OAAO,GAAG,EAAE;EAClB,MAAMC,SAAS,GAAG,EAAE;EACpB,MAAMC,OAAO,GAAG,EAAE;EAClB,MAAMC,GAAG,GAAG,EAAE;EACd,MAAMC,QAAQ,GAAGL,OAAO,CAACK,QAAQ,IAAI,CAAC;EACtC,MAAMC,SAAS,GAAGN,OAAO,CAACM,SAAS,IAAI,GAAG;EAC1C,MAAMC,YAAY,GAAG,CAACP,OAAO,CAACO,YAAY,IAAI,EAAE,IAAI,CAAC;EACrD,MAAMC,eAAe,GAAGR,OAAO,CAACQ,eAAe,KAAK,CAAC,GAAG,CAAC,GAAGR,OAAO,CAACQ,eAAe,IAAIX,UAAU,CAACY,WAAW;EAC7G,MAAMC,MAAM,GAAGH,YAAY,GAAG,CAAC;EAC/B,KAAK,IAAII,CAAC,GAAG,CAAC,EAAEA,CAAC,IAAIJ,YAAY,EAAEI,CAAC,EAAE,EAAE;IACpC,MAAMC,CAAC,GAAGD,CAAC,GAAGJ,YAAY;IAC1B,MAAMM,UAAU,GAAIF,CAAC,GAAGG,IAAI,CAACC,EAAE,GAAG,GAAG,GAAIR,YAAY,GAAGO,IAAI,CAACC,EAAE,GAAG,GAAG;IACrE,MAAMC,SAAS,GAAGvB,MAAM,CAACwB,WAAW,CAACZ,QAAQ,GAAG,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC,CAACa,QAA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