2 # Documentation for KX_SCA_ReplaceMeshActuator
3 from SCA_IActuator import *
5 class KX_SCA_ReplaceMeshActuator(SCA_IActuator):
7 Edit Object actuator, in Replace Mesh mode.
11 # Switch a game object's mesh based on its depth in the camera view.
12 # +----------+ +-----------+ +-------------------------------------+
13 # | Always +-----+ Python +-----+ Edit Object (Replace Mesh) LOD.Mesh |
14 # +----------+ +-----------+ +-------------------------------------+
17 # List detail meshes here
18 # Mesh (name, near, far)
19 # Meshes overlap so that they don't 'pop' when on the edge of the distance.
20 meshes = ((".Hi", 0.0, -20.0),
21 (".Med", -15.0, -50.0),
22 (".Lo", -40.0, -100.0)
25 co = GameLogic.getCurrentController()
27 act = co.getActuator("LOD." + obj.name)
28 cam = GameLogic.getCurrentScene().active_camera
30 def Depth(pos, plane):
31 return pos[0]*plane[0] + pos[1]*plane[1] + pos[2]*plane[2] + plane[3]
33 # Depth is negative and decreasing further from the camera
34 depth = Depth(obj.position, cam.world_to_camera[2])
38 # Find the lowest detail mesh for depth
40 if depth < mesh[1] and depth > mesh[2]:
42 if "ME" + obj.name + mesh[0] == act.getMesh():
45 if newmesh != None and "ME" + obj.name + newmesh[0] != act.getMesh():
46 # The mesh is a different mesh - switch it.
47 # Check the current mesh is not a better fit.
48 if curmesh == None or curmesh[1] < depth or curmesh[2] > depth:
49 act.setMesh(obj.getName() + newmesh[0])
50 GameLogic.addActiveActuator(act, True)
52 @warning: Replace mesh actuators will be ignored if at game start, the
53 named mesh doesn't exist.
55 This will generate a warning in the console:
57 C{ERROR: GameObject I{OBName} ReplaceMeshActuator I{ActuatorName} without object}
59 @ivar mesh: L{KX_MeshProxy} or the name of the mesh that will replace the current one
60 Set to None to disable actuator
61 @type mesh: L{KX_MeshProxy} or None if no mesh is set
65 DEPRECATED: Use the mesh property instead.
66 Sets the name of the mesh that will replace the current one.
67 When the name is None it will unset the mesh value so no action is taken.
69 @type name: string or None
73 DEPRECATED: Use the mesh property instead.
74 Returns the name of the mesh that will replace the current one.
76 Returns None if no mesh has been scheduled to be added.
78 @rtype: string or None