Exemplo n.º 1
0
def getProjectionMatrix(forward, up = pgl.Vector3(0,0,1)):
    forward.normalize()
    up.normalize();
    side = pgl.cross(up, forward);
    side.normalize();
    up = pgl.cross(forward, side);
    up.normalize();
    return pgl.Matrix3(side, up, forward).inverse()
Exemplo n.º 2
0
 def lookAt(self, eyePosition3D, center3D, upVector3D):
     forward = Vector3(center3D) - Vector3(eyePosition3D)
     forward.normalize()
     upVector3D = Vector3(upVector3D)
     upVector3D.normalize()
     side = cross(forward, upVector3D)
     side.normalize()
     up = cross(side, forward)
     up.normalize()
     m = Matrix4(side, up, forward, -eyePosition3D)
     self.worldToCamera = m.inverse()
     return m
Exemplo n.º 3
0
def project3Dto2D(p3list):
    v01 = Vector3((p3list[1][0] - p3list[0][0]), (p3list[1][1] - p3list[0][1]), (p3list[1][2] - p3list[0][2]))
    v12 = Vector3((p3list[2][0] - p3list[1][0]), (p3list[2][1] - p3list[1][1]), (p3list[2][2] - p3list[1][2]))
    vn = pgl.cross(v01, v12)

    p2s = []
    # cosTheta = A dot B/(|A|*|B|) => if A dot B ==0, then Theta == 90
    # if polygon not || y axis, project it to the y=0 plane
    if pgl.dot(vn, Vector3(0, 1, 0)) != 0:
        for i in range(len(p3list)):
            v = p3list[i][0], p3list[i][2]
            p2s.append(v)

    else:
        # if polygon || y axis and z axis (it will perpendicular x axis), project it to the x=0 plane
        # if polygon || y axis and x axis (it will perpendicular z axis), project it to the z=0 plane
        # if polygon || y axis, not || x and z (it will not perpendicular z and x
        # axis), project it to the z=0 plane (or x=0 plane)
        if pgl.dot(vn, Vector3(0, 0, 1)) == 0:
            for i in range(len(p3list)):
                v = p3list[i][1], p3list[i][2]
                p2s.append(v)

        else:
            for i in range(len(p3list)):
                v = p3list[i][0], p3list[i][1]
                p2s.append(v)
    return p2s
Exemplo n.º 4
0
def project3Dto2D(p3list):
    v01 = Vector3((p3list[1][0] - p3list[0][0]), (p3list[1][1] - p3list[0][1]),
                  (p3list[1][2] - p3list[0][2]))
    v12 = Vector3((p3list[2][0] - p3list[1][0]), (p3list[2][1] - p3list[1][1]),
                  (p3list[2][2] - p3list[1][2]))
    vn = pgl.cross(v01, v12)

    p2s = []
    # cosTheta = A dot B/(|A|*|B|) => if A dot B ==0, then Theta == 90
    # if polygon not || y axis, project it to the y=0 plane
    if pgl.dot(vn, Vector3(0, 1, 0)) != 0:
        for i in range(len(p3list)):
            v = p3list[i][0], p3list[i][2]
            p2s.append(v)

    else:
        # if polygon || y axis and z axis (it will perpendicular x axis), project it to the x=0 plane
        # if polygon || y axis and x axis (it will perpendicular z axis), project it to the z=0 plane
        # if polygon || y axis, not || x and z (it will not perpendicular z and x
        # axis), project it to the z=0 plane (or x=0 plane)
        if pgl.dot(vn, Vector3(0, 0, 1)) == 0:
            for i in range(len(p3list)):
                v = p3list[i][1], p3list[i][2]
                p2s.append(v)

        else:
            for i in range(len(p3list)):
                v = p3list[i][0], p3list[i][1]
                p2s.append(v)
    return p2s
Exemplo n.º 5
0
 def _set_axis(self, axis):
     """Property helper method.
     """
     if axis != self._axis:
         self._axis = axis
         rotation_axis = pgl.cross(pgl.Vector3.OZ, self._axis)
         rotation_angle = pgl.angle(self._axis, pgl.Vector3.OZ)
         self.rotated.axis = rotation_axis
         self.rotated.angle = rotation_angle
Exemplo n.º 6
0
 def _set_axis( self, axis ):
     """Property helper method.
     """
     if axis != self._axis:
         self._axis = axis
         rotation_axis = pgl.cross( pgl.Vector3.OZ, self._axis )
         rotation_angle = pgl.angle( self._axis, pgl.Vector3.OZ )
         self.rotated.axis = rotation_axis
         self.rotated.angle = rotation_angle
