Combining objects/datablocks?
by Aaron Moore · in Torque Game Engine · 05/23/2007 (11:53 pm) · 24 replies
I'm not sure if this can be done but I thought I'd try. I've looked but haven't really seen anything about it.
My question is whether or not you can combine different types of objects to be a single entity. For example I have a torch that belongs in my castle...
It consists of a model, a light, and particle effects(fire).
Now I have these set and need to make a couple dozen of these for different parts of my castle. Can I combine these as a single object so I'm dealing with only the Torch object, or do I need to deal with 3 of these every time I go to position one of them (effectively dealing with "a couple dozen" x 3)?
If it's possible, how would I go about it? A single datablock deriving from the other 3 as base classes?
My question is whether or not you can combine different types of objects to be a single entity. For example I have a torch that belongs in my castle...
It consists of a model, a light, and particle effects(fire).
Now I have these set and need to make a couple dozen of these for different parts of my castle. Can I combine these as a single object so I'm dealing with only the Torch object, or do I need to deal with 3 of these every time I go to position one of them (effectively dealing with "a couple dozen" x 3)?
If it's possible, how would I go about it? A single datablock deriving from the other 3 as base classes?
#2
05/24/2007 (4:35 am)
A quick and dirty way of doing it would be to write some script in the onAdd method for the torch dts datablock. You can have the light and particle node created every time a torch is placed in the scene.
#3
05/24/2007 (5:27 am)
You can mount the light to the dts object. Look at SpotSwingStaticShape in the sgExamples.cs.
#4
My education is very heavy in programming so I knew I could probably work it out by going into the engine, but I figure if there's an easier and simpler way to do it, why re-invent the wheel?
Thanks!
05/24/2007 (6:02 am)
Got the light mounted...I'll try and see if the particle effect can be done in a similar way. Thanks for the help.My education is very heavy in programming so I knew I could probably work it out by going into the engine, but I figure if there's an easier and simpler way to do it, why re-invent the wheel?
Thanks!
#5
05/24/2007 (6:47 am)
I second what Tim said. Create & mount in the ::onAdd.
#6
Also, when I mount the light to the shape it works, but it also creates a light object (without light) in the middle of the mission. It seems to be sort of a dummy object. When I move my shape, it's actually lit and there's light all around it and it moves with the shape, but if I delete the dummy object it disappears.
05/24/2007 (8:13 am)
Can't seem to mount he particles to the shape.Also, when I mount the light to the shape it works, but it also creates a light object (without light) in the middle of the mission. It seems to be sort of a dummy object. When I move my shape, it's actually lit and there's light all around it and it moves with the shape, but if I delete the dummy object it disappears.
#7
Hard to help you more than that without seeing some code.
05/24/2007 (8:16 am)
Check out the particle editor script for a guide on how to spawn a particle emitter node.Hard to help you more than that without seeing some code.
#8
05/24/2007 (2:04 pm)
Can you give screen shots of dummy object, I have never had this happen. There maybe something wrong with the way you mounting it. Do you have mountpoint in dts you are mounting the light to?
#9
My scripting:
The result when I instantiate this in the world editor:

The selected object is the extra light that isn't a light. You can see the torch is lit, but you can also see the light in the tree view. Also, it isn't on top of the torch like I would expect it to be (like being parented to the torch). Instead, it's sitting at 0 0 0 doing nothing.
As for the particles, I already thought about spawning the particles with the torch and setting its position to whatever the position is of the torch, but that doesn't parent the particles to the torch like I'm hoping for.
BTW, the particle editor...is there a way to actually use this? I've been doing all my particles through script.
05/24/2007 (8:38 pm)
EDIT: Ah! I just found that SpotSwingStaticShape in the sgExamples.cs file does the same exact thing. I guess it's normal and if I want to do it this way I just have to deal with having a couple dozen dummy objects at 0 0 0.My scripting:
datablock StaticShapeData(TorchShape)
{
category = "LightSources";
className = "Torch";
shapeFile = "~/data/shapes/Torch/Torch.dts";
};
function Torch::onAdd(%this, %obj)
{
%obj.playthread(0, "ambient");
%light = new sgLightObject() {
dataBlock = "sgTowerFireLightDataBlock";
canSaveDynamicFields = "1";
rotation = "1 0 0 0";
scale = "1 1 1";
dataBlock = "sgTowerFireLightDataBlock";
Enable = "1";
IconSize = "1";
ParticleColorAttenuation = "1";
};
%light.attachtoobject(%obj);
}The result when I instantiate this in the world editor:

