C++ Question Is it possible for a Mesh to be a Resource

jimd

New member
Joined
Mar 30, 2009
Messages
25
Reaction score
0
Points
0
Guys,

I am currently working with Chuck Tetakel on writing a .dll for his fabulous model of Dream Chaser. We have been discussing the possibility of somehow allowing a mesh to become a resource embedded in the .dll.

I fully realize that this is not the ordinary or maybe even easy way to do this and it most likely will create a number of complications later on but I want to see if this is possible.

Does anyone have any ideas about how that could be accomplished?

Sincerely

JimD

Feel free to post here or PM me if you wish.
 
It is possible, but not recommended.

I have to wonder why you are trying to embed a mesh file into your DLL instead of doing it the regular way.

Some people don't like it when they can't edit the mesh of the ships they downloaded.

Is it possible: yes.
Is it easy: yes.
Is it recommended: no.

If you want to embed it, you would want to do it as a .cpp file, not a .msh file. Here's something Martins did a while ago. needless to say, you would need to change it from a panel to a vessel mesh, but you can do it...

Code:
void MyVessel::DefineMainPanel (PANELHANDLE hPanel)
{
  static DWORD panelW = 1280;
  static DWORD panelH =  400;
  float fpanelW = (float)panelW;
  float fpanelH = (float)panelH;
  static NTVERTEX VTX[4] = {
    {      0,      0,0,   0,0,0,   0,0},
    {      0,fpanelH,0,   0,0,0,   0,0},
    {fpanelW,fpanelH,0,   0,0,0,   0,0},
    {fpanelW,      0,0,   0,0,0,   0,0}
  };
  static WORD IDX[6] = {
    0,2,1,
    2,0,3
  };

  if (hPanelMesh) oapiDeleteMesh (hPanelMesh);
  hPanelMesh = oapiCreateMesh (0,0);
  MESHGROUP grp = {VTX, IDX, 4, 6, 0, 0, 0, 0, 0};
  oapiAddMeshGroup (hPanelMesh, &grp);
  SetPanelBackground (hPanel, 0, 0, hPanelMesh, panelW, panelH, 0,
    PANEL_ATTACH_BOTTOM | PANEL_MOVEOUT_BOTTOM);
}

However, I don't like the idea of doing it this way, because it is harder to change and it just gives you a mangled mess of c++ code to look after. in this case, VTX is the list of vertexes from the mesh file, and ITX is the triangle list from the mesh file.
 
Last edited:
If you want to embed it, you would want to do it as a .cpp file, not a .msh file. Here's something Martins did a while ago. needless to say, you would need to change it from a panel to a vessel mesh, but you can do it...

Note that while there is oapiAddMaterial function which can be used to add materials to the created mesh, there is no function that would add textures to the mesh (oapiSetTexture can be only used to replace them in meshes with already existing textures). SetPanelBackground is only used to set texture for the panel.
 
I have to wonder why you are trying to embed a mesh file into your DLL instead of doing it the regular way.
My guess: Make it 'closed source'.
If the author for example doesn't want anyone to 'steal and modify' the mesh.
 
in this case, VTX is the list of vertexes from the mesh file, and ITX is the triangle list from the mesh file.

No. ITX is the list of vertex indices for rendering.

If you want to render two triangles, there are two ways to do that:
-Define 6 vertices and each 3 make a triangle. It's easy to do it, but it uses two excess vertices in the process.
- Instead you can define a list of four vertices and then tell the hardware which vertices to use to draw the triangles. In this case, triangle one is being drawn using vertices 0, 2 and 1 and triangle two is being drawn using vertices 2, 0, 3. These numbers refer to the vertices' positions in the array of vertices.

This way of drawing triangles is faster. With less vertices, the graphics card has to do less transformations.
 
No. ITX is the list of vertex indices for rendering.

If you want to render two triangles, there are two ways to do that:
-Define 6 vertices and each 3 make a triangle. It's easy to do it, but it uses two excess vertices in the process.
- Instead you can define a list of four vertices and then tell the hardware which vertices to use to draw the triangles. In this case, triangle one is being drawn using vertices 0, 2 and 1 and triangle two is being drawn using vertices 2, 0, 3. These numbers refer to the vertices' positions in the array of vertices.

This way of drawing triangles is faster. With less vertices, the graphics card has to do less transformations.

right. I guess what I said was ambiguous to some people. I doubt that anyone would be using six vertices to draw a square, though. It makes absolutely no sense to do it that way.
 
I doubt that anyone would be using six vertices to draw a square, though.

It's not using six vertices. It's merely assigning the indices of 4 vertices to the six corners of 2 triangles. If you look at the list, you see that vertex 0 and vertex 2 are referenced two times, because they are the vertices where the two triangles connect.

I have to wonder why you are trying to embed a mesh file into your DLL instead of doing it the regular way.

Probably because he doesn't want anyone else to use the mesh. That is perfectly justified if you spent a lot of work on your mesh and don't want to see it pop up all over the net by some dude shouting "OMG look what I did I'm so good lulz".

Now for the actual question... I know Orbiter can load textures from resources, but I'm not sure about meshes. Mesh-encrypting AMSO-style might be a better way to go.
 
Last edited:
"It's not using six vertices. It's merely assigning the indices of 4 vertices to the six corners of 2 triangles. If you look at the list, you see that vertex 0 and vertex 2 are referenced two times, because they are the vertices where the two triangles connect."
I AM NOT SAYING THAT IT USES SIX VERTICES!
I AM SAYING THAT IT DOES NOT USE SIX VERTICES!

Probably because he doesn't want anyone else to use the mesh. That is perfectly justified if you spent a lot of work on your mesh and don't want to see it pop up all over the net by some dude shouting "OMG look what I did I'm so good lulz".

Perfectly sensible. I suppose if I ever released a mesh, I would do the same.

As to AMSO-style encryption, doesn't AMSO need a custom mesh loader to decode those, though? or does it just decrypt and then pass to orbiter's parser
 
Last edited:
doesn't AMSO need a custom mesh loader to decode those, though? or does it just decrypt and then pass to orbiter's parser

It does but that loader function is contained in the AMSO .dll and called as part of the Post Creation call-back.
 
Back
Top