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>2011-01-12 20:29:54 +0300
committerCampbell Barton <ideasman42@gmail.com>2011-01-12 20:29:54 +0300
commitda69433ff9b579452e18cb781f44230b28b93bcf (patch)
tree94e2bb14488474eda68396d4f52499b3adb06958 /release
parent792f3b11f952be344ef24bc5879883a156b0e04f (diff)
simple add mesh operator template.
Diffstat (limited to 'release')
-rw-r--r--release/scripts/templates/operator_mesh_add.py99
1 files changed, 99 insertions, 0 deletions
diff --git a/release/scripts/templates/operator_mesh_add.py b/release/scripts/templates/operator_mesh_add.py
new file mode 100644
index 00000000000..677fa855951
--- /dev/null
+++ b/release/scripts/templates/operator_mesh_add.py
@@ -0,0 +1,99 @@
+import bpy
+
+
+def add_box(width, height, depth):
+ """
+ This function takes inputs and returns vertex and face arrays.
+ no actual mesh data creation is done here.
+ """
+
+ vertices = [1.0, 1.0, -1.0,
+ 1.0, -1.0, -1.0,
+ -1.0, -1.0, -1.0,
+ -1.0, 1.0, -1.0,
+ 1.0, 1.0, 1.0,
+ 1.0, -1.0, 1.0,
+ -1.0, -1.0, 1.0,
+ -1.0, 1.0, 1.0,
+ ]
+
+ faces = [0, 1, 2, 3,
+ 4, 7, 6, 5,
+ 0, 4, 5, 1,
+ 1, 5, 6, 2,
+ 2, 6, 7, 3,
+ 4, 0, 3, 7,
+ ]
+
+ # apply size
+ for i in range(0, len(vertices), 3):
+ vertices[i] *= width
+ vertices[i + 1] *= depth
+ vertices[i + 2] *= height
+
+ return vertices, faces
+
+
+from bpy.props import *
+
+
+class AddBox(bpy.types.Operator):
+ '''Add a simple box mesh'''
+ bl_idname = "mesh.primitive_box_add"
+ bl_label = "Add Box"
+ bl_options = {'REGISTER', 'UNDO'}
+
+ width = FloatProperty(name="Width",
+ description="Box Width",
+ default=1.0, min=0.01, max=100.0)
+
+ height = FloatProperty(name="Height",
+ description="Box Height",
+ default=1.0, min=0.01, max=100.0)
+
+ depth = FloatProperty(name="Depth",
+ description="Box Depth",
+ default=1.0, min=0.01, max=100.0)
+
+ # generic transform props
+ view_align = BoolProperty(name="Align to View",
+ default=False)
+ location = FloatVectorProperty(name="Location")
+ rotation = FloatVectorProperty(name="Rotation")
+
+ def execute(self, context):
+
+ verts_loc, faces = add_box(self.width,
+ self.height,
+ self.depth,
+ )
+
+ mesh = bpy.data.meshes.new("Box")
+
+ mesh.vertices.add(len(verts_loc) // 3)
+ mesh.faces.add(len(faces) // 4)
+
+ mesh.vertices.foreach_set("co", verts_loc)
+ mesh.faces.foreach_set("vertices_raw", faces)
+ mesh.update()
+
+ # add the mesh as an object into the scene with this utility module
+ import add_object_utils
+ add_object_utils.object_data_add(context, mesh, operator=self)
+
+ return {'FINISHED'}
+
+
+def menu_func(self, context):
+ self.layout.operator(AddBox.bl_idname, icon='MESH_CUBE')
+
+
+def register():
+ bpy.types.INFO_MT_mesh_add.append(menu_func)
+
+
+def unregister():
+ bpy.types.INFO_MT_mesh_add.remove(menu_func)
+
+if __name__ == "__main__":
+ bpy.ops.mesh.primitive_box_add()