刘向辉
3 years ago
10 changed files with 219 additions and 17 deletions
@ -0,0 +1,170 @@
|
||||
import { AbstractMesh, Color3, EventState, Mesh, MeshBuilder, Observer, PointerEventTypes, PointerInfo, StandardMaterial, Vector3 } from "@babylonjs/core"; |
||||
import { classToClass, plainToClass } from "class-transformer"; |
||||
import { SceneManager } from "src/app/babylon/controller/scene-manager"; |
||||
import { BabylonTool } from "src/app/babylon/tool/babylon-tool"; |
||||
import { MarkWindow } from "src/app/babylon/view/mark-window/mark-window"; |
||||
import { MarkData } from "../../../data/mark/mark-data"; |
||||
import { MarkData_multiLine } from "../../../data/mark/other/mark-data-multi-line"; |
||||
import { ModelInfo_mark } from "../model-info-mark"; |
||||
|
||||
export class MarkPlanSYGInfo extends ModelInfo_mark { |
||||
lineData: MarkData_multiLine; |
||||
|
||||
onPointObserver: Observer<PointerInfo>; |
||||
|
||||
lineMesh: Mesh; |
||||
|
||||
mat: StandardMaterial; |
||||
|
||||
|
||||
onCreate(isNew: boolean) { |
||||
let instance = this; |
||||
instance.lineData = this.markData as MarkData_multiLine; |
||||
|
||||
|
||||
this.mat = new StandardMaterial("mat_multiLine", SceneManager.Instance.scene); |
||||
this.mat.emissiveColor = Color3.FromHexString(this.lineData.color); |
||||
this.mat.disableLighting = true; |
||||
|
||||
if (isNew) { |
||||
instance.lineData.pointData = []; |
||||
instance.addPoint(this.modelBox.absolutePosition.clone()); |
||||
|
||||
setTimeout(() => { |
||||
instance.onPointObserver = SceneManager.Instance.scene.onPointerObservable.add((eventData: PointerInfo, eventState: EventState) => { |
||||
instance.onPointerObservable(eventData, eventState); |
||||
} |
||||
|
||||
); |
||||
}, 300); |
||||
} |
||||
else { |
||||
instance.lineData.pointData = plainToClass(Vector3, instance.lineData.pointData); |
||||
} |
||||
instance.updateRender(); |
||||
} |
||||
|
||||
/** |
||||
* 更新显示 |
||||
*/ |
||||
updateRender() { |
||||
if (this.lineData.pointData != null && this.lineData.pointData.length > 1) { |
||||
this.lineMesh = MeshBuilder.CreateTube("tube", { path: this.lineData.pointData, radius: this.lineData.radius, sideOrientation: Mesh.DOUBLESIDE, updatable: true, cap: Mesh.CAP_ALL }, SceneManager.Instance.scene); |
||||
this.lineMesh.setParent(this.modelBox); |
||||
this.lineMesh.position = Vector3.Zero(); |
||||
this.lineMesh.material = this.mat; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 添加节点 |
||||
* @param point
|
||||
*/ |
||||
addPoint(point: Vector3) { |
||||
point.y = point.y + this.lineData.yPos; |
||||
this.lineData.pointData.push(point.subtract(this.modelBox.absolutePosition)); |
||||
//更新表现
|
||||
|
||||
if (this.lineData.pointData.length > 1) { |
||||
|
||||
this.updateRender(); |
||||
} |
||||
|
||||
} |
||||
|
||||
/** |
||||
* 移除事件 |
||||
*/ |
||||
removeEvent() { |
||||
if (this.onPointObserver != null) { |
||||
SceneManager.Instance.scene.onPointerObservable.remove(this.onPointObserver); |
||||
this.onPointObserver = null; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 取消创建 |
||||
*/ |
||||
cancelCreate() { |
||||
if (this.lineData.pointData.length < 2) { |
||||
MarkWindow.instance.deleteMarkInfo(this); |
||||
} |
||||
// MarkWindow.instance.mulLineIsBreak_SD = -1;
|
||||
|
||||
} |
||||
|
||||
|
||||
onPointerObservable(eventData: PointerInfo, eventState: EventState) { |
||||
let instance = this; |
||||
// if (MarkWindow.instance.mulLineIsBreak_SD < 0) {
|
||||
// instance.cancelCreate();
|
||||
// instance.removeEvent();
|
||||
// return;
|
||||
// }
|
||||
|
||||
switch (eventData.type) { |
||||
case PointerEventTypes.POINTERUP: |
||||
if (eventData.event.button == 0) { //左键正常
|
||||
if (eventData.pickInfo.hit && !SceneManager.s_isPointerDrag) { |
||||
instance.addPoint(eventData.pickInfo.pickedPoint); |
||||
} |
||||
} |
||||
else if (eventData.event.button == 2) { //右键取消
|
||||
instance.cancelCreate(); |
||||
instance.removeEvent(); |
||||
} |
||||
break; |
||||
|
||||
} |
||||
} |
||||
|
||||
|
||||
onSelect(select: boolean) { |
||||
super.onSelect(select); |
||||
|
||||
if (select = false) { |
||||
this.cancelCreate(); |
||||
} |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 克隆 |
||||
*/ |
||||
clone(markData?: MarkData, isNew: boolean = true): ModelInfo_mark { |
||||
|
||||
let l_markData: MarkData = null; |
||||
if (markData == null) { |
||||
l_markData = classToClass(this.modelData) as MarkData; |
||||
} |
||||
else { |
||||
l_markData = markData; |
||||
} |
||||
|
||||
let childMeshes = null; |
||||
let modelBox = null; |
||||
|
||||
modelBox = BabylonTool.cloneMesh(this.modelBox as Mesh, null, (childMesh: AbstractMesh[]) => { |
||||
childMeshes = childMesh; |
||||
}); |
||||
|
||||
|
||||
let info = new MarkPlanSYGInfo(l_markData, childMeshes, modelBox, null, isNew); |
||||
|
||||
this.cloneAnimTo(info); |
||||
|
||||
|
||||
|
||||
return info; |
||||
} |
||||
|
||||
|
||||
dispose() { |
||||
if (this.mat != null) { |
||||
this.mat.dispose(); |
||||
} |
||||
|
||||
this.removeEvent(); |
||||
super.dispose(); |
||||
} |
||||
} |
After Width: | Height: | Size: 8.5 KiB |
Binary file not shown.
Loading…
Reference in new issue