import bpy
from random import random
#Define vertices and faces that form a plane
verts = [(0,0,0),(0,5,0),(5,5,0),(5,0,0)]
faces = [(0,1,2,3)]
#Define a mesh
mesh = bpy.data.meshes.new("Plane_mesh")
#Generate a mesh from vertex and face data
mesh.from_pydata(verts,[],faces)
mesh.update(calc_edges=True)
#Define an object from mesh data
obj = bpy.data.objects.new("Plane", mesh)
#Specify the location where the object is created with the cursor
obj.location = bpy.context.scene.cursor.location
#Link objects to the scene(display)Let
bpy.context.scene.collection.objects.link(obj)
frame_num = 0
#Setting the end frame of the animation
bpy.context.scene.frame_end = 20
for i in range(0,10):
#Select one vertex from the vertex list and decide on which axis of xyz to move
mesh.vertices[0].co[2] += 3
mesh.update(calc_edges=True)
#Insert the movement of the selected vertex into a keyframe with the selected axis and the number of frames
mesh.vertices[0].keyframe_insert('co',index = 2,frame = frame_num)
frame_num += 5
Point:co[] Determines which axis to coordinate the vertices with. -1 → xyz axis 0 → x axis 1 → y-axis 2 → z axis
import bpy
from random import random
bpy.ops.mesh.primitive_monkey_add()
obj = bpy.context.object
frame_num = 0
for f in range(0,100):
for v in obj.data.vertices:
m = random() * 0.02
#When the number of frames is even
if f%2:
#Randomly move in the z-axis direction
v.co.z += m
#other than that(Odd number of frames)in the case of
else:
#Randomly move in the z-axis direction
v.co.z -= m
v.keyframe_insert('co',index = 2,frame = frame_num)
frame_num += 1
import bpy
from random import random
#Define the vertices and faces that form the cube
verts = [(0,0,0),(0,5,0),(5,5,0),(5,0,0),(0,0,5),(0,5,5),(5,5,5),(5,0,5)]
faces = [(0,1,2,3), (4,5,6,7), (0,4,5,1), (1,5,6,2), (2,6,7,3), (3,7,4,0)]
#Define a mesh
mesh = bpy.data.meshes.new("Cube_mesh")
#Generate a mesh from vertex and face data
mesh.from_pydata(verts,[],faces)
mesh.update(calc_edges=True)
#Define an object from mesh data
obj = bpy.data.objects.new("Cube", mesh)
#Specify the location where the object is created with the cursor
obj.location = bpy.context.scene.cursor.location
#Link objects to the scene(display)Let
bpy.context.scene.collection.objects.link(obj)
frame_num = 0
for f in range(0,100):
for v in obj.data.vertices:
m = random()
if f%2:
v.co.x += m
v.co.y += m
else:
v.co.x -= m
v.co.y -= m
v.keyframe_insert('co',index = -1,frame = frame_num)
frame_num += 3
import bpy
import math
#Specify how many squares
p = 24
#Place the vertices starting from the center
verts = [(0,0,0)]
for i in range(0,p + 1):
x = 2 *math.pi / p * i
verts.append([math.cos(x),math.sin(x),0])
#A surface is formed by a total of 3 points, 2 points on the center and the circumference.
faces = []
for i in range(0,p):
faces.append([0,i + 1,i + 2])
mesh = bpy.data.meshes.new("Polygon_mesh")
mesh.from_pydata(verts, [], faces)
obj = bpy.data.objects.new("Polygon", mesh)
bpy.context.scene.collection.objects.link(obj)
#Put into edit mode
bpy.context.view_layer.objects.active = obj
bpy.ops.object.mode_set(mode='EDIT')
#Remove duplicate vertices
bpy.ops.mesh.remove_doubles()
#Return to object mode
bpy.ops.object.mode_set(mode='OBJECT')
frame_num = 0
bpy.context.scene.frame_end = 600
for f in range(0,600):
#Move the vertices except the center up and down
for i in range(1,p + 1):
mesh.vertices[i].co[2] += 5
mesh.update(calc_edges=True)
mesh.vertices[i].keyframe_insert('co',index = 2,frame = frame_num)
frame_num += 15
mesh.vertices[i].co[2] -= 5
mesh.update(calc_edges=True)
mesh.vertices[i].keyframe_insert('co',index = 2,frame = frame_num)
frame_num += 1
import bpy
import math
verts = []
faces = []
#Variables related to mesh
numX = 10
numY = 10
#Generate vertex coordinates
for i in range (0, numX):
for j in range(0,numY):
x = scale * i
y = scale * j
z = 0
vert = (x,y,z)
verts.append(vert)
#Generate a face from four vertices
count = 0
for i in range (0, numY *(numX-1)):
if count < numY-1:
A = i
B = i+1
C = (i+numY)+1
D = (i+numY)
face = (A,B,C,D)
faces.append(face)
count = count + 1
else:
count = 0
mesh = bpy.data.meshes.new("Wave_mesh")
mesh.from_pydata(verts,[],faces)
mesh.update(calc_edges=True)
obj = bpy.data.objects.new("Wave",mesh)
obj.location = (0,0,0)
bpy.context.scene.collection.objects.link(obj)
#Adapt subdivision surface
obj.modifiers.new("subd", type='SUBSURF')
obj.modifiers['subd'].levels = 3
#Adapt smooth shade
mypolys = mesh.polygons
for p in mypolys:
p.use_smooth = True
frame_num = 0
bpy.context.scene.frame_end = 300
for f in range(0,600):
for i in range(0,numX * numY):
mesh.vertices[i].co[2] += 5
mesh.update(calc_edges=True)
mesh.vertices[i].keyframe_insert('co',index = 2,frame = frame_num)
frame_num += 1
mesh.vertices[i].co[2] -= 5
mesh.update(calc_edges=True)
mesh.vertices[i].keyframe_insert('co',index = 2,frame = frame_num)
frame_num += 1
Recommended Posts