@adatechnology/game-vfx-three 0.1.3 → 0.2.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/README.md +2 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.global.js +916 -215
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +101 -1
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -710,6 +710,75 @@ function createSpriteLayer(THREE, system, pointScale) {
|
|
|
710
710
|
};
|
|
711
711
|
}
|
|
712
712
|
|
|
713
|
+
// src/mesh-layer.ts
|
|
714
|
+
var SPHERE_DEFAULT_WIDTH = 8;
|
|
715
|
+
var SPHERE_DEFAULT_HEIGHT = 6;
|
|
716
|
+
function geometryOf(THREE, particle) {
|
|
717
|
+
switch (particle.shape) {
|
|
718
|
+
case "cone":
|
|
719
|
+
return new THREE.ConeGeometry(particle.radius, particle.height, particle.segments || void 0, particle.segments2 || 1, false);
|
|
720
|
+
case "cone_open":
|
|
721
|
+
return new THREE.ConeGeometry(particle.radius, particle.height, particle.segments || void 0, particle.segments2 || 1, true);
|
|
722
|
+
case "sphere":
|
|
723
|
+
return new THREE.SphereGeometry(particle.radius, particle.segments || SPHERE_DEFAULT_WIDTH, particle.segments2 || SPHERE_DEFAULT_HEIGHT);
|
|
724
|
+
case "icosahedron":
|
|
725
|
+
return new THREE.IcosahedronGeometry(particle.radius, particle.segments);
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
function materialOf(THREE, particle) {
|
|
729
|
+
if (particle.lit) return new THREE.MeshStandardMaterial({ color: particle.color, roughness: 1, metalness: 0, transparent: true, opacity: particle.opacity, depthWrite: false });
|
|
730
|
+
return new THREE.MeshBasicMaterial({ color: particle.color, transparent: true, opacity: particle.opacity, depthWrite: false, ...particle.additive ? { blending: THREE.AdditiveBlending } : {} });
|
|
731
|
+
}
|
|
732
|
+
function createMeshLayer(THREE, pool) {
|
|
733
|
+
const group = new THREE.Group();
|
|
734
|
+
group.name = "workshop-meshes";
|
|
735
|
+
const drawn = /* @__PURE__ */ new Map();
|
|
736
|
+
const frame = new THREE.Quaternion();
|
|
737
|
+
const euler = new THREE.Euler();
|
|
738
|
+
const turn = new THREE.Quaternion();
|
|
739
|
+
const offset = new THREE.Vector3();
|
|
740
|
+
function release(mesh) {
|
|
741
|
+
mesh.removeFromParent();
|
|
742
|
+
mesh.geometry.dispose();
|
|
743
|
+
mesh.material.dispose();
|
|
744
|
+
}
|
|
745
|
+
return {
|
|
746
|
+
group,
|
|
747
|
+
sync() {
|
|
748
|
+
const live = /* @__PURE__ */ new Set();
|
|
749
|
+
for (const particle of pool.particles) {
|
|
750
|
+
live.add(particle.id);
|
|
751
|
+
let mesh = drawn.get(particle.id);
|
|
752
|
+
if (!mesh) {
|
|
753
|
+
mesh = new THREE.Mesh(geometryOf(THREE, particle), materialOf(THREE, particle));
|
|
754
|
+
mesh.frustumCulled = false;
|
|
755
|
+
mesh.renderOrder = particle.additive ? 5 : 3;
|
|
756
|
+
drawn.set(particle.id, mesh);
|
|
757
|
+
group.add(mesh);
|
|
758
|
+
}
|
|
759
|
+
frame.set(particle.frame[0], particle.frame[1], particle.frame[2], particle.frame[3]);
|
|
760
|
+
offset.set(particle.at[0], particle.at[1], particle.at[2]).multiplyScalar(particle.scale).applyQuaternion(frame);
|
|
761
|
+
mesh.position.set(particle.x + offset.x, particle.y + offset.y, particle.z + offset.z);
|
|
762
|
+
turn.setFromEuler(euler.set(particle.rx, particle.ry, particle.rz));
|
|
763
|
+
mesh.quaternion.copy(frame).multiply(turn);
|
|
764
|
+
mesh.scale.setScalar(particle.scale);
|
|
765
|
+
mesh.material.opacity = particle.opacity;
|
|
766
|
+
}
|
|
767
|
+
for (const [id, mesh] of drawn) {
|
|
768
|
+
if (live.has(id)) continue;
|
|
769
|
+
release(mesh);
|
|
770
|
+
drawn.delete(id);
|
|
771
|
+
}
|
|
772
|
+
return pool.count;
|
|
773
|
+
},
|
|
774
|
+
dispose() {
|
|
775
|
+
for (const mesh of drawn.values()) release(mesh);
|
|
776
|
+
drawn.clear();
|
|
777
|
+
group.removeFromParent();
|
|
778
|
+
}
|
|
779
|
+
};
|
|
780
|
+
}
|
|
781
|
+
|
|
713
782
|
// src/shaders/workshop-sprite.ts
|
|
714
783
|
var WORKSHOP_SPRITE_VERTEX = `attribute float size;attribute float alpha;attribute vec3 pcol;varying vec3 vC;varying float vA;uniform float uScale;
|
|
715
784
|
void main(){vC=pcol;vA=alpha;vec4 mv=modelViewMatrix*vec4(position,1.);gl_PointSize=clamp(size*uScale/-mv.z,1.,512.);gl_Position=projectionMatrix*mv;}`;
|
|
@@ -788,6 +857,30 @@ function streakLayer(THREE, pool) {
|
|
|
788
857
|
}
|
|
789
858
|
};
|
|
790
859
|
}
|
|
860
|
+
function rainLayer(THREE, rain) {
|
|
861
|
+
const geometry = new THREE.BufferGeometry();
|
|
862
|
+
const position = new THREE.BufferAttribute(rain.positions, 3).setUsage(THREE.DynamicDrawUsage);
|
|
863
|
+
geometry.setAttribute("position", position);
|
|
864
|
+
geometry.setDrawRange(0, 0);
|
|
865
|
+
const material = new THREE.LineBasicMaterial({ color: 10466255, transparent: true, opacity: 0.35, depthWrite: false });
|
|
866
|
+
const lines = new THREE.LineSegments(geometry, material);
|
|
867
|
+
lines.frustumCulled = false;
|
|
868
|
+
lines.name = "workshop-rain";
|
|
869
|
+
return {
|
|
870
|
+
object: lines,
|
|
871
|
+
sync() {
|
|
872
|
+
const drawn = rain.on && rain.count > 0;
|
|
873
|
+
lines.visible = drawn;
|
|
874
|
+
geometry.setDrawRange(0, drawn ? rain.count * 2 : 0);
|
|
875
|
+
position.needsUpdate = true;
|
|
876
|
+
return drawn;
|
|
877
|
+
},
|
|
878
|
+
dispose() {
|
|
879
|
+
geometry.dispose();
|
|
880
|
+
material.dispose();
|
|
881
|
+
}
|
|
882
|
+
};
|
|
883
|
+
}
|
|
791
884
|
function debrisLayer(THREE, pool) {
|
|
792
885
|
const geometry = new THREE.BoxGeometry(1, 1, 1);
|
|
793
886
|
const material = new THREE.MeshStandardMaterial({ color: 16777215, roughness: 0.45, metalness: 0.25, flatShading: true });
|
|
@@ -990,11 +1083,14 @@ function createWorkshopLayers(THREE, engine, pointScale, lightScale) {
|
|
|
990
1083
|
spriteLayer(THREE, engine.add, true, 1, pointScale),
|
|
991
1084
|
spriteLayer(THREE, engine.normal, false, 0.55, pointScale),
|
|
992
1085
|
streakLayer(THREE, engine.streaks),
|
|
1086
|
+
rainLayer(THREE, engine.rain),
|
|
993
1087
|
debrisLayer(THREE, engine.debris),
|
|
994
1088
|
decalLayer(THREE, engine.decals),
|
|
995
1089
|
ringLayer(THREE, engine.rings)
|
|
996
1090
|
];
|
|
997
1091
|
for (const layer2 of layers) group.add(layer2.object);
|
|
1092
|
+
const meshes = createMeshLayer(THREE, engine.meshes);
|
|
1093
|
+
group.add(meshes.group);
|
|
998
1094
|
const flashLights = engine.lights.lights.map(() => new THREE.PointLight(16760944, 0, 14));
|
|
999
1095
|
const fireLights = engine.lights.fire.map(() => new THREE.PointLight(FIRE_LIGHT_COLOR, 0, FIRE_LIGHT_DISTANCE));
|
|
1000
1096
|
for (const light of [...flashLights, ...fireLights]) group.add(light);
|
|
@@ -1003,6 +1099,7 @@ function createWorkshopLayers(THREE, engine, pointScale, lightScale) {
|
|
|
1003
1099
|
sync() {
|
|
1004
1100
|
let drawCalls = 0;
|
|
1005
1101
|
for (const layer2 of layers) if (layer2.sync()) drawCalls++;
|
|
1102
|
+
drawCalls += meshes.sync();
|
|
1006
1103
|
engine.lights.lights.forEach((source, index) => {
|
|
1007
1104
|
const light = flashLights[index];
|
|
1008
1105
|
light.position.set(source.x, source.y, source.z);
|
|
@@ -1019,6 +1116,7 @@ function createWorkshopLayers(THREE, engine, pointScale, lightScale) {
|
|
|
1019
1116
|
},
|
|
1020
1117
|
dispose() {
|
|
1021
1118
|
for (const layer2 of layers) layer2.dispose();
|
|
1119
|
+
meshes.dispose();
|
|
1022
1120
|
group.clear();
|
|
1023
1121
|
}
|
|
1024
1122
|
};
|
|
@@ -1137,8 +1235,10 @@ function createVfxRenderer(THREE, options) {
|
|
|
1137
1235
|
return world.play(request.effect, request.point, {
|
|
1138
1236
|
...request.direction ? { direction: request.direction } : {},
|
|
1139
1237
|
...request.normal ? { normal: request.normal } : {},
|
|
1238
|
+
...request.orientation ? { orientation: request.orientation } : {},
|
|
1140
1239
|
...request.seed !== void 0 ? { seed: request.seed } : {},
|
|
1141
|
-
...request.param !== void 0 ? { param: request.param } : {}
|
|
1240
|
+
...request.param !== void 0 ? { param: request.param } : {},
|
|
1241
|
+
...request.values ? { values: request.values } : {}
|
|
1142
1242
|
});
|
|
1143
1243
|
},
|
|
1144
1244
|
stop: (handle) => world.stop(handle),
|