import bpy
import math
# Define the parameters of the ovoid
a = 1.9
b = 1.5
c = 1.5
# Define the number of vertices in each direction
n_long = 32
n_lat = 16
# Create a new mesh
mesh = bpy.data.meshes.new(name="Ovoid")
# Create the vertices
verts = []
for j in range(n_lat):
lat = (j / (n_lat - 1)) * math.pi
for i in range(n_long):
lon = (i / (n_long - 1)) * 2 * math.pi
x = a * math.sin(lat) * math.cos(lon)
y = b * math.sin(lat) * math.sin(lon)
z = c * math.cos(lat)
verts.append((x, y, z))
# Create the faces
faces = []
for j in range(n_lat - 1):
for i in range(n_long - 1):
v1 = j * n_long + i
v2 = j * n_long + i + 1
v3 = (j + 1) * n_long + i + 1
v4 = (j + 1) * n_long + i
faces.append((v1, v2, v3, v4))
# Create the mesh and object
mesh.from_pydata(verts, [], faces)
obj = bpy.data.objects.new(name="Ovoid", object_data=mesh)
# Add the object to the scene
scene = bpy.context.scene
scene.collection.objects.link(obj)
Python tutorials with source code, examples, guides, and tips and tricks for Windows and Linux development.
Saturday, April 8, 2023
Create an ovoid with python on Blender 3D.
Blender 3D use python version 3.10.9 and you can write your scripts with the Blender 3D features.
This script can also be found on the website where I write tutorials.
This Python script for Blender 3D creates an ovoid model using the math formula for ovoid:
Posted by
Cătălin George Feștilă
Labels:
2023,
Blender 3D,
bpy,
module,
modules,
packages,
python,
python 3,
python modules,
python packages,
tutorial,
tutorials