123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- //解析来自算法部的数据:https://4dkk.4dage.com/data/datat-uXiVK7k/floorplan_cad.json?_=0
- import { floorplanService } from './FloorplanService'
- import { wallService } from './WallService'
- import { floorplanData } from '../FloorplanData'
- import VectorType from '../enum/VectorType.js'
- export default class AnalyService {
- constructor(layer) {
- this.layer = layer
- this.app = this.layer.app
- this.houseData = null
- }
- initVectors(data) {
- let floors = data.floors
- let currentId = -1
- let offWallId = 0 //算法部的id都是从0开始,且每层楼的id都是从0开始
- let offPointId = 0
- for (let i = 0; i < floors.length; ++i) {
- let floorNum = floors[i].subgroup
- let floor = floors[i]
- floorplanData.floors[floorNum] = {}
- floorplanData.floors[floorNum].points = {}
- floorplanData.floors[floorNum].walls = {}
- floorplanData.floors[floorNum].symbols = {}
- floorplanData.floors[floorNum].components = {}
- floorplanData.floors[floorNum].tags = {}
- floorplanData.floors[floorNum].furnitures = {}
- floorplanData.floors[floorNum].boundingBox = {}
- floorplanData.floors[floorNum].rooms = []
- let minX = null,
- minY = null,
- maxX = null,
- maxY = null
- for (let j = 0; j < floor['vertex-xy'].length; ++j) {
- let vectorId = floor['vertex-xy'][j].id + offPointId
- if (currentId < vectorId) {
- currentId = vectorId
- }
- vectorId = VectorType.Point + vectorId
- let point = {
- x: floor['vertex-xy'][j].x,
- y: floor['vertex-xy'][j].y,
- }
- wallService.createPoint(point.x, point.y, vectorId, floorNum)
- if (minX == null || minX > point.x) {
- minX = point.x
- }
- if (minY == null || minY > point.y) {
- minY = point.y
- }
- if (maxX == null || maxX < point.x) {
- maxX = point.x
- }
- if (maxY == null || maxY < point.y) {
- maxY = point.y
- }
- }
- offWallId = currentId + 1
- floorplanData.floors[floorNum].boundingBox.minX = minX
- floorplanData.floors[floorNum].boundingBox.minY = minY
- floorplanData.floors[floorNum].boundingBox.maxX = maxX
- floorplanData.floors[floorNum].boundingBox.maxY = maxY
- for (let j = 0; j < floor['segment'].length; ++j) {
- let vectorId = floor['segment'][j].id + offWallId
- if (currentId < vectorId) {
- currentId = vectorId
- }
- vectorId = VectorType.Wall + vectorId
- let start = VectorType.Point + (floor['segment'][j].a + offPointId)
- let end = VectorType.Point + (floor['segment'][j].b + offPointId)
- wallService.createWall(start, end, vectorId, floorNum)
- }
- offWallId = currentId + 1
- offPointId = currentId + 1
- }
- floorplanService.setCurrentId(currentId + 1)
- const currentFloorNum = this.app.core.get('Player').model.currentFloor.floorIndex
- floorplanService.setCurrentFloor(currentFloorNum)
- //随心装的json数据
- //this.houseData = this.createDecorateData(floorplanData)
- }
- //随心装数据,houseType.json
- createDecorateData(floorplanData) {
- let house = {}
- house.name = 'houseType.json'
- house.version = '2.1'
- house.floors = []
- for (let i = 0; i < floorplanData.floors.length; ++i) {
- let item = {}
- item.points = []
- item.walls = []
- //floorplanData.floors.points
- //floorplanData.floors.walls
- for (let key in floorplanData.floors[i].points) {
- let point = {}
- point.x = floorplanData.floors[i].points[key].x
- point.y = floorplanData.floors[i].points[key].y
- point.parent = floorplanData.floors[i].points[key].parent
- point.vectorId = floorplanData.floors[i].points[key].vectorId
- item.points.push(point)
- }
- for (let key in floorplanData.floors[i].walls) {
- let wall = {}
- wall.start = floorplanData.floors[i].walls[key].start
- wall.end = floorplanData.floors[i].walls[key].end
- wall.children = []
- wall.vectorId = floorplanData.floors[i].walls[key].vectorId
- wall.width = 0.2
- item.walls.push(wall)
- }
- house.floors.push(item)
- }
- return house
- }
- }
|