laymur 0.3.0 → 0.3.3
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 +78 -264
- package/dist/index.d.ts +2 -0
- package/dist/index.js +432 -3
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/layers/UILayer.d.ts +12 -1
- package/dist/miscellaneous/UIGenericInstancedPlane.d.ts +32 -0
- package/dist/miscellaneous/UISceneWrapperClientAPI.d.ts +3 -1
- package/dist/miscellaneous/asserts.d.ts +9 -9
- package/dist/wrappers/UISceneWrapper.d.ts +9 -4
- package/package.json +7 -4
- package/dist/scalable/UIScalableMesh.d.ts +0 -0
- package/dist/scalable/UIScalablePlaneMesh.d.ts +0 -0
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PlaneGeometry, Color, Scene, OrthographicCamera, ShaderMaterial, Vector4, Mesh, Texture, Vector2, Vector3, Matrix2, Matrix3, Matrix4, MathUtils, Quaternion, WebGLRenderTarget, UnsignedByteType, LinearFilter, RGBAFormat, PerspectiveCamera, CanvasTexture } from 'three';
|
|
1
|
+
import { PlaneGeometry, Color, Scene, OrthographicCamera, ShaderMaterial, Vector4, Mesh, Texture, Vector2, Vector3, Matrix2, Matrix3, Matrix4, MathUtils, Quaternion, WebGLRenderTarget, UnsignedByteType, LinearFilter, RGBAFormat, PerspectiveCamera, CanvasTexture, InstancedBufferGeometry, InstancedBufferAttribute } from 'three';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Mathematical expression builder for constraint equations in the UI layout system.
|
|
@@ -2225,9 +2225,10 @@ class UISceneWrapper {
|
|
|
2225
2225
|
lights: false,
|
|
2226
2226
|
fog: false,
|
|
2227
2227
|
depthWrite: false,
|
|
2228
|
-
depthTest:
|
|
2228
|
+
depthTest: true,
|
|
2229
2229
|
});
|
|
2230
2230
|
const plane = new Mesh(geometry, material);
|
|
2231
|
+
plane.frustumCulled = false;
|
|
2231
2232
|
plane.matrixAutoUpdate = false;
|
|
2232
2233
|
this._private_scene.add(plane);
|
|
2233
2234
|
const index = this._private_lastPlaneIndex++;
|
|
@@ -2288,6 +2289,14 @@ class UISceneWrapper {
|
|
|
2288
2289
|
descriptor.plane.visible = visible;
|
|
2289
2290
|
return this;
|
|
2290
2291
|
}
|
|
2292
|
+
insertCustomObject(object) {
|
|
2293
|
+
this._private_scene.add(object);
|
|
2294
|
+
return this;
|
|
2295
|
+
}
|
|
2296
|
+
removeCustomObject(object) {
|
|
2297
|
+
this._private_scene.remove(object);
|
|
2298
|
+
return this;
|
|
2299
|
+
}
|
|
2291
2300
|
resize(width, height) {
|
|
2292
2301
|
this._private_camera.right = width;
|
|
2293
2302
|
this._private_camera.top = height;
|
|
@@ -2927,6 +2936,20 @@ class UILayer extends i {
|
|
|
2927
2936
|
this.orientationInternal =
|
|
2928
2937
|
w > h ? UIOrientation.HORIZONTAL : UIOrientation.VERTICAL;
|
|
2929
2938
|
}
|
|
2939
|
+
/**
|
|
2940
|
+
* Gets the current x position value from the constraint solver.
|
|
2941
|
+
* @returns The current x position in pixels
|
|
2942
|
+
*/
|
|
2943
|
+
get x() {
|
|
2944
|
+
return this.solverWrapper.readVariableValue(this.xVariable);
|
|
2945
|
+
}
|
|
2946
|
+
/**
|
|
2947
|
+
* Gets the current y position value from the constraint solver.
|
|
2948
|
+
* @returns The current y position in pixels
|
|
2949
|
+
*/
|
|
2950
|
+
get y() {
|
|
2951
|
+
return this.solverWrapper.readVariableValue(this.yVariable);
|
|
2952
|
+
}
|
|
2930
2953
|
/**
|
|
2931
2954
|
* Gets the current width value from the constraint solver.
|
|
2932
2955
|
* @returns The current layer width in pixels
|
|
@@ -2957,6 +2980,18 @@ class UILayer extends i {
|
|
|
2957
2980
|
get orientation() {
|
|
2958
2981
|
return this.orientationInternal;
|
|
2959
2982
|
}
|
|
2983
|
+
// public set x(value: number) {
|
|
2984
|
+
// throw new Error("You cannot set the x position of a UI layer.");
|
|
2985
|
+
// }
|
|
2986
|
+
// public set y(value: number) {
|
|
2987
|
+
// throw new Error("You cannot set the y position of a UI layer.");
|
|
2988
|
+
// }
|
|
2989
|
+
// public set width(value: number) {
|
|
2990
|
+
// throw new Error("You cannot set the width of a UI layer.");
|
|
2991
|
+
// }
|
|
2992
|
+
// public set height(value: number) {
|
|
2993
|
+
// throw new Error("You cannot set the height of a UI layer.");
|
|
2994
|
+
// }
|
|
2960
2995
|
/**
|
|
2961
2996
|
* Sets the visibility and interaction mode and emits change event.
|
|
2962
2997
|
* @param value - The new UIMode setting
|
|
@@ -6339,6 +6374,400 @@ class UIFullscreenLayer extends UILayer {
|
|
|
6339
6374
|
}
|
|
6340
6375
|
}
|
|
6341
6376
|
|
|
6377
|
+
const INSTANCED_GEOMETRY = (() => {
|
|
6378
|
+
const planeGeometry = new PlaneGeometry(1, 1);
|
|
6379
|
+
const geometry = new InstancedBufferGeometry();
|
|
6380
|
+
geometry.index = planeGeometry.index;
|
|
6381
|
+
geometry.setAttribute("position", planeGeometry.attributes["position"]);
|
|
6382
|
+
geometry.setAttribute("uv", planeGeometry.attributes["uv"]);
|
|
6383
|
+
planeGeometry.dispose();
|
|
6384
|
+
return geometry;
|
|
6385
|
+
})();
|
|
6386
|
+
const ITEM_1_OFFSET = 1;
|
|
6387
|
+
const ITEM_2_OFFSET = 2;
|
|
6388
|
+
const ITEM_3_OFFSET = 3;
|
|
6389
|
+
const CAPACITY_STEP = 16;
|
|
6390
|
+
const ALPHA_TEST = 0.5;
|
|
6391
|
+
function resolveTypeInfo(property) {
|
|
6392
|
+
if (property === "Texture" || property instanceof Texture) {
|
|
6393
|
+
return { glslType: "sampler2D", instantiable: false, itemSize: -1 };
|
|
6394
|
+
}
|
|
6395
|
+
else if (property === "UIColor" || property instanceof UIColor) {
|
|
6396
|
+
return { glslType: "vec4", instantiable: true, itemSize: 4 };
|
|
6397
|
+
}
|
|
6398
|
+
else if (property === "Vector2" || property instanceof Vector2) {
|
|
6399
|
+
return { glslType: "vec2", instantiable: true, itemSize: 2 };
|
|
6400
|
+
}
|
|
6401
|
+
else if (property === "Vector3" || property instanceof Vector3) {
|
|
6402
|
+
return { glslType: "vec3", instantiable: true, itemSize: 3 };
|
|
6403
|
+
}
|
|
6404
|
+
else if (property === "Vector4" || property instanceof Vector4) {
|
|
6405
|
+
return { glslType: "vec4", instantiable: true, itemSize: 4 };
|
|
6406
|
+
}
|
|
6407
|
+
else if (property === "Matrix2" || property instanceof Matrix2) {
|
|
6408
|
+
return { glslType: "mat2", instantiable: true, itemSize: 4 };
|
|
6409
|
+
}
|
|
6410
|
+
else if (property === "Matrix3" || property instanceof Matrix3) {
|
|
6411
|
+
return { glslType: "mat3", instantiable: true, itemSize: 9 };
|
|
6412
|
+
}
|
|
6413
|
+
else if (property === "Matrix4" || property instanceof Matrix4) {
|
|
6414
|
+
return { glslType: "mat4", instantiable: true, itemSize: 16 };
|
|
6415
|
+
}
|
|
6416
|
+
else if (property === "number" || typeof property === "number") {
|
|
6417
|
+
return { glslType: "float", instantiable: true, itemSize: 1 };
|
|
6418
|
+
}
|
|
6419
|
+
else {
|
|
6420
|
+
throw new Error(`Unsupported property type: ${property}`);
|
|
6421
|
+
}
|
|
6422
|
+
}
|
|
6423
|
+
function udpateProperty(value, attribute, itemOffset) {
|
|
6424
|
+
const array = attribute.array;
|
|
6425
|
+
if (value instanceof UIColor) {
|
|
6426
|
+
array[itemOffset] = value.r;
|
|
6427
|
+
array[itemOffset + ITEM_1_OFFSET] = value.g;
|
|
6428
|
+
array[itemOffset + ITEM_2_OFFSET] = value.b;
|
|
6429
|
+
array[itemOffset + ITEM_3_OFFSET] = value.a;
|
|
6430
|
+
}
|
|
6431
|
+
else if (value instanceof Vector2) {
|
|
6432
|
+
array[itemOffset] = value.x;
|
|
6433
|
+
array[itemOffset + ITEM_1_OFFSET] = value.y;
|
|
6434
|
+
}
|
|
6435
|
+
else if (value instanceof Vector3) {
|
|
6436
|
+
array[itemOffset] = value.x;
|
|
6437
|
+
array[itemOffset + ITEM_1_OFFSET] = value.y;
|
|
6438
|
+
array[itemOffset + ITEM_2_OFFSET] = value.z;
|
|
6439
|
+
}
|
|
6440
|
+
else if (value instanceof Vector4) {
|
|
6441
|
+
array[itemOffset] = value.x;
|
|
6442
|
+
array[itemOffset + ITEM_1_OFFSET] = value.y;
|
|
6443
|
+
array[itemOffset + ITEM_2_OFFSET] = value.z;
|
|
6444
|
+
array[itemOffset + ITEM_3_OFFSET] = value.w;
|
|
6445
|
+
}
|
|
6446
|
+
else if (value instanceof Matrix2) {
|
|
6447
|
+
const elements = value.elements;
|
|
6448
|
+
for (let j = 0; j < elements.length; j++) {
|
|
6449
|
+
array[itemOffset + j] = elements[j];
|
|
6450
|
+
}
|
|
6451
|
+
}
|
|
6452
|
+
else if (value instanceof Matrix3) {
|
|
6453
|
+
const elements = value.elements;
|
|
6454
|
+
for (let j = 0; j < elements.length; j++) {
|
|
6455
|
+
array[itemOffset + j] = elements[j];
|
|
6456
|
+
}
|
|
6457
|
+
}
|
|
6458
|
+
else if (value instanceof Matrix4) {
|
|
6459
|
+
const elements = value.elements;
|
|
6460
|
+
for (let j = 0; j < elements.length; j++) {
|
|
6461
|
+
array[itemOffset + j] = elements[j];
|
|
6462
|
+
}
|
|
6463
|
+
}
|
|
6464
|
+
else if (typeof value === "number") {
|
|
6465
|
+
array[itemOffset] = value;
|
|
6466
|
+
}
|
|
6467
|
+
attribute.needsUpdate = true;
|
|
6468
|
+
}
|
|
6469
|
+
function buildEmptyInstancedBufferAttribute(property, capacity) {
|
|
6470
|
+
const info = resolveTypeInfo(property);
|
|
6471
|
+
if (!info.instantiable) {
|
|
6472
|
+
throw new Error(`Invalid property type: ${property}`);
|
|
6473
|
+
}
|
|
6474
|
+
return new InstancedBufferAttribute(new Float32Array(capacity * info.itemSize), info.itemSize);
|
|
6475
|
+
}
|
|
6476
|
+
function buildMaterial(source, uniformLayout, varyingLayout, transparency) {
|
|
6477
|
+
const uniforms = {};
|
|
6478
|
+
const uniformDeclarations = [];
|
|
6479
|
+
const attributeDeclarations = [];
|
|
6480
|
+
const varyingDeclarations = [];
|
|
6481
|
+
const vertexAssignments = [];
|
|
6482
|
+
for (const [name, propertyTypeName] of Object.entries(uniformLayout)) {
|
|
6483
|
+
const glslType = resolveTypeInfo(propertyTypeName).glslType;
|
|
6484
|
+
uniforms[`u_${name}`] = { value: null };
|
|
6485
|
+
uniformDeclarations.push(`uniform ${glslType} u_${name};`);
|
|
6486
|
+
}
|
|
6487
|
+
for (const [name, propertyTypeName] of Object.entries(varyingLayout)) {
|
|
6488
|
+
const glslType = resolveTypeInfo(propertyTypeName).glslType;
|
|
6489
|
+
attributeDeclarations.push(`attribute ${glslType} a_${name};`);
|
|
6490
|
+
varyingDeclarations.push(`varying ${glslType} v_${name};`);
|
|
6491
|
+
vertexAssignments.push(`v_${name} = a_${name};`);
|
|
6492
|
+
}
|
|
6493
|
+
const vertexShader = `
|
|
6494
|
+
${attributeDeclarations.join("\n")}
|
|
6495
|
+
|
|
6496
|
+
${uniformDeclarations.join("\n")}
|
|
6497
|
+
|
|
6498
|
+
${varyingDeclarations.join("\n")}
|
|
6499
|
+
varying vec3 v_position;
|
|
6500
|
+
varying vec2 v_uv;
|
|
6501
|
+
|
|
6502
|
+
void main() {
|
|
6503
|
+
if (a_visibility < 0.5) {
|
|
6504
|
+
gl_Position = vec4(2.0, 2.0, 2.0, 2.0);
|
|
6505
|
+
return;
|
|
6506
|
+
}
|
|
6507
|
+
|
|
6508
|
+
${vertexAssignments.join("\n")}
|
|
6509
|
+
|
|
6510
|
+
v_position = position;
|
|
6511
|
+
v_uv = (a_uvTransform * vec3(uv, 1.0)).xy;
|
|
6512
|
+
|
|
6513
|
+
gl_Position = projectionMatrix * modelViewMatrix * a_instanceTransform * vec4(position, 1.0);
|
|
6514
|
+
}
|
|
6515
|
+
`;
|
|
6516
|
+
const fragmentShader = `
|
|
6517
|
+
${uniformDeclarations.join("\n")}
|
|
6518
|
+
|
|
6519
|
+
${varyingDeclarations.join("\n")}
|
|
6520
|
+
varying vec3 v_position;
|
|
6521
|
+
varying vec2 v_uv;
|
|
6522
|
+
|
|
6523
|
+
#include <alphahash_pars_fragment>
|
|
6524
|
+
|
|
6525
|
+
// Source have to define 'draw' function
|
|
6526
|
+
${source}
|
|
6527
|
+
|
|
6528
|
+
void main() {
|
|
6529
|
+
vec4 diffuseColor = draw();
|
|
6530
|
+
|
|
6531
|
+
#ifdef USE_ALPHATEST
|
|
6532
|
+
if (diffuseColor.a < v_alphaTest) {
|
|
6533
|
+
discard;
|
|
6534
|
+
}
|
|
6535
|
+
#endif
|
|
6536
|
+
|
|
6537
|
+
#ifdef USE_ALPHAHASH
|
|
6538
|
+
if (diffuseColor.a < getAlphaHashThreshold(v_position)) {
|
|
6539
|
+
discard;
|
|
6540
|
+
}
|
|
6541
|
+
#endif
|
|
6542
|
+
|
|
6543
|
+
gl_FragColor = linearToOutputTexel(diffuseColor);
|
|
6544
|
+
}
|
|
6545
|
+
`;
|
|
6546
|
+
console.log(vertexShader);
|
|
6547
|
+
console.log(fragmentShader);
|
|
6548
|
+
console.log(uniforms);
|
|
6549
|
+
return new ShaderMaterial({
|
|
6550
|
+
uniforms,
|
|
6551
|
+
vertexShader,
|
|
6552
|
+
fragmentShader,
|
|
6553
|
+
transparent: transparency === UITransparencyMode.BLEND,
|
|
6554
|
+
alphaTest: transparency === UITransparencyMode.CLIP ? ALPHA_TEST : 0.0,
|
|
6555
|
+
alphaHash: transparency === UITransparencyMode.HASH,
|
|
6556
|
+
});
|
|
6557
|
+
}
|
|
6558
|
+
class UIGenericInstancedPlane extends Mesh {
|
|
6559
|
+
constructor(source, layout, transparency = UITransparencyMode.CLIP, capacity = CAPACITY_STEP) {
|
|
6560
|
+
const uniformLayout = {};
|
|
6561
|
+
const varyingLayout = {
|
|
6562
|
+
instanceTransform: "Matrix4",
|
|
6563
|
+
uvTransform: "Matrix3",
|
|
6564
|
+
...(transparency === UITransparencyMode.CLIP
|
|
6565
|
+
? { alphaTest: "number" }
|
|
6566
|
+
: {}),
|
|
6567
|
+
};
|
|
6568
|
+
for (const [name, propertyTypeName] of Object.entries(layout)) {
|
|
6569
|
+
(resolveTypeInfo(propertyTypeName).instantiable
|
|
6570
|
+
? varyingLayout
|
|
6571
|
+
: uniformLayout)[name] = propertyTypeName;
|
|
6572
|
+
}
|
|
6573
|
+
const instancedGeometry = INSTANCED_GEOMETRY.clone();
|
|
6574
|
+
const shaderMaterial = buildMaterial(source, uniformLayout, varyingLayout, transparency);
|
|
6575
|
+
super(instancedGeometry, shaderMaterial);
|
|
6576
|
+
this.handlerToDescriptor = new Map();
|
|
6577
|
+
this.lastHandler = 0;
|
|
6578
|
+
this.capacity = 0;
|
|
6579
|
+
this.propertyBuffers = new Map();
|
|
6580
|
+
this._private_instancedGeometry = instancedGeometry;
|
|
6581
|
+
this._private_instancedGeometry.instanceCount = 0;
|
|
6582
|
+
this._private_shaderMaterial = shaderMaterial;
|
|
6583
|
+
this.capacity = Math.max(capacity, CAPACITY_STEP);
|
|
6584
|
+
for (const [name, propertyTypeName] of Object.entries(varyingLayout)) {
|
|
6585
|
+
const attribute = buildEmptyInstancedBufferAttribute(propertyTypeName, this.capacity);
|
|
6586
|
+
this._private_instancedGeometry.setAttribute(`a_${name}`, attribute);
|
|
6587
|
+
this.propertyBuffers.set(`a_${name}`, attribute);
|
|
6588
|
+
}
|
|
6589
|
+
}
|
|
6590
|
+
createInstances(count) {
|
|
6591
|
+
const handler = this.lastHandler++;
|
|
6592
|
+
if (this._private_instancedGeometry.instanceCount + count > this.capacity) {
|
|
6593
|
+
this._private_resizeGeometry(Math.ceil((this.capacity + count) / CAPACITY_STEP) * CAPACITY_STEP);
|
|
6594
|
+
}
|
|
6595
|
+
this.handlerToDescriptor.set(handler, {
|
|
6596
|
+
firstIndex: this._private_instancedGeometry.instanceCount,
|
|
6597
|
+
count,
|
|
6598
|
+
});
|
|
6599
|
+
this._private_instancedGeometry.instanceCount += count;
|
|
6600
|
+
return handler;
|
|
6601
|
+
}
|
|
6602
|
+
destroyInstances(handler) {
|
|
6603
|
+
const releasedDescriptor = this.handlerToDescriptor.get(handler);
|
|
6604
|
+
if (releasedDescriptor === undefined) {
|
|
6605
|
+
throw new Error(`No range found for userIndex: ${handler}`);
|
|
6606
|
+
}
|
|
6607
|
+
this.handlerToDescriptor.delete(handler);
|
|
6608
|
+
const values = Array.from(this.handlerToDescriptor.values());
|
|
6609
|
+
const edge = releasedDescriptor.firstIndex + releasedDescriptor.count;
|
|
6610
|
+
let replacementDescriptor;
|
|
6611
|
+
for (let i = values.length - 1; i > edge; i--) {
|
|
6612
|
+
const descriptor = values[i];
|
|
6613
|
+
if (descriptor.count === releasedDescriptor.count) {
|
|
6614
|
+
replacementDescriptor = descriptor;
|
|
6615
|
+
break;
|
|
6616
|
+
}
|
|
6617
|
+
}
|
|
6618
|
+
if (replacementDescriptor) {
|
|
6619
|
+
this._private_copyRangeData(replacementDescriptor, releasedDescriptor);
|
|
6620
|
+
replacementDescriptor.firstIndex = releasedDescriptor.firstIndex;
|
|
6621
|
+
this._private_shiftRangesDown(replacementDescriptor.firstIndex + replacementDescriptor.count, replacementDescriptor.count);
|
|
6622
|
+
}
|
|
6623
|
+
else {
|
|
6624
|
+
this._private_shiftRangesDown(releasedDescriptor.firstIndex + releasedDescriptor.count, releasedDescriptor.count);
|
|
6625
|
+
}
|
|
6626
|
+
this._private_instancedGeometry.instanceCount -= releasedDescriptor.count;
|
|
6627
|
+
}
|
|
6628
|
+
updateProperties(handler, offset, instancesProperties) {
|
|
6629
|
+
assertValidNonNegativeNumber(offset, "UIGenericInstancedPlane updateProperties offset");
|
|
6630
|
+
const descriptor = this._private_resolveDescriptor(handler);
|
|
6631
|
+
if (instancesProperties.length + offset > descriptor.count) {
|
|
6632
|
+
throw new Error(`Too many instances for handler: ${handler}, offset: ${offset}, and count: ${instancesProperties.length}`);
|
|
6633
|
+
}
|
|
6634
|
+
for (let i = 0; i < instancesProperties.length; i++) {
|
|
6635
|
+
const instanceProperties = instancesProperties[i];
|
|
6636
|
+
const instanceOffset = descriptor.firstIndex + offset + i;
|
|
6637
|
+
for (const [name, value] of Object.entries(instanceProperties)) {
|
|
6638
|
+
if (resolveTypeInfo(value).instantiable) {
|
|
6639
|
+
const attribute = this._private_resolveBufferAttribute(name);
|
|
6640
|
+
const itemOffset = instanceOffset * attribute.itemSize;
|
|
6641
|
+
udpateProperty(value, attribute, itemOffset);
|
|
6642
|
+
}
|
|
6643
|
+
else {
|
|
6644
|
+
const uniform = this._private_resolveUniform(name);
|
|
6645
|
+
uniform.value = value;
|
|
6646
|
+
this._private_shaderMaterial.uniformsNeedUpdate = true;
|
|
6647
|
+
}
|
|
6648
|
+
}
|
|
6649
|
+
}
|
|
6650
|
+
}
|
|
6651
|
+
updateTransforms(handler, offset, instancesTransforms) {
|
|
6652
|
+
assertValidNonNegativeNumber(offset, "UIGenericInstancedPlane updateTransforms offset");
|
|
6653
|
+
const descriptor = this._private_resolveDescriptor(handler);
|
|
6654
|
+
if (instancesTransforms.length + offset > descriptor.count) {
|
|
6655
|
+
throw new Error(`Too many instances for handler: ${handler}, offset: ${offset}, and count: ${instancesTransforms.length}`);
|
|
6656
|
+
}
|
|
6657
|
+
for (let i = 0; i < instancesTransforms.length; i++) {
|
|
6658
|
+
const attribute = this._private_resolveBufferAttribute("instanceTransform");
|
|
6659
|
+
const instanceOffset = descriptor.firstIndex + offset + i;
|
|
6660
|
+
const array = attribute.array;
|
|
6661
|
+
const itemOffset = instanceOffset * attribute.itemSize;
|
|
6662
|
+
const elements = instancesTransforms[i].elements;
|
|
6663
|
+
for (let j = 0; j < elements.length; j++) {
|
|
6664
|
+
array[itemOffset + j] = elements[j];
|
|
6665
|
+
}
|
|
6666
|
+
attribute.needsUpdate = true;
|
|
6667
|
+
}
|
|
6668
|
+
}
|
|
6669
|
+
updateUVTransforms(handler, offset, uvTransforms) {
|
|
6670
|
+
assertValidNonNegativeNumber(offset, "UIGenericInstancedPlane updateUVTransforms offset");
|
|
6671
|
+
const descriptor = this._private_resolveDescriptor(handler);
|
|
6672
|
+
if (uvTransforms.length + offset > descriptor.count) {
|
|
6673
|
+
throw new Error(`Too many instances for handler: ${handler}, offset: ${offset}, and count: ${uvTransforms.length}`);
|
|
6674
|
+
}
|
|
6675
|
+
for (let i = 0; i < uvTransforms.length; i++) {
|
|
6676
|
+
const attribute = this._private_resolveBufferAttribute("uvTransform");
|
|
6677
|
+
const instanceOffset = descriptor.firstIndex + offset + i;
|
|
6678
|
+
const array = attribute.array;
|
|
6679
|
+
const itemOffset = instanceOffset * attribute.itemSize;
|
|
6680
|
+
const elements = uvTransforms[i].elements;
|
|
6681
|
+
for (let j = 0; j < elements.length; j++) {
|
|
6682
|
+
array[itemOffset + j] = elements[j];
|
|
6683
|
+
}
|
|
6684
|
+
attribute.needsUpdate = true;
|
|
6685
|
+
}
|
|
6686
|
+
}
|
|
6687
|
+
updateVisibility(handler, offset, instancesVisibility) {
|
|
6688
|
+
assertValidNonNegativeNumber(offset, "UIGenericInstancedPlane updateVisibility offset");
|
|
6689
|
+
const descriptor = this._private_resolveDescriptor(handler);
|
|
6690
|
+
if (instancesVisibility.length + offset > descriptor.count) {
|
|
6691
|
+
throw new Error(`Too many instances for handler: ${handler}, offset: ${offset}, and count: ${instancesVisibility.length}`);
|
|
6692
|
+
}
|
|
6693
|
+
for (let i = 0; i < instancesVisibility.length; i++) {
|
|
6694
|
+
const attribute = this._private_resolveBufferAttribute("visibility");
|
|
6695
|
+
const instanceOffset = descriptor.firstIndex + offset + i;
|
|
6696
|
+
const array = attribute.array;
|
|
6697
|
+
const itemOffset = instanceOffset * attribute.itemSize;
|
|
6698
|
+
array[itemOffset] = instancesVisibility[i] ? 1 : 0;
|
|
6699
|
+
attribute.needsUpdate = true;
|
|
6700
|
+
}
|
|
6701
|
+
}
|
|
6702
|
+
destroy() {
|
|
6703
|
+
this._private_instancedGeometry.dispose();
|
|
6704
|
+
this._private_shaderMaterial.dispose();
|
|
6705
|
+
}
|
|
6706
|
+
_private_resolveDescriptor(handler) {
|
|
6707
|
+
const descriptor = this.handlerToDescriptor.get(handler);
|
|
6708
|
+
if (descriptor === undefined) {
|
|
6709
|
+
throw new Error(`No active range found for handler: ${handler}`);
|
|
6710
|
+
}
|
|
6711
|
+
return descriptor;
|
|
6712
|
+
}
|
|
6713
|
+
_private_resolveBufferAttribute(name) {
|
|
6714
|
+
const attribute = this.propertyBuffers.get(`a_${name}`);
|
|
6715
|
+
if (attribute === undefined) {
|
|
6716
|
+
throw new Error(`No attribute found for property: ${name} (a_${name})`);
|
|
6717
|
+
}
|
|
6718
|
+
return attribute;
|
|
6719
|
+
}
|
|
6720
|
+
_private_resolveUniform(name) {
|
|
6721
|
+
const uniform = this._private_shaderMaterial.uniforms[`u_${name}`];
|
|
6722
|
+
if (uniform === undefined) {
|
|
6723
|
+
throw new Error(`No uniform found for handler: ${name}`);
|
|
6724
|
+
}
|
|
6725
|
+
return uniform;
|
|
6726
|
+
}
|
|
6727
|
+
_private_resizeGeometry(newCapacity) {
|
|
6728
|
+
for (const [name, oldAttribute] of this.propertyBuffers.entries()) {
|
|
6729
|
+
const itemSize = oldAttribute.itemSize;
|
|
6730
|
+
const newArray = new Float32Array(newCapacity * itemSize);
|
|
6731
|
+
newArray.set(oldAttribute.array);
|
|
6732
|
+
const newAttribute = new InstancedBufferAttribute(newArray, itemSize);
|
|
6733
|
+
this._private_instancedGeometry.setAttribute(`a_${name}`, newAttribute);
|
|
6734
|
+
this.propertyBuffers.set(`a_${name}`, newAttribute);
|
|
6735
|
+
}
|
|
6736
|
+
this.capacity = newCapacity;
|
|
6737
|
+
}
|
|
6738
|
+
_private_copyRangeData(sourceRange, targetRange) {
|
|
6739
|
+
for (const attribute of this.propertyBuffers.values()) {
|
|
6740
|
+
const array = attribute.array;
|
|
6741
|
+
const itemSize = attribute.itemSize;
|
|
6742
|
+
const sourceStart = sourceRange.firstIndex * itemSize;
|
|
6743
|
+
const targetStart = targetRange.firstIndex * itemSize;
|
|
6744
|
+
const dataLength = sourceRange.count * itemSize;
|
|
6745
|
+
for (let i = 0; i < dataLength; i++) {
|
|
6746
|
+
array[targetStart + i] = array[sourceStart + i];
|
|
6747
|
+
}
|
|
6748
|
+
attribute.needsUpdate = true;
|
|
6749
|
+
}
|
|
6750
|
+
}
|
|
6751
|
+
_private_shiftRangesDown(startIndex, shiftAmount) {
|
|
6752
|
+
for (const descriptor of this.handlerToDescriptor.values()) {
|
|
6753
|
+
if (descriptor.firstIndex >= startIndex) {
|
|
6754
|
+
descriptor.firstIndex -= shiftAmount;
|
|
6755
|
+
}
|
|
6756
|
+
}
|
|
6757
|
+
for (const attribute of this.propertyBuffers.values()) {
|
|
6758
|
+
const array = attribute.array;
|
|
6759
|
+
const itemSize = attribute.itemSize;
|
|
6760
|
+
const startByteIndex = startIndex * itemSize;
|
|
6761
|
+
const endByteIndex = this._private_instancedGeometry.instanceCount * itemSize;
|
|
6762
|
+
const shiftByteAmount = shiftAmount * itemSize;
|
|
6763
|
+
for (let i = startByteIndex; i < endByteIndex - shiftByteAmount; i++) {
|
|
6764
|
+
array[i] = array[i + shiftByteAmount];
|
|
6765
|
+
}
|
|
6766
|
+
attribute.needsUpdate = true;
|
|
6767
|
+
}
|
|
6768
|
+
}
|
|
6769
|
+
}
|
|
6770
|
+
|
|
6342
6771
|
function isUITextSpan(obj) {
|
|
6343
6772
|
return (obj !== null &&
|
|
6344
6773
|
typeof obj === "object" &&
|
|
@@ -6347,5 +6776,5 @@ function isUITextSpan(obj) {
|
|
|
6347
6776
|
(!("style" in obj) || isUITextStyle(obj.style)));
|
|
6348
6777
|
}
|
|
6349
6778
|
|
|
6350
|
-
export { UIAnchor, UIAspectConstraint, UIColor, UIColorEvent, UIConstraint, UIConstraint2DBuilder, UICoverConstraintBuilder, UICustomConstraint, UIDummy, UIElement, UIExpression, UIFitConstraintBuilder, UIFullscreenLayer, UIHeightConstraint, UIHorizontalDistanceConstraint, UIHorizontalProportionConstraint, UIImage, UIInputEvent, UILayer, UILayerEvent, UIMicro, UIMicroAnchorMode, UIMode, UINineSlice, UIOrientation, UIPriority, UIProgress, UIProgressMaskFunction, UIRelation, UIScene, UISceneUpdateMode, UISingleParameterConstraint, UIText, UITransparencyMode, UIVerticalDistanceConstraint, UIVerticalProportionConstraint, UIWidthConstraint, convertPriority, convertRelation, isUITextSpan, isUITextStyle, resolveOrientation, resolvePriority, resolveRelation, resolveTextPadding, resolveTextStyle };
|
|
6779
|
+
export { UIAnchor, UIAspectConstraint, UIColor, UIColorEvent, UIConstraint, UIConstraint2DBuilder, UICoverConstraintBuilder, UICustomConstraint, UIDummy, UIElement, UIExpression, UIFitConstraintBuilder, UIFullscreenLayer, UIGenericInstancedPlane, UIHeightConstraint, UIHorizontalDistanceConstraint, UIHorizontalProportionConstraint, UIImage, UIInputEvent, UILayer, UILayerEvent, UIMicro, UIMicroAnchorMode, UIMode, UINineSlice, UIOrientation, UIPriority, UIProgress, UIProgressMaskFunction, UIRelation, UIScene, UISceneUpdateMode, UISingleParameterConstraint, UIText, UITransparencyMode, UIVerticalDistanceConstraint, UIVerticalProportionConstraint, UIWidthConstraint, convertPriority, convertRelation, isUITextSpan, isUITextStyle, resolveOrientation, resolvePriority, resolveRelation, resolveTextPadding, resolveTextStyle };
|
|
6351
6780
|
//# sourceMappingURL=index.js.map
|