Game Development Community

dev|Pro Game Development Curriculum

guiObjectView - Mountable Animated DTS Viewer

by Loonatik · 12/22/2002 (4:35 pm) · 56 comments

Download Code File

Install Steps:

1) Extract guiObjectView.zip into torque/

2) Do a clean build of torque

3) Extract objectViewExample.zip if needed



Usage:

"objectName" was used to identify an object, to allow you to reference it later on for things like setSequence.

// objectName, shape, skin, detail
view.setObject("objectName", "fps/data/shapes/object/object.dts", "", 0);
Sets the main object for the scene. Calling this again after the scene has a main object will cause everything to get unloaded and the new object to be loaded.

// objectName, shape, skin, parentNode, detail
view.mountObject("objectName", "fps/data/shapes/object/object.dts", "", "nodeName", 0);
Allows you to mount an object containing a node called mountPoint, to any node on the Main Object. Mounting an object to the same nodeName will cause the previous object to be unmounted.

// objectName, nodeName
view.unMountObject("objectName", "");
view.unMountObject("", "nodeName");
This allows you to unMount an object from the main object by either specifying the object name or the nodeName of the object.

// objectName, dsq
view.loadDSQ("objectName", "fps/data/shapes/object/object_animation.dsq");
This allows you to load dsq files for the specified object. Note: not all objects require you to load a DSQ to use thier sequence. An example would be the chaingun from tribes2.

// objectName, sequence, time
view.setSequence("objectName", "sequenceName", 1);
This allows you to run a sequence for the specified object. You can also control how fast or slow the sequence will play by using time.

//
view.setEmpty();
This clears the current scene of all objects.



Example:

Here is an example of how to load up a player object, mount a weapon and a pack. (saying you had these objects)

You can also animate mounted objects if they have sequences by using the same code that you did with player.

// Load the player up
view.setObject("player", "fps/data/shapes/player/player.dts", "", 0); // Example player, with default skin and detail level of 0
view.loadDSQ("player", "fps/data/shapes/player/player_root.dsq"); // Load up the root sequence
view.setSequence("player", "Root", 1); // Set the sequence to Root

// Mount the objects
view.mountObject("weapon", "fps/data/shapes/rifle/weapon.dts", "", "mount0", 0); // Example weapon with default skin and detail level of 0
view.mountObject("pack", "fps/data/shapes/pack1/pack.dts", "", "mount1", 0); // Example pack with default skin and detail level of 0

// Get rid of the pack
view.unMountObject("pack", ""); or view.unMountObject("", "mount1");

Todo:

* Better camera options are next, should be able to bust this out within a few days. I plan to add the ability to have it spin, and work on making it fit better.

* We really plan to expose all the animation options, including blending, multiple threads, and sound.

* Our other goal from this will be to create a Player Selection example. Which will allow people to pick a player model and customize its apperance and skin. Then allow you to load that customized object within the game.

About the author

Recent Blogs

Page «Previous 1 2 3 Last »
#1
12/18/2002 (10:42 am)
Very very very nice!! :D Works like a charm!
Thanks a lot :)
#2
12/22/2002 (5:18 pm)
Great work, although I am biased since it was partially developed for my game.

Smurf, have you talked to loonatik anytime soon? He's been missing for days. :)
#3
12/22/2002 (8:40 pm)
We should be releasing a new version with better camera support shortly. Will keep you posted.
#4
12/24/2002 (6:39 am)
Awesome, great addition for any multiplayer game.
#5
01/04/2003 (10:41 am)
Awesome snippet!
#6
01/30/2003 (2:35 pm)
My model is cropped. How do I set the distance between the camera and the model? I'm doing something wrong.

Thanks,

Robert
#7
03/16/2003 (8:51 pm)
Robert...

Below is one method I used to solve the camera to model issue by modifying GuiObjectView::processCameraQuery in guiObjectView.cc change the divisor in the assigment to a smaller value to increase the field of view or to a larger value to decrease it. EG:

query->fov = 3.1415 / 2.5;

Regards,

Mark
#8
03/16/2003 (10:26 pm)
Fantastic Mark Owen! Thank you. Seems like this would be a good parameter to set from the gui script.

