Moderators: Nexuiz Moderators, Moderators
#!BPY
"""
Name: 'z'
Blender: 244
Group: 'Export'
Tooltip: '-'
"""
import Blender
import bpy
import math
print
print "---------------------"
print
print
sce = bpy.data.scenes.active
ob = sce.objects.active
mesh = ob.getData(mesh=1)
matrix = ob.matrixWorld
faces = mesh.faces
netscale = 64
obloc = ob.getLocation()
obx = obloc[0]
oby = obloc[1]
obz = obloc[2]
for face in faces:
nor2 = face.no*matrix
x = nor2.x-obx
y = nor2.y-oby
z = nor2.z-obz
azi = math.degrees(math.atan2(y,x))
inc = math.degrees(math.acos(z/math.sqrt(x**2+y**2+z**2)))
print "face:", face.index,inc,azi,
if inc < 45:
## top projection
print "top"
print "----------"
elif inc > 135:
## bottom projection
print "bottom"
print "----------"
elif azi >= -45 and azi <= 45:
## front projection
print "front"
v1m = face.v[0].co*matrix
v2m = face.v[1].co*matrix
v1x = v1m.y*netscale
v1y = v1m.z*netscale
v2x = v2m.y*netscale
v2y = v2m.z*netscale
imgSx = face.image.size[0]
imgSy = face.image.size[1]
v1u = face.uv[0][0]*imgSx
v1v = face.uv[0][1]*imgSy
v2u = face.uv[1][0]*imgSx
v2v = face.uv[1][1]*imgSy
rota1 = math.atan2(v2y-v1y,v2x-v1x)
rota2 = math.atan2(v2v-v1v,v2u-v1u)
rota = math.degrees(rota1-rota2)
scar1 = abs(math.cos(math.atan2(z,x)))
scar2 = abs(math.cos(math.atan2(y,x)))
sca2cos = abs(math.cos(math.radians(rota)))
rsquax = sca2cos*scar2+math.sqrt(1-sca2cos**2)*scar1
rsquay = sca2cos*scar1+math.sqrt(1-sca2cos**2)*scar2
dAB = math.sqrt((v2x-v1x)**2+(v2y-v1y)**2)
duvAB = math.sqrt((rsquax*(v2u-v1u))**2+(rsquay*(v2v-v1v))**2)
sca = dAB/duvAB
scax = sca*rsquax
scay = sca*rsquay
ccos = math.cos(math.radians(-rota))
csin = math.sin(math.radians(-rota))
v1x2 = (ccos*v1x)-(csin*v1y)
v1y2 = (csin*v1x)+(ccos*v1y)
xpos = v1u-(v1x2/scax)
ypos = -v1v+(v1y2/scay)
print
print "h pos:", xpos
print "v pos:", ypos
print "h stretch:", scax
print "v stretch:", scay
print "rota:", rota
print "----------"
elif (azi > -135 and azi < -45):
## left projection
print "left"
print "----------"
elif azi >= 135 or azi <= -135:
## back projection
print "back"
print "----------"
else:
## right projection
print "right"
print "----------"
Users browsing this forum: No registered users and 1 guest