Implementing two default MFDs in VC on Lua

I got my MFDs working, but I need to use a separate mesh for them:

Без імені.png

Is it necessary to use a separate mesh for MFD displays? Can't we use a single mesh for external model, VC and MFDs?

Also, can't we see MFD information in external view even if both commands MESHVIS.EXTERNAL and MESHVIS.VC are used for the mesh that contains MFDs?:

Без імені2.png
 
Is it necessary to use a separate mesh for MFD displays? Can't we use a single mesh for external model, VC and MFDs?
Only needs to be a seperate mshgrp. The Thunder fighter I made, extern, intern, VC and instruments are all one single mesh.
 
Thanks. So, I need to find the reason why I can't use two separate meshgroups for MFDs located in a single mesh.
 
It looks I found the reason. It's because of the *.metal map that I'm using for some other meshgroups in a mesh. But what can I do? I can't add a pure black *.rghn map for my MFD meshgroups, since they don't use a texture at all. So, the only way is using a separate mesh (for MFDs) that doesn't include any meshgroups with *.metal maps?
 
It looks I found the reason. It's because of the *.metal map that I'm using for some other meshgroups in a mesh. But what can I do? I can't add a pure black *.rghn map for my MFD meshgroups, since they don't use a texture at all. So, the only way is using a separate mesh (for MFDs) that doesn't include any meshgroups with *.metal maps?
Oh, you might be right! The metal shader is bound to the whole mesh (AFAIK you can activate the shader in two ways; with materials and/or setting a .cfg in the GC folder). Good that you found that, I might have ran into that a little later with the N1 project.
So if a mesh has the metal shader active the MFD shows absoletely nothing?
Having an extra mesh doesn't really bring any negatives. It should be possible to have them visible intern and extern (with the Thunder fighter I had the opposite problem that the MFDs were visible through the hull- still unresolved).
 
I can use a single mesh for external view, VC and MFDs, and I see MFDs in external view, but it requires deleting all *.metal maps:

Без імені.png
 
Also, I tried to use a texture for MFDs with a pure black *.rghn map. It doesn't help. But it still works after deleting all *.metal maps.
 
This seems like a very radical solution. I will try to use a separate mesh for MFDs first.
 
Is it necessary to use a separate mesh for MFD displays? Can't we use a single mesh for external model, VC and MFDs?

Also, can't we see MFD information in external view even if both commands MESHVIS.EXTERNAL and MESHVIS.VC are used for the mesh that contains MFDs?:

We definitively can do this.

The reason to separate the VCs from the 'External' meshes was a performance optimization thing I think. Back in the days (2002) there were still many 'wooden PCs' around. Nowadays... I'd say if you want to render a full 747 cockpit with all the gauges functional then yes, it is probably a good idea to have it as a separate mesh. But for something like a General Aviation monoprop, there should be no issues.
 
Yes, thank you. I've already understood the problem. The reason was *.metal maps. I'll try to use a separate mesh for MFDs and I hope I'll see MFDs displayed in external views.
 
I have a problem. I can't use a single mesh for MFDs and the rest of my mesh, because of the *.metal maps that make MFDs meshgroups invisible, so I use two meshes in my script:
C++:
  -- Mesh

  vi:add_mesh('Cirrus-SR22/Cirrus-SR22(MFDs)')
  vi:set_mesh_visibility_mode(0,bit.bor(MESHVIS.EXTERNAL,MESHVIS.VC))
  vi:add_mesh('Cirrus-SR22/Cirrus-SR22')
  vi:set_mesh_visibility_mode(0,bit.bor(MESHVIS.EXTERNAL,MESHVIS.VC))
The first mesh contains the only left and right MFDs (two squares with UVs). The second one contains the rest.

