November 28, 2020, 01:22:14 PM

Author Topic: [bb] Lightwave3d Exporter by starfox [ 1+ years ago ]  (Read 525 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] Lightwave3d Exporter by starfox [ 1+ years ago ]
« on: June 29, 2017, 12:28:42 AM »
Title : Lightwave3d Exporter
Author : starfox
Posted : 1+ years ago

Description : This supports multiple surfaces and upto 65535 vertices, and uvmapping. All is needed is credit.

Code :
Code: BlitzBasic
  1. Function CreateLwoObject(mesh,filename$)
  2. Local vertcount=0
  3. Local tricount=0
  4. Local tempvar=0
  5. For surfe = 1 To CountSurfaces(mesh)
  6. surf = GetSurface(mesh,surfe)
  7. surfsize = surfsize + FindStringLength("Surface "+surfe)
  8. vertcount = vertcount + CountVertices(surf)
  9. tricount = tricount + CountTriangles(surf)
  10. Next
  11. tagsize = surfsize
  12. pointsize = vertcount*12
  13. polysize = tricount*8 + 4;(tricount*2) + 4
  14. ptagsize = tricount*4 + 4
  15. surfsize = surfsize + (CountSurfaces(mesh)*(30))
  16. uvsize = 18+(vertcount*10)
  17. totalsize = 70+pointsize+polysize+ptagsize+surfsize+uvsize+tagsize
  18. w = WriteFile(filename)
  19. writelwostring("FORM",totalsize,w) ;Header
  20. writelwostring("LWO2",0,w)
  21. writelwostring("TAGS",tagsize,w)
  22. For surfe = 1 To CountSurfaces(mesh)
  23.         writelworstring("Surface "+surfe,w)
  24. Next
  25. writelwostring("LAYR",18,w)
  26.         writelwoshort(0,w)
  27.         writelwoshort(0,w)
  28.         writelwopointfloat(0,0,0,w)
  29.         Writelworstring("",w)
  30. writelwostring("PNTS",pointsize,w) ;Point Header
  31. For surfe = 1 To CountSurfaces(mesh)
  32. surf = GetSurface(mesh,surfe)
  33.         For vertindex = 0 To CountVertices(surf)-1
  34.         writelwopointfloat(VertexX(surf,vertindex),VertexY(surf,vertindex),VertexZ(surf,vertindex),w)
  35.         Next
  36. Next
  37. writelwostring("POLS",polysize,w)
  38.         writelwostring("FACE",0,w)
  39. For surfe = 1 To CountSurfaces(mesh)
  40. surf = GetSurface(mesh,surfe)
  41.         For index = 0 To CountTriangles(surf)-1
  42.         writelwoshort(3,w)
  43.         in1 = TriangleVertex(surf,index,0):in2 = TriangleVertex(surf,index,1)
  44.         in3 = TriangleVertex(surf,index,2)
  45.         in1 = findvertindex(in1,surf,mesh)
  46.         in2 = findvertindex(in2,surf,mesh)
  47.         in3 = findvertindex(in3,surf,mesh)
  48.         writelwoshort(in1,w):writelwoshort(in2,w):writelwoshort(in3,w)
  49.         Next
  50. Next
  51. tempvar = 0
  52. writelwostring("PTAG",ptagsize,w)
  53.         writelwostring("SURF",0,w)
  54. For surfe = 1 To CountSurfaces(mesh)
  55. surf = GetSurface(mesh,surfe)
  56.         For vertindex = 0 To CountTriangles(surf)-1
  57.         writelwoshort(tempvar,w):writelwoshort(surfe-1,w)
  58.         tempvar = tempvar + 1
  59.         Next
  60. Next
  61.  
  62. For surfe = 1 To CountSurfaces(mesh)
  63. length = findstringlength("Surface "+surfe)+22
  64. writelwostring("SURF",length,w)
  65.         writelworstring("Surface "+surfe,w)
  66.         Writelworstring("",w)
  67.         writelwostring("COLR",0,w):writelwoshort(14,w)
  68.                 writelwopointfloat(Rnd(1),Rnd(1),Rnd(1),w)
  69.                 Writelwoshort(0,w)
  70. Next
  71. writelwostring("VMAP",uvsize,w)
  72.         writelwostring("TXUV",0,w)
  73.         writelwoshort(2,w)
  74.         writelworstring("UV Texture",w)
  75.         tempvar = 0
  76. For surfe = 1 To CountSurfaces(mesh)
  77. surf = GetSurface(mesh,surfe)
  78.         For vertindex = 0 To CountVertices(surf)-1
  79.         writelwoshort(tempvar,w)
  80.         writelwofloat(w,VertexU(surf,vertindex))
  81.         writelwofloat(w,1.0-VertexV(surf,vertindex))
  82.         tempvar = tempvar + 1
  83.         Next
  84. Next
  85.  
  86. CloseFile w
  87. End Function
  88.  
  89.  
  90.  
  91. Function WriteLwoString(stri$,size,file)
  92. For e = 1 To Len(stri)
  93. ty$ = Mid(stri,e,1)
  94. val = Asc(ty)
  95. WriteByte(file,val)
  96. Next
  97. If size <> 0
  98. WriteMotorolaInt(size,file)
  99. ;WriteInt(file,size)
  100. EndIf
  101. End Function
  102.  
  103. Function WriteLwoPointFloat(floa#,floa1#,floa2#,file)
  104. WriteLwoFloat(file,floa)
  105. WriteLwoFloat(file,floa1)
  106. WriteLwoFloat(file,floa2)
  107. End Function
  108.  
  109. Function WriteLwoFloat(file,floa#)
  110. bank = CreateBank(4)
  111. PokeFloat(bank, 0, floa) ; write the float value
  112. swapped% = Int_SwapEndian(PeekInt(bank, 0))
  113. FreeBank(bank)
  114. WriteInt(file,swapped)
  115. End Function
  116.  
  117. Function WriteLwoShort(short,file)
  118. WriteByte(file,short Shr 8 And $FF)
  119. WriteByte(file,short And $FF)
  120. ;WriteShort(file,short)
  121. End Function
  122.  
  123. Function FindStringLength(stri$)
  124. size = Len(stri)+1
  125. even = size Mod 2
  126. If even <> 0 Then size = size + 1
  127. Return size
  128. End Function
  129.  
  130. Function FindVertIndex(index,surfi,mesh)
  131. count = 0
  132. For surfe = 1 To CountSurfaces(mesh)
  133. surf = GetSurface(mesh,surfe)
  134.         For vertindex = 0 To CountVertices(surf)-1
  135.         If index = vertindex And surf = surfi Then Return count
  136.         count = count + 1
  137.         Next
  138. Next
  139. End Function
  140.  
  141. Function WriteLwoRString(stri$,file)
  142. For e = 1 To Len(stri)
  143. ty$ = Mid(stri,e,1)
  144. WriteByte(file,Asc(ty))
  145. Next
  146. WriteByte(file,0)
  147. even = (Len(stri)+1) Mod 2
  148. If even <> 0 Then WriteByte(file,0)
  149. End Function
  150.  
  151. Function WriteMotorolaInt(a,w)
  152. WriteByte(w, a Shr 24 And $FF)
  153. WriteByte(w, a Shr 16 And $FF)
  154. WriteByte(w, a Shr 8 And $FF)
  155. WriteByte(w, a And $FF)
  156. End Function
  157.  
  158. Function Int_SwapEndian%(n#)
  159. var = $FF000000
  160. var2 = $FF0000
  161. Return ((n And $FF) Shl 24) Or ((n And $FF00) Shl 8) Or ((n And var2) Shr 8) Or ((n And var) Shr 24)
  162. End Function


Comments :


Litobyte(Posted 1+ years ago)

 Good stuff.


Junkprogger(Posted 1+ years ago)

 Yea, very good! You're in my Credits...


RifRaf(Posted 1+ years ago)

 nice, how much work would it be for this format to include multiple textures per surface, and vertexcoloring ? or does the format support vertexcolor, and vertexalpha ?


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal