Attaching lights and items
by Dusty Monk · in Torque 3D Professional · 01/11/2011 (5:39 pm) · 4 replies
Couple of questions that are probably rudimentary, but this morning (1/11/11) the search engine appears to be broken here at the site. Any attempt at any query just returns "Invalid Search Terms". Go figure.
So two quick questions, both of these relate to T3D Beta 3:
1.) Do the light fields in the 'item' datablock still work? That is, under the advanced lighting model? They don't appear to be working trivially, but I haven't really dug into them yet, so I'd like to know if they're supposed to work, currently, or if they're just hold-overs from TGE legacy days.
2.) What's the easiest way to attach a light to an animated object in a level? I have some spotlights that have a nice ambient animation that pans the spotlight back and forth. I'd like to put an actual conelight on the spotlight, and have it pan with the spotlight, and ideally, I'd like to have them bound together in a package, so I could just plop the package down and have it work. Thoughts?
Thanks, in general any current thread links on setting up lights in a level in current gen T3D are greatly appreciated, again as it appears (at least for me) search is broken.
Dusty
So two quick questions, both of these relate to T3D Beta 3:
1.) Do the light fields in the 'item' datablock still work? That is, under the advanced lighting model? They don't appear to be working trivially, but I haven't really dug into them yet, so I'd like to know if they're supposed to work, currently, or if they're just hold-overs from TGE legacy days.
2.) What's the easiest way to attach a light to an animated object in a level? I have some spotlights that have a nice ambient animation that pans the spotlight back and forth. I'd like to put an actual conelight on the spotlight, and have it pan with the spotlight, and ideally, I'd like to have them bound together in a package, so I could just plop the package down and have it work. Thoughts?
Thanks, in general any current thread links on setting up lights in a level in current gen T3D are greatly appreciated, again as it appears (at least for me) search is broken.
Dusty
About the author
Dusty Monk is founder and president of Windstorm Studios, an independant game studio. Formerly a sr. programmer at Ensemble Studios, Dusty has worked on AAA titles such as Age of Empires II & III, and Halo Wars.
#2
this is what I used to use(in 11b3), for mounting spotlights as headlights to vehicles, I am sure you can adapt it for your needs
01/11/2011 (8:20 pm)
hi Dusty,this is what I used to use(in 11b3), for mounting spotlights as headlights to vehicles, I am sure you can adapt it for your needs
function Jeep::onAdd(%this,%obj)
{
//Parent::onAdd(%this, %obj);
%obj.mountable = true;
%jeepHeadLight1 = new SpotLight() {
range = "80";
innerAngle = "40";
outerAngle = "45";
isEnabled = "1";
color = "1 1 1 1";
brightness = "1";
castShadows = "1";
priority = "1";
animate = "0";
animationPeriod = "1";
animationPhase = "1";
flareType = "LightFlareExample1";
flareScale = "1";
attenuationRatio = "0 1 1";
shadowType = "Spot";
texSize = "512";
overDarkFactor = "2000 1000 500 100";
shadowDistance = "400";
shadowSoftness = "0.15";
numSplits = "1";
logWeight = "0.91";
fadeStartDistance = "0";
lastSplitTerrainOnly = "0";
splitFadeDistances = "10 20 30 40";
representedInLightmap = "0";
shadowDarkenColor = "0 0 0 -1";
includeLightmappedGeometryInShadow = "0";
ownedByMount = "1";
canSaveDynamicFields = "1";
Enabled = "1";
};
%jeepHeadLight2 = new SpotLight() {
range = "80";
innerAngle = "40";
outerAngle = "45";
isEnabled = "1";
color = "1 1 1 1";
brightness = "1";
castShadows = "1";
priority = "1";
animate = "0";
animationPeriod = "1";
animationPhase = "1";
flareType = "LightFlareExample1";
flareScale = "1";
attenuationRatio = "0 1 1";
shadowType = "Spot";
texSize = "512";
overDarkFactor = "2000 1000 500 100";
shadowDistance = "400";
shadowSoftness = "0.15";
numSplits = "1";
logWeight = "0.91";
fadeStartDistance = "0";
lastSplitTerrainOnly = "0";
splitFadeDistances = "10 20 30 40";
representedInLightmap = "0";
shadowDarkenColor = "0 0 0 -1";
includeLightmappedGeometryInShadow = "0";
ownedByMount = "1";
canSaveDynamicFields = "1";
Enabled = "1";
};
%obj.jeepHlight1 = %jeepHeadLight1;
%obj.jeepHlight2 = %jeepHeadLight2;
%obj.mountObject(%obj.jeepHlight1, 10);
%obj.mountObject(%obj.jeepHlight2, 11);
}
#3
I don't have an answer for question 1, but looking at item.cpp, it seems
As for question 2; Have you tried to use mountObject?
Hope it helps :P
01/11/2011 (8:35 pm)
Quote:searchterm0 searchtermn :torquepowered.comOr just use this. Basically the same, just compressed into a nice search bar with some ratio boxes.
I don't have an answer for question 1, but looking at item.cpp, it seems
Item::registerLights(LightManager * lightManager, bool lightingScene)Is never called. This is most likely something that got droped when torque got upgraded to Advanced Lighting. And i guess reviving it is not an easy task btw.
As for question 2; Have you tried to use mountObject?
%obj.mountObject(%obj_to_mount, %node_index);Not sure it will follow the node if you animate it, but it shouldn't be hard to fix if it doesn't. As for a package like object, i haven't tested it, but maybe a prefab would work. If not you could just modify the onAdd callback a little like Deepscratch showed.
Hope it helps :P
#4
As soon as you want to use mountObject, the thing you place in your level has to get promoted a bit. That is, just placing meshes down in the level, they're very lightway TSStatics. You can even give them an ambient animation, and it will play. But as soon as you want to mount an object on it (like a light), then it has to become a Item. This means creating an Item Datablock for it, instantiating it through scripted objects in the editor, and creating an onAdd function that creates your light and mounts it to the object. That's not too bad of a promotion though, and if you specify that the item is static, then it will save on network traffic as wel.
But that still didn't get exactly what I wanted, as I wanted to mount the object to a node on the mesh, that would animate. MountObject only specifies a slot to mount to, and by default orients it to the same orientation as the object you mounted to. You can provide an arbitrary orientation, but if that node animates, the object's orientation won't be updated. Note -- this is different than mounting an Image, which does update it's orientation according to the node at which you mount it. But you can't mount lights as images.
Fortunately, again AFX (Arcane FX) comes to the rescue. I created a very small effectron datablock that added the light as a single effect. In the datablock's onAdd callback, I instantiate the effectron and give it the spotlight "item" as the constraint. And afx effects allow you to specify a node on an object as a constraint, so I could mount the light to the spotlight node, orient it, and it animates perfectly!
I've said it before but I'll say it again -- if you are creating any signficant game in T3D and you haven't yet integrated Faust Logic's excellent effects addon package into your game - do it now. This package is so incredibly useful in so many ways, I wouldn't consider building a T3D game without it.
Thanks to those that replied - definitely got me thinking in the right direction!
Dusty
01/26/2011 (7:15 am)
So just a bit of an update here, for those interested. Mounting the light as an object to the spotlight requires a number of steps, and in the end, wasn't entirely satisfactory. Here's why:As soon as you want to use mountObject, the thing you place in your level has to get promoted a bit. That is, just placing meshes down in the level, they're very lightway TSStatics. You can even give them an ambient animation, and it will play. But as soon as you want to mount an object on it (like a light), then it has to become a Item. This means creating an Item Datablock for it, instantiating it through scripted objects in the editor, and creating an onAdd function that creates your light and mounts it to the object. That's not too bad of a promotion though, and if you specify that the item is static, then it will save on network traffic as wel.
But that still didn't get exactly what I wanted, as I wanted to mount the object to a node on the mesh, that would animate. MountObject only specifies a slot to mount to, and by default orients it to the same orientation as the object you mounted to. You can provide an arbitrary orientation, but if that node animates, the object's orientation won't be updated. Note -- this is different than mounting an Image, which does update it's orientation according to the node at which you mount it. But you can't mount lights as images.
Fortunately, again AFX (Arcane FX) comes to the rescue. I created a very small effectron datablock that added the light as a single effect. In the datablock's onAdd callback, I instantiate the effectron and give it the spotlight "item" as the constraint. And afx effects allow you to specify a node on an object as a constraint, so I could mount the light to the spotlight node, orient it, and it animates perfectly!
I've said it before but I'll say it again -- if you are creating any signficant game in T3D and you haven't yet integrated Faust Logic's excellent effects addon package into your game - do it now. This package is so incredibly useful in so many ways, I wouldn't consider building a T3D game without it.
Thanks to those that replied - definitely got me thinking in the right direction!
Dusty
Torque Owner Netwyrm
Canopic Games
searchterm0 searchtermn :torquepowered.com
you will be able to turn up the unlocatable articles fairly readily. I've been using this as a stopgap. Note the colon in front of "torquepowered.com".