Browse Source

新建Rack模块文件

master
yuliang 7 months ago
parent
commit
a1be15ad46
  1. 5
      src/modules/rack/RackEntity.ts
  2. 22
      src/modules/rack/RackInteraction.ts
  3. 14
      src/modules/rack/RackMeta.ts
  4. 105
      src/modules/rack/RackRenderer.ts
  5. 15
      src/modules/rack/index.ts

5
src/modules/rack/RackEntity.ts

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

22
src/modules/rack/RackInteraction.ts

@ -0,0 +1,22 @@
import BaseInteraction from '@/core/base/BaseInteraction.ts'
import * as THREE from 'three'
export default class RackInteraction 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/rack/RackMeta.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

105
src/modules/rack/RackRenderer.ts

@ -0,0 +1,105 @@
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'
/**
*
*/
export default class RackRenderer extends BaseRenderer {
static POINT_NAME = 'ground_store'
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)
readonly defaultLineWidth: number = 0.05
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 group = new THREE.Group()
group.name = RackRenderer.POINT_NAME
// 绘制背景矩形框
const planeGeometry = new THREE.PlaneGeometry(item.dt.storeWidth, item.dt.storeDepth);
planeGeometry.rotateX(-Math.PI / 2)
const planeMaterial = new THREE.MeshBasicMaterial({
color: 'white',
transparent: true, // 启用透明
opacity: 0.2, // 50%透明度
depthWrite: false, // 防止深度冲突
side: THREE.DoubleSide // 双面渲染:ml-citation{ref="5,8" data="citationList"}
});
const planeMesh = new THREE.Mesh(planeGeometry, planeMaterial);
group.add(planeMesh)
if (!item.dt.storeWidth || !item.dt.storeDepth) {
return [group]
}
// 绘制边框
const lineXLen = item.dt.storeWidth - this.defaultLineWidth
const lineYLen = item.dt.storeDepth - this.defaultLineWidth
const lineGeometry = new LineGeometry().setPositions([
-(lineXLen/2),-(lineYLen/2),0,
lineXLen/2,-(lineYLen/2),0,
lineXLen/2,lineYLen/2,0,
-(lineXLen/2),lineYLen/2,0,
-(lineXLen/2),-(lineYLen/2),0
]);
lineGeometry.rotateX(-Math.PI / 2)
const lineMaterial = new LineMaterial({
color: 0x00ff00,
linewidth: 0.05,
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)
return [group]
}
dispose() {
super.dispose()
this.pointMaterial.dispose()
}
}

15
src/modules/rack/index.ts

@ -0,0 +1,15 @@
import { defineModule } from '@/core/manager/ModuleManager.ts'
import RackRenderer from './RackRenderer.ts'
import RackEntity from './RackEntity.ts'
import RackMeta from './RackMeta.ts'
import RackInteraction from './RackInteraction.ts'
export const ITEM_TYPE_NAME = 'rack'
export default defineModule({
name: ITEM_TYPE_NAME,
renderer: new RackRenderer(ITEM_TYPE_NAME),
interaction: new RackInteraction(ITEM_TYPE_NAME),
meta: RackMeta,
entity: RackEntity
})
Loading…
Cancel
Save