@babylonjs-toolkit/next 9.0.1 → 9.5.0
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 +0 -5
- package/lib/index.d.ts +0 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +0 -2
- package/lib/scenemanager.d.ts +102 -66
- package/lib/scenemanager.d.ts.map +1 -1
- package/lib/scenemanager.js +1159 -524
- package/package.json +11 -11
- package/lib/treebranchmaterial.d.ts +0 -31
- package/lib/treebranchmaterial.d.ts.map +0 -1
- package/lib/treebranchmaterial.js +0 -369
- package/lib/universalterrainmaterial.d.ts +0 -48
- package/lib/universalterrainmaterial.d.ts.map +0 -1
- package/lib/universalterrainmaterial.js +0 -639
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@babylonjs-toolkit/next",
|
|
3
|
-
"version": "9.0
|
|
3
|
+
"version": "9.5.0",
|
|
4
4
|
"description": "Babylon Toolkit Runtime Library (ES6)",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "lib/index.js",
|
|
@@ -191,21 +191,21 @@
|
|
|
191
191
|
"lib/**/*"
|
|
192
192
|
],
|
|
193
193
|
"devDependencies": {
|
|
194
|
-
"@babylonjs/core": "^9.
|
|
195
|
-
"@babylonjs/gui": "^9.
|
|
194
|
+
"@babylonjs/core": "^9.5.0",
|
|
195
|
+
"@babylonjs/gui": "^9.5.0",
|
|
196
196
|
"@babylonjs/havok": "^1.3.10",
|
|
197
|
-
"@babylonjs/addons": "^9.
|
|
198
|
-
"@babylonjs/loaders": "^9.
|
|
199
|
-
"@babylonjs/materials": "^9.
|
|
197
|
+
"@babylonjs/addons": "^9.5.0",
|
|
198
|
+
"@babylonjs/loaders": "^9.5.0",
|
|
199
|
+
"@babylonjs/materials": "^9.5.0",
|
|
200
200
|
"rimraf": "^6.0.1",
|
|
201
201
|
"typescript": "^6.0.3"
|
|
202
202
|
},
|
|
203
203
|
"peerDependencies": {
|
|
204
|
-
"@babylonjs/core": "^9.
|
|
205
|
-
"@babylonjs/gui": "^9.
|
|
204
|
+
"@babylonjs/core": "^9.5.0",
|
|
205
|
+
"@babylonjs/gui": "^9.5.0",
|
|
206
206
|
"@babylonjs/havok": "^1.3.10",
|
|
207
|
-
"@babylonjs/addons": "^9.
|
|
208
|
-
"@babylonjs/loaders": "^9.
|
|
209
|
-
"@babylonjs/materials": "^9.
|
|
207
|
+
"@babylonjs/addons": "^9.5.0",
|
|
208
|
+
"@babylonjs/loaders": "^9.5.0",
|
|
209
|
+
"@babylonjs/materials": "^9.5.0"
|
|
210
210
|
}
|
|
211
211
|
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { Scene } from '@babylonjs/core/scene';
|
|
2
|
-
import { Vector4 } from '@babylonjs/core/Maths/math.vector';
|
|
3
|
-
import { CustomShaderMaterial, CustomShaderMaterialPlugin } from './scenemanager';
|
|
4
|
-
import { ShaderLanguage } from '@babylonjs/core/Materials';
|
|
5
|
-
import { MaterialDefines } from '@babylonjs/core/Materials/materialDefines';
|
|
6
|
-
import { UniformBuffer } from '@babylonjs/core/Materials/uniformBuffer';
|
|
7
|
-
import { SubMesh } from '@babylonjs/core/Meshes/subMesh';
|
|
8
|
-
import { TransformNode } from '@babylonjs/core/Meshes/transformNode';
|
|
9
|
-
import { AbstractMesh } from '@babylonjs/core/Meshes/abstractMesh';
|
|
10
|
-
import { AbstractEngine } from '@babylonjs/core/Engines/abstractEngine';
|
|
11
|
-
export declare class TreeBranchMaterial extends CustomShaderMaterial {
|
|
12
|
-
private _windTimeAccum;
|
|
13
|
-
constructor(name: string, scene: Scene);
|
|
14
|
-
awake(): void;
|
|
15
|
-
update(): void;
|
|
16
|
-
getShaderName(): string;
|
|
17
|
-
setWindDirection(x: number, y: number, z: number): void;
|
|
18
|
-
getWindDirection(): Vector4;
|
|
19
|
-
}
|
|
20
|
-
export declare class TreeBranchMaterialPlugin extends CustomShaderMaterialPlugin {
|
|
21
|
-
constructor(customMaterial: CustomShaderMaterial, shaderName: string);
|
|
22
|
-
isCompatible(shaderLanguage: ShaderLanguage): boolean;
|
|
23
|
-
getCustomCode(shaderType: string, shaderLanguage: ShaderLanguage): any;
|
|
24
|
-
getUniforms(shaderLanguage: ShaderLanguage): any;
|
|
25
|
-
getSamplers(samplers: string[]): void;
|
|
26
|
-
getAttributes(attributes: string[], scene: Scene, mesh: AbstractMesh): void;
|
|
27
|
-
prepareDefines(defines: MaterialDefines, scene: Scene, mesh: AbstractMesh): void;
|
|
28
|
-
bindForSubMesh(uniformBuffer: UniformBuffer, scene: Scene, engine: AbstractEngine, subMesh: SubMesh): void;
|
|
29
|
-
static ExtractWindZoneOverride(properties: any, terrainTransform: TransformNode, builderInstance?: any): any | null;
|
|
30
|
-
}
|
|
31
|
-
//# sourceMappingURL=treebranchmaterial.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"treebranchmaterial.d.ts","sourceRoot":"","sources":["../src/treebranchmaterial.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAW,MAAM,mCAAmC,CAAC;AACrE,OAAO,EAAE,oBAAoB,EAAgB,0BAA0B,EAAE,MAAM,gBAAgB,CAAC;AAChG,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,2CAA2C,CAAC;AAC5E,OAAO,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAC;AACxE,OAAO,EAAE,OAAO,EAAE,MAAM,gCAAgC,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AACrE,OAAO,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,wCAAwC,CAAC;AAExE,qBAAa,kBAAmB,SAAQ,oBAAoB;IACpD,OAAO,CAAC,cAAc,CAAe;gBAElB,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK;IAsBtC,KAAK,IAAI,IAAI;IAIb,MAAM,IAAI,IAAI;IAcd,aAAa,IAAI,MAAM;IAIvB,gBAAgB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI;IAUvD,gBAAgB,IAAI,OAAO;CAGrC;AAEL,qBAAa,wBAAyB,SAAQ,0BAA0B;gBAC7C,cAAc,EAAE,oBAAoB,EAAE,UAAU,EAAE,MAAM;IAIpE,YAAY,CAAC,cAAc,EAAE,cAAc,GAAG,OAAO;IAIrD,aAAa,CAAC,UAAU,EAAE,MAAM,EAAE,cAAc,EAAE,cAAc,GAAG,GAAG;IAyOtE,WAAW,CAAC,cAAc,EAAE,cAAc,GAAG,GAAG;IAOhD,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,IAAI;IAKrC,aAAa,CAAC,UAAU,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,YAAY,GAAG,IAAI;IAS3E,cAAc,CAAC,OAAO,EAAE,eAAe,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,YAAY,GAAG,IAAI;IAKhF,cAAc,CAAC,aAAa,EAAE,aAAa,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI;WAYnG,uBAAuB,CAAC,UAAU,EAAE,GAAG,EAAE,gBAAgB,EAAE,aAAa,EAAE,eAAe,CAAC,EAAE,GAAG,GAAG,GAAG,GAAG,IAAI;CA+C7H"}
|
|
@@ -1,369 +0,0 @@
|
|
|
1
|
-
import { Vector4, Vector3 } from '@babylonjs/core/Maths/math.vector';
|
|
2
|
-
import { CustomShaderMaterial, SceneManager, CustomShaderMaterialPlugin } from './scenemanager';
|
|
3
|
-
import { ShaderLanguage } from '@babylonjs/core/Materials';
|
|
4
|
-
export class TreeBranchMaterial extends CustomShaderMaterial {
|
|
5
|
-
constructor(name, scene) {
|
|
6
|
-
super(name, scene);
|
|
7
|
-
this._windTimeAccum = 0.0;
|
|
8
|
-
this.shader = this.getShaderName();
|
|
9
|
-
this.plugin = new TreeBranchMaterialPlugin(this, this.shader);
|
|
10
|
-
this.addFloatUniform("g_windTime", 0.0);
|
|
11
|
-
this.addFloatUniform("g_windAmount", 0.5);
|
|
12
|
-
this.addFloatUniform("g_windSpeed", 1.0);
|
|
13
|
-
this.addFloatUniform("g_windStrength", 0.5);
|
|
14
|
-
this.addVector4Uniform("g_windDirection", new Vector4(1.0, 0.0, 0.0, 0.0));
|
|
15
|
-
this.addFloatUniform("g_branchRootY", 0.0);
|
|
16
|
-
this.addFloatUniform("g_branchMaxAngle", 0.35);
|
|
17
|
-
this.addFloatUniform("g_branchMaxHeight", 2.0);
|
|
18
|
-
this.addFloatUniform("g_useVertexColorMask", 1.0);
|
|
19
|
-
this.addFloatUniform("g_spatialFrequency", 0.15);
|
|
20
|
-
this._windTimeAccum = 0.0;
|
|
21
|
-
}
|
|
22
|
-
awake() {
|
|
23
|
-
}
|
|
24
|
-
update() {
|
|
25
|
-
try {
|
|
26
|
-
const rawDt = SceneManager.GetDeltaSeconds(this.getScene());
|
|
27
|
-
const dt = Math.min(rawDt, 1 / 30);
|
|
28
|
-
const speed = this.getFloatValue("g_windSpeed") ?? 0;
|
|
29
|
-
if (speed > 0) {
|
|
30
|
-
this._windTimeAccum += dt;
|
|
31
|
-
this.setFloatValue("g_windTime", this._windTimeAccum);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
catch (e) {
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
getShaderName() {
|
|
38
|
-
return "TreeBranchMaterial";
|
|
39
|
-
}
|
|
40
|
-
setWindDirection(x, y, z) {
|
|
41
|
-
const v = new Vector3(x, y, z);
|
|
42
|
-
if (v.lengthSquared() < 1e-8) {
|
|
43
|
-
this.setVector4Value("g_windDirection", new Vector4(1, 0, 0, 0));
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
v.normalize();
|
|
47
|
-
this.setVector4Value("g_windDirection", new Vector4(v.x, v.y, v.z, 0.0));
|
|
48
|
-
}
|
|
49
|
-
getWindDirection() {
|
|
50
|
-
return this.getVector4Value("g_windDirection");
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
export class TreeBranchMaterialPlugin extends CustomShaderMaterialPlugin {
|
|
54
|
-
constructor(customMaterial, shaderName) {
|
|
55
|
-
super(customMaterial, shaderName, 110, { TREEBRANCHMATERIAL: false });
|
|
56
|
-
}
|
|
57
|
-
isCompatible(shaderLanguage) {
|
|
58
|
-
return (shaderLanguage === ShaderLanguage.WGSL || shaderLanguage === ShaderLanguage.GLSL);
|
|
59
|
-
}
|
|
60
|
-
getCustomCode(shaderType, shaderLanguage) {
|
|
61
|
-
if (shaderType === "vertex") {
|
|
62
|
-
if (shaderLanguage === ShaderLanguage.WGSL) {
|
|
63
|
-
return {
|
|
64
|
-
CUSTOM_VERTEX_MAIN_END: `
|
|
65
|
-
// -------------------------
|
|
66
|
-
// TreeBranch wind bending (local-space)
|
|
67
|
-
// Authoring (recommended):
|
|
68
|
-
// vertexColor.r = bend weight (0 trunk .. 1 tips)
|
|
69
|
-
// vertexColor.g = phase offset noise (0..1)
|
|
70
|
-
// Falls back to height-based weight if vertex color missing/disabled.
|
|
71
|
-
// -------------------------
|
|
72
|
-
|
|
73
|
-
fn safeNormalize(v: vec3f) -> vec3f {
|
|
74
|
-
let lsq = dot(v, v);
|
|
75
|
-
if (lsq < 1e-8) { return vec3f(1.0, 0.0, 0.0); }
|
|
76
|
-
return v * inverseSqrt(lsq);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
fn rotateRodrigues(p: vec3f, axis: vec3f, angle: f32) -> vec3f {
|
|
80
|
-
let a = safeNormalize(axis);
|
|
81
|
-
let c = cos(angle);
|
|
82
|
-
let s = sin(angle);
|
|
83
|
-
return p * c + cross(a, p) * s + a * dot(a, p) * (1.0 - c);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
// Local position & normal (preferred: use normalUpdated if present in shader)
|
|
87
|
-
var pL: vec3f = positionUpdated;
|
|
88
|
-
|
|
89
|
-
// If COLOR attribute exists, Babylon usually provides vertexInputs.color.
|
|
90
|
-
// If not available, these will be 1,1,1,1 (depending on pipeline) — we guard with g_useVertexColorMask.
|
|
91
|
-
var bendMask: f32 = 1.0;
|
|
92
|
-
var phaseNoise: f32 = 0.0;
|
|
93
|
-
if (uniforms.g_useVertexColorMask > 0.5) {
|
|
94
|
-
bendMask = clamp(vertexInputs.color.r, 0.0, 1.0);
|
|
95
|
-
phaseNoise = vertexInputs.color.g; // 0..1
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// Height-based fallback weight (normalized between rootY..maxHeight)
|
|
99
|
-
let denom = max(uniforms.g_branchMaxHeight - uniforms.g_branchRootY, 1e-3);
|
|
100
|
-
let h01 = clamp((pL.y - uniforms.g_branchRootY) / denom, 0.0, 1.0);
|
|
101
|
-
|
|
102
|
-
// Final per-vertex weight:
|
|
103
|
-
// - If using vertex colors: bendMask * smooth tip emphasis
|
|
104
|
-
// - Else: height-based
|
|
105
|
-
var w: f32 = h01;
|
|
106
|
-
if (uniforms.g_useVertexColorMask > 0.5) {
|
|
107
|
-
w = bendMask * (h01 * h01 * (3.0 - 2.0 * h01)); // smoothstep(h01)
|
|
108
|
-
} else {
|
|
109
|
-
w = h01 * h01; // a bit stiffer near base
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// Wind direction in LOCAL space:
|
|
113
|
-
// We transform windDirWorld by inverse world matrix rotation (approx using finalWorld columns).
|
|
114
|
-
// finalWorld transforms local->world. For direction, inverse rotation is transpose of 3x3 if no shear.
|
|
115
|
-
let windW = safeNormalize(uniforms.g_windDirection.xyz);
|
|
116
|
-
let rightW = safeNormalize(finalWorld[0].xyz);
|
|
117
|
-
let upW = safeNormalize(finalWorld[1].xyz);
|
|
118
|
-
let fwdW = safeNormalize(finalWorld[2].xyz);
|
|
119
|
-
|
|
120
|
-
// Convert world dir to local by dot with basis
|
|
121
|
-
let windL = safeNormalize(vec3f(dot(windW, rightW), dot(windW, upW), dot(windW, fwdW)));
|
|
122
|
-
|
|
123
|
-
// Bend axis: perpendicular to up and wind, in LOCAL space
|
|
124
|
-
var axisL = safeNormalize(cross(vec3f(0.0, 1.0, 0.0), windL));
|
|
125
|
-
if (dot(axisL, axisL) < 1e-6) { axisL = vec3f(1.0, 0.0, 0.0); }
|
|
126
|
-
|
|
127
|
-
// Spatially varying phase so whole tree doesn't move as a rigid sheet
|
|
128
|
-
// Use local xz for coherence; optionally mod by vertexColor.g
|
|
129
|
-
let spatial = (pL.x + pL.z) * uniforms.g_spatialFrequency;
|
|
130
|
-
let phase = uniforms.g_windTime * uniforms.g_windSpeed
|
|
131
|
-
+ spatial * uniforms.g_windStrength
|
|
132
|
-
+ phaseNoise * 6.28318;
|
|
133
|
-
|
|
134
|
-
// Two-wave composite like Unity-ish wind
|
|
135
|
-
let base = sin(phase);
|
|
136
|
-
let gust = 0.5 * sin(phase * 1.7 + 1.2);
|
|
137
|
-
let sway = (base + gust) * uniforms.g_windAmount;
|
|
138
|
-
|
|
139
|
-
// Convert sway to angle (clamped)
|
|
140
|
-
var angle = sway * w * uniforms.g_branchMaxAngle;
|
|
141
|
-
angle = clamp(angle, -uniforms.g_branchMaxAngle, uniforms.g_branchMaxAngle);
|
|
142
|
-
|
|
143
|
-
// Pivot in local space
|
|
144
|
-
let pivotL = vec3f(0.0, uniforms.g_branchRootY, 0.0);
|
|
145
|
-
let relL = pL - pivotL;
|
|
146
|
-
let bentRelL = rotateRodrigues(relL, axisL, angle);
|
|
147
|
-
let bentPL = pivotL + bentRelL;
|
|
148
|
-
|
|
149
|
-
// Transform to world using finalWorld (keeps proper anchoring)
|
|
150
|
-
let branchWorld = (finalWorld * vec4f(bentPL, 1.0)).xyz;
|
|
151
|
-
|
|
152
|
-
// Rotate normal similarly (only if NORMAL is active)
|
|
153
|
-
#ifdef NORMAL
|
|
154
|
-
// Babylon WGSL PBR usually provides normalUpdated in local/object space
|
|
155
|
-
var nL: vec3f = normalize(normalUpdated);
|
|
156
|
-
let bentNL = rotateRodrigues(nL, axisL, angle);
|
|
157
|
-
// Convert to world by world 3x3
|
|
158
|
-
let nW = normalize(vec3f(
|
|
159
|
-
dot(bentNL, vec3f(finalWorld[0].x, finalWorld[0].y, finalWorld[0].z)),
|
|
160
|
-
dot(bentNL, vec3f(finalWorld[1].x, finalWorld[1].y, finalWorld[1].z)),
|
|
161
|
-
dot(bentNL, vec3f(finalWorld[2].x, finalWorld[2].y, finalWorld[2].z))
|
|
162
|
-
));
|
|
163
|
-
vertexOutputs.vNormalW = nW;
|
|
164
|
-
#endif
|
|
165
|
-
|
|
166
|
-
#if defined(POSITION) || defined(BUMP)
|
|
167
|
-
vertexOutputs.vPositionW = branchWorld;
|
|
168
|
-
#endif
|
|
169
|
-
|
|
170
|
-
vertexOutputs.position = scene.viewProjection * vec4f(branchWorld, 1.0);
|
|
171
|
-
`
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
else {
|
|
175
|
-
return {
|
|
176
|
-
CUSTOM_VERTEX_DEFINITIONS: `
|
|
177
|
-
uniform float g_windTime;
|
|
178
|
-
uniform float g_windAmount;
|
|
179
|
-
uniform float g_windSpeed;
|
|
180
|
-
uniform float g_windStrength;
|
|
181
|
-
uniform vec4 g_windDirection;
|
|
182
|
-
|
|
183
|
-
uniform float g_branchRootY;
|
|
184
|
-
uniform float g_branchMaxAngle;
|
|
185
|
-
uniform float g_branchMaxHeight;
|
|
186
|
-
uniform float g_useVertexColorMask;
|
|
187
|
-
uniform float g_spatialFrequency;
|
|
188
|
-
|
|
189
|
-
vec3 safeNormalize(vec3 v) {
|
|
190
|
-
float lsq = dot(v, v);
|
|
191
|
-
if (lsq < 1e-8) return vec3(1.0, 0.0, 0.0);
|
|
192
|
-
return v * inversesqrt(lsq);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
vec3 rotateRodrigues(vec3 p, vec3 axis, float angle) {
|
|
196
|
-
vec3 a = safeNormalize(axis);
|
|
197
|
-
float c = cos(angle);
|
|
198
|
-
float s = sin(angle);
|
|
199
|
-
return p * c + cross(a, p) * s + a * dot(a, p) * (1.0 - c);
|
|
200
|
-
}
|
|
201
|
-
`,
|
|
202
|
-
CUSTOM_VERTEX_MAIN_END: `
|
|
203
|
-
// Local/object position
|
|
204
|
-
vec3 pL = positionUpdated;
|
|
205
|
-
|
|
206
|
-
// Vertex color mask (recommended authoring)
|
|
207
|
-
float bendMask = 1.0;
|
|
208
|
-
float phaseNoise = 0.0;
|
|
209
|
-
#ifdef VERTEXCOLOR
|
|
210
|
-
if (g_useVertexColorMask > 0.5) {
|
|
211
|
-
bendMask = clamp(color.r, 0.0, 1.0);
|
|
212
|
-
phaseNoise = color.g;
|
|
213
|
-
}
|
|
214
|
-
#endif
|
|
215
|
-
|
|
216
|
-
float denom = max(g_branchMaxHeight - g_branchRootY, 1e-3);
|
|
217
|
-
float h01 = clamp((pL.y - g_branchRootY) / denom, 0.0, 1.0);
|
|
218
|
-
|
|
219
|
-
float w = h01;
|
|
220
|
-
if (g_useVertexColorMask > 0.5) {
|
|
221
|
-
// smoothstep(h01)
|
|
222
|
-
w = bendMask * (h01 * h01 * (3.0 - 2.0 * h01));
|
|
223
|
-
} else {
|
|
224
|
-
w = h01 * h01;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
// Convert wind world dir to local using world basis (transpose approx)
|
|
228
|
-
vec3 windW = safeNormalize(g_windDirection.xyz);
|
|
229
|
-
vec3 rightW = safeNormalize(finalWorld[0].xyz);
|
|
230
|
-
vec3 upW = safeNormalize(finalWorld[1].xyz);
|
|
231
|
-
vec3 fwdW = safeNormalize(finalWorld[2].xyz);
|
|
232
|
-
vec3 windL = safeNormalize(vec3(dot(windW, rightW), dot(windW, upW), dot(windW, fwdW)));
|
|
233
|
-
|
|
234
|
-
vec3 axisL = safeNormalize(cross(vec3(0.0, 1.0, 0.0), windL));
|
|
235
|
-
if (dot(axisL, axisL) < 1e-6) axisL = vec3(1.0, 0.0, 0.0);
|
|
236
|
-
|
|
237
|
-
float spatial = (pL.x + pL.z) * g_spatialFrequency;
|
|
238
|
-
float phase = g_windTime * g_windSpeed
|
|
239
|
-
+ spatial * g_windStrength
|
|
240
|
-
+ phaseNoise * 6.2831853;
|
|
241
|
-
|
|
242
|
-
float base = sin(phase);
|
|
243
|
-
float gust = 0.5 * sin(phase * 1.7 + 1.2);
|
|
244
|
-
float sway = (base + gust) * g_windAmount;
|
|
245
|
-
|
|
246
|
-
float angle = clamp(sway * w * g_branchMaxAngle, -g_branchMaxAngle, g_branchMaxAngle);
|
|
247
|
-
|
|
248
|
-
vec3 pivotL = vec3(0.0, g_branchRootY, 0.0);
|
|
249
|
-
vec3 relL = pL - pivotL;
|
|
250
|
-
vec3 bentPL = pivotL + rotateRodrigues(relL, axisL, angle);
|
|
251
|
-
|
|
252
|
-
vec3 branchWorld = (finalWorld * vec4(bentPL, 1.0)).xyz;
|
|
253
|
-
|
|
254
|
-
#if defined(POSITION) || defined(BUMP)
|
|
255
|
-
vPositionW = branchWorld;
|
|
256
|
-
#endif
|
|
257
|
-
|
|
258
|
-
#ifdef NORMAL
|
|
259
|
-
// normalUpdated is local/object normal
|
|
260
|
-
vec3 nL = normalize(normalUpdated);
|
|
261
|
-
vec3 bentNL = rotateRodrigues(nL, axisL, angle);
|
|
262
|
-
|
|
263
|
-
// world normal from world basis (approx; assumes no non-uniform scale/shear)
|
|
264
|
-
vec3 nW = normalize(bentNL.x * rightW + bentNL.y * upW + bentNL.z * fwdW);
|
|
265
|
-
vNormalW = nW;
|
|
266
|
-
#endif
|
|
267
|
-
|
|
268
|
-
gl_Position = viewProjection * vec4(branchWorld, 1.0);
|
|
269
|
-
`
|
|
270
|
-
};
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
if (shaderType === "fragment") {
|
|
274
|
-
if (shaderLanguage === ShaderLanguage.WGSL) {
|
|
275
|
-
return {
|
|
276
|
-
CUSTOM_FRAGMENT_BEFORE_FINALCOLORCOMPOSITION: `
|
|
277
|
-
// no-op
|
|
278
|
-
`
|
|
279
|
-
};
|
|
280
|
-
}
|
|
281
|
-
else {
|
|
282
|
-
return {
|
|
283
|
-
CUSTOM_FRAGMENT_BEFORE_FINALCOLORCOMPOSITION: `
|
|
284
|
-
// no-op
|
|
285
|
-
`
|
|
286
|
-
};
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
return null;
|
|
290
|
-
}
|
|
291
|
-
getUniforms(shaderLanguage) {
|
|
292
|
-
const wgsl = (shaderLanguage === ShaderLanguage.WGSL);
|
|
293
|
-
this.vertexDefinitions = this.getCustomShaderMaterial().getCustomVertexCode(wgsl);
|
|
294
|
-
this.fragmentDefinitions = (wgsl === true) ? this.getCustomShaderMaterial().getCustomFragmentCode(wgsl) : null;
|
|
295
|
-
return this.getCustomShaderMaterial().getCustomUniforms(wgsl);
|
|
296
|
-
}
|
|
297
|
-
getSamplers(samplers) {
|
|
298
|
-
const customSamplers = this.getCustomShaderMaterial().getCustomSamplers();
|
|
299
|
-
if (customSamplers && customSamplers.length > 0)
|
|
300
|
-
samplers.push(...customSamplers);
|
|
301
|
-
}
|
|
302
|
-
getAttributes(attributes, scene, mesh) {
|
|
303
|
-
const customAttributes = this.getCustomShaderMaterial().getCustomAttributes();
|
|
304
|
-
if (customAttributes && customAttributes.length > 0)
|
|
305
|
-
attributes.push(...customAttributes);
|
|
306
|
-
if (attributes.indexOf("color") === -1)
|
|
307
|
-
attributes.push("color");
|
|
308
|
-
}
|
|
309
|
-
prepareDefines(defines, scene, mesh) {
|
|
310
|
-
if (!this.getIsEnabled())
|
|
311
|
-
return;
|
|
312
|
-
this.getCustomShaderMaterial().prepareCustomDefines(defines);
|
|
313
|
-
}
|
|
314
|
-
bindForSubMesh(uniformBuffer, scene, engine, subMesh) {
|
|
315
|
-
if (!this.getIsEnabled())
|
|
316
|
-
return;
|
|
317
|
-
this.getCustomShaderMaterial().updateCustomBindings(uniformBuffer);
|
|
318
|
-
}
|
|
319
|
-
static ExtractWindZoneOverride(properties, terrainTransform, builderInstance) {
|
|
320
|
-
const candidates = [];
|
|
321
|
-
if (properties)
|
|
322
|
-
candidates.push(properties);
|
|
323
|
-
if (properties && properties.properties)
|
|
324
|
-
candidates.push(properties.properties);
|
|
325
|
-
const meta = terrainTransform?.metadata;
|
|
326
|
-
if (meta)
|
|
327
|
-
candidates.push(meta);
|
|
328
|
-
if (meta && meta.toolkit)
|
|
329
|
-
candidates.push(meta.toolkit);
|
|
330
|
-
if (meta && meta.properties)
|
|
331
|
-
candidates.push(meta.properties);
|
|
332
|
-
const bmeta = builderInstance?.metadata;
|
|
333
|
-
if (bmeta)
|
|
334
|
-
candidates.push(bmeta);
|
|
335
|
-
if (bmeta && bmeta.toolkit)
|
|
336
|
-
candidates.push(bmeta.toolkit);
|
|
337
|
-
const tmeta = builderInstance?.transform?.metadata;
|
|
338
|
-
if (tmeta)
|
|
339
|
-
candidates.push(tmeta);
|
|
340
|
-
if (tmeta && tmeta.toolkit)
|
|
341
|
-
candidates.push(tmeta.toolkit);
|
|
342
|
-
let zones = null;
|
|
343
|
-
for (const c of candidates) {
|
|
344
|
-
if (!c)
|
|
345
|
-
continue;
|
|
346
|
-
if (Array.isArray(c.windzones)) {
|
|
347
|
-
zones = c.windzones;
|
|
348
|
-
break;
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
if (!zones || zones.length === 0)
|
|
352
|
-
return null;
|
|
353
|
-
let best = null;
|
|
354
|
-
let bestScore = -1e9;
|
|
355
|
-
for (const z of zones) {
|
|
356
|
-
if (!z)
|
|
357
|
-
continue;
|
|
358
|
-
const t = ((z.type != null) ? z.type : (z.mode != null ? z.mode : "")).toString().toLowerCase();
|
|
359
|
-
const isDirectional = (t.indexOf("direction") >= 0);
|
|
360
|
-
const main = (z.windMain != null) ? z.windMain : 0.0;
|
|
361
|
-
const score = (isDirectional ? 1000.0 : 0.0) + main;
|
|
362
|
-
if (score > bestScore) {
|
|
363
|
-
bestScore = score;
|
|
364
|
-
best = z;
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
return best;
|
|
368
|
-
}
|
|
369
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { Scene } from '@babylonjs/core/scene';
|
|
2
|
-
import { CustomShaderMaterial, CustomShaderMaterialPlugin } from './scenemanager';
|
|
3
|
-
import { ShaderLanguage } from '@babylonjs/core/Materials';
|
|
4
|
-
import { MaterialDefines } from '@babylonjs/core/Materials/materialDefines';
|
|
5
|
-
import { UniformBuffer } from '@babylonjs/core/Materials/uniformBuffer';
|
|
6
|
-
import { SubMesh } from '@babylonjs/core/Meshes/subMesh';
|
|
7
|
-
import { AbstractMesh } from '@babylonjs/core/Meshes/abstractMesh';
|
|
8
|
-
import { AbstractEngine } from '@babylonjs/core/Engines/abstractEngine';
|
|
9
|
-
export declare class UniversalTerrainMaterial extends CustomShaderMaterial {
|
|
10
|
-
protected terrainInfo: any;
|
|
11
|
-
constructor(name: string, scene: Scene);
|
|
12
|
-
awake(): void;
|
|
13
|
-
update(): void;
|
|
14
|
-
getShaderName(): string;
|
|
15
|
-
getTerrainInfo(): any;
|
|
16
|
-
}
|
|
17
|
-
export declare class UniversalTerrainMaterialPlugin extends CustomShaderMaterialPlugin {
|
|
18
|
-
private colorName;
|
|
19
|
-
private splatmapSampler;
|
|
20
|
-
private detailsSampler;
|
|
21
|
-
private normalsSampler;
|
|
22
|
-
private GLSL_CustomFragment;
|
|
23
|
-
private GLSL_CustomVertex;
|
|
24
|
-
private GLSL_VertexMainEnd;
|
|
25
|
-
private GLSL_FragmentUpdateColor;
|
|
26
|
-
private WGSL_CustomFragment;
|
|
27
|
-
private WGSL_CustomVertex;
|
|
28
|
-
private WGSL_VertexMainEnd;
|
|
29
|
-
private WGSL_FragmentUpdateColor;
|
|
30
|
-
constructor(customMaterial: CustomShaderMaterial, shaderName: string);
|
|
31
|
-
isCompatible(shaderLanguage: ShaderLanguage): boolean;
|
|
32
|
-
getClassName(): string;
|
|
33
|
-
getCustomCode(shaderType: string, shaderLanguage: ShaderLanguage): any;
|
|
34
|
-
getUniforms(shaderLanguage: ShaderLanguage): any;
|
|
35
|
-
getSamplers(samplers: string[]): void;
|
|
36
|
-
getAttributes(attributes: string[], scene: Scene, mesh: AbstractMesh): void;
|
|
37
|
-
prepareDefines(defines: MaterialDefines, scene: Scene, mesh: AbstractMesh): void;
|
|
38
|
-
bindForSubMesh(uniformBuffer: UniformBuffer, scene: Scene, engine: AbstractEngine, subMesh: SubMesh): void;
|
|
39
|
-
private WGSL_FormatTerrainVertexDefintions;
|
|
40
|
-
private WGSL_FormatTerrainVertexMainEnd;
|
|
41
|
-
private WGSL_FormatTerrainFragmentDefintions;
|
|
42
|
-
private WGSL_FormatTerrainFragmentUpdateColor;
|
|
43
|
-
private GLSL_FormatTerrainVertexDefintions;
|
|
44
|
-
private GLSL_FormatTerrainVertexMainEnd;
|
|
45
|
-
private GLSL_FormatTerrainFragmentDefintions;
|
|
46
|
-
private GLSL_FormatTerrainFragmentUpdateColor;
|
|
47
|
-
}
|
|
48
|
-
//# sourceMappingURL=universalterrainmaterial.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"universalterrainmaterial.d.ts","sourceRoot":"","sources":["../src/universalterrainmaterial.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAC9C,OAAO,EAAE,oBAAoB,EAAE,0BAA0B,EAAgB,MAAM,gBAAgB,CAAC;AAChG,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,2CAA2C,CAAC;AAC5E,OAAO,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAC;AACxE,OAAO,EAAE,OAAO,EAAE,MAAM,gCAAgC,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,qCAAqC,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,wCAAwC,CAAC;AAIxE,qBAAa,wBAAyB,SAAQ,oBAAoB;IAC9D,SAAS,CAAC,WAAW,EAAE,GAAG,CAAQ;gBAEf,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK;IAMtC,KAAK,IAAI,IAAI;IAIb,MAAM,IAAI,IAAI;IAId,aAAa,IAAI,MAAM;IAIvB,cAAc,IAAI,GAAG;CAG7B;AAEH,qBAAa,8BAA+B,SAAQ,0BAA0B;IAC1E,OAAO,CAAC,SAAS,CAA2B;IAC5C,OAAO,CAAC,eAAe,CAA6B;IACpD,OAAO,CAAC,cAAc,CAA4B;IAClD,OAAO,CAAC,cAAc,CAA4B;IAClD,OAAO,CAAC,mBAAmB,CAAgB;IAC3C,OAAO,CAAC,iBAAiB,CAAgB;IACzC,OAAO,CAAC,kBAAkB,CAAgB;IAC1C,OAAO,CAAC,wBAAwB,CAAgB;IAChD,OAAO,CAAC,mBAAmB,CAAgB;IAC3C,OAAO,CAAC,iBAAiB,CAAgB;IACzC,OAAO,CAAC,kBAAkB,CAAgB;IAC1C,OAAO,CAAC,wBAAwB,CAAgB;gBAC7B,cAAc,EAAE,oBAAoB,EAAE,UAAU,EAAE,MAAM;IAOpE,YAAY,CAAC,cAAc,EAAE,cAAc,GAAG,OAAO;IAIrD,YAAY,IAAI,MAAM;IAatB,aAAa,CAAC,UAAU,EAAE,MAAM,EAAE,cAAc,EAAE,cAAc,GAAG,GAAG;IA2CtE,WAAW,CAAC,cAAc,EAAE,cAAc,GAAG,GAAG;IAoBhD,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,IAAI;IAMrC,aAAa,CAAC,UAAU,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,YAAY,GAAG,IAAI;IAM3E,cAAc,CAAC,OAAO,EAAE,eAAe,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,YAAY,GAAG,IAAI;IAMhF,cAAc,CAAC,aAAa,EAAE,aAAa,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI;IASjH,OAAO,CAAC,kCAAkC;IAY1C,OAAO,CAAC,+BAA+B;IAcvC,OAAO,CAAC,oCAAoC;IAsF5C,OAAO,CAAC,qCAAqC;IAyK7C,OAAO,CAAC,kCAAkC;IAY1C,OAAO,CAAC,+BAA+B;IAcvC,OAAO,CAAC,oCAAoC;IAiF5C,OAAO,CAAC,qCAAqC;CAoK9C"}
|