chorama 0.0.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/publish.yml +24 -0
- package/.github/workflows/static.yml +22 -53
- package/README.md +3 -1
- package/assets/models/glb/AlphaBlendModeTest.glb +0 -0
- package/assets/models/glb/IridescenceLamp.glb +0 -0
- package/assets/models/glb/teapot.glb +0 -0
- package/astro.config.mjs +9 -21
- package/content/guide/render-targets-and-views.md +3 -4
- package/content/guide/textures-and-assets.md +5 -2
- package/dist/index.module.js +23334 -0
- package/dist/index.module.js.map +1 -0
- package/dist/index.umd.js +23610 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/website/_astro/DocLayout.BsV7p0dY.css +1 -0
- package/dist/website/examples/camera/orthographic/example.html +172 -0
- package/dist/website/examples/camera/orthographic/index.html +124 -0
- package/dist/website/examples/camera/perspective/example.html +190 -0
- package/dist/website/examples/camera/perspective/index.html +142 -0
- package/dist/website/examples/camera/tone_mapping/example.html +238 -0
- package/dist/website/examples/camera/tone_mapping/index.html +190 -0
- package/dist/website/examples/index.html +2 -0
- package/dist/website/examples/lights/directional/example.html +447 -0
- package/dist/website/examples/lights/directional/index.html +399 -0
- package/dist/website/examples/lights/multiple_spot_lights/example.html +356 -0
- package/dist/website/examples/lights/multiple_spot_lights/index.html +308 -0
- package/dist/website/examples/lights/point/example.html +387 -0
- package/dist/website/examples/lights/point/index.html +339 -0
- package/dist/website/examples/lights/spot/example.html +416 -0
- package/dist/website/examples/lights/spot/index.html +368 -0
- package/dist/website/examples/loader/gltf/basic/example.html +129 -0
- package/dist/website/examples/loader/gltf/basic/index.html +81 -0
- package/dist/website/examples/loader/gltf/material/alpha-blend-mode/example.html +131 -0
- package/dist/website/examples/loader/gltf/material/alpha-blend-mode/index.html +83 -0
- package/dist/website/examples/loader/gltf/material/flight_helmet/example.html +162 -0
- package/dist/website/examples/loader/gltf/material/flight_helmet/index.html +114 -0
- package/dist/website/examples/loader/gltf/material/iridescence_lamp/example.html +169 -0
- package/dist/website/examples/loader/gltf/material/iridescence_lamp/index.html +121 -0
- package/dist/website/examples/loader/objloader/example.html +144 -0
- package/dist/website/examples/loader/objloader/index.html +96 -0
- package/dist/website/examples/material/cullface/example.html +163 -0
- package/dist/website/examples/material/cullface/index.html +115 -0
- package/dist/website/examples/material/materials/example.html +175 -0
- package/dist/website/examples/material/materials/index.html +127 -0
- package/dist/website/examples/material/standard/basic/example.html +212 -0
- package/dist/website/examples/material/standard/basic/index.html +164 -0
- package/dist/website/examples/material/standard/reflection_refraction/example.html +241 -0
- package/dist/website/examples/material/standard/reflection_refraction/index.html +193 -0
- package/dist/website/examples/mesh/capsule/example.html +173 -0
- package/dist/website/examples/mesh/capsule/index.html +125 -0
- package/dist/website/examples/mesh/circle/example.html +173 -0
- package/dist/website/examples/mesh/circle/index.html +125 -0
- package/dist/website/examples/mesh/cone/example.html +180 -0
- package/dist/website/examples/mesh/cone/index.html +132 -0
- package/dist/website/examples/mesh/cuboid/example.html +207 -0
- package/dist/website/examples/mesh/cuboid/index.html +159 -0
- package/dist/website/examples/mesh/cylinder/example.html +195 -0
- package/dist/website/examples/mesh/cylinder/index.html +147 -0
- package/dist/website/examples/mesh/dodecahedron/example.html +158 -0
- package/dist/website/examples/mesh/dodecahedron/index.html +110 -0
- package/dist/website/examples/mesh/ellipsoid/example.html +179 -0
- package/dist/website/examples/mesh/ellipsoid/index.html +131 -0
- package/dist/website/examples/mesh/extrude/example.html +169 -0
- package/dist/website/examples/mesh/extrude/index.html +121 -0
- package/dist/website/examples/mesh/frustum/example.html +185 -0
- package/dist/website/examples/mesh/frustum/index.html +137 -0
- package/dist/website/examples/mesh/helix/example.html +184 -0
- package/dist/website/examples/mesh/helix/index.html +136 -0
- package/dist/website/examples/mesh/icosahedron/example.html +158 -0
- package/dist/website/examples/mesh/icosahedron/index.html +110 -0
- package/dist/website/examples/mesh/icosphere/example.html +163 -0
- package/dist/website/examples/mesh/icosphere/index.html +115 -0
- package/dist/website/examples/mesh/lathe/example.html +175 -0
- package/dist/website/examples/mesh/lathe/index.html +127 -0
- package/dist/website/examples/mesh/meshTopology/example.html +210 -0
- package/dist/website/examples/mesh/meshTopology/index.html +162 -0
- package/dist/website/examples/mesh/octahedron/example.html +158 -0
- package/dist/website/examples/mesh/octahedron/index.html +110 -0
- package/dist/website/examples/mesh/plane/example.html +173 -0
- package/dist/website/examples/mesh/plane/index.html +125 -0
- package/dist/website/examples/mesh/prism/example.html +173 -0
- package/dist/website/examples/mesh/prism/index.html +125 -0
- package/dist/website/examples/mesh/pyramid/example.html +172 -0
- package/dist/website/examples/mesh/pyramid/index.html +124 -0
- package/dist/website/examples/mesh/ring/example.html +173 -0
- package/dist/website/examples/mesh/ring/index.html +125 -0
- package/dist/website/examples/mesh/skinning/example.html +187 -0
- package/dist/website/examples/mesh/skinning/index.html +139 -0
- package/dist/website/examples/mesh/terrain/example.html +214 -0
- package/dist/website/examples/mesh/terrain/index.html +166 -0
- package/dist/website/examples/mesh/tetrahedron/example.html +158 -0
- package/dist/website/examples/mesh/tetrahedron/index.html +110 -0
- package/dist/website/examples/mesh/torus/example.html +173 -0
- package/dist/website/examples/mesh/torus/index.html +125 -0
- package/dist/website/examples/mesh/torus-knot/example.html +188 -0
- package/dist/website/examples/mesh/torus-knot/index.html +140 -0
- package/dist/website/examples/mesh/tube/example.html +180 -0
- package/dist/website/examples/mesh/tube/index.html +132 -0
- package/dist/website/examples/mesh/uvsphere/example.html +169 -0
- package/dist/website/examples/mesh/uvsphere/index.html +121 -0
- package/dist/website/examples/mesh/wedge/example.html +168 -0
- package/dist/website/examples/mesh/wedge/index.html +120 -0
- package/dist/website/examples/other/rotatingCube/example.html +142 -0
- package/dist/website/examples/other/rotatingCube/index.html +94 -0
- package/dist/website/examples/other/rotatingSphere/example.html +144 -0
- package/dist/website/examples/other/rotatingSphere/index.html +96 -0
- package/dist/website/examples/rendertarget/basic_canvas/example.html +178 -0
- package/dist/website/examples/rendertarget/basic_canvas/index.html +130 -0
- package/dist/website/examples/rendertarget/depth_texture/example.html +188 -0
- package/dist/website/examples/rendertarget/depth_texture/index.html +140 -0
- package/dist/website/examples/rendertarget/image_target/example.html +196 -0
- package/dist/website/examples/rendertarget/image_target/index.html +148 -0
- package/dist/website/examples/rendertarget/multiple_views/example.html +204 -0
- package/dist/website/examples/rendertarget/multiple_views/index.html +156 -0
- package/dist/website/examples/rendertarget/render_masks/example.html +222 -0
- package/dist/website/examples/rendertarget/render_masks/index.html +174 -0
- package/dist/website/examples/rendertarget/split_screen/example.html +178 -0
- package/dist/website/examples/rendertarget/split_screen/index.html +130 -0
- package/dist/website/examples/rendertarget/split_view/example.html +191 -0
- package/dist/website/examples/rendertarget/split_view/index.html +143 -0
- package/dist/website/examples/skybox/skybox/example.html +162 -0
- package/dist/website/examples/skybox/skybox/index.html +114 -0
- package/dist/website/examples/texture/arrays/example.html +204 -0
- package/dist/website/examples/texture/arrays/index.html +156 -0
- package/dist/website/examples/texture/textureWrap/example.html +169 -0
- package/dist/website/examples/texture/textureWrap/index.html +121 -0
- package/dist/website/examples/transform/propagation/example.html +141 -0
- package/dist/website/examples/transform/propagation/index.html +93 -0
- package/dist/website/guide/api-map/index.html +82 -0
- package/dist/website/guide/camera-and-controls/index.html +62 -0
- package/dist/website/guide/first-scene/index.html +119 -0
- package/dist/website/guide/index.html +58 -0
- package/dist/website/guide/installation/index.html +133 -0
- package/dist/website/guide/materials-and-lighting/index.html +90 -0
- package/dist/website/guide/plugins-and-render-pipeline/index.html +89 -0
- package/dist/website/guide/render-targets-and-views/index.html +95 -0
- package/dist/website/guide/scene-graph-and-transforms/index.html +69 -0
- package/dist/website/guide/textures-and-assets/index.html +85 -0
- package/dist/website/guide/troubleshooting/index.html +39 -0
- package/dist/website/images/disappointed.jpg +0 -0
- package/dist/website/images/skybox/grimmnight_back.png +0 -0
- package/dist/website/images/skybox/grimmnight_bottom.png +0 -0
- package/dist/website/images/skybox/grimmnight_front.png +0 -0
- package/dist/website/images/skybox/grimmnight_left.png +0 -0
- package/dist/website/images/skybox/grimmnight_right.png +0 -0
- package/dist/website/images/skybox/grimmnight_top.png +0 -0
- package/dist/website/images/skybox/miramar_back.png +0 -0
- package/dist/website/images/skybox/miramar_bottom.png +0 -0
- package/dist/website/images/skybox/miramar_front.png +0 -0
- package/dist/website/images/skybox/miramar_left.png +0 -0
- package/dist/website/images/skybox/miramar_right.png +0 -0
- package/dist/website/images/skybox/miramar_top.png +0 -0
- package/dist/website/images/uv.jpg +0 -0
- package/dist/website/index.html +157 -0
- package/dist/website/models/glb/AlphaBlendModeTest.glb +0 -0
- package/dist/website/models/glb/IridescenceLamp.glb +0 -0
- package/dist/website/models/glb/teapot.glb +0 -0
- package/dist/website/models/gltf/flight_helmet/FlightHelmet_Materials_GlassPlasticMat_BaseColor.png +0 -0
- package/dist/website/models/gltf/flight_helmet/FlightHelmet_Materials_GlassPlasticMat_Normal.png +0 -0
- package/dist/website/models/gltf/flight_helmet/FlightHelmet_Materials_GlassPlasticMat_OcclusionRoughMetal.png +0 -0
- package/dist/website/models/gltf/flight_helmet/FlightHelmet_Materials_LeatherPartsMat_BaseColor.png +0 -0
- package/dist/website/models/gltf/flight_helmet/FlightHelmet_Materials_LeatherPartsMat_Normal.png +0 -0
- package/dist/website/models/gltf/flight_helmet/FlightHelmet_Materials_LeatherPartsMat_OcclusionRoughMetal.png +0 -0
- package/dist/website/models/gltf/flight_helmet/FlightHelmet_Materials_LensesMat_BaseColor.png +0 -0
- package/dist/website/models/gltf/flight_helmet/FlightHelmet_Materials_LensesMat_Normal.png +0 -0
- package/dist/website/models/gltf/flight_helmet/FlightHelmet_Materials_LensesMat_OcclusionRoughMetal.png +0 -0
- package/dist/website/models/gltf/flight_helmet/FlightHelmet_Materials_MetalPartsMat_BaseColor.png +0 -0
- package/dist/website/models/gltf/flight_helmet/FlightHelmet_Materials_MetalPartsMat_Normal.png +0 -0
- package/dist/website/models/gltf/flight_helmet/FlightHelmet_Materials_MetalPartsMat_OcclusionRoughMetal.png +0 -0
- package/dist/website/models/gltf/flight_helmet/FlightHelmet_Materials_RubberWoodMat_BaseColor.png +0 -0
- package/dist/website/models/gltf/flight_helmet/FlightHelmet_Materials_RubberWoodMat_Normal.png +0 -0
- package/dist/website/models/gltf/flight_helmet/FlightHelmet_Materials_RubberWoodMat_OcclusionRoughMetal.png +0 -0
- package/dist/website/models/gltf/flight_helmet/index.bin +0 -0
- package/dist/website/models/gltf/flight_helmet/index.gltf +705 -0
- package/dist/website/models/gltf/object.gltf +23 -0
- package/dist/website/models/gltf/pirate_girl/index.bin +0 -0
- package/dist/website/models/gltf/pirate_girl/index.gltf +2082 -0
- package/dist/website/models/obj/pirate_girl/pirate_girl.obj +18459 -0
- package/dist/website/models/obj/pirate_girl/pirate_girl.png +0 -0
- package/env.d.ts +0 -14
- package/examples/camera/orthographic.js +2 -1
- package/examples/camera/perspective.js +2 -1
- package/examples/camera/tone_mapping.js +187 -0
- package/examples/lights/directional.js +2 -3
- package/examples/lights/multiple_spot_lights.js +2 -1
- package/examples/lights/point.js +2 -3
- package/examples/lights/spot.js +2 -3
- package/examples/loader/{gltfloader.js → gltf/basic.js} +8 -8
- package/examples/loader/gltf/material/alpha-blend-mode.js +80 -0
- package/examples/loader/{gltf_material.js → gltf/material/flight_helmet.js} +8 -8
- package/examples/loader/gltf/material/iridescence_lamp.js +118 -0
- package/examples/loader/objloader.js +9 -11
- package/examples/material/cullface.js +8 -7
- package/examples/material/materials.js +9 -11
- package/examples/material/standard/basic.js +3 -6
- package/examples/material/standard/reflection_refraction.js +190 -0
- package/examples/mesh/capsule.js +122 -0
- package/examples/mesh/circle.js +11 -6
- package/examples/mesh/cone.js +129 -0
- package/examples/mesh/cuboid.js +11 -6
- package/examples/mesh/cylinder.js +11 -6
- package/examples/mesh/dodecahedron.js +107 -0
- package/examples/mesh/ellipsoid.js +128 -0
- package/examples/mesh/extrude.js +118 -0
- package/examples/mesh/frustum.js +134 -0
- package/examples/mesh/helix.js +133 -0
- package/examples/mesh/icosahedron.js +107 -0
- package/examples/mesh/icosphere.js +112 -0
- package/examples/mesh/lathe.js +124 -0
- package/examples/mesh/meshTopology.js +64 -8
- package/examples/mesh/octahedron.js +107 -0
- package/examples/mesh/plane.js +11 -6
- package/examples/mesh/prism.js +122 -0
- package/examples/mesh/pyramid.js +121 -0
- package/examples/mesh/ring.js +122 -0
- package/examples/mesh/skinning.js +8 -8
- package/examples/mesh/terrain.js +163 -0
- package/examples/mesh/tetrahedron.js +107 -0
- package/examples/mesh/torus-knot.js +137 -0
- package/examples/mesh/torus.js +122 -0
- package/examples/mesh/tube.js +129 -0
- package/examples/mesh/uvsphere.js +11 -6
- package/examples/mesh/wedge.js +117 -0
- package/examples/other/rotatingCube.js +9 -11
- package/examples/other/rotatingSphere.js +9 -12
- package/examples/rendertarget/basic_canvas.js +5 -8
- package/examples/rendertarget/depth_texture.js +18 -11
- package/examples/rendertarget/image_target.js +19 -14
- package/examples/rendertarget/multiple_views.js +11 -16
- package/examples/rendertarget/render_masks.js +3 -5
- package/examples/rendertarget/split_screen.js +18 -14
- package/examples/rendertarget/split_view.js +12 -9
- package/examples/skybox/skybox.js +8 -8
- package/examples/texture/arrays.js +9 -12
- package/examples/texture/textureWrap.js +8 -8
- package/examples/transform/propagation.js +9 -11
- package/package.json +18 -12
- package/src/caches/cache.js +121 -182
- package/src/caches/uniformbuffers.js +42 -53
- package/src/constants/texture.js +1 -1
- package/src/content.config.js +1 -0
- package/src/core/layouts/bindgroup.js +167 -0
- package/src/core/layouts/index.js +3 -1
- package/src/core/layouts/pipeline.js +165 -0
- package/src/core/layouts/uniformbuffer.js +11 -3
- package/src/core/resources/gpubuffer.js +23 -2
- package/src/core/resources/gpumesh.js +37 -4
- package/src/core/resources/gpusampler.js +43 -0
- package/src/core/resources/gputexture.js +31 -2
- package/src/core/resources/index.js +4 -2
- package/src/core/resources/newuniformbuffer.js +58 -0
- package/src/core/resources/webglshadermodule.js +58 -0
- package/src/core/shader.js +24 -11
- package/src/core/webgl/bindgroup.js +200 -42
- package/src/core/webgl/descriptors.js +87 -25
- package/src/core/webgl/gpuqueue.js +63 -0
- package/src/core/webgl/index.js +3 -0
- package/src/core/webgl/renderpassencoder.js +703 -16
- package/src/core/webgl/renderpipeline.js +38 -1
- package/src/core/webgl/utils.js +207 -57
- package/src/core/webgl/webglrenderdevice.js +77 -53
- package/src/loader/gltf.js +716 -166
- package/src/loader/texture.js +69 -16
- package/src/loader/utils.js +44 -0
- package/src/material/alphablend.js +21 -0
- package/src/material/basic.js +15 -1
- package/src/material/depth.js +15 -1
- package/src/material/index.js +1 -0
- package/src/material/lambert.js +15 -1
- package/src/material/material.js +49 -7
- package/src/material/normal.js +14 -0
- package/src/material/phong.js +16 -2
- package/src/material/raw.js +21 -2
- package/src/material/standard.js +90 -2
- package/src/mesh/attribute/attribute.js +2 -2
- package/src/mesh/attributedata/separate.js +2 -2
- package/src/mesh/builders/capsule.js +47 -0
- package/src/mesh/builders/cone.js +29 -0
- package/src/mesh/builders/dodecahedron.js +130 -0
- package/src/mesh/builders/ellipsoid.js +65 -0
- package/src/mesh/builders/extrude.js +136 -0
- package/src/mesh/builders/frustum.js +26 -0
- package/src/mesh/builders/geometry.js +121 -0
- package/src/mesh/builders/helix.js +35 -0
- package/src/mesh/builders/icosahedron.js +61 -0
- package/src/mesh/builders/icosphere.js +141 -0
- package/src/mesh/builders/index.js +22 -1
- package/src/mesh/builders/lathe.js +85 -0
- package/src/mesh/builders/octahedron.js +43 -0
- package/src/mesh/builders/polyhedron.js +121 -0
- package/src/mesh/builders/prism.js +19 -0
- package/src/mesh/builders/pyramid.js +90 -0
- package/src/mesh/builders/ring.js +109 -0
- package/src/mesh/builders/surfaces.js +69 -0
- package/src/mesh/builders/terrain.js +80 -0
- package/src/mesh/builders/tetrahedron.js +37 -0
- package/src/mesh/builders/torusknot.js +36 -0
- package/src/mesh/builders/tube.js +209 -0
- package/src/mesh/builders/utils.js +130 -2
- package/src/mesh/builders/wedge.js +22 -0
- package/src/mesh/mesh.js +12 -4
- package/src/objects/camera/camera.js +104 -1
- package/src/objects/light/ambient.js +22 -1
- package/src/objects/light/directional.js +23 -1
- package/src/objects/light/point.js +25 -1
- package/src/objects/light/spot.js +27 -1
- package/src/objects/mesh.js +1 -53
- package/src/plugins/camera/RenderTarget2DPool.js +94 -0
- package/src/plugins/camera/camera.js +14 -6
- package/src/plugins/camera/index.js +2 -0
- package/src/plugins/camera/nodes/canvasblit.js +153 -0
- package/src/plugins/camera/nodes/index.js +4 -1
- package/src/plugins/camera/nodes/opaquepass.js +48 -33
- package/src/plugins/camera/nodes/tonemapping.js +217 -0
- package/src/plugins/camera/nodes/transparentpass.js +87 -0
- package/src/plugins/camera/nodes/{cameraview.js → view.js} +27 -1
- package/src/plugins/camera/resources/cameracolortargets.js +66 -0
- package/src/plugins/camera/resources/canvasblitpipeline.js +6 -0
- package/src/plugins/camera/resources/index.js +3 -0
- package/src/plugins/camera/resources/tonemappingpipeline.js +6 -0
- package/src/plugins/light/light.js +0 -4
- package/src/plugins/meshmaterial/meshmaterial.js +433 -170
- package/src/plugins/meshmaterial/nodes/meshmaterial.js +39 -6
- package/src/plugins/meshmaterial/resources/bonetexture.js +176 -0
- package/src/plugins/meshmaterial/resources/environmentmap.js +44 -0
- package/src/plugins/meshmaterial/resources/index.js +4 -0
- package/src/plugins/meshmaterial/resources/materialuniformbuffers.js +94 -0
- package/src/plugins/meshmaterial/resources/meshmaterialbindgroups.js +40 -0
- package/src/plugins/shadow/nodes/index.js +3 -3
- package/src/plugins/shadow/nodes/{shadowOccluder.js → occluder.js} +13 -19
- package/src/plugins/shadow/nodes/opaquePass.js +110 -0
- package/src/plugins/shadow/shadow.js +0 -5
- package/src/plugins/skeletonhelper/skeletonhelper.js +111 -69
- package/src/plugins/skybox/nodes/skybox.js +230 -38
- package/src/plugins/skybox/resources/skyboxpipeline.js +10 -0
- package/src/plugins/skybox/skybox.js +0 -119
- package/src/renderer/core/index.js +135 -21
- package/src/renderer/plugin.js +0 -20
- package/src/renderer/renderer.js +28 -12
- package/src/rendertarget/canvastarget.js +8 -5
- package/src/rendertarget/image.js +3 -3
- package/src/shader/basicFragment.glsl +12 -4
- package/src/shader/basicVertex.glsl +26 -15
- package/src/shader/blitFragment.glsl +9 -0
- package/src/shader/common/common.glsl +35 -6
- package/src/shader/common/index.js +1 -0
- package/src/shader/common/tonemap.glsl +118 -0
- package/src/shader/debug/skeletonFragment.glsl +0 -2
- package/src/shader/debug/skeletonVertex.glsl +1 -3
- package/src/shader/depthFragment.glsl +0 -3
- package/src/shader/fullscreenVertex.glsl +26 -0
- package/src/shader/index.js +3 -0
- package/src/shader/lambertFragment.glsl +12 -4
- package/src/shader/normalFragment.glsl +0 -3
- package/src/shader/phongFragment.glsl +12 -4
- package/src/shader/skyboxFragment.glsl +5 -5
- package/src/shader/skyboxVertex.glsl +5 -4
- package/src/shader/standardFragment.glsl +74 -17
- package/src/shader/tonemappingFragment.glsl +37 -0
- package/src/texture/sampler.js +101 -21
- package/src/texture/texture.js +252 -48
- package/src/utils/index.js +15 -1
- package/{examples/addons → src/utils}/rendergraph_gui.js +5 -2
- package/examples/mesh/geometries.js +0 -108
- package/scripts/stage-chorama.mjs +0 -29
- package/src/core/resources/framebuffer.js +0 -127
- package/src/plugins/shadow/nodes/shadowOpaquePass.js +0 -73
- package/website/config/index.ts +0 -1
- package/website/config/navigation.ts +0 -53
- package/website/content.config.ts +0 -92
- package/website/layouts/DocLayout.astro +0 -501
- package/website/layouts/Example.astro +0 -91
- package/website/pages/examples/[...slug].astro +0 -77
- package/website/pages/examples/index.astro +0 -98
- package/website/pages/examples/samples/[...slug].astro +0 -17
- package/website/pages/guide/[slug].astro +0 -30
- package/website/pages/guide/index.astro +0 -21
- package/website/pages/index.astro +0 -9
- package/website/plugins/remark-link-base.js +0 -23
- package/website/utils/url.ts +0 -30
- /package/src/plugins/shadow/nodes/{shadow.js → view.js} +0 -0
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
import { Vector3 } from "../../math/index.js"
|
|
3
|
+
import { assert } from "../../utils/index.js"
|
|
4
|
+
import { MeshBuilder } from "./base.js"
|
|
5
|
+
import { createMeshFromArrays, sphericalUV } from "./geometry.js"
|
|
6
|
+
|
|
7
|
+
const icosahedronVertices = [
|
|
8
|
+
new Vector3(-1, 1.618033988749895, 0),
|
|
9
|
+
new Vector3(1, 1.618033988749895, 0),
|
|
10
|
+
new Vector3(-1, -1.618033988749895, 0),
|
|
11
|
+
new Vector3(1, -1.618033988749895, 0),
|
|
12
|
+
new Vector3(0, -1, 1.618033988749895),
|
|
13
|
+
new Vector3(0, 1, 1.618033988749895),
|
|
14
|
+
new Vector3(0, -1, -1.618033988749895),
|
|
15
|
+
new Vector3(0, 1, -1.618033988749895),
|
|
16
|
+
new Vector3(1.618033988749895, 0, -1),
|
|
17
|
+
new Vector3(1.618033988749895, 0, 1),
|
|
18
|
+
new Vector3(-1.618033988749895, 0, -1),
|
|
19
|
+
new Vector3(-1.618033988749895, 0, 1)
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
const icosahedronFaces = [
|
|
23
|
+
[0, 11, 5],
|
|
24
|
+
[0, 5, 1],
|
|
25
|
+
[0, 1, 7],
|
|
26
|
+
[0, 7, 10],
|
|
27
|
+
[0, 10, 11],
|
|
28
|
+
[1, 5, 9],
|
|
29
|
+
[5, 11, 4],
|
|
30
|
+
[11, 10, 2],
|
|
31
|
+
[10, 7, 6],
|
|
32
|
+
[7, 1, 8],
|
|
33
|
+
[3, 9, 4],
|
|
34
|
+
[3, 4, 2],
|
|
35
|
+
[3, 2, 6],
|
|
36
|
+
[3, 6, 8],
|
|
37
|
+
[3, 8, 9],
|
|
38
|
+
[4, 9, 5],
|
|
39
|
+
[2, 4, 11],
|
|
40
|
+
[6, 2, 10],
|
|
41
|
+
[8, 6, 7],
|
|
42
|
+
[9, 8, 1]
|
|
43
|
+
]
|
|
44
|
+
|
|
45
|
+
export class IcosphereMeshBuilder extends MeshBuilder {
|
|
46
|
+
radius = 0.5
|
|
47
|
+
subdivisions = 1
|
|
48
|
+
|
|
49
|
+
/** @override */
|
|
50
|
+
build() {
|
|
51
|
+
let vertices = icosahedronVertices.map((vertex) => vertex.clone().normalize())
|
|
52
|
+
let faces = icosahedronFaces.map((face) => face.slice())
|
|
53
|
+
|
|
54
|
+
for (let subdivision = 0; subdivision < this.subdivisions; subdivision++) {
|
|
55
|
+
const midpointCache = new Map()
|
|
56
|
+
/** @type {number[][]} */
|
|
57
|
+
const nextFaces = []
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @param {number} a
|
|
61
|
+
* @param {number} b
|
|
62
|
+
* @returns {number}
|
|
63
|
+
*/
|
|
64
|
+
const midpointIndex = (a, b) => {
|
|
65
|
+
const key = a < b ? `${a}:${b}` : `${b}:${a}`
|
|
66
|
+
const cached = midpointCache.get(key)
|
|
67
|
+
if (cached !== undefined) {
|
|
68
|
+
return cached
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const vertexA = vertices[a]
|
|
72
|
+
const vertexB = vertices[b]
|
|
73
|
+
assert(vertexA, `Missing icosahedron vertex at index ${a}`)
|
|
74
|
+
assert(vertexB, `Missing icosahedron vertex at index ${b}`)
|
|
75
|
+
const midpoint = vertexA.clone().add(vertexB).divideScalar(2).normalize()
|
|
76
|
+
const index = vertices.push(midpoint) - 1
|
|
77
|
+
midpointCache.set(key, index)
|
|
78
|
+
return index
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
for (const face of faces) {
|
|
82
|
+
const a = face[0]
|
|
83
|
+
const b = face[1]
|
|
84
|
+
const c = face[2]
|
|
85
|
+
assert(a, "Icosahedron subdivision face requires at least three vertices")
|
|
86
|
+
assert(b, "Icosahedron subdivision face requires at least three vertices")
|
|
87
|
+
assert(c, "Icosahedron subdivision face requires at least three vertices")
|
|
88
|
+
const ab = midpointIndex(a, b)
|
|
89
|
+
const bc = midpointIndex(b, c)
|
|
90
|
+
const ca = midpointIndex(c, a)
|
|
91
|
+
|
|
92
|
+
nextFaces.push([a, ab, ca])
|
|
93
|
+
nextFaces.push([b, bc, ab])
|
|
94
|
+
nextFaces.push([c, ca, bc])
|
|
95
|
+
nextFaces.push([ab, bc, ca])
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
faces = nextFaces
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** @type {number[]} */
|
|
102
|
+
const positions = []
|
|
103
|
+
/** @type {number[]} */
|
|
104
|
+
const normals = []
|
|
105
|
+
/** @type {number[]} */
|
|
106
|
+
const uvs = []
|
|
107
|
+
/** @type {number[]} */
|
|
108
|
+
const indices = []
|
|
109
|
+
|
|
110
|
+
for (const vertex of vertices) {
|
|
111
|
+
const normal = vertex.clone().normalize()
|
|
112
|
+
const position = normal.clone().multiplyScalar(this.radius)
|
|
113
|
+
const uv = sphericalUV(normal)
|
|
114
|
+
|
|
115
|
+
positions.push(position.x, position.y, position.z)
|
|
116
|
+
normals.push(normal.x, normal.y, normal.z)
|
|
117
|
+
uvs.push(uv.x, uv.y)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
for (const face of faces) {
|
|
121
|
+
const firstFaceVertex = face[0]
|
|
122
|
+
const secondFaceVertex = face[1]
|
|
123
|
+
const thirdFaceVertex = face[2]
|
|
124
|
+
assert(firstFaceVertex, "Icosahedron face requires at least three vertices")
|
|
125
|
+
assert(secondFaceVertex, "Icosahedron face requires at least three vertices")
|
|
126
|
+
assert(thirdFaceVertex, "Icosahedron face requires at least three vertices")
|
|
127
|
+
indices.push(
|
|
128
|
+
firstFaceVertex,
|
|
129
|
+
secondFaceVertex,
|
|
130
|
+
thirdFaceVertex
|
|
131
|
+
)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return createMeshFromArrays({
|
|
135
|
+
positions,
|
|
136
|
+
normals,
|
|
137
|
+
uvs,
|
|
138
|
+
indices
|
|
139
|
+
})
|
|
140
|
+
}
|
|
141
|
+
}
|
|
@@ -2,6 +2,27 @@ export * from './base.js'
|
|
|
2
2
|
export * from './plane.js'
|
|
3
3
|
export * from './circle.js'
|
|
4
4
|
export * from './cylinder.js'
|
|
5
|
+
export * from './cone.js'
|
|
6
|
+
export * from './frustum.js'
|
|
5
7
|
export * from './cuboid.js'
|
|
6
8
|
export * from './uvsphere.js'
|
|
7
|
-
export * from './
|
|
9
|
+
export * from './ellipsoid.js'
|
|
10
|
+
export * from './lathe.js'
|
|
11
|
+
export * from './capsule.js'
|
|
12
|
+
export * from './tube.js'
|
|
13
|
+
export * from './helix.js'
|
|
14
|
+
export * from './torusknot.js'
|
|
15
|
+
export * from './surfaces.js'
|
|
16
|
+
export * from './ring.js'
|
|
17
|
+
export * from './extrude.js'
|
|
18
|
+
export * from './prism.js'
|
|
19
|
+
export * from './wedge.js'
|
|
20
|
+
export * from './pyramid.js'
|
|
21
|
+
export * from './polyhedron.js'
|
|
22
|
+
export * from './tetrahedron.js'
|
|
23
|
+
export * from './octahedron.js'
|
|
24
|
+
export * from './icosahedron.js'
|
|
25
|
+
export * from './dodecahedron.js'
|
|
26
|
+
export * from './icosphere.js'
|
|
27
|
+
export * from './terrain.js'
|
|
28
|
+
export * from './wireframe.js'
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
import { Vector2, Vector3 } from "../../math/index.js"
|
|
3
|
+
import { assert } from "../../utils/index.js"
|
|
4
|
+
import { MeshBuilder } from "./base.js"
|
|
5
|
+
import { createMeshFromArrays } from "./geometry.js"
|
|
6
|
+
|
|
7
|
+
export class LatheMeshBuilder extends MeshBuilder {
|
|
8
|
+
/**
|
|
9
|
+
* Profile points in the X/Y plane. X is the radius from the revolution axis.
|
|
10
|
+
* @type {Vector2[]}
|
|
11
|
+
*/
|
|
12
|
+
profile = []
|
|
13
|
+
segments = 32
|
|
14
|
+
phiStart = 0
|
|
15
|
+
phiLength = Math.PI * 2
|
|
16
|
+
|
|
17
|
+
/** @override */
|
|
18
|
+
build() {
|
|
19
|
+
const profile = this.profile
|
|
20
|
+
|
|
21
|
+
if (profile.length < 2) {
|
|
22
|
+
return createMeshFromArrays({ positions: [] })
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const positions = []
|
|
26
|
+
const normals = []
|
|
27
|
+
const uvs = []
|
|
28
|
+
const indices = []
|
|
29
|
+
const columnCount = this.segments + 1
|
|
30
|
+
|
|
31
|
+
for (let i = 0; i < profile.length; i++) {
|
|
32
|
+
const current = profile[i]
|
|
33
|
+
assert(current, `Missing lathe profile point ${i}`)
|
|
34
|
+
const previous = i > 0 ? profile[i - 1] : current
|
|
35
|
+
assert(previous, `Missing previous lathe profile point ${i - 1}`)
|
|
36
|
+
const next = i < profile.length - 1 ? profile[i + 1] : current
|
|
37
|
+
assert(next, `Missing next lathe profile point ${i + 1}`)
|
|
38
|
+
|
|
39
|
+
const tangent = next.clone().subtract(previous).normalize()
|
|
40
|
+
const normal = new Vector2(tangent.y, -tangent.x).normalize()
|
|
41
|
+
|
|
42
|
+
for (let segment = 0; segment < columnCount; segment++) {
|
|
43
|
+
const t = segment / this.segments
|
|
44
|
+
const angle = this.phiStart + t * this.phiLength
|
|
45
|
+
const cos = Math.cos(angle)
|
|
46
|
+
const sin = Math.sin(angle)
|
|
47
|
+
|
|
48
|
+
const position = new Vector3(
|
|
49
|
+
current.x * cos,
|
|
50
|
+
current.y,
|
|
51
|
+
current.x * sin
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
const surfaceNormal = new Vector3(
|
|
55
|
+
normal.x * cos,
|
|
56
|
+
normal.y,
|
|
57
|
+
normal.x * sin
|
|
58
|
+
).normalize()
|
|
59
|
+
|
|
60
|
+
positions.push(position.x, position.y, position.z)
|
|
61
|
+
normals.push(surfaceNormal.x, surfaceNormal.y, surfaceNormal.z)
|
|
62
|
+
uvs.push(t, i / (profile.length - 1))
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
for (let i = 0; i < profile.length - 1; i++) {
|
|
67
|
+
for (let segment = 0; segment < this.segments; segment++) {
|
|
68
|
+
const a = i * columnCount + segment
|
|
69
|
+
const b = (i + 1) * columnCount + segment
|
|
70
|
+
const c = (i + 1) * columnCount + segment + 1
|
|
71
|
+
const d = i * columnCount + segment + 1
|
|
72
|
+
|
|
73
|
+
indices.push(a, b, d)
|
|
74
|
+
indices.push(b, c, d)
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return createMeshFromArrays({
|
|
79
|
+
positions,
|
|
80
|
+
normals,
|
|
81
|
+
uvs,
|
|
82
|
+
indices
|
|
83
|
+
})
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
import { Vector3 } from "../../math/index.js"
|
|
3
|
+
import { MeshBuilder } from "./base.js"
|
|
4
|
+
import { PolyhedronMeshBuilder } from "./polyhedron.js"
|
|
5
|
+
|
|
6
|
+
const octahedronVertices = [
|
|
7
|
+
new Vector3(1, 0, 0),
|
|
8
|
+
new Vector3(-1, 0, 0),
|
|
9
|
+
new Vector3(0, 1, 0),
|
|
10
|
+
new Vector3(0, -1, 0),
|
|
11
|
+
new Vector3(0, 0, 1),
|
|
12
|
+
new Vector3(0, 0, -1)
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
const octahedronFaces = [
|
|
16
|
+
[0, 2, 4],
|
|
17
|
+
[2, 1, 4],
|
|
18
|
+
[1, 3, 4],
|
|
19
|
+
[3, 0, 4],
|
|
20
|
+
[2, 0, 5],
|
|
21
|
+
[1, 2, 5],
|
|
22
|
+
[3, 1, 5],
|
|
23
|
+
[0, 3, 5]
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
export class OctahedronMeshBuilder extends MeshBuilder {
|
|
27
|
+
radius = 0.5
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @type {Set<number>}
|
|
31
|
+
*/
|
|
32
|
+
excludeFaces = new Set()
|
|
33
|
+
|
|
34
|
+
/** @override */
|
|
35
|
+
build() {
|
|
36
|
+
const builder = new PolyhedronMeshBuilder()
|
|
37
|
+
builder.vertices = octahedronVertices
|
|
38
|
+
builder.faces = octahedronFaces
|
|
39
|
+
builder.excludeFaces = this.excludeFaces
|
|
40
|
+
builder.radius = this.radius
|
|
41
|
+
return builder.build()
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
import { Vector3 } from "../../math/index.js"
|
|
3
|
+
import { assert } from "../../utils/index.js"
|
|
4
|
+
import { MeshBuilder } from "./base.js"
|
|
5
|
+
import { createMeshFromArrays } from "./geometry.js"
|
|
6
|
+
import { faceNormal, projectFaceUVs, pushTriangle } from "./utils.js"
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Shared builder for polyhedron meshes.
|
|
10
|
+
* Assign vertices, faces, and optional excluded face indices before calling build.
|
|
11
|
+
*/
|
|
12
|
+
export class PolyhedronMeshBuilder extends MeshBuilder {
|
|
13
|
+
/**
|
|
14
|
+
* @type {import("../../math/index.js").Vector3[]}
|
|
15
|
+
*/
|
|
16
|
+
vertices = []
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @type {number[][]}
|
|
20
|
+
*/
|
|
21
|
+
faces = []
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Face indices to exclude from the final mesh.
|
|
25
|
+
* @type {Set<number>}
|
|
26
|
+
*/
|
|
27
|
+
excludeFaces = new Set()
|
|
28
|
+
|
|
29
|
+
radius = 0.5
|
|
30
|
+
|
|
31
|
+
/** @override */
|
|
32
|
+
build() {
|
|
33
|
+
const scaledVertices = this.vertices.map((vertex) =>
|
|
34
|
+
vertex.clone().normalize().multiplyScalar(this.radius)
|
|
35
|
+
)
|
|
36
|
+
const includedFaces = this.faces.filter((_, faceIndex) =>
|
|
37
|
+
!this.excludeFaces.has(faceIndex)
|
|
38
|
+
)
|
|
39
|
+
/** @type {number[]} */
|
|
40
|
+
const positions = []
|
|
41
|
+
/** @type {number[]} */
|
|
42
|
+
const normals = []
|
|
43
|
+
/** @type {number[]} */
|
|
44
|
+
const uvs = []
|
|
45
|
+
/** @type {number[]} */
|
|
46
|
+
const indices = []
|
|
47
|
+
|
|
48
|
+
for (const face of includedFaces) {
|
|
49
|
+
if (face.length < 3) {
|
|
50
|
+
continue
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const faceVertices = face.map((index) => {
|
|
54
|
+
const sourceVertex = scaledVertices[index]
|
|
55
|
+
assert(sourceVertex, `Missing polyhedron vertex at index ${index}`)
|
|
56
|
+
return sourceVertex.clone()
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
const faceCenter = new Vector3()
|
|
60
|
+
for (const vertex of faceVertices) {
|
|
61
|
+
faceCenter.add(vertex)
|
|
62
|
+
}
|
|
63
|
+
faceCenter.divideScalar(faceVertices.length)
|
|
64
|
+
|
|
65
|
+
let firstVertex = faceVertices[0]
|
|
66
|
+
let secondVertex = faceVertices[1]
|
|
67
|
+
let thirdVertex = faceVertices[2]
|
|
68
|
+
assert(firstVertex, "Polyhedron face requires at least three vertices")
|
|
69
|
+
assert(secondVertex, "Polyhedron face requires at least three vertices")
|
|
70
|
+
assert(thirdVertex, "Polyhedron face requires at least three vertices")
|
|
71
|
+
|
|
72
|
+
let normal = faceNormal(firstVertex, secondVertex, thirdVertex)
|
|
73
|
+
if (normal.dot(faceCenter) < 0) {
|
|
74
|
+
faceVertices.reverse()
|
|
75
|
+
firstVertex = faceVertices[0]
|
|
76
|
+
secondVertex = faceVertices[1]
|
|
77
|
+
thirdVertex = faceVertices[2]
|
|
78
|
+
assert(firstVertex, "Polyhedron face requires at least three vertices")
|
|
79
|
+
assert(secondVertex, "Polyhedron face requires at least three vertices")
|
|
80
|
+
assert(thirdVertex, "Polyhedron face requires at least three vertices")
|
|
81
|
+
normal = faceNormal(firstVertex, secondVertex, thirdVertex)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const faceUvs = projectFaceUVs(faceVertices, normal)
|
|
85
|
+
|
|
86
|
+
for (let i = 1; i < faceVertices.length - 1; i++) {
|
|
87
|
+
const currentVertex = faceVertices[i]
|
|
88
|
+
const nextVertex = faceVertices[i + 1]
|
|
89
|
+
const firstUv = faceUvs[0]
|
|
90
|
+
const currentUv = faceUvs[i]
|
|
91
|
+
const nextUv = faceUvs[i + 1]
|
|
92
|
+
assert(currentVertex, `Missing polyhedron face vertex at index ${i}`)
|
|
93
|
+
assert(nextVertex, `Missing polyhedron face vertex at index ${i + 1}`)
|
|
94
|
+
assert(firstUv, "Polyhedron face requires at least three UV coordinates")
|
|
95
|
+
assert(currentUv, `Missing polyhedron face UV at index ${i}`)
|
|
96
|
+
assert(nextUv, `Missing polyhedron face UV at index ${i + 1}`)
|
|
97
|
+
|
|
98
|
+
pushTriangle(
|
|
99
|
+
positions,
|
|
100
|
+
normals,
|
|
101
|
+
uvs,
|
|
102
|
+
indices,
|
|
103
|
+
firstVertex,
|
|
104
|
+
currentVertex,
|
|
105
|
+
nextVertex,
|
|
106
|
+
normal,
|
|
107
|
+
firstUv,
|
|
108
|
+
currentUv,
|
|
109
|
+
nextUv
|
|
110
|
+
)
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return createMeshFromArrays({
|
|
115
|
+
positions,
|
|
116
|
+
normals,
|
|
117
|
+
uvs,
|
|
118
|
+
indices
|
|
119
|
+
})
|
|
120
|
+
}
|
|
121
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
import { MeshBuilder } from "./base.js"
|
|
3
|
+
import { ExtrudeMeshBuilder } from "./extrude.js"
|
|
4
|
+
import { regularPolygonPoints } from "./geometry.js"
|
|
5
|
+
|
|
6
|
+
export class PrismMeshBuilder extends MeshBuilder {
|
|
7
|
+
sides = 6
|
|
8
|
+
radius = 0.5
|
|
9
|
+
depth = 1
|
|
10
|
+
rotation = 0
|
|
11
|
+
|
|
12
|
+
/** @override */
|
|
13
|
+
build() {
|
|
14
|
+
const builder = new ExtrudeMeshBuilder()
|
|
15
|
+
builder.contour = regularPolygonPoints(this.sides, this.radius, this.rotation)
|
|
16
|
+
builder.depth = this.depth
|
|
17
|
+
return builder.build()
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
import { Vector2, Vector3 } from "../../math/index.js"
|
|
3
|
+
import { MeshBuilder } from "./base.js"
|
|
4
|
+
import { createMeshFromArrays, regularPolygonPoints, signedArea2D } from "./geometry.js"
|
|
5
|
+
import { assert } from "../../utils/index.js"
|
|
6
|
+
import { faceNormal, getBounds, projectUV, pushTriangle } from "./utils.js"
|
|
7
|
+
|
|
8
|
+
export class PyramidMeshBuilder extends MeshBuilder {
|
|
9
|
+
sides = 4
|
|
10
|
+
radius = 0.5
|
|
11
|
+
height = 1
|
|
12
|
+
rotation = 0
|
|
13
|
+
|
|
14
|
+
/** @override */
|
|
15
|
+
build() {
|
|
16
|
+
const contour = regularPolygonPoints(this.sides, this.radius, this.rotation)
|
|
17
|
+
if (contour.length < 3) {
|
|
18
|
+
return createMeshFromArrays({ positions: [] })
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (signedArea2D(contour) < 0) {
|
|
22
|
+
contour.reverse()
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** @type {number[]} */
|
|
26
|
+
const positions = []
|
|
27
|
+
/** @type {number[]} */
|
|
28
|
+
const normals = []
|
|
29
|
+
/** @type {number[]} */
|
|
30
|
+
const uvs = []
|
|
31
|
+
/** @type {number[]} */
|
|
32
|
+
const indices = []
|
|
33
|
+
const halfHeight = this.height * 0.5
|
|
34
|
+
const apex = new Vector3(0, 0, halfHeight)
|
|
35
|
+
const baseCenter = new Vector3(0, 0, -halfHeight)
|
|
36
|
+
const bounds = getBounds(contour)
|
|
37
|
+
|
|
38
|
+
for (let i = 0; i < contour.length; i++) {
|
|
39
|
+
const current = contour[i]
|
|
40
|
+
assert(current, `Missing pyramid contour point at index ${i}`)
|
|
41
|
+
const next = contour[(i + 1) % contour.length]
|
|
42
|
+
assert(next, `Missing pyramid contour point at index ${(i + 1) % contour.length}`)
|
|
43
|
+
const currentTop = new Vector3(current.x, current.y, -halfHeight)
|
|
44
|
+
const nextTop = new Vector3(next.x, next.y, -halfHeight)
|
|
45
|
+
const normal = faceNormal(currentTop, nextTop, apex)
|
|
46
|
+
|
|
47
|
+
pushTriangle(
|
|
48
|
+
positions,
|
|
49
|
+
normals,
|
|
50
|
+
uvs,
|
|
51
|
+
indices,
|
|
52
|
+
currentTop,
|
|
53
|
+
nextTop,
|
|
54
|
+
apex,
|
|
55
|
+
normal,
|
|
56
|
+
projectUV(current, bounds),
|
|
57
|
+
projectUV(next, bounds),
|
|
58
|
+
new Vector2(0.5, 0.5)
|
|
59
|
+
)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
for (let i = 0; i < contour.length; i++) {
|
|
63
|
+
const current = contour[i]
|
|
64
|
+
assert(current, `Missing pyramid contour point at index ${i}`)
|
|
65
|
+
const next = contour[(i + 1) % contour.length]
|
|
66
|
+
assert(next, `Missing pyramid contour point at index ${(i + 1) % contour.length}`)
|
|
67
|
+
|
|
68
|
+
pushTriangle(
|
|
69
|
+
positions,
|
|
70
|
+
normals,
|
|
71
|
+
uvs,
|
|
72
|
+
indices,
|
|
73
|
+
baseCenter,
|
|
74
|
+
new Vector3(next.x, next.y, -halfHeight),
|
|
75
|
+
new Vector3(current.x, current.y, -halfHeight),
|
|
76
|
+
new Vector3(0, 0, -1),
|
|
77
|
+
new Vector2(0.5, 0.5),
|
|
78
|
+
projectUV(next, bounds),
|
|
79
|
+
projectUV(current, bounds)
|
|
80
|
+
)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return createMeshFromArrays({
|
|
84
|
+
positions,
|
|
85
|
+
normals,
|
|
86
|
+
uvs,
|
|
87
|
+
indices
|
|
88
|
+
})
|
|
89
|
+
}
|
|
90
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
import { Vector2, Vector3 } from "../../math/index.js"
|
|
3
|
+
import { MeshBuilder } from "./base.js"
|
|
4
|
+
import { createMeshFromArrays } from "./geometry.js"
|
|
5
|
+
import { pushVertex } from "./utils.js"
|
|
6
|
+
|
|
7
|
+
export class RingMeshBuilder extends MeshBuilder {
|
|
8
|
+
innerRadius = 0.25
|
|
9
|
+
outerRadius = 0.5
|
|
10
|
+
thickness = 0.1
|
|
11
|
+
radialSegments = 32
|
|
12
|
+
|
|
13
|
+
/** @override */
|
|
14
|
+
build() {
|
|
15
|
+
/** @type {number[]} */
|
|
16
|
+
const positions = []
|
|
17
|
+
/** @type {number[]} */
|
|
18
|
+
const normals = []
|
|
19
|
+
/** @type {number[]} */
|
|
20
|
+
const uvs = []
|
|
21
|
+
/** @type {number[]} */
|
|
22
|
+
const indices = []
|
|
23
|
+
const halfThickness = this.thickness * 0.5
|
|
24
|
+
const innerRadius = Math.min(this.innerRadius, this.outerRadius)
|
|
25
|
+
const outerRadius = Math.max(this.innerRadius, this.outerRadius)
|
|
26
|
+
const step = (Math.PI * 2) / this.radialSegments
|
|
27
|
+
const topNormal = new Vector3(0, 1, 0)
|
|
28
|
+
const bottomNormal = new Vector3(0, -1, 0)
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @param {Vector3} point
|
|
32
|
+
* @returns {Vector2}
|
|
33
|
+
*/
|
|
34
|
+
const topUv = (point) => new Vector2(
|
|
35
|
+
(point.x + outerRadius) / (outerRadius * 2),
|
|
36
|
+
(point.z + outerRadius) / (outerRadius * 2)
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
for (let segment = 0; segment < this.radialSegments; segment++) {
|
|
40
|
+
const angle0 = segment * step
|
|
41
|
+
const angle1 = (segment + 1) * step
|
|
42
|
+
const cos0 = Math.cos(angle0)
|
|
43
|
+
const sin0 = Math.sin(angle0)
|
|
44
|
+
const cos1 = Math.cos(angle1)
|
|
45
|
+
const sin1 = Math.sin(angle1)
|
|
46
|
+
|
|
47
|
+
const outer0Top = new Vector3(outerRadius * cos0, halfThickness, outerRadius * sin0)
|
|
48
|
+
const outer1Top = new Vector3(outerRadius * cos1, halfThickness, outerRadius * sin1)
|
|
49
|
+
const inner0Top = new Vector3(innerRadius * cos0, halfThickness, innerRadius * sin0)
|
|
50
|
+
const inner1Top = new Vector3(innerRadius * cos1, halfThickness, innerRadius * sin1)
|
|
51
|
+
|
|
52
|
+
const outer0Bottom = new Vector3(outerRadius * cos0, -halfThickness, outerRadius * sin0)
|
|
53
|
+
const outer1Bottom = new Vector3(outerRadius * cos1, -halfThickness, outerRadius * sin1)
|
|
54
|
+
const inner0Bottom = new Vector3(innerRadius * cos0, -halfThickness, innerRadius * sin0)
|
|
55
|
+
const inner1Bottom = new Vector3(innerRadius * cos1, -halfThickness, innerRadius * sin1)
|
|
56
|
+
|
|
57
|
+
const outerNormal0 = new Vector3(cos0, 0, sin0)
|
|
58
|
+
const outerNormal1 = new Vector3(cos1, 0, sin1)
|
|
59
|
+
const innerNormal0 = new Vector3(-cos0, 0, -sin0)
|
|
60
|
+
const innerNormal1 = new Vector3(-cos1, 0, -sin1)
|
|
61
|
+
|
|
62
|
+
const outerUv0 = segment / this.radialSegments
|
|
63
|
+
const outerUv1 = (segment + 1) / this.radialSegments
|
|
64
|
+
|
|
65
|
+
// Top face
|
|
66
|
+
pushVertex(positions, normals, uvs, indices, outer0Top, topNormal, topUv(outer0Top))
|
|
67
|
+
pushVertex(positions, normals, uvs, indices, inner0Top, topNormal, topUv(inner0Top))
|
|
68
|
+
pushVertex(positions, normals, uvs, indices, outer1Top, topNormal, topUv(outer1Top))
|
|
69
|
+
|
|
70
|
+
pushVertex(positions, normals, uvs, indices, outer1Top, topNormal, topUv(outer1Top))
|
|
71
|
+
pushVertex(positions, normals, uvs, indices, inner0Top, topNormal, topUv(inner0Top))
|
|
72
|
+
pushVertex(positions, normals, uvs, indices, inner1Top, topNormal, topUv(inner1Top))
|
|
73
|
+
|
|
74
|
+
// Bottom face
|
|
75
|
+
pushVertex(positions, normals, uvs, indices, outer0Bottom, bottomNormal, topUv(outer0Bottom))
|
|
76
|
+
pushVertex(positions, normals, uvs, indices, outer1Bottom, bottomNormal, topUv(outer1Bottom))
|
|
77
|
+
pushVertex(positions, normals, uvs, indices, inner0Bottom, bottomNormal, topUv(inner0Bottom))
|
|
78
|
+
|
|
79
|
+
pushVertex(positions, normals, uvs, indices, outer1Bottom, bottomNormal, topUv(outer1Bottom))
|
|
80
|
+
pushVertex(positions, normals, uvs, indices, inner1Bottom, bottomNormal, topUv(inner1Bottom))
|
|
81
|
+
pushVertex(positions, normals, uvs, indices, inner0Bottom, bottomNormal, topUv(inner0Bottom))
|
|
82
|
+
|
|
83
|
+
// Outer wall
|
|
84
|
+
pushVertex(positions, normals, uvs, indices, outer0Top, outerNormal0, new Vector2(outerUv0, 1))
|
|
85
|
+
pushVertex(positions, normals, uvs, indices, outer1Top, outerNormal1, new Vector2(outerUv1, 1))
|
|
86
|
+
pushVertex(positions, normals, uvs, indices, outer0Bottom, outerNormal0, new Vector2(outerUv0, 0))
|
|
87
|
+
|
|
88
|
+
pushVertex(positions, normals, uvs, indices, outer1Top, outerNormal1, new Vector2(outerUv1, 1))
|
|
89
|
+
pushVertex(positions, normals, uvs, indices, outer1Bottom, outerNormal1, new Vector2(outerUv1, 0))
|
|
90
|
+
pushVertex(positions, normals, uvs, indices, outer0Bottom, outerNormal0, new Vector2(outerUv0, 0))
|
|
91
|
+
|
|
92
|
+
// Inner wall
|
|
93
|
+
pushVertex(positions, normals, uvs, indices, inner0Top, innerNormal0, new Vector2(outerUv0, 1))
|
|
94
|
+
pushVertex(positions, normals, uvs, indices, inner0Bottom, innerNormal0, new Vector2(outerUv0, 0))
|
|
95
|
+
pushVertex(positions, normals, uvs, indices, inner1Top, innerNormal1, new Vector2(outerUv1, 1))
|
|
96
|
+
|
|
97
|
+
pushVertex(positions, normals, uvs, indices, inner1Top, innerNormal1, new Vector2(outerUv1, 1))
|
|
98
|
+
pushVertex(positions, normals, uvs, indices, inner0Bottom, innerNormal0, new Vector2(outerUv0, 0))
|
|
99
|
+
pushVertex(positions, normals, uvs, indices, inner1Bottom, innerNormal1, new Vector2(outerUv1, 0))
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return createMeshFromArrays({
|
|
103
|
+
positions,
|
|
104
|
+
normals,
|
|
105
|
+
uvs,
|
|
106
|
+
indices
|
|
107
|
+
})
|
|
108
|
+
}
|
|
109
|
+
}
|