|
A scriptable, renderable shape. More...
Public Member Functions | |
void | applyDamage (float amount) |
Increment the current damage level by the specified amount. | |
bool | applyImpulse (Point3F pos, Point3F vec) |
Apply an impulse to the object. | |
void | applyRepair (float amount) |
Repair damage by the specified amount. | |
bool | canCloak () |
Check if this object can cloak. | |
void | changeMaterial (string mapTo, Material oldMat, Material newMat) |
Change one of the materials on the shape. | |
bool | destroyThread (int slot) |
Destroy an animation thread, which prevents it from playing. | |
void | dumpMeshVisibility () |
Print a list of visible and hidden meshes in the shape to the console for debugging purposes. | |
Point3F | getAIRepairPoint () |
Get the position at which the AI should stand to repair things. | |
float | getCameraFov () |
Returns the vertical field of view in degrees for this object if used as a camera. | |
int | getControllingClient () |
Get the client (if any) that controls this object. | |
int | getControllingObject () |
Get the object (if any) that controls this object. | |
float | getDamageFlash () |
Get the damage flash level. | |
float | getDamageLevel () |
Get the object's current damage level. | |
float | getDamagePercent () |
Get the object's current damage level as a percentage of maxDamage. | |
string | getDamageState () |
Get the object's damage state. | |
float | getDefaultCameraFov () |
Returns the default vertical field of view in degrees for this object if used as a camera. | |
float | getEnergyLevel () |
Get the object's current energy level. | |
float | getEnergyPercent () |
Get the object's current energy level as a percentage of maxEnergy. | |
Point3F | getEyePoint () |
Get the position of the 'eye' for this object. | |
TransformF | getEyeTransform () |
Get the 'eye' transform for this object. | |
VectorF | getEyeVector () |
Get the forward direction of the 'eye' for this object. | |
bool | getImageAltTrigger (int slot) |
Get the alt trigger state of the Image mounted in the specified slot. | |
bool | getImageAmmo (int slot) |
Get the ammo state of the Image mounted in the specified slot. | |
bool | getImageLoaded (int slot) |
Get the loaded state of the Image mounted in the specified slot. | |
int | getImageSkinTag (int slot) |
Get the skin tag ID for the Image mounted in the specified slot. | |
string | getImageState (int slot) |
Get the name of the current state of the Image in the specified slot. | |
bool | getImageTrigger (int slot) |
Get the trigger state of the Image mounted in the specified slot. | |
string | getLookAtPoint (float distance=2000, int typeMask=0xFFFFFFFF) |
Get the world position this object is looking at. | |
string | getModelFile () |
Get the model filename used by this shape. | |
int | getMountedImage (int slot) |
Get the Image mounted in the specified slot. | |
int | getMountSlot (ShapeBaseImageData image) |
Get the first slot the given datablock is mounted to on this object. | |
Point3F | getMuzzlePoint (int slot) |
Get the muzzle position of the Image mounted in the specified slot. | |
VectorF | getMuzzleVector (int slot) |
Get the muzzle vector of the Image mounted in the specified slot. | |
int | getPendingImage (int slot) |
Get the Image that will be mounted next in the specified slot. | |
float | getRechargeRate () |
Get the current recharge rate. | |
float | getRepairRate () |
Get the per-tick repair amount. | |
string | getShapeName () |
Get the name of the shape. | |
string | getSkinName () |
Get the name of the skin applied to this shape. | |
TransformF | getSlotTransform (int slot) |
Get the world transform of the specified mount slot. | |
int | getTargetCount () |
Get the number of materials in the shape. | |
string | getTargetName (int index) |
Get the name of the indexed shape material. | |
VectorF | getVelocity () |
Get the object's current velocity. | |
float | getWhiteOut () |
Get the white-out level. | |
bool | isCloaked () |
Check if this object is cloaked. | |
bool | isDestroyed () |
Check if the object is in the Destroyed damage state. | |
bool | isDisabled () |
Check if the object is in the Disabled or Destroyed damage state. | |
bool | isEnabled () |
Check if the object is in the Enabled damage state. | |
bool | isHidden () |
Check if the object is hidden. | |
bool | isImageFiring (int slot) |
Check if the current Image state is firing. | |
bool | isImageMounted (ShapeBaseImageData image) |
Check if the given datablock is mounted to any slot on this object. | |
bool | mountImage (ShapeBaseImageData image, int slot, bool loaded=true, string skinTag="") |
Mount a new Image. | |
bool | pauseThread (int slot) |
Pause an animation thread. | |
bool | playAudio (int slot, SFXTrack track) |
Attach a sound to this shape and start playing it. | |
bool | playThread (int slot, string name="") |
Start a new animation thread, or restart one that has been paused or stopped. | |
void | setAllMeshesHidden (bool hide) |
Set the hidden state on all the shape meshes. | |
void | setCameraFov (float fov) |
Set the vertical field of view in degrees for this object if used as a camera. | |
void | setCloaked (bool cloak) |
Set the cloaked state of this object. | |
void | setDamageFlash (float level) |
Set the damage flash level. | |
void | setDamageLevel (float level) |
Set the object's current damage level. | |
bool | setDamageState (string state) |
Set the object's damage state. | |
void | setDamageVector (Point3F vec) |
Set the damage direction vector. | |
void | setEnergyLevel (float level) |
Set this object's current energy level. | |
void | setHidden (bool show) |
Add or remove this object from the scene. | |
bool | setImageAltTrigger (int slot, bool state) |
Set the alt trigger state of the Image mounted in the specified slot. | |
bool | setImageAmmo (int slot, bool state) |
Set the ammo state of the Image mounted in the specified slot. | |
bool | setImageLoaded (int slot, bool state) |
Set the loaded state of the Image mounted in the specified slot. | |
bool | setImageTrigger (int slot, bool state) |
Set the trigger state of the Image mounted in the specified slot. | |
void | setInvincibleMode (float time, float speed) |
Setup the invincible effect. | |
void | setMeshHidden (string name, bool hide) |
Set the hidden state on the named shape mesh. | |
void | setRechargeRate (float rate) |
Set the recharge rate. | |
void | setRepairRate (float rate) |
Set amount to repair damage by each tick. | |
void | setShapeName (string name) |
Set the name of this shape. | |
void | setSkinName (string name) |
Apply a new skin to this shape. | |
bool | setThreadDir (int slot, bool fwd) |
Set the playback direction of an animation thread. | |
bool | setThreadTimeScale (int slot, float scale) |
Set the playback time scale of an animation thread. | |
bool | setVelocity (Point3F vel) |
Set the object's velocity. | |
void | setWhiteOut (float level) |
Set the white-out level. | |
void | startFade (int time, int delay, bool fadeOut) |
Fade the object in or out without removing it from the scene. | |
bool | stopAudio (int slot) |
Stop a sound started with playAudio. | |
bool | stopThread (int slot) |
Stop an animation thread. | |
bool | unmountImage (int slot) |
Unmount the mounted Image in the specified slot. | |
Callbacks | |
float | validateCameraFov (float fov) |
Called on the server when the client has requested a FOV change. | |
Static Public Attributes | |
static bool | isRenderable |
Disables rendering of all instances of this type. | |
static bool | isSelectable |
Disables selection of all instances of this type. |
A scriptable, renderable shape.
ShapeBase is the renderable shape from which most of the scriptable, game objects are derived, including the Player, Vehicle and Item classes. ShapeBase provides collision detection, audio channels, and animation as well as damage (and damage states), energy, and the ability to mount Images and objects.
ShapeBase objects are not normally instantiated in the scene; derived classes such as Player, WheeledVehicle, and, StaticShape are used instead. But ShapeBase (and the associated datablock, ShapeBaseData) may be used to provide functionality common to all derived objects.
A ShapeBase object consists of a DTS or DAE shape file. This file has the following requirements:
Nodes
Sequences Indicating Condition
Detail Levels
Generally in a Torque game, each client is in control of a single game object (such as a Player in an FPS game, or a WheeledVehicle in a racing game). In a game where the client has control over multiple objects (such as units in an RTS), the control object may be the Camera that determines the client's view of the world (although in general, the client's camera object does not need to be the same as the control object).
The object controlled by the client is important for several reasons:
ShapeBase includes basic enery and damage systems that may be used by derived classes as required. For example, the Player class uses energy to determine whether the character is capabable of running and jumping, which can be used to mimic the character getting tired and having to rest before continuing. The Player class also uses the damage system PlayerData::onDestroyed callback to trigger a death animation. The Vehicle classes use the current damage level to trigger particle emitters, so a vehicle could progressively generate more smoke as it becomes more damaged.
ShapeBase also includes parameters to 'blow up' the object when it is Destroyed (damage level above ShapeBaseData::destroyedLevel). Blowing up an object can generate an explosion and debris, as well as exclude the object from rendering.
Parameters to control the object's energy and damage functionality can be found in the ShapeBaseData datablock.
void ShapeBase::applyDamage | ( | float | amount | ) |
Increment the current damage level by the specified amount.
amount | value to add to current damage level |
bool ShapeBase::applyImpulse | ( | Point3F | pos, | |
Point3F | vec | |||
) |
Apply an impulse to the object.
pos | world position of the impulse | |
vec | impulse momentum (velocity * mass) |
void ShapeBase::applyRepair | ( | float | amount | ) |
Repair damage by the specified amount.
Note that the damage level is only reduced by repairRate per tick, so it may take several ticks for the total repair to complete.
amount | total repair value (subtracted from damage level over time) |
bool ShapeBase::canCloak | ( | ) |
Check if this object can cloak.
Change one of the materials on the shape.
This method changes materials per mapTo with others. The material that is being replaced is mapped to unmapped_mat as a part of this transition.
mapTo | the name of the material target to remap (from getTargetName) | |
oldMat | the old Material that was mapped | |
newMat | the new Material to map |
// remap the first material in the shape
%mapTo = %obj.getTargetName( 0 );
%obj.changeMaterial( %mapTo, 0, MyMaterial );
bool ShapeBase::destroyThread | ( | int | slot | ) |
Destroy an animation thread, which prevents it from playing.
slot | thread slot to destroy |
void ShapeBase::dumpMeshVisibility | ( | ) |
Print a list of visible and hidden meshes in the shape to the console for debugging purposes.
Point3F ShapeBase::getAIRepairPoint | ( | ) |
Get the position at which the AI should stand to repair things.
If the shape defines a node called "AIRepairNode", this method will return the current world position of that node, otherwise "0 0 0".
float ShapeBase::getCameraFov | ( | ) |
Returns the vertical field of view in degrees for this object if used as a camera.
int ShapeBase::getControllingClient | ( | ) |
Get the client (if any) that controls this object.
The controlling client is the one that will send moves to us to act on.
int ShapeBase::getControllingObject | ( | ) |
Get the object (if any) that controls this object.
float ShapeBase::getDamageFlash | ( | ) |
float ShapeBase::getDamageLevel | ( | ) |
float ShapeBase::getDamagePercent | ( | ) |
Get the object's current damage level as a percentage of maxDamage.
string ShapeBase::getDamageState | ( | ) |
Get the object's damage state.
float ShapeBase::getDefaultCameraFov | ( | ) |
Returns the default vertical field of view in degrees for this object if used as a camera.
float ShapeBase::getEnergyLevel | ( | ) |
float ShapeBase::getEnergyPercent | ( | ) |
Get the object's current energy level as a percentage of maxEnergy.
Point3F ShapeBase::getEyePoint | ( | ) |
Get the position of the 'eye' for this object.
If the object model has a node called 'eye', this method will return that node's current world position, otherwise it will return the object's current world position.
TransformF ShapeBase::getEyeTransform | ( | ) |
Get the 'eye' transform for this object.
If the object model has a node called 'eye', this method will return that node's current transform, otherwise it will return the object's current transform.
VectorF ShapeBase::getEyeVector | ( | ) |
Get the forward direction of the 'eye' for this object.
If the object model has a node called 'eye', this method will return that node's current forward direction vector, otherwise it will return the object's current forward direction vector.
bool ShapeBase::getImageAltTrigger | ( | int | slot | ) |
Get the alt trigger state of the Image mounted in the specified slot.
slot | Image slot to query |
bool ShapeBase::getImageAmmo | ( | int | slot | ) |
Get the ammo state of the Image mounted in the specified slot.
slot | Image slot to query |
bool ShapeBase::getImageLoaded | ( | int | slot | ) |
Get the loaded state of the Image mounted in the specified slot.
slot | Image slot to query |
int ShapeBase::getImageSkinTag | ( | int | slot | ) |
Get the skin tag ID for the Image mounted in the specified slot.
slot | Image slot to query |
string ShapeBase::getImageState | ( | int | slot | ) |
Get the name of the current state of the Image in the specified slot.
slot | Image slot to query |
bool ShapeBase::getImageTrigger | ( | int | slot | ) |
Get the trigger state of the Image mounted in the specified slot.
slot | Image slot to query |
string ShapeBase::getLookAtPoint | ( | float | distance = 2000 , |
|
int | typeMask = 0xFFFFFFFF | |||
) |
Get the world position this object is looking at.
Casts a ray from the eye and returns information about what the ray hits.
distance | maximum distance of the raycast | |
typeMask | typeMask of objects to include for raycast collision testing |
string ShapeBase::getModelFile | ( | ) |
Get the model filename used by this shape.
int ShapeBase::getMountedImage | ( | int | slot | ) |
Get the Image mounted in the specified slot.
slot | Image slot to query |
int ShapeBase::getMountSlot | ( | ShapeBaseImageData | image | ) |
Get the first slot the given datablock is mounted to on this object.
image | ShapeBaseImageData datablock to query |
Point3F ShapeBase::getMuzzlePoint | ( | int | slot | ) |
Get the muzzle position of the Image mounted in the specified slot.
If the Image shape contains a node called 'muzzlePoint', then the muzzle position is the position of that node in world space. If no such node is specified, the slot's mount node is used instead.
slot | Image slot to query |
VectorF ShapeBase::getMuzzleVector | ( | int | slot | ) |
Get the muzzle vector of the Image mounted in the specified slot.
If the Image shape contains a node called 'muzzlePoint', then the muzzle vector is the forward direction vector of that node's transform in world space. If no such node is specified, the slot's mount node is used instead.
If the correctMuzzleVector and firstPerson flags are set in the Image, the muzzle vector is computed to point at whatever object is right in front of the object's 'eye' node.
slot | Image slot to query |
int ShapeBase::getPendingImage | ( | int | slot | ) |
Get the Image that will be mounted next in the specified slot.
Calling mountImage when an Image is already mounted does one of two things:
This command retrieves the ID of the pending Image (2nd case above).
slot | Image slot to query |
float ShapeBase::getRechargeRate | ( | ) |
float ShapeBase::getRepairRate | ( | ) |
Get the per-tick repair amount.
string ShapeBase::getShapeName | ( | ) |
Get the name of the shape.
string ShapeBase::getSkinName | ( | ) |
TransformF ShapeBase::getSlotTransform | ( | int | slot | ) |
Get the world transform of the specified mount slot.
slot | Image slot to query |
int ShapeBase::getTargetCount | ( | ) |
Get the number of materials in the shape.
string ShapeBase::getTargetName | ( | int | index | ) |
Get the name of the indexed shape material.
index | index of the material to get (valid range is 0 - getTargetCount()-1). |
VectorF ShapeBase::getVelocity | ( | ) |
float ShapeBase::getWhiteOut | ( | ) |
bool ShapeBase::isCloaked | ( | ) |
bool ShapeBase::isDestroyed | ( | ) |
Check if the object is in the Destroyed damage state.
bool ShapeBase::isDisabled | ( | ) |
Check if the object is in the Disabled or Destroyed damage state.
bool ShapeBase::isEnabled | ( | ) |
Check if the object is in the Enabled damage state.
bool ShapeBase::isHidden | ( | ) |
Check if the object is hidden.
bool ShapeBase::isImageFiring | ( | int | slot | ) |
Check if the current Image state is firing.
slot | Image slot to query |
bool ShapeBase::isImageMounted | ( | ShapeBaseImageData | image | ) |
Check if the given datablock is mounted to any slot on this object.
image | ShapeBaseImageData datablock to query |
bool ShapeBase::mountImage | ( | ShapeBaseImageData | image, | |
int | slot, | |||
bool | loaded = true , |
|||
string | skinTag = "" | |||
) |
Mount a new Image.
image | the Image to mount | |
slot | Image slot to mount into (valid range is 0 - 3) | |
loaded | initial loaded state for the Image | |
skinTag | tagged string to reskin the mounted Image |
%player.mountImage( PistolImage, 1 ); %player.mountImage( CrossbowImage, 0, false ); %player.mountImage( RocketLauncherImage, 0, true, 'blue' );
bool ShapeBase::pauseThread | ( | int | slot | ) |
Pause an animation thread.
If restarted using playThread, the animation will resume from the paused position.
slot | thread slot to stop |
bool ShapeBase::playAudio | ( | int | slot, | |
SFXTrack | track | |||
) |
Attach a sound to this shape and start playing it.
slot | Audio slot index for the sound (valid range is 0 - 3) | |
track | SFXTrack to play |
bool ShapeBase::playThread | ( | int | slot, | |
string | name = "" | |||
) |
Start a new animation thread, or restart one that has been paused or stopped.
slot | thread slot to play. Valid range is 0 - 3) | |
name | name of the animation sequence to play in this slot. If not specified, the paused or stopped thread in this slot will be resumed. |
%obj.playThread( 0, "ambient" ); // Play the ambient sequence in slot 0 %obj.setThreadTimeScale( 0, 0.5 ); // Play at half-speed %obj.pauseThread( 0 ); // Pause the sequence %obj.playThread( 0 ); // Resume playback %obj.playThread( 0, "spin" ); // Replace the sequence in slot 0
void ShapeBase::setAllMeshesHidden | ( | bool | hide | ) |
Set the hidden state on all the shape meshes.
This allows you to hide all meshes in the shape, for example, and then only enable a few.
hide | new hidden state for all meshes |
void ShapeBase::setCameraFov | ( | float | fov | ) |
Set the vertical field of view in degrees for this object if used as a camera.
fov | new FOV value |
void ShapeBase::setCloaked | ( | bool | cloak | ) |
Set the cloaked state of this object.
When an object is cloaked it is not rendered.
cloak | true to cloak the object, false to uncloak |
void ShapeBase::setDamageFlash | ( | float | level | ) |
Set the damage flash level.
Damage flash may be used as a postfx effect to flash the screen when the client is damaged.
level | flash level (0-1) |
void ShapeBase::setDamageLevel | ( | float | level | ) |
Set the object's current damage level.
level | new damage level |
bool ShapeBase::setDamageState | ( | string | state | ) |
Set the object's damage state.
state | should be one of "Enabled", "Disabled", "Destroyed" |
void ShapeBase::setDamageVector | ( | Point3F | vec | ) |
Set the damage direction vector.
Currently this is only used to initialise the explosion if this object is blown up.
vec | damage direction vector |
%obj.setDamageVector( "0 0 1" );
void ShapeBase::setEnergyLevel | ( | float | level | ) |
Set this object's current energy level.
level | new energy level |
void ShapeBase::setHidden | ( | bool | show | ) |
Add or remove this object from the scene.
When removed from the scene, the object will not be processed or rendered.
show | False to hide the object, true to re-show it |
Reimplemented from SimObject.
bool ShapeBase::setImageAltTrigger | ( | int | slot, | |
bool | state | |||
) |
Set the alt trigger state of the Image mounted in the specified slot.
slot | Image slot to modify | |
state | new alt trigger state for the Image |
bool ShapeBase::setImageAmmo | ( | int | slot, | |
bool | state | |||
) |
Set the ammo state of the Image mounted in the specified slot.
slot | Image slot to modify | |
state | new ammo state for the Image |
bool ShapeBase::setImageLoaded | ( | int | slot, | |
bool | state | |||
) |
Set the loaded state of the Image mounted in the specified slot.
slot | Image slot to modify | |
state | new loaded state for the Image |
bool ShapeBase::setImageTrigger | ( | int | slot, | |
bool | state | |||
) |
Set the trigger state of the Image mounted in the specified slot.
slot | Image slot to modify | |
state | new trigger state for the Image |
void ShapeBase::setInvincibleMode | ( | float | time, | |
float | speed | |||
) |
Setup the invincible effect.
This effect is used for HUD feedback to the user that they are invincible.
time | duration in seconds for the invincible effect | |
speed | speed at which the invincible effect progresses |
void ShapeBase::setMeshHidden | ( | string | name, | |
bool | hide | |||
) |
Set the hidden state on the named shape mesh.
name | name of the mesh to hide/show | |
hide | new hidden state for the mesh |
void ShapeBase::setRechargeRate | ( | float | rate | ) |
Set the recharge rate.
The recharge rate is added to the object's current energy level each tick, up to the maxEnergy level set in the ShapeBaseData datablock.
rate | the recharge rate (per tick) |
void ShapeBase::setRepairRate | ( | float | rate | ) |
Set amount to repair damage by each tick.
Note that this value is separate to the repairRate field in ShapeBaseData. This value will be subtracted from the damage level each tick, whereas the ShapeBaseData field limits how much of the applyRepair value is subtracted each tick. Both repair types can be active at the same time.
rate | value to subtract from damage level each tick (must be > 0) |
void ShapeBase::setShapeName | ( | string | name | ) |
Set the name of this shape.
name | new name for the shape |
void ShapeBase::setSkinName | ( | string | name | ) |
bool ShapeBase::setThreadDir | ( | int | slot, | |
bool | fwd | |||
) |
Set the playback direction of an animation thread.
slot | thread slot to modify | |
fwd | true to play the animation forwards, false to play backwards |
bool ShapeBase::setThreadTimeScale | ( | int | slot, | |
float | scale | |||
) |
Set the playback time scale of an animation thread.
slot | thread slot to modify | |
scale | new thread time scale (1=normal speed, 0.5=half speed etc) |
bool ShapeBase::setVelocity | ( | Point3F | vel | ) |
Set the object's velocity.
vel | new velocity for the object |
void ShapeBase::setWhiteOut | ( | float | level | ) |
Set the white-out level.
White-out may be used as a postfx effect to brighten the screen in response to a game event.
level | flash level (0-1) |
void ShapeBase::startFade | ( | int | time, | |
int | delay, | |||
bool | fadeOut | |||
) |
Fade the object in or out without removing it from the scene.
A faded out object is still in the scene and can still be collided with, so if you want to disable collisions for this shape after it fades out use setHidden to temporarily remove this shape from the scene.
time | duration of the fade effect in ms | |
delay | delay in ms before the fade effect begins | |
fadeOut | true to fade-out to invisible, false to fade-in to full visibility |
bool ShapeBase::stopAudio | ( | int | slot | ) |
Stop a sound started with playAudio.
slot | audio slot index (started with playAudio) |
bool ShapeBase::stopThread | ( | int | slot | ) |
Stop an animation thread.
If restarted using playThread, the animation will start from the beginning again.
slot | thread slot to stop |
bool ShapeBase::unmountImage | ( | int | slot | ) |
Unmount the mounted Image in the specified slot.
slot | Image slot to unmount |
float ShapeBase::validateCameraFov | ( | float | fov | ) |
Called on the server when the client has requested a FOV change.
When the client requests that its field of view should be changed (because they want to use a sniper scope, for example) this new FOV needs to be validated by the server. This method is called if it exists (it is optional) to validate the requested FOV, and modify it if necessary. This could be as simple as checking that the FOV falls within a correct range, to making sure that the FOV matches the capabilities of the current weapon.
Following this method, ShapeBase ensures that the given FOV still falls within the datablock's cameraMinFov and cameraMaxFov. If that is good enough for your purposes, then you do not need to define the validateCameraFov() callback for your ShapeBase.
fov | The FOV that has been requested by the client. |
bool ShapeBase::isRenderable [static] |
Disables rendering of all instances of this type.
Reimplemented from GameBase.
Reimplemented in MissionMarker, WayPoint, StaticShape, Vehicle, HoverVehicle, Player, AIPlayer, Camera, Item, SpawnSphere, PathCamera, RigidShape, FlyingVehicle, and WheeledVehicle.
bool ShapeBase::isSelectable [static] |
Disables selection of all instances of this type.
Reimplemented from GameBase.
Reimplemented in MissionMarker, WayPoint, StaticShape, Vehicle, HoverVehicle, Player, AIPlayer, Camera, Item, SpawnSphere, PathCamera, RigidShape, FlyingVehicle, and WheeledVehicle.