0

I've successfully created a plane mesh in Blender by first specifying the coordinates of the four vertices in a .obj file and then importing this file into Blender.

Is directly adding a plane using vertex coordinates via Python possible?

Python function bpy.ops.mesh.primitive_plane_add allows users to add a plane, but it takes in radius, location, rotation, etc. instead. I don't see a quick and easy way of converting four vertex coordinates into these parameters.

Sibbs Gambling
  • 719
  • 2
  • 15
  • 30

1 Answers1

8

With this code you can set the vertex location manually:

import bpy

def create_custom_mesh(objname, px, py, pz):

# Define arrays for holding data    
myvertex = []
myfaces = []

# Create all Vertices

# vertex 0
mypoint = [(-1.0, -1.0, 0.0)]
myvertex.extend(mypoint)

# vertex 1
mypoint = [(1.0, -1.0, 0.0)]
myvertex.extend(mypoint)

# vertex 2
mypoint = [(-1.0, 1.0, 0.0)]
myvertex.extend(mypoint)

# vertex 3
mypoint = [(1.0, 1.0, 0.0)]
myvertex.extend(mypoint)

# -------------------------------------
# Create all Faces
# -------------------------------------
myface = [(0, 1, 3, 2)]
myfaces.extend(myface)


mymesh = bpy.data.meshes.new(objname)

myobject = bpy.data.objects.new(objname, mymesh)

bpy.context.scene.collection.objects.link(myobject)

# Generate mesh data
mymesh.from_pydata(myvertex, [], myfaces)
# Calculate the edges
mymesh.update(calc_edges=True)

# Set Location
myobject.location.x = px
myobject.location.y = py
myobject.location.z = pz

return myobject

curloc = bpy.context.scene.cursor.location

create_custom_mesh("Awesome_object", curloc[0], curloc[1], 0)

I hope this helps!

Roy Shmuli
  • 117
  • 5
float
  • 486
  • 2
  • 8