def __updatePrism(self, mesh, o, e, index, p): dir = aljabr.vsub(e, o) # direction vector from o to e len = aljabr.vlen(dir) # distance from o to e scale = 0.5 # the thickness is 10% of the length i = aljabr.vadd(o, aljabr.vmul(dir, 0.25)) # the thickest part is 25% from o n = aljabr.vmul(dir, 1.0 / len) # the normalized direction q = aljabr.axisAngleToQuaternion(n, pi / 2.0) # a quaternion to rotate the point p1 to obtain the other points p1 = p # a random point in the plane defined by 0,0,0 and n p1 = aljabr.vmul(aljabr.vnorm(p1), scale) # the point scaled to the thickness p2 = aljabr.quaternionVectorTransform(q, p1) # the other points p3 = aljabr.quaternionVectorTransform(q, p2) p4 = aljabr.quaternionVectorTransform(q, p3) p1 = aljabr.vadd(i, p1) # translate by i since we were working in the origin p2 = aljabr.vadd(i, p2) p3 = aljabr.vadd(i, p3) p4 = aljabr.vadd(i, p4) # The 6 vertices mesh.verts[index].co = o mesh.verts[index+1].co = p1 mesh.verts[index+2].co = p2 mesh.verts[index+3].co = p3 mesh.verts[index+4].co = p4 mesh.verts[index+5].co = e
def updatePrism(mesh, o, e, index, p): dir = aljabr.vsub(e, o) # direction vector from o to e if dir == [0.0, 0.0, 0.0]: dir = [0.0, 1.0, 0.0] len = aljabr.vlen(dir) # distance from o to e if len == 0: len = 1 scale = 0.5 # the thickness is 10% of the length i = aljabr.vadd(o, aljabr.vmul(dir, 0.25)) # the thickest part is 25% from o n = aljabr.vmul(dir, 1.0 / len) # the normalized direction q = aljabr.axisAngleToQuaternion( n, pi / 2.0) # a quaternion to rotate the point p1 to obtain the other points p1 = p # a random point in the plane defined by 0,0,0 and n p1 = aljabr.vmul(aljabr.vnorm(p1), scale) # the point scaled to the thickness p2 = aljabr.quaternionVectorTransform(q, p1) # the other points p3 = aljabr.quaternionVectorTransform(q, p2) p4 = aljabr.quaternionVectorTransform(q, p3) p1 = aljabr.vadd(i, p1) # translate by i since we were working in the origin p2 = aljabr.vadd(i, p2) p3 = aljabr.vadd(i, p3) p4 = aljabr.vadd(i, p4) # The 6 vertices mesh.verts[index].co = o mesh.verts[index + 1].co = p1 mesh.verts[index + 2].co = p2 mesh.verts[index + 3].co = p3 mesh.verts[index + 4].co = p4 mesh.verts[index + 5].co = e
def addPrism(mesh, o=[0.0, 0.0, 0.0], e=[0.0, 1.0, 0.0], name='prism'): fg = mesh.createFaceGroup(name) dir = aljabr.vsub(e, o) # direction vector from o to e if dir == [0.0, 0.0, 0.0]: dir = [0.0, 1.0, 0.0] len = aljabr.vlen(dir) # distance from o to e if len == 0: len = 1 scale = 0.5 # the thickness is 10% of the length i = aljabr.vadd(o, aljabr.vmul(dir, 0.25)) # the thickest part is 25% from o n = aljabr.vmul(dir, 1.0 / len) # the normalized direction q = aljabr.axisAngleToQuaternion( n, pi / 2.0) # a quaternion to rotate the point p1 to obtain the other points p = p1 = aljabr.randomPointFromNormal( n) # a random point in the plane defined by 0,0,0 and n p1 = aljabr.vmul(aljabr.vnorm(p1), scale) # the point scaled to the thickness p2 = aljabr.quaternionVectorTransform(q, p1) # the other points p3 = aljabr.quaternionVectorTransform(q, p2) p4 = aljabr.quaternionVectorTransform(q, p3) p1 = aljabr.vadd(i, p1) # translate by i since we were working in the origin p2 = aljabr.vadd(i, p2) p3 = aljabr.vadd(i, p3) p4 = aljabr.vadd(i, p4) # The 6 vertices v = [] v.append(mesh.createVertex(o)) # 0 0 v.append(mesh.createVertex(p1)) # 1 /|\ v.append(mesh.createVertex(p2)) # 2 /.2.\ v.append(mesh.createVertex(p3)) # 3 1` | `3 v.append(mesh.createVertex(p4)) # 4 \`.4.`/ v.append(mesh.createVertex(e)) # 5 \ | / # \|/ # 5 # The 8 faces fg.createFace((v[0], v[1], v[4], v[0])) fg.createFace((v[0], v[4], v[3], v[0])) fg.createFace((v[0], v[3], v[2], v[0])) fg.createFace((v[0], v[2], v[1], v[0])) fg.createFace((v[5], v[4], v[1], v[5])) fg.createFace((v[5], v[1], v[2], v[5])) fg.createFace((v[5], v[2], v[3], v[5])) fg.createFace((v[5], v[3], v[4], v[5])) return p
def addPrism(mesh, o=[0.0, 0.0, 0.0], e=[0.0, 1.0, 0.0], name='prism'): fg = mesh.createFaceGroup(name) dir = aljabr.vsub(e, o) # direction vector from o to e if dir == [0.0, 0.0, 0.0]: dir = [0.0, 1.0, 0.0] len = aljabr.vlen(dir) # distance from o to e if len == 0: len = 1 scale = 0.5 # the thickness is 10% of the length i = aljabr.vadd(o, aljabr.vmul(dir, 0.25)) # the thickest part is 25% from o n = aljabr.vmul(dir, 1.0 / len) # the normalized direction q = aljabr.axisAngleToQuaternion(n, pi / 2.0) # a quaternion to rotate the point p1 to obtain the other points p = p1 = aljabr.randomPointFromNormal(n) # a random point in the plane defined by 0,0,0 and n p1 = aljabr.vmul(aljabr.vnorm(p1), scale) # the point scaled to the thickness p2 = aljabr.quaternionVectorTransform(q, p1) # the other points p3 = aljabr.quaternionVectorTransform(q, p2) p4 = aljabr.quaternionVectorTransform(q, p3) p1 = aljabr.vadd(i, p1) # translate by i since we were working in the origin p2 = aljabr.vadd(i, p2) p3 = aljabr.vadd(i, p3) p4 = aljabr.vadd(i, p4) # The 6 vertices v = [] v.append(mesh.createVertex(o)) # 0 0 v.append(mesh.createVertex(p1)) # 1 /|\ v.append(mesh.createVertex(p2)) # 2 /.2.\ v.append(mesh.createVertex(p3)) # 3 1` | `3 v.append(mesh.createVertex(p4)) # 4 \`.4.`/ v.append(mesh.createVertex(e)) # 5 \ | / # \|/ # 5 # The 8 faces fg.createFace((v[0], v[1], v[4], v[0])) fg.createFace((v[0], v[4], v[3], v[0])) fg.createFace((v[0], v[3], v[2], v[0])) fg.createFace((v[0], v[2], v[1], v[0])) fg.createFace((v[5], v[4], v[1], v[5])) fg.createFace((v[5], v[1], v[2], v[5])) fg.createFace((v[5], v[2], v[3], v[5])) fg.createFace((v[5], v[3], v[4], v[5])) return p