@woosh/meep-engine 2.33.24 → 2.33.28

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 (126) hide show
  1. package/core/binary/BitSet.js +151 -167
  2. package/core/binary/BitSet.spec.js +99 -1
  3. package/core/binary/ValidatingBitSetWrapper.js +81 -0
  4. package/core/bvh2/aabb3/AABB3.js +3 -10
  5. package/core/bvh2/binary/IndexedBinaryBVH.js +1 -1
  6. package/core/bvh2/traversal/ThreeClippingPlaneComputingBVHVisitor.js +5 -1
  7. package/core/bvh2/traversal/__detailed_box_volume_intersection.js +22 -5
  8. package/core/cache/Cache.d.ts +4 -2
  9. package/core/cache/Cache.js +5 -2
  10. package/core/collection/HashMap.d.ts +9 -2
  11. package/core/collection/HashSet.d.ts +7 -2
  12. package/core/collection/HashSet.js +7 -2
  13. package/core/collection/array/binarySearchHighIndex.js +1 -1
  14. package/core/collection/array/copyArray.js +2 -2
  15. package/core/collection/array/typed/typed_array_copy.js +1 -1
  16. package/core/geom/3d/frustum/array_setFromProjectionMatrix.js +3 -3
  17. package/core/geom/3d/normal/hemioct/unit_hemioct.spec.js +1 -1
  18. package/core/geom/3d/shape/AbstractShape3D.js +37 -1
  19. package/core/geom/3d/shape/TransformedShape3D.js +121 -10
  20. package/core/geom/3d/shape/TransformedShape3D.spec.js +33 -0
  21. package/core/geom/3d/shape/UnionShape3D.js +255 -0
  22. package/core/geom/3d/shape/UnitCubeShape3D.js +88 -0
  23. package/core/geom/3d/shape/UnitCubeShape3D.spec.js +42 -0
  24. package/core/geom/3d/shape/UnitSphereShape3D.js +39 -0
  25. package/core/geom/3d/shape/util/compute_signed_distance_gradient_by_sampling.js +48 -0
  26. package/core/geom/3d/shape/util/shape_to_visual_entity.js +159 -0
  27. package/core/geom/random/randomPointInSphere.js +3 -2
  28. package/core/json/resolvePathByArray.js +2 -2
  29. package/core/model/ObservedBoolean.d.ts +2 -0
  30. package/core/parser/simple/Token.d.ts +13 -0
  31. package/core/parser/simple/Token.js +61 -27
  32. package/{engine/graphics/render/forward_plus/materials → core/primitives/strings}/insert_after.js +3 -0
  33. package/core/primitives/strings/insert_after_or_replace.js +27 -0
  34. package/editor/process/symbolic/makeHelperBoxGeometry.js +44 -0
  35. package/editor/tools/FoliagePaintTool.js +4 -4
  36. package/editor/view/ecs/EntityEditor.js +2 -2
  37. package/editor/view/ecs/components/particles/ParticleEmitterController.js +2 -2
  38. package/engine/EngineHarness.js +1 -0
  39. package/engine/animation/AnimationUtils.js +5 -5
  40. package/engine/asset/loaders/GLTFAssetLoader.js +52 -1
  41. package/engine/asset/loaders/image/ImageDecoderWorker.js +4 -3
  42. package/engine/asset/loaders/image/ImageRGBADataAsset.js +3 -2
  43. package/engine/asset/loaders/image/ImageRGBADataLoader.js +3 -3
  44. package/engine/asset/loaders/image/codec/NativeImageDecoder.js +2 -1
  45. package/engine/asset/loaders/image/png/PNG.js +113 -6
  46. package/engine/asset/loaders/image/png/PNGReader.js +5 -0
  47. package/engine/asset/loaders/material/bitmap2sampler_gl.js +1 -1
  48. package/engine/asset/loaders/material/computeImageBitmapEquality.js +6 -1
  49. package/engine/asset/loaders/material/computeTextureEquality.js +40 -49
  50. package/engine/ecs/EntityBuilder.js +25 -5
  51. package/engine/ecs/EntityComponentDataset.js +1 -1
  52. package/engine/ecs/attachment/AttachmentBinding.js +8 -0
  53. package/engine/ecs/attachment/AttachmentSystem.js +4 -0
  54. package/engine/ecs/attachment/TransformAttachmentBinding.js +14 -44
  55. package/engine/ecs/components/Tag.js +27 -6
  56. package/engine/ecs/foliage/InstancedFoliage.js +277 -266
  57. package/engine/ecs/foliage/ecs/Foliage2System.js +7 -7
  58. package/engine/ecs/foliage/ecs/InstancedMeshComponent.js +37 -0
  59. package/engine/ecs/foliage/ecs/{Foliage2.js → InstancedMeshLayer.js} +3 -45
  60. package/engine/ecs/foliage/ecs/InstancedMeshSerializationAdapter.js +6 -5
  61. package/engine/ecs/foliage/ecs/InstancedMeshUtils.js +7 -6
  62. package/engine/ecs/fow/FogOfWar.js +4 -0
  63. package/engine/ecs/fow/FogOfWarSystem.js +2 -0
  64. package/engine/ecs/gui/hud/HeadsUpDisplaySystem.js +2 -0
  65. package/engine/ecs/storage/binary/BinarySerializationRegistry.js +1 -1
  66. package/engine/ecs/system/AbstractContextSystem.js +1 -1
  67. package/engine/ecs/systems/TagSystem.js +17 -0
  68. package/engine/ecs/terrain/ecs/layers/TerrainLayer.js +12 -16
  69. package/engine/ecs/transform/Transform.js +19 -6
  70. package/engine/graphics/GraphicsEngine.js +11 -6
  71. package/engine/graphics/composit/CompositLayer.js +17 -4
  72. package/engine/graphics/composit/CompositingStages.js +8 -0
  73. package/engine/graphics/composit/LayerCompositer.js +35 -6
  74. package/engine/graphics/ecs/highlight/plugin/OutlineRenderPlugin.js +11 -7
  75. package/engine/graphics/ecs/light/Light.js +2 -0
  76. package/engine/graphics/ecs/light/binding/three/ThreeLightBinding.js +5 -1
  77. package/engine/graphics/ecs/mesh-v2/DrawMode.js +5 -0
  78. package/engine/graphics/ecs/mesh-v2/ShadedGeometry.js +32 -18
  79. package/engine/graphics/geometry/instancing/InstancedMeshGroup.js +14 -72
  80. package/engine/graphics/geometry/instancing/rewriteMaterial.js +70 -0
  81. package/engine/graphics/material/manager/MaterialManager.js +2 -1
  82. package/engine/graphics/micron/render/instanced/AttributeDataTexture.js +6 -4
  83. package/engine/graphics/micron/render/instanced/ThreeInstancedAdapter.js +0 -2
  84. package/engine/graphics/particles/ParticleEmitterLibrary.js +3 -0
  85. package/engine/graphics/particles/ecs/{ParticleEmitterSystem2.js → ParticleEmitterSystem.js} +17 -9
  86. package/engine/graphics/particles/particular/engine/ParticularEngine.js +8 -2
  87. package/engine/graphics/particles/particular/engine/emitter/ParticleEmitter.js +14 -25
  88. package/engine/graphics/particles/particular/engine/emitter/ParticleEmitterFlag.js +5 -0
  89. package/engine/graphics/particles/particular/engine/emitter/ParticlePool.js +90 -2
  90. package/engine/graphics/particles/particular/engine/emitter/ParticlePool.spec.js +7 -7
  91. package/engine/graphics/particles/particular/engine/renderers/billboard/BILLBOARD_PARTICLE_SPECIFICATION.js +15 -12
  92. package/engine/graphics/particles/particular/engine/renderers/billboard/ParticleBillboardMaterial.js +262 -51
  93. package/engine/graphics/particles/particular/engine/shader/ShaderManager.js +81 -48
  94. package/engine/graphics/particles/particular/engine/shader/debugAtlas.js +14 -0
  95. package/engine/graphics/particles/particular/engine/utils/volume/AttributeValue.js +141 -0
  96. package/engine/graphics/particles/particular/engine/utils/volume/ParticleVolume.js +148 -54
  97. package/engine/graphics/particles/particular/engine/utils/volume/lut_to_sampler.js +27 -0
  98. package/engine/graphics/particles/particular/engine/utils/volume/prototypeParticleVolume.js +544 -164
  99. package/engine/graphics/render/buffer/simple-fx/ao/AmbientOcclusionPostProcessEffect.js +15 -10
  100. package/engine/graphics/render/forward_plus/materials/FP_INJECTION_POINT_ACCUMULATION.js +1 -0
  101. package/engine/graphics/render/forward_plus/materials/FP_SHADER_CHUNK_ACCUMULATION.js +32 -0
  102. package/engine/graphics/render/forward_plus/materials/FP_SHADER_CHUNK_DECODE_PARS.js +51 -0
  103. package/engine/graphics/render/forward_plus/materials/FP_SHADER_CHUNK_PREAMBLE.js +25 -0
  104. package/engine/graphics/render/forward_plus/materials/FPlusDebugMaterial.js +3 -3
  105. package/engine/graphics/render/forward_plus/materials/ForwardPlusThreeMaterial.js +1 -1
  106. package/engine/graphics/render/forward_plus/materials/fp_build_fragment_shader.js +31 -120
  107. package/engine/graphics/render/forward_plus/materials/fp_build_vertex_lighting_shared.js +35 -0
  108. package/engine/graphics/render/forward_plus/materials/fp_build_vertex_shader.js +4 -5
  109. package/engine/graphics/render/forward_plus/plugin/MaterialTransformer.js +10 -3
  110. package/engine/graphics/render/forward_plus/plugin/ptototypeFPPlugin.js +588 -53
  111. package/engine/graphics/render/forward_plus/prototypeLightManager.js +31 -6
  112. package/engine/graphics/render/forward_plus/query/point_light_inside_volume.js +10 -9
  113. package/engine/graphics/shaders/TerrainShader.js +4 -5
  114. package/engine/graphics/shadows/ShadowMapRenderer.js +8 -2
  115. package/engine/graphics/texture/atlas/ManagedTextureAtlas.js +12 -1
  116. package/engine/graphics/texture/sampler/Sampler2D.js +3 -1
  117. package/engine/graphics/texture/sampler/convertTexture2Sampler2D.js +1 -1
  118. package/engine/graphics/texture/sampler/copy_Sampler2D_channel_data.js +66 -0
  119. package/engine/graphics/util/composeMatrix4.js +33 -23
  120. package/engine/graphics/util/decompose_matrix_4_array.js +61 -0
  121. package/engine/intelligence/behavior/ecs/BehaviorComponent.js +30 -14
  122. package/engine/knowledge/database/StaticKnowledgeDataTable.js +6 -1
  123. package/engine/navigation/ecs/components/Path.js +0 -5
  124. package/package.json +1 -1
  125. package/view/minimap/gl/MinimapWorldGL.js +12 -5
  126. package/core/geom/3d/shape/CompositeShape.js +0 -60