Robert
#9
04/07/2003 (2:48 pm)
I wonder if there's a simple way to keep track of the currently active model. The problem with the current setup is that "setSequence" requires you to chooose a model in the script for the button actions. This is as opposed to say, having several player scripts and being able to run the "run" or "back" animation on any character model you load.
#10
06/13/2003 (1:39 am)
Hey guys,

I am getting this error:
Unable to find object: 'view' attempting to call function 'setObject'

When applying the view.blah functions like this:
function UnitsPane::onWake(%this){ // Create Drop List Menus using names of created items

...Some Code...

	view.setObject("player", "fps/data/shapes/player/player.dts", "", 0);
}

I was looking at the example provided and it looks like "view" is static. I seem to be missing something fundamental. I tried replacing "view" with the parent Gui object "TroopConfigGui" and with %this, but I am having no luck.

Any idea's?

Thanks,
-Jeff
#11
06/15/2003 (7:15 am)
Got it working, but I am having some difficulty with the main models mounted objects not always showing up. It's probably me, so I will poke around more. Did anyone else have this problem?

EDIT:
Is there a way to get the handle to the ObjectName? I want to do condition tests based on its existance.

Found why the attachments weren't always showing up. I guess when you forget to put mountPoint on each of the attaching models, things can get wierd. :)

Thanks,
-Jeff
#12
07/04/2003 (8:31 am)
Loading the dsq's seems to cause problems with client connections. When a client player dies for example it doesn't play the correct animation. I think it tries to play one of the loaded animations instead of the death one like it should. As soon as I comment out the load dsq lines it works fine.

Edit: It works fine if I use a different copy of the dts player model for the viewer then the one used in the game.
#13
11/19/2003 (1:55 pm)
Alright, I got it loaded up as stated in the readme's, but it doesnt display the player. I havent changed any of the code supplied in the example. Any advice on why it doesnt work? Thanks.
#14
01/13/2004 (8:12 am)
Some updates you can do...

--------------------------------
Script-based "setCamera":

guiObjectView.h - put this next to the other setCamera
void setCamera(F32 rX, F32 rY, F32 rZ, F32 dist);

guiObjectView.cc - as above, just put it below the other setCamera definition
void GuiObjectView::setCamera(F32 rX, F32 rY, F32 rZ, F32 dist)
{
	// Make sure there is a main object in the scene
	if (mMeshObjects.mMainObject)
	{
		F32 degToRad = (M_PI / 180);
		mCameraRot.x = rX * degToRad;
		mCameraRot.y = rY * degToRad;
		mCameraRot.z = rZ * degToRad;
		// Initialize camera values:
		mOrbitPos = mMeshObjects.mMainObject->getShape()->center;
		mMinOrbitDist = mMeshObjects.mMainObject->getShape()->radius;
		mOrbitDist = dist > mMinOrbitDist ? dist : mMinOrbitDist;
	}
}

Same file, put this somewhere, I put it below the other console definitions (under setSequence)
// Script function handling for "setCamera"
ConsoleMethod( GuiObjectView, setCamera, void, 6, 6, "ObjectView.setCamera(x, y, z, dist)" )
{
	argc;
	GuiObjectView* view = static_cast<GuiObjectView*>( object );
	view->setCamera(dAtof(argv[2]), dAtof(argv[3]), dAtof(argv[4]), dAtof(argv[5]));
}


--------------------------------
Add in roll:
guiObjectView.cc - replace processCameraQuery definition with this one
bool GuiObjectView::processCameraQuery( CameraQuery* query )
{
	// Make sure the orbit distance is within the acceptable range:
	mOrbitDist = ( mOrbitDist < mMinOrbitDist ) ? mMinOrbitDist : ( ( mOrbitDist > MaxOrbitDist ) ? MaxOrbitDist : mOrbitDist );

	// Adjust the camera so that we are still facing the model:
	Point3F vec;
	MatrixF xRot, yRot, zRot, t;
	xRot.set( EulerF( mCameraRot.x, 0, 0 ) );
	yRot.set( EulerF( 0, mCameraRot.y, 0 ) );
	zRot.set( EulerF( 0, 0, mCameraRot.z ) );

	mCameraMatrix.mul( zRot, xRot );
	mCameraMatrix.mul( mCameraMatrix, yRot );
	mCameraMatrix.getColumn( 1, &vec );
	vec *= mOrbitDist;
	mCameraPos = mOrbitPos - vec;

	query->nearPlane = 0.1;
	query->farPlane = 2100.0;
	query->fov = 3.1415 / 3.5;
	mCameraMatrix.setColumn( 3, mCameraPos );
	query->cameraMatrix = mCameraMatrix;
	return( true );
}

