|
|
@ -8,6 +8,7 @@ import EventBus from '@/runtime/EventBus' |
|
|
import { markRaw } from 'vue' |
|
|
import { markRaw } from 'vue' |
|
|
import { getMeta } from '@/core/manager/ModuleManager.ts' |
|
|
import { getMeta } from '@/core/manager/ModuleManager.ts' |
|
|
import MouseMoveInspect from '@/core/controls/MouseMoveInspect.ts' |
|
|
import MouseMoveInspect from '@/core/controls/MouseMoveInspect.ts' |
|
|
|
|
|
import Constract from '@/core/Constract.ts' |
|
|
|
|
|
|
|
|
let pdFn, pmFn, puFn |
|
|
let pdFn, pmFn, puFn |
|
|
|
|
|
|
|
|
@ -19,12 +20,12 @@ export default class SelectInspect implements IControls { |
|
|
/** |
|
|
/** |
|
|
* 线框材质,用于显示选中对象的包围盒 |
|
|
* 线框材质,用于显示选中对象的包围盒 |
|
|
*/ |
|
|
*/ |
|
|
yellowMaterial: LineMaterial = new LineMaterial({ color: 0xffff00, linewidth: 2 }) |
|
|
yellowMaterial: LineMaterial = new LineMaterial({ color: 0xffff00, linewidth: 3 }) |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 线框材质,用于显示选中对象的包围盒 |
|
|
* 线框材质,用于显示选中对象的包围盒 |
|
|
*/ |
|
|
*/ |
|
|
redMaterial: LineMaterial = new LineMaterial({ color: 0xff0000, linewidth: 2 }) |
|
|
redMaterial: LineMaterial = new LineMaterial({ color: 0xff0000, linewidth: 3 }) |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 矩形材质,用于显示鼠标拖拽选择的矩形区域 |
|
|
* 矩形材质,用于显示鼠标拖拽选择的矩形区域 |
|
|
@ -132,36 +133,43 @@ export default class SelectInspect implements IControls { |
|
|
this.viewport.scene.add(this.redSelectionGroup) |
|
|
this.viewport.scene.add(this.redSelectionGroup) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 创建红选包围盒 |
|
|
|
|
|
*/ |
|
|
createRedSelectionBox(object: THREE.Object3D) { |
|
|
createRedSelectionBox(object: THREE.Object3D) { |
|
|
// 如果对象没有 entityId,则不创建包围盒线框
|
|
|
// 如果对象没有 entityId,则不创建包围盒线框
|
|
|
if (!object.userData.entityId) { |
|
|
if (!object.userData.entityId) { |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 如果选中的对象小于 0.5,要扩展包围盒
|
|
|
|
|
|
const RED_EXPAND_AMOUNT = 0.01 // 扩展包围盒的大小
|
|
|
|
|
|
// 避免某些蒙皮网格的帧延迟效应(e.g. Michelle.glb)
|
|
|
|
|
|
object.updateWorldMatrix(false, true) |
|
|
|
|
|
|
|
|
|
|
|
const box = new THREE.Box3().setFromObject(object) |
|
|
const box = new THREE.Box3().setFromObject(object) |
|
|
box.expandByScalar(RED_EXPAND_AMOUNT) |
|
|
box.expandByScalar(Constract.RED_EXPAND_AMOUNT) // 假设 Constract.RED_EXPAND_AMOUNT 已定义
|
|
|
|
|
|
|
|
|
const size = new THREE.Vector3() |
|
|
const min = box.min |
|
|
box.getSize(size) |
|
|
const max = box.max |
|
|
|
|
|
|
|
|
const center = new THREE.Vector3() |
|
|
const corners = [ |
|
|
box.getCenter(center) |
|
|
new THREE.Vector3(min.x - Constract.RED_EXPAND_AMOUNT, max.y + Constract.RED_EXPAND_AMOUNT, min.z - Constract.RED_EXPAND_AMOUNT), |
|
|
|
|
|
new THREE.Vector3(max.x + Constract.RED_EXPAND_AMOUNT, max.y + Constract.RED_EXPAND_AMOUNT, min.z - Constract.RED_EXPAND_AMOUNT), |
|
|
|
|
|
new THREE.Vector3(max.x + Constract.RED_EXPAND_AMOUNT, max.y + Constract.RED_EXPAND_AMOUNT, max.z + Constract.RED_EXPAND_AMOUNT), |
|
|
|
|
|
new THREE.Vector3(min.x - Constract.RED_EXPAND_AMOUNT, max.y + Constract.RED_EXPAND_AMOUNT, max.z + Constract.RED_EXPAND_AMOUNT) |
|
|
|
|
|
] |
|
|
|
|
|
|
|
|
// 创建包围盒几何体
|
|
|
// 构建矩形边框(4 条边)
|
|
|
const helperGeometry = new THREE.BoxGeometry(size.x, size.y, size.z) |
|
|
const positions = [] |
|
|
const edgesGeometry = new THREE.EdgesGeometry(helperGeometry) |
|
|
for (let i = 0; i < 4; i++) { |
|
|
|
|
|
const p1 = corners[i] |
|
|
|
|
|
const p2 = corners[(i + 1) % 4] |
|
|
|
|
|
positions.push(p1.x, p1.y, p1.z) |
|
|
|
|
|
positions.push(p2.x, p2.y, p2.z) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 创建几何体
|
|
|
const lineGeom = new LineGeometry() |
|
|
const lineGeom = new LineGeometry() |
|
|
// @ts-ignore
|
|
|
const vertices = new Float32Array(positions) |
|
|
lineGeom.setPositions(edgesGeometry.attributes.position.array) |
|
|
lineGeom.setPositions(vertices) |
|
|
|
|
|
|
|
|
const selectionBox = new Line2(lineGeom, this.redMaterial) |
|
|
const selectionBox = new Line2(lineGeom, this.redMaterial) |
|
|
selectionBox.computeLineDistances() |
|
|
selectionBox.computeLineDistances() |
|
|
selectionBox.position.copy(center) |
|
|
|
|
|
|
|
|
|
|
|
this.redSelectionGroup.add(selectionBox) |
|
|
this.redSelectionGroup.add(selectionBox) |
|
|
} |
|
|
} |
|
|
@ -177,30 +185,43 @@ export default class SelectInspect implements IControls { |
|
|
} |
|
|
} |
|
|
this.selectionId = selectedObject.userData?.entityId |
|
|
this.selectionId = selectedObject.userData?.entityId |
|
|
|
|
|
|
|
|
// 如果选中的对象小于 0.5,要扩展包围盒
|
|
|
|
|
|
const YELLOW_EXPAND_AMOUNT = 0.03 // 扩展包围盒的大小
|
|
|
|
|
|
// 避免某些蒙皮网格的帧延迟效应(e.g. Michelle.glb)
|
|
|
// 避免某些蒙皮网格的帧延迟效应(e.g. Michelle.glb)
|
|
|
selectedObject.updateWorldMatrix(false, true) |
|
|
selectedObject.updateWorldMatrix(false, true) |
|
|
|
|
|
|
|
|
const box = new THREE.Box3().setFromObject(selectedObject) |
|
|
const box = new THREE.Box3().setFromObject(selectedObject) |
|
|
box.expandByScalar(YELLOW_EXPAND_AMOUNT) |
|
|
|
|
|
|
|
|
|
|
|
const size = new THREE.Vector3() |
|
|
const min = box.min |
|
|
box.getSize(size) |
|
|
const max = box.max |
|
|
|
|
|
|
|
|
const center = new THREE.Vector3() |
|
|
const corners = [ |
|
|
box.getCenter(center) |
|
|
new THREE.Vector3(min.x - Constract.YELLOW_EXPAND_AMOUNT, max.y + Constract.YELLOW_EXPAND_AMOUNT, min.z - Constract.YELLOW_EXPAND_AMOUNT), |
|
|
|
|
|
new THREE.Vector3(max.x + Constract.YELLOW_EXPAND_AMOUNT, max.y + Constract.YELLOW_EXPAND_AMOUNT, min.z - Constract.YELLOW_EXPAND_AMOUNT), |
|
|
|
|
|
new THREE.Vector3(max.x + Constract.YELLOW_EXPAND_AMOUNT, max.y + Constract.YELLOW_EXPAND_AMOUNT, max.z + Constract.YELLOW_EXPAND_AMOUNT), |
|
|
|
|
|
new THREE.Vector3(min.x - Constract.YELLOW_EXPAND_AMOUNT, max.y + Constract.YELLOW_EXPAND_AMOUNT, max.z + Constract.YELLOW_EXPAND_AMOUNT) |
|
|
|
|
|
] |
|
|
|
|
|
|
|
|
// 创建包围盒几何体
|
|
|
// 构建矩形边框(4 条边)
|
|
|
const helperGeometry = new THREE.BoxGeometry(size.x, size.y, size.z) |
|
|
const positions = [] |
|
|
const edgesGeometry = new THREE.EdgesGeometry(helperGeometry) |
|
|
for (let i = 0; i < 4; i++) { |
|
|
|
|
|
const p1 = corners[i] |
|
|
|
|
|
const p2 = corners[(i + 1) % 4] |
|
|
|
|
|
positions.push(p1.x, p1.y, p1.z) |
|
|
|
|
|
positions.push(p2.x, p2.y, p2.z) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 创建几何体
|
|
|
const lineGeom = new LineGeometry() |
|
|
const lineGeom = new LineGeometry() |
|
|
// @ts-ignore
|
|
|
const vertices = new Float32Array(positions) |
|
|
lineGeom.setPositions(edgesGeometry.attributes.position.array) |
|
|
lineGeom.setPositions(vertices) |
|
|
|
|
|
|
|
|
const selectionBox = new Line2(lineGeom, this.yellowMaterial) |
|
|
const selectionBox = new Line2(lineGeom, this.yellowMaterial) |
|
|
selectionBox.computeLineDistances() |
|
|
selectionBox.computeLineDistances() |
|
|
selectionBox.position.copy(center) |
|
|
|
|
|
|
|
|
// 获取包围盒中心并设置位置
|
|
|
|
|
|
const center = new THREE.Vector3() |
|
|
|
|
|
box.getCenter(center) |
|
|
|
|
|
// selectionBox.position.copy(center)
|
|
|
|
|
|
selectionBox.computeLineDistances() |
|
|
|
|
|
|
|
|
this.selectionBox = selectionBox |
|
|
this.selectionBox = selectionBox |
|
|
|
|
|
|
|
|
console.log('selectedItem', this.viewport.state.selectedItem) |
|
|
console.log('selectedItem', this.viewport.state.selectedItem) |
|
|
|