FloorplanTransformation icon indicating copy to clipboard operation
FloorplanTransformation copied to clipboard

The floor is not visible in the 3D output

Open jackyjaiswal123 opened this issue 4 years ago • 1 comments

Converting 2d floorplan to 3D model, using https://github.com/art-programmer/FloorplanTransformation. In rendering folder, while after running viewer.py we get the 3d model. But the floor and ceiling is not visible the function for floor and ceiling in floorplan.py is and output is also attached out

def generateFloor(self, data): floorGroup = EggGroup('floor') data.addChild(floorGroup)

vp = EggVertexPool('floor_vertex')
floorGroup.addChild(vp)


exteriorWalls = []
for wall in self.walls:
  if (wall[4] == 6 or wall[5] == 6):
    exteriorWalls.append(copy.deepcopy(wall))
    pass
  continue    


exteriorOpenings = []
for wall in exteriorWalls:
  lineDim = calcLineDim((wall[:2], wall[2:4]))
  for doorIndex, door in enumerate(self.doors):
    if calcLineDim((door[:2], door[2:4])) != lineDim:
      continue
    if door[lineDim] >= wall[lineDim] and door[2 + lineDim] <= wall[2 + lineDim] and abs(door[1 - lineDim] - wall[1 - lineDim]) <= self.wallWidth:
      exteriorOpenings.append(doorIndex)
      pass
    continue
  continue

minDistance = 10000
mainDoorIndex = -1
for icon in self.icons:
  if icon[4] == 'entrance':
    for doorIndex in exteriorOpenings:
      door = self.doors[doorIndex]
      distance = pow(pow((door[0] + door[2]) / 2 - (icon[0] + icon[2]) / 2, 2) + pow((door[1] + door[3]) / 2 - (icon[1] + icon[3]) / 2, 2), 0.5)
      if distance < minDistance:
        minDistance = distance
        mainDoorIndex = doorIndex
        pass
      continue
    break
  continue

self.startCameraPos = [0.5, -0.5, self.wallHeight * 0.5]
self.startTarget = [0.5, 0.5, self.wallHeight * 0.5]
if mainDoorIndex >= 0:
  mainDoor = self.doors[mainDoorIndex]
  lineDim = calcLineDim((mainDoor[:2], mainDoor[2:4]))
  fixedValue = (mainDoor[1 - lineDim] + mainDoor[3 - lineDim]) / 2
  imageSize = [self.width / self.maxDim, self.height / self.maxDim]
  side = int(fixedValue < imageSize[1 - lineDim] * 0.5) * 2 - 1
  self.startCameraPos[lineDim] = (mainDoor[lineDim] + mainDoor[2 + lineDim]) / 2
  self.startTarget[lineDim] = (mainDoor[lineDim] + mainDoor[2 + lineDim]) / 2
  self.startCameraPos[1 - lineDim] = fixedValue - 0.5 * side
  self.startTarget[1 - lineDim] = fixedValue + 0.5 * side
  
  self.startCameraPos[0] = 1 - self.startCameraPos[0]
  self.startTarget[0] = 1 - self.startTarget[0]
  pass

newDoors = []
self.windows = []
for doorIndex, door in enumerate(self.doors):
  if doorIndex == mainDoorIndex or doorIndex not in exteriorOpenings:
    newDoors.append(door)
  else:
    self.windows.append(door)
    pass
  continue
self.doors = newDoors


exteriorWallLoops = []
visitedMask = {}
gap = 5.0 / self.maxDim
for wallIndex, wall in enumerate(exteriorWalls):
  if wallIndex in visitedMask:
    continue
  visitedMask[wallIndex] = True
  exteriorWallLoop = []
  exteriorWallLoop.append(wall)
  for loopWall in exteriorWallLoop:
    for neighborWallIndex, neighborWall in enumerate(exteriorWalls):
      if neighborWallIndex in visitedMask:
        continue
      #if calcDistance(neighborWall[:2], loopWall[:2]) < gap or calcDistance(neighborWall[2:4], loopWall[:2]) < gap or calcDistance(neighborWall[:2], loopWall[2:4]) < gap or calcDistance(neighborWall[2:4], loopWall[2:4]) < gap:
      if calcDistance(neighborWall[:2], loopWall[2:4]) < gap:
        exteriorWallLoop.append(neighborWall)
        visitedMask[neighborWallIndex] = True
        break
      elif calcDistance(neighborWall[2:4], loopWall[2:4]) < gap:
        neighborWall[0], neighborWall[2] = neighborWall[2], neighborWall[0]
        neighborWall[1], neighborWall[3] = neighborWall[3], neighborWall[1]
        exteriorWallLoop.append(neighborWall)
        visitedMask[neighborWallIndex] = True
        break
      continue
    continue
  exteriorWallLoops.append(exteriorWallLoop)
  continue


