Kód:
#ZDENDOS COMPANY SCRIPT
#Autor: Zdenek Koukol
#Verze: 0.1 (02.03.2008)
import Blender
def prusecikDvouPrimek3D (rovina, Ax, Ay, Az, Bx, By, Bz, Cx, Cy, Cz, Dx, Dy, Dz):
"""Funkce zjisti prusecik dvou primek ve 3D prostoru podle jedne roviny (xy, yz, xz)."""
VAx = Bx - Ax
VAy = By - Ay
VAz = Bz - Az
VBx = Dx - Cx
VBy = Dy - Cy
VBz = Dz - Cz
if (rovina == 0): #rovina XY
if ((VBy * VAx - VBx * VAy) != 0):
Sxy = ((Cx - Ax) * VAy + (Ay - Cy) * VAx) / (VBy * VAx - VBx * VAy)
else:
Sxy = 0
if (VAx != 0):
Txy = ((Cx - Ax) + (Sxy * VBx)) / VAx
else:
Txy = 0;
XY_bodA_x = Ax + Txy * VAx
XY_bodA_y = Ay + Txy * VAy
XY_bodA_z = Az + Txy * VAz
XY_bodB_x = Cx + Sxy * VBx
XY_bodB_y = Cy + Sxy * VBy
XY_bodB_z = Cz + Sxy * VBz
return XY_bodA_x, XY_bodA_y, XY_bodA_z, XY_bodB_x, XY_bodB_y, XY_bodB_z
if (rovina == 1): #rovina YZ
if ((VBz * VAy - VBy * VAz) != 0):
Syz = ((Cy - Ay) * VAz + (Az - Cz) * VAy) / (VBz * VAy - VBy * VAz)
else:
Syz = 0
if (VAy != 0):
Tyz = ((Cy - Ay) + (Syz * VBy)) / VAy
else:
Tyz = 0
YZ_bodA_x = Ax + Tyz * VAx
YZ_bodA_y = Ay + Tyz * VAy
YZ_bodA_z = Az + Tyz * VAz
YZ_bodB_x = Cx + Syz * VBx
YZ_bodB_y = Cy + Syz * VBy
YZ_bodB_z = Cz + Syz * VBz
return YZ_bodA_x, YZ_bodA_y, YZ_bodA_z, YZ_bodB_x, YZ_bodB_y, YZ_bodB_z
if (rovina == 2): #rovina XZ
if ((VBz * VAx - VBx * VAz) != 0):
Sxz = ((Cx - Ax) * VAz + (Az - Cz) * VAx) / (VBz * VAx - VBx * VAz)
else:
Sxz = 0
if (VAx != 0):
Txz = ((Cx - Ax) + (Sxz * VBx)) / VAx
else:
Txz = 0
XZ_bodA_x = Ax + Txz * VAx
XZ_bodA_y = Ay + Txz * VAy
XZ_bodA_z = Az + Txz * VAz
XZ_bodB_x = Cx + Sxz * VBx
XZ_bodB_y = Cy + Sxz * VBy
XZ_bodB_z = Cz + Sxz * VBz
return XZ_bodA_x, XZ_bodA_y, XZ_bodA_z, XZ_bodB_x, XZ_bodB_y, XZ_bodB_z
def stredUsecky3D (Ax, Ay, Az, Bx, By, Bz):
"""Funkce vrati stred usecky."""
return ((Ax + Bx) / 2.0), ((Ay + By) / 2.0), ((Az + Bz) / 2.0)
if Blender.Get("version") == 245:
scn = Blender.Scene.GetCurrent()
obj = scn.getActiveObject()
if (obj.getType() == "Mesh"):
editMode = Blender.Window.EditMode()
if (editMode): Blender.Window.EditMode(0)
muj_mesh = obj.getData()
vybrane_usecky = []
for usecka in (muj_mesh.edges):
if (usecka.flag & 0x01): vybrane_usecky.append(usecka)
if (len (vybrane_usecky) == 2):
Ax, Ay, Az = (vybrane_usecky[0].v1.co)
Bx, By, Bz = (vybrane_usecky[0].v2.co)
Cx, Cy, Cz = (vybrane_usecky[1].v1.co)
Dx, Dy, Dz = (vybrane_usecky[1].v2.co)
x1, y1, z1, x2, y2, z2 = prusecikDvouPrimek3D (0, Ax, Ay, Az, Bx, By, Bz, Cx, Cy, Cz, Dx, Dy, Dz)
xA, yA, zA = stredUsecky3D(x1, y1, z1, x2, y2, z2)
x1, y1, z1, x2, y2, z2 = prusecikDvouPrimek3D (1, Ax, Ay, Az, Bx, By, Bz, Cx, Cy, Cz, Dx, Dy, Dz)
xB, yB, zB = stredUsecky3D(x1, y1, z1, x2, y2, z2)
x1, y1, z1, x2, y2, z2 = prusecikDvouPrimek3D (2, Ax, Ay, Az, Bx, By, Bz, Cx, Cy, Cz, Dx, Dy, Dz)
xC, yC, zC = stredUsecky3D(x1, y1, z1, x2, y2, z2)
muj_mesh.verts.extend([Blender.NMesh.Vert(xA, yA, zA)])
muj_mesh.verts.extend([Blender.NMesh.Vert(xB, yB, zB)])
muj_mesh.verts.extend([Blender.NMesh.Vert(xC, yC, zC)])
print zA, zB, zC
print xA, xB, xC
print yA, yB, yC
muj_mesh.update()
else:
print "Vyberte pouze 2 usecky!"
if (editMode): Blender.Window.EditMode(1)
else:
print "Vyberte objekt typu MESH!"
else:
print "Testovano na verzi 2.45!"