Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2009-10-29 14:26:44 +0300
committerCampbell Barton <ideasman42@gmail.com>2009-10-29 14:26:44 +0300
commit6f1e9a843ee3ef0a3c51155237c41e88481d2919 (patch)
treeb4a74a8ac24d45714a91bf42c4ee982e8aecc628 /release/scripts/templates
parente14a8635cca97f339d28744624cf1284866bc63d (diff)
Script templates, including game logic scripts from 2.4x and new operator template.
Files copied into scripts/templates will automatically appear in the menu. the operator template is a bit rough but a start.
Diffstat (limited to 'release/scripts/templates')
-rw-r--r--release/scripts/templates/gamelogic.py78
-rw-r--r--release/scripts/templates/gamelogic_basic.py15
-rw-r--r--release/scripts/templates/gamelogic_module.py26
-rw-r--r--release/scripts/templates/operator.py53
-rw-r--r--release/scripts/templates/operator_simple.py20
5 files changed, 192 insertions, 0 deletions
diff --git a/release/scripts/templates/gamelogic.py b/release/scripts/templates/gamelogic.py
new file mode 100644
index 00000000000..af9dbd8a56a
--- /dev/null
+++ b/release/scripts/templates/gamelogic.py
@@ -0,0 +1,78 @@
+# This script must be assigned to a python controller
+# where it can access the object that owns it and the sensors/actuators that it connects to.
+
+# GameLogic has been added to the global namespace no need to import
+
+# for keyboard event comparison
+# import GameKeys
+
+# support for Vector(), Matrix() types and advanced functions like AngleBetweenVecs(v1,v2) and RotationMatrix(...)
+# import Mathutils
+
+# for functions like getWindowWidth(), getWindowHeight()
+# import Rasterizer
+
+def main():
+ cont = GameLogic.getCurrentController()
+
+ # The KX_GameObject that owns this controller.
+ own = cont.owner
+
+ # for scripts that deal with spacial logic
+ own_pos = own.worldPosition
+
+
+ # Some example functions, remove to write your own script.
+ # check for a positive sensor, will run on any object without errors.
+ print 'Logic info for KX_GameObject', own.name
+ input = False
+
+ for sens in cont.sensors:
+ # The sensor can be on another object, we may want to use it
+ own_sens = sens.owner
+ print ' sensor:', sens.name,
+ if sens.positive:
+ print '(true)'
+ input = True
+ else:
+ print '(false)'
+
+ for actu in cont.actuators:
+ # The actuator can be on another object, we may want to use it
+ own_actu = actu.owner
+ print ' actuator:', actu.name
+
+ # This runs the actuator or turns it off
+ # note that actuators will continue to run unless explicitly turned off.
+ if input:
+ cont.activate(actu)
+ else:
+ cont.deactivate(actu)
+
+ # Its also good practice to get sensors and actuators by name
+ # rather then index so any changes to their order wont break the script.
+
+ # sens_key = cont.sensors['key_sensor']
+ # actu_motion = cont.actuators['motion']
+
+
+ # Loop through all other objects in the scene
+ sce = GameLogic.getCurrentScene()
+ print 'Scene Objects:', sce.name
+ for ob in sce.objects:
+ print ' ', ob.name, ob.worldPosition
+
+
+ # Example where collision objects are checked for their properties
+ # adding to our objects "life" property
+ """
+ actu_collide = cont.sensors['collision_sens']
+ for ob in actu_collide.objectHitList:
+ # Check to see the object has this property
+ if ob.has_key('life'):
+ own['life'] += ob['life']
+ ob['life'] = 0
+ print own['life']
+ """
+
+main()
diff --git a/release/scripts/templates/gamelogic_basic.py b/release/scripts/templates/gamelogic_basic.py
new file mode 100644
index 00000000000..c9c2a594309
--- /dev/null
+++ b/release/scripts/templates/gamelogic_basic.py
@@ -0,0 +1,15 @@
+
+def main():
+
+ cont = GameLogic.getCurrentController()
+ own = cont.owner
+
+ sens = cont.sensors['mySensor']
+ actu = cont.actuators['myActuator']
+
+ if sens.positive:
+ cont.activate(actu)
+ else:
+ cont.deactivate(actu)
+
+main()
diff --git a/release/scripts/templates/gamelogic_module.py b/release/scripts/templates/gamelogic_module.py
new file mode 100644
index 00000000000..1bc221e727d
--- /dev/null
+++ b/release/scripts/templates/gamelogic_module.py
@@ -0,0 +1,26 @@
+# This module can be accessed by a python controller with
+# its execution method set to 'Module'
+# * Set the module string to "gamelogic_module.main" (without quotes)
+# * When renaming the script it MUST have a .py extension
+# * External text modules are supported as long as they are at
+# the same location as the blendfile or one of its libraries.
+
+import GameLogic
+
+# variables defined here will only be set once when the
+# module is first imported. Set object spesific vars
+# inside the function if you intend to use the module
+# with multiple objects.
+
+def main(cont):
+ own = cont.owner
+
+ sens = cont.sensors['mySensor']
+ actu = cont.actuators['myActuator']
+
+ if sens.positive:
+ cont.activate(actu)
+ else:
+ cont.deactivate(actu)
+
+# dont call main(GameLogic.getCurrentController()), the py controller will
diff --git a/release/scripts/templates/operator.py b/release/scripts/templates/operator.py
new file mode 100644
index 00000000000..7e3dad93ad8
--- /dev/null
+++ b/release/scripts/templates/operator.py
@@ -0,0 +1,53 @@
+def write_some_data(context, path, use_some_setting):
+ pass
+
+class ExportSomeData(bpy.types.Operator):
+ '''This appiers in the tooltip of the operator and in the generated docs.'''
+ __idname__ = "export.some_data" # this is important since its how bpy.ops.export.some_data is constructed
+ __label__ = "Export Some Data"
+
+ # List of operator properties, the attributes will be assigned
+ # to the class instance from the operator settings before calling.
+
+ # TODO, add better example props
+ __props__ = [
+ bpy.props.StringProperty(attr="path", name="File Path", description="File path used for exporting the PLY file", maxlen= 1024, default= ""),
+ bpy.props.BoolProperty(attr="use_some_setting", name="Apply Modifiers", description="Apply Modifiers to the exported mesh", default= True),
+ ]
+
+ def poll(self, context):
+ return context.active_object != None
+
+ def execute(self, context):
+ if not self.is_property_set("path"):
+ raise Exception("filename not set")
+
+ write(self.path, context, use_setting, SOME_SETTING = self.use_some_setting)
+
+ return ('FINISHED',)
+
+ def invoke(self, context, event):
+ wm = context.manager
+
+ if True:
+ # File selector
+ wm.add_fileselect(self.__operator__) # will run self.execute()
+ return ('RUNNING_MODAL',)
+ else if 0:
+ # Redo popup
+ wm.invoke_props_popup(self.__operator__, event) #
+ return ('RUNNING_MODAL',)
+ else if 0:
+ return self.execute(context)
+
+
+bpy.ops.add(ExportSomeData)
+
+# Only needed if you want to add into a dynamic menu
+import dynamic_menu
+menu_func = lambda self, context: self.layout.itemO("export.some_data", text="Example Exporter...")
+menu_item = dynamic_menu.add(bpy.types.INFO_MT_file_export, menu_func)
+
+# Use for running this script directly
+if __name__ == "__main__":
+ bpy.ops.export.some_data(path="/tmp/test.ply") \ No newline at end of file
diff --git a/release/scripts/templates/operator_simple.py b/release/scripts/templates/operator_simple.py
new file mode 100644
index 00000000000..b82543c3bf8
--- /dev/null
+++ b/release/scripts/templates/operator_simple.py
@@ -0,0 +1,20 @@
+def main(context):
+ for ob in context.scene.objects:
+ print(ob)
+
+class SimpleOperator(bpy.types.Operator):
+ ''''''
+ __idname__ = "object.simple_operator"
+ __label__ = "Simple Object Operator"
+
+ def poll(self, context):
+ return context.active_object != None
+
+ def execute(self, context):
+ main(context)
+ return ('FINISHED',)
+
+bpy.ops.add(SimpleOperator)
+
+if __name__ == "__main__":
+ bpy.ops.object.simple_operator()