1
$\begingroup$

I am trying to create a script that assigns a differente rotation to polys according to their normals but I can´t figure out how to do it. This is my script so far.

import math
import mathutils


mirando_arriba = mathutils.Vector((0.0000,0.0000,1.0000))
mirando_derecha = mathutils.Vector((0.0000,1.0000,0.0000))
mirando_izquierda = mathutils.Vector((-0.0000,-1.0000,-0.0000))
mirando_abajo = mathutils.Vector((0.0000,0.0000,-1.0000))
mirando_fondo = mathutils.Vector((1.0000,0.0000,0.0000))
mirando_trasera = mathutils.Vector((-1.0000,0.0000,-0.0000))
if (Normal == mirando_arriba):
    result = rotateY
    TextBlock = "Mira hacia arriba"
elif (Normal ==  mirando_derecha):
    result = rotateX
    TextBlock = "Mira hacia derecha"
elif (Normal ==  mirando_abajo):
    result = rotateX
    TextBlock = "Mira hacia abajo"   
elif (Normal ==  mirando_fondo):
    result = rotateX     
    TextBlock = "Mira hacia fondo" 
elif (Normal ==  mirando_izquierda):
    result = rotateX     
    TextBlock = "Mira hacia izquierda" 
elif (Normal ==  mirando_trasera):
    result = rotateY     
    TextBlock = "Mira hacia trasera"     
else:
    result = rotateY
    TextBlock = "No mira"
$\endgroup$
2
  • $\begingroup$ By polys do you mean faces? Or mesh objects? $\endgroup$
    – TLousky
    Commented Dec 31, 2015 at 12:07
  • $\begingroup$ Yes I mean faces $\endgroup$ Commented Jan 2, 2016 at 11:30

1 Answer 1

3
$\begingroup$

The only issue I see here is comparing vectors that are float vectors and that can give false negatives.

For vector comparison it's better to use "distance", rather than "==". (Also, in blender precision appears to go up to 6, so use at most < 0.00001)

For more see: https://github.com/JacquesLucke/animation_nodes/issues/327


However, that means in your code:

if (Normal - mirando_arriba).length_squared < 0.0001:
    result = rotateY
    TextBlock = "Mira hacia arriba"

and same for the rest.

$\endgroup$
1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .