laymur 0.20.0 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -3
- package/dist/_virtual/2d.js +3 -0
- package/dist/_virtual/3d.js +3 -0
- package/dist/_virtual/4d.js +3 -0
- package/dist/_virtual/mod.js +5 -0
- package/dist/_virtual/mod2.js +3 -0
- package/dist/core/constraints/UIHorizontalInterpolationConstraint/UIHorizontalInterpolationConstraint.js +0 -1
- package/dist/core/constraints/UIVerticalInterpolationConstraint/UIVerticalInterpolationConstraint.js +0 -1
- package/dist/core/elements/UIElement/UIElement.Internal.d.ts +22 -0
- package/dist/core/elements/UIElement/UIElement.Internal.js +21 -1
- package/dist/core/elements/UIElement/UIElement.d.ts +24 -0
- package/dist/core/elements/UIElement/UIElement.js +61 -2
- package/dist/core/elements/UIProgress/UIProgress.js +2 -1
- package/dist/core/elements/UIText/UIText.js +1 -8
- package/dist/core/index.d.ts +1 -0
- package/dist/core/miscellaneous/UIBlendMode.d.ts +7 -0
- package/dist/core/miscellaneous/UIBlendMode.js +10 -0
- package/dist/core/miscellaneous/UIRelation.d.ts +2 -2
- package/dist/core/miscellaneous/UIRelation.js +2 -2
- package/dist/core/miscellaneous/generic-plane/UIGenericInstancedPlane/UIGenericInstancedPlane.js +50 -6
- package/dist/core/miscellaneous/generic-plane/UIGenericPlaneRegistry/UIGenericPlaneRegistry.Internal.d.ts +3 -1
- package/dist/core/miscellaneous/generic-plane/UIGenericPlaneRegistry/UIGenericPlaneRegistry.js +80 -60
- package/dist/core/miscellaneous/generic-plane/shared.d.ts +9 -0
- package/dist/core/miscellaneous/generic-plane/shared.js +66 -2
- package/dist/core/miscellaneous/webglCapabilities.js +0 -1
- package/dist/core/wrappers/UIInputWrapper/UIInputWrapper.js +2 -0
- package/dist/core/wrappers/UISceneWrapper/UISceneWrapper.Internal.d.ts +4 -2
- package/dist/core/wrappers/UISceneWrapper/UISceneWrapper.d.ts +4 -2
- package/dist/core/wrappers/UISceneWrapper/UISceneWrapper.js +8 -2
- package/dist/debug/UIAspectDebug.js +1 -1
- package/dist/index.js +1 -0
- package/dist/node_modules/fast-simplex-noise/lib/2d.js +93 -0
- package/dist/node_modules/fast-simplex-noise/lib/3d.js +142 -0
- package/dist/node_modules/fast-simplex-noise/lib/4d.js +196 -0
- package/dist/node_modules/fast-simplex-noise/lib/mod.js +24 -0
- package/dist/particles/behaviorModules/UIBehaviorDirectionalGravity.d.ts +3 -3
- package/dist/particles/behaviorModules/UIBehaviorDirectionalGravity.js +3 -3
- package/dist/particles/behaviorModules/UIBehaviorPointGravity.js +0 -3
- package/dist/particles/behaviorModules/UIBehaviorScaleOverLife.js +0 -1
- package/dist/particles/behaviorModules/UIBehaviorTorqueDamping.js +0 -1
- package/dist/particles/behaviorModules/UIBehaviorTorqueNoise.js +1 -3
- package/dist/particles/behaviorModules/UIBehaviorVelocityDamping.js +0 -1
- package/dist/particles/behaviorModules/UIBehaviorVelocityNoise.js +1 -3
- package/dist/particles/miscellaneous/miscellaneous.d.ts +1 -1
- package/dist/particles/miscellaneous/miscellaneous.js +2 -4
- package/package.json +5 -3
package/dist/core/miscellaneous/generic-plane/UIGenericPlaneRegistry/UIGenericPlaneRegistry.js
CHANGED
|
@@ -13,13 +13,10 @@ import { UIGenericInstancedPlane } from '../UIGenericInstancedPlane/UIGenericIns
|
|
|
13
13
|
*/
|
|
14
14
|
class UIPlaneRegistry {
|
|
15
15
|
constructor(scene) {
|
|
16
|
-
// Source of truth
|
|
17
16
|
this._private_handlerToState = new Map();
|
|
18
17
|
this._private_lastHandler = 0;
|
|
19
|
-
// GPU representation
|
|
20
18
|
this._private_orderedMeshes = [];
|
|
21
19
|
this._private_handlerToDescriptor = new Map();
|
|
22
|
-
// Dirty tracking
|
|
23
20
|
this._private_pendingCreate = new Set();
|
|
24
21
|
this._private_pendingDelete = new Set();
|
|
25
22
|
this._private_pendingRelocate = new Set();
|
|
@@ -32,7 +29,7 @@ class UIPlaneRegistry {
|
|
|
32
29
|
* Changes are pending until flush() is called.
|
|
33
30
|
* @returns Plane handler for subsequent operations
|
|
34
31
|
*/
|
|
35
|
-
createPlane(source, properties, transform, visibility, transparency) {
|
|
32
|
+
createPlane(source, properties, transform, visibility, transparency, blend, hsl) {
|
|
36
33
|
const handler = this._private_lastHandler++;
|
|
37
34
|
const glProperties = convertUIPropertiesToGLProperties(cloneProperties(properties));
|
|
38
35
|
const zIndex = extractZIndex(transform);
|
|
@@ -42,6 +39,8 @@ class UIPlaneRegistry {
|
|
|
42
39
|
transform: transform.clone(),
|
|
43
40
|
visibility,
|
|
44
41
|
transparency,
|
|
42
|
+
blend,
|
|
43
|
+
hsl: { h: hsl.h, s: hsl.s, l: hsl.l },
|
|
45
44
|
zIndex,
|
|
46
45
|
};
|
|
47
46
|
this._private_handlerToState.set(handler, state);
|
|
@@ -57,14 +56,11 @@ class UIPlaneRegistry {
|
|
|
57
56
|
throw new Error(`UIPlaneRegistry.destroyPlane: handler ${handler} not found`);
|
|
58
57
|
}
|
|
59
58
|
this._private_handlerToState.delete(handler);
|
|
60
|
-
// If was pending create, just remove from there
|
|
61
59
|
if (this._private_pendingCreate.has(handler)) {
|
|
62
60
|
this._private_pendingCreate.delete(handler);
|
|
63
61
|
return;
|
|
64
62
|
}
|
|
65
|
-
// Remove from relocate if was there
|
|
66
63
|
this._private_pendingRelocate.delete(handler);
|
|
67
|
-
// Mark for deletion
|
|
68
64
|
this._private_pendingDelete.add(handler);
|
|
69
65
|
this._private_needsFlush = true;
|
|
70
66
|
}
|
|
@@ -77,7 +73,6 @@ class UIPlaneRegistry {
|
|
|
77
73
|
setProperties(handler, properties) {
|
|
78
74
|
const state = this._private_resolveState(handler);
|
|
79
75
|
const glProperties = convertUIPropertiesToGLProperties(properties);
|
|
80
|
-
// Check if any non-instantiable (texture) changed
|
|
81
76
|
let textureChanged = false;
|
|
82
77
|
for (const name in glProperties) {
|
|
83
78
|
const newProp = glProperties[name];
|
|
@@ -87,7 +82,6 @@ class UIPlaneRegistry {
|
|
|
87
82
|
textureChanged = true;
|
|
88
83
|
}
|
|
89
84
|
}
|
|
90
|
-
// Update state
|
|
91
85
|
state.properties[name] = {
|
|
92
86
|
value: newProp.value,
|
|
93
87
|
glslTypeInfo: newProp.glslTypeInfo,
|
|
@@ -98,7 +92,6 @@ class UIPlaneRegistry {
|
|
|
98
92
|
this._private_needsFlush = true;
|
|
99
93
|
}
|
|
100
94
|
else {
|
|
101
|
-
// Apply immediately if already in mesh and no texture change
|
|
102
95
|
const descriptor = this._private_handlerToDescriptor.get(handler);
|
|
103
96
|
if (descriptor) {
|
|
104
97
|
descriptor.mesh.setPropertiesAt(descriptor.instanceIndex, glProperties);
|
|
@@ -121,7 +114,6 @@ class UIPlaneRegistry {
|
|
|
121
114
|
this._private_needsFlush = true;
|
|
122
115
|
}
|
|
123
116
|
else {
|
|
124
|
-
// Apply immediately if already in mesh and zIndex unchanged
|
|
125
117
|
const descriptor = this._private_handlerToDescriptor.get(handler);
|
|
126
118
|
if (descriptor) {
|
|
127
119
|
descriptor.mesh.setTransformAt(descriptor.instanceIndex, transform);
|
|
@@ -135,12 +127,37 @@ class UIPlaneRegistry {
|
|
|
135
127
|
setVisibility(handler, visibility) {
|
|
136
128
|
const state = this._private_resolveState(handler);
|
|
137
129
|
state.visibility = visibility;
|
|
138
|
-
// Apply immediately if already in a mesh
|
|
139
130
|
const descriptor = this._private_handlerToDescriptor.get(handler);
|
|
140
131
|
if (descriptor) {
|
|
141
132
|
descriptor.mesh.setVisibilityAt(descriptor.instanceIndex, visibility);
|
|
142
133
|
}
|
|
143
134
|
}
|
|
135
|
+
/**
|
|
136
|
+
* Updates plane blend factor (1 = normal over, 0 = additive).
|
|
137
|
+
* This is applied immediately (doesn't affect batching structure).
|
|
138
|
+
*/
|
|
139
|
+
setBlend(handler, blend) {
|
|
140
|
+
const state = this._private_resolveState(handler);
|
|
141
|
+
state.blend = blend;
|
|
142
|
+
const descriptor = this._private_handlerToDescriptor.get(handler);
|
|
143
|
+
if (descriptor) {
|
|
144
|
+
descriptor.mesh.setBlendAt(descriptor.instanceIndex, blend);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Updates plane HSL adjustment (hue in turns, saturation multiplier, lightness offset).
|
|
149
|
+
* This is applied immediately (doesn't affect batching structure).
|
|
150
|
+
*/
|
|
151
|
+
setHSL(handler, hsl) {
|
|
152
|
+
const state = this._private_resolveState(handler);
|
|
153
|
+
state.hsl.h = hsl.h;
|
|
154
|
+
state.hsl.s = hsl.s;
|
|
155
|
+
state.hsl.l = hsl.l;
|
|
156
|
+
const descriptor = this._private_handlerToDescriptor.get(handler);
|
|
157
|
+
if (descriptor) {
|
|
158
|
+
descriptor.mesh.setHSLAt(descriptor.instanceIndex, hsl);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
144
161
|
/**
|
|
145
162
|
* Updates plane transparency mode.
|
|
146
163
|
* Element will be relocated on flush() if transparency changes.
|
|
@@ -179,7 +196,7 @@ class UIPlaneRegistry {
|
|
|
179
196
|
for (const handler of this._private_pendingDelete) {
|
|
180
197
|
const descriptor = this._private_handlerToDescriptor.get(handler);
|
|
181
198
|
if (!descriptor) {
|
|
182
|
-
continue;
|
|
199
|
+
continue;
|
|
183
200
|
}
|
|
184
201
|
const { mesh, instanceIndex } = descriptor;
|
|
185
202
|
mesh.removeAt(instanceIndex);
|
|
@@ -191,13 +208,12 @@ class UIPlaneRegistry {
|
|
|
191
208
|
for (const handler of this._private_pendingRelocate) {
|
|
192
209
|
const descriptor = this._private_handlerToDescriptor.get(handler);
|
|
193
210
|
if (!descriptor) {
|
|
194
|
-
continue;
|
|
211
|
+
continue;
|
|
195
212
|
}
|
|
196
213
|
const { mesh, instanceIndex } = descriptor;
|
|
197
214
|
mesh.removeAt(instanceIndex);
|
|
198
215
|
this._private_shiftHandlerIndices(mesh, instanceIndex + 1, -1);
|
|
199
216
|
this._private_handlerToDescriptor.delete(handler);
|
|
200
|
-
// Will be re-inserted in processCreates
|
|
201
217
|
this._private_pendingCreate.add(handler);
|
|
202
218
|
}
|
|
203
219
|
}
|
|
@@ -205,7 +221,6 @@ class UIPlaneRegistry {
|
|
|
205
221
|
if (this._private_pendingCreate.size === 0) {
|
|
206
222
|
return;
|
|
207
223
|
}
|
|
208
|
-
// Collect and sort by zIndex
|
|
209
224
|
const toCreate = [];
|
|
210
225
|
for (const handler of this._private_pendingCreate) {
|
|
211
226
|
const state = this._private_handlerToState.get(handler);
|
|
@@ -214,56 +229,74 @@ class UIPlaneRegistry {
|
|
|
214
229
|
}
|
|
215
230
|
}
|
|
216
231
|
toCreate.sort((a, b) => a.state.zIndex - b.state.zIndex);
|
|
217
|
-
// Check for duplicate zIndex
|
|
218
232
|
for (let i = 1; i < toCreate.length; i++) {
|
|
219
233
|
if (toCreate[i].state.zIndex === toCreate[i - 1].state.zIndex) {
|
|
220
234
|
throw new Error(`UIPlaneRegistry.flush: duplicate zIndex=${toCreate[i].state.zIndex} ` +
|
|
221
235
|
`for handlers ${toCreate[i - 1].handler} and ${toCreate[i].handler}`);
|
|
222
236
|
}
|
|
223
237
|
}
|
|
224
|
-
// Insert each element
|
|
225
238
|
for (const { handler, state } of toCreate) {
|
|
226
239
|
this._private_insertSingleElement(handler, state);
|
|
227
240
|
}
|
|
228
241
|
}
|
|
229
242
|
_private_insertSingleElement(handler, state) {
|
|
230
|
-
const { source, properties, transform, visibility, transparency, zIndex } = state;
|
|
231
|
-
|
|
232
|
-
let
|
|
233
|
-
|
|
234
|
-
if (!mesh.isCompatibleWith(source, properties, transparency)) {
|
|
235
|
-
continue;
|
|
236
|
-
}
|
|
243
|
+
const { source, properties, transform, visibility, transparency, blend, hsl, zIndex } = state;
|
|
244
|
+
let newMeshIndex = this._private_orderedMeshes.length;
|
|
245
|
+
for (let i = 0; i < this._private_orderedMeshes.length; i++) {
|
|
246
|
+
const mesh = this._private_orderedMeshes[i];
|
|
237
247
|
if (mesh.instancesCount === 0) {
|
|
238
|
-
|
|
239
|
-
break;
|
|
248
|
+
continue;
|
|
240
249
|
}
|
|
241
250
|
const meshMinZ = mesh.getZIndexAt(0);
|
|
242
251
|
const meshMaxZ = mesh.getZIndexAt(mesh.instancesCount - 1);
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
candidateMesh = mesh;
|
|
252
|
+
if (zIndex < meshMinZ) {
|
|
253
|
+
newMeshIndex = i;
|
|
246
254
|
break;
|
|
247
255
|
}
|
|
256
|
+
if (zIndex <= meshMaxZ) {
|
|
257
|
+
if (mesh.isCompatibleWith(source, properties, transparency)) {
|
|
258
|
+
const instanceIndex = this._private_findInstanceIndexInMesh(mesh, zIndex);
|
|
259
|
+
mesh.insertAt(instanceIndex, properties, transform, visibility, blend, hsl);
|
|
260
|
+
this._private_shiftHandlerIndices(mesh, instanceIndex, 1);
|
|
261
|
+
this._private_handlerToDescriptor.set(handler, { mesh, instanceIndex });
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
const splitIndex = this._private_findInstanceIndexInMesh(mesh, zIndex);
|
|
265
|
+
if (splitIndex === 0) {
|
|
266
|
+
newMeshIndex = i;
|
|
267
|
+
}
|
|
268
|
+
else if (splitIndex >= mesh.instancesCount) {
|
|
269
|
+
newMeshIndex = i + 1;
|
|
270
|
+
}
|
|
271
|
+
else {
|
|
272
|
+
this._private_splitMeshAt(i, mesh, splitIndex);
|
|
273
|
+
newMeshIndex = i + 1;
|
|
274
|
+
}
|
|
275
|
+
break;
|
|
276
|
+
}
|
|
277
|
+
newMeshIndex = i + 1;
|
|
248
278
|
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
279
|
+
const mesh = new UIGenericInstancedPlane(source, cloneGLProperties(properties), transparency);
|
|
280
|
+
mesh.insertAt(0, properties, transform, visibility, blend, hsl);
|
|
281
|
+
this._private_orderedMeshes.splice(newMeshIndex, 0, mesh);
|
|
282
|
+
this._private_scene.add(mesh);
|
|
283
|
+
this._private_handlerToDescriptor.set(handler, { mesh, instanceIndex: 0 });
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Split an existing mesh at the given instance index, inserting the tail half as a
|
|
287
|
+
* new mesh immediately after it in render order. Descriptors are remapped to follow
|
|
288
|
+
* their instances into the new mesh.
|
|
289
|
+
*/
|
|
290
|
+
_private_splitMeshAt(meshIndex, mesh, splitIndex) {
|
|
291
|
+
const tail = mesh.split(splitIndex);
|
|
292
|
+
for (const descriptor of this._private_handlerToDescriptor.values()) {
|
|
293
|
+
if (descriptor.mesh === mesh && descriptor.instanceIndex >= splitIndex) {
|
|
294
|
+
descriptor.mesh = tail;
|
|
295
|
+
descriptor.instanceIndex -= splitIndex;
|
|
296
|
+
}
|
|
266
297
|
}
|
|
298
|
+
this._private_orderedMeshes.splice(meshIndex + 1, 0, tail);
|
|
299
|
+
this._private_scene.add(tail);
|
|
267
300
|
}
|
|
268
301
|
_private_mergeCompatibleNeighbors() {
|
|
269
302
|
let i = 0;
|
|
@@ -276,7 +309,6 @@ class UIPlaneRegistry {
|
|
|
276
309
|
}
|
|
277
310
|
const leftMaxZ = left.getZIndexAt(left.instancesCount - 1);
|
|
278
311
|
const rightMinZ = right.getZIndexAt(0);
|
|
279
|
-
// Check if they can be merged (non-overlapping zIndex ranges and compatible)
|
|
280
312
|
if (leftMaxZ < rightMinZ &&
|
|
281
313
|
left.isCompatibleWith(right.source, right.getProperties(), right.transparency)) {
|
|
282
314
|
const indexOffset = left.instancesCount;
|
|
@@ -285,7 +317,6 @@ class UIPlaneRegistry {
|
|
|
285
317
|
this._private_scene.remove(right);
|
|
286
318
|
right.destroy();
|
|
287
319
|
this._private_orderedMeshes.splice(i + 1, 1);
|
|
288
|
-
// Don't increment i, check if we can merge again
|
|
289
320
|
continue;
|
|
290
321
|
}
|
|
291
322
|
i++;
|
|
@@ -308,15 +339,6 @@ class UIPlaneRegistry {
|
|
|
308
339
|
}
|
|
309
340
|
return state;
|
|
310
341
|
}
|
|
311
|
-
_private_findMeshIndexForZIndex(zIndex) {
|
|
312
|
-
for (let i = 0; i < this._private_orderedMeshes.length; i++) {
|
|
313
|
-
const mesh = this._private_orderedMeshes[i];
|
|
314
|
-
if (mesh.instancesCount > 0 && mesh.getZIndexAt(0) > zIndex) {
|
|
315
|
-
return i;
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
return this._private_orderedMeshes.length;
|
|
319
|
-
}
|
|
320
342
|
_private_findInstanceIndexInMesh(mesh, zIndex) {
|
|
321
343
|
for (let i = 0; i < mesh.instancesCount; i++) {
|
|
322
344
|
if (mesh.getZIndexAt(i) > zIndex) {
|
|
@@ -341,13 +363,11 @@ class UIPlaneRegistry {
|
|
|
341
363
|
}
|
|
342
364
|
}
|
|
343
365
|
_private_syncSceneOrder() {
|
|
344
|
-
// Sort meshes by their minimum zIndex
|
|
345
366
|
this._private_orderedMeshes.sort((a, b) => {
|
|
346
367
|
const aZ = a.instancesCount > 0 ? a.getZIndexAt(0) : 0;
|
|
347
368
|
const bZ = b.instancesCount > 0 ? b.getZIndexAt(0) : 0;
|
|
348
369
|
return aZ - bZ;
|
|
349
370
|
});
|
|
350
|
-
// Update render order
|
|
351
371
|
for (let i = 0; i < this._private_orderedMeshes.length; i++) {
|
|
352
372
|
this._private_orderedMeshes[i].renderOrder = i;
|
|
353
373
|
}
|
|
@@ -23,6 +23,15 @@ export interface PlaneData {
|
|
|
23
23
|
visibility: boolean;
|
|
24
24
|
transparency: UITransparencyMode;
|
|
25
25
|
}
|
|
26
|
+
/** Per-instance HSL adjustment in shader space (matches the instanceHSL attribute). */
|
|
27
|
+
export interface HSLAdjustment {
|
|
28
|
+
/** Hue shift in turns (degrees / 360); wrapped with fract() in the shader. */
|
|
29
|
+
h: number;
|
|
30
|
+
/** Saturation multiplier. */
|
|
31
|
+
s: number;
|
|
32
|
+
/** Lightness offset. */
|
|
33
|
+
l: number;
|
|
34
|
+
}
|
|
26
35
|
export declare function resolveGLSLTypeInfo(value: UIProperty | UIPropertyName | UIPropertyConstructor): GLTypeInfo;
|
|
27
36
|
export declare function resolvePropertyUniform(name: string, material: ShaderMaterial): IUniform<UIProperty>;
|
|
28
37
|
export declare function arePropertiesPartiallyCompatible(full: Readonly<Record<string, Readonly<GLProperty>>>, partial: Readonly<Record<string, Readonly<GLProperty>>>): boolean;
|
|
@@ -130,7 +130,6 @@ function arePropertiesPartiallyCompatible(full, partial) {
|
|
|
130
130
|
if (infoFull.glslTypeName !== infoPartial.glslTypeName) {
|
|
131
131
|
return false;
|
|
132
132
|
}
|
|
133
|
-
// Non-instantiable (textures) must match by reference
|
|
134
133
|
if (!infoFull.instantiable && full[key].value !== partial[key].value) {
|
|
135
134
|
return false;
|
|
136
135
|
}
|
|
@@ -205,10 +204,75 @@ function buildGenericPlaneFragmentShader(uniformDeclarations, varyingDeclaration
|
|
|
205
204
|
#endif
|
|
206
205
|
}
|
|
207
206
|
|
|
207
|
+
// HSL adjustment helpers.
|
|
208
|
+
// p_instanceHSL = (hue in turns, saturation multiplier, lightness offset).
|
|
209
|
+
vec3 rgbToHsl(vec3 color) {
|
|
210
|
+
float maxChannel = max(color.r, max(color.g, color.b));
|
|
211
|
+
float minChannel = min(color.r, min(color.g, color.b));
|
|
212
|
+
float chroma = maxChannel - minChannel;
|
|
213
|
+
float lightness = (maxChannel + minChannel) * 0.5;
|
|
214
|
+
float hue = 0.0;
|
|
215
|
+
float saturation = 0.0;
|
|
216
|
+
if (chroma > 0.0) {
|
|
217
|
+
saturation = lightness > 0.5
|
|
218
|
+
? chroma / (2.0 - maxChannel - minChannel)
|
|
219
|
+
: chroma / (maxChannel + minChannel);
|
|
220
|
+
if (maxChannel == color.r) {
|
|
221
|
+
hue = (color.g - color.b) / chroma + (color.g < color.b ? 6.0 : 0.0);
|
|
222
|
+
} else if (maxChannel == color.g) {
|
|
223
|
+
hue = (color.b - color.r) / chroma + 2.0;
|
|
224
|
+
} else {
|
|
225
|
+
hue = (color.r - color.g) / chroma + 4.0;
|
|
226
|
+
}
|
|
227
|
+
hue /= 6.0;
|
|
228
|
+
}
|
|
229
|
+
return vec3(hue, saturation, lightness);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
float hueToRgbChannel(float low, float high, float hue) {
|
|
233
|
+
hue = fract(hue);
|
|
234
|
+
if (hue < 1.0 / 6.0) return low + (high - low) * 6.0 * hue;
|
|
235
|
+
if (hue < 1.0 / 2.0) return high;
|
|
236
|
+
if (hue < 2.0 / 3.0) return low + (high - low) * (2.0 / 3.0 - hue) * 6.0;
|
|
237
|
+
return low;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
vec3 hslToRgb(vec3 hsl) {
|
|
241
|
+
float hue = hsl.x;
|
|
242
|
+
float saturation = hsl.y;
|
|
243
|
+
float lightness = hsl.z;
|
|
244
|
+
if (saturation <= 0.0) {
|
|
245
|
+
return vec3(lightness);
|
|
246
|
+
}
|
|
247
|
+
float high = lightness < 0.5
|
|
248
|
+
? lightness * (1.0 + saturation)
|
|
249
|
+
: lightness + saturation - lightness * saturation;
|
|
250
|
+
float low = 2.0 * lightness - high;
|
|
251
|
+
return vec3(
|
|
252
|
+
hueToRgbChannel(low, high, hue + 1.0 / 3.0),
|
|
253
|
+
hueToRgbChannel(low, high, hue),
|
|
254
|
+
hueToRgbChannel(low, high, hue - 1.0 / 3.0)
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
vec3 applyInstanceHSL(vec3 color) {
|
|
259
|
+
vec3 hsl = rgbToHsl(color);
|
|
260
|
+
hsl.x = fract(hsl.x + p_instanceHSL.x);
|
|
261
|
+
hsl.y = clamp(hsl.y * p_instanceHSL.y, 0.0, 1.0);
|
|
262
|
+
hsl.z = clamp(hsl.z + p_instanceHSL.z, 0.0, 1.0);
|
|
263
|
+
return hslToRgb(hsl);
|
|
264
|
+
}
|
|
265
|
+
|
|
208
266
|
// Source must define vec4 draw() function
|
|
209
267
|
${source}
|
|
210
268
|
void main() {
|
|
211
269
|
vec4 diffuseColor = draw();
|
|
270
|
+
|
|
271
|
+
// Skip the HSL roundtrip entirely for the default (identity) case.
|
|
272
|
+
if (p_instanceHSL != vec3(0.0, 1.0, 0.0)) {
|
|
273
|
+
diffuseColor.rgb = applyInstanceHSL(diffuseColor.rgb);
|
|
274
|
+
}
|
|
275
|
+
|
|
212
276
|
if (diffuseColor.a <= ${alphaTestValue.toFixed(8)}) {
|
|
213
277
|
discard;
|
|
214
278
|
}
|
|
@@ -219,7 +283,7 @@ function buildGenericPlaneFragmentShader(uniformDeclarations, varyingDeclaration
|
|
|
219
283
|
#endif
|
|
220
284
|
|
|
221
285
|
gl_FragColor = linearToOutputTexel(diffuseColor);
|
|
222
|
-
gl_FragColor = ${usePremultipliedAlpha ? "vec4(gl_FragColor.rgb * gl_FragColor.a, gl_FragColor.a)" : "gl_FragColor"};
|
|
286
|
+
gl_FragColor = ${usePremultipliedAlpha ? "vec4(gl_FragColor.rgb * gl_FragColor.a, gl_FragColor.a * p_instanceBlend)" : "gl_FragColor"};
|
|
223
287
|
}
|
|
224
288
|
`;
|
|
225
289
|
}
|
|
@@ -40,7 +40,6 @@ function checkOffscreenCanvasSupportInternal() {
|
|
|
40
40
|
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
41
41
|
gl.deleteFramebuffer(framebuffer);
|
|
42
42
|
gl.deleteTexture(texture);
|
|
43
|
-
// Check that the read pixel is red (with tolerance)
|
|
44
43
|
const isRedPixel = pixelData[0] > 200 && pixelData[1] < 50 && pixelData[2] < 50 && pixelData[3] > 200;
|
|
45
44
|
if (!isRedPixel) {
|
|
46
45
|
return false;
|
|
@@ -26,6 +26,8 @@ class UIInputWrapper {
|
|
|
26
26
|
throw new Error("UIInputWrapper.destroyInputCatcher.handler: handler not found");
|
|
27
27
|
}
|
|
28
28
|
this._private_catchers.splice(index, 1);
|
|
29
|
+
this._private_zIndicesDirty = true;
|
|
30
|
+
this.dirty = true;
|
|
29
31
|
}
|
|
30
32
|
getZIndex(handler) {
|
|
31
33
|
this._private_ensureSorted();
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import type { Matrix4, Object3D } from "three";
|
|
2
2
|
import type { UITransparencyMode } from "../../miscellaneous/UITransparencyMode";
|
|
3
|
-
import type { UIProperty } from "../../miscellaneous/generic-plane/shared";
|
|
3
|
+
import type { HSLAdjustment, UIProperty } from "../../miscellaneous/generic-plane/shared";
|
|
4
4
|
export interface UISceneWrapperView {
|
|
5
|
-
createPlane(source: string, properties: Record<string, UIProperty>, transform: Matrix4, visibility: boolean, transparency: UITransparencyMode): number;
|
|
5
|
+
createPlane(source: string, properties: Record<string, UIProperty>, transform: Matrix4, visibility: boolean, transparency: UITransparencyMode, blend: number, hsl: HSLAdjustment): number;
|
|
6
6
|
destroyPlane(handler: number): void;
|
|
7
7
|
setTransform(handler: number, transform: Matrix4): void;
|
|
8
8
|
setProperties(handler: number, properties: Record<string, UIProperty>): void;
|
|
9
9
|
setVisibility(handler: number, visible: boolean): void;
|
|
10
10
|
setTransparency(handler: number, transparency: UITransparencyMode): void;
|
|
11
|
+
setBlend(handler: number, blend: number): void;
|
|
12
|
+
setHSL(handler: number, hsl: HSLAdjustment): void;
|
|
11
13
|
insertCustomObject(object: Object3D): void;
|
|
12
14
|
removeCustomObject(object: Object3D): void;
|
|
13
15
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Matrix4, Object3D, WebGLRenderer } from "three";
|
|
2
|
-
import type { UIProperty } from "../../miscellaneous/generic-plane/shared";
|
|
2
|
+
import type { HSLAdjustment, UIProperty } from "../../miscellaneous/generic-plane/shared";
|
|
3
3
|
import type { UITransparencyMode } from "../../miscellaneous/UITransparencyMode";
|
|
4
4
|
import type { UISceneWrapperView } from "./UISceneWrapper.Internal";
|
|
5
5
|
export declare class UISceneWrapper implements UISceneWrapperView {
|
|
@@ -7,12 +7,14 @@ export declare class UISceneWrapper implements UISceneWrapperView {
|
|
|
7
7
|
private readonly camera;
|
|
8
8
|
private readonly planeRegistry;
|
|
9
9
|
constructor(width: number, height: number);
|
|
10
|
-
createPlane(source: string, properties: Record<string, UIProperty>, transform: Matrix4, visibility: boolean, transparency: UITransparencyMode): number;
|
|
10
|
+
createPlane(source: string, properties: Record<string, UIProperty>, transform: Matrix4, visibility: boolean, transparency: UITransparencyMode, blend: number, hsl: HSLAdjustment): number;
|
|
11
11
|
destroyPlane(handler: number): void;
|
|
12
12
|
setTransform(handler: number, transform: Matrix4): void;
|
|
13
13
|
setProperties(handler: number, properties: Record<string, UIProperty>): void;
|
|
14
14
|
setVisibility(handler: number, visible: boolean): void;
|
|
15
15
|
setTransparency(handler: number, transparency: UITransparencyMode): void;
|
|
16
|
+
setBlend(handler: number, blend: number): void;
|
|
17
|
+
setHSL(handler: number, hsl: HSLAdjustment): void;
|
|
16
18
|
insertCustomObject(object: Object3D): this;
|
|
17
19
|
removeCustomObject(object: Object3D): this;
|
|
18
20
|
resize(width: number, height: number): this;
|
|
@@ -15,8 +15,8 @@ class UISceneWrapper {
|
|
|
15
15
|
this._private_camera.matrixAutoUpdate = false;
|
|
16
16
|
this._private_camera.matrixWorldAutoUpdate = false;
|
|
17
17
|
}
|
|
18
|
-
createPlane(source, properties, transform, visibility, transparency) {
|
|
19
|
-
return this._private_planeRegistry.createPlane(source, properties, transform, visibility, transparency);
|
|
18
|
+
createPlane(source, properties, transform, visibility, transparency, blend, hsl) {
|
|
19
|
+
return this._private_planeRegistry.createPlane(source, properties, transform, visibility, transparency, blend, hsl);
|
|
20
20
|
}
|
|
21
21
|
destroyPlane(handler) {
|
|
22
22
|
this._private_planeRegistry.destroyPlane(handler);
|
|
@@ -33,6 +33,12 @@ class UISceneWrapper {
|
|
|
33
33
|
setTransparency(handler, transparency) {
|
|
34
34
|
this._private_planeRegistry.setTransparency(handler, transparency);
|
|
35
35
|
}
|
|
36
|
+
setBlend(handler, blend) {
|
|
37
|
+
this._private_planeRegistry.setBlend(handler, blend);
|
|
38
|
+
}
|
|
39
|
+
setHSL(handler, hsl) {
|
|
40
|
+
this._private_planeRegistry.setHSL(handler, hsl);
|
|
41
|
+
}
|
|
36
42
|
insertCustomObject(object) {
|
|
37
43
|
this._private_scene.add(object);
|
|
38
44
|
return this;
|
|
@@ -42,7 +42,7 @@ class UIAspectDebug {
|
|
|
42
42
|
new Vector3(x, y, 0),
|
|
43
43
|
new Vector3(oppositeX, oppositeY, 0),
|
|
44
44
|
]);
|
|
45
|
-
const nextText = this.constraint.aspect.toFixed(2) + " (" + width.toFixed(0) + "
|
|
45
|
+
const nextText = this.constraint.aspect.toFixed(2) + " (" + width.toFixed(0) + "x" + height.toFixed(0) + ")";
|
|
46
46
|
if (nextText !== this._private_lastRenderedText || tintDirty) {
|
|
47
47
|
this._private_drawText(nextText);
|
|
48
48
|
this._private_textTexture.needsUpdate = true;
|
package/dist/index.js
CHANGED
|
@@ -49,3 +49,4 @@ export { UIOrientation } from './core/miscellaneous/UIOrientation.js';
|
|
|
49
49
|
export { UIPriority } from './core/miscellaneous/UIPriority.js';
|
|
50
50
|
export { UIRelation } from './core/miscellaneous/UIRelation.js';
|
|
51
51
|
export { UITransparencyMode } from './core/miscellaneous/UITransparencyMode.js';
|
|
52
|
+
export { UIBlendMode } from './core/miscellaneous/UIBlendMode.js';
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { __exports as _2d } from '../../../_virtual/2d.js';
|
|
2
|
+
|
|
3
|
+
var hasRequired_2d;
|
|
4
|
+
|
|
5
|
+
function require_2d () {
|
|
6
|
+
if (hasRequired_2d) return _2d;
|
|
7
|
+
hasRequired_2d = 1;
|
|
8
|
+
/*
|
|
9
|
+
* Based on example code by Stefan Gustavson (stegu@itn.liu.se).
|
|
10
|
+
* Optimisations by Peter Eastman (peastman@drizzle.stanford.edu).
|
|
11
|
+
* Better rank ordering method by Stefan Gustavson in 2012.
|
|
12
|
+
*
|
|
13
|
+
* This code was placed in the public domain by its original author,
|
|
14
|
+
* Stefan Gustavson. You may use it as you see fit, but
|
|
15
|
+
* attribution is appreciated.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(_2d, "__esModule", { value: true });
|
|
18
|
+
_2d.makeNoise2D = void 0;
|
|
19
|
+
var G2 = (3.0 - Math.sqrt(3.0)) / 6.0;
|
|
20
|
+
var Grad = [
|
|
21
|
+
[1, 1],
|
|
22
|
+
[-1, 1],
|
|
23
|
+
[1, -1],
|
|
24
|
+
[-1, -1],
|
|
25
|
+
[1, 0],
|
|
26
|
+
[-1, 0],
|
|
27
|
+
[1, 0],
|
|
28
|
+
[-1, 0],
|
|
29
|
+
[0, 1],
|
|
30
|
+
[0, -1],
|
|
31
|
+
[0, 1],
|
|
32
|
+
[0, -1],
|
|
33
|
+
];
|
|
34
|
+
function makeNoise2D(random) {
|
|
35
|
+
if (random === void 0) { random = Math.random; }
|
|
36
|
+
var p = new Uint8Array(256);
|
|
37
|
+
for (var i = 0; i < 256; i++)
|
|
38
|
+
p[i] = i;
|
|
39
|
+
var n;
|
|
40
|
+
var q;
|
|
41
|
+
for (var i = 255; i > 0; i--) {
|
|
42
|
+
n = Math.floor((i + 1) * random());
|
|
43
|
+
q = p[i];
|
|
44
|
+
p[i] = p[n];
|
|
45
|
+
p[n] = q;
|
|
46
|
+
}
|
|
47
|
+
var perm = new Uint8Array(512);
|
|
48
|
+
var permMod12 = new Uint8Array(512);
|
|
49
|
+
for (var i = 0; i < 512; i++) {
|
|
50
|
+
perm[i] = p[i & 255];
|
|
51
|
+
permMod12[i] = perm[i] % 12;
|
|
52
|
+
}
|
|
53
|
+
return function (x, y) {
|
|
54
|
+
// Skew the input space to determine which simplex cell we're in
|
|
55
|
+
var s = (x + y) * 0.5 * (Math.sqrt(3.0) - 1.0); // Hairy factor for 2D
|
|
56
|
+
var i = Math.floor(x + s);
|
|
57
|
+
var j = Math.floor(y + s);
|
|
58
|
+
var t = (i + j) * G2;
|
|
59
|
+
var X0 = i - t; // Unskew the cell origin back to (x,y) space
|
|
60
|
+
var Y0 = j - t;
|
|
61
|
+
var x0 = x - X0; // The x,y distances from the cell origin
|
|
62
|
+
var y0 = y - Y0;
|
|
63
|
+
// Determine which simplex we are in.
|
|
64
|
+
var i1 = x0 > y0 ? 1 : 0;
|
|
65
|
+
var j1 = x0 > y0 ? 0 : 1;
|
|
66
|
+
// Offsets for corners
|
|
67
|
+
var x1 = x0 - i1 + G2;
|
|
68
|
+
var y1 = y0 - j1 + G2;
|
|
69
|
+
var x2 = x0 - 1.0 + 2.0 * G2;
|
|
70
|
+
var y2 = y0 - 1.0 + 2.0 * G2;
|
|
71
|
+
// Work out the hashed gradient indices of the three simplex corners
|
|
72
|
+
var ii = i & 255;
|
|
73
|
+
var jj = j & 255;
|
|
74
|
+
var g0 = Grad[permMod12[ii + perm[jj]]];
|
|
75
|
+
var g1 = Grad[permMod12[ii + i1 + perm[jj + j1]]];
|
|
76
|
+
var g2 = Grad[permMod12[ii + 1 + perm[jj + 1]]];
|
|
77
|
+
// Calculate the contribution from the three corners
|
|
78
|
+
var t0 = 0.5 - x0 * x0 - y0 * y0;
|
|
79
|
+
var n0 = t0 < 0 ? 0.0 : Math.pow(t0, 4) * (g0[0] * x0 + g0[1] * y0);
|
|
80
|
+
var t1 = 0.5 - x1 * x1 - y1 * y1;
|
|
81
|
+
var n1 = t1 < 0 ? 0.0 : Math.pow(t1, 4) * (g1[0] * x1 + g1[1] * y1);
|
|
82
|
+
var t2 = 0.5 - x2 * x2 - y2 * y2;
|
|
83
|
+
var n2 = t2 < 0 ? 0.0 : Math.pow(t2, 4) * (g2[0] * x2 + g2[1] * y2);
|
|
84
|
+
// Add contributions from each corner to get the final noise value.
|
|
85
|
+
// The result is scaled to return values in the interval [-1, 1]
|
|
86
|
+
return 70.14805770653952 * (n0 + n1 + n2);
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
_2d.makeNoise2D = makeNoise2D;
|
|
90
|
+
return _2d;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export { require_2d as __require };
|