Browse Source

Merge remote-tracking branch 'origin/master'

master
lizw-2015 7 months ago
parent
commit
a4128aca1e
  1. 2
      src/core/Constract.ts
  2. 85
      src/core/base/BaseInteraction.ts
  3. 4
      src/core/manager/WorldModel.ts
  4. 9
      src/editor/Model2DEditor.vue
  5. 12
      src/example/example1.js
  6. 5
      src/modules/gstore/GstoreEntity.ts
  7. 22
      src/modules/gstore/GstoreInteraction.ts
  8. 14
      src/modules/gstore/GstoreMeta.ts
  9. 62
      src/modules/gstore/GstoreRenderer.ts
  10. 15
      src/modules/gstore/index.ts
  11. 2
      src/modules/measure/MeasureRenderer.ts

2
src/core/Constract.ts

@ -12,8 +12,8 @@ export default Object.freeze({
// 测量相关的光标模式 // 测量相关的光标模式
CursorModeMeasure: 'measure', CursorModeMeasure: 'measure',
CursorModeWay: 'way', CursorModeWay: 'way',
CursorModeGstore: 'gstore',
// 选择模式 // 选择模式
CursorModeSelectByRec: 'selectByRec' CursorModeSelectByRec: 'selectByRec'

85
src/core/base/BaseInteraction.ts

@ -54,10 +54,41 @@ export default abstract class BaseInteraction {
alphaToCoverage: true alphaToCoverage: true
}) })
/**
* "单点", 线
*/
get isSinglePointMode(): boolean {
return false
}
constructor(itemTypeName: string) { constructor(itemTypeName: string) {
this.itemTypeName = itemTypeName this.itemTypeName = itemTypeName
} }
createPointOfItem(catchPoint: ItemJson, point: THREE.Vector3): ItemJson {
const renderer = getRenderer(this.itemTypeName)
const defaultScale = renderer.defaultScale
const defaultRotation = renderer.defaultRotation
_.extend(catchPoint, {
id: system.createUUID(),
t: this.itemTypeName,
v: true,
tf: [
[point.x, point.y, point.z],
[defaultRotation.x, defaultRotation.y, defaultRotation.z],
[defaultScale.x, defaultScale.y, defaultScale.z]
],
dt: {
in: [] as string[],
out: [] as string[],
center: [] as string[]
}
})
return catchPoint
}
/** /**
* *
*/ */
@ -125,7 +156,14 @@ export default abstract class BaseInteraction {
} }
if (this.linkStartPointId) { if (this.linkStartPointId) {
this.linkStartPointObject = this.viewport.entityManager.findObjectsById(this.linkStartPointId)?.[0] if (this.isSinglePointMode) {
// 单点模式不需要起始点
this.linkStartPointId = undefined
this.linkStartPointObject = undefined
} else {
this.linkStartPointObject = this.viewport.entityManager.findObjectsById(this.linkStartPointId)?.[0]
}
} }
pdFn = this.mousedown.bind(this) pdFn = this.mousedown.bind(this)
@ -266,9 +304,29 @@ export default abstract class BaseInteraction {
} }
this.lastClickTime = now this.lastClickTime = now
// 如果正式的点命中到同类型的节点上,则不添加新的点,只牵线到该点 // 如果正式的点命中到同类型的节点上,则不添加新的点,只牵线到该点
let catchPoint: ItemJson | null = this.viewport.stateManager.findItemByPosition(point, this.itemTypeName) let catchPoint: ItemJson | null = this.viewport.stateManager.findItemByPosition(point, this.itemTypeName)
if (this.isSinglePointMode) {
// 单点模式,直接添加点
if (catchPoint) {
// 如果已经有点了,则不再添加
system.msg('Point already exists at this position.')
return
}
// 则添加一个新的点
const stateManager = this.viewport.stateManager
stateManager.beginStateUpdate({ createFromInteraction: true })
catchPoint = {} as ItemJson
catchPoint = this.createPointOfItem(catchPoint, point)
stateManager.vdata.items.push(catchPoint)
stateManager.endStateUpdate()
return
}
let from: ItemJson | undefined = undefined let from: ItemJson | undefined = undefined
if (this.linkStartPointId) { if (this.linkStartPointId) {
from = this.viewport.stateManager.findItemById(this.linkStartPointId) from = this.viewport.stateManager.findItemById(this.linkStartPointId)
@ -300,28 +358,9 @@ export default abstract class BaseInteraction {
stateManager.endStateUpdate() stateManager.endStateUpdate()
} else { } else {
const renderer = getRenderer(this.itemTypeName)
const defaultScale = renderer.defaultScale
const defaultRotation = renderer.defaultRotation
// 添加正式点 // 添加正式点
catchPoint = { catchPoint = {} as ItemJson
id: system.createUUID(), catchPoint = this.createPointOfItem(catchPoint, point)
t: this.itemTypeName,
v: true,
tf: [
[point.x, point.y, point.z],
[defaultRotation.x, defaultRotation.y, defaultRotation.z],
[defaultScale.x, defaultScale.y, defaultScale.z]
],
dt: {
in: [] as string[],
out: [] as string[],
center: [] as string[]
}
} as ItemJson
// 提交状态管理器 // 提交状态管理器
const stateManager = this.viewport.stateManager const stateManager = this.viewport.stateManager
@ -396,6 +435,8 @@ export default abstract class BaseInteraction {
const obj = new CSS2DObject(div) const obj = new CSS2DObject(div)
return obj return obj
} }
} }
export interface DragOption { export interface DragOption {

4
src/core/manager/WorldModel.ts

@ -3,6 +3,7 @@ import { reactive, watch } from 'vue'
import EventBus from '@/runtime/EventBus' import EventBus from '@/runtime/EventBus'
import Measure from '@/modules/measure' import Measure from '@/modules/measure'
import Way from '@/modules/way' import Way from '@/modules/way'
import Gstore from '@/modules/gstore'
import StateManager from '@/core/manager/StateManager.ts' import StateManager from '@/core/manager/StateManager.ts'
export interface WorldModelState { export interface WorldModelState {
@ -62,7 +63,8 @@ export default class WorldModel {
return Promise.all([ return Promise.all([
Measure, Measure,
Way Way,
Gstore
]).then(() => { ]).then(() => {
console.log('世界模型初始化完成') console.log('世界模型初始化完成')

9
src/editor/Model2DEditor.vue

@ -32,13 +32,18 @@
:type="state?.cursorMode===Constract.CursorModeSLink?'primary':''" :type="state?.cursorMode===Constract.CursorModeSLink?'primary':''"
@click="()=>state.cursorMode = Constract.CursorModeSLink"></el-button> @click="()=>state.cursorMode = Constract.CursorModeSLink"></el-button>
<span class="section-toolbar-line"></span> <span class="section-toolbar-line"></span>
<el-button title="测量工具" :icon="renderIcon('fa Ruler')" link <el-button title="进入测量工具" :icon="renderIcon('fa Ruler')" link
:type="state?.cursorMode===Constract.CursorModeMeasure?'primary':''" :type="state?.cursorMode===Constract.CursorModeMeasure?'primary':''"
@click="()=>state.cursorMode = Constract.CursorModeMeasure"></el-button> @click="()=>state.cursorMode = Constract.CursorModeMeasure"></el-button>
<el-button title="AGV线路" :icon="renderIcon('antd GatewayOutlined')" link <el-button title="进入AGV线路" :icon="renderIcon('antd GatewayOutlined')" link
:type="state?.cursorMode===Constract.CursorModeWay?'primary':''" :type="state?.cursorMode===Constract.CursorModeWay?'primary':''"
@click="()=>state.cursorMode = Constract.CursorModeWay"></el-button> @click="()=>state.cursorMode = Constract.CursorModeWay"></el-button>
<el-button title="进入地堆货位" :icon="renderIcon('antd CompressOutlined')" link
:type="state?.cursorMode===Constract.CursorModeGstore?'primary':''"
@click="()=>state.cursorMode = Constract.CursorModeGstore"></el-button>
</div> </div>
<div class="section-toolbar-right"> <div class="section-toolbar-right">
<el-input v-model="searchKeyword" size="small" style="width: 110px; margin-right: 5px;" <el-input v-model="searchKeyword" size="small" style="width: 110px; margin-right: 5px;"

12
src/example/example1.js

@ -112,6 +112,18 @@ export default {
v: true, v: true,
tf: [[5, 0.1, 2], [90, 0, 0], [0.25, 0.25, 0.1]], tf: [[5, 0.1, 2], [90, 0, 0], [0.25, 0.25, 0.1]],
dt: { in: [], out: [], center: ['39zML1rnSOOQGQYQ2YUMGy'] } dt: { in: [], out: [], center: ['39zML1rnSOOQGQYQ2YUMGy'] }
}, {
id: '6UhIIw9QPYh6acwyW8OSGs',
t: 'gstore',
v: true,
tf: [[-1, 0.1, 0.75], [0, 0, 0], [1.5, 1.2, 0.1]],
dt: { in: [], out: [], center: [], storeWidth: 1.2, storeDepth: 1.2 }
}, {
id: '1D0WSRPj8JJJwIcmA0UMqG',
t: 'gstore',
v: true,
tf: [[0.75, 0.1, 0.75], [0, 0, 0], [1.5, 1.2, 0.1]],
dt: { in: [], out: [], center: [], storeWidth: 1.2, storeDepth: 1.2 }
} }
] ]
} }

5
src/modules/gstore/GstoreEntity.ts

@ -0,0 +1,5 @@
import BaseEntity from '@/core/base/BaseItemEntity.ts'
export default class GstoreEntity extends BaseEntity {
}

22
src/modules/gstore/GstoreInteraction.ts

@ -0,0 +1,22 @@
import BaseInteraction from '@/core/base/BaseInteraction.ts'
import * as THREE from 'three'
export default class GstoreInteraction extends BaseInteraction {
get isSinglePointMode(): boolean {
return true
}
constructor(itemTypeName: string) {
super(itemTypeName)
}
createPointOfItem(item: ItemJson, point: THREE.Vector3): ItemJson {
item = super.createPointOfItem(item, point)
// 创建一个地堆货架
item.dt.storeWidth = 1.2 // 宽度
item.dt.storeDepth = 1.2 // 深度
return item
}
}

14
src/modules/gstore/GstoreMeta.ts

@ -0,0 +1,14 @@
import type { IMeta } from '@/core/base/IMeta.ts'
export default [
{ field: 'uuid', editor: 'UUID', label: 'uuid', readonly: true, category: 'basic' },
{ field: 'name', editor: 'TextInput', label: '名称', category: 'basic' },
{ field: 'dt.label', editor: 'TextInput', label: '标签', category: 'basic' },
{ editor: 'TransformEditor', category: 'basic' },
{ field: 'dt.color', editor: 'Color', label: '颜色', category: 'basic' },
{ editor: '-', category: 'basic' },
{ field: 'tf', editor: 'InOutCenterEditor', category: 'basic' },
{ field: 'dt.selectable', editor: 'Switch', label: '可选中', category: 'basic' },
{ field: 'dt.protected', editor: 'Switch', label: '受保护', category: 'basic' },
{ field: 'visible', editor: 'Switch', label: '可见', category: 'basic' }
] as IMeta

62
src/modules/gstore/GstoreRenderer.ts

@ -0,0 +1,62 @@
import * as THREE from 'three'
import BaseRenderer from '@/core/base/BaseRenderer.ts'
import { Text } from 'troika-three-text'
import MoveLinePointPng from '@/assets/images/moveline_point.png'
import SimSunTTF from '@/assets/fonts/simsunb.ttf'
import { getLineId } from '@/core/ModelUtils.ts'
/**
*
*/
export default class GstoreRenderer extends BaseRenderer {
static POINT_NAME = 'way_point'
pointMaterial: THREE.Material
/**
* ,
*/
readonly defulePositionY: number = 0.5 // 默认点的高度, 0.01, 防止和地面重合
readonly defaultScale: THREE.Vector3 = new THREE.Vector3(1.5, 1.2, 0.1)
readonly defaultRotation: THREE.Vector3 = new THREE.Vector3(0, 0, 0)
constructor(itemTypeName: string) {
super(itemTypeName)
}
/**
* 使 storeWidth/storeDepth, TF无效
*/
override afterCreateOrUpdatePoint(item: ItemJson, option: RendererCudOption, objects: THREE.Object3D[]) {
super.afterCreateOrUpdatePoint(item, option, objects)
const point = objects[0]
point.position.y = this.defulePositionY
point.scale.set(item.dt.storeWidth, this.defaultScale.y, item.dt.storeDepth)
point.rotation.set(
THREE.MathUtils.degToRad(this.defaultRotation.x),
THREE.MathUtils.degToRad(this.defaultRotation.y),
THREE.MathUtils.degToRad(this.defaultRotation.z)
)
}
createLineBasic(start: ItemJson, end: ItemJson, type: LinkType): THREE.Object3D[] {
throw new Error('not allow store line.')
}
updateLine(start: ItemJson, end: ItemJson, type: LinkType, option?: RendererCudOption) {
throw new Error('not allow store line.')
}
createPointBasic(item: ItemJson, option?: RendererCudOption): THREE.Object3D[] {
const obj = new THREE.Sprite(this.pointMaterial as THREE.SpriteMaterial)
obj.name = GstoreRenderer.POINT_NAME
return [obj]
}
dispose() {
super.dispose()
this.pointMaterial.dispose()
}
}

15
src/modules/gstore/index.ts

@ -0,0 +1,15 @@
import { defineModule } from '@/core/manager/ModuleManager.ts'
import GstoreRenderer from './GstoreRenderer.ts'
import GstoreEntity from './GstoreEntity.ts'
import GstoreMeta from './GstoreMeta.ts'
import GstoreInteraction from './GstoreInteraction.ts'
export const ITEM_TYPE_NAME = 'gstore'
export default defineModule({
name: ITEM_TYPE_NAME,
renderer: new GstoreRenderer(ITEM_TYPE_NAME),
interaction: new GstoreInteraction(ITEM_TYPE_NAME),
meta: GstoreMeta,
entity: GstoreEntity
})

2
src/modules/measure/MeasureRenderer.ts

@ -29,7 +29,7 @@ export default class MeasureRenderer extends BaseRenderer {
lineMaterial: LineMaterial lineMaterial: LineMaterial
readonly defulePositionY = 0.01 readonly defulePositionY = 0.01
readonly defaultScale: THREE.Vector3 = new THREE.Vector3(0.25, 0.25, 0.1) readonly defaultScale: THREE.Vector3 = new THREE.Vector3(0.1, 0.1, 0.1)
readonly defaultRotation: THREE.Vector3 = new THREE.Vector3(90, 0, 0) readonly defaultRotation: THREE.Vector3 = new THREE.Vector3(90, 0, 0)
constructor(itemTypeName: string) { constructor(itemTypeName: string) {

Loading…
Cancel
Save