@@ -0,0 +1,13 @@
1
+ export class Token<V = string, T = string> {
2
+ readonly value: V
3
+ readonly start: number
4
+ readonly end: number
5
+ readonly name: string
6
+ readonly type: T
7
+
8
+ constructor(value: V, start: number, end: number, name: string, type: T)
9
+
10
+ equals(other: Token<V, T>): boolean
11
+
12
+ hash(): number
13
+ }
@@ -1,31 +1,65 @@
1
- function Token(value, start, end, name, type) {
2
- this.value = value;
3
- this.start = start;
4
- this.end = end;
5
- this.name = name;
6
- this.type = type;
7
- }
1
+ class Token {
2
+ /**
3
+ * @template V,T
4
+ * @param {V} value
5
+ * @param {number} start
6
+ * @param {number} end
7
+ * @param {string} name
8
+ * @param {T} type
9
+ */
10
+ constructor(value, start, end, name, type) {
11
+ /**
12
+ * @readonly
13
+ * @type {V}
14
+ */
15
+ this.value = value;
16
+ /**
17
+ * Starting position in the input
18
+ * @readonly
19
+ * @type {number}
20
+ */
21
+ this.start = start;
22
+ /**
23
+ * End position in the input
24
+ * @readonly
25
+ * @type {number}
26
+ */
27
+ this.end = end;
28
+ /**
29
+ * @readonly
30
+ * @type {string}
31
+ */
32
+ this.name = name;
33
+ /**
34
+ * Token type
35
+ * @readonly
36
+ * @type {T}
37
+ */
38
+ this.type = type;
39
+ }
8
40
 
9
- /**
10
- *
11
- * @param {Token} other
12
- * @returns {boolean}
13
- */
14
- Token.prototype.equals = function (other) {
15
- return this.value === other.value &&
16
- this.start === other.start &&
17
- this.end === other.end &&
18
- this.name === other.name &&
19
- this.type === other.type
20
- ;
21
- };
41
+ /**
42
+ *
43
+ * @param {Token} other
44
+ * @returns {boolean}
45
+ */
46
+ equals(other) {
47
+ return this.value === other.value &&
48
+ this.start === other.start &&
49
+ this.end === other.end &&
50
+ this.name === other.name &&
51
+ this.type === other.type
52
+ ;
53
+ }
22
54
 
23
- /**
24
- *
25
- * @return {number}
26
- */
27
- Token.prototype.hash = function () {
28
- return 0;
29
- };
55
+ /**
56
+ *
57
+ * @return {number}
58
+ */
59
+ hash() {
60
+ // TODO make an actual hash
61
+ return 0;
62
+ }
63
+ }
30
64
 
