Jump to content

Trail using triangle strip and a vbo


shadmar
 Share

Recommended Posts

It works but seem to render only every other frame.

Maybe someone can figure it out:

 

function Script:Start()
  	 --make a vertex buffer
       vbo = { }
       maxvbo = 100

       mat=Material:Create()
       mat:SetBackFaceCullMode(false)

       --fill it with nonsense positions
       local pos=self.entity:GetPosition(true)
       for x=1,maxvbo,2 do
          	 --just insert some data
               table.insert(vbo,Vec3(pos.x-.5,pos.y+x,pos.z))
               table.insert(vbo,Vec3(pos.x+.5,pos.y+x,pos.z))
       end

       lasttime=0

       --create a model
       model = Model:Create()
       model:SetOcclusionCullingMode(false)
    model:SetColor(1.0,0.0,1.0)

       --make surface
    local surface = model:AddSurface()

       --add vertices
       for k,v in ipairs(vbo) do
           surface:AddVertex(v.x,v.y,v.z, 0,0,-1)	   
    end

       --make triangle strip
       surface:AddTriangle(2,1,0)
    surface:AddTriangle(0,3,2)
       for x=1,maxvbo-4,2
       do
           surface:AddTriangle(x+3,x+1,x+2)
           surface:AddTriangle(x+2,x+4,x+3)
       end

       surface:Update()
    model:UpdateAABB(Entity.LocalAABB)
    model:UpdateAABB(Entity.GlobalAABB)

       model:SetMaterial(mat)
end


function Script:UpdateWorld()

   if Time:GetCurrent()-20 > lasttime then

       --get positions
       local pos=self.entity:GetPosition(false)

       table.insert(vbo,Vec3(pos.x+.5,pos.y,pos.z))
       table.insert(vbo,Vec3(pos.x-.5,pos.y,pos.z))

       --remove last vertex each loop
       table.remove(vbo,1)
       table.remove(vbo,2)

       lasttime=Time:GetCurrent()

       --ok move all vertices according to vbo

       local surface = model:GetSurface(0)
    for  v=0, surface:CountVertices()-1 do
           surface:SetVertexPosition(v,vbo[v+1])
       end

       surface:Update()
    model:UpdateAABB(Entity.LocalAABB)
    model:UpdateAABB(Entity.GlobalAABB)

   end
end

  • Upvote 1

HP Omen - 16GB - i7 - Nvidia GTX 1060 6GB

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...