# 空间管理教程

在本教程中,你可以通过调用后端接口,来实现空间的管理。

# 在使用之前

在使用之前,你需要将模型上传并成功转换。同时,你也需要有相应的权限,并获取到可用的Access Token。

# 创建空间

通过调用后端接口,你可以实现空间的创建:

POST https://api.bimface.com/feature-management/v1/spaces/new-space/extrusion

在body参数中,需要指定:

  1. 文件ID或集成ID(必须)
  2. 空间的boundary和height(必须)
  3. 长度单位(需指定,不指定默认给定为mm)
  4. 空间名称与描述(可选)

body示例参数如下:

{
    "fileId": "10000026980510",
    "name": "测试分析时间用s",
    "unit": "m",
    "description": "for test ",
    "height": 4.5,
    "boundary": {
        "outer": [
            {"x": 71.5,"y": 94.2,"z": -4.5},
            {"x": -0.1,"y": 94.2,"z": -4.5},
            {"x": -0.1,"y": -0.76,"z": -4.5},
            {"x": 71.5,"y": -0.76,"z": -4.5}
        ],
        "inner": [[            
            {"x": 7.15,"y": 9.42,"z": -0.45},
            {"x": -0.1,"y": 9.42,"z": -0.45},
            {"x": -0.1,"y": -0.76,"z": -0.45},
            {"x": 7.15,"y": -0.76,"z": -0.45}]]
    }
}

在完成创建后,BIMFACE在结果中返回创建的空间的ID。

{
    "code": "bimfaceservice-0000",
    "message": null,
    "data": {
        "createTime": "2022-12-26T07:07:57.691Z",
        "fileId": 10000731425271,
        "integrateId": null,
        "spaceId": "285d37fe068b4cf6a0396eb84453ca31"
    }
}

# 空间属性查询

针对用户需要,BIMFACE提供了查询单个空间和查询批量空间的接口。

依据空间ID与文件ID查询单个空间属性

POST https://api.bimface.com/data/v1/feature-management/spaces/{space-id}/properties

依据空间ID列表与文件ID批量查询空间属性

https://api.bimface.com/data/v1/feature-management/spaces/properties

通过查询接口,你可以获取到模型自带房间属性以及自定义的空间属性。返回信息示意如下:

{
    "code": "bimfaceservice-0000",
    "message": null,
    "data": {
        "area": "14.073148872759932",
        "bboxMax": {"x": 2.3838,"y": -4.2743,"z": 5.9384},
        "bboxMin": {"x": -2.1162,"y": -7.6443,"z": 3.5},
        "boundary": {
            "inner": null,
            "outer": [
                {"x": "-2.1162","y": "-6.8393","z": "3.5"},
                {"x": "-2.1162","y": "-7.6443","z": "3.5"},
                {"x": "-1.3712","y": "-7.6443","z": "3.5"},
                {"x": "1.6388","y": "-7.6443","z": "3.5"}
            ]
        },
        "boundarySegments": [
            "264056",
            "281803",
            "264129",
            "306006"
        ],
        "description": null,
        "geometryType": null,
        "height": 2.4383999999999997,
        "levelId": "694",
        "name": "健身房 9",
        "perimeter": "18.14",
        "spaceId": "306376",
        "spaceType": "room",
        "spaceVersion": null,
        "spaceVersionId": null,
        "unit": "m"
    }
}

其中boundary、height、spaceId为必有项,若为文件解析自带房间,还会附带area、perimeter和boundarySegments信息。

# 前端应用

在获取空间信息后,可在前端中调用绘制接口,对空间进行展示与表达,如:

let roomConfig = new Glodon.Bimface.Plugins.Rooms.RoomConfig();
roomConfig.viewer = viewer3D;
roomConfig.roomId = 'room1_boundary_height';
roomConfig.geometry = {
    type: 'extrusion',
    // boundary信息,可使用后端返回结果
    boundary: {
        "outer": [
                    { "x": "0", "y": "0", "z": "0" },
                    { "x": "30000", "y": "0", "z": "0" },
                    { "x": "30000", "y": "30000", "z": "0" },
                    { "x": "0", "y": "30000", "z": "0" }
                ],
        "inner": [
                    [
                        { "x": "10000", "y": "10000", "z": "0" },
                        { "x": "20000", "y": "10000", "z": "0" },
                        { "x": "20000", "y": "20000", "z": "0" },
                        { "x": "10000", "y": "20000", "z": "0" }
                    ]
                ]
    },
    // height信息,可使用后端返回结果
    height: 3000,
    unit: 'mm'
    }
let room = new Glodon.Bimface.Plugins.Rooms.Room(roomConfig);
viewer3D.getRoomManager().addRoom(room);

在完成房间的设置和加载后,就可以在页面中加载出绘制的房间信息了。