Hiding dif ojects
by Steve D · in Torque Game Engine · 11/25/2007 (2:42 pm) · 7 replies
My scenario is I have a "party" of 6 ai characters that are controllable by mouse, ie right click and that's where they will go. I have a dif building I made in constructor, 2 versions of it, one with a roof and one without. I have a trigger zone at the front door, when an ai player steps in the trigger zone the entire party is transported inside the building. Great all works.
But I can't figure out how to swap out the building with the version without a roof once they are inside. The way I see it, if I delete the building and re-create it with the right version, won't I have to re-light the entire mission again? Can you even re-light a mission in script?
I tried SetHidden on the dif object itself but console output says it's an unrecognized command, is this suppose to work on dif's or am I doing something wrong?
Besides deleting and re-creating the building, is there any other more efficient way of swapping out in script?
But I can't figure out how to swap out the building with the version without a roof once they are inside. The way I see it, if I delete the building and re-create it with the right version, won't I have to re-light the entire mission again? Can you even re-light a mission in script?
I tried SetHidden on the dif object itself but console output says it's an unrecognized command, is this suppose to work on dif's or am I doing something wrong?
Besides deleting and re-creating the building, is there any other more efficient way of swapping out in script?
#2
so a possible solution is to use a dts as your roof so that you can cloak it, ect. say take your diff without a roof and make a brush across the top (so that you can portalize it off if you want to) and recreate your roof as a dts. if i remeber correctly there are some resources that will allow you to fade the dts out or in to yor likings.
hope that helps
11/25/2007 (5:05 pm)
Well the impression im getting is that your camera is a rts style overhead view.so a possible solution is to use a dts as your roof so that you can cloak it, ect. say take your diff without a roof and make a brush across the top (so that you can portalize it off if you want to) and recreate your roof as a dts. if i remeber correctly there are some resources that will allow you to fade the dts out or in to yor likings.
hope that helps
#3
11/25/2007 (6:35 pm)
Thanks for the response but I don't think that will work on multi-level dif buildings.
#4
I've spent the past 4 days tweaking and optimizing this code so it doesn't result in the slight hiccup when you do it, but on a slow machine it can still be present if you have shadows enabled. The harder problem to solve is relighting the terrain if you need to. Even after gutting the code it is still taking me 400-500ms to relight the entire terrain without shadows... It does not look like you'll have need for that, and re-writing the code to support just individual object relighting isn't too difficult - maybe 3 days of work if you are a decent coder.
The FAR simpler option is to check Use GLLighting on the DIFs. They won't have shadows or lighting, but will render with textures when placed. I plan to do this on really low end machines where even the 20-30ms will become a problem for interior relights. In fact, you'll probably want to have GLLighting enabled when you place the gifs so the black DIF isn't visible just prior to the relight finishing.
Some thoughts on how to relight the lighting code...
You'll notice that the lightmap generation code consists of a start function that kicks off several TGE lighting functions. Once those complete the SG lighting functions get kicked off. They are all events, meaning they are slow and recursive You'll want to write it as a ConsoleFunction that calls a single SceneLighting function.
You'll also need a way in TorqueScript to call the ConsoleFunction and pass it the object to be relit. Then the Console function passes the argument into the SceneLighting function. Now, the default Lightmap generation code loops through every light, and every object for both TGE and SG modes. You'll first want to comment out the TGE functions (they only lights the terrain) and rewrite the SG code (it relights interiors) to just take the sunlight (always light 0) and the object that matches the ID of the one you passed in, and relight just it.
I would also remove all calls to Canvas->paint as they slow down the relighting. Lastly I'd put in some timing code to estimate how long your DIFs are taking to relight. My estimates were on DIfs with 3000-4000 surfaces. If yours have more then you might need to reduce their complexity to cut down on the relight time. I can't even tell you what I did to optimize it entirely... I plan to do a file dif when I'm done and figure out exactly what changed, and maybe resource it for folks.
Please feel free to email me if you need more help with this.. I am still hoping to find some inspiration or direction with regards to breaking up the ProcessSurfaces functions in the relighting code. It is my only hope for making terrain lighting (not shadowing) reasonably fast. It can't be too hard! All the videos of Day/Night I see are doing it, but no explainations are ever given :/
Good luck with things!
11/25/2007 (10:00 pm)
One option is to re-write the object lighting code to support individual interior dif relights. I recently completed this and its working decently. Relighting a single interior using DESIGN quality lighting/shadows takes about 100-150ms on a 2Ghz CPU. Relighting without shadows takes only 20-30ms or so.I've spent the past 4 days tweaking and optimizing this code so it doesn't result in the slight hiccup when you do it, but on a slow machine it can still be present if you have shadows enabled. The harder problem to solve is relighting the terrain if you need to. Even after gutting the code it is still taking me 400-500ms to relight the entire terrain without shadows... It does not look like you'll have need for that, and re-writing the code to support just individual object relighting isn't too difficult - maybe 3 days of work if you are a decent coder.
The FAR simpler option is to check Use GLLighting on the DIFs. They won't have shadows or lighting, but will render with textures when placed. I plan to do this on really low end machines where even the 20-30ms will become a problem for interior relights. In fact, you'll probably want to have GLLighting enabled when you place the gifs so the black DIF isn't visible just prior to the relight finishing.
Some thoughts on how to relight the lighting code...
You'll notice that the lightmap generation code consists of a start function that kicks off several TGE lighting functions. Once those complete the SG lighting functions get kicked off. They are all events, meaning they are slow and recursive You'll want to write it as a ConsoleFunction that calls a single SceneLighting function.
You'll also need a way in TorqueScript to call the ConsoleFunction and pass it the object to be relit. Then the Console function passes the argument into the SceneLighting function. Now, the default Lightmap generation code loops through every light, and every object for both TGE and SG modes. You'll first want to comment out the TGE functions (they only lights the terrain) and rewrite the SG code (it relights interiors) to just take the sunlight (always light 0) and the object that matches the ID of the one you passed in, and relight just it.
I would also remove all calls to Canvas->paint as they slow down the relighting. Lastly I'd put in some timing code to estimate how long your DIFs are taking to relight. My estimates were on DIfs with 3000-4000 surfaces. If yours have more then you might need to reduce their complexity to cut down on the relight time. I can't even tell you what I did to optimize it entirely... I plan to do a file dif when I'm done and figure out exactly what changed, and maybe resource it for folks.
Please feel free to email me if you need more help with this.. I am still hoping to find some inspiration or direction with regards to breaking up the ProcessSurfaces functions in the relighting code. It is my only hope for making terrain lighting (not shadowing) reasonably fast. It can't be too hard! All the videos of Day/Night I see are doing it, but no explainations are ever given :/
Good luck with things!
#5
Another crazy idea I had - My mission areas are going to be somewhat limited in size, nothing big, and also it will not be a FPS. Maybe I could try loading all the dif's and put the ones not in use literally off the map where the camera and player can't go this way everything would be lit up correctly on mission start up. Then I can swap out the dif's by setting their transform, this will avoid having to load them and delete them on the fly. I'm kind of thinking out loud since I haven't tried it yet but it might be a decent hack! :)
11/26/2007 (8:21 am)
Thanks again for the detailed answer, it's very interesting but unfortunately my c++ skills are at book level only so I'm a novice at best. I plan to take some c++ courses as I get further along.Another crazy idea I had - My mission areas are going to be somewhat limited in size, nothing big, and also it will not be a FPS. Maybe I could try loading all the dif's and put the ones not in use literally off the map where the camera and player can't go this way everything would be lit up correctly on mission start up. Then I can swap out the dif's by setting their transform, this will avoid having to load them and delete them on the fly. I'm kind of thinking out loud since I haven't tried it yet but it might be a decent hack! :)
#6
I'm not even sure what happens if you tell a Dif to exist off the map... I'll have to try it. There could also be some issues with collision. Say you have an object or player already in the building on the second floor - when you swap DiFs they might fall down ever so slightly as interiors swap, and get stuck. Some quick testing would tell if its going to work. Cool idea though!
I thought of an interesting way to speed up some of my terrain lighting problems last night. If I can convince myself that what I have is wanted by the community I'll resource it. Then you can just add it to your project and go.
11/26/2007 (8:57 am)
The problem with that is the lightmap is generated just once. So the interiors will need to be on the playable map initially to get the correct lightmap generated. This will unfortunately cause ground shadows to be created during that time, which will remain even if the buildings are moved. The lighting is also generated with regards to how the buildings face the sun, so that too could be off a bit.I'm not even sure what happens if you tell a Dif to exist off the map... I'll have to try it. There could also be some issues with collision. Say you have an object or player already in the building on the second floor - when you swap DiFs they might fall down ever so slightly as interiors swap, and get stuck. Some quick testing would tell if its going to work. Cool idea though!
I thought of an interesting way to speed up some of my terrain lighting problems last night. If I can convince myself that what I have is wanted by the community I'll resource it. Then you can just add it to your project and go.
#7
11/26/2007 (6:04 pm)
That's true but as an experiment I will have to see what it looks like if you actually stack the dif objects in the air above their placement. With my game type the camera will never be allowed to look up into the sky so maybe with the dif's just higher the sun, lighting etc will be pretty close to normal.
Torque Owner Steve D