@babylonjs-toolkit/next 9.10.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 +312 -0
- package/lib/blendtreeposition.d.ts +5 -0
- package/lib/blendtreeposition.d.ts.map +1 -0
- package/lib/blendtreeposition.js +5 -0
- package/lib/channelmixerplugin.d.ts +11 -0
- package/lib/channelmixerplugin.d.ts.map +1 -0
- package/lib/channelmixerplugin.js +34 -0
- package/lib/collisioncontact.d.ts +7 -0
- package/lib/collisioncontact.d.ts.map +1 -0
- package/lib/collisioncontact.js +7 -0
- package/lib/collisionfilters.d.ts +10 -0
- package/lib/collisionfilters.d.ts.map +1 -0
- package/lib/collisionfilters.js +10 -0
- package/lib/collisionflags.d.ts +14 -0
- package/lib/collisionflags.d.ts.map +1 -0
- package/lib/collisionflags.js +14 -0
- package/lib/collisionstate.d.ts +8 -0
- package/lib/collisionstate.d.ts.map +1 -0
- package/lib/collisionstate.js +8 -0
- package/lib/customloadingscreen.d.ts +16 -0
- package/lib/customloadingscreen.d.ts.map +1 -0
- package/lib/customloadingscreen.js +48 -0
- package/lib/entitycontroller.d.ts +11 -0
- package/lib/entitycontroller.d.ts.map +1 -0
- package/lib/entitycontroller.js +41 -0
- package/lib/fontmanifestentry.d.ts +8 -0
- package/lib/fontmanifestentry.d.ts.map +1 -0
- package/lib/fontmanifestentry.js +1 -0
- package/lib/handedness.d.ts +6 -0
- package/lib/handedness.d.ts.map +1 -0
- package/lib/handedness.js +6 -0
- package/lib/ianimationcurve.d.ts +14 -0
- package/lib/ianimationcurve.d.ts.map +1 -0
- package/lib/ianimationcurve.js +1 -0
- package/lib/index.d.ts +94 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +90 -0
- package/lib/intersectionprecision.d.ts +5 -0
- package/lib/intersectionprecision.d.ts.map +1 -0
- package/lib/intersectionprecision.js +5 -0
- package/lib/iparticlesystemtransform.d.ts +9 -0
- package/lib/iparticlesystemtransform.d.ts.map +1 -0
- package/lib/iparticlesystemtransform.js +1 -0
- package/lib/irecastnavigationplugin.d.ts +92 -0
- package/lib/irecastnavigationplugin.d.ts.map +1 -0
- package/lib/irecastnavigationplugin.js +1 -0
- package/lib/linesmeshrenderer.d.ts +22 -0
- package/lib/linesmeshrenderer.d.ts.map +1 -0
- package/lib/linesmeshrenderer.js +79 -0
- package/lib/localmessagebus.d.ts +9 -0
- package/lib/localmessagebus.d.ts.map +1 -0
- package/lib/localmessagebus.js +44 -0
- package/lib/lutblendplugin.d.ts +13 -0
- package/lib/lutblendplugin.d.ts.map +1 -0
- package/lib/lutblendplugin.js +153 -0
- package/lib/mousebuttonmode.d.ts +6 -0
- package/lib/mousebuttonmode.d.ts.map +1 -0
- package/lib/mousebuttonmode.js +6 -0
- package/lib/movementtype.d.ts +5 -0
- package/lib/movementtype.d.ts.map +1 -0
- package/lib/movementtype.js +5 -0
- package/lib/noisefunction2d.d.ts +2 -0
- package/lib/noisefunction2d.d.ts.map +1 -0
- package/lib/noisefunction2d.js +1 -0
- package/lib/noisefunction3d.d.ts +2 -0
- package/lib/noisefunction3d.d.ts.map +1 -0
- package/lib/noisefunction3d.js +1 -0
- package/lib/noisefunction4d.d.ts +2 -0
- package/lib/noisefunction4d.d.ts.map +1 -0
- package/lib/noisefunction4d.js +1 -0
- package/lib/perlin2d.d.ts +9 -0
- package/lib/perlin2d.d.ts.map +1 -0
- package/lib/perlin2d.js +45 -0
- package/lib/playercontrol.d.ts +5 -0
- package/lib/playercontrol.d.ts.map +1 -0
- package/lib/playercontrol.js +5 -0
- package/lib/prefabobjectpool.d.ts +20 -0
- package/lib/prefabobjectpool.d.ts.map +1 -0
- package/lib/prefabobjectpool.js +96 -0
- package/lib/project.d.ts +2283 -0
- package/lib/project.d.ts.map +1 -0
- package/lib/project.js +10497 -0
- package/lib/randomfn.d.ts +2 -0
- package/lib/randomfn.d.ts.map +1 -0
- package/lib/randomfn.js +1 -0
- package/lib/raycasthitresult.d.ts +21 -0
- package/lib/raycasthitresult.d.ts.map +1 -0
- package/lib/raycasthitresult.js +36 -0
- package/lib/recastclassctor.d.ts +2 -0
- package/lib/recastclassctor.d.ts.map +1 -0
- package/lib/recastclassctor.js +1 -0
- package/lib/roomerrormessage.d.ts +5 -0
- package/lib/roomerrormessage.d.ts.map +1 -0
- package/lib/roomerrormessage.js +2 -0
- package/lib/scenemanager.d.ts +4212 -0
- package/lib/scenemanager.d.ts.map +1 -0
- package/lib/scenemanager.js +41292 -0
- package/lib/simplexnoise.d.ts +21 -0
- package/lib/simplexnoise.d.ts.map +1 -0
- package/lib/simplexnoise.js +362 -0
- package/lib/touchjoystickhandler.d.ts +39 -0
- package/lib/touchjoystickhandler.d.ts.map +1 -0
- package/lib/touchjoystickhandler.js +175 -0
- package/lib/touchmousebutton.d.ts +6 -0
- package/lib/touchmousebutton.d.ts.map +1 -0
- package/lib/touchmousebutton.js +6 -0
- package/lib/triggervolume.d.ts +6 -0
- package/lib/triggervolume.d.ts.map +1 -0
- package/lib/triggervolume.js +6 -0
- package/lib/unitydropdownmenu.d.ts +20 -0
- package/lib/unitydropdownmenu.d.ts.map +1 -0
- package/lib/unitydropdownmenu.js +144 -0
- package/lib/unityscrollbar.d.ts +11 -0
- package/lib/unityscrollbar.d.ts.map +1 -0
- package/lib/unityscrollbar.js +38 -0
- package/lib/unityslider.d.ts +4 -0
- package/lib/unityslider.d.ts.map +1 -0
- package/lib/unityslider.js +3 -0
- package/lib/universalcharactercontroller.d.ts +3 -0
- package/lib/universalcharactercontroller.d.ts.map +1 -0
- package/lib/universalcharactercontroller.js +1 -0
- package/lib/userinputpointer.d.ts +6 -0
- package/lib/userinputpointer.d.ts.map +1 -0
- package/lib/userinputpointer.js +6 -0
- package/lib/windowsplatform.d.ts +17 -0
- package/lib/windowsplatform.d.ts.map +1 -0
- package/lib/windowsplatform.js +133 -0
- package/lib/xbox360trigger.d.ts +5 -0
- package/lib/xbox360trigger.d.ts.map +1 -0
- package/lib/xbox360trigger.js +5 -0
- package/package.json +217 -0
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { Texture } from '@babylonjs/core/Materials/Textures/texture';
|
|
2
|
+
import { PostProcess } from '@babylonjs/core';
|
|
3
|
+
export class LUTBlendPlugin {
|
|
4
|
+
static CreatePostProcess(scene, camera, options) {
|
|
5
|
+
const lutA = options?.lutA || null;
|
|
6
|
+
const lutB = options?.lutB || null;
|
|
7
|
+
const mix = options?.mix ?? 0.0;
|
|
8
|
+
const fragment = `
|
|
9
|
+
precision highp float;
|
|
10
|
+
varying vec2 vUV;
|
|
11
|
+
uniform sampler2D textureSampler;
|
|
12
|
+
uniform sampler2D lutA;
|
|
13
|
+
uniform sampler2D lutB;
|
|
14
|
+
uniform float mixVal;
|
|
15
|
+
uniform float lutTileCountA; // number of tiles per row for LUT A
|
|
16
|
+
uniform float lutTileCountB; // number of tiles per row for LUT B
|
|
17
|
+
|
|
18
|
+
vec3 sampleLUT(in sampler2D lut, in vec3 color, in float tileCount) {
|
|
19
|
+
if (tileCount <= 0.5) return color;
|
|
20
|
+
float tc = floor(tileCount + 0.5);
|
|
21
|
+
float tileSize = 1.0 / tc;
|
|
22
|
+
|
|
23
|
+
// For normalized RGB [0..1], compute position in LUT
|
|
24
|
+
float r = color.r;
|
|
25
|
+
float g = color.g;
|
|
26
|
+
float b = color.b;
|
|
27
|
+
|
|
28
|
+
// Determine slice and tile coords
|
|
29
|
+
float slice = b * (tc - 1.0);
|
|
30
|
+
float sliceIndex = floor(slice + 0.5);
|
|
31
|
+
|
|
32
|
+
float tx = mod(sliceIndex, tc);
|
|
33
|
+
float ty = floor(sliceIndex / tc);
|
|
34
|
+
|
|
35
|
+
vec2 uv = vec2(tx * tileSize + r * tileSize, ty * tileSize + g * tileSize);
|
|
36
|
+
vec3 sampled = texture2D(lut, uv).rgb;
|
|
37
|
+
return sampled;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
void main(void) {
|
|
41
|
+
vec4 sceneColor = texture2D(textureSampler, vUV);
|
|
42
|
+
vec3 a = sceneColor.rgb;
|
|
43
|
+
if (lutTileCountA <= 0.5 || lutTileCountB <= 0.5) {
|
|
44
|
+
// No LUT size provided fallback to passthrough
|
|
45
|
+
gl_FragColor = sceneColor;
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
vec3 colA = sampleLUT(lutA, a, lutTileCountA);
|
|
49
|
+
vec3 colB = sampleLUT(lutB, a, lutTileCountB);
|
|
50
|
+
vec3 outc = mix(colA, colB, mixVal);
|
|
51
|
+
gl_FragColor = vec4(outc, sceneColor.a);
|
|
52
|
+
}
|
|
53
|
+
`;
|
|
54
|
+
const post = new PostProcess("lutBlend", fragment, ["mixVal", "lutTileCountA", "lutTileCountB"], ["lutA", "lutB"], 1.0, camera, Texture.BILINEAR_SAMPLINGMODE, scene.getEngine(), false);
|
|
55
|
+
function detectTileCountFromDims(w, h) {
|
|
56
|
+
if (!w || !h)
|
|
57
|
+
return 0;
|
|
58
|
+
if (w % h === 0)
|
|
59
|
+
return Math.round(w / h);
|
|
60
|
+
if (h % w === 0)
|
|
61
|
+
return Math.round(h / w);
|
|
62
|
+
if (w === h) {
|
|
63
|
+
const t = Math.round(Math.sqrt(w));
|
|
64
|
+
if (t * t === w)
|
|
65
|
+
return t;
|
|
66
|
+
return Math.round(Math.sqrt(w));
|
|
67
|
+
}
|
|
68
|
+
return Math.round(Math.pow(w * h, 1.0 / 3.0));
|
|
69
|
+
}
|
|
70
|
+
let tileA = 0, tileB = 0;
|
|
71
|
+
post.onApply = (effect) => {
|
|
72
|
+
effect.setFloat('mixVal', mix);
|
|
73
|
+
if (lutA && typeof lutA === 'string') {
|
|
74
|
+
const tA = new Texture(lutA, scene, true, false, Texture.TRILINEAR_SAMPLINGMODE, undefined, undefined, undefined, false);
|
|
75
|
+
tA.onLoadObservable.addOnce(() => {
|
|
76
|
+
tileA = detectTileCountFromDims(tA.getSize ? tA.getSize().width : tA.width, tA.getSize ? tA.getSize().height : tA.height);
|
|
77
|
+
});
|
|
78
|
+
effect.setTexture('lutA', tA);
|
|
79
|
+
}
|
|
80
|
+
else if (lutA instanceof Texture) {
|
|
81
|
+
const tA = lutA;
|
|
82
|
+
tileA = detectTileCountFromDims(tA.getSize ? tA.getSize().width : tA.width, tA.getSize ? tA.getSize().height : tA.height);
|
|
83
|
+
effect.setTexture('lutA', tA);
|
|
84
|
+
}
|
|
85
|
+
if (lutB && typeof lutB === 'string') {
|
|
86
|
+
const tB = new Texture(lutB, scene, true, false, Texture.TRILINEAR_SAMPLINGMODE, undefined, undefined, undefined, false);
|
|
87
|
+
tB.onLoadObservable.addOnce(() => {
|
|
88
|
+
tileB = detectTileCountFromDims(tB.getSize ? tB.getSize().width : tB.width, tB.getSize ? tB.getSize().height : tB.height);
|
|
89
|
+
});
|
|
90
|
+
effect.setTexture('lutB', tB);
|
|
91
|
+
}
|
|
92
|
+
else if (lutB instanceof Texture) {
|
|
93
|
+
const tB = lutB;
|
|
94
|
+
tileB = detectTileCountFromDims(tB.getSize ? tB.getSize().width : tB.width, tB.getSize ? tB.getSize().height : tB.height);
|
|
95
|
+
effect.setTexture('lutB', tB);
|
|
96
|
+
}
|
|
97
|
+
effect.setFloat('lutTileCountA', tileA);
|
|
98
|
+
effect.setFloat('lutTileCountB', tileB);
|
|
99
|
+
};
|
|
100
|
+
post._detectedTileCountA = () => tileA;
|
|
101
|
+
post._detectedTileCountB = () => tileB;
|
|
102
|
+
return post;
|
|
103
|
+
}
|
|
104
|
+
getWGSLShaderCode() {
|
|
105
|
+
return `
|
|
106
|
+
[[group(0), binding(0)]] var textureSampler: texture_2d<f32>;
|
|
107
|
+
[[group(0), binding(1)]] var textureSamplerSampler: sampler;
|
|
108
|
+
[[group(0), binding(2)]] var lutA: texture_2d<f32>;
|
|
109
|
+
[[group(0), binding(3)]] var lutASampler: sampler;
|
|
110
|
+
[[group(0), binding(4)]] var lutB: texture_2d<f32>;
|
|
111
|
+
[[group(0), binding(5)]] var lutBSampler: sampler;
|
|
112
|
+
|
|
113
|
+
[[block]] struct Uniforms {
|
|
114
|
+
mixVal: f32;
|
|
115
|
+
lutTileCountA: f32;
|
|
116
|
+
lutTileCountB: f32;
|
|
117
|
+
};
|
|
118
|
+
[[group(0), binding(6)]] var<uniform> uniforms: Uniforms;
|
|
119
|
+
|
|
120
|
+
fn sampleLUT(lut: texture_2d<f32>, lutSamp: sampler, color: vec3<f32>, tileCount: f32) -> vec3<f32> {
|
|
121
|
+
if (tileCount <= 0.5) { return color; }
|
|
122
|
+
let tc = floor(tileCount + 0.5);
|
|
123
|
+
let tileSize = 1.0 / tc;
|
|
124
|
+
|
|
125
|
+
let r = color.r;
|
|
126
|
+
let g = color.g;
|
|
127
|
+
let b = color.b;
|
|
128
|
+
|
|
129
|
+
let slice = b * (tc - 1.0);
|
|
130
|
+
let sliceIndex = floor(slice + 0.5);
|
|
131
|
+
|
|
132
|
+
let tx = sliceIndex % tc;
|
|
133
|
+
let ty = floor(sliceIndex / tc);
|
|
134
|
+
|
|
135
|
+
let uv = vec2<f32>(tx * tileSize + r * tileSize, ty * tileSize + g * tileSize);
|
|
136
|
+
let sampled = textureSample(lut, lutSamp, uv).rgb;
|
|
137
|
+
return sampled;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
fn mainImage(vUV: vec2<f32>) -> vec4<f32> {
|
|
141
|
+
let sceneColor = textureSample(textureSampler, textureSamplerSampler, vUV);
|
|
142
|
+
let a = sceneColor.rgb;
|
|
143
|
+
if (uniforms.lutTileCountA <= 0.5 || uniforms.lutTileCountB <= 0.5) {
|
|
144
|
+
return sceneColor;
|
|
145
|
+
}
|
|
146
|
+
let colA = sampleLUT(lutA, lutASampler, a, uniforms.lutTileCountA);
|
|
147
|
+
let colB = sampleLUT(lutB, lutBSampler, a, uniforms.lutTileCountB);
|
|
148
|
+
let outc = mix(colA, colB, uniforms.mixVal);
|
|
149
|
+
return vec4<f32>(outc, sceneColor.a);
|
|
150
|
+
}
|
|
151
|
+
`;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mousebuttonmode.d.ts","sourceRoot":"","sources":["../src/mousebuttonmode.ts"],"names":[],"mappings":"AAEA,oBAAY,eAAe;IACnB,GAAG,IAAI;IACP,IAAI,IAAI;IACR,IAAI,IAAI;CACX"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export var MouseButtonMode;
|
|
2
|
+
(function (MouseButtonMode) {
|
|
3
|
+
MouseButtonMode[MouseButtonMode["Pan"] = 0] = "Pan";
|
|
4
|
+
MouseButtonMode[MouseButtonMode["Look"] = 1] = "Look";
|
|
5
|
+
MouseButtonMode[MouseButtonMode["Move"] = 2] = "Move";
|
|
6
|
+
})(MouseButtonMode || (MouseButtonMode = {}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"movementtype.d.ts","sourceRoot":"","sources":["../src/movementtype.ts"],"names":[],"mappings":"AACA,oBAAY,YAAY;IAChB,cAAc,IAAI;IAClB,aAAa,IAAI;CACpB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"noisefunction2d.d.ts","sourceRoot":"","sources":["../src/noisefunction2d.ts"],"names":[],"mappings":"AACA,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"noisefunction3d.d.ts","sourceRoot":"","sources":["../src/noisefunction3d.ts"],"names":[],"mappings":"AACA,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"noisefunction4d.d.ts","sourceRoot":"","sources":["../src/noisefunction4d.ts"],"names":[],"mappings":"AACA,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"perlin2d.d.ts","sourceRoot":"","sources":["../src/perlin2d.ts"],"names":[],"mappings":"AACA,qBAAa,QAAQ;IACf,OAAO,CAAC,IAAI,CAAW;gBACX,IAAI,EAAE,MAAM;IAsBxB,OAAO,CAAC,IAAI;IAGZ,OAAO,CAAC,IAAI;IAGZ,OAAO,CAAC,IAAI;IAUL,KAAK,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM;CAuB7C"}
|
package/lib/perlin2d.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export class Perlin2D {
|
|
2
|
+
constructor(seed) {
|
|
3
|
+
const p = new Array(256);
|
|
4
|
+
for (let i = 0; i < 256; i++)
|
|
5
|
+
p[i] = i;
|
|
6
|
+
let state = (seed | 0) >>> 0;
|
|
7
|
+
const nextRand = () => {
|
|
8
|
+
state = (state * 16807) % 2147483647;
|
|
9
|
+
return state / 2147483647;
|
|
10
|
+
};
|
|
11
|
+
for (let i = 255; i > 0; i--) {
|
|
12
|
+
const r = Math.floor(nextRand() * (i + 1));
|
|
13
|
+
const tmp = p[i];
|
|
14
|
+
p[i] = p[r];
|
|
15
|
+
p[r] = tmp;
|
|
16
|
+
}
|
|
17
|
+
this.perm = new Array(512);
|
|
18
|
+
for (let i = 0; i < 512; i++) {
|
|
19
|
+
this.perm[i] = p[i & 255];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
fade(t) {
|
|
23
|
+
return t * t * t * (t * (t * 6 - 15) + 10);
|
|
24
|
+
}
|
|
25
|
+
lerp(a, b, t) {
|
|
26
|
+
return a + t * (b - a);
|
|
27
|
+
}
|
|
28
|
+
grad(hash, x, y) {
|
|
29
|
+
const h = hash & 7;
|
|
30
|
+
const u = h < 4 ? x : y;
|
|
31
|
+
const v = h < 4 ? y : x;
|
|
32
|
+
return ((h & 1) ? -u : u) + ((h & 2) ? -v : v);
|
|
33
|
+
}
|
|
34
|
+
noise(x, y) {
|
|
35
|
+
const X = Math.floor(x) & 255;
|
|
36
|
+
const Y = Math.floor(y) & 255;
|
|
37
|
+
const xf = x - Math.floor(x);
|
|
38
|
+
const yf = y - Math.floor(y);
|
|
39
|
+
const u = this.fade(xf);
|
|
40
|
+
const v = this.fade(yf);
|
|
41
|
+
const A = this.perm[X] + Y;
|
|
42
|
+
const B = this.perm[X + 1] + Y;
|
|
43
|
+
return this.lerp(this.lerp(this.grad(this.perm[A], xf, yf), this.grad(this.perm[B], xf - 1, yf), u), this.lerp(this.grad(this.perm[A + 1], xf, yf - 1), this.grad(this.perm[B + 1], xf - 1, yf - 1), u), v);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"playercontrol.d.ts","sourceRoot":"","sources":["../src/playercontrol.ts"],"names":[],"mappings":"AACA,oBAAY,aAAa;IACjB,WAAW,IAAI;IACf,WAAW,IAAI;CAClB"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { TransformNode } from '@babylonjs/core/Meshes/transformNode';
|
|
2
|
+
import { AssetContainer } from '@babylonjs/core/assetContainer';
|
|
3
|
+
import { Vector3, Quaternion } from '@babylonjs/core/Maths/math.vector';
|
|
4
|
+
import { Scene } from '@babylonjs/core/scene';
|
|
5
|
+
export declare class PrefabObjectPool {
|
|
6
|
+
private prefabName;
|
|
7
|
+
private allowGrowth;
|
|
8
|
+
private assetContainer;
|
|
9
|
+
private cloneAnimations;
|
|
10
|
+
private makeNewMaterials;
|
|
11
|
+
private availableInstances;
|
|
12
|
+
getAvailableCount(): number;
|
|
13
|
+
constructor(container: AssetContainer | Scene, prefabName: string, prefabCount?: number, allowGrowth?: boolean, makeNewMaterials?: boolean, cloneAnimations?: boolean);
|
|
14
|
+
populatePool(count: number): void;
|
|
15
|
+
getInstance(position?: Vector3, rotation?: Quaternion): TransformNode;
|
|
16
|
+
freeInstance(instance: TransformNode): void;
|
|
17
|
+
private appendNewInstance;
|
|
18
|
+
private createNewInstance;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=prefabobjectpool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prefabobjectpool.d.ts","sourceRoot":"","sources":["../src/prefabobjectpool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AAErE,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAChE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,mCAAmC,CAAC;AAExE,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAE9C,qBAAa,gBAAgB;IACrB,OAAO,CAAC,UAAU,CAAgB;IAClC,OAAO,CAAC,WAAW,CAAiB;IACpC,OAAO,CAAC,cAAc,CAAgC;IACtD,OAAO,CAAC,eAAe,CAAiB;IACxC,OAAO,CAAC,gBAAgB,CAAkB;IAC1C,OAAO,CAAC,kBAAkB,CAAyB;IAC5C,iBAAiB,IAAI,MAAM;gBACf,SAAS,EAAE,cAAc,GAAG,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,WAAW,GAAE,MAAU,EAAE,WAAW,GAAE,OAAc,EAAE,gBAAgB,GAAE,OAAe,EAAE,eAAe,GAAE,OAAc;IAU3L,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IASjC,WAAW,CAAC,QAAQ,GAAE,OAAc,EAAE,QAAQ,GAAE,UAAiB,GAAG,aAAa;IAkBjF,YAAY,CAAC,QAAQ,EAAE,aAAa,GAAG,IAAI;IAoBlD,OAAO,CAAC,iBAAiB;IAOzB,OAAO,CAAC,iBAAiB;CAW5B"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { SceneManager } from './scenemanager';
|
|
2
|
+
import { AssetContainer } from '@babylonjs/core/assetContainer';
|
|
3
|
+
import { Quaternion } from '@babylonjs/core/Maths/math.vector';
|
|
4
|
+
import { Scene } from '@babylonjs/core/scene';
|
|
5
|
+
export class PrefabObjectPool {
|
|
6
|
+
getAvailableCount() { return this.availableInstances.length; }
|
|
7
|
+
constructor(container, prefabName, prefabCount = 1, allowGrowth = true, makeNewMaterials = false, cloneAnimations = true) {
|
|
8
|
+
this.prefabName = null;
|
|
9
|
+
this.allowGrowth = true;
|
|
10
|
+
this.assetContainer = null;
|
|
11
|
+
this.cloneAnimations = true;
|
|
12
|
+
this.makeNewMaterials = false;
|
|
13
|
+
this.availableInstances = null;
|
|
14
|
+
this.prefabName = prefabName;
|
|
15
|
+
this.allowGrowth = allowGrowth;
|
|
16
|
+
this.assetContainer = container;
|
|
17
|
+
this.cloneAnimations = cloneAnimations;
|
|
18
|
+
this.makeNewMaterials = makeNewMaterials;
|
|
19
|
+
this.availableInstances = [];
|
|
20
|
+
this.populatePool(prefabCount);
|
|
21
|
+
}
|
|
22
|
+
populatePool(count) {
|
|
23
|
+
if (count > 0) {
|
|
24
|
+
for (let i = 0; i < count; i++) {
|
|
25
|
+
const instance = this.createNewInstance();
|
|
26
|
+
if (instance != null)
|
|
27
|
+
this.freeInstance(instance);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
getInstance(position = null, rotation = null) {
|
|
32
|
+
const instance = (this.availableInstances.length > 0) ? this.availableInstances.pop() : this.appendNewInstance();
|
|
33
|
+
if (instance != null) {
|
|
34
|
+
if (position != null)
|
|
35
|
+
instance.position.copyFrom(position);
|
|
36
|
+
else
|
|
37
|
+
instance.position.set(0, 0, 0);
|
|
38
|
+
if (rotation != null) {
|
|
39
|
+
if (instance.rotationQuaternion != null)
|
|
40
|
+
instance.rotationQuaternion.copyFrom(rotation);
|
|
41
|
+
else
|
|
42
|
+
instance.rotationQuaternion = rotation.clone();
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
if (instance.rotationQuaternion != null)
|
|
46
|
+
instance.rotationQuaternion.set(0, 0, 0, 1);
|
|
47
|
+
else
|
|
48
|
+
instance.rotationQuaternion = new Quaternion(0, 0, 0, 1);
|
|
49
|
+
}
|
|
50
|
+
instance.name = (this.prefabName + ".Instance");
|
|
51
|
+
instance.setEnabled(true);
|
|
52
|
+
}
|
|
53
|
+
return instance;
|
|
54
|
+
}
|
|
55
|
+
freeInstance(instance) {
|
|
56
|
+
if (instance != null) {
|
|
57
|
+
instance.setEnabled(false);
|
|
58
|
+
instance.position.set(0, 0, 0);
|
|
59
|
+
if (instance.rotationQuaternion != null)
|
|
60
|
+
instance.rotationQuaternion.set(0, 0, 0, 1);
|
|
61
|
+
else
|
|
62
|
+
instance.rotationQuaternion = new Quaternion(0, 0, 0, 1);
|
|
63
|
+
if (instance.metadata != null && instance.metadata.toolkit != null && instance.metadata.toolkit.components != null) {
|
|
64
|
+
instance.metadata.toolkit.components.forEach((script) => {
|
|
65
|
+
if (script != null) {
|
|
66
|
+
try {
|
|
67
|
+
script.resetScriptComponent();
|
|
68
|
+
}
|
|
69
|
+
catch (e) { }
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
instance.name = (this.prefabName + ".Unassigned");
|
|
74
|
+
this.availableInstances.push(instance);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
appendNewInstance() {
|
|
78
|
+
let result = null;
|
|
79
|
+
if (this.allowGrowth === true) {
|
|
80
|
+
result = this.createNewInstance();
|
|
81
|
+
}
|
|
82
|
+
return result;
|
|
83
|
+
}
|
|
84
|
+
createNewInstance(newParent = null, newPosition = null, newRotation = null, newScaling = null) {
|
|
85
|
+
let result = null;
|
|
86
|
+
if (this.assetContainer != null && this.prefabName != null && this.prefabName !== "") {
|
|
87
|
+
if (this.assetContainer instanceof AssetContainer) {
|
|
88
|
+
result = SceneManager.InstantiatePrefabFromContainer(this.assetContainer, this.prefabName, (this.prefabName + ".Instance"), newParent, newPosition, newRotation, newScaling, this.cloneAnimations, this.makeNewMaterials);
|
|
89
|
+
}
|
|
90
|
+
else if (this.assetContainer instanceof Scene) {
|
|
91
|
+
result = SceneManager.InstantiatePrefabFromScene(this.assetContainer, this.prefabName, (this.prefabName + ".Instance"), newParent, newPosition, newRotation, newScaling, this.cloneAnimations);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return result;
|
|
95
|
+
}
|
|
96
|
+
}
|