SDK Question Dynamically updating vessel vextures? is it possible?

Mr Martian

Orbinaut/Addon dev/Donator
Addon Developer
Donator
Joined
Jun 6, 2012
Messages
279
Reaction score
62
Points
28
Location
Sydney, Australia, Earth, Sol
Website
www.orbithangar.com
Hi All,

I'm experimenting with a vessel class which updtaes some of its textures in realtime.

I have this in clbkPreStep:
C++:
    SURFHANDLE surf[2];
    surf[0] = oapiLoadTexture ("texture_1.dds", false);
    surf[1] = oapiLoadTexture ("texture_2.dds", false);
    if (light == ON) {
        oapiSetTexture (mh_main, 1, surf[0]);
    }
    else {
        oapiSetTexture (mh_main, 1, surf[1]);
    }

This will work to update the texture based on my parameter "light", but only on simulation load. Does anyone know a way to force oapiSetTexture to update in realtime? Or is this just not possible?

Thanks!
 

jedidia

shoemaker without legs
Addon Developer
Joined
Mar 19, 2008
Messages
10,393
Reaction score
1,637
Points
203
Location
between the planets
What you want to do is possible, I've done it in the past, but I can't tell you how it works right now.
The most important thing you have to be aware of when it comes to meshes and textures though is that they exist on 2 levels:
On the one hand are the things you load in with oapiLoadMesh and oapiLoadTexture. These return you pointers to global templates, from which meshes and textures get instantiated for each vessel that actually needs them.
In other words, if you change those, you change the global template you don't actually change any of the existing vessels, you just change the template for all vessels that will instantiate it in the future.
You have to get and modify the mesh and texture handles of specific vessel instances to actually change them on the fly. As mentioned, it would take me rather too long to reconstruct how it's done, but this distinction is a major gotcha that should help you along a bit.
 

N_Molson

Addon Developer
Addon Developer
Donator
Joined
Mar 5, 2010
Messages
8,965
Reaction score
2,791
Points
203
Location
Toulouse
Definitively possible, some addons do that with the heatshield getting red, etc...
 

Urwumpe

Not funny anymore
Addon Developer
Donator
Joined
Feb 6, 2008
Messages
36,996
Reaction score
1,677
Points
203
Location
Langendernbach
I think you need to tell Orbiter, that the visual of the spacecraft is finally modified and the data should be exchanged with the 3D client.

Did you call VESSEL::MeshModified()?
 

jarmonik

Well-known member
Orbiter Contributor
Addon Developer
Beta Tester
Joined
Mar 28, 2008
Messages
2,443
Reaction score
527
Points
113
Website
users.kymp.net
The MeshModified() should work although it will reinitialize entire mesh.

Other possibility is:

C++:
DEVMESHHANDLE hdMesh = GetDevMesh(hVis, index);
oapiSetTexture(hdMesh, texidx, surf[x]);

Also doing render configuration changes in clbkPreStep or clbkPostStep can severally impact in performance. Or at-least you should check if a state change has occurred before doing anything.

Code:
if (light != light_prev) {
    light_prev = light;   
    if (light == ON) {
        oapiSetTexture (mh_main, 1, surf[0]);
    }
    else {
        oapiSetTexture (mh_main, 1, surf[1]);
    }
}
 
Top