Skip to content

EffectsFacade — 效果子门面

通过 app.effects 访问 3D 场景效果管理。

add(type, options)

添加效果。

ts
add(type: string, options?: object): EffectRef
参数类型描述
typestring效果类型(如 'bloom''fog''glow'
optionsobject类型对应的选项

返回值:EffectRef,每次调用生成唯一 ID。

ts
const fx = app.effects.add('bloom');
// fx.id 形如 'fx_1'

const fog = app.effects.add('fog', { density: 0.5 });

get(id)

获取效果引用。

ts
get(id: string): EffectRef | null
ts
const fx = app.effects.get('fx_1');
if (fx) {
  fx.setEnabled(false);
}

list()

列出所有效果。

ts
list(): EffectRef[]
ts
const effects = app.effects.list();
effects.forEach(fx => console.log(fx.id));

remove(idOrRef)

移除效果。

ts
remove(idOrRef: string | EffectRef): void

接受字符串 ID 或 EffectRef 对象。

ts
app.effects.remove('fx_1');
// 或
app.effects.remove(fxRef);

setLighting(options)

设置场景光照。

ts
setLighting(options?: { sunPosition?: Coordinate | 'now'; shadows?: boolean; ambient?: string }): this
参数类型描述
sunPositionCoordinate | 'now'太阳位置坐标或 'now'(当前时间)
shadowsboolean是否启用阴影
ambientstring环境光颜色
ts
app.effects.setLighting({ sunPosition: 'now', shadows: true, ambient: '#ffffff' });

// 指定太阳位置
app.effects.setLighting({ sunPosition: [116, 39] });

setClipping(planes)

设置裁剪平面。

ts
setClipping(planes: Array<{ normal: [number, number, number]; distance: number }> | null): this
参数类型描述
planesArray | null裁剪平面数组,或 null 移除所有裁剪

每个平面包含:

字段类型说明
normal[number, number, number]平面法向量
distancenumber到原点的距离
ts
app.effects.setClipping([
  { normal: [0, 0, 1], distance: 100 },
]);

// 移除裁剪
app.effects.setClipping(null);

EffectRef

效果引用对象:

属性/方法类型说明
idstring效果唯一标识
setEnabled(enabled)EffectRef启用/禁用效果(链式)
remove()void移除自身
ts
fx.setEnabled(false);   // 禁用
fx.setEnabled(true);    // 启用
fx.remove();            // 移除

四川省交通运输综合地理服务平台 地图开发框架