feat(all): 迁移扩展相关功能

This commit is contained in:
plum
2026-04-08 15:34:43 +08:00
parent ad2dd979eb
commit d7c0dba569
278 changed files with 25207 additions and 62 deletions
@@ -0,0 +1,76 @@
import * as THREE from 'three';
import { WaterPool } from '@/core/objects';
import App from "@/core/app/App";
import { AddObjectCommand } from '@/core/commands/AddObjectCommand';
export class Water {
static DefaultTilesUrl = new URL(import.meta.env.BASE_URL + 'resource/textures/tiles.jpg', import.meta.url).href;
constructor() { }
static loadFile(url: string) {
return new Promise((resolve, reject) => {
const loader = new THREE.FileLoader();
loader.load(url, resolve, undefined, reject);
});
}
/**
* 水池/也可以做水面
*/
static waterPool(options?: IWaterPool.Options, position: number[] = [0, 0, 0]) {
return new Promise<WaterPool>((resolve, reject) => {
const _options: IWaterPool.Options = Object.assign({
name: "WaterPool",
type: 'cylinder',
light: [0.7, 1, -0.3],
diameter: 3.2,
height: 5,
// 仅显示水体体积,不显示池壁纹理
wallMode: 'volume',
wallOpacity: 0.3,
// 使用与原始着色接近的水体颜色(偏亮蓝绿)
volumeColor: new THREE.Color(0.4, 0.9, 1.0),
// 开启屏幕空间折射,保证能看到水下物体
useSceneRefraction: 1,
// 水面透视强度
surfaceTransmittance: 0.9,
// 降低波纹边缘对比度
normalStrength: 0.6,
refractionStrength: 0.035,
}, options);
if (!_options.tiles && (_options.wallMode ? _options.wallMode === 'wall' : _options.wall === true)) {
_options.tiles = new THREE.TextureLoader().load(Water.DefaultTilesUrl);
_options.tiles.wrapS = THREE.RepeatWrapping;
_options.tiles.wrapT = THREE.RepeatWrapping;
}
const cylinderPool = new WaterPool(_options);
Promise.all([cylinderPool.loaded]).then(() => {
cylinderPool.setPosition(...position);
WaterPool.register(cylinderPool);
const viewer = App.viewer;
if (viewer && !cylinderPool.parent) {
App.execute(new AddObjectCommand(cylinderPool), `Add WaterPool: ${_options.name}`);
}
if (viewer) {
Water.registerRendering();
}
resolve(cylinderPool);
}).catch((err) => {
reject(err);
});
});
}
/**
* 注册渲染行为
*/
static registerRendering() {
WaterPool.registerRendering();
}
}