|
|
@ -33,6 +33,17 @@ export interface Cl2Task { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
interface Task { |
|
|
|
|
|
SeqNo: number; |
|
|
|
|
|
OperationType: 0 | 1 | 2 | 3 | 4 | 5 | 135 | 136; |
|
|
|
|
|
PickMode: 0 | 1 | 2 | 3 | 4 | 5 | 6; |
|
|
|
|
|
GoodsSlotHeight: number; |
|
|
|
|
|
GoodsSlotDirection: 0 | 1 | 2 | 3 | 15; |
|
|
|
|
|
X: number; |
|
|
|
|
|
Y: number; |
|
|
|
|
|
Speed: number; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
export default class Cl23dObject extends THREE.Object3D { |
|
|
export default class Cl23dObject extends THREE.Object3D { |
|
|
|
|
|
|
|
|
// 创建ptr的底座
|
|
|
// 创建ptr的底座
|
|
|
@ -323,8 +334,33 @@ export default class Cl23dObject extends THREE.Object3D { |
|
|
private static ptrPillarGeometry: THREE.BufferGeometry = null; |
|
|
private static ptrPillarGeometry: THREE.BufferGeometry = null; |
|
|
private static ptrForkGeometry: THREE.BufferGeometry = null; |
|
|
private static ptrForkGeometry: THREE.BufferGeometry = null; |
|
|
|
|
|
|
|
|
|
|
|
private item: ItemJson; |
|
|
|
|
|
|
|
|
|
|
|
private _cl2Entity: Cl2Entity = null; |
|
|
|
|
|
|
|
|
|
|
|
private taskList: Task[] = []; |
|
|
|
|
|
private executingTask: Task[] = []; |
|
|
|
|
|
|
|
|
|
|
|
private travelAnimation: core.Tween = null |
|
|
|
|
|
private rotationAnimation: core.Tween = null; |
|
|
|
|
|
private riseAnimation: core.Tween = null; |
|
|
|
|
|
private stretchAnimation: core.Tween = null; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public get cl2Entity(): Cl2Entity { |
|
|
|
|
|
if (!this._cl2Entity) { |
|
|
|
|
|
const cl2: Cl2Entity = Model.getCl2(this.item.id) as Cl2Entity |
|
|
|
|
|
this._cl2Entity = cl2 |
|
|
|
|
|
} |
|
|
|
|
|
return this._cl2Entity |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private clock = new THREE.Clock(); |
|
|
constructor(item: ItemJson, option?: RendererCudOption) { |
|
|
constructor(item: ItemJson, option?: RendererCudOption) { |
|
|
super(); |
|
|
super(); |
|
|
|
|
|
console.log("time", this.clock.getElapsedTime()); |
|
|
|
|
|
this.item = item; |
|
|
if (!Cl23dObject.ptrPedestalGeometry) { |
|
|
if (!Cl23dObject.ptrPedestalGeometry) { |
|
|
Cl23dObject.ptrPedestalGeometry = Cl23dObject.createPtrPedestal() |
|
|
Cl23dObject.ptrPedestalGeometry = Cl23dObject.createPtrPedestal() |
|
|
} |
|
|
} |
|
|
@ -398,7 +434,7 @@ export default class Cl23dObject extends THREE.Object3D { |
|
|
|
|
|
|
|
|
client.on('message', (topic, msg) => { |
|
|
client.on('message', (topic, msg) => { |
|
|
console.log(`[${topic}] ${msg}`); |
|
|
console.log(`[${topic}] ${msg}`); |
|
|
const a = JSON.parse(msg.toString()); |
|
|
const a: Cl2Task = JSON.parse(msg.toString()); |
|
|
this.handleMessage(a); |
|
|
this.handleMessage(a); |
|
|
|
|
|
|
|
|
}); |
|
|
}); |
|
|
@ -409,9 +445,62 @@ export default class Cl23dObject extends THREE.Object3D { |
|
|
} catch (e) { |
|
|
} catch (e) { |
|
|
console.error(e) |
|
|
console.error(e) |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*==========消息处理============*/ |
|
|
|
|
|
|
|
|
|
|
|
handleMessage(data: Cl2Task) { |
|
|
|
|
|
if (data.id === 10010) { |
|
|
|
|
|
|
|
|
|
|
|
if (this.taskList.length <= 0) { |
|
|
|
|
|
//当队列为空时,检查当前车辆所在位置
|
|
|
|
|
|
const pointItem = Model.getItemByXYZ(this.position.x, this.position.y, this.position.z) |
|
|
|
|
|
if (!pointItem || data.content.StartX != pointItem.logicX || data.content.StartY != pointItem.logicY) { |
|
|
|
|
|
throw new Error('当前车辆所在位置未找到') |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for (const item of data.content.Link) { |
|
|
|
|
|
// 添加到队列
|
|
|
|
|
|
this.taskList.push({ |
|
|
|
|
|
SeqNo: data.content.SeqNo, |
|
|
|
|
|
OperationType: data.content.OperationType, |
|
|
|
|
|
PickMode: data.content.PickMode, |
|
|
|
|
|
GoodsSlotHeight: data.content.GoodsSlotHeight, |
|
|
|
|
|
GoodsSlotDirection: data.content.GoodsSlotDirection, |
|
|
|
|
|
X: item.X, |
|
|
|
|
|
Y: item.Y, |
|
|
|
|
|
Speed: item.Speed, |
|
|
|
|
|
}) |
|
|
|
|
|
} |
|
|
|
|
|
console.log("time", this.clock.getElapsedTime()); |
|
|
|
|
|
|
|
|
|
|
|
this.executeTask() |
|
|
|
|
|
return |
|
|
|
|
|
|
|
|
|
|
|
this.cl2Entity.addRobotTask(data) |
|
|
|
|
|
if (!this.cl2Entity.taskIsRunning) { |
|
|
|
|
|
this.cl2Entity.taskStartRun() |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
executeTask() { |
|
|
|
|
|
|
|
|
|
|
|
while (this.taskList.length > 0) { |
|
|
|
|
|
const task = this.taskList.shift() |
|
|
|
|
|
this.addTravel(task.X, task.Y, task.Speed/1000) |
|
|
|
|
|
|
|
|
|
|
|
this.executingTask.push(task) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*==========动画处理============*/ |
|
|
|
|
|
|
|
|
animationShowFork(z: number): Promise<void> { |
|
|
animationShowFork(z: number): Promise<void> { |
|
|
|
|
|
|
|
|
const ptrPillar = this.getObjectByName('ptrPillar') |
|
|
const ptrPillar = this.getObjectByName('ptrPillar') |
|
|
@ -493,35 +582,42 @@ export default class Cl23dObject extends THREE.Object3D { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 走
|
|
|
// 走
|
|
|
addTravel(pos: Vector3IF | string, speed : number = 1): Promise<void> { |
|
|
addTravel(logicX: number, logicY: number, speed : number = 1): Promise<void> { |
|
|
|
|
|
|
|
|
|
|
|
const pos = Model.getPositionByLogicXY(logicX, logicY) |
|
|
|
|
|
|
|
|
const fromPos = this.position |
|
|
const fromPos = this.position |
|
|
const toPos = new THREE.Vector3(pos.x, pos.y, pos.z) |
|
|
const toPos = new THREE.Vector3(pos.x, pos.y, pos.z) |
|
|
const distance = fromPos.distanceTo(toPos) |
|
|
const distance = fromPos.distanceTo(toPos) |
|
|
const duration = Math.max(1.0, distance / speed) |
|
|
const duration = Math.max(1.0, distance / speed) |
|
|
|
|
|
|
|
|
|
|
|
if (!this.travelAnimation) { |
|
|
return new Promise(resolve => { |
|
|
return new Promise(resolve => { |
|
|
gsap.to(this.position, { |
|
|
this.travelAnimation = gsap.to(this.position, { |
|
|
x: toPos.x, |
|
|
x: toPos.x, |
|
|
y: toPos.y, |
|
|
y: toPos.y, |
|
|
z: toPos.z, |
|
|
z: toPos.z, |
|
|
duration, |
|
|
duration, |
|
|
ease: 'sine.inOut', |
|
|
ease: 'sine.inOut', |
|
|
onComplete: resolve |
|
|
onComplete: ()=>{ |
|
|
|
|
|
this.travelAnimation = null; |
|
|
|
|
|
resolve() |
|
|
|
|
|
} |
|
|
}) |
|
|
}) |
|
|
}) |
|
|
}) |
|
|
|
|
|
} else { |
|
|
|
|
|
this.travelAnimation.vars.x = toPos.x |
|
|
|
|
|
this.travelAnimation.vars.y = toPos.y |
|
|
|
|
|
this.travelAnimation.vars.z = toPos.z |
|
|
|
|
|
const tt = this.travelAnimation.duration() |
|
|
|
|
|
this.travelAnimation.duration(tt + duration) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
handleMessage(data) { |
|
|
|
|
|
if (data.id === 10010) { |
|
|
|
|
|
const cl2: Cl2Entity = Model.getCl2("10") as Cl2Entity |
|
|
|
|
|
cl2.addRobotTask(data) |
|
|
|
|
|
this.fn(cl2) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
fn = _.debounce((cl2: Cl2Entity) => { |
|
|
// fn = _.debounce((cl2: Cl2Entity) => {
|
|
|
cl2.taskStartRun() |
|
|
// cl2.taskStartRun()
|
|
|
}, 2000) |
|
|
// }, 2000)
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|