Ooops
March 05, 2021, 07:13:02 PM

Author Topic: old bb code : city buildings generator (2012.09.27)  (Read 170 times)

Offline RemiD

old bb code : city buildings generator (2012.09.27)
« on: December 20, 2020, 10:46:13 AM »
old bb code : city buildings generator (2012.09.27)

use only meshes and vertices colors...

the positioning / rotating of the buildings is a little weird... but cool result nonetheless

Code: [Select]
Graphics3D(854,480,32,2) 
HidePointer() 
SeedRnd(MilliSecs()) 

Global DebugMode% = 0

Origine = CreateCube() 
ScaleMesh(Origine,1.0/2,1024.0,1.0/2)
EntityColor(Origine,255,000,000)
PositionEntity(Origine,0,0,0) 
HideEntity(Origine)

Global Camera = CreateCamera() 
CameraRange(Camera,1,1000)
CameraClsColor(Camera,000,000,000) 
PositionEntity(Camera,0,0,0) 

;Input
Global MX%
Global MY%
Global MXDiff%
Global MYDiff%

;Ghost
Global GhostRoot
Global GhostRootYaw#
Global GhostEyes
Global GhostEyesPitch#
AddGhost()

Global DistanceChecker = CreatePivot()
PositionEntity(DistanceChecker,0,0,0)

TrianglesMaxCount% = 10000
VerticesMaxCount% = TrianglesMaxCount%*3
Dim MVertexX#(VerticesMaxCount%)
Dim MVertexY#(VerticesMaxCount%)
Dim MVertexZ#(VerticesMaxCount%)
Dim MTriangleVertex0%(TrianglesMaxCount%)
Dim MTriangleVertex1%(TrianglesMaxCount%)
Dim MTriangleVertex2%(TrianglesMaxCount%)

Const ApartmentCube% = 101
Const ApartmentPrism% = 102
Const ApartmentCylinder% = 103

Const BuildingsMaxCount% = 200
Dim BuildingKind%(BuildingsMaxCount%)
Dim BuildingWallsMesh(BuildingsMaxCount%)
Dim BuildingGlowMesh(BuildingsMaxCount%)
Dim BuildingWidth%(BuildingsMaxCount%)
Dim BuildingHeight%(BuildingsMaxCount%)
Dim BuildingDepth%(BuildingsMaxCount%)
Dim BuildingX#(BuildingsMaxCount%)
Dim BuildingY#(BuildingsMaxCount%)
Dim BuildingZ#(BuildingsMaxCount%)
Dim BuildingPitch#(BuildingsMaxCount%)
Dim BuildingYaw#(BuildingsMaxCount%)
Dim BuildingRoll#(BuildingsMaxCount%)
Global BuildingsCount% = 0

Const CollidersMaxCount% = BuildingsMaxCount%
Dim Collider(CollidersMaxCount%)
Global CollidersCount% = 0

Const NodesPerBuildingMaxCount% = 12
Dim NodePivot(BuildingsMaxCount%,NodesPerBuildingMaxCount%)
If(DebugMode% = 1)
 Dim NodeMesh(BuildingsMaxCount%,NodesPerBuildingMaxCount%)
EndIf
Dim NodesCount%(BuildingsMaxCount%)
Global NodesTotalCount% = 0
Global SNodesCount% = 0

;Const LinksPerNodeMaxCount% = 100
;Dim NodeLinkToNode%(BuildingsMaxCount%,NodesPerBuildingMaxCount%,LinksPerNodeMaxCount%)
;Dim NodeLinksCount%(BuildingsMaxCount%,NodesPerBuildingMaxCount%)

Global GroundMesh = CreateCube()
ScaleMesh(GroundMesh,1024.0/2,0.1/2,1024.0/2)
PositionMesh(GroundMesh,1024.0/2,-0.1/2,1024.0/2)
EntityColor(GroundMesh,030,030,030)
PositionEntity(GroundMesh,0,0,0)
ScaleEntity(GroundMesh,2,2,2)
MoveEntity(GroundMesh,-512,0,-512)

Global SkyBoxMesh = CreateCube()
FlipMesh(SkyBoxMesh)
ScaleMesh(SkyBoxMesh,1024.0/2,1024.0/2,1024.0/2)
PositionMesh(SkyBoxMesh,1024.0/2,0,1024.0/2)
EntityColor(SkyBoxMesh,010,010,010)
PositionEntity(SkyBoxMesh,0,0,0)
HideEntity(SkyBoxMesh)

Global ApartmentCubeWalls = CreateCube()
ScaleMesh(ApartmentCubeWalls,1.0/2,1.0/2,1.0/2)
PositionMesh(ApartmentCubeWalls,1.0/2,1.0/2,1.0/2)
EntityColor(ApartmentCubeWalls,050,050,050)
PositionEntity(ApartmentCubeWalls,0,0,0)
HideEntity(ApartmentCubeWalls)

Global ApartmentCubeBorder = CreateMesh()
Surface = CreateSurface(ApartmentCubeBorder)
AddVertex(Surface, 0.0, 0.0, 0.0)
AddVertex(Surface, 0.0, 1.0, 0.0)
AddVertex(Surface, 1.0, 1.0, 0.0)
AddVertex(Surface, 1.0, 0.0, 0.0)
AddTriangle(Surface,0,1,2)
AddTriangle(Surface,0,2,3)
AddVertex(Surface, 0.0, 0.0, 1.0)
AddVertex(Surface, 0.0, 1.0, 1.0)
AddVertex(Surface, 0.0, 1.0, 0.0)
AddVertex(Surface, 0.0, 0.0, 0.0)
AddTriangle(Surface,4,5,6)
AddTriangle(Surface,4,6,7)
UpdateNormals(ApartmentCubeBorder)
PositionMesh(ApartmentCubeBorder,0,0,0)
HideEntity(ApartmentCubeBorder)

;ScaleMesh(ApartmentCubeBorder,1.0/2,1.0/2,1.0/2)
;PositionMesh(ApartmentCubeBorder,0,1.0/2,0)
;EntityColor(ApartmentCubeBorder,255,255,255)
;PositionEntity(ApartmentCubeBorder,0,0,0)
;HideEntity(ApartmentCubeBorder)

Global ApartmentCubePlatform = CreateCube()
ScaleMesh(ApartmentCubePlatform,1.0/2,0.1/2,1.0/2)
PositionMesh(ApartmentCubePlatform,1.0/2,0,1.0/2)
EntityColor(ApartmentCubePlatform,255,255,255)
PositionEntity(ApartmentCubePlatform,0,0,0)
HideEntity(ApartmentCubePlatform)

Global ApartmentCubeDoorWalls = CreateCube()
ScaleMesh(ApartmentCubeDoorWalls,5.0/2,4.0/2,2.0/2)
PositionMesh(ApartmentCubeDoorWalls,5.0/2,4.0/2,2.0/2)
EntityColor(ApartmentCubeDoorWalls,255,255,255)
PositionEntity(ApartmentCubeDoorWalls,0,0,0)
HideEntity(ApartmentCubeDoorWalls)

Global ApartmentCubeDoor = CreateMesh()
Surface = CreateSurface(ApartmentCubeDoor)
AddVertex(Surface, 0.0, 0.0, 0.0)
AddVertex(Surface, 0.0, 3.0, 0.0)
AddVertex(Surface, 3.0, 3.0, 0.0)
AddVertex(Surface, 3.0, 0.0, 0.0)
AddTriangle(Surface,0,1,2)
AddTriangle(Surface,0,2,3)
UpdateNormals(ApartmentCubeDoor)
PositionMesh(ApartmentCubeDoor,0,0,0)
HideEntity(ApartmentCubeDoor)

;Global ApartmentCubeWindow = CreateMesh()
;Surface = CreateSurface(ApartmentCubeWindow)
;AddVertex(Surface, 0.0, 0.0, 0.0)
;AddVertex(Surface, 0.0, 3.0, 0.0)
;AddVertex(Surface, 6.0, 3.0, 0.0)
;AddVertex(Surface, 6.0, 0.0, 0.0)
;AddTriangle(Surface,0,1,2)
;AddTriangle(Surface,0,2,3)
;UpdateNormals(ApartmentCubeWindow)
;PositionMesh(ApartmentCubeWindow,0,0,0)
;HideEntity(ApartmentCubeWindow)

Global ApartmentCubeWindow = CreateMesh()
Surface = CreateSurface(ApartmentCubeWindow)
AddVertex(Surface, 3.0, 1.5, 0.0) ;0
AddVertex(Surface, 0.0, 3.0, 0.0) ;1
AddVertex(Surface, 6.0, 3.0, 0.0) ;2
AddVertex(Surface, 0.0, 0.0, 0.0) ;3
AddVertex(Surface, 6.0, 0.0, 0.0) ;4
AddTriangle(Surface,0,1,2)
AddTriangle(Surface,0,4,3)
AddTriangle(Surface,0,3,1)
AddTriangle(Surface,0,2,4)
UpdateNormals(ApartmentCubeWindow)
PositionMesh(ApartmentCubeWindow,0,0,0)
HideEntity(ApartmentCubeWindow)

Global CubeCollider = CreateCube()
ScaleMesh(CubeCollider,1.0/2,1.0/2,1.0/2)
PositionMesh(CubeCollider,1.0/2,1.0/2,1.0/2)
EntityColor(CubeCollider,125,000,000)
EntityAlpha(CubeCollider,0.5)
PositionEntity(CubeCollider,0,0,0)
HideEntity(CubeCollider)

Global NodePositionerCube = CreateMesh()
Surface = CreateSurface(NodePositionerCube)
AddVertex(Surface, 0.0, 0.0, 0.0)
AddVertex(Surface, 0.0, 0.0, 1.0)
AddVertex(Surface, 1.0, 0.0, 1.0)
AddVertex(Surface, 1.0, 0.0, 0.0)
AddTriangle(Surface,0,1,2)
AddTriangle(Surface,0,2,3)
UpdateNormals(NodePositionerCube)
PositionMesh(NodePositionerCube,0,0,0)
HideEntity(NodePositionerCube)

Global SNodePositionerCube = CopyMesh(NodePositionerCube)
PositionMesh(SNodePositionerCube,0,0,0)
HideEntity(SNodePositionerCube)

;BuildingPrism = CreateCube()
;ScaleMesh(BuildingPrism,1.0/2,1.0/2,1.0/2)
;PositionMesh(BuildingPrism,1.0/2,1.0/2,1.0/2)
;EntityColor(BuildingPrism,050,050,050)
;PositionEntity(BuildingPrism,0,0,0)
;HideEntity(BuildingPrism)

;BuildingCylinder = CreateCylinder(8)
;ScaleMesh(BuildingCylinder,1.0/2,1.0/2,1.0/2)
;PositionMesh(BuildingCylinder,1.0/2,1.0/2,1.0/2)
;EntityColor(BuildingCylinder,050,050,050)
;PositionEntity(BuildingCylinder,0,0,0)
;HideEntity(BuildingCylinder)

Global NodeXMesh = CreateCube()
ScaleMesh(NodeXMesh,0.1/2,0.1/2,0.1/2)
PositionMesh(NodeXMesh,0,0,0)
EntityColor(NodeXMesh,255,255,000)
PositionEntity(NodeXMesh,0,0,0)
HideEntity(NodeXMesh)

Global SNodeXMesh = CreateCube()
ScaleMesh(SNodeXMesh,1.0/2,1.0/2,1.0/2)
PositionMesh(SNodeXMesh,0,0,0)
EntityColor(SNodeXMesh,255,125,000)
PositionEntity(SNodeXMesh,0,0,0)
HideEntity(SNodeXMesh)

Global LinkXMesh = CreateCube()
ScaleMesh(LinkXMesh,0.05/2,0.05/2,0.05/2)
EntityColor(LinkXMesh,255,255,255)
PositionEntity(LinkXMesh,0,0,0)
HideEntity(LinkXMesh)