Exemplo n.º 7
0
    def __init__(self,
                 pos=ASHAPE3D_STANDARD_POS,
                 axis=ASHAPE3D_STANDARD_AXIS,
                 roll=ASHAPE3D_STANDARD_ROLL,
                 scale=ASHAPE3D_STANDARD_SCALE,
                 material=ASHAPE3D_STANDARD_MATERIAL,
                 geometry=None,
                 **keys):
        """Default constructor.
        
        Parameters:
            pos : Vector3 convertable
                pos of the object (look below),
            axis : Vector3 convertable
                main axis of the object, should be defined to describe the rotation. The Z of the primitive geometry
                would point to axis,
            roll : Real
                Property: rotation of the object around main axis,
            scale :  Vector3 convertable
                to use while resizing the object. While scaling the Z corresponds to main axis of the object,
            material : pgl.Material
                describes the appearance of the object,
            geometry : pgl.Geometry
                describes the geometry of the object.
        """
        if not geometry:
            raise Exception("AShape3D: geometry not defined.")
        self.geometry = geometry
        #TODO check for custom rotation, scale, transformation objects (shared between shapes)
        self.scaled = pgl.Scaled(scale, self.geometry)

        # roll related
        self._roll = roll  #: to keep internal roll
        self.rolled = pgl.AxisRotated(pgl.Vector3.OZ, self._roll, self.scaled)

        # axis related (even the object which do not have intuitive axis need to have predefined axis
        self._axis = axis  #: to keep internal axis vector
        rotation_axis = pgl.cross(pgl.Vector3.OZ, self._axis)
        rotation_angle = pgl.angle(self._axis, pgl.Vector3.OZ)
        self.rotated = pgl.AxisRotated(rotation_axis, rotation_angle,
                                       self.rolled)

        # position related
        self.translated = pgl.Translated(pos, self.rotated)

        # apperance related
        self.shape = pgl.Shape(self.translated, material)
Exemplo n.º 8
0
    def __init__( self, pos=ASHAPE3D_STANDARD_POS,  axis=ASHAPE3D_STANDARD_AXIS, roll=ASHAPE3D_STANDARD_ROLL,
                 scale=ASHAPE3D_STANDARD_SCALE, material=ASHAPE3D_STANDARD_MATERIAL, geometry=None, **keys ):
        """Default constructor.
        
        Parameters:
            pos : Vector3 convertable
                pos of the object (look below),
            axis : Vector3 convertable
                main axis of the object, should be defined to describe the rotation. The Z of the primitive geometry
                would point to axis,
            roll : Real
                Property: rotation of the object around main axis,
            scale :  Vector3 convertable
                to use while resizing the object. While scaling the Z corresponds to main axis of the object,
            material : pgl.Material
                describes the appearance of the object,
            geometry : pgl.Geometry
                describes the geometry of the object.
        """
        if not geometry:
            raise Exception( "AShape3D: geometry not defined." )
        self.geometry = geometry
        #TODO check for custom rotation, scale, transformation objects (shared between shapes)
        self.scaled = pgl.Scaled( scale, self.geometry )

        # roll related        
        self._roll = roll #: to keep internal roll
        self.rolled = pgl.AxisRotated(pgl.Vector3.OZ, self._roll, self.scaled)

        # axis related (even the object which do not have intuitive axis need to have predefined axis
        self._axis = axis #: to keep internal axis vector
        rotation_axis = pgl.cross( pgl.Vector3.OZ, self._axis )
        rotation_angle = pgl.angle( self._axis, pgl.Vector3.OZ )
        self.rotated = pgl.AxisRotated( rotation_axis, rotation_angle, self.rolled )
        
        # position related
        self.translated = pgl.Translated( pos, self.rotated )
        
        # apperance related
        self.shape = pgl.Shape( self.translated, material )
Exemplo n.º 9
0
 def _normal(ind, pts):
     A, B, C = [pts[i] for i in ind]
     n = pgl.cross(B - A, C - A)
     return n.normed()
Exemplo n.º 10
0
 def _surf(ind, pts):
     A, B, C = [pts[i] for i in ind]
     return pgl.norm(pgl.cross(B - A, C - A)) / 2.0
Exemplo n.º 11
0
 def _normal(ind,pts):
     A,B,C = [pts[i] for i in ind]
     n = pgl.cross(B-A, C-A)
     return n.normed()
Exemplo n.º 12
0
 def _surf(ind,pts):
     A,B,C = [pts[i] for i in ind]
     return pgl.norm(pgl.cross(B-A, C-A)) / 2.0
Exemplo n.º 13
0
 def _normal(mesh, iface):
     A, B, C = [mesh.pointList[i] for i in mesh.indexAt(iface)]
     n = pgl.cross(B - A, C - A)
     return n.normed()
Exemplo n.º 14
0
 def _surf(mesh, iface):
     A, B, C = [mesh.pointList[i] for i in mesh.indexAt(iface)]
     return pgl.norm(pgl.cross(B - A, C - A)) / 2.0
Exemplo n.º 15
0
 def _surf(ind, pts):
     from openalea.plantgl.all import norm, cross, Vector3
     A, B, C = [Vector3(pts[i]) for i in ind]
     return norm(cross(B - A, C - A)) / 2.0