@needle-tools/engine 4.6.1 → 4.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/generateMeshBVH.worker-BaNp_Xtp.js +25 -0
  3. package/dist/{gltf-progressive-Bm9eEfgu.min.js → gltf-progressive-Bl4okF1b.min.js} +1 -1
  4. package/dist/{gltf-progressive-GjIqwSG3.js → gltf-progressive-DSpdn0QT.js} +2 -2
  5. package/dist/{gltf-progressive-Dn6o99rH.umd.cjs → gltf-progressive-P8b8a0qY.umd.cjs} +1 -1
  6. package/dist/needle-engine.bundle-D0XWaCQs.min.js +1575 -0
  7. package/dist/{needle-engine.bundle-BVg46UWZ.js → needle-engine.bundle-DGcStTA7.js} +9715 -9555
  8. package/dist/needle-engine.bundle-DmYMLdWP.umd.cjs +1575 -0
  9. package/dist/needle-engine.js +352 -351
  10. package/dist/needle-engine.min.js +1 -1
  11. package/dist/needle-engine.umd.cjs +1 -1
  12. package/dist/{postprocessing-CRQa6Qxn.umd.cjs → postprocessing-CjW23fio.umd.cjs} +18 -18
  13. package/dist/{postprocessing-D6W1EyZ-.js → postprocessing-DYLNOL3W.js} +4 -3
  14. package/dist/{postprocessing-DF8AlRgW.min.js → postprocessing-xYQWCHFu.min.js} +26 -26
  15. package/dist/{three-DMrv-4ar.umd.cjs → three-B_hneGZr.umd.cjs} +4 -4
  16. package/dist/{three-Bz6X1mrw.js → three-DrqIzZTH.js} +4198 -4198
  17. package/dist/{three-Boa-jOq-.min.js → three-DuDKwKB8.min.js} +33 -33
  18. package/dist/{three-examples-GggCDHv0.js → three-examples-B50TT3Iu.js} +5 -5
  19. package/dist/{three-examples-DuVhxqft.min.js → three-examples-DaDLBuy6.min.js} +14 -14
  20. package/dist/{three-examples-C7ryg8vN.umd.cjs → three-examples-X3OadjXB.umd.cjs} +3 -3
  21. package/dist/{three-mesh-ui-CY6Izc7C.min.js → three-mesh-ui-B3p3gyUz.min.js} +1 -1
  22. package/dist/{three-mesh-ui-CwlN0FUC.umd.cjs → three-mesh-ui-CQiIQIlA.umd.cjs} +1 -1
  23. package/dist/{three-mesh-ui-CLNOfsWn.js → three-mesh-ui-CxuWt7m-.js} +1 -1
  24. package/dist/{vendor-zxXa3Dmr.min.js → vendor-BlSxe9JJ.min.js} +3 -3
  25. package/dist/{vendor-BSD1RQIh.js → vendor-BmYIgaS1.js} +3 -3
  26. package/dist/{vendor-DHr4aqIZ.umd.cjs → vendor-Cavtu3CP.umd.cjs} +3 -3
  27. package/lib/engine/engine_context.d.ts +4 -1
  28. package/lib/engine/engine_context.js +9 -2
  29. package/lib/engine/engine_context.js.map +1 -1
  30. package/lib/engine/engine_three_utils.d.ts +17 -14
  31. package/lib/engine/engine_three_utils.js +106 -53
  32. package/lib/engine/engine_three_utils.js.map +1 -1
  33. package/lib/engine/engine_tonemapping.d.ts +4 -0
  34. package/lib/engine/engine_tonemapping.js +21 -18
  35. package/lib/engine/engine_tonemapping.js.map +1 -1
  36. package/lib/engine/engine_utils.js.map +1 -1
  37. package/lib/engine/engine_utils_screenshot.d.ts +1 -1
  38. package/lib/engine/engine_utils_screenshot.js +11 -2
  39. package/lib/engine/engine_utils_screenshot.js.map +1 -1
  40. package/lib/engine/webcomponents/needle-engine.d.ts +4 -1
  41. package/lib/engine/webcomponents/needle-engine.extras.js +3 -3
  42. package/lib/engine/webcomponents/needle-engine.extras.js.map +1 -1
  43. package/lib/engine/webcomponents/needle-engine.js +11 -21
  44. package/lib/engine/webcomponents/needle-engine.js.map +1 -1
  45. package/lib/engine-components/CameraUtils.js.map +1 -1
  46. package/lib/engine-components/postprocessing/Effects/Antialiasing.js +3 -1
  47. package/lib/engine-components/postprocessing/Effects/Antialiasing.js.map +1 -1
  48. package/lib/engine-components/postprocessing/Effects/BloomEffect.d.ts +2 -2
  49. package/lib/engine-components/postprocessing/Effects/BloomEffect.js +5 -2
  50. package/lib/engine-components/postprocessing/Effects/BloomEffect.js.map +1 -1
  51. package/lib/engine-components/postprocessing/Effects/ColorAdjustments.d.ts +8 -0
  52. package/lib/engine-components/postprocessing/Effects/ColorAdjustments.js +27 -8
  53. package/lib/engine-components/postprocessing/Effects/ColorAdjustments.js.map +1 -1
  54. package/lib/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusionN8.js +1 -0
  55. package/lib/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusionN8.js.map +1 -1
  56. package/lib/engine-components/postprocessing/Effects/Sharpening.d.ts +1 -0
  57. package/lib/engine-components/postprocessing/Effects/Sharpening.js +4 -0
  58. package/lib/engine-components/postprocessing/Effects/Sharpening.js.map +1 -1
  59. package/lib/engine-components/postprocessing/Effects/Tonemapping.d.ts +2 -9
  60. package/lib/engine-components/postprocessing/Effects/Tonemapping.js +23 -71
  61. package/lib/engine-components/postprocessing/Effects/Tonemapping.js.map +1 -1
  62. package/lib/engine-components/postprocessing/Effects/Tonemapping.utils.d.ts +13 -0
  63. package/lib/engine-components/postprocessing/Effects/Tonemapping.utils.js +52 -0
  64. package/lib/engine-components/postprocessing/Effects/Tonemapping.utils.js.map +1 -0
  65. package/lib/engine-components/postprocessing/PostProcessingEffect.d.ts +18 -0
  66. package/lib/engine-components/postprocessing/PostProcessingEffect.js +22 -3
  67. package/lib/engine-components/postprocessing/PostProcessingEffect.js.map +1 -1
  68. package/lib/engine-components/postprocessing/PostProcessingHandler.d.ts +20 -4
  69. package/lib/engine-components/postprocessing/PostProcessingHandler.js +209 -112
  70. package/lib/engine-components/postprocessing/PostProcessingHandler.js.map +1 -1
  71. package/lib/engine-components/postprocessing/Volume.d.ts +2 -1
  72. package/lib/engine-components/postprocessing/Volume.js +51 -33
  73. package/lib/engine-components/postprocessing/Volume.js.map +1 -1
  74. package/lib/engine-components/postprocessing/index.d.ts +1 -0
  75. package/lib/engine-components/postprocessing/index.js +1 -0
  76. package/lib/engine-components/postprocessing/index.js.map +1 -1
  77. package/lib/engine-components/postprocessing/utils.d.ts +43 -0
  78. package/lib/engine-components/postprocessing/utils.js +82 -0
  79. package/lib/engine-components/postprocessing/utils.js.map +1 -1
  80. package/package.json +1 -1
  81. package/src/engine/engine_context.ts +13 -4
  82. package/src/engine/engine_three_utils.ts +134 -58
  83. package/src/engine/engine_tonemapping.ts +23 -24
  84. package/src/engine/engine_utils.ts +2 -2
  85. package/src/engine/engine_utils_screenshot.ts +13 -3
  86. package/src/engine/webcomponents/needle-engine.extras.ts +3 -3
  87. package/src/engine/webcomponents/needle-engine.ts +14 -25
  88. package/src/engine-components/CameraUtils.ts +3 -3
  89. package/src/engine-components/postprocessing/Effects/Antialiasing.ts +3 -1
  90. package/src/engine-components/postprocessing/Effects/BloomEffect.ts +6 -4
  91. package/src/engine-components/postprocessing/Effects/ColorAdjustments.ts +24 -13
  92. package/src/engine-components/postprocessing/Effects/ScreenspaceAmbientOcclusionN8.ts +1 -0
  93. package/src/engine-components/postprocessing/Effects/Sharpening.ts +5 -0
  94. package/src/engine-components/postprocessing/Effects/Tonemapping.ts +26 -80
  95. package/src/engine-components/postprocessing/Effects/Tonemapping.utils.ts +60 -0
  96. package/src/engine-components/postprocessing/PostProcessingEffect.ts +23 -3
  97. package/src/engine-components/postprocessing/PostProcessingHandler.ts +239 -119
  98. package/src/engine-components/postprocessing/Volume.ts +54 -38
  99. package/src/engine-components/postprocessing/index.ts +2 -1
  100. package/src/engine-components/postprocessing/utils.ts +102 -2
  101. package/dist/generateMeshBVH.worker-Cdfpaq5W.js +0 -25
  102. package/dist/needle-engine.bundle-AOXFIsYk.umd.cjs +0 -1563
  103. package/dist/needle-engine.bundle-Dt52m2jf.min.js +0 -1563
