跳转至

Box3Bounds3 / GameBounds3 三维区域空间

这是一个服务端API

该API仅在服务端脚本使用

查阅官方文档
查阅官方文档(Arena)
查阅社区文档(Arena)

Box3Bounds3 / GameBounds3 是用于指定世界中一个立方体空间区域的一个类

构造函数

Box3Bounds3(lo: Box3Vector3, hi: Box3Vector3): Box3Bounds3
GameBounds3(lo: GameVector3, hi: GameVector3): GameBounds3
新建一个区域

属性 类型 说明
lo Box3Vector3 区域的低处顶点
hi Box3Vector3 区域的高处顶点
属性 类型 说明
lo GameVector3 区域的低处顶点
hi GameVector3 区域的高处顶点

关于lohi参数的说明

在编写代码的时候,要保证lo的每个值是比hi小的(lo.x < hi.x && lo.y < hi.y && lo.z < hi.z),否则会发生问题
如果不能保证,可以使用Box3Vector3minmax方法

警告

Box3Bounds3 / GameBounds3不能像Box3Vector3 / GameVector3一样,定义时必须有两个参数,不然你会收到一条:TypeError: Cannot read property 'toString' of undefined

常用

set copy
intersect intersects
contains containsBounds

属性

属性 类型 说明
lo Box3Vector3 区域的低处顶点
hi Box3Vector3 区域的高处顶点
属性 类型 说明
lo GameVector3 区域的低处顶点
hi GameVector3 区域的高处顶点

方法

