|
|
|
@ -2,6 +2,44 @@ import * as THREE from 'three' |
|
|
|
import type { ItemTypeDefineOption } from '@/model/itemType/ItemTypeDefine.ts' |
|
|
|
import type { ItemJson } from '@/model/WorldModelType.ts' |
|
|
|
import { getAllItemTypes, getItemTypeByName } from '@/runtime/DefineItemType.ts' |
|
|
|
import type Viewport from '@/designer/Viewport.ts' |
|
|
|
import type Toolbox from '@/model/itemType/Toolbox.ts' |
|
|
|
|
|
|
|
export function quickCopyByMouse() { |
|
|
|
// 获取鼠标位置,查看鼠标是否在某个 viewport 的画布上,并取得该 viewport
|
|
|
|
const currentMouseInfo = window['CurrentMouseInfo'] |
|
|
|
if (!currentMouseInfo?.viewport || !currentMouseInfo.x || !currentMouseInfo.z) { |
|
|
|
system.msg('无法获取鼠标位置') |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
// 从当前 mouse.x, mouse.z 获取地图坐标
|
|
|
|
const viewport: Viewport = currentMouseInfo.viewport |
|
|
|
const x = currentMouseInfo.x |
|
|
|
const z = currentMouseInfo.z |
|
|
|
|
|
|
|
// 如果当前 x,y 命中在某条线上,以当前鼠标为点,插入一个这个线段的起点的相似点,连接两头的点。
|
|
|
|
|
|
|
|
// 如果不在线上,查找0.2米内的有效点 Object3D, 如果有,则以这个点为起点, 延伸同类型的点,并让他们相连
|
|
|
|
findObject3DByCondition(viewport.scene, object => { |
|
|
|
// 判断 object 是否是有效的 Object3D, 并且是当前 viewport 的对象
|
|
|
|
if (object instanceof THREE.Object3D && object.visible && |
|
|
|
object.userData.type && viewport.toolbox[object.userData.type]) { |
|
|
|
|
|
|
|
const toolbox: Toolbox = viewport.toolbox[object.userData.type] |
|
|
|
|
|
|
|
// 检查是否在 0.2 米内
|
|
|
|
const distance = object.position.distanceTo(new THREE.Vector3(x, 0, z)) |
|
|
|
if (distance < 0.2) { |
|
|
|
// 找到一个有效点,执行复制操作
|
|
|
|
toolbox.start(object) |
|
|
|
system.msg('复制成功') |
|
|
|
return true |
|
|
|
} |
|
|
|
} |
|
|
|
return false |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 考虑吸附的情况下计算鼠标事件位置 |
|
|
|
|