Module GameTypes :: Class KX_SCA_ReplaceMeshActuator
[hide private]
[frames] | no frames]

Class KX_SCA_ReplaceMeshActuator

source code

PyObjectPlus --+            
               |            
          CValue --+        
                   |        
     SCA_ILogicBrick --+    
                       |    
           SCA_IActuator --+
                           |
                          KX_SCA_ReplaceMeshActuator

Edit Object actuator, in Replace Mesh mode.

Example:
       # Level-of-detail
       # Switch a game object's mesh based on its depth in the camera view.
       # +----------+     +-----------+     +-------------------------------------+
       # | Always   +-----+ Python    +-----+ Edit Object (Replace Mesh) LOD.Mesh |
       # +----------+     +-----------+     +-------------------------------------+
       import GameLogic

       # List detail meshes here
       # Mesh (name, near, far)
       # Meshes overlap so that they don't 'pop' when on the edge of the distance.
       meshes = ((".Hi", 0.0, -20.0),
                         (".Med", -15.0, -50.0),
                         (".Lo", -40.0, -100.0)
                       )
       
       co = GameLogic.getCurrentController()
       obj = co.owner
       act = co.actuators["LOD." + obj.name]
       cam = GameLogic.getCurrentScene().active_camera
       
       def Depth(pos, plane):
               return pos[0]*plane[0] + pos[1]*plane[1] + pos[2]*plane[2] + plane[3]
       
       # Depth is negative and decreasing further from the camera
       depth = Depth(obj.position, cam.world_to_camera[2])
       
       newmesh = None
       curmesh = None
       # Find the lowest detail mesh for depth
       for mesh in meshes:
               if depth < mesh[1] and depth > mesh[2]:
                       newmesh = mesh
               if "ME" + obj.name + mesh[0] == act.getMesh():
                       curmesh = mesh
       
       if newmesh != None and "ME" + obj.name + newmesh[0] != act.getMesh():
               # The mesh is a different mesh - switch it.
               # Check the current mesh is not a better fit.
               if curmesh == None or curmesh[1] < depth or curmesh[2] > depth:
                       act.mesh = obj.getName() + newmesh[0]
                       GameLogic.addActiveActuator(act, True)



Warning:

Replace mesh actuators will be ignored if at game start, the named mesh doesn't exist.

This will generate a warning in the console:

ERROR: GameObject OBName ReplaceMeshActuator ActuatorName without object

Instance Methods [hide private]
 
setMesh(name)
Sets the name of the mesh that will replace the current one.
source code
string or None
getMesh()
Returns the name of the mesh that will replace the current one.
source code
None
instantReplaceMesh()
Immediately replace mesh without delay.
source code
    Deprecated
    Inherited from SCA_ILogicBrick
integer
getExecutePriority()
Gets the execution priority of this logic brick.
source code
KX_GameObject
getOwner()
Gets the game object associated with this logic brick.
source code
 
setExecutePriority(priority)
Sets the priority of this logic brick.
source code
    Inherited from CValue
string
getName()
Returns the name of the CValue.
source code
    Inherited from PyObjectPlus
bool
isA(game_type)
Check if this is a type or a subtype game_type.
source code
Instance Variables [hide private]
KX_MeshProxy or None if no mesh is set mesh
KX_MeshProxy or the name of the mesh that will replace the current one Set to None to disable actuator
boolean useDisplayMesh
when true the displayed mesh is replaced.
boolean usePhysicsMesh
when true the physics mesh is replaced.
    Inherited from SCA_ILogicBrick
int executePriority
This determines the order controllers are evaluated, and actuators are activated (lower priority is executed first).
string name
The name of this CValue derived object (read-only).
KX_GameObject or None in exceptional cases. owner
The game object this logic brick is attached to (read-only).
    Inherited from PyObjectPlus
bool invalid
Test if the object has been freed by the game engine and is no longer valid.
Method Details [hide private]

setMesh(name)

source code 
Sets the name of the mesh that will replace the current one. When the name is None it will unset the mesh value so no action is taken.

Deprecated: Use the mesh attribute instead.

getMesh()

source code 

Returns the name of the mesh that will replace the current one.

Returns None if no mesh has been scheduled to be added.
Returns: string or None

Deprecated: Use the mesh attribute instead.