I am learning how to use blender with python script. I want to draw a block with ramp. until here, I can generate a block but my problem is precisely on how do the ramp. if you can help me please.
I know the point from which I must start the ramp coordinates(0, 4, 5) and (0, -4, 5). the angle is 60°
Here is the script(this script allows to draw a cube. if you help me to do a ramp with coordinates and angle known please):
import bpy, bmesh
from math import *
from mathutils import Vector
import numpy as np
def create_mesh(polygon):
coords = []
pos = 0
while pos < len(polygon) - 1 :
i = polygon[pos]
pos_suivant = pos + 1
if pos_suivant < len(polygon):
j = polygon[pos_suivant]
coords.append(i)
coords.append(j)
pos += 1
return coords
def draw(zTop, polygon):
"""this function receives 2 arguments :
* zTop of type Integr: it's the maximum height
* polygon of type list of tuple: it's coordinates of polygon
* this function allows to draw a cube
"""
coords = create_mesh(polygon)
bm = bmesh.new()
for v in coords:
bm.verts.new(v)
print(bm.verts)
#création de la base
base = bm.faces.new(bm.verts)
#processus d'extrusion
hauteur = bmesh.ops.extrude_face_region(bm, geom=[base])
#ajout d'auteur d'extrusion
bmesh.ops.translate(bm, vec=Vector((0,0,zTop)), verts=[v for v in hauteur["geom"] if isinstance(v,bmesh.types.BMVert)])
bm.normal_update()
me = bpy.data.meshes.new("Shape")
bm.to_mesh(me)
# ajouter à la scene
ob = bpy.data.objects.new("Shape",me)
bpy.context.collection.objects.link(ob)
coords = [(0,4, 0),(0,-4, 0), (4,-4, 0), (4,4, 0)]
draw(10, coords)

