@luma.gl/engine 9.0.0-alpha.33 → 9.0.0-alpha.35

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 (39) hide show
  1. package/dist/animation/key-frames.js +6 -7
  2. package/dist/animation/key-frames.js.map +1 -1
  3. package/dist/animation/timeline.js +5 -6
  4. package/dist/animation/timeline.js.map +1 -1
  5. package/dist/animation-loop/animation-loop.js +18 -19
  6. package/dist/animation-loop/animation-loop.js.map +1 -1
  7. package/dist/dist.dev.js +93 -96
  8. package/dist/geometries/ico-sphere-geometry.js +1 -1
  9. package/dist/geometries/ico-sphere-geometry.js.map +1 -1
  10. package/dist/geometries/plane-geometry.js +4 -4
  11. package/dist/geometries/plane-geometry.js.map +1 -1
  12. package/dist/geometry/geometry.js +8 -9
  13. package/dist/geometry/geometry.js.map +1 -1
  14. package/dist/geometry/gpu-geometry.d.ts +4 -15
  15. package/dist/geometry/gpu-geometry.d.ts.map +1 -1
  16. package/dist/geometry/gpu-geometry.js +27 -62
  17. package/dist/geometry/gpu-geometry.js.map +1 -1
  18. package/dist/index.cjs +28 -44
  19. package/dist/lib/clip-space.js +16 -3
  20. package/dist/lib/clip-space.js.map +1 -1
  21. package/dist/lib/pipeline-factory.d.ts.map +1 -1
  22. package/dist/lib/pipeline-factory.js +15 -11
  23. package/dist/lib/pipeline-factory.js.map +1 -1
  24. package/dist/model/model.d.ts.map +1 -1
  25. package/dist/model/model.js +27 -34
  26. package/dist/model/model.js.map +1 -1
  27. package/dist/scenegraph/group-node.js +1 -2
  28. package/dist/scenegraph/group-node.js.map +1 -1
  29. package/dist/scenegraph/model-node.js +3 -4
  30. package/dist/scenegraph/model-node.js.map +1 -1
  31. package/dist/scenegraph/scenegraph-node.js +9 -10
  32. package/dist/scenegraph/scenegraph-node.js.map +1 -1
  33. package/dist/transform/transform.js +4 -5
  34. package/dist/transform/transform.js.map +1 -1
  35. package/dist.min.js +83 -75
  36. package/package.json +6 -6
  37. package/src/geometry/gpu-geometry.ts +18 -52
  38. package/src/lib/pipeline-factory.ts +13 -10
  39. package/src/model/model.ts +3 -12