intersect (b: Box3Bounds3): Box3Bounds3
intersect (b: GameBounds3): GameBounds3
计算与此包围盒相交的部分
示例
new Box3Bounds3(new Box3Vector3(0, 0, 0), new Box3Vector3(5, 5, 5)).intersect(new Box3Bounds3(new Box3Vector3(2, 2, 2), new Box3Vector3(7, 7, 7))) //<~ { lo:{ x:2, y:2, z:2 }, hi:{ x:5, y:5, z:5 } }
new GameBounds3(new GameVector3(0, 0, 0), new GameVector3(5, 5, 5)).intersect(new GameBounds3(new GameVector3(2, 2, 2), new GameVector3(7, 7, 7))) //<~ { lo:{ x:2, y:2, z:2 }, hi:{ x:5, y:5, z:5 } }
contains (b: Box3Vector3): boolean
contains (b: GameVector3): boolean
判断一个三维向量是否在这个空间区域里,包括边界
示例
new Box3Bounds3(new Box3Vector3(0, 0, 0), new Box3Vector3(5, 5, 5)).contains(new Box3Vector3(2, 2, 2)) //<~ true
new Box3Bounds3(new Box3Vector3(0, 0, 0), new Box3Vector3(5, 5, 5)).contains(new Box3Vector3(-2, -2, -2)) //<~ false
new GameBounds3(new GameVector3(0, 0, 0), new GameVector3(5, 5, 5)).contains(new GameVector3(2, 2, 2)) //<~ true
new GameBounds3(new GameVector3(0, 0, 0), new GameVector3(5, 5, 5)).contains(new GameVector3(-2, -2, -2)) //<~ false
containsBounds (b: Box3Vector3): boolean
containsBounds (b: GameVector3): boolean
检测一个空间区域是否完全在空间区域里(边界也算)
示例
new Box3Bounds3(new Box3Vector3(0, 0, 0), new Box3Vector3(5, 5, 5)).containsBounds(new Box3Bounds3(new Box3Vector3(2, 2, 2), new Box3Vector3(7, 7, 7))) //<~ false
new Box3Bounds3(new Box3Vector3(2, 2, 2), new Box3Vector3(7, 7, 7)).containsBounds(new Box3Bounds3(new Box3Vector3(0, 0, 0), new Box3Vector3(5, 5, 5))) //<~ false
new Box3Bounds3(new Box3Vector3(0, 0, 0), new Box3Vector3(7, 7, 7)).containsBounds(new Box3Bounds3(new Box3Vector3(2, 2, 2), new Box3Vector3(5, 5, 5))) // <~ true
new Box3Bounds3(new Box3Vector3(0, 0, 0), new Box3Vector3(7, 7, 7)).containsBounds(new Box3Bounds3(new Box3Vector3(2, 2, 0), new Box3Vector3(5, 7, 5))) // <~ true
new GameBounds3(new GameVector3(0, 0, 0), new GameVector3(5, 5, 5)).containsBounds(new GameBounds3(new GameVector3(2, 2, 2), new GameVector3(7, 7, 7))) //<~ false
new GameBounds3(new GameVector3(2, 2, 2), new GameVector3(7, 7, 7)).containsBounds(new GameBounds3(new GameVector3(0, 0, 0), new GameVector3(5, 5, 5))) //<~ false
new GameBounds3(new GameVector3(0, 0, 0), new GameVector3(7, 7, 7)).containsBounds(new GameBounds3(new GameVector3(2, 2, 2), new GameVector3(5, 5, 5))) // <~ true
new GameBounds3(new GameVector3(0, 0, 0), new GameVector3(7, 7, 7)).containsBounds(new GameBounds3(new GameVector3(2, 2, 0), new GameVector3(5, 7, 5))) // <~ true
intersects (b: Box3Bounds3): boolean
intersects (b: GameBounds3): boolean
判断一个空间区域是否与这个空间区域相交(挨着不算)
示例
new Box3Bounds3(new Box3Vector3(0, 0, 0), new Box3Vector3(5, 5, 5)).intersects(new Box3Bounds3(new Box3Vector3(2, 2, 2), new Box3Vector3(7, 7, 7))) //<~ true
new Box3Bounds3(new Box3Vector3(0, 0, 0), new Box3Vector3(5, 5, 5)).intersects(new Box3Bounds3(new Box3Vector3(5, 5, 5), new Box3Vector3(7, 7, 7))) //<~ false
new Box3Bounds3(new Box3Vector3(0, 0, 0), new Box3Vector3(5, 5, 5)).intersects(new Box3Bounds3(new Box3Vector3(4.99999, 4.99999, 4.99999), new Box3Vector3(7, 7, 7))) //<~ true
new GameBounds3(new GameVector3(0, 0, 0), new GameVector3(5, 5, 5)).intersects(new GameBounds3(new GameVector3(2, 2, 2), new GameVector3(7, 7, 7))) //<~ true
new GameBounds3(new GameVector3(0, 0, 0), new GameVector3(5, 5, 5)).intersects(new GameBounds3(new GameVector3(5, 5, 5), new GameVector3(7, 7, 7))) //<~ false
new GameBounds3(new GameVector3(0, 0, 0), new GameVector3(5, 5, 5)).intersects(new GameBounds3(new GameVector3(4.99999, 4.99999, 4.99999), new GameVector3(7, 7, 7))) //<~ true
set (lox: , loy: , loz: , hix: , hiy: , hiz: ): Box3Bounds3
set (lox: , loy: , loz: , hix: , hiy: , hiz: ): GameBounds3
设置这个空间区域
示例
new Box3Bounds3(new Box3Vector3(0, 0, 0), new Box3Vector3(0, 0, 0)).set(1, 1, 4, 5, 1, 4) //<~ { lo:{ x:1, y:1, z:4 }, hi:{ x:5, y:1, z:4 } }
new GameBounds3(new GameVector3(0, 0, 0), new GameVector3(0, 0, 0)).set(1, 1, 4, 5, 1, 4) //<~ { lo:{ x:1, y:1, z:4 }, hi:{ x:5, y:1, z:4 } }
copy (b: Box3Bounds3): Box3Bounds3
copy (b: GameBounds3): GameBounds3
把一个空间区域的值复制到这个空间区域上
toString (): string
将这个空间区域转换成字符串
fromPoints (points: ...Box3Vector3): Box3Bounds3
fromPoints (points: ...GameVector3): GameBounds3
根据坐标点生成一个空间区域,使每个点都在这个空间区域内

评论区