Appearance
贴花
样例:
createDecal
创建贴花
定义:
ts
interface DecalInfo extends BaseObjectInfo {
url?: string;
color?: IColor;
opacity?: number;
snapping?: boolean;
snappingDistance?: number;
snappingTargets?: Object3D[];
}
function createDecal(info: DecalInfo, parent?: Object3D | null): Promise<Decal>;
用法:
js
const decal = await ssp.createDecal({
id: 'decal',
url: './img/poi_001.png',
position: {
x: 0,
y: 2,
z: 3,
},
rotation: {
x: 0,
y: 0,
z: 0,
},
scale: {
x: 1,
y: 1,
z: 1,
},
snapping: true,
snappingDistance: 1,
});
参数:
info
- 描述: 贴花参数
- 必填:
- 类型: DecalInfo
DecalInfo
属性 | 描述 | 类型 | 必填 | 默认值 |
---|---|---|---|---|
url | 图片地址 | string | ||
color | 颜色 | IColor | #fff | |
opacity | 不透明度 | number | 1 | |
snapping | 是否开启吸附 | boolean | true | |
snappingDistance | 吸附距离 | number | 1 | |
snappingTargets | 吸附目标 | Object3D[] | 场景所有模型 |
其他配置请参考BaseObjectInfo
decal.updateTexture
更新贴花纹理
定义:
ts
Decal.updateTexture(url: DecalInfo['url']): Promise<void>;
用法:
js
decal.updateTexture('xxx.png');
// 重新渲染
ssp.render();
decal.updateMaterial
更新贴花材质
定义:
ts
type DecalMaterialInfo = Pick<DecalInfo, 'color' | 'opacity'>
Decal.updateMaterial(params?: DecalMaterialInfo): void
用法:
js
decal.updateMaterial({ color: '#ff0', opacity: 0.5 });
// 重新渲染
ssp.render();
updateDecalGeometry
更新贴花几何结构
定义:
ts
type DecalGeometryInfo = Pick<DecalInfo, 'snapping' | 'snappingDistance' | 'snappingTargets'>;
function updateDecalGeometry(decal: Decal, info?: DecalGeometryInfo): Decal;
用法:
js
// 只可以吸附到特定的对象上
ssp.updateDecalGeometry(decal, { snapping: true, snappingDistance: 1, snappingTargets: [xxxObject] });
// 可以吸附到所有模型上
ssp.updateDecalGeometry(decal, { snapping: true, snappingDistance: 1 });
updateAllDecalGeometry
更新所有贴花几何结构
定义:
ts
type DecalGeometryInfo = Pick<DecalInfo, 'snapping' | 'snappingDistance' | 'snappingTargets'>;
function updateAllDecalGeometry(info?: DecalGeometryInfo): Decal;
用法:
js
// 只可以吸附到特定的对象上
ssp.updateAllDecalGeometry({ snapping: true, snappingDistance: 1, snappingTargets: [xxxObject] });
// 可以吸附到所有模型上
ssp.updateAllDecalGeometry({ snapping: true, snappingDistance: 1 });
getAllDecal
获取所有 Decal
定义:
ts
function getAllDecal(): Decal[];
用法:
js
const decals = ssp.getAllDecal();
showAllDecal
显示所有 Decal
定义:
ts
function showAllDecal(): void;
用法:
js
ssp.showAllDecal();
hideAllDecal
隐藏所有 Decal
定义:
ts
function hideAllDecal(): void;
用法:
js
ssp.hideAllDecal();
clearDecal
清空 Decal
定义:
ts
function clearDecal(): void;
用法:
js
ssp.clearDecal();