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>2008-04-22 19:37:54 +0400
committerCampbell Barton <ideasman42@gmail.com>2008-04-22 19:37:54 +0400
commitfa27b5bcc72e83bc804081031318264742c68880 (patch)
treec54931c18d3e06a4d7c2daf7a9668a028ebdc0c1 /release
parent20f2607c3ab2e4e8c94ed0a15373f2b7edb3c9ea (diff)
Script templates, metaball creation script from forTe, and camera script from macouno
Diffstat (limited to 'release')
-rw-r--r--release/scripts/scripttemplate_camer_object.py104
-rw-r--r--release/scripts/scripttemplate_metaball_create.py76
2 files changed, 180 insertions, 0 deletions
diff --git a/release/scripts/scripttemplate_camer_object.py b/release/scripts/scripttemplate_camer_object.py
new file mode 100644
index 00000000000..b4df64d9108
--- /dev/null
+++ b/release/scripts/scripttemplate_camer_object.py
@@ -0,0 +1,104 @@
+#!BPY
+"""
+Name: 'Camera/Object Example'
+Blender: 245
+Group: 'ScriptTemplate'
+Tooltip: 'Script template for setting the camera direction'
+"""
+
+from Blender import Window
+import bpy
+
+script_data = \
+'''#!BPY
+"""
+Name: 'My Camera script'
+Blender: 245
+Group: 'Object'
+Tooltip: 'Rotate the camera to center on the active object'
+"""
+
+import Blender
+from Blender import Window, Scene, Draw, Mathutils
+
+# Rotate the camera in such a way that it centers on the currently active object
+def RotCamToOb(cam, ob):
+
+ # Get the camera matrix
+ camMat = cam.getMatrix('worldspace');
+
+ # Get the location of the camera and object and make sure they're vectors
+ camLoc = Mathutils.Vector(cam.loc)
+ obLoc = Mathutils.Vector(ob.loc)
+
+ # Get the vector (direction) from the camera to the object
+ newVec = obLoc - camLoc
+
+ # Make a quaternion that points the camera along the vector
+ newQuat = newVec.toTrackQuat('-z', 'y')
+
+ # Convert the new quaternion to a rotation matrix (and resize it to 4x4 so it matches the other matrices)
+ rotMat = newQuat.toMatrix().resize4x4()
+
+ # Make a matrix with only the current location of the camera
+ transMat = Mathutils.TranslationMatrix(camMat.translationPart());
+
+ # Multiply the rotation and translation matrixes to make 1 matrix with all data
+ newMat = rotMat * transMat
+
+ # Now we make this matrix the camera matrix and voila done!
+ cam.setMatrix(newMat)
+
+#Make sure blender and the objects are in the right state and start doing stuff
+def SceneCheck():
+
+ # Show a neat waitcursor whilst the script runs
+ Window.WaitCursor(1)
+
+ # If we are in edit mode, go out of edit mode and store the status in a var
+ emode = int(Window.EditMode())
+ if emode: Window.EditMode(0)
+
+ # Get the scene, the camera and the currently active object
+ scn = Scene.GetCurrent()
+ cam = scn.getCurrentCamera()
+ ob = scn.getActiveObject()
+
+ # Lets do some checks to make sure we have everything
+ # And if we don't then call a return which stops the entire script
+ if not cam:
+ Draw.PupMenu('Error, no active camera, aborting.')
+ return
+
+ if not ob:
+ Draw.PupMenu('Error, no active object, aborting.')
+ return
+
+ if cam == ob:
+ Draw.PupMenu('Error, select an object other than the camera, aborting.')
+ return
+
+ # Start the main function of the script if we didn't encounter any errors
+ RotCamToOb(cam, ob)
+
+ # Update the scene
+ scn.update()
+
+ # Redraw the 3d view so we can instantly see what was changed
+ Window.Redraw(Window.Types.VIEW3D)
+
+ # If we were in edit mode when the script started, go back into edit mode
+ if emode: Window.EditMode(1)
+
+ # Remove the waitcursor
+ Window.WaitCursor(0)
+
+# Start the script
+SceneCheck()
+
+'''
+
+new_text = bpy.data.texts.new('pyconstraint_template.py')
+new_text.write(script_data)
+bpy.data.texts.active = new_text
+Window.RedrawAll()
diff --git a/release/scripts/scripttemplate_metaball_create.py b/release/scripts/scripttemplate_metaball_create.py
new file mode 100644
index 00000000000..881f9c4fc4b
--- /dev/null
+++ b/release/scripts/scripttemplate_metaball_create.py
@@ -0,0 +1,76 @@
+#!BPY
+"""
+Name: 'Metaball Generation'
+Blender: 245
+Group: 'ScriptTemplate'
+Tooltip: 'Script template to make metaballs from a mesh'
+"""
+
+from Blender import Window
+import bpy
+
+script_data = \
+'''#!BPY
+"""
+Name: 'My Metaball Script'
+Blender: 245
+Group: 'Misc'
+Tooltip: 'Put some useful info here'
+"""
+
+# Add a license here if you wish to re-disribute, we recommend the GPL
+
+from Blender import Metaball, Mesh, Window
+import bpy
+
+def makeMetaSculpture(sce):
+ #Create a base mesh for our sculpture to use
+ monkey = Mesh.Primitives.Monkey()
+
+ #Create a new meta datablock to use and give it a name
+ metaObj = Metaball.New()
+ metaObj.name = "MetaSuzanne"
+
+ #Increase the resolution so it looks better
+ metaObj.wiresize = 0.2
+ metaObj.rendersize = 0.1
+
+ #The radius for our new meta objects to take
+ metaRadius = 2.0
+
+ for f in monkey.faces:
+
+ #Create a new metaball as part of the Meta Object Data
+ newBall = metaObj.elements.add()
+
+ #Make the new ball have the same coordinates as a vertex on our Mesh
+ newBall.co = f.cent
+
+ #Assign the same radius to all balls
+ newBall.radius = f.area * metaRadius
+
+ #Create the new object and put our meta data there
+ sce.objects.new(metaObj, "MetaSuzanne")
+
+
+def main():
+ scene = bpy.data.scenes.active #Get the active scene
+
+ Window.WaitCursor(1)
+
+ #Call the sculpture making function
+ makeMetaSculpture(scene)
+
+ Window.WaitCursor(0)
+
+ #Redraw the Screen When Finished
+ Window.RedrawAll(1)
+
+if __name__ == '__main__':
+ main()
+'''
+
+new_text = bpy.data.texts.new('pyconstraint_template.py')
+new_text.write(script_data)
+bpy.data.texts.active = new_text
+Window.RedrawAll()