/// import 'reflect-metadata'; import { Component, ComponentManager } from './ComponentManager'; import { FrameGraphSystem } from './components/framegraph/System'; import { GeometryComponent } from './components/geometry/GeometryComponent'; import { GeometrySystem } from './components/geometry/System'; import type { IUniformBinding } from './components/material/interface'; import { MaterialComponent } from './components/material/MaterialComponent'; import { MaterialSystem } from './components/material/System'; import { CullableComponent } from './components/mesh/CullableComponent'; import type { IMeshParams } from './components/mesh/interface'; import { MeshComponent } from './components/mesh/MeshComponent'; import { MeshSystem } from './components/mesh/System'; import { RendererSystem } from './components/renderer/System'; import { HierarchyComponent } from './components/scenegraph/HierarchyComponent'; import { SceneGraphSystem } from './components/scenegraph/System'; import { TransformComponent } from './components/scenegraph/TransformComponent'; import { gl } from './components/renderer/gl'; import type { IAttribute, IAttributeInitializationOptions } from './components/renderer/IAttribute'; import type { IBuffer, IBufferInitializationOptions } from './components/renderer/IBuffer'; import type { IComputeModel } from './components/renderer/IComputeModel'; import type { IElements, IElementsInitializationOptions } from './components/renderer/IElements'; import type { IFramebuffer, IFramebufferInitializationOptions } from './components/renderer/IFramebuffer'; import type { IModel, IModelDrawOptions, IModelInitializationOptions } from './components/renderer/IModel'; import type { IRenderbuffer, IRenderbufferInitializationOptions } from './components/renderer/IRenderbuffer'; import type { BufferData, ICamera, IClearOptions, IReadPixelsOptions, IRendererConfig, IRendererService, IScene, IView, IViewport } from './components/renderer/IRendererService'; import type { ITexture2D, ITexture2DInitializationOptions } from './components/renderer/ITexture2D'; import type { IUniform } from './components/renderer/IUniform'; import { PixelPickingPass } from './components/renderer/passes/PixelPickingPass'; import { createEntity } from './Entity'; import { IDENTIFIER } from './identifier'; import { container, createWorldContainer, lazyInject, lazyMultiInject } from './inversify.config'; import type { ISystem } from './ISystem'; import type { IConfig, IConfigService } from './services/config/IConfigService'; import type { IInteractorEvent } from './services/interactor/IIteractorService'; import type { IInteractorService } from './services/interactor/IIteractorService'; import type { IShaderModuleService } from './services/shader-module/IShaderModuleService'; import { Frustum } from './shape/Frustum'; import { AABB } from './shape/AABB'; import { Ray } from './shape/Ray'; import { isSafari } from './utils/isSafari'; import { generateAABBFromVertices } from './utils/aabb'; declare type Entity = number; declare enum AST_TOKEN_TYPES { Void = "Void", Boolean = "Boolean", Float = "Float", Uint32 = "Uint32", Int32 = "Int32", Vector = "Vector", Vector2Float = "vec2", Vector3Float = "vec3", Vector4Float = "vec4", Vector2Boolean = "vec2", Vector3Boolean = "vec3", Vector4Boolean = "vec4", Vector2Uint = "vec2", Vector3Uint = "vec3", Vector4Uint = "vec4", Vector2Int = "vec2", Vector3Int = "vec3", Vector4Int = "vec4", Matrix = "Matrix", Matrix3x3Float = "mat3x3", Matrix4x4Float = "mat4x4", Struct = "Struct", FloatArray = "Float[]", Vector4FloatArray = "vec4[]" } declare enum AST_NODE_TYPES { Program = "Program", Identifier = "Identifier", VariableDeclaration = "VariableDeclaration", BlockStatement = "BlockStatement", ReturnStatement = "ReturnStatement", FunctionDeclaration = "FunctionDeclaration", VariableDeclarator = "VariableDeclarator", AssignmentExpression = "AssignmentExpression", LogicalExpression = "LogicalExpression", BinaryExpression = "BinaryExpression", ArrayExpression = "ArrayExpression", UnaryExpression = "UnaryExpression", UpdateExpression = "UpdateExpression", FunctionExpression = "FunctionExpression", MemberExpression = "MemberExpression", ConditionalExpression = "ConditionalExpression", ExpressionStatement = "ExpressionStatement", CallExpression = "CallExpression", NumThreadStatement = "NumThreadStatement", StorageStatement = "StorageStatement", DoWhileStatement = "DoWhileStatement", WhileStatement = "WhileStatement", ForStatement = "ForStatement", BreakStatement = "BreakStatement", ContinueStatement = "ContinueStatement", IfStatement = "IfStatement", ImportedFunctionStatement = "ImportedFunctionStatement" } declare enum STORAGE_CLASS { Input = "Input", Output = "Output", Uniform = "Uniform", Workgroup = "Workgroup", UniformConstant = "UniformConstant", Image = "Image", StorageBuffer = "StorageBuffer", Private = "Private", Function = "Function" } declare type TypedArrayConstructor = Int8ArrayConstructor | Uint8ArrayConstructor | Uint8ClampedArrayConstructor | Int16ArrayConstructor | Uint16ArrayConstructor | Int32ArrayConstructor | Uint32ArrayConstructor | Float32ArrayConstructor | Float64ArrayConstructor; declare type DataType = AST_TOKEN_TYPES.Uint32 | AST_TOKEN_TYPES.Int32 | AST_TOKEN_TYPES.Boolean | AST_TOKEN_TYPES.Float | AST_TOKEN_TYPES.Vector2Float | AST_TOKEN_TYPES.Vector3Float | AST_TOKEN_TYPES.Vector4Float | AST_TOKEN_TYPES.Vector2Int | AST_TOKEN_TYPES.Vector3Int | AST_TOKEN_TYPES.Vector4Int | AST_TOKEN_TYPES.Vector2Uint | AST_TOKEN_TYPES.Vector3Uint | AST_TOKEN_TYPES.Vector4Uint | AST_TOKEN_TYPES.Vector2Boolean | AST_TOKEN_TYPES.Vector3Boolean | AST_TOKEN_TYPES.Vector4Boolean | AST_TOKEN_TYPES.Matrix3x3Float | AST_TOKEN_TYPES.Matrix4x4Float | AST_TOKEN_TYPES.FloatArray | AST_TOKEN_TYPES.Vector4FloatArray | AST_TOKEN_TYPES.Void; interface GLSLContext { /** * 程序名 */ name: string; shader?: string; /** * size of thread grid * 即 WebGL 2 Compute 中的 dispatchCompute * 或者 WebGPU 中的 dispatch */ dispatch: [number, number, number]; /** * size of each thread group * Compute Shader 中的 local_size_x/y/z */ threadGroupSize: [number, number, number]; /** * 迭代次数,例如布局运算中需要迭代很多次才能到达稳定 */ maxIteration: number; /** * 是否需要 pingpong,如果存在输入和输出为同一个的情况 */ needPingpong: boolean; /** * 目前仅支持单一输出,受限于 WebGL 实现 */ output: { name: string; size?: [number, number]; textureSize?: [number, number]; length?: number; typedArrayConstructor?: TypedArrayConstructor; gpuBuffer?: GPUBuffer; outputElementsPerTexel?: number; }; /** * 常量,可分成编译时和运行时两类: * 1. 编译时即可确定值 * 2. 运行时:例如循环长度需要为常量,但在编译时又无法确定 * TODO 支持定义函数,例如 tensorflow 中的 DIV_CEIL */ defines: Array<{ name: string; type: DataType; value: number; runtime: boolean; }>; globalDeclarations: Array<{ name: string; type: DataType; value: string; shared: boolean; }>; uniforms: Array<{ name: string; type: DataType; data?: number | number[] | Float32Array | Uint8Array | Uint16Array | Uint32Array | Int8Array | Int16Array | Int32Array; size?: [number, number]; storageClass: STORAGE_CLASS; readonly: boolean; writeonly: boolean; isReferer?: boolean; }>; } /** * 根据目标平台生成 Shader 代码 * * WebGL GLSL 1.0 * * WebGPU Chrome/Edge GLSL 4.5 & WGSL @see https://gpuweb.github.io/gpuweb/wgsl.html * * Safari WHLSL (maybe deprecated) */ declare enum Target { GLSL100 = "GLSL100", GLSL450 = "GLSL450", WGSL = "WGSL" } declare const DefineValuePlaceholder = "__DefineValuePlaceholder__"; interface KernelBundle { shaders: { [Target.WGSL]: string; [Target.GLSL450]: string; [Target.GLSL100]: string; }; context?: GLSLContext; toString(): string; } export { container, createWorldContainer, lazyInject, lazyMultiInject, createEntity, Component, ComponentManager, IDENTIFIER, FrameGraphSystem, GeometrySystem, RendererSystem, MaterialSystem, MeshSystem, SceneGraphSystem, CullableComponent, MeshComponent, TransformComponent, MaterialComponent, GeometryComponent, HierarchyComponent, isSafari, generateAABBFromVertices, gl, PixelPickingPass, AST_TOKEN_TYPES, AST_NODE_TYPES, STORAGE_CLASS, Target, DefineValuePlaceholder, AABB, Frustum, Ray, }; export type { ISystem, IUniform, IMeshParams, IUniformBinding, IAttribute, IAttributeInitializationOptions, IBuffer, IBufferInitializationOptions, IClearOptions, IElements, IElementsInitializationOptions, IFramebuffer, IFramebufferInitializationOptions, IRenderbuffer, IRenderbufferInitializationOptions, IModel, IModelInitializationOptions, IModelDrawOptions, IReadPixelsOptions, IRendererConfig, IRendererService, ITexture2D, ITexture2DInitializationOptions, IComputeModel, IShaderModuleService, IConfigService, IInteractorService, IInteractorEvent, IConfig, IView, IScene, IViewport, ICamera, BufferData, // type DataType, // type Entity, // type GLSLContext, // interface KernelBundle, };