for exteriorWallLoop in exteriorWallLoops:
  poly = EggPolygon()
  floorGroup.addChild(poly)
  
  poly.setTexture(self.floorMat.getEggTexture())
  poly.setMaterial(self.floorMat.getEggMaterial())
  
  
  for wallIndex, wall in enumerate(exteriorWallLoop):
    if wallIndex == 0:
      v = EggVertex()
      v.setPos(Point3D(1 - wall[0], wall[1], 0))
      v.setUv(Point2D(wall[0] * self.maxDim / self.width, 1 - wall[1] * self.maxDim / self.height))
      poly.addVertex(vp.addVertex(v))
    else:
      v = EggVertex()
      v.setPos(Point3D(1 - (wall[0] + exteriorWallLoop[wallIndex - 1][2]) / 2, (wall[1] + exteriorWallLoop[wallIndex - 1][3]) / 2, 0))
      v.setUv(Point2D((wall[0] + exteriorWallLoop[wallIndex - 1][2]) / 2 * self.maxDim / self.width, 1 - (wall[1] + exteriorWallLoop[wallIndex - 1][3]) / 2 * self.maxDim / self.height))
      poly.addVertex(vp.addVertex(v))
      pass
    if wallIndex == len(exteriorWallLoop) - 1:
      v = EggVertex()
      v.setPos(Point3D(1 - wall[2], wall[3], 0))
      v.setUv(Point2D(wall[2] * self.maxDim / self.width, 1 - wall[3] * self.maxDim / self.height))
      poly.addVertex(vp.addVertex(v))
      pass
    continue
  continue


ceilingGroup = EggGroup('ceiling')
data.addChild(ceilingGroup)

vp = EggVertexPool('ceiling_vertex')
ceilingGroup.addChild(vp)

for exteriorWallLoop in exteriorWallLoops:
  poly = EggPolygon()
  ceilingGroup.addChild(poly)
  
  poly.setTexture(self.ceilingMat.getEggTexture())
  poly.setMaterial(self.ceilingMat.getEggMaterial())

  for wallIndex, wall in enumerate(exteriorWallLoop):
    if wallIndex == 0:
      v = EggVertex()
      v.setPos(Point3D(1 - wall[0], wall[1], self.wallHeight))
      v.setUv(Point2D(wall[0], 1 - wall[1]))
      poly.addVertex(vp.addVertex(v))
    else:
      v = EggVertex()
      v.setPos(Point3D(1 - (wall[0] + exteriorWallLoop[wallIndex - 1][2]) / 2, (wall[1] + exteriorWallLoop[wallIndex - 1][3]) / 2, self.wallHeight))
      v.setUv(Point2D((wall[0] + exteriorWallLoop[wallIndex - 1][2]) / 2, 1 - (wall[1] + exteriorWallLoop[wallIndex - 1][3]) / 2))
      poly.addVertex(vp.addVertex(v))
      pass
    if wallIndex == len(exteriorWallLoop) - 1:
      v = EggVertex()
      v.setPos(Point3D(1 - wall[2], wall[3], self.wallHeight))
      v.setUv(Point2D(wall[2], 1 - wall[3]))
      poly.addVertex(vp.addVertex(v))
      pass
    continue
  continue

return 

jackyjaiswal123 avatar Apr 25 '21 16:04 jackyjaiswal123

have you solve this problem?

ArtemisZGL avatar Apr 25 '24 06:04 ArtemisZGL