Question Usage to set multiple GRP_EDIT flags?

Thunder Chicken

Resident Lua Script Rabble-Rouser
Donator
Joined
Mar 22, 2008
Messages
5,847
Reaction score
5,509
Points
188
Location
Massachusetts
So I am tinkering with a simple flag mesh to see how the positions of the vertices can be manipulated.


So I am trying to prepare the group edit spec to do this. I need to set flags to replace the X, Y, Z coordinates of the vertices, and maybe the normals.

This is what I have so far, but I am not sure of the syntax to set multiple flags. There are some C++ API examples, but that doesn't really help with Lua syntax issues:

Code:
function clbk_visualcreated(vis, refcount)

    hdevmesh0 = vi:get_devmesh(vis,0)

    local nvtx = 56
    local vtx = oapi.create_ntvertexarray(nvtx)
    local index_array = {}

    for i = 1, nvtx do
        index_array[i]=i-1
    end

    local vidx = oapi.create_indexarray(index_array)

    --create group edit spec (ges)

    ges = {}
    ges.flags = GRP_EDIT.VTXCRDX, GRP_EDIT.VTXCRDY, GRP_EDIT.VTXCRDZ --??
    ges.vIdx = vidx
    ges.Vtx = vtx

end

EDIT: The above syntax fails, with an error stating GRP_EDIT is an undefined global, but that is how the type is presented in the Orbiter Lua script interface documentation?
GRP_EDIT Mesh group edit flags
The only two examples of GRP_EDIT usage in the code base are in the documentation in types.lua and Interpreter.cpp. [/EDIT]

If I can get this to work I think I can then manipulate the coordinates using something like this:

Code:
if ges ~= nil then

    for i = 1, #index_array do
   
        ges.Vtx[i].x = *some wacky function*
        ges.Vtx[i].y = *some wacky function*
        ges.Vtx[i].z = *some wacky function*
       
    end

    oapi.edit_meshgroup(hdevmesh0, 0, ges)
    oapi.edit_meshgroup(hdevmesh0, 1, ges)

end

I think I might also have to manually update the normals as well (ges.Vtx.nx, ges.Vtx.ny, ges.Vtx.nz), but one thing at a time.

So how do I set multiple GRP_EDIT flags?
 
Last edited:
OK, so I have learned some things from my trip down the rabbit hole:

1. The syntax for the type in Lua is GRPEDIT, not GRP_EDIT as stated in the docs. GRP_EDIT is the C++ API syntax.

2. Figuring that out and searching GitHub for GRPEDIT flags in Lua scripts, I found that the syntax to add multiple flags is simply an addition sign, for example:

Code:
ges.flags = GRPEDIT.VTXCRDX + GRPEDIT.VTXCRDY + GRPEDIT.VTXCRDZ

3. ges.Vtx does not hold any information about the mesh - it apparently is just a template for the mesh parameters to be changed. Which means you can't use them in geometry formulas. If you need to calculate something based on a mesh value, you need to provide that mesh information manually, so far as I can see. I'd like to see if I can get mesh information (x,y,z, nx, ny,nz, tu, tv) from Orbiter in some way.

4. Once you set a flag, it seems that you must update the mesh parameter delineated by that flag. Skipping actually editing the mesh spec doesn't seem to be permitted.

But, once I figured all that out...victory!

Flag_Waving.gif
 
Back
Top