Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Question about a certain mesh I am trying to generate

edited February 2017 in Questions Posts: 26

Say I had a bunch of meshes, and all of the meshes' vertices were stored on a table. How would I generate a mesh, from those vertices, that takes up the entire screen, except for the area of the meshes whose vertices I am generating it from. In other words I need to generate a mesh that takes up the area that a bunch of meshes aren't taking up. Could I have help finding a way to do this?


  • dave1707dave1707 Mod
    Posts: 9,733

    @PlatinumFrog Are the meshes you want to create connected to each other or are they just scattered around the screen. Could you create a mesh that covers the whole screen and the other meshes just overlay the full screen mesh.

  • Posts: 2,020

    It sounds to me like you're describing a mesh covering the entire screen, but with a bunch of holes in it, is that correct? If so, that's hard. Codea's triangulate function can't handle areas with holes in them. We need more context though, what are you going to use this for? What have you tried so far?

  • edited February 2017 Posts: 26

    My meshes are scattered around the screen and they are overlapping too which presents another problem. I am describing a mesh covering the entire screen but with a bunch of holes it. I am attempting to create a lighting system for a game I am making, and I want to create a sort of global shadow, because simply tinting a sprite with a dark color and then making it bright again by puting a light mesh over it and setting the blend mode to additive degrades the image, and so does making a dark semi-transparent rectangle cover the entire screen. I also want everything to be completely dark when not by a light source so tinting anything completely black would make the sprite invisable in the light, and making it sort of dark would make the sprite visable in the dark. Making a dark mesh with holes for the lights would fix these problems. Here is an example of how I draw these lights:

    function setup()
        -- Adding a light is as simple as adding a table with its parameters to the "light" table.
        light = {
            l1 = {
                m = mesh(),
                t = "circle",
                c=color(226, 216, 114, 76)
    function lCir(light,x,y,w,h,d,s,c)
        local lphv = {}
        local lphc = {}
    --The #vertices in that should be in the mesh should be equal to the number of sides*3 therefore by only adding triangles the the table when #vertices is <= 0 makes the table less infinite.
        if #light.vertices <= s*3 then
            for i = 1,d,d/s do
                local v = i + (d/s)
                table.insert(lphv, vec2(math.cos(math.rad(i))*(w/2)+x, math.sin(math.rad(i))*(h/2)+y))
                table.insert(lphv, vec2(math.cos(math.rad(v))*(w/2)+x, math.sin(math.rad(v))*(h/2)+y))
                table.insert(lphv, vec2(x,y))
                table.insert(lphc, c)
        light.vertices = lphv
        light.colors = lphc
    function draw()
    --I have other types of lights not included in this example which is the reason for identifying what v.t is
    for k,v in pairs(light) do
            if v.t == "circle" then
  • I have tried to collect all vertices from every light into a table, sorting the table, and then draw that as a mesh. I tried sorting it in a way that would delete every vector that was the same as any other one, but that didn't work. I tried to not sort the table at all, which gave me the same result you would expect when adding four vectors to the vertices table and being disappointed when it doesn't draw a rectangle.

  • Posts: 2,020

    I'm still not entirely sure what effect you're after (this kind of thing is sometimes easier to explain with images). If the lights are moving, creating lots of geometry would be expensive. A better approach might be a shader like the one @Ignatz describes here:

    The above example has 3 lights, you'd need to modify it if you wanted more.

    If the lights are static, you could rasterize the output from the above shader for better performance.

Sign In or Register to comment.