December 03, 2021, 00:14:16

Author Topic: [bb] Mesh builder by puki [ 1+ years ago ]  (Read 1815 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] Mesh builder by puki [ 1+ years ago ]
« on: June 29, 2017, 00:28:43 »
Title : Mesh builder
Author : puki
Posted : 1+ years ago

Description : Just something I knocked up while playing with the vertex stuff in Blitz3D.

Not sure how efficient it is - but it's small and cute.

Actually, I think the code is duff - seems to me like I am creating far too many vertices. So, I'll have to look at it later and rewrite it.

Code :
Code: BlitzBasic
  1. ; mesh builder by "puki" - 24/10/04
  3. Graphics3D 640,480,16,2
  4. SetBuffer BackBuffer()
  6. cam = CreateCamera()
  7. MoveEntity cam, 0,0,-5
  9. WireFrame 1
  11. mesh = CreateMesh()
  12. surface=CreateSurface(mesh)
  14. ; here we set the size of the mesh (in squares)
  15. ; both values must each be at least 1 - they do not have to be matching values
  16. mwidth=8
  17. mheight=6
  19. ; there will only be 4 vertices per square - 0 to 3
  20. ; we re-use the array cells repeatedly to save memory
  21. Dim vert_no(3)
  23. ; the following code draws each section of the mesh from left to right
  24. ; then it starts a new row below the first and again works along left to right
  25. For height=1 To mheight
  26.         For width=1 To mwidth
  27.                         vert_no(0)=AddVertex(surface,curx,cury-1,curz)
  28.                         vert_no(1)=AddVertex(surface,curx,cury,curz)
  29.                         vert_no(2)=AddVertex(surface,curx+1,cury,curz)
  30.                         vert_no(3)=AddVertex(surface,curx+1,cury-1,curz)
  32.                         tri1=AddTriangle(surface,vert_no(0),vert_no(1),vert_no(2))
  33.                         tri2=AddTriangle(surface,vert_no(0),vert_no(2),vert_no(3))
  34.                         curx=curx+1
  35.         Next
  36.         curx=0
  37.         cury=cury-1
  38. Next
  40. UpdateNormals mesh
  41. PositionMesh mesh,-4,3,0
  43. While Not KeyHit(1)
  44. RenderWorld
  45. Flip
  46. Wend
  47. End

Comments :

puki(Posted 1+ years ago)

 EDIT - well, almost there - the vertices are under control - but they are still produced 4x each square - need to modify this.  Other than that, the sucker is okayish.EDIT:Just to save my botty over creating this code archive.Here's one I have found from 2 years ago!:Mesh Plane by "Neo Genesis10"<a href="codearcs18ed.html?code=382" target="_blank">[/url]This nullifies mine.I was going to redo mine to be more efficient, but it will probably end up like "Neo Genesis10's".  I think mine is cuter - I like the fact that mine wasn't using an array in the same way.I was never going to use vertex coords though - I was just going to modify progressive squares to use the right-hand vertices of the preceding square.  Which would bring my vertex count down to optimal.

aab(Posted 1+ years ago)

 Good Luck

puki(Posted 1+ years ago)

 Mine' will never work without making the code bigger.  I optimised it (although the above code has not been amended) and this works 100% for the rows running left to right.  However, when adding a new row, the top left and top right vertices are always repeated - there is no way around it other than using an array or, perhaps, types.  It can be modified to work, it is just the code will be twice the size.Another solution is to do the mesh as a 'spread' from vertex 0,0 by processing the rows and columns together (at the same time).  However, the only gain of this would be keeping the initial array small.I'm just glad I found 'Mesh Plane' by "Neo Genesis10"

Ross C(Posted 1+ years ago)

 I don't know if this will help you or not, but you don't need to store the vertexs in an array or anything. Each vertex is given an index number anyway, and if you build the mesh using loops, you can easily find which vertex your looking for :o)

Ziltch(Posted 1+ years ago)

 I wrote a CreateSquare function that uses less Vertices.  It is in the Codes Archives. If you are interested !It does use more code.

puki(Posted 1+ years ago)

 I found it "Ziltch"<a href="codearcs6ac4.html?code=463" target="_blank">[/url]
Code: [Select]
; Top bit added by puki (for demonstration purposes) - 1/11/04
Graphics3D 640,480,16,2

PositionEntity cam,0,0,2

; set the size of Ziltch's square, now use it as a normal entity
; so, as Ziltch said, it is scaleable.

PointEntity cam,ground

While KeyHit(1)=0

TurnEntity ground,1,0,0




Function createsquare(segs#=2,parent=0)
; by ADAmor Ziltch. Oct 2002
; v2 Feb 2003
;v3  may 2003 fixed rounding bug

    mesh=CreateMesh( parent )
    surf=CreateSurface( mesh )

    l# =-.5
    b# = -.5
    tvc= 0

    ;create all the vertices first
      u# = l + .5
      v# = b + .5
      AddVertex surf,l,0,b,u,1-v
      tvc=tvc + 1
      l = l + 1/segs
      If l > .501 Then
        l = -.5
        b = b + 1/segs
      End If
    Until b > .5

    ;create polys
    vc# =0

      AddTriangle (surf,vc,vc+segs+1,vc+segs+2)
      AddTriangle (surf,vc,vc+segs+2,vc+1)

      vc = vc + 1
      tst# =  ((vc+1) /(segs+1)) -Floor ((vc+1) /(segs+1))

      If (vc > 0) And (tst=0) Then
        vc = vc + 1
      End If

    Until vc=>tvc-segs-2
    UpdateNormals mesh
    Return mesh

End Function


SimplePortal 2.3.6 © 2008-2014, SimplePortal