Change sky dml file in mission
by Luis Anton · in Torque Game Engine · 04/13/2005 (4:50 am) · 33 replies
Hi,
I need to change the sky material list (dml file) while in a mission. I've tried to emulate the editor inspector apply button behaviour, with the following code:
but the sky does not change. However, if I follow those steps in the console, it works (set materialList, create editor object, inspector.apply)
Is that the right way to change the sky material list? I don't need dynamic changes, I know it's been done. I just need to reload sky textures.
Thanks.
I need to change the sky material list (dml file) while in a mission. I've tried to emulate the editor inspector apply button behaviour, with the following code:
function changeSky(%day)
{
if (%day)
Sky.materialList="game/data/skies/day.dml";
else
Sky.materialList="game/data/skies/night.dml";
if (!isObject(Editor))
{
Editor::create();
MissionCleanup.add(Editor);
}
Inspector.apply(Sky);
}but the sky does not change. However, if I follow those steps in the console, it works (set materialList, create editor object, inspector.apply)
Is that the right way to change the sky material list? I don't need dynamic changes, I know it's been done. I just need to reload sky textures.
Thanks.
#2
04/13/2005 (8:48 am)
Hmmm where are you getting Inspector from?
#3
04/13/2005 (8:51 am)
If it works in the console, then it should work if you execute the code from a script. I figured he was getting it from script, from whereever the sky is initially loaded from
#4
04/13/2005 (8:55 am)
There is a function in the Sky to Save() according to dump, so I wonder what it would take to add a console method to Sky to Apply, prolly just copy the Insepectors console method over and make a couple mods, no clue where it's at right now though.
#5
04/13/2005 (9:01 am)
Bool loadDml ()
#6
Sky.loadDml(1);
However I don't believe it's addressed in script as Sky, you prolly need to get the Skies object ID first, also if this is Multiplayer you will need to create a Client Side Command, to reload the new sky material, then loop through each client and send the command out.
04/13/2005 (9:08 am)
If it's a bool then theorectially...Sky.loadDml(1);
However I don't believe it's addressed in script as Sky, you prolly need to get the Skies object ID first, also if this is Multiplayer you will need to create a Client Side Command, to reload the new sky material, then loop through each client and send the command out.
#7
Im slowly learning Torque... Can you explain in a little more detail how you go about creating a client side command to reload the sky materials?
04/13/2005 (9:18 am)
He probably named his sky to "Sky" which works the same as calling the ObjectIDIm slowly learning Torque... Can you explain in a little more detail how you go about creating a client side command to reload the sky materials?
#8
Yes, I used an echo. It's the first thing to do :)
And the sky... welll, it is addresesd in script as Sky. Just try it in the console. sky.dump(). It's also like that in the example application.
@Dreamer
The Inspector is created when the editor is created. That's why I'm creating the editor if it does not exist. Just try Inspector.dump before doing anything else, it won't work. Then open the editor (F11), close it, and try Inspector.dump again. It's there. So I force the editor to be created, at least once.
And there's no bool loadDml. Not at least in the script. If it's in the code, then I'll try to create a new consoleMethod for the sky.
04/13/2005 (10:04 am)
@ChirsYes, I used an echo. It's the first thing to do :)
And the sky... welll, it is addresesd in script as Sky. Just try it in the console. sky.dump(). It's also like that in the example application.
@Dreamer
The Inspector is created when the editor is created. That's why I'm creating the editor if it does not exist. Just try Inspector.dump before doing anything else, it won't work. Then open the editor (F11), close it, and try Inspector.dump again. It's there. So I force the editor to be created, at least once.
And there's no bool loadDml. Not at least in the script. If it's in the code, then I'll try to create a new consoleMethod for the sky.
#9
04/13/2005 (10:10 am)
It is a class member function of the Sky class... You will have to expose it to the console to be able to call it.
#10
and even aded a initSkyData(); after 'loadDml()' (and a Con::printf) and nothing happens.
I change the dml file this way, in the console:
sky.materialList="game/data/skies/night.dml";
sky.reloadDml();
but the sky does not change. However, if right after that I open the editor, select the sky object and, without changing anything else, I press the apply button, it changes!!
So, How could I emulate this button?? I cannot find nothing else than this code:
So I tried changing my previous function to...
And... It does not work... again.
I just don't get it. What am I missing? What does that button do that I'm not doing properly?
04/14/2005 (1:44 am)
Ok, I've done it, and it does not work. ConsoleMethod( Sky, reloadDML, void, 2, 2, "...")
{
object->reloadDml();
}
void Sky::reloadDml()
{
loadDml();
}and even aded a initSkyData(); after 'loadDml()' (and a Con::printf) and nothing happens.
I change the dml file this way, in the console:
sky.materialList="game/data/skies/night.dml";
sky.reloadDml();
but the sky does not change. However, if right after that I open the editor, select the sky object and, without changing anything else, I press the apply button, it changes!!
So, How could I emulate this button?? I cannot find nothing else than this code:
new GuiButtonCtrl() {
profile = "GuiButtonProfile";
horizSizing = "right";
vertSizing = "bottom";
position = "2 2";
extent = "40 20";
minExtent = "8 8";
visible = "1";
command = "EWorldEditor.isDirty = true;
inspector.apply(InspectorNameEdit.getValue());";
helpTag = "0";
text = "Apply";
groupNum = "-1";
buttonType = "PushButton";
};So I tried changing my previous function to...
function changeSky(%day)
{
if (%dia)
Sky.materialList="game/data/skies/day.dml";
else
Sky.materialList="game/data/skies/night.dml";
if (!isObject(Editor))
{
Editor::create();
MissionCleanup.add(Editor);
}
EWorldEditor.isDirty=true;
Inspector.apply(Sky);
}And... It does not work... again.
I just don't get it. What am I missing? What does that button do that I'm not doing properly?
#11
I don't know if it's the best way, but it works.
I just delete the sky, and create a new one :)
Have you ever tried deleting the sky (sky.delete())? It's a nice effect... lol.
Thanks to everyone.
04/14/2005 (1:56 am)
Ok, I've done it.I don't know if it's the best way, but it works.
I just delete the sky, and create a new one :)
Have you ever tried deleting the sky (sky.delete())? It's a nice effect... lol.
Thanks to everyone.
#12
04/14/2005 (3:37 am)
I will have to remember that. How bad is the reload time?
#13
Well, I don't know how this may work in a network game, because I'm working on a single user program, but for me it opens some possibilities, like a not so complex day-night cicle (forgetting shadows) or even wathing eyes in the sky (lol)
04/14/2005 (6:41 am)
It's fast, but not instantaneous. Say... half a second. I think it depends on how many different images form the sky. A simple sky like my 'clearNight' uses just two images: one full of stars and another one with stars and a moon. This one loads pretty fast. A normal skybox seems to take a little more time, around 500ms (or less).Well, I don't know how this may work in a network game, because I'm working on a single user program, but for me it opens some possibilities, like a not so complex day-night cicle (forgetting shadows) or even wathing eyes in the sky (lol)
#14
04/14/2005 (6:44 am)
Is there a way to have two skies and swap them? This way you could preload the textures (and have very psychedelic skies by switching them every tick).
#15
has anyone used animated textures for sky? I searched the resources but haven't found anyhting yet. When I do I will post back here.
04/14/2005 (7:15 am)
I am interested in using animated textures.. like a lif (I think that is the extension) that animates through a list of bmp 's to produce a very dynamic sky. You could also probably use an animated gif. I haven't got this far yet in my development, so I dont know how to do it, but I dont imagine it takes very much to impliment it. has anyone used animated textures for sky? I searched the resources but haven't found anyhting yet. When I do I will post back here.
#16
This might make sky switching easy for you dirkk
You should probably keep in mind that I haven't actually looked into seeing what the function actually does. Just noted that it had the function
04/14/2005 (8:33 am)
Bool Sky::loadDml() didn't work because it is a protected member function... If you want to try and use it again you will have to create a public function that calls loaddml() and expose it to the console. This might make sky switching easy for you dirkk
You should probably keep in mind that I haven't actually looked into seeing what the function actually does. Just noted that it had the function
#17
04/14/2005 (8:43 am)
Just for refference from Sky.ccbool Sky::loadDml()
{
char path[1024], *p;
dStrcpy(path, mMaterialListName);
if ((p = dStrrchr(path, '/')) != NULL)
*p = 0;
mNumCloudLayers = 0;
Stream *stream = ResourceManager->openStream(mMaterialListName);
if (stream==NULL)
{
#if defined(TORQUE_DEBUG)
Con::warnf("Sky material list is missing: %s", mMaterialListName);
#else
// ASSERT?? !!!!!!TBD
#endif
return false;
}
else
{// !!!!!TBD dhc - there's no fricking error checking here or in materialList.read!!!!
mMaterialList.read(*stream);
ResourceManager->closeStream(stream);
if(!mMaterialList.load(SkyTexture, path))
return false;
for(S32 x = 0; x < 6; ++x)
{
mMaterialList.getMaterial(x).setClamp(true);
mSkyHandle[x] = mMaterialList.getMaterial(x);
}
for(S32 x = 0; x < mMaterialList.size() - CloudMaterialOffset; ++x, ++mNumCloudLayers)
{
mMaterialList.getMaterial(x + CloudMaterialOffset).setClamp(false);
mCloudLayer[x].setTexture(mMaterialList.getMaterial(x + CloudMaterialOffset));
}
}
return true;
}
#18
When I get home I might take a look at the code (dont have access to it here) to see how difficult it looks. Give it a go if you want to, it is fairly simple... You might have to alter the pak and unpack functions as well.
04/14/2005 (8:49 am)
Ya... you could use that to load a new skybox ... if TGE is set up to handle animated textures then you could probably also modify it (Dont even know that it needs it) to handle loading animated textures for your skybox. You would have to alter void renderObject to handle the animated texture I imagine... When I get home I might take a look at the code (dont have access to it here) to see how difficult it looks. Give it a go if you want to, it is fairly simple... You might have to alter the pak and unpack functions as well.
#19
04/14/2005 (9:05 am)
Untested but this should work...ConsoleMethod( Sky, loadDml, void, 2, 2, "sky.loadDml();" ) {
Sky *Sky = static_cast<Sky *>( object );
Sky->loadDml();
}
#20
if reloadDml is public, it can call loadDml without problems, but there are no changes in sky.
It did not work, at least not the way I did it. I don't know it that static_cast does something really different, but looks pretty similar to what I did. Please, try it and check if it works for you.
04/14/2005 (2:12 pm)
I exposed the loadDml protected method, creating a Sky public method called reloadDml that called loadDml. I did not say 'it did not compile', because that it what happens if you call loadDml from a ConsoleMethod function.ConsoleMethod( Sky, reloadDML, void, 2, 2, "...")
{
object->reloadDml();
}
void Sky::reloadDml()
{
loadDml();
}if reloadDml is public, it can call loadDml without problems, but there are no changes in sky.
It did not work, at least not the way I did it. I don't know it that static_cast does something really different, but looks pretty similar to what I did. Please, try it and check if it works for you.
Torque Owner Chris Labombard
Premium Preferred