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.
 

thepenguin

Flying Penguin
Addon Developer
Joined
Jul 27, 2013
Messages
220
Reaction score
1
Points
16
Location
Earth-Moon Lagrange Point (L4)
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:

orb

New member
News Reporter
Joined
Oct 30, 2009
Messages
14,020
Reaction score
4
Points
0
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.
 

kuddel

Donator
Donator
Joined
Apr 1, 2008
Messages
2,064
Reaction score
507
Points
113
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.
 

RisingFury

OBSP developer
Addon Developer
Joined
Aug 15, 2008
Messages
6,427
Reaction score
492
Points
173
Location
Among bits and Bytes...
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.
 

thepenguin

Flying Penguin
Addon Developer
Joined
Jul 27, 2013
Messages
220
Reaction score
1
Points
16
Location
Earth-Moon Lagrange Point (L4)
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.
 

jedidia

shoemaker without legs
Addon Developer
Joined
Mar 19, 2008
Messages
10,875
Reaction score
2,129
Points
203
Location
between the planets
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:

thepenguin

Flying Penguin
Addon Developer
Joined
Jul 27, 2013
Messages
220
Reaction score
1
Points
16
Location
Earth-Moon Lagrange Point (L4)
"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:

Hlynkacg

Aspiring rocket scientist
Addon Developer
Tutorial Publisher
Donator
Joined
Dec 27, 2010
Messages
1,870
Reaction score
3
Points
0
Location
San Diego
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.
 
Top