home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / CODE_UPLOAD150752162001.psc / AscMod.bas
Encoding:
BASIC Source File  |  2001-02-03  |  6.1 KB  |  277 lines

  1. Attribute VB_Name = "AsciiModule"
  2. Type rCoord
  3.    X As Double
  4.    Y As Double
  5.    z1 As Double
  6.    z2 As Double
  7. End Type
  8.  
  9. Type RkPar
  10.     Mode As Integer
  11.     Tip As Integer
  12.     nv As Integer
  13.     Crd() As rCoord
  14.     Col As Long
  15.     dis As Boolean
  16. End Type
  17.  
  18. Type ASLayer
  19.    nome As String
  20.    nPar As Integer ' Numero Pareti
  21.    Par() As RkPar
  22. End Type
  23.  
  24.  
  25.  
  26.  
  27. Type Coord
  28.   X As Double
  29.   Y As Double
  30.   z As Double
  31. End Type
  32.  
  33. Type Box3D
  34.    xmin As Double
  35.    xmax As Double
  36.    ymin As Double
  37.    ymax As Double
  38.    zmin As Double
  39.    zmax As Double
  40. End Type
  41.  
  42. Const BIG = 1E+30
  43.  
  44. Public DxCTL As Control
  45. Sub LoadPCMFile(File As String)
  46.   
  47.  ' this is my own file structure to generate buildings.
  48.  ' you can use whatever programmable structure you want
  49.  
  50.   
  51.   Dim St As String, X#, Y#, z1#, z2#, Dummy$
  52.   Dim Piani%, Fondazioni%
  53.   Dim PN() As ASLayer
  54.   Dim i%, j%, k%, s%
  55.   Dim Mode%, Tip%, nv%
  56.   Dim Col&, dis%
  57.   Dim Dex$
  58.   
  59.   Dim v() As Coord
  60.   Dim Bx As Box3D
  61.   
  62.   
  63.   
  64. If Len(File) = 0 Then Exit Sub
  65.   
  66.   ReDim Preserve PN(1)
  67.   
  68.   n = FreeFile
  69.   Open File For Input As #n
  70.   Line Input #n, Dummy ' DIMENSIONAMENTI
  71.   Input #n, Piani
  72.   Input #n, i, PN(0).nPar
  73.   
  74.   ReDim Preserve PN(Piani)
  75.   For i = 1 To Piani
  76.         Input #n, j, PN(i).nPar
  77.   Next
  78.   
  79.   
  80.   For i = 0 To Piani
  81.          Line Input #n, nome$  ' PARETInn  (Nome del Layer)
  82.          If i = 0 Then nome = "0"
  83.          
  84.          ReDim PN(i).Par(PN(i).nPar)
  85.          
  86.          For k = 1 To PN(i).nPar
  87.                 Input #n, j, Mode, Tip, nv
  88.                 ReDim PN(i).Par(k).Crd(nv)
  89.                 PN(i).Par(k).nv = nv
  90.                 PN(i).Par(k).Mode = Mode
  91.                 PN(i).Par(k).Tip = Tip
  92.                 
  93.                 For s = 1 To nv
  94.                      Input #n, X, Y, z1, z2
  95.                      PN(i).Par(k).Crd(s).X = X
  96.                      PN(i).Par(k).Crd(s).Y = Y
  97.                      PN(i).Par(k).Crd(s).z1 = z1
  98.                      PN(i).Par(k).Crd(s).z2 = z2
  99.                 Next
  100.                 Input #n, Col, dis
  101.                 PN(i).Par(k).Col = Col
  102.                 PN(i).Par(k).dis = dis
  103.                 
  104.                 ReDim v(nv)
  105.                 Bx = InitBox3D
  106.                 
  107.                 z# = 0
  108.                 For s = 1 To nv
  109.                     v(s).X = PN(i).Par(k).Crd(s).X
  110.                     v(s).Y = PN(i).Par(k).Crd(s).Y
  111.                     v(s).z = PN(i).Par(k).Crd(s).z1
  112.                     z# = Max(PN(i).Par(k).Crd(s).z2, z#)
  113.                     AssignBox3D Bx, v(s)
  114.                 Next
  115.                 
  116.                 cl% = GetQBColor(Col)
  117.               ' here i have all 2D contour, now perform the Dx Extrusion
  118.                 AddExtrusion v, nv, z, 0, 0, 0, cl
  119.    
  120.          Next
  121.   
  122.   Next
  123.   
  124.   
  125.  
  126. End Sub
  127.  
  128. Function Max(v1 As Double, v2 As Double) As Double
  129.   If v1 > v2 Then Max = v1 Else Max = v2
  130. End Function
  131.  
  132. Function Min(v1 As Double, v2 As Double) As Double
  133.   If v1 < v2 Then Min = v1 Else Min = v2
  134. End Function
  135.  
  136. Sub AssignBox3D(b As Box3D, P As Coord)
  137.    
  138.     With P
  139.        If .X < b.xmin Then b.xmin = .X
  140.        If .Y < b.ymin Then b.ymin = .Y
  141.        If .z < b.zmin Then b.zmin = .z
  142.        
  143.        If .X > b.xmax Then b.xmax = .X
  144.        If .Y > b.ymax Then b.ymax = .Y
  145.        If .z > b.zmax Then b.zmax = .z
  146.    End With
  147.    
  148. End Sub
  149.  
  150. Sub AddExtrusion(v() As Coord, nv As Integer, Height#, X#, Y#, z#, Color%)
  151.     
  152. '  might be better doing a single frame then add all meshes to it
  153. '  or a root frame with its tree with frames/meshes
  154. '  now.. for clarity i use a frame by mesh
  155. With DxCTL
  156.          FName$ = "F-" & .GenerateHandle
  157.          mName$ = "M-" & .GenerateHandle
  158.         
  159.         .newFrame FName
  160.         .xMesh.Init
  161.          For i% = 1 To nv
  162.             .xMesh.AddProfileVertex CSng(v(i).X), CSng(v(i).Y)
  163.          Next
  164.          .xMesh.Extrude CSng(Height)
  165.         
  166.         .AddUserMesh FName, mName, .xMesh.ResolveMesh
  167.         .xMesh.Init
  168.         If v(1).z <> 0 Then .Frame_Translate FName, 0, CSng(v(1).z), 0
  169.         .Mesh_AddMaterial mName, 0, QBColor(Color), QBColor(Color), QBColor(0), 1
  170. '&H6FC0C0C0
  171.       '  .Mesh_AddTexture mName, 0, "c:\banana.bmp"
  172. End With
  173.     
  174. End Sub
  175.  
  176.  
  177. Function GetQBColor(Rg As Long) As Integer
  178. Dim c As Integer
  179.  
  180. ' Riottiene il codice QBColor dal Long RGB corrispondente
  181.  
  182. c = -1
  183.  
  184. Select Case Rg
  185.      Case 0: c = 0
  186.      Case 8388608: c = 1
  187.      Case 32768: c = 2
  188.      Case 8421376: c = 3
  189.      Case 128: c = 4
  190.      Case 8388736: c = 5
  191.      Case 32896: c = 6
  192.      Case 12632256: c = 7
  193.      Case 8421504: c = 8
  194.      Case 16711680: c = 9
  195.      Case 65280: c = 10
  196.      Case 16776960: c = 11
  197.      Case 255: c = 12
  198.      Case 16711935: c = 13
  199.      Case 65535: c = 14
  200.      Case 16777215: c = 15
  201.      Case Else
  202.         c = 0    ' nel caso non sia un Long Generato da QBColor restituisce "Nero"
  203. End Select
  204.  
  205.  GetQBColor = c
  206.     
  207.  
  208. End Function
  209.  
  210.  
  211. Function QBColor2Plastica(Color As Integer) As Integer
  212.  
  213. ' VB QbColor            Plastica
  214. ' =============         ===========
  215. '0   Nero                  8
  216. '1   Blu                   4
  217. '2   Verde                 3
  218. '3   Azzurro               9
  219. '4   Rosso                 2
  220. '5   Fucsia                7
  221. '6   Giallo                5
  222. '7   Bianco                33
  223. '8   Grigio                21
  224. '9   Blu chiaro            32
  225. '10  Verde limone          28
  226. '11  Azzurro chiaro        70
  227. '12  Rosso chiaro          30
  228. '13  Fucsia chiaro         31
  229. '14  Giallo chiaro         69
  230. '15  Bianco brillante      1
  231.  
  232. Dim Rt%
  233. Select Case Color
  234.     Case 0: Rt = 8
  235.     Case 1: Rt = 4
  236.     Case 2: Rt = 3
  237.     Case 3: Rt = 9
  238.     Case 4: Rt = 2
  239.     Case 5: Rt = 7
  240.     Case 6: Rt = 5
  241.     Case 7: Rt = 33
  242.     Case 8: Rt = 21
  243.     Case 9: Rt = 32
  244.     Case 10: Rt = 28
  245.     Case 11: Rt = 70
  246.     Case 12: Rt = 30
  247.     Case 13: Rt = 31
  248.     Case 14: Rt = 69
  249.     Case 15: Rt = 1
  250.     Case Else
  251.       Rt = 1
  252. End Select
  253.  
  254.  
  255. QBColor2Plastica = Rt
  256.  
  257. End Function
  258.  
  259.  
  260. Function InitBox3D() As Box3D
  261.  
  262.  With InitBox3D
  263.    
  264.    .xmin = BIG
  265.    .ymin = BIG
  266.    .zmin = BIG
  267.    
  268.    .xmax = -BIG
  269.    .ymax = -BIG
  270.    .zmax = -BIG
  271.  
  272.  End With
  273.  
  274.  
  275. End Function
  276.  
  277.