Commit a9dcf2ed by xhw

uploadImage

parent 3a29c1d7
...@@ -43,7 +43,7 @@ export class SparkSplatViewer { ...@@ -43,7 +43,7 @@ export class SparkSplatViewer {
// Spark渲染器配置 // Spark渲染器配置
maxStdDev: options.maxStdDev ?? Math.sqrt(5), maxStdDev: options.maxStdDev ?? Math.sqrt(5),
sortRadial: options.sortRadial ?? true, sortRadial: options.sortRadial ?? false,
enableLod: options.enableLod ?? true, enableLod: options.enableLod ?? true,
lodSplatScale: options.lodSplatScale ?? 1.0, lodSplatScale: options.lodSplatScale ?? 1.0,
...@@ -117,11 +117,17 @@ export class SparkSplatViewer { ...@@ -117,11 +117,17 @@ export class SparkSplatViewer {
antialias: false, antialias: false,
alpha: false, alpha: false,
canvas: options.canvas || undefined, canvas: options.canvas || undefined,
powerPreference: "high-performance", // 强制独显
depth: false, // 3DGS 不需要 depth
stencil: false,
}); });
this.renderer.setSize(this.container.clientWidth, this.container.clientHeight); this.renderer.setSize(this.container.clientWidth, this.container.clientHeight);
this.renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2)); this.renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1));
this.renderer.toneMapping = THREE.ACESFilmicToneMapping; // this.renderer.toneMapping = THREE.ACESFilmicToneMapping;
this.renderer.toneMappingExposure = 1; // this.renderer.toneMappingExposure = 1;
// 改为:
this.renderer.toneMapping = THREE.NoToneMapping; // 或 LinearToneMapping
if (!options.canvas) { if (!options.canvas) {
this.container.appendChild(this.renderer.domElement); this.container.appendChild(this.renderer.domElement);
...@@ -293,17 +299,35 @@ export class SparkSplatViewer { ...@@ -293,17 +299,35 @@ export class SparkSplatViewer {
_startRenderLoop() { _startRenderLoop() {
const animate = () => { const animate = () => {
if (this.isDestroyed) return; if (this.isDestroyed) return;
requestAnimationFrame(animate); // 先预约下一帧,避免掉帧
const deltaTime = this._clock.getDelta(); const deltaTime = this._clock.getDelta();
// 自动旋转(仅在用户未交互时) // 自动旋转
if (this.options.autoRotate && !this._isUserInteracting) { if (this.options.autoRotate && !this._isUserInteracting) {
this._doAutoRotate(deltaTime); this._doAutoRotate(deltaTime);
this._needsRender = true;
} }
// 控制器阻尼更新
if (this.controls.enableDamping) {
const oldPos = this._lastCameraPos.clone();
const oldQuat = this._lastCameraQuat.clone();
this.controls.update();
if (!this.camera.position.equals(oldPos) || !this.camera.quaternion.equals(oldQuat)) {
this._needsRender = true;
this._lastCameraPos.copy(this.camera.position);
this._lastCameraQuat.copy(this.camera.quaternion);
}
} else {
this.controls.update(); this.controls.update();
}
// 只在需要时渲染
if (this._needsRender) {
this.renderer.render(this.scene, this.camera); this.renderer.render(this.scene, this.camera);
requestAnimationFrame(animate); this._needsRender = false;
}
}; };
requestAnimationFrame(animate); requestAnimationFrame(animate);
} }
...@@ -316,6 +340,7 @@ export class SparkSplatViewer { ...@@ -316,6 +340,7 @@ export class SparkSplatViewer {
this.camera.aspect = w / h; this.camera.aspect = w / h;
this.camera.updateProjectionMatrix(); this.camera.updateProjectionMatrix();
this.renderer.setSize(w, h); this.renderer.setSize(w, h);
this.renderer.setPixelRatio(Math.min(window.devicePixelRatio, 1.0)); // ← 保持限制
} }
/** 获取设备类型 */ /** 获取设备类型 */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment