Dies ist eine alte Version des Dokuments!
import bpy import numpy as np from bpy_extras.mesh_utils import ngon_tessellate from random import randint
def generateObj(name, verts, faces, loc = np.array([0,0,0]), col = ( 1.0, 1.0, 1.0, 1.0 )):
mymesh = bpy.data.meshes.new(name) myobject = bpy.data.objects.new(name,mymesh) mymat = bpy.data.materials.new("Mesh_mat") mymat.diffuse_color = col mymesh.materials.append(mymat) myobject.location = loc #(0,0,0) #bpy.context.scene.cursor.location bpy.context.collection.objects.link(myobject)
mymesh.from_pydata(verts,[],faces) mymesh.update(calc_edges=True)
# six points on a rectangle #a = np.array([0.0, 0.0, 0.0]) #b = np.array([1.0, 0.0, 0.0]) #c = np.array([1.0, 1.0, 0.0]) #d = np.array([1.0, -1.0, 0.0]) #e = np.array([-1.0, -1.0, 0.0]) #f = np.array([-1.0, 0.0, 0.0])
def genMesh(pointList):
vertex = []
for i in range(0, len(pointList)): vertex.append(i)
faces = ngon_tessellate(pointList, vertex) print( faces ) # => [(4, 3, 0), (4, 0, 5)] # How can it loop over 6 vertices forming a convex shape with 2 triangles ?
print(faces,vertex) v = [vertex]
generateObj("whatever", pointList , v)
#v = [np.array([0,0,0]), np.array([1,0,0]), np.array([1,1,0]), np.array([0,1,0]), np.array([0,0,1]), np.array([1,0,1]), np.array([1,1,1]), np.array([0,1,1])] #print(v)
#v = [] #for i in range(0, randint(0,20)): # a = np.array([randint(-10,10), randint(-10,10), randint(-1,1)]) # print(a) # v.append(a)
v = [np.array([0,0,0]), np.array([0,5,0]), np.array([5,0,0]), np.array([5,7,0]), np.array([7,5,0])] genMesh(v)