@d5techs/3dgs-lib 1.4.49 → 1.4.51
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 +38 -38
- package/dist/3dgs-lib.cjs.map +1 -1
- package/dist/3dgs-lib.js +38 -38
- 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,22 +2128,38 @@ 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
|
|
2152
|
-
|
|
2141
|
+
let dir = normalize(input.dir);
|
|
2142
|
+
|
|
2143
|
+
let camX = u.extra.y;
|
|
2144
|
+
let camY = u.extra.z;
|
|
2145
|
+
let camZ = u.extra.w;
|
|
2146
|
+
|
|
2147
|
+
let doGround = u.extra.x > 0.5 && dir.y < -0.001 && camY > 0.01;
|
|
2148
|
+
let safeDirY = select(dir.y, -0.01, dir.y > -0.001);
|
|
2149
|
+
let t = camY / (-safeDirY);
|
|
2150
|
+
let gx = camX + dir.x * t;
|
|
2151
|
+
let gz = camZ + dir.z * t;
|
|
2152
|
+
let scale = max(camY, 1.0) * 5.0;
|
|
2153
|
+
let groundDir = normalize(vec3<f32>(gx / max(scale, 0.01), -1.0, gz / max(scale, 0.01)));
|
|
2154
|
+
|
|
2155
|
+
let skyColor = textureSample(cubeTexture, cubeSampler, dir);
|
|
2156
|
+
let groundColor = textureSample(cubeTexture, cubeSampler, groundDir);
|
|
2157
|
+
|
|
2158
|
+
let blend = smoothstep(0.0, -0.12, dir.y);
|
|
2159
|
+
let mixed = mix(skyColor.rgb, groundColor.rgb, blend);
|
|
2160
|
+
|
|
2161
|
+
let final_color = select(skyColor.rgb, mixed, doGround);
|
|
2162
|
+
return vec4<f32>(final_color, 1.0);
|
|
2153
2163
|
}
|
|
2154
2164
|
`
|
|
2155
2165
|
);
|
|
@@ -2171,7 +2181,7 @@ class SkyboxRenderer {
|
|
|
2171
2181
|
entries: [
|
|
2172
2182
|
{
|
|
2173
2183
|
binding: 0,
|
|
2174
|
-
visibility: GPUShaderStage.VERTEX,
|
|
2184
|
+
visibility: GPUShaderStage.VERTEX | GPUShaderStage.FRAGMENT,
|
|
2175
2185
|
buffer: { type: "uniform" }
|
|
2176
2186
|
},
|
|
2177
2187
|
{
|
|
@@ -2261,12 +2271,7 @@ class SkyboxRenderer {
|
|
|
2261
2271
|
});
|
|
2262
2272
|
this.cubeTexture = tex;
|
|
2263
2273
|
}
|
|
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) {
|
|
2274
|
+
prepareFrame(viewMatrix, projectionMatrix, cameraPosition) {
|
|
2270
2275
|
if (!this.isActive) {
|
|
2271
2276
|
this.frameReady = false;
|
|
2272
2277
|
return;
|
|
@@ -2284,10 +2289,17 @@ class SkyboxRenderer {
|
|
|
2284
2289
|
ud[9] = viewMatrix[9];
|
|
2285
2290
|
ud[10] = viewMatrix[10];
|
|
2286
2291
|
ud[11] = 0;
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2292
|
+
if (this.alignToGround && cameraPosition) {
|
|
2293
|
+
ud[12] = 1;
|
|
2294
|
+
ud[13] = cameraPosition[0];
|
|
2295
|
+
ud[14] = cameraPosition[1];
|
|
2296
|
+
ud[15] = cameraPosition[2];
|
|
2297
|
+
} else {
|
|
2298
|
+
ud[12] = 0;
|
|
2299
|
+
ud[13] = 0;
|
|
2300
|
+
ud[14] = 0;
|
|
2301
|
+
ud[15] = 0;
|
|
2302
|
+
}
|
|
2291
2303
|
this.device.queue.writeBuffer(this.uniformBuffer, 0, ud);
|
|
2292
2304
|
this.frameReady = true;
|
|
2293
2305
|
}
|
|
@@ -18922,23 +18934,11 @@ class App {
|
|
|
18922
18934
|
this.updateAdaptivePerformance();
|
|
18923
18935
|
this.hotspotManager.updateBillboards();
|
|
18924
18936
|
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.15, Math.min(0.15, -fullAngle * 0.1));
|
|
18936
|
-
}
|
|
18937
|
-
}
|
|
18937
|
+
const cam = this.camera.position;
|
|
18938
18938
|
this.skyboxRenderer.prepareFrame(
|
|
18939
18939
|
this.camera.viewMatrix,
|
|
18940
18940
|
this.camera.projectionMatrix,
|
|
18941
|
-
|
|
18941
|
+
[cam[0], cam[1], cam[2]]
|
|
18942
18942
|
);
|
|
18943
18943
|
}
|
|
18944
18944
|
const pass = this.renderer.beginFrame();
|