Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The floor is not visible in the 3D output #37

Open
jackyjaiswal123 opened this issue Apr 25, 2021 · 1 comment
Open

The floor is not visible in the 3D output #37

jackyjaiswal123 opened this issue Apr 25, 2021 · 1 comment

Comments

@jackyjaiswal123
Copy link

jackyjaiswal123 commented Apr 25, 2021

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 
@ArtemisZGL
Copy link

have you solve this problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants