KX_ReplaceMeshActuator
Base class: SCA_IActuator
Edit Object actuator, in Replace Mesh mode.
# 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 |# +----------+ +-----------+ +-------------------------------------+from Range import logic
# 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) )
cont = logic.getCurrentController()object = cont.owneractuator = cont.actuators["LOD." + obj.name]camera = logic.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 cameradepth = Depth(object.position, camera.world_to_camera[2])
newmesh = Nonecurmesh = None# Find the lowest detail mesh for depthfor mesh in meshes: if depth < mesh[1] and depth > mesh[2]: newmesh = mesh if "ME" + object.name + mesh[0] == actuator.getMesh(): curmesh = mesh
if newmesh != None and "ME" + object.name + newmesh[0] != actuator.mesh: # 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: actuator.mesh = object.name + newmesh[0] cont.activate(actuator)MeshProxy or the name of the mesh that will replace the current one.
Set to None to disable actuator.
Type: MeshProxy or None if no mesh is set
useDisplayMesh
Section titled “useDisplayMesh”when true the displayed mesh is replaced.
Type: boolean
usePhysicsMesh
Section titled “usePhysicsMesh”when true the physics mesh is replaced.
Type: boolean
instantReplaceMesh()
Section titled “instantReplaceMesh()”Immediately replace mesh without delay.
