I am flailing away at a J-3 add-on, and one of the things I want to do is shift the UV coordinates of a texture to animate a switch toggle on the panel.
Here is where I started: https://www.orbiter-forum.com/threa...ntures-and-questions.41799/page-3#post-619969.
This image shows the 1024 x 512 pixel texture associated with the instrument panel. The panel showing the OFF position is the upper half with UV coordinates from (0,0) to (1,0.5). To show the switch in the ON position, I need to change the UV coordinates to the lower half of the texture, coordinates (0,0.5) to (1,1). Only the V coordinate needs to be modified.
![j-3_panel_switches.png j-3_panel_switches.png](https://cdn.orbiter-forum.com/data/attachments/38/38893-1e3a8115a6d7f61a221d625b447adad3.jpg)
This texture is associated with the following meshgroup (23) in my mesh:
The UV coordinates (last two digits on each vertex entry) are set to show the upper portion of the texture on the panel.
The question is how to get and edit the meshgroup to change the V coordinates so the bottom half of the texture is shown.
I am trying to figure out how to implement oapi.get_meshgroup and oapi.set_meshgroup to do this. I am rummaging around the Orbiter code and have some snippets, but certain things are not working and I am not seeing why.
First thing I am trying to do is access the current vertex information in the mesh. From what I gathered looking through the code, I need to specify the number of vertices (4), and allocate vertex and index arrays. From there, I need to create a group mesh spec structure (grs), and I thought that running get_meshgroup would populate that structure with the data. This is the code I have for that so far.
This gives me the following error for the last line: bad argument #1 to 'get_meshgroup' (DEVMESHHANDLE expected, got userdata).
OK, some reading into the API_Reference.pdf, there is this to get the DEVMESHHANDLE mesh instance:
There does appear to be a Lua equivalent v:get_devmesh(vis, idx) to do this. idx is 0 as there is only one mesh file, but I can't make sense of how to reference the "visual" vis (or even know what it is), and there is no further description of what vis is in the API_Reference.pdf or that I can find rummaging around in the code.
I'm sure I'll have more questions on how to edit the group spec to have the two specs needed to toggle the UV coordinates, but let's start with what I have above. Has anyone done this in Lua and does anyone see where I am going amiss?
Thanks again for your help.
Here is where I started: https://www.orbiter-forum.com/threa...ntures-and-questions.41799/page-3#post-619969.
This image shows the 1024 x 512 pixel texture associated with the instrument panel. The panel showing the OFF position is the upper half with UV coordinates from (0,0) to (1,0.5). To show the switch in the ON position, I need to change the UV coordinates to the lower half of the texture, coordinates (0,0.5) to (1,1). Only the V coordinate needs to be modified.
![j-3_panel_switches.png j-3_panel_switches.png](https://cdn.orbiter-forum.com/data/attachments/38/38893-1e3a8115a6d7f61a221d625b447adad3.jpg)
This texture is associated with the following meshgroup (23) in my mesh:
Code:
LABEL Instrument_Panel
MATERIAL 7
TEXTURE 1
GEOM 4 2
-0.358 0.102 0.895 0 0 -1 0 0.5
0.358 0.102 0.895 0 0 -1 1 0.5
0.102 0.256 0.895 0 0 -1 0.6425 0
-0.102 0.256 0.895 0 0 -1 0.3575 0
0 3 1
3 2 1
The UV coordinates (last two digits on each vertex entry) are set to show the upper portion of the texture on the panel.
The question is how to get and edit the meshgroup to change the V coordinates so the bottom half of the texture is shown.
I am trying to figure out how to implement oapi.get_meshgroup and oapi.set_meshgroup to do this. I am rummaging around the Orbiter code and have some snippets, but certain things are not working and I am not seeing why.
First thing I am trying to do is access the current vertex information in the mesh. From what I gathered looking through the code, I need to specify the number of vertices (4), and allocate vertex and index arrays. From there, I need to create a group mesh spec structure (grs), and I thought that running get_meshgroup would populate that structure with the data. This is the code I have for that so far.
Code:
--Load mesh and set visibility
hmesh = oapi.load_mesh_global('J-3/J-3')
vi:add_mesh(hmesh)
vi:set_mesh_visibility_mode(0, MESHVIS.ALWAYS)
--Get mesh group spec for instrument panel group 23
nvtx = 4
vtx = oapi.create_ntvertexarray(nvtx)
vperm = oapi.create_indexarray(nvtx)
grs = {}
grs.Vtx = vtx
grs.VtxPerm = vperm
oapi.get_meshgroup(hmesh, 23, grs) --get mesh group spec for instrument panel with switch OFF
This gives me the following error for the last line: bad argument #1 to 'get_meshgroup' (DEVMESHHANDLE expected, got userdata).
OK, some reading into the API_Reference.pdf, there is this to get the DEVMESHHANDLE mesh instance:
DEVMESHHANDLE VESSEL::GetDevMesh ( VISHANDLE vis, UINT idx ) const
Returns a handle for a device-specific mesh instance.
Parameters
vis identifies the visual for which the mesh was created.
idx mesh index (0 <= idx < GetMeshCount()
There does appear to be a Lua equivalent v:get_devmesh(vis, idx) to do this. idx is 0 as there is only one mesh file, but I can't make sense of how to reference the "visual" vis (or even know what it is), and there is no further description of what vis is in the API_Reference.pdf or that I can find rummaging around in the code.
I'm sure I'll have more questions on how to edit the group spec to have the two specs needed to toggle the UV coordinates, but let's start with what I have above. Has anyone done this in Lua and does anyone see where I am going amiss?
Thanks again for your help.
Last edited: