Last active
October 20, 2020 23:20
-
-
Save x4fx77x4f/742e251dad5d01acf20141ca8037dc71 to your computer and use it in GitHub Desktop.
Realtime mesh demo in StarfallEx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--@client | |
--@include libs/fh_lube.lua | |
require("libs/fh_lube.lua")(function() | |
local math_cos = math.cos | |
local math_sin = math.sin | |
local mesh_advanceVertex = mesh.advanceVertex | |
local mesh_generate = mesh.generate | |
local mesh_writeColor = mesh.writeColor | |
local mesh_writePosition = mesh.writePosition | |
local mesh_writeUV = mesh.writeUV | |
local render_drawPoly = render.drawPoly | |
local render_popMatrix = render.popMatrix | |
local render_pushMatrix = render.pushMatrix | |
local render_setBackgroundColor = render.setBackgroundColor | |
local render_setMaterial = render.setMaterial | |
local render_selectRenderTarget = render.selectRenderTarget | |
local render_setRenderTargetTexture = render.setRenderTargetTexture | |
local render_setRGBA = render.setRGBA | |
local timer_systime = timer.systime | |
local Vector = Vector | |
render.createRenderTarget("main") | |
local wireframe = material.load("models/wireframe") | |
local bg = Color(127, 127, 127) | |
local zm = 20 | |
local zo = 50 | |
local ship = { | |
{x=0, y=-0.5}, | |
{x=0.3, y=0.5}, | |
{x=0, y=0.3}, | |
{x=-0.3, y=0.5} | |
} | |
local shipMtx = Matrix() | |
shipMtx:setScale(Vector(128, 128)) | |
local shipPos = Vector(512, 512) | |
shipMtx:setTranslation(shipPos) | |
local function generator() | |
local now = timer_systime() | |
for y=0, 9 do | |
local y2 = y/10 | |
local y3 = y2+0.1 | |
local y4 = y2*512 | |
local y5 = y3*512 | |
for x=0, 9 do | |
local x2 = x/10 | |
local x3 = x2+0.1 | |
local x4 = x2*512 | |
local x5 = x3*512 | |
local tr = Vector(x5, y4, (math_sin(x+1+now)+math_cos(y+now))*zm+zo) | |
local bl = Vector(x4, y5, (math_sin(x+now)+math_cos(y+1+now))*zm+zo) | |
mesh_writeColor(255, 255, 255, 255) | |
mesh_writePosition(Vector(x4, y4, (math_sin(x+now)+math_cos(y+now))*zm+zo)) | |
mesh_writeUV(0, x2, y2) | |
mesh_advanceVertex() | |
mesh_writeColor(255, 255, 255, 255) | |
mesh_writePosition(tr) | |
mesh_writeUV(0, x3, y2) | |
mesh_advanceVertex() | |
mesh_writeColor(255, 255, 255, 255) | |
mesh_writePosition(bl) | |
mesh_writeUV(0, x2, y3) | |
mesh_advanceVertex() | |
mesh_writeColor(255, 255, 255, 255) | |
mesh_writePosition(bl) | |
mesh_writeUV(0, x2, y3) | |
mesh_advanceVertex() | |
mesh_writeColor(255, 255, 255, 255) | |
mesh_writePosition(tr) | |
mesh_writeUV(0, x3, y2) | |
mesh_advanceVertex() | |
mesh_writeColor(255, 255, 255, 255) | |
mesh_writePosition(Vector(x5, y5, (math_sin(x+1+now)+math_cos(y+1+now))*zm+zo)) | |
mesh_writeUV(0, x3, y3) | |
mesh_advanceVertex() | |
end | |
end | |
end | |
hook.add("render", "render", function() | |
render_setBackgroundColor(bg) | |
render_setRGBA(255, 255, 255, 255) | |
render_selectRenderTarget("main") | |
render_setMaterial(wireframe) | |
render_pushMatrix(shipMtx) | |
render_drawPoly(ship) | |
render_popMatrix() | |
render_selectRenderTarget() | |
render_setRenderTargetTexture("main") | |
mesh_generate(nil, 2, 200, generator) | |
end) | |
end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment