From caa39923dd9f547b7e46d370bbdb43c5abf21a2a Mon Sep 17 00:00:00 2001 From: xiefan <1789784602@qq.com> Date: Fri, 3 Apr 2020 10:17:02 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E9=80=89=E6=8B=A9=E6=9D=BF?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Utils.ts | 20 -------------------- src/Viewer.ts | 46 ++++++++++++++++++++++++++++++++++++---------- 2 files changed, 36 insertions(+), 30 deletions(-) diff --git a/src/Utils.ts b/src/Utils.ts index 69a6c0c..13a02f7 100644 --- a/src/Utils.ts +++ b/src/Utils.ts @@ -36,23 +36,3 @@ export function LoadBoard(view: Viewer, data: any[], clear: boolean = true) return relations; } - -export function SelectBlock(view: Viewer, blockMeshMap: Map, dataID: number) -{ - if (blockMeshMap.has(dataID)) - { - let meshId = blockMeshMap.get(dataID); - view.m_Scene.children.forEach(obj => - { - if (obj instanceof Mesh) - { - if (obj.id == meshId) - { - obj.material = selectMaterial; - view.m_bNeedUpdate = true; - } - } - - }) - } -} diff --git a/src/Viewer.ts b/src/Viewer.ts index 3c6d540..7fbdd40 100644 --- a/src/Viewer.ts +++ b/src/Viewer.ts @@ -37,18 +37,9 @@ export class Viewer this.OnSize(); }); - let oldMesh: Mesh; this.m_Render.domElement.addEventListener("mousemove", (e: MouseEvent) => { - let mesh = PointPick(this, e.offsetX, e.offsetY); - if (oldMesh) - oldMesh.material = boardMaterial; - if (mesh && mesh.material !== ColorMaterial.GetBasicMaterial(1)) - { - oldMesh = mesh; - mesh.material = selectMaterial; - } - this.m_bNeedUpdate = true; + this.SelectByPoint(e.offsetX, e.offsetY); }) } @@ -196,4 +187,39 @@ export class Viewer this.m_Camera.LookAt(new Vector3(1, 1, -1)); this.m_bNeedUpdate = true; } + + oldMesh: Mesh; + SelectByPoint(x: number, y: number) + { + let mesh = PointPick(this, x, y); + if (this.oldMesh) + this.oldMesh.material = boardMaterial; + if (mesh && mesh.material !== ColorMaterial.GetBasicMaterial(1)) + { + this.oldMesh = mesh; + mesh.material = selectMaterial; + } + this.m_bNeedUpdate = true; + } + SelectBlock(blockMeshMap: Map, dataID: number) + { + if (blockMeshMap.has(dataID)) + { + let meshId = blockMeshMap.get(dataID); + if (this.oldMesh) + this.oldMesh.material = boardMaterial; + this.m_Scene.children.forEach(obj => + { + if (obj instanceof Mesh) + { + if (obj.id == meshId) + { + obj.material = selectMaterial; + this.m_bNeedUpdate = true; + } + } + + }) + } + } }