In the end of the script I define function clbk_loadVC(id):
C++:
function clbk_loadVC(id)

    local mfds =
    {
        pos = _R(0,0,0,0),
        nmesh = 0,
        ngroup = 0,
        flag = 1,
        nbt1 = 6,
        nbt2 = 6,
        bt_yofs = 1024/6,
        bt_ydist = 1024/7
    }
 
    local mfdgrp = {0,1}

  if id == 0 then
    vi:set_cameraoffset({x=-0.49644,y=0.60708,z=1})
    oapi.VC_set_neighbours(-1, 1, -1, 2)
  elseif id == 1 then
    vi:set_cameraoffset({x=0.49644,y=0.60708,z=1})
    oapi.VC_set_neighbours(0, -1, -1, 2)
  elseif id == 2 then
    vi:set_cameraoffset({x=0,y=0.45,z=-1})
    oapi.VC_set_neighbours(-1, -1, 0, -1)
  end

    for i=0, 1 do
        mfds.ngroup = mfdgrp[i + 1]
        oapi.register_mfd(MFDID.LEFT + i, mfds)
    end

  return true
end

In game I see both meshes in external view:

Без імені.png

But in VC view I see the only first mesh (two MFDs):

Без імені2.png

I suppose it's because the function clbk_loadVC(id) defines the only first mesh (nmesh = 0).

So, Is it possible to see both meshes in VC view?

Also, if I define the MFDs mesh second, namely:
C++:
  -- Mesh

  vi:add_mesh('Cirrus-SR22/Cirrus-SR22')
  vi:set_mesh_visibility_mode(0,bit.bor(MESHVIS.EXTERNAL,MESHVIS.VC))
  vi:add_mesh('Cirrus-SR22/Cirrus-SR22(MFDs)')
  vi:set_mesh_visibility_mode(0,bit.bor(MESHVIS.EXTERNAL,MESHVIS.VC))
And set nmesh = 1, in function clbk_loadVC(id), then I don't see MFDs at all.
 
I do something like very much that with the ShuttlePB, and I don't have that issue.

In my (C++) code I have the meshes declaration, along with their 'visibility rule' :

void ShuttlePB::clbkSetClassCaps (FILEHANDLE cfg)
{
...

// associate a mesh for the visual

AddMesh("ShuttlePB_pilothead");
SetMeshVisibilityMode(0, MESHVIS_EXTERNAL); // hide the pilot head when in VC mode

AddMesh("ShuttlePB_pilot");
SetMeshVisibilityMode(1, MESHVIS_ALWAYS);

AddMesh("ShuttlePB_MFDs");
SetMeshVisibilityMode(2, MESHVIS_ALWAYS); // MFD as separate mesh for D3D9 metalness shader reason

AddMesh("ShuttlePB");
SetMeshVisibilityMode (3, MESHVIS_ALWAYS);

...
}

then the VC function :

bool ShuttlePB::clbkLoadVC (int id)
{
static VCMFDSPEC mfds_left = { 2, 1 };
static VCMFDSPEC mfds_right = { 2, 0 };
static VCHUDSPEC hud_pilot = { 3, 7,_V(0,0.305,1.22429),0.3 };

// Left & Right MFDs
oapiVCRegisterMFD(MFD_LEFT, &mfds_left);
oapiVCRegisterMFD(MFD_RIGHT, &mfds_right);

// HUD
oapiVCRegisterHUD(&hud_pilot);

// Pilot's eyes location
SetCameraOffset(_V(0, 0.305, 0.492));

return true;
}

The only difference is that I also have a Virtual HUD there, but really the code works without it.

So in total I have 4 different meshes.

And set nmesh = 1, in function clbk_loadVC(id), then I don't see MFDs at all.

This is very weird, your second mesh is indeed index 1. LUA or not Orbiter always loads the first mesh as 'index 0', the second as 'index 1' etc etc...
 
Last edited:
I have a problem. I can't use a single mesh for MFDs and the rest of my mesh, because of the *.metal maps that make MFDs meshgroups invisible, so I use two meshes in my script:
C++:
  -- Mesh

  vi:add_mesh('Cirrus-SR22/Cirrus-SR22(MFDs)')
  vi:set_mesh_visibility_mode(0,bit.bor(MESHVIS.EXTERNAL,MESHVIS.VC))
  vi:add_mesh('Cirrus-SR22/Cirrus-SR22')
  vi:set_mesh_visibility_mode(0,bit.bor(MESHVIS.EXTERNAL,MESHVIS.VC))
