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,69 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
import { Vector2, Vector3 } from "../../math/index.js"
|
|
3
|
+
import { MeshBuilder } from "./base.js"
|
|
4
|
+
import { createMeshFromArrays } from "./geometry.js"
|
|
5
|
+
|
|
6
|
+
export class TorusMeshBuilder extends MeshBuilder {
|
|
7
|
+
radius = 0.75
|
|
8
|
+
tubeRadius = 0.25
|
|
9
|
+
radialSegments = 32
|
|
10
|
+
tubularSegments = 16
|
|
11
|
+
|
|
12
|
+
/** @override */
|
|
13
|
+
build() {
|
|
14
|
+
const positions = []
|
|
15
|
+
const normals = []
|
|
16
|
+
const uvs = []
|
|
17
|
+
const indices = []
|
|
18
|
+
|
|
19
|
+
for (let tube = 0; tube <= this.tubularSegments; tube++) {
|
|
20
|
+
const v = tube / this.tubularSegments
|
|
21
|
+
const phi = v * Math.PI * 2
|
|
22
|
+
const cosphi = Math.cos(phi)
|
|
23
|
+
const sinphi = Math.sin(phi)
|
|
24
|
+
|
|
25
|
+
for (let radial = 0; radial <= this.radialSegments; radial++) {
|
|
26
|
+
const u = radial / this.radialSegments
|
|
27
|
+
const theta = u * Math.PI * 2
|
|
28
|
+
const costheta = Math.cos(theta)
|
|
29
|
+
const sintheta = Math.sin(theta)
|
|
30
|
+
|
|
31
|
+
const ringRadius = this.radius + this.tubeRadius * cosphi
|
|
32
|
+
const position = new Vector3(
|
|
33
|
+
ringRadius * costheta,
|
|
34
|
+
this.tubeRadius * sinphi,
|
|
35
|
+
ringRadius * sintheta
|
|
36
|
+
)
|
|
37
|
+
const normal = new Vector3(
|
|
38
|
+
cosphi * costheta,
|
|
39
|
+
sinphi,
|
|
40
|
+
cosphi * sintheta
|
|
41
|
+
)
|
|
42
|
+
const uv = new Vector2(1 - u, 1 - v)
|
|
43
|
+
|
|
44
|
+
positions.push(position.x, position.y, position.z)
|
|
45
|
+
normals.push(normal.x, normal.y, normal.z)
|
|
46
|
+
uvs.push(uv.x, uv.y)
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
for (let tube = 0; tube < this.tubularSegments; tube++) {
|
|
51
|
+
for (let radial = 0; radial < this.radialSegments; radial++) {
|
|
52
|
+
const a = tube * (this.radialSegments + 1) + radial
|
|
53
|
+
const b = (tube + 1) * (this.radialSegments + 1) + radial
|
|
54
|
+
const c = (tube + 1) * (this.radialSegments + 1) + radial + 1
|
|
55
|
+
const d = tube * (this.radialSegments + 1) + radial + 1
|
|
56
|
+
|
|
57
|
+
indices.push(a, b, d)
|
|
58
|
+
indices.push(b, c, d)
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return createMeshFromArrays({
|
|
63
|
+
positions,
|
|
64
|
+
normals,
|
|
65
|
+
uvs,
|
|
66
|
+
indices
|
|
67
|
+
})
|
|
68
|
+
}
|
|
69
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
import { Vector2, Vector3 } from "../../math/index.js"
|
|
3
|
+
import { MeshBuilder } from "./base.js"
|
|
4
|
+
import { createMeshFromArrays } from "./geometry.js"
|
|
5
|
+
|
|
6
|
+
export class TerrainMeshBuilder extends MeshBuilder {
|
|
7
|
+
width = 1
|
|
8
|
+
depth = 1
|
|
9
|
+
widthSegments = 32
|
|
10
|
+
depthSegments = 32
|
|
11
|
+
heightScale = 1
|
|
12
|
+
/**
|
|
13
|
+
* @type {(x: number, z: number) => number}
|
|
14
|
+
*/
|
|
15
|
+
sampleHeight = () => 0
|
|
16
|
+
|
|
17
|
+
/** @override */
|
|
18
|
+
build() {
|
|
19
|
+
const positions = []
|
|
20
|
+
const normals = []
|
|
21
|
+
const uvs = []
|
|
22
|
+
const indices = []
|
|
23
|
+
const widthStep = this.width / this.widthSegments
|
|
24
|
+
const depthStep = this.depth / this.depthSegments
|
|
25
|
+
const halfWidth = this.width * 0.5
|
|
26
|
+
const halfDepth = this.depth * 0.5
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @param {number} x
|
|
30
|
+
* @param {number} z
|
|
31
|
+
* @returns {number}
|
|
32
|
+
*/
|
|
33
|
+
const heightAt = (x, z) => this.sampleHeight(x, z) * this.heightScale
|
|
34
|
+
|
|
35
|
+
for (let zIndex = 0; zIndex <= this.depthSegments; zIndex++) {
|
|
36
|
+
const v = zIndex / this.depthSegments
|
|
37
|
+
const z = -halfDepth + v * this.depth
|
|
38
|
+
|
|
39
|
+
for (let xIndex = 0; xIndex <= this.widthSegments; xIndex++) {
|
|
40
|
+
const u = xIndex / this.widthSegments
|
|
41
|
+
const x = -halfWidth + u * this.width
|
|
42
|
+
const height = heightAt(x, z)
|
|
43
|
+
|
|
44
|
+
const hL = heightAt(x - widthStep, z)
|
|
45
|
+
const hR = heightAt(x + widthStep, z)
|
|
46
|
+
const hD = heightAt(x, z - depthStep)
|
|
47
|
+
const hU = heightAt(x, z + depthStep)
|
|
48
|
+
const normal = new Vector3(
|
|
49
|
+
(hL - hR) / (widthStep || 1),
|
|
50
|
+
2,
|
|
51
|
+
(hD - hU) / (depthStep || 1)
|
|
52
|
+
).normalize()
|
|
53
|
+
const uv = new Vector2(u, 1 - v)
|
|
54
|
+
|
|
55
|
+
positions.push(x, height, z)
|
|
56
|
+
normals.push(normal.x, normal.y, normal.z)
|
|
57
|
+
uvs.push(uv.x, uv.y)
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
for (let zIndex = 0; zIndex < this.depthSegments; zIndex++) {
|
|
62
|
+
for (let xIndex = 0; xIndex < this.widthSegments; xIndex++) {
|
|
63
|
+
const a = zIndex * (this.widthSegments + 1) + xIndex
|
|
64
|
+
const b = (zIndex + 1) * (this.widthSegments + 1) + xIndex
|
|
65
|
+
const c = (zIndex + 1) * (this.widthSegments + 1) + xIndex + 1
|
|
66
|
+
const d = zIndex * (this.widthSegments + 1) + xIndex + 1
|
|
67
|
+
|
|
68
|
+
indices.push(a, b, d)
|
|
69
|
+
indices.push(b, c, d)
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return createMeshFromArrays({
|
|
74
|
+
positions,
|
|
75
|
+
normals,
|
|
76
|
+
uvs,
|
|
77
|
+
indices
|
|
78
|
+
})
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
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 tetrahedronVertices = [
|
|
7
|
+
new Vector3(1, 1, 1),
|
|
8
|
+
new Vector3(-1, -1, 1),
|
|
9
|
+
new Vector3(-1, 1, -1),
|
|
10
|
+
new Vector3(1, -1, -1)
|
|
11
|
+
]
|
|
12
|
+
|
|
13
|
+
const tetrahedronFaces = [
|
|
14
|
+
[0, 2, 1],
|
|
15
|
+
[0, 1, 3],
|
|
16
|
+
[0, 3, 2],
|
|
17
|
+
[1, 2, 3]
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
export class TetrahedronMeshBuilder extends MeshBuilder {
|
|
21
|
+
radius = 0.5
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @type {Set<number>}
|
|
25
|
+
*/
|
|
26
|
+
excludeFaces = new Set()
|
|
27
|
+
|
|
28
|
+
/** @override */
|
|
29
|
+
build() {
|
|
30
|
+
const builder = new PolyhedronMeshBuilder()
|
|
31
|
+
builder.vertices = tetrahedronVertices
|
|
32
|
+
builder.faces = tetrahedronFaces
|
|
33
|
+
builder.excludeFaces = this.excludeFaces
|
|
34
|
+
builder.radius = this.radius
|
|
35
|
+
return builder.build()
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
import { Vector3 } from "../../math/index.js"
|
|
3
|
+
import { MeshBuilder } from "./base.js"
|
|
4
|
+
import { TubeMeshBuilder } from "./tube.js"
|
|
5
|
+
|
|
6
|
+
export class TorusKnotMeshBuilder extends MeshBuilder {
|
|
7
|
+
radius = 0.75
|
|
8
|
+
knotRadius = 0.25
|
|
9
|
+
tubeRadius = 0.08
|
|
10
|
+
p = 2
|
|
11
|
+
q = 3
|
|
12
|
+
radialSegments = 8
|
|
13
|
+
pathSegments = 256
|
|
14
|
+
|
|
15
|
+
/** @override */
|
|
16
|
+
build() {
|
|
17
|
+
/** @type {Vector3[]} */
|
|
18
|
+
const points = []
|
|
19
|
+
for (let i = 0; i < this.pathSegments; i++) {
|
|
20
|
+
const t = (i / this.pathSegments) * Math.PI * 2
|
|
21
|
+
const radial = this.radius + this.knotRadius * Math.cos(this.q * t)
|
|
22
|
+
points.push(new Vector3(
|
|
23
|
+
radial * Math.cos(this.p * t),
|
|
24
|
+
radial * Math.sin(this.p * t),
|
|
25
|
+
this.knotRadius * Math.sin(this.q * t)
|
|
26
|
+
))
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const builder = new TubeMeshBuilder()
|
|
30
|
+
builder.points = points
|
|
31
|
+
builder.radius = this.tubeRadius
|
|
32
|
+
builder.radialSegments = this.radialSegments
|
|
33
|
+
builder.closed = true
|
|
34
|
+
return builder.build()
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
import { Quaternion, 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 TubeMeshBuilder extends MeshBuilder {
|
|
8
|
+
/**
|
|
9
|
+
* Path points in world space.
|
|
10
|
+
* @type {Vector3[]}
|
|
11
|
+
*/
|
|
12
|
+
points = []
|
|
13
|
+
radius = 0.1
|
|
14
|
+
radialSegments = 8
|
|
15
|
+
closed = false
|
|
16
|
+
|
|
17
|
+
/** @override */
|
|
18
|
+
build() {
|
|
19
|
+
const points = this.points
|
|
20
|
+
|
|
21
|
+
if (points.length < 2) {
|
|
22
|
+
return createMeshFromArrays({ positions: [] })
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const { normals: frameNormals, binormals } = buildTubeFrames(points, this.closed)
|
|
26
|
+
const positions = []
|
|
27
|
+
const normals = []
|
|
28
|
+
const uvs = []
|
|
29
|
+
const indices = []
|
|
30
|
+
const ringCount = this.radialSegments + 1
|
|
31
|
+
|
|
32
|
+
for (let i = 0; i < points.length; i++) {
|
|
33
|
+
const point = points[i]
|
|
34
|
+
assert(point, `Missing tube path point at index ${i}`)
|
|
35
|
+
const normal = frameNormals[i]
|
|
36
|
+
assert(normal, `Missing tube frame normal at index ${i}`)
|
|
37
|
+
const binormal = binormals[i]
|
|
38
|
+
assert(binormal, `Missing tube frame binormal at index ${i}`)
|
|
39
|
+
|
|
40
|
+
for (let segment = 0; segment <= this.radialSegments; segment++) {
|
|
41
|
+
const t = segment / this.radialSegments
|
|
42
|
+
const angle = t * Math.PI * 2
|
|
43
|
+
const cos = Math.cos(angle)
|
|
44
|
+
const sin = Math.sin(angle)
|
|
45
|
+
const offset = normal.clone().multiplyScalar(cos * this.radius)
|
|
46
|
+
.add(binormal.clone().multiplyScalar(sin * this.radius))
|
|
47
|
+
const position = point.clone().add(offset)
|
|
48
|
+
const surfaceNormal = offset.clone().normalize()
|
|
49
|
+
|
|
50
|
+
positions.push(position.x, position.y, position.z)
|
|
51
|
+
normals.push(surfaceNormal.x, surfaceNormal.y, surfaceNormal.z)
|
|
52
|
+
uvs.push(t, i / (points.length - 1))
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const segmentCount = this.closed ? points.length : points.length - 1
|
|
57
|
+
|
|
58
|
+
for (let i = 0; i < segmentCount; i++) {
|
|
59
|
+
const nextRow = (i + 1) % points.length
|
|
60
|
+
for (let segment = 0; segment < this.radialSegments; segment++) {
|
|
61
|
+
const a = i * ringCount + segment
|
|
62
|
+
const b = nextRow * ringCount + segment
|
|
63
|
+
const c = nextRow * ringCount + segment + 1
|
|
64
|
+
const d = i * ringCount + segment + 1
|
|
65
|
+
|
|
66
|
+
indices.push(a, b, d)
|
|
67
|
+
indices.push(b, c, d)
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return createMeshFromArrays({
|
|
72
|
+
positions,
|
|
73
|
+
normals,
|
|
74
|
+
uvs,
|
|
75
|
+
indices
|
|
76
|
+
})
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* @typedef {{
|
|
82
|
+
* tangents: Vector3[],
|
|
83
|
+
* normals: Vector3[],
|
|
84
|
+
* binormals: Vector3[]
|
|
85
|
+
* }} TubeFrames
|
|
86
|
+
*/
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Builds a moving frame for a path.
|
|
90
|
+
*
|
|
91
|
+
* @param {Vector3[]} points
|
|
92
|
+
* @param {boolean} closed
|
|
93
|
+
* @returns {TubeFrames}
|
|
94
|
+
*/
|
|
95
|
+
function buildTubeFrames(points, closed) {
|
|
96
|
+
/** @type {Vector3[]} */
|
|
97
|
+
const tangents = []
|
|
98
|
+
/** @type {Vector3[]} */
|
|
99
|
+
const normals = []
|
|
100
|
+
/** @type {Vector3[]} */
|
|
101
|
+
const binormals = []
|
|
102
|
+
|
|
103
|
+
for (let i = 0; i < points.length; i++) {
|
|
104
|
+
const previous = closed || i > 0
|
|
105
|
+
? points[(i - 1 + points.length) % points.length]
|
|
106
|
+
: points[i]
|
|
107
|
+
assert(
|
|
108
|
+
previous,
|
|
109
|
+
`Missing tube path point at index ${closed || i > 0 ? (i - 1 + points.length) % points.length : i}`
|
|
110
|
+
)
|
|
111
|
+
const next = closed || i < points.length - 1
|
|
112
|
+
? points[(i + 1) % points.length]
|
|
113
|
+
: points[i]
|
|
114
|
+
assert(
|
|
115
|
+
next,
|
|
116
|
+
`Missing tube path point at index ${closed || i < points.length - 1 ? (i + 1) % points.length : i}`
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
const tangent = next.clone().subtract(previous).normalize()
|
|
120
|
+
tangents.push(tangent)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
const firstTangent = tangents[0]
|
|
124
|
+
assert(firstTangent, "Tube path requires at least two points")
|
|
125
|
+
const firstTangentClone = firstTangent.clone()
|
|
126
|
+
let helper = Math.abs(firstTangent.y) < 0.9
|
|
127
|
+
? new Vector3(0, 1, 0)
|
|
128
|
+
: new Vector3(1, 0, 0)
|
|
129
|
+
let normal = helper.clone().cross(firstTangentClone)
|
|
130
|
+
|
|
131
|
+
if (normal.magnitudeSquared() < 1e-8) {
|
|
132
|
+
helper = new Vector3(0, 0, 1)
|
|
133
|
+
normal = helper.clone().cross(firstTangentClone)
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
normal.normalize()
|
|
137
|
+
let binormal = firstTangentClone.clone().cross(normal).normalize()
|
|
138
|
+
normal = binormal.clone().cross(firstTangentClone).normalize()
|
|
139
|
+
|
|
140
|
+
normals.push(normal)
|
|
141
|
+
binormals.push(binormal)
|
|
142
|
+
|
|
143
|
+
for (let i = 1; i < points.length; i++) {
|
|
144
|
+
const previousTangent = tangents[i - 1]
|
|
145
|
+
assert(previousTangent, `Missing previous tangent at index ${i - 1}`)
|
|
146
|
+
const currentTangent = tangents[i]
|
|
147
|
+
assert(currentTangent, `Missing tangent at index ${i}`)
|
|
148
|
+
const axis = previousTangent.clone().cross(currentTangent)
|
|
149
|
+
const cosine = Math.max(-1, Math.min(1, previousTangent.dot(currentTangent)))
|
|
150
|
+
|
|
151
|
+
if (axis.magnitudeSquared() < 1e-8) {
|
|
152
|
+
if (cosine > 0.999999) {
|
|
153
|
+
const previousNormal = normals[i - 1]
|
|
154
|
+
assert(previousNormal, `Missing frame normal at index ${i - 1}`)
|
|
155
|
+
const previousBinormal = binormals[i - 1]
|
|
156
|
+
assert(previousBinormal, `Missing frame binormal at index ${i - 1}`)
|
|
157
|
+
normals.push(previousNormal.clone())
|
|
158
|
+
binormals.push(previousBinormal.clone())
|
|
159
|
+
continue
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const fallback = Math.abs(previousTangent.x) < 0.9
|
|
163
|
+
? new Vector3(1, 0, 0)
|
|
164
|
+
: new Vector3(0, 1, 0)
|
|
165
|
+
axis.copy(previousTangent).cross(fallback)
|
|
166
|
+
|
|
167
|
+
if (axis.magnitudeSquared() < 1e-8) {
|
|
168
|
+
axis.copy(previousTangent).cross(new Vector3(0, 0, 1))
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
axis.normalize()
|
|
172
|
+
} else {
|
|
173
|
+
axis.normalize()
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const angle = Math.acos(cosine)
|
|
177
|
+
|
|
178
|
+
if (axis.magnitudeSquared() < 1e-8) {
|
|
179
|
+
const previousNormal = normals[i - 1]
|
|
180
|
+
assert(previousNormal, `Missing frame normal at index ${i - 1}`)
|
|
181
|
+
const previousBinormal = binormals[i - 1]
|
|
182
|
+
assert(previousBinormal, `Missing frame binormal at index ${i - 1}`)
|
|
183
|
+
normals.push(previousNormal.clone())
|
|
184
|
+
binormals.push(previousBinormal.clone())
|
|
185
|
+
continue
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const rotation = Quaternion.fromAxisAngle(axis, angle)
|
|
189
|
+
|
|
190
|
+
const previousNormal = normals[i - 1]
|
|
191
|
+
assert(previousNormal, `Missing frame normal at index ${i - 1}`)
|
|
192
|
+
let nextNormal = Quaternion.transformVector3(
|
|
193
|
+
rotation,
|
|
194
|
+
previousNormal.clone()
|
|
195
|
+
)
|
|
196
|
+
nextNormal.normalize()
|
|
197
|
+
let nextBinormal = currentTangent.clone().cross(nextNormal).normalize()
|
|
198
|
+
nextNormal = nextBinormal.clone().cross(currentTangent).normalize()
|
|
199
|
+
|
|
200
|
+
normals.push(nextNormal)
|
|
201
|
+
binormals.push(nextBinormal)
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
return {
|
|
205
|
+
tangents,
|
|
206
|
+
normals,
|
|
207
|
+
binormals
|
|
208
|
+
}
|
|
209
|
+
}
|
|
@@ -1,5 +1,14 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
import { Vector2, Vector3 } from "../../math/index.js"
|
|
1
3
|
import { Mesh } from "../mesh.js"
|
|
2
4
|
|
|
5
|
+
/**
|
|
6
|
+
* @typedef {{
|
|
7
|
+
* min: Vector2,
|
|
8
|
+
* max: Vector2
|
|
9
|
+
* }} Bounds2D
|
|
10
|
+
*/
|
|
11
|
+
|
|
3
12
|
/**
|
|
4
13
|
* @param {Mesh[]} meshes
|
|
5
14
|
*/
|
|
@@ -11,10 +20,129 @@ export function mergeMeshes(meshes) {
|
|
|
11
20
|
}
|
|
12
21
|
|
|
13
22
|
for (let i = 1; i < meshes.length; i++) {
|
|
14
|
-
const nextMesh =
|
|
23
|
+
const nextMesh = /** @type {Mesh} */ (meshes[i])
|
|
15
24
|
|
|
16
25
|
result = result.merge(nextMesh)
|
|
17
26
|
}
|
|
18
27
|
|
|
19
28
|
return result
|
|
20
|
-
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @param {Vector2[]} points
|
|
33
|
+
* @returns {Bounds2D}
|
|
34
|
+
*/
|
|
35
|
+
export function getBounds(points) {
|
|
36
|
+
const min = new Vector2(Infinity, Infinity)
|
|
37
|
+
const max = new Vector2(-Infinity, -Infinity)
|
|
38
|
+
|
|
39
|
+
for (const point of points) {
|
|
40
|
+
if (point.x < min.x) min.x = point.x
|
|
41
|
+
if (point.y < min.y) min.y = point.y
|
|
42
|
+
if (point.x > max.x) max.x = point.x
|
|
43
|
+
if (point.y > max.y) max.y = point.y
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return { min, max }
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @param {Vector2} point
|
|
51
|
+
* @param {Bounds2D} bounds
|
|
52
|
+
* @returns {Vector2}
|
|
53
|
+
*/
|
|
54
|
+
export function projectUV(point, bounds) {
|
|
55
|
+
const width = bounds.max.x - bounds.min.x || 1
|
|
56
|
+
const height = bounds.max.y - bounds.min.y || 1
|
|
57
|
+
return new Vector2(
|
|
58
|
+
(point.x - bounds.min.x) / width,
|
|
59
|
+
(point.y - bounds.min.y) / height
|
|
60
|
+
)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* @param {Vector3} a
|
|
65
|
+
* @param {Vector3} b
|
|
66
|
+
* @param {Vector3} c
|
|
67
|
+
* @returns {Vector3}
|
|
68
|
+
*/
|
|
69
|
+
export function faceNormal(a, b, c) {
|
|
70
|
+
return b.clone().subtract(a).cross(c.clone().subtract(a)).normalize()
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* @param {number[]} positions
|
|
75
|
+
* @param {number[]} normals
|
|
76
|
+
* @param {number[]} uvs
|
|
77
|
+
* @param {number[]} indices
|
|
78
|
+
* @param {Vector3} position
|
|
79
|
+
* @param {Vector3} normal
|
|
80
|
+
* @param {Vector2} uv
|
|
81
|
+
*/
|
|
82
|
+
export function pushVertex(positions, normals, uvs, indices, position, normal, uv) {
|
|
83
|
+
positions.push(position.x, position.y, position.z)
|
|
84
|
+
normals.push(normal.x, normal.y, normal.z)
|
|
85
|
+
uvs.push(uv.x, uv.y)
|
|
86
|
+
indices.push(indices.length)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* @param {number[]} positions
|
|
91
|
+
* @param {number[]} normals
|
|
92
|
+
* @param {number[]} uvs
|
|
93
|
+
* @param {number[]} indices
|
|
94
|
+
* @param {Vector3} a
|
|
95
|
+
* @param {Vector3} b
|
|
96
|
+
* @param {Vector3} c
|
|
97
|
+
* @param {Vector3} normal
|
|
98
|
+
* @param {Vector2} uvA
|
|
99
|
+
* @param {Vector2} uvB
|
|
100
|
+
* @param {Vector2} uvC
|
|
101
|
+
*/
|
|
102
|
+
export function pushTriangle(positions, normals, uvs, indices, a, b, c, normal, uvA, uvB, uvC) {
|
|
103
|
+
pushVertex(positions, normals, uvs, indices, a, normal, uvA)
|
|
104
|
+
pushVertex(positions, normals, uvs, indices, b, normal, uvB)
|
|
105
|
+
pushVertex(positions, normals, uvs, indices, c, normal, uvC)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* @param {Vector3[]} vertices
|
|
110
|
+
* @param {Vector3} normal
|
|
111
|
+
* @returns {Vector2[]}
|
|
112
|
+
*/
|
|
113
|
+
export function projectFaceUVs(vertices, normal) {
|
|
114
|
+
const center = new Vector3()
|
|
115
|
+
for (const vertex of vertices) {
|
|
116
|
+
center.add(vertex)
|
|
117
|
+
}
|
|
118
|
+
center.divideScalar(vertices.length)
|
|
119
|
+
|
|
120
|
+
const helper = Math.abs(normal.x) < 0.9
|
|
121
|
+
? new Vector3(1, 0, 0)
|
|
122
|
+
: new Vector3(0, 1, 0)
|
|
123
|
+
const tangent = helper.clone().cross(normal).normalize()
|
|
124
|
+
const bitangent = normal.clone().cross(tangent).normalize()
|
|
125
|
+
|
|
126
|
+
const projected = vertices.map((vertex) => {
|
|
127
|
+
const offset = vertex.clone().subtract(center)
|
|
128
|
+
return new Vector2(offset.dot(tangent), offset.dot(bitangent))
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
const min = new Vector2(Infinity, Infinity)
|
|
132
|
+
const max = new Vector2(-Infinity, -Infinity)
|
|
133
|
+
|
|
134
|
+
for (const point of projected) {
|
|
135
|
+
if (point.x < min.x) min.x = point.x
|
|
136
|
+
if (point.y < min.y) min.y = point.y
|
|
137
|
+
if (point.x > max.x) max.x = point.x
|
|
138
|
+
if (point.y > max.y) max.y = point.y
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const width = max.x - min.x || 1
|
|
142
|
+
const height = max.y - min.y || 1
|
|
143
|
+
|
|
144
|
+
return projected.map((point) => new Vector2(
|
|
145
|
+
(point.x - min.x) / width,
|
|
146
|
+
(point.y - min.y) / height
|
|
147
|
+
))
|
|
148
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// @ts-check
|
|
2
|
+
import { Vector2 } from "../../math/index.js"
|
|
3
|
+
import { MeshBuilder } from "./base.js"
|
|
4
|
+
import { ExtrudeMeshBuilder } from "./extrude.js"
|
|
5
|
+
|
|
6
|
+
export class WedgeMeshBuilder extends MeshBuilder {
|
|
7
|
+
width = 1
|
|
8
|
+
height = 1
|
|
9
|
+
depth = 1
|
|
10
|
+
|
|
11
|
+
/** @override */
|
|
12
|
+
build() {
|
|
13
|
+
const builder = new ExtrudeMeshBuilder()
|
|
14
|
+
builder.contour = [
|
|
15
|
+
new Vector2(-this.width * 0.5, -this.height * 0.5),
|
|
16
|
+
new Vector2(this.width * 0.5, -this.height * 0.5),
|
|
17
|
+
new Vector2(-this.width * 0.5, this.height * 0.5)
|
|
18
|
+
]
|
|
19
|
+
builder.depth = this.depth
|
|
20
|
+
return builder.build()
|
|
21
|
+
}
|
|
22
|
+
}
|
package/src/mesh/mesh.js
CHANGED
|
@@ -83,16 +83,24 @@ export class Mesh {
|
|
|
83
83
|
|
|
84
84
|
if (this.indices && other.indices) {
|
|
85
85
|
const positions = this.attributes.get(Attribute.Position.name)
|
|
86
|
+
const otherPositions = other.attributes.get(Attribute.Position.name)
|
|
86
87
|
|
|
87
88
|
if (!positions) {
|
|
88
89
|
return newMesh
|
|
89
90
|
}
|
|
90
91
|
|
|
91
|
-
// TODO: Remove this hardcoding and use the attribute map instead
|
|
92
92
|
const attributeCount = positions.byteLength / (3 * 4)
|
|
93
|
+
const otherAttributeCount = otherPositions
|
|
94
|
+
? otherPositions.byteLength / (3 * 4)
|
|
95
|
+
: 0
|
|
93
96
|
const offset = this.indices.length
|
|
97
|
+
const IndexArray = (
|
|
98
|
+
this.indices instanceof Uint32Array ||
|
|
99
|
+
other.indices instanceof Uint32Array ||
|
|
100
|
+
attributeCount + otherAttributeCount > 65535
|
|
101
|
+
) ? Uint32Array : Uint16Array
|
|
94
102
|
|
|
95
|
-
const newIndices = new
|
|
103
|
+
const newIndices = new IndexArray(this.indices.length + other.indices.length)
|
|
96
104
|
|
|
97
105
|
for (let i = 0; i < this.indices.length; i++) {
|
|
98
106
|
const index = /**@type {number} */(this.indices[i]);
|
|
@@ -106,7 +114,7 @@ export class Mesh {
|
|
|
106
114
|
newIndices[i + offset] = index + attributeCount
|
|
107
115
|
}
|
|
108
116
|
newMesh.indices = newIndices
|
|
109
|
-
} else if (!this.indices && !
|
|
117
|
+
} else if (!this.indices && !other.indices) {
|
|
110
118
|
// Do nothing because attributes are already merged
|
|
111
119
|
} else {
|
|
112
120
|
// TODO: How do we merge an indexed and non-indexed mesh?
|
|
@@ -146,4 +154,4 @@ export class Mesh {
|
|
|
146
154
|
}
|
|
147
155
|
}
|
|
148
156
|
}
|
|
149
|
-
}
|
|
157
|
+
}
|