@@ -1,5 +1,6 @@
1
1
  export * from "./PostProcessingEffect.js";
2
2
  export * from "./PostProcessingHandler.js"
3
+ export { PostProcessingEffectOrder } from "./utils.js";
3
4
  export { PostProcessingManager } from "./Volume.js"
4
5
  export * from "./VolumeParameter.js"
5
- export * from "./VolumeProfile.js";
6
+ export * from "./VolumeProfile.js";
@@ -1,9 +1,11 @@
1
+ import type { Effect, Pass } from "postprocessing";
1
2
  import { Object3D } from "three";
2
3
 
3
4
  import { isDevEnvironment } from "../../engine/debug/index.js";
4
5
  import { addComponent } from "../../engine/engine_components.js";
5
6
  import { foreachComponentEnumerator } from "../../engine/engine_gameobject.js";
6
- import { ConstructorConcrete, IComponent } from "../../engine/engine_types.js";
7
+ import { MODULES } from "../../engine/engine_modules.js";
8
+ import { Constructor, ConstructorConcrete, IComponent } from "../../engine/engine_types.js";
7
9
  import { getParam } from "../../engine/engine_utils.js";
8
10
  import { type PostProcessingEffect } from "./PostProcessingEffect.js";
9
11
 
@@ -11,6 +13,8 @@ export const debug = getParam("debugpost");
11
13
 