31
65
  export default Token;
@@ -3,6 +3,7 @@
3
3
  * @param {string} source
4
4
  * @param {string} term
5
5
  * @param {string} extra
6
+ * @returns {string}
6
7
  */
7
8
  export function insert_after(source, term, extra) {
8
9
  const i = source.indexOf(term);
@@ -16,3 +17,5 @@ export function insert_after(source, term, extra) {
16
17
 
17
18
  return source.slice(0, end) + extra + source.slice(end);
18
19
  }
20
+
21
+
@@ -0,0 +1,27 @@
1
+ /**
2
+ *
3
+ * @param {string} source
4
+ * @param {string} insert_term
5
+ * @param {string} replace_term
6
+ * @param {string} value
7
+ * @returns {string}
8
+ */
9
+ export function insert_after_or_replace(source, insert_term, replace_term, value) {
10
+ const insert_term_index = source.indexOf(insert_term);
11
+
12
+ if (insert_term_index !== -1) {
13
+ const end = insert_term_index + insert_term.length;
14
+ return source.slice(0, end) + value + source.slice(end);
15
+ }
16
+
17
+ const replace_term_index = source.indexOf(replace_term);
18
+
19
+ if (replace_term_index === -1) {
20
+ // not found
21
+ console.warn(`Neither insert term '${insert_term}', nor replacement term '${replace_term}' were found in the source`, source, value);
22
+ return source;
23
+ }
24
+
25
+
26
+ return source.slice(0, replace_term_index) + value + source.slice(replace_term_index + replace_term.length);
27
+ }
@@ -0,0 +1,44 @@
1
+ import { BufferAttribute, BufferGeometry, Float32BufferAttribute } from "three";
2
+
3
+ export function makeHelperBoxGeometry(sx = 1, sy = 1, sz = 1) {
4
+
5
+ const geometry = new BufferGeometry();
6
+
7
+ const dx = sx / 2;
8
+ const dy = sy / 2;
9
+ const dz = sz / 2;
10
+
11
+ const vertices = new Float32Array([
12
+ -dx, -dy, -dz,
13
+ dx, -dy, -dz,
14
+ dx, dy, -dz,
15
+ -dx, dy, -dz,
16
+
17
+ -dx, dy, dz,
18
+ dx, dy, dz,
19
+ dx, -dy, dz,
20
+ -dx, -dy, dz
21
+ ]);
22
+
23
+ geometry.setAttribute("position", new Float32BufferAttribute(vertices, 3));
24
+
25
+ geometry.setIndex(new BufferAttribute(new Uint8Array([
26
+ 0, 1,
27
+ 1, 2,
28
+ 2, 3,
29
+ 3, 0,
30
+
31
+ 4, 5,
32
+ 5, 6,
33
+ 6, 7,
34
+ 7, 4,
35
+
36
+
37
+ 0, 7,
38
+ 1, 6,
39
+ 2, 5,
40
+ 3, 4
41
+ ]), 1, false));
42
+
43
+ return geometry;
44
+ }
@@ -6,7 +6,7 @@ import { parseHex } from "../../core/color/ColorUtils.js";
6
6
  import Vector4 from "../../core/geom/Vector4.js";
7
7
  import loadSampler2D from "../../engine/graphics/texture/sampler/loadSampler2D.js";
8
8
  import convertSampler2D2Canvas from "../../engine/graphics/texture/sampler/Sampler2D2Canvas.js";
9
- import { Foliage2 } from "../../engine/ecs/foliage/ecs/Foliage2.js";
9
+ import { InstancedMeshComponent } from "../../engine/ecs/foliage/ecs/InstancedMeshComponent.js";
10
10
 
11
11
  class FoliagePaintTool extends Tool {
12
12
  constructor() {
@@ -100,7 +100,7 @@ class FoliagePaintTool extends Tool {
100
100
 
101
101
  /**
102
102
  *
103
- * @param {Foliage2} foliage
103
+ * @param {InstancedMeshComponent} foliage
104
104
  * @param {Number} entity
105
105
  */
106
106
  function visit(foliage, entity) {
@@ -149,9 +149,9 @@ class FoliagePaintTool extends Tool {
149
149
 
150
150
  /**
151
151
  *
152
- * @type {Foliage2}
152
+ * @type {InstancedMeshComponent}
153
153
  */
154
- const foliage = entityManger.getComponent(entity, Foliage2);
154
+ const foliage = entityManger.getComponent(entity, InstancedMeshComponent);
155
155
 
156
156
 
157
157
  if (foliage === null) {
@@ -38,7 +38,7 @@ import { HeadsUpDisplayController } from "./components/HeadsUpDisplayController.
38
38
  import { BlackboardController } from "./components/BlackboardController.js";
39
39
  import { GridObstacleController } from "./components/GridObstacleController.js";
40
40
  import { AttachmentSocketsController } from "./components/sockets/AttachmentSocketsController.js";
41
- import { ParticleEmitterSystem2 } from "../../../engine/graphics/particles/ecs/ParticleEmitterSystem2.js";
41
+ import { ParticleEmitterSystem } from "../../../engine/graphics/particles/ecs/ParticleEmitterSystem.js";
42
42
 
43
43
  /**
44
44
  *
@@ -82,7 +82,7 @@ function prepareComponentFactory(factory, editor) {
82
82
  .register('ParticleEmitter', () => {
83
83
  const em = editor.engine.entityManager;
84
84
 
85
- const particleEmitterSystem = em.getSystem(ParticleEmitterSystem2);
85
+ const particleEmitterSystem = em.getSystem(ParticleEmitterSystem);
86
86
 
87
87
  return new ParticleEmitterController(particleEmitterSystem);
88
88
  })
@@ -24,7 +24,7 @@ export function enumNameByValue(value, enumerable) {
24
24
  /**
25
25
  *
26
26
  * @param {ParticleEmitter} emitter
27
- * @param {ParticleEmitterSystem2} system
27
+ * @param {ParticleEmitterSystem} system
28
28
  * @param {function} op
29
29
  * @param {*} [arg0]
30
30
  */
@@ -61,7 +61,7 @@ function applyEmitterChanges(emitter, system, op, arg0) {
61
61
  export class ParticleEmitterController extends EmptyView {
62
62
  /**
63
63
  *
64
- * @param {ParticleEmitterSystem2} particleEmitterSystem
64
+ * @param {ParticleEmitterSystem} particleEmitterSystem
65
65
  * @constructor
66
66
  */
67
67
  constructor(particleEmitterSystem) {
@@ -367,6 +367,7 @@ export class EngineHarness {
367
367
  sensitivity
368
368
  });
369
369
 
370
+ eb.add(Tag.fromJSON(['CameraController']));
370
371
  eb.add(SerializationMetadata.Transient);
371
372
 
372
373
  eb.build(ecd);
@@ -7,7 +7,7 @@ import { removeComponentsExcept } from "../ecs/util/removeComponentsExcept.js";
7
7
  import { createSound, createTimer } from "../EntityCreator.js";
8
8
  import Mesh from "../graphics/ecs/mesh/Mesh.js";
9
9
  import Trail2D, { Trail2DFlags } from "../graphics/ecs/trail2d/Trail2D.js";
10
- import { ParticleEmitterSystem2 } from "../graphics/particles/ecs/ParticleEmitterSystem2.js";
10
+ import { ParticleEmitterSystem } from "../graphics/particles/ecs/ParticleEmitterSystem.js";
11
11
  import { ParticleEmitter } from "../graphics/particles/particular/engine/emitter/ParticleEmitter.js";
12
12
  import { ParticleEmitterFlag } from "../graphics/particles/particular/engine/emitter/ParticleEmitterFlag.js";
13
13
  import { distributeParticlesOnObject3D } from "../graphics/particles/particular/engine/utils/distributeParticlesOnObject3D.js";
@@ -137,9 +137,9 @@ export function removeEntityWithMeshParticlesEffect(
137
137
 
138
138
  /**
139
139
  *
140
- * @type {ParticleEmitterSystem2}
140
+ * @type {ParticleEmitterSystem}
141
141
  */
142
- const sPE = entityManager.getSystem(ParticleEmitterSystem2);
142
+ const sPE = entityManager.getSystem(ParticleEmitterSystem);
143
143
 
144
144
  /**
145
145
  *
@@ -214,9 +214,9 @@ export function removeEntityGenericEffect(
214
214
 
215
215
  /**
216
216
  *
217
- * @type {ParticleEmitterSystem2}
217
+ * @type {ParticleEmitterSystem}
218
218
  */
219
- const sPE = engine.entityManager.getSystem(ParticleEmitterSystem2);
219
+ const sPE = engine.entityManager.getSystem(ParticleEmitterSystem);
220
220
 
221
221
  /**
222
222
  *
@@ -24,10 +24,42 @@ import { HashSet } from "../../../core/collection/HashSet.js";
24
24
  import { computeGeometryHash } from "./geometry/geometry/computeGeometryHash.js";
25
25
  import { computeGeometryEquality } from "./geometry/geometry/computeGeometryEquality.js";
26
26
  import { traverseThreeObject } from "../../graphics/ecs/highlight/renderer/traverseThreeObject.js";
27
+ import { computeTextureHash } from "./material/computeTextureHash.js";
28
+ import { computeTextureEquality } from "./material/computeTextureEquality.js";
27
29
 
28
30
  const animationOptimizer = new AnimationOptimizer();
29
31
  const materialCache = StaticMaterialCache.Global;
30
32
 
33
+ /**
34
+ *
35
+ * @param {THREE.Material} material
36
+ * @param {HashSet<Texture>} texture_cache
37
+ */
38
+ function replace_material_textures_from_cache(material, texture_cache) {
39
+ const attachments = TextureAttachmentsByMaterialType[material.type];
40
+
41
+ if (attachments === undefined) {
42
+ // unsupported material
43
+ return;
44
+ }
45
+
46
+ const attachment_count = attachments.length;
47
+
48
+ for (let i = 0; i < attachment_count; i++) {
49
+ const attachment = attachments[i];
50
+
51
+ const texture = attachment.read(material);
52
+ if (texture !== undefined && texture !== null) {
53
+ const cached = texture_cache.ensure(texture);
54
+
55
+ if (cached !== texture) {
56
+ // got an existing cached texture, write that instead
57
+ attachment.write(material, cached);
58
+ }
59
+ }
60
+ }
61
+ }
62
+
31
63
  /**
32
64
  * Transfer any transform on the root down to the children instead
33
65
  * @param {Object3D} root
@@ -154,7 +186,20 @@ export class GLTFAssetLoader extends AssetLoader {
154
186
  */
155
187
  this.__geometry_cache = new HashSet({
156
188
  keyHashFunction: computeGeometryHash,
157
- keyEqualityFunction: computeGeometryEquality
189
+ keyEqualityFunction: computeGeometryEquality,
190
+ capacity: 1024
191
+ });
192
+
193
+
194
+ /**
195
+ *
196
+ * @type {HashSet<Texture>}
197
+ * @private
198
+ */
199
+ this.__texture_cache = new HashSet({
200
+ keyHashFunction: computeTextureHash,
201
+ keyEqualityFunction: computeTextureEquality,
202
+ capacity: 2048
158
203
  });
159
204
  }
160
205
 
@@ -234,9 +279,12 @@ export class GLTFAssetLoader extends AssetLoader {
234
279
  }
235
280
  }
236
281
 
282
+
237
283
  load(path, success, failure, progress) {
238
284
  const loader = this.loader;
239
285
  const geometry_cache = this.__geometry_cache;
286
+ const texture_cache = this.__texture_cache;
287
+
240
288
 
241
289
  /**
242
290
  *
@@ -253,6 +301,9 @@ export class GLTFAssetLoader extends AssetLoader {
253
301
  geometry = geometry_cache.ensure(geometry);
254
302
  mesh.geometry = geometry;
255
303
 
304
+ // replace textures from cache
305
+ replace_material_textures_from_cache(mesh.material, texture_cache);
306
+
256
307
  const isSkinned = mesh.isSkinnedMesh === true;
257
308
 
258
309
 
@@ -10,7 +10,7 @@ async function decode_png(png_bytes) {
10
10
 
11
11
  const png = reader.parse();
12
12
 
13
- const data = png.getRGBA8Array();
13
+ const uint_channels = png.getUint8Data();
14
14
 
15
15
  const width = png.getWidth();
16
16
  const height = png.getHeight();
@@ -19,9 +19,10 @@ async function decode_png(png_bytes) {
19
19
  // console.profileEnd('decode');
20
20
 
21
21
  resolve({
22
- data,
22
+ data: uint_channels.data,
23
23
  width,
24
- height
24
+ height,
25
+ itemSize: uint_channels.itemSize
25
26
  });
26
27
  });
27
28
  }
@@ -6,8 +6,9 @@ export class ImageRGBADataAsset extends Asset {
6
6
  * @param {number[]|Uint8Array} data
7
7
  * @param {number} width
8
8
  * @param {number} height
9
+ * @param {number} [itemSize]
9
10
  */
10
- constructor(data, width, height) {
11
+ constructor(data, width, height, itemSize = 4) {
11
12
  super();
12
13
 
13
14
  /**
@@ -32,7 +33,7 @@ export class ImageRGBADataAsset extends Asset {
32
33
  * Number of channels
33
34
  * @type {number}
34
35
  */
35
- this.itemSize = 4;
36
+ this.itemSize = itemSize;
36
37
 
37
38
  this.byteSize = data.length;
38
39
  }
@@ -23,7 +23,7 @@ export class ImageRGBADataLoader extends AssetLoader {
23
23
  /**
24
24
  *
25
25
  * @param {string} path
26
- * @returns {Promise<{data:ArrayBuffer, width: number, height:number}>}
26
+ * @returns {Promise<{data:ArrayBuffer, width: number, height:number, itemSize: number}>}
27
27
  * @private
28
28
  */
29
29
  async __decode_via_worker(path) {
@@ -45,7 +45,7 @@ export class ImageRGBADataLoader extends AssetLoader {
45
45
 
46
46
  const bitmap = await this.__decode_via_worker(path);
47
47
 
48
- return new ImageRGBADataAsset(new Uint8Array(bitmap.data), bitmap.width, bitmap.height);
48
+ return new ImageRGBADataAsset(new Uint8Array(bitmap.data), bitmap.width, bitmap.height, bitmap.itemSize);
49
49
  }
50
50
 
51
51
  load(path, success, failure, progress) {
@@ -65,7 +65,7 @@ export class ImageRGBADataLoader extends AssetLoader {
65
65
 
66
66
  texture.dispose();
67
67
 
68
- const f = new ImageRGBADataAsset(sampler2D.data, sampler2D.width, sampler2D.height);
68
+ const f = new ImageRGBADataAsset(sampler2D.data, sampler2D.width, sampler2D.height, sampler2D.itemSize);
69
69
 
70
70
  success(f);
71
71
 
@@ -45,7 +45,8 @@ export class NativeImageDecoder extends Codec {
45
45
  return {
46
46
  data: rgba_data,
47
47
  width: width,
48
- height: height
48
+ height: height,
49
+ itemSize: 4
49
50
  };
50
51
  }
51
52
  }
@@ -5,12 +5,23 @@ export function PNG() {
5
5
  // initialize all members to keep the same hidden class
6
6
  this.width = 0;
7
7
  this.height = 0;
8
+
9
+ /**
10
+ * Number of bits per channel?
11
+ * @type {number}
12
+ */
8
13
  this.bitDepth = 0;
14
+
9
15
  this.colorType = 0;
10
16
  this.compressionMethod = 0;
11
17
  this.filterMethod = 0;
12
18
  this.interlaceMethod = 0;
13
19
 
20
+ /**
21
+ * Number of channels in the image
22
+ * @example RGB = 3, RGBA = 4, etc.
23
+ * @type {number}
24
+ */
14
25
  this.colors = 0;
15
26
  this.alpha = false;
16
27
  this.pixelBits = 0;
@@ -23,6 +34,10 @@ export function PNG() {
23
34
  */
24
35
  this.pixels = null;
25
36
 
37
+ /**
38
+ * Transparency palette
39
+ * @type {Uint8Array|null}
40
+ */
26
41
  this.trns = null;
27
42
 
28
43
  }
@@ -138,6 +153,10 @@ PNG.prototype.setInterlaceMethod = function (interlaceMethod) {
138
153
  this.interlaceMethod = interlaceMethod;
139
154
  };
140
155
 
156
+ /**
157
+ *
158
+ * @param {Uint8Array} trns
159
+ */
141
160
  PNG.prototype.setTRNS = function (trns) {
142
161
  this.trns = trns;
143
162
  };
@@ -161,7 +180,9 @@ PNG.prototype.getPalette = function () {
161
180
  * result is an array: [red, green, blue, alpha]
162
181
  */
163
182
  PNG.prototype.getPixel = function (result, result_offset, x, y) {
164
- if (!this.pixels) {
183
+ var pixels = this.pixels;
184
+
185
+ if (!pixels) {
165
186
  throw new Error("pixel data is empty");
166
187
  }
167
188
 
@@ -170,7 +191,6 @@ PNG.prototype.getPixel = function (result, result_offset, x, y) {
170
191
  }
171
192
 
172
193
  var i = this.colors * this.bitDepth / 8 * (y * this.width + x);
173
- var pixels = this.pixels;
174
194
 
175
195
  let r, g, b, a;
176
196
 
@@ -189,14 +209,17 @@ PNG.prototype.getPixel = function (result, result_offset, x, y) {
189
209
  break;
190
210
  case 3:
191
211
  a = 255;
192
- if (this.trns != null && this.trns[pixels[i]] != null) {
212
+
213
+ if (this.trns != null) {
193
214
  a = this.trns[pixels[i]];
194
215
  }
216
+
195
217
  const offset = pixels[i] * 3;
196
218
 
197
- r = this.palette[offset];
198
- g = this.palette[offset + 1];
199
- b = this.palette[offset + 2];
219
+ const palette = this.palette;
220
+ r = palette[offset];
221
+ g = palette[offset + 1];
222
+ b = palette[offset + 2];
200
223
 
201
224
  break;
202
225
  case 4:
@@ -293,3 +316,87 @@ PNG.prototype.getRGBA8Array = function () {
293
316
 
294
317
  return data;
295
318
  };
319
+
320
+ PNG.prototype.getUint8Data_case3 = function () {
321
+ const w = this.width;
322
+ const h = this.height;
323
+
324
+ const pixel_count = w * h;
325
+
326
+ let itemSize;
327
+
328
+ const transparency_lookup = this.trns;
329
+ if (transparency_lookup !== null) {
330
+ // has transparency
331
+ itemSize = 4;
332
+ } else {
333
+ itemSize = 3;
334
+ }
335
+
336
+ const result_data = new Uint8Array(pixel_count * itemSize);
337
+
338
+ const pixels = this.pixels;
339
+ const palette = this.palette;
340
+
341
+ const d = this.colors * this.bitDepth / 8;
342
+
343
+ for (let i = 0; i < pixel_count; i++) {
344
+ const destination_address = i * itemSize;
345
+
346
+ const lookup_value = pixels[i * d];
347
+
348
+ result_data[destination_address] = palette[lookup_value];
349
+ result_data[destination_address + 1] = palette[lookup_value + 1];
350
+ result_data[destination_address + 2] = palette[lookup_value + 2];
351
+ }
352
+
353
+ //transparency
354
+ if (transparency_lookup !== null) {
355
+ for (let i = 0; i < pixel_count; i++) {
356
+ result_data[i * 4 + 3] = transparency_lookup[pixels[i * d]];
357
+ }
358
+ }
359
+
360
+ return {
361
+ data: result_data,
362
+ itemSize: itemSize
363
+ }
364
+ }
365
+
366
+ /**
367
+ * @returns {{itemSize:number, data:Uint8Array}}
368
+ */
369
+ PNG.prototype.getUint8Data = function () {
370
+ let data;
371
+ let itemSize = 0; // note, can take this from this.colors
372
+
373
+ switch (this.colorType) {
374
+ case 0:
375
+ data = this.pixels;
376
+ itemSize = 1;
377
+ break;
378
+ case 2:
379
+ data = this.pixels;
380
+ itemSize = 3;
381
+ break;
382
+ case 3:
383
+ // palette
384
+ return this.getUint8Data_case3();
385
+ case 4:
386
+ // grayscale with alpha
387
+ data = this.pixels;
388
+ itemSize = 2;
389
+ break;
390
+ case 6:
391
+ data = this.pixels;
392
+ itemSize = 4;
393
+ break;
394
+ default:
395
+ throw new Error('Unsupported color type');
396
+ }
397
+
398
+ return {
399
+ data,
400
+ itemSize
401
+ };
402
+ };
@@ -91,6 +91,10 @@ PNGReader.prototype.decodeChunk = function () {
91
91
 
92
92
  const type = buffer.readASCIICharacters(4);
93
93
 
94
+ /**
95
+ *
96
+ * @type {Uint8Array}
97
+ */
94
98
  var chunk = this.readBytes(length);
95
99
 
96
100
  // checksum
@@ -161,6 +165,7 @@ PNGReader.prototype.decodeIDAT = function (chunk) {
161
165
 
162
166
  /**
163
167
  * https://www.w3.org/TR/PNG/#11tRNS
168
+ * @param {Uint8Array} chunk
164
169
  */
165
170
  PNGReader.prototype.decodeTRNS = function (chunk) {
166
171
  this.png.setTRNS(chunk);
@@ -1,5 +1,5 @@
1
1
  /**
2
- *
2
+ * Transfer bitmap contents to Sampler2D, effectively moving data to CPU, making it readable
3
3
  * @param {WebGL2RenderingContext} gl
4
4
  * @param {Sampler2D} sampler
5
5
  * @param {ImageBitmap} bitmap