From ba2d6efe422fe8745025c2f4f1cc428ae9afa06b Mon Sep 17 00:00:00 2001 From: luoyifan Date: Fri, 13 Jun 2025 13:57:24 +0800 Subject: [PATCH] =?UTF-8?q?Way=20=E7=82=B9=E4=BD=8D=E7=9A=84=E5=88=A0?= =?UTF-8?q?=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/OBB矩形包围盒API.md | 93 ++++++++++++++++++++++++++++++++++++++++++++ src/example/example1.js | 84 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 177 insertions(+) create mode 100644 doc/OBB矩形包围盒API.md diff --git a/doc/OBB矩形包围盒API.md b/doc/OBB矩形包围盒API.md new file mode 100644 index 0000000..6f924a6 --- /dev/null +++ b/doc/OBB矩形包围盒API.md @@ -0,0 +1,93 @@ +## OBB 包围盒快速查找算法 + +### 物品数据结构 + +```typescript +items = ItemJson[] + +interface ItemJson { + // 物体ID, 唯一标识 + id: string + + /** + * 变换矩阵, 3x3矩阵, 采用Y轴向上为正, X轴向右, Z轴向前。右手坐标系 + */ + tf: [ + /** + * 平移向量 position, 三维坐标, [0]=x, [1]=高度值,在2D下忽略, [2]=z + */ + [number, number, number], + + /** + * 旋转向量 rotation, 单位为度。对应 three.js 应进行"角度"转"弧度"的换算 [0]=X轴逆向旋转角度, [1]=Y轴逆向旋转角度, [2]=Z轴逆向旋转角度 + */ + [number, number, number], + + /** + * 缩放向量 scale, 三维缩放比例, [0]=X宽度, [1]=Y高度,在2D下忽略, [2]=Z长度 + */ + [number, number, number], + ] +} +``` + + +### add(...items: ItemJson[]) + +添加点位 + +add(...items: ItemJson[]) + + +--- + +### update(item: ItemJson) + +更新点位 + +update(itemJson) + + +--- + +### deleteItem(id: string) + +删除点位 + +deleteItem(id: string) + + +--- + +### getItemsByPosition(x:number, z:number): ItemJson[] + +根据位置,获取命中的物品集合 + +getItemsByPosition({x:number, z:number}): ItemJson[] + + +--- + +### getItemsByPositionDistance(x, z, distance): {item, distance}[] + +getItemsByPositionDistance(x:number, z:number, distance:number): {item:ItemJson, distance:number}[] + +根据位置,获取周边单位距离内的所有物品集合,及距离 + + +--- + +### getItemsByRect(x1,y1,x2,y2): ItemJson[] + +根据矩形,获取与矩形有碰撞的所有物品集合 + +getItemsByPosition({x:number, z:number}): ItemJson[] + + +--- + +### getItemsByRect2(x1,y1,x2,y2): ItemJson[] + +根据矩形,获取矩形内的所有物品,物品OBB包围盒必须完全在矩形内 + +getItemsByPosition({x:number, z:number}): ItemJson[] diff --git a/src/example/example1.js b/src/example/example1.js index aff836d..e25f075 100644 --- a/src/example/example1.js +++ b/src/example/example1.js @@ -547,6 +547,90 @@ export default { dt: async () => import('./flash.js') } ] + }, + { + catalogCode: 'flash2', t: 'floor', + items: [ + { + id: 'flash_rack1', + t: 'flash_rack', + dt: async () => import('./flash.js') + } + ] + }, + { + catalogCode: 'flash3', t: 'floor', + items: [ + { + id: 'flash_rack1', + t: 'flash_rack', + dt: async () => import('./flash.js') + } + ] + }, + { + catalogCode: 'de1', t: 'side', + floorHeight: [ // 侧面视图的各层面高度 + 1.3, 1.3, 1.3, 1.3, 1.3, + 1.3, 1.3, 1.3, 1.3, 1.3, + 1.3 + ], + items: [ + { + id: 'elevation1', + t: 'elevation', + dt: { + lift: { // 升降机 + enable: true, // 是否启用 + width: 1.2, // 升降机侧视图宽度 + depth: 1.0 // 侧视图深度 + }, + liftLeft: { + width: 1.1, depth: 1.0, // 侧视图深度 + items: [ + { pdId: true, pdOut: true, carArrive: true }, + { pdId: true, pdOut: true, carArrive: true }, + { pdId: true, pdOut: true, carArrive: true }, + { pdId: true, pdOut: true, carArrive: true }, + { pdId: true, pdOut: true, carArrive: true }, + { pdId: true, pdOut: true, carArrive: true }, + { pdId: true, pdOut: true, carArrive: true }, + { pdId: true, pdOut: true, carArrive: true }, + { enable: false }, // 升降机[0]层 左侧的第1个位置 + { enable: false }, + { enable: false } + ] + }, + liftRight: { + width: 1.1, + items: [ + { enable: false }, + { enable: false }, + { pdId: true, pdOut: true, carArrive: true }, + { pdId: true, pdOut: true, carArrive: true }, + { pdId: true, pdOut: true, carArrive: true }, + { pdId: true, pdOut: true, carArrive: true }, + { pdId: true, pdOut: true, carArrive: true }, + { pdId: true, pdOut: true, carArrive: true }, + { pdId: true, pdOut: true, carArrive: true }, + { pdId: true, pdOut: true, carArrive: true }, + { enable: false }, + { enable: false } + ] + } + } + }, + { + id: 'elevation2', + t: 'elevation', + dt: {} + }, + { + id: 'elevation3', + t: 'elevation', + dt: {} + } + ] } ], elevator: [], // 电梯