Exemplo n.º 1
0
def transform4(matrix, shape):
    """
    Return a shape transformed by a Matrix4.
    """
    if matrix == None:
        matrix = pgl.Matrix4()
    scale, (a, e, r), translation = matrix.getTransformation2()

    if type(shape) is pgl.Cylinder and matrix != pgl.Matrix4():
        #print "scale for cylinder is :", scale
        #print "scale.xyz = ", scale.x, scale.y, scale.z
        if round(scale.x, 1) == 1.0 and round(scale.y, 1) == 1.0 and round(
                scale.z, 1) == 1.0:
            shape = pgl.Translated(translation,
                                   pgl.EulerRotated(a, e, r, shape))
        else:
            raise Exception, "Invalid transformation for cylinder!"

    elif type(shape) is pgl.Sphere:
        shape = pgl.Translated(
            translation, pgl.EulerRotated(a, e, r, pgl.Scaled(scale, shape)))
    elif type(shape) is pgl.BezierPatch:
        scale1 = pgl.Vector3(1, 1, 1)
        shape = pgl.Translated(
            translation,
            pgl.EulerRotated(a, e, r,
                             pgl.Scaled(scale, pgl.Scaled(scale1, shape))))
    else:
        shape = pgl.Translated(
            translation, pgl.EulerRotated(a, e, r, pgl.Scaled(scale, shape)))

    return shape
Exemplo n.º 2
0
 def _common_init( self, **keys ):
     """
     """
     if "height" in keys:
         self._height = keys[ "height" ]
     else:
         self._height = pgl.norm( keys[ "axis" ] )
     self._radius = keys[ "radius" ]
     
     self.shaft = pgl.Scaled(pgl.Vector3(1, 1, AARROW_SHAFT_PROPORTION), ACYLINDER_PRIMITIVE )
     self.head = pgl.Translated(pgl.Vector3(0, 0, AARROW_SHAFT_PROPORTION), pgl.Scaled(pgl.Vector3(
         AARROW_HEAD_PROPORTION,AARROW_HEAD_PROPORTION,1-AARROW_SHAFT_PROPORTION), ACONE_PRIMITIVE) )
Exemplo n.º 3
0
def leaf(**kwds):
    global __myLeaf
    if __myLeaf is None:
        __myLeaf = mangoLeaf(alpha=20)

    rp = rdm_pos((1, 1, 1))
    rx, ry, rz = rp.x, rp.y, rp.z
    az, el, rl = rdm_orientation()
    x = kwds.get('x', rx)
    y = kwds.get('y', ry)
    z = kwds.get('z', rz)
    delta = kwds.get('rotz', az)
    phi = kwds.get('roty', el)
    psi = kwds.get('rotx', rl)
    size = kwds.get('len', 10.0)
    color = kwds.get('color', __niceGreen)
    if not size:
        size = 10.0
        print "length is None, using 10 instead : small leaf"
    v = pgl.Vector3(x, y, z)
    #print "leaf size : ", size
    #sx = pgl.Vector3(4,1,1) * size/40.
    #scaled_geometry = pgl.Scaled(sx, pgl.Translated(pgl.Vector3(0.5,0,0), pgl.Disc(0.5, 6)) )
    sx = pgl.Vector3(1, 1, 1) * size / 10.

    scaled_geometry = pgl.Scaled(sx, __myLeaf.geometry)
    rotated_geometry = pgl.EulerRotated(delta, phi, psi, scaled_geometry)
    tr = pgl.Translated(v, rotated_geometry)
    return pgl.Shape(tr, color)
Exemplo n.º 4
0
def transform4(matrix, shape):
    """
    Return a shape transformed by a Matrix4.
    """
    scale, (a, e, r), translation = matrix.getTransformation2()
    shape = pgl.Translated(translation,
                           pgl.Scaled(scale, pgl.EulerRotated(a, e, r, shape)))
    return shape
def Unileaflet(length=1., width=1.):
    disc = pgl.Translated((-0.5,0,0), pgl.Disc())
    disc = pgl.Scaled((length, width,1), disc)
    disc = pgl.AxisRotated(axis=(0,1,0), angle=radians(90.), geometry=disc)

    d3 = pgl.AxisRotated(axis=(1,0,0), angle=0., geometry=disc)

    shape = pgl.Group([d3])
    return shape
Exemplo n.º 6
0
def leaflet(length=1., width=1.):
    """
    return 
    ------
    a strawberry leaf composed of three discs
    """
    disc = pgl.Translated((-0.5, 0, 0), pgl.Disc())
    disc = pgl.Scaled((length, width, 1), disc)
    disc = pgl.AxisRotated(axis=(0, 1, 0), angle=radians(90.), geometry=disc)

    d1 = pgl.AxisRotated(axis=(1, 0, 0), angle=-radians(60.), geometry=disc)
    d2 = pgl.AxisRotated(axis=(1, 0, 0), angle=-radians(-60.), geometry=disc)
    d3 = pgl.AxisRotated(axis=(1, 0, 0), angle=0., geometry=disc)

    shape = pgl.Group([d1, d2, d3])
    return shape
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 unileaflet(length=1., width=1.):
    """Generates a unileaflet shape

    :param length: length of the shape, defaults to 1.
    :type length: float, optional
    :param width: width of the shape, defaults to 1.
    :type width: float, optional
    :return: the shape
    :rtype: pgl.Group
    """  
    disc = pgl.Translated((-0.5,0,0), pgl.Disc())
    disc = pgl.Scaled((length, width,1), disc)
    disc = pgl.AxisRotated(axis=(0,1,0), angle=radians(90.), geometry=disc)

    d3 = pgl.AxisRotated(axis=(1,0,0), angle=0., geometry=disc)

    shape = pgl.Group([d3])
    return shape
Exemplo n.º 9
0
def leaflet(length=1., width=1.):
    """Generate a strawberry leaf

    :param length: length of the leaflet, defaults to 1.
    :type length: float, optional
    :param width: width of the leaflet, defaults to 1.
    :type width: float, optional
    :return: A strawberry leaf composed of three discs
    :rtype: pgl.Group
    """    
    disc = pgl.Translated((-0.5,0,0), pgl.Disc())
    disc = pgl.Scaled((length, width,1), disc)
    disc = pgl.AxisRotated(axis=(0,1,0), angle=radians(90.), geometry=disc)

    d1 = pgl.AxisRotated(axis=(1,0,0), angle=-radians(60.), geometry=disc)
    d2 = pgl.AxisRotated(axis=(1,0,0), angle=-radians(-60.), geometry=disc)
    d3 = pgl.AxisRotated(axis=(1,0,0), angle=0., geometry=disc)

    shape = pgl.Group([d1, d2, d3])
    return shape