Repeat
 CityGenerate()
Until(BuildingsCount% = BuildingsMaxCount%)
If(DebugMode% = 0)
 For CId% = 1 To CollidersCount%
  FreeEntity(Collider(CId%))
  Collider(CId%) = 0
 Next
EndIf
   
PositionEntity(GhostRoot,512,100+1.65,512,True)

DirectLight = CreateLight(1) 
LightColor(DirectLight,125,125,125) 
PositionEntity(DirectLight,0,128.0,-128.0) 
RotateEntity(DirectLight,45,0,0) 
;HideEntity(DirectLight)
AmbientLight(010,010,010)
;CameraFogMode(Camera,1)
;CameraFogColor(Camera,010,010,10)
;CameraFogRange(Camera,0.1,512.0)

Main()

Function Main()

 Repeat 
 
  MX = MouseX()
  MY = MouseY()

  MXDiff = MouseXSpeed()
  MYDiff = MouseYSpeed()
   
  UpdateGhost() 

  WireFrame(False)
  If( KeyDown(2)=1 )
   WireFrame(True)
  EndIf

  PositionEntity(Camera,EntityX(GhostEyes,True),EntityY(GhostEyes,True),EntityZ(GhostEyes,True),True)
  RotateEntity(Camera,EntityPitch(GhostEyes,True),EntityYaw(GhostEyes,True),EntityRoll(GhostEyes,True),True)

  CameraViewport(Camera,0,0,GraphicsWidth(),GraphicsHeight())
  CameraClsColor(Camera,000,000,000)
  SetBuffer(BackBuffer())
  RenderWorld()

  If( KeyDown(2)=1 )
   Color(255,255,255)
   Text(0,0,"Tris = "+TrisRendered())
  EndIf
 
  Flip(1)
 
 Until(KeyDown(1)=True)

End Function

Function CityGenerate()

 ;Print("")
 ;Repeat
 If(BuildingsCount% <= BuildingsMaxCount%)

 ;Print("Defines the TempBuildingKind.")
  ;RandomKindTries% = 0
  ;.LineRandomKind
  RandomKind% = 1;Rand(1,3)
  If(RandomKind% = 1)
   TempKind% = ApartmentCube% 
  ElseIf(RandomKind% = 2)
   TempKind% = ApartmentPrism%
  ElseIf(RandomKind% = 3)
   TempKind% = ApartmentCylinder%
  EndIf 

  ;Print("Defines the TempBuildingScale.")
  ;RandomScaleTries% = 0
  ;.LineRandomScale 
  RandomChoice% = Rand(1,2)
  If(RandomChoice% = 1)
   BlocsXCount% = 3
  ElseIf(RandomChoice% = 2)
   BlocsXCount% = 5
  ElseIf(RandomChoice% = 3)
   BlocsXCount% = 7
  ElseIf(RandomChoice% = 4)
   BlocsXCount% = 9
  EndIf
;BlocsXCount% = 9
  TempWidth% = 10*BlocsXCount%
  ;PlatformsCount% = Rand(3,10)
  BlocsYCount% = Rand(3,30)
;BlocsYCount% = 50
  TempHeight% = 5*BlocsYCount%
  RandomChoice% = Rand(1,2)
  If(RandomChoice% = 1)
   BlocsZCount% = 3
  ElseIf(RandomChoice% = 2)
   BlocsZCount% = 5
  ElseIf(RandomChoice% = 3)
   BlocsZCount% = 7
  ElseIf(RandomChoice% = 4)
   BlocsZCount% = 9
  EndIf
