== python api doc ==
First commit to make some structure in doc/ directory. - moved source/blender/python/doc -> doc/python_api - moved source/gameengine/PyDoc/*.rst -> doc/python_api/rst - modified accordingly sphinx_doc_gen.py and sphinx_doc_gen.sh (later on I'll try alternative/ scripts by neXyon as promised :) - source/gameengine/PyDoc/ is still there because contains epydoc stuff for the bge, will ask more and look into it later
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,189 +0,0 @@
|
||||
# Blender.Geometry module and its subtypes
|
||||
|
||||
"""
|
||||
The Blender.Geometry submodule.
|
||||
|
||||
Geometry
|
||||
========
|
||||
(when accessing it from the Game Engine use Geometry instead of Blender.Geometry)
|
||||
|
||||
This new module provides access to a geometry function.
|
||||
"""
|
||||
|
||||
def Intersect(vec1, vec2, vec3, ray, orig, clip=1):
|
||||
"""
|
||||
Return the intersection between a ray and a triangle, if possible, return None otherwise.
|
||||
@type vec1: Vector object.
|
||||
@param vec1: A 3d vector, one corner of the triangle.
|
||||
@type vec2: Vector object.
|
||||
@param vec2: A 3d vector, one corner of the triangle.
|
||||
@type vec3: Vector object.
|
||||
@param vec3: A 3d vector, one corner of the triangle.
|
||||
@type ray: Vector object.
|
||||
@param ray: A 3d vector, the orientation of the ray. the length of the ray is not used, only the direction.
|
||||
@type orig: Vector object.
|
||||
@param orig: A 3d vector, the origin of the ray.
|
||||
@type clip: integer
|
||||
@param clip: if 0, don't restrict the intersection to the area of the triangle, use the infinite plane defined by the triangle.
|
||||
@rtype: Vector object
|
||||
@return: The intersection between a ray and a triangle, if possible, None otherwise.
|
||||
"""
|
||||
|
||||
def TriangleArea(vec1, vec2, vec3):
|
||||
"""
|
||||
Return the area size of the 2D or 3D triangle defined.
|
||||
@type vec1: Vector object.
|
||||
@param vec1: A 2d or 3d vector, one corner of the triangle.
|
||||
@type vec2: Vector object.
|
||||
@param vec2: A 2d or 3d vector, one corner of the triangle.
|
||||
@type vec3: Vector object.
|
||||
@param vec3: A 2d or 3d vector, one corner of the triangle.
|
||||
@rtype: float
|
||||
@return: The area size of the 2D or 3D triangle defined.
|
||||
"""
|
||||
|
||||
def TriangleNormal(vec1, vec2, vec3):
|
||||
"""
|
||||
Return the normal of the 3D triangle defined.
|
||||
@type vec1: Vector object.
|
||||
@param vec1: A 3d vector, one corner of the triangle.
|
||||
@type vec2: Vector object.
|
||||
@param vec2: A 3d vector, one corner of the triangle.
|
||||
@type vec3: Vector object.
|
||||
@param vec3: A 3d vector, one corner of the triangle.
|
||||
@rtype: float
|
||||
@return: The normal of the 3D triangle defined.
|
||||
"""
|
||||
|
||||
def QuadNormal(vec1, vec2, vec3, vec4):
|
||||
"""
|
||||
Return the normal of the 3D quad defined.
|
||||
@type vec1: Vector object.
|
||||
@param vec1: A 3d vector, the first vertex of the quad.
|
||||
@type vec2: Vector object.
|
||||
@param vec2: A 3d vector, the second vertex of the quad.
|
||||
@type vec3: Vector object.
|
||||
@param vec3: A 3d vector, the third vertex of the quad.
|
||||
@type vec4: Vector object.
|
||||
@param vec4: A 3d vector, the fourth vertex of the quad.
|
||||
@rtype: float
|
||||
@return: The normal of the 3D quad defined.
|
||||
"""
|
||||
|
||||
def LineIntersect(vec1, vec2, vec3, vec4):
|
||||
"""
|
||||
Return a tuple with the points on each line respectively closest to the other
|
||||
(when both lines intersect, both vector hold the same value).
|
||||
The lines are evaluated as infinite lines in space, the values returned may not be between the 2 points given for each line.
|
||||
@type vec1: Vector object.
|
||||
@param vec1: A 3d vector, one point on the first line.
|
||||
@type vec2: Vector object.
|
||||
@param vec2: A 3d vector, another point on the first line.
|
||||
@type vec3: Vector object.
|
||||
@param vec3: A 3d vector, one point on the second line.
|
||||
@type vec4: Vector object.
|
||||
@param vec4: A 3d vector, another point on the second line.
|
||||
@rtype: (Vector object, Vector object)
|
||||
@return: A tuple with the points on each line respectively closest to the other.
|
||||
"""
|
||||
|
||||
def PolyFill(polylines):
|
||||
"""
|
||||
Takes a list of polylines and calculates triangles that would fill in the polylines.
|
||||
Multiple lines can be used to make holes inside a polyline, or fill in 2 separate lines at once.
|
||||
@type polylines: List of lists containing vectors, each representing a closed polyline.
|
||||
@rtype: list
|
||||
@return: a list if tuples each a tuple of 3 ints representing a triangle indexing the points given.
|
||||
@note: 2D Vectors will have an assumed Z axis of zero, 4D Vectors W axis is ignored.
|
||||
@note: The order of points in a polyline effect the direction returned triangles face, reverse the order of a polyline to flip the normal of returned faces.
|
||||
|
||||
I{B{Example:}}
|
||||
|
||||
The example below creates 2 polylines and fills them in with faces, then makes a mesh in the current scene::
|
||||
import Blender
|
||||
Vector= Blender.mathutils.Vector
|
||||
|
||||
# Outline of 5 points
|
||||
polyline1= [Vector(-2.0, 1.0, 1.0), Vector(-1.0, 2.0, 1.0), Vector(1.0, 2.0, 1.0), Vector(1.0, -1.0, 1.0), Vector(-1.0, -1.0, 1.0)]
|
||||
polyline2= [Vector(-1, 1, 1.0), Vector(0, 1, 1.0), Vector(0, 0, 1.0), Vector(-1.0, 0.0, 1.0)]
|
||||
fill= Blender.Geometry.PolyFill([polyline1, polyline2])
|
||||
|
||||
# Make a new mesh and add the truangles into it
|
||||
me= Blender.Mesh.New()
|
||||
me.verts.extend(polyline1)
|
||||
me.verts.extend(polyline2)
|
||||
me.faces.extend(fill) # Add the faces, they reference the verts in polyline 1 and 2
|
||||
|
||||
scn = Blender.Scene.GetCurrent()
|
||||
ob = scn.objects.new(me)
|
||||
Blender.Redraw()
|
||||
"""
|
||||
|
||||
def LineIntersect2D(vec1, vec2, vec3, vec4):
|
||||
"""
|
||||
Takes 2 lines vec1, vec2 for the 2 points of the first line and vec2, vec3 for the 2 points of the second line.
|
||||
@rtype: Vector
|
||||
@return: a 2D Vector for the intersection or None where there is no intersection.
|
||||
"""
|
||||
|
||||
def ClosestPointOnLine(pt, vec1, vec2):
|
||||
"""
|
||||
Takes 2 lines vec1, vec2 for the 2 points of the first line and vec2, vec3 for the 2 points of the second line.
|
||||
@rtype: tuple
|
||||
@return: a tuple containing a vector and a float, the vector is the closest point on the line, the float is the position on the line, between 0 and 1 the point is on the line.
|
||||
"""
|
||||
|
||||
def PointInTriangle2D(pt, tri_pt1, tri_pt2, tri_pt3):
|
||||
"""
|
||||
Takes 4 vectors (one for the test point and 3 for the triangle)
|
||||
This is a 2d function so only X and Y are used, Z and W will be ignored.
|
||||
@rtype: int
|
||||
@return: 1 for a clockwise intersection, -1 for counter clockwise intersection, 0 when there is no intersection.
|
||||
"""
|
||||
|
||||
def PointInQuad2D(pt, quad_pt1, quad_pt2, quad_pt3):
|
||||
"""
|
||||
Takes 5 vectors (one for the test point and 5 for the quad)
|
||||
This is a 2d function so only X and Y are used, Z and W will be ignored.
|
||||
@rtype: int
|
||||
@return: 1 for a clockwise intersection, -1 for counter clockwise intersection, 0 when there is no intersection.
|
||||
"""
|
||||
|
||||
def BoxPack2D(boxlist):
|
||||
"""
|
||||
Takes a list of 2D boxes and packs them into a square.
|
||||
Each box in boxlist must be a list of at least 4 items - [x,y,w,h], after running this script,
|
||||
the X and Y values in each box will be moved to packed, non overlapping locations.
|
||||
|
||||
Example::
|
||||
|
||||
# Make 500 random boxes, pack them and make a mesh from it
|
||||
from Blender import Geometry, Scene, Mesh
|
||||
import random
|
||||
boxes = []
|
||||
for i in xrange(500):
|
||||
boxes.append( [0,0, random.random()+0.1, random.random()+0.1] )
|
||||
boxsize = Geometry.BoxPack2D(boxes)
|
||||
print 'BoxSize', boxsize
|
||||
me = Mesh.New()
|
||||
for x in boxes:
|
||||
me.verts.extend([(x[0],x[1], 0), (x[0],x[1]+x[3], 0), (x[0]+x[2],x[1]+x[3], 0), (x[0]+x[2],x[1], 0) ])
|
||||
v1= me.verts[-1]
|
||||
v2= me.verts[-2]
|
||||
v3= me.verts[-3]
|
||||
v4= me.verts[-4]
|
||||
me.faces.extend([(v1,v2,v3,v4)])
|
||||
scn = Scene.GetCurrent()
|
||||
scn.objects.new(me)
|
||||
|
||||
@note: Each boxlist item can be longer then 4, the extra items are ignored and stay untouched.
|
||||
@rtype: tuple
|
||||
@return: a tuple pair - (width, height) of all the packed boxes.
|
||||
"""
|
||||
def BezierInterp(vec_knot_1, vec_handle_1, vec_handle_2, vec_knot_2, resolution):
|
||||
"""
|
||||
Takes 4 vectors representing a bezier curve and returns a list of vector points.
|
||||
@note: any vector size is supported, the largest dimension from the input will be used for all returned vectors/
|
||||
@rtype: list
|
||||
@return: a list of vectors the size of resolution including the start and end points (vec_knot_1 and vec_knot_2)
|
||||
"""
|
||||
@@ -1,132 +0,0 @@
|
||||
class IDGroup:
|
||||
"""
|
||||
The IDGroup Type
|
||||
================
|
||||
This type supports both iteration and the []
|
||||
operator to get child ID properties.
|
||||
|
||||
You can also add new properties using the [] operator.
|
||||
For example::
|
||||
|
||||
group['a float!'] = 0.0
|
||||
group['an int!'] = 0
|
||||
group['a string!'] = "hi!"
|
||||
group['an array!'] = [0, 0, 1.0, 0]
|
||||
|
||||
group['a subgroup!] = {"float": 0.0, "an int": 1.0, "an array": [1, 2],
|
||||
"another subgroup": {"a": 0.0, "str": "bleh"}}
|
||||
|
||||
Note that for arrays, the array type defaults to int unless a float is found
|
||||
while scanning the template list; if any floats are found, then the whole
|
||||
array is float. Note that double-precision floating point numbers are used for
|
||||
python-created float ID properties and arrays (though the internal C api does
|
||||
support single-precision floats, and the python code will read them).
|
||||
|
||||
You can also delete properties with the del operator. For example:
|
||||
|
||||
del group['property']
|
||||
|
||||
To get the type of a property, use the type() operator, for example::
|
||||
|
||||
if type(group['bleh']) == str: pass
|
||||
|
||||
To tell if the property is a group or array type, import the Blender.Types module and test
|
||||
against IDGroupType and IDArrayType, like so::
|
||||
|
||||
from Blender.Types import IDGroupType, IDArrayType.
|
||||
|
||||
if type(group['bleghr']) == IDGroupType:
|
||||
(do something)
|
||||
|
||||
@ivar name: The name of the property
|
||||
@type name: string
|
||||
"""
|
||||
|
||||
def pop(item):
|
||||
"""
|
||||
Pop an item from the group property.
|
||||
@type item: string
|
||||
@param item: The item name.
|
||||
@rtype: can be dict, list, int, float or string.
|
||||
@return: The removed property.
|
||||
"""
|
||||
|
||||
def update(updatedict):
|
||||
"""
|
||||
Updates items in the dict, similar to normal python
|
||||
dictionary method .update().
|
||||
@type updatedict: dict
|
||||
@param updatedict: A dict of simple types to derive updated/new IDProperties from.
|
||||
@rtype: None
|
||||
@return: None
|
||||
"""
|
||||
|
||||
def keys():
|
||||
"""
|
||||
Returns a list of the keys in this property group.
|
||||
@rtype: list of strings.
|
||||
@return: a list of the keys in this property group.
|
||||
"""
|
||||
|
||||
def values():
|
||||
"""
|
||||
Returns a list of the values in this property group.
|
||||
|
||||
Note that unless a value is itself a property group or an array, you
|
||||
cannot change it by changing the values in this list, you must change them
|
||||
in the parent property group.
|
||||
|
||||
For example,
|
||||
|
||||
group['some_property'] = new_value
|
||||
|
||||
. . .is correct, while,
|
||||
|
||||
values = group.values()
|
||||
values[0] = new_value
|
||||
|
||||
. . .is wrong.
|
||||
|
||||
@rtype: list of strings.
|
||||
@return: a list of the values in this property group.
|
||||
"""
|
||||
|
||||
def iteritems():
|
||||
"""
|
||||
Implements the python dictionary iteritmes method.
|
||||
|
||||
For example::
|
||||
|
||||
for k, v in group.iteritems():
|
||||
print "Property name: " + k
|
||||
print "Property value: " + str(v)
|
||||
|
||||
@rtype: an iterator that spits out items of the form [key, value]
|
||||
@return: an iterator.
|
||||
"""
|
||||
|
||||
def convert_to_pyobject():
|
||||
"""
|
||||
Converts the entire property group to a purely python form.
|
||||
|
||||
@rtype: dict
|
||||
@return: A python dictionary representing the property group
|
||||
"""
|
||||
|
||||
class IDArray:
|
||||
"""
|
||||
The IDArray Type
|
||||
================
|
||||
|
||||
@ivar type: returns the type of the array, can be either IDP_Int or IDP_Float
|
||||
"""
|
||||
|
||||
def __getitem__(index):
|
||||
pass
|
||||
|
||||
def __setitem__(index, value):
|
||||
pass
|
||||
|
||||
def __len__():
|
||||
pass
|
||||
|
||||
@@ -1,156 +0,0 @@
|
||||
# Blender.mathutils module and its subtypes
|
||||
|
||||
|
||||
|
||||
class Vector:
|
||||
"""
|
||||
|
||||
@attention: Vector data can be wrapped or non-wrapped. When a object is wrapped it
|
||||
means that the object will give you direct access to the data inside of blender. Modification
|
||||
of this object will directly change the data inside of blender. To copy a wrapped object
|
||||
you need to use the object's constructor. If you copy and object by assignment you will not get
|
||||
a second copy but a second reference to the same data. Only certain functions will return
|
||||
wrapped data. This will be indicated in the method description.
|
||||
"""
|
||||
|
||||
def __init__(list = None):
|
||||
"""
|
||||
Create a new 2d, 3d, or 4d Vector object from a list of floating point numbers.
|
||||
@note: that python uses higher precission floating point numbers, so values assigned to a vector may have some rounding error.
|
||||
|
||||
|
||||
Example::
|
||||
v = Vector(1,0,0)
|
||||
v = Vector(myVec)
|
||||
v = Vector(list)
|
||||
@type list: PyList of float or int
|
||||
@param list: The list of values for the Vector object. Can be a sequence or raw numbers.
|
||||
Must be 2, 3, or 4 values. The list is mapped to the parameters as [x,y,z,w].
|
||||
@rtype: Vector object.
|
||||
@return: It depends wheter a parameter was passed:
|
||||
- (list): Vector object initialized with the given values;
|
||||
- (): An empty 3 dimensional vector.
|
||||
"""
|
||||
|
||||
class Euler:
|
||||
"""
|
||||
The Euler object
|
||||
================
|
||||
This object gives access to Eulers in Blender.
|
||||
@note: You can access a euler object like a sequence
|
||||
- x = euler[0]
|
||||
@note: Comparison operators can be done:
|
||||
- ==, != test numeric values within epsilon
|
||||
@attention: Euler data can be wrapped or non-wrapped. When a object is wrapped it
|
||||
means that the object will give you direct access to the data inside of blender. Modification
|
||||
of this object will directly change the data inside of blender. To copy a wrapped object
|
||||
you need to use the object's constructor. If you copy and object by assignment you will not get
|
||||
a second copy but a second reference to the same data. Only certain functions will return
|
||||
wrapped data. This will be indicated in the method description.
|
||||
"""
|
||||
|
||||
def __init__(list = None):
|
||||
"""
|
||||
Create a new euler object.
|
||||
|
||||
Example::
|
||||
euler = Euler(45,0,0)
|
||||
euler = Euler(myEuler)
|
||||
euler = Euler(sequence)
|
||||
@type list: PyList of float/int
|
||||
@param list: 3d list to initialize euler
|
||||
@rtype: Euler object
|
||||
@return: Euler representing heading, pitch, bank.
|
||||
@note: Values are in degrees.
|
||||
"""
|
||||
|
||||
class Quaternion:
|
||||
"""
|
||||
The Quaternion object
|
||||
=====================
|
||||
This object gives access to Quaternions in Blender.
|
||||
@note: Comparison operators can be done:
|
||||
- ==, != test numeric values within epsilon
|
||||
@note: Math can be performed on Quaternion classes
|
||||
- quat + quat
|
||||
- quat - quat
|
||||
- quat * float/int
|
||||
- quat * vec
|
||||
- quat * quat
|
||||
@note: You can access a quaternion object like a sequence
|
||||
- x = quat[0]
|
||||
@attention: Quaternion data can be wrapped or non-wrapped. When a object is wrapped it
|
||||
means that the object will give you direct access to the data inside of blender. Modification
|
||||
of this object will directly change the data inside of blender. To copy a wrapped object
|
||||
you need to use the object's constructor. If you copy and object by assignment you will not get
|
||||
a second copy but a second reference to the same data. Only certain functions will return
|
||||
wrapped data. This will be indicated in the method description.
|
||||
"""
|
||||
|
||||
def __init__(list, angle = None):
|
||||
"""
|
||||
Create a new quaternion object from initialized values.
|
||||
|
||||
Example::
|
||||
quat = Quaternion(1,2,3,4)
|
||||
quat = Quaternion(axis, angle)
|
||||
quat = Quaternion()
|
||||
quat = Quaternion(180, list)
|
||||
|
||||
@type list: PyList of int/float
|
||||
@param list: A 3d or 4d list to initialize quaternion.
|
||||
4d if intializing [w,x,y,z], 3d if used as an axis of rotation.
|
||||
@type angle: float (optional)
|
||||
@param angle: An arbitrary rotation amount around 'list'.
|
||||
List is used as an axis of rotation in this case.
|
||||
@rtype: New quaternion object.
|
||||
@return: It depends wheter a parameter was passed:
|
||||
- (list/angle): Quaternion object initialized with the given values;
|
||||
- (): An identity 4 dimensional quaternion.
|
||||
"""
|
||||
|
||||
class Matrix:
|
||||
"""
|
||||
The Matrix Object
|
||||
=================
|
||||
@note: Math can be performed on Matrix classes
|
||||
- mat + mat
|
||||
- mat - mat
|
||||
- mat * float/int
|
||||
- mat * vec
|
||||
- mat * mat
|
||||
@note: Comparison operators can be done:
|
||||
- ==, != test numeric values within epsilon
|
||||
@note: You can access a quaternion object like a 2d sequence
|
||||
- x = matrix[0][1]
|
||||
- vector = matrix[2]
|
||||
@attention: Quaternion data can be wrapped or non-wrapped. When a object is wrapped it
|
||||
means that the object will give you direct access to the data inside of blender. Modification
|
||||
of this object will directly change the data inside of blender. To copy a wrapped object
|
||||
you need to use the object's constructor. If you copy and object by assignment you will not get
|
||||
a second copy but a second reference to the same data. Only certain functions will return
|
||||
wrapped data. This will be indicated in the method description.
|
||||
"""
|
||||
|
||||
def __init__(list1 = None, list2 = None, list3 = None, list4 = None):
|
||||
"""
|
||||
Create a new matrix object from initialized values.
|
||||
|
||||
Example::
|
||||
matrix = Matrix([1,1,1],[0,1,0],[1,0,0])
|
||||
matrix = Matrix(mat)
|
||||
matrix = Matrix(seq1, seq2, vector)
|
||||
|
||||
@type list1: PyList of int/float
|
||||
@param list1: A 2d,3d or 4d list.
|
||||
@type list2: PyList of int/float
|
||||
@param list2: A 2d,3d or 4d list.
|
||||
@type list3: PyList of int/float
|
||||
@param list3: A 2d,3d or 4d list.
|
||||
@type list4: PyList of int/float
|
||||
@param list4: A 2d,3d or 4d list.
|
||||
@rtype: New matrix object.
|
||||
@return: It depends wheter a parameter was passed:
|
||||
- (list1, etc.): Matrix object initialized with the given values;
|
||||
- (): An empty 3 dimensional matrix.
|
||||
"""
|
||||
@@ -1,45 +0,0 @@
|
||||
# Testing the BGL module
|
||||
|
||||
import Blender
|
||||
from Blender.BGL import *
|
||||
from Blender import Draw
|
||||
|
||||
R = G = B = 0
|
||||
A = 1
|
||||
|
||||
instructions = "Hold mouse buttons to change the background color."
|
||||
quitting = " Press ESC or q to quit."
|
||||
|
||||
def show_win():
|
||||
glClearColor(R,G,B,A) # define color used to clear buffers
|
||||
glClear(GL_COLOR_BUFFER_BIT) # use it to clear the color buffer
|
||||
glColor3f(1,1,1) # change default color
|
||||
glRasterPos2i(50,100) # move cursor to x = 50, y = 100
|
||||
Draw.Text("Testing BGL + Draw") # draw this text there
|
||||
glRasterPos2i(350,20) # move cursor again
|
||||
Draw.Text(instructions + quitting) # draw another msg
|
||||
glBegin(GL_LINE_LOOP) # begin a vertex-data list
|
||||
glVertex2i(46,92)
|
||||
glVertex2i(120,92)
|
||||
glVertex2i(120,115)
|
||||
glVertex2i(46,115)
|
||||
glEnd() # close this list
|
||||
glColor3f(0.35,0.18,0.92) # change default color again
|
||||
glBegin(GL_POLYGON) # another list, for a polygon
|
||||
glVertex2i(315, 292)
|
||||
glVertex2i(412, 200)
|
||||
glVertex2i(264, 256)
|
||||
glEnd()
|
||||
Draw.Redraw(1) # make changes visible.
|
||||
|
||||
def ev(evt, val): # this is a callback for Draw.Register()
|
||||
global R,G,B,A # it handles input events
|
||||
if evt == Draw.ESCKEY or evt == Draw.QKEY:
|
||||
Draw.Exit() # this quits the script
|
||||
elif evt == Draw.LEFTMOUSE: R = 1 - R
|
||||
elif evt == Draw.MIDDLEMOUSE: G = 1 - G
|
||||
elif evt == Draw.RIGHTMOUSE: B = 1 - B
|
||||
else:
|
||||
Draw.Register(show_win, ev, None)
|
||||
|
||||
Draw.Register(show_win, ev, None) # start the main loop
|
||||
@@ -1,29 +0,0 @@
|
||||
import bpy
|
||||
|
||||
|
||||
# print all objects
|
||||
for obj in bpy.data.objects:
|
||||
print(obj.name)
|
||||
|
||||
|
||||
# print all scene names in a list
|
||||
print(bpy.data.scenes.keys())
|
||||
|
||||
|
||||
# remove mesh Cube
|
||||
if "Cube" in bpy.data.meshes:
|
||||
mesh = bpy.data.meshes["Cube"]
|
||||
print("removing mesh", mesh)
|
||||
bpy.data.meshes.unlink(mesh)
|
||||
|
||||
|
||||
# write images into a file next to the blend
|
||||
import os
|
||||
file = open(os.path.splitext(bpy.data.filepath)[0] + ".txt", 'w')
|
||||
|
||||
for image in bpy.data.images:
|
||||
file.write("%s %dx%d\n" % (image.filepath, image.size[0], image.size[1]))
|
||||
|
||||
file.close()
|
||||
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
import mathutils
|
||||
|
||||
# todo
|
||||
@@ -1,3 +0,0 @@
|
||||
import mathutils
|
||||
|
||||
# todo
|
||||
@@ -1,3 +0,0 @@
|
||||
import mathutils
|
||||
|
||||
# todo
|
||||
@@ -1,55 +0,0 @@
|
||||
import mathutils
|
||||
|
||||
# zero length vector
|
||||
vec = mathutils.Vector((0, 0, 1))
|
||||
|
||||
# unit length vector
|
||||
vec_a = vec.copy().normalize()
|
||||
|
||||
vec_b = mathutils.Vector((0, 1, 2))
|
||||
|
||||
vec2d = mathutils.Vector((1, 2))
|
||||
vec3d = mathutils.Vector((1, 0, 0))
|
||||
vec4d = vec_a.copy().resize4D()
|
||||
|
||||
# other mathutuls types
|
||||
quat = mathutils.Quaternion()
|
||||
matrix = mathutils.Matrix()
|
||||
|
||||
# Comparison operators can be done on Vector classes:
|
||||
|
||||
# greater and less then test vector length.
|
||||
vec_a > vec_b
|
||||
vec_a >= vec_b
|
||||
vec_a < vec_b
|
||||
vec_a <= vec_b
|
||||
|
||||
# ==, != test vector values e.g. 1,2,3 != 3,2,1 even if they are the same length
|
||||
vec_a == vec_b
|
||||
vec_a != vec_b
|
||||
|
||||
|
||||
# Math can be performed on Vector classes
|
||||
vec_a + vec_b
|
||||
vec_a - vec_b
|
||||
vec_a * vec_b
|
||||
vec_a * 10.0
|
||||
vec_a * matrix
|
||||
vec_a * vec_b
|
||||
vec_a * quat
|
||||
-vec_a
|
||||
|
||||
|
||||
# You can access a vector object like a sequence
|
||||
x = vec_a[0]
|
||||
len(vec)
|
||||
vec_a[:] = vec_b
|
||||
vec2d[:] = vec3d[:2]
|
||||
|
||||
|
||||
# Vectors support 'swizzle' operations
|
||||
# See http://en.wikipedia.org/wiki/Swizzling_(computer_graphics)
|
||||
vec.xyz = vec.zyx
|
||||
vec.xy = vec4d.zw
|
||||
vec.xyz = vec4d.wzz
|
||||
vec4d.wxyz = vec.yxyx
|
||||
@@ -1,18 +0,0 @@
|
||||
import mathutils
|
||||
from math import radians
|
||||
|
||||
vec = mathutils.Vector((1.0, 2.0, 3.0))
|
||||
|
||||
mat_rot = mathutils.Matrix.Rotation(radians(90), 4, 'X')
|
||||
mat_trans = mathutils.Matrix.Translation(vec)
|
||||
|
||||
mat = mat_trans * mat_rot
|
||||
mat.invert()
|
||||
|
||||
mat3 = mat.rotation_part()
|
||||
quat1 = mat.to_quat()
|
||||
quat2 = mat3.to_quat()
|
||||
|
||||
angle = quat1.difference(quat2)
|
||||
|
||||
print(angle)
|
||||
@@ -1,862 +0,0 @@
|
||||
# ***** BEGIN GPL LICENSE BLOCK *****
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
#
|
||||
# Contributor(s): Campbell Barton
|
||||
#
|
||||
# #**** END GPL LICENSE BLOCK #****
|
||||
|
||||
script_help_msg = '''
|
||||
Usage,
|
||||
run this script from blenders root path once you have compiled blender
|
||||
./blender.bin -b -P /b/source/blender/python/doc/sphinx_doc_gen.py
|
||||
|
||||
This will generate python files in "./source/blender/python/doc/sphinx-in"
|
||||
Generate html docs by running...
|
||||
|
||||
sphinx-build source/blender/python/doc/sphinx-in source/blender/python/doc/sphinx-out
|
||||
|
||||
|
||||
For PDF generation
|
||||
|
||||
sphinx-build -b latex source/blender/python/doc/sphinx-in source/blender/python/doc/sphinx-out
|
||||
cd source/blender/python/doc/sphinx-out
|
||||
make
|
||||
'''
|
||||
|
||||
# import rpdb2; rpdb2.start_embedded_debugger('test')
|
||||
|
||||
import os
|
||||
import inspect
|
||||
import bpy
|
||||
import rna_info
|
||||
reload(rna_info)
|
||||
|
||||
# lame, python wont give some access
|
||||
ClassMethodDescriptorType = type(dict.__dict__['fromkeys'])
|
||||
MethodDescriptorType = type(dict.get)
|
||||
GetSetDescriptorType = type(int.real)
|
||||
|
||||
EXAMPLE_SET = set()
|
||||
EXAMPLE_SET_USED = set()
|
||||
|
||||
_BPY_STRUCT_FAKE = "bpy_struct"
|
||||
_BPY_FULL_REBUILD = False
|
||||
|
||||
def undocumented_message(module_name, type_name, identifier):
|
||||
message = "Undocumented (`contribute " \
|
||||
"<http://wiki.blender.org/index.php/Dev:2.5/Py/API/Documentation/Contribute" \
|
||||
"?action=edit§ion=new&preload=Dev:2.5/Py/API/Documentation/Contribute/Howto-message" \
|
||||
"&preloadtitle=%s.%s.%s>`_)\n\n" % (module_name, type_name, identifier)
|
||||
return message
|
||||
|
||||
|
||||
def range_str(val):
|
||||
'''
|
||||
Converts values to strings for the range directive.
|
||||
(unused function it seems)
|
||||
'''
|
||||
if val < -10000000: return '-inf'
|
||||
if val > 10000000: return 'inf'
|
||||
if type(val)==float:
|
||||
return '%g' % val
|
||||
else:
|
||||
return str(val)
|
||||
|
||||
|
||||
def write_example_ref(ident, fw, example_id, ext="py"):
|
||||
if example_id in EXAMPLE_SET:
|
||||
fw("%s.. literalinclude:: ../examples/%s.%s\n\n" % (ident, example_id, ext))
|
||||
EXAMPLE_SET_USED.add(example_id)
|
||||
else:
|
||||
if bpy.app.debug:
|
||||
print("\tskipping example:", example_id)
|
||||
|
||||
|
||||
def write_indented_lines(ident, fn, text, strip=True):
|
||||
'''
|
||||
Apply same indentation to all lines in a multilines text.
|
||||
'''
|
||||
if text is None:
|
||||
return
|
||||
for l in text.split("\n"):
|
||||
if strip:
|
||||
fn(ident + l.strip() + "\n")
|
||||
else:
|
||||
fn(ident + l + "\n")
|
||||
|
||||
|
||||
def pymethod2sphinx(ident, fw, identifier, py_func):
|
||||
'''
|
||||
class method to sphinx
|
||||
'''
|
||||
arg_str = inspect.formatargspec(*inspect.getargspec(py_func))
|
||||
if arg_str.startswith("(self, "):
|
||||
arg_str = "(" + arg_str[7:]
|
||||
func_type = "method"
|
||||
elif arg_str.startswith("(cls, "):
|
||||
arg_str = "(" + arg_str[6:]
|
||||
func_type = "classmethod"
|
||||
else:
|
||||
func_type = "staticmethod"
|
||||
|
||||
fw(ident + ".. %s:: %s%s\n\n" % (func_type, identifier, arg_str))
|
||||
if py_func.__doc__:
|
||||
write_indented_lines(ident + " ", fw, py_func.__doc__)
|
||||
fw("\n")
|
||||
|
||||
|
||||
def pyfunc2sphinx(ident, fw, identifier, py_func, is_class=True):
|
||||
'''
|
||||
function or class method to sphinx
|
||||
'''
|
||||
arg_str = inspect.formatargspec(*inspect.getargspec(py_func))
|
||||
|
||||
if not is_class:
|
||||
func_type = "function"
|
||||
|
||||
# ther rest are class methods
|
||||
elif arg_str.startswith("(self, "):
|
||||
arg_str = "(" + arg_str[7:]
|
||||
func_type = "method"
|
||||
elif arg_str.startswith("(cls, "):
|
||||
arg_str = "(" + arg_str[6:]
|
||||
func_type = "classmethod"
|
||||
else:
|
||||
func_type = "staticmethod"
|
||||
|
||||
fw(ident + ".. %s:: %s%s\n\n" % (func_type, identifier, arg_str))
|
||||
if py_func.__doc__:
|
||||
write_indented_lines(ident + " ", fw, py_func.__doc__.strip())
|
||||
fw("\n")
|
||||
|
||||
|
||||
def py_descr2sphinx(ident, fw, descr, module_name, type_name, identifier):
|
||||
if identifier.startswith("_"):
|
||||
return
|
||||
|
||||
doc = descr.__doc__
|
||||
if not doc:
|
||||
doc = undocumented_message(module_name, type_name, identifier)
|
||||
|
||||
if type(descr) == GetSetDescriptorType:
|
||||
fw(ident + ".. attribute:: %s\n\n" % identifier)
|
||||
write_indented_lines(ident + " ", fw, doc, False)
|
||||
elif type(descr) in (MethodDescriptorType, ClassMethodDescriptorType):
|
||||
write_indented_lines(ident, fw, doc, False)
|
||||
else:
|
||||
raise TypeError("type was not GetSetDescriptorType, MethodDescriptorType or ClassMethodDescriptorType")
|
||||
|
||||
write_example_ref(ident, fw, module_name + "." + type_name + "." + identifier)
|
||||
fw("\n")
|
||||
|
||||
|
||||
def py_c_func2sphinx(ident, fw, module_name, type_name, identifier, py_func, is_class=True):
|
||||
'''
|
||||
c defined function to sphinx.
|
||||
'''
|
||||
|
||||
# dump the docstring, assume its formatted correctly
|
||||
if py_func.__doc__:
|
||||
write_indented_lines(ident, fw, py_func.__doc__, False)
|
||||
fw("\n")
|
||||
else:
|
||||
fw(ident + ".. function:: %s()\n\n" % identifier)
|
||||
fw(ident + " " + undocumented_message(module_name, type_name, identifier))
|
||||
|
||||
|
||||
def pyprop2sphinx(ident, fw, identifier, py_prop):
|
||||
'''
|
||||
python property to sphinx
|
||||
'''
|
||||
# readonly properties use "data" directive, variables use "attribute" directive
|
||||
if py_prop.fset is None:
|
||||
fw(ident + ".. data:: %s\n\n" % identifier)
|
||||
else:
|
||||
fw(ident + ".. attribute:: %s\n\n" % identifier)
|
||||
write_indented_lines(ident + " ", fw, py_prop.__doc__)
|
||||
if py_prop.fset is None:
|
||||
fw(ident + " (readonly)\n\n")
|
||||
|
||||
|
||||
def pymodule2sphinx(BASEPATH, module_name, module, title):
|
||||
import types
|
||||
attribute_set = set()
|
||||
filepath = os.path.join(BASEPATH, module_name + ".rst")
|
||||
|
||||
file = open(filepath, "w")
|
||||
|
||||
fw = file.write
|
||||
|
||||
fw(title + "\n")
|
||||
fw(("=" * len(title)) + "\n\n")
|
||||
|
||||
fw(".. module:: %s\n\n" % module_name)
|
||||
|
||||
if module.__doc__:
|
||||
# Note, may contain sphinx syntax, dont mangle!
|
||||
fw(module.__doc__.strip())
|
||||
fw("\n\n")
|
||||
|
||||
write_example_ref("", fw, module_name)
|
||||
|
||||
# write members of the module
|
||||
# only tested with PyStructs which are not exactly modules
|
||||
for key, descr in sorted(type(module).__dict__.items()):
|
||||
if type(descr) == types.MemberDescriptorType:
|
||||
if descr.__doc__:
|
||||
fw(".. data:: %s\n\n" % key)
|
||||
write_indented_lines(" ", fw, descr.__doc__, False)
|
||||
attribute_set.add(key)
|
||||
fw("\n")
|
||||
del key, descr
|
||||
|
||||
classes = []
|
||||
|
||||
for attribute in sorted(dir(module)):
|
||||
if not attribute.startswith("_"):
|
||||
|
||||
if attribute in attribute_set:
|
||||
continue
|
||||
|
||||
if attribute.startswith("n_"): # annoying exception, needed for bpy.app
|
||||
continue
|
||||
|
||||
value = getattr(module, attribute)
|
||||
|
||||
value_type = type(value)
|
||||
|
||||
if value_type == types.FunctionType:
|
||||
pyfunc2sphinx("", fw, attribute, value, is_class=False)
|
||||
elif value_type in (types.BuiltinMethodType, types.BuiltinFunctionType): # both the same at the moment but to be future proof
|
||||
# note: can't get args from these, so dump the string as is
|
||||
# this means any module used like this must have fully formatted docstrings.
|
||||
py_c_func2sphinx("", fw, module_name, module, attribute, value, is_class=False)
|
||||
elif value_type == type:
|
||||
classes.append((attribute, value))
|
||||
elif value_type in (bool, int, float, str, tuple):
|
||||
# constant, not much fun we can do here except to list it.
|
||||
# TODO, figure out some way to document these!
|
||||
fw(".. data:: %s\n\n" % attribute)
|
||||
write_indented_lines(" ", fw, "constant value %s" % repr(value), False)
|
||||
fw("\n")
|
||||
else:
|
||||
print("\tnot documenting %s.%s" % (module_name, attribute))
|
||||
continue
|
||||
|
||||
attribute_set.add(attribute)
|
||||
# TODO, more types...
|
||||
|
||||
# write collected classes now
|
||||
for (type_name, value) in classes:
|
||||
# May need to be its own function
|
||||
fw(".. class:: %s\n\n" % type_name)
|
||||
if value.__doc__:
|
||||
write_indented_lines(" ", fw, value.__doc__, False)
|
||||
fw("\n")
|
||||
write_example_ref(" ", fw, module_name + "." + type_name)
|
||||
|
||||
descr_items = [(key, descr) for key, descr in sorted(value.__dict__.items()) if not key.startswith("__")]
|
||||
|
||||
for key, descr in descr_items:
|
||||
if type(descr) == ClassMethodDescriptorType:
|
||||
py_descr2sphinx(" ", fw, descr, module_name, type_name, key)
|
||||
|
||||
for key, descr in descr_items:
|
||||
if type(descr) == MethodDescriptorType:
|
||||
py_descr2sphinx(" ", fw, descr, module_name, type_name, key)
|
||||
|
||||
for key, descr in descr_items:
|
||||
if type(descr) == GetSetDescriptorType:
|
||||
py_descr2sphinx(" ", fw, descr, module_name, type_name, key)
|
||||
|
||||
fw("\n\n")
|
||||
|
||||
file.close()
|
||||
|
||||
|
||||
|
||||
def rna2sphinx(BASEPATH):
|
||||
|
||||
structs, funcs, ops, props = rna_info.BuildRNAInfo()
|
||||
|
||||
try:
|
||||
os.mkdir(BASEPATH)
|
||||
except:
|
||||
pass
|
||||
|
||||
# conf.py - empty for now
|
||||
filepath = os.path.join(BASEPATH, "conf.py")
|
||||
file = open(filepath, "w")
|
||||
fw = file.write
|
||||
|
||||
|
||||
version_string = bpy.app.version_string.split("(")[0]
|
||||
if bpy.app.build_revision != "Unknown":
|
||||
version_string = version_string + " r" + bpy.app.build_revision
|
||||
|
||||
# for use with files
|
||||
version_string_fp = "_".join(str(v) for v in bpy.app.version)
|
||||
|
||||
fw("project = 'Blender'\n")
|
||||
# fw("master_doc = 'index'\n")
|
||||
fw("copyright = u'Blender Foundation'\n")
|
||||
fw("version = '%s - UNSTABLE API'\n" % version_string)
|
||||
fw("release = '%s - UNSTABLE API'\n" % version_string)
|
||||
fw("html_theme = 'blender-org'\n")
|
||||
fw("html_theme_path = ['../']\n")
|
||||
fw("html_favicon = 'favicon.ico'\n")
|
||||
# not helpful since the source us generated, adds to upload size.
|
||||
fw("html_copy_source = False\n")
|
||||
fw("\n")
|
||||
# needed for latex, pdf gen
|
||||
fw("latex_documents = [ ('contents', 'contents.tex', 'Blender Index', 'Blender Foundation', 'manual'), ]\n")
|
||||
fw("latex_paper_size = 'a4paper'\n")
|
||||
file.close()
|
||||
|
||||
|
||||
filepath = os.path.join(BASEPATH, "contents.rst")
|
||||
file = open(filepath, "w")
|
||||
fw = file.write
|
||||
|
||||
fw("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n")
|
||||
fw(" Blender Documentation contents\n")
|
||||
fw("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n")
|
||||
fw("\n")
|
||||
fw("This document is an API reference for Blender %s. built %s.\n" % (version_string, bpy.app.build_date))
|
||||
fw("\n")
|
||||
fw("An introduction to Blender and Python can be found at <http://wiki.blender.org/index.php/Dev:2.5/Py/API/Intro>\n")
|
||||
fw("\n")
|
||||
fw("`A PDF version of this document is also available <blender_python_reference_%s.pdf>`__\n" % version_string_fp)
|
||||
fw("\n")
|
||||
fw(".. warning:: The Python API in Blender is **UNSTABLE**, It should only be used for testing, any script written now may break in future releases.\n")
|
||||
fw(" \n")
|
||||
fw(" The following areas are subject to change.\n")
|
||||
fw(" * operator names and arguments\n")
|
||||
fw(" * render api\n")
|
||||
fw(" * function calls with the data api (any function calls with values accessed from bpy.data), including functions for importing and exporting meshes\n")
|
||||
fw(" * class registration (Operator, Panels, Menus, Headers)\n")
|
||||
fw(" * modules: bpy.props, blf)\n")
|
||||
fw(" * members in the bpy.context have to be reviewed\n")
|
||||
fw(" * python defined modal operators, especially drawing callbacks are highly experemental\n")
|
||||
fw(" \n")
|
||||
fw(" These parts of the API are relatively stable and are unlikely to change significantly\n")
|
||||
fw(" * data API, access to attributes of blender data such as mesh verts, material color, timeline frames and scene objects\n")
|
||||
fw(" * user interface functions for defining buttons, creation of menus, headers, panels\n")
|
||||
fw(" * modules: bgl, mathutils and geometry\n")
|
||||
fw(" * game engine modules\n")
|
||||
fw("\n")
|
||||
|
||||
fw("===================\n")
|
||||
fw("Application Modules\n")
|
||||
fw("===================\n")
|
||||
fw("\n")
|
||||
fw(".. toctree::\n")
|
||||
fw(" :maxdepth: 1\n\n")
|
||||
fw(" bpy.data.rst\n\n") # note: not actually a module
|
||||
fw(" bpy.ops.rst\n\n")
|
||||
fw(" bpy.types.rst\n\n")
|
||||
|
||||
# py modules
|
||||
fw(" bpy.utils.rst\n\n")
|
||||
fw(" bpy.path.rst\n\n")
|
||||
fw(" bpy.app.rst\n\n")
|
||||
|
||||
# C modules
|
||||
fw(" bpy.props.rst\n\n")
|
||||
|
||||
fw("==================\n")
|
||||
fw("Standalone Modules\n")
|
||||
fw("==================\n")
|
||||
fw("\n")
|
||||
fw(".. toctree::\n")
|
||||
fw(" :maxdepth: 1\n\n")
|
||||
|
||||
|
||||
fw(" mathutils.rst\n\n")
|
||||
fw(" blf.rst\n\n")
|
||||
fw(" aud.rst\n\n")
|
||||
|
||||
# game engine
|
||||
fw("===================\n")
|
||||
fw("Game Engine Modules\n")
|
||||
fw("===================\n")
|
||||
fw("\n")
|
||||
fw(".. toctree::\n")
|
||||
fw(" :maxdepth: 1\n\n")
|
||||
fw(" bge.types.rst\n\n")
|
||||
fw(" bge.logic.rst\n\n")
|
||||
fw(" bge.render.rst\n\n")
|
||||
fw(" bge.events.rst\n\n")
|
||||
|
||||
file.close()
|
||||
|
||||
|
||||
# internal modules
|
||||
filepath = os.path.join(BASEPATH, "bpy.ops.rst")
|
||||
file = open(filepath, "w")
|
||||
fw = file.write
|
||||
fw("Operators (bpy.ops)\n")
|
||||
fw("===================\n\n")
|
||||
fw(".. toctree::\n")
|
||||
fw(" :glob:\n\n")
|
||||
fw(" bpy.ops.*\n\n")
|
||||
file.close()
|
||||
|
||||
filepath = os.path.join(BASEPATH, "bpy.types.rst")
|
||||
file = open(filepath, "w")
|
||||
fw = file.write
|
||||
fw("Types (bpy.types)\n")
|
||||
fw("=================\n\n")
|
||||
fw(".. toctree::\n")
|
||||
fw(" :glob:\n\n")
|
||||
fw(" bpy.types.*\n\n")
|
||||
file.close()
|
||||
|
||||
|
||||
# not actually a module, only write this file so we
|
||||
# can reference in the TOC
|
||||
filepath = os.path.join(BASEPATH, "bpy.data.rst")
|
||||
file = open(filepath, "w")
|
||||
fw = file.write
|
||||
fw("Data Access (bpy.data)\n")
|
||||
fw("======================\n\n")
|
||||
fw(".. module:: bpy\n")
|
||||
fw("\n")
|
||||
fw("This module is used for all blender/python access.\n")
|
||||
fw("\n")
|
||||
fw(".. literalinclude:: ../examples/bpy.data.py\n")
|
||||
fw("\n")
|
||||
fw(".. data:: data\n")
|
||||
fw("\n")
|
||||
fw(" Access to blenders internal data\n")
|
||||
fw("\n")
|
||||
fw(" :type: :class:`bpy.types.BlendData`\n")
|
||||
file.close()
|
||||
|
||||
EXAMPLE_SET_USED.add("bpy.data")
|
||||
|
||||
|
||||
# python modules
|
||||
from bpy import utils as module
|
||||
pymodule2sphinx(BASEPATH, "bpy.utils", module, "Utilities (bpy.utils)")
|
||||
|
||||
from bpy import path as module
|
||||
pymodule2sphinx(BASEPATH, "bpy.path", module, "Path Utilities (bpy.path)")
|
||||
|
||||
# C modules
|
||||
from bpy import app as module
|
||||
pymodule2sphinx(BASEPATH, "bpy.app", module, "Application Data (bpy.app)")
|
||||
|
||||
from bpy import props as module
|
||||
pymodule2sphinx(BASEPATH, "bpy.props", module, "Property Definitions (bpy.props)")
|
||||
|
||||
import mathutils as module
|
||||
pymodule2sphinx(BASEPATH, "mathutils", module, "Math Types & Utilities (mathutils)")
|
||||
del module
|
||||
|
||||
import blf as module
|
||||
pymodule2sphinx(BASEPATH, "blf", module, "Font Drawing (blf)")
|
||||
del module
|
||||
|
||||
import aud as module
|
||||
pymodule2sphinx(BASEPATH, "aud", module, "Audio System (aud)")
|
||||
del module
|
||||
|
||||
# game engine
|
||||
import shutil
|
||||
# copy2 keeps time/date stamps
|
||||
shutil.copy2(os.path.join(BASEPATH, "../../../../gameengine/PyDoc/bge.types.rst"), BASEPATH)
|
||||
shutil.copy2(os.path.join(BASEPATH, "../../../../gameengine/PyDoc/bge.logic.rst"), BASEPATH)
|
||||
shutil.copy2(os.path.join(BASEPATH, "../../../../gameengine/PyDoc/bge.render.rst"), BASEPATH)
|
||||
shutil.copy2(os.path.join(BASEPATH, "../../../../gameengine/PyDoc/bge.events.rst"), BASEPATH)
|
||||
|
||||
|
||||
if 0:
|
||||
filepath = os.path.join(BASEPATH, "bpy.rst")
|
||||
file = open(filepath, "w")
|
||||
fw = file.write
|
||||
|
||||
fw("\n")
|
||||
|
||||
title = ":mod:`bpy` --- Blender Python Module"
|
||||
fw("%s\n%s\n\n" % (title, "=" * len(title)))
|
||||
fw(".. module:: bpy.types\n\n")
|
||||
file.close()
|
||||
|
||||
def write_param(ident, fw, prop, is_return=False):
|
||||
if is_return:
|
||||
id_name = "return"
|
||||
id_type = "rtype"
|
||||
kwargs = {"as_ret": True, "class_fmt": ":class:`%s`"}
|
||||
identifier = ""
|
||||
else:
|
||||
id_name = "arg"
|
||||
id_type = "type"
|
||||
kwargs = {"as_arg": True, "class_fmt": ":class:`%s`"}
|
||||
identifier = " %s" % prop.identifier
|
||||
|
||||
type_descr = prop.get_type_description(**kwargs)
|
||||
if prop.name or prop.description:
|
||||
fw(ident + ":%s%s: %s\n" % (id_name, identifier, ", ".join(val for val in (prop.name, prop.description) if val)))
|
||||
fw(ident + ":%s%s: %s\n" % (id_type, identifier, type_descr))
|
||||
|
||||
def write_struct(struct):
|
||||
#if not struct.identifier.startswith("Sc") and not struct.identifier.startswith("I"):
|
||||
# return
|
||||
|
||||
#if not struct.identifier == "Object":
|
||||
# return
|
||||
|
||||
filepath = os.path.join(BASEPATH, "bpy.types.%s.rst" % struct.identifier)
|
||||
file = open(filepath, "w")
|
||||
fw = file.write
|
||||
|
||||
base_id = getattr(struct.base, "identifier", "")
|
||||
|
||||
if _BPY_STRUCT_FAKE:
|
||||
if not base_id:
|
||||
base_id = _BPY_STRUCT_FAKE
|
||||
|
||||
if base_id:
|
||||
title = "%s(%s)" % (struct.identifier, base_id)
|
||||
else:
|
||||
title = struct.identifier
|
||||
|
||||
fw("%s\n%s\n\n" % (title, "=" * len(title)))
|
||||
|
||||
fw(".. module:: bpy.types\n\n")
|
||||
|
||||
base_ids = [base.identifier for base in struct.get_bases()]
|
||||
|
||||
if _BPY_STRUCT_FAKE:
|
||||
base_ids.append(_BPY_STRUCT_FAKE)
|
||||
|
||||
base_ids.reverse()
|
||||
|
||||
if base_ids:
|
||||
if len(base_ids) > 1:
|
||||
fw("base classes --- ")
|
||||
else:
|
||||
fw("base class --- ")
|
||||
|
||||
fw(", ".join((":class:`%s`" % base_id) for base_id in base_ids))
|
||||
fw("\n\n")
|
||||
|
||||
subclass_ids = [s.identifier for s in structs.values() if s.base is struct if not rna_info.rna_id_ignore(s.identifier)]
|
||||
if subclass_ids:
|
||||
fw("subclasses --- \n" + ", ".join((":class:`%s`" % s) for s in subclass_ids) + "\n\n")
|
||||
|
||||
base_id = getattr(struct.base, "identifier", "")
|
||||
|
||||
if _BPY_STRUCT_FAKE:
|
||||
if not base_id:
|
||||
base_id = _BPY_STRUCT_FAKE
|
||||
|
||||
if base_id:
|
||||
fw(".. class:: %s(%s)\n\n" % (struct.identifier, base_id))
|
||||
else:
|
||||
fw(".. class:: %s\n\n" % struct.identifier)
|
||||
|
||||
fw(" %s\n\n" % struct.description)
|
||||
|
||||
# properties sorted in alphabetical order
|
||||
sorted_struct_properties = struct.properties[:]
|
||||
sorted_struct_properties.sort(key=lambda prop: prop.identifier)
|
||||
|
||||
for prop in sorted_struct_properties:
|
||||
type_descr = prop.get_type_description(class_fmt=":class:`%s`")
|
||||
# readonly properties use "data" directive, variables properties use "attribute" directive
|
||||
if 'readonly' in type_descr:
|
||||
fw(" .. data:: %s\n\n" % prop.identifier)
|
||||
else:
|
||||
fw(" .. attribute:: %s\n\n" % prop.identifier)
|
||||
if prop.description:
|
||||
fw(" %s\n\n" % prop.description)
|
||||
fw(" :type: %s\n\n" % type_descr)
|
||||
|
||||
# python attributes
|
||||
py_properties = struct.get_py_properties()
|
||||
py_prop = None
|
||||
for identifier, py_prop in py_properties:
|
||||
pyprop2sphinx(" ", fw, identifier, py_prop)
|
||||
del py_properties, py_prop
|
||||
|
||||
for func in struct.functions:
|
||||
args_str = ", ".join(prop.get_arg_default(force=False) for prop in func.args)
|
||||
|
||||
fw(" .. %s:: %s(%s)\n\n" % ("classmethod" if func.is_classmethod else "method", func.identifier, args_str))
|
||||
fw(" %s\n\n" % func.description)
|
||||
|
||||
for prop in func.args:
|
||||
write_param(" ", fw, prop)
|
||||
|
||||
if len(func.return_values) == 1:
|
||||
write_param(" ", fw, func.return_values[0], is_return=True)
|
||||
elif func.return_values: # multiple return values
|
||||
fw(" :return (%s):\n" % ", ".join(prop.identifier for prop in func.return_values))
|
||||
for prop in func.return_values:
|
||||
type_descr = prop.get_type_description(as_ret=True, class_fmt=":class:`%s`")
|
||||
descr = prop.description
|
||||
if not descr:
|
||||
descr = prop.name
|
||||
fw(" `%s`, %s, %s\n\n" % (prop.identifier, descr, type_descr))
|
||||
|
||||
fw("\n")
|
||||
|
||||
|
||||
# python methods
|
||||
py_funcs = struct.get_py_functions()
|
||||
py_func = None
|
||||
|
||||
for identifier, py_func in py_funcs:
|
||||
pyfunc2sphinx(" ", fw, identifier, py_func, is_class=True)
|
||||
del py_funcs, py_func
|
||||
|
||||
lines = []
|
||||
|
||||
if struct.base or _BPY_STRUCT_FAKE:
|
||||
bases = list(reversed(struct.get_bases()))
|
||||
|
||||
# props
|
||||
lines[:] = []
|
||||
|
||||
if _BPY_STRUCT_FAKE:
|
||||
descr_items = [(key, descr) for key, descr in sorted(bpy.types.Struct.__bases__[0].__dict__.items()) if not key.startswith("__")]
|
||||
|
||||
if _BPY_STRUCT_FAKE:
|
||||
for key, descr in descr_items:
|
||||
if type(descr) == GetSetDescriptorType:
|
||||
lines.append(" * :class:`%s.%s`\n" % (_BPY_STRUCT_FAKE, key))
|
||||
|
||||
for base in bases:
|
||||
for prop in base.properties:
|
||||
lines.append(" * :class:`%s.%s`\n" % (base.identifier, prop.identifier))
|
||||
|
||||
for identifier, py_prop in base.get_py_properties():
|
||||
lines.append(" * :class:`%s.%s`\n" % (base.identifier, identifier))
|
||||
|
||||
for identifier, py_prop in base.get_py_properties():
|
||||
lines.append(" * :class:`%s.%s`\n" % (base.identifier, identifier))
|
||||
|
||||
if lines:
|
||||
fw(".. rubric:: Inherited Properties\n\n")
|
||||
|
||||
fw(".. hlist::\n")
|
||||
fw(" :columns: 2\n\n")
|
||||
|
||||
for line in lines:
|
||||
fw(line)
|
||||
fw("\n")
|
||||
|
||||
|
||||
# funcs
|
||||
lines[:] = []
|
||||
|
||||
if _BPY_STRUCT_FAKE:
|
||||
for key, descr in descr_items:
|
||||
if type(descr) == MethodDescriptorType:
|
||||
lines.append(" * :class:`%s.%s`\n" % (_BPY_STRUCT_FAKE, key))
|
||||
|
||||
for base in bases:
|
||||
for func in base.functions:
|
||||
lines.append(" * :class:`%s.%s`\n" % (base.identifier, func.identifier))
|
||||
for identifier, py_func in base.get_py_functions():
|
||||
lines.append(" * :class:`%s.%s`\n" % (base.identifier, identifier))
|
||||
|
||||
if lines:
|
||||
fw(".. rubric:: Inherited Functions\n\n")
|
||||
|
||||
fw(".. hlist::\n")
|
||||
fw(" :columns: 2\n\n")
|
||||
|
||||
for line in lines:
|
||||
fw(line)
|
||||
fw("\n")
|
||||
|
||||
lines[:] = []
|
||||
|
||||
|
||||
if struct.references:
|
||||
# use this otherwise it gets in the index for a normal heading.
|
||||
fw(".. rubric:: References\n\n")
|
||||
|
||||
fw(".. hlist::\n")
|
||||
fw(" :columns: 2\n\n")
|
||||
|
||||
for ref in struct.references:
|
||||
ref_split = ref.split(".")
|
||||
if len(ref_split) > 2:
|
||||
ref = ref_split[-2] + "." + ref_split[-1]
|
||||
fw(" * :class:`%s`\n" % ref)
|
||||
fw("\n")
|
||||
|
||||
|
||||
for struct in structs.values():
|
||||
# TODO, rna_info should filter these out!
|
||||
if "_OT_" in struct.identifier:
|
||||
continue
|
||||
write_struct(struct)
|
||||
|
||||
# special case, bpy_struct
|
||||
if _BPY_STRUCT_FAKE:
|
||||
filepath = os.path.join(BASEPATH, "bpy.types.%s.rst" % _BPY_STRUCT_FAKE)
|
||||
file = open(filepath, "w")
|
||||
fw = file.write
|
||||
|
||||
fw("%s\n" % _BPY_STRUCT_FAKE)
|
||||
fw("=" * len(_BPY_STRUCT_FAKE) + "\n")
|
||||
fw("\n")
|
||||
fw(".. module:: bpy.types\n")
|
||||
fw("\n")
|
||||
|
||||
subclass_ids = [s.identifier for s in structs.values() if s.base is None if not rna_info.rna_id_ignore(s.identifier)]
|
||||
if subclass_ids:
|
||||
fw("subclasses --- \n" + ", ".join((":class:`%s`" % s) for s in sorted(subclass_ids)) + "\n\n")
|
||||
|
||||
fw(".. class:: %s\n\n" % _BPY_STRUCT_FAKE)
|
||||
fw(" built-in base class for all classes in bpy.types.\n\n")
|
||||
fw(" .. note::\n\n")
|
||||
fw(" Note that bpy.types.%s is not actually available from within blender, it only exists for the purpose of documentation.\n\n" % _BPY_STRUCT_FAKE)
|
||||
|
||||
descr_items = [(key, descr) for key, descr in sorted(bpy.types.Struct.__bases__[0].__dict__.items()) if not key.startswith("__")]
|
||||
|
||||
for key, descr in descr_items:
|
||||
if type(descr) == MethodDescriptorType: # GetSetDescriptorType, GetSetDescriptorType's are not documented yet
|
||||
py_descr2sphinx(" ", fw, descr, "bpy.types", _BPY_STRUCT_FAKE, key)
|
||||
|
||||
for key, descr in descr_items:
|
||||
if type(descr) == GetSetDescriptorType:
|
||||
py_descr2sphinx(" ", fw, descr, "bpy.types", _BPY_STRUCT_FAKE, key)
|
||||
|
||||
|
||||
# operators
|
||||
def write_ops():
|
||||
API_BASEURL='https://svn.blender.org/svnroot/bf-blender/trunk/blender/release/scripts'
|
||||
fw = None
|
||||
last_mod = ''
|
||||
|
||||
for op_key in sorted(ops.keys()):
|
||||
op = ops[op_key]
|
||||
|
||||
if last_mod != op.module_name:
|
||||
filepath = os.path.join(BASEPATH, "bpy.ops.%s.rst" % op.module_name)
|
||||
file = open(filepath, "w")
|
||||
fw = file.write
|
||||
|
||||
title = "%s Operators" % (op.module_name[0].upper() + op.module_name[1:])
|
||||
fw("%s\n%s\n\n" % (title, "=" * len(title)))
|
||||
|
||||
fw(".. module:: bpy.ops.%s\n\n" % op.module_name)
|
||||
last_mod = op.module_name
|
||||
|
||||
args_str = ", ".join(prop.get_arg_default(force=True) for prop in op.args)
|
||||
fw(".. function:: %s(%s)\n\n" % (op.func_name, args_str))
|
||||
|
||||
# if the description isn't valid, we output the standard warning
|
||||
# with a link to the wiki so that people can help
|
||||
if not op.description or op.description == "(undocumented operator)":
|
||||
operator_description = undocumented_message('bpy.ops',op.module_name,op.func_name)
|
||||
else:
|
||||
operator_description = op.description
|
||||
|
||||
fw(" %s\n\n" % operator_description)
|
||||
for prop in op.args:
|
||||
write_param(" ", fw, prop)
|
||||
if op.args:
|
||||
fw("\n")
|
||||
|
||||
location = op.get_location()
|
||||
if location != (None, None):
|
||||
fw(" :file: `%s <%s/%s>`_:%d\n\n" % (location[0],API_BASEURL,location[0],location[1]))
|
||||
|
||||
write_ops()
|
||||
|
||||
file.close()
|
||||
|
||||
def main():
|
||||
import bpy
|
||||
if 'bpy' not in dir():
|
||||
print("\nError, this script must run from inside blender2.5")
|
||||
print(script_help_msg)
|
||||
else:
|
||||
import shutil
|
||||
|
||||
path_in = 'source/blender/python/doc/sphinx-in'
|
||||
path_out = 'source/blender/python/doc/sphinx-out'
|
||||
path_examples = 'source/blender/python/doc/examples'
|
||||
# only for partial updates
|
||||
path_in_tmp = path_in + "-tmp"
|
||||
|
||||
if not os.path.exists(path_in):
|
||||
os.mkdir(path_in)
|
||||
|
||||
for f in os.listdir(path_examples):
|
||||
if f.endswith(".py"):
|
||||
EXAMPLE_SET.add(os.path.splitext(f)[0])
|
||||
|
||||
|
||||
# only for full updates
|
||||
if _BPY_FULL_REBUILD:
|
||||
shutil.rmtree(path_in, True)
|
||||
shutil.rmtree(path_out, True)
|
||||
else:
|
||||
# write here, then move
|
||||
shutil.rmtree(path_in_tmp, True)
|
||||
|
||||
rna2sphinx(path_in_tmp)
|
||||
|
||||
if not _BPY_FULL_REBUILD:
|
||||
import filecmp
|
||||
|
||||
# now move changed files from 'path_in_tmp' --> 'path_in'
|
||||
file_list_path_in = set(os.listdir(path_in))
|
||||
file_list_path_in_tmp = set(os.listdir(path_in_tmp))
|
||||
|
||||
# remove deprecated files that have been removed.
|
||||
for f in sorted(file_list_path_in):
|
||||
if f not in file_list_path_in_tmp:
|
||||
print("\tdeprecated: %s" % f)
|
||||
os.remove(os.path.join(path_in, f))
|
||||
|
||||
# freshen with new files.
|
||||
for f in sorted(file_list_path_in_tmp):
|
||||
f_from = os.path.join(path_in_tmp, f)
|
||||
f_to = os.path.join(path_in, f)
|
||||
|
||||
do_copy = True
|
||||
if f in file_list_path_in:
|
||||
if filecmp.cmp(f_from, f_to):
|
||||
do_copy = False
|
||||
|
||||
if do_copy:
|
||||
print("\tupdating: %s" % f)
|
||||
shutil.copy(f_from, f_to)
|
||||
'''else:
|
||||
print("\tkeeping: %s" % f) # eh, not that useful'''
|
||||
|
||||
|
||||
EXAMPLE_SET_UNUSED = EXAMPLE_SET - EXAMPLE_SET_USED
|
||||
if EXAMPLE_SET_UNUSED:
|
||||
print("\nUnused examples found in '%s'..." % path_examples)
|
||||
for f in EXAMPLE_SET_UNUSED:
|
||||
print(" %s.py" % f)
|
||||
print(" %d total\n" % len(EXAMPLE_SET_UNUSED))
|
||||
|
||||
import sys
|
||||
sys.exit()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -1,35 +0,0 @@
|
||||
#!/bin/sh
|
||||
# run from the blender source dir
|
||||
# bash source/blender/python/doc/sphinx_doc_gen.sh
|
||||
# ssh upload means you need an account on the server
|
||||
|
||||
BLENDER="./blender.bin"
|
||||
SSH_HOST="ideasman42@emo.blender.org"
|
||||
SSH_UPLOAD="/data/www/vhosts/www.blender.org/documentation" # blender_python_api_VERSION, added after
|
||||
|
||||
# sed string from hell, 'Blender 2.53 (sub 1) Build' --> '2_53_1'
|
||||
# "_".join(str(v) for v in bpy.app.version)
|
||||
# custom blender vars
|
||||
blender_srcdir=$(dirname $0)/../../../../
|
||||
blender_version=$(grep BLENDER_VERSION $blender_srcdir/source/blender/blenkernel/BKE_blender.h | tr -dc 0-9)
|
||||
blender_subversion=$(grep BLENDER_SUBVERSION $blender_srcdir/source/blender/blenkernel/BKE_blender.h | tr -dc 0-9)
|
||||
BLENDER_VERSION=$(expr $blender_version / 100)_$(expr $blender_version % 100)_$blender_subversion
|
||||
|
||||
BLENDER_VERSION=`$BLENDER --version | cut -f2-4 -d" " | sed 's/(//g' | sed 's/)//g' | sed 's/ sub /./g' | sed 's/\./_/g'`
|
||||
SSH_UPLOAD_FULL=$SSH_UPLOAD/"blender_python_api_"$BLENDER_VERSION
|
||||
|
||||
# dont delete existing docs, now partial updates are used for quick builds.
|
||||
$BLENDER --background --python ./source/blender/python/doc/sphinx_doc_gen.py
|
||||
|
||||
# html
|
||||
sphinx-build source/blender/python/doc/sphinx-in source/blender/python/doc/sphinx-out
|
||||
cp source/blender/python/doc/sphinx-out/contents.html source/blender/python/doc/sphinx-out/index.html
|
||||
ssh ideasman42@emo.blender.org 'rm -rf '$SSH_UPLOAD_FULL'/*'
|
||||
rsync --progress -avze "ssh -p 22" /b/source/blender/python/doc/sphinx-out/* $SSH_HOST:$SSH_UPLOAD_FULL/
|
||||
|
||||
# pdf
|
||||
sphinx-build -b latex source/blender/python/doc/sphinx-in source/blender/python/doc/sphinx-out
|
||||
cd source/blender/python/doc/sphinx-out
|
||||
make
|
||||
cd ../../../../../
|
||||
rsync --progress -avze "ssh -p 22" source/blender/python/doc/sphinx-out/contents.pdf $SSH_HOST:$SSH_UPLOAD_FULL/blender_python_reference_$BLENDER_VERSION.pdf
|
||||
Reference in New Issue
Block a user