Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import bpy
- from bpy import context
- from math import sin, cos, radians
- import mathutils
- from mathutils import Vector
- #set the name of the object
- nameo = "CustomLine"
- #if the mesh already exists, delete it
- for ob in bpy.context.scene.objects:
- if ob.type == 'MESH' and nameo in ob.name:
- ob.select = True
- bpy.ops.object.delete()
- else:
- ob.select = False
- #create a mesh where the x and z values of each vertex follow sine and cosine curves
- #and the y value simply increments forward on the y axis.
- verts = []
- faces = []
- for i in range(360):
- z = 10*sin(radians(i))
- x = 10*cos(radians(i))
- y = i/10
- verts.append((x,y,z))
- for i in range(359):
- faces.append((i,i+1))
- verts = tuple(verts)
- faces = tuple(faces)
- me = bpy.data.meshes.new("Mesh" + nameo)
- ob = bpy.data.objects.new(nameo, me)
- ob.location = Vector((0,0,0))
- scn = bpy.context.scene
- scn.objects.link(ob)
- scn.objects.active = ob
- ob.select = True
- me.from_pydata(verts, [], faces)
- me.update()
- #select the recently created object and make it the active object
- for ob in bpy.context.scene.objects:
- if ob.type == 'MESH' and nameo in ob.name:
- ob.select = True
- bpy.context.scene.objects.active = ob
- else:
- ob.select = False
- bpy.ops.object.mode_set(mode = 'OBJECT')
- #create 2 shape keys, the basis, and the shape key that we will alter
- obj = bpy.context.object
- Basis = obj.shape_key_add(from_mix=False)
- Basis.name = "Basis"
- shapeKey1 = obj.shape_key_add(from_mix=False)
- shapeKey1.name = "ShapeKey1"
- #set the current frame to 0 and set the keyframe at a value of 0 at frame = 0
- bpy.context.scene.frame_set(0)
- shapeKey1.value = 0.0
- shapeKey1.keyframe_insert("value",frame=0)
- #negate each vertex's value
- vertices = obj.data.vertices
- for vert in vertices:
- vert.co.z = -vert.co.z
- #set a keyframe for the shapekey at a value of 1 at frame 100
- shapeKey1.value = 1.0
- shapeKey1.keyframe_insert("value",frame=100)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement