@adatechnology/game-fluids-three 0.3.1 → 0.4.1
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/dist/index.d.ts +3 -0
- package/dist/index.global.js +213 -96
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +49 -0
- package/dist/index.js.map +1 -1
- package/package.json +5 -4
package/dist/index.js
CHANGED
|
@@ -206,6 +206,11 @@ var LiquidBody = class {
|
|
|
206
206
|
this.vertices = 0;
|
|
207
207
|
return;
|
|
208
208
|
}
|
|
209
|
+
if (state.closed && this.isShellOpaque()) {
|
|
210
|
+
if (this.mesh) this.mesh.visible = false;
|
|
211
|
+
this.vertices = 0;
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
209
214
|
this.build(state, quality);
|
|
210
215
|
if (!this.mesh || !this.solid) return;
|
|
211
216
|
this.mesh.material = materials.liquidBody(def);
|
|
@@ -231,6 +236,17 @@ var LiquidBody = class {
|
|
|
231
236
|
}
|
|
232
237
|
} else this.steamAcc = 0;
|
|
233
238
|
}
|
|
239
|
+
/** Every mesh of the bound object (the liquid itself aside) is drawn with an opaque material. */
|
|
240
|
+
isShellOpaque() {
|
|
241
|
+
let opaque = true;
|
|
242
|
+
this.object.traverse((child) => {
|
|
243
|
+
const mesh = child;
|
|
244
|
+
if (!opaque || !mesh.isMesh || child === this.mesh) return;
|
|
245
|
+
const materials = Array.isArray(mesh.material) ? mesh.material : [mesh.material];
|
|
246
|
+
if (materials.some((material) => material.transparent || material.opacity < 1)) opaque = false;
|
|
247
|
+
});
|
|
248
|
+
return opaque;
|
|
249
|
+
}
|
|
234
250
|
get triangles() {
|
|
235
251
|
return this.visible ? Math.floor(this.vertices / 3) : 0;
|
|
236
252
|
}
|
|
@@ -356,6 +372,16 @@ var MaterialCache = class {
|
|
|
356
372
|
}
|
|
357
373
|
return m;
|
|
358
374
|
}
|
|
375
|
+
/** One material per role, in a clear and in an opaque liquid, which are the shader programs a leak will need (the colour is not part of a program). */
|
|
376
|
+
probes() {
|
|
377
|
+
const base = { id: "warm_up", color: 8421504, viscosity: 1, density: 1e3, dryTime: 60, gloss: 0.5 };
|
|
378
|
+
const defs = [{ ...base, opacity: 0.5 }, { ...base, opacity: 1 }];
|
|
379
|
+
return {
|
|
380
|
+
plain: defs.flatMap((def) => [this.liquidBody(def), this.liquidStream(def)]),
|
|
381
|
+
instanced: defs.map((def) => this.liquidStream(def)),
|
|
382
|
+
coloured: defs.flatMap((def) => [this.stainFilm(def), this.stainWet(def)])
|
|
383
|
+
};
|
|
384
|
+
}
|
|
359
385
|
dispose() {
|
|
360
386
|
for (const map of [this.body, this.stream, this.film, this.wet]) {
|
|
361
387
|
for (const m of map.values()) m.dispose();
|
|
@@ -881,6 +907,29 @@ function createFluidRenderer(THREE, options) {
|
|
|
881
907
|
body.dispose();
|
|
882
908
|
bodies.delete(containerId);
|
|
883
909
|
},
|
|
910
|
+
warmUpProbes() {
|
|
911
|
+
const plainGeometry = new THREE.BufferGeometry();
|
|
912
|
+
plainGeometry.setAttribute("position", new THREE.BufferAttribute(new Float32Array(9), 3));
|
|
913
|
+
plainGeometry.setAttribute("normal", new THREE.BufferAttribute(new Float32Array(9), 3));
|
|
914
|
+
const stainGeometry = plainGeometry.clone();
|
|
915
|
+
stainGeometry.setAttribute("color", new THREE.BufferAttribute(new Float32Array(12), 4));
|
|
916
|
+
const { plain, instanced, coloured } = materials.probes();
|
|
917
|
+
const meshes = [
|
|
918
|
+
...plain.map((material) => new THREE.Mesh(plainGeometry, material)),
|
|
919
|
+
...instanced.map((material) => new THREE.InstancedMesh(dropGeometry, material, 1)),
|
|
920
|
+
...coloured.map((material) => new THREE.Mesh(stainGeometry, material))
|
|
921
|
+
];
|
|
922
|
+
const group = new THREE.Group();
|
|
923
|
+
for (const mesh of meshes) mesh.frustumCulled = false;
|
|
924
|
+
group.add(...meshes);
|
|
925
|
+
return {
|
|
926
|
+
group,
|
|
927
|
+
dispose() {
|
|
928
|
+
plainGeometry.dispose();
|
|
929
|
+
stainGeometry.dispose();
|
|
930
|
+
}
|
|
931
|
+
};
|
|
932
|
+
},
|
|
884
933
|
update(dt) {
|
|
885
934
|
if (disposed) return;
|
|
886
935
|
time += dt;
|