TkAstral3D/packages/sdk/lib/core/script/Helper.ts
2025-10-04 23:36:07 +08:00

66 lines
1.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* @author ErSan
* @email mlt131220@163.com
* @date 2024/4/24 10:39
* @description 迁移App.ts中的一些方法也有新增提供脚本使用因为脚本在运行态时执行应该与原环境隔离
*/
import {Scene,Object3D} from "three";
import {Animation} from "./Animation";
export class Helper {
scene: Scene;
/* 动画 */
Animation: typeof Animation;
constructor(scene: Scene) {
this.scene = scene;
this.Animation = Animation;
// 注册一个资源管理类,用于管理资源的加载和释放
// 注册一个flyControls类用于控制场景中的物体的飞行动画
}
/**
* 通过uuid获取对象
* @param uuid
* @returns THREE.Object3D
*/
objectByUuid(uuid: string) {
return this.scene.getObjectByProperty('uuid', uuid);
}
/**
* 移动3D对象到指定位置
* @param object
* @param parent
* @param before
*/
moveObject(object: Object3D, parent: Object3D, before: Object3D) {
if (parent === undefined) {
parent = this.scene;
}
parent.add(object);
// 对子数组进行排序
if (before !== undefined) {
const index = parent.children.indexOf(before);
parent.children.splice(index, 0, object);
parent.children.pop();
}
}
/**
* 移除对象
* @param object
*/
removeObject(object: Object3D) {
if (object.parent === null) return;
// TODO 未处理材质的释放
object.parent.remove(object);
}
}