MountObject VS MountImage
by Steve Lamperti · in Torque Game Engine · 09/02/2004 (9:27 am) · 55 replies
I am working with mounting objects onto other objects. Objects, not Images, therefore the topic title.
It's all been working great, until I tried to use a 'mountPoint' node on the object that is to be mounted that was somewhere other then the default bottom of the object.
Looking at the code, it looks like the 'mountPoint' on the object/image to be mounted is only supported for Images and Players, not other shapebase objects. Does this sound right to those of you more familiar with the code then me, or am I missing something here?
I would appreciate any feedback.
It's all been working great, until I tried to use a 'mountPoint' node on the object that is to be mounted that was somewhere other then the default bottom of the object.
Looking at the code, it looks like the 'mountPoint' on the object/image to be mounted is only supported for Images and Players, not other shapebase objects. Does this sound right to those of you more familiar with the code then me, or am I missing something here?
I would appreciate any feedback.
#22
07/05/2005 (9:38 am)
One thing that was missing from my code above was that I had added a mountPoint variable and the code to set it to my ExtendItem object. Also, I have since moved my call to moveToMountedLocation to advanceTime from processTick.
#23
What do you mean by 'I had added a mountPoint varialbe and the code to set it to my ExtendItem object.'? I don't quite understand what you mean by that. Do you mean the mount0, mount1, etc. node on the object you are mounting your ExtendItem to? How exactly did you 'add' that to the code... might you have an example... :)
Anyway, thanks again!
I just tried mounting my object using mountImage instead of mountObject and they are not properly mounted at their 'mountPoint' node... so I am questioning whether it is actually my code that is the problem or whether there is something wrong with the mountPoint/mount0 nodes themselves...
Any help you could provide would be greatly appreciated!
07/05/2005 (9:41 am)
Thank you very much for the reply Steve.What do you mean by 'I had added a mountPoint varialbe and the code to set it to my ExtendItem object.'? I don't quite understand what you mean by that. Do you mean the mount0, mount1, etc. node on the object you are mounting your ExtendItem to? How exactly did you 'add' that to the code... might you have an example... :)
Anyway, thanks again!
I just tried mounting my object using mountImage instead of mountObject and they are not properly mounted at their 'mountPoint' node... so I am questioning whether it is actually my code that is the problem or whether there is something wrong with the mountPoint/mount0 nodes themselves...
Any help you could provide would be greatly appreciated!
#24
During the onAdd code, I call the following code to set the value of the mountPoint variable;
The advanceTime code I was referring to is below;
I don't recall why I needed to do this three times, but it may have helped with some kind of redraw issue. (This code is probably not terribly fast.)
07/05/2005 (9:57 am)
I have created an object type (in C++ ) that is a descendent of Item. (Called an ExtendItem.) because I was struggling with the two problems I mentioned above, I had to add some stuff to my object that was not in Item. One of the things I added was an instance variable called mountPoint, which was set to the mountPoint of the Item. This is then the mountPoint variable referred to in my moveToMountedLocation routine above.During the onAdd code, I call the following code to set the value of the mountPoint variable;
// JSL - find the mountPoint on the item
myShape = (TSShape *) getShape();
if (myShape)
mountPoint = myShape->findNode("mountPoint");The advanceTime code I was referring to is below;
void ExtendBase::advanceTime(F32 dt)
{
long i;
GameBase::advanceTime(dt);
// JSL - move the mounted item to the correct location to
// account for animation movement (Robot arm, forklift.)
for(i = 0; i < 2; i++)
{
ShapeBase *mounted = getMountNodeObject(i);
if (mounted)
{
ExtendItem* eItem = dynamic_cast<ExtendItem*>(mounted);
if (eItem)
eItem->moveToMountedLocation();
}
}
}I don't recall why I needed to do this three times, but it may have helped with some kind of redraw issue. (This code is probably not terribly fast.)
#25
07/05/2005 (10:24 am)
Sorry, I posted that code without thinking about it much. Obviously, the advanceTime code is not in my ExtendItem object, but rather in the objects that the ExtendItems are mounted onto, and the reason why there are three calls, is that I could have potentially up to three Items mounted on the Base object on up to three mount nodes.
#26
I have come to the temporary conclusion that there is something wrong with my model(s). I tried mounting my object using mountImage (and just letting the default Torque code handle the mountPoint/mount0 transforms on its own) and it still didn't match-up the mountPoint and the mount0 nodes properly... which must mean that something else is wrong... right?
I really can't understand what could be going on now though as mountImage is mounting my object quite a ways off of its mountPoint. The worst part is that everything looks great in the Torque Show Tool Pro!!! Ahhh!!!
Hehe... anyway, back to the drawing board... :(
07/05/2005 (11:00 pm)
Thanks a bunch for posting your work Steve... I very much appreciate the help.I have come to the temporary conclusion that there is something wrong with my model(s). I tried mounting my object using mountImage (and just letting the default Torque code handle the mountPoint/mount0 transforms on its own) and it still didn't match-up the mountPoint and the mount0 nodes properly... which must mean that something else is wrong... right?
I really can't understand what could be going on now though as mountImage is mounting my object quite a ways off of its mountPoint. The worst part is that everything looks great in the Torque Show Tool Pro!!! Ahhh!!!
Hehe... anyway, back to the drawing board... :(
#27
01/27/2006 (12:45 pm)
I had a simular issue on another post about my chair. The character was mounting the chair at his feet. Then someone suggested that it had to do with a node in the character not the chair and I would have to move the character to account for the node.
#28
%obj.mountObject(%col,0);
where obj is the vehicle, col is the Item which I want to now mount to the vehicle at the mount point 0.
Does anyone have experience that this should or shouldn't work? Like I said, mountImage worked but I don't think I can do an animation with just an Image.
03/23/2006 (10:37 pm)
I'm not getting far enough to even have a mount location problem with mountObject(...). I am trying to mount an Item to a Vehicle. I can do a mountImage(...), but I need the object to do an animation which is why I'm trying to do a mountObject(...). Here is my simple code:%obj.mountObject(%col,0);
where obj is the vehicle, col is the Item which I want to now mount to the vehicle at the mount point 0.
Does anyone have experience that this should or shouldn't work? Like I said, mountImage worked but I don't think I can do an animation with just an Image.
#29
this is what works perfectly for me:
03/24/2006 (12:03 am)
That should work, at least it does for me... not sure you can mount Items, though, maybe try some static shape first...this is what works perfectly for me:
for(%i=0;%i<%numObjs;%i++)
{
%this.falter[%i] = new StaticShape() {
dataBlock = %db;
// set some random pos, doesn't matter since we mount it anyways :P
position = "419.953 -527.676 95.5";
rotation = "0 1 0 285.347";
};
%this.falter[%i].playThread(0,"fly");
%this.mountObject(%this.falter[%i],%i);
...
#30
Edit: After a quick look at the shapeBase source code, it turns out the shapeBase does not handle updating the transform for mounted objects. You might want to put something like this in the Item::processTick method(and something similar in interpolateTick or advanceTime):
03/24/2006 (1:34 am)
Items are ShapeBases so, in theory you should be able to mount object/images to them, and mount them to other objects. If it doesn't seem to be working, the Item code might be ignoring/overwriting the shapeBase mounting system.Edit: After a quick look at the shapeBase source code, it turns out the shapeBase does not handle updating the transform for mounted objects. You might want to put something like this in the Item::processTick method(and something similar in interpolateTick or advanceTime):
if(isMounted()) {
MatrixF mat;
mMount.object->getMountTransform(mMount.node,&mat);
setTransform(mat);
}
#31
03/24/2006 (9:01 am)
Josh's code above is a version of something I had to add to the engine to support object mounting as well. This does seem like it should be corrected in the engine.
#32
03/24/2006 (9:06 am)
Thanks guys. I'll give it a try.
#33
03/28/2006 (5:56 am)
It worked. Thanks. This should be standard in the Item class methods.
#34
check out my Hierarchical Coordinate Spaces resource, and note the bug fix someone added to the thread. I do not, alas, support mount points being expressed in a DTS file. I'd be glad to hear your feedback.
tone
03/28/2006 (12:50 pm)
I feel it should be standard in the SceneObject class, and that it should be fully dynamic (i.e.: mount points should be expressable in script, not merely in 3D authoring).check out my Hierarchical Coordinate Spaces resource, and note the bug fix someone added to the thread. I do not, alas, support mount points being expressed in a DTS file. I'd be glad to hear your feedback.
tone
#35
06/14/2006 (10:25 am)
Sorry to bring up this thread again. But the stand tge with tlk this doesn't work. Though mounting of objects in Show Tool Pro works perfectly. Anyone that worked on Show Tool Pro did you use the above code? or did you put in your own code? If you used your own code.. would you care to share it?
#36
09/14/2006 (3:12 am)
I want to know this too. And any more info on mount points too.
#37
In Maya, everything looks fine. In Showtool, everything mounts just fine. However, during game play, the battery is not mounted properly, there's always a messed up offset or gap.
I tried applying Josh Moore's code suggesion inside of ShapeBase::advanceTime() and ShapeBase::processTick(), but I yield the same results.
Any suggestions?
11/08/2006 (1:19 pm)
Giving this thread a bump, since I'm having this problem now as well. I'm trying to mount one object (a battery) to another object (device).[b]// Defined the datablocks[/b]
datablock StaticShapeData(Battery)
{
category = "CP100";
shapeFile = "~/data/shapes/battery/battery.dts";
mass = 3;
friction = 1;
elasticity = 0.3;
};
datablock StaticShapeData(GPS)
{
category = "CP100";
shapeFile = "~/data/shapes/gps/gps.dts";
mass = 3;
friction = 1;
elasticity = 0.3;
};
[b]// This function creates them in the world for me[/b]
function spawnItems()
{
new StaticShape(testBattery) {
position = "110.656 -219.889 125.094";
rotation = "1 0 0 0";
scale = "1 1 1";
dataBlock = "Battery";
};
new StaticShape(testGPS) {
position = "110.571 -219.224 125.094";
rotation = "1 0 0 0";
scale = "1 1 1";
dataBlock = "GPS";
};
$GPS = testGPS;
$Battery = testbattery;
}
[b]//This function mounts the objects[/b]
function mountBatteryToGPS()
{
$GPS.mountObject($Battery, 0);
}In Maya, everything looks fine. In Showtool, everything mounts just fine. However, during game play, the battery is not mounted properly, there's always a messed up offset or gap.
I tried applying Josh Moore's code suggesion inside of ShapeBase::advanceTime() and ShapeBase::processTick(), but I yield the same results.
Any suggestions?
#38
11/13/2006 (11:36 am)
Is there a way to investigate how the Showtool handles mounting in it's code?
#39
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=10304
11/13/2006 (12:52 pm)
[plug]This resource should help you. You can control the rotation, offset, and scale in the datablock[/plug]www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=10304
#40
this mounts shape 'b' at mount point 5 on shape 'a'. if there is no mount point 5 it will mount in the center of the object. you need a mount point node 5 (mount5) on shape A and a node named mountPoint on shape B.
btw: if your trying to mount an image you have to define what mountPoint the image mounts to in its datablock:
{
...
mountPoint = 5;
...
}
11/13/2006 (1:12 pm)
%shapeA.mountObject( %shapeB, 5);this mounts shape 'b' at mount point 5 on shape 'a'. if there is no mount point 5 it will mount in the center of the object. you need a mount point node 5 (mount5) on shape A and a node named mountPoint on shape B.
btw: if your trying to mount an image you have to define what mountPoint the image mounts to in its datablock:
{
...
mountPoint = 5;
...
}
Torque 3D Owner Stephane Conde
The model that is being mounted definitely has a valid mountPoint node and the model that is having the object mounted to it has a valid mount0 node. I have checked both these nodes by printing out their locations according to Torque and comparing it with the values in the Torque Show Tool Pro.
I have tried Steve's code above with many different permutations (Steve, you need to do this for both setTransform and setRenderTransform to get things working over the network, I believe) but it doesn't seem to make the objects mount at the correct locations.
Does anyone know if there has ever been working code in Torque to get two objects (NOT images) mounting at the correct locations? Do vehicles not use mountObject to mount a player to the vehicle?
Any insight anyone can offer would be greatly appreciated as I have been struggling with this issue on and off for about a year now! If you need any more information, also please let me know...