@d5techs/3dgs-lib 1.4.48 → 1.4.50
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/3dgs-lib.cjs +39 -37
- package/dist/3dgs-lib.cjs.map +1 -1
- package/dist/3dgs-lib.js +39 -37
- package/dist/3dgs-lib.js.map +1 -1
- package/dist/core/SkyboxRenderer.d.ts +1 -6
- package/package.json +1 -1
package/dist/3dgs-lib.js
CHANGED
|
@@ -2115,12 +2115,6 @@ struct VSOut {
|
|
|
2115
2115
|
@location(0) dir: vec3<f32>,
|
|
2116
2116
|
};
|
|
2117
2117
|
|
|
2118
|
-
fn rotateX(d: vec3<f32>, angle: f32) -> vec3<f32> {
|
|
2119
|
-
let c = cos(angle);
|
|
2120
|
-
let s = sin(angle);
|
|
2121
|
-
return vec3<f32>(d.x, c * d.y - s * d.z, s * d.y + c * d.z);
|
|
2122
|
-
}
|
|
2123
|
-
|
|
2124
2118
|
@vertex
|
|
2125
2119
|
fn vs(@builtin(vertex_index) vi: u32) -> VSOut {
|
|
2126
2120
|
let positions = array<vec2<f32>, 3>(
|
|
@@ -2134,21 +2128,39 @@ fn vs(@builtin(vertex_index) vi: u32) -> VSOut {
|
|
|
2134
2128
|
|
|
2135
2129
|
let eyeDir = vec3<f32>(p.x * u.col0.w, p.y * u.col1.w, -1.0);
|
|
2136
2130
|
|
|
2137
|
-
|
|
2131
|
+
out.dir = vec3<f32>(
|
|
2138
2132
|
dot(u.col0.xyz, eyeDir),
|
|
2139
2133
|
dot(u.col1.xyz, eyeDir),
|
|
2140
2134
|
dot(u.col2.xyz, eyeDir),
|
|
2141
2135
|
);
|
|
2142
|
-
|
|
2143
|
-
worldDir = rotateX(worldDir, u.extra.x);
|
|
2144
|
-
|
|
2145
|
-
out.dir = worldDir;
|
|
2146
2136
|
return out;
|
|
2147
2137
|
}
|
|
2148
2138
|
|
|
2149
2139
|
@fragment
|
|
2150
2140
|
fn fs(input: VSOut) -> @location(0) vec4<f32> {
|
|
2151
|
-
let
|
|
2141
|
+
let dir = normalize(input.dir);
|
|
2142
|
+
|
|
2143
|
+
let alignGround = u.extra.x > 0.5;
|
|
2144
|
+
let camY = u.extra.z;
|
|
2145
|
+
|
|
2146
|
+
if (alignGround && dir.y < -0.001 && camY > 0.01) {
|
|
2147
|
+
let camX = u.extra.y;
|
|
2148
|
+
let camZ = u.extra.w;
|
|
2149
|
+
|
|
2150
|
+
let t = camY / (-dir.y);
|
|
2151
|
+
let gx = camX + dir.x * t;
|
|
2152
|
+
let gz = camZ + dir.z * t;
|
|
2153
|
+
|
|
2154
|
+
let scale = max(camY, 1.0) * 5.0;
|
|
2155
|
+
let groundDir = normalize(vec3<f32>(gx / max(scale, 0.01), -1.0, gz / max(scale, 0.01)));
|
|
2156
|
+
let groundColor = textureSample(cubeTexture, cubeSampler, groundDir);
|
|
2157
|
+
let skyColor = textureSample(cubeTexture, cubeSampler, dir);
|
|
2158
|
+
|
|
2159
|
+
let blend = smoothstep(0.0, -0.12, dir.y);
|
|
2160
|
+
return vec4<f32>(mix(skyColor.rgb, groundColor.rgb, blend), 1.0);
|
|
2161
|
+
}
|
|
2162
|
+
|
|
2163
|
+
let color = textureSample(cubeTexture, cubeSampler, dir);
|
|
2152
2164
|
return vec4<f32>(color.rgb, 1.0);
|
|
2153
2165
|
}
|
|
2154
2166
|
`
|
|
@@ -2171,7 +2183,7 @@ class SkyboxRenderer {
|
|
|
2171
2183
|
entries: [
|
|
2172
2184
|
{
|
|
2173
2185
|
binding: 0,
|
|
2174
|
-
visibility: GPUShaderStage.VERTEX,
|
|
2186
|
+
visibility: GPUShaderStage.VERTEX | GPUShaderStage.FRAGMENT,
|
|
2175
2187
|
buffer: { type: "uniform" }
|
|
2176
2188
|
},
|
|
2177
2189
|
{
|
|
@@ -2261,12 +2273,7 @@ class SkyboxRenderer {
|
|
|
2261
2273
|
});
|
|
2262
2274
|
this.cubeTexture = tex;
|
|
2263
2275
|
}
|
|
2264
|
-
|
|
2265
|
-
* Write uniforms BEFORE beginFrame().
|
|
2266
|
-
* pitchOffset: radians to rotate sampling direction around world X axis,
|
|
2267
|
-
* used to align skybox horizon with model ground plane.
|
|
2268
|
-
*/
|
|
2269
|
-
prepareFrame(viewMatrix, projectionMatrix, pitchOffset = 0) {
|
|
2276
|
+
prepareFrame(viewMatrix, projectionMatrix, cameraPosition) {
|
|
2270
2277
|
if (!this.isActive) {
|
|
2271
2278
|
this.frameReady = false;
|
|
2272
2279
|
return;
|
|
@@ -2284,10 +2291,17 @@ class SkyboxRenderer {
|
|
|
2284
2291
|
ud[9] = viewMatrix[9];
|
|
2285
2292
|
ud[10] = viewMatrix[10];
|
|
2286
2293
|
ud[11] = 0;
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2294
|
+
if (this.alignToGround && cameraPosition) {
|
|
2295
|
+
ud[12] = 1;
|
|
2296
|
+
ud[13] = cameraPosition[0];
|
|
2297
|
+
ud[14] = cameraPosition[1];
|
|
2298
|
+
ud[15] = cameraPosition[2];
|
|
2299
|
+
} else {
|
|
2300
|
+
ud[12] = 0;
|
|
2301
|
+
ud[13] = 0;
|
|
2302
|
+
ud[14] = 0;
|
|
2303
|
+
ud[15] = 0;
|
|
2304
|
+
}
|
|
2291
2305
|
this.device.queue.writeBuffer(this.uniformBuffer, 0, ud);
|
|
2292
2306
|
this.frameReady = true;
|
|
2293
2307
|
}
|
|
@@ -18922,23 +18936,11 @@ class App {
|
|
|
18922
18936
|
this.updateAdaptivePerformance();
|
|
18923
18937
|
this.hotspotManager.updateBillboards();
|
|
18924
18938
|
if ((_a2 = this.skyboxRenderer) == null ? void 0 : _a2.isActive) {
|
|
18925
|
-
|
|
18926
|
-
if (this.skyboxRenderer.alignToGround) {
|
|
18927
|
-
const cam = this.camera.position;
|
|
18928
|
-
const mc = this.controls.modelCenter;
|
|
18929
|
-
const mr = this.controls.modelRadius;
|
|
18930
|
-
if (mr !== Infinity) {
|
|
18931
|
-
const dx = cam[0] - mc[0];
|
|
18932
|
-
const dz = cam[2] - mc[2];
|
|
18933
|
-
const hDist = Math.sqrt(dx * dx + dz * dz);
|
|
18934
|
-
const fullAngle = Math.atan2(cam[1], Math.max(hDist, 0.01));
|
|
18935
|
-
pitchOffset = Math.max(-0.5, Math.min(0.5, -fullAngle * 0.35));
|
|
18936
|
-
}
|
|
18937
|
-
}
|
|
18939
|
+
const cam = this.camera.position;
|
|
18938
18940
|
this.skyboxRenderer.prepareFrame(
|
|
18939
18941
|
this.camera.viewMatrix,
|
|
18940
18942
|
this.camera.projectionMatrix,
|
|
18941
|
-
|
|
18943
|
+
[cam[0], cam[1], cam[2]]
|
|
18942
18944
|
);
|
|
18943
18945
|
}
|
|
18944
18946
|
const pass = this.renderer.beginFrame();
|