2
Game Engine bge.types Module
3
=============================
7
.. class:: PyObjectPlus
9
PyObjectPlus base class of most other types in the Game Engine.
11
.. attribute:: invalid
13
Test if the object has been freed by the game engine and is no longer valid.
15
Normally this is not a problem but when storing game engine data in the GameLogic module,
16
KX_Scenes or other KX_GameObjects its possible to hold a reference to invalid data.
17
Calling an attribute or method on an invalid object will raise a SystemError.
19
The invalid attribute allows testing for this case without exception handling.
23
.. method:: isA(game_type)
25
Check if this is a type or a subtype game_type.
27
:arg game_type: the name of the type or the type its self from the :mod:`bge.types` module.
28
:type game_type: string or type
29
:return: True if this object is a type or a subtype of game_type.
32
.. class:: CValue(PyObjectPlus)
34
This class is a basis for other classes.
38
The name of this CValue derived object (read-only).
42
.. class:: CPropValue(CValue)
44
This class has no python functions
46
.. class:: SCA_ILogicBrick(CValue)
48
Base class for all logic bricks.
50
.. attribute:: executePriority
52
This determines the order controllers are evaluated, and actuators are activated (lower priority is executed first).
54
:type: executePriority: int
58
The game object this logic brick is attached to (read-only).
60
:type: :class:`KX_GameObject` or None in exceptional cases.
64
The name of this logic brick (read-only).
68
.. class:: SCA_PythonKeyboard(PyObjectPlus)
74
A list of pressed keys that have either been pressed, or just released, or are active this frame. (read-only).
76
:type: list [[:ref:`keycode<keyboard-keys>`, :ref:`status<input-status>`], ...]
78
.. class:: SCA_PythonMouse(PyObjectPlus)
84
a list of pressed buttons that have either been pressed, or just released, or are active this frame. (read-only).
86
:type: list [[:ref:`keycode<mouse-keys>`, :ref:`status<input-status>`], ...]
88
.. attribute:: position
90
The normalized x and y position of the mouse cursor.
94
.. attribute:: visible
96
The visibility of the mouse cursor.
100
.. class:: SCA_IObject(CValue)
102
This class has no python functions
104
.. class:: SCA_ISensor(SCA_ILogicBrick)
106
Base class for all sensor logic bricks.
108
.. attribute:: usePosPulseMode
110
Flag to turn positive pulse mode on and off.
114
.. attribute:: useNegPulseMode
116
Flag to turn negative pulse mode on and off.
120
.. attribute:: frequency
122
The frequency for pulse mode sensors.
128
level Option whether to detect level or edge transition when entering a state.
129
It makes a difference only in case of logic state transition (state actuator).
130
A level detector will immediately generate a pulse, negative or positive
131
depending on the sensor condition, as soon as the state is activated.
132
A edge detector will wait for a state change before generating a pulse.
133
note: mutually exclusive with :data:`tap`, enabling will disable :data:`tap`.
139
When enabled only sensors that are just activated will send a positive event,
140
after this they will be detected as negative by the controllers.
141
This will make a key thats held act as if its only tapped for an instant.
142
note: mutually exclusive with :data:`level`, enabling will disable :data:`level`.
146
.. attribute:: invert
148
Flag to set if this sensor activates on positive or negative events.
152
.. attribute:: triggered
154
True if this sensor brick is in a positive state. (read-only).
158
.. attribute:: positive
160
True if this sensor brick is in a positive state. (read-only).
164
.. attribute:: status
166
The status of the sensor (read-only): can be one of :ref:`these constants<sensor-status>`.
172
This convenient attribute combines the values of triggered and positive attributes.
176
Reset sensor internal state, effect depends on the type of sensor and settings.
178
The sensor is put in its initial state as if it was just activated.
180
.. class:: SCA_IController(SCA_ILogicBrick)
182
Base class for all controller logic bricks.
186
The controllers state bitmask. This can be used with the GameObject's state to test if the controller is active.
190
.. attribute:: sensors
192
A list of sensors linked to this controller.
194
:type: sequence supporting index/string lookups and iteration.
198
The sensors are not necessarily owned by the same object.
202
When objects are instanced in dupligroups links may be lost from objects outside the dupligroup.
204
.. attribute:: actuators
206
A list of actuators linked to this controller.
208
:type: sequence supporting index/string lookups and iteration.
212
The sensors are not necessarily owned by the same object.
216
When objects are instanced in dupligroups links may be lost from objects outside the dupligroup.
218
.. attribute:: useHighPriority
220
When set the controller executes always before all other controllers that dont have this set.
226
Order of execution between high priority controllers is not guaranteed.
228
.. class:: SCA_IActuator(SCA_ILogicBrick)
230
Base class for all actuator logic bricks.
232
.. class:: BL_ActionActuator(SCA_IActuator)
234
Action Actuators apply an action to an actor.
236
.. attribute:: action
238
The name of the action to set as the current action.
242
.. attribute:: channelNames
244
A list of channel names that may be used with :data:`setChannel` and :data:`getChannel`.
246
:type: list of strings
248
.. attribute:: frameStart
250
Specifies the starting frame of the animation.
254
.. attribute:: frameEnd
256
Specifies the ending frame of the animation.
260
.. attribute:: blendIn
262
Specifies the number of frames of animation to generate when making transitions between actions.
266
.. attribute:: priority
268
Sets the priority of this actuator. Actuators will lower priority numbers will override actuators with higher numbers.
274
Sets the current frame for the animation.
278
.. attribute:: propName
280
Sets the property to be used in FromProp playback mode.
284
.. attribute:: blendTime
286
Sets the internal frame timer. This property must be in the range from 0.0 to blendIn.
292
The operation mode of the actuator. Can be one of :ref:`these constants<action-actuator>`.
296
.. attribute:: useContinue
298
The actions continue option, True or False. When True, the action will always play from where last left off, otherwise negative events to this actuator will reset it to its start frame.
302
.. attribute:: framePropName
304
The name of the property that is set to the current frame number.
308
.. method:: setChannel(channel, matrix)
310
Alternative to the 2 arguments, 4 arguments (channel, matrix, loc, size, quat) are also supported.
312
:arg channel: A string specifying the name of the bone channel, error raised if not in :data:`channelNames`.
313
:type channel: string
314
:arg matrix: A 4x4 matrix specifying the overriding transformation as an offset from the bone's rest position.
315
:arg matrix: list [[float]]
319
These values are relative to the bones rest position, currently the api has no way to get this info (which is annoying), but can be worked around by using bones with a rest pose that has no translation.
321
.. method:: getChannel(channel)
323
:arg channel: A string specifying the name of the bone channel. error raised if not in :data:`channelNames`.
324
:type channel: string
325
:return: (loc, size, quat)
328
.. class:: BL_Shader(PyObjectPlus)
330
BL_Shader GLSL shaders.
334
.. method:: setUniformfv(name, fList)
336
Set a uniform with a list of float values
338
:arg name: the uniform name
340
:arg fList: a list (2, 3 or 4 elements) of float values
341
:type fList: list[float]
343
.. method:: delSource()
345
Clear the shader. Use this method before the source is changed with :data:`setSource`.
347
.. method:: getFragmentProg()
349
Returns the fragment program.
351
:return: The fragment program.
354
.. method:: getVertexProg()
356
Get the vertex program.
358
:return: The vertex program.
361
.. method:: isValid()
363
Check if the shader is valid.
365
:return: True if the shader is valid
368
.. method:: setAttrib(enum)
370
Set attribute location. (The parameter is ignored a.t.m. and the value of "tangent" is always used.)
372
:arg enum: attribute location value
375
.. method:: setNumberOfPasses( max_pass )
377
Set the maximum number of passes. Not used a.t.m.
379
:arg max_pass: the maximum number of passes
380
:type max_pass: integer
382
.. method:: setSampler(name, index)
384
Set uniform texture sample index.
386
:arg name: Uniform name
388
:arg index: Texture sample index.
391
.. method:: setSource(vertexProgram, fragmentProgram)
393
Set the vertex and fragment programs
395
:arg vertexProgram: Vertex program
396
:type vertexProgram: string
397
:arg fragmentProgram: Fragment program
398
:type fragmentProgram: string
400
.. method:: setUniform1f(name, fx)
402
Set a uniform with 1 float value.
404
:arg name: the uniform name
406
:arg fx: Uniform value
409
.. method:: setUniform1i(name, ix)
411
Set a uniform with an integer value.
413
:arg name: the uniform name
415
:arg ix: the uniform value
418
.. method:: setUniform2f(name, fx, fy)
420
Set a uniform with 2 float values
422
:arg name: the uniform name
424
:arg fx: first float value
427
:arg fy: second float value
430
.. method:: setUniform2i(name, ix, iy)
432
Set a uniform with 2 integer values
434
:arg name: the uniform name
436
:arg ix: first integer value
438
:arg iy: second integer value
441
.. method:: setUniform3f(name, fx, fy, fz)
443
Set a uniform with 3 float values.
445
:arg name: the uniform name
447
:arg fx: first float value
449
:arg fy: second float value
451
:arg fz: third float value
454
.. method:: setUniform3i(name, ix, iy, iz)
456
Set a uniform with 3 integer values
458
:arg name: the uniform name
460
:arg ix: first integer value
462
:arg iy: second integer value
464
:arg iz: third integer value
467
.. method:: setUniform4f(name, fx, fy, fz, fw)
469
Set a uniform with 4 float values.
471
:arg name: the uniform name
473
:arg fx: first float value
475
:arg fy: second float value
477
:arg fz: third float value
479
:arg fw: fourth float value
482
.. method:: setUniform4i(name, ix, iy, iz, iw)
484
Set a uniform with 4 integer values
486
:arg name: the uniform name
488
:arg ix: first integer value
490
:arg iy: second integer value
492
:arg iz: third integer value
494
:arg iw: fourth integer value
497
.. method:: setUniformDef(name, type)
501
:arg name: the uniform name
503
:arg type: uniform type
504
:type type: UNI_NONE, UNI_INT, UNI_FLOAT, UNI_INT2, UNI_FLOAT2, UNI_INT3, UNI_FLOAT3, UNI_INT4, UNI_FLOAT4, UNI_MAT3, UNI_MAT4, UNI_MAX
506
.. method:: setUniformMatrix3(name, mat, transpose)
508
Set a uniform with a 3x3 matrix value
510
:arg name: the uniform name
512
:arg mat: A 3x3 matrix [[f, f, f], [f, f, f], [f, f, f]]
513
:type mat: 3x3 matrix
514
:arg transpose: set to True to transpose the matrix
515
:type transpose: boolean
517
.. method:: setUniformMatrix4(name, mat, transpose)
519
Set a uniform with a 4x4 matrix value
521
:arg name: the uniform name
523
:arg mat: A 4x4 matrix [[f, f, f, f], [f, f, f, f], [f, f, f, f], [f, f, f, f]]
524
:type mat: 4x4 matrix
525
:arg transpose: set to True to transpose the matrix
526
:type transpose: boolean
528
.. method:: setUniformiv(name, iList)
530
Set a uniform with a list of integer values
532
:arg name: the uniform name
534
:arg iList: a list (2, 3 or 4 elements) of integer values
535
:type iList: list[integer]
537
.. method:: validate()
539
Validate the shader object.
541
.. class:: BL_ShapeActionActuator(SCA_IActuator)
543
ShapeAction Actuators apply an shape action to an mesh object.
545
.. attribute:: action
547
The name of the action to set as the current shape action.
551
.. attribute:: frameStart
553
Specifies the starting frame of the shape animation.
557
.. attribute:: frameEnd
559
Specifies the ending frame of the shape animation.
563
.. attribute:: blendIn
565
Specifies the number of frames of animation to generate when making transitions between actions.
569
.. attribute:: priority
571
Sets the priority of this actuator. Actuators will lower priority numbers will override actuators with higher numbers.
577
Sets the current frame for the animation.
581
.. attribute:: propName
583
Sets the property to be used in FromProp playback mode.
587
.. attribute:: blendTime
589
Sets the internal frame timer. This property must be in the range from 0.0 to blendin.
595
The operation mode of the actuator. Can be one of :ref:`these constants<shape-action-actuator>`.
599
.. attribute:: framePropName
601
The name of the property that is set to the current frame number.
605
.. class:: CListValue(CPropValue)
607
This is a list like object used in the game engine internally that behaves similar to a python list in most ways.
609
As well as the normal index lookup (``val= clist[i]``), CListValue supports string lookups (``val= scene.objects["Cube"]``)
611
Other operations such as ``len(clist)``, ``list(clist)``, ``clist[0:10]`` are also supported.
613
.. method:: append(val)
615
Add an item to the list (like pythons append)
619
Appending values to the list can cause crashes when the list is used internally by the game engine.
621
.. method:: count(val)
623
Count the number of instances of a value in the list.
625
:return: number of instances
628
.. method:: index(val)
630
Return the index of a value in the list.
632
:return: The index of the value in the list.
635
.. method:: reverse()
637
Reverse the order of the list.
639
.. method:: get(key, default=None)
641
Return the value matching key, or the default value if its not found.
643
:return: The key value or a default.
645
.. method:: from_id(id)
647
This is a funtion especially for the game engine to return a value with a spesific id.
649
Since object names are not always unique, the id of an object can be used to get an object from the CValueList.
653
.. code-block:: python
655
myObID=id(gameObject)
656
ob= scene.objects.from_id(myObID)
658
Where ``myObID`` is an int or long from the id function.
660
This has the advantage that you can store the id in places you could not store a gameObject.
664
The id is derived from a memory location and will be different each time the game engine starts.
666
.. class:: KX_BlenderMaterial(PyObjectPlus)
670
.. method:: getShader()
672
Returns the material's shader.
674
:return: the material's shader
675
:rtype: :class:`BL_Shader`
677
.. method:: setBlending(src, dest)
679
Set the pixel color arithmetic functions.
681
:arg src: Specifies how the red, green, blue, and alpha source blending factors are computed.
682
:type src: Value in...
687
* GL_ONE_MINUS_SRC_COLOR,
689
* GL_ONE_MINUS_DST_COLOR,
691
* GL_ONE_MINUS_SRC_ALPHA,
693
* GL_ONE_MINUS_DST_ALPHA,
694
* GL_SRC_ALPHA_SATURATE
696
:arg dest: Specifies how the red, green, blue, and alpha destination blending factors are computed.
697
:type dest: Value in...
702
* GL_ONE_MINUS_SRC_COLOR
704
* GL_ONE_MINUS_DST_COLOR
706
* GL_ONE_MINUS_SRC_ALPHA
708
* GL_ONE_MINUS_DST_ALPHA
709
* GL_SRC_ALPHA_SATURATE
711
.. method:: getMaterialIndex()
713
Returns the material's index.
715
:return: the material's index
718
.. class:: KX_CameraActuator(SCA_IActuator)
720
Applies changes to a camera.
724
minimum distance to the target object maintained by the actuator.
730
maximum distance to stay from the target object.
734
.. attribute:: height
736
height to stay above the target object.
742
axis this actuator is tracking, True=X, False=Y.
746
.. attribute:: object
748
the object this actuator tracks.
750
:type: :class:`KX_GameObject` or None
752
.. class:: KX_ConstraintActuator(SCA_IActuator)
754
A constraint actuator limits the position, rotation, distance or orientation of an object.
758
Time constant of the constraint expressed in frame (not use by Force field constraint).
762
.. attribute:: rotDamp
764
Time constant for the rotation expressed in frame (only for the distance constraint), 0 = use damp for rotation as well.
768
.. attribute:: direction
770
The reference direction in world coordinate for the orientation constraint.
772
:type: 3-tuple of float: (x, y, z)
774
.. attribute:: option
776
Binary combination of :ref:`these constants <constraint-actuator-option>`
782
activation time of the actuator. The actuator disables itself after this many frame. If set to 0, the actuator is not limited in time.
786
.. attribute:: propName
788
the name of the property or material for the ray detection of the distance constraint.
794
The lower bound of the constraint. For the rotation and orientation constraint, it represents radiant.
798
.. attribute:: distance
800
the target distance of the distance constraint.
806
the upper bound of the constraint. For rotation and orientation constraints, it represents radiant.
810
.. attribute:: rayLength
812
the length of the ray of the distance constraint.
818
type of constraint. Use one of the :ref:`these constants <constraint-actuator-limit>`
823
.. class:: KX_ConstraintWrapper(PyObjectPlus)
827
.. method:: getConstraintId(val)
829
Returns the contraint's ID
831
:return: the constraint's ID
834
.. class:: KX_GameActuator(SCA_IActuator)
836
The game actuator loads a new .blend file, restarts the current .blend file or quits the game.
838
.. attribute:: fileName
840
the new .blend file to load.
846
The mode of this actuator. Can be on of :ref:`these constants <game-actuator>`
850
.. class:: KX_GameObject(SCA_IObject)
852
All game objects are derived from this class.
854
Properties assigned to game objects are accessible as attributes of this class.
858
Calling ANY method or attribute on an object that has been removed from a scene will raise a SystemError, if an object may have been removed since last accessing it use the :data:`invalid` attribute to check.
862
The object's name. (read-only).
874
The object must have a physics controller for the mass to be applied, otherwise the mass value will be returned as 0.0.
876
.. attribute:: linVelocityMin
878
Enforces the object keeps moving at a minimum velocity.
884
Applies to dynamic and rigid body objects only.
888
A value of 0.0 disables this option.
892
While objects are stationary the minimum velocity will not be applied.
894
.. attribute:: linVelocityMax
896
Clamp the maximum linear velocity to prevent objects moving beyond a set speed.
902
Applies to dynamic and rigid body objects only.
906
A value of 0.0 disables this option (rather then setting it stationary).
908
.. attribute:: localInertia
910
the object's inertia vector in local coordinates. Read only.
912
:type: list [ix, iy, iz]
914
.. attribute:: parent
916
The object's parent object. (read-only).
918
:type: :class:`KX_GameObject` or None
920
.. attribute:: visible
928
Game logic will still run for invisible objects.
932
The object color of the object.
934
:type: list [r, g, b, a]
936
.. attribute:: occlusion
938
occlusion capability flag.
942
.. attribute:: position
944
The object's position.
946
.. deprecated:: use :data:`localPosition` and :data:`worldPosition`.
948
:type: list [x, y, z] On write: local position, on read: world position
950
.. attribute:: orientation
952
The object's orientation. 3x3 Matrix. You can also write a Quaternion or Euler vector.
954
.. deprecated:: use :data:`localOrientation` and :data:`worldOrientation`.
956
:type: 3x3 Matrix [[float]] On write: local orientation, on read: world orientation
958
.. attribute:: scaling
960
The object's scaling factor. list [sx, sy, sz]
962
.. deprecated:: use :data:`localScale` and :data:`worldScale`.
964
:type: list [sx, sy, sz] On write: local scaling, on read: world scaling
966
.. attribute:: localOrientation
968
The object's local orientation. 3x3 Matrix. You can also write a Quaternion or Euler vector.
970
:type: 3x3 Matrix [[float]]
972
.. attribute:: worldOrientation
974
The object's world orientation.
976
:type: 3x3 Matrix [[float]]
978
.. attribute:: localScale
980
The object's local scaling factor.
982
:type: list [sx, sy, sz]
984
.. attribute:: worldScale
986
The object's world scaling factor. Read-only.
988
:type: list [sx, sy, sz]
990
.. attribute:: localPosition
992
The object's local position.
994
:type: list [x, y, z]
996
.. attribute:: worldPosition
998
The object's world position.
1000
:type: list [x, y, z]
1002
.. attribute:: timeOffset
1004
adjust the slowparent delay at runtime.
1008
.. attribute:: state
1010
the game object's state bitmask, using the first 30 bits, one bit must always be set.
1014
.. attribute:: meshes
1016
a list meshes for this object.
1018
:type: list of :class:`KX_MeshProxy`
1022
Most objects use only 1 mesh.
1026
Changes to this list will not update the KX_GameObject.
1028
.. attribute:: sensors
1030
a sequence of :class:`SCA_ISensor` objects with string/index lookups and iterator support.
1036
This attribute is experemental and may be removed (but probably wont be).
1040
Changes to this list will not update the KX_GameObject.
1042
.. attribute:: controllers
1044
a sequence of :class:`SCA_IController` objects with string/index lookups and iterator support.
1046
:type: list of :class:`SCA_ISensor`
1050
This attribute is experemental and may be removed (but probably wont be).
1054
Changes to this list will not update the KX_GameObject.
1056
.. attribute:: actuators
1058
a list of :class:`SCA_IActuator` with string/index lookups and iterator support.
1064
This attribute is experemental and may be removed (but probably wont be).
1068
Changes to this list will not update the KX_GameObject.
1070
.. attribute:: attrDict
1072
get the objects internal python attribute dictionary for direct (faster) access.
1076
.. attribute:: children
1078
direct children of this object, (read-only).
1080
:type: :class:`CListValue` of :class:`KX_GameObject`'s
1082
.. attribute:: childrenRecursive
1084
all children of this object including childrens children, (read-only).
1086
:type: :class:`CListValue` of :class:`KX_GameObject`'s
1088
.. method:: endObject()
1090
Delete this object, can be used in place of the EndObject Actuator.
1092
The actual removal of the object from the scene is delayed.
1094
.. method:: replaceMesh(mesh, useDisplayMesh=True, usePhysicsMesh=False)
1096
Replace the mesh of this object with a new mesh. This works the same was as the actuator.
1098
:arg mesh: mesh to replace or the meshes name.
1099
:type mesh: :class:`MeshProxy` or string
1100
:arg useDisplayMesh: when enabled the display mesh will be replaced (optional argument).
1101
:type useDisplayMesh: boolean
1102
:arg usePhysicsMesh: when enabled the physics mesh will be replaced (optional argument).
1103
:type usePhysicsMesh: boolean
1105
.. method:: setVisible(visible, recursive)
1107
Sets the game object's visible flag.
1109
:arg visible: the visible state to set.
1110
:type visible: boolean
1111
:arg recursive: optional argument to set all childrens visibility flag too.
1112
:type recursive: boolean
1114
.. method:: setOcclusion(occlusion, recursive)
1116
Sets the game object's occlusion capability.
1118
:arg occlusion: the state to set the occlusion to.
1119
:type occlusion: boolean
1120
:arg recursive: optional argument to set all childrens occlusion flag too.
1121
:type recursive: boolean
1123
.. method:: alignAxisToVect(vect, axis=2, factor=1.0)
1125
Aligns any of the game object's axis along the given vector.
1128
:arg vect: a vector to align the axis.
1129
:type vect: 3D vector
1130
:arg axis: The axis you want to align
1137
:arg factor: Only rotate a feaction of the distance to the target vector (0.0 - 1.0)
1140
.. method:: getAxisVect(vect)
1142
Returns the axis vector rotates by the objects worldspace orientation.
1143
This is the equivalent of multiplying the vector by the orientation matrix.
1145
:arg vect: a vector to align the axis.
1146
:type vect: 3D Vector
1147
:return: The vector in relation to the objects rotation.
1150
.. method:: applyMovement(movement, local=False)
1152
Sets the game object's movement.
1154
:arg movement: movement vector.
1155
:type movement: 3D Vector
1157
* False: you get the "global" movement ie: relative to world orientation.
1158
* True: you get the "local" movement ie: relative to object orientation.
1161
.. method:: applyRotation(rotation, local=False)
1163
Sets the game object's rotation.
1165
:arg rotation: rotation vector.
1166
:type rotation: 3D Vector
1168
* False: you get the "global" rotation ie: relative to world orientation.
1169
* True: you get the "local" rotation ie: relative to object orientation.
1172
.. method:: applyForce(force, local=False)
1174
Sets the game object's force.
1176
This requires a dynamic object.
1178
:arg force: force vector.
1179
:type force: 3D Vector
1181
* False: you get the "global" force ie: relative to world orientation.
1182
* True: you get the "local" force ie: relative to object orientation.
1183
:type local: boolean
1185
.. method:: applyTorque(torque, local=False)
1187
Sets the game object's torque.
1189
This requires a dynamic object.
1191
:arg torque: torque vector.
1192
:type torque: 3D Vector
1194
* False: you get the "global" torque ie: relative to world orientation.
1195
* True: you get the "local" torque ie: relative to object orientation.
1196
:type local: boolean
1198
.. method:: getLinearVelocity(local=False)
1200
Gets the game object's linear velocity.
1202
This method returns the game object's velocity through it's centre of mass, ie no angular velocity component.
1205
* False: you get the "global" velocity ie: relative to world orientation.
1206
* True: you get the "local" velocity ie: relative to object orientation.
1207
:type local: boolean
1208
:return: the object's linear velocity.
1209
:rtype: list [vx, vy, vz]
1211
.. method:: setLinearVelocity(velocity, local=False)
1213
Sets the game object's linear velocity.
1215
This method sets game object's velocity through it's centre of mass,
1216
ie no angular velocity component.
1218
This requires a dynamic object.
1220
:arg velocity: linear velocity vector.
1221
:type velocity: 3D Vector
1223
* False: you get the "global" velocity ie: relative to world orientation.
1224
* True: you get the "local" velocity ie: relative to object orientation.
1225
:type local: boolean
1227
.. method:: getAngularVelocity(local=False)
1229
Gets the game object's angular velocity.
1232
* False: you get the "global" velocity ie: relative to world orientation.
1233
* True: you get the "local" velocity ie: relative to object orientation.
1234
:type local: boolean
1235
:return: the object's angular velocity.
1236
:rtype: list [vx, vy, vz]
1238
.. method:: setAngularVelocity(velocity, local=False)
1240
Sets the game object's angular velocity.
1242
This requires a dynamic object.
1244
:arg velocity: angular velocity vector.
1245
:type velocity: boolean
1247
* False: you get the "global" velocity ie: relative to world orientation.
1248
* True: you get the "local" velocity ie: relative to object orientation.
1250
.. method:: getVelocity(point=(0, 0, 0))
1252
Gets the game object's velocity at the specified point.
1254
Gets the game object's velocity at the specified point, including angular
1257
:arg point: optional point to return the velocity for, in local coordinates.
1258
:type point: 3D Vector
1259
:return: the velocity at the specified point.
1260
:rtype: list [vx, vy, vz]
1262
.. method:: getReactionForce()
1264
Gets the game object's reaction force.
1266
The reaction force is the force applied to this object over the last simulation timestep.
1267
This also includes impulses, eg from collisions.
1269
:return: the reaction force of this object.
1270
:rtype: list [fx, fy, fz]
1274
This is not implimented at the moment.
1276
.. method:: applyImpulse(point, impulse)
1278
Applies an impulse to the game object.
1280
This will apply the specified impulse to the game object at the specified point.
1281
If point != position, applyImpulse will also change the object's angular momentum.
1282
Otherwise, only linear momentum will change.
1284
:arg point: the point to apply the impulse to (in world coordinates)
1285
:type point: the point to apply the impulse to (in world coordinates)
1287
.. method:: suspendDynamics()
1289
Suspends physics for this object.
1291
.. method:: restoreDynamics()
1293
Resumes physics for this object.
1297
The objects linear velocity will be applied from when the dynamics were suspended.
1299
.. method:: enableRigidBody()
1301
Enables rigid body physics for this object.
1303
Rigid body physics allows the object to roll on collisions.
1307
This is not working with bullet physics yet.
1309
.. method:: disableRigidBody()
1311
Disables rigid body physics for this object.
1315
This is not working with bullet physics yet. The angular is removed but rigid body physics can still rotate it later.
1317
.. method:: setParent(parent, compound=True, ghost=True)
1319
Sets this object's parent.
1320
Control the shape status with the optional compound and ghost parameters:
1322
In that case you can control if it should be ghost or not:
1324
:arg parent: new parent object.
1325
:type parent: :class:`KX_GameObject`
1326
:arg compound: whether the shape should be added to the parent compound shape.
1328
* True: the object shape should be added to the parent compound shape.
1329
* False: the object should keep its individual shape.
1331
:type compound: boolean
1332
:arg ghost: whether the object should be ghost while parented.
1334
* True: if the object should be made ghost while parented.
1335
* False: if the object should be solid while parented.
1337
:type ghost: boolean
1341
If the object type is sensor, it stays ghost regardless of ghost parameter
1343
.. method:: removeParent()
1345
Removes this objects parent.
1347
.. method:: getPhysicsId()
1349
Returns the user data object associated with this game object's physics controller.
1351
.. method:: getPropertyNames()
1353
Gets a list of all property names.
1355
:return: All property names for this object.
1358
.. method:: getDistanceTo(other)
1360
:arg other: a point or another :class:`KX_GameObject` to measure the distance to.
1361
:type other: :class:`KX_GameObject` or list [x, y, z]
1362
:return: distance to another object or point.
1365
.. method:: getVectTo(other)
1367
Returns the vector and the distance to another object or point.
1368
The vector is normalized unless the distance is 0, in which a zero length vector is returned.
1370
:arg other: a point or another :class:`KX_GameObject` to get the vector and distance to.
1371
:type other: :class:`KX_GameObject` or list [x, y, z]
1372
:return: (distance, globalVector(3), localVector(3))
1373
:rtype: 3-tuple (float, 3-tuple (x, y, z), 3-tuple (x, y, z))
1375
.. method:: rayCastTo(other, dist, prop)
1377
Look towards another point/object and find first object hit within dist that matches prop.
1379
The ray is always casted from the center of the object, ignoring the object itself.
1380
The ray is casted towards the center of another object or an explicit [x, y, z] point.
1381
Use rayCast() if you need to retrieve the hit point
1383
:arg other: [x, y, z] or object towards which the ray is casted
1384
:type other: :class:`KX_GameObject` or 3-tuple
1385
:arg dist: max distance to look (can be negative => look behind); 0 or omitted => detect up to other
1387
:arg prop: property name that object must have; can be omitted => detect any object
1389
:return: the first object hit or None if no object or object does not match prop
1390
:rtype: :class:`KX_GameObject`
1392
.. method:: rayCast(objto, objfrom, dist, prop, face, xray, poly)
1394
Look from a point/object to another point/object and find first object hit within dist that matches prop.
1395
if poly is 0, returns a 3-tuple with object reference, hit point and hit normal or (None, None, None) if no hit.
1396
if poly is 1, returns a 4-tuple with in addition a :class:`KX_PolyProxy` as 4th element.
1397
if poly is 2, returns a 5-tuple with in addition a 2D vector with the UV mapping of the hit point as 5th element.
1399
.. code-block:: python
1401
# shoot along the axis gun-gunAim (gunAim should be collision-free)
1402
obj, point, normal = gun.rayCast(gunAim, None, 50)
1407
The face paremeter determines the orientation of the normal.
1409
* 0 => hit normal is always oriented towards the ray origin (as if you casted the ray from outside)
1410
* 1 => hit normal is the real face normal (only for mesh object, otherwise face has no effect)
1412
The ray has X-Ray capability if xray parameter is 1, otherwise the first object hit (other than self object) stops the ray.
1413
The prop and xray parameters interact as follow.
1415
* prop off, xray off: return closest hit or no hit if there is no object on the full extend of the ray.
1416
* prop off, xray on : idem.
1417
* prop on, xray off: return closest hit if it matches prop, no hit otherwise.
1418
* prop on, xray on : return closest hit matching prop or no hit if there is no object matching prop on the full extend of the ray.
1420
The :class:`KX_PolyProxy` 4th element of the return tuple when poly=1 allows to retrieve information on the polygon hit by the ray.
1421
If there is no hit or the hit object is not a static mesh, None is returned as 4th element.
1423
The ray ignores collision-free objects and faces that dont have the collision flag enabled, you can however use ghost objects.
1425
:arg objto: [x, y, z] or object to which the ray is casted
1426
:type objto: :class:`KX_GameObject` or 3-tuple
1427
:arg objfrom: [x, y, z] or object from which the ray is casted; None or omitted => use self object center
1428
:type objfrom: :class:`KX_GameObject` or 3-tuple or None
1429
:arg dist: max distance to look (can be negative => look behind); 0 or omitted => detect up to to
1431
:arg prop: property name that object must have; can be omitted or "" => detect any object
1433
:arg face: normal option: 1=>return face normal; 0 or omitted => normal is oriented towards origin
1435
:arg xray: X-ray option: 1=>skip objects that don't match prop; 0 or omitted => stop on first object
1437
:arg poly: polygon option: 0, 1 or 2 to return a 3-, 4- or 5-tuple with information on the face hit.
1439
* 0 or omitted: return value is a 3-tuple (object, hitpoint, hitnormal) or (None, None, None) if no hit
1440
* 1: return value is a 4-tuple and the 4th element is a :class:`KX_PolyProxy` or None if no hit or the object doesn't use a mesh collision shape.
1441
* 2: return value is a 5-tuple and the 5th element is a 2-tuple (u, v) with the UV mapping of the hit point or None if no hit, or the object doesn't use a mesh collision shape, or doesn't have a UV mapping.
1444
:return: (object, hitpoint, hitnormal) or (object, hitpoint, hitnormal, polygon) or (object, hitpoint, hitnormal, polygon, hituv).
1446
* object, hitpoint and hitnormal are None if no hit.
1447
* polygon is valid only if the object is valid and is a static object, a dynamic object using mesh collision shape or a soft body object, otherwise it is None
1448
* hituv is valid only if polygon is valid and the object has a UV mapping, otherwise it is None
1452
* 3-tuple (:class:`KX_GameObject`, 3-tuple (x, y, z), 3-tuple (nx, ny, nz))
1453
* or 4-tuple (:class:`KX_GameObject`, 3-tuple (x, y, z), 3-tuple (nx, ny, nz), :class:`PolyProxy`)
1454
* or 5-tuple (:class:`KX_GameObject`, 3-tuple (x, y, z), 3-tuple (nx, ny, nz), :class:`PolyProxy`, 2-tuple (u, v))
1458
The ray ignores the object on which the method is called. It is casted from/to object center or explicit [x, y, z] points.
1460
.. method:: setCollisionMargin(margin)
1462
Set the objects collision margin.
1464
:arg margin: the collision margin distance in blender units.
1469
If this object has no physics controller (a physics ID of zero), this function will raise RuntimeError.
1471
.. method:: sendMessage(subject, body="", to="")
1475
:arg subject: The subject of the message
1476
:type subject: string
1477
:arg body: The body of the message (optional)
1479
:arg to: The name of the object to send the message to (optional)
1482
.. method:: reinstancePhysicsMesh(gameObject, meshObject)
1484
Updates the physics system with the changed mesh.
1486
If no arguments are given the physics mesh will be re-created from the first mesh assigned to the game object.
1488
:arg gameObject: optional argument, set the physics shape from this gameObjets mesh.
1489
:type gameObject: string, :class:`KX_GameObject` or None
1490
:arg meshObject: optional argument, set the physics shape from this mesh.
1491
:type meshObject: string, :class:`MeshProxy` or None
1493
:return: True if reinstance succeeded, False if it failed.
1498
If this object has instances the other instances will be updated too.
1502
The gameObject argument has an advantage that it can convert from a mesh with modifiers applied (such as subsurf).
1506
Only triangle mesh type objects are supported currently (not convex hull)
1510
If the object is a part of a combound object it will fail (parent or child)
1514
Rebuilding the physics mesh can be slow, running many times per second will give a performance hit.
1516
.. method:: get(key, default=None)
1518
Return the value matching key, or the default value if its not found.
1519
:return: The key value or a default.
1521
.. class:: KX_IpoActuator(SCA_IActuator)
1523
IPO actuator activates an animation.
1525
.. attribute:: frameStart
1531
.. attribute:: frameEnd
1537
.. attribute:: propName
1539
Use this property to define the Ipo position.
1543
.. attribute:: framePropName
1545
Assign this property this action current frame number.
1551
Play mode for the ipo. Can be on of :ref:`these constants <ipo-actuator>`
1555
.. attribute:: useIpoAsForce
1557
Apply Ipo as a global or local force depending on the local option (dynamic objects only).
1561
.. attribute:: useIpoAdd
1563
Ipo is added to the current loc/rot/scale in global or local coordinate according to Local flag.
1567
.. attribute:: useIpoLocal
1569
Let the ipo acts in local coordinates, used in Force and Add mode.
1573
.. attribute:: useChildren
1575
Update IPO on all children Objects as well.
1579
.. class:: KX_LightObject(KX_GameObject)
1583
.. code-block:: python
1585
# Turn on a red alert light.
1588
co = bge.logic.getCurrentController()
1592
light.colour = [1.0, 0.0, 0.0]
1596
A spot light source. See attribute :data:`type`
1600
A point light source with no attenuation. See attribute :data:`type`
1604
A point light source. See attribute :data:`type`
1608
The type of light - must be SPOT, SUN or NORMAL
1610
.. attribute:: layer
1612
The layer mask that this light affects object on.
1616
.. attribute:: energy
1618
The brightness of this light.
1622
.. attribute:: distance
1624
The maximum distance this light can illuminate. (SPOT and NORMAL lights only).
1628
.. attribute:: colour
1630
The colour of this light. Black = [0.0, 0.0, 0.0], White = [1.0, 1.0, 1.0].
1632
:type: list [r, g, b]
1634
.. attribute:: color
1638
.. attribute:: lin_attenuation
1640
The linear component of this light's attenuation. (SPOT and NORMAL lights only).
1644
.. attribute:: quad_attenuation
1646
The quadratic component of this light's attenuation (SPOT and NORMAL lights only).
1650
.. attribute:: spotsize
1652
The cone angle of the spot light, in degrees (SPOT lights only).
1654
:type: float in [0 - 180].
1656
.. attribute:: spotblend
1658
Specifies the intensity distribution of the spot light (SPOT lights only).
1660
:type: float in [0 - 1]
1664
Higher values result in a more focused light source.
1666
.. class:: KX_MeshProxy(SCA_IObject)
1670
You can only change the vertex properties of a mesh object, not the mesh topology.
1672
To use mesh objects effectively, you should know a bit about how the game engine handles them.
1674
#. Mesh Objects are converted from Blender at scene load.
1675
#. The Converter groups polygons by Material. This means they can be sent to the renderer efficiently. A material holds:
1678
#. The Blender material.
1679
#. The Tile properties
1680
#. The face properties - (From the "Texture Face" panel)
1681
#. Transparency & z sorting
1683
#. Polygon shape (triangle/quad)
1686
#. Verticies will be split by face if necessary. Verticies can only be shared between faces if:
1688
#. They are at the same position
1689
#. UV coordinates are the same
1690
#. Their normals are the same (both polygons are "Set Smooth")
1691
#. They are the same colour, for example: a cube has 24 verticies: 6 faces with 4 verticies per face.
1693
The correct method of iterating over every :class:`KX_VertexProxy` in a game object
1695
.. code-block:: python
1699
co = GameLogic.getCurrentController()
1703
mesh = obj.getMesh(m_i) # There can be more than one mesh...
1705
for mat in range(mesh.getNumMaterials()):
1706
for v_index in range(mesh.getVertexArrayLength(mat)):
1707
vertex = mesh.getVertex(mat, v_index)
1708
# Do something with vertex here...
1709
# ... eg: colour the vertex red.
1710
vertex.colour = [1.0, 0.0, 0.0, 1.0]
1712
mesh = obj.getMesh(m_i)
1714
.. attribute:: materials
1716
:type: list of :class:`KX_BlenderMaterial` or :class:`KX_PolygonMaterial` types
1718
.. attribute:: numPolygons
1722
.. attribute:: numMaterials
1726
.. method:: getNumMaterials()
1728
:return: number of materials associated with this object
1731
.. method:: getMaterialName(matid)
1733
Gets the name of the specified material.
1735
:arg matid: the specified material.
1736
:type matid: integer
1737
:return: the attached material name.
1740
.. method:: getTextureName(matid)
1742
Gets the name of the specified material's texture.
1744
:arg matid: the specified material
1745
:type matid: integer
1746
:return: the attached material's texture name.
1749
.. method:: getVertexArrayLength(matid)
1751
Gets the length of the vertex array associated with the specified material.
1753
There is one vertex array for each material.
1755
:arg matid: the specified material
1756
:type matid: integer
1757
:return: the number of verticies in the vertex array.
1760
.. method:: getVertex(matid, index)
1762
Gets the specified vertex from the mesh object.
1764
:arg matid: the specified material
1765
:type matid: integer
1766
:arg index: the index into the vertex array.
1767
:type index: integer
1768
:return: a vertex object.
1769
:rtype: :class:`KX_VertexProxy`
1771
.. method:: getNumPolygons()
1773
:return: The number of polygon in the mesh.
1776
.. method:: getPolygon(index)
1778
Gets the specified polygon from the mesh.
1780
:arg index: polygon number
1781
:type index: integer
1782
:return: a polygon object.
1783
:rtype: :class:`PolyProxy`
1785
.. class:: SCA_MouseSensor(SCA_ISensor)
1787
Mouse Sensor logic brick.
1789
.. attribute:: position
1791
current [x, y] coordinates of the mouse, in frame coordinates (pixels).
1793
:type: [integer, interger]
1801
* KX_MOUSESENSORMODE_LEFTBUTTON(1)
1802
* KX_MOUSESENSORMODE_MIDDLEBUTTON(2)
1803
* KX_MOUSESENSORMODE_RIGHTBUTTON(3)
1804
* KX_MOUSESENSORMODE_WHEELUP(4)
1805
* KX_MOUSESENSORMODE_WHEELDOWN(5)
1806
* KX_MOUSESENSORMODE_MOVEMENT(6)
1808
.. method:: getButtonStatus(button)
1810
Get the mouse button status.
1812
:arg button: The code that represents the key you want to get the state of, use one of :ref:`these constants<mouse-keys>`
1814
:return: The state of the given key, can be one of :ref:`these constants<input-status>`
1817
.. class:: KX_MouseFocusSensor(SCA_MouseSensor)
1819
The mouse focus sensor detects when the mouse is over the current game object.
1821
The mouse focus sensor works by transforming the mouse coordinates from 2d device
1822
space to 3d space then raycasting away from the camera.
1824
.. attribute:: raySource
1826
The worldspace source of the ray (the view position).
1828
:type: list (vector of 3 floats)
1830
.. attribute:: rayTarget
1832
The worldspace target of the ray.
1834
:type: list (vector of 3 floats)
1836
.. attribute:: rayDirection
1838
The :data:`rayTarget` - :class:`raySource` normalized.
1840
:type: list (normalized vector of 3 floats)
1842
.. attribute:: hitObject
1844
the last object the mouse was over.
1846
:type: :class:`KX_GameObject` or None
1848
.. attribute:: hitPosition
1850
The worldspace position of the ray intersecton.
1852
:type: list (vector of 3 floats)
1854
.. attribute:: hitNormal
1856
the worldspace normal from the face at point of intersection.
1858
:type: list (normalized vector of 3 floats)
1860
.. attribute:: hitUV
1862
the UV coordinates at the point of intersection.
1864
:type: list (vector of 2 floats)
1866
If the object has no UV mapping, it returns [0, 0].
1868
The UV coordinates are not normalized, they can be < 0 or > 1 depending on the UV mapping.
1870
.. attribute:: usePulseFocus
1872
When enabled, moving the mouse over a different object generates a pulse. (only used when the 'Mouse Over Any' sensor option is set).
1876
.. class:: KX_TouchSensor(SCA_ISensor)
1878
Touch sensor detects collisions between objects.
1880
.. attribute:: propName
1882
The property or material to collide with.
1886
.. attribute:: useMaterial
1888
Determines if the sensor is looking for a property or material. KX_True = Find material; KX_False = Find property.
1892
.. attribute:: usePulseCollision
1894
When enabled, changes to the set of colliding objects generate a pulse.
1898
.. attribute:: hitObject
1900
The last collided object. (read-only).
1902
:type: :class:`KX_GameObject` or None
1904
.. attribute:: hitObjectList
1906
A list of colliding objects. (read-only).
1908
:type: :class:`CListValue` of :class:`KX_GameObject`
1910
.. class:: KX_NearSensor(KX_TouchSensor)
1912
A near sensor is a specialised form of touch sensor.
1914
.. attribute:: distance
1916
The near sensor activates when an object is within this distance.
1920
.. attribute:: resetDistance
1922
The near sensor deactivates when the object exceeds this distance.
1926
.. class:: KX_NetworkMessageActuator(SCA_IActuator)
1930
.. attribute:: propName
1932
Messages will only be sent to objects with the given property name.
1936
.. attribute:: subject
1938
The subject field of the message.
1944
The body of the message.
1948
.. attribute:: usePropBody
1950
Send a property instead of a regular body message.
1954
.. class:: KX_NetworkMessageSensor(SCA_ISensor)
1956
The Message Sensor logic brick.
1958
Currently only loopback (local) networks are supported.
1960
.. attribute:: subject
1962
The subject the sensor is looking for.
1966
.. attribute:: frameMessageCount
1968
The number of messages received since the last frame. (read-only).
1972
.. attribute:: subjects
1974
The list of message subjects received. (read-only).
1976
:type: list of strings
1978
.. attribute:: bodies
1980
The list of message bodies received. (read-only).
1982
:type: list of strings
1984
.. class:: KX_ObjectActuator(SCA_IActuator)
1986
The object actuator ("Motion Actuator") applies force, torque, displacement, angular displacement,
1987
velocity, or angular velocity to an object.
1988
Servo control allows to regulate force to achieve a certain speed target.
1990
.. attribute:: force
1992
The force applied by the actuator.
1994
:type: list [x, y, z]
1996
.. attribute:: useLocalForce
1998
A flag specifying if the force is local.
2002
.. attribute:: torque
2004
The torque applied by the actuator.
2006
:type: list [x, y, z]
2008
.. attribute:: useLocalTorque
2010
A flag specifying if the torque is local.
2016
The displacement vector applied by the actuator.
2018
:type: list [x, y, z]
2020
.. attribute:: useLocalDLoc
2022
A flag specifying if the dLoc is local.
2028
The angular displacement vector applied by the actuator
2030
:type: list [x, y, z]
2034
Since the displacement is applied every frame, you must adjust the displacement based on the frame rate, or you game experience will depend on the player's computer speed.
2036
.. attribute:: useLocalDRot
2038
A flag specifying if the dRot is local.
2044
The linear velocity applied by the actuator.
2046
:type: list [x, y, z]
2048
.. attribute:: useLocalLinV
2050
A flag specifying if the linear velocity is local.
2056
This is the target speed for servo controllers.
2060
The angular velocity applied by the actuator.
2062
:type: list [x, y, z]
2064
.. attribute:: useLocalAngV
2066
A flag specifying if the angular velocity is local.
2070
.. attribute:: damping
2072
The damping parameter of the servo controller.
2076
.. attribute:: forceLimitX
2078
The min/max force limit along the X axis and activates or deactivates the limits in the servo controller.
2080
:type: list [min(float), max(float), bool]
2082
.. attribute:: forceLimitY
2084
The min/max force limit along the Y axis and activates or deactivates the limits in the servo controller.
2086
:type: list [min(float), max(float), bool]
2088
.. attribute:: forceLimitZ
2090
The min/max force limit along the Z axis and activates or deactivates the limits in the servo controller.
2092
:type: list [min(float), max(float), bool]
2096
The PID coefficients of the servo controller.
2098
:type: list of floats [proportional, integral, derivate]
2100
.. attribute:: reference
2102
The object that is used as reference to compute the velocity for the servo controller.
2104
:type: :class:`KX_GameObject` or None
2106
.. class:: KX_ParentActuator(SCA_IActuator)
2108
The parent actuator can set or remove an objects parent object.
2110
.. attribute:: object
2112
the object this actuator sets the parent too.
2114
:type: :class:`KX_GameObject` or None
2118
The mode of this actuator.
2120
:type: integer from 0 to 1.
2122
.. attribute:: compound
2124
Whether the object shape should be added to the parent compound shape when parenting.
2126
Effective only if the parent is already a compound shape.
2130
.. attribute:: ghost
2132
Whether the object should be made ghost when parenting
2133
Effective only if the shape is not added to the parent compound shape.
2137
.. class:: KX_PhysicsObjectWrapper(PyObjectPlus)
2139
KX_PhysicsObjectWrapper
2141
.. method:: setActive(active)
2143
Set the object to be active.
2145
:arg active: set to True to be active
2146
:type active: boolean
2148
.. method:: setAngularVelocity(x, y, z, local)
2150
Set the angular velocity of the object.
2152
:arg x: angular velocity for the x-axis
2155
:arg y: angular velocity for the y-axis
2158
:arg z: angular velocity for the z-axis
2161
:arg local: set to True for local axis
2162
:type local: boolean
2164
.. method:: setLinearVelocity(x, y, z, local)
2166
Set the linear velocity of the object.
2168
:arg x: linear velocity for the x-axis
2171
:arg y: linear velocity for the y-axis
2174
:arg z: linear velocity for the z-axis
2177
:arg local: set to True for local axis
2178
:type local: boolean
2180
.. class:: KX_PolyProxy(SCA_IObject)
2182
A polygon holds the index of the vertex forming the poylgon.
2185
The polygon attributes are read-only, you need to retrieve the vertex proxy if you want
2186
to change the vertex settings.
2188
.. attribute:: matname
2190
The name of polygon material, empty if no material.
2194
.. attribute:: material
2196
The material of the polygon.
2198
:type: :class:`KX_PolygonMaterial` or :class:`KX_BlenderMaterial`
2200
.. attribute:: texture
2202
The texture name of the polygon.
2206
.. attribute:: matid
2208
The material index of the polygon, use this to retrieve vertex proxy from mesh proxy.
2214
vertex index of the first vertex of the polygon, use this to retrieve vertex proxy from mesh proxy.
2220
vertex index of the second vertex of the polygon, use this to retrieve vertex proxy from mesh proxy.
2226
vertex index of the third vertex of the polygon, use this to retrieve vertex proxy from mesh proxy.
2232
Vertex index of the fourth vertex of the polygon, 0 if polygon has only 3 vertex
2233
Use this to retrieve vertex proxy from mesh proxy.
2237
.. attribute:: visible
2239
visible state of the polygon: 1=visible, 0=invisible.
2243
.. attribute:: collide
2245
collide state of the polygon: 1=receives collision, 0=collision free.
2249
.. method:: getMaterialName()
2251
Returns the polygon material name with MA prefix
2253
:return: material name
2256
.. method:: getMaterial()
2258
:return: The polygon material
2259
:rtype: :class:`KX_PolygonMaterial` or :class:`KX_BlenderMaterial`
2261
.. method:: getTextureName()
2263
:return: The texture name
2266
.. method:: getMaterialIndex()
2268
Returns the material bucket index of the polygon.
2269
This index and the ones returned by getVertexIndex() are needed to retrieve the vertex proxy from :class:`MeshProxy`.
2271
:return: the material index in the mesh
2274
.. method:: getNumVertex()
2276
Returns the number of vertex of the polygon.
2278
:return: number of vertex, 3 or 4.
2281
.. method:: isVisible()
2283
Returns whether the polygon is visible or not
2285
:return: 0=invisible, 1=visible
2288
.. method:: isCollider()
2290
Returns whether the polygon is receives collision or not
2292
:return: 0=collision free, 1=receives collision
2295
.. method:: getVertexIndex(vertex)
2297
Returns the mesh vertex index of a polygon vertex
2298
This index and the one returned by getMaterialIndex() are needed to retrieve the vertex proxy from :class:`MeshProxy`.
2300
:arg vertex: index of the vertex in the polygon: 0->3
2301
:arg vertex: integer
2302
:return: mesh vertex index
2305
.. method:: getMesh()
2307
Returns a mesh proxy
2310
:rtype: :class:`MeshProxy`
2312
.. class:: KX_PolygonMaterial(PyObjectPlus)
2314
This is the interface to materials in the game engine.
2316
Materials define the render state to be applied to mesh objects.
2320
Some of the methods/variables are CObjects. If you mix these up, you will crash blender.
2322
This example requires `PyOpenGL <http://pyopengl.sourceforge.net>`_ and `GLEWPy <http://glewpy.sourceforge.net>`_
2324
.. code-block:: python
2328
from OpenGL.GL import *
2329
from OpenGL.GLU import *
2339
gl_Position = ftransform();
2343
fragment_shader ="""
2347
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
2355
self.m_program = glCreateProgramObjectARB()
2356
# Compile the vertex shader
2357
self.shader(GL_VERTEX_SHADER_ARB, (vertex_shader))
2358
# Compile the fragment shader
2359
self.shader(GL_FRAGMENT_SHADER_ARB, (fragment_shader))
2360
# Link the shaders together
2363
def PrintInfoLog(self, tag, object):
2365
PrintInfoLog prints the GLSL compiler log
2367
print "Tag: def PrintGLError(self, tag = ""):
2369
def PrintGLError(self, tag = ""):
2371
Prints the current GL error status
2376
if err != GL_NO_ERROR:
2377
print "GL Error: %s\\n"%(gluErrorString(err))
2379
def shader(self, type, shaders):
2381
shader compiles a GLSL shader and attaches it to the current
2384
type should be either GL_VERTEX_SHADER_ARB or GL_FRAGMENT_SHADER_ARB
2385
shaders should be a sequence of shader source to compile.
2387
# Create a shader object
2388
shader_object = glCreateShaderObjectARB(type)
2390
# Add the source code
2391
glShaderSourceARB(shader_object, len(shaders), shaders)
2393
# Compile the shader
2394
glCompileShaderARB(shader_object)
2396
# Print the compiler log
2397
self.PrintInfoLog("vertex shader", shader_object)
2399
# Check if compiled, and attach if it did
2400
compiled = glGetObjectParameterivARB(shader_object, GL_OBJECT_COMPILE_STATUS_ARB)
2402
glAttachObjectARB(self.m_program, shader_object)
2404
# Delete the object (glAttachObjectARB makes a copy)
2405
glDeleteObjectARB(shader_object)
2407
# print the gl error log
2412
Links the shaders together.
2414
# clear error indicator
2417
glLinkProgramARB(self.m_program)
2419
self.PrintInfoLog("link", self.m_program)
2421
linked = glGetObjectParameterivARB(self.m_program, GL_OBJECT_LINK_STATUS_ARB)
2423
print "Shader failed to link"
2426
glValidateProgramARB(self.m_program)
2427
valid = glGetObjectParameterivARB(self.m_program, GL_OBJECT_VALIDATE_STATUS_ARB)
2429
print "Shader failed to validate"
2432
def activate(self, rasty, cachingInfo, mat):
2434
if (self.pass_no == 1):
2435
glDisable(GL_COLOR_MATERIAL)
2436
glUseProgramObjectARB(self.m_program)
2439
glEnable(GL_COLOR_MATERIAL)
2440
glUseProgramObjectARB(0)
2444
obj = GameLogic.getCurrentController().owner
2446
mesh = obj.meshes[0]
2448
for mat in mesh.materials:
2449
mat.setCustomMaterial(MyMaterial())
2452
.. attribute:: texture
2456
:type: string (read-only)
2458
.. attribute:: gl_texture
2460
OpenGL texture handle (eg for glBindTexture(GL_TEXTURE_2D, gl_texture).
2462
:type: integer (read-only)
2464
.. attribute:: material
2468
:type: string (read-only)
2470
.. attribute:: tface
2472
Texture face properties.
2474
:type: CObject (read-only)
2482
.. attribute:: tilexrep
2484
Number of tile repetitions in x direction.
2488
.. attribute:: tileyrep
2490
Number of tile repetitions in y direction.
2494
.. attribute:: drawingmode
2496
Drawing mode for the material.
2497
- 2 (drawingmode & 4) Textured
2498
- 4 (drawingmode & 16) Light
2499
- 14 (drawingmode & 16384) 3d Polygon Text.
2503
.. attribute:: transparent
2505
This material is transparent. All meshes with this
2506
material will be rendered after non transparent meshes from back
2511
.. attribute:: zsort
2513
Transparent polygons in meshes with this material will be sorted back to
2514
front before rendering.
2515
Non-Transparent polygons will be sorted front to back before rendering.
2519
.. attribute:: lightlayer
2521
Light layers this material affects.
2525
.. attribute:: triangle
2527
Mesh data with this material is triangles. It's probably not safe to change this.
2531
.. attribute:: diffuse
2533
The diffuse colour of the material. black = [0.0, 0.0, 0.0] white = [1.0, 1.0, 1.0].
2535
:type: list [r, g, b]
2537
.. attribute:: specular
2539
The specular colour of the material. black = [0.0, 0.0, 0.0] white = [1.0, 1.0, 1.0].
2541
:type: list [r, g, b]
2543
.. attribute:: shininess
2545
The shininess (specular exponent) of the material. 0.0 <= shininess <= 128.0.
2549
.. attribute:: specularity
2551
The amount of specular of the material. 0.0 <= specularity <= 1.0.
2555
.. method:: updateTexture(tface, rasty)
2557
Updates a realtime animation.
2559
:arg tface: Texture face (eg mat.tface)
2560
:type tface: CObject
2561
:arg rasty: Rasterizer
2562
:type rasty: CObject
2564
.. method:: setTexture(tface)
2566
Sets texture render state.
2568
:arg tface: Texture face
2569
:type tface: CObject
2571
.. code-block:: python
2573
mat.setTexture(mat.tface)
2575
.. method:: activate(rasty, cachingInfo)
2577
Sets material parameters for this object for rendering.
2579
Material Parameters set:
2589
:arg rasty: Rasterizer instance.
2590
:type rasty: CObject
2591
:arg cachingInfo: Material cache instance.
2592
:type cachingInfo: CObject
2594
.. method:: setCustomMaterial(material)
2596
Sets the material state setup object.
2598
Using this method, you can extend or completely replace the gameengine material
2599
to do your own advanced multipass effects.
2601
Use this method to register your material class. Instead of the normal material,
2602
your class's activate method will be called just before rendering the mesh.
2603
This should setup the texture, material, and any other state you would like.
2604
It should return True to render the mesh, or False if you are finished. You should
2605
clean up any state Blender does not set before returning False.
2607
Activate Method Definition:
2609
.. code-block:: python
2611
def activate(self, rasty, cachingInfo, material):
2613
:arg material: The material object.
2614
:type material: instance
2616
.. code-block:: python
2622
def activate(self, rasty, cachingInfo, material):
2623
# Activate the material here.
2625
# The activate method will be called until it returns False.
2626
# Every time the activate method returns True the mesh will
2629
# rasty is a CObject for passing to material.updateTexture()
2630
# and material.activate()
2631
# cachingInfo is a CObject for passing to material.activate()
2632
# material is the KX_PolygonMaterial instance this material
2635
# default material properties:
2637
if self.pass_no == 0:
2638
material.activate(rasty, cachingInfo)
2639
# Return True to do this pass
2642
# clean up and return False to finish.
2646
# Create a new Python Material and pass it to the renderer.
2647
mat.setCustomMaterial(PyMaterial())
2649
.. class:: KX_RadarSensor(KX_NearSensor)
2651
Radar sensor is a near sensor with a conical sensor object.
2653
.. attribute:: coneOrigin
2655
The origin of the cone with which to test. The origin is in the middle of the cone. (read-only).
2657
:type: list of floats [x, y, z]
2659
.. attribute:: coneTarget
2661
The center of the bottom face of the cone with which to test. (read-only).
2663
:type: list of floats [x, y, z]
2665
.. attribute:: distance
2667
The height of the cone with which to test.
2671
.. attribute:: angle
2673
The angle of the cone (in degrees) with which to test.
2675
:type: float from 0 to 360
2679
The axis on which the radar cone is cast.
2681
:type: integer from 0 to 5
2683
KX_RADAR_AXIS_POS_X, KX_RADAR_AXIS_POS_Y, KX_RADAR_AXIS_POS_Z,
2684
KX_RADAR_AXIS_NEG_X, KX_RADAR_AXIS_NEG_Y, KX_RADAR_AXIS_NEG_Z
2686
.. method:: getConeHeight()
2688
:return: The height of the cone with which to test.
2691
.. class:: KX_RaySensor(SCA_ISensor)
2693
A ray sensor detects the first object in a given direction.
2695
.. attribute:: propName
2697
The property the ray is looking for.
2701
.. attribute:: range
2703
The distance of the ray.
2707
.. attribute:: useMaterial
2709
Whether or not to look for a material (false = property).
2713
.. attribute:: useXRay
2715
Whether or not to use XRay.
2719
.. attribute:: hitObject
2721
The game object that was hit by the ray. (read-only).
2723
:type: :class:`KX_GameObject`
2725
.. attribute:: hitPosition
2727
The position (in worldcoordinates) where the object was hit by the ray. (read-only).
2729
:type: list [x, y, z]
2731
.. attribute:: hitNormal
2733
The normal (in worldcoordinates) of the object at the location where the object was hit by the ray. (read-only).
2735
:type: list [x, y, z]
2737
.. attribute:: rayDirection
2739
The direction from the ray (in worldcoordinates). (read-only).
2741
:type: list [x, y, z]
2745
The axis the ray is pointing on.
2747
:type: integer from 0 to 5
2756
.. class:: KX_SCA_AddObjectActuator(SCA_IActuator)
2758
Edit Object Actuator (in Add Object Mode)
2762
An Add Object actuator will be ignored if at game start, the linked object doesn't exist (or is empty) or the linked object is in an active layer.
2764
.. code-block:: none
2766
Error: GameObject 'Name' has a AddObjectActuator 'ActuatorName' without object (in 'nonactive' layer)
2768
.. attribute:: object
2770
the object this actuator adds.
2772
:type: :class:`KX_GameObject` or None
2774
.. attribute:: objectLastCreated
2776
the last added object from this actuator (read-only).
2778
:type: :class:`KX_GameObject` or None
2782
the lifetime of added objects, in frames. Set to 0 to disable automatic deletion.
2786
.. attribute:: linearVelocity
2788
the initial linear velocity of added objects.
2790
:type: list [vx, vy, vz]
2792
.. attribute:: angularVelocity
2794
the initial angular velocity of added objects.
2796
:type: list [vx, vy, vz]
2798
.. method:: instantAddObject()
2800
:return: The last object created by this actuator. The object can then be accessed from :data:`objectLastCreated`.
2803
.. class:: KX_SCA_DynamicActuator(SCA_IActuator)
2811
the type of operation of the actuator, 0-4
2813
* KX_DYN_RESTORE_DYNAMICS(0)
2814
* KX_DYN_DISABLE_DYNAMICS(1)
2815
* KX_DYN_ENABLE_RIGID_BODY(2)
2816
* KX_DYN_DISABLE_RIGID_BODY(3)
2817
* KX_DYN_SET_MASS(4)
2821
the mass value for the KX_DYN_SET_MASS operation.
2825
.. class:: KX_SCA_EndObjectActuator(SCA_IActuator)
2827
Edit Object Actuator (in End Object mode)
2829
This actuator has no python methods.
2831
.. class:: KX_SCA_ReplaceMeshActuator(SCA_IActuator)
2833
Edit Object actuator, in Replace Mesh mode.
2837
Replace mesh actuators will be ignored if at game start, the named mesh doesn't exist.
2839
This will generate a warning in the console
2841
.. code-block:: none
2843
Error: GameObject 'Name' ReplaceMeshActuator 'ActuatorName' without object
2845
.. code-block:: python
2848
# Switch a game object's mesh based on its depth in the camera view.
2849
# +----------+ +-----------+ +-------------------------------------+
2850
# | Always +-----+ Python +-----+ Edit Object (Replace Mesh) LOD.Mesh |
2851
# +----------+ +-----------+ +-------------------------------------+
2854
# List detail meshes here
2855
# Mesh (name, near, far)
2856
# Meshes overlap so that they don't 'pop' when on the edge of the distance.
2857
meshes = ((".Hi", 0.0, -20.0),
2858
(".Med", -15.0, -50.0),
2859
(".Lo", -40.0, -100.0)
2862
co = GameLogic.getCurrentController()
2864
act = co.actuators["LOD." + obj.name]
2865
cam = GameLogic.getCurrentScene().active_camera
2867
def Depth(pos, plane):
2868
return pos[0]*plane[0] + pos[1]*plane[1] + pos[2]*plane[2] + plane[3]
2870
# Depth is negative and decreasing further from the camera
2871
depth = Depth(obj.position, cam.world_to_camera[2])
2875
# Find the lowest detail mesh for depth
2877
if depth < mesh[1] and depth > mesh[2]:
2879
if "ME" + obj.name + mesh[0] == act.getMesh():
2882
if newmesh != None and "ME" + obj.name + newmesh[0] != act.getMesh():
2883
# The mesh is a different mesh - switch it.
2884
# Check the current mesh is not a better fit.
2885
if curmesh == None or curmesh[1] < depth or curmesh[2] > depth:
2886
act.mesh = obj.getName() + newmesh[0]
2887
GameLogic.addActiveActuator(act, True)
2891
:class:`MeshProxy` or the name of the mesh that will replace the current one.
2893
Set to None to disable actuator.
2895
:type: :class:`MeshProxy` or None if no mesh is set
2897
.. attribute:: useDisplayMesh
2899
when true the displayed mesh is replaced.
2903
.. attribute:: usePhysicsMesh
2905
when true the physics mesh is replaced.
2909
.. method:: instantReplaceMesh()
2911
Immediately replace mesh without delay.
2913
.. class:: KX_Scene(PyObjectPlus)
2915
An active scene that gives access to objects, cameras, lights and scene attributes.
2917
The activity culling stuff is supposed to disable logic bricks when their owner gets too far
2918
from the active camera. It was taken from some code lurking at the back of KX_Scene - who knows
2921
.. code-block:: python
2926
scene = GameLogic.getCurrentScene()
2928
# print all the objects in the scene
2929
for obj in scene.objects:
2932
# get an object named 'Cube'
2933
obj = scene.objects["Cube"]
2935
# get the first object in the scene.
2936
obj = scene.objects[0]
2938
.. code-block:: python
2940
# Get the depth of an object in the camera view.
2943
obj = GameLogic.getCurrentController().owner
2944
cam = GameLogic.getCurrentScene().active_camera
2946
# Depth is negative and decreasing further from the camera
2947
depth = obj.position[0]*cam.world_to_camera[2][0] + obj.position[1]*cam.world_to_camera[2][1] + obj.position[2]*cam.world_to_camera[2][2] + cam.world_to_camera[2][3]
2949
@bug: All attributes are read only at the moment.
2953
The scene's name, (read-only).
2957
.. attribute:: objects
2959
A list of objects in the scene, (read-only).
2961
:type: :class:`CListValue` of :class:`KX_GameObject`
2963
.. attribute:: objectsInactive
2965
A list of objects on background layers (used for the addObject actuator), (read-only).
2967
:type: :class:`CListValue` of :class:`KX_GameObject`
2969
.. attribute:: lights
2971
A list of lights in the scene, (read-only).
2973
:type: :class:`CListValue` of :class:`KX_LightObject`
2975
.. attribute:: cameras
2977
A list of cameras in the scene, (read-only).
2979
:type: :class:`CListValue` of :class:`KX_Camera`
2981
.. attribute:: active_camera
2983
The current active camera.
2985
:type: :class:`KX_Camera`
2989
This can be set directly from python to avoid using the :class:`KX_SceneActuator`.
2991
.. attribute:: suspended
2993
True if the scene is suspended, (read-only).
2997
.. attribute:: activity_culling
2999
True if the scene is activity culling.
3003
.. attribute:: activity_culling_radius
3005
The distance outside which to do activity culling. Measured in manhattan distance.
3009
.. attribute:: dbvt_culling
3011
True when Dynamic Bounding box Volume Tree is set (read-only).
3015
.. attribute:: pre_draw
3017
A list of callables to be run before the render step.
3021
.. attribute:: post_draw
3023
A list of callables to be run after the render step.
3027
.. method:: addObject(object, other, time=0)
3029
Adds an object to the scene like the Add Object Actuator would.
3031
:arg object: The object to add
3032
:type object: :class:`KX_GameObject` or string
3033
:arg other: The object's center to use when adding the object
3034
:type other: :class:`KX_GameObject` or string
3035
:arg time: The lifetime of the added object, in frames. A time of 0 means the object will last forever.
3037
:return: The newly added object.
3038
:rtype: :class:`KX_GameObject`
3042
Removes the scene from the game.
3044
.. method:: restart()
3048
.. method:: replace(scene)
3050
Replaces this scene with another one.
3052
:arg scene: The name of the scene to replace this scene with.
3055
.. method:: suspend()
3057
Suspends this scene.
3059
.. method:: resume()
3063
.. method:: get(key, default=None)
3065
Return the value matching key, or the default value if its not found.
3066
:return: The key value or a default.
3068
.. class:: KX_SceneActuator(SCA_IActuator)
3070
Scene Actuator logic brick.
3074
Scene actuators that use a scene name will be ignored if at game start, the named scene doesn't exist or is empty
3076
This will generate a warning in the console:
3078
.. code-block:: none
3080
Error: GameObject 'Name' has a SceneActuator 'ActuatorName' (SetScene) without scene
3082
.. attribute:: scene
3084
the name of the scene to change to/overlay/underlay/remove/suspend/resume.
3088
.. attribute:: camera
3090
the camera to change to.
3092
:type: :class:`KX_Camera` on read, string or :class:`KX_Camera` on write
3096
When setting the attribute, you can use either a :class:`KX_Camera` or the name of the camera.
3098
.. attribute:: useRestart
3100
Set flag to True to restart the sene.
3106
The mode of the actuator.
3108
:type: integer from 0 to 5.
3110
.. class:: KX_SoundActuator(SCA_IActuator)
3114
The :data:`startSound`, :data:`pauseSound` and :data:`stopSound` do not requirethe actuator to be activated - they act instantly provided that the actuator has been activated once at least.
3116
.. attribute:: fileName
3118
The filename of the sound this actuator plays.
3122
.. attribute:: volume
3124
The volume (gain) of the sound.
3128
.. attribute:: pitch
3130
The pitch of the sound.
3134
.. attribute:: rollOffFactor
3136
The roll off factor. Rolloff defines the rate of attenuation as the sound gets further away.
3140
.. attribute:: looping
3142
The loop mode of the actuator.
3146
.. attribute:: position
3148
The position of the sound as a list: [x, y, z].
3152
.. attribute:: velocity
3154
The velocity of the emitter as a list: [x, y, z]. The relative velocity to the observer determines the pitch. List of 3 floats: [x, y, z].
3158
.. attribute:: orientation
3160
The orientation of the sound. When setting the orientation you can also use quaternion [float, float, float, float] or euler angles [float, float, float].
3162
:type: 3x3 matrix [[float]]
3166
The operation mode of the actuator. Can be one of :ref:`these constants<logic-sound-actuator>`
3170
.. class:: KX_StateActuator(SCA_IActuator)
3172
State actuator changes the state mask of parent object.
3174
.. attribute:: operation
3176
Type of bit operation to be applied on object state mask.
3178
You can use one of :ref:`these constants <state-actuator-operation>`
3184
Value that defines the bits that will be modified by the operation.
3186
The bits that are 1 in the mask will be updated in the object state.
3188
The bits that are 0 are will be left unmodified expect for the Copy operation which copies the mask to the object state.
3192
.. class:: KX_TrackToActuator(SCA_IActuator)
3194
Edit Object actuator in Track To mode.
3198
Track To Actuators will be ignored if at game start, the object to track to is invalid.
3200
This will generate a warning in the console:
3202
.. code-block:: none
3204
GameObject 'Name' no object in EditObjectActuator 'ActuatorName'
3206
.. attribute:: object
3208
the object this actuator tracks.
3210
:type: :class:`KX_GameObject` or None
3214
the time in frames with which to delay the tracking motion.
3218
.. attribute:: use3D
3220
the tracking motion to use 3D.
3224
.. class:: KX_VehicleWrapper(PyObjectPlus)
3230
.. method:: addWheel(wheel, attachPos, attachDir, axleDir, suspensionRestLength, wheelRadius, hasSteering)
3232
Add a wheel to the vehicle
3234
:arg wheel: The object to use as a wheel.
3235
:type wheel: :class:`KX_GameObject` or a KX_GameObject name
3236
:arg attachPos: The position that this wheel will attach to.
3237
:type attachPos: vector of 3 floats
3238
:arg attachDir: The direction this wheel points.
3239
:type attachDir: vector of 3 floats
3240
:arg axleDir: The direction of this wheels axle.
3241
:type axleDir: vector of 3 floats
3242
:arg suspensionRestLength: TODO - Description
3243
:type suspensionRestLength: float
3244
:arg wheelRadius: The size of the wheel.
3245
:type wheelRadius: float
3247
.. method:: applyBraking(force, wheelIndex)
3249
Apply a braking force to the specified wheel
3251
:arg force: the brake force
3254
:arg wheelIndex: index of the wheel where the force needs to be applied
3255
:type wheelIndex: integer
3257
.. method:: applyEngineForce(force, wheelIndex)
3259
Apply an engine force to the specified wheel
3261
:arg force: the engine force
3264
:arg wheelIndex: index of the wheel where the force needs to be applied
3265
:type wheelIndex: integer
3267
.. method:: getConstraintId()
3269
Get the constraint ID
3271
:return: the constraint id
3274
.. method:: getConstraintType()
3276
Returns the constraint type.
3278
:return: constraint type
3281
.. method:: getNumWheels()
3283
Returns the number of wheels.
3285
:return: the number of wheels for this vehicle
3288
.. method:: getWheelOrientationQuaternion(wheelIndex)
3290
Returns the wheel orientation as a quaternion.
3292
:arg wheelIndex: the wheel index
3293
:type wheelIndex: integer
3295
:return: TODO Description
3296
:rtype: TODO - type should be quat as per method name but from the code it looks like a matrix
3298
.. method:: getWheelPosition(wheelIndex)
3300
Returns the position of the specified wheel
3302
:arg wheelIndex: the wheel index
3303
:type wheelIndex: integer
3304
:return: position vector
3305
:rtype: list[x, y, z]
3307
.. method:: getWheelRotation(wheelIndex)
3309
Returns the rotation of the specified wheel
3311
:arg wheelIndex: the wheel index
3312
:type wheelIndex: integer
3314
:return: the wheel rotation
3317
.. method:: setRollInfluence(rollInfluece, wheelIndex)
3319
Set the specified wheel's roll influence.
3320
The higher the roll influence the more the vehicle will tend to roll over in corners.
3322
:arg rollInfluece: the wheel roll influence
3323
:type rollInfluece: float
3325
:arg wheelIndex: the wheel index
3326
:type wheelIndex: integer
3328
.. method:: setSteeringValue(steering, wheelIndex)
3330
Set the specified wheel's steering
3332
:arg steering: the wheel steering
3333
:type steering: float
3335
:arg wheelIndex: the wheel index
3336
:type wheelIndex: integer
3338
.. method:: setSuspensionCompression(compression, wheelIndex)
3340
Set the specified wheel's compression
3342
:arg compression: the wheel compression
3343
:type compression: float
3345
:arg wheelIndex: the wheel index
3346
:type wheelIndex: integer
3348
.. method:: setSuspensionDamping(damping, wheelIndex)
3350
Set the specified wheel's damping
3352
:arg damping: the wheel damping
3353
:type damping: float
3355
:arg wheelIndex: the wheel index
3356
:type wheelIndex: integer
3358
.. method:: setSuspensionStiffness(stiffness, wheelIndex)
3360
Set the specified wheel's stiffness
3362
:arg stiffness: the wheel stiffness
3363
:type stiffness: float
3365
:arg wheelIndex: the wheel index
3366
:type wheelIndex: integer
3368
.. method:: setTyreFriction(friction, wheelIndex)
3370
Set the specified wheel's tyre friction
3372
:arg friction: the tyre friction
3373
:type friction: float
3375
:arg wheelIndex: the wheel index
3376
:type wheelIndex: integer
3378
.. class:: KX_VertexProxy(SCA_IObject)
3380
A vertex holds position, UV, colour and normal information.
3383
The physics simulation is NOT currently updated - physics will not respond
3384
to changes in the vertex position.
3388
The position of the vertex.
3390
:type: list [x, y, z]
3394
The texture coordinates of the vertex.
3398
.. attribute:: normal
3400
The normal of the vertex.
3402
:type: list [nx, ny, nz]
3404
.. attribute:: colour
3406
The colour of the vertex.
3408
:type: list [r, g, b, a]
3410
Black = [0.0, 0.0, 0.0, 1.0], White = [1.0, 1.0, 1.0, 1.0]
3412
.. attribute:: color
3418
The x coordinate of the vertex.
3424
The y coordinate of the vertex.
3430
The z coordinate of the vertex.
3436
The u texture coordinate of the vertex.
3442
The v texture coordinate of the vertex.
3448
The second u texture coordinate of the vertex.
3454
The second v texture coordinate of the vertex.
3460
The red component of the vertex colour. 0.0 <= r <= 1.0.
3466
The green component of the vertex colour. 0.0 <= g <= 1.0.
3472
The blue component of the vertex colour. 0.0 <= b <= 1.0.
3478
The alpha component of the vertex colour. 0.0 <= a <= 1.0.
3482
.. method:: getXYZ()
3484
Gets the position of this vertex.
3486
:return: this vertexes position in local coordinates.
3487
:rtype: list [x, y, z]
3489
.. method:: setXYZ(pos)
3491
Sets the position of this vertex.
3493
:type: list [x, y, z]
3495
:arg pos: the new position for this vertex in local coordinates.
3499
Gets the UV (texture) coordinates of this vertex.
3501
:return: this vertexes UV (texture) coordinates.
3504
.. method:: setUV(uv)
3506
Sets the UV (texture) coordinates of this vertex.
3510
.. method:: getUV2()
3512
Gets the 2nd UV (texture) coordinates of this vertex.
3514
:return: this vertexes UV (texture) coordinates.
3517
.. method:: setUV2(uv, unit)
3519
Sets the 2nd UV (texture) coordinates of this vertex.
3523
:arg unit: optional argument, FLAT==1, SECOND_UV==2, defaults to SECOND_UV
3526
.. method:: getRGBA()
3528
Gets the colour of this vertex.
3530
The colour is represented as four bytes packed into an integer value. The colour is
3533
Since Python offers no way to get each byte without shifting, you must use the struct module to
3534
access colour in an machine independent way.
3536
Because of this, it is suggested you use the r, g, b and a attributes or the colour attribute instead.
3538
.. code-block:: python
3541
col = struct.unpack('4B', struct.pack('I', v.getRGBA()))
3542
# col = (r, g, b, a)
3543
# black = ( 0, 0, 0, 255)
3544
# white = (255, 255, 255, 255)
3546
:return: packed colour. 4 byte integer with one byte per colour channel in RGBA format.
3549
.. method:: setRGBA(col)
3551
Sets the colour of this vertex.
3553
See getRGBA() for the format of col, and its relevant problems. Use the r, g, b and a attributes
3554
or the colour attribute instead.
3556
setRGBA() also accepts a four component list as argument col. The list represents the colour as [r, g, b, a]
3557
with black = [0.0, 0.0, 0.0, 1.0] and white = [1.0, 1.0, 1.0, 1.0]
3559
.. code-block:: python
3561
v.setRGBA(0xff0000ff) # Red
3562
v.setRGBA(0xff00ff00) # Green on little endian, transparent purple on big endian
3563
v.setRGBA([1.0, 0.0, 0.0, 1.0]) # Red
3564
v.setRGBA([0.0, 1.0, 0.0, 1.0]) # Green on all platforms.
3566
:arg col: the new colour of this vertex in packed RGBA format.
3567
:type col: integer or list [r, g, b, a]
3569
.. method:: getNormal()
3571
Gets the normal vector of this vertex.
3573
:return: normalised normal vector.
3574
:rtype: list [nx, ny, nz]
3576
.. method:: setNormal(normal)
3578
Sets the normal vector of this vertex.
3580
:type: sequence of floats [r, g, b]
3582
:arg normal: the new normal of this vertex.
3584
.. class:: KX_VisibilityActuator(SCA_IActuator)
3586
Visibility Actuator.
3588
.. attribute:: visibility
3590
whether the actuator makes its parent object visible or invisible.
3594
.. attribute:: useOcclusion
3596
whether the actuator makes its parent object an occluder or not.
3600
.. attribute:: useRecursion
3602
whether the visibility/occlusion should be propagated to all children of the object.
3606
.. class:: SCA_2DFilterActuator(SCA_IActuator)
3608
Create, enable and disable 2D filters
3610
The following properties don't have an immediate effect.
3611
You must active the actuator to get the result.
3612
The actuator is not persistent: it automatically stops itself after setting up the filter
3613
but the filter remains active. To stop a filter you must activate the actuator with 'type'
3614
set to :data:`~bge.logic.RAS_2DFILTER_DISABLED` or :data:`~bge.logic.RAS_2DFILTER_NOFILTER`.
3616
.. attribute:: shaderText
3618
shader source code for custom shader.
3622
.. attribute:: disableMotionBlur
3624
action on motion blur: 0=enable, 1=disable.
3630
Type of 2D filter, use one of :ref:`these constants <Two-D-FilterActuator-mode>`
3634
.. attribute:: passNumber
3636
order number of filter in the stack of 2D filters. Filters are executed in increasing order of passNb.
3638
Only be one filter can be defined per passNb.
3640
:type: integer (0-100)
3642
.. attribute:: value
3644
argument for motion blur filter.
3646
:type: float (0.0-100.0)
3648
.. class:: SCA_ANDController(SCA_IController)
3650
An AND controller activates only when all linked sensors are activated.
3652
There are no special python methods for this controller.
3654
.. class:: SCA_ActuatorSensor(SCA_ISensor)
3656
Actuator sensor detect change in actuator state of the parent object.
3657
It generates a positive pulse if the corresponding actuator is activated
3658
and a negative pulse if the actuator is deactivated.
3660
.. attribute:: actuator
3662
the name of the actuator that the sensor is monitoring.
3666
.. class:: SCA_AlwaysSensor(SCA_ISensor)
3668
This sensor is always activated.
3670
.. class:: SCA_DelaySensor(SCA_ISensor)
3672
The Delay sensor generates positive and negative triggers at precise time,
3673
expressed in number of frames. The delay parameter defines the length of the initial OFF period. A positive trigger is generated at the end of this period.
3675
The duration parameter defines the length of the ON period following the OFF period.
3676
There is a negative trigger at the end of the ON period. If duration is 0, the sensor stays ON and there is no negative trigger.
3678
The sensor runs the OFF-ON cycle once unless the repeat option is set: the OFF-ON cycle repeats indefinately (or the OFF cycle if duration is 0).
3680
Use :class:`SCA_ISensor.reset` at any time to restart sensor.
3682
.. attribute:: delay
3684
length of the initial OFF period as number of frame, 0 for immediate trigger.
3688
.. attribute:: duration
3690
length of the ON period in number of frame after the initial OFF period.
3692
If duration is greater than 0, a negative trigger is sent at the end of the ON pulse.
3696
.. attribute:: repeat
3698
1 if the OFF-ON cycle should be repeated indefinately, 0 if it should run once.
3702
.. class:: SCA_JoystickSensor(SCA_ISensor)
3704
This sensor detects player joystick events.
3706
.. attribute:: axisValues
3708
The state of the joysticks axis as a list of values :data:`numAxis` long. (read-only).
3710
:type: list of ints.
3712
Each spesifying the value of an axis between -32767 and 32767 depending on how far the axis is pushed, 0 for nothing.
3713
The first 2 values are used by most joysticks and gamepads for directional control. 3rd and 4th values are only on some joysticks and can be used for arbitary controls.
3715
* left:[-32767, 0, ...]
3716
* right:[32767, 0, ...]
3717
* up:[0, -32767, ...]
3718
* down:[0, 32767, ...]
3720
.. attribute:: axisSingle
3722
like :data:`axisValues` but returns a single axis value that is set by the sensor. (read-only).
3728
Only use this for "Single Axis" type sensors otherwise it will raise an error.
3730
.. attribute:: hatValues
3732
The state of the joysticks hats as a list of values :data:`numHats` long. (read-only).
3736
Each spesifying the direction of the hat from 1 to 12, 0 when inactive.
3738
Hat directions are as follows...
3750
.. attribute:: hatSingle
3752
Like :data:`hatValues` but returns a single hat direction value that is set by the sensor. (read-only).
3756
.. attribute:: numAxis
3758
The number of axes for the joystick at this index. (read-only).
3762
.. attribute:: numButtons
3764
The number of buttons for the joystick at this index. (read-only).
3768
.. attribute:: numHats
3770
The number of hats for the joystick at this index. (read-only).
3774
.. attribute:: connected
3776
True if a joystick is connected at this joysticks index. (read-only).
3780
.. attribute:: index
3782
The joystick index to use (from 0 to 7). The first joystick is always 0.
3786
.. attribute:: threshold
3788
Axis threshold. Joystick axis motion below this threshold wont trigger an event. Use values between (0 and 32767), lower values are more sensitive.
3792
.. attribute:: button
3794
The button index the sensor reacts to (first button = 0). When the "All Events" toggle is set, this option has no effect.
3800
The axis this sensor reacts to, as a list of two values [axisIndex, axisDirection]
3802
* axisIndex: the axis index to use when detecting axis movement, 1=primary directional control, 2=secondary directional control.
3803
* axisDirection: 0=right, 1=up, 2=left, 3=down.
3805
:type: [integer, integer]
3809
The hat the sensor reacts to, as a list of two values: [hatIndex, hatDirection]
3811
* hatIndex: the hat index to use when detecting hat movement, 1=primary hat, 2=secondary hat (4 max).
3812
* hatDirection: 1-12.
3814
:type: [integer, integer]
3816
.. method:: getButtonActiveList()
3818
:return: A list containing the indicies of the currently pressed buttons.
3821
.. method:: getButtonStatus(buttonIndex)
3823
:arg buttonIndex: the button index, 0=first button
3824
:type buttonIndex: integer
3825
:return: The current pressed state of the specified button.
3828
.. class:: SCA_KeyboardSensor(SCA_ISensor)
3830
A keyboard sensor detects player key presses.
3832
See module :mod:`bge.keys` for keycode values.
3836
The key code this sensor is looking for.
3838
:type: keycode from :mod:`bge.keys` module
3840
.. attribute:: hold1
3842
The key code for the first modifier this sensor is looking for.
3844
:type: keycode from :mod:`bge.keys` module
3846
.. attribute:: hold2
3848
The key code for the second modifier this sensor is looking for.
3850
:type: keycode from :mod:`bge.keys` module
3852
.. attribute:: toggleProperty
3854
The name of the property that indicates whether or not to log keystrokes as a string.
3858
.. attribute:: targetProperty
3860
The name of the property that receives keystrokes in case in case a string is logged.
3864
.. attribute:: useAllKeys
3866
Flag to determine whether or not to accept all keys.
3870
.. attribute:: events
3872
a list of pressed keys that have either been pressed, or just released, or are active this frame. (read-only).
3874
:type: list [[:ref:`keycode<keyboard-keys>`, :ref:`status<input-status>`], ...]
3876
.. method:: getKeyStatus(keycode)
3878
Get the status of a key.
3880
:arg keycode: The code that represents the key you want to get the state of, use one of :ref:`these constants<keyboard-keys>`
3881
:type keycode: integer
3882
:return: The state of the given key, can be one of :ref:`these constants<input-status>`
3885
.. class:: SCA_NANDController(SCA_IController)
3887
An NAND controller activates when all linked sensors are not active.
3889
There are no special python methods for this controller.
3891
.. class:: SCA_NORController(SCA_IController)
3893
An NOR controller activates only when all linked sensors are de-activated.
3895
There are no special python methods for this controller.
3897
.. class:: SCA_ORController(SCA_IController)
3899
An OR controller activates when any connected sensor activates.
3901
There are no special python methods for this controller.
3903
.. class:: SCA_PropertyActuator(SCA_IActuator)
3907
.. attribute:: propName
3909
the property on which to operate.
3913
.. attribute:: value
3915
the value with which the actuator operates.
3921
TODO - add constants to game logic dict!.
3925
.. class:: SCA_PropertySensor(SCA_ISensor)
3927
Activates when the game object property matches.
3931
Type of check on the property. Can be one of :ref:`these constants <logic-property-sensor>`
3935
.. attribute:: propName
3937
the property the sensor operates.
3941
.. attribute:: value
3943
the value with which the sensor compares to the value of the property.
3949
the minimum value of the range used to evaluate the property when in interval mode.
3955
the maximum value of the range used to evaluate the property when in interval mode.
3959
.. class:: SCA_PythonController(SCA_IController)
3961
A Python controller uses a Python script to activate it's actuators,
3962
based on it's sensors.
3964
.. attribute:: script
3966
The value of this variable depends on the execution methid.
3968
* When 'Script' execution mode is set this value contains the entire python script as a single string (not the script name as you might expect) which can be modified to run different scripts.
3969
* When 'Module' execution mode is set this value will contain a single line string - module name and function "module.func" or "package.modile.func" where the module names are python textblocks or external scripts.
3975
Once this is set the script name given for warnings will remain unchanged.
3979
the execution mode for this controller (read-only).
3981
* Script: 0, Execite the :data:`script` as a python code.
3982
* Module: 1, Execite the :data:`script` as a module and function.
3986
.. method:: activate(actuator)
3988
Activates an actuator attached to this controller.
3990
:arg actuator: The actuator to operate on.
3991
:type actuator: actuator or the actuator name as a string
3993
.. method:: deactivate(actuator)
3995
Deactivates an actuator attached to this controller.
3997
:arg actuator: The actuator to operate on.
3998
:type actuator: actuator or the actuator name as a string
4000
.. class:: SCA_RandomActuator(SCA_IActuator)
4006
Seed of the random number generator.
4010
Equal seeds produce equal series. If the seed is 0, the generator will produce the same value on every call.
4012
.. attribute:: para1
4014
the first parameter of the active distribution.
4016
:type: float, read-only.
4018
Refer to the documentation of the generator types for the meaning of this value.
4020
.. attribute:: para2
4022
the second parameter of the active distribution.
4024
:type: float, read-only
4026
Refer to the documentation of the generator types for the meaning of this value.
4028
.. attribute:: distribution
4030
Distribution type. (read-only). Can be one of :ref:`these constants <logic-random-distributions>`
4034
.. attribute:: propName
4036
the name of the property to set with the random value.
4040
If the generator and property types do not match, the assignment is ignored.
4042
.. method:: setBoolConst(value)
4044
Sets this generator to produce a constant boolean value.
4046
:arg value: The value to return.
4047
:type value: boolean
4049
.. method:: setBoolUniform()
4051
Sets this generator to produce a uniform boolean distribution.
4053
The generator will generate True or False with 50% chance.
4055
.. method:: setBoolBernouilli(value)
4057
Sets this generator to produce a Bernouilli distribution.
4059
:arg value: Specifies the proportion of False values to produce.
4061
* 0.0: Always generate True
4062
* 1.0: Always generate False
4065
.. method:: setIntConst(value)
4067
Sets this generator to always produce the given value.
4069
:arg value: the value this generator produces.
4070
:type value: integer
4072
.. method:: setIntUniform(lower_bound, upper_bound)
4074
Sets this generator to produce a random value between the given lower and
4075
upper bounds (inclusive).
4077
:type lower_bound: integer
4078
:type upper_bound: integer
4080
.. method:: setIntPoisson(value)
4082
Generate a Poisson-distributed number.
4084
This performs a series of Bernouilli tests with parameter value.
4085
It returns the number of tries needed to achieve succes.
4089
.. method:: setFloatConst(value)
4091
Always generate the given value.
4095
.. method:: setFloatUniform(lower_bound, upper_bound)
4097
Generates a random float between lower_bound and upper_bound with a
4098
uniform distribution.
4100
:type lower_bound: float
4101
:type upper_bound: float
4103
.. method:: setFloatNormal(mean, standard_deviation)
4105
Generates a random float from the given normal distribution.
4107
:arg mean: The mean (average) value of the generated numbers
4109
:arg standard_deviation: The standard deviation of the generated numbers.
4110
:type standard_deviation: float
4112
.. method:: setFloatNegativeExponential(half_life)
4114
Generate negative-exponentially distributed numbers.
4116
The half-life 'time' is characterized by half_life.
4118
:type half_life: float
4120
.. class:: SCA_RandomSensor(SCA_ISensor)
4122
This sensor activates randomly.
4124
.. attribute:: lastDraw
4126
The seed of the random number generator.
4132
The seed of the random number generator.
4136
.. method:: setSeed(seed)
4138
Sets the seed of the random number generator.
4140
If the seed is 0, the generator will produce the same value on every call.
4144
.. method:: getSeed()
4146
:return: The initial seed of the generator. Equal seeds produce equal random series.
4149
.. method:: getLastDraw()
4151
:return: The last random number generated.
4154
.. class:: SCA_XNORController(SCA_IController)
4156
An XNOR controller activates when all linked sensors are the same (activated or inative).
4158
There are no special python methods for this controller.
4160
.. class:: SCA_XORController(SCA_IController)
4162
An XOR controller activates when there is the input is mixed, but not when all are on or off.
4164
There are no special python methods for this controller.
4166
.. class:: KX_Camera(KX_GameObject)
4172
See :data:`sphereInsideFrustum` and :data:`boxInsideFrustum`
4176
See :data:`sphereInsideFrustum` and :data:`boxInsideFrustum`
4180
See :data:`sphereInsideFrustum` and :data:`boxInsideFrustum`
4184
The camera's lens value.
4188
.. attribute:: ortho_scale
4190
The camera's view scale when in orthographic mode.
4196
The camera's near clip distance.
4202
The camera's far clip distance.
4206
.. attribute:: perspective
4208
True if this camera has a perspective transform, False for an orthographic projection.
4212
.. attribute:: frustum_culling
4214
True if this camera is frustum culling.
4218
.. attribute:: projection_matrix
4220
This camera's 4x4 projection matrix.
4222
:type: 4x4 Matrix [[float]]
4224
.. attribute:: modelview_matrix
4226
This camera's 4x4 model view matrix. (read-only).
4228
:type: 4x4 Matrix [[float]]
4232
This matrix is regenerated every frame from the camera's position and orientation.
4234
.. attribute:: camera_to_world
4236
This camera's camera to world transform. (read-only).
4238
:type: 4x4 Matrix [[float]]
4242
This matrix is regenerated every frame from the camera's position and orientation.
4244
.. attribute:: world_to_camera
4246
This camera's world to camera transform. (read-only).
4248
:type: 4x4 Matrix [[float]]
4252
Regenerated every frame from the camera's position and orientation.
4256
This is camera_to_world inverted.
4258
.. attribute:: useViewport
4260
True when the camera is used as a viewport, set True to enable a viewport for this camera.
4264
.. method:: sphereInsideFrustum(centre, radius)
4266
Tests the given sphere against the view frustum.
4268
:arg centre: The centre of the sphere (in world coordinates.)
4269
:type centre: list [x, y, z]
4270
:arg radius: the radius of the sphere
4272
:return: :data:`~bge.types.KX_Camera.INSIDE`, :data:`~bge.types.KX_Camera.OUTSIDE` or :data:`~bge.types.KX_Camera.INTERSECT`
4277
When the camera is first initialized the result will be invalid because the projection matrix has not been set.
4279
.. code-block:: python
4282
co = GameLogic.getCurrentController()
4285
# A sphere of radius 4.0 located at [x, y, z] = [1.0, 1.0, 1.0]
4286
if (cam.sphereInsideFrustum([1.0, 1.0, 1.0], 4) != cam.OUTSIDE):
4287
# Sphere is inside frustum !
4288
# Do something useful !
4290
# Sphere is outside frustum
4292
.. method:: boxInsideFrustum(box)
4294
Tests the given box against the view frustum.
4296
:arg box: Eight (8) corner points of the box (in world coordinates.)
4297
:type box: list of lists
4298
:return: :data:`~bge.types.KX_Camera.INSIDE`, :data:`~bge.types.KX_Camera.OUTSIDE` or :data:`~bge.types.KX_Camera.INTERSECT`
4302
When the camera is first initialized the result will be invalid because the projection matrix has not been set.
4304
.. code-block:: python
4307
co = GameLogic.getCurrentController()
4312
box.append([-1.0, -1.0, -1.0])
4313
box.append([-1.0, -1.0, 1.0])
4314
box.append([-1.0, 1.0, -1.0])
4315
box.append([-1.0, 1.0, 1.0])
4316
box.append([ 1.0, -1.0, -1.0])
4317
box.append([ 1.0, -1.0, 1.0])
4318
box.append([ 1.0, 1.0, -1.0])
4319
box.append([ 1.0, 1.0, 1.0])
4321
if (cam.boxInsideFrustum(box) != cam.OUTSIDE):
4322
# Box is inside/intersects frustum !
4323
# Do something useful !
4325
# Box is outside the frustum !
4327
.. method:: pointInsideFrustum(point)
4329
Tests the given point against the view frustum.
4331
:arg point: The point to test (in world coordinates.)
4332
:type point: 3D Vector
4333
:return: True if the given point is inside this camera's viewing frustum.
4338
When the camera is first initialized the result will be invalid because the projection matrix has not been set.
4340
.. code-block:: python
4343
co = GameLogic.getCurrentController()
4346
# Test point [0.0, 0.0, 0.0]
4347
if (cam.pointInsideFrustum([0.0, 0.0, 0.0])):
4348
# Point is inside frustum !
4349
# Do something useful !
4351
# Box is outside the frustum !
4353
.. method:: getCameraToWorld()
4355
Returns the camera-to-world transform.
4357
:return: the camera-to-world transform matrix.
4358
:rtype: matrix (4x4 list)
4360
.. method:: getWorldToCamera()
4362
Returns the world-to-camera transform.
4364
This returns the inverse matrix of getCameraToWorld().
4366
:return: the world-to-camera transform matrix.
4367
:rtype: matrix (4x4 list)
4369
.. method:: setOnTop()
4371
Set this cameras viewport ontop of all other viewport.
4373
.. method:: setViewport(left, bottom, right, top)
4375
Sets the region of this viewport on the screen in pixels.
4377
Use :data:`bge.render.getWindowHeight` and :data:`bge.render.getWindowWidth` to calculate values relative to the entire display.
4379
:arg left: left pixel coordinate of this viewport
4381
:arg bottom: bottom pixel coordinate of this viewport
4382
:type bottom: integer
4383
:arg right: right pixel coordinate of this viewport
4384
:type right: integer
4385
:arg top: top pixel coordinate of this viewport
4388
.. method:: getScreenPosition(object)
4390
Gets the position of an object projected on screen space.
4392
.. code-block:: python
4394
# For an object in the middle of the screen, coord = [0.5, 0.5]
4395
coord = camera.getScreenPosition(object)
4397
:arg object: object name or list [x, y, z]
4398
:type object: :class:`KX_GameObject` or 3D Vector
4399
:return: the object's position in screen coordinates.
4402
.. method:: getScreenVect(x, y)
4404
Gets the vector from the camera position in the screen coordinate direction.
4411
:return: The vector from screen coordinate.
4413
.. code-block:: python
4415
# Gets the vector of the camera front direction:
4416
m_vect = camera.getScreenVect(0.5, 0.5)
4418
.. method:: getScreenRay(x, y, dist=inf, property=None)
4420
Look towards a screen coordinate (x, y) and find first object hit within dist that matches prop.
4421
The ray is similar to KX_GameObject->rayCastTo.
4427
:arg dist: max distance to look (can be negative => look behind); 0 or omitted => detect up to other
4429
:arg property: property name that object must have; can be omitted => detect any object
4430
:type property: string
4431
:rtype: :class:`KX_GameObject`
4432
:return: the first object hit or None if no object or object does not match prop
4434
.. code-block:: python
4436
# Gets an object with a property "wall" in front of the camera within a distance of 100:
4437
target = camera.getScreenRay(0.5, 0.5, 100, "wall")
4439
.. class:: BL_ArmatureObject(KX_GameObject)
4443
.. attribute:: constraints
4445
The list of armature constraint defined on this armature.
4446
Elements of the list can be accessed by index or string.
4447
The key format for string access is '<bone_name>:<constraint_name>'.
4449
:type: list of :class:`BL_ArmatureConstraint`
4451
.. attribute:: channels
4453
The list of armature channels.
4454
Elements of the list can be accessed by index or name the bone.
4456
:type: list of :class:`BL_ArmatureChannel`
4458
.. method:: update()
4460
Ensures that the armature will be updated on next graphic frame.
4462
This action is unecessary if a KX_ArmatureActuator with mode run is active
4463
or if an action is playing. Use this function in other cases. It must be called
4464
on each frame to ensure that the armature is updated continously.
4466
.. class:: BL_ArmatureActuator(SCA_IActuator)
4468
Armature Actuators change constraint condition on armatures.
4470
.. _armatureactuator-constants-type:
4472
Constants related to :data:`~bge.types.BL_ArmatureActuator.type`
4474
.. data:: KX_ACT_ARMATURE_RUN
4476
Just make sure the armature will be updated on the next graphic frame. This is the only persistent mode of the actuator: it executes automatically once per frame until stopped by a controller
4480
.. data:: KX_ACT_ARMATURE_ENABLE
4482
Enable the constraint.
4486
.. data:: KX_ACT_ARMATURE_DISABLE
4488
Disable the constraint (runtime constraint values are not updated).
4492
.. data:: KX_ACT_ARMATURE_SETTARGET
4494
Change target and subtarget of constraint.
4498
.. data:: KX_ACT_ARMATURE_SETWEIGHT
4500
Change weight of (only for IK constraint).
4506
The type of action that the actuator executes when it is active.
4508
Can be one of :ref:`these constants <armatureactuator-constants-type>`
4512
.. attribute:: constraint
4514
The constraint object this actuator is controlling.
4516
:type: :class:`BL_ArmatureConstraint`
4518
.. attribute:: target
4520
The object that this actuator will set as primary target to the constraint it controls.
4522
:type: :class:`KX_GameObject`
4524
.. attribute:: subtarget
4526
The object that this actuator will set as secondary target to the constraint it controls.
4528
:type: :class:`KX_GameObject`.
4532
Currently, the only secondary target is the pole target for IK constraint.
4534
.. attribute:: weight
4536
The weight this actuator will set on the constraint it controls.
4542
Currently only the IK constraint has a weight. It must be a value between 0 and 1.
4546
A weight of 0 disables a constraint while still updating constraint runtime values (see :class:`BL_ArmatureConstraint`)
4548
.. class:: KX_ArmatureSensor(SCA_ISensor)
4550
Armature sensor detect conditions on armatures.
4552
.. _armaturesensor-type:
4554
Constants related to :data:`type`
4556
.. data:: KX_ARMSENSOR_STATE_CHANGED
4558
Detect that the constraint is changing state (active/inactive)
4562
.. data:: KX_ARMSENSOR_LIN_ERROR_BELOW
4564
Detect that the constraint linear error is above a threshold
4568
.. data:: KX_ARMSENSOR_LIN_ERROR_ABOVE
4570
Detect that the constraint linear error is below a threshold
4574
.. data:: KX_ARMSENSOR_ROT_ERROR_BELOW
4576
Detect that the constraint rotation error is above a threshold
4580
.. data:: KX_ARMSENSOR_ROT_ERROR_ABOVE
4582
Detect that the constraint rotation error is below a threshold
4588
The type of measurement that the sensor make when it is active.
4590
Can be one of :ref:`these constants <armaturesensor-type>`
4594
.. attribute:: constraint
4596
The constraint object this sensor is watching.
4598
:type: :class:`BL_ArmatureConstraint`
4600
.. attribute:: value
4602
The threshold used in the comparison with the constraint error
4603
The linear error is only updated on CopyPose/Distance IK constraint with iTaSC solver
4604
The rotation error is only updated on CopyPose+rotation IK constraint with iTaSC solver
4605
The linear error on CopyPose is always >= 0: it is the norm of the distance between the target and the bone
4606
The rotation error on CopyPose is always >= 0: it is the norm of the equivalent rotation vector between the bone and the target orientations
4607
The linear error on Distance can be positive if the distance between the bone and the target is greater than the desired distance, and negative if the distance is smaller.
4611
.. class:: BL_ArmatureConstraint(PyObjectPlus)
4613
Proxy to Armature Constraint. Allows to change constraint on the fly.
4614
Obtained through :class:`BL_ArmatureObject`.constraints.
4618
Not all armature constraints are supported in the GE.
4620
.. _armatureconstraint-constants-type:
4622
Constants related to :data:`type`
4624
.. data:: CONSTRAINT_TYPE_TRACKTO
4625
.. data:: CONSTRAINT_TYPE_KINEMATIC
4626
.. data:: CONSTRAINT_TYPE_ROTLIKE
4627
.. data:: CONSTRAINT_TYPE_LOCLIKE
4628
.. data:: CONSTRAINT_TYPE_MINMAX
4629
.. data:: CONSTRAINT_TYPE_SIZELIKE
4630
.. data:: CONSTRAINT_TYPE_LOCKTRACK
4631
.. data:: CONSTRAINT_TYPE_STRETCHTO
4632
.. data:: CONSTRAINT_TYPE_CLAMPTO
4633
.. data:: CONSTRAINT_TYPE_TRANSFORM
4634
.. data:: CONSTRAINT_TYPE_DISTLIMIT
4636
.. _armatureconstraint-constants-ik-type:
4638
Constants related to :data:`ik_type`
4640
.. data:: CONSTRAINT_IK_COPYPOSE
4642
constraint is trying to match the position and eventually the rotation of the target.
4646
.. data:: CONSTRAINT_IK_DISTANCE
4648
Constraint is maintaining a certain distance to target subject to ik_mode
4652
.. _armatureconstraint-constants-ik-flag:
4654
Constants related to :data:`ik_flag`
4656
.. data:: CONSTRAINT_IK_FLAG_TIP
4658
Set when the constraint operates on the head of the bone and not the tail
4662
.. data:: CONSTRAINT_IK_FLAG_ROT
4664
Set when the constraint tries to match the orientation of the target
4668
.. data:: CONSTRAINT_IK_FLAG_STRETCH
4670
Set when the armature is allowed to stretch (only the bones with stretch factor > 0.0)
4674
.. data:: CONSTRAINT_IK_FLAG_POS
4676
Set when the constraint tries to match the position of the target.
4680
.. _armatureconstraint-constants-ik-mode:
4682
Constants related to :data:`ik_mode`
4684
.. data:: CONSTRAINT_IK_MODE_INSIDE
4686
The constraint tries to keep the bone within ik_dist of target
4690
.. data:: CONSTRAINT_IK_MODE_OUTSIDE
4692
The constraint tries to keep the bone outside ik_dist of the target
4696
.. data:: CONSTRAINT_IK_MODE_ONSURFACE
4698
The constraint tries to keep the bone exactly at ik_dist of the target.
4704
Type of constraint, (read-only).
4706
Use one of :ref:`these constants<armatureconstraint-constants-type>`.
4708
:type: integer, one of CONSTRAINT_TYPE_* constants
4712
Name of constraint constructed as <bone_name>:<constraint_name>. constraints list.
4716
This name is also the key subscript on :class:`BL_ArmatureObject`.
4718
.. attribute:: enforce
4720
fraction of constraint effect that is enforced. Between 0 and 1.
4724
.. attribute:: headtail
4726
Position of target between head and tail of the target bone: 0=head, 1=tail.
4732
Only used if the target is a bone (i.e target object is an armature.
4734
.. attribute:: lin_error
4736
runtime linear error (in Blender units) on constraint at the current frame.
4738
This is a runtime value updated on each frame by the IK solver. Only available on IK constraint and iTaSC solver.
4742
.. attribute:: rot_error
4744
Runtime rotation error (in radiant) on constraint at the current frame.
4748
This is a runtime value updated on each frame by the IK solver. Only available on IK constraint and iTaSC solver.
4750
It is only set if the constraint has a rotation part, for example, a CopyPose+Rotation IK constraint.
4752
.. attribute:: target
4754
Primary target object for the constraint. The position of this object in the GE will be used as target for the constraint.
4756
:type: :class:`KX_GameObject`.
4758
.. attribute:: subtarget
4760
Secondary target object for the constraint. The position of this object in the GE will be used as secondary target for the constraint.
4762
:type: :class:`KX_GameObject`.
4764
Currently this is only used for pole target on IK constraint.
4766
.. attribute:: active
4768
True if the constraint is active.
4774
An inactive constraint does not update lin_error and rot_error.
4776
.. attribute:: ik_weight
4778
Weight of the IK constraint between 0 and 1.
4780
Only defined for IK constraint.
4784
.. attribute:: ik_type
4786
Type of IK constraint, (read-only).
4788
Use one of :ref:`these constants<armatureconstraint-constants-ik-type>`.
4792
.. attribute:: ik_flag
4794
Combination of IK constraint option flags, read-only.
4796
Use one of :ref:`these constants<armatureconstraint-constants-ik-flag>`.
4800
.. attribute:: ik_dist
4802
Distance the constraint is trying to maintain with target, only used when ik_type=CONSTRAINT_IK_DISTANCE.
4806
.. attribute:: ik_mode
4808
Use one of :ref:`these constants<armatureconstraint-constants-ik-mode>`.
4810
Additional mode for IK constraint. Currently only used for Distance constraint:
4814
.. class:: BL_ArmatureChannel(PyObjectPlus)
4816
Proxy to armature pose channel. Allows to read and set armature pose.
4817
The attributes are identical to RNA attributes, but mostly in read-only mode.
4819
See :data:`rotation_mode`
4821
.. data:: PCHAN_ROT_QUAT
4822
.. data:: PCHAN_ROT_XYZ
4823
.. data:: PCHAN_ROT_XZY
4824
.. data:: PCHAN_ROT_YXZ
4825
.. data:: PCHAN_ROT_YZX
4826
.. data:: PCHAN_ROT_ZXY
4827
.. data:: PCHAN_ROT_ZYX
4831
channel name (=bone name), read-only.
4837
return the bone object corresponding to this pose channel, read-only.
4839
:type: :class:`BL_ArmatureBone`
4841
.. attribute:: parent
4843
return the parent channel object, None if root channel, read-only.
4845
:type: :class:`BL_ArmatureChannel`
4847
.. attribute:: has_ik
4849
true if the bone is part of an active IK chain, read-only.
4850
This flag is not set when an IK constraint is defined but not enabled (miss target information for example).
4854
.. attribute:: ik_dof_x
4856
true if the bone is free to rotation in the X axis, read-only.
4860
.. attribute:: ik_dof_y
4862
true if the bone is free to rotation in the Y axis, read-only.
4866
.. attribute:: ik_dof_z
4868
true if the bone is free to rotation in the Z axis, read-only.
4872
.. attribute:: ik_limit_x
4874
true if a limit is imposed on X rotation, read-only.
4878
.. attribute:: ik_limit_y
4880
true if a limit is imposed on Y rotation, read-only.
4884
.. attribute:: ik_limit_z
4886
true if a limit is imposed on Z rotation, read-only.
4890
.. attribute:: ik_rot_control
4892
true if channel rotation should applied as IK constraint, read-only.
4896
.. attribute:: ik_lin_control
4898
true if channel size should applied as IK constraint, read-only.
4902
.. attribute:: location
4904
displacement of the bone head in armature local space, read-write.
4906
:type: vector [X, Y, Z].
4910
You can only move a bone if it is unconnected to its parent. An action playing on the armature may change the value. An IK chain does not update this value, see joint_rotation.
4914
Changing this field has no immediate effect, the pose is updated when the armature is updated during the graphic render (see :data:`BL_ArmatureObject.update`).
4916
.. attribute:: scale
4918
scale of the bone relative to its parent, read-write.
4920
:type: vector [sizeX, sizeY, sizeZ].
4924
An action playing on the armature may change the value. An IK chain does not update this value, see joint_rotation.
4928
Changing this field has no immediate effect, the pose is updated when the armature is updated during the graphic render (see :data:`BL_ArmatureObject.update`)
4930
.. attribute:: rotation
4932
rotation of the bone relative to its parent expressed as a quaternion, read-write.
4934
:type: vector [qr, qi, qj, qk].
4938
This field is only used if rotation_mode is 0. An action playing on the armature may change the value. An IK chain does not update this value, see joint_rotation.
4942
Changing this field has no immediate effect, the pose is updated when the armature is updated during the graphic render (see :data:`BL_ArmatureObject.update`)
4944
.. attribute:: euler_rotation
4946
rotation of the bone relative to its parent expressed as a set of euler angles, read-write.
4948
:type: vector [X, Y, Z].
4952
This field is only used if rotation_mode is > 0. You must always pass the angles in [X, Y, Z] order; the order of applying the angles to the bone depends on rotation_mode. An action playing on the armature may change this field. An IK chain does not update this value, see joint_rotation.
4956
Changing this field has no immediate effect, the pose is updated when the armature is updated during the graphic render (see :data:`BL_ArmatureObject.update`)
4958
.. attribute:: rotation_mode
4960
Method of updating the bone rotation, read-write.
4964
Use the following constants (euler mode are named as in Blender UI but the actual axis order is reversed).
4966
* PCHAN_ROT_QUAT(0) : use quaternioin in rotation attribute to update bone rotation
4967
* PCHAN_ROT_XYZ(1) : use euler_rotation and apply angles on bone's Z, Y, X axis successively
4968
* PCHAN_ROT_XZY(2) : use euler_rotation and apply angles on bone's Y, Z, X axis successively
4969
* PCHAN_ROT_YXZ(3) : use euler_rotation and apply angles on bone's Z, X, Y axis successively
4970
* PCHAN_ROT_YZX(4) : use euler_rotation and apply angles on bone's X, Z, Y axis successively
4971
* PCHAN_ROT_ZXY(5) : use euler_rotation and apply angles on bone's Y, X, Z axis successively
4972
* PCHAN_ROT_ZYX(6) : use euler_rotation and apply angles on bone's X, Y, Z axis successively
4974
.. attribute:: channel_matrix
4976
pose matrix in bone space (deformation of the bone due to action, constraint, etc), Read-only.
4977
This field is updated after the graphic render, it represents the current pose.
4979
:type: matrix [4][4]
4981
.. attribute:: pose_matrix
4983
pose matrix in armature space, read-only,
4984
This field is updated after the graphic render, it represents the current pose.
4986
:type: matrix [4][4]
4988
.. attribute:: pose_head
4990
position of bone head in armature space, read-only.
4992
:type: vector [x, y, z]
4994
.. attribute:: pose_tail
4996
position of bone tail in armature space, read-only.
4998
:type: vector [x, y, z]
5000
.. attribute:: ik_min_x
5002
minimum value of X rotation in degree (<= 0) when X rotation is limited (see ik_limit_x), read-only.
5006
.. attribute:: ik_max_x
5008
maximum value of X rotation in degree (>= 0) when X rotation is limited (see ik_limit_x), read-only.
5012
.. attribute:: ik_min_y
5014
minimum value of Y rotation in degree (<= 0) when Y rotation is limited (see ik_limit_y), read-only.
5018
.. attribute:: ik_max_y
5020
maximum value of Y rotation in degree (>= 0) when Y rotation is limited (see ik_limit_y), read-only.
5024
.. attribute:: ik_min_z
5026
minimum value of Z rotation in degree (<= 0) when Z rotation is limited (see ik_limit_z), read-only.
5030
.. attribute:: ik_max_z
5032
maximum value of Z rotation in degree (>= 0) when Z rotation is limited (see ik_limit_z), read-only.
5036
.. attribute:: ik_stiffness_x
5038
bone rotation stiffness in X axis, read-only.
5040
:type: float between 0 and 1
5042
.. attribute:: ik_stiffness_y
5044
bone rotation stiffness in Y axis, read-only.
5046
:type: float between 0 and 1
5048
.. attribute:: ik_stiffness_z
5050
bone rotation stiffness in Z axis, read-only.
5052
:type: float between 0 and 1
5054
.. attribute:: ik_stretch
5056
ratio of scale change that is allowed, 0=bone can't change size, read-only.
5060
.. attribute:: ik_rot_weight
5062
weight of rotation constraint when ik_rot_control is set, read-write.
5064
:type: float between 0 and 1
5066
.. attribute:: ik_lin_weight
5068
weight of size constraint when ik_lin_control is set, read-write.
5070
:type: float between 0 and 1
5072
.. attribute:: joint_rotation
5074
Control bone rotation in term of joint angle (for robotic applications), read-write.
5076
When writing to this attribute, you pass a [x, y, z] vector and an appropriate set of euler angles or quaternion is calculated according to the rotation_mode.
5078
When you read this attribute, the current pose matrix is converted into a [x, y, z] vector representing the joint angles.
5080
The value and the meaning of the x, y, z depends on the ik_dof_x/ik_dof_y/ik_dof_z attributes:
5082
* 1DoF joint X, Y or Z: the corresponding x, y, or z value is used an a joint angle in radiant
5083
* 2DoF joint X+Y or Z+Y: treated as 2 successive 1DoF joints: first X or Z, then Y. The x or z value is used as a joint angle in radiant along the X or Z axis, followed by a rotation along the new Y axis of y radiants.
5084
* 2DoF joint X+Z: treated as a 2DoF joint with rotation axis on the X/Z plane. The x and z values are used as the coordinates of the rotation vector in the X/Z plane.
5085
* 3DoF joint X+Y+Z: treated as a revolute joint. The [x, y, z] vector represents the equivalent rotation vector to bring the joint from the rest pose to the new pose.
5087
:type: vector [x, y, z]
5091
The bone must be part of an IK chain if you want to set the ik_dof_x/ik_dof_y/ik_dof_z attributes via the UI, but this will interfere with this attribute since the IK solver will overwrite the pose. You can stay in control of the armature if you create an IK constraint but do not finalize it (e.g. don't set a target) the IK solver will not run but the IK panel will show up on the UI for each bone in the chain.
5095
[0, 0, 0] always corresponds to the rest pose.
5099
You must request the armature pose to update and wait for the next graphic frame to see the effect of setting this attribute (see :data:`BL_ArmatureObject.update`).
5103
You can read the result of the calculation in rotation or euler_rotation attributes after setting this attribute.
5105
.. class:: BL_ArmatureBone(PyObjectPlus)
5107
Proxy to Blender bone structure. All fields are read-only and comply to RNA names.
5108
All space attribute correspond to the rest pose.
5116
.. attribute:: connected
5118
true when the bone head is struck to the parent's tail.
5122
.. attribute:: hinge
5124
true when bone doesn't inherit rotation or scale from parent bone.
5128
.. attribute:: inherit_scale
5130
true when bone inherits scaling from parent bone.
5134
.. attribute:: bbone_segments
5136
number of B-bone segments.
5142
bone rotation around head-tail axis.
5148
location of head end of the bone in parent bone space.
5150
:type: vector [x, y, z]
5154
location of head end of the bone in parent bone space.
5156
:type: vector [x, y, z]
5158
.. attribute:: length
5164
.. attribute:: arm_head
5166
location of head end of the bone in armature space.
5168
:type: vector [x, y, z]
5170
.. attribute:: arm_tail
5172
location of tail end of the bone in armature space.
5174
:type: vector [x, y, z]
5176
.. attribute:: arm_mat
5178
matrix of the bone head in armature space.
5180
:type: matrix [4][4]
5184
This matrix has no scale part.
5186
.. attribute:: bone_mat
5188
rotation matrix of the bone in parent bone space.
5190
:type: matrix [3][3]
5192
.. attribute:: parent
5194
parent bone, or None for root bone.
5196
:type: :class:`BL_ArmatureBone`
5198
.. attribute:: children
5200
list of bone's children.
5202
:type: list of :class:`BL_ArmatureBone`