;BlocsZCount% = 9
  TempDepth% = 10*BlocsZCount%
  If(NodesTotalCount% = 0)

   ;Print("Defines the coordinates of the first node.")
   SNodeX# = 512.0
   SNodeY# = 0.0
   SNodeZ# = 512.0   
  ElseIf(NodesTotalCount% > 0)

   ;Print("Defines the coordinates of the new node by selecting a random node from a random building.")
   SBuildingId% = Rand(1,BuildingsCount%)
   If(BuildingKind%(SBuildingId%) = ApartmentCube%)
    TempSNodePositionerCube = CopyEntity(SNodePositionerCube)
    ScaleEntity(TempSNodePositionerCube,BuildingWidth%(SBuildingId%)+4,1.0,BuildingDepth%(SBuildingId%)+4)
    RotateEntity(TempSNodePositionerCube,BuildingPitch#(SBuildingId%),BuildingYaw#(SBuildingId%),BuildingRoll#(SBuildingId%))
    PositionEntity(TempSNodePositionerCube,BuildingX#(SBuildingId%),BuildingY#(SBuildingId%),BuildingZ#(SBuildingId%))
    MoveEntity(TempSNodePositionerCube,-2.0,0,-2.0)
    EntityColor(TempSNodePositionerCube,125,125,125)
    For SI% = 1 To CountSurfaces(TempSNodePositionerCube)
     SP% = GetSurface(TempSNodePositionerCube,SI%)
     SNodeI% = Rand(0,CountVertices(SP%)-1)
     For VI% = 0 To CountVertices(SP%)-1
      If(VI% = SNodeI%)
       ;VX# = VertexX(SP%,VI%)
       ;VY# = VertexY(SP%,VI%)
       ;VZ# = VertexZ(SP%,VI%)
       TFormPoint(VertexX(SP%,VI%),VertexY(SP%,VI%),VertexZ(SP%,VI%),TempSNodePositionerCube,0)
       VX# = TFormedX()
       VY# = TFormedY()
       VZ# = TFormedZ()
       SNodeX# = VX#
       SNodeY# = VY#
       SNodeZ# = VZ#         
      EndIf
     Next
    Next
    FreeEntity(TempSNodePositionerCube)
   EndIf
  EndIf   

  ;Print("Defines the TempBuildingPosition depending on the node chosen.")
  ;RandomPositionTries% = 0
  ;.LineRandomPosition
  TempX# = SNodeX#
  TempY# = SNodeY#
  TempZ# = SNodeZ# 

  ;Print("Defines the TempBuildingOrientation.")
  ;RandomOrientationTries% = 0
  ;.LineRandomOrientation
  TempPitch# = 0
  TempYaw# = Rand(-180,180)
  TempRoll# = 0 

  ;Print("Checks if the TempCollider is inside the zone of the level.")
  TempColliderInZoneState% = 0
  If( (TempX# > (0 + (TempWidth%+2))) And (TempX# < (1024.0 - (TempWidth%+2))) And (TempX# > (0 + (TempDepth%+2))) And (TempX# < (1024.0 - (TempDepth%+2))) And (TempZ# > (0 + (TempWidth%+2))) And (TempZ# < (1024.0 - (TempWidth%+2))) And (TempZ# > (0 + (TempDepth%+2))) And (TempZ# < (1024.0 - (TempDepth%+2))) )
   TempColliderInZoneState% = 1
  Else
   TempColliderInZoneState% = 2   
  EndIf
 If(TempColliderInZoneState% = 1)

  ;Print("Create, scales, positions, rotates the TempCollider.")
  If(TempKind% = ApartmentCube%)
   TempCollider = CopyEntity(CubeCollider)
  ElseIf(TempKind% = ApartmentPrism%)
;   TempCollider = CopyEntity(PrismCollider)
  ElseIf(TempKind% = ApartmentCylinder%)
;   TempCollider = CopyEntity(CylinderCollider)
  EndIf
  ScaleEntity(TempCollider,TempWidth%+2,TempHeight%+1,TempDepth%+2)
  RotateEntity(TempCollider,TempPitch#,TempYaw#,TempRoll#)
  PositionEntity(TempCollider,TempX#,TempY#,TempZ#)
  MoveEntity(TempCollider,-1.0,0,-1.0)

  ;Print("Checks if the TempCollider collides with one of the existing Colliders.")
  CollisionsCount% = 0
  If(CollidersCount% = 0)
   CollisionsCount% = 0
  ElseIf(CollidersCount% > 0)
   For ColliderId% = 1 To CollidersCount%
    If(Collider(ColliderId%) <> 0)
     If( MeshesIntersect(TempCollider,Collider(ColliderId%))=True )
      CollisionsCount% = CollisionsCount% + 1
     EndIf
    EndIf
   Next
  EndIf

  ;Print("Deletes the TempCollider.")
  FreeEntity(TempCollider)
  If(CollisionsCount% = 0)

   ;Print("The TempCollider does not collide with one of the existing Colliders.")
   If(TempKind% = ApartmentCube%) 
   
    ;Print("Creates the final Building.")
    BuildingsCount% = BuildingsCount% + 1
    ;Print("BuildingsCount% : "+BuildingsCount%)
    BuildingId% = BuildingsCount%
    BuildingKind%(BuildingId%) = ApartmentCube%
    BuildingWidth%(BuildingId%) = TempWidth%
    BuildingHeight%(BuildingId%) = TempHeight%
    BuildingDepth%(BuildingId%) = TempDepth%
    BuildingX#(BuildingId%) = TempX#
    BuildingY#(BuildingId%) = TempY#
    BuildingZ#(BuildingId%) = TempZ#
    BuildingPitch#(BuildingId%) = TempPitch#
    BuildingYaw#(BuildingId%) = TempYaw#
    BuildingRoll#(BuildingId%) = TempRoll#

    ;Print("Creates the final BuildingWalls.")   
    BuildingWallsMesh(BuildingId%) = CreateMesh()
    EntityFX(BuildingWallsMesh(BuildingId%),0)
    RGB% = Rand(050,150)
    EntityColor(BuildingWallsMesh(BuildingId%),RGB+Rand(-012,012),RGB+Rand(-012,012),RGB+Rand(-012,012))
    RotateMesh(BuildingWallsMesh(BuildingId%),0,0,0)
    PositionMesh(BuildingWallsMesh(BuildingId%),0,0,0)

    ;Print("Creates the final BuildingGlow.")
    BuildingGlowMesh(BuildingId%) = CreateMesh()
    EntityFX(BuildingGlowMesh(BuildingId%),1+2)
    RotateMesh(BuildingGlowMesh(BuildingId%),0,0,0)
    PositionMesh(BuildingGlowMesh(BuildingId%),0,0,0)

    ;Print("Creates the Walls.")
    TempMarqueur = CreatePivot()   
    RotateEntity(TempMarqueur,0,0,0)
    PositionEntity(TempMarqueur,0,0,0)   
    MoveEntity(TempMarqueur,0,0,0)
    TempMarqueurX# = EntityX(TempMarqueur,True)
    TempMarqueurY# = EntityY(TempMarqueur,True)
    TempMarqueurZ# = EntityZ(TempMarqueur,True)
    FreeEntity(TempMarqueur)
    TempPart = CopyMesh(ApartmentCubeWalls)
    ScaleMesh(TempPart,TempWidth%,TempHeight%,TempDepth%)
    ;EntityFX(TempPart,2)   
    ;For SI% = 1 To CountSurfaces(TempPart)
     ;SP% = GetSurface(TempPart,SI%)
     ;For VI% = 0 To CountVertices(SP%)-1
      ;VertexColor(SP%,VI%,030,030,030,1.0)     
     ;Next
    ;Next
    RotateMesh(TempPart,0,0,0)
    PositionMesh(TempPart,TempMarqueurX#,TempMarqueurY#,TempMarqueurZ#) 
    AddMesh(TempPart,BuildingWallsMesh(BuildingId%))
    FreeEntity(TempPart)   
    R% = Rand(000,255)
    G% = Rand(000,255)
    B% = Rand(000,255)   

;    ;Print("Creates the Border BackLeft.")
;    TempMarqueur = CreatePivot()   
;    RotateEntity(TempMarqueur,0,0,0)
;    PositionEntity(TempMarqueur,0,0,0)   
;    MoveEntity(TempMarqueur,-0.1,0,-0.1)
;    TempMarqueurX# = EntityX(TempMarqueur,True)
;    TempMarqueurY# = EntityY(TempMarqueur,True)
;    TempMarqueurZ# = EntityZ(TempMarqueur,True)
;    FreeEntity(TempMarqueur)
;    TempPart = CopyMesh(ApartmentCubeBorder)
;    ScaleMesh(TempPart,1.0,TempHeight%,1.0)
;    EntityFX(TempPart,1+2)
;    For SI% = 1 To CountSurfaces(TempPart)
;     SP% = GetSurface(TempPart,SI%)
;     For VI% = 0 To CountVertices(SP%)-1           
;       VertexColor(SP%,VI%,R%,G%,B%,1.0)
;     Next     
;    Next
;    RotateMesh(TempPart,0,0,0)
;    RotateMesh(TempPart,0,0,0)
;    PositionMesh(TempPart,TempMarqueurX#,TempMarqueurY#,TempMarqueurZ#)
;    AddMesh(TempPart,BuildingGlowMesh(BuildingId%))
;    FreeEntity(TempPart)
;    ;Print("Creates the Border FrontLeft.")
;    TempMarqueur = CreatePivot()   
;    RotateEntity(TempMarqueur,0,0,0)
;    PositionEntity(TempMarqueur,0,0,0)   
;    MoveEntity(TempMarqueur,0,0,TempDepth%)
;    MoveEntity(TempMarqueur,-0.1,0,0.1)
;    TempMarqueurX# = EntityX(TempMarqueur,True)
;    TempMarqueurY# = EntityY(TempMarqueur,True)
;    TempMarqueurZ# = EntityZ(TempMarqueur,True)
;    FreeEntity(TempMarqueur)
;    TempPart = CopyMesh(ApartmentCubeBorder)
;    ScaleMesh(TempPart,1.0,TempHeight%,1.0)
;    EntityFX(TempPart,1+2)   
;    For SI% = 1 To CountSurfaces(TempPart)
;     SP% = GetSurface(TempPart,SI%)
;     For VI% = 0 To CountVertices(SP%)-1           
;       VertexColor(SP%,VI%,R%,G%,B%,1.0)
;     Next     
;    Next
;    RotateMesh(TempPart,0,-90,0)
;    RotateMesh(TempPart,0,0,0)
;    PositionMesh(TempPart,TempMarqueurX#,TempMarqueurY#,TempMarqueurZ#)
;    AddMesh(TempPart,BuildingGlowMesh(BuildingId%))
;    FreeEntity(TempPart)
;    ;Print("Creates the Border FrontRight.")
;    TempMarqueur = CreatePivot()   
;    RotateEntity(TempMarqueur,0,0,0)
;    PositionEntity(TempMarqueur,0,0,0)   
;    MoveEntity(TempMarqueur,TempWidth%,0,TempDepth%)
;    MoveEntity(TempMarqueur,0.1,0,0.1)
;    TempMarqueurX# = EntityX(TempMarqueur,True)
;    TempMarqueurY# = EntityY(TempMarqueur,True)
;    TempMarqueurZ# = EntityZ(TempMarqueur,True)
;    FreeEntity(TempMarqueur)
;    TempPart = CopyMesh(ApartmentCubeBorder)
;    ScaleMesh(TempPart,1.0,TempHeight%,1.0)
;    EntityFX(TempPart,1+2)   
;    For SI% = 1 To CountSurfaces(TempPart)
;     SP% = GetSurface(TempPart,SI%)
;     For VI% = 0 To CountVertices(SP%)-1           
;       VertexColor(SP%,VI%,R%,G%,B%,1.0)
;     Next     
;    Next
;    RotateMesh(TempPart,0,-180,0)
;    RotateMesh(TempPart,0,0,0)
;    PositionMesh(TempPart,TempMarqueurX#,TempMarqueurY#,TempMarqueurZ#)
;    AddMesh(TempPart,BuildingGlowMesh(BuildingId%))
;    FreeEntity(TempPart)
;    ;Print("Creates the Border BackRight.")
;    TempMarqueur = CreatePivot()   
;    RotateEntity(TempMarqueur,0,0,0)
;    PositionEntity(TempMarqueur,0,0,0)   
;    MoveEntity(TempMarqueur,TempWidth%,0,0)
;    MoveEntity(TempMarqueur,0.1,0,-0.1)
;    TempMarqueurX# = EntityX(TempMarqueur,True)
;    TempMarqueurY# = EntityY(TempMarqueur,True)
;    TempMarqueurZ# = EntityZ(TempMarqueur,True)
;    FreeEntity(TempMarqueur)
;    TempPart = CopyMesh(ApartmentCubeBorder)     
;    ScaleMesh(TempPart,1.0,TempHeight%,1.0)
;    EntityFX(TempPart,1+2) 
;    For SI% = 1 To CountSurfaces(TempPart)
;     SP% = GetSurface(TempPart,SI%)
;     For VI% = 0 To CountVertices(SP%)-1           
;       VertexColor(SP%,VI%,R%,G%,B%,1.0)
;     Next     
;    Next   
;    RotateMesh(TempPart,0,90,0)
;    RotateMesh(TempPart,0,0,0)
;    PositionMesh(TempPart,TempMarqueurX#,TempMarqueurY#,TempMarqueurZ#)
;    AddMesh(TempPart,BuildingGlowMesh(BuildingId%))
;    FreeEntity(TempPart)

    ;Print("Creates the Door Back.")

    ;Print("Creates the Door Left.")

    ;Print("Creates the Door Front.")

    ;Print("Creates the Door Right.")

    ;Print("Creates the Windows Back.")
    WindowsBackPart = CreateMesh()
    For BX% = 0 To BlocsXCount%-1
     For BY% = 0 To BlocsYCount%-1
      BZ% = 0
      TempMarqueur = CreateCube()
      ScaleEntity(TempMarqueur,0.1/2,0.1/2,0.1/2)
      RotateEntity(TempMarqueur,0,0,0)
      PositionEntity(TempMarqueur,0,0,0)   
      MoveEntity(TempMarqueur,(BX%*10)+10.0/2-6.0/2,(BY%*5.0)+5.0/2-3.0/2,BZ%-0.1)
      EntityColor(TempMarqueur,125,000,255)
      TempMarqueurX# = EntityX(TempMarqueur,True)
      TempMarqueurY# = EntityY(TempMarqueur,True)
      TempMarqueurZ# = EntityZ(TempMarqueur,True)     
      FreeEntity(TempMarqueur)
      TempPart = CopyMesh(ApartmentCubeWindow)   
      ScaleMesh(TempPart,1.0,1.0,1.0)
      EntityFX(TempPart,1+2)
      WindowLightState% = Rand(1,2)     
      For SI% = 1 To CountSurfaces(TempPart)
       SP% = GetSurface(TempPart,SI%)
       If(WindowLightState% = 1) 
        R% = Rand(000,255)
        G% = Rand(000,255)
        B% = Rand(000,255)   
        VI% = 0
        VertexColor(SP%,VI%,R%,G%,B%,1.0)
        For VI% = 1 To CountVertices(SP%)-1         
          VertexColor(SP%,VI%,000,000,000,1.0)
        Next
       ElseIf(WindowLightState% = 2)
        For VI% = 0 To CountVertices(SP%)-1         
          VertexColor(SP%,VI%,000,000,000,1.0)
        Next
       EndIf
      Next
      RotateMesh(TempPart,0,0,0)
      PositionMesh(TempPart,TempMarqueurX#,TempMarqueurY#,TempMarqueurZ#)
      AddMesh(TempPart,WindowsBackPart)
      FreeEntity(TempPart)
     Next
    Next
    RotateMesh(WindowsBackPart,0,0,0)
    PositionMesh(WindowsBackPart,0,0,0)
    AddMesh(WindowsBackPart,BuildingGlowMesh(BuildingId%))
    FreeEntity(WindowsBackPart)

    ;Print("Creates the Windows Left.")
    WindowsLeftPart = CreateMesh()
    For BX% = 0 To BlocsZCount%-1
     For BY% = 0 To BlocsYCount%-1
      BZ% = 0
      TempMarqueur = CreateCube()
      ScaleEntity(TempMarqueur,0.1/2,0.1/2,0.1/2)
      RotateEntity(TempMarqueur,0,0,0)
      PositionEntity(TempMarqueur,0,0,0)   
      MoveEntity(TempMarqueur,(BX%*10)+10.0/2-6.0/2,(BY%*5.0)+5.0/2-3.0/2,BZ%-0.1)
      EntityColor(TempMarqueur,125,000,255)
      TempMarqueurX# = EntityX(TempMarqueur,True)
      TempMarqueurY# = EntityY(TempMarqueur,True)
      TempMarqueurZ# = EntityZ(TempMarqueur,True)     
      FreeEntity(TempMarqueur)
      TempPart = CopyMesh(ApartmentCubeWindow)   
      ScaleMesh(TempPart,1.0,1.0,1.0)
      EntityFX(TempPart,1+2)
      WindowLightState% = Rand(1,2)     
      For SI% = 1 To CountSurfaces(TempPart)
       SP% = GetSurface(TempPart,SI%)
       If(WindowLightState% = 1) 
        R% = Rand(000,255)
        G% = Rand(000,255)
        B% = Rand(000,255)   
        VI% = 0
        VertexColor(SP%,VI%,R%,G%,B%,1.0)
        For VI% = 1 To CountVertices(SP%)-1         
          VertexColor(SP%,VI%,000,000,000,1.0)
        Next
       ElseIf(WindowLightState% = 2)
        For VI% = 0 To CountVertices(SP%)-1         
          VertexColor(SP%,VI%,000,000,000,1.0)
        Next
       EndIf 
      Next
      RotateMesh(TempPart,0,0,0)
      PositionMesh(TempPart,TempMarqueurX#,TempMarqueurY#,TempMarqueurZ#)
      AddMesh(TempPart,WindowsLeftPart)
      FreeEntity(TempPart)
     Next
    Next
    RotateMesh(WindowsLeftPart,0,-90,0)
    PositionMesh(WindowsLeftPart,0,0,TempDepth%)
    AddMesh(WindowsLeftPart,BuildingGlowMesh(BuildingId%))
    FreeEntity(WindowsLeftPart)

    ;Print("Creates the Windows Front.")
    WindowsFrontPart = CreateMesh()
    For BX% = 0 To BlocsXCount%-1
     For BY% = 0 To BlocsYCount%-1
      BZ% = 0
      TempMarqueur = CreateCube()
      ScaleEntity(TempMarqueur,0.1/2,0.1/2,0.1/2)
      RotateEntity(TempMarqueur,0,0,0)
      PositionEntity(TempMarqueur,0,0,0)   
      MoveEntity(TempMarqueur,(BX%*10)+10.0/2-6.0/2,(BY%*5.0)+5.0/2-3.0/2,BZ%-0.1)
      EntityColor(TempMarqueur,125,000,255)
      TempMarqueurX# = EntityX(TempMarqueur,True)
      TempMarqueurY# = EntityY(TempMarqueur,True)
      TempMarqueurZ# = EntityZ(TempMarqueur,True)     
      FreeEntity(TempMarqueur)
      TempPart = CopyMesh(ApartmentCubeWindow)   
      ScaleMesh(TempPart,1.0,1.0,1.0)
      EntityFX(TempPart,1+2)
      WindowLightState% = Rand(1,2)     
      For SI% = 1 To CountSurfaces(TempPart)
       SP% = GetSurface(TempPart,SI%)
       If(WindowLightState% = 1) 
        R% = Rand(000,255)
        G% = Rand(000,255)
        B% = Rand(000,255)   
        VI% = 0
        VertexColor(SP%,VI%,R%,G%,B%,1.0)
        For VI% = 1 To CountVertices(SP%)-1         
          VertexColor(SP%,VI%,000,000,000,1.0)
        Next
       ElseIf(WindowLightState% = 2)
        For VI% = 0 To CountVertices(SP%)-1         
          VertexColor(SP%,VI%,000,000,000,1.0)
        Next
       EndIf
      Next
      RotateMesh(TempPart,0,0,0)
      PositionMesh(TempPart,TempMarqueurX#,TempMarqueurY#,TempMarqueurZ#)
      AddMesh(TempPart,WindowsFrontPart)
      FreeEntity(TempPart)
     Next
    Next
    RotateMesh(WindowsFrontPart,0,180,0)
    PositionMesh(WindowsFrontPart,TempWidth%,0,TempDepth%)
    AddMesh(WindowsFrontPart,BuildingGlowMesh(BuildingId%))
    FreeEntity(WindowsFrontPart)

    ;Print("Creates the Windows Right.")
    WindowsRightPart = CreateMesh()
    For BX% = 0 To BlocsZCount%-1
     For BY% = 0 To BlocsYCount%-1
      BZ% = 0
      TempMarqueur = CreateCube()
      ScaleEntity(TempMarqueur,0.1/2,0.1/2,0.1/2)
      RotateEntity(TempMarqueur,0,0,0)
      PositionEntity(TempMarqueur,0,0,0)   
      MoveEntity(TempMarqueur,(BX%*10)+10.0/2-6.0/2,(BY%*5.0)+5.0/2-3.0/2,BZ%-0.1)
      EntityColor(TempMarqueur,125,000,255)
      TempMarqueurX# = EntityX(TempMarqueur,True)
      TempMarqueurY# = EntityY(TempMarqueur,True)
      TempMarqueurZ# = EntityZ(TempMarqueur,True)     
      FreeEntity(TempMarqueur)
      TempPart = CopyMesh(ApartmentCubeWindow)   
      ScaleMesh(TempPart,1.0,1.0,1.0)
      EntityFX(TempPart,1+2)
      WindowLightState% = Rand(1,2)     
      For SI% = 1 To CountSurfaces(TempPart)
       SP% = GetSurface(TempPart,SI%)
       If(WindowLightState% = 1) 
        R% = Rand(000,255)
        G% = Rand(000,255)
        B% = Rand(000,255)   
        VI% = 0
        VertexColor(SP%,VI%,R%,G%,B%,1.0)
        For VI% = 1 To CountVertices(SP%)-1         
          VertexColor(SP%,VI%,000,000,000,1.0)
        Next
       ElseIf(WindowLightState% = 2)
        For VI% = 0 To CountVertices(SP%)-1         
          VertexColor(SP%,VI%,000,000,000,1.0)
        Next
       EndIf
      Next
      RotateMesh(TempPart,0,0,0)
      PositionMesh(TempPart,TempMarqueurX#,TempMarqueurY#,TempMarqueurZ#)
      AddMesh(TempPart,WindowsRightPart)
      FreeEntity(TempPart)
     Next
    Next
    RotateMesh(WindowsRightPart,0,90,0)
    PositionMesh(WindowsRightPart,TempWidth%,0,0)
    AddMesh(WindowsRightPart,BuildingGlowMesh(BuildingId%))
    FreeEntity(WindowsRightPart)

    ;Print("Rotates, positions the final BuildingMesh.")
    RotateMesh(BuildingWallsMesh(BuildingId%),TempPitch#,TempYaw#,TempRoll#)
    PositionMesh(BuildingWallsMesh(BuildingId%),TempX#,TempY#,TempZ#)
    RotateMesh(BuildingGlowMesh(BuildingId%),TempPitch#,TempYaw#,TempRoll#)
    PositionMesh(BuildingGlowMesh(BuildingId%),TempX#,TempY#,TempZ#)

    ;Print("Creates the final Collider.")
    CollidersCount% = CollidersCount% + 1
    ;Print("CollidersCount% : "+CollidersCount%)
    ColliderId% = CollidersCount%
    Collider(ColliderId%) = CopyEntity(CubeCollider)
    ScaleEntity(Collider(ColliderId%),TempWidth%+2,TempHeight%+1,TempDepth%+2)
    RotateEntity(Collider(ColliderId%),TempPitch#,TempYaw#,TempRoll#)
    PositionEntity(Collider(ColliderId%),TempX#,TempY#,TempZ#)
    MoveEntity(Collider(ColliderId%),-1.0,0,-1.0)
    EntityColor(Collider(ColliderId%),Rand(125,255),Rand(125,255),Rand(125,255))

    ;Print("Creates, scales, positions, rotates the TempNodePositioner.")
    TempNodePositionerCube = CopyEntity(NodePositionerCube)
    ScaleEntity(TempNodePositionerCube,TempWidth%+2,1.0,TempDepth%+2)
    RotateEntity(TempNodePositionerCube,TempPitch#,TempYaw#,TempRoll#)
    PositionEntity(TempNodePositionerCube,TempX#,TempY#,TempZ#)
    MoveEntity(TempNodePositionerCube,-1.0,0,-1.0)
    EntityColor(TempNodePositionerCube,255,255,255)

    ;Print("Creates the final Nodes.")
    For SI% = 1 To CountSurfaces(TempNodePositionerCube)
     SP% = GetSurface(TempNodePositionerCube,SI%)
     For VI% = 0 To CountVertices(SP%)-1     
      ;VX# = VertexX(SP%,VI%)
      ;VY# = VertexY(SP%,VI%)
      ;VZ# = VertexZ(SP%,VI%)
      TFormPoint(VertexX(SP%,VI%),VertexY(SP%,VI%),VertexZ(SP%,VI%),TempNodePositionerCube,0)
      VX# = TFormedX()
      VY# = TFormedY()
      VZ# = TFormedZ()
      NodesTotalCount% = NodesTotalCount% + 1     
      NodeX# = VX#
      NodeY# = VY#
      NodeZ# = VZ#               
      NodesCount%(BuildingId%) = NodesCount%(BuildingId%) + 1
      NodeId% = NodesCount%(BuildingId%)
      NodePivot(BuildingId%,NodeId%) = CreatePivot()
      PositionEntity(NodePivot(BuildingId%,NodeId%),NodeX#,NodeY#,NodeZ#)
      If(DebugMode% = 1)
       NodeMesh(BuildingId%,NodeId%) = CopyEntity(NodeXMesh) 
       PositionEntity(NodeMesh(BuildingId%,NodeId%),EntityX(NodePivot(BuildingId%,NodeId%),True),EntityY(NodePivot(BuildingId%,NodeId%),True),EntityZ(NodePivot(BuildingId%,NodeId%),True))
       EntityParent(NodeMesh(BuildingId%,NodeId%),NodePivot(BuildingId%,NodeId%),True)
      EndIf
     Next
    Next   

    ;Print("Deletes the TempNodePositioner.")
    FreeEntity(TempNodePositionerCube)   
   ElseIf(TempKind% = ApartmentPrism%)

   ElseIf(TempKind% = ApartmentCylinder%)

   EndIf
  ElseIf(CollisionsCount% > 0)
   ;Print("The TempCollider collides with one of the existing Colliders.")
   ;Checks if the OrientationTries is less than 100.
;   If(RandomOrientationTries% < 1000)
;    ;Tries to define another orientation.
;    RandomOrientationTries% = RandomOrientationTries% + 1
;    Print("RandomOrientationTries% : "+RandomOrientationTries%)
;    Goto LineRandomOrientation
;   Else
;    ;Checks if the ScaleTries is less than 100.
;    If(RandomScaleTries% <= 10)
;     ;Tries to define another scale.
;     RandomScaleTries% = RandomScaleTries% + 1
;     Print("RandomScaleTries% : "+RandomScaleTries%)
;     Goto LineRandomScale
;    Else
;     ;Checks if the PositionTries is less than 100.
;     If(RandomPositionTries% <= 10)
;      ;Tries to define another position.
;      RandomPositionTries% = RandomPositionTries% + 1
;      Print("RandomPositionTries% : "+RandomPositionTries%)
;      Goto LineRandomPosition
;     EndIf
;    EndIf
;   EndIf
  EndIf   
;  Until(BuildingsCount% = 3)
  ;Print("Creates the SNodeMesh for debug.")
  If(DebugMode% = 1)
   SNodesCount% = SNodesCount% + 1
   SNodeId% = SNodesCount%
   SNodeMesh = CopyEntity(SNodeXMesh)   
   PositionEntity(SNodeMesh,SNodeX#,SNodeY#+1.7,SNodeZ#)
   SNodeTexture = CreateTexture(32,32)
   SetBuffer(TextureBuffer(SNodeTexture))
    ClsColor(000,000,000)
    Cls   
    StringX$ = Str(SNodeId%)
    StringXWidth% = StringWidth(StringX$)
    StringXHeight% = StringHeight(StringX$)
    TextureXWidth% = TextureWidth(SNodeTexture)
    TextureXHeight% = TextureHeight(SNodeTexture)
    PX% = (TextureXWidth%/2) - (StringXWidth%/2)
    PY % = (TextureXHeight%/2) - (StringXHeight%/2)
    Color(255,255,255)
    Text(PX%,PY%,StringX$)
   SetBuffer(BackBuffer()) 
   EntityTexture(SNodeMesh,SNodeTexture)
  EndIf
 EndIf
EndIf

End Function

Function AddGhost()
 
 GhostRoot = CreatePivot()

 GhostEyes = CreatePivot()
 EntityParent(GhostEyes,GhostRoot,True)

End Function

Function UpdateGhost()

 MoveMouse(GraphicsWidth()/2,GraphicsHeight()/2)
 GhostEyesPitch = GhostEyesPitch + Float(MYDiff)/10
 If( GhostEyesPitch < -89 )
  GhostEyesPitch = -89
 Else If( GhostEyesPitch > 89 )
  GhostEyesPitch = 89
 EndIf
 RotateEntity(GhostEyes,GhostEyesPitch,0,0,False)
 GhostRootYaw = GhostRootYaw - Float(MXDiff)/10
 RotateEntity(GhostRoot,0,GhostRootYaw,0,False)

 If( KeyDown(42) = 0 And KeyDown(29) = 0 )
  Speed# = 0.1
 Else If( KeyDown(42) = 1 And KeyDown(29) = 0 )
  Speed# = 1
 Else If( KeyDown(42) = 0 And KeyDown(29) = 1 )
  Speed# = 0.01
 EndIf

 If( KeyDown(17)=1 )
  MoveEntity(GhostRoot,0,0,Speed)
 Else If( KeyDown(31)=1 )
  MoveEntity(GhostRoot,0,0,-Speed)
 EndIf
 If( KeyDown(30)=1 )
  MoveEntity(GhostRoot,-Speed,0,0)
 Else If( KeyDown(32)=1 )
  MoveEntity(GhostRoot,Speed,0,0)
 EndIf
 If( KeyDown(16)=1 )
  MoveEntity(GhostRoot,0,-Speed,0)
 Else If( KeyDown(18)=1 )
  MoveEntity(GhostRoot,0,Speed,0)
 EndIf
 
End Function

DualCore AMD E-450, 1646 MHz - 6 Go DDR3 1333 SDRAM - AMD Radeon HD 6320 Graphics (384 Mo) - Windows 7 Home Premium - DirectX 11.0

Offline Matty

Re: old bb code : city buildings generator (2012.09.27)
« Reply #1 on: December 20, 2020, 11:53:04 AM »
That looks nice
I eat cheese in the trees when its eight degrees

Offline DruggedBunny

Re: old bb code : city buildings generator (2012.09.27)
« Reply #2 on: December 20, 2020, 09:34:32 PM »
Nice results!

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal