Add record model into actuator
This commit is contained in:
parent
bc67782365
commit
776a5f571e
@ -1,5 +1,13 @@
|
|||||||
import { Model } from "@Model/Model";
|
import { Model } from "@Model/Model";
|
||||||
import { Emitter } from "@Model/Emitter";
|
import { Emitter } from "@Model/Emitter";
|
||||||
|
import { Clip } from "@Model/Clip";
|
||||||
|
|
||||||
|
enum ActuatorModel {
|
||||||
|
Play = 1,
|
||||||
|
Record = 2,
|
||||||
|
View = 3,
|
||||||
|
Offline = 4
|
||||||
|
}
|
||||||
|
|
||||||
interface IActuatorEvent {
|
interface IActuatorEvent {
|
||||||
startChange: boolean;
|
startChange: boolean;
|
||||||
@ -26,6 +34,43 @@ class Actuator extends Emitter<IActuatorEvent> {
|
|||||||
*/
|
*/
|
||||||
private startFlag: boolean = false;
|
private startFlag: boolean = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模式
|
||||||
|
*/
|
||||||
|
public mod: ActuatorModel = ActuatorModel.View;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 录制剪辑
|
||||||
|
*/
|
||||||
|
public recordClip?: Clip;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 开始录制
|
||||||
|
*/
|
||||||
|
public startRecord(clip: Clip) {
|
||||||
|
|
||||||
|
// 记录录制片段
|
||||||
|
this.recordClip = clip;
|
||||||
|
|
||||||
|
// 如果仿真未开启,开启仿真
|
||||||
|
if (!this.start()) this.start(true);
|
||||||
|
|
||||||
|
// 设置状态
|
||||||
|
this.mod = ActuatorModel.Record;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 结束录制
|
||||||
|
*/
|
||||||
|
public endRecord() {
|
||||||
|
|
||||||
|
// 如果仿真未停止,停止仿真
|
||||||
|
if (this.start()) this.start(false);
|
||||||
|
|
||||||
|
// 设置状态
|
||||||
|
this.mod = ActuatorModel.View;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 主时钟状态控制
|
* 主时钟状态控制
|
||||||
*/
|
*/
|
||||||
@ -72,13 +117,29 @@ class Actuator extends Emitter<IActuatorEvent> {
|
|||||||
} else {
|
} else {
|
||||||
this.alignTimer += durTime;
|
this.alignTimer += durTime;
|
||||||
if (this.alignTimer > (1 / this.fps)) {
|
if (this.alignTimer > (1 / this.fps)) {
|
||||||
|
|
||||||
|
// 更新模型
|
||||||
this.model.update(this.alignTimer * this.speed);
|
this.model.update(this.alignTimer * this.speed);
|
||||||
|
|
||||||
|
// 绘制模型
|
||||||
|
this.model.draw();
|
||||||
|
|
||||||
|
// 录制模型
|
||||||
|
if (
|
||||||
|
this.mod === ActuatorModel.Record ||
|
||||||
|
this.mod === ActuatorModel.Offline
|
||||||
|
) {
|
||||||
|
this.recordClip?.record(this.alignTimer * this.speed);
|
||||||
|
}
|
||||||
|
|
||||||
this.emit("loop", this.alignTimer);
|
this.emit("loop", this.alignTimer);
|
||||||
this.alignTimer = 0;
|
this.alignTimer = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
this.emit("loop", Infinity);
|
this.emit("loop", Infinity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -122,4 +183,4 @@ class Actuator extends Emitter<IActuatorEvent> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export { Actuator }
|
export { Actuator, ActuatorModel }
|
@ -1,4 +1,5 @@
|
|||||||
import { IAnyObject, Model } from "@Model/Model";
|
import { IAnyObject, Model } from "@Model/Model";
|
||||||
|
import { v4 as uuid } from "uuid";
|
||||||
import { Group } from "@Model/Group";
|
import { Group } from "@Model/Group";
|
||||||
import { Range } from "@Model/Range";
|
import { Range } from "@Model/Range";
|
||||||
|
|
||||||
@ -21,6 +22,8 @@ interface IFrame {
|
|||||||
*/
|
*/
|
||||||
class Clip {
|
class Clip {
|
||||||
|
|
||||||
|
public id: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户自定义名称
|
* 用户自定义名称
|
||||||
*/
|
*/
|
||||||
@ -78,10 +81,13 @@ class Clip {
|
|||||||
return frame;
|
return frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public equal(clip?: Clip) {
|
||||||
|
return clip === this || clip?.id === this.id;
|
||||||
|
}
|
||||||
|
|
||||||
public constructor(model: Model) {
|
public constructor(model: Model) {
|
||||||
this.model = model;
|
this.model = model;
|
||||||
|
this.id = uuid();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ type ModelEvent = {
|
|||||||
objectChange: CtrlObject[];
|
objectChange: CtrlObject[];
|
||||||
individualChange: Group;
|
individualChange: Group;
|
||||||
behaviorChange: IAnyBehavior;
|
behaviorChange: IAnyBehavior;
|
||||||
|
clipChange: Clip[];
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -331,8 +332,51 @@ class Model extends Emitter<ModelEvent> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 剪辑数据
|
||||||
|
*/
|
||||||
public clipPool: Clip[] = [];
|
public clipPool: Clip[] = [];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新建剪辑片段
|
||||||
|
*/
|
||||||
|
public addClip(name?: string): Clip {
|
||||||
|
let newClip = new Clip(this);
|
||||||
|
newClip.name = name ?? "";
|
||||||
|
this.clipPool.push(newClip);
|
||||||
|
console.log(`Model: Create clip ${name ?? newClip.id}`);
|
||||||
|
this.emit("clipChange", this.clipPool);
|
||||||
|
return newClip;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除一个剪辑片段
|
||||||
|
*/
|
||||||
|
public deleteClip(name: ObjectID | Clip) {
|
||||||
|
let deletedClip: Clip | undefined;
|
||||||
|
let index = 0;
|
||||||
|
|
||||||
|
for (let i = 0; i < this.clipPool.length; i++) {
|
||||||
|
if (name instanceof Clip) {
|
||||||
|
if (this.clipPool[i].equal(name)) {
|
||||||
|
deletedClip = this.clipPool[i];
|
||||||
|
index = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (name === this.clipPool[i].id) {
|
||||||
|
deletedClip = this.clipPool[i];
|
||||||
|
index = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (deletedClip) {
|
||||||
|
this.behaviorPool.splice(index, 1);
|
||||||
|
console.log(`Model: Delete clip ${deletedClip.name ?? deletedClip.id}`);
|
||||||
|
this.emit("clipChange", this.clipPool);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 渲染器
|
* 渲染器
|
||||||
*/
|
*/
|
||||||
@ -350,7 +394,7 @@ class Model extends Emitter<ModelEvent> {
|
|||||||
/**
|
/**
|
||||||
* 更新渲染数据
|
* 更新渲染数据
|
||||||
*/
|
*/
|
||||||
public update(t: number, skipDraw: boolean = false) {
|
public update(t: number) {
|
||||||
|
|
||||||
// 第一轮更新
|
// 第一轮更新
|
||||||
for (let i = 0; i < this.objectPool.length; i++) {
|
for (let i = 0; i < this.objectPool.length; i++) {
|
||||||
@ -375,10 +419,6 @@ class Model extends Emitter<ModelEvent> {
|
|||||||
object.runner(t, "finalEffect");
|
object.runner(t, "finalEffect");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!skipDraw) {
|
|
||||||
this.draw();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public draw() {
|
public draw() {
|
||||||
|
Loading…
Reference in New Issue
Block a user