The first mesh contains the only left and right MFDs (two squares with UVs). The second one contains the rest.

In the end of the script I define function clbk_loadVC(id):
C++:
function clbk_loadVC(id)

    local mfds =
    {
        pos = _R(0,0,0,0),
        nmesh = 0,
        ngroup = 0,
        flag = 1,
        nbt1 = 6,
        nbt2 = 6,
        bt_yofs = 1024/6,
        bt_ydist = 1024/7
    }
 
    local mfdgrp = {0,1}

  if id == 0 then
    vi:set_cameraoffset({x=-0.49644,y=0.60708,z=1})
    oapi.VC_set_neighbours(-1, 1, -1, 2)
  elseif id == 1 then
    vi:set_cameraoffset({x=0.49644,y=0.60708,z=1})
    oapi.VC_set_neighbours(0, -1, -1, 2)
  elseif id == 2 then
    vi:set_cameraoffset({x=0,y=0.45,z=-1})
    oapi.VC_set_neighbours(-1, -1, 0, -1)
  end

    for i=0, 1 do
        mfds.ngroup = mfdgrp[i + 1]
        oapi.register_mfd(MFDID.LEFT + i, mfds)
    end

  return true
end

In game I see both meshes in external view:

View attachment 45691

But in VC view I see the only first mesh (two MFDs):

View attachment 45692

I suppose it's because the function clbk_loadVC(id) defines the only first mesh (nmesh = 0).

So, Is it possible to see both meshes in VC view?

Also, if I define the MFDs mesh second, namely:
C++:
  -- Mesh

  vi:add_mesh('Cirrus-SR22/Cirrus-SR22')
  vi:set_mesh_visibility_mode(0,bit.bor(MESHVIS.EXTERNAL,MESHVIS.VC))
  vi:add_mesh('Cirrus-SR22/Cirrus-SR22(MFDs)')
  vi:set_mesh_visibility_mode(0,bit.bor(MESHVIS.EXTERNAL,MESHVIS.VC))
And set nmesh = 1, in function clbk_loadVC(id), then I don't see MFDs at all.
Shouldn't it be vi:set_mesh_visibility_mode(1,..) for the second mesh?
vi:add_mesh returns the index of the loaded mesh BTW so you can try something like that :
Code:
self:set_mesh_visibility_mode (self:add_mesh (self.vcmesh_tpl), MESHVIS.VC)
 
If I define the MFDs mesh second, then I don't see MFDs in external view:
C++:
  vi:add_mesh('Cirrus-SR22/Cirrus-SR22')
  vi:set_mesh_visibility_mode(0,bit.bor(MESHVIS.EXTERNAL,MESHVIS.VC))
  vi:add_mesh('Cirrus-SR22/Cirrus-SR22(MFDs)')
  vi:set_mesh_visibility_mode(1,bit.bor(MESHVIS.EXTERNAL,MESHVIS.VC))

Без імені.png

But if I define the MFDs mesh first, then I see MFDs in external view:
C++:
  vi:add_mesh('Cirrus-SR22/Cirrus-SR22(MFDs)')
  vi:set_mesh_visibility_mode(0,bit.bor(MESHVIS.EXTERNAL,MESHVIS.VC))
  vi:add_mesh('Cirrus-SR22/Cirrus-SR22')
  vi:set_mesh_visibility_mode(1,bit.bor(MESHVIS.EXTERNAL,MESHVIS.VC))

Без імені2.png

But I get crash to desktop after closing simulation in this case (Orbiter Lauchpad doesn't relaunch). The last line in Orbiter.log says: D3D9: [Destroy Render Window Called].
 
Maybe I won't display MFDs in external view, since it's very unstable (crashes to desktop) and I don't know why it happens. In VC it looks good and no crashes:


Без імені.png
 
Back
Top