Blender script python per un esportatore frullatore primitiva
Domanda
Sto cercando di scrivere un export molto di base al frullatore (da forme primitive) script. Devo disegnare cilindri, a vari angoli e posizioni. Ho informazioni di posizione disassata e dimensioni.
import bpy
import bgl
from mathutils import *
from math import *
material = bpy.data.materials.new('red')
material.diffuse_color = (1.0,0.0,0.0)
def draw_cylinder(name,material,radius,depth,location,rotation,offsetPosition,offsetAngle):
bgl.glRotatef(*offsetAngle[:4])
bgl.glTranslatef(*offsetPosition[:3])
bpy.ops.mesh.primitive_cylinder_add(radius=radius, depth=depth, location=location, rotation=rotation)
Cylinder = bpy.context.active_object
Cylinder.name = name
Cylinder.active_material = material
bgl.glTranslatef(*[i*-1 for i in offsetPosition[:3]])
bgl.glRotatef(*[i*-1 for i in offsetAngle[:4]])
return Cylinder
cmpt = draw_cylinder('first',material,radius=1,depth=2,location=(-1,0,0),rotation=(pi/2,0,0),offsetPosition=(10,2,7),offsetAngle=(pi/2,0,1,0))
Questa non disegna il cilindro a (9,2,7) [né ruotato lungo l'asse y] Dove mi trovo terribilmente sbagliato? Come posso correggere questo. Molto apprezza il vostro aiuto.
EDIT: Utilizzando Blender versione 2.60 (python interattivo console 3.2.2) spettacoli uscita del cilindro, a (-1,0,0). Mi aspetto / bisogno di essere al (9,2,7) (posizione + offsetPosition)
Soluzione
Nella funzione draw_cylinder
, è necessario aggiungere i due vettori:
pos = (
location[0]+offsetPosition[0],
location[1]+offsetPosition[2],
location[1]+offsetPosition[2],
)
e quindi
bpy.ops.mesh.primitive_cylinder_add(radius=radius, depth=depth, location=pos, rotation=rotation)
[EDIT] Se avete bisogno di operazioni più complesse, hanno uno sguardo al mathutils libreria .