AnalyService.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. //解析来自算法部的数据:https://4dkk.4dage.com/data/datat-uXiVK7k/floorplan_cad.json?_=0
  2. import { floorplanService } from './FloorplanService'
  3. import { wallService } from './WallService'
  4. import { floorplanData } from '../FloorplanData'
  5. import VectorType from '../enum/VectorType.js'
  6. export default class AnalyService {
  7. constructor(layer) {
  8. this.layer = layer
  9. this.app = this.layer.app
  10. this.houseData = null
  11. }
  12. initVectors(data) {
  13. let floors = data.floors
  14. let currentId = -1
  15. let offWallId = 0 //算法部的id都是从0开始,且每层楼的id都是从0开始
  16. let offPointId = 0
  17. for (let i = 0; i < floors.length; ++i) {
  18. let floorNum = floors[i].subgroup
  19. let floor = floors[i]
  20. floorplanData.floors[floorNum] = {}
  21. floorplanData.floors[floorNum].points = {}
  22. floorplanData.floors[floorNum].walls = {}
  23. floorplanData.floors[floorNum].symbols = {}
  24. floorplanData.floors[floorNum].components = {}
  25. floorplanData.floors[floorNum].tags = {}
  26. floorplanData.floors[floorNum].furnitures = {}
  27. floorplanData.floors[floorNum].boundingBox = {}
  28. floorplanData.floors[floorNum].rooms = []
  29. let minX = null,
  30. minY = null,
  31. maxX = null,
  32. maxY = null
  33. for (let j = 0; j < floor['vertex-xy'].length; ++j) {
  34. let vectorId = floor['vertex-xy'][j].id + offPointId
  35. if (currentId < vectorId) {
  36. currentId = vectorId
  37. }
  38. vectorId = VectorType.Point + vectorId
  39. let point = {
  40. x: floor['vertex-xy'][j].x,
  41. y: floor['vertex-xy'][j].y,
  42. }
  43. wallService.createPoint(point.x, point.y, vectorId, floorNum)
  44. if (minX == null || minX > point.x) {
  45. minX = point.x
  46. }
  47. if (minY == null || minY > point.y) {
  48. minY = point.y
  49. }
  50. if (maxX == null || maxX < point.x) {
  51. maxX = point.x
  52. }
  53. if (maxY == null || maxY < point.y) {
  54. maxY = point.y
  55. }
  56. }
  57. offWallId = currentId + 1
  58. floorplanData.floors[floorNum].boundingBox.minX = minX
  59. floorplanData.floors[floorNum].boundingBox.minY = minY
  60. floorplanData.floors[floorNum].boundingBox.maxX = maxX
  61. floorplanData.floors[floorNum].boundingBox.maxY = maxY
  62. for (let j = 0; j < floor['segment'].length; ++j) {
  63. let vectorId = floor['segment'][j].id + offWallId
  64. if (currentId < vectorId) {
  65. currentId = vectorId
  66. }
  67. vectorId = VectorType.Wall + vectorId
  68. let start = VectorType.Point + (floor['segment'][j].a + offPointId)
  69. let end = VectorType.Point + (floor['segment'][j].b + offPointId)
  70. wallService.createWall(start, end, vectorId, floorNum)
  71. }
  72. offWallId = currentId + 1
  73. offPointId = currentId + 1
  74. }
  75. floorplanService.setCurrentId(currentId + 1)
  76. const currentFloorNum = this.app.core.get('Player').model.currentFloor.floorIndex
  77. floorplanService.setCurrentFloor(currentFloorNum)
  78. //随心装的json数据
  79. //this.houseData = this.createDecorateData(floorplanData)
  80. }
  81. //随心装数据,houseType.json
  82. createDecorateData(floorplanData) {
  83. let house = {}
  84. house.name = 'houseType.json'
  85. house.version = '2.1'
  86. house.floors = []
  87. for (let i = 0; i < floorplanData.floors.length; ++i) {
  88. let item = {}
  89. item.points = []
  90. item.walls = []
  91. //floorplanData.floors.points
  92. //floorplanData.floors.walls
  93. for (let key in floorplanData.floors[i].points) {
  94. let point = {}
  95. point.x = floorplanData.floors[i].points[key].x
  96. point.y = floorplanData.floors[i].points[key].y
  97. point.parent = floorplanData.floors[i].points[key].parent
  98. point.vectorId = floorplanData.floors[i].points[key].vectorId
  99. item.points.push(point)
  100. }
  101. for (let key in floorplanData.floors[i].walls) {
  102. let wall = {}
  103. wall.start = floorplanData.floors[i].walls[key].start
  104. wall.end = floorplanData.floors[i].walls[key].end
  105. wall.children = []
  106. wall.vectorId = floorplanData.floors[i].walls[key].vectorId
  107. wall.width = 0.2
  108. item.walls.push(wall)
  109. }
  110. house.floors.push(item)
  111. }
  112. return house
  113. }
  114. }