@@ -1,12 +1,11 @@
1
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
1
  export class KeyFrames {
3
2
  constructor(keyFrames) {
4
- _defineProperty(this, "startIndex", -1);
5
- _defineProperty(this, "endIndex", -1);
6
- _defineProperty(this, "factor", 0);
7
- _defineProperty(this, "times", []);
8
- _defineProperty(this, "values", []);
9
- _defineProperty(this, "_lastTime", -1);
3
+ this.startIndex = -1;
4
+ this.endIndex = -1;
5
+ this.factor = 0;
6
+ this.times = [];
7
+ this.values = [];
8
+ this._lastTime = -1;
10
9
  this.setKeyFrames(keyFrames);
11
10
  this.setTime(0);
12
11
  }
@@ -1 +1 @@
1
- {"version":3,"file":"key-frames.js","names":["KeyFrames","constructor","keyFrames","_defineProperty","setKeyFrames","setTime","numKeys","length","times","values","i","_calculateKeys","_lastTime","time","Math","max","getStartTime","startIndex","getEndTime","endIndex","getStartData","getEndData","index","startTime","endTime","factor","min"],"sources":["../../src/animation/key-frames.ts"],"sourcesContent":["// keyframes\nexport type KeyFrame<T> = [number, T];\n\n/** Holds a list of key frames (timestamped values) */\nexport class KeyFrames<T = number> {\n startIndex: number = -1;\n endIndex: number = -1;\n factor: number = 0;\n times: number[] = [];\n values: T[] = [];\n private _lastTime = -1;\n\n constructor(keyFrames: KeyFrame<T>[]) {\n this.setKeyFrames(keyFrames);\n this.setTime(0);\n }\n\n setKeyFrames(keyFrames: KeyFrame<T>[]): void {\n const numKeys = keyFrames.length;\n this.times.length = numKeys;\n this.values.length = numKeys;\n\n for (let i = 0; i < numKeys; ++i) {\n this.times[i] = keyFrames[i][0];\n this.values[i] = keyFrames[i][1];\n }\n\n this._calculateKeys(this._lastTime);\n }\n\n setTime(time: number): void {\n time = Math.max(0, time);\n\n if (time !== this._lastTime) {\n this._calculateKeys(time);\n this._lastTime = time;\n }\n }\n\n getStartTime(): number {\n return this.times[this.startIndex];\n }\n\n getEndTime(): number {\n return this.times[this.endIndex];\n }\n\n getStartData(): T {\n return this.values[this.startIndex];\n }\n\n getEndData(): T {\n return this.values[this.endIndex];\n }\n\n _calculateKeys(time: number): void {\n let index = 0;\n const numKeys = this.times.length;\n\n for (index = 0; index < numKeys - 2; ++index) {\n if (this.times[index + 1] > time) {\n break;\n }\n }\n\n this.startIndex = index;\n this.endIndex = index + 1;\n\n const startTime = this.times[this.startIndex];\n const endTime = this.times[this.endIndex];\n this.factor = Math.min(Math.max(0, (time - startTime) / (endTime - startTime)), 1);\n }\n}\n"],"mappings":";AAIA,OAAO,MAAMA,SAAS,CAAa;EAQjCC,WAAWA,CAACC,SAAwB,EAAE;IAAAC,eAAA,qBAPjB,CAAC,CAAC;IAAAA,eAAA,mBACJ,CAAC,CAAC;IAAAA,eAAA,iBACJ,CAAC;IAAAA,eAAA,gBACA,EAAE;IAAAA,eAAA,iBACN,EAAE;IAAAA,eAAA,oBACI,CAAC,CAAC;IAGpB,IAAI,CAACC,YAAY,CAACF,SAAS,CAAC;IAC5B,IAAI,CAACG,OAAO,CAAC,CAAC,CAAC;EACjB;EAEAD,YAAYA,CAACF,SAAwB,EAAQ;IAC3C,MAAMI,OAAO,GAAGJ,SAAS,CAACK,MAAM;IAChC,IAAI,CAACC,KAAK,CAACD,MAAM,GAAGD,OAAO;IAC3B,IAAI,CAACG,MAAM,CAACF,MAAM,GAAGD,OAAO;IAE5B,KAAK,IAAII,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGJ,OAAO,EAAE,EAAEI,CAAC,EAAE;MAChC,IAAI,CAACF,KAAK,CAACE,CAAC,CAAC,GAAGR,SAAS,CAACQ,CAAC,CAAC,CAAC,CAAC,CAAC;MAC/B,IAAI,CAACD,MAAM,CAACC,CAAC,CAAC,GAAGR,SAAS,CAACQ,CAAC,CAAC,CAAC,CAAC,CAAC;IAClC;IAEA,IAAI,CAACC,cAAc,CAAC,IAAI,CAACC,SAAS,CAAC;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AACZ,IAAI,CAACC,GAAG,CAAC,CAAC,EAAE,CAACF,IAAI,GAAGU,SAAS,KAAKC,OAAO,GAAGD,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC;EACpF;AACF"}
1
+ {"version":3,"file":"key-frames.js","names":["KeyFrames","constructor","keyFrames","startIndex","endIndex","factor","times","values","_lastTime","setKeyFrames","setTime","numKeys","length","i","_calculateKeys","time","Math","max","getStartTime","getEndTime","getStartData","getEndData","index","startTime","endTime","min"],"sources":["../../src/animation/key-frames.ts"],"sourcesContent":["// keyframes\nexport type KeyFrame<T> = [number, T];\n\n/** Holds a list of key frames (timestamped values) */\nexport class KeyFrames<T = number> {\n startIndex: number = -1;\n endIndex: number = -1;\n factor: number = 0;\n times: number[] = [];\n values: T[] = [];\n private _lastTime = -1;\n\n constructor(keyFrames: KeyFrame<T>[]) {\n this.setKeyFrames(keyFrames);\n this.setTime(0);\n }\n\n setKeyFrames(keyFrames: KeyFrame<T>[]): void {\n const numKeys = keyFrames.length;\n this.times.length = numKeys;\n this.values.length = numKeys;\n\n for (let i = 0; i < numKeys; ++i) {\n this.times[i] = keyFrames[i][0];\n this.values[i] = keyFrames[i][1];\n }\n\n this._calculateKeys(this._lastTime);\n }\n\n setTime(time: number): void {\n time = Math.max(0, time);\n\n if (time !== this._lastTime) {\n this._calculateKeys(time);\n this._lastTime = time;\n }\n }\n\n getStartTime(): number {\n return this.times[this.startIndex];\n }\n\n getEndTime(): number {\n return this.times[this.endIndex];\n }\n\n getStartData(): T {\n return this.values[this.startIndex];\n }\n\n getEndData(): T {\n return this.values[this.endIndex];\n }\n\n _calculateKeys(time: number): void {\n let index = 0;\n const numKeys = this.times.length;\n\n for (index = 0; index < numKeys - 2; ++index) {\n if (this.times[index + 1] > time) {\n break;\n }\n }\n\n this.startIndex = index;\n this.endIndex = index + 1;\n\n const startTime = this.times[this.startIndex];\n const endTime = this.times[this.endIndex];\n this.factor = Math.min(Math.max(0, (time - startTime) / (endTime - startTime)), 1);\n }\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CAAC;EACpC;EAEAgB,UAAUA,CAAA,EAAW;IACnB,OAAO,IAAI,CAACb,KAAK,CAAC,IAAI,CAACF,QAAQ,CAAC;EAClC;EAEAgB,YAAYA,CAAA,EAAM;IAChB,OAAO,IAAI,CAACb,MAAM,CAAC,IAAI,CAACJ,UAAU,CAAC;EACrC;EAEAkB,UAAUA,CAAA,EAAM;IACd,OAAO,IAAI,CAACd,MAAM,CAAC,IAAI,CAACH,QAAQ,CAAC;EACnC;EAEAU,cAAcA,CAACC,IAAY,EAAQ;IACjC,IAAIO,KAAK,GAAG,CAAC;IACb,MAAMX,OAAO,GAAG,IAAI,CAACL,KAAK,CAACM,MAAM;IAEjC,KAAKU,KAAK,GAAG,CAAC,EAAEA,KAAK,GAAGX,OAAO,GAAG,CAAC,EAAE,EAAEW,KAAK,EAAE;MAC5C,IAAI,IAAI,CAAChB,KAAK,CAACgB,KAAK,GAAG,CAAC,CAAC,GAAGP,IAAI,EAAE;QAChC;MACF;IACF;IAEA,IAAI,CAACZ,UAAU,GAAGmB,KAAK;IACvB,IAAI,CAAClB,QAAQ,GAAGkB,KAAK,GAAG,CAAC;IAEzB,MAAMC,SAAS,GAAG,IAAI,CAACjB,KAAK,CAAC,IAAI,CAACH,UAAU,CAAC;IAC7C,MAAMqB,OAAO,GAAG,IAAI,CAAClB,KAAK,CAAC,IAAI,CAACF,QAAQ,CAAC;IACzC,IAAI,CAACC,MAAM,GAAGW,IAAI,CAACS,GAAG,CAACT,IAAI,CAACC,GAAG,CAAC,CAAC,EAAE,CAACF,IAAI,GAAGQ,SAAS,KAAKC,OAAO,GAAGD,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC;EACpF;AACF"}
@@ -1,13 +1,12 @@
1
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
1
  let channelHandles = 1;
3
2
  let animationHandles = 1;
4
3
  export class Timeline {
5
4
  constructor() {
6
- _defineProperty(this, "time", 0);
7
- _defineProperty(this, "channels", new Map());
8
- _defineProperty(this, "animations", new Map());
9
- _defineProperty(this, "playing", false);
10
- _defineProperty(this, "lastEngineTime", -1);
5
+ this.time = 0;
6
+ this.channels = new Map();
7
+ this.animations = new Map();
8
+ this.playing = false;
9
+ this.lastEngineTime = -1;
11
10
  }
12
11
  addChannel(props) {
13
12
  const {
@@ -1 +1 @@
1
- {"version":3,"file":"timeline.js","names":["channelHandles","animationHandles","Timeline","constructor","_defineProperty","Map","addChannel","props","delay","duration","Number","POSITIVE_INFINITY","rate","repeat","handle","channel","time","_setChannelTime","channels","set","removeChannel","delete","animationHandle","animation","animations","detachAnimation","isFinished","get","undefined","getTime","setTime","Math","max","values","animationData","play","playing","pause","lastEngineTime","reset","attachAnimation","channelHandle","update","engineTime","offsetTime","totalDuration"],"sources":["../../src/animation/timeline.ts"],"sourcesContent":["// luma.gl, MIT license\n\n/**\n * Timeline channel properties\n * @param delay = 0;\n * @param duration = Number.POSITIVE_INFINITY;\n * @param rate = 1\n * @param repeat = 1\n */\nexport type ChannelOptions = {\n delay?: number\n duration?: number\n rate?: number\n repeat?: number\n}\n\nexport type AnimationOptions = {\n setTime: (time: number) => void\n}\n\n type Channel = {\n time: number\n delay: number\n duration: number\n rate: number\n repeat: number\n}\n\ntype Animation = {\n channel?: number;\n animation: {\n setTime: (time: number) => void\n }\n}\n\nlet channelHandles = 1;\nlet animationHandles = 1;\n\nexport class Timeline {\n time: number = 0;\n channels = new Map<number, Channel>();\n animations = new Map<number, Animation>();\n playing: boolean = false;\n lastEngineTime: number = -1;\n\n constructor() {\n }\n\n addChannel(props: ChannelOptions): number {\n const {delay = 0, duration = Number.POSITIVE_INFINITY, rate = 1, repeat = 1} = props;\n\n const handle = channelHandles++;\n const channel: Channel = {\n time: 0,\n delay,\n duration,\n rate,\n repeat\n };\n this._setChannelTime(channel, this.time);\n this.channels.set(handle, channel);\n\n return handle;\n }\n\n removeChannel(handle: number): void {\n this.channels.delete(handle);\n\n for (const [animationHandle, animation] of this.animations) {\n if (animation.channel === handle) {\n this.detachAnimation(animationHandle);\n }\n }\n }\n\n isFinished(handle: number): boolean {\n const channel = this.channels.get(handle);\n if (channel === undefined) {\n return false;\n }\n\n return this.time >= channel.delay + channel.duration * channel.repeat;\n }\n\n getTime(handle?: number): number {\n if (handle === undefined) {\n return this.time;\n }\n\n const channel = this.channels.get(handle);\n\n if (channel === undefined) {\n return -1;\n }\n\n return channel.time;\n }\n\n setTime(time: number): void {\n this.time = Math.max(0, time);\n\n const channels = this.channels.values();\n for (const channel of channels) {\n this._setChannelTime(channel, this.time);\n }\n\n const animations = this.animations.values();\n for (const animationData of animations) {\n const {animation, channel} = animationData;\n animation.setTime(this.getTime(channel));\n }\n }\n\n play(): void {\n this.playing = true;\n }\n\n pause(): void {\n this.playing = false;\n this.lastEngineTime = -1;\n }\n\n reset(): void {\n this.setTime(0);\n }\n\n attachAnimation(animation: AnimationOptions, channelHandle?: number): number {\n const animationHandle = animationHandles++;\n\n this.animations.set(animationHandle, {\n animation,\n channel: channelHandle\n });\n\n animation.setTime(this.getTime(channelHandle));\n\n return animationHandle;\n }\n\n detachAnimation(handle: number): void {\n this.animations.delete(handle);\n }\n\n update(engineTime: number): void {\n if (this.playing) {\n if (this.lastEngineTime === -1) {\n this.lastEngineTime = engineTime;\n }\n this.setTime(this.time + (engineTime - this.lastEngineTime));\n this.lastEngineTime = engineTime;\n }\n }\n\n _setChannelTime(channel: Channel, time: number): void {\n const offsetTime = time - channel.delay;\n const totalDuration = channel.duration * channel.repeat;\n // Note(Tarek): Don't loop on final repeat.\n if (offsetTime >= totalDuration) {\n channel.time = channel.duration * channel.rate;\n } else {\n channel.time = Math.max(0, offsetTime) % channel.duration;\n channel.time *= channel.rate;\n }\n }\n}\n"],"mappings":";AAmCA,IAAIA,cAAc,GAAG,CAAC;AACtB,IAAIC,gBAAgB,GAAG,CAAC;AAExB,OAAO,MAAMC,QAAQ,CAAC;EAOpBC,WAAWA,CAAA,EAAG;IAAAC,eAAA,eANC,CAAC;IAAAA,eAAA,mBACL,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ACTR,OAAO,EAAE0B;IACX,CAAC,CAAC;IAEFlB,SAAS,CAACO,OAAO,CAAC,IAAI,CAACD,OAAO,CAACY,aAAa,CAAC,CAAC;IAE9C,OAAOnB,eAAe;EACxB;EAEAG,eAAeA,CAACX,MAAc,EAAQ;IACpC,IAAI,CAACU,UAAU,CAACH,MAAM,CAACP,MAAM,CAAC;EAChC;EAEA4B,MAAMA,CAACC,UAAkB,EAAQ;IAC/B,IAAI,IAAI,CAACP,OAAO,EAAE;MAChB,IAAI,IAAI,CAACE,cAAc,KAAK,CAAC,CAAC,EAAE;QAC9B,IAAI,CAACA,cAAc,GAAGK,UAAU;MAClC;MACA,IAAI,CAACb,OAAO,CAAC,IAAI,CAACd,IAAI,IAAI2B,UAAU,GAAG,IAAI,CAACL,cAAc,CAAC,CAAC;MAC5D,IAAI,CAACA,cAAc,GAAGK,UAAU;IAClC;EACF;EAEA1B,eAAeA,CAACF,OAAgB,EAAEC,IAAY,EAAQ;IACpD,MAAM4B,UAAU,GAAG5B,IAAI,GAAGD,OAAO,CAACP,KAAK;IACvC,MAAMqC,aAAa,GAAG9B,OAAO,CAACN,QAAQ,GAAGM,OAAO,CAACF,MAAM;IAEvD,IAAI+B,UAAU,IAAIC,aAAa,EAAE;MAC/B9B,OAAO,CAACC,IAAI,GAAGD,OAAO,CAACN,QAAQ,GAAGM,OAAO,CAACH,IAAI;IAChD,CAAC,MAAM;MACLG,OAAO,CAACC,IAAI,GAAGe,IAAI,CAACC,GAAG,CAAC,CAAC,EAAEY,UAAU,CAAC,GAAG7B,OAAO,CAACN,QAAQ;MACzDM,OAAO,CAACC,IAAI,IAAID,OAAO,CAACH,IAAI;IAC9B;EACF;AACF"}
1
+ {"version":3,"file":"timeline.js","names":["channelHandles","animationHandles","Timeline","constructor","time","channels","Map","animations","playing","lastEngineTime","addChannel","props","delay","duration","Number","POSITIVE_INFINITY","rate","repeat","handle","channel","_setChannelTime","set","removeChannel","delete","animationHandle","animation","detachAnimation","isFinished","get","undefined","getTime","setTime","Math","max","values","animationData","play","pause","reset","attachAnimation","channelHandle","update","engineTime","offsetTime","totalDuration"],"sources":["../../src/animation/timeline.ts"],"sourcesContent":["// luma.gl, MIT license\n\n/**\n * Timeline channel properties\n * @param delay = 0;\n * @param duration = Number.POSITIVE_INFINITY;\n * @param rate = 1\n * @param repeat = 1\n */\nexport type ChannelOptions = {\n delay?: number\n duration?: number\n rate?: number\n repeat?: number\n}\n\nexport type AnimationOptions = {\n setTime: (time: number) => void\n}\n\n type Channel = {\n time: number\n delay: number\n duration: number\n rate: number\n repeat: number\n}\n\ntype Animation = {\n channel?: number;\n animation: {\n setTime: (time: number) => void\n }\n}\n\nlet channelHandles = 1;\nlet animationHandles = 1;\n\nexport class Timeline {\n time: number = 0;\n channels = new Map<number, Channel>();\n animations = new Map<number, Animation>();\n playing: boolean = false;\n lastEngineTime: number = -1;\n\n constructor() {\n }\n\n addChannel(props: ChannelOptions): number {\n const {delay = 0, duration = Number.POSITIVE_INFINITY, rate = 1, repeat = 1} = props;\n\n const handle = channelHandles++;\n const channel: Channel = {\n time: 0,\n delay,\n duration,\n rate,\n repeat\n };\n this._setChannelTime(channel, this.time);\n this.channels.set(handle, channel);\n\n return handle;\n }\n\n removeChannel(handle: number): void {\n this.channels.delete(handle);\n\n for (const [animationHandle, animation] of this.animations) {\n if (animation.channel === handle) {\n this.detachAnimation(animationHandle);\n }\n }\n }\n\n isFinished(handle: number): boolean {\n const channel = this.channels.get(handle);\n if (channel === undefined) {\n return false;\n }\n\n return this.time >= channel.delay + channel.duration * channel.repeat;\n }\n\n getTime(handle?: number): number {\n if (handle === undefined) {\n return this.time;\n }\n\n const channel = this.channels.get(handle);\n\n if (channel === undefined) {\n return -1;\n }\n\n return channel.time;\n }\n\n setTime(time: number): void {\n this.time = Math.max(0, time);\n\n const channels = this.channels.values();\n for (const channel of channels) {\n this._setChannelTime(channel, this.time);\n }\n\n const animations = this.animations.values();\n for (const animationData of animations) {\n const {animation, channel} = animationData;\n animation.setTime(this.getTime(channel));\n }\n }\n\n play(): void {\n this.playing = true;\n }\n\n pause(): void {\n this.playing = false;\n this.lastEngineTime = -1;\n }\n\n reset(): void {\n this.setTime(0);\n }\n\n attachAnimation(animation: AnimationOptions, channelHandle?: number): number {\n const animationHandle = animationHandles++;\n\n this.animations.set(animationHandle, {\n animation,\n channel: channelHandle\n });\n\n animation.setTime(this.getTime(channelHandle));\n\n return animationHandle;\n }\n\n detachAnimation(handle: number): void {\n this.animations.delete(handle);\n }\n\n update(engineTime: number): void {\n if (this.playing) {\n if (this.lastEngineTime === -1) {\n this.lastEngineTime = engineTime;\n }\n this.setTime(this.time + (engineTime - this.lastEngineTime));\n this.lastEngineTime = engineTime;\n }\n }\n\n _setChannelTime(channel: Channel, time: number): void {\n const offsetTime = time - channel.delay;\n const totalDuration = channel.duration * channel.repeat;\n // Note(Tarek): Don't loop on final repeat.\n if (offsetTime >= totalDuration) {\n channel.time = channel.duration * channel.rate;\n } else {\n channel.time = Math.max(0, offsetTime) % channel.duration;\n channel.time *= channel.rate;\n }\n }\n}\n"],"mappings":"AAmCA,IAAIA,cAAc,GAAG,CAAC;AACtB,IAAIC,gBAAgB,GAAG,CAAC;AAExB,OAAO,MAAMC,QAAQ,CAAC;EAOpBC,WAAWA,CAAA,EAAG;IAAA,KANdC,IAAI,GAAW,CAAC;IAAA,KAChBC,QAAQ,GAAG,IAAIC,GAAG,CAAkB,CAAC;IAAA,KACrCC,UAAU,GAAG,IAAID,GAAG,CAAoB,CAAC;IAAA,KACzCE,OAAO,GAAY,KAAK;IAAA,KACxBC,cAAc,GAAW,CAAC,CAAC;EAG3B;EAEAC,UAAUA,CAACC,KAAqB,EAAU;IACxC,MAAM;MAACC,KAAK,GAAG,CAAC;MAAEC,QAAQ,GAAGC,MAAM,CAACC,iBAAiB;MAAEC,IAAI,GAAG,CAAC;MAAEC,MAAM,GAAG;IAAC,CAAC,GAAGN,KAAK;IAEpF,MAAMO,MAAM,GAAGlB,cAAc,EAAE;I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Ac,KAAK,CAAC,CAAC,EAAE;QAC9B,IAAI,CAACA,cAAc,GAAGiC,UAAU;MAClC;MACA,IAAI,CAACX,OAAO,CAAC,IAAI,CAAC3B,IAAI,IAAIsC,UAAU,GAAG,IAAI,CAACjC,cAAc,CAAC,CAAC;MAC5D,IAAI,CAACA,cAAc,GAAGiC,UAAU;IAClC;EACF;EAEAtB,eAAeA,CAACD,OAAgB,EAAEf,IAAY,EAAQ;IACpD,MAAMuC,UAAU,GAAGvC,IAAI,GAAGe,OAAO,CAACP,KAAK;IACvC,MAAMgC,aAAa,GAAGzB,OAAO,CAACN,QAAQ,GAAGM,OAAO,CAACF,MAAM;IAEvD,IAAI0B,UAAU,IAAIC,aAAa,EAAE;MAC/BzB,OAAO,CAACf,IAAI,GAAGe,OAAO,CAACN,QAAQ,GAAGM,OAAO,CAACH,IAAI;IAChD,CAAC,MAAM;MACLG,OAAO,CAACf,IAAI,GAAG4B,IAAI,CAACC,GAAG,CAAC,CAAC,EAAEU,UAAU,CAAC,GAAGxB,OAAO,CAACN,QAAQ;MACzDM,OAAO,CAACf,IAAI,IAAIe,OAAO,CAACH,IAAI;IAC9B;EACF;AACF"}
@@ -1,4 +1,3 @@
1
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
1
  import { luma } from '@luma.gl/core';
3
2
  import { requestAnimationFrame, cancelAnimationFrame } from '@luma.gl/core';
4
3
  import { Stats } from '@probe.gl/stats';
@@ -12,30 +11,30 @@ const DEFAULT_ANIMATION_LOOP_PROPS = {
12
11
  onRender: () => {},
13
12
  onFinalize: () => {},
14
13
  onError: error => console.error(error),
15
- stats: luma.stats.get("animation-loop-".concat(statIdCounter++)),
14
+ stats: luma.stats.get(`animation-loop-${statIdCounter++}`),
16
15
  useDevicePixels: true,
17
16
  autoResizeViewport: false,
18
17
  autoResizeDrawingBuffer: false
19
18
  };
20
19
  export class AnimationLoop {
21
20
  constructor(props) {
22
- _defineProperty(this, "device", null);
23
- _defineProperty(this, "canvas", null);
24
- _defineProperty(this, "props", void 0);
25
- _defineProperty(this, "animationProps", null);
26
- _defineProperty(this, "timeline", null);
27
- _defineProperty(this, "stats", void 0);
28
- _defineProperty(this, "cpuTime", void 0);
29
- _defineProperty(this, "gpuTime", void 0);
30
- _defineProperty(this, "frameRate", void 0);
31
- _defineProperty(this, "display", void 0);
32
- _defineProperty(this, "needsRedraw", 'initialized');
33
- _defineProperty(this, "_initialized", false);
34
- _defineProperty(this, "_running", false);
35
- _defineProperty(this, "_animationFrameId", null);
36
- _defineProperty(this, "_nextFramePromise", null);
37
- _defineProperty(this, "_resolveNextFrame", null);
38
- _defineProperty(this, "_cpuStartTime", 0);
21
+ this.device = null;
22
+ this.canvas = null;
23
+ this.props = void 0;
24
+ this.animationProps = null;
25
+ this.timeline = null;
26
+ this.stats = void 0;
27
+ this.cpuTime = void 0;
28
+ this.gpuTime = void 0;
29
+ this.frameRate = void 0;
30
+ this.display = void 0;
31
+ this.needsRedraw = 'initialized';
32
+ this._initialized = false;
33
+ this._running = false;
34
+ this._animationFrameId = null;
35
+ this._nextFramePromise = null;
36
+ this._resolveNextFrame = null;
37
+ this._cpuStartTime = 0;
39
38
  this.props = {
40
39
  ...DEFAULT_ANIMATION_LOOP_PROPS,
41
40
  ...props
@@ -1 +1 @@
1
- {"version":3,"file":"animation-loop.js","names":["luma","requestAnimationFrame","cancelAnimationFrame","Stats","statIdCounter","DEFAULT_ANIMATION_LOOP_PROPS","device","onAddHTML","onInitialize","onRender","onFinalize","onError","error","console","stats","get","concat","useDevicePixels","autoResizeViewport","autoResizeDrawingBuffer","AnimationLoop","constructor","props","_defineProperty","Error","id","cpuTime","gpuTime","frameRate","setProps","start","bind","stop","_onMousemove","_onMouseleave","destroy","_setDisplay","delete","setNeedsRedraw","reason","needsRedraw","_running","appContext","_initialized","_initDevice","_initialize","_getAnimationProps","_cancelAnimationFrame","_requestAnimationFrame","err","redraw","_this$device","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","_this$device2","canvasContext","renderPass","getDefaultRenderPass","width","height","aspect","time","startTime","Date","now","engineTime","tick","tock","_mousePosition","_getSizeAndAspect","update","Math","floor","getTime","_this$device$canvasCo","_createInfoDiv","wrapperDiv","document","createElement","body","appendChild","style","position","div","left","bottom","background","html","innerHTML","_this$device3","_this$device4","getPixelSize","clientHeight","clientWidth","gl","viewport","drawingBufferWidth","drawingBufferHeight","_this$device5","resize","timeEnd","timeStart","addEventListener","event","MouseEvent","offsetX","offsetY"],"sources":["../../src/animation-loop/animation-loop.ts"],"sourcesContent":["// luma.gl, MIT license\n\nimport {luma, Device} from '@luma.gl/core';\nimport {requestAnimationFrame, cancelAnimationFrame} from '@luma.gl/core';\nimport {Timeline} from '../animation/timeline';\nimport {AnimationProps} from './animation-props';\nimport {Stats, Stat} from '@probe.gl/stats';\n\nlet statIdCounter = 0;\n\n/** AnimationLoop properties */\nexport type AnimationLoopProps = {\n device: Device | Promise<Device>;\n\n onAddHTML?: (div: HTMLDivElement) => string; // innerHTML\n onInitialize?: (animationProps: AnimationProps) => Promise<unknown>;\n onRender?: (animationProps: AnimationProps) => unknown;\n onFinalize?: (animationProps: AnimationProps) => void;\n onError?: (reason: Error) => void;\n\n stats?: Stats;\n\n // view parameters - TODO move to CanvasContext?\n autoResizeViewport?: boolean;\n autoResizeDrawingBuffer?: boolean;\n useDevicePixels?: number | boolean;\n};\n\nexport type MutableAnimationLoopProps = {\n // view parameters\n autoResizeViewport?: boolean;\n autoResizeDrawingBuffer?: boolean;\n useDevicePixels?: number | boolean;\n}\n\n\nconst DEFAULT_ANIMATION_LOOP_PROPS: Required<AnimationLoopProps> = {\n device: null!,\n\n onAddHTML: () => '',\n onInitialize: async () => { return null; },\n onRender: () => {},\n onFinalize: () => {},\n onError: (error) => console.error(error), // eslint-disable-line no-console\n\n stats: luma.stats.get(`animation-loop-${statIdCounter++}`),\n\n // view parameters\n useDevicePixels: true,\n autoResizeViewport: false,\n autoResizeDrawingBuffer: false,\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: 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 if (!props.device) {\n throw new Error('No device provided');\n }\n\n const {useDevicePixels = true} = this.props;\n\n // state\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: MutableAnimationLoopProps): 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._initDevice();\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: any) {\n if (this.display) {\n this.display.destroy();\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(animationProps: AnimationProps) {\n // Allow e.g. VR display to render multiple frames.\n if (this.display) {\n this.display._renderFrame(animationProps);\n return;\n }\n\n // call callback\n this.props.onRender(this._getAnimationProps());\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\n device: this.device,\n canvas: this.device?.canvasContext?.canvas,\n renderPass: this.device.getDefaultRenderPass(),\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 this.animationProps.renderPass = this.device.getDefaultRenderPass();\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 /** Wait for supplied device */\n async _initDevice() {\n this.device = await this.props.device;\n if (!this.device) {\n throw new Error('No device provided');\n }\n this.canvas = this.device.canvasContext?.canvas || null;\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.bind(this));\n this.canvas.addEventListener('mouseleave', this._onMouseleave.bind(this));\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"],"mappings":";AAEA,SAAQA,IAAI,QAAe,eAAe;AAC1C,SAAQC,qBAAqB,EAAEC,oBAAoB,QAAO,eAAe;AAGzE,SAAQC,KAAK,QAAa,iBAAiB;AAE3C,IAAIC,aAAa,GAAG,CAAC;AA4BrB,MAAMC,4BAA0D,GAAG;EACjEC,MAAM,EAAE,IAAK;EAEbC,SAAS,EAAEA,CAAA,KAAM,EAAE;EACnBC,YAAY,EAAE,MAAAA,CAAA,KAAY;IAAE,OAA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AgB,CAAC,WAAW,EAAE,IAAI,CAAC9F,YAAY,CAACF,IAAI,CAAC,IAAI,CAAC,CAAC;MACvE,IAAI,CAACsC,MAAM,CAAC0D,gBAAgB,CAAC,YAAY,EAAE,IAAI,CAAC7F,aAAa,CAACH,IAAI,CAAC,IAAI,CAAC,CAAC;IAC3E;EACF;EAEAE,YAAYA,CAAC+F,KAAY,EAAE;IACzB,IAAIA,KAAK,YAAYC,UAAU,EAAE;MAC/B,IAAI,CAACnF,kBAAkB,CAAC,CAAC,CAAC+C,cAAc,GAAG,CAACmC,KAAK,CAACE,OAAO,EAAEF,KAAK,CAACG,OAAO,CAAC;IAC3E;EACF;EAEAjG,aAAaA,CAAC8F,KAAY,EAAE;IAC1B,IAAI,CAAClF,kBAAkB,CAAC,CAAC,CAAC+C,cAAc,GAAG,IAAI;EACjD;AACF"}
1
+ {"version":3,"file":"animation-loop.js","names":["luma","requestAnimationFrame","cancelAnimationFrame","Stats","statIdCounter","DEFAULT_ANIMATION_LOOP_PROPS","device","onAddHTML","onInitialize","onRender","onFinalize","onError","error","console","stats","get","useDevicePixels","autoResizeViewport","autoResizeDrawingBuffer","AnimationLoop","constructor","props","canvas","animationProps","timeline","cpuTime","gpuTime","frameRate","display","needsRedraw","_initialized","_running","_animationFrameId","_nextFramePromise","_resolveNextFrame","_cpuStartTime","Error","id","setProps","start","bind","stop","_onMousemove","_onMouseleave","destroy","_setDisplay","delete","setNeedsRedraw","reason","appContext","_initDevice","_initialize","_getAnimationProps","_cancelAnimationFrame","_requestAnimationFrame","err","redraw","_this$device","isLost","_beginTimers","_setupFrame","_updateAnimationProps","_renderFrame","_clearNeedsRedraw","_endTimers","attachTimeline","detachTimeline","waitForRender","Promise","resolve","toDataURL","HTMLCanvasElement","_startEventHandling","_initializeAnimationProps","_resizeCanvasDrawingBuffer","_resizeViewport","animationLoop","_animationFrame","_this$device2","canvasContext","renderPass","getDefaultRenderPass","width","height","aspect","time","startTime","Date","now","engineTime","tick","tock","_mousePosition","_getSizeAndAspect","update","Math","floor","getTime","_this$device$canvasCo","_createInfoDiv","wrapperDiv","document","createElement","body","appendChild","style","position","div","left","bottom","background","html","innerHTML","_this$device3","_this$device4","getPixelSize","clientHeight","clientWidth","gl","viewport","drawingBufferWidth","drawingBufferHeight","_this$device5","resize","timeEnd","timeStart","addEventListener","event","MouseEvent","offsetX","offsetY"],"sources":["../../src/animation-loop/animation-loop.ts"],"sourcesContent":["// luma.gl, MIT license\n\nimport {luma, Device} from '@luma.gl/core';\nimport {requestAnimationFrame, cancelAnimationFrame} from '@luma.gl/core';\nimport {Timeline} from '../animation/timeline';\nimport {AnimationProps} from './animation-props';\nimport {Stats, Stat} from '@probe.gl/stats';\n\nlet statIdCounter = 0;\n\n/** AnimationLoop properties */\nexport type AnimationLoopProps = {\n device: Device | Promise<Device>;\n\n onAddHTML?: (div: HTMLDivElement) => string; // innerHTML\n onInitialize?: (animationProps: AnimationProps) => Promise<unknown>;\n onRender?: (animationProps: AnimationProps) => unknown;\n onFinalize?: (animationProps: AnimationProps) => void;\n onError?: (reason: Error) => void;\n\n stats?: Stats;\n\n // view parameters - TODO move to CanvasContext?\n autoResizeViewport?: boolean;\n autoResizeDrawingBuffer?: boolean;\n useDevicePixels?: number | boolean;\n};\n\nexport type MutableAnimationLoopProps = {\n // view parameters\n autoResizeViewport?: boolean;\n autoResizeDrawingBuffer?: boolean;\n useDevicePixels?: number | boolean;\n}\n\n\nconst DEFAULT_ANIMATION_LOOP_PROPS: Required<AnimationLoopProps> = {\n device: null!,\n\n onAddHTML: () => '',\n onInitialize: async () => { return null; },\n onRender: () => {},\n onFinalize: () => {},\n onError: (error) => console.error(error), // eslint-disable-line no-console\n\n stats: luma.stats.get(`animation-loop-${statIdCounter++}`),\n\n // view parameters\n useDevicePixels: true,\n autoResizeViewport: false,\n autoResizeDrawingBuffer: false,\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: 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 if (!props.device) {\n throw new Error('No device provided');\n }\n\n const {useDevicePixels = true} = this.props;\n\n // state\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: MutableAnimationLoopProps): 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._initDevice();\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: any) {\n if (this.display) {\n this.display.destroy();\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(animationProps: AnimationProps) {\n // Allow e.g. VR display to render multiple frames.\n if (this.display) {\n this.display._renderFrame(animationProps);\n return;\n }\n\n // call callback\n this.props.onRender(this._getAnimationProps());\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\n device: this.device,\n canvas: this.device?.canvasContext?.canvas,\n renderPass: this.device.getDefaultRenderPass(),\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 this.animationProps.renderPass = this.device.getDefaultRenderPass();\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 /** Wait for supplied device */\n async _initDevice() {\n this.device = await this.props.device;\n if (!this.device) {\n throw new Error('No device provided');\n }\n this.canvas = this.device.canvasContext?.canvas || null;\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.bind(this));\n this.canvas.addEventListener('mouseleave', this._onMouseleave.bind(this));\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"],"mappings":"AAEA,SAAQA,IAAI,QAAe,eAAe;AAC1C,SAAQC,qBAAqB,EAAEC,oBAAoB,QAAO,eAAe;AAGzE,SAAQC,KAAK,QAAa,iBAAiB;AAE3C,IAAIC,aAAa,GAAG,CAAC;AA4BrB,MAAMC,4BAA0D,GAAG;EACjEC,MAAM,EAAE,IAAK;EAEbC,SAAS,EAAEA,CAAA,KAAM,EAAE;EACnBC,YAAY,EAAE,MAAAA,CAAA,KAAY;IAAE,OAAO,IAAI;EAAE,CAAC;EAC1CC,QAAQ,EAAEA,CAAA,KAAM,CAAC,CAAC;EAClBC,UAAU,EAAEA,CAAA,KAAM,CAAC,CAAC;EACpBC,OAAO,EAAGC,KAAK,IAAKC,OAAO,CAACD,KAAK,CAACA,KAAK,CAAC;EAExCE,KAAK,EAAEd,IAAI,CAACc,KAAK,CAACC,GAAG,CAAE,kBAAiBX,aAAa,EAAG,EAAC,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C,YAAY,EAAE,IAAI,CAACnF,aAAa,CAACH,IAAI,CAAC,IAAI,CAAC,CAAC;IAC3E;EACF;EAEAE,YAAYA,CAACqF,KAAY,EAAE;IACzB,IAAIA,KAAK,YAAYC,UAAU,EAAE;MAC/B,IAAI,CAAC5E,kBAAkB,CAAC,CAAC,CAACwC,cAAc,GAAG,CAACmC,KAAK,CAACE,OAAO,EAAEF,KAAK,CAACG,OAAO,CAAC;IAC3E;EACF;EAEAvF,aAAaA,CAACoF,KAAY,EAAE;IAC1B,IAAI,CAAC3E,kBAAkB,CAAC,CAAC,CAACwC,cAAc,GAAG,IAAI;EACjD;AACF"}
package/dist/dist.dev.js CHANGED
@@ -1369,7 +1369,7 @@ var __exports__ = (() => {
1369
1369
  // Resource creation helpers
1370
1370
  _getBufferProps(props) {
1371
1371
  if (props instanceof ArrayBuffer || ArrayBuffer.isView(props)) {
1372
- return {
1372
+ props = {
1373
1373
  data: props
1374
1374
  };
1375
1375
  }
@@ -1381,6 +1381,8 @@ var __exports__ = (() => {
1381
1381
  newProps.indexType = "uint32";
1382
1382
  } else if (props.data instanceof Uint16Array) {
1383
1383
  newProps.indexType = "uint16";
1384
+ } else {
1385
+ log.warn("indices buffer content must be of integer type")();
1384
1386
  }
1385
1387
  }
1386
1388
  return newProps;
@@ -2456,8 +2458,8 @@ var __exports__ = (() => {
2456
2458
  const vertexFormat = bufferMapping?.vertexFormat || attributeTypeInfo.defaultVertexFormat;
2457
2459
  const vertexFormatInfo = decodeVertexFormat(vertexFormat);
2458
2460
  return {
2459
- name: name2,
2460
- bufferName: bufferMapping?.name || name2,
2461
+ attributeName: bufferMapping?.attributeName || shaderDeclaration.name,
2462
+ bufferName: bufferMapping?.bufferName || shaderDeclaration.name,
2461
2463
  location: shaderDeclaration.location,
2462
2464
  shaderType: shaderDeclaration.type,
2463
2465
  shaderDataType: attributeTypeInfo.dataType,
@@ -2481,38 +2483,63 @@ var __exports__ = (() => {
2481
2483
  }
2482
2484
  return attribute || null;
2483
2485
  }
2484
- function getAttributeFromBufferLayout(bufferLayout, name2) {
2485
- for (const bufferMapping of bufferLayout) {
2486
- if (bufferMapping.name === name2) {
2486
+ function getAttributeFromBufferLayout(bufferLayouts, name2) {
2487
+ checkBufferLayouts(bufferLayouts);
2488
+ let bufferLayoutInfo = getAttributeFromShortHand(bufferLayouts, name2);
2489
+ if (bufferLayoutInfo) {
2490
+ return bufferLayoutInfo;
2491
+ }
2492
+ bufferLayoutInfo = getAttributeFromAttributesList(bufferLayouts, name2);
2493
+ if (bufferLayoutInfo) {
2494
+ return bufferLayoutInfo;
2495
+ }
2496
+ log.warn(`layout for attribute "${name2}" not present in buffer layout`);
2497
+ return null;
2498
+ }
2499
+ function checkBufferLayouts(bufferLayouts) {
2500
+ for (const bufferLayout of bufferLayouts) {
2501
+ if (bufferLayout.attributes && bufferLayout.format || !bufferLayout.attributes && !bufferLayout.format) {
2502
+ log.warn(`BufferLayout ${name} must have either 'attributes' or 'format' field`);
2503
+ }
2504
+ }
2505
+ }
2506
+ function getAttributeFromShortHand(bufferLayouts, name2) {
2507
+ for (const bufferLayout of bufferLayouts) {
2508
+ if (bufferLayout.format && bufferLayout.name === name2) {
2487
2509
  return {
2488
- name: bufferMapping.name,
2510
+ attributeName: bufferLayout.name,
2489
2511
  bufferName: name2,
2490
- vertexFormat: bufferMapping.format,
2491
- byteOffset: bufferMapping.byteOffset || 0,
2492
- byteStride: bufferMapping.byteStride || 0
2512
+ stepMode: bufferLayout.stepMode,
2513
+ vertexFormat: bufferLayout.format,
2514
+ // If offset is needed, use `attributes` field.
2515
+ byteOffset: 0,
2516
+ byteStride: bufferLayout.byteStride || 0
2493
2517
  };
2494
2518
  }
2495
- let nextByteOffset = bufferMapping.byteOffset || 0;
2496
- let byteStride = 0;
2497
- for (const interleavedMapping of bufferMapping.attributes || []) {
2498
- const info = decodeVertexFormat(interleavedMapping.format);
2499
- byteStride += info.byteLength;
2500
- }
2501
- for (const interleavedMapping of bufferMapping.attributes || []) {
2502
- const byteOffset = nextByteOffset;
2503
- nextByteOffset += interleavedMapping?.byteStrideOffset || decodeVertexFormat(interleavedMapping.format).byteLength;
2504
- if (interleavedMapping.name === name2) {
2505
- return {
2506
- name: bufferMapping.name,
2507
- bufferName: name2,
2508
- vertexFormat: interleavedMapping.format,
2509
- byteOffset,
2510
- byteStride: bufferMapping.byteStride || byteStride
2511
- };
2519
+ }
2520
+ return null;
2521
+ }
2522
+ function getAttributeFromAttributesList(bufferLayouts, name2) {
2523
+ for (const bufferLayout of bufferLayouts) {
2524
+ let byteStride = bufferLayout.byteStride;
2525
+ if (typeof bufferLayout.byteStride !== "number") {
2526
+ for (const attributeMapping2 of bufferLayout.attributes || []) {
2527
+ const info = decodeVertexFormat(attributeMapping2.format);
2528
+ byteStride += info.byteLength;
2512
2529
  }
2513
2530
  }
2531
+ const attributeMapping = bufferLayout.attributes?.find((mapping) => mapping.attribute === name2);
2532
+ if (attributeMapping) {
2533
+ return {
2534
+ attributeName: attributeMapping.attribute,
2535
+ bufferName: bufferLayout.name,
2536
+ stepMode: bufferLayout.stepMode,
2537
+ vertexFormat: attributeMapping.format,
2538
+ byteOffset: attributeMapping.byteOffset,
2539
+ byteStride
2540
+ };
2541
+ }
2514
2542
  }
2515
- log.warn(`layout for attribute "${name2}" not present in buffer layout`);
2516
2543
  return null;
2517
2544
  }
2518
2545
  function mergeShaderLayout(baseLayout, overrideLayout) {
@@ -3416,6 +3443,10 @@ ${moduleSource}// END MODULE_${this.name}
3416
3443
  #define DEFAULT_GPU
3417
3444
  // Prevent driver from optimizing away the calculation necessary for emulated fp64
3418
3445
  #define LUMA_FP64_CODE_ELIMINATION_WORKAROUND 1
3446
+ // Headless Chrome's software shader 'tan' function doesn't have acceptable precision
3447
+ #define LUMA_FP32_TAN_PRECISION_WORKAROUND 1
3448
+ // If the GPU doesn't have full 32 bits precision, will causes overflow
3449
+ #define LUMA_FP64_HIGH_BITS_OVERFLOW_WORKAROUND 1
3419
3450
  `;
3420
3451
  }
3421
3452
  }
@@ -5991,30 +6022,6 @@ void main() {
5991
6022
  this.attributes = props.attributes;
5992
6023
  this.vertexCount = props.vertexCount;
5993
6024
  this.bufferLayout = props.bufferLayout || [];
5994
- if (!this.bufferLayout.find((layout) => layout.name === "positions")) {
5995
- this.bufferLayout.push({
5996
- name: "positions",
5997
- format: "float32x3"
5998
- });
5999
- }
6000
- if (this.attributes.normals && !this.bufferLayout.find((layout) => layout.name === "normals")) {
6001
- this.bufferLayout.push({
6002
- name: "normals",
6003
- format: "float32x3"
6004
- });
6005
- }
6006
- if (this.attributes.texCoords && !this.bufferLayout.find((layout) => layout.name === "texCoords")) {
6007
- this.bufferLayout.push({
6008
- name: "texCoords",
6009
- format: "float32x2"
6010
- });
6011
- }
6012
- if (this.attributes.colors && !this.bufferLayout.find((layout) => layout.name === "colors")) {
6013
- this.bufferLayout.push({
6014
- name: "colors",
6015
- format: "float32x3"
6016
- });
6017
- }
6018
6025
  if (this.indices) {
6019
6026
  assert2(this.indices.usage === Buffer2.INDEX);
6020
6027
  }
@@ -6062,44 +6069,34 @@ void main() {
6062
6069
  return void 0;
6063
6070
  }
6064
6071
  const data = geometry.indices.value;
6065
- assert2(data instanceof Uint16Array || data instanceof Uint32Array, 'attribute array for "indices" must be of integer type');
6066
6072
  return device.createBuffer({
6067
6073
  usage: Buffer2.INDEX,
6068
6074
  data
6069
6075
  });
6070
6076
  }
6071
6077
  function getAttributeBuffersFromGeometry(device, geometry) {
6072
- const positions = geometry.attributes.positions || geometry.attributes.POSITION;
6073
- const normals = geometry.attributes.normals || geometry.attributes.NORMAL;
6074
- const texCoords = geometry.attributes.texCoords || geometry.attributes.TEXCOORD_0;
6075
- const attributes = {
6076
- positions: device.createBuffer({
6077
- data: positions.value,
6078
- id: "positions-buffer"
6079
- })
6080
- };
6081
- const bufferLayout = [{
6082
- name: "positions",
6083
- format: `float32x${positions.size}`
6084
- }];
6085
- if (normals) {
6086
- attributes.normals = device.createBuffer({
6087
- data: normals.value,
6088
- id: "normals-buffer"
6089
- });
6090
- bufferLayout.push({
6091
- name: "normals",
6092
- format: `float32x${normals.size}`
6093
- });
6094
- }
6095
- if (texCoords) {
6096
- attributes.texCoords = device.createBuffer({
6097
- data: texCoords.value,
6098
- id: "texCoords-buffer"
6078
+ const bufferLayout = [];
6079
+ const attributes = {};
6080
+ for (const [attributeName, attribute] of Object.entries(geometry.attributes)) {
6081
+ let name2 = attributeName;
6082
+ switch (attributeName) {
6083
+ case "POSITION":
6084
+ name2 = "positions";
6085
+ break;
6086
+ case "NORMAL":
6087
+ name2 = "normals";
6088
+ break;
6089
+ case "TEXCOORD_0":
6090
+ name2 = "texCoords";
6091
+ break;
6092
+ }
6093
+ attributes[name2] = device.createBuffer({
6094
+ data: attribute.value,
6095
+ id: `${attributeName}-buffer`
6099
6096
  });
6100
6097
  bufferLayout.push({
6101
- name: "texCoords",
6102
- format: `float32x${texCoords.size}`
6098
+ name: name2,
6099
+ format: `float32x${attribute.size}`
6103
6100
  });
6104
6101
  }
6105
6102
  const vertexCount = geometry._calculateVertexCount(geometry.attributes, geometry.indices);
@@ -6181,10 +6178,15 @@ void main() {
6181
6178
  _hashRenderPipeline(props) {
6182
6179
  const vsHash = this._getHash(props.vs);
6183
6180
  const fsHash = props.fs ? this._getHash(props.fs) : 0;
6184
- const parameterHash = this._getHash(JSON.stringify(props.parameters));
6185
- const bufferLayoutHash = this._getHash(JSON.stringify(props.bufferLayout));
6186
6181
  const varyingHash = "-";
6187
- return `${vsHash}/${fsHash}V${varyingHash}T${props.topology}P${parameterHash}BL${bufferLayoutHash}}`;
6182
+ switch (this.device.info.type) {
6183
+ case "webgpu":
6184
+ const parameterHash = this._getHash(JSON.stringify(props.parameters));
6185
+ const bufferLayoutHash = this._getHash(JSON.stringify(props.bufferLayout));
6186
+ return `${vsHash}/${fsHash}V${varyingHash}T${props.topology}P${parameterHash}BL${bufferLayoutHash}}`;
6187
+ default:
6188
+ return `${vsHash}/${fsHash}V${varyingHash}`;
6189
+ }
6188
6190
  }
6189
6191
  _getHash(key) {
6190
6192
  if (this._hashes[key] === void 0) {
@@ -6318,9 +6320,7 @@ void main() {
6318
6320
  setTopology(topology) {
6319
6321
  if (topology !== this.topology) {
6320
6322
  this.topology = topology;
6321
- if (this.device.info.type === "webgpu") {
6322
- this._setPipelineNeedsUpdate("topology");
6323
- }
6323
+ this._setPipelineNeedsUpdate("topology");
6324
6324
  }
6325
6325
  }
6326
6326
  /**
@@ -6330,9 +6330,7 @@ void main() {
6330
6330
  setBufferLayout(bufferLayout) {
6331
6331
  if (bufferLayout !== this.bufferLayout) {
6332
6332
  this.bufferLayout = bufferLayout;
6333
- if (this.device.info.type === "webgpu") {
6334
- this._setPipelineNeedsUpdate("bufferLayout");
6335
- }
6333
+ this._setPipelineNeedsUpdate("bufferLayout");
6336
6334
  }
6337
6335
  }
6338
6336
  /**
@@ -6343,9 +6341,7 @@ void main() {
6343
6341
  setParameters(parameters) {
6344
6342
  if (!deepEqual(parameters, this.parameters, 2)) {
6345
6343
  this.parameters = parameters;
6346
- if (this.device.info.type === "webgpu") {
6347
- this._setPipelineNeedsUpdate("parameters");
6348
- }
6344
+ this._setPipelineNeedsUpdate("parameters");
6349
6345
  }
6350
6346
  }
6351
6347
  // Update dynamic fields
@@ -13112,8 +13108,8 @@ ${formattedLog}`)();
13112
13108
  }
13113
13109
  const webglBuffer = cast(buffer);
13114
13110
  const glType = getGLFromVertexType(attributeInfo.bufferDataType);
13115
- log.log(1, {
13116
- setAttribute: attributeInfo.name,
13111
+ log.log(2, {
13112
+ setAttribute: attributeInfo.attributeName,
13117
13113
  toBuffer: bufferName,
13118
13114
  size: attributeInfo.bufferComponents,
13119
13115
  type: glType,
@@ -13311,6 +13307,7 @@ ${formattedLog}`)();
13311
13307
  continue;
13312
13308
  }
13313
13309
  this.vertexArrayObject.setConstant(attributeInfo.location, value);
13310
+ this.vertexArrayObject.enable(attributeInfo.location, false);
13314
13311
  }
13315
13312
  }
13316
13313
  /** Apply any bindings (before each draw call) */
@@ -42,7 +42,7 @@ function tesselateIcosaHedron(props) {
42
42
  i2 *= 3;
43
43
  const mini = i1 < i2 ? i1 : i2;
44
44
  const maxi = i1 > i2 ? i1 : i2;
45
- const key = "".concat(mini, "|").concat(maxi);
45
+ const key = `${mini}|${maxi}`;
46
46
  if (key in pointMemo) {
47
47
  return pointMemo[key];
48
48
  }