The selected object is the extra light that isn't a light. You can see the torch is lit, but you can also see the light in the tree view. Also, it isn't on top of the torch like I would expect it to be (like being parented to the torch). Instead, it's sitting at 0 0 0 doing nothing.
As for the particles, I already thought about spawning the particles with the torch and setting its position to whatever the position is of the torch, but that doesn't parent the particles to the torch like I'm hoping for.
BTW, the particle editor...is there a way to actually use this? I've been doing all my particles through script.
#10

Here picture using same light datablock that you used.

Couple problems I see. I always make copy of the light datablock and rename it, for example sgMountLanternTower. It tell me I am mount the light, what dts the light is mounted too and what light datablock I made copy of. I make copies so I still have the original untouch.
The light datablock you are use dont have mountPoint, MountPosition or MountRotation. You will need to add these, look at sgMountLight.cs in common/lighting/lights about line 68 to see what I am talking about.
05/25/2007 (5:47 am)
What engine you using? I am using TGE 1.5.2. Do you have a mount point in the Torch? If not you will need one. Can you send me your script and model, I have never had this happen. This is what you should be getting. 
Here picture using same light datablock that you used.

Couple problems I see. I always make copy of the light datablock and rename it, for example sgMountLanternTower. It tell me I am mount the light, what dts the light is mounted too and what light datablock I made copy of. I make copies so I still have the original untouch.
The light datablock you are use dont have mountPoint, MountPosition or MountRotation. You will need to add these, look at sgMountLight.cs in common/lighting/lights about line 68 to see what I am talking about.
#11
And I'm using Torque 1.5.2 as well.
This is the best way to show what's going on for me...



I guess the extra object is just something I'm gonna have to live with. it appears when I use the sgMountLight as well. As for the location of the extra object, could it be because:
I think I could deal with the extra object in the world inspector if it was least at the same place/moved with the torch object.
you asked for my model, you want the DTS to look at it in showtool? or do you want my .blend file (I'm using blender)
05/25/2007 (6:34 am)
MountPoint = "0"; MountPosition = "0 0 0"; MountRotation = "1 0 0 0"; };
And I'm using Torque 1.5.2 as well.
This is the best way to show what's going on for me...



