Range.render
Example of using a Range.types.SCA_MouseSensor,
and two Range.types.KX_ObjectActuator to implement MouseLook:
# To use a mouse movement sensor "Mouse" and a# motion actuator to mouse look:import Range
# scale sets the speed of motionscale = 1.0, 0.5
co = Range.logic.getCurrentController()obj = co.ownermouse = co.sensors["Mouse"]lmotion = co.actuators["LMove"]wmotion = co.actuators["WMove"]
# Transform the mouse coordinates to see how far the mouse has moved.def mousePos(): x = (Range.render.getWindowWidth() / 2 - mouse.position[0]) * scale[0] y = (Range.render.getWindowHeight() / 2 - mouse.position[1]) * scale[1] return (x, y)
pos = mousePos()
# Set the amount of motion: X is applied in world coordinates...wmotion.useLocalTorque = Falsewmotion.torque = ((0.0, 0.0, pos[0]))
# ...Y is applied in local coordinateslmotion.useLocalTorque = Truelmotion.torque = ((-pos[1], 0.0, 0.0))
# Activate both actuatorsco.activate(lmotion)co.activate(wmotion)
# Centre the mouseRange.render.setMousePosition(int(Range.render.getWindowWidth() / 2), int(Range.render.getWindowHeight() / 2))Constants
Section titled “Constants”KX_TEXFACE_MATERIAL
Section titled “KX_TEXFACE_MATERIAL”Deprecated.
Materials as defined by the texture face settings.
KX_BLENDER_MULTITEX_MATERIAL
Section titled “KX_BLENDER_MULTITEX_MATERIAL”Deprecated.
Materials approximating blender materials with multitexturing.
KX_BLENDER_GLSL_MATERIAL
Section titled “KX_BLENDER_GLSL_MATERIAL”Deprecated.
Materials approximating blender materials with GLSL.
Disables vsync Enables vsync Enables adaptive vsync if supported. Adaptive vsync enables vsync if the framerate is above the monitors refresh rate. Otherwise, vsync is diabled if the framerate is too low.
LEFT_EYE
Section titled “LEFT_EYE”Left eye being used during stereoscopic rendering.
RIGHT_EYE
Section titled “RIGHT_EYE”Right eye being used during stereoscopic rendering.
HDR_NONE
Section titled “HDR_NONE”Use 8 bit per channel image format.
HDR_HALF_FLOAT
Section titled “HDR_HALF_FLOAT”Use 16 bit float per channel image format.
HDR_FULL_FLOAT
Section titled “HDR_FULL_FLOAT”Use 32 bit float per channel image format.
Functions
Section titled “Functions”getWindowWidth()
Section titled “getWindowWidth()”Gets the width of the window (in pixels)
Return type: integer
getWindowHeight()
Section titled “getWindowHeight()”Gets the height of the window (in pixels)
Return type: integer
setWindowSize(width, height)
Section titled “setWindowSize(width, height)”Set the width and height of the window (in pixels). This also works for fullscreen applications.
width: width in pixels- type: integer
height: height in pixels- type: integer
setFullScreen(enable)
Section titled “setFullScreen(enable)”Set whether or not the window should be fullscreen.
enable:Trueto set full screen,Falseto set windowed.- type: bool
getFullScreen()
Section titled “getFullScreen()”Returns whether or not the window is fullscreen.
Return type: bool
getDisplayDimensions()
Section titled “getDisplayDimensions()”Get the display dimensions, in pixels, of the display (e.g., the
monitor). Can return the size of the entire view, so the
combination of all monitors; for example, (3840, 1080) for two
side-by-side 1080p monitors.
Return type: tuple (width, height)
makeScreenshot(filename)
Section titled “makeScreenshot(filename)”Writes an image file with the displayed image at the frame end.
The image is written to ‘filename’.
The path may be absolute (eg. /home/foo/image) or relative when started with
// (eg. //image). Note that absolute paths are not portable between platforms.
If the filename contains a #,
it will be replaced by an incremental index so that screenshots can be taken multiple
times without overwriting the previous ones (eg. image-#).
Settings for the image are taken from the render settings (file format and respective settings, gamma and colospace conversion, etc). The image resolution matches the framebuffer, meaning, the window size and aspect ratio. When running from the standalone player, instead of the embedded player, only PNG files are supported. Additional color conversions are also not supported.
filename: path and name of the file to write- type: string
enableVisibility(visible)
Section titled “enableVisibility(visible)”Deprecated; doesn’t do anything.
showMouse(visible)
Section titled “showMouse(visible)”Enables or disables the operating system mouse cursor.
visible:- type: boolean
setMousePosition(x, y)
Section titled “setMousePosition(x, y)”Sets the mouse cursor position.
x: X-coordinate in screen pixel coordinates.- type: integer
y: Y-coordinate in screen pixel coordinates.- type: integer
setBackgroundColor(rgba)
Section titled “setBackgroundColor(rgba)”Deprecated and no longer functional. Use Range.types.KX_WorldInfo.horizonColor or Range.types.KX_WorldInfo.zenithColor instead.
setEyeSeparation(eyesep)
Section titled “setEyeSeparation(eyesep)”Sets the eye separation for stereo mode. Usually Focal Length/30 provides a confortable value.
eyesep: The distance between the left and right eye.- type: float
getEyeSeparation()
Section titled “getEyeSeparation()”Gets the current eye separation for stereo mode.
Return type: float
setFocalLength(focallength)
Section titled “setFocalLength(focallength)”Sets the focal length for stereo mode. It uses the current camera focal length as initial value.
focallength: The focal length.- type: float
getFocalLength()
Section titled “getFocalLength()”Gets the current focal length for stereo mode.
Return type: float
getStereoEye()
Section titled “getStereoEye()”Gets the current stereoscopy eye being rendered.
This function is mainly used in a Range.types.KX_Scene.pre_draw callback
function to customize the camera projection matrices for each
stereoscopic eye.
Return type: LEFT_EYE, RIGHT_EYE
setMaterialMode(mode)
Section titled “setMaterialMode(mode)”Deprecated and no longer functional.
Set the material mode to use for OpenGL rendering.
mode: material mode- type: KX_TEXFACE_MATERIAL, KX_BLENDER_MULTITEX_MATERIAL, KX_BLENDER_GLSL_MATERIAL
getMaterialMode(mode)
Section titled “getMaterialMode(mode)”Deprecated and no longer functional.
Get the material mode to use for OpenGL rendering.
Return type: KX_TEXFACE_MATERIAL, KX_BLENDER_MULTITEX_MATERIAL, KX_BLENDER_GLSL_MATERIAL
setGLSLMaterialSetting(setting, enable)
Section titled “setGLSLMaterialSetting(setting, enable)”Enables or disables a GLSL material setting.
setting:- type: string (lights, shaders, shadows, ramps, nodes, extra_textures)
enable:- type: boolean
getGLSLMaterialSetting(setting)
Section titled “getGLSLMaterialSetting(setting)”Get the state of a GLSL material setting.
setting:- type: string (lights, shaders, shadows, ramps, nodes, extra_textures)
Return type: boolean
setAnisotropicFiltering(level)
Section titled “setAnisotropicFiltering(level)”Set the anisotropic filtering level for textures.
level: The new anisotropic filtering level to use- type: integer (must be one of 1, 2, 4, 8, 16)
getAnisotropicFiltering()
Section titled “getAnisotropicFiltering()”Get the anisotropic filtering level used for textures.
Return type: integer (one of 1, 2, 4, 8, 16)
setAntiAliasing(level)
Section titled “setAntiAliasing(level)”Set the anti aliasing level.
level: The new anti aliasing level to use- type: integer (must be one of 0, 2, 4, 8, 16)
getAntiAliasing()
Section titled “getAntiAliasing()”Get the anti aliasing level setting.
Return type: integer (one of 0, 2, 4, 8, 16)
setMipmapping(value)
Section titled “setMipmapping(value)”Change how to use mipmapping.
- type: RAS_MIPMAP_NONE, RAS_MIPMAP_NEAREST, RAS_MIPMAP_LINEAR
getMipmapping()
Section titled “getMipmapping()”Get the current mipmapping setting.
Return type: RAS_MIPMAP_NONE, RAS_MIPMAP_NEAREST, RAS_MIPMAP_LINEAR
setTextureQuality(level)
Section titled “setTextureQuality(level)”Texture quality of a graphics menu: keep only the high resolution texture in the project and drop its largest mipmap levels when it is sent to the graphics card.
0: full size1: half size (1/4 of the video memory)2: quarter size (1/16 of the video memory)
Textures never go below 256 pixels on their larger side, and textures without mipmaps (or with mipmapping off) keep their size. DDS files skip the levels stored in the file.
level: 0, 1 or 2- type: integer
getTextureQuality()
Section titled “getTextureQuality()”Returns: the current texture quality (0 full, 1 half, 2 quarter).
Return type: integer
drawLine(fromVec,toVec,color)
Section titled “drawLine(fromVec,toVec,color)”Draw a line in the 3D scene.
fromVec: the origin of the line- type: list [x, y, z]
toVec: the end of the line- type: list [x, y, z]
color: the color of the line- type: list [r, g, b, a]
enableMotionBlur(factor)
Section titled “enableMotionBlur(factor)”Enable the motion blur effect.
factor: the ammount of motion blur to display.- type: float [0.0 - 1.0]
disableMotionBlur()
Section titled “disableMotionBlur()”Disable the motion blur effect.
showFramerate(enable)
Section titled “showFramerate(enable)”Show or hide the framerate.
enable:- type: boolean
showProfile(enable)
Section titled “showProfile(enable)”Show or hide the profile.
enable:- type: boolean
showProperties(enable)
Section titled “showProperties(enable)”Show or hide the debug properties.
enable:- type: boolean
autoDebugList(enable)
Section titled “autoDebugList(enable)”Enable or disable auto adding debug properties to the debug list.
enable:- type: boolean
clearDebugList()
Section titled “clearDebugList()”Clears the debug property list.
setVsync(value)
Section titled “setVsync(value)”Set the vsync value
value: One of VSYNC_OFF, VSYNC_ON, VSYNC_ADAPTIVE- type: integer
getVsync()
Section titled “getVsync()”Get the current vsync value
Return type: One of VSYNC_OFF, VSYNC_ON, VSYNC_ADAPTIVE
setDynamicResolution(enabled, targetFPS=60, minScale=50, maxScale=100, step=5)
Section titled “setDynamicResolution(enabled, targetFPS=60, minScale=50, maxScale=100, step=5)”Runtime version of the scene’s Dynamic Resolution settings. The 3D scene is rendered at a
scale of the window size and stretched to the screen; the window itself does not change.
With dynamic resolution the scale goes down by step when the GPU time of a frame is above
the target and back up when there is time left. minScale == maxScale gives a fixed render
scale. Paused while “Show Render Queries” is on (both use a GPU timer query).
enabled: False renders at 100%.- type: boolean
targetFPS: Frame rate the GPU time is compared to.- type: integer
minScale: Lowest scale, in percent (25-100).- type: integer
maxScale: Highest scale, in percent (25-100).- type: integer
step: Scale change per adjustment, in percent (1-25).- type: integer
getRenderScale()
Section titled “getRenderScale()”Current render scale, 1.0 = full resolution.
Return type: float
Not in the Range documentation
Section titled “Not in the Range documentation”These items exist in the engine but were not in the Range documentation. The ones marked new in Anastacio were added by Anastacio Engine.
getMasterVolume()
Section titled “getMasterVolume()”function
Overall game sound volume, from 0 to 1. See setMasterVolume().
Returns: volume
getStereoMode()
Section titled “getStereoMode()”new in Anastacio function
get the stereo mode
getVRChromaticAberration()
Section titled “getVRChromaticAberration()”new in Anastacio function
get the VR lens chromatic aberration correction
getVRLensStrength()
Section titled “getVRLensStrength()”new in Anastacio function
get the VR lens distortion strength
setCustomMouse(path)
Section titled “setCustomMouse(path)”function
Uses the image at path as the mouse cursor.
setMasterVolume(volume)
Section titled “setMasterVolume(volume)”function
– volume in [0, 1], applies to the engine’s actual audio device
setStereoMode()
Section titled “setStereoMode()”new in Anastacio function
set the stereo mode (STEREO_* constants)
setVRChromaticAberration()
Section titled “setVRChromaticAberration()”new in Anastacio function
set the VR lens chromatic aberration correction (0..0.1, default 0.01)
setVRLensStrength()
Section titled “setVRLensStrength()”new in Anastacio function
set the VR lens distortion strength (0..1, default 0.3)
showDebugPhysics(enabled)
Section titled “showDebugPhysics(enabled)”function
Shows or hides the physics collision shapes.
RAS_MIPMAP_LINEAR
Section titled “RAS_MIPMAP_LINEAR”constant
Linear mipmap (smoother).
RAS_MIPMAP_NEAREST
Section titled “RAS_MIPMAP_NEAREST”constant
Nearest mipmap.
RAS_MIPMAP_NONE
Section titled “RAS_MIPMAP_NONE”constant
No mipmap.
STEREO_ABOVEBELOW
Section titled “STEREO_ABOVEBELOW”constant
Stereo: one image above the other.
STEREO_ANAGLYPH
Section titled “STEREO_ANAGLYPH”constant
Stereo: anaglyph (red/cyan glasses).
STEREO_INTERLACED
Section titled “STEREO_INTERLACED”constant
Stereo: interlaced lines.
STEREO_NOSTEREO
Section titled “STEREO_NOSTEREO”constant
No stereo.
STEREO_SIDEBYSIDE
Section titled “STEREO_SIDEBYSIDE”constant
Stereo: side by side.
VSYNC_ADAPTIVE
Section titled “VSYNC_ADAPTIVE”constant
Adaptive VSync: syncs, but doesn’t stall when FPS drops.
VSYNC_OFF
Section titled “VSYNC_OFF”constant
VSync off.
VSYNC_ON
Section titled “VSYNC_ON”constant
VSync on.
