@zephyr3d/scene 0.8.0 → 0.8.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/dist/animation/animationset.js +220 -1
- package/dist/animation/animationset.js.map +1 -1
- package/dist/animation/ik/ccd_solver.js +3 -4
- package/dist/animation/ik/ccd_solver.js.map +1 -1
- package/dist/animation/ik/fabrik_solver.js +3 -4
- package/dist/animation/ik/fabrik_solver.js.map +1 -1
- package/dist/animation/ik/ik_pole_constraint.js +7 -2
- package/dist/animation/ik/ik_pole_constraint.js.map +1 -1
- package/dist/animation/ik/ik_utils.js +0 -79
- package/dist/animation/ik/ik_utils.js.map +1 -1
- package/dist/animation/ik/two_bone_ik_solver.js +3 -4
- package/dist/animation/ik/two_bone_ik_solver.js.map +1 -1
- package/dist/animation/skeleton.js +157 -125
- package/dist/animation/skeleton.js.map +1 -1
- package/dist/animation/spring/spring_bone.js +240 -0
- package/dist/animation/spring/spring_bone.js.map +1 -0
- package/dist/animation/spring/spring_bone_collider.js +198 -0
- package/dist/animation/spring/spring_bone_collider.js.map +1 -0
- package/dist/animation/spring/spring_bone_constraint.js +170 -0
- package/dist/animation/spring/spring_bone_constraint.js.map +1 -0
- package/dist/animation/spring/spring_bone_system.js +328 -0
- package/dist/animation/spring/spring_bone_system.js.map +1 -0
- package/dist/asset/model.js +2 -2
- package/dist/index.d.ts +17 -0
- package/dist/material/mixins/pbr/common.js +20 -17
- package/dist/material/mixins/pbr/common.js.map +1 -1
- package/dist/render/gpu_picking.js +100 -0
- package/dist/render/gpu_picking.js.map +1 -0
- package/dist/render/rendergraph/device_pool_allocator.js +41 -0
- package/dist/render/rendergraph/device_pool_allocator.js.map +1 -0
- package/dist/render/rendergraph/executor.js +146 -0
- package/dist/render/rendergraph/executor.js.map +1 -0
- package/dist/render/rendergraph/forward_plus_builder.js +414 -0
- package/dist/render/rendergraph/forward_plus_builder.js.map +1 -0
- package/dist/render/rendergraph/rendergraph.js +306 -0
- package/dist/render/rendergraph/rendergraph.js.map +1 -0
- package/dist/render/rendergraph/types.js +57 -0
- package/dist/render/rendergraph/types.js.map +1 -0
- package/dist/render/sky_motion_vector.js +85 -0
- package/dist/render/sky_motion_vector.js.map +1 -0
- package/dist/utility/serialization/scene/animation.js +3 -3
- package/dist/utility/serialization/scene/node.js +1 -1
- package/package.json +2 -2
- package/dist/animation/ik/ik_chain_builder.js +0 -68
- package/dist/animation/ik/ik_chain_builder.js.map +0 -1
- package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimemgr.js +0 -38
- package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimemgr.js.map +0 -1
- package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimescript.js +0 -10
- package/dist/node_modules/@zephyr3d/runtime/dist/runtime/runtimescript.js.map +0 -1
- package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptingsystem.js +0 -127
- package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptingsystem.js.map +0 -1
- package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptregistry.js +0 -263
- package/dist/node_modules/@zephyr3d/runtime/dist/runtime/scriptregistry.js.map +0 -1
- package/dist/src/animation/animation.js +0 -127
- package/dist/src/animation/animation.js.map +0 -1
- package/dist/src/animation/animationset.js +0 -255
- package/dist/src/animation/animationset.js.map +0 -1
- package/dist/src/animation/animationtrack.js +0 -34
- package/dist/src/animation/animationtrack.js.map +0 -1
- package/dist/src/animation/eulerrotationtrack.js +0 -52
- package/dist/src/animation/eulerrotationtrack.js.map +0 -1
- package/dist/src/animation/morphtarget.js +0 -93
- package/dist/src/animation/morphtarget.js.map +0 -1
- package/dist/src/animation/morphtrack.js +0 -70
- package/dist/src/animation/morphtrack.js.map +0 -1
- package/dist/src/animation/proptrack.js +0 -161
- package/dist/src/animation/proptrack.js.map +0 -1
- package/dist/src/animation/rotationtrack.js +0 -51
- package/dist/src/animation/rotationtrack.js.map +0 -1
- package/dist/src/animation/scaletrack.js +0 -50
- package/dist/src/animation/scaletrack.js.map +0 -1
- package/dist/src/animation/skeleton.js +0 -204
- package/dist/src/animation/skeleton.js.map +0 -1
- package/dist/src/animation/translationtrack.js +0 -50
- package/dist/src/animation/translationtrack.js.map +0 -1
- package/dist/src/app/app.js +0 -129
- package/dist/src/app/app.js.map +0 -1
- package/dist/src/app/inputmgr.js +0 -267
- package/dist/src/app/inputmgr.js.map +0 -1
- package/dist/src/asset/assetmanager.js +0 -404
- package/dist/src/asset/assetmanager.js.map +0 -1
- package/dist/src/asset/builtin.js +0 -337
- package/dist/src/asset/builtin.js.map +0 -1
- package/dist/src/asset/loaders/dds/dds.js +0 -470
- package/dist/src/asset/loaders/dds/dds.js.map +0 -1
- package/dist/src/asset/loaders/dds/dds_loader.js +0 -28
- package/dist/src/asset/loaders/dds/dds_loader.js.map +0 -1
- package/dist/src/asset/loaders/gltf/gltf_loader.js +0 -1265
- package/dist/src/asset/loaders/gltf/gltf_loader.js.map +0 -1
- package/dist/src/asset/loaders/gltf/helpers.js +0 -327
- package/dist/src/asset/loaders/gltf/helpers.js.map +0 -1
- package/dist/src/asset/loaders/hdr/hdr.js +0 -180
- package/dist/src/asset/loaders/hdr/hdr.js.map +0 -1
- package/dist/src/asset/loaders/image/tga_Loader.js +0 -116
- package/dist/src/asset/loaders/image/tga_Loader.js.map +0 -1
- package/dist/src/asset/loaders/image/webimage_loader.js +0 -63
- package/dist/src/asset/loaders/image/webimage_loader.js.map +0 -1
- package/dist/src/asset/loaders/loader.js +0 -45
- package/dist/src/asset/loaders/loader.js.map +0 -1
- package/dist/src/asset/model.js +0 -414
- package/dist/src/asset/model.js.map +0 -1
- package/dist/src/blitter/bilateralblur.js +0 -221
- package/dist/src/blitter/bilateralblur.js.map +0 -1
- package/dist/src/blitter/blitter.js +0 -390
- package/dist/src/blitter/blitter.js.map +0 -1
- package/dist/src/blitter/box.js +0 -118
- package/dist/src/blitter/box.js.map +0 -1
- package/dist/src/blitter/copy.js +0 -22
- package/dist/src/blitter/copy.js.map +0 -1
- package/dist/src/blitter/gaussianblur.js +0 -228
- package/dist/src/blitter/gaussianblur.js.map +0 -1
- package/dist/src/camera/base.js +0 -92
- package/dist/src/camera/base.js.map +0 -1
- package/dist/src/camera/camera.js +0 -1005
- package/dist/src/camera/camera.js.map +0 -1
- package/dist/src/camera/fps.js +0 -238
- package/dist/src/camera/fps.js.map +0 -1
- package/dist/src/camera/orbit.js +0 -245
- package/dist/src/camera/orbit.js.map +0 -1
- package/dist/src/camera/orthocamera.js +0 -167
- package/dist/src/camera/orthocamera.js.map +0 -1
- package/dist/src/camera/perspectivecamera.js +0 -141
- package/dist/src/camera/perspectivecamera.js.map +0 -1
- package/dist/src/index.js +0 -120
- package/dist/src/index.js.map +0 -1
- package/dist/src/material/blinn.js +0 -81
- package/dist/src/material/blinn.js.map +0 -1
- package/dist/src/material/grassmaterial.js +0 -113
- package/dist/src/material/grassmaterial.js.map +0 -1
- package/dist/src/material/lambert.js +0 -92
- package/dist/src/material/lambert.js.map +0 -1
- package/dist/src/material/material.js +0 -301
- package/dist/src/material/material.js.map +0 -1
- package/dist/src/material/meshmaterial.js +0 -704
- package/dist/src/material/meshmaterial.js.map +0 -1
- package/dist/src/material/mixins/albedocolor.js +0 -76
- package/dist/src/material/mixins/albedocolor.js.map +0 -1
- package/dist/src/material/mixins/foliage.js +0 -47
- package/dist/src/material/mixins/foliage.js.map +0 -1
- package/dist/src/material/mixins/lightmodel/blinnphong.js +0 -112
- package/dist/src/material/mixins/lightmodel/blinnphong.js.map +0 -1
- package/dist/src/material/mixins/lightmodel/lambert.js +0 -58
- package/dist/src/material/mixins/lightmodel/lambert.js.map +0 -1
- package/dist/src/material/mixins/lightmodel/pbrmetallicroughness.js +0 -178
- package/dist/src/material/mixins/lightmodel/pbrmetallicroughness.js.map +0 -1
- package/dist/src/material/mixins/lightmodel/pbrspecularglossness.js +0 -139
- package/dist/src/material/mixins/lightmodel/pbrspecularglossness.js.map +0 -1
- package/dist/src/material/mixins/lit.js +0 -476
- package/dist/src/material/mixins/lit.js.map +0 -1
- package/dist/src/material/mixins/pbr/common.js +0 -918
- package/dist/src/material/mixins/pbr/common.js.map +0 -1
- package/dist/src/material/mixins/texture.js +0 -172
- package/dist/src/material/mixins/texture.js.map +0 -1
- package/dist/src/material/mixins/vertexcolor.js +0 -56
- package/dist/src/material/mixins/vertexcolor.js.map +0 -1
- package/dist/src/material/particle.js +0 -178
- package/dist/src/material/particle.js.map +0 -1
- package/dist/src/material/pbrmr.js +0 -97
- package/dist/src/material/pbrmr.js.map +0 -1
- package/dist/src/material/pbrsg.js +0 -97
- package/dist/src/material/pbrsg.js.map +0 -1
- package/dist/src/material/shader/helper.js +0 -1209
- package/dist/src/material/shader/helper.js.map +0 -1
- package/dist/src/material/terrain-cm.js +0 -606
- package/dist/src/material/terrain-cm.js.map +0 -1
- package/dist/src/material/terrainmaterial.js +0 -375
- package/dist/src/material/terrainmaterial.js.map +0 -1
- package/dist/src/material/unlit.js +0 -41
- package/dist/src/material/unlit.js.map +0 -1
- package/dist/src/material/water.js +0 -417
- package/dist/src/material/water.js.map +0 -1
- package/dist/src/posteffect/bloom.js +0 -361
- package/dist/src/posteffect/bloom.js.map +0 -1
- package/dist/src/posteffect/compositor.js +0 -226
- package/dist/src/posteffect/compositor.js.map +0 -1
- package/dist/src/posteffect/fxaa.js +0 -273
- package/dist/src/posteffect/fxaa.js.map +0 -1
- package/dist/src/posteffect/grayscale.js +0 -69
- package/dist/src/posteffect/grayscale.js.map +0 -1
- package/dist/src/posteffect/motionblur.js +0 -96
- package/dist/src/posteffect/motionblur.js.map +0 -1
- package/dist/src/posteffect/posteffect.js +0 -126
- package/dist/src/posteffect/posteffect.js.map +0 -1
- package/dist/src/posteffect/sao.js +0 -324
- package/dist/src/posteffect/sao.js.map +0 -1
- package/dist/src/posteffect/ssr.js +0 -489
- package/dist/src/posteffect/ssr.js.map +0 -1
- package/dist/src/posteffect/taa.js +0 -172
- package/dist/src/posteffect/taa.js.map +0 -1
- package/dist/src/posteffect/tonemap.js +0 -94
- package/dist/src/posteffect/tonemap.js.map +0 -1
- package/dist/src/render/abuffer_oit.js +0 -361
- package/dist/src/render/abuffer_oit.js.map +0 -1
- package/dist/src/render/clipmap.js +0 -851
- package/dist/src/render/clipmap.js.map +0 -1
- package/dist/src/render/cluster_light.js +0 -333
- package/dist/src/render/cluster_light.js.map +0 -1
- package/dist/src/render/cull_visitor.js +0 -187
- package/dist/src/render/cull_visitor.js.map +0 -1
- package/dist/src/render/depthpass.js +0 -68
- package/dist/src/render/depthpass.js.map +0 -1
- package/dist/src/render/drawable_mixin.js +0 -227
- package/dist/src/render/drawable_mixin.js.map +0 -1
- package/dist/src/render/envlight.js +0 -463
- package/dist/src/render/envlight.js.map +0 -1
- package/dist/src/render/fbm_wavegenerator.js +0 -251
- package/dist/src/render/fbm_wavegenerator.js.map +0 -1
- package/dist/src/render/fft_wavegenerator.js +0 -1006
- package/dist/src/render/fft_wavegenerator.js.map +0 -1
- package/dist/src/render/fullscreenquad.js +0 -38
- package/dist/src/render/fullscreenquad.js.map +0 -1
- package/dist/src/render/gerstner_wavegenerator.js +0 -314
- package/dist/src/render/gerstner_wavegenerator.js.map +0 -1
- package/dist/src/render/globalbindgroup_allocator.js +0 -60
- package/dist/src/render/globalbindgroup_allocator.js.map +0 -1
- package/dist/src/render/hzb.js +0 -273
- package/dist/src/render/hzb.js.map +0 -1
- package/dist/src/render/lightpass.js +0 -172
- package/dist/src/render/lightpass.js.map +0 -1
- package/dist/src/render/objectcolorpass.js +0 -51
- package/dist/src/render/objectcolorpass.js.map +0 -1
- package/dist/src/render/primitive.js +0 -364
- package/dist/src/render/primitive.js.map +0 -1
- package/dist/src/render/render_queue.js +0 -467
- package/dist/src/render/render_queue.js.map +0 -1
- package/dist/src/render/renderbundle_wrapper.js +0 -152
- package/dist/src/render/renderbundle_wrapper.js.map +0 -1
- package/dist/src/render/renderer.js +0 -455
- package/dist/src/render/renderer.js.map +0 -1
- package/dist/src/render/renderpass.js +0 -200
- package/dist/src/render/renderpass.js.map +0 -1
- package/dist/src/render/shadowmap_pass.js +0 -56
- package/dist/src/render/shadowmap_pass.js.map +0 -1
- package/dist/src/render/sky.js +0 -1103
- package/dist/src/render/sky.js.map +0 -1
- package/dist/src/render/weightedblended_oit.js +0 -168
- package/dist/src/render/weightedblended_oit.js.map +0 -1
- package/dist/src/scene/batchgroup.js +0 -162
- package/dist/src/scene/batchgroup.js.map +0 -1
- package/dist/src/scene/environment.js +0 -209
- package/dist/src/scene/environment.js.map +0 -1
- package/dist/src/scene/graph_node.js +0 -72
- package/dist/src/scene/graph_node.js.map +0 -1
- package/dist/src/scene/light.js +0 -416
- package/dist/src/scene/light.js.map +0 -1
- package/dist/src/scene/mesh.js +0 -341
- package/dist/src/scene/mesh.js.map +0 -1
- package/dist/src/scene/octree.js +0 -649
- package/dist/src/scene/octree.js.map +0 -1
- package/dist/src/scene/particlesys.js +0 -738
- package/dist/src/scene/particlesys.js.map +0 -1
- package/dist/src/scene/raycast_visitor.js +0 -103
- package/dist/src/scene/raycast_visitor.js.map +0 -1
- package/dist/src/scene/scene.js +0 -284
- package/dist/src/scene/scene.js.map +0 -1
- package/dist/src/scene/scene_node.js +0 -732
- package/dist/src/scene/scene_node.js.map +0 -1
- package/dist/src/scene/terrain/grass.js +0 -278
- package/dist/src/scene/terrain/grass.js.map +0 -1
- package/dist/src/scene/terrain/heightfield.js +0 -475
- package/dist/src/scene/terrain/heightfield.js.map +0 -1
- package/dist/src/scene/terrain/patch.js +0 -530
- package/dist/src/scene/terrain/patch.js.map +0 -1
- package/dist/src/scene/terrain/quadtree.js +0 -461
- package/dist/src/scene/terrain/quadtree.js.map +0 -1
- package/dist/src/scene/terrain/terrain.js +0 -246
- package/dist/src/scene/terrain/terrain.js.map +0 -1
- package/dist/src/scene/terrain-cm/grass.js +0 -594
- package/dist/src/scene/terrain-cm/grass.js.map +0 -1
- package/dist/src/scene/terrain-cm/grassmaterial.js +0 -159
- package/dist/src/scene/terrain-cm/grassmaterial.js.map +0 -1
- package/dist/src/scene/terrain-cm/terrain-cm.js +0 -538
- package/dist/src/scene/terrain-cm/terrain-cm.js.map +0 -1
- package/dist/src/scene/water.js +0 -374
- package/dist/src/scene/water.js.map +0 -1
- package/dist/src/shaders/atmosphere.js +0 -957
- package/dist/src/shaders/atmosphere.js.map +0 -1
- package/dist/src/shaders/fog.js +0 -112
- package/dist/src/shaders/fog.js.map +0 -1
- package/dist/src/shaders/misc.js +0 -266
- package/dist/src/shaders/misc.js.map +0 -1
- package/dist/src/shaders/noise.js +0 -222
- package/dist/src/shaders/noise.js.map +0 -1
- package/dist/src/shaders/pbr.js +0 -51
- package/dist/src/shaders/pbr.js.map +0 -1
- package/dist/src/shaders/shadow.js +0 -636
- package/dist/src/shaders/shadow.js.map +0 -1
- package/dist/src/shaders/ssr.js +0 -490
- package/dist/src/shaders/ssr.js.map +0 -1
- package/dist/src/shaders/temporal.js +0 -215
- package/dist/src/shaders/temporal.js.map +0 -1
- package/dist/src/shaders/water.js +0 -756
- package/dist/src/shaders/water.js.map +0 -1
- package/dist/src/shadow/esm.js +0 -237
- package/dist/src/shadow/esm.js.map +0 -1
- package/dist/src/shadow/pcf_opt.js +0 -181
- package/dist/src/shadow/pcf_opt.js.map +0 -1
- package/dist/src/shadow/pcf_pd.js +0 -189
- package/dist/src/shadow/pcf_pd.js.map +0 -1
- package/dist/src/shadow/shader.js +0 -37
- package/dist/src/shadow/shader.js.map +0 -1
- package/dist/src/shadow/shadow_impl.js +0 -15
- package/dist/src/shadow/shadow_impl.js.map +0 -1
- package/dist/src/shadow/shadowmapper.js +0 -790
- package/dist/src/shadow/shadowmapper.js.map +0 -1
- package/dist/src/shadow/ssm.js +0 -159
- package/dist/src/shadow/ssm.js.map +0 -1
- package/dist/src/shadow/vsm.js +0 -297
- package/dist/src/shadow/vsm.js.map +0 -1
- package/dist/src/shapes/box.js +0 -386
- package/dist/src/shapes/box.js.map +0 -1
- package/dist/src/shapes/cylinder.js +0 -125
- package/dist/src/shapes/cylinder.js.map +0 -1
- package/dist/src/shapes/plane.js +0 -88
- package/dist/src/shapes/plane.js.map +0 -1
- package/dist/src/shapes/shape.js +0 -87
- package/dist/src/shapes/shape.js.map +0 -1
- package/dist/src/shapes/sphere.js +0 -114
- package/dist/src/shapes/sphere.js.map +0 -1
- package/dist/src/shapes/tetrahedron.js +0 -188
- package/dist/src/shapes/tetrahedron.js.map +0 -1
- package/dist/src/shapes/torus.js +0 -111
- package/dist/src/shapes/torus.js.map +0 -1
- package/dist/src/utility/aabbtree.js +0 -400
- package/dist/src/utility/aabbtree.js.map +0 -1
- package/dist/src/utility/bounding_volume.js +0 -29
- package/dist/src/utility/bounding_volume.js.map +0 -1
- package/dist/src/utility/debug.js +0 -28
- package/dist/src/utility/debug.js.map +0 -1
- package/dist/src/utility/draco/decoder.js +0 -116
- package/dist/src/utility/draco/decoder.js.map +0 -1
- package/dist/src/utility/misc.js +0 -105
- package/dist/src/utility/misc.js.map +0 -1
- package/dist/src/utility/panorama.js +0 -163
- package/dist/src/utility/panorama.js.map +0 -1
- package/dist/src/utility/pmrem.js +0 -354
- package/dist/src/utility/pmrem.js.map +0 -1
- package/dist/src/utility/rendermipmap.js +0 -115
- package/dist/src/utility/rendermipmap.js.map +0 -1
- package/dist/src/utility/serialization/json.js +0 -402
- package/dist/src/utility/serialization/json.js.map +0 -1
- package/dist/src/utility/serialization/manager.js +0 -623
- package/dist/src/utility/serialization/manager.js.map +0 -1
- package/dist/src/utility/serialization/scene/animation.js +0 -248
- package/dist/src/utility/serialization/scene/animation.js.map +0 -1
- package/dist/src/utility/serialization/scene/batch.js +0 -59
- package/dist/src/utility/serialization/scene/batch.js.map +0 -1
- package/dist/src/utility/serialization/scene/camera.js +0 -790
- package/dist/src/utility/serialization/scene/camera.js.map +0 -1
- package/dist/src/utility/serialization/scene/common.js +0 -222
- package/dist/src/utility/serialization/scene/common.js.map +0 -1
- package/dist/src/utility/serialization/scene/light.js +0 -575
- package/dist/src/utility/serialization/scene/light.js.map +0 -1
- package/dist/src/utility/serialization/scene/material.js +0 -1111
- package/dist/src/utility/serialization/scene/material.js.map +0 -1
- package/dist/src/utility/serialization/scene/mesh.js +0 -148
- package/dist/src/utility/serialization/scene/mesh.js.map +0 -1
- package/dist/src/utility/serialization/scene/misc.js +0 -39
- package/dist/src/utility/serialization/scene/misc.js.map +0 -1
- package/dist/src/utility/serialization/scene/node.js +0 -451
- package/dist/src/utility/serialization/scene/node.js.map +0 -1
- package/dist/src/utility/serialization/scene/particle.js +0 -425
- package/dist/src/utility/serialization/scene/particle.js.map +0 -1
- package/dist/src/utility/serialization/scene/primitive.js +0 -692
- package/dist/src/utility/serialization/scene/primitive.js.map +0 -1
- package/dist/src/utility/serialization/scene/scene.js +0 -704
- package/dist/src/utility/serialization/scene/scene.js.map +0 -1
- package/dist/src/utility/serialization/scene/terrain.js +0 -488
- package/dist/src/utility/serialization/scene/terrain.js.map +0 -1
- package/dist/src/utility/serialization/scene/water.js +0 -465
- package/dist/src/utility/serialization/scene/water.js.map +0 -1
- package/dist/src/utility/shprojector.js +0 -297
- package/dist/src/utility/shprojector.js.map +0 -1
- package/dist/src/utility/textures/ggxlut.js +0 -213
- package/dist/src/utility/textures/ggxlut.js.map +0 -1
- package/dist/src/utility/textures/gradientnoise.js +0 -62
- package/dist/src/utility/textures/gradientnoise.js.map +0 -1
- package/dist/src/utility/textures/randomnoise.js +0 -41
- package/dist/src/utility/textures/randomnoise.js.map +0 -1
- package/dist/src/values.js +0 -162
- package/dist/src/values.js.map +0 -1
- package/dist/utility/blueprint/material/common.js +0 -7
- package/dist/utility/blueprint/material/common.js.map +0 -1
- package/dist/utility/serialization/blueprint/constants.js +0 -255
- package/dist/utility/serialization/blueprint/constants.js.map +0 -1
- package/dist/utility/serialization/blueprint/material/constants.js +0 -203
- package/dist/utility/serialization/blueprint/material/constants.js.map +0 -1
- package/dist/utility/serialization/blueprint/material/texture.js +0 -165
- package/dist/utility/serialization/blueprint/material/texture.js.map +0 -1
|
@@ -1,594 +0,0 @@
|
|
|
1
|
-
import { Application } from '../../app/app.js';
|
|
2
|
-
import { Disposable, DRef, AABB, ClipState, nextPowerOf2, DWeakRef } from '@zephyr3d/base';
|
|
3
|
-
import '../../values.js';
|
|
4
|
-
import '@zephyr3d/device';
|
|
5
|
-
import '../../material/shader/helper.js';
|
|
6
|
-
import '../../material/lambert.js';
|
|
7
|
-
import '../../material/blinn.js';
|
|
8
|
-
import '../../material/unlit.js';
|
|
9
|
-
import '../../material/particle.js';
|
|
10
|
-
import '../../material/meshmaterial.js';
|
|
11
|
-
import '../../material/grassmaterial.js';
|
|
12
|
-
import '../../material/terrainmaterial.js';
|
|
13
|
-
import '../../material/terrain-cm.js';
|
|
14
|
-
import '../../material/pbrmr.js';
|
|
15
|
-
import '../../material/pbrsg.js';
|
|
16
|
-
import '../../render/renderer.js';
|
|
17
|
-
import { Primitive } from '../../render/primitive.js';
|
|
18
|
-
import '../../render/sky.js';
|
|
19
|
-
import '../../render/clipmap.js';
|
|
20
|
-
import '../../shaders/atmosphere.js';
|
|
21
|
-
import { ClipmapGrassMaterial } from './grassmaterial.js';
|
|
22
|
-
|
|
23
|
-
const MAX_INSTANCES_PER_NODE = 2048;
|
|
24
|
-
// Two floats
|
|
25
|
-
const INSTANCE_BYTES = 4 * 4;
|
|
26
|
-
/**
|
|
27
|
-
* Grass glade instance manager class
|
|
28
|
-
* @internal
|
|
29
|
-
*/ class GrassInstances extends Disposable {
|
|
30
|
-
_instances;
|
|
31
|
-
_baseVertexBuffer;
|
|
32
|
-
_indexBuffer;
|
|
33
|
-
_instanceBuffer;
|
|
34
|
-
_primitive;
|
|
35
|
-
constructor(baseVertexBuffer, indexBuffer){
|
|
36
|
-
super();
|
|
37
|
-
this._instances = [];
|
|
38
|
-
this._baseVertexBuffer = new DRef(baseVertexBuffer);
|
|
39
|
-
this._indexBuffer = new DRef(indexBuffer);
|
|
40
|
-
this._instanceBuffer = new DRef();
|
|
41
|
-
this._primitive = new DRef();
|
|
42
|
-
}
|
|
43
|
-
get numInstances() {
|
|
44
|
-
return this._instances.length;
|
|
45
|
-
}
|
|
46
|
-
get instanceBuffer() {
|
|
47
|
-
return this._instanceBuffer.get();
|
|
48
|
-
}
|
|
49
|
-
setBaseVertexBuffer(baseVertexBuffer) {
|
|
50
|
-
if (baseVertexBuffer !== this._baseVertexBuffer.get()) {
|
|
51
|
-
this._baseVertexBuffer.set(baseVertexBuffer);
|
|
52
|
-
this._primitive.dispose();
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
draw() {
|
|
56
|
-
if (this._instances.length > 0) {
|
|
57
|
-
if (!this._primitive.get()) {
|
|
58
|
-
const primitive = new Primitive();
|
|
59
|
-
primitive.setVertexBuffer(this._baseVertexBuffer.get());
|
|
60
|
-
primitive.setVertexBuffer(this._instanceBuffer.get(), 'instance');
|
|
61
|
-
primitive.setIndexBuffer(this._indexBuffer.get());
|
|
62
|
-
primitive.primitiveType = 'triangle-list';
|
|
63
|
-
primitive.indexStart = 0;
|
|
64
|
-
primitive.indexCount = this._indexBuffer.get().length;
|
|
65
|
-
this._primitive.set(primitive);
|
|
66
|
-
}
|
|
67
|
-
this._primitive.get().drawInstanced(this._instances.length);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
updateBuffers() {
|
|
71
|
-
const device = Application.instance.device;
|
|
72
|
-
if (this._instances.length === 0) {
|
|
73
|
-
this._instanceBuffer.set(null);
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
if (this._instances.length > 0 && !this._instanceBuffer.get()) {
|
|
77
|
-
this._instanceBuffer.set(device.createVertexBuffer('tex1_f32x4', new Uint8Array(this._instances.length * INSTANCE_BYTES)));
|
|
78
|
-
}
|
|
79
|
-
let buffer = this._instanceBuffer.get();
|
|
80
|
-
const currentBytes = buffer.byteLength;
|
|
81
|
-
const bytesRequired = this._instances.length * INSTANCE_BYTES;
|
|
82
|
-
if (currentBytes < bytesRequired) {
|
|
83
|
-
buffer = device.createVertexBuffer('tex1_f32x4', new Uint8Array(nextPowerOf2(bytesRequired)));
|
|
84
|
-
this._instanceBuffer.set(buffer);
|
|
85
|
-
this._primitive.dispose();
|
|
86
|
-
}
|
|
87
|
-
const data = new Float32Array(4 * this._instances.length);
|
|
88
|
-
for(let i = 0; i < this._instances.length; i++){
|
|
89
|
-
data[i * 4 + 0] = this._instances[i].x;
|
|
90
|
-
data[i * 4 + 1] = this._instances[i].y;
|
|
91
|
-
data[i * 4 + 2] = Math.sin(this._instances[i].angle);
|
|
92
|
-
data[i * 4 + 3] = Math.cos(this._instances[i].angle);
|
|
93
|
-
}
|
|
94
|
-
buffer.bufferSubData(0, data);
|
|
95
|
-
}
|
|
96
|
-
removeInstances(minX, minZ, maxX, maxZ, num) {
|
|
97
|
-
if (num <= 0) {
|
|
98
|
-
return 0;
|
|
99
|
-
}
|
|
100
|
-
let removed = 0;
|
|
101
|
-
for(let i = this._instances.length - 1; i >= 0; i--){
|
|
102
|
-
const instance = this._instances[i];
|
|
103
|
-
if (instance.x >= minX && instance.x <= maxX && instance.y >= minZ && instance.y <= maxZ) {
|
|
104
|
-
this._instances.splice(i, 1);
|
|
105
|
-
removed++;
|
|
106
|
-
if (removed === num) {
|
|
107
|
-
break;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
if (removed > 0) {
|
|
112
|
-
this.updateBuffers();
|
|
113
|
-
}
|
|
114
|
-
return removed;
|
|
115
|
-
}
|
|
116
|
-
addInstances(instances) {
|
|
117
|
-
this._instances.push(...instances);
|
|
118
|
-
this.updateBuffers();
|
|
119
|
-
}
|
|
120
|
-
onDispose() {
|
|
121
|
-
super.onDispose();
|
|
122
|
-
this._baseVertexBuffer.dispose();
|
|
123
|
-
this._indexBuffer.dispose();
|
|
124
|
-
this._instanceBuffer.dispose();
|
|
125
|
-
this._primitive.dispose();
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Grass layer class
|
|
130
|
-
* @public
|
|
131
|
-
*/ class GrassLayer extends Disposable {
|
|
132
|
-
static _indexBuffer = new DRef();
|
|
133
|
-
_material;
|
|
134
|
-
_quadtree;
|
|
135
|
-
_bladeWidth;
|
|
136
|
-
_bladeHeight;
|
|
137
|
-
_baseVertexBuffer;
|
|
138
|
-
/**
|
|
139
|
-
* Creates an instance of GrassLayer
|
|
140
|
-
* @param terrain - Clipmap terrain object
|
|
141
|
-
* @param bladeWidth - Grass blade width
|
|
142
|
-
* @param bladeHeight - Grass blade height
|
|
143
|
-
* @param albedoMap - Albedo texture for the blade
|
|
144
|
-
*/ constructor(terrain, bladeWidth, bladeHeight, albedoMap){
|
|
145
|
-
super();
|
|
146
|
-
this._material = new DRef(new ClipmapGrassMaterial(terrain));
|
|
147
|
-
this._material.get().albedoTexture = albedoMap;
|
|
148
|
-
if (albedoMap) {
|
|
149
|
-
this._material.get().setTextureSize(albedoMap.width, albedoMap.height);
|
|
150
|
-
}
|
|
151
|
-
this._bladeWidth = bladeWidth;
|
|
152
|
-
this._bladeHeight = bladeHeight;
|
|
153
|
-
this._baseVertexBuffer = new DRef(this.createBaseVertexBuffer(this._bladeWidth, this._bladeHeight));
|
|
154
|
-
this._quadtree = new DRef(new GrassQuadtreeNode(this._baseVertexBuffer.get(), GrassLayer._getIndexBuffer()));
|
|
155
|
-
}
|
|
156
|
-
/** @internal */ get quadtree() {
|
|
157
|
-
return this._quadtree.get();
|
|
158
|
-
}
|
|
159
|
-
/** @internal */ updateMaterial() {
|
|
160
|
-
this._material.get().uniformChanged();
|
|
161
|
-
}
|
|
162
|
-
/**
|
|
163
|
-
* Sets the albedo texture of grass blades in this layer
|
|
164
|
-
* @param albedoMap - Albedo texture to set
|
|
165
|
-
*/ setAlbedoMap(albedoMap) {
|
|
166
|
-
this._material.get().albedoTexture = albedoMap;
|
|
167
|
-
if (albedoMap) {
|
|
168
|
-
this._material.get().setTextureSize(albedoMap.width, albedoMap.height);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* Gets the albedo texture of grass blades in this layer
|
|
173
|
-
* @returns - Albedo texture of grass blades in this layer
|
|
174
|
-
*/ getAlbedoMap() {
|
|
175
|
-
return this._material.get().albedoTexture;
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* Add grass blades to this layer in a region
|
|
179
|
-
* @param instances - Grass blade instances to add
|
|
180
|
-
*/ addInstances(instances) {
|
|
181
|
-
this._quadtree.get().addInstances(instances);
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* Remove grass blades to this layer in a region
|
|
185
|
-
* @param minX - Minimum x position of the region
|
|
186
|
-
* @param minZ - Minimum z position of the region
|
|
187
|
-
* @param maxX - Maximum x position of the region
|
|
188
|
-
* @param maxZ - Maximum z position of the region
|
|
189
|
-
* @param numInstances - How many grass blades to add
|
|
190
|
-
*/ removeInstances(minX, minZ, maxX, maxZ, numInstances) {
|
|
191
|
-
this._quadtree.get().removeInstances(minX, minZ, maxX, maxZ, numInstances);
|
|
192
|
-
}
|
|
193
|
-
/** Grass blade width in this layer */ get bladeWidth() {
|
|
194
|
-
return this._bladeWidth;
|
|
195
|
-
}
|
|
196
|
-
set bladeWidth(val) {
|
|
197
|
-
this.setBladeSize(val, this._bladeHeight);
|
|
198
|
-
}
|
|
199
|
-
/** Grass blade height in this layer */ get bladeHeight() {
|
|
200
|
-
return this._bladeHeight;
|
|
201
|
-
}
|
|
202
|
-
set bladeHeight(val) {
|
|
203
|
-
this.setBladeSize(this._bladeWidth, val);
|
|
204
|
-
}
|
|
205
|
-
/**
|
|
206
|
-
* Sets the size of grass blades in this layer
|
|
207
|
-
* @param width - Grass blade width
|
|
208
|
-
* @param height - Grass blade height
|
|
209
|
-
*/ setBladeSize(width, height) {
|
|
210
|
-
if (width !== this._bladeWidth || height !== this._bladeHeight) {
|
|
211
|
-
this._bladeWidth = width;
|
|
212
|
-
this._bladeHeight = height;
|
|
213
|
-
this._baseVertexBuffer.set(this.createBaseVertexBuffer(this._bladeWidth, this._bladeHeight));
|
|
214
|
-
this._quadtree.get().setBaseVertexBuffer(this._baseVertexBuffer.get());
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
/** @internal */ static _getIndexBuffer() {
|
|
218
|
-
if (!this._indexBuffer.get()) {
|
|
219
|
-
this._indexBuffer.set(Application.instance.device.createIndexBuffer(new Uint16Array([
|
|
220
|
-
0,
|
|
221
|
-
1,
|
|
222
|
-
2,
|
|
223
|
-
0,
|
|
224
|
-
2,
|
|
225
|
-
3,
|
|
226
|
-
4,
|
|
227
|
-
5,
|
|
228
|
-
6,
|
|
229
|
-
4,
|
|
230
|
-
6,
|
|
231
|
-
7,
|
|
232
|
-
8,
|
|
233
|
-
9,
|
|
234
|
-
10,
|
|
235
|
-
8,
|
|
236
|
-
10,
|
|
237
|
-
11
|
|
238
|
-
])));
|
|
239
|
-
}
|
|
240
|
-
return this._indexBuffer.get();
|
|
241
|
-
}
|
|
242
|
-
/** @internal */ createBaseVertexBuffer(bladeWidth, bladeHeight) {
|
|
243
|
-
const device = Application.instance.device;
|
|
244
|
-
const r = bladeWidth * 0.5;
|
|
245
|
-
const t = bladeHeight;
|
|
246
|
-
const c = r * Math.cos(Math.PI / 3);
|
|
247
|
-
const s = r * Math.sin(Math.PI / 3);
|
|
248
|
-
const vertices = new Float32Array([
|
|
249
|
-
r,
|
|
250
|
-
0,
|
|
251
|
-
0,
|
|
252
|
-
0,
|
|
253
|
-
1,
|
|
254
|
-
r,
|
|
255
|
-
t,
|
|
256
|
-
0,
|
|
257
|
-
0,
|
|
258
|
-
0,
|
|
259
|
-
-r,
|
|
260
|
-
t,
|
|
261
|
-
0,
|
|
262
|
-
1,
|
|
263
|
-
0,
|
|
264
|
-
-r,
|
|
265
|
-
0,
|
|
266
|
-
0,
|
|
267
|
-
1,
|
|
268
|
-
1,
|
|
269
|
-
c,
|
|
270
|
-
0,
|
|
271
|
-
s,
|
|
272
|
-
0,
|
|
273
|
-
1,
|
|
274
|
-
-c,
|
|
275
|
-
0,
|
|
276
|
-
-s,
|
|
277
|
-
1,
|
|
278
|
-
1,
|
|
279
|
-
-c,
|
|
280
|
-
t,
|
|
281
|
-
-s,
|
|
282
|
-
1,
|
|
283
|
-
0,
|
|
284
|
-
c,
|
|
285
|
-
t,
|
|
286
|
-
s,
|
|
287
|
-
0,
|
|
288
|
-
0,
|
|
289
|
-
-c,
|
|
290
|
-
0,
|
|
291
|
-
s,
|
|
292
|
-
0,
|
|
293
|
-
1,
|
|
294
|
-
c,
|
|
295
|
-
0,
|
|
296
|
-
-s,
|
|
297
|
-
1,
|
|
298
|
-
1,
|
|
299
|
-
c,
|
|
300
|
-
t,
|
|
301
|
-
-s,
|
|
302
|
-
1,
|
|
303
|
-
0,
|
|
304
|
-
-c,
|
|
305
|
-
t,
|
|
306
|
-
s,
|
|
307
|
-
0,
|
|
308
|
-
0
|
|
309
|
-
]);
|
|
310
|
-
return device.createInterleavedVertexBuffer([
|
|
311
|
-
'position_f32x3',
|
|
312
|
-
'tex0_f32x2'
|
|
313
|
-
], vertices);
|
|
314
|
-
}
|
|
315
|
-
/** @internal */ draw(ctx, region, minY, maxY) {
|
|
316
|
-
this._material.get().apply(ctx);
|
|
317
|
-
for(let pass = 0; pass < this._material.get().numPasses; pass++){
|
|
318
|
-
this._material.get().bind(ctx.device, pass);
|
|
319
|
-
this._quadtree.get().draw(ctx.camera, region, minY, maxY, false);
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
/** @internal */ onDispose() {
|
|
323
|
-
super.onDispose();
|
|
324
|
-
this._material.dispose();
|
|
325
|
-
this._quadtree.dispose();
|
|
326
|
-
this._baseVertexBuffer.dispose();
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
/**
|
|
330
|
-
* Grass renderer for clipmap terrain
|
|
331
|
-
* @public
|
|
332
|
-
*/ class GrassRenderer extends Disposable {
|
|
333
|
-
_terrain;
|
|
334
|
-
_layers;
|
|
335
|
-
/**
|
|
336
|
-
* Creates an instance of GrassRenderer
|
|
337
|
-
* @param terrain - Clipmap terrain object
|
|
338
|
-
*/ constructor(terrain){
|
|
339
|
-
super();
|
|
340
|
-
this._terrain = new DWeakRef(terrain);
|
|
341
|
-
this._layers = [];
|
|
342
|
-
}
|
|
343
|
-
/** @internal */ updateMaterial() {
|
|
344
|
-
for (const layer of this._layers){
|
|
345
|
-
layer.updateMaterial();
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
/** How many grass layers */ get numLayers() {
|
|
349
|
-
return this._layers.length;
|
|
350
|
-
}
|
|
351
|
-
/**
|
|
352
|
-
* Gets the grass layer at given index
|
|
353
|
-
* @param index - Index of the grass layer
|
|
354
|
-
* @returns The grass layer at the index
|
|
355
|
-
*/ getLayer(index) {
|
|
356
|
-
return this._layers[index];
|
|
357
|
-
}
|
|
358
|
-
/**
|
|
359
|
-
* Adds a grass layer
|
|
360
|
-
* @param bladeWidth - Width of grass blades in this layer
|
|
361
|
-
* @param bladeHeight - Height of grass blades in this layer
|
|
362
|
-
* @param albedoMap - Albedo texture of grass blades in this layer
|
|
363
|
-
* @returns Index of the added grass layer
|
|
364
|
-
*/ addLayer(bladeWidth, bladeHeight, albedoMap) {
|
|
365
|
-
const layer = new GrassLayer(this._terrain.get(), bladeWidth, bladeHeight, albedoMap);
|
|
366
|
-
this._layers.push(layer);
|
|
367
|
-
return this._layers.length - 1;
|
|
368
|
-
}
|
|
369
|
-
/**
|
|
370
|
-
* Gets the albedo texture of grass blades in the grass layer at given index
|
|
371
|
-
* @param layer - Index of the grass layer to get
|
|
372
|
-
* @returns Albedo texture of grass blades in the grass layer
|
|
373
|
-
*/ getGrassTexture(layer) {
|
|
374
|
-
return this._layers[layer]?.getAlbedoMap() ?? null;
|
|
375
|
-
}
|
|
376
|
-
/**
|
|
377
|
-
* Sets the albedo texture of grass blades in the grass layer at given index
|
|
378
|
-
* @param layer - Index of the grass layer to set
|
|
379
|
-
* @param texture - Albedo texture to set
|
|
380
|
-
*/ setGrassTexture(layer, texture) {
|
|
381
|
-
const grassLayer = this._layers[layer];
|
|
382
|
-
if (grassLayer) {
|
|
383
|
-
grassLayer.setAlbedoMap(texture);
|
|
384
|
-
} else {
|
|
385
|
-
console.error(`Invalid grass layer: ${layer}`);
|
|
386
|
-
}
|
|
387
|
-
}
|
|
388
|
-
/**
|
|
389
|
-
* Gets width of the grass blades in the grass layer at given index
|
|
390
|
-
* @param layer - Index of the grass layer
|
|
391
|
-
* @returns Width of the grass blades in the layer
|
|
392
|
-
*/ getBladeWidth(layer) {
|
|
393
|
-
return this._layers[layer]?.bladeWidth ?? 0;
|
|
394
|
-
}
|
|
395
|
-
/**
|
|
396
|
-
* Gets height of the grass blades in the grass layer at given index
|
|
397
|
-
* @param layer - Index of the grass layer
|
|
398
|
-
* @returns Height of the grass blades in the layer
|
|
399
|
-
*/ getBladeHeight(layer) {
|
|
400
|
-
return this._layers[layer]?.bladeHeight ?? 0;
|
|
401
|
-
}
|
|
402
|
-
/**
|
|
403
|
-
* Sets size of the grass blades in the grass layer at given index
|
|
404
|
-
* @param layer - Index of the grass layer
|
|
405
|
-
* @param width - Width to set
|
|
406
|
-
* @param height - Height to set
|
|
407
|
-
*/ setBladeSize(layer, width, height) {
|
|
408
|
-
const grassLayer = this._layers[layer];
|
|
409
|
-
if (grassLayer) {
|
|
410
|
-
grassLayer.setBladeSize(width, height);
|
|
411
|
-
} else {
|
|
412
|
-
console.error(`Invalid grass layer: ${layer}`);
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
/**
|
|
416
|
-
* Add grass instances to the grass layer at given index
|
|
417
|
-
* @param layer - Index of the grass layer
|
|
418
|
-
* @param instances - Grass blade instances to add
|
|
419
|
-
*/ addInstances(layer, instances) {
|
|
420
|
-
const grassLayer = this._layers[layer];
|
|
421
|
-
if (!grassLayer) {
|
|
422
|
-
console.error(`Invalid grass layer: ${layer}`);
|
|
423
|
-
} else {
|
|
424
|
-
grassLayer.addInstances(instances);
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
/**
|
|
428
|
-
* Remove grass instances from the grass layer at given index within a region
|
|
429
|
-
* @param layer - Index of the grass layer
|
|
430
|
-
* @param minX - Minimum x of the region
|
|
431
|
-
* @param minZ - Minimum z of the region
|
|
432
|
-
* @param maxX - Maximum x of the region
|
|
433
|
-
* @param maxZ - Maximum z of the region
|
|
434
|
-
* @param num - How many grass blades to remove
|
|
435
|
-
*/ removeInstances(layer, minX, minZ, maxX, maxZ, num) {
|
|
436
|
-
const grassLayer = this._layers[layer];
|
|
437
|
-
if (!grassLayer) {
|
|
438
|
-
console.error(`Invalid grass layer: ${layer}`);
|
|
439
|
-
} else {
|
|
440
|
-
grassLayer.removeInstances(minX, minZ, maxX, maxZ, num);
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
/** @internal */ draw(ctx) {
|
|
444
|
-
const bv = this._terrain.get().getWorldBoundingVolume().toAABB();
|
|
445
|
-
const minY = bv.minPoint.y;
|
|
446
|
-
const maxY = bv.maxPoint.y;
|
|
447
|
-
for (const layer of this._layers){
|
|
448
|
-
layer.draw(ctx, this._terrain.get().worldRegion, minY - layer.bladeHeight, maxY + layer.bladeHeight);
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
onDispose() {
|
|
452
|
-
super.onDispose();
|
|
453
|
-
this._terrain.dispose();
|
|
454
|
-
for (const layer of this._layers){
|
|
455
|
-
layer.dispose();
|
|
456
|
-
}
|
|
457
|
-
this._layers = null;
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
/** @internal */ class GrassQuadtreeNode extends Disposable {
|
|
461
|
-
static _cullAABB = new AABB();
|
|
462
|
-
_grassInstances;
|
|
463
|
-
_children;
|
|
464
|
-
_baseVertexBuffer;
|
|
465
|
-
_indexBuffer;
|
|
466
|
-
_minX;
|
|
467
|
-
_minZ;
|
|
468
|
-
_maxX;
|
|
469
|
-
_maxZ;
|
|
470
|
-
constructor(baseVertexBuffer, indexBuffer){
|
|
471
|
-
super();
|
|
472
|
-
this._baseVertexBuffer = new DRef(baseVertexBuffer);
|
|
473
|
-
this._indexBuffer = new DRef(indexBuffer);
|
|
474
|
-
this._grassInstances = new DRef(new GrassInstances(baseVertexBuffer, indexBuffer));
|
|
475
|
-
this._children = null;
|
|
476
|
-
this._minX = 0;
|
|
477
|
-
this._minZ = 0;
|
|
478
|
-
this._maxX = 1;
|
|
479
|
-
this._maxZ = 1;
|
|
480
|
-
}
|
|
481
|
-
get grassInstances() {
|
|
482
|
-
return this._grassInstances.get();
|
|
483
|
-
}
|
|
484
|
-
get children() {
|
|
485
|
-
return this._children;
|
|
486
|
-
}
|
|
487
|
-
draw(camera, region, minY, maxY, skipClipTest) {
|
|
488
|
-
if (!skipClipTest) {
|
|
489
|
-
const cullAABB = GrassQuadtreeNode._cullAABB;
|
|
490
|
-
const x = region.x;
|
|
491
|
-
const z = region.y;
|
|
492
|
-
const dx = region.z - x;
|
|
493
|
-
const dz = region.w - z;
|
|
494
|
-
cullAABB.minPoint.setXYZ(x + this._minX * dx, minY, z + this._minZ * dz);
|
|
495
|
-
cullAABB.maxPoint.setXYZ(x + this._maxX * dx, maxY, z + this._maxZ * dz);
|
|
496
|
-
const clipState = camera.clipMask ? cullAABB.getClipStateWithFrustumMask(camera.frustum, camera.clipMask) : cullAABB.getClipStateWithFrustum(camera.frustum);
|
|
497
|
-
if (clipState === ClipState.NOT_CLIPPED) {
|
|
498
|
-
return;
|
|
499
|
-
}
|
|
500
|
-
skipClipTest = clipState === ClipState.A_INSIDE_B;
|
|
501
|
-
}
|
|
502
|
-
if (this._grassInstances.get().numInstances > 0) {
|
|
503
|
-
this._grassInstances.get().draw();
|
|
504
|
-
}
|
|
505
|
-
if (this._children) {
|
|
506
|
-
for (const child of this._children){
|
|
507
|
-
child.draw(camera, region, minY, maxY, skipClipTest);
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
setBaseVertexBuffer(baseVertexBuffer) {
|
|
512
|
-
if (baseVertexBuffer !== this._baseVertexBuffer.get()) {
|
|
513
|
-
this._baseVertexBuffer.set(baseVertexBuffer);
|
|
514
|
-
this._grassInstances.get().setBaseVertexBuffer(baseVertexBuffer);
|
|
515
|
-
if (this._children) {
|
|
516
|
-
for (const child of this._children){
|
|
517
|
-
child.setBaseVertexBuffer(baseVertexBuffer);
|
|
518
|
-
}
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
removeInstances(minX, minZ, maxX, maxZ, numInstances) {
|
|
523
|
-
let n = Math.min(this._grassInstances.get().numInstances, numInstances);
|
|
524
|
-
if (n <= 0) {
|
|
525
|
-
return 0;
|
|
526
|
-
}
|
|
527
|
-
let removed = 0;
|
|
528
|
-
if (this._children) {
|
|
529
|
-
for (const child of this._children){
|
|
530
|
-
if (child._minX < maxX && child._minZ < maxZ && child._maxX > minX && child._maxZ > minZ) {
|
|
531
|
-
removed += child.removeInstances(minX, minZ, maxX, maxZ, n);
|
|
532
|
-
n -= removed;
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
if (n > 0) {
|
|
537
|
-
removed += this._grassInstances.get().removeInstances(minX, minZ, maxX, maxZ, n);
|
|
538
|
-
}
|
|
539
|
-
return removed;
|
|
540
|
-
}
|
|
541
|
-
addInstances(instances) {
|
|
542
|
-
if (instances.length === 0) {
|
|
543
|
-
return 0;
|
|
544
|
-
}
|
|
545
|
-
let n = Math.min(instances.length, MAX_INSTANCES_PER_NODE - this._grassInstances.get().numInstances);
|
|
546
|
-
this._grassInstances.get().addInstances(instances.slice(0, n));
|
|
547
|
-
if (n < instances.length) {
|
|
548
|
-
if (!this._children) {
|
|
549
|
-
this._children = [
|
|
550
|
-
new GrassQuadtreeNode(this._baseVertexBuffer.get(), this._indexBuffer.get()),
|
|
551
|
-
new GrassQuadtreeNode(this._baseVertexBuffer.get(), this._indexBuffer.get()),
|
|
552
|
-
new GrassQuadtreeNode(this._baseVertexBuffer.get(), this._indexBuffer.get()),
|
|
553
|
-
new GrassQuadtreeNode(this._baseVertexBuffer.get(), this._indexBuffer.get())
|
|
554
|
-
];
|
|
555
|
-
this._children[0]._minX = this._minX;
|
|
556
|
-
this._children[0]._minZ = this._minZ;
|
|
557
|
-
this._children[0]._maxX = (this._minX + this._maxX) * 0.5;
|
|
558
|
-
this._children[0]._maxZ = (this._minZ + this._maxZ) * 0.5;
|
|
559
|
-
this._children[1]._minX = this._children[0]._maxX;
|
|
560
|
-
this._children[1]._minZ = this._minZ;
|
|
561
|
-
this._children[1]._maxX = this._maxX;
|
|
562
|
-
this._children[1]._maxZ = this._children[0]._maxZ;
|
|
563
|
-
this._children[2]._minX = this._minX;
|
|
564
|
-
this._children[2]._minZ = this._children[0]._maxZ;
|
|
565
|
-
this._children[2]._maxX = this._children[0]._maxX;
|
|
566
|
-
this._children[2]._maxZ = this._maxZ;
|
|
567
|
-
this._children[3]._minX = this._children[0]._maxX;
|
|
568
|
-
this._children[3]._minZ = this._children[0]._maxZ;
|
|
569
|
-
this._children[3]._maxX = this._maxX;
|
|
570
|
-
this._children[3]._maxZ = this._maxZ;
|
|
571
|
-
}
|
|
572
|
-
for (const child of this._children){
|
|
573
|
-
if (n < instances.length) {
|
|
574
|
-
n += child.addInstances(instances.slice(n).filter((val)=>val.x >= child._minX && val.y >= child._minZ && val.x < child._maxX && val.y < child._maxZ));
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
}
|
|
578
|
-
return n;
|
|
579
|
-
}
|
|
580
|
-
onDispose() {
|
|
581
|
-
super.onDispose();
|
|
582
|
-
this._baseVertexBuffer.dispose();
|
|
583
|
-
this._indexBuffer.dispose();
|
|
584
|
-
this._grassInstances.dispose();
|
|
585
|
-
if (this._children) {
|
|
586
|
-
for (const child of this._children){
|
|
587
|
-
child.dispose();
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
}
|
|
591
|
-
}
|
|
592
|
-
|
|
593
|
-
export { GrassInstances, GrassLayer, GrassQuadtreeNode, GrassRenderer };
|
|
594
|
-
//# sourceMappingURL=grass.js.map
|