I guess the extra object is just something I'm gonna have to live with. it appears when I use the sgMountLight as well. As for the location of the extra object, could it be because:
MountPosition = "0 0 0";?
I think I could deal with the extra object in the world inspector if it was least at the same place/moved with the torch object.
you asked for my model, you want the DTS to look at it in showtool? or do you want my .blend file (I'm using blender)
#12
MountPosition = "0 0 0"; // you can move the light left to right, forward and back and up and down
MountRotation = "1 0 0 0"; // the last number you can adjust the angle of the light.
05/25/2007 (9:42 am)
I cant tell from the new pictures but is the light mounting to dts now or away from it, like in the first screen shot. If it is mounting away from it you need a Mount0 in your dts. Yes I want look at it in showtool and test it with my script. I will not keep a copy when I am done testing I will delete it from my computer. If you like I can email you the lantern and you can drop that in your scripts.MountPosition = "0 0 0"; // you can move the light left to right, forward and back and up and down
MountRotation = "1 0 0 0"; // the last number you can adjust the angle of the light.
#13
I edited it and better centered it where it should be.
www.katalyststudios.com/images/Torch.zip
I actually sort of got it working. I added the fire particle to the script as well. When I'd add the object I'd position it right, then copy/paste the location to the light object and the particle effect so they'd both be exactly where I needed 'em and so I wouldn't have to manually add 3 different objects. When I reloaded the mission however the lighting was no longer attached to my particles (even though the editor says they were). I removed the particle effect/lighting added on when the torch model is instantiated and it fixed everything. So I think this is only going to work when I'm actually adding the torches, then when I'm done I'll have to comment out the extra light and particles to the model.
05/25/2007 (10:07 am)
It was always mounting to the dts, it was a trick of the terrain and the fact that my model wasn't centered that made it look funny in the first shot.I edited it and better centered it where it should be.
www.katalyststudios.com/images/Torch.zip
I actually sort of got it working. I added the fire particle to the script as well. When I'd add the object I'd position it right, then copy/paste the location to the light object and the particle effect so they'd both be exactly where I needed 'em and so I wouldn't have to manually add 3 different objects. When I reloaded the mission however the lighting was no longer attached to my particles (even though the editor says they were). I removed the particle effect/lighting added on when the torch model is instantiated and it fixed everything. So I think this is only going to work when I'm actually adding the torches, then when I'm done I'll have to comment out the extra light and particles to the model.
#14
05/25/2007 (10:16 am)
That what I am try to do now is get the fire particle to mount. I will take at look this and get back to you.
#15
Here another screenshot.

I hope this helps.
05/25/2007 (2:42 pm)
I have done alot testing today, I am not getting any problems you have. I create some dts in three different softwares. The light always mount to the mountpoint. I can move the dts around and light stay in the position it should. I can reload the missions without any problems. I am not getting the dummy light you have. I look at dts but show tool only show a little with blender models. Right now I would have to same your problems is with the dts. I dont think the dts file is setup correctly. I think you dont have a mountPoint in the dts or it is setup wrong. I can not be 100 percent sure, if you can email me your light datablock and script file for dts to make sure there is nothing wrong there. I create a dts without a mountPoint and I start having some of your problems with light not align up. I notice your texture is not correctly size for Torque. The one in zip is 200 x 200, it should be power of 2 (32 x 32, 64 x 64, 128 x 128, 128 x 256, 256 x 256, etc.)Here another screenshot.

I hope this helps.
#16
As for the script, it's above in my post.
In the explorer, I'm seeing the light on your screenshot.
If you click to select either of those volumeLights, where does it say the object is? (even though the light shows up on your object, is that where the exploere says the light is? or does it say the light is at "0 0 0"?
05/26/2007 (7:47 am)
Ah, I thought I read somewhere as long as the texture file is a square it's fine. I'll change it to 256x256.As for the script, it's above in my post.
In the explorer, I'm seeing the light on your screenshot.
Quote:
1533:volumeLight
1534:StaticShape
1536:volumeLight
1537StaticShape
If you click to select either of those volumeLights, where does it say the object is? (even though the light shows up on your object, is that where the exploere says the light is? or does it say the light is at "0 0 0"?
#17
It has the position of the object, but it should not matter what in light position. I am using a mount node so in my mission file I cannot move the light unless I move the dts. the volumeLight appears in the explore so you can adjust the light parameter. When mount lights to dts you should not use the light position to move it, only the position in the dts.
In the screenshot you will notice there is no handles on the light.

You will notice handles here because I have click dts.

If you need to tweak the light it should be done in the light datablock with MountPosition. But if you have mount point setup in your dts (model) you should not have to tweak the MountPosition only the MountRotation. You can use the mount point node in the dts where you want the light.
Your script looks good and your light datablock is good then the problem with light not mounting where it should is because your dts is not setup correctly. If you like I can email you one my dts to try.
05/26/2007 (8:27 am)
In your first screenshot your dts is a shade of gray that because the texture is incorrectly size and Torque will not load it. It has the position of the object, but it should not matter what in light position. I am using a mount node so in my mission file I cannot move the light unless I move the dts. the volumeLight appears in the explore so you can adjust the light parameter. When mount lights to dts you should not use the light position to move it, only the position in the dts.
In the screenshot you will notice there is no handles on the light.

You will notice handles here because I have click dts.

If you need to tweak the light it should be done in the light datablock with MountPosition. But if you have mount point setup in your dts (model) you should not have to tweak the MountPosition only the MountRotation. You can use the mount point node in the dts where you want the light.
Your script looks good and your light datablock is good then the problem with light not mounting where it should is because your dts is not setup correctly. If you like I can email you one my dts to try.
#18
I fixed the texture, and re-checked my mount...it looks correct here.
As for you clicking the volumeLight, no, there's no handle-bars...but look around, are there handlebars for the light that aren't where the light is shining? Handlebars for the light that are in the middle of nowhere?
my torch in the first image actually wasn't textured at all...I've fixed it (as you can see in the above image)
If you look at the previous images, my light IS actually attached to my torch. I move the torch, the light moves with it. However, if I click the light object in the explorer view, handlebars for it show up at 0 0 0. Now, if I move the handlebars nothing happens to the light...it's just annoying. Especially when I have to edit the light to attach the particle emitter to it. The handlebars shouldn't really get to me, they just seem...sloppy, or "dirty" as Tim Heldna described it.
I understand totally how you'd draw the conclusion of it being my .dts though (especially with the texture being wrong for torque). But I also have the same thing happen when I add the "SpotSwingStaticShape". It appears in the right place and the spotlight swings with the shape and all that...but there are handlebars at 0 0 0.
I assume there's still no way to mount or parent the fire particles to the torch? I've looked all over the forums and I only see people who want to do the same thing I'm doing, and no examples of people who have actually done it. I hear you mount particles to vehicles though. How easy do you suppose it'd be to make a new class copying the code out of the vehicle class and making it into a new class deriving from the same class "StaticShapeData" is derived from which is what the torch is currently?
EDIT: Actually, Fucifer...look in the top image of that latest post of yours. Look at the left edge of the picture about 2/3 of the way down. That little green arrow with the 'y' looks like to me like a handle-bar.
EDIT2: I just found Peter Simard's mounted particles solution...think this would work on my torch? I'm gonna attempt some modifications so that a light, if attached to an object, has it's properties appended to the object it's attached to, and also work out a system so that the mounted particle is created, mounted, and given a name dynamically, and if possible also has it's properties appended to the shape's properties. This might be tricky but it would clean up my editor so much when I have to place 50 torches in my mission so that I don't end up manually editing 150 objects just for my lighting. Later I can copy the script and change variables so that any other lightsources can be done the same way (candles and lanterns). Comments? Suggestions? Am I out of my mind?
05/26/2007 (9:17 am)
I fixed the texture, and re-checked my mount...it looks correct here. As for you clicking the volumeLight, no, there's no handle-bars...but look around, are there handlebars for the light that aren't where the light is shining? Handlebars for the light that are in the middle of nowhere?
my torch in the first image actually wasn't textured at all...I've fixed it (as you can see in the above image)
If you look at the previous images, my light IS actually attached to my torch. I move the torch, the light moves with it. However, if I click the light object in the explorer view, handlebars for it show up at 0 0 0. Now, if I move the handlebars nothing happens to the light...it's just annoying. Especially when I have to edit the light to attach the particle emitter to it. The handlebars shouldn't really get to me, they just seem...sloppy, or "dirty" as Tim Heldna described it.
I understand totally how you'd draw the conclusion of it being my .dts though (especially with the texture being wrong for torque). But I also have the same thing happen when I add the "SpotSwingStaticShape". It appears in the right place and the spotlight swings with the shape and all that...but there are handlebars at 0 0 0.
I assume there's still no way to mount or parent the fire particles to the torch? I've looked all over the forums and I only see people who want to do the same thing I'm doing, and no examples of people who have actually done it. I hear you mount particles to vehicles though. How easy do you suppose it'd be to make a new class copying the code out of the vehicle class and making it into a new class deriving from the same class "StaticShapeData" is derived from which is what the torch is currently?
EDIT: Actually, Fucifer...look in the top image of that latest post of yours. Look at the left edge of the picture about 2/3 of the way down. That little green arrow with the 'y' looks like to me like a handle-bar.
EDIT2: I just found Peter Simard's mounted particles solution...think this would work on my torch? I'm gonna attempt some modifications so that a light, if attached to an object, has it's properties appended to the object it's attached to, and also work out a system so that the mounted particle is created, mounted, and given a name dynamically, and if possible also has it's properties appended to the shape's properties. This might be tricky but it would clean up my editor so much when I have to place 50 torches in my mission so that I don't end up manually editing 150 objects just for my lighting. Later I can copy the script and change variables so that any other lightsources can be done the same way (candles and lanterns). Comments? Suggestions? Am I out of my mind?
#19
I have not look at the vehicles class but that a good idea. Your dts look outstanding, you did good job on that. Same here the other day I was working on something I was not see any change in Torque. I had the wrong script file open, I said to myslef I am losing my mind.
05/26/2007 (6:25 pm)
Sound like youi doing real well, I glad to hear it. I have been look at Peter Simard code too. I have not try, so I might have some questions for you about it. I hope you dont mind it. You know I never notice them handle there, I going to see If I can do some about it. If I fix them I will drop you line.I have not look at the vehicles class but that a good idea. Your dts look outstanding, you did good job on that. Same here the other day I was working on something I was not see any change in Torque. I had the wrong script file open, I said to myslef I am losing my mind.
#20
you can see my solution here http://www.garagegames.com/mg/forums/result.thread.php?qt=60640
now, as easy as it is to get particles to give off light, as of the lighting kit, im sure you could achieve a cool effect. keep in mind if you move the object the light wont follow, but next time you load the mission after all your editing it will appear on the shape in the right spot.
05/26/2007 (7:03 pm)
I was fighting this same fight trying to tie particle effects to objects, i found a solution but it required head changes to actually tie the effect to the object using mounts, but that lead to alot of crashing so i ended up taking a different approachyou can see my solution here http://www.garagegames.com/mg/forums/result.thread.php?qt=60640
now, as easy as it is to get particles to give off light, as of the lighting kit, im sure you could achieve a cool effect. keep in mind if you move the object the light wont follow, but next time you load the mission after all your editing it will appear on the shape in the right spot.
Torque Owner Aaron E
Default Studio Name
So, yes, it can be done. However, depending on your coding background, it may not be easy for you.