# SDK QuestionDynamically updating vessel vextures? is it possible?

#### Mr Martian

Donator
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];
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
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

Donator
Definitively possible, some addons do that with the heatshield getting red, etc...

#### Urwumpe

##### Not funny anymore
Donator
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
Beta Tester
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]);
}
}

Replies
10
Views
393
Replies
5
Views
158
Replies
5
Views
457
Replies
21
Views
861
Replies
5
Views
696