@luma.gl/engine 8.6.0-alpha.5 → 9.0.0-alpha.10

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.
Files changed (129) hide show
  1. package/dist/animation/key-frames.d.ts +1 -0
  2. package/dist/animation/key-frames.d.ts.map +1 -1
  3. package/dist/animation/key-frames.js.map +1 -1
  4. package/dist/animation/timeline.d.ts +2 -2
  5. package/dist/animation/timeline.d.ts.map +1 -1
  6. package/dist/animation/timeline.js.map +1 -1
  7. package/dist/geometries/cone-geometry.d.ts.map +1 -1
  8. package/dist/geometries/cone-geometry.js +1 -1
  9. package/dist/geometries/cone-geometry.js.map +1 -1
  10. package/dist/geometries/cube-geometry.d.ts +4 -0
  11. package/dist/geometries/cube-geometry.d.ts.map +1 -1
  12. package/dist/geometries/cube-geometry.js +31 -7
  13. package/dist/geometries/cube-geometry.js.map +1 -1
  14. package/dist/geometries/cylinder-geometry.d.ts.map +1 -1
  15. package/dist/geometries/cylinder-geometry.js +1 -1
  16. package/dist/geometries/cylinder-geometry.js.map +1 -1
  17. package/dist/geometries/ico-sphere-geometry.d.ts.map +1 -1
  18. package/dist/geometries/ico-sphere-geometry.js +1 -1
  19. package/dist/geometries/ico-sphere-geometry.js.map +1 -1
  20. package/dist/geometries/plane-geometry.d.ts.map +1 -1
  21. package/dist/geometries/plane-geometry.js +1 -1
  22. package/dist/geometries/plane-geometry.js.map +1 -1
  23. package/dist/geometries/sphere-geometry.d.ts.map +1 -1
  24. package/dist/geometries/sphere-geometry.js +1 -1
  25. package/dist/geometries/sphere-geometry.js.map +1 -1
  26. package/dist/geometries/truncated-cone-geometry.d.ts +15 -3
  27. package/dist/geometries/truncated-cone-geometry.d.ts.map +1 -1
  28. package/dist/geometries/truncated-cone-geometry.js +29 -15
  29. package/dist/geometries/truncated-cone-geometry.js.map +1 -1
  30. package/dist/geometry/geometry-table.d.ts +15 -0
  31. package/dist/geometry/geometry-table.d.ts.map +1 -0
  32. package/dist/geometry/geometry-table.js +2 -0
  33. package/dist/{transform/transform-types.js.map → geometry/geometry-table.js.map} +1 -1
  34. package/dist/geometry/geometry-utils.js.map +1 -1
  35. package/dist/geometry/geometry.d.ts +32 -14
  36. package/dist/geometry/geometry.d.ts.map +1 -1
  37. package/dist/geometry/geometry.js +57 -34
  38. package/dist/geometry/geometry.js.map +1 -1
  39. package/dist/geometry/primitive-utils.d.ts +1 -0
  40. package/dist/geometry/primitive-utils.d.ts.map +1 -0
  41. package/dist/geometry/primitive-utils.js +2 -0
  42. package/dist/geometry/primitive-utils.js.map +1 -0
  43. package/dist/index.d.ts +6 -7
  44. package/dist/index.d.ts.map +1 -1
  45. package/dist/index.js +4 -6
  46. package/dist/index.js.map +1 -1
  47. package/dist/lib/animation-loop.d.ts +23 -84
  48. package/dist/lib/animation-loop.d.ts.map +1 -1
  49. package/dist/lib/animation-loop.js +106 -193
  50. package/dist/lib/animation-loop.js.map +1 -1
  51. package/dist/lib/animation-props.d.ts +24 -0
  52. package/dist/lib/animation-props.d.ts.map +1 -0
  53. package/dist/lib/animation-props.js +2 -0
  54. package/dist/lib/animation-props.js.map +1 -0
  55. package/dist/lib/clip-space.d.ts +1 -0
  56. package/dist/lib/clip-space.d.ts.map +1 -0
  57. package/dist/lib/clip-space.js +2 -0
  58. package/dist/lib/clip-space.js.map +1 -0
  59. package/dist/lib/model-utils.d.ts +4 -3
  60. package/dist/lib/model-utils.d.ts.map +1 -1
  61. package/dist/lib/model-utils.js +24 -70
  62. package/dist/lib/model-utils.js.map +1 -1
  63. package/dist/lib/model.d.ts +34 -104
  64. package/dist/lib/model.d.ts.map +1 -1
  65. package/dist/lib/model.js +111 -502
  66. package/dist/lib/model.js.map +1 -1
  67. package/dist/lib/pipeline-factory.d.ts +60 -0
  68. package/dist/lib/pipeline-factory.d.ts.map +1 -0
  69. package/dist/lib/pipeline-factory.js +219 -0
  70. package/dist/lib/pipeline-factory.js.map +1 -0
  71. package/dist/lib/render-loop.d.ts +5 -18
  72. package/dist/lib/render-loop.d.ts.map +1 -1
  73. package/dist/lib/render-loop.js +16 -23
  74. package/dist/lib/render-loop.js.map +1 -1
  75. package/package.json +6 -6
  76. package/src/animation/key-frames.ts +1 -0
  77. package/src/animation/timeline.ts +2 -2
  78. package/src/geometries/cone-geometry.ts +1 -1
  79. package/src/geometries/cube-geometry.ts +160 -8
  80. package/src/geometries/cylinder-geometry.ts +1 -1
  81. package/src/geometries/ico-sphere-geometry.ts +2 -2
  82. package/src/geometries/plane-geometry.ts +1 -1
  83. package/src/geometries/sphere-geometry.ts +2 -2
  84. package/src/geometries/truncated-cone-geometry.ts +30 -12
  85. package/src/geometry/geometry-table.ts +16 -0
  86. package/src/geometry/geometry-utils.ts +1 -1
  87. package/src/geometry/geometry.ts +97 -47
  88. package/src/geometry/primitive-utils.ts +30 -0
  89. package/src/index.ts +13 -12
  90. package/src/lib/animation-loop.ts +136 -314
  91. package/src/lib/animation-props.ts +31 -0
  92. package/src/{utils → lib}/clip-space.ts +5 -2
  93. package/src/lib/model-utils.ts +60 -32
  94. package/src/lib/model.ts +127 -639
  95. package/src/lib/pipeline-factory.ts +234 -0
  96. package/src/lib/render-loop.ts +24 -22
  97. package/dist/lib/program-manager.d.ts +0 -39
  98. package/dist/lib/program-manager.d.ts.map +0 -1
  99. package/dist/lib/program-manager.js +0 -175
  100. package/dist/lib/program-manager.js.map +0 -1
  101. package/dist/transform/buffer-transform.d.ts +0 -36
  102. package/dist/transform/buffer-transform.d.ts.map +0 -1
  103. package/dist/transform/buffer-transform.js +0 -255
  104. package/dist/transform/buffer-transform.js.map +0 -1
  105. package/dist/transform/texture-transform.d.ts +0 -57
  106. package/dist/transform/texture-transform.d.ts.map +0 -1
  107. package/dist/transform/texture-transform.js +0 -412
  108. package/dist/transform/texture-transform.js.map +0 -1
  109. package/dist/transform/transform-shader-utils.d.ts +0 -26
  110. package/dist/transform/transform-shader-utils.d.ts.map +0 -1
  111. package/dist/transform/transform-shader-utils.js +0 -149
  112. package/dist/transform/transform-shader-utils.js.map +0 -1
  113. package/dist/transform/transform-types.d.ts +0 -44
  114. package/dist/transform/transform-types.d.ts.map +0 -1
  115. package/dist/transform/transform-types.js +0 -2
  116. package/dist/transform/transform.d.ts +0 -47
  117. package/dist/transform/transform.d.ts.map +0 -1
  118. package/dist/transform/transform.js +0 -198
  119. package/dist/transform/transform.js.map +0 -1
  120. package/dist/utils/clip-space.d.ts +0 -5
  121. package/dist/utils/clip-space.d.ts.map +0 -1
  122. package/dist/utils/clip-space.js +0 -34
  123. package/dist/utils/clip-space.js.map +0 -1
  124. package/src/lib/program-manager.ts +0 -187
  125. package/src/transform/buffer-transform.ts +0 -214
  126. package/src/transform/texture-transform.ts +0 -344
  127. package/src/transform/transform-shader-utils.ts +0 -169
  128. package/src/transform/transform-types.ts +0 -42
  129. package/src/transform/transform.ts +0 -189
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/lib/animation-loop.ts"],"names":["luma","lumaStats","log","isWebGL","resetParameters","requestAnimationFrame","cancelAnimationFrame","Query","Framebuffer","isBrowser","isPage","document","statIdCounter","DEFAULT_ANIMATION_LOOP_PROPS","onCreateDevice","props","createDevice","onCreateContext","onAddHTML","onInitialize","onRender","onFinalize","onError","error","console","device","debug","useDevicePixels","autoResizeViewport","autoResizeDrawingBuffer","stats","get","gl","glOptions","createFramebuffer","AnimationLoop","constructor","deprecated","useDevicePixelRatio","cpuTime","gpuTime","frameRate","setProps","start","bind","stop","_onMousemove","_onMouseleave","destroy","_setDisplay","delete","setNeedsRedraw","reason","needsRedraw","opts","_start","_running","_getPageLoadPromise","appContext","_initialized","_initialize","animationProps","_addCallbackData","_cancelAnimationFrame","_requestAnimationFrame","redraw","isContextLost","_beginTimers","_setupFrame","_updateCallbackData","_renderFrame","_clearNeedsRedraw","_resolveNextFrame","_nextFramePromise","_endTimers","_finalizeCallbackData","attachTimeline","timeline","detachTimeline","waitForRender","Promise","resolve","toDataURL","canvas","deviceProps","getHTMLControlValue","id","defaultValue","element","getElementById","Number","value","_createDevice","_createFramebuffer","_startEventHandling","_initializeCallbackData","_resizeCanvasDrawingBuffer","_resizeViewport","_gpuTimeQuery","isSupported","_pageLoadPromise","reject","readyState","window","addEventListener","display","animationLoop","_animationFrameId","_animationFrame","_resizeFramebuffer","startTime","Date","now","engineTime","tick","tock","time","_mousePosition","framebuffer","_timeline","_loop","_animationLoop","width","height","aspect","_getSizeAndAspect","update","Math","floor","getTime","Object","assign","Error","_createInfoDiv","wrapperDiv","createElement","body","appendChild","style","position","div","left","bottom","background","html","innerHTML","drawingBufferWidth","drawingBufferHeight","clientHeight","clientWidth","viewport","resize","timeEnd","timeStart","isResultAvailable","isTimerDisjoint","addTime","getTimerMilliseconds","beginTimeElapsedQuery","end","e","offsetX","offsetY"],"mappings":";AAAA,SAAQA,IAAR,QAA2B,cAA3B;AACA,SACEC,SADF,EAGEC,GAHF,QAKO,cALP;AAQA,SACEC,OADF,EAKEC,eALF,QAMO,gBANP;AASA,SACEC,qBADF,EAEEC,oBAFF,EAGEC,KAHF,EAKEC,WALF,QAMO,gBANP;AASA,SAAQC,SAAR,QAAwB,eAAxB;AAQA,MAAMC,MAAM,GAAGD,SAAS,MAAM,OAAOE,QAAP,KAAoB,WAAlD;AAEA,IAAIC,aAAa,GAAG,CAApB;AAqEA,MAAMC,4BAA0D,GAAG;AACjEC,EAAAA,cAAc,EAAGC,KAAD,IAAwBf,IAAI,CAACgB,YAAL,CAAkBD,KAAlB,CADyB;AAEjEE,EAAAA,eAAe,EAAE,IAFgD;AAGjEC,EAAAA,SAAS,EAAE,IAHsD;AAIjEC,EAAAA,YAAY,EAAE,OAAO,EAAP,CAJmD;AAKjEC,EAAAA,QAAQ,EAAE,MAAM,CAAE,CAL+C;AAMjEC,EAAAA,UAAU,EAAE,MAAM,CAAE,CAN6C;AAOjEC,EAAAA,OAAO,EAAGC,KAAD,IAAWC,OAAO,CAACD,KAAR,CAAcA,KAAd,CAP6C;AASjEE,EAAAA,MAAM,EAAE,IATy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A,WAAL,CAAiBiC,MAAjB,CAAwB;AACtB7B,QAAAA,KAAK,EAAE,KAAK1F,EAAL,CAAQkH,kBADO;AAEtBvB,QAAAA,MAAM,EAAE,KAAK3F,EAAL,CAAQmH;AAFM,OAAxB;AAID;AACF;;AA9kBgC","sourcesContent":["import {luma, Device} from '@luma.gl/api';\nimport {\n lumaStats,\n // TODO - remove dependency on framebuffer (bundle size impact)\n log,\n assert\n} from '@luma.gl/api';\nimport type {WebGLDeviceProps} from '@luma.gl/webgl'\nimport {WebGLDevice} from '@luma.gl/webgl';\nimport {\n isWebGL,\n // createGLContext,\n // instrumentGLContext,\n // resizeGLContext,\n resetParameters\n} from '@luma.gl/webgl';\n\n\nimport {\n requestAnimationFrame,\n cancelAnimationFrame,\n Query,\n // TODO - remove dependency on framebuffer (bundle size impact)\n Framebuffer\n} from '@luma.gl/webgl';\n\nimport { Stats, Stat } from '@probe.gl/stats'\nimport {isBrowser} from '@probe.gl/env';\n\nimport { Timeline } from '../animation/timeline'\n\n\ntype DeviceProps = WebGLDeviceProps;\ntype ContextProps = WebGLDeviceProps;\n\nconst isPage = isBrowser() && typeof document !== 'undefined';\n\nlet statIdCounter = 0;\n\n/** AnimationLoop properties */\nexport type AnimationLoopProps = {\n onCreateDevice?: (props: DeviceProps) => Device;\n onCreateContext?: (props: ContextProps) => WebGLRenderingContext; // TODO: signature from createGLContext\n onAddHTML?: (div: HTMLDivElement) => string; // innerHTML\n onInitialize?: (animationProps: AnimationProps) => {} | void;\n onRender?: (animationProps: AnimationProps) => void;\n onFinalize?: (animationProps: AnimationProps) => void;\n onError?: (reason: any) => void;\n\n stats?: Stats;\n\n device?: Device;\n glOptions?: ContextProps; // createGLContext options\n debug?: boolean;\n\n // view parameters\n autoResizeViewport?: boolean;\n autoResizeDrawingBuffer?: boolean;\n useDevicePixels?: number | boolean;\n\n /** @deprecated Use .device */\n gl?: WebGLRenderingContext\n /** @deprecated Will be removed */\n createFramebuffer?: boolean;\n};\n\nexport type AnimationProps = {\n device: Device;\n\n stop: () => AnimationLoop\n canvas: HTMLCanvasElement | OffscreenCanvas\n // Initial values\n useDevicePixels: number | boolean\n needsRedraw?: string\n // Animation props\n startTime: number\n engineTime: number\n tick: number\n tock: number\n\n // Timeline time for back compatibility\n time: number\n\n width: number\n height: number\n aspect: number\n\n timeline: Timeline\n animationLoop: AnimationLoop\n\n // Experimental\n _mousePosition?: [number, number] // [offsetX, offsetY],\n\n /** @deprecated Will be removed, create your own Framebuffer */\n framebuffer: Framebuffer\n /** @deprecated Use .device */\n gl: WebGLRenderingContext\n\n /** @deprecated Use .timeline */\n _timeline: Timeline\n /** @deprecated Use .animationLoop */\n _loop: AnimationLoop\n /** @deprecated Use .animationLoop */\n _animationLoop: AnimationLoop\n}\n\nconst DEFAULT_ANIMATION_LOOP_PROPS: Required<AnimationLoopProps> = {\n onCreateDevice: (props: DeviceProps) => luma.createDevice(props),\n onCreateContext: null,\n onAddHTML: null,\n onInitialize: () => ({}),\n onRender: () => {},\n onFinalize: () => {},\n onError: (error) => console.error(error), // eslint-disable-line no-console\n\n device: null,\n debug: false,\n\n // view parameters\n useDevicePixels: true,\n autoResizeViewport: true,\n autoResizeDrawingBuffer: true,\n stats: lumaStats.get(`animation-loop-${statIdCounter++}`),\n\n // deprecated\n // onCreateContext: (opts) => createGLContext(opts),\n gl: null,\n glOptions: {},\n createFramebuffer: false\n};\n\n/** Convenient animation loop */\nexport default class AnimationLoop {\n device: Device;\n canvas: HTMLCanvasElement | OffscreenCanvas;\n\n props: Required<AnimationLoopProps>;\n animationProps: AnimationProps;\n framebuffer: Framebuffer = null;\n timeline: Timeline = null;\n stats: Stats;\n cpuTime: Stat;\n gpuTime: Stat;\n frameRate: Stat;\n\n display: any;\n\n needsRedraw: string | null = 'initialized';\n\n _initialized: boolean = false;\n _running: boolean = false;\n _animationFrameId = null;\n _pageLoadPromise: Promise<{}> | null = null;\n _nextFramePromise: Promise<AnimationLoop> | null = null;\n _resolveNextFrame: ((AnimationLoop) => void) | null = null;\n _cpuStartTime: number = 0;\n\n _gpuTimeQuery: Query | null = null;\n\n /** @deprecated */\n gl: WebGLRenderingContext;\n\n /*\n * @param {HTMLCanvasElement} canvas - if provided, width and height will be passed to context\n */\n constructor(props: AnimationLoopProps = {}) {\n this.props = {...DEFAULT_ANIMATION_LOOP_PROPS, ...props};\n props = this.props;\n\n let {useDevicePixels = true} = this.props;\n\n if ('useDevicePixelRatio' in props) {\n log.deprecated('useDevicePixelRatio', 'useDevicePixels')();\n // @ts-expect-error\n useDevicePixels = props.useDevicePixelRatio;\n }\n\n // state\n this.device = props.device;\n // @ts-expect-error\n this.gl = (this.device && this.device.gl) || props.gl;\n\n this.stats = props.stats;\n this.cpuTime = this.stats.get('CPU Time');\n this.gpuTime = this.stats.get('GPU Time');\n this.frameRate = this.stats.get('Frame Rate');\n\n this.setProps({\n autoResizeViewport: props.autoResizeViewport,\n autoResizeDrawingBuffer: props.autoResizeDrawingBuffer,\n useDevicePixels\n });\n\n // Bind methods\n this.start = this.start.bind(this);\n this.stop = this.stop.bind(this);\n\n this._onMousemove = this._onMousemove.bind(this);\n this._onMouseleave = this._onMouseleave.bind(this);\n }\n\n destroy(): void {\n this.stop();\n this._setDisplay(null);\n }\n\n /** @deprecated Use .destroy() */\n delete(): void {\n this.destroy();\n }\n\n setNeedsRedraw(reason: string): this {\n this.needsRedraw = this.needsRedraw || reason;\n return this;\n }\n\n setProps(props: AnimationLoopProps): this {\n if ('autoResizeViewport' in props) {\n this.props.autoResizeViewport = props.autoResizeViewport;\n }\n if ('autoResizeDrawingBuffer' in props) {\n this.props.autoResizeDrawingBuffer = props.autoResizeDrawingBuffer;\n }\n if ('useDevicePixels' in props) {\n this.props.useDevicePixels = props.useDevicePixels;\n }\n return this;\n }\n\n start(opts = {}) {\n this._start(opts);\n return this;\n }\n\n /** Starts a render loop if not already running\n * @param {Object} context - contains frame specific info (E.g. tick, width, height, etc)\n */\n async _start(opts) {\n if (this._running) {\n return this;\n }\n this._running = true;\n\n // console.debug(`Starting ${this.constructor.name}`);\n // Wait for start promise before rendering frame\n try {\n await this._getPageLoadPromise();\n\n // check that we haven't been stopped\n if (!this._running) {\n return null;\n }\n\n let appContext;\n if (!this._initialized) {\n this._initialized = true;\n this._initialize(opts);\n\n // Note: onIntialize can return a promise (in case app needs to load resources)\n appContext = await this.onInitialize(this.animationProps);\n this._addCallbackData(appContext || {});\n }\n\n // check that we haven't been stopped\n if (!this._running) {\n return null;\n }\n\n // Start the loop\n if (appContext !== false) {\n // cancel any pending renders to ensure only one loop can ever run\n this._cancelAnimationFrame();\n this._requestAnimationFrame();\n }\n\n return this;\n } catch (error) {\n this.props.onError(error);\n // this._running = false; // TODO\n return null;\n }\n }\n\n /** Explicitly draw a frame */\n redraw(): this {\n if (this.isContextLost()) {\n return this;\n }\n\n this._beginTimers();\n\n this._setupFrame();\n this._updateCallbackData();\n\n this._renderFrame(this.animationProps);\n\n // clear needsRedraw flag\n this._clearNeedsRedraw();\n\n if (this._resolveNextFrame) {\n this._resolveNextFrame(this);\n this._nextFramePromise = null;\n this._resolveNextFrame = null;\n }\n\n this._endTimers();\n\n return this;\n }\n\n // Stops a render loop if already running, finalizing\n stop() {\n // console.debug(`Stopping ${this.constructor.name}`);\n if (this._running) {\n this._finalizeCallbackData();\n this._cancelAnimationFrame();\n this._nextFramePromise = null;\n this._resolveNextFrame = null;\n this._running = false;\n }\n return this;\n }\n\n attachTimeline(timeline: Timeline): Timeline {\n this.timeline = timeline;\n return this.timeline;\n }\n\n detachTimeline(): void {\n this.timeline = null;\n }\n\n waitForRender(): Promise<AnimationLoop> {\n this.setNeedsRedraw('waitForRender');\n\n if (!this._nextFramePromise) {\n this._nextFramePromise = new Promise((resolve) => {\n this._resolveNextFrame = resolve;\n });\n }\n return this._nextFramePromise;\n }\n\n async toDataURL() {\n this.setNeedsRedraw('toDataURL');\n\n await this.waitForRender();\n\n return this.gl.canvas.toDataURL();\n }\n\n isContextLost(): boolean {\n return this.gl.isContextLost();\n }\n\n onCreateDevice(deviceProps: DeviceProps) {\n return this.props.onCreateDevice(deviceProps);\n }\n\n onInitialize(animationProps: AnimationProps): {} | void {\n return this.props.onInitialize(animationProps);\n }\n\n onRender(animationProps: AnimationProps) {\n return this.props.onRender(animationProps);\n }\n\n onFinalize(animationProps: AnimationProps) {\n return this.props.onFinalize(animationProps);\n }\n\n // DEPRECATED/REMOVED METHODS\n\n /** @deprecated Use .onCreateDevice() */\n onCreateContext(props: ContextProps) {\n return this.props.onCreateContext(props);\n }\n\n /** @deprecated */\n getHTMLControlValue(id, defaultValue = 1) {\n const element = document.getElementById(id);\n // @ts-expect-error Not all html elements have value\n return element ? Number(element.value) : defaultValue;\n }\n\n // PRIVATE METHODS\n\n _initialize(props: AnimationLoopProps) {\n // Create the WebGL context\n this._createDevice(props);\n this._createFramebuffer();\n this._startEventHandling();\n\n // Initialize the callback data\n this._initializeCallbackData();\n this._updateCallbackData();\n\n // Default viewport setup, in case onInitialize wants to render\n this._resizeCanvasDrawingBuffer();\n this._resizeViewport();\n\n this._gpuTimeQuery = Query.isSupported(this.gl, ['timers']) ? new Query(this.gl) : null;\n }\n\n _getPageLoadPromise() {\n if (!this._pageLoadPromise) {\n this._pageLoadPromise = isPage\n ? new Promise((resolve, reject) => {\n if (isPage && document.readyState === 'complete') {\n resolve(document);\n return;\n }\n window.addEventListener('load', () => {\n resolve(document);\n });\n })\n : Promise.resolve({});\n }\n return this._pageLoadPromise;\n }\n\n _setDisplay(display) {\n if (this.display) {\n this.display.delete();\n this.display.animationLoop = null;\n }\n\n // store animation loop on the display\n if (display) {\n display.animationLoop = this;\n }\n\n this.display = display;\n }\n\n _requestAnimationFrame() {\n if (!this._running) {\n return;\n }\n\n // VR display has a separate animation frame to sync with headset\n // TODO WebVR API discontinued, replaced by WebXR: https://immersive-web.github.io/webxr/\n // See https://developer.mozilla.org/en-US/docs/Web/API/VRDisplay/requestAnimationFrame\n // if (this.display && this.display.requestAnimationFrame) {\n // this._animationFrameId = this.display.requestAnimationFrame(this._animationFrame.bind(this));\n // }\n this._animationFrameId = requestAnimationFrame(this._animationFrame.bind(this));\n }\n\n _cancelAnimationFrame() {\n if (this._animationFrameId !== null) {\n return;\n }\n\n // VR display has a separate animation frame to sync with headset\n // TODO WebVR API discontinued, replaced by WebXR: https://immersive-web.github.io/webxr/\n // See https://developer.mozilla.org/en-US/docs/Web/API/VRDisplay/requestAnimationFrame\n // if (this.display && this.display.cancelAnimationFrame) {\n // this.display.cancelAnimationFrame(this._animationFrameId);\n // }\n cancelAnimationFrame(this._animationFrameId);\n this._animationFrameId = null;\n }\n\n _animationFrame() {\n if (!this._running) {\n return;\n }\n this.redraw();\n this._requestAnimationFrame();\n }\n\n // Called on each frame, can be overridden to call onRender multiple times\n // to support e.g. stereoscopic rendering\n _renderFrame(props: AnimationProps) {\n // Allow e.g. VR display to render multiple frames.\n if (this.display) {\n this.display._renderFrame(props);\n return;\n }\n\n // call callback\n this.onRender(props);\n // end callback\n }\n\n _clearNeedsRedraw() {\n this.needsRedraw = null;\n }\n\n _setupFrame() {\n this._resizeCanvasDrawingBuffer();\n this._resizeViewport();\n this._resizeFramebuffer();\n }\n\n // Initialize the object that will be passed to app callbacks\n _initializeCallbackData() {\n // @ts-expect-error\n this.animationProps = {\n device: this.device,\n gl: this.gl,\n\n stop: this.stop,\n canvas: this.gl.canvas,\n\n // Initial values\n useDevicePixels: this.props.useDevicePixels,\n needsRedraw: null,\n\n // Animation props\n startTime: Date.now(),\n engineTime: 0,\n tick: 0,\n tock: 0,\n\n timeline: this.timeline,\n animationLoop: this,\n\n // Timeline time for back compatibility\n time: 0,\n\n // Experimental\n _mousePosition: null, // Event props\n\n // Deprecated\n framebuffer: this.framebuffer,\n _timeline: this.timeline,\n _loop: this,\n _animationLoop: this\n };\n }\n\n // Update the context object that will be passed to app callbacks\n _updateCallbackData() {\n const {width, height, aspect} = this._getSizeAndAspect();\n if (width !== this.animationProps.width || height !== this.animationProps.height) {\n this.setNeedsRedraw('drawing buffer resized');\n }\n if (aspect !== this.animationProps.aspect) {\n this.setNeedsRedraw('drawing buffer aspect changed');\n }\n\n this.animationProps.width = width;\n this.animationProps.height = height;\n this.animationProps.aspect = aspect;\n\n this.animationProps.needsRedraw = this.needsRedraw;\n\n // Update time properties\n this.animationProps.engineTime = Date.now() - this.animationProps.startTime;\n\n if (this.timeline) {\n this.timeline.update(this.animationProps.engineTime);\n }\n\n this.animationProps.tick = Math.floor((this.animationProps.time / 1000) * 60);\n this.animationProps.tock++;\n\n // For back compatibility\n this.animationProps.time = this.timeline\n ? this.timeline.getTime()\n : this.animationProps.engineTime;\n }\n\n _finalizeCallbackData() {\n // call callback\n this.onFinalize(this.animationProps);\n // end callback\n }\n\n /** Add application's data to the app context object */\n _addCallbackData(appContext) {\n if (typeof appContext === 'object' && appContext !== null) {\n this.animationProps = Object.assign({}, this.animationProps, appContext);\n }\n }\n\n /** Either uses supplied or existing context, or calls provided callback to create one */\n _createDevice(props: DeviceProps) {\n const deviceProps = {...this.props, ...props, ...this.props.glOptions};\n\n // TODO - support this.onCreateContext\n // Create the WebGL context if necessary\n // this.gl = this.props.gl ? instrumentGLContext(this.props.gl, deviceProps) : this.onCreateContext(deviceProps);\n\n this.device = this.onCreateDevice(deviceProps);\n // @ts-expect-error\n this.gl = this.device.gl;\n\n if (!isWebGL(this.gl)) {\n throw new Error('AnimationLoop.onCreateContext - illegal context returned');\n }\n\n // Reset the WebGL context.\n resetParameters(this.gl);\n\n this._createInfoDiv();\n }\n\n _createInfoDiv() {\n if (this.gl.canvas && this.props.onAddHTML) {\n const wrapperDiv = document.createElement('div');\n document.body.appendChild(wrapperDiv);\n wrapperDiv.style.position = 'relative';\n const div = document.createElement('div');\n div.style.position = 'absolute';\n div.style.left = '10px';\n div.style.bottom = '10px';\n div.style.width = '300px';\n div.style.background = 'white';\n wrapperDiv.appendChild(this.gl.canvas);\n wrapperDiv.appendChild(div);\n const html = this.props.onAddHTML(div);\n if (html) {\n div.innerHTML = html;\n }\n }\n }\n\n _getSizeAndAspect() {\n // https://webglfundamentals.org/webgl/lessons/webgl-resizing-the-canvas.html\n const width = this.gl.drawingBufferWidth;\n const height = this.gl.drawingBufferHeight;\n\n // https://webglfundamentals.org/webgl/lessons/webgl-anti-patterns.html\n let aspect = 1;\n const {canvas} = this.gl;\n\n if (canvas && canvas.clientHeight) {\n aspect = canvas.clientWidth / canvas.clientHeight;\n } else if (width > 0 && height > 0) {\n aspect = width / height;\n }\n\n return {width, height, aspect};\n }\n\n /** Default viewport setup */\n _resizeViewport() {\n if (this.props.autoResizeViewport) {\n this.gl.viewport(0, 0, this.gl.drawingBufferWidth, this.gl.drawingBufferHeight);\n }\n }\n\n /** \n * Resize the render buffer of the canvas to match canvas client size\n * Optionally multiplying with devicePixel ratio\n */\n _resizeCanvasDrawingBuffer() {\n if (this.props.autoResizeDrawingBuffer) {\n (this.device as WebGLDevice).resize({useDevicePixels: this.props.useDevicePixels});\n }\n }\n\n _beginTimers() {\n this.frameRate.timeEnd();\n this.frameRate.timeStart();\n\n // Check if timer for last frame has completed.\n // GPU timer results are never available in the same\n // frame they are captured.\n if (\n this._gpuTimeQuery &&\n this._gpuTimeQuery.isResultAvailable() &&\n !this._gpuTimeQuery.isTimerDisjoint()\n ) {\n this.stats.get('GPU Time').addTime(this._gpuTimeQuery.getTimerMilliseconds());\n }\n\n if (this._gpuTimeQuery) {\n // GPU time query start\n this._gpuTimeQuery.beginTimeElapsedQuery();\n }\n\n this.cpuTime.timeStart();\n }\n\n _endTimers() {\n this.cpuTime.timeEnd();\n\n if (this._gpuTimeQuery) {\n // GPU time query end. Results will be available on next frame.\n this._gpuTimeQuery.end();\n }\n }\n\n // Event handling\n\n _startEventHandling() {\n const {canvas} = this.gl;\n if (canvas) {\n canvas.addEventListener('mousemove', this._onMousemove);\n canvas.addEventListener('mouseleave', this._onMouseleave);\n }\n }\n\n _onMousemove(e) {\n this.animationProps._mousePosition = [e.offsetX, e.offsetY];\n }\n _onMouseleave(e) {\n this.animationProps._mousePosition = null;\n }\n\n // Deprecated\n\n /** @deprecated */\n _createFramebuffer() {\n // Setup default framebuffer\n if (this.props.createFramebuffer) {\n this.framebuffer = new Framebuffer(this.gl);\n }\n }\n\n /** @deprecated */\n _resizeFramebuffer() {\n if (this.framebuffer) {\n this.framebuffer.resize({\n width: this.gl.drawingBufferWidth,\n height: this.gl.drawingBufferHeight\n });\n }\n } \n}\n"],"file":"animation-loop.js"}
1
+ {"version":3,"sources":["../../src/lib/animation-loop.ts"],"names":["luma","requestAnimationFrame","cancelAnimationFrame","Stats","isBrowser","isPage","document","statIdCounter","DEFAULT_ANIMATION_LOOP_PROPS","onCreateDevice","props","createDevice","onAddHTML","onInitialize","onRender","onFinalize","onError","error","console","device","deviceProps","debug","stats","get","useDevicePixels","autoResizeViewport","autoResizeDrawingBuffer","AnimationLoop","constructor","gl","id","cpuTime","gpuTime","frameRate","setProps","start","bind","stop","_onMousemove","_onMouseleave","destroy","_setDisplay","delete","setNeedsRedraw","reason","needsRedraw","_running","appContext","_initialized","_createDevice","_initialize","_getAnimationProps","_cancelAnimationFrame","_requestAnimationFrame","err","Error","redraw","isLost","_beginTimers","_setupFrame","_updateAnimationProps","_renderFrame","_clearNeedsRedraw","_resolveNextFrame","_nextFramePromise","_endTimers","animationProps","attachTimeline","timeline","detachTimeline","waitForRender","Promise","resolve","toDataURL","canvas","HTMLCanvasElement","_startEventHandling","_initializeAnimationProps","_resizeCanvasDrawingBuffer","_resizeViewport","display","animationLoop","_animationFrameId","_animationFrame","canvasContext","width","height","aspect","time","startTime","Date","now","engineTime","tick","tock","_mousePosition","_getSizeAndAspect","update","Math","floor","getTime","_createInfoDiv","wrapperDiv","createElement","body","appendChild","style","position","div","left","bottom","background","html","innerHTML","getPixelSize","clientHeight","clientWidth","viewport","drawingBufferWidth","drawingBufferHeight","resize","timeEnd","timeStart","addEventListener","event","MouseEvent","offsetX","offsetY"],"mappings":";AAAA,SAAQA,IAAR,QAAwC,cAAxC;AACA,SAAQC,qBA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0BAA0B,GAAG;AAC3B,QAAI,KAAKpE,KAAL,CAAWgB,uBAAf,EAAwC;AAAA;;AACtC,4BAAKP,MAAL,yFAAaiE,aAAb,gFAA4BoC,MAA5B,CAAmC;AAAChG,QAAAA,eAAe,EAAE,KAAKd,KAAL,CAAWc;AAA7B,OAAnC;AACD;AACF;;AAEDkC,EAAAA,YAAY,GAAG;AACb,SAAKzB,SAAL,CAAewF,OAAf;AACA,SAAKxF,SAAL,CAAeyF,SAAf;AAmBD;;AAEDzD,EAAAA,UAAU,GAAG;AACX,SAAKlC,OAAL,CAAa0F,OAAb;AAMD;;AAID7C,EAAAA,mBAAmB,GAAG;AACpB,QAAI,KAAKF,MAAT,EAAiB;AACf,WAAKA,MAAL,CAAYiD,gBAAZ,CAA6B,WAA7B,EAA0C,KAAKrF,YAA/C;AACA,WAAKoC,MAAL,CAAYiD,gBAAZ,CAA6B,YAA7B,EAA2C,KAAKpF,aAAhD;AACD;AACF;;AAEDD,EAAAA,YAAY,CAACsF,KAAD,EAAe;AACzB,QAAIA,KAAK,YAAYC,UAArB,EAAiC;AAC/B,WAAK1E,kBAAL,GAA0B4C,cAA1B,GAA2C,CAAC6B,KAAK,CAACE,OAAP,EAAgBF,KAAK,CAACG,OAAtB,CAA3C;AACD;AACF;;AAEDxF,EAAAA,aAAa,CAACqF,KAAD,EAAe;AAC1B,SAAKzE,kBAAL,GAA0B4C,cAA1B,GAA2C,IAA3C;AACD;;AA3ewB","sourcesContent":["import {luma, Device, DeviceProps} from '@luma.gl/api';\nimport {requestAnimationFrame, cancelAnimationFrame} from '@luma.gl/api';\nimport {Timeline} from '../animation/timeline';\nimport {AnimationProps} from '../lib/animation-props';\nimport {Stats, Stat} from '@probe.gl/stats';\nimport {isBrowser} from '@probe.gl/env';\n\nconst isPage = isBrowser() && typeof document !== 'undefined';\n\nlet statIdCounter = 0;\n\ntype ContextProps = DeviceProps;\n\n/** AnimationLoop properties */\nexport type AnimationLoopProps = {\n onCreateDevice?: (props: DeviceProps) => Promise<Device>;\n onAddHTML?: (div: HTMLDivElement) => string; // innerHTML\n onInitialize?: (animationProps: AnimationProps) => void;\n onRender?: (animationProps: AnimationProps) => void;\n onFinalize?: (animationProps: AnimationProps) => void;\n onError?: (reason: Error) => void;\n\n device?: Device | null;\n deviceProps?: DeviceProps;\n stats?: Stats;\n\n // view parameters\n debug?: boolean;\n autoResizeViewport?: boolean;\n autoResizeDrawingBuffer?: boolean;\n useDevicePixels?: number | boolean;\n};\n\nconst DEFAULT_ANIMATION_LOOP_PROPS: Required<AnimationLoopProps> = {\n onCreateDevice: (props: DeviceProps): Promise<Device> => luma.createDevice(props),\n onAddHTML: () => '',\n onInitialize: () => ({}),\n onRender: () => {},\n onFinalize: () => {},\n onError: (error) => console.error(error), // eslint-disable-line no-console\n\n device: null,\n deviceProps: {},\n debug: false,\n stats: luma.stats.get(`animation-loop-${statIdCounter++}`),\n\n // view parameters\n useDevicePixels: true,\n autoResizeViewport: true,\n autoResizeDrawingBuffer: true,\n};\n\n/** Convenient animation loop */\nexport class AnimationLoop {\n device: Device | null = null;\n canvas: HTMLCanvasElement | OffscreenCanvas | null = null;\n\n props: Required<AnimationLoopProps>;\n animationProps: AnimationProps | null = null;\n timeline: Timeline | null = null;\n stats: Stats;\n cpuTime: Stat;\n gpuTime: Stat;\n frameRate: Stat;\n\n display: any;\n\n needsRedraw: string | false = 'initialized';\n\n _initialized: boolean = false;\n _running: boolean = false;\n _animationFrameId: any = null;\n _nextFramePromise: Promise<AnimationLoop> | null = null;\n _resolveNextFrame: ((AnimationLoop) => void) | null = null;\n _cpuStartTime: number = 0;\n\n // _gpuTimeQuery: Query | null = null;\n\n /*\n * @param {HTMLCanvasElement} canvas - if provided, width and height will be passed to context\n */\n constructor(props: AnimationLoopProps = {}) {\n this.props = {...DEFAULT_ANIMATION_LOOP_PROPS, ...props};\n props = this.props;\n\n let {useDevicePixels = true} = this.props;\n\n // state\n this.device = props.device || null;\n // @ts-expect-error\n this.gl = (this.device && this.device.gl) || props.gl;\n\n this.stats = props.stats || new Stats({id: 'animation-loop-stats'});\n this.cpuTime = this.stats.get('CPU Time');\n this.gpuTime = this.stats.get('GPU Time');\n this.frameRate = this.stats.get('Frame Rate');\n\n this.setProps({\n autoResizeViewport: props.autoResizeViewport,\n autoResizeDrawingBuffer: props.autoResizeDrawingBuffer,\n useDevicePixels\n });\n\n // Bind methods\n this.start = this.start.bind(this);\n this.stop = this.stop.bind(this);\n\n this._onMousemove = this._onMousemove.bind(this);\n this._onMouseleave = this._onMouseleave.bind(this);\n }\n\n destroy(): void {\n this.stop();\n this._setDisplay(null);\n }\n\n /** @deprecated Use .destroy() */\n delete(): void {\n this.destroy();\n }\n\n setNeedsRedraw(reason: string): this {\n this.needsRedraw = this.needsRedraw || reason;\n return this;\n }\n\n // TODO - move to CanvasContext\n setProps(props: AnimationLoopProps): this {\n if ('autoResizeViewport' in props) {\n this.props.autoResizeViewport = props.autoResizeViewport || false;\n }\n if ('autoResizeDrawingBuffer' in props) {\n this.props.autoResizeDrawingBuffer = props.autoResizeDrawingBuffer || false;\n }\n if ('useDevicePixels' in props) {\n this.props.useDevicePixels = props.useDevicePixels || false;\n }\n return this;\n }\n\n /** Starts a render loop if not already running */\n async start() {\n if (this._running) {\n return this;\n }\n this._running = true;\n\n try {\n // check that we haven't been stopped\n if (!this._running) {\n return null;\n }\n\n let appContext;\n if (!this._initialized) {\n this._initialized = true;\n // Create the WebGL context\n await this._createDevice();\n this._initialize();\n\n // Note: onIntialize can return a promise (e.g. in case app needs to load resources)\n await this.props.onInitialize(this._getAnimationProps());\n }\n\n // check that we haven't been stopped\n if (!this._running) {\n return null;\n }\n\n // Start the loop\n if (appContext !== false) {\n // cancel any pending renders to ensure only one loop can ever run\n this._cancelAnimationFrame();\n this._requestAnimationFrame();\n }\n\n return this;\n } catch (err: unknown) {\n const error = err instanceof Error ? err : new Error('Unknown error')\n this.props.onError(error);\n // this._running = false; // TODO\n throw error;\n }\n }\n\n /** Explicitly draw a frame */\n redraw(): this {\n if (this.device?.isLost) {\n return this;\n }\n\n this._beginTimers();\n\n this._setupFrame();\n this._updateAnimationProps();\n\n this._renderFrame(this._getAnimationProps());\n\n // clear needsRedraw flag\n this._clearNeedsRedraw();\n\n if (this._resolveNextFrame) {\n this._resolveNextFrame(this);\n this._nextFramePromise = null;\n this._resolveNextFrame = null;\n }\n\n this._endTimers();\n\n return this;\n }\n\n // Stops a render loop if already running, finalizing\n stop() {\n // console.debug(`Stopping ${this.constructor.name}`);\n if (this._running) {\n // call callback\n // If stop is called immediately, we can end up in a state where props haven't been initialized...\n if (this.animationProps) {\n this.props.onFinalize(this.animationProps);\n }\n\n this._cancelAnimationFrame();\n this._nextFramePromise = null;\n this._resolveNextFrame = null;\n this._running = false;\n }\n return this;\n }\n\n attachTimeline(timeline: Timeline): Timeline {\n this.timeline = timeline;\n return this.timeline;\n }\n\n detachTimeline(): void {\n this.timeline = null;\n }\n\n waitForRender(): Promise<AnimationLoop> {\n this.setNeedsRedraw('waitForRender');\n\n if (!this._nextFramePromise) {\n this._nextFramePromise = new Promise((resolve) => {\n this._resolveNextFrame = resolve;\n });\n }\n return this._nextFramePromise;\n }\n\n async toDataURL(): Promise<string> {\n this.setNeedsRedraw('toDataURL');\n await this.waitForRender();\n if (this.canvas instanceof HTMLCanvasElement) {\n return this.canvas.toDataURL();\n }\n throw new Error('OffscreenCanvas');\n }\n\n // PRIVATE METHODS\n\n _initialize() {\n this._startEventHandling();\n\n // Initialize the callback data\n this._initializeAnimationProps();\n this._updateAnimationProps();\n\n // Default viewport setup, in case onInitialize wants to render\n this._resizeCanvasDrawingBuffer();\n this._resizeViewport();\n\n // this._gpuTimeQuery = Query.isSupported(this.gl, ['timers']) ? new Query(this.gl) : null;\n }\n\n _setDisplay(display) {\n if (this.display) {\n this.display.delete();\n this.display.animationLoop = null;\n }\n\n // store animation loop on the display\n if (display) {\n display.animationLoop = this;\n }\n\n this.display = display;\n }\n\n _requestAnimationFrame() {\n if (!this._running) {\n return;\n }\n\n // VR display has a separate animation frame to sync with headset\n // TODO WebVR API discontinued, replaced by WebXR: https://immersive-web.github.io/webxr/\n // See https://developer.mozilla.org/en-US/docs/Web/API/VRDisplay/requestAnimationFrame\n // if (this.display && this.display.requestAnimationFrame) {\n // this._animationFrameId = this.display.requestAnimationFrame(this._animationFrame.bind(this));\n // }\n this._animationFrameId = requestAnimationFrame(this._animationFrame.bind(this));\n }\n\n _cancelAnimationFrame() {\n if (this._animationFrameId !== null) {\n return;\n }\n\n // VR display has a separate animation frame to sync with headset\n // TODO WebVR API discontinued, replaced by WebXR: https://immersive-web.github.io/webxr/\n // See https://developer.mozilla.org/en-US/docs/Web/API/VRDisplay/requestAnimationFrame\n // if (this.display && this.display.cancelAnimationFrame) {\n // this.display.cancelAnimationFrame(this._animationFrameId);\n // }\n cancelAnimationFrame(this._animationFrameId);\n this._animationFrameId = null;\n }\n\n _animationFrame() {\n if (!this._running) {\n return;\n }\n this.redraw();\n this._requestAnimationFrame();\n }\n\n // Called on each frame, can be overridden to call onRender multiple times\n // to support e.g. stereoscopic rendering\n _renderFrame(props: AnimationProps) {\n // Allow e.g. VR display to render multiple frames.\n if (this.display) {\n this.display._renderFrame(props);\n return;\n }\n\n // call callback\n this.props.onRender(props);\n // end callback\n }\n\n _clearNeedsRedraw() {\n this.needsRedraw = false;\n }\n\n _setupFrame() {\n this._resizeCanvasDrawingBuffer();\n this._resizeViewport();\n }\n\n // Initialize the object that will be passed to app callbacks\n _initializeAnimationProps() {\n if (!this.device) {\n throw new Error('loop');\n }\n this.animationProps = {\n animationLoop: this,\n device: this.device,\n canvas: this.device?.canvasContext?.canvas!,\n timeline: this.timeline,\n\n // Initial values\n useDevicePixels: this.props.useDevicePixels,\n needsRedraw: false,\n\n // Placeholders\n width: 1,\n height: 1,\n aspect: 1,\n\n // Animation props\n time: 0,\n startTime: Date.now(),\n engineTime: 0,\n tick: 0,\n tock: 0,\n\n // Experimental\n _mousePosition: null // Event props\n };\n }\n\n _getAnimationProps(): AnimationProps {\n if (!this.animationProps) {\n throw new Error('animationProps');\n }\n return this.animationProps;\n }\n\n // Update the context object that will be passed to app callbacks\n _updateAnimationProps(): void {\n if (!this.animationProps) {\n return;\n }\n\n const {width, height, aspect} = this._getSizeAndAspect();\n if (width !== this.animationProps.width || height !== this.animationProps.height) {\n this.setNeedsRedraw('drawing buffer resized');\n }\n if (aspect !== this.animationProps.aspect) {\n this.setNeedsRedraw('drawing buffer aspect changed');\n }\n\n this.animationProps.width = width;\n this.animationProps.height = height;\n this.animationProps.aspect = aspect;\n\n this.animationProps.needsRedraw = this.needsRedraw;\n\n // Update time properties\n this.animationProps.engineTime = Date.now() - this.animationProps.startTime;\n\n if (this.timeline) {\n this.timeline.update(this.animationProps.engineTime);\n }\n\n this.animationProps.tick = Math.floor((this.animationProps.time / 1000) * 60);\n this.animationProps.tock++;\n\n // For back compatibility\n this.animationProps.time = this.timeline\n ? this.timeline.getTime()\n : this.animationProps.engineTime;\n }\n\n /** Either uses supplied or existing context, or calls provided callback to create one */\n async _createDevice() {\n const deviceProps = {...this.props, ...this.props.deviceProps};\n this.device = await this.props.onCreateDevice(deviceProps);\n this.canvas = this.device.canvasContext?.canvas!;\n this._createInfoDiv();\n }\n\n _createInfoDiv() {\n if (this.canvas && this.props.onAddHTML) {\n const wrapperDiv = document.createElement('div');\n document.body.appendChild(wrapperDiv);\n wrapperDiv.style.position = 'relative';\n const div = document.createElement('div');\n div.style.position = 'absolute';\n div.style.left = '10px';\n div.style.bottom = '10px';\n div.style.width = '300px';\n div.style.background = 'white';\n if (this.canvas instanceof HTMLCanvasElement) {\n wrapperDiv.appendChild(this.canvas);\n }\n wrapperDiv.appendChild(div);\n const html = this.props.onAddHTML(div);\n if (html) {\n div.innerHTML = html;\n }\n }\n }\n\n _getSizeAndAspect(): {width: number; height: number; aspect: number} {\n if (!this.device) {\n return {width: 1, height: 1, aspect: 1};\n }\n // https://webglfundamentals.org/webgl/lessons/webgl-resizing-the-canvas.html\n const [width, height] = this.device?.canvasContext?.getPixelSize() || [1, 1];\n\n // https://webglfundamentals.org/webgl/lessons/webgl-anti-patterns.html\n let aspect = 1;\n const canvas = this.device?.canvasContext?.canvas;\n\n // @ts-expect-error\n if (canvas && canvas.clientHeight) {\n // @ts-expect-error\n aspect = canvas.clientWidth / canvas.clientHeight;\n } else if (width > 0 && height > 0) {\n aspect = width / height;\n }\n\n return {width, height, aspect};\n }\n\n /** Default viewport setup */\n _resizeViewport() {\n // @ts-expect-error Expose on canvasContext\n if (this.props.autoResizeViewport && this.device.gl) {\n // @ts-expect-error Expose canvasContext\n this.device.gl.viewport(0, 0, this.device.gl.drawingBufferWidth, this.device.gl.drawingBufferHeight);\n }\n }\n\n /**\n * Resize the render buffer of the canvas to match canvas client size\n * Optionally multiplying with devicePixel ratio\n */\n _resizeCanvasDrawingBuffer() {\n if (this.props.autoResizeDrawingBuffer) {\n this.device?.canvasContext?.resize({useDevicePixels: this.props.useDevicePixels});\n }\n }\n\n _beginTimers() {\n this.frameRate.timeEnd();\n this.frameRate.timeStart();\n\n // Check if timer for last frame has completed.\n // GPU timer results are never available in the same\n // frame they are captured.\n // if (\n // this._gpuTimeQuery &&\n // this._gpuTimeQuery.isResultAvailable() &&\n // !this._gpuTimeQuery.isTimerDisjoint()\n // ) {\n // this.stats.get('GPU Time').addTime(this._gpuTimeQuery.getTimerMilliseconds());\n // }\n\n // if (this._gpuTimeQuery) {\n // // GPU time query start\n // this._gpuTimeQuery.beginTimeElapsedQuery();\n // }\n\n // this.cpuTime.timeStart();\n }\n\n _endTimers() {\n this.cpuTime.timeEnd();\n\n // if (this._gpuTimeQuery) {\n // // GPU time query end. Results will be available on next frame.\n // this._gpuTimeQuery.end();\n // }\n }\n\n // Event handling\n\n _startEventHandling() {\n if (this.canvas) {\n this.canvas.addEventListener('mousemove', this._onMousemove);\n this.canvas.addEventListener('mouseleave', this._onMouseleave);\n }\n }\n\n _onMousemove(event: Event) {\n if (event instanceof MouseEvent) {\n this._getAnimationProps()._mousePosition = [event.offsetX, event.offsetY];\n }\n }\n\n _onMouseleave(event: Event) {\n this._getAnimationProps()._mousePosition = null;\n }\n}\n"],"file":"animation-loop.js"}
@@ -0,0 +1,24 @@
1
+ /// <reference types="offscreencanvas" />
2
+ import { Device } from '@luma.gl/api';
3
+ import { Timeline } from '../animation/timeline';
4
+ import type { AnimationLoop } from './animation-loop';
5
+ /** Properties passed to every render frame */
6
+ export declare type AnimationProps = {
7
+ device: Device;
8
+ animationLoop: AnimationLoop;
9
+ /** @todo Should be canvasContext */
10
+ canvas: HTMLCanvasElement | OffscreenCanvas;
11
+ useDevicePixels: number | boolean;
12
+ width: number;
13
+ height: number;
14
+ aspect: number;
15
+ time: number;
16
+ startTime: number;
17
+ engineTime: number;
18
+ tick: number;
19
+ tock: number;
20
+ needsRedraw?: string | false;
21
+ timeline: Timeline | null;
22
+ _mousePosition?: [number, number] | null;
23
+ };
24
+ //# sourceMappingURL=animation-props.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"animation-props.d.ts","sourceRoot":"","sources":["../../src/lib/animation-props.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,cAAc,CAAC;AACpC,OAAO,EAAC,QAAQ,EAAC,MAAM,uBAAuB,CAAA;AAC9C,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,kBAAkB,CAAC;AAEpD,+CAA+C;AAC/C,oBAAY,cAAc,GAAG;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,aAAa,CAAC;IAE7B,oCAAoC;IACpC,MAAM,EAAE,iBAAiB,GAAG,eAAe,CAAC;IAC5C,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IAGf,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IAGb,WAAW,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;IAE7B,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAAC;IAG1B,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI,CAAC;CAC1C,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=animation-props.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[],"file":"animation-props.js"}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=clip-space.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clip-space.d.ts","sourceRoot":"","sources":["../../src/lib/clip-space.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+
2
+ //# sourceMappingURL=clip-space.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[],"file":"clip-space.js"}
@@ -1,4 +1,5 @@
1
- import { Buffer } from '@luma.gl/webgl';
2
- export declare function getBuffersFromGeometry(gl: WebGLRenderingContext, geometry: any, options?: any): Record<string, Buffer | [Buffer, {}]>;
3
- export declare function inferAttributeAccessor(attributeName: any, attribute: any): void;
1
+ import { Device, Buffer } from '@luma.gl/api';
2
+ import type Geometry from '../geometry/geometry';
3
+ export declare function getIndexBufferFromGeometry(device: Device, geometry: Geometry): Buffer | undefined;
4
+ export declare function getAttributeBuffersFromGeometry(device: Device, geometry: Geometry): Record<string, Buffer>;
4
5
  //# sourceMappingURL=model-utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"model-utils.d.ts","sourceRoot":"","sources":["../../src/lib/model-utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,MAAM,EAAS,MAAM,gBAAgB,CAAC;AAY9C,wBAAgB,sBAAsB,CAAC,EAAE,EAAE,qBAAqB,EAAE,QAAQ,KAAA,EAAE,OAAO,CAAC,KAAA,yCA2CnF;AASD,wBAAgB,sBAAsB,CAAC,aAAa,KAAA,EAAE,SAAS,KAAA,QA8B9D"}
1
+ {"version":3,"file":"model-utils.d.ts","sourceRoot":"","sources":["../../src/lib/model-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAE,MAAM,EAAS,MAAM,cAAc,CAAC;AACpD,OAAO,KAAK,QAAQ,MAAM,sBAAsB,CAAC;AAsDjD,wBAAgB,0BAA0B,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,MAAM,GAAG,SAAS,CAYjG;AAED,wBAAgB,+BAA+B,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAc1G"}
@@ -1,5 +1,4 @@
1
- import GL from '@luma.gl/constants';
2
- import { Buffer, assert } from '@luma.gl/webgl';
1
+ import { Buffer, assert } from '@luma.gl/api';
3
2
  const GLTF_TO_LUMA_ATTRIBUTE_MAP = {
4
3
  POSITION: 'positions',
5
4
  NORMAL: 'normals',
@@ -8,84 +7,39 @@ const GLTF_TO_LUMA_ATTRIBUTE_MAP = {
8
7
  TEXCOORD_1: 'texCoords1',
9
8
  TEXCOORD_2: 'texCoords2'
10
9
  };
11
- export function getBuffersFromGeometry(gl, geometry, options) {
10
+ export function getIndexBufferFromGeometry(device, geometry) {
11
+ if (!geometry.indices) {
12
+ return undefined;
13
+ }
14
+
15
+ const data = geometry.indices.value || geometry.indices;
16
+ assert(data instanceof Uint16Array || data instanceof Uint32Array, 'attribute array for "indices" must be of integer type');
17
+ return device.createBuffer({
18
+ usage: Buffer.INDEX,
19
+ data
20
+ });
21
+ }
22
+ export function getAttributeBuffersFromGeometry(device, geometry) {
12
23
  const buffers = {};
13
- let indices = geometry.indices;
14
24
 
15
- for (const name in geometry.attributes) {
16
- const attribute = geometry.attributes[name];
17
- const remappedName = mapAttributeName(name, options);
25
+ for (const [name, attribute] of Object.entries(geometry.attributes)) {
26
+ const remappedName = mapAttributeName(name);
18
27
 
19
- if (name === 'indices') {
20
- indices = attribute;
21
- } else if (attribute.constant) {
22
- buffers[remappedName] = attribute.value;
28
+ if (attribute.constant) {
29
+ throw new Error('constant attributes not supported');
23
30
  } else {
24
31
  const typedArray = attribute.value;
25
- const accessor = { ...attribute
26
- };
27
- delete accessor.value;
28
- buffers[remappedName] = [new Buffer(gl, typedArray), accessor];
29
- inferAttributeAccessor(name, accessor);
32
+ buffers[remappedName] = device.createBuffer({
33
+ data: typedArray,
34
+ id: "".concat(remappedName, "-buffer")
35
+ });
30
36
  }
31
37
  }
32
38
 
33
- if (indices) {
34
- const data = indices.value || indices;
35
- assert(data instanceof Uint16Array || data instanceof Uint32Array, 'attribute array for "indices" must be of integer type');
36
- const accessor = {
37
- size: 1,
38
- isIndexed: indices.isIndexed === undefined ? true : indices.isIndexed
39
- };
40
- buffers.indices = [new Buffer(gl, {
41
- data,
42
- target: GL.ELEMENT_ARRAY_BUFFER
43
- }), accessor];
44
- }
45
-
46
39
  return buffers;
47
40
  }
48
41
 
49
- function mapAttributeName(name, options) {
50
- const {
51
- attributeMap = GLTF_TO_LUMA_ATTRIBUTE_MAP
52
- } = options || {};
53
- return attributeMap && attributeMap[name] || name;
54
- }
55
-
56
- export function inferAttributeAccessor(attributeName, attribute) {
57
- let category;
58
-
59
- switch (attributeName) {
60
- case 'texCoords':
61
- case 'texCoord1':
62
- case 'texCoord2':
63
- case 'texCoord3':
64
- category = 'uvs';
65
- break;
66
-
67
- case 'vertices':
68
- case 'positions':
69
- case 'normals':
70
- case 'pickingColors':
71
- category = 'vectors';
72
- break;
73
-
74
- default:
75
- }
76
-
77
- switch (category) {
78
- case 'vectors':
79
- attribute.size = attribute.size || 3;
80
- break;
81
-
82
- case 'uvs':
83
- attribute.size = attribute.size || 2;
84
- break;
85
-
86
- default:
87
- }
88
-
89
- assert(Number.isFinite(attribute.size), "attribute ".concat(attributeName, " needs size"));
42
+ function mapAttributeName(name) {
43
+ return GLTF_TO_LUMA_ATTRIBUTE_MAP[name] || name;
90
44
  }
91
45
  //# sourceMappingURL=model-utils.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/lib/model-utils.ts"],"names":["GL","Buffer","assert","GLTF_TO_LUMA_ATTRIBUTE_MAP","POSITION","NORMAL","COLOR_0","TEXCOORD_0","TEXCOORD_1","TEXCOORD_2","getBuffersFromGeometry","gl","geometry","options","buffers","indices","name","attributes","attribute","remappedName","mapAttributeName","constant","value","typedArray","accessor","inferAttributeAccessor","data","Uint16Array","Uint32Array","size","isIndexed","undefined","target","ELEMENT_ARRAY_BUFFER","attributeMap","attributeName","category","Number","isFinite"],"mappings":"AAAA,OAAOA,EAAP,MAAe,oBAAf;AACA,SAAQC,MAAR,EAAgBC,MAAhB,QAA6B,gBAA7B;AAGA,MAAMC,0BAA0B,GAAG;AACjCC,EAAAA,QAAQ,EAAE,WADuB;AAEjCC,EAAAA,MAAM,EAAE,SAFyB;AAGjCC,EAAAA,OAAO,EAAE,QAHwB;AAIjCC,EAAAA,UAAU,EAAE,WAJqB;AAKjCC,EAAAA,UAAU,EAAE,YALqB;AAMjCC,EAAAA,UAAU,EAAE;AANqB,CAAnC;AASA,OAAO,SAASC,sBAAT,CAAgCC,EAAhC,EAA2DC,QAA3D,EAAqEC,OAArE,EAA+E;AACpF,QAAMC,OAA8C,GAAG,EAAvD;AACA,MAAIC,OAAO,GAAGH,QAAQ,CAACG,OAAvB;;AAEA,OAAK,MAAMC,IAAX,IAAmBJ,QAAQ,CAACK,UAA5B,EAAwC;AACtC,UAAMC,SAAS,GAAGN,QAAQ,CAACK,UAAT,CAAoBD,IAApB,CAAlB;AACA,UAAMG,YAAY,GAAGC,gBAAgB,CAACJ,IAAD,EAAOH,OAAP,CAArC;;AAEA,QAAIG,IAAI,KAAK,SAAb,EAAwB;AACtBD,MAAAA,OAAO,GAAGG,SAAV;AACD,KAFD,MAEO,I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U,aAAhC,EAA+CjB,SAA/C,EAA0D;AAC/D,MAAIkB,QAAJ;;AACA,UAAQD,aAAR;AACE,SAAK,WAAL;AACA,SAAK,WAAL;AACA,SAAK,WAAL;AACA,SAAK,WAAL;AACEC,MAAAA,QAAQ,GAAG,KAAX;AACA;;AACF,SAAK,UAAL;AACA,SAAK,WAAL;AACA,SAAK,SAAL;AACA,SAAK,eAAL;AACEA,MAAAA,QAAQ,GAAG,SAAX;AACA;;AACF;AAbF;;AAiBA,UAAQA,QAAR;AACE,SAAK,SAAL;AACElB,MAAAA,SAAS,CAACW,IAAV,GAAiBX,SAAS,CAACW,IAAV,IAAkB,CAAnC;AACA;;AACF,SAAK,KAAL;AACEX,MAAAA,SAAS,CAACW,IAAV,GAAiBX,SAAS,CAACW,IAAV,IAAkB,CAAnC;AACA;;AACF;AAPF;;AAUA3B,EAAAA,MAAM,CAACmC,MAAM,CAACC,QAAP,CAAgBpB,SAAS,CAACW,IAA1B,CAAD,sBAA+CM,aAA/C,iBAAN;AACD","sourcesContent":["import GL from '@luma.gl/constants';\nimport {Buffer, assert} from '@luma.gl/webgl';\n\n// Support for mapping new geometries with glTF attribute names to \"classic\" luma.gl shader names\nconst GLTF_TO_LUMA_ATTRIBUTE_MAP = {\n POSITION: 'positions',\n NORMAL: 'normals',\n COLOR_0: 'colors',\n TEXCOORD_0: 'texCoords',\n TEXCOORD_1: 'texCoords1',\n TEXCOORD_2: 'texCoords2'\n};\n\nexport function getBuffersFromGeometry(gl: WebGLRenderingContext, geometry, options?) {\n const buffers: Record<string, Buffer | [Buffer, {}]> = {};\n let indices = geometry.indices;\n\n for (const name in geometry.attributes) {\n const attribute = geometry.attributes[name];\n const remappedName = mapAttributeName(name, options);\n\n if (name === 'indices') {\n indices = attribute;\n } else if (attribute.constant) {\n buffers[remappedName] = attribute.value;\n } else {\n const typedArray = attribute.value;\n // Create accessor by copying the attribute and removing `value``\n const accessor = {...attribute};\n delete accessor.value;\n buffers[remappedName] = [new Buffer(gl, typedArray), accessor];\n\n inferAttributeAccessor(name, accessor);\n }\n }\n\n if (indices) {\n const data = indices.value || indices;\n assert(\n data instanceof Uint16Array || data instanceof Uint32Array,\n 'attribute array for \"indices\" must be of integer type'\n );\n const accessor = {\n size: 1,\n isIndexed: indices.isIndexed === undefined ? true : indices.isIndexed\n };\n buffers.indices = [\n new Buffer(gl, {\n data,\n target: GL.ELEMENT_ARRAY_BUFFER\n }),\n accessor\n ];\n }\n\n return buffers;\n}\n\nfunction mapAttributeName(name, options) {\n const {attributeMap = GLTF_TO_LUMA_ATTRIBUTE_MAP} = options || {};\n return (attributeMap && attributeMap[name]) || name;\n}\n\n// Check for well known attribute names\n// eslint-disable-next-line complexity\nexport function inferAttributeAccessor(attributeName, attribute) {\n let category;\n switch (attributeName) {\n case 'texCoords':\n case 'texCoord1':\n case 'texCoord2':\n case 'texCoord3':\n category = 'uvs';\n break;\n case 'vertices':\n case 'positions':\n case 'normals':\n case 'pickingColors':\n category = 'vectors';\n break;\n default:\n }\n\n // Check for categorys\n switch (category) {\n case 'vectors':\n attribute.size = attribute.size || 3;\n break;\n case 'uvs':\n attribute.size = attribute.size || 2;\n break;\n default:\n }\n\n assert(Number.isFinite(attribute.size), `attribute ${attributeName} needs size`);\n}\n"],"file":"model-utils.js"}
1
+ {"version":3,"sources":["../../src/lib/model-utils.ts"],"names":["Buffer","assert","GLTF_TO_LUMA_ATTRIBUTE_MAP","POSITION","NORMAL","COLOR_0","TEXCOORD_0","TEXCOORD_1","TEXCOORD_2","getIndexBufferFromGeometry","device","geometry","indices","undefined","data","value","Uint16Array","Uint32Array","createBuffer","usage","INDEX","getAttributeBuffersFromGeometry","buffers","name","attribute","Object","entries","attributes","remappedName","mapAttributeName","constant","Error","typedArray","id"],"mappings":"AAAA,SAAgBA,MAAhB,EAAwBC,MAAxB,QAAqC,cAArC;AAIA,MAAMC,0BAA0B,GAAG;AACjCC,EAAAA,QAAQ,EAAE,WADuB;AAEjCC,EAAAA,MAAM,EAAE,S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,IAA1B,EAAgD;AAC9C,SAAOrB,0BAA0B,CAACqB,IAAD,CAA1B,IAAoCA,IAA3C;AACD","sourcesContent":["import {Device, Buffer, assert} from '@luma.gl/api';\nimport type Geometry from '../geometry/geometry';\n\n// Support for mapping new geometries with glTF attribute names to \"classic\" luma.gl shader names\nconst GLTF_TO_LUMA_ATTRIBUTE_MAP = {\n POSITION: 'positions',\n NORMAL: 'normals',\n COLOR_0: 'colors',\n TEXCOORD_0: 'texCoords',\n TEXCOORD_1: 'texCoords1',\n TEXCOORD_2: 'texCoords2'\n};\n\n/*\nexport function getAttributeLayoutsFromGeometry(geometry: Geometry) {\n const layouts: Record<string, {}> = {};\n let indices = geometry.indices;\n\n for (const [name, attribute] of Object.entries(geometry.attributes)) {\n const remappedName = mapAttributeName(name);\n\n if (attribute.constant) {\n throw new Error('constant attributes not supported');\n } else {\n const typedArray = attribute.value;\n // Create accessor by copying the attribute and removing `value``\n const accessor = {...attribute};\n delete accessor.value;\n buffers[remappedName] = [device.createBuffer(typedArray), accessor];\n\n inferAttributeAccessor(name, accessor);\n }\n }\n}\n\nexport class Table {\n length: number;\n // columns: Record<string, TypedArray> = {};\n}\n\nexport class GPUTable {\n length: number;\n columns: Record<string, Buffer> = {};\n}\n\nexport function convertTableToGPUTable(table: Table) {\n // for (const ) {}\n}\n\nexport function renameTableColumns(table: Table, map: (name: string) => string) {\n const newColumns = table.columns.reduce()\n table.clone();\n}\n*/\n\nexport function getIndexBufferFromGeometry(device: Device, geometry: Geometry): Buffer | undefined {\n if (!geometry.indices) {\n return undefined;\n }\n\n // @ts-expect-error\n const data = geometry.indices.value || geometry.indices;\n assert(\n data instanceof Uint16Array || data instanceof Uint32Array,\n 'attribute array for \"indices\" must be of integer type'\n );\n return device.createBuffer({usage: Buffer.INDEX, data});\n}\n\nexport function getAttributeBuffersFromGeometry(device: Device, geometry: Geometry): Record<string, Buffer> {\n const buffers: Record<string, Buffer> = {};\n\n for (const [name, attribute] of Object.entries(geometry.attributes)) {\n const remappedName = mapAttributeName(name);\n if (attribute.constant) {\n throw new Error('constant attributes not supported');\n } else {\n const typedArray = attribute.value;\n buffers[remappedName] = device.createBuffer({data: typedArray, id: `${remappedName}-buffer`});\n }\n }\n\n return buffers;\n}\n\nfunction mapAttributeName(name: string): string {\n return GLTF_TO_LUMA_ATTRIBUTE_MAP[name] || name;\n}\n\n/*\n// Check for well known attribute names\n// eslint-disable-next-line complexity\nexport function inferAttributeAccessor(attributeName, attribute) {\n let category;\n switch (attributeName) {\n case 'texCoords':\n case 'texCoord1':\n case 'texCoord2':\n case 'texCoord3':\n category = 'uvs';\n break;\n case 'vertices':\n case 'positions':\n case 'normals':\n case 'pickingColors':\n category = 'vectors';\n break;\n default:\n }\n\n // Check for categorys\n switch (category) {\n case 'vectors':\n attribute.size = attribute.size || 3;\n break;\n case 'uvs':\n attribute.size = attribute.size || 2;\n break;\n default:\n }\n\n assert(Number.isFinite(attribute.size), `attribute ${attributeName} needs size`);\n}\n*/\n"],"file":"model-utils.js"}
@@ -1,111 +1,41 @@
1
- import { Device } from '@luma.gl/api';
2
- import type { ProgramProps } from '@luma.gl/webgl';
3
- import { Program, VertexArray, TransformFeedback } from '@luma.gl/webgl';
4
- import ProgramManager from './program-manager';
5
- export declare type ModelProps = ProgramProps & {
6
- id?: string;
7
- varyings?: string[];
8
- bufferMode?: any;
9
- program?: Program;
10
- modules?: any[];
11
- defines?: Record<string, number | boolean>;
12
- inject?: Record<string, any>;
13
- transpileToGLSL100?: boolean;
14
- moduleSettings?: object;
15
- attributes?: object;
16
- uniforms?: object;
17
- geometry?: object;
18
- vertexCount?: number;
19
- drawMode?: number;
20
- isInstanced?: boolean;
21
- instanceCount?: number;
22
- programManager?: ProgramManager;
23
- onBeforeRender?: () => void;
24
- onAfterRender?: () => void;
25
- _feedbackBuffers?: object;
26
- isIndexed?: boolean;
27
- indexType?: any;
28
- indexOffset?: number;
29
- vertexArrayInstanced?: boolean;
30
- /** @deprecated Use isInstanced */
31
- instanced?: boolean;
32
- };
33
- export declare type ModelDrawOptions = {
34
- moduleSettings?: any;
35
- framebuffer?: any;
36
- uniforms?: any;
37
- attributes?: any;
38
- transformFeedback?: any;
39
- parameters?: any;
40
- vertexArray?: any;
1
+ import type { Device, Buffer, RenderPipelineProps, RenderPass, Binding, PrimitiveTopology } from '@luma.gl/api';
2
+ import { RenderPipeline } from '@luma.gl/api';
3
+ import type { ShaderModule } from '@luma.gl/shadertools';
4
+ import type Geometry from '../geometry/geometry';
5
+ export declare type ModelProps = Omit<RenderPipelineProps, 'vs' | 'fs'> & {
6
+ vs?: {
7
+ glsl?: string;
8
+ wgsl?: string;
9
+ } | string | null;
10
+ fs?: {
11
+ glsl?: string;
12
+ wgsl?: string;
13
+ } | string | null;
14
+ modules?: ShaderModule[];
15
+ moduleSettings?: Record<string, Record<string, any>>;
16
+ geometry?: Geometry | null;
41
17
  };
18
+ /** v9 API */
42
19
  export default class Model {
43
20
  readonly device: Device;
44
- readonly gl: WebGLRenderingContext;
21
+ readonly pipeline: RenderPipeline;
45
22
  readonly id: string;
46
- readonly animated: boolean;
47
- programManager: ProgramManager;
48
- vertexCount: number;
49
- lastLogTime: number;
50
- props: ModelProps;
51
- userData: Record<string, any>;
52
- needsRedraw: boolean;
53
- attributes: Record<string, any>;
54
- _attributes: Record<string, any>;
55
- uniforms: Record<string, any>;
56
- drawMode: any;
57
- instanceCount: number;
58
- pickable: boolean;
59
- programProps: ProgramProps & {
60
- program?: Program;
61
- modules: any;
62
- inject: any;
63
- defines: any;
64
- varyings: any;
65
- bufferMode: any;
66
- transpileToGLSL100: any;
67
- };
68
- vertexArray: VertexArray;
69
- program: Program;
70
- transformFeedback: TransformFeedback | undefined;
71
- _programDirty: boolean;
72
- _programManagerState: any;
73
- _managedProgram: any;
74
- geometryBuffers: {};
75
- isInstanced: boolean;
76
- geometry: {};
77
- constructor(device: Device, props?: ModelProps);
78
- constructor(gl: WebGLRenderingContext, props?: ModelProps);
79
- initialize(props: ModelProps): void;
80
- setProps(props: any): void;
23
+ readonly vs: string;
24
+ readonly fs: string | null;
25
+ readonly topology: PrimitiveTopology;
26
+ readonly vertexCount: any;
27
+ props: Required<ModelProps>;
28
+ private _getModuleUniforms;
29
+ constructor(device: Device, props: ModelProps);
81
30
  destroy(): void;
82
- /** @deprecated Use .destroy() */
83
- delete(): void;
84
- getDrawMode(): any;
85
- getVertexCount(): number;
86
- getInstanceCount(): number;
87
- getAttributes(): Record<string, any>;
88
- getProgram(): Program;
89
- setProgram(props: any): void;
90
- getUniforms(): Record<string, any>;
91
- setDrawMode(drawMode: any): this;
92
- setVertexCount(vertexCount: any): this;
93
- setInstanceCount(instanceCount: any): this;
94
- setGeometry(geometry: any): this;
95
- setAttributes(attributes?: {}): this;
96
- setUniforms(uniforms?: {}): this;
97
- getModuleUniforms(opts?: any): any;
98
- updateModuleSettings(opts?: any): this;
99
- clear(opts: any): this;
100
- draw(opts?: ModelDrawOptions): boolean;
101
- transform(opts?: ModelDrawOptions): this;
102
- render(uniforms?: {}): boolean;
103
- _setModelProps(props: any): void;
104
- _checkProgram(): void;
105
- _deleteGeometryBuffers(): void;
106
- _setAnimationProps(animationProps: any): void;
107
- _setFeedbackBuffers(feedbackBuffers?: {}): this;
108
- _logDrawCallStart(logLevel: number): number;
109
- _logDrawCallEnd(logLevel: any, vertexArray: any, uniforms: any, framebuffer?: any): void;
31
+ draw(renderPass?: RenderPass): this;
32
+ setProps(props: ModelProps): this;
33
+ updateModuleSettings(props: Record<string, any>): this;
34
+ setIndexBuffer(indices: Buffer): this;
35
+ setAttributes(attributes: Record<string, Buffer>): this;
36
+ /** Set the bindings */
37
+ setBindings(bindings: Record<string, Binding>): this;
38
+ setUniforms(uniforms: Record<string, any>): this;
39
+ _setGeometry(geometry: Geometry): void;
110
40
  }
111
41
  //# sourceMappingURL=model.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../src/lib/model.ts"],"names":[],"mappings":"AACA,OAAO,EAA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