Note that the way I did it, you'll need to use setCamera to roll the view. Perhaps you could add a flag to make right mouse roll instead of zoom?
#15
02/29/2004 (12:47 pm)
Guys, if you are still monitoring this, ever had problems like this:
www.garagegames.com/mg/forums/result.thread.php?qt=16485 ?
#16
09/13/2004 (12:23 pm)
This resource does not appear to work in head (receives an error that it cannot find the command 'setObject'.). I installed it then tried using the demo that comes with it, however I received that error and no models were displayed at all.

Anyone else having this problem?

(This is head as of September 10'th, 2004).
#17
02/19/2005 (6:25 pm)
I get the following from my console errors..

CombatMechanix/client/scripts/objectViewExample.cs (18): Unable to find object: 'view' attempting to call function 'setObject'
CombatMechanix/client/scripts/objectViewExample.cs (21): Unable to find object: 'view' attempting to call function 'loadDSQ'
CombatMechanix/client/scripts/objectViewExample.cs (22): Unable to find object: 'view' attempting to call function 'loadDSQ'
CombatMechanix/client/scripts/objectViewExample.cs (23): Unable to find object: 'view' attempting to call function 'loadDSQ'
CombatMechanix/client/scripts/objectViewExample.cs (24): Unable to find object: 'view' attempting to call function 'loadDSQ'
CombatMechanix/client/scripts/objectViewExample.cs (27): Unable to find object: 'view' attempting to call function 'setSequence'
keyboard0 input device created.
mouse0 input device created.
(0): Unable to find object: 'view' attempting to call function 'setSequence'
(0): Unable to find object: 'view' attempting to call function 'setSequence'
(0): Unable to find object: 'view' attempting to call function 'mountObject'
(0): Unable to find object: 'view' attempting to call function 'unmountObject'
CombatMechanix/client/scripts/objectViewExample.cs (0): Unable to find object: 'view' attempting to call function




Am I missing something simple here? The code instances "view" in the objectViewExample GUI File:

new GuiObjectView(view) {
profile = "GuiDefaultProfile";
horizSizing = "relative";
vertSizing = "relative";
position = "0 0";
extent = "400 400";
minExtent = "8 2";
visible = "1";
helpTag = "0";
cameraZRot = "0";
forceFOV = "0";
};
Thanks in advance for the help..
#18
03/01/2005 (6:25 pm)
Dan: just try a clean rebuild of your engine.. that should do it ;o)
#19
06/06/2005 (7:38 pm)
something clever add this from after the animate call if you want a trigger call back
for (S32 ti = 1; ti < 33; ti++) { 
  if (mMeshObjects.mMesh[i].mesh->getTriggerState(ti)) {
   char buf1[20]; 
  dSprintf(buf1,sizeof(buf1),"%d",ti); 
  Con::executef(this,2,"onTrigger",buf1);
}}

then in script
function ObjectView::onTrigger(%this, %num){
         echo("trigger" SPC %num );
}
#20
06/08/2005 (1:06 pm)
Just a note. The first time I ran the sample gui with my own dts files animations would not run when I setSequence with names like "Root" and "Forward".

This was the result of my forgetting to name the sequence nodes in my Max file before I ran the exporter. I'm sure this wasn't news to a lot of other folks but it was news to me when I found out that dsq files have sequence names embedded inside themselves based on the name of the sequence node that triggered the export.

So, if you want to be able to refer to a sequence "Root" by name on the shape level you must name the sequence node that triggers the export as "Root" or you'll end up over writing your animation over and over under what ever name the node defaulted to when it was created. (Mine was "Sequence01").

I was able to find this out after I wrote a little program that dumps the list of names associated with meshes inside GuiObjectView. I'm still working on ignoring empty slots in the mesh list. I'll be sure to put the code up here once it's done. It's a stupid utility but useful never the less.
Page «Previous 1 2 3 Last »