12
14
  export type IPostProcessingManager = IComponent & {
13
15
  get isPostProcessingManager(): boolean;
16
+ get dirty(): boolean;
17
+ set dirty(value: boolean);
14
18
  addEffect(effect: PostProcessingEffect): void;
15
19
  removeEffect(effect: PostProcessingEffect): void;
16
20
  }
@@ -50,4 +54,100 @@ export function getPostProcessingManager(effect: PostProcessingEffect): IPostPro
50
54
  }
51
55
  }
52
56
  return manager;
53
- }
57
+ }
58
+
59
+
60
+
61
+ export type PostprocessingEffectData = {
62
+ effect: Effect | Pass;
63
+ priority?: number,
64
+ }
65
+
66
+ /**
67
+ * Default order for post-processing effects. This can be used to sort effects by their rendering order when creating custom effects.
68
+ * E.g. in your custom effect, you can set `order: PostProcessingEffectOrder.Bloom + 1;` to ensure it gets rendered after the bloom effect.
69
+ * OR `order: PostProcessingEffectOrder.Bloom - 1;` to ensure it gets rendered before the bloom effect.
70
+ * @example
71
+ * ```typescript
72
+ * import { PostProcessingEffectOrder } from "@needle-tools/engine"
73
+ *
74
+ * export class MyCustomEffect extends PostProcessingEffect {
75
+ * order: PostProcessingEffectPriority.Bloom + 1; // render after bloom
76
+ *
77
+ * // ... your effect code
78
+ * }
79
+ * ```
80
+ */
81
+ export const PostProcessingEffectOrder = {
82
+ /** Used to render effects at the start of the post-processing chain */
83
+ AT_START: -10_000,
84
+
85
+ NormalPass: 0,
86
+ DepthDownsamplingPass: 10,
87
+ SSAO: 20,
88
+ SMAA: 30,
89
+ TiltShift: 40,
90
+ DepthOfField: 50,
91
+ ChromaticAberration: 60,
92
+ Bloom: 70,
93
+ Vignette: 80,
94
+ Pixelation: 90,
95
+ ToneMapping: 100,
96
+ HueSaturation: 110,
97
+ BrightnessContrast: 120,
98
+ Sharpening: 130,
99
+
100
+ /** Used to render effects at the end of the post-processing chain, e.g. for final adjustments or overlays. */
101
+ AT_END: 10_000,
102
+ }
103
+ // let effectsOrder: Array<Constructor<Effect | Pass>> | null = null;
104
+
105
+ let builtinOrder: Map<Constructor<Effect | Pass>, number> | null = null;
106
+
107
+ export function orderEffects(effects: Array<PostprocessingEffectData>) {
108
+ if (debug === "verbose") console.debug("Before ordering effects", [...effects]);
109
+
110
+ if (!builtinOrder) {
111
+ builtinOrder = new Map<Constructor<Effect | Pass>, number>();
112
+ builtinOrder.set(MODULES.POSTPROCESSING.MODULE.NormalPass, PostProcessingEffectOrder.NormalPass);
113
+ builtinOrder.set(MODULES.POSTPROCESSING.MODULE.DepthDownsamplingPass, PostProcessingEffectOrder.DepthDownsamplingPass);
114
+ builtinOrder.set(MODULES.POSTPROCESSING.MODULE.SMAAEffect, PostProcessingEffectOrder.SMAA);
115
+ builtinOrder.set(MODULES.POSTPROCESSING.MODULE.SSAOEffect, PostProcessingEffectOrder.SSAO);
116
+ builtinOrder.set(MODULES.POSTPROCESSING_AO.MODULE.N8AOPostPass, PostProcessingEffectOrder.SSAO);
117
+ builtinOrder.set(MODULES.POSTPROCESSING_AO.MODULE.N8AOPass, PostProcessingEffectOrder.SSAO);
118
+ builtinOrder.set(MODULES.POSTPROCESSING.MODULE.TiltShiftEffect, PostProcessingEffectOrder.TiltShift);
119
+ builtinOrder.set(MODULES.POSTPROCESSING.MODULE.DepthOfFieldEffect, PostProcessingEffectOrder.DepthOfField);
120
+ builtinOrder.set(MODULES.POSTPROCESSING.MODULE.ChromaticAberrationEffect, PostProcessingEffectOrder.ChromaticAberration);
121
+ builtinOrder.set(MODULES.POSTPROCESSING.MODULE.BloomEffect, PostProcessingEffectOrder.Bloom);
122
+ builtinOrder.set(MODULES.POSTPROCESSING.MODULE.SelectiveBloomEffect, PostProcessingEffectOrder.Bloom);
123
+ builtinOrder.set(MODULES.POSTPROCESSING.MODULE.VignetteEffect, PostProcessingEffectOrder.Vignette);
124
+ builtinOrder.set(MODULES.POSTPROCESSING.MODULE.PixelationEffect, PostProcessingEffectOrder.Pixelation);
125
+ builtinOrder.set(MODULES.POSTPROCESSING.MODULE.ToneMappingEffect, PostProcessingEffectOrder.ToneMapping);
126
+ builtinOrder.set(MODULES.POSTPROCESSING.MODULE.HueSaturationEffect, PostProcessingEffectOrder.HueSaturation);
127
+ builtinOrder.set(MODULES.POSTPROCESSING.MODULE.BrightnessContrastEffect, PostProcessingEffectOrder.BrightnessContrast);
128
+ }
129
+
130
+ // enforce correct order of effects (e.g. DOF before Bloom)
131
+ effects.sort((a, b) => {
132
+ // we use find index here because sometimes constructor names are prefixed with `_`
133
+ // TODO: find a more robust solution that isnt name based (not sure if that exists tho... maybe we must give effect TYPES some priority/index)
134
+ const aidx = typeof a.priority === "number" ? a.priority : builtinOrder!.get(a.effect.constructor as Constructor<Effect | Pass>) ?? Number.NEGATIVE_INFINITY;
135
+ const bidx = typeof b.priority === "number" ? b.priority : builtinOrder!.get(b.effect.constructor as Constructor<Effect | Pass>) ?? Number.NEGATIVE_INFINITY;
136
+
137
+ // Unknown effects should be rendered first
138
+ if (aidx === Number.NEGATIVE_INFINITY) {
139
+ if (debug) console.warn("Unknown effect found: ", a.constructor.name, a);
140
+ return 1;
141
+ }
142
+ else if (bidx === Number.NEGATIVE_INFINITY) {
143
+ if (debug) console.warn("Unknown effect found: ", b.constructor.name, b);
144
+ return -1;
145
+ }
146
+ return aidx - bidx;
147
+ });
148
+
149
+
150
+ if (debug === "verbose") console.debug("After ordering effects", [...effects]);
151
+ }
152
+
153
+