feat(All):Initial

This commit is contained in:
2025-10-04 23:36:07 +08:00
commit 2b4e5d2668
1321 changed files with 415958 additions and 0 deletions
+111
View File
@@ -0,0 +1,111 @@
import {Object3D, AnimationAction,LoopOnce, LoopRepeat, LoopPingPong} from "three";
import type {AnimationActionLoopStyles} from "three";
export class Animation {
object:Object3D;
actionsMap:Map<string, AnimationAction>;
lastPlayAction:AnimationAction | undefined;
// 整个动作过程动画剪辑(AnimationClip)执行的次数
repetitions:number = Infinity;
static ActionLoop = {
LoopOnce: LoopOnce,
LoopRepeat: LoopRepeat,
LoopPingPong: LoopPingPong,
}
constructor(object:Object3D) {
this.object = object;
this.actionsMap = this.getActionsMap();
}
/**
* 获取对象的AnimationActions。
* @returns AnimationAction Map.
*/
getActionsMap():Map<string, AnimationAction> {
const actionsMap = new Map<string, AnimationAction>();
const animations = this.object.animations as unknown as AnimationAction[];
if (animations.length > 0) {
for (let animation of animations ) {
actionsMap.set(animation.getClip().name, animation);
}
}
return actionsMap;
}
/**
* 返回 AnimationAction,用于用户直接调用AnimationAction的方法。
* AnimationAction 文档:https://threejs.org/docs/index.html#api/zh/animation/AnimationAction
* @param name 动画名称。
* @returns AnimationAction | undefined
*/
getAction(name:string):AnimationAction | undefined {
return this.actionsMap.get(name);
}
get actions():AnimationAction[] {
return Array.from(this.actionsMap.values());
}
/**
* 播放动画,支持链式调用
*/
play(name:string, loop:AnimationActionLoopStyles = Animation.ActionLoop.LoopRepeat, timeScale:number = 1):Animation {
const action = this.actionsMap.get(name);
if (action) {
action.paused = false;
action.repetitions = this.repetitions;
action.loop = loop;
action.timeScale = timeScale;
action.play();
this.lastPlayAction = action;
}
return this;
}
/**
* 暂停动画,支持链式调用
*/
pause(name:string | undefined):Animation {
if(name === undefined){
this.lastPlayAction && (this.lastPlayAction.paused = true);
return this;
}
const action = this.actionsMap.get(name);
if (action) {
action.paused = true;
}
return this;
}
/**
* 停止动画,支持链式调用
*/
stop(name:string | undefined):Animation {
if (name === undefined) {
this.lastPlayAction &&this.lastPlayAction.stop();
this.lastPlayAction = undefined;
return this;
}
const action = this.actionsMap.get(name);
if (action) {
action.stop();
}
if (this.lastPlayAction === action) {
this.lastPlayAction = undefined;
}
return this;
}
}
+66
View File
@@ -0,0 +1,66 @@
/**
* @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);
}
}
+7
View File
@@ -0,0 +1,7 @@
export const Source = `
/**
* @document http://editor-doc.astraljs.com/guide/component/h4v1bkyh/
**/
function loaded() {}
`;
+3
View File
@@ -0,0 +1,3 @@
export {Animation} from "./Animation";
export {Helper} from "./Helper";
export {Source} from "./Source";