16 changed files with 463 additions and 36 deletions
|
After Width: | Height: | Size: 4.2 KiB |
@ -0,0 +1,5 @@ |
|||
import BaseEntity from '@/core/base/BaseItemEntity.ts' |
|||
|
|||
export default class PalletEntity extends BaseEntity { |
|||
|
|||
} |
|||
@ -0,0 +1,22 @@ |
|||
import BaseInteraction from '@/core/base/BaseInteraction.ts' |
|||
import * as THREE from 'three' |
|||
|
|||
export default class PalletInteraction 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.palletWidth = 1 // 宽度
|
|||
item.dt.palletDepth = 1.2 // 深度
|
|||
return item |
|||
} |
|||
} |
|||
@ -0,0 +1,49 @@ |
|||
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: 'dt.palletWidth', editor: 'NumberInput', label: '托盘深度', category: 'basic' }, |
|||
{ field: 'dt.palletDepth', editor: 'NumberInput', label: '托盘深度', category: 'basic' }, |
|||
/** |
|||
* dt.bays 5列3层货架示例 |
|||
* { |
|||
* dt: { |
|||
* rackDepth: 1.1, // 货架深度
|
|||
* levelCount: 3, // 总层数
|
|||
* bayCount: 5, // 总列数
|
|||
* hideFloor: false, // 隐藏底板
|
|||
* extendColumns: true, // 扩展挡板
|
|||
* columnSpacing: 1, // 支脚跨越
|
|||
* bays: [ // 每列的配置
|
|||
* { |
|||
* bayWidth: 1.6, // 列的宽度
|
|||
* levelHeight: [ 1.4, 1.4, 1.4 ] // 每层的高度
|
|||
* }, |
|||
* {bayWidth: 1.6, levelHeight: [ 1.4, 1.4, 1.4 ]}, |
|||
* {bayWidth: 1.6, levelHeight: [ 1.4, 1.4, 1.4 ]}, |
|||
* {bayWidth: 1.6, levelHeight: [ 1.4, 1.4, 1.4 ]}, |
|||
* {bayWidth: 1.6, levelHeight: [ 1.4, 1.4, 1.4 ]}, |
|||
* ] |
|||
* } |
|||
* } |
|||
* |
|||
* |
|||
* |
|||
* |
|||
* |
|||
* |
|||
* |
|||
*/ |
|||
|
|||
|
|||
{ 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 |
|||
@ -0,0 +1,115 @@ |
|||
import * as THREE from 'three' |
|||
import BaseRenderer from '@/core/base/BaseRenderer.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' |
|||
import {decimalSumBy} from "@/core/ModelUtils"; |
|||
import Constract from '@/core/Constract.ts' |
|||
|
|||
/** |
|||
* 货架货位渲染器 |
|||
*/ |
|||
export default class PalletRenderer extends BaseRenderer { |
|||
static POINT_NAME = 'pallet' |
|||
|
|||
pointMaterial: THREE.Material |
|||
|
|||
/** |
|||
* 默认点的高度, 防止和地面重合 |
|||
*/ |
|||
readonly defulePositionY: number = Constract.HEIGHT_WAY |
|||
readonly defaultScale: THREE.Vector3 = new THREE.Vector3(1, 1, 1) |
|||
readonly defaultRotation: THREE.Vector3 = new THREE.Vector3(0, 0, 0) |
|||
readonly defaultLineWidth: number = 0.15 |
|||
|
|||
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(_.sumBy(item.dt.bays, b=>b.bayWidth), this.defaultScale.y, item.dt.rackDepth)
|
|||
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.') |
|||
} |
|||
|
|||
|
|||
createPoint(item: ItemJson, option?: RendererCudOption): THREE.Object3D[] { |
|||
// 创建平面几何体
|
|||
if (!item.dt.palletWidth || !item.dt.palletDepth) { |
|||
return [] |
|||
} |
|||
|
|||
const group = new THREE.Group() |
|||
group.name = PalletRenderer.POINT_NAME |
|||
|
|||
// 绘制背景矩形框
|
|||
const planeGeometry = new THREE.PlaneGeometry(item.dt.palletWidth - this.defaultLineWidth, item.dt.palletDepth - this.defaultLineWidth); |
|||
planeGeometry.rotateX(Math.PI / 2) |
|||
const planeMaterial = new THREE.MeshBasicMaterial({ |
|||
color: '#029de5', |
|||
side: THREE.DoubleSide // 双面渲染:ml-citation{ref="5,8" data="citationList"}
|
|||
}); |
|||
const planeMesh = new THREE.Mesh(planeGeometry, planeMaterial); |
|||
group.add(planeMesh) |
|||
|
|||
// 绘制边框
|
|||
const lineXLen = item.dt.palletWidth - this.defaultLineWidth |
|||
const lineYLen = item.dt.palletDepth - this.defaultLineWidth |
|||
|
|||
const lineGeometry = new LineGeometry().setPositions([ |
|||
-(lineXLen/2),0,-(lineYLen/2), |
|||
lineXLen/2,0,-(lineYLen/2), |
|||
lineXLen/2,0,lineYLen/2, |
|||
-(lineXLen/2),0,lineYLen/2, |
|||
-(lineXLen/2),0,-(lineYLen/2) |
|||
]); |
|||
const lineMaterial = new LineMaterial({ |
|||
color: '#029de5', |
|||
linewidth: this.defaultLineWidth, |
|||
worldUnits: true, |
|||
resolution: new THREE.Vector2(window.innerWidth, window.innerHeight), |
|||
side: THREE.DoubleSide |
|||
}); |
|||
//
|
|||
const line = new Line2(lineGeometry, lineMaterial); |
|||
group.add(line as THREE.Object3D) |
|||
// 设置位置
|
|||
group.position.set(item.tf[0][0], item.tf[0][1], item.tf[0][2]) |
|||
|
|||
const points = [group] |
|||
this.fillObjectUserDataFromItem(item, ...points) |
|||
this.afterCreateOrUpdatePoint(item, option, points) |
|||
this.tempViewport.entityManager.appendObject(item.id, points) |
|||
this.appendToScene(...points) |
|||
return points |
|||
} |
|||
|
|||
dispose() { |
|||
super.dispose() |
|||
this.pointMaterial?.dispose() |
|||
} |
|||
|
|||
createPointBasic(item: ItemJson, option?: RendererCudOption): Object3D[] { |
|||
return []; |
|||
} |
|||
} |
|||
@ -0,0 +1,15 @@ |
|||
import { defineModule } from '@/core/manager/ModuleManager.ts' |
|||
import PalletRenderer from './PalletRenderer.ts' |
|||
import PalletEntity from './PalletEntity.ts' |
|||
import PalletMeta from './PalletMeta.ts' |
|||
import PalletInteraction from './PalletInteraction.ts' |
|||
|
|||
export const ITEM_TYPE_NAME = 'pallet' |
|||
|
|||
export default defineModule({ |
|||
name: ITEM_TYPE_NAME, |
|||
renderer: new PalletRenderer(ITEM_TYPE_NAME), |
|||
interaction: new PalletInteraction(ITEM_TYPE_NAME), |
|||
meta: PalletMeta, |
|||
entity: PalletEntity |
|||
}) |
|||
@ -0,0 +1,5 @@ |
|||
import BaseEntity from '@/core/base/BaseItemEntity.ts' |
|||
|
|||
export default class PtrEntity extends BaseEntity { |
|||
|
|||
} |
|||
@ -0,0 +1,22 @@ |
|||
import BaseInteraction from '@/core/base/BaseInteraction.ts' |
|||
import * as THREE from 'three' |
|||
|
|||
export default class PtrInteraction 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.palletWidth = 1 // 宽度
|
|||
item.dt.palletDepth = 1.2 // 深度
|
|||
return item |
|||
} |
|||
} |
|||
@ -0,0 +1,49 @@ |
|||
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: 'dt.palletWidth', editor: 'NumberInput', label: '托盘深度', category: 'basic' }, |
|||
{ field: 'dt.palletDepth', editor: 'NumberInput', label: '托盘深度', category: 'basic' }, |
|||
/** |
|||
* dt.bays 5列3层货架示例 |
|||
* { |
|||
* dt: { |
|||
* rackDepth: 1.1, // 货架深度
|
|||
* levelCount: 3, // 总层数
|
|||
* bayCount: 5, // 总列数
|
|||
* hideFloor: false, // 隐藏底板
|
|||
* extendColumns: true, // 扩展挡板
|
|||
* columnSpacing: 1, // 支脚跨越
|
|||
* bays: [ // 每列的配置
|
|||
* { |
|||
* bayWidth: 1.6, // 列的宽度
|
|||
* levelHeight: [ 1.4, 1.4, 1.4 ] // 每层的高度
|
|||
* }, |
|||
* {bayWidth: 1.6, levelHeight: [ 1.4, 1.4, 1.4 ]}, |
|||
* {bayWidth: 1.6, levelHeight: [ 1.4, 1.4, 1.4 ]}, |
|||
* {bayWidth: 1.6, levelHeight: [ 1.4, 1.4, 1.4 ]}, |
|||
* {bayWidth: 1.6, levelHeight: [ 1.4, 1.4, 1.4 ]}, |
|||
* ] |
|||
* } |
|||
* } |
|||
* |
|||
* |
|||
* |
|||
* |
|||
* |
|||
* |
|||
* |
|||
*/ |
|||
|
|||
|
|||
{ 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 |
|||
@ -0,0 +1,98 @@ |
|||
import * as THREE from 'three' |
|||
import BaseRenderer from '@/core/base/BaseRenderer.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' |
|||
import {decimalSumBy} from "@/core/ModelUtils"; |
|||
import Constract from '@/core/Constract.ts' |
|||
import ptrUrl from '@/assets/images/ptr/ptr.png' |
|||
|
|||
/** |
|||
* ptr侧叉渲染器 |
|||
*/ |
|||
export default class PtrRenderer extends BaseRenderer { |
|||
static POINT_NAME = 'ptr' |
|||
|
|||
pointMaterial: THREE.Material |
|||
|
|||
/** |
|||
* 默认点的高度, 防止和地面重合 |
|||
*/ |
|||
readonly defulePositionY: number = Constract.HEIGHT_WAY |
|||
readonly defaultScale: THREE.Vector3 = new THREE.Vector3(1, 1, 1) |
|||
readonly defaultRotation: THREE.Vector3 = new THREE.Vector3(0, 0, 0) |
|||
readonly defaultLineWidth: number = 0.15 |
|||
|
|||
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(_.sumBy(item.dt.bays, b=>b.bayWidth), this.defaultScale.y, item.dt.rackDepth)
|
|||
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.') |
|||
} |
|||
|
|||
|
|||
createPoint(item: ItemJson, option?: RendererCudOption): THREE.Object3D[] { |
|||
// 创建平面几何体
|
|||
if (!item.dt.ptrWidth || !item.dt.ptrDepth) { |
|||
return [] |
|||
} |
|||
|
|||
const textureLoader = new THREE.TextureLoader() |
|||
const texture = textureLoader.load(ptrUrl) |
|||
|
|||
const group = new THREE.Group() |
|||
group.name = PtrRenderer.POINT_NAME |
|||
|
|||
// 绘制背景矩形框
|
|||
const planeGeometry = new THREE.PlaneGeometry(item.dt.ptrWidth, item.dt.ptrDepth); |
|||
planeGeometry.rotateX(-Math.PI / 2) |
|||
planeGeometry.rotateY(-Math.PI / 2) |
|||
const planeMaterial = new THREE.MeshLambertMaterial({ |
|||
map: texture, // 颜色贴图
|
|||
transparent: true, // 允许透明纹理
|
|||
}); |
|||
const planeMesh = new THREE.Mesh(planeGeometry, planeMaterial); |
|||
group.add(planeMesh) |
|||
|
|||
// 设置位置
|
|||
group.position.set(item.tf[0][0], item.tf[0][1], item.tf[0][2]) |
|||
|
|||
const points = [group] |
|||
this.fillObjectUserDataFromItem(item, ...points) |
|||
this.afterCreateOrUpdatePoint(item, option, points) |
|||
this.tempViewport.entityManager.appendObject(item.id, points) |
|||
this.appendToScene(...points) |
|||
return points |
|||
} |
|||
|
|||
dispose() { |
|||
super.dispose() |
|||
this.pointMaterial?.dispose() |
|||
} |
|||
|
|||
createPointBasic(item: ItemJson, option?: RendererCudOption): Object3D[] { |
|||
return []; |
|||
} |
|||
} |
|||
@ -0,0 +1,15 @@ |
|||
import { defineModule } from '@/core/manager/ModuleManager.ts' |
|||
import PtrRenderer from './PtrRenderer.ts' |
|||
import PtrEntity from './PtrEntity.ts' |
|||
import PtrMeta from './PtrMeta.ts' |
|||
import PtrInteraction from './PtrInteraction.ts' |
|||
|
|||
export const ITEM_TYPE_NAME = 'ptr' |
|||
|
|||
export default defineModule({ |
|||
name: ITEM_TYPE_NAME, |
|||
renderer: new PtrRenderer(ITEM_TYPE_NAME), |
|||
interaction: new PtrInteraction(ITEM_TYPE_NAME), |
|||
meta: PtrMeta, |
|||
entity: PtrEntity |
|||
}) |
|||
Loading…
Reference in new issue