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.
#22
04/14/2005 (2:43 pm)
Err never mind I'm an idiot and you're closer to the answer than I am :(
#23
I dont see where you are specifying what to load it to... if you don't tell it what to load then obviously it wont load it for you.
What about making 2 Skys in the editor, then using a function to switch them... Either by calling load on one of them (I doubt that will work) or simply setting one to hidden?
04/14/2005 (2:44 pm)
You dont need to cast object. it is autyomatically done and varified (It wasnt in previous versions of Torque but is now)I dont see where you are specifying what to load it to... if you don't tell it what to load then obviously it wont load it for you.
What about making 2 Skys in the editor, then using a function to switch them... Either by calling load on one of them (I doubt that will work) or simply setting one to hidden?
#24
And thanks for the info on the cast, my impression from looking at the code was that it was always needed, but now I know better.
04/14/2005 (2:57 pm)
@Chris, I'm pretty sure thats exactly what we are both trying to accomplish here, although I must admit I hand't considered hiding one.And thanks for the info on the cast, my impression from looking at the code was that it was always needed, but now I know better.
#25
Methods for classes can also be declared in C++, using the ConsoleMethod macro:
ConsoleMethod(SimObject, helloWorld, void, 2, 2, "A somewhat more complex test method.")
{
Con::printf("Hello World!");
Con::printf("Called on object: %s", argv[1]);
Con::printf("Also called on object: %s", object->getName());
}
This defines a method callable on any instance of a SimObject the console has access to.
Note:
Three useful parameters are provided to the code in the body of a ConsoleFunction or ConsoleMethod:
int argc, indicating how many arguments were passed.
char* argv[], an array of strings corresponding to the arguments.
object, which is present only in the case of a ConsoleMethod, is a pointer to the object on which the method is being called. It is automatically cast and validated, so you don't need to cast it yourself (this was the case in older versions of Torque).
see: http://www.garagegames.com/docs/torque.sdk/engine/Console.php
04/14/2005 (2:59 pm)
It is in the docs... Look at the Consolemethod docs to see what I mean: Methods for classes can also be declared in C++, using the ConsoleMethod macro:
ConsoleMethod(SimObject, helloWorld, void, 2, 2, "A somewhat more complex test method.")
{
Con::printf("Hello World!");
Con::printf("Called on object: %s", argv[1]);
Con::printf("Also called on object: %s", object->getName());
}
This defines a method callable on any instance of a SimObject the console has access to.
Note:
Three useful parameters are provided to the code in the body of a ConsoleFunction or ConsoleMethod:
int argc, indicating how many arguments were passed.
char* argv[], an array of strings corresponding to the arguments.
object, which is present only in the case of a ConsoleMethod, is a pointer to the object on which the method is being called. It is automatically cast and validated, so you don't need to cast it yourself (this was the case in older versions of Torque).
see: http://www.garagegames.com/docs/torque.sdk/engine/Console.php
#26
04/14/2005 (3:01 pm)
Is anyone actually trying to implement this? Have any of the ideas we shot out actually worked yet?
#27
04/14/2005 (3:25 pm)
It's on my list, but it's not something I'm actively pursuing at the moment, however the original poster appears to be trying.
#28
I got it working by deleting the old sky and creating a new one with the dml file I needed. The loadDml approach did not work. Calling it as posted some posts ago was not effective.
04/15/2005 (9:48 am)
I'm the original poster :D I got it working by deleting the old sky and creating a new one with the dml file I needed. The loadDml approach did not work. Calling it as posted some posts ago was not effective.
#29
04/18/2005 (6:49 am)
Loading 2 skies then switching which is visible via a key bind didn't work?
#30
12/18/2006 (5:48 pm)
In case anyone wonders how to do this. Expose 'InspectPostApply()" on the sky to script. . . set the new DML and apply changes . . .BTW you will need to do a full rebuilt for it to work Sky.materialList = $thisSky; Sky.inspectPostApplY();
#31
Exposing "inspectPostApply()" is the fastest, easiest, and least memory intensive way of performing this operation.
Oh, and for future reference, any time you want to perform an action in game that the WorldEditor performs, look into the object-in-question's apply() or inspectPostApply() functionality. I've been working on a custom MissionEditor that the end-user would launch for custom map creation, instead of Torque's WorldEditor. I had to repeat this step for precipitation, Sun, Sky, ect. . .
12/19/2006 (5:45 am)
Darn it Anthony! You beat me to it!Exposing "inspectPostApply()" is the fastest, easiest, and least memory intensive way of performing this operation.
Oh, and for future reference, any time you want to perform an action in game that the WorldEditor performs, look into the object-in-question's apply() or inspectPostApply() functionality. I've been working on a custom MissionEditor that the end-user would launch for custom map creation, instead of Torque's WorldEditor. I had to repeat this step for precipitation, Sun, Sky, ect. . .
#32
No rebuild neccessary
12/28/2006 (6:59 pm)
I just used Sky.materialList = "~\game\data\skies\night.dml"; Sky.applySkyChanges();
No rebuild neccessary
#33
However you must have TGE 1.5 for this to work...
Was a good enough reason for me to upgrade from TGE 1.4, :-) well worth $50
Thanks again James!
01/10/2007 (2:11 pm)
James is correct!However you must have TGE 1.5 for this to work...
Was a good enough reason for me to upgrade from TGE 1.4, :-) well worth $50
Thanks again James!
Torque Owner Dreamer
Default Studio Name
Is this what you are trying to do maybe?
ConsoleMethod( Sky, loadDml, void, 2, 2, "sky.loadDml();" ) { Sky *Sky = static_cast<Sky *>( object ); Sky->reloadDml(); } void Sky::reloadDml() { loadDml(); }Near as I can tell Object by itself should be completely NULL and uninitialized, FYI the static_cast creates a new pointer to the current Sky object.