Advertisement
Guest User

Untitled

a guest
May 25th, 2016
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. import bpy
  2. from bpy import context
  3. from math import sin, cos, radians
  4. import mathutils
  5. from mathutils import Vector
  6.  
  7. #set the name of the object
  8. nameo = "CustomLine"
  9.  
  10. #if the mesh already exists, delete it
  11. for ob in bpy.context.scene.objects:
  12. if ob.type == 'MESH' and nameo in ob.name:
  13. ob.select = True
  14. bpy.ops.object.delete()
  15. else:
  16. ob.select = False
  17.  
  18. #create a mesh where the x and z values of each vertex follow sine and cosine curves
  19. #and the y value simply increments forward on the y axis.
  20.  
  21. verts = []
  22. faces = []
  23.  
  24.  
  25. for i in range(360):
  26. z = 10*sin(radians(i))
  27. x = 10*cos(radians(i))
  28. y = i/10
  29. verts.append((x,y,z))
  30.  
  31. for i in range(359):
  32. faces.append((i,i+1))
  33.  
  34. verts = tuple(verts)
  35. faces = tuple(faces)
  36.  
  37. me = bpy.data.meshes.new("Mesh" + nameo)
  38. ob = bpy.data.objects.new(nameo, me)
  39. ob.location = Vector((0,0,0))
  40.  
  41. scn = bpy.context.scene
  42. scn.objects.link(ob)
  43. scn.objects.active = ob
  44. ob.select = True
  45.  
  46. me.from_pydata(verts, [], faces)
  47. me.update()
  48.  
  49. #select the recently created object and make it the active object
  50. for ob in bpy.context.scene.objects:
  51. if ob.type == 'MESH' and nameo in ob.name:
  52. ob.select = True
  53. bpy.context.scene.objects.active = ob
  54. else:
  55. ob.select = False
  56.  
  57. bpy.ops.object.mode_set(mode = 'OBJECT')
  58.  
  59. #create 2 shape keys, the basis, and the shape key that we will alter
  60. obj = bpy.context.object
  61.  
  62. Basis = obj.shape_key_add(from_mix=False)
  63. Basis.name = "Basis"
  64. shapeKey1 = obj.shape_key_add(from_mix=False)
  65. shapeKey1.name = "ShapeKey1"
  66.  
  67. #set the current frame to 0 and set the keyframe at a value of 0 at frame = 0
  68. bpy.context.scene.frame_set(0)
  69.  
  70. shapeKey1.value = 0.0
  71.  
  72. shapeKey1.keyframe_insert("value",frame=0)
  73.  
  74. #negate each vertex's value
  75. vertices = obj.data.vertices
  76.  
  77. for vert in vertices:
  78. vert.co.z = -vert.co.z
  79.  
  80. #set a keyframe for the shapekey at a value of 1 at frame 100
  81. shapeKey1.value = 1.0
  82.  
  83. shapeKey1.keyframe_insert("value",frame=100)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement