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
cam
This node is used as the 3rd person camera position. If this is not found the 'eye' node is used instead.
eye
This node is used as the 1st person camera position.
ear
This node is where the SFX listener is mounted on. If this is not found the 'eye' node is used instead.
mountN
Nodes used for mounting ShapeBaseImages to this object. N is an integer from 0 to 31
AIRepairNode
This node is where AI should stand to repair the object. If not found, the object's origin is used.
Sequences Indicating Condition
visibility
A two frame sequence used to show object damage when the object is destroyed (start=no damage, end=destroyed). This sequence is optional.
damage
Sequence used to show object damage, such as a vehicle getting more dents (start=no damage, end=fully damaged). When the object is fully destroyed this sequence returns to the start and the visibility sequence kicks in. This sequence is optional.
Detail Levels
collision-N
Convex geometry used for collision detection. N is a integer from 1 to 8. For classes that support polysoup collision, this geometry need not be convex.
LOS-N
Convex geometry used for line-of-sight collision detection. N is an integer from 9 to 16.
Control Object
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:
The control object receives Moves from the client
GameConnection (such as keyboard or gamepad input).
The control object is used to 'scope' the client, that is, to determine what else in the world is significant for the client, and which objects the server should give priority when sending network updates to the client.
Energy/Damage
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.
See also:
ShapeBaseData::maxEnergy
ShapeBaseData::maxDamage
Member Function Documentation
void ShapeBase::applyDamage
(
float
amount
)
Increment the current damage level by the specified amount.
Parameters:
amount
value to add to current damage level
bool ShapeBase::applyImpulse
(
Point3F
pos,
Point3F
vec
)
Apply an impulse to the object.
Parameters:
pos
world position of the impulse
vec
impulse momentum (velocity * mass)
Returns:
true
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.
Parameters:
amount
total repair value (subtracted from damage level over time)
bool ShapeBase::canCloak
(
)
Check if this object can cloak.
Returns:
true
Note:
Not implemented as it always returns true.
void ShapeBase::changeMaterial
(
string
mapTo,
Material
oldMat,
Material
newMat
)
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.
Note:
Warning, right now this only sort of works. It doesn't do a live update like it should.
Parameters:
mapTo
the name of the material target to remap (from getTargetName)
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.
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.
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.
index of the first slot the Image is mounted in, or -1 if the Image is not mounted in any slot on this object.
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.
Parameters:
slot
Image slot to query
Returns:
the muzzle position, or "0 0 0" if the slot is invalid
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 flag (correctMuzzleVectorTP in 3rd person) is set in the Image, the muzzle vector is computed to point at whatever object is right in front of the object's 'eye' node.
Parameters:
slot
Image slot to query
Returns:
the muzzle vector, or "0 1 0" if the slot is invalid
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:
Mount the new Image immediately, the old Image is discarded and whatever state it was in is ignored.
If the current Image state does not allow Image changes, the new Image is marked as pending, and will not be mounted until the current state completes. eg. if the user changes weapons, you may wish to ensure that the current weapon firing state plays to completion first.
This command retrieves the ID of the pending Image (2nd case above).
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.
Parameters:
rate
value to subtract from damage level each tick (must be > 0)
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.
Note:
Items have the ability to light their surroundings. When an Item with an active light is fading out, the light it emits is correspondingly reduced until it goes out. Likewise, when the item fades in, the light is turned-up till it reaches it's normal brightntess.
Parameters:
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.
Parameters:
slot
audio slot index (started with playAudio)
Returns:
true if the sound was stopped successfully, false if failed
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.
'Skinning' the shape effectively renames the material targets, allowing different materials to be used on different instances of the same model. Using getSkinName() and setSkinName() is equivalent to reading and writing the skin field directly.
Any material targets that start with the old skin name have that part of the name replaced with the new skin name. The initial old skin name is "base". For example, if a new skin of "blue" was applied to a model that had material targets base_body and face, the new targets would be blue_body and face. Note that face was not renamed since it did not start with the old skin name of "base".
To support models that do not use the default "base" naming convention, you can also specify the part of the name to replace in the skin field itself. For example, if a model had a material target called shapemat, we could apply a new skin "shape=blue", and the material target would be renamed to bluemat (note "shape" has been replaced with "blue").
Multiple skin updates can also be applied at the same time by separating them with a semicolon. For example: "base=blue;face=happy_face".
Material targets are only renamed if an existing
Material maps to that name, or if there is a diffuse texture in the model folder with the same name as the new target.