Created
December 14, 2016 15:09
-
-
Save pcote/1b9c2bef3c6e9d99f31e2511c1cb73ae to your computer and use it in GitHub Desktop.
A simple 'revisiting' of the basics of custom Blender operators for making meshes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
ShapeMaker.py | |
A just for fun blender operator that sticks a mesh into the current scene. | |
Mainly just a 'revisiting' exercise in operators that make specialized mesh objects. | |
""" | |
import bpy | |
import bmesh | |
from bpy.props import FloatProperty | |
class ShapeMaker(bpy.types.Operator): | |
bl_idname = "object.shapemaker" | |
bl_label = "Shape Maker" | |
bl_options = {"REGISTER", "UNDO"} | |
x_loc = FloatProperty(name="x loc", min=-5, max=5, default=0) | |
def execute(self, cxt): | |
vert_data = [[-5, 0, 0], | |
[5, 0, 0], | |
[self.x_loc, 5, 0]] | |
bm = bmesh.new() | |
for vert in vert_data: | |
bm.verts.new(vert) | |
bm.verts.ensure_lookup_table() | |
face_idxs = [[0, 1, 2]] | |
for face_idx in face_idxs: | |
bm.faces.new([bm.verts[i] for i in face_idx]) | |
mesh = bpy.data.meshes.new("mymesh") | |
bm.to_mesh(mesh) | |
ob = bpy.data.objects.new("myob", object_data=mesh) | |
cxt.scene.objects.link(ob) | |
return {"FINISHED"} | |
if __name__ == '__main__': | |
bpy.utils.register_class(ShapeMaker) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment