9 changed files with 199 additions and 78 deletions
@ -0,0 +1,82 @@ |
|||
import * as THREE from 'three' |
|||
import { Material } from 'three' |
|||
import ItemTypeLine from '@/model/itemType/ItemTypeLine.ts' |
|||
import WorldModel from '@/model/WorldModel.ts' |
|||
import Viewport from '@/designer/Viewport.ts' |
|||
import ToolboxLine from '@/model/itemType/ToolboxLine.ts' |
|||
import ConveyorToolbox from './ConveyorToolbox.ts' |
|||
import { Line2 } from 'three/examples/jsm/lines/Line2.js' |
|||
import { LineGeometry } from 'three/examples/jsm/lines/LineGeometry.js' |
|||
import { LineMaterial } from 'three/examples/jsm/lines/LineMaterial.js' |
|||
|
|||
export default class Conveyor extends ItemTypeLine { |
|||
defaultScale: THREE.Vector3 = new THREE.Vector3(0.25, 0.1, 0.25) |
|||
defaultRotation: THREE.Vector3 = new THREE.Vector3(0, 0, 0) |
|||
|
|||
pointMaterial!: Material |
|||
|
|||
lineMaterial!: LineMaterial |
|||
|
|||
static POINT_NAME = 'conveyor_point' |
|||
static LINE_NAME = 'conveyor_line' |
|||
|
|||
override init(worldModel: WorldModel): Promise<void> { |
|||
super.init(worldModel) |
|||
|
|||
this.lineMaterial = new LineMaterial({ |
|||
color: 0xE63C17, // 主颜色
|
|||
linewidth: 2, // 实际可用的线宽
|
|||
vertexColors: true, // 启用顶点颜色
|
|||
dashed: false, |
|||
alphaToCoverage: true |
|||
}) |
|||
|
|||
this.pointMaterial = new THREE.MeshBasicMaterial({ color: 0x303133, transparent: true, opacity: 0.9 }) |
|||
|
|||
return Promise.resolve() |
|||
} |
|||
|
|||
getDefaultScale(): THREE.Vector3 { |
|||
return this.defaultScale |
|||
} |
|||
|
|||
getDefaultRotation(): THREE.Vector3 { |
|||
return this.defaultRotation |
|||
} |
|||
|
|||
createToolbox(viewport: Viewport): ToolboxLine { |
|||
const toolbox = new ConveyorToolbox() |
|||
toolbox.init(viewport, this) |
|||
//@ts-ignore
|
|||
return toolbox |
|||
} |
|||
|
|||
/** |
|||
* 创建测量点 |
|||
*/ |
|||
createPointBasic(position?: THREE.Vector3): THREE.Object3D { |
|||
const p = position |
|||
const scale = 0.25 |
|||
|
|||
const tt = new THREE.BoxGeometry(1, 1, 1) |
|||
const obj = new THREE.Mesh(tt, this.pointMaterial) |
|||
obj.scale.set(scale, 0.1, scale) |
|||
if (p) { |
|||
obj.position.set(p.x, p.y, p.z) |
|||
} |
|||
obj.name = Conveyor.POINT_NAME |
|||
return obj |
|||
} |
|||
|
|||
/** |
|||
* 创建测量线 |
|||
*/ |
|||
createLineBasic(): Line2 { |
|||
const geom = new LineGeometry() |
|||
const obj = new Line2(geom, this.lineMaterial) |
|||
obj.frustumCulled = false |
|||
obj.name = Conveyor.LINE_NAME |
|||
obj.uuid = THREE.MathUtils.generateUUID() |
|||
return obj |
|||
} |
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
import { defineItemType } from '@/runtime/DefineItemType.ts' |
|||
import Conveyor from './Conveyor.ts' |
|||
|
|||
export default defineItemType({ |
|||
name: 'conveyor', |
|||
label: '输送线', |
|||
actionType: 'ln', |
|||
clazz: new Conveyor() |
|||
}) |
|||
@ -0,0 +1,16 @@ |
|||
import ToolboxLine from '@/model/itemType/ToolboxLine.ts' |
|||
import type Conveyor from './Conveyor.ts' |
|||
|
|||
/** |
|||
* 测量工具箱,用于处理测量相关的操作 |
|||
*/ |
|||
export default class ConveyorToolbox extends ToolboxLine { |
|||
|
|||
constructor() { |
|||
super() |
|||
} |
|||
|
|||
get conveyor(): Conveyor { |
|||
return this._itemType |
|||
} |
|||
} |
|||
Loading…
Reference in new issue