@zephyr3d/scene 0.9.14 → 0.9.16
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.map +1 -1
- package/dist/app/engine.js +3 -1
- package/dist/app/engine.js.map +1 -1
- package/dist/asset/assetmanager.js +1 -0
- package/dist/asset/assetmanager.js.map +1 -1
- package/dist/camera/camera.js +87 -0
- package/dist/camera/camera.js.map +1 -1
- package/dist/index.d.ts +380 -6
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -1
- package/dist/material/meshmaterial.js +8 -1
- package/dist/material/meshmaterial.js.map +1 -1
- package/dist/material/shader/helper.js +6 -0
- package/dist/material/shader/helper.js.map +1 -1
- package/dist/material/skin.js +263 -0
- package/dist/material/skin.js.map +1 -0
- package/dist/posteffect/compositor.js +3 -0
- package/dist/posteffect/compositor.js.map +1 -1
- package/dist/posteffect/sao.js +1 -1
- package/dist/posteffect/sao.js.map +1 -1
- package/dist/posteffect/skinsss.js +194 -0
- package/dist/posteffect/skinsss.js.map +1 -0
- package/dist/posteffect/ssr.js +26 -49
- package/dist/posteffect/ssr.js.map +1 -1
- package/dist/posteffect/sss.js +1 -0
- package/dist/posteffect/sss.js.map +1 -1
- package/dist/posteffect/taa.js +2 -40
- package/dist/posteffect/taa.js.map +1 -1
- package/dist/render/abuffer_oit.js +1 -0
- package/dist/render/abuffer_oit.js.map +1 -1
- package/dist/render/drawable_mixin.js +1 -0
- package/dist/render/drawable_mixin.js.map +1 -1
- package/dist/render/fbm_wavegenerator.js +1 -0
- package/dist/render/fbm_wavegenerator.js.map +1 -1
- package/dist/render/gerstner_wavegenerator.js +1 -0
- package/dist/render/gerstner_wavegenerator.js.map +1 -1
- package/dist/render/globalbindgroup_allocator.js +1 -0
- package/dist/render/globalbindgroup_allocator.js.map +1 -1
- package/dist/render/lightpass.js +4 -1
- package/dist/render/lightpass.js.map +1 -1
- package/dist/render/render_queue.js +1 -0
- package/dist/render/render_queue.js.map +1 -1
- package/dist/render/renderer.js +1 -0
- package/dist/render/renderer.js.map +1 -1
- package/dist/render/rendergraph/device_pool_allocator.js +12 -5
- package/dist/render/rendergraph/device_pool_allocator.js.map +1 -1
- package/dist/render/rendergraph/executor.js +270 -1
- package/dist/render/rendergraph/executor.js.map +1 -1
- package/dist/render/rendergraph/forward_plus_builder.js +97 -9
- package/dist/render/rendergraph/forward_plus_builder.js.map +1 -1
- package/dist/render/rendergraph/types.js.map +1 -1
- package/dist/scene/basesprite.js +1 -0
- package/dist/scene/basesprite.js.map +1 -1
- package/dist/scene/batchgroup.js +1 -0
- package/dist/scene/batchgroup.js.map +1 -1
- package/dist/scene/environment.js +1 -0
- package/dist/scene/environment.js.map +1 -1
- package/dist/scene/light.js +6 -4
- package/dist/scene/light.js.map +1 -1
- package/dist/scene/mesh.js +1 -0
- package/dist/scene/mesh.js.map +1 -1
- package/dist/scene/msdftext.js +1 -0
- package/dist/scene/msdftext.js.map +1 -1
- package/dist/scene/msdftextsprite.js +1 -0
- package/dist/scene/msdftextsprite.js.map +1 -1
- package/dist/scene/particlesys.js +1 -0
- package/dist/scene/particlesys.js.map +1 -1
- package/dist/scene/scene.js +2 -0
- package/dist/scene/scene.js.map +1 -1
- package/dist/scene/terrain-cm/grass.js +1 -0
- package/dist/scene/terrain-cm/grass.js.map +1 -1
- package/dist/scene/terrain-cm/grassmaterial.js +1 -0
- package/dist/scene/terrain-cm/grassmaterial.js.map +1 -1
- package/dist/scene/terrain-cm/terrain-cm.js +1 -0
- package/dist/scene/terrain-cm/terrain-cm.js.map +1 -1
- package/dist/scene/water.js +1 -0
- package/dist/scene/water.js.map +1 -1
- package/dist/shaders/shadow.js +504 -1
- package/dist/shaders/shadow.js.map +1 -1
- package/dist/shadow/esm.js +1 -0
- package/dist/shadow/esm.js.map +1 -1
- package/dist/shadow/pcf_opt.js +1 -0
- package/dist/shadow/pcf_opt.js.map +1 -1
- package/dist/shadow/pcf_pd.js +1 -0
- package/dist/shadow/pcf_pd.js.map +1 -1
- package/dist/shadow/pcss.js +181 -0
- package/dist/shadow/pcss.js.map +1 -0
- package/dist/shadow/shader.js +1 -0
- package/dist/shadow/shader.js.map +1 -1
- package/dist/shadow/shadow_impl.js.map +1 -1
- package/dist/shadow/shadowmapper.js +86 -8
- package/dist/shadow/shadowmapper.js.map +1 -1
- package/dist/shadow/ssm.js +1 -0
- package/dist/shadow/ssm.js.map +1 -1
- package/dist/shadow/vsm.js +1 -0
- package/dist/shadow/vsm.js.map +1 -1
- package/dist/utility/serialization/manager.js +3 -1
- package/dist/utility/serialization/manager.js.map +1 -1
- package/dist/utility/serialization/scene/animation.js +1 -0
- package/dist/utility/serialization/scene/animation.js.map +1 -1
- package/dist/utility/serialization/scene/batch.js +1 -0
- package/dist/utility/serialization/scene/batch.js.map +1 -1
- package/dist/utility/serialization/scene/camera.js +122 -0
- package/dist/utility/serialization/scene/camera.js.map +1 -1
- package/dist/utility/serialization/scene/common.js +1 -0
- package/dist/utility/serialization/scene/common.js.map +1 -1
- package/dist/utility/serialization/scene/light.js +82 -21
- package/dist/utility/serialization/scene/light.js.map +1 -1
- package/dist/utility/serialization/scene/material.js +195 -3
- package/dist/utility/serialization/scene/material.js.map +1 -1
- package/dist/utility/serialization/scene/mesh.js +1 -0
- package/dist/utility/serialization/scene/mesh.js.map +1 -1
- package/dist/utility/serialization/scene/node.js +1 -0
- package/dist/utility/serialization/scene/node.js.map +1 -1
- package/dist/utility/serialization/scene/particle.js +1 -0
- package/dist/utility/serialization/scene/particle.js.map +1 -1
- package/dist/utility/serialization/scene/primitive.js +1 -0
- package/dist/utility/serialization/scene/primitive.js.map +1 -1
- package/dist/utility/serialization/scene/sprite.js +1 -0
- package/dist/utility/serialization/scene/sprite.js.map +1 -1
- package/dist/utility/serialization/scene/terrain.js +1 -0
- package/dist/utility/serialization/scene/terrain.js.map +1 -1
- package/dist/utility/serialization/scene/text.js +1 -0
- package/dist/utility/serialization/scene/text.js.map +1 -1
- package/dist/utility/serialization/scene/water.js +1 -0
- package/dist/utility/serialization/scene/water.js.map +1 -1
- package/dist/values.js +1 -0
- package/dist/values.js.map +1 -1
- package/package.json +2 -2
- package/dist/animation/joint_dynamics/convex_collider.js +0 -320
- package/dist/animation/joint_dynamics/convex_collider.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sources":["../../../src/render/rendergraph/types.ts"],"sourcesContent":["import type { TextureFormat } from '@zephyr3d/device';\r\n\r\n// ─── Resource Descriptors ───────────────────────────────────────────────\r\n\r\n/**\r\n * Sizing mode for render graph textures.\r\n *\r\n * - 'absolute': fixed pixel dimensions\r\n * - 'backbuffer-relative': scaled relative to the backbuffer size\r\n *\r\n * @public\r\n */\r\nexport type RGSizeMode = 'absolute' | 'backbuffer-relative';\r\n\r\n/**\r\n * Descriptor for a transient texture resource within the render graph.\r\n *\r\n * Transient textures are allocated and released automatically by the graph compiler.\r\n *\r\n * @public\r\n */\r\nexport interface RGTextureDesc {\r\n /** Debug label for this resource. */\r\n label?: string;\r\n /** Texture format (e.g. 'rgba8unorm', 'r32f', 'rgba16f'). */\r\n format: TextureFormat;\r\n /** Sizing mode. Default 'backbuffer-relative'. */\r\n sizeMode?: RGSizeMode;\r\n /** Width in pixels (absolute) or scale factor (backbuffer-relative, default 1.0). */\r\n width?: number;\r\n /** Height in pixels (absolute) or scale factor (backbuffer-relative, default 1.0). */\r\n height?: number;\r\n /** Number of mip levels. Default 1. */\r\n mipLevels?: number;\r\n}\r\n\r\n// ─── Handles ────────────────────────────────────────────────────────────\r\n\r\n/**\r\n * Opaque handle referencing a resource within the render graph.\r\n *\r\n * Handles are obtained from {@link RGPassBuilder.createTexture}, {@link RGPassBuilder.createFramebuffer},\r\n * {@link RenderGraph.importTexture}, or {@link RGPassBuilder.write}. They are lightweight identifiers\r\n * used to declare dependencies between passes.\r\n *\r\n * @public\r\n */\r\nexport class RGHandle {\r\n /** @internal */\r\n readonly _id: number;\r\n /** @internal */\r\n readonly _name: string;\r\n\r\n /** @internal */\r\n constructor(id: number, name: string) {\r\n this._id = id;\r\n this._name = name;\r\n }\r\n\r\n /** Debug-friendly name of the referenced resource. */\r\n get name(): string {\r\n return this._name;\r\n }\r\n}\r\n\r\n// ─── Internal Resource Tracking ─────────────────────────────────────────\r\n\r\n/** @public */\r\nexport type RGResourceKind = 'transient' | 'imported' | 'token' | 'framebuffer';\r\n\r\n/**\r\n * Internal bookkeeping for a resource within the render graph.\r\n * @public\r\n */\r\nexport class RGResource {\r\n readonly id: number;\r\n readonly name: string;\r\n readonly kind: RGResourceKind;\r\n readonly desc: RGTextureDesc | RGFramebufferDesc | null;\r\n /** Resource ID of the physical backing resource used by imported versions. */\r\n readonly physicalId: number;\r\n /** The pass that creates / writes this resource (null for imported until written). */\r\n producer: RGPass | null = null;\r\n /** Passes that read this resource. */\r\n readonly consumers: RGPass[] = [];\r\n\r\n constructor(\r\n id: number,\r\n name: string,\r\n kind: RGResourceKind,\r\n desc: RGTextureDesc | RGFramebufferDesc | null,\r\n physicalId = id\r\n ) {\r\n this.id = id;\r\n this.name = name;\r\n this.kind = kind;\r\n this.desc = desc;\r\n this.physicalId = physicalId;\r\n }\r\n}\r\n\r\n// ─── Internal Pass Tracking ─────────────────────────────────────────────\r\n\r\n// ─── Execution Context ──────────────────────────────────────────────\r\n\r\n/**\r\n * Context passed to pass execute callbacks during graph execution.\r\n *\r\n * Provides access to resolved GPU resources by their handles.\r\n *\r\n * @public\r\n */\r\nexport interface RGExecuteContext {\r\n /**\r\n * Resolve a handle to the actual GPU texture object.\r\n *\r\n * For transient resources, this returns the texture allocated by the executor.\r\n * For imported resources, this returns the texture registered via\r\n * {@link RenderGraphExecutor.setImportedTexture}. The handle must be declared\r\n * by the current pass with {@link RGPassBuilder.read} or {@link RGPassBuilder.write}.\r\n *\r\n * @param handle - Handle of the resource to resolve.\r\n * @returns The resolved texture object (type depends on the allocator).\r\n */\r\n getTexture<TTexture = unknown>(handle: RGHandle): TTexture;\r\n\r\n /**\r\n * Resolve a framebuffer handle to the actual backend framebuffer object.\r\n *\r\n * The handle must be declared by the current pass with {@link RGPassBuilder.read}\r\n * or created by the same pass with {@link RGPassBuilder.createFramebuffer}.\r\n *\r\n * @param handle - Handle returned from {@link RGPassBuilder.createFramebuffer}.\r\n * @returns The resolved framebuffer object (type depends on the allocator).\r\n */\r\n getFramebuffer<TFramebuffer = unknown>(handle: RGHandle): TFramebuffer;\r\n\r\n /**\r\n * Create a temporary framebuffer managed by the graph executor.\r\n *\r\n * The framebuffer is released automatically when graph execution finishes or\r\n * aborts. Attachments may be actual backend resources or texture formats,\r\n * depending on the allocator implementation. If an attachment is an\r\n * {@link RGHandle}, the current pass must declare it with\r\n * {@link RGPassBuilder.read} or {@link RGPassBuilder.write}.\r\n *\r\n * @param desc - Framebuffer descriptor.\r\n * @returns The allocated framebuffer object (type depends on the allocator).\r\n */\r\n createFramebuffer<TFramebuffer = unknown>(desc: RGFramebufferDesc): TFramebuffer;\r\n\r\n /**\r\n * Register a cleanup callback to run when graph execution finishes or aborts.\r\n *\r\n * Callbacks run in reverse registration order. Use this for temporary objects\r\n * created inside pass execution that are not graph resources, such as pooled\r\n * framebuffers wrapping graph-managed textures. If pass execution throws, the\r\n * executor still runs cleanup callbacks and preserves the original pass error\r\n * ahead of cleanup errors.\r\n *\r\n * @param callback - Cleanup function to invoke after execution.\r\n */\r\n deferCleanup(callback: () => void): void;\r\n}\r\n\r\n/**\r\n * Execute callback signature.\r\n *\r\n * The callback receives a context for resolving handles to GPU resources,\r\n * plus the user data returned from the setup function.\r\n *\r\n * @public\r\n */\r\nexport type RGExecuteFn<T = void> = (ctx: RGExecuteContext, data: T) => void;\r\n\r\n/**\r\n * Ordered execution step inside a render graph pass.\r\n *\r\n * Subpasses share the parent pass's resource declarations, lifetime, culling,\r\n * and access validation. They are intended to make multi-step pass bodies\r\n * explicit without splitting graph-level resource dependencies.\r\n *\r\n * @public\r\n */\r\nexport class RGSubpass<T = unknown> {\r\n readonly name: string;\r\n readonly executeFn: RGExecuteFn<T>;\r\n\r\n constructor(name: string, executeFn: RGExecuteFn<T>) {\r\n this.name = name;\r\n this.executeFn = executeFn;\r\n }\r\n}\r\n\r\n/**\r\n * Internal bookkeeping for a pass within the render graph.\r\n * @public\r\n */\r\nexport class RGPass<T = unknown> {\r\n readonly index: number;\r\n readonly name: string;\r\n /** Resources this pass reads (dependencies). */\r\n readonly reads: RGResource[] = [];\r\n /** Resources this pass creates or writes. */\r\n readonly writes: RGResource[] = [];\r\n /** Passes that must complete before this pass due to non-resource hazards. */\r\n readonly dependencies: RGPass[] = [];\r\n /** Whether this pass has side effects and must not be culled. */\r\n hasSideEffect = false;\r\n /** User data returned from the setup function. */\r\n data: T | null = null;\r\n /** Execute callback. */\r\n executeFn: RGExecuteFn<T> | null = null;\r\n /** Ordered subpasses for passes with multiple logical execution steps. */\r\n readonly subpasses: RGSubpass<T>[] = [];\r\n /** Set during compilation: true if this pass is needed. */\r\n alive = true;\r\n\r\n constructor(index: number, name: string) {\r\n this.index = index;\r\n this.name = name;\r\n }\r\n}\r\n\r\n// ─── Pass Builder ───────────────────────────────────────────────────────\r\n\r\n/**\r\n * Builder interface used within the setup callback of {@link RenderGraph.addPass}\r\n * to declare a pass's resource requirements.\r\n *\r\n * @public\r\n */\r\nexport interface RGPassBuilder {\r\n /**\r\n * Declare a read dependency on an existing resource.\r\n *\r\n * The resource must have been created by a prior pass or imported into the graph.\r\n *\r\n * @param handle - Handle of the resource to read.\r\n */\r\n read(handle: RGHandle): void;\r\n\r\n /**\r\n * Declare that this pass writes a new version of an existing resource.\r\n *\r\n * The returned handle represents the post-write version. Use it for subsequent\r\n * reads and as the graph output passed to {@link RenderGraph.compile}. Passing\r\n * an older version of the same resource to `compile()` is rejected because it\r\n * usually means the caller ignored the handle returned by `write()`. If the pass\r\n * needs the previous contents, call {@link RGPassBuilder.read} on the input handle explicitly\r\n * before writing.\r\n *\r\n * @param handle - Handle of the resource to write to.\r\n * @returns A handle referencing the newly written version.\r\n */\r\n write(handle: RGHandle): RGHandle;\r\n\r\n /**\r\n * Create a new transient texture resource that this pass will produce.\r\n *\r\n * @param desc - Texture descriptor.\r\n * @returns A handle referencing the newly created resource.\r\n */\r\n createTexture(desc: RGTextureDesc): RGHandle;\r\n\r\n /**\r\n * Create a logical dependency token produced by this pass.\r\n *\r\n * Tokens do not resolve to GPU resources and are not allocated by the executor.\r\n * They are useful for ordering passes whose dependencies are side effects rather\r\n * than texture reads/writes.\r\n *\r\n * @param name - Debug label for this token.\r\n * @returns A handle referencing the newly created token.\r\n */\r\n createToken(name?: string): RGHandle;\r\n\r\n /**\r\n * Create a graph-managed framebuffer view.\r\n *\r\n * The graph compiler infers dependencies from any attachment handles in the\r\n * descriptor. The executor creates and releases the framebuffer automatically.\r\n *\r\n * @param desc - Framebuffer descriptor.\r\n * @returns A handle referencing the framebuffer view.\r\n */\r\n createFramebuffer(desc: RGFramebufferDesc): RGHandle;\r\n\r\n /**\r\n * Mark this pass as having side effects.\r\n *\r\n * Side-effect passes are never culled by the graph compiler, regardless of\r\n * whether their outputs are consumed. Use this for GPU readback, picking,\r\n * debug overlays, etc.\r\n */\r\n sideEffect(): void;\r\n\r\n /**\r\n * Add an ordered logical subpass to this pass.\r\n *\r\n * Subpasses execute in registration order and share the parent pass's declared\r\n * reads, writes, framebuffer views, and user data. A pass may use either\r\n * subpasses or {@link RGPassBuilder.setExecute}, but not both.\r\n *\r\n * @param name - Debug label for the subpass.\r\n * @param fn - Callback invoked when this subpass executes.\r\n */\r\n addSubpass<D>(name: string, fn: RGExecuteFn<D>): void;\r\n\r\n /**\r\n * Set the execution callback for this pass.\r\n *\r\n * A pass may use either this method or {@link RGPassBuilder.addSubpass}, but not both.\r\n *\r\n * @param fn - Callback invoked during graph execution.\r\n */\r\n setExecute<D>(fn: RGExecuteFn<D>): void;\r\n}\r\n\r\n// ─── Compiled Graph ─────────────────────────────────────────────────────\r\n\r\n/**\r\n * Lifetime information for a resource within the compiled graph.\r\n *\r\n * @public\r\n */\r\nexport interface RGResourceLifetime {\r\n /** The resource. */\r\n readonly resource: RGResource;\r\n /** Index of the first pass that uses (produces or reads) this resource. */\r\n readonly firstUse: number;\r\n /** Index of the last pass that uses this resource. */\r\n readonly lastUse: number;\r\n}\r\n\r\n/**\r\n * Result of compiling a render graph.\r\n *\r\n * Contains the ordered list of passes to execute and lifetime information\r\n * for automatic resource management.\r\n *\r\n * @public\r\n */\r\nexport interface CompiledRenderGraph {\r\n /** Topologically sorted passes (only non-culled passes). */\r\n readonly orderedPasses: ReadonlyArray<RGPass>;\r\n /** Resource lifetime information keyed by resource ID. */\r\n readonly lifetimes: ReadonlyMap<number, RGResourceLifetime>;\r\n}\r\n\r\n// ─── Texture Allocator ──────────────────────────────────────────────\r\n\r\n/**\r\n * Resolved dimensions for a texture allocation.\r\n * @public\r\n */\r\nexport interface RGResolvedSize {\r\n width: number;\r\n height: number;\r\n}\r\n\r\n/**\r\n * Descriptor for a framebuffer view managed by the graph or created temporarily during pass execution.\r\n *\r\n * This is intentionally backend-agnostic: graph-managed descriptors may use\r\n * {@link RGHandle} attachments, and executor-created descriptors use resolved\r\n * resources or texture formats understood by the allocator.\r\n *\r\n * @public\r\n */\r\nexport interface RGFramebufferDesc {\r\n /** Debug label for this framebuffer. */\r\n label?: string;\r\n /** Framebuffer width. Required when attachments are formats. */\r\n width?: number;\r\n /** Framebuffer height. Required when attachments are formats. */\r\n height?: number;\r\n /** Color attachments or formats. */\r\n colorAttachments: unknown | unknown[] | null;\r\n /** Depth/stencil attachment or format. */\r\n depthAttachment?: unknown | null;\r\n /** Whether color attachments created from formats should support mipmapping. */\r\n mipmapping?: boolean;\r\n /** Framebuffer sample count. */\r\n sampleCount?: number;\r\n /** Whether to ignore depth/stencil during MSAA resolve. */\r\n ignoreDepthStencil?: boolean;\r\n /** Attachment mip level. */\r\n attachmentMipLevel?: number;\r\n /** Attachment cubemap face. */\r\n attachmentCubeface?: number;\r\n /** Attachment array layer. */\r\n attachmentLayer?: number;\r\n}\r\n\r\n/**\r\n * Interface for allocating and releasing transient textures.\r\n *\r\n * Implement this to bridge the render graph with your GPU device's resource pool.\r\n * The executor calls `allocate()` before a resource's first use and\r\n * `release()` after its last use.\r\n *\r\n * @typeParam TTexture - The concrete texture type (e.g. `Texture2D`).\r\n * @public\r\n */\r\nexport interface RGTextureAllocator<TTexture = unknown, TFramebuffer = unknown> {\r\n /**\r\n * Allocate a transient texture matching the given descriptor and resolved size.\r\n *\r\n * @param desc - The texture descriptor from the pass builder.\r\n * @param size - The resolved pixel dimensions.\r\n * @returns The allocated texture object.\r\n */\r\n allocate(desc: RGTextureDesc, size: RGResolvedSize): TTexture;\r\n\r\n /**\r\n * Release a previously allocated transient texture back to the pool.\r\n *\r\n * @param texture - The texture to release.\r\n */\r\n release(texture: TTexture): void;\r\n\r\n /**\r\n * Retain a texture allocated by this allocator so it can outlive the graph pass\r\n * that produced it.\r\n *\r\n * This is used when a graph-produced transient texture must be handed off to\r\n * an external owner, such as a cross-frame history resource. Executors still\r\n * release the graph's own reference at the resource's last use; the external\r\n * owner must later call {@link RGTextureAllocator.release} for the retained\r\n * reference.\r\n *\r\n * Allocators that cannot retain transient textures should leave this undefined.\r\n */\r\n retain?(texture: TTexture): void;\r\n\r\n /**\r\n * Allocate a temporary framebuffer matching the given descriptor.\r\n *\r\n * Implementations should not auto-release this framebuffer; the graph executor\r\n * calls {@link RGTextureAllocator.releaseFramebuffer} when execution completes or aborts.\r\n *\r\n * @param desc - Framebuffer descriptor.\r\n * @returns The allocated framebuffer object.\r\n */\r\n allocateFramebuffer?(desc: RGFramebufferDesc): TFramebuffer;\r\n\r\n /**\r\n * Release a previously allocated temporary framebuffer.\r\n *\r\n * @param framebuffer - The framebuffer to release.\r\n */\r\n releaseFramebuffer?(framebuffer: TFramebuffer): void;\r\n}\r\n"],"names":["RGHandle","id","name","_id","_name","RGResource","kind","desc","producer","consumers","physicalId","RGSubpass","executeFn","RGPass","index","reads","writes","dependencies","hasSideE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4B,GAAA,EAAE;gEAEvCC,QAAQ,IAAK;IAEb,WAAYP,CAAAA,KAAa,EAAEZ,IAAY,CAAE;QACvC,IAAI,CAACY,KAAK,GAAGA,KAAAA;QACb,IAAI,CAACZ,IAAI,GAAGA,IAAAA;AACd;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"types.js","sources":["../../../src/render/rendergraph/types.ts"],"sourcesContent":["import type { AbstractDevice, TextureFormat, TimestampQueryStatus } from '@zephyr3d/device';\r\n\r\n// ─── Resource Descriptors ───────────────────────────────────────────────\r\n\r\n/**\r\n * Sizing mode for render graph textures.\r\n *\r\n * - 'absolute': fixed pixel dimensions\r\n * - 'backbuffer-relative': scaled relative to the backbuffer size\r\n *\r\n * @public\r\n */\r\nexport type RGSizeMode = 'absolute' | 'backbuffer-relative';\r\n\r\n/**\r\n * Descriptor for a transient texture resource within the render graph.\r\n *\r\n * Transient textures are allocated and released automatically by the graph compiler.\r\n *\r\n * @public\r\n */\r\nexport interface RGTextureDesc {\r\n /** Debug label for this resource. */\r\n label?: string;\r\n /** Texture format (e.g. 'rgba8unorm', 'r32f', 'rgba16f'). */\r\n format: TextureFormat;\r\n /** Sizing mode. Default 'backbuffer-relative'. */\r\n sizeMode?: RGSizeMode;\r\n /** Width in pixels (absolute) or scale factor (backbuffer-relative, default 1.0). */\r\n width?: number;\r\n /** Height in pixels (absolute) or scale factor (backbuffer-relative, default 1.0). */\r\n height?: number;\r\n /** Number of mip levels. Default 1. */\r\n mipLevels?: number;\r\n}\r\n\r\n// ─── Handles ────────────────────────────────────────────────────────────\r\n\r\n/**\r\n * Opaque handle referencing a resource within the render graph.\r\n *\r\n * Handles are obtained from {@link RGPassBuilder.createTexture}, {@link RGPassBuilder.createFramebuffer},\r\n * {@link RenderGraph.importTexture}, or {@link RGPassBuilder.write}. They are lightweight identifiers\r\n * used to declare dependencies between passes.\r\n *\r\n * @public\r\n */\r\nexport class RGHandle {\r\n /** @internal */\r\n readonly _id: number;\r\n /** @internal */\r\n readonly _name: string;\r\n\r\n /** @internal */\r\n constructor(id: number, name: string) {\r\n this._id = id;\r\n this._name = name;\r\n }\r\n\r\n /** Debug-friendly name of the referenced resource. */\r\n get name(): string {\r\n return this._name;\r\n }\r\n}\r\n\r\n// ─── Internal Resource Tracking ─────────────────────────────────────────\r\n\r\n/** @public */\r\nexport type RGResourceKind = 'transient' | 'imported' | 'token' | 'framebuffer';\r\n\r\n/**\r\n * Internal bookkeeping for a resource within the render graph.\r\n * @public\r\n */\r\nexport class RGResource {\r\n readonly id: number;\r\n readonly name: string;\r\n readonly kind: RGResourceKind;\r\n readonly desc: RGTextureDesc | RGFramebufferDesc | null;\r\n /** Resource ID of the physical backing resource used by imported versions. */\r\n readonly physicalId: number;\r\n /** The pass that creates / writes this resource (null for imported until written). */\r\n producer: RGPass | null = null;\r\n /** Passes that read this resource. */\r\n readonly consumers: RGPass[] = [];\r\n\r\n constructor(\r\n id: number,\r\n name: string,\r\n kind: RGResourceKind,\r\n desc: RGTextureDesc | RGFramebufferDesc | null,\r\n physicalId = id\r\n ) {\r\n this.id = id;\r\n this.name = name;\r\n this.kind = kind;\r\n this.desc = desc;\r\n this.physicalId = physicalId;\r\n }\r\n}\r\n\r\n// ─── Internal Pass Tracking ─────────────────────────────────────────────\r\n\r\n// ─── Execution Context ──────────────────────────────────────────────\r\n\r\n/**\r\n * Context passed to pass execute callbacks during graph execution.\r\n *\r\n * Provides access to resolved GPU resources by their handles.\r\n *\r\n * @public\r\n */\r\nexport interface RGExecuteContext {\r\n /**\r\n * Resolve a handle to the actual GPU texture object.\r\n *\r\n * For transient resources, this returns the texture allocated by the executor.\r\n * For imported resources, this returns the texture registered via\r\n * {@link RenderGraphExecutor.setImportedTexture}. The handle must be declared\r\n * by the current pass with {@link RGPassBuilder.read} or {@link RGPassBuilder.write}.\r\n *\r\n * @param handle - Handle of the resource to resolve.\r\n * @returns The resolved texture object (type depends on the allocator).\r\n */\r\n getTexture<TTexture = unknown>(handle: RGHandle): TTexture;\r\n\r\n /**\r\n * Resolve a framebuffer handle to the actual backend framebuffer object.\r\n *\r\n * The handle must be declared by the current pass with {@link RGPassBuilder.read}\r\n * or created by the same pass with {@link RGPassBuilder.createFramebuffer}.\r\n *\r\n * @param handle - Handle returned from {@link RGPassBuilder.createFramebuffer}.\r\n * @returns The resolved framebuffer object (type depends on the allocator).\r\n */\r\n getFramebuffer<TFramebuffer = unknown>(handle: RGHandle): TFramebuffer;\r\n\r\n /**\r\n * Create a temporary framebuffer managed by the graph executor.\r\n *\r\n * The framebuffer is released automatically when graph execution finishes or\r\n * aborts. Attachments may be actual backend resources or texture formats,\r\n * depending on the allocator implementation. If an attachment is an\r\n * {@link RGHandle}, the current pass must declare it with\r\n * {@link RGPassBuilder.read} or {@link RGPassBuilder.write}.\r\n *\r\n * @param desc - Framebuffer descriptor.\r\n * @returns The allocated framebuffer object (type depends on the allocator).\r\n */\r\n createFramebuffer<TFramebuffer = unknown>(desc: RGFramebufferDesc): TFramebuffer;\r\n\r\n /**\r\n * Register a cleanup callback to run when graph execution finishes or aborts.\r\n *\r\n * Callbacks run in reverse registration order. Use this for temporary objects\r\n * created inside pass execution that are not graph resources, such as pooled\r\n * framebuffers wrapping graph-managed textures. If pass execution throws, the\r\n * executor still runs cleanup callbacks and preserves the original pass error\r\n * ahead of cleanup errors.\r\n *\r\n * @param callback - Cleanup function to invoke after execution.\r\n */\r\n deferCleanup(callback: () => void): void;\r\n}\r\n\r\n/**\r\n * Execute callback signature.\r\n *\r\n * The callback receives a context for resolving handles to GPU resources,\r\n * plus the user data returned from the setup function.\r\n *\r\n * @public\r\n */\r\nexport type RGExecuteFn<T = void> = (ctx: RGExecuteContext, data: T) => void;\r\n\r\n/**\r\n * Ordered execution step inside a render graph pass.\r\n *\r\n * Subpasses share the parent pass's resource declarations, lifetime, culling,\r\n * and access validation. They are intended to make multi-step pass bodies\r\n * explicit without splitting graph-level resource dependencies.\r\n *\r\n * @public\r\n */\r\nexport class RGSubpass<T = unknown> {\r\n readonly name: string;\r\n readonly executeFn: RGExecuteFn<T>;\r\n\r\n constructor(name: string, executeFn: RGExecuteFn<T>) {\r\n this.name = name;\r\n this.executeFn = executeFn;\r\n }\r\n}\r\n\r\n/**\r\n * Internal bookkeeping for a pass within the render graph.\r\n * @public\r\n */\r\nexport class RGPass<T = unknown> {\r\n readonly index: number;\r\n readonly name: string;\r\n /** Resources this pass reads (dependencies). */\r\n readonly reads: RGResource[] = [];\r\n /** Resources this pass creates or writes. */\r\n readonly writes: RGResource[] = [];\r\n /** Passes that must complete before this pass due to non-resource hazards. */\r\n readonly dependencies: RGPass[] = [];\r\n /** Whether this pass has side effects and must not be culled. */\r\n hasSideEffect = false;\r\n /** User data returned from the setup function. */\r\n data: T | null = null;\r\n /** Execute callback. */\r\n executeFn: RGExecuteFn<T> | null = null;\r\n /** Ordered subpasses for passes with multiple logical execution steps. */\r\n readonly subpasses: RGSubpass<T>[] = [];\r\n /** Set during compilation: true if this pass is needed. */\r\n alive = true;\r\n\r\n constructor(index: number, name: string) {\r\n this.index = index;\r\n this.name = name;\r\n }\r\n}\r\n\r\n// ─── Pass Builder ───────────────────────────────────────────────────────\r\n\r\n/**\r\n * Builder interface used within the setup callback of {@link RenderGraph.addPass}\r\n * to declare a pass's resource requirements.\r\n *\r\n * @public\r\n */\r\nexport interface RGPassBuilder {\r\n /**\r\n * Declare a read dependency on an existing resource.\r\n *\r\n * The resource must have been created by a prior pass or imported into the graph.\r\n *\r\n * @param handle - Handle of the resource to read.\r\n */\r\n read(handle: RGHandle): void;\r\n\r\n /**\r\n * Declare that this pass writes a new version of an existing resource.\r\n *\r\n * The returned handle represents the post-write version. Use it for subsequent\r\n * reads and as the graph output passed to {@link RenderGraph.compile}. Passing\r\n * an older version of the same resource to `compile()` is rejected because it\r\n * usually means the caller ignored the handle returned by `write()`. If the pass\r\n * needs the previous contents, call {@link RGPassBuilder.read} on the input handle explicitly\r\n * before writing.\r\n *\r\n * @param handle - Handle of the resource to write to.\r\n * @returns A handle referencing the newly written version.\r\n */\r\n write(handle: RGHandle): RGHandle;\r\n\r\n /**\r\n * Create a new transient texture resource that this pass will produce.\r\n *\r\n * @param desc - Texture descriptor.\r\n * @returns A handle referencing the newly created resource.\r\n */\r\n createTexture(desc: RGTextureDesc): RGHandle;\r\n\r\n /**\r\n * Create a logical dependency token produced by this pass.\r\n *\r\n * Tokens do not resolve to GPU resources and are not allocated by the executor.\r\n * They are useful for ordering passes whose dependencies are side effects rather\r\n * than texture reads/writes.\r\n *\r\n * @param name - Debug label for this token.\r\n * @returns A handle referencing the newly created token.\r\n */\r\n createToken(name?: string): RGHandle;\r\n\r\n /**\r\n * Create a graph-managed framebuffer view.\r\n *\r\n * The graph compiler infers dependencies from any attachment handles in the\r\n * descriptor. The executor creates and releases the framebuffer automatically.\r\n *\r\n * @param desc - Framebuffer descriptor.\r\n * @returns A handle referencing the framebuffer view.\r\n */\r\n createFramebuffer(desc: RGFramebufferDesc): RGHandle;\r\n\r\n /**\r\n * Mark this pass as having side effects.\r\n *\r\n * Side-effect passes are never culled by the graph compiler, regardless of\r\n * whether their outputs are consumed. Use this for GPU readback, picking,\r\n * debug overlays, etc.\r\n */\r\n sideEffect(): void;\r\n\r\n /**\r\n * Add an ordered logical subpass to this pass.\r\n *\r\n * Subpasses execute in registration order and share the parent pass's declared\r\n * reads, writes, framebuffer views, and user data. A pass may use either\r\n * subpasses or {@link RGPassBuilder.setExecute}, but not both.\r\n *\r\n * @param name - Debug label for the subpass.\r\n * @param fn - Callback invoked when this subpass executes.\r\n */\r\n addSubpass<D>(name: string, fn: RGExecuteFn<D>): void;\r\n\r\n /**\r\n * Set the execution callback for this pass.\r\n *\r\n * A pass may use either this method or {@link RGPassBuilder.addSubpass}, but not both.\r\n *\r\n * @param fn - Callback invoked during graph execution.\r\n */\r\n setExecute<D>(fn: RGExecuteFn<D>): void;\r\n}\r\n\r\n// ─── Compiled Graph ─────────────────────────────────────────────────────\r\n\r\n/**\r\n * Lifetime information for a resource within the compiled graph.\r\n *\r\n * @public\r\n */\r\nexport interface RGResourceLifetime {\r\n /** The resource. */\r\n readonly resource: RGResource;\r\n /** Index of the first pass that uses (produces or reads) this resource. */\r\n readonly firstUse: number;\r\n /** Index of the last pass that uses this resource. */\r\n readonly lastUse: number;\r\n}\r\n\r\n/**\r\n * Result of compiling a render graph.\r\n *\r\n * Contains the ordered list of passes to execute and lifetime information\r\n * for automatic resource management.\r\n *\r\n * @public\r\n */\r\nexport interface CompiledRenderGraph {\r\n /** Topologically sorted passes (only non-culled passes). */\r\n readonly orderedPasses: ReadonlyArray<RGPass>;\r\n /** Resource lifetime information keyed by resource ID. */\r\n readonly lifetimes: ReadonlyMap<number, RGResourceLifetime>;\r\n}\r\n\r\n/**\r\n * Profiling scope type in a render graph timing tree.\r\n * @public\r\n */\r\nexport type RGProfileScopeType = 'graph' | 'pass' | 'subpass';\r\n\r\n/**\r\n * Render graph GPU timestamp profiling options.\r\n * @public\r\n */\r\nexport interface RGProfilingOptions {\r\n /** Enable render graph timestamp profiling. Default true when an options object is provided. */\r\n enabled?: boolean;\r\n /** Measure the whole graph execution. Default true. */\r\n graph?: boolean;\r\n /** Measure every render graph pass. Default true. */\r\n pass?: boolean;\r\n /** Measure every subpass and expose it as a child scope. Default true. */\r\n subpass?: boolean;\r\n /** Include pending upload/copy commands at timestamp boundaries. Default true. */\r\n includePendingUploads?: boolean;\r\n /** Allow graph profile scopes to remain open across frame boundaries. Default false. */\r\n allowCrossFrame?: boolean;\r\n /** Maximum unresolved profile frames kept by the executor. Default 3. */\r\n maxPendingFrames?: number;\r\n /** Root graph profile label. Default 'RenderGraph'. */\r\n label?: string;\r\n /** Device used for timestamp queries. If omitted, the scene global getDevice() is used. */\r\n device?: AbstractDevice;\r\n}\r\n\r\n/**\r\n * Render graph executor construction options.\r\n * @public\r\n */\r\nexport interface RenderGraphExecutorOptions {\r\n /** Device used for timestamp queries. If omitted, the scene global getDevice() is used. */\r\n device?: AbstractDevice;\r\n /** Render graph timestamp profiling options. Default false. */\r\n profiling?: boolean | RGProfilingOptions;\r\n}\r\n\r\n/**\r\n * Resolved GPU timing for one graph/pass/subpass scope.\r\n * @public\r\n */\r\nexport interface RGProfileScopeResult {\r\n /** Scope label. */\r\n name: string;\r\n /** Scope type. */\r\n type: RGProfileScopeType;\r\n /** Timestamp query id used by the device, or 0 for synthetic/unsupported scopes. */\r\n queryId: number;\r\n /** GPU duration in milliseconds. */\r\n durationMs: number;\r\n /** Timestamp result status. */\r\n status: TimestampQueryStatus;\r\n /** Child scopes. */\r\n children: RGProfileScopeResult[];\r\n /** Optional diagnostic message. */\r\n message?: string;\r\n}\r\n\r\n/**\r\n * Resolved GPU timing tree for one render graph execution.\r\n * @public\r\n */\r\nexport interface RGProfileResult {\r\n /** Render frame id when profiling began. */\r\n frameId: number;\r\n /** Aggregate profile status. */\r\n status: TimestampQueryStatus;\r\n /** Root graph scope. */\r\n graph: RGProfileScopeResult;\r\n /** Top-level pass scopes. Same objects as graph.children. */\r\n passes: RGProfileScopeResult[];\r\n}\r\n\r\n// ─── Texture Allocator ──────────────────────────────────────────────\r\n\r\n/**\r\n * Resolved dimensions for a texture allocation.\r\n * @public\r\n */\r\nexport interface RGResolvedSize {\r\n width: number;\r\n height: number;\r\n}\r\n\r\n/**\r\n * Descriptor for a framebuffer view managed by the graph or created temporarily during pass execution.\r\n *\r\n * This is intentionally backend-agnostic: graph-managed descriptors may use\r\n * {@link RGHandle} attachments, and executor-created descriptors use resolved\r\n * resources or texture formats understood by the allocator.\r\n *\r\n * @public\r\n */\r\nexport interface RGFramebufferDesc {\r\n /** Debug label for this framebuffer. */\r\n label?: string;\r\n /** Framebuffer width. Required when attachments are formats. */\r\n width?: number;\r\n /** Framebuffer height. Required when attachments are formats. */\r\n height?: number;\r\n /** Color attachments or formats. */\r\n colorAttachments: unknown | unknown[] | null;\r\n /** Depth/stencil attachment or format. */\r\n depthAttachment?: unknown | null;\r\n /** Whether color attachments created from formats should support mipmapping. */\r\n mipmapping?: boolean;\r\n /** Framebuffer sample count. */\r\n sampleCount?: number;\r\n /** Whether to ignore depth/stencil during MSAA resolve. */\r\n ignoreDepthStencil?: boolean;\r\n /** Attachment mip level. */\r\n attachmentMipLevel?: number;\r\n /** Attachment cubemap face. */\r\n attachmentCubeface?: number;\r\n /** Attachment array layer. */\r\n attachmentLayer?: number;\r\n}\r\n\r\n/**\r\n * Interface for allocating and releasing transient textures.\r\n *\r\n * Implement this to bridge the render graph with your GPU device's resource pool.\r\n * The executor calls `allocate()` before a resource's first use and\r\n * `release()` after its last use.\r\n *\r\n * @typeParam TTexture - The concrete texture type (e.g. `Texture2D`).\r\n * @public\r\n */\r\nexport interface RGTextureAllocator<TTexture = unknown, TFramebuffer = unknown> {\r\n /**\r\n * Allocate a transient texture matching the given descriptor and resolved size.\r\n *\r\n * @param desc - The texture descriptor from the pass builder.\r\n * @param size - The resolved pixel dimensions.\r\n * @returns The allocated texture object.\r\n */\r\n allocate(desc: RGTextureDesc, size: RGResolvedSize): TTexture;\r\n\r\n /**\r\n * Release a previously allocated transient texture back to the pool.\r\n *\r\n * @param texture - The texture to release.\r\n */\r\n release(texture: TTexture): void;\r\n\r\n /**\r\n * Retain a texture allocated by this allocator so it can outlive the graph pass\r\n * that produced it.\r\n *\r\n * This is used when a graph-produced transient texture must be handed off to\r\n * an external owner, such as a cross-frame history resource. Executors still\r\n * release the graph's own reference at the resource's last use; the external\r\n * owner must later call {@link RGTextureAllocator.release} for the retained\r\n * reference.\r\n *\r\n * Allocators that cannot retain transient textures should leave this undefined.\r\n */\r\n retain?(texture: TTexture): void;\r\n\r\n /**\r\n * Allocate a temporary framebuffer matching the given descriptor.\r\n *\r\n * Implementations should not auto-release this framebuffer; the graph executor\r\n * calls {@link RGTextureAllocator.releaseFramebuffer} when execution completes or aborts.\r\n *\r\n * @param desc - Framebuffer descriptor.\r\n * @returns The allocated framebuffer object.\r\n */\r\n allocateFramebuffer?(desc: RGFramebufferDesc): TFramebuffer;\r\n\r\n /**\r\n * Release a previously allocated temporary framebuffer.\r\n *\r\n * @param framebuffer - The framebuffer to release.\r\n */\r\n releaseFramebuffer?(framebuffer: TFramebuffer): void;\r\n}\r\n"],"names":["RGHandle","id","name","_id","_name","RGResource","kind","desc","producer","consumers","physicalId","RGSubpass","executeFn","RGPass","index","reads","writes","dependencies","hasSideEffect","data","subpasses","alive"],"mappings":"AAoCA;AAEA;;;;;;;;AAQC,IACM,MAAMA,QAAAA,CAAAA;qBAEX,GAAqB;qBAErB,KAAuB;AAEvB,qBACA,WAAA,CAAYC,EAAU,EAAEC,IAAY,CAAE;QACpC,IAAI,CAACC,GAAG,GAAGF,EAAAA;QACX,IAAI,CAACG,KAAK,GAAGF,IAAAA;AACf;2DAGA,IAAIA,IAAe,GAAA;QACjB,OAAO,IAAI,CAACE,KAAK;AACnB;AACF;AAOA;;;AAGC,IACM,MAAMC,UAAAA,CAAAA;IACFJ,EAAW;IACXC,IAAa;IACbI,IAAqB;IACrBC,IAA+C;mFAExD,UAA4B;2FAE5BC,WAA0B,IAAK;AAC/B,2CACSC,SAAsB,GAAA,EAAE;IAEjC,WACER,CAAAA,EAAU,EACVC,IAAY,EACZI,IAAoB,EACpBC,IAA8C,EAC9CG,UAAaT,GAAAA,EAAE,CACf;QACA,IAAI,CAACA,EAAE,GAAGA,EAAAA;QACV,IAAI,CAACC,IAAI,GAAGA,IAAAA;QACZ,IAAI,CAACI,IAAI,GAAGA,IAAAA;QACZ,IAAI,CAACC,IAAI,GAAGA,IAAAA;QACZ,IAAI,CAACG,UAAU,GAAGA,UAAAA;AACpB;AACF;AA4EA;;;;;;;;AAQC,IACM,MAAMC,SAAAA,CAAAA;IACFT,IAAa;IACbU,SAA0B;IAEnC,WAAYV,CAAAA,IAAY,EAAEU,SAAyB,CAAE;QACnD,IAAI,CAACV,IAAI,GAAGA,IAAAA;QACZ,IAAI,CAACU,SAAS,GAAGA,SAAAA;AACnB;AACF;AAEA;;;AAGC,IACM,MAAMC,MAAAA,CAAAA;IACFC,KAAc;IACdZ,IAAa;AACtB,qDACSa,KAAsB,GAAA,EAAE;AACjC,kDACSC,MAAuB,GAAA,EAAE;AAClC,mFACSC,YAAyB,GAAA,EAAE;sEAEpCC,gBAAgB,KAAM;uDAEtBC,OAAiB,IAAK;6BAEtBP,YAAmC,IAAK;AACxC,+EACSQ,SAA4B,GAAA,EAAE;gEAEvCC,QAAQ,IAAK;IAEb,WAAYP,CAAAA,KAAa,EAAEZ,IAAY,CAAE;QACvC,IAAI,CAACY,KAAK,GAAGA,KAAAA;QACb,IAAI,CAACZ,IAAI,GAAGA,IAAAA;AACd;AACF;;;;"}
|
package/dist/scene/basesprite.js
CHANGED
|
@@ -12,6 +12,7 @@ import '../material/blinn.js';
|
|
|
12
12
|
import '../material/unlit.js';
|
|
13
13
|
import '../material/particle.js';
|
|
14
14
|
import '../material/subsurfaceprofile.js';
|
|
15
|
+
import '../material/skin.js';
|
|
15
16
|
import '../material/meshmaterial.js';
|
|
16
17
|
import '../material/grassmaterial.js';
|
|
17
18
|
import '../material/terrain-cm.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"basesprite.js","sources":["../../src/scene/basesprite.ts"],"sourcesContent":["import type { Matrix4x4, Nullable } from '@zephyr3d/base';\r\nimport { applyMixins, DRef, Quaternion, Vector2, Vector3 } from '@zephyr3d/base';\r\nimport { GraphNode } from './graph_node';\r\nimport type { RenderPass, BatchDrawable, DrawContext, PickTarget, RenderQueue } from '../render';\r\nimport { Primitive } from '../render';\r\nimport type { RenderBundle } from '@zephyr3d/device';\r\nimport type { Scene } from './scene';\r\nimport { BoundingBox } from '../utility/bounding_volume';\r\nimport { QUEUE_OPAQUE } from '../values';\r\nimport { mixinDrawable } from '../render/drawable_mixin';\r\nimport { RenderBundleWrapper } from '../render/renderbundle_wrapper';\r\nimport type { SceneNode } from './scene_node';\r\nimport { getDevice } from '../app/api';\r\nimport { SpriteMaterial } from '../material/sprite';\r\n\r\n/**\r\n * Mesh node\r\n * @public\r\n */\r\nexport class BaseSprite<M extends SpriteMaterial>\r\n extends applyMixins(GraphNode, mixinDrawable)\r\n implements BatchDrawable\r\n{\r\n /** @internal */\r\n private static _primitive: DRef<Primitive> = new DRef();\r\n /** @internal */\r\n protected readonly _material: DRef<M>;\r\n /** @internal */\r\n protected _instanceHash: Nullable<string>;\r\n /** @internal */\r\n protected _batchable: boolean;\r\n /** @internal */\r\n protected _pickTarget: PickTarget;\r\n /** @internal */\r\n protected _renderBundle: Record<string, RenderBundle>;\r\n /** @internal */\r\n protected _useRenderBundle: boolean;\r\n /** @internal */\r\n protected _materialChangeTag: Nullable<number>;\r\n /** @internal */\r\n protected _anchor: Vector2;\r\n /** @internal */\r\n protected _rotateAngle: number;\r\n /**\r\n * Creates an instance of mesh node\r\n * @param scene - The scene to which the mesh node belongs\r\n */\r\n constructor(scene: Scene) {\r\n super(scene);\r\n this._material = new DRef();\r\n this._instanceHash = null;\r\n this._pickTarget = { node: this };\r\n this._batchable = getDevice().type !== 'webgl';\r\n this._anchor = new Vector2(0.5, 0.5);\r\n this._rotateAngle = 0;\r\n this._renderBundle = {};\r\n this._useRenderBundle = true;\r\n this._materialChangeTag = null;\r\n }\r\n /**\r\n * Returns the batch instance ID for the current render pass.\r\n */\r\n getInstanceId(_renderPass: RenderPass) {\r\n return `${this._instanceHash}:${this.worldMatrixDet >= 0}`;\r\n }\r\n /**\r\n * Returns the packed instance-uniform buffer used for batching.\r\n */\r\n getInstanceUniforms() {\r\n return this._material.get()!.$instanceUniforms;\r\n }\r\n /**\r\n * {@inheritDoc Drawable.getPickTarget }\r\n */\r\n getPickTarget() {\r\n return this._pickTarget;\r\n }\r\n setPickTarget(node: SceneNode, label?: string) {\r\n this._pickTarget = { node, label };\r\n }\r\n /** Material of the mesh */\r\n get material() {\r\n return this._material.get()!;\r\n }\r\n set material(m) {\r\n if (this._material.get() !== m && m instanceof SpriteMaterial) {\r\n this._material.set(m);\r\n if (m) {\r\n this.onSetMaterial(m);\r\n RenderBundleWrapper.materialAttached(m.coreMaterial, this);\r\n }\r\n this._instanceHash = m ? `${this.constructor.name}:${this._scene?.id ?? 0}:${m.instanceId}` : null;\r\n RenderBundleWrapper.drawableChanged(this);\r\n this._materialChangeTag = null;\r\n }\r\n }\r\n get anchorX() {\r\n return this._anchor.x;\r\n }\r\n set anchorX(value) {\r\n if (this._anchor.x !== value) {\r\n this._anchor.x = value;\r\n this.invalidateWorldBoundingVolume(false);\r\n const material = this._material.get();\r\n if (material) {\r\n material.anchorX = this._anchor.x;\r\n }\r\n }\r\n }\r\n get anchorY() {\r\n return this._anchor.y;\r\n }\r\n set anchorY(value) {\r\n if (this._anchor.y !== value) {\r\n this._anchor.y = value;\r\n this.invalidateWorldBoundingVolume(false);\r\n const material = this._material.get();\r\n if (material) {\r\n material.anchorY = this._anchor.y;\r\n }\r\n }\r\n }\r\n get uvTopLeft() {\r\n const uvinfo = this._material.get()!.uvinfo;\r\n return new Vector2(uvinfo.x, uvinfo.y);\r\n }\r\n set uvTopLeft(value) {\r\n const uvinfo = this._material.get()!.uvinfo;\r\n this._material.get()!.setUVInfo(value.x, value.y, uvinfo.z, uvinfo.w);\r\n }\r\n get uvBottomRight() {\r\n const uvinfo = this._material.get()!.uvinfo;\r\n return new Vector2(uvinfo.z, uvinfo.w);\r\n }\r\n set uvBottomRight(value) {\r\n const uvinfo = this._material.get()!.uvinfo;\r\n this._material.get()!.setUVInfo(uvinfo.x, uvinfo.y, value.x, value.y);\r\n }\r\n /**\r\n * {@inheritDoc Drawable.getMorphData}\r\n */\r\n getMorphData() {\r\n return null;\r\n }\r\n /**\r\n * {@inheritDoc Drawable.getMorphInfo}\r\n */\r\n getMorphInfo() {\r\n return null;\r\n }\r\n /**\r\n * {@inheritDoc Drawable.isBatchable}\r\n */\r\n isBatchable(): this is BatchDrawable {\r\n return this._batchable && !!this._material.get() && this._material.get()!.isBatchable();\r\n }\r\n /**\r\n * {@inheritDoc Drawable.getQueueType}\r\n */\r\n getQueueType() {\r\n return this.material?.getQueueType() ?? QUEUE_OPAQUE;\r\n }\r\n /**\r\n * {@inheritDoc Drawable.isUnlit}\r\n */\r\n isUnlit() {\r\n return !this.material?.supportLighting();\r\n }\r\n /**\r\n * {@inheritDoc Drawable.needSceneColor}\r\n */\r\n needSceneColor() {\r\n return this.material?.needSceneColor();\r\n }\r\n /**\r\n * {@inheritDoc Drawable.needSceneDepth}\r\n */\r\n needSceneDepth() {\r\n return this.material?.needSceneDepth();\r\n }\r\n /**\r\n * {@inheritDoc Drawable.draw}\r\n */\r\n draw(ctx: DrawContext, renderQueue: Nullable<RenderQueue>, hash?: string) {\r\n const material = this.material;\r\n const primitive = this.getPrimitive();\r\n if (material && primitive) {\r\n if (this._useRenderBundle && !ctx.instanceData && hash) {\r\n if (this._materialChangeTag !== material.changeTag) {\r\n this._renderBundle = {};\r\n this._materialChangeTag = material.changeTag;\r\n }\r\n const renderBundle = this._renderBundle[hash];\r\n if (!renderBundle) {\r\n ctx.device.beginCapture();\r\n this.bind(ctx, renderQueue);\r\n material.draw(primitive, ctx);\r\n this._renderBundle[hash] = ctx.device.endCapture();\r\n } else {\r\n ctx.device.executeRenderBundle(renderBundle);\r\n }\r\n } else {\r\n this.bind(ctx, renderQueue);\r\n material.draw(primitive, ctx);\r\n }\r\n }\r\n }\r\n /**\r\n * {@inheritDoc Drawable.getMaterial}\r\n */\r\n getMaterial() {\r\n return this.material;\r\n }\r\n /**\r\n * {@inheritDoc Drawable.getPrimitive}\r\n */\r\n getPrimitive() {\r\n let primitive = BaseSprite._primitive.get();\r\n if (!primitive) {\r\n primitive = new Primitive();\r\n primitive.createAndSetVertexBuffer('position_f32', new Float32Array([0, 1, 2, 3]));\r\n primitive.createAndSetIndexBuffer(new Uint16Array([0, 1, 2, 3]));\r\n primitive.primitiveType = 'triangle-strip';\r\n BaseSprite._primitive.set(primitive);\r\n }\r\n return primitive;\r\n }\r\n /**\r\n * {@inheritDoc Drawable.getBoneMatrices}\r\n */\r\n getBoneMatrices() {\r\n return null;\r\n }\r\n /**\r\n * {@inheritDoc Drawable.getNode}\r\n */\r\n getNode() {\r\n // mesh transform should be ignored when skinned\r\n return this;\r\n }\r\n /**\r\n * {@inheritDoc SceneNode.computeBoundingVolume}\r\n */\r\n computeBoundingVolume() {\r\n return null;\r\n }\r\n /**\r\n * {@inheritDoc SceneNode.computeWorldBoundingVolume}\r\n */\r\n computeWorldBoundingVolume() {\r\n const p = this.worldMatrix.transformPointAffine(Vector3.zero());\r\n const scaleX = Math.hypot(this.worldMatrix[0], this.worldMatrix[1], this.worldMatrix[2]);\r\n const scaleY = Math.hypot(this.worldMatrix[4], this.worldMatrix[5], this.worldMatrix[6]);\r\n const mat = this._material?.get();\r\n if (mat) {\r\n const boundingBox = new BoundingBox();\r\n const cx = Math.max(Math.abs(this._anchor.x), Math.abs(1 - this._anchor.x)) * scaleX;\r\n const cy = Math.max(Math.abs(this._anchor.y), Math.abs(1 - this._anchor.y)) * scaleY;\r\n const size = Math.max(cx, cy);\r\n boundingBox.minPoint.setXYZ(p.x - size, p.y - size, p.z - size);\r\n boundingBox.maxPoint.setXYZ(p.x + size, p.y + size, p.z + size);\r\n return boundingBox;\r\n }\r\n return null;\r\n }\r\n calculateLocalTransform(outMatrix: Matrix4x4) {\r\n const rot = this.rotation.toEulerAngles().z;\r\n const rotationZ = Quaternion.fromAxisAngle(Vector3.axisPZ(), rot);\r\n outMatrix.compose(this._scaling, rotationZ, this._position);\r\n if (this._material?.get()) {\r\n this._rotateAngle = -rot;\r\n this._material.get()!.rotation = this._rotateAngle;\r\n }\r\n\r\n //outMatrix.scaling(this.scale).translateLeft(this._position);\r\n }\r\n calculateWorldTransform(outMatrix: Matrix4x4) {\r\n outMatrix.set(this.localMatrix);\r\n if (this.parent) {\r\n outMatrix.m03 += this.parent.worldMatrix.m03;\r\n outMatrix.m13 += this.parent.worldMatrix.m13;\r\n outMatrix.m23 += this.parent.worldMatrix.m23;\r\n }\r\n }\r\n /** Called when new material is set */\r\n protected onSetMaterial(material: M) {\r\n material.anchor = this._anchor;\r\n material.rotation = this._rotateAngle;\r\n }\r\n /** Disposes the mesh node */\r\n protected onDispose() {\r\n super.onDispose();\r\n this._material.dispose();\r\n RenderBundleWrapper.drawableChanged(this);\r\n }\r\n}\r\n"],"names":["BaseSprite","applyMixins","GraphNode","mixinDrawable","_primitive","DRef","scene","_material","_instanceHash","_pickTarget","node","_batchable","getDevice","type","_anchor","Vector2","_rotateAngle","_renderBundle","_useRenderBundle","_materialChangeTag","getInstanceId","_renderPass","worldMatrixDet","getInstanceUniforms","get","$instanceUniforms","getPickTarget","setPickTarget","label","material","m","SpriteMaterial","set","onSetMaterial","RenderBundleWrapper","materialAttached","coreMaterial","name","_scene","id","instanceId","drawableChanged","anchorX","x","value","invalidateWorldBoundingVolume","anchorY","y","uvTopLeft","uvinfo","setUVInfo","z","w","uvBottomRight","getMorphData","getMorphInfo","isBatchable","getQueueType","QUEUE_OPAQUE","isUnlit","supportLighting","needSceneColor","needSceneDepth","draw","ctx","renderQueue","hash","primitive","getPrimitive","instanceData","changeTag","renderBundle","device","beginCapture","bind","endCapture","executeRenderBundle","getMaterial","Primitive","createAndSetVertexBuffer","Float32Array","createAndSetIndexBuffer","Uint16Array","primitiveType","getBoneMatrices","getNode","computeBoundingVolume","computeWorldBoundingVolume","p","worldMatrix","transformPointAffine","Vector3","zero","scaleX","Math","hypot","scaleY","mat","boundingBox","BoundingBox","cx","max","abs","cy","size","minPoint","setXYZ","maxPoint","calculateLocalTransform","outMatrix","rot","rotation","toEulerAngles","rotationZ","Quaternion","fromAxisAngle","axisPZ","compose","_scaling","_position","calculateWorldTransform","localMatrix","parent","m03","m13","m23","anchor","onDispose","dispose"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAeA;;;AAGC,IACM,MAAMA,UACHC,SAAAA,WAAAA,CAAYC,SAAWC,EAAAA,aAAAA,CAAAA,CAAAA;AAG/B,qBACA,OAAeC,UAA8B,GAAA,IAAIC,IAAO,EAAA;qBAExD,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AACAwG,IAAAA,uBAAAA,CAAwBX,SAAoB,EAAE;AAC5CA,QAAAA,SAAAA,CAAU7E,GAAG,CAAC,IAAI,CAACyF,WAAW,CAAA;QAC9B,IAAI,IAAI,CAACC,MAAM,EAAE;YACfb,SAAUc,CAAAA,GAAG,IAAI,IAAI,CAACD,MAAM,CAACjC,WAAW,CAACkC,GAAG;YAC5Cd,SAAUe,CAAAA,GAAG,IAAI,IAAI,CAACF,MAAM,CAACjC,WAAW,CAACmC,GAAG;YAC5Cf,SAAUgB,CAAAA,GAAG,IAAI,IAAI,CAACH,MAAM,CAACjC,WAAW,CAACoC,GAAG;AAC9C;AACF;AACA,2CACU5F,aAAcJ,CAAAA,QAAW,EAAE;AACnCA,QAAAA,QAAAA,CAASiG,MAAM,GAAG,IAAI,CAAChH,OAAO;AAC9Be,QAAAA,QAAAA,CAASkF,QAAQ,GAAG,IAAI,CAAC/F,YAAY;AACvC;kCAEA,SAAsB,GAAA;AACpB,QAAA,KAAK,CAAC+G,SAAAA,EAAAA;QACN,IAAI,CAACxH,SAAS,CAACyH,OAAO,EAAA;QACtB9F,mBAAoBO,CAAAA,eAAe,CAAC,IAAI,CAAA;AAC1C;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"basesprite.js","sources":["../../src/scene/basesprite.ts"],"sourcesContent":["import type { Matrix4x4, Nullable } from '@zephyr3d/base';\r\nimport { applyMixins, DRef, Quaternion, Vector2, Vector3 } from '@zephyr3d/base';\r\nimport { GraphNode } from './graph_node';\r\nimport type { RenderPass, BatchDrawable, DrawContext, PickTarget, RenderQueue } from '../render';\r\nimport { Primitive } from '../render';\r\nimport type { RenderBundle } from '@zephyr3d/device';\r\nimport type { Scene } from './scene';\r\nimport { BoundingBox } from '../utility/bounding_volume';\r\nimport { QUEUE_OPAQUE } from '../values';\r\nimport { mixinDrawable } from '../render/drawable_mixin';\r\nimport { RenderBundleWrapper } from '../render/renderbundle_wrapper';\r\nimport type { SceneNode } from './scene_node';\r\nimport { getDevice } from '../app/api';\r\nimport { SpriteMaterial } from '../material/sprite';\r\n\r\n/**\r\n * Mesh node\r\n * @public\r\n */\r\nexport class BaseSprite<M extends SpriteMaterial>\r\n extends applyMixins(GraphNode, mixinDrawable)\r\n implements BatchDrawable\r\n{\r\n /** @internal */\r\n private static _primitive: DRef<Primitive> = new DRef();\r\n /** @internal */\r\n protected readonly _material: DRef<M>;\r\n /** @internal */\r\n protected _instanceHash: Nullable<string>;\r\n /** @internal */\r\n protected _batchable: boolean;\r\n /** @internal */\r\n protected _pickTarget: PickTarget;\r\n /** @internal */\r\n protected _renderBundle: Record<string, RenderBundle>;\r\n /** @internal */\r\n protected _useRenderBundle: boolean;\r\n /** @internal */\r\n protected _materialChangeTag: Nullable<number>;\r\n /** @internal */\r\n protected _anchor: Vector2;\r\n /** @internal */\r\n protected _rotateAngle: number;\r\n /**\r\n * Creates an instance of mesh node\r\n * @param scene - The scene to which the mesh node belongs\r\n */\r\n constructor(scene: Scene) {\r\n super(scene);\r\n this._material = new DRef();\r\n this._instanceHash = null;\r\n this._pickTarget = { node: this };\r\n this._batchable = getDevice().type !== 'webgl';\r\n this._anchor = new Vector2(0.5, 0.5);\r\n this._rotateAngle = 0;\r\n this._renderBundle = {};\r\n this._useRenderBundle = true;\r\n this._materialChangeTag = null;\r\n }\r\n /**\r\n * Returns the batch instance ID for the current render pass.\r\n */\r\n getInstanceId(_renderPass: RenderPass) {\r\n return `${this._instanceHash}:${this.worldMatrixDet >= 0}`;\r\n }\r\n /**\r\n * Returns the packed instance-uniform buffer used for batching.\r\n */\r\n getInstanceUniforms() {\r\n return this._material.get()!.$instanceUniforms;\r\n }\r\n /**\r\n * {@inheritDoc Drawable.getPickTarget }\r\n */\r\n getPickTarget() {\r\n return this._pickTarget;\r\n }\r\n setPickTarget(node: SceneNode, label?: string) {\r\n this._pickTarget = { node, label };\r\n }\r\n /** Material of the mesh */\r\n get material() {\r\n return this._material.get()!;\r\n }\r\n set material(m) {\r\n if (this._material.get() !== m && m instanceof SpriteMaterial) {\r\n this._material.set(m);\r\n if (m) {\r\n this.onSetMaterial(m);\r\n RenderBundleWrapper.materialAttached(m.coreMaterial, this);\r\n }\r\n this._instanceHash = m ? `${this.constructor.name}:${this._scene?.id ?? 0}:${m.instanceId}` : null;\r\n RenderBundleWrapper.drawableChanged(this);\r\n this._materialChangeTag = null;\r\n }\r\n }\r\n get anchorX() {\r\n return this._anchor.x;\r\n }\r\n set anchorX(value) {\r\n if (this._anchor.x !== value) {\r\n this._anchor.x = value;\r\n this.invalidateWorldBoundingVolume(false);\r\n const material = this._material.get();\r\n if (material) {\r\n material.anchorX = this._anchor.x;\r\n }\r\n }\r\n }\r\n get anchorY() {\r\n return this._anchor.y;\r\n }\r\n set anchorY(value) {\r\n if (this._anchor.y !== value) {\r\n this._anchor.y = value;\r\n this.invalidateWorldBoundingVolume(false);\r\n const material = this._material.get();\r\n if (material) {\r\n material.anchorY = this._anchor.y;\r\n }\r\n }\r\n }\r\n get uvTopLeft() {\r\n const uvinfo = this._material.get()!.uvinfo;\r\n return new Vector2(uvinfo.x, uvinfo.y);\r\n }\r\n set uvTopLeft(value) {\r\n const uvinfo = this._material.get()!.uvinfo;\r\n this._material.get()!.setUVInfo(value.x, value.y, uvinfo.z, uvinfo.w);\r\n }\r\n get uvBottomRight() {\r\n const uvinfo = this._material.get()!.uvinfo;\r\n return new Vector2(uvinfo.z, uvinfo.w);\r\n }\r\n set uvBottomRight(value) {\r\n const uvinfo = this._material.get()!.uvinfo;\r\n this._material.get()!.setUVInfo(uvinfo.x, uvinfo.y, value.x, value.y);\r\n }\r\n /**\r\n * {@inheritDoc Drawable.getMorphData}\r\n */\r\n getMorphData() {\r\n return null;\r\n }\r\n /**\r\n * {@inheritDoc Drawable.getMorphInfo}\r\n */\r\n getMorphInfo() {\r\n return null;\r\n }\r\n /**\r\n * {@inheritDoc Drawable.isBatchable}\r\n */\r\n isBatchable(): this is BatchDrawable {\r\n return this._batchable && !!this._material.get() && this._material.get()!.isBatchable();\r\n }\r\n /**\r\n * {@inheritDoc Drawable.getQueueType}\r\n */\r\n getQueueType() {\r\n return this.material?.getQueueType() ?? QUEUE_OPAQUE;\r\n }\r\n /**\r\n * {@inheritDoc Drawable.isUnlit}\r\n */\r\n isUnlit() {\r\n return !this.material?.supportLighting();\r\n }\r\n /**\r\n * {@inheritDoc Drawable.needSceneColor}\r\n */\r\n needSceneColor() {\r\n return this.material?.needSceneColor();\r\n }\r\n /**\r\n * {@inheritDoc Drawable.needSceneDepth}\r\n */\r\n needSceneDepth() {\r\n return this.material?.needSceneDepth();\r\n }\r\n /**\r\n * {@inheritDoc Drawable.draw}\r\n */\r\n draw(ctx: DrawContext, renderQueue: Nullable<RenderQueue>, hash?: string) {\r\n const material = this.material;\r\n const primitive = this.getPrimitive();\r\n if (material && primitive) {\r\n if (this._useRenderBundle && !ctx.instanceData && hash) {\r\n if (this._materialChangeTag !== material.changeTag) {\r\n this._renderBundle = {};\r\n this._materialChangeTag = material.changeTag;\r\n }\r\n const renderBundle = this._renderBundle[hash];\r\n if (!renderBundle) {\r\n ctx.device.beginCapture();\r\n this.bind(ctx, renderQueue);\r\n material.draw(primitive, ctx);\r\n this._renderBundle[hash] = ctx.device.endCapture();\r\n } else {\r\n ctx.device.executeRenderBundle(renderBundle);\r\n }\r\n } else {\r\n this.bind(ctx, renderQueue);\r\n material.draw(primitive, ctx);\r\n }\r\n }\r\n }\r\n /**\r\n * {@inheritDoc Drawable.getMaterial}\r\n */\r\n getMaterial() {\r\n return this.material;\r\n }\r\n /**\r\n * {@inheritDoc Drawable.getPrimitive}\r\n */\r\n getPrimitive() {\r\n let primitive = BaseSprite._primitive.get();\r\n if (!primitive) {\r\n primitive = new Primitive();\r\n primitive.createAndSetVertexBuffer('position_f32', new Float32Array([0, 1, 2, 3]));\r\n primitive.createAndSetIndexBuffer(new Uint16Array([0, 1, 2, 3]));\r\n primitive.primitiveType = 'triangle-strip';\r\n BaseSprite._primitive.set(primitive);\r\n }\r\n return primitive;\r\n }\r\n /**\r\n * {@inheritDoc Drawable.getBoneMatrices}\r\n */\r\n getBoneMatrices() {\r\n return null;\r\n }\r\n /**\r\n * {@inheritDoc Drawable.getNode}\r\n */\r\n getNode() {\r\n // mesh transform should be ignored when skinned\r\n return this;\r\n }\r\n /**\r\n * {@inheritDoc SceneNode.computeBoundingVolume}\r\n */\r\n computeBoundingVolume() {\r\n return null;\r\n }\r\n /**\r\n * {@inheritDoc SceneNode.computeWorldBoundingVolume}\r\n */\r\n computeWorldBoundingVolume() {\r\n const p = this.worldMatrix.transformPointAffine(Vector3.zero());\r\n const scaleX = Math.hypot(this.worldMatrix[0], this.worldMatrix[1], this.worldMatrix[2]);\r\n const scaleY = Math.hypot(this.worldMatrix[4], this.worldMatrix[5], this.worldMatrix[6]);\r\n const mat = this._material?.get();\r\n if (mat) {\r\n const boundingBox = new BoundingBox();\r\n const cx = Math.max(Math.abs(this._anchor.x), Math.abs(1 - this._anchor.x)) * scaleX;\r\n const cy = Math.max(Math.abs(this._anchor.y), Math.abs(1 - this._anchor.y)) * scaleY;\r\n const size = Math.max(cx, cy);\r\n boundingBox.minPoint.setXYZ(p.x - size, p.y - size, p.z - size);\r\n boundingBox.maxPoint.setXYZ(p.x + size, p.y + size, p.z + size);\r\n return boundingBox;\r\n }\r\n return null;\r\n }\r\n calculateLocalTransform(outMatrix: Matrix4x4) {\r\n const rot = this.rotation.toEulerAngles().z;\r\n const rotationZ = Quaternion.fromAxisAngle(Vector3.axisPZ(), rot);\r\n outMatrix.compose(this._scaling, rotationZ, this._position);\r\n if (this._material?.get()) {\r\n this._rotateAngle = -rot;\r\n this._material.get()!.rotation = this._rotateAngle;\r\n }\r\n\r\n //outMatrix.scaling(this.scale).translateLeft(this._position);\r\n }\r\n calculateWorldTransform(outMatrix: Matrix4x4) {\r\n outMatrix.set(this.localMatrix);\r\n if (this.parent) {\r\n outMatrix.m03 += this.parent.worldMatrix.m03;\r\n outMatrix.m13 += this.parent.worldMatrix.m13;\r\n outMatrix.m23 += this.parent.worldMatrix.m23;\r\n }\r\n }\r\n /** Called when new material is set */\r\n protected onSetMaterial(material: M) {\r\n material.anchor = this._anchor;\r\n material.rotation = this._rotateAngle;\r\n }\r\n /** Disposes the mesh node */\r\n protected onDispose() {\r\n super.onDispose();\r\n this._material.dispose();\r\n RenderBundleWrapper.drawableChanged(this);\r\n }\r\n}\r\n"],"names":["BaseSprite","applyMixins","GraphNode","mixinDrawable","_primitive","DRef","scene","_material","_instanceHash","_pickTarget","node","_batchable","getDevice","type","_anchor","Vector2","_rotateAngle","_renderBundle","_useRenderBundle","_materialChangeTag","getInstanceId","_renderPass","worldMatrixDet","getInstanceUniforms","get","$instanceUniforms","getPickTarget","setPickTarget","label","material","m","SpriteMaterial","set","onSetMaterial","RenderBundleWrapper","materialAttached","coreMaterial","name","_scene","id","instanceId","drawableChanged","anchorX","x","value","invalidateWorldBoundingVolume","anchorY","y","uvTopLeft","uvinfo","setUVInfo","z","w","uvBottomRight","getMorphData","getMorphInfo","isBatchable","getQueueType","QUEUE_OPAQUE","isUnlit","supportLighting","needSceneColor","needSceneDepth","draw","ctx","renderQueue","hash","primitive","getPrimitive","instanceData","changeTag","renderBundle","device","beginCapture","bind","endCapture","executeRenderBundle","getMaterial","Primitive","createAndSetVertexBuffer","Float32Array","createAndSetIndexBuffer","Uint16Array","primitiveType","getBoneMatrices","getNode","computeBoundingVolume","computeWorldBoundingVolume","p","worldMatrix","transformPointAffine","Vector3","zero","scaleX","Math","hypot","scaleY","mat","boundingBox","BoundingBox","cx","max","abs","cy","size","minPoint","setXYZ","maxPoint","calculateLocalTransform","outMatrix","rot","rotation","toEulerAngles","rotationZ","Quaternion","fromAxisAngle","axisPZ","compose","_scaling","_position","calculateWorldTransform","localMatrix","parent","m03","m13","m23","anchor","onDispose","dispose"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAeA;;;AAGC,IACM,MAAMA,UACHC,SAAAA,WAAAA,CAAYC,SAAWC,EAAAA,a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AACvG,SAAS,CAACiB,GAAG,GAAIuF,QAAQ,GAAG,IAAI,CAAC/F,YAAY;AACpD;;AAGF;AACAwG,IAAAA,uBAAAA,CAAwBX,SAAoB,EAAE;AAC5CA,QAAAA,SAAAA,CAAU7E,GAAG,CAAC,IAAI,CAACyF,WAAW,CAAA;QAC9B,IAAI,IAAI,CAACC,MAAM,EAAE;YACfb,SAAUc,CAAAA,GAAG,IAAI,IAAI,CAACD,MAAM,CAACjC,WAAW,CAACkC,GAAG;YAC5Cd,SAAUe,CAAAA,GAAG,IAAI,IAAI,CAACF,MAAM,CAACjC,WAAW,CAACmC,GAAG;YAC5Cf,SAAUgB,CAAAA,GAAG,IAAI,IAAI,CAACH,MAAM,CAACjC,WAAW,CAACoC,GAAG;AAC9C;AACF;AACA,2CACU5F,aAAcJ,CAAAA,QAAW,EAAE;AACnCA,QAAAA,QAAAA,CAASiG,MAAM,GAAG,IAAI,CAAChH,OAAO;AAC9Be,QAAAA,QAAAA,CAASkF,QAAQ,GAAG,IAAI,CAAC/F,YAAY;AACvC;kCAEA,SAAsB,GAAA;AACpB,QAAA,KAAK,CAAC+G,SAAAA,EAAAA;QACN,IAAI,CAACxH,SAAS,CAACyH,OAAO,EAAA;QACtB9F,mBAAoBO,CAAAA,eAAe,CAAC,IAAI,CAAA;AAC1C;AACF;;;;"}
|
package/dist/scene/batchgroup.js
CHANGED
|
@@ -10,6 +10,7 @@ import '../material/blinn.js';
|
|
|
10
10
|
import '../material/unlit.js';
|
|
11
11
|
import '../material/particle.js';
|
|
12
12
|
import '../material/subsurfaceprofile.js';
|
|
13
|
+
import '../material/skin.js';
|
|
13
14
|
import '../material/meshmaterial.js';
|
|
14
15
|
import '../material/grassmaterial.js';
|
|
15
16
|
import '../material/terrain-cm.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"batchgroup.js","sources":["../../src/scene/batchgroup.ts"],"sourcesContent":["import { GraphNode } from './graph_node';\r\nimport type { CullVisitor, RenderPass } from '../render';\r\nimport { RenderQueue, InstanceBindGroupAllocator } from '../render';\r\nimport type { Scene } from './scene';\r\nimport { BoundingBox, type BoundingVolume } from '../utility/bounding_volume';\r\nimport { Matrix4x4 } from '@zephyr3d/base';\r\n\r\nconst tmpMatrix = new Matrix4x4();\r\n\r\n/**\r\n * Batch group node\r\n * @public\r\n */\r\nexport class BatchGroup extends GraphNode {\r\n private readonly _renderQueueMap: Map<\r\n RenderPass,\r\n {\r\n queue: RenderQueue;\r\n tag: number;\r\n }\r\n >;\r\n private readonly _bindGroupAllocator: InstanceBindGroupAllocator;\r\n private _changeTag: number;\r\n private _staticBV: boolean;\r\n /**\r\n * Creates an instance of mesh node\r\n * @param scene - The scene to which the mesh node belongs\r\n */\r\n constructor(scene: Scene) {\r\n super(scene);\r\n this._renderQueueMap = new Map();\r\n this._changeTag = 0;\r\n this._bindGroupAllocator = new InstanceBindGroupAllocator();\r\n this._staticBV = false;\r\n const bvCallback = () => {\r\n if (!this._staticBV) {\r\n this.invalidateBoundingVolume();\r\n }\r\n };\r\n const primitiveCallback = () => {\r\n bvCallback();\r\n this.invalidate();\r\n };\r\n const materialCallback = () => {\r\n this.invalidate();\r\n };\r\n this.on('visiblechanged', (node) => {\r\n node.iterate((child) => {\r\n if (child.isMesh()) {\r\n this.invalidate();\r\n return true;\r\n }\r\n return false;\r\n });\r\n });\r\n this.on('nodeattached', (node) => {\r\n node.iterate((child) => {\r\n if (child.isMesh()) {\r\n child.placeToOctree = false;\r\n if (!this._staticBV) {\r\n this.invalidateBoundingVolume();\r\n }\r\n child.on('bvchanged', bvCallback);\r\n child.on('primitive_changed', primitiveCallback);\r\n child.on('material_changed', materialCallback);\r\n this.invalidate();\r\n }\r\n });\r\n });\r\n this.on('noderemoved', (node) => {\r\n node.iterate((child) => {\r\n if (child.isMesh()) {\r\n child.placeToOctree = true;\r\n if (!this._staticBV) {\r\n this.invalidateBoundingVolume();\r\n }\r\n child.off('bvchanged', bvCallback);\r\n child.off('primitive_changed', primitiveCallback);\r\n child.off('material_changed', materialCallback);\r\n this.invalidate();\r\n }\r\n });\r\n });\r\n }\r\n /** Gets the batch group name. */\r\n getName() {\r\n return this._name;\r\n }\r\n /**\r\n * {@inheritDoc SceneNode.isBatchGroup}\r\n */\r\n isBatchGroup(): this is BatchGroup {\r\n return true;\r\n }\r\n /**\r\n * Force the batch state to be rebuilt\r\n */\r\n invalidate() {\r\n this._changeTag++;\r\n }\r\n /** @internal */\r\n protected _onDetached() {\r\n super._onDetached();\r\n // Usually the node will be garbage collected after it is detached,\r\n // We should reset the render queue to release the render bundles.\r\n this._renderQueueMap.forEach((val) => {\r\n val.queue.reset();\r\n });\r\n this.invalidate();\r\n }\r\n /** @internal */\r\n protected _onAttached() {\r\n // Reset the render queue when attached to a new scene.\r\n this.invalidate();\r\n }\r\n /** @internal */\r\n computeBoundingVolume() {\r\n const bv = new BoundingBox();\r\n const invWorldMatrix = Matrix4x4.invertAffine(this.worldMatrix);\r\n bv.beginExtend();\r\n this.iterate((node) => {\r\n if (node.isMesh()) {\r\n Matrix4x4.multiplyAffine(invWorldMatrix, node.worldMatrix, tmpMatrix);\r\n const wb = node.getBoundingVolume()!.transform(tmpMatrix).toAABB();\r\n bv.extend(wb.minPoint);\r\n bv.extend(wb.maxPoint);\r\n }\r\n });\r\n return bv.isValid() ? bv : null;\r\n }\r\n /** @internal */\r\n setBoundingVolume(bv: BoundingVolume) {\r\n this._staticBV = !!bv;\r\n super.setBoundingVolume(bv);\r\n }\r\n /** @internal */\r\n cull(cullVisitor: CullVisitor) {\r\n let queueInfo = this._renderQueueMap.get(cullVisitor.renderPass);\r\n if (!queueInfo) {\r\n queueInfo = {\r\n queue: new RenderQueue(cullVisitor.renderPass, this._bindGroupAllocator),\r\n tag: -1\r\n };\r\n this._renderQueueMap.set(cullVisitor.renderPass, queueInfo);\r\n }\r\n if (queueInfo.tag !== this._changeTag) {\r\n queueInfo.tag = this._changeTag;\r\n queueInfo.queue.reset();\r\n const frustumCulling = cullVisitor.frustumCulling;\r\n const renderQueue = cullVisitor.renderQueue;\r\n cullVisitor.frustumCulling = false;\r\n cullVisitor.renderQueue = queueInfo.queue;\r\n this.iterate((node) => {\r\n if (node.isMesh()) {\r\n cullVisitor.visit(node);\r\n }\r\n });\r\n queueInfo.queue.end(cullVisitor.camera, true);\r\n cullVisitor.frustumCulling = frustumCulling;\r\n cullVisitor.renderQueue = renderQueue;\r\n }\r\n cullVisitor.pushRenderQueue(queueInfo.queue);\r\n }\r\n}\r\n"],"names":["tmpMatrix","Matrix4x4","BatchGroup","GraphNode","_renderQueueMap","_bindGroupAllocator","_changeTag","_staticBV","scene","Map","InstanceBindGroupAllocator","bvCallback","invalidateBoundingVolume","primitiveCallback","invalidate","materialCallback","on","node","iterate","child","isMesh","placeToOctree","off","getName","_name","isBatchGroup","_onDetached","forEach","val","queue","reset","computeBoundingVolume","bv","BoundingBox","invWorldMatrix","invertAffine","worldMatrix","beginExtend","multiplyAffine","wb","getBoundingVolume","transform","toAABB","extend","minPoint","maxPoint","isValid","setBoundingVolume","cull","cullVisitor","queueInfo","get","renderPass","RenderQueue","tag","set","frustumCulling","renderQueue","visit","end","camera","pushRenderQueue"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA,MAAMA,YAAY,IAAIC,SAAAA,EAAAA;AAEtB;;;IAIO,MAAMC,UAAmBC,SAAAA,SAAAA,CAAAA;IACbC,eAMf;IACeC,mBAAgD;IACzDC,UAAmB;IACnBC,SAAmB;AAC3B;;;MAIA,WAAA,CAAYC,KAAY,CAAE;AACxB,QAAA,KAAK,CAACA,KAAAA,CAAAA;QACN,IAAI,CAACJ,eAAe,GAAG,IAAIK,GAAAA,EAAAA;QAC3B,IAAI,CAACH,UAAU,GAAG,CAAA;QAClB,IAAI,CAACD,mBAAmB,GAAG,IAAIK,0BAAAA,EAAAA;QAC/B,IAAI,CAACH,SAAS,GAAG,KAAA;AACjB,QAAA,MAAMI,UAAa,GAAA,IAAA;AACjB,YAAA,IAA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B,CAAAA,KAAK,CAACC,KAAK,EAAA;YACrB,MAAM0B,cAAAA,GAAiBP,YAAYO,cAAc;YACjD,MAAMC,WAAAA,GAAcR,YAAYQ,WAAW;AAC3CR,YAAAA,WAAAA,CAAYO,cAAc,GAAG,KAAA;YAC7BP,WAAYQ,CAAAA,WAAW,GAAGP,SAAAA,CAAUrB,KAAK;YACzC,IAAI,CAACX,OAAO,CAAC,CAACD,IAAAA,GAAAA;gBACZ,IAAIA,IAAAA,CAAKG,MAAM,EAAI,EAAA;AACjB6B,oBAAAA,WAAAA,CAAYS,KAAK,CAACzC,IAAAA,CAAAA;AACpB;AACF,aAAA,CAAA;AACAiC,YAAAA,SAAAA,CAAUrB,KAAK,CAAC8B,GAAG,CAACV,WAAAA,CAAYW,MAAM,EAAE,IAAA,CAAA;AACxCX,YAAAA,WAAAA,CAAYO,cAAc,GAAGA,cAAAA;AAC7BP,YAAAA,WAAAA,CAAYQ,WAAW,GAAGA,WAAAA;AAC5B;QACAR,WAAYY,CAAAA,eAAe,CAACX,SAAAA,CAAUrB,KAAK,CAAA;AAC7C;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"batchgroup.js","sources":["../../src/scene/batchgroup.ts"],"sourcesContent":["import { GraphNode } from './graph_node';\r\nimport type { CullVisitor, RenderPass } from '../render';\r\nimport { RenderQueue, InstanceBindGroupAllocator } from '../render';\r\nimport type { Scene } from './scene';\r\nimport { BoundingBox, type BoundingVolume } from '../utility/bounding_volume';\r\nimport { Matrix4x4 } from '@zephyr3d/base';\r\n\r\nconst tmpMatrix = new Matrix4x4();\r\n\r\n/**\r\n * Batch group node\r\n * @public\r\n */\r\nexport class BatchGroup extends GraphNode {\r\n private readonly _renderQueueMap: Map<\r\n RenderPass,\r\n {\r\n queue: RenderQueue;\r\n tag: number;\r\n }\r\n >;\r\n private readonly _bindGroupAllocator: InstanceBindGroupAllocator;\r\n private _changeTag: number;\r\n private _staticBV: boolean;\r\n /**\r\n * Creates an instance of mesh node\r\n * @param scene - The scene to which the mesh node belongs\r\n */\r\n constructor(scene: Scene) {\r\n super(scene);\r\n this._renderQueueMap = new Map();\r\n this._changeTag = 0;\r\n this._bindGroupAllocator = new InstanceBindGroupAllocator();\r\n this._staticBV = false;\r\n const bvCallback = () => {\r\n if (!this._staticBV) {\r\n this.invalidateBoundingVolume();\r\n }\r\n };\r\n const primitiveCallback = () => {\r\n bvCallback();\r\n this.invalidate();\r\n };\r\n const materialCallback = () => {\r\n this.invalidate();\r\n };\r\n this.on('visiblechanged', (node) => {\r\n node.iterate((child) => {\r\n if (child.isMesh()) {\r\n this.invalidate();\r\n return true;\r\n }\r\n return false;\r\n });\r\n });\r\n this.on('nodeattached', (node) => {\r\n node.iterate((child) => {\r\n if (child.isMesh()) {\r\n child.placeToOctree = false;\r\n if (!this._staticBV) {\r\n this.invalidateBoundingVolume();\r\n }\r\n child.on('bvchanged', bvCallback);\r\n child.on('primitive_changed', primitiveCallback);\r\n child.on('material_changed', materialCallback);\r\n this.invalidate();\r\n }\r\n });\r\n });\r\n this.on('noderemoved', (node) => {\r\n node.iterate((child) => {\r\n if (child.isMesh()) {\r\n child.placeToOctree = true;\r\n if (!this._staticBV) {\r\n this.invalidateBoundingVolume();\r\n }\r\n child.off('bvchanged', bvCallback);\r\n child.off('primitive_changed', primitiveCallback);\r\n child.off('material_changed', materialCallback);\r\n this.invalidate();\r\n }\r\n });\r\n });\r\n }\r\n /** Gets the batch group name. */\r\n getName() {\r\n return this._name;\r\n }\r\n /**\r\n * {@inheritDoc SceneNode.isBatchGroup}\r\n */\r\n isBatchGroup(): this is BatchGroup {\r\n return true;\r\n }\r\n /**\r\n * Force the batch state to be rebuilt\r\n */\r\n invalidate() {\r\n this._changeTag++;\r\n }\r\n /** @internal */\r\n protected _onDetached() {\r\n super._onDetached();\r\n // Usually the node will be garbage collected after it is detached,\r\n // We should reset the render queue to release the render bundles.\r\n this._renderQueueMap.forEach((val) => {\r\n val.queue.reset();\r\n });\r\n this.invalidate();\r\n }\r\n /** @internal */\r\n protected _onAttached() {\r\n // Reset the render queue when attached to a new scene.\r\n this.invalidate();\r\n }\r\n /** @internal */\r\n computeBoundingVolume() {\r\n const bv = new BoundingBox();\r\n const invWorldMatrix = Matrix4x4.invertAffine(this.worldMatrix);\r\n bv.beginExtend();\r\n this.iterate((node) => {\r\n if (node.isMesh()) {\r\n Matrix4x4.multiplyAffine(invWorldMatrix, node.worldMatrix, tmpMatrix);\r\n const wb = node.getBoundingVolume()!.transform(tmpMatrix).toAABB();\r\n bv.extend(wb.minPoint);\r\n bv.extend(wb.maxPoint);\r\n }\r\n });\r\n return bv.isValid() ? bv : null;\r\n }\r\n /** @internal */\r\n setBoundingVolume(bv: BoundingVolume) {\r\n this._staticBV = !!bv;\r\n super.setBoundingVolume(bv);\r\n }\r\n /** @internal */\r\n cull(cullVisitor: CullVisitor) {\r\n let queueInfo = this._renderQueueMap.get(cullVisitor.renderPass);\r\n if (!queueInfo) {\r\n queueInfo = {\r\n queue: new RenderQueue(cullVisitor.renderPass, this._bindGroupAllocator),\r\n tag: -1\r\n };\r\n this._renderQueueMap.set(cullVisitor.renderPass, queueInfo);\r\n }\r\n if (queueInfo.tag !== this._changeTag) {\r\n queueInfo.tag = this._changeTag;\r\n queueInfo.queue.reset();\r\n const frustumCulling = cullVisitor.frustumCulling;\r\n const renderQueue = cullVisitor.renderQueue;\r\n cullVisitor.frustumCulling = false;\r\n cullVisitor.renderQueue = queueInfo.queue;\r\n this.iterate((node) => {\r\n if (node.isMesh()) {\r\n cullVisitor.visit(node);\r\n }\r\n });\r\n queueInfo.queue.end(cullVisitor.camera, true);\r\n cullVisitor.frustumCulling = frustumCulling;\r\n cullVisitor.renderQueue = renderQueue;\r\n }\r\n cullVisitor.pushRenderQueue(queueInfo.queue);\r\n }\r\n}\r\n"],"names":["tmpMatrix","Matrix4x4","BatchGroup","GraphNode","_renderQueueMap","_bindGroupAllocator","_changeTag","_staticBV","scene","Map","InstanceBindGroupAllocator","bvCallback","invalidateBoundingVolume","primitiveCallback","invalidate","materialCallback","on","node","iterate","child","isMesh","placeToOctree","off","getName","_name","isBatchGroup","_onDetached","forEach","val","queue","reset","computeBoundingVolume","bv","BoundingBox","invWorldMatrix","invertAffine","worldMatrix","beginExtend","multiplyAffine","wb","getBoundingVolume","transform","toAABB","extend","minPoint","maxPoint","isValid","setBoundingVolume","cull","cullVisitor","queueInfo","get","renderPass","RenderQueue","tag","set","frustumCulling","renderQueue","visit","end","camera","pushRenderQueue"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA,MAAMA,YAAY,IAAIC,SAAAA,EAAAA;AAEtB;;;IAIO,MAAMC,UAAmBC,SAAAA,SAAAA,CAAAA;IACbC,eAMf;IACeC,mBAAgD;IACzDC,UAAmB;IACnBC,SAAmB;AAC3B;;;MAIA,WAAA,CAAYC,KAAY,CAAE;AACxB,QAAA,KAAK,CAACA,KAAAA,CAAAA;QACN,IAAI,CAACJ,eAAe,GAAG,IAAIK,GAAAA,EAAAA;QAC3B,IAAI,CAACH,UAAU,GAAG,CAAA;QAClB,IAAI,CAACD,mBAAmB,GAAG,IAAIK,0BAAAA,EAAAA;QAC/B,IAAI,CAACH,SAAS,GAAG,KAAA;AACjB,QAAA,MAAMI,UAAa,GAAA,IAAA;AACjB,YAAA,IAAI,CAAC,IAAI,CAACJ,SAAS,EAAE;AACnB,gBAAA,IAAI,CAACK,wBAAwB,EAAA;AAC/B;AACF,SAAA;AACA,QAAA,MAAMC,iBAAoB,GAAA,IAAA;AACxBF,YAAAA,UAAAA,EAAAA;AACA,YAAA,IAAI,CAACG,UAAU,EAAA;AACjB,SAAA;AACA,QAAA,MAAMC,gBAAmB,GAAA,IAAA;AACvB,YAAA,IAAI,CAACD,UAAU,EAAA;AACjB,SAAA;AACA,QAAA,IAAI,CAACE,EAAE,CAAC,gBAAA,EAAkB,CAACC,IAAAA,GAAAA;YACzBA,IAAKC,CAAAA,OAAO,CAAC,CAACC,KAAAA,GAAAA;gBACZ,IAA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CAAUrB,KAAK,CAAC8B,GAAG,CAACV,WAAAA,CAAYW,MAAM,EAAE,IAAA,CAAA;AACxCX,YAAAA,WAAAA,CAAYO,cAAc,GAAGA,cAAAA;AAC7BP,YAAAA,WAAAA,CAAYQ,WAAW,GAAGA,WAAAA;AAC5B;QACAR,WAAYY,CAAAA,eAAe,CAACX,SAAAA,CAAUrB,KAAK,CAAA;AAC7C;AACF;;;;"}
|
|
@@ -9,6 +9,7 @@ import '../material/blinn.js';
|
|
|
9
9
|
import '../material/unlit.js';
|
|
10
10
|
import '../material/particle.js';
|
|
11
11
|
import '../material/subsurfaceprofile.js';
|
|
12
|
+
import '../material/skin.js';
|
|
12
13
|
import '../material/meshmaterial.js';
|
|
13
14
|
import '../material/grassmaterial.js';
|
|
14
15
|
import '../material/terrain-cm.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"environment.js","sources":["../../src/scene/environment.ts"],"sourcesContent":["import type { Immutable, Nullable, Vector4 } from '@zephyr3d/base';\r\nimport { Vector3, DRef, Disposable } from '@zephyr3d/base';\r\nimport { ObservableVector4 } from '@zephyr3d/base';\r\nimport type { DrawContext, EnvironmentLighting } from '../render';\r\nimport { EnvShIBL } from '../render';\r\nimport { EnvConstantAmbient, EnvHemisphericAmbient } from '../render';\r\nimport { SkyRenderer } from '../render/sky';\r\nimport type { FrameBuffer, GPUDataBuffer, TextureCube } from '@zephyr3d/device';\r\n\r\n/**\r\n * Wrapper for environmant lighting\r\n * @public\r\n */\r\nexport class EnvLightWrapper extends Disposable {\r\n private _envLight: Nullable<EnvironmentLighting>;\r\n private readonly _ambientColor: ObservableVector4;\r\n private readonly _ambientDown: ObservableVector4;\r\n private readonly _ambientUp: ObservableVector4;\r\n private readonly _radianceMap: DRef<TextureCube>;\r\n private readonly _sheenRadianceMap: DRef<TextureCube>;\r\n private readonly _irradianceMap: DRef<TextureCube>;\r\n private readonly _irradianceSH: DRef<GPUDataBuffer>;\r\n private readonly _irradianceSHFB: DRef<FrameBuffer>;\r\n private readonly _irradianceWindow: Vector3;\r\n private _strength: number;\r\n private _specularStrength: number;\r\n /** @internal */\r\n constructor() {\r\n super();\r\n this._envLight = new EnvShIBL();\r\n this._ambientColor = new ObservableVector4(0.2, 0.2, 0.2, 1).setCallback(() => {\r\n if (this.type === 'constant') {\r\n (this._envLight as EnvConstantAmbient).ambientColor.set(this._ambientColor);\r\n }\r\n });\r\n this._ambientDown = new ObservableVector4(0.2, 0.2, 0.2, 1).setCallback(() => {\r\n if (this.type === 'hemisphere') {\r\n (this._envLight as EnvHemisphericAmbient).ambientDown.set(this._ambientDown);\r\n }\r\n });\r\n this._ambientUp = new ObservableVector4(0.3, 0.5, 0.8, 1).setCallback(() => {\r\n if (this.type === 'hemisphere') {\r\n (this._envLight as EnvHemisphericAmbient).ambientUp.set(this._ambientUp);\r\n }\r\n });\r\n this._radianceMap = new DRef();\r\n this._sheenRadianceMap = new DRef();\r\n this._irradianceMap = new DRef();\r\n this._irradianceSH = new DRef();\r\n this._irradianceSHFB = new DRef();\r\n this._irradianceWindow = new Vector3();\r\n this._strength = 1;\r\n this._specularStrength = 1;\r\n }\r\n /** @internal */\r\n getHash(ctx?: DrawContext) {\r\n const irradianceSource =\r\n this.type === 'ibl'\r\n ? this._irradianceSHFB.get()\r\n ? 'fb'\r\n : this._irradianceSH.get()\r\n ? 'buf'\r\n : 'none'\r\n : 'na';\r\n return !ctx || ctx.drawEnvLight\r\n ? `${this.type}:${this._envLight!.hasRadiance() ? '1' : '0'}:${\r\n this._envLight!.hasSheenRadiance() ? '1' : '0'\r\n }:${this._envLight!.hasIrradiance() ? '1' : '0'}:${irradianceSource}`\r\n : 'none';\r\n }\r\n /** @internal */\r\n get envLight() {\r\n return this._envLight!;\r\n }\r\n /** The strength of environment lighting */\r\n get strength() {\r\n return this._strength;\r\n }\r\n set strength(val) {\r\n this._strength = val;\r\n }\r\n /** The strength of environment specular lighting */\r\n get specularStrength() {\r\n return this._specularStrength;\r\n }\r\n set specularStrength(val) {\r\n this._specularStrength = val;\r\n }\r\n /** Ambient light color for environment light type constant */\r\n get ambientColor(): Vector4 {\r\n return this._ambientColor;\r\n }\r\n set ambientColor(val: Vector4) {\r\n this._ambientColor.set(val);\r\n }\r\n /** Up color for environment light type hemisphere */\r\n get ambientUp(): Vector4 {\r\n return this._ambientUp;\r\n }\r\n set ambientUp(val: Vector4) {\r\n this._ambientUp.set(val);\r\n }\r\n /** Down color for environment light type hemisphere */\r\n get ambientDown(): Vector4 {\r\n return this._ambientDown;\r\n }\r\n set ambientDown(val: Vector4) {\r\n this._ambientDown.set(val);\r\n }\r\n /** Radiance map for environment light type ibl */\r\n get radianceMap() {\r\n return this._radianceMap.get();\r\n }\r\n set radianceMap(tex) {\r\n this._radianceMap.set(tex);\r\n if (this.type === 'ibl') {\r\n (this._envLight as EnvShIBL).radianceMap = this.radianceMap;\r\n }\r\n }\r\n /** Charlie-filtered sheen radiance map for environment light type ibl */\r\n get sheenRadianceMap() {\r\n return this._sheenRadianceMap.get();\r\n }\r\n set sheenRadianceMap(tex) {\r\n this._sheenRadianceMap.set(tex);\r\n if (this.type === 'ibl') {\r\n (this._envLight as EnvShIBL).sheenRadianceMap = this.sheenRadianceMap;\r\n }\r\n }\r\n /** Irradiance SH buffer for environment light type ibl */\r\n get irradianceSH() {\r\n return this._irradianceSH.get();\r\n }\r\n set irradianceSH(value) {\r\n this._irradianceSH.set(value);\r\n if (this.type === 'ibl') {\r\n (this._envLight as EnvShIBL).irradianceSH = this.irradianceSH;\r\n }\r\n }\r\n /** Irradiance SH texture for environment light type ibl */\r\n get irradianceSHFB() {\r\n return this._irradianceSHFB.get();\r\n }\r\n set irradianceSHFB(value) {\r\n this._irradianceSHFB.set(value);\r\n if (this.type === 'ibl') {\r\n (this._envLight as EnvShIBL).irradianceSHFB = this.irradianceSHFB;\r\n }\r\n }\r\n /** Irradiance SH window for environment light type ibl */\r\n get irradianceWindow(): Immutable<Vector3> {\r\n return this._irradianceWindow;\r\n }\r\n set irradianceWindow(value: Immutable<Vector3>) {\r\n this._irradianceWindow.set(value);\r\n if (this.type === 'ibl') {\r\n (this._envLight as EnvShIBL).irradianceWindow = this._irradianceWindow;\r\n }\r\n }\r\n /** The environment light type */\r\n get type() {\r\n return this._envLight?.getType() ?? 'none';\r\n }\r\n set type(val) {\r\n switch (val) {\r\n case 'none':\r\n this._envLight = null;\r\n break;\r\n case 'ibl':\r\n if (this._envLight?.getType() !== val) {\r\n this._envLight = new EnvShIBL(\r\n this.radianceMap!,\r\n this.irradianceSH!,\r\n this.irradianceSHFB!,\r\n this.sheenRadianceMap!\r\n );\r\n }\r\n (this._envLight as EnvShIBL).radianceMap = this.radianceMap;\r\n (this._envLight as EnvShIBL).sheenRadianceMap = this.sheenRadianceMap;\r\n (this._envLight as EnvShIBL).irradianceSH = this.irradianceSH;\r\n (this._envLight as EnvShIBL).irradianceSHFB = this.irradianceSHFB;\r\n (this._envLight as EnvShIBL).irradianceWindow = this.irradianceWindow;\r\n break;\r\n case 'constant':\r\n if (this._envLight?.getType() !== val) {\r\n this._envLight = new EnvConstantAmbient(this._ambientColor);\r\n }\r\n break;\r\n case 'hemisphere':\r\n if (this._envLight?.getType() !== val) {\r\n this._envLight = new EnvHemisphericAmbient(this._ambientUp, this._ambientDown);\r\n }\r\n break;\r\n default:\r\n break;\r\n }\r\n }\r\n /** Disposes the environment lighting wrapper */\r\n protected onDispose() {\r\n super.onDispose();\r\n this._envLight?.dispose();\r\n this._radianceMap.dispose();\r\n this._sheenRadianceMap.dispose();\r\n this._irradianceMap.dispose();\r\n this._irradianceSHFB.dispose();\r\n this._irradianceSH.dispose();\r\n }\r\n}\r\n\r\n/**\r\n * Environment of scene\r\n * @public\r\n */\r\nexport class Environment extends Disposable {\r\n private readonly _sky: SkyRenderer;\r\n private readonly _light: EnvLightWrapper;\r\n /** @internal */\r\n constructor() {\r\n super();\r\n this._sky = new SkyRenderer();\r\n this._light = new EnvLightWrapper();\r\n }\r\n /** The sky renderer */\r\n get sky() {\r\n return this._sky;\r\n }\r\n /** The environment lighting renderer */\r\n get light() {\r\n return this._light;\r\n }\r\n /** @internal */\r\n getHash(ctx: DrawContext) {\r\n return `${this.light?.getHash(ctx)}:${this._sky?.getHash(ctx)}`;\r\n }\r\n /** @internal */\r\n needSceneDepthTexture() {\r\n return this._sky.fogType !== 'none';\r\n }\r\n /** Disposes the environment object */\r\n protected onDispose() {\r\n super.onDispose();\r\n this._sky.dispose();\r\n this._light.dispose();\r\n }\r\n}\r\n"],"names":["EnvLightWrapper","Disposable","_envLight","_ambientColor","_ambientDown","_ambientUp","_radianceMap","_sheenRadianceMap","_irradianceMap","_irradianceSH","_irradianceSHFB","_irradianceWindow","_strength","_specularStrength","EnvShIBL","ObservableVector4","setCallback","type","ambientColor","set","ambientDown","ambientUp","DRef","Vector3","getHash","ctx","irradianceSource","get","drawEnvLight","hasRadiance","hasSheenRadiance","hasIrradiance","envLight","strength","val","specularStrength","radianceMap","tex","sheenRadianceMap","irradianceSH","value","irradianceSHFB","irradianceWindow","getType","EnvConstantAmbient","EnvHemisphericAmbient","onDispose","dispose","Environment","_sky","_light","SkyRenderer","sky","light","needSceneDepthTexture","fogType"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AASA;;;IAIO,MAAMA,eAAwBC,SAAAA,UAAAA,CAAAA;IAC3BC,SAAyC;IAChCC,aAAiC;IACjCC,YAAgC;IAChCC,UAA8B;IAC9BC,YAAgC;IAChCC,iBAAqC;IACrCC,cAAkC;IAClCC,aAAmC;IACnCC,eAAmC;IACnCC,iBAA2B;IACpCC,SAAkB;IAClBC,iBAA0B;AAClC,qBACA,WAAc,EAAA;QACZ,KAAK,EAAA;QACL,IAAI,CAACX,SAAS,GAAG,IAAIY,QAAAA,EAAAA;QACrB,IAAI,CAACX,aAAa,GAAG,IAAIY,iBAAAA,CAAkB,KAAK,GAAK,EAAA,GAAA,EAAK,CAAGC,CAAAA,CAAAA,WAAW,CAAC,IAAA;AACvE,YAAA,IAAI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AO,IAAI,CAACH,IAAI;AAClB;6CAEA,IAAII,KAAQ,GAAA;QACV,OAAO,IAAI,CAACH,MAAM;AACpB;qBAEA1B,OAAQC,CAAAA,GAAgB,EAAE;AACxB,QAAA,OAAO,CAAG,EAAA,IAAI,CAAC4B,KAAK,EAAE7B,OAAQC,CAAAA,GAAAA,CAAAA,CAAK,CAAC,EAAE,IAAI,CAACwB,IAAI,EAAEzB,QAAQC,GAAM,CAAA,CAAA,CAAA;AACjE;AACA,qBACA6B,qBAAwB,GAAA;AACtB,QAAA,OAAO,IAAI,CAACL,IAAI,CAACM,OAAO,KAAK,MAAA;AAC/B;2CAEA,SAAsB,GAAA;AACpB,QAAA,KAAK,CAACT,SAAAA,EAAAA;QACN,IAAI,CAACG,IAAI,CAACF,OAAO,EAAA;QACjB,IAAI,CAACG,MAAM,CAACH,OAAO,EAAA;AACrB;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"environment.js","sources":["../../src/scene/environment.ts"],"sourcesContent":["import type { Immutable, Nullable, Vector4 } from '@zephyr3d/base';\r\nimport { Vector3, DRef, Disposable } from '@zephyr3d/base';\r\nimport { ObservableVector4 } from '@zephyr3d/base';\r\nimport type { DrawContext, EnvironmentLighting } from '../render';\r\nimport { EnvShIBL } from '../render';\r\nimport { EnvConstantAmbient, EnvHemisphericAmbient } from '../render';\r\nimport { SkyRenderer } from '../render/sky';\r\nimport type { FrameBuffer, GPUDataBuffer, TextureCube } from '@zephyr3d/device';\r\n\r\n/**\r\n * Wrapper for environmant lighting\r\n * @public\r\n */\r\nexport class EnvLightWrapper extends Disposable {\r\n private _envLight: Nullable<EnvironmentLighting>;\r\n private readonly _ambientColor: ObservableVector4;\r\n private readonly _ambientDown: ObservableVector4;\r\n private readonly _ambientUp: ObservableVector4;\r\n private readonly _radianceMap: DRef<TextureCube>;\r\n private readonly _sheenRadianceMap: DRef<TextureCube>;\r\n private readonly _irradianceMap: DRef<TextureCube>;\r\n private readonly _irradianceSH: DRef<GPUDataBuffer>;\r\n private readonly _irradianceSHFB: DRef<FrameBuffer>;\r\n private readonly _irradianceWindow: Vector3;\r\n private _strength: number;\r\n private _specularStrength: number;\r\n /** @internal */\r\n constructor() {\r\n super();\r\n this._envLight = new EnvShIBL();\r\n this._ambientColor = new ObservableVector4(0.2, 0.2, 0.2, 1).setCallback(() => {\r\n if (this.type === 'constant') {\r\n (this._envLight as EnvConstantAmbient).ambientColor.set(this._ambientColor);\r\n }\r\n });\r\n this._ambientDown = new ObservableVector4(0.2, 0.2, 0.2, 1).setCallback(() => {\r\n if (this.type === 'hemisphere') {\r\n (this._envLight as EnvHemisphericAmbient).ambientDown.set(this._ambientDown);\r\n }\r\n });\r\n this._ambientUp = new ObservableVector4(0.3, 0.5, 0.8, 1).setCallback(() => {\r\n if (this.type === 'hemisphere') {\r\n (this._envLight as EnvHemisphericAmbient).ambientUp.set(this._ambientUp);\r\n }\r\n });\r\n this._radianceMap = new DRef();\r\n this._sheenRadianceMap = new DRef();\r\n this._irradianceMap = new DRef();\r\n this._irradianceSH = new DRef();\r\n this._irradianceSHFB = new DRef();\r\n this._irradianceWindow = new Vector3();\r\n this._strength = 1;\r\n this._specularStrength = 1;\r\n }\r\n /** @internal */\r\n getHash(ctx?: DrawContext) {\r\n const irradianceSource =\r\n this.type === 'ibl'\r\n ? this._irradianceSHFB.get()\r\n ? 'fb'\r\n : this._irradianceSH.get()\r\n ? 'buf'\r\n : 'none'\r\n : 'na';\r\n return !ctx || ctx.drawEnvLight\r\n ? `${this.type}:${this._envLight!.hasRadiance() ? '1' : '0'}:${\r\n this._envLight!.hasSheenRadiance() ? '1' : '0'\r\n }:${this._envLight!.hasIrradiance() ? '1' : '0'}:${irradianceSource}`\r\n : 'none';\r\n }\r\n /** @internal */\r\n get envLight() {\r\n return this._envLight!;\r\n }\r\n /** The strength of environment lighting */\r\n get strength() {\r\n return this._strength;\r\n }\r\n set strength(val) {\r\n this._strength = val;\r\n }\r\n /** The strength of environment specular lighting */\r\n get specularStrength() {\r\n return this._specularStrength;\r\n }\r\n set specularStrength(val) {\r\n this._specularStrength = val;\r\n }\r\n /** Ambient light color for environment light type constant */\r\n get ambientColor(): Vector4 {\r\n return this._ambientColor;\r\n }\r\n set ambientColor(val: Vector4) {\r\n this._ambientColor.set(val);\r\n }\r\n /** Up color for environment light type hemisphere */\r\n get ambientUp(): Vector4 {\r\n return this._ambientUp;\r\n }\r\n set ambientUp(val: Vector4) {\r\n this._ambientUp.set(val);\r\n }\r\n /** Down color for environment light type hemisphere */\r\n get ambientDown(): Vector4 {\r\n return this._ambientDown;\r\n }\r\n set ambientDown(val: Vector4) {\r\n this._ambientDown.set(val);\r\n }\r\n /** Radiance map for environment light type ibl */\r\n get radianceMap() {\r\n return this._radianceMap.get();\r\n }\r\n set radianceMap(tex) {\r\n this._radianceMap.set(tex);\r\n if (this.type === 'ibl') {\r\n (this._envLight as EnvShIBL).radianceMap = this.radianceMap;\r\n }\r\n }\r\n /** Charlie-filtered sheen radiance map for environment light type ibl */\r\n get sheenRadianceMap() {\r\n return this._sheenRadianceMap.get();\r\n }\r\n set sheenRadianceMap(tex) {\r\n this._sheenRadianceMap.set(tex);\r\n if (this.type === 'ibl') {\r\n (this._envLight as EnvShIBL).sheenRadianceMap = this.sheenRadianceMap;\r\n }\r\n }\r\n /** Irradiance SH buffer for environment light type ibl */\r\n get irradianceSH() {\r\n return this._irradianceSH.get();\r\n }\r\n set irradianceSH(value) {\r\n this._irradianceSH.set(value);\r\n if (this.type === 'ibl') {\r\n (this._envLight as EnvShIBL).irradianceSH = this.irradianceSH;\r\n }\r\n }\r\n /** Irradiance SH texture for environment light type ibl */\r\n get irradianceSHFB() {\r\n return this._irradianceSHFB.get();\r\n }\r\n set irradianceSHFB(value) {\r\n this._irradianceSHFB.set(value);\r\n if (this.type === 'ibl') {\r\n (this._envLight as EnvShIBL).irradianceSHFB = this.irradianceSHFB;\r\n }\r\n }\r\n /** Irradiance SH window for environment light type ibl */\r\n get irradianceWindow(): Immutable<Vector3> {\r\n return this._irradianceWindow;\r\n }\r\n set irradianceWindow(value: Immutable<Vector3>) {\r\n this._irradianceWindow.set(value);\r\n if (this.type === 'ibl') {\r\n (this._envLight as EnvShIBL).irradianceWindow = this._irradianceWindow;\r\n }\r\n }\r\n /** The environment light type */\r\n get type() {\r\n return this._envLight?.getType() ?? 'none';\r\n }\r\n set type(val) {\r\n switch (val) {\r\n case 'none':\r\n this._envLight = null;\r\n break;\r\n case 'ibl':\r\n if (this._envLight?.getType() !== val) {\r\n this._envLight = new EnvShIBL(\r\n this.radianceMap!,\r\n this.irradianceSH!,\r\n this.irradianceSHFB!,\r\n this.sheenRadianceMap!\r\n );\r\n }\r\n (this._envLight as EnvShIBL).radianceMap = this.radianceMap;\r\n (this._envLight as EnvShIBL).sheenRadianceMap = this.sheenRadianceMap;\r\n (this._envLight as EnvShIBL).irradianceSH = this.irradianceSH;\r\n (this._envLight as EnvShIBL).irradianceSHFB = this.irradianceSHFB;\r\n (this._envLight as EnvShIBL).irradianceWindow = this.irradianceWindow;\r\n break;\r\n case 'constant':\r\n if (this._envLight?.getType() !== val) {\r\n this._envLight = new EnvConstantAmbient(this._ambientColor);\r\n }\r\n break;\r\n case 'hemisphere':\r\n if (this._envLight?.getType() !== val) {\r\n this._envLight = new EnvHemisphericAmbient(this._ambientUp, this._ambientDown);\r\n }\r\n break;\r\n default:\r\n break;\r\n }\r\n }\r\n /** Disposes the environment lighting wrapper */\r\n protected onDispose() {\r\n super.onDispose();\r\n this._envLight?.dispose();\r\n this._radianceMap.dispose();\r\n this._sheenRadianceMap.dispose();\r\n this._irradianceMap.dispose();\r\n this._irradianceSHFB.dispose();\r\n this._irradianceSH.dispose();\r\n }\r\n}\r\n\r\n/**\r\n * Environment of scene\r\n * @public\r\n */\r\nexport class Environment extends Disposable {\r\n private readonly _sky: SkyRenderer;\r\n private readonly _light: EnvLightWrapper;\r\n /** @internal */\r\n constructor() {\r\n super();\r\n this._sky = new SkyRenderer();\r\n this._light = new EnvLightWrapper();\r\n }\r\n /** The sky renderer */\r\n get sky() {\r\n return this._sky;\r\n }\r\n /** The environment lighting renderer */\r\n get light() {\r\n return this._light;\r\n }\r\n /** @internal */\r\n getHash(ctx: DrawContext) {\r\n return `${this.light?.getHash(ctx)}:${this._sky?.getHash(ctx)}`;\r\n }\r\n /** @internal */\r\n needSceneDepthTexture() {\r\n return this._sky.fogType !== 'none';\r\n }\r\n /** Disposes the environment object */\r\n protected onDispose() {\r\n super.onDispose();\r\n this._sky.dispose();\r\n this._light.dispose();\r\n }\r\n}\r\n"],"names":["EnvLightWrapper","Disposable","_envLight","_ambientColor","_ambientDown","_ambientUp","_radianceMap","_sheenRadianceMap","_irradianceMap","_irradianceSH","_irradianceSHFB","_irradianceWindow","_strength","_specularStrength","EnvShIBL","ObservableVector4","setCallback","type","ambientColor","set","ambientDown","ambientUp","DRef","Vector3","getHash","ctx","irradianceSource","get","drawEnvLight","hasRadiance","hasSheenRadiance","hasIrradiance","envLight","strength","val","specularStrength","radianceMap","tex","sheenRadianceMap","irradianceSH","value","irradianceSHFB","irradianceWindow","getType","EnvConstantAmbient","EnvHemisphericAmbient","onDispose","dispose","Environment","_sky","_light","SkyRenderer","sky","light","needSceneDepthTexture","fogType"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASA;;;IAIO,MAAMA,eAAwBC,SAAAA,UAAAA,CAAAA;IAC3BC,SAAyC;IAChCC,aAAiC;IACjCC,YAAgC;IAChCC,UAA8B;IAC9BC,YAAgC;IAChCC,iBAAqC;IACrCC,cAAkC;IAClCC,aAAmC;IACnCC,eAAmC;IACnCC,iBAA2B;IACpCC,SAAkB;IAClBC,iBAA0B;AAClC,qBACA,WAAc,EAAA;QACZ,KAAK,EAAA;QACL,IAAI,CAACX,SAAS,GAAG,IAAIY,QAAAA,EAAAA;QACrB,IAAI,CAACX,aAAa,GAAG,IAAIY,iBAAAA,CAAkB,KAAK,GAAK,EAAA,GAAA,EAAK,CAAGC,CAAAA,CAAAA,WAAW,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,IAAIoD,GAAM,GAAA;QACR,OAAO,IAAI,CAACH,IAAI;AAClB;6CAEA,IAAII,KAAQ,GAAA;QACV,OAAO,IAAI,CAACH,MAAM;AACpB;qBAEA1B,OAAQC,CAAAA,GAAgB,EAAE;AACxB,QAAA,OAAO,CAAG,EAAA,IAAI,CAAC4B,KAAK,EAAE7B,OAAQC,CAAAA,GAAAA,CAAAA,CAAK,CAAC,EAAE,IAAI,CAACwB,IAAI,EAAEzB,QAAQC,GAAM,CAAA,CAAA,CAAA;AACjE;AACA,qBACA6B,qBAAwB,GAAA;AACtB,QAAA,OAAO,IAAI,CAACL,IAAI,CAACM,OAAO,KAAK,MAAA;AAC/B;2CAEA,SAAsB,GAAA;AACpB,QAAA,KAAK,CAACT,SAAAA,EAAAA;QACN,IAAI,CAACG,IAAI,CAACF,OAAO,EAAA;QACjB,IAAI,CAACG,MAAM,CAACH,OAAO,EAAA;AACrB;AACF;;;;"}
|
package/dist/scene/light.js
CHANGED
|
@@ -297,7 +297,7 @@ export abstract class AmbientLight extends BaseLight {
|
|
|
297
297
|
* @param scene - The scene to which the light belongs
|
|
298
298
|
*/ constructor(scene){
|
|
299
299
|
super(scene, LIGHT_TYPE_POINT);
|
|
300
|
-
this._range =
|
|
300
|
+
this._range = -1;
|
|
301
301
|
this._diffuseScale = 1;
|
|
302
302
|
this._specularScale = 1;
|
|
303
303
|
this._sourceRadius = 0;
|
|
@@ -391,7 +391,8 @@ export abstract class AmbientLight extends BaseLight {
|
|
|
391
391
|
/** @internal */ computeUniforms() {
|
|
392
392
|
const a = this.worldMatrix.getRow(3);
|
|
393
393
|
const b = this.worldMatrix.getRow(2);
|
|
394
|
-
this.
|
|
394
|
+
const range = this.range < 0 ? 32 * Math.sqrt(Math.max(0.0001, this.intensity * Math.max(this._diffuseScale, this._specularScale))) : this.range;
|
|
395
|
+
this._positionRange = new Vector4(a.x, a.y, a.z, range);
|
|
395
396
|
this._directionCutoff = new Vector4(b.x, b.y, b.z, -1);
|
|
396
397
|
this._diffuseIntensity = new Vector4(this.color.x, this.color.y, this.color.z, this.intensity);
|
|
397
398
|
this._extraParams = new Vector4(this._diffuseScale, this._specularScale, this._sourceRadius, this.lightType);
|
|
@@ -408,7 +409,7 @@ export abstract class AmbientLight extends BaseLight {
|
|
|
408
409
|
* @param scene - The scene to which the light belongs
|
|
409
410
|
*/ constructor(scene){
|
|
410
411
|
super(scene, LIGHT_TYPE_SPOT);
|
|
411
|
-
this._range =
|
|
412
|
+
this._range = -1;
|
|
412
413
|
this._cutoff = Math.cos(Math.PI / 4);
|
|
413
414
|
this.invalidateBoundingVolume();
|
|
414
415
|
}
|
|
@@ -467,7 +468,8 @@ export abstract class AmbientLight extends BaseLight {
|
|
|
467
468
|
/** @internal */ computeUniforms() {
|
|
468
469
|
const a = this.worldMatrix.getRow(3);
|
|
469
470
|
const b = this.worldMatrix.getRow(2).scaleBy(-1);
|
|
470
|
-
this.
|
|
471
|
+
const range = this.range < 0 ? 32 * Math.sqrt(Math.max(0.0001, this.intensity)) : this.range;
|
|
472
|
+
this._positionRange = new Vector4(a.x, a.y, a.z, range);
|
|
471
473
|
this._directionCutoff = new Vector4(b.x, b.y, b.z, this.cutoff);
|
|
472
474
|
this._diffuseIntensity = new Vector4(this.color.x, this.color.y, this.color.z, this.intensity);
|
|
473
475
|
this._extraParams = new Vector4(0, 0, 0, this.lightType);
|