コード例 #1
0
ファイル: Sphere.py プロジェクト: Biniou/pi3d
    def __init__(
        self,
        camera=None,
        light=None,
        radius=1,
        slices=12,
        sides=12,
        hemi=0.0,
        name="",
        x=0.0,
        y=0.0,
        z=0.0,
        rx=0.0,
        ry=0.0,
        rz=0.0,
        sx=1.0,
        sy=1.0,
        sz=1.0,
        cx=0.0,
        cy=0.0,
        cz=0.0,
        invert=False,
    ):
        """uses standard constructor for Shape extra Keyword arguments:

      *radius*
        radius of sphere
      *slices*
        number of latitude edges
      *hemi*
        if set to 0.5 it will only construct the top half of sphere
      *sides*
        number of sides for Shape._lathe() to use
      *invert*
        normals will face inwards, Texture will need flip=True
    """
        super(Sphere, self).__init__(camera, light, name, x, y, z, rx, ry, rz, sx, sy, sz, cx, cy, cz)

        if VERBOSE:
            print("Creating sphere ...")

        path = []
        # extra points added at poles to reduce distortion (mainly normals)
        st = ((math.pi - 0.002) * (1.0 - hemi)) / slices
        path.append((0.0, radius))
        for r in range(slices + 1):
            x, y = Utility.from_polar_rad(r * st + 0.001, radius)
            path.append((y, x))
        x, y = Utility.from_polar_rad(r * st + 0.002, radius)
        path.append((y, x))
        if invert:
            path.reverse()

        self.radius = radius
        self.slices = slices
        self.hemi = hemi
        self.ttype = GL_TRIANGLES

        self.buf = []
        self.buf.append(self._lathe(path, sides))
コード例 #2
0
ファイル: Sphere.py プロジェクト: wildone/pi3d
    def __init__(self,
                 camera=None,
                 light=None,
                 radius=1,
                 slices=12,
                 sides=12,
                 hemi=0.0,
                 name="",
                 x=0.0,
                 y=0.0,
                 z=0.0,
                 rx=0.0,
                 ry=0.0,
                 rz=0.0,
                 sx=1.0,
                 sy=1.0,
                 sz=1.0,
                 cx=0.0,
                 cy=0.0,
                 cz=0.0,
                 invert=False):
        """uses standard constructor for Shape extra Keyword arguments:

      *radius*
        radius of sphere
      *slices*
        number of latitude edges
      *hemi*
        if set to 0.5 it will only construct the top half of sphere
      *sides*
        number of sides for Shape._lathe() to use
      *invert*
        normals will face inwards, Texture will need flip=True
    """
        super(Sphere, self).__init__(camera, light, name, x, y, z, rx, ry, rz,
                                     sx, sy, sz, cx, cy, cz)

        if VERBOSE:
            print("Creating sphere ...")

        path = []
        #extra points added at poles to reduce distortion (mainly normals)
        st = ((math.pi - 0.002) * (1.0 - hemi)) / slices
        path.append((0.0, radius))
        for r in range(slices + 1):
            x, y = Utility.from_polar_rad(r * st + 0.001, radius)
            path.append((y, x))
        x, y = Utility.from_polar_rad(r * st + 0.002, radius)
        path.append((y, x))
        if invert:
            path.reverse()

        self.radius = radius
        self.slices = slices
        self.hemi = hemi
        self.ttype = GL_TRIANGLES

        self.buf = []
        self.buf.append(self._lathe(path, sides))
コード例 #3
0
ファイル: Disk.py プロジェクト: JamesR1/pi3d
  def __init__(self, radius=1, sides=12, name="", x=0.0, y=0.0, z=0.0,
               rx=0.0, ry=0.0, rz=0.0, sx=1.0, sy=1.0, sz=1.0,
               cx=0.0, cy=0.0, cz=0.0):
    super(Disk, self).__init__(name, x, y, z, rx, ry, rz, sx, sy, sz,
                               cx, cy, cz)

    if VERBOSE:
      print "Creating disk ..."

    self.verts = []
    self.norms = []
    self.inds = []
    self.texcoords = []
    self.ttype = GL_TRIANGLES
    self.sides = sides

    st = math.pi / slices
    self.add_vertex(x, y, z, 0, 1, 0, 0.5, 0.5)
    for r in range(sides+1):
      ca, sa = Utility.from_polar_rad(r * st)
      self.add_vertex(x + radius * sa, y, z + radius * ca,
                      0, 1, 0, sa * 0.5 + 0.5, ca * 0.5 + 0.5)
      # TODO: why the reversal?

    for r in range(sides):
      self.add_tri(0, r + 1, r + 2)

    self.vertices = c_floats(self.verts);
    self.indices = c_shorts(self.inds);
    self.normals = c_floats(self.norms);
    self.tex_coords = c_floats(self.texcoords);
    self.ssize = sides * 3
コード例 #4
0
ファイル: Sphere.py プロジェクト: JamesR1/pi3d
  def __init__(self, radius=1, slices=12, sides=12, hemi=0.0, name="",
               x=0.0, y=0.0, z=0.0, rx=0.0, ry=0.0, rz=0.0,
               sx=1.0, sy=1.0, sz=1.0, cx=0.0, cy=0.0, cz=0.0):
    super(Sphere,self).__init__(name, x, y, z, rx, ry, rz,
                                sx, sy, sz, cx, cy, cz)

    if VERBOSE:
      print "Creating sphere ..."

    path = []
    st = (math.pi * (1.0 - hemi)) / slices
    for r in range(slices + 1):
      x, y = Utility.from_polar_rad(r * st, radius)
      path.append((y, x))  # TODO: why is the reversal here?

    self.radius = radius
    self.slices = slices
    self.sides = sides
    self.hemi = hemi
    self.ttype = GL_TRIANGLES

    results = self.lathe(path)

    self.vertices = c_floats(results[0])
    self.normals = c_floats(results[1])
    self.indices = c_shorts(results[2])
    self.tex_coords = c_floats(results[3])
    self.ssize = results[4]
コード例 #5
0
ファイル: Torus.py プロジェクト: JamesR1/pi3d
  def __init__(self,radius=2.0, thickness=0.5, ringrots=6, sides=12, name="",
               x=0.0, y=0.0, z=0.0, rx=0.0, ry=0.0, rz=0.0,
               sx=1.0, sy=1.0, sz=1.0, cx=0.0, cy=0.0, cz=0.0):
    super(Torus,self).__init__(name, x, y, z, rx, ry, rz,
                               sx, sy, sz, cx, cy, cz)

    if VERBOSE:
      print "Creating Torus ..."

    path = []
    st = (math.pi * 2)/ringrots
    for r in range(ringrots + 1):
      x, y = Utility.from_polar_rad(r * st, thickness)
      path.append((radius + y, x))  # TODO: why the reversal?

    self.radius = radius
    self.thickness = thickness
    self.ringrots = ringrots
    self.sides = sides
    self.ttype = GL_TRIANGLES

    results = self.lathe(path)

    self.vertices = c_floats(results[0])
    self.normals = c_floats(results[1])
    self.indices = c_shorts(results[2])
    self.tex_coords = c_floats(results[3])
    self.ssize = results[4]
コード例 #6
0
ファイル: Sphere.py プロジェクト: Arexxk/pi3d
  def __init__(self, camera=None, light=None,
               radius=1, slices=12, sides=12, hemi=0.0, name="",
               x=0.0, y=0.0, z=0.0, rx=0.0, ry=0.0, rz=0.0,
               sx=1.0, sy=1.0, sz=1.0, cx=0.0, cy=0.0, cz=0.0):
    """uses standard constructor for Shape extra Keyword arguments:
    
      *radius*
        radius of sphere
      *slices*
        number of latitude edges
      *hemi*
        if set to 0.5 it will only construct the top half of sphere
      *sides*
        number of sides for Shape._lathe() to use
    """
    super(Sphere, self).__init__(camera, light, name, x, y, z, rx, ry, rz,
                                sx, sy, sz, cx, cy, cz)

    if VERBOSE:
      print "Creating sphere ..."

    path = []
    st = (math.pi * (1.0 - hemi)) / slices
    for r in range(slices + 1):
      x, y = Utility.from_polar_rad(r * st, radius)
      path.append((y, x))  # TODO: why is the reversal here?

    self.radius = radius
    self.slices = slices
    self.hemi = hemi
    self.ttype = GL_TRIANGLES

    self.buf = []
    self.buf.append(self._lathe(path, sides))
コード例 #7
0
ファイル: Torus.py プロジェクト: Arexxk/pi3d
  def __init__(self, camera=None, light=None, radius=2.0, thickness=0.5, ringrots=6, sides=12, name="",
               x=0.0, y=0.0, z=0.0, rx=0.0, ry=0.0, rz=0.0,
               sx=1.0, sy=1.0, sz=1.0, cx=0.0, cy=0.0, cz=0.0):
    """uses standard constructor for Shape extra Keyword arguments:
    
      *radius*
        Major radius of torus
      *thickness*
        Minor radius, section through one side of torus
      *ringrots*
        Sides around minor radius circle
      *sides* 
        Number of sides for Shape._lathe() to use
    """
    super(Torus,self).__init__(camera, light, name, x, y, z, rx, ry, rz,
                               sx, sy, sz, cx, cy, cz)

    if VERBOSE:
      print "Creating Torus ..."

    path = []
    st = (math.pi * 2)/ringrots
    for r in range(ringrots + 1):
      x, y = Utility.from_polar_rad(r * st, thickness)
      path.append((radius + y, x))  # TODO: why the reversal?

    self.radius = radius
    self.thickness = thickness
    self.ringrots = ringrots
    self.ttype = GL_TRIANGLES

    self.buf = []
    self.buf.append(self._lathe(path, sides))
コード例 #8
0
ファイル: Disk.py プロジェクト: wildone/pi3d
    def __init__(self,
                 camera=None,
                 light=None,
                 radius=1,
                 sides=12,
                 name="",
                 x=0.0,
                 y=0.0,
                 z=0.0,
                 rx=0.0,
                 ry=0.0,
                 rz=0.0,
                 sx=1.0,
                 sy=1.0,
                 sz=1.0,
                 cx=0.0,
                 cy=0.0,
                 cz=0.0):
        """uses standard constructor for Shape extra Keyword arguments:

      *radius*
        Radius of disk.
      *sides*
        Number of sides to polygon representing disk.
    """
        super(Disk, self).__init__(camera, light, name, x, y, z, rx, ry, rz,
                                   sx, sy, sz, cx, cy, cz)

        if VERBOSE:
            print("Creating disk ...")

        self.verts = []
        self.norms = []
        self.inds = []
        self.texcoords = []
        self.ttype = GL_TRIANGLES
        self.sides = sides

        st = 2 * pi / sides
        for j in range(-1, 1):
            self.verts.append((0.0, -0.1 * j, 0.0))
            self.norms.append((0.0, -j, 0.0))
            self.texcoords.append((0.5, 0.5))
            for r in range(sides + 1):
                ca, sa = Utility.from_polar_rad(r * st)
                self.verts.append((radius * sa, 0.0, radius * ca))
                self.norms.append((0.0, -j - 0.1 * j, 0.0))
                self.texcoords.append((sa * 0.5 + 0.5, ca * 0.5 + 0.5))
            if j == -1:
                v0, v1, v2 = 0, 1, 2
            else:
                v0, v1, v2 = sides + 2, sides + 4, sides + 3  # i.e. reverse direction to show on back
            for r in range(sides):
                self.inds.append((v0, r + v1, r + v2))

        self.but = []
        self.buf.append(
            Buffer(self, self.verts, self.texcoords, self.inds, self.norms))
コード例 #9
0
ファイル: Disk.py プロジェクト: Xatpy/echomesh
    def __init__(
        self,
        camera=None,
        light=None,
        radius=1,
        sides=12,
        name="",
        x=0.0,
        y=0.0,
        z=0.0,
        rx=0.0,
        ry=0.0,
        rz=0.0,
        sx=1.0,
        sy=1.0,
        sz=1.0,
        cx=0.0,
        cy=0.0,
        cz=0.0,
    ):
        """uses standard constructor for Shape extra Keyword arguments:
    
      *radius*
        Radius of disk.
      *sides*
        Number of sides to polygon representing disk.
    """
        super(Disk, self).__init__(camera, light, name, x, y, z, rx, ry, rz, sx, sy, sz, cx, cy, cz)

        if VERBOSE:
            print "Creating disk ..."

        self.verts = []
        self.norms = []
        self.inds = []
        self.texcoords = []
        self.ttype = GL_TRIANGLES
        self.sides = sides

        st = 2 * pi / sides
        for j in range(-1, 1):
            self._add_vertex((0.0, -0.1 * j, 0.0), (0.0, -j, 0.0), (0.5, 0.5))
            for r in range(sides + 1):
                ca, sa = Utility.from_polar_rad(r * st)
                self._add_vertex(
                    (radius * sa, 0.0, radius * ca), (0.0, -j - 0.1 * j, 0.0), (sa * 0.5 + 0.5, ca * 0.5 + 0.5)
                )
            if j == -1:
                v0, v1, v2 = 0, 1, 2
            else:
                v0, v1, v2 = sides + 2, sides + 4, sides + 3  # i.e. reverse direction to show on back
            for r in range(sides):
                self._add_tri((v0, r + v1, r + v2))

        self.but = []
        self.buf.append(Buffer(self, self.verts, self.texcoords, self.inds, self.norms))
コード例 #10
0
    def __init__(self,
                 camera=None,
                 light=None,
                 radius=1,
                 sides=12,
                 name="",
                 x=0.0,
                 y=0.0,
                 z=0.0,
                 rx=0.0,
                 ry=0.0,
                 rz=0.0,
                 sx=1.0,
                 sy=1.0,
                 sz=1.0,
                 cx=0.0,
                 cy=0.0,
                 cz=0.0):
        """uses standard constructor for Shape extra Keyword arguments:

      *radius*
        Radius of disk.
      *sides*
        Number of sides to polygon representing disk.
    """
        super(RoundCorner, self).__init__(camera, light, name, x, y, z, rx, ry,
                                          rz, sx, sy, sz, cx, cy, cz)

        verts = []
        norms = []
        inds = []
        texcoords = []
        self.sides = sides

        st = (pi / 2) / sides
        for j in range(-1, 1):
            verts.append((0.0, -0.1 * j, 0.0))
            norms.append((0.0, -j, 0.0))
            texcoords.append((0.5, 0.5))
            for r in range(0, sides + 1):
                ca, sa = Utility.from_polar_rad(r * st)
                verts.append((radius * sa, 0.0, radius * ca))
                norms.append((0.0, -j - 0.1 * j, 0.0))
                texcoords.append((sa * 0.5 + 0.5, ca * 0.5 + 0.5))
            if j == -1:
                v0, v1, v2 = 0, 1, 2
            else:
                v0, v1, v2 = sides + 2, sides + 4, sides + 3  # i.e. reverse direction to show on back
            for r in range(sides):
                inds.append((v0, r + v1, r + v2))

        self.buf = [Buffer(self, verts, texcoords, inds, norms)]
コード例 #11
0
    def __init__(self,
                 camera=None,
                 light=None,
                 radius=2.0,
                 thickness=0.5,
                 ringrots=6,
                 sides=12,
                 name="",
                 x=0.0,
                 y=0.0,
                 z=0.0,
                 rx=0.0,
                 ry=0.0,
                 rz=0.0,
                 sx=1.0,
                 sy=1.0,
                 sz=1.0,
                 cx=0.0,
                 cy=0.0,
                 cz=0.0):
        """uses standard constructor for Shape extra Keyword arguments:
    
      *radius*
        Major radius of torus
      *thickness*
        Minor radius, section through one side of torus
      *ringrots*
        Sides around minor radius circle
      *sides* 
        Number of sides for Shape._lathe() to use
    """
        super(Torus, self).__init__(camera, light, name, x, y, z, rx, ry, rz,
                                    sx, sy, sz, cx, cy, cz)

        if VERBOSE:
            print "Creating Torus ..."

        path = []
        st = (math.pi * 2) / ringrots
        for r in range(ringrots + 1):
            x, y = Utility.from_polar_rad(r * st, thickness)
            path.append((radius + y, x))  # TODO: why the reversal?

        self.radius = radius
        self.thickness = thickness
        self.ringrots = ringrots
        self.ttype = GL_TRIANGLES

        self.buf = []
        self.buf.append(self._lathe(path, sides))
コード例 #12
0
    def __init__(self,
                 camera=None,
                 light=None,
                 radius=1,
                 slices=12,
                 sides=12,
                 hemi=0.0,
                 name="",
                 x=0.0,
                 y=0.0,
                 z=0.0,
                 rx=0.0,
                 ry=0.0,
                 rz=0.0,
                 sx=1.0,
                 sy=1.0,
                 sz=1.0,
                 cx=0.0,
                 cy=0.0,
                 cz=0.0):
        """uses standard constructor for Shape extra Keyword arguments:
    
      *radius*
        radius of sphere
      *slices*
        number of latitude edges
      *hemi*
        if set to 0.5 it will only construct the top half of sphere
      *sides*
        number of sides for Shape._lathe() to use
    """
        super(Sphere, self).__init__(camera, light, name, x, y, z, rx, ry, rz,
                                     sx, sy, sz, cx, cy, cz)

        if VERBOSE:
            print "Creating sphere ..."

        path = []
        st = (math.pi * (1.0 - hemi)) / slices
        for r in range(slices + 1):
            x, y = Utility.from_polar_rad(r * st, radius)
            path.append((y, x))  # TODO: why is the reversal here?

        self.radius = radius
        self.slices = slices
        self.hemi = hemi
        self.ttype = GL_TRIANGLES

        self.buf = []
        self.buf.append(self._lathe(path, sides))
コード例 #13
0
ファイル: Disk.py プロジェクト: tipam/pi3d
  def __init__(self, camera=None, light=None, radius=1, sides=12, name="", x=0.0, y=0.0, z=0.0,
               rx=0.0, ry=0.0, rz=0.0, sx=1.0, sy=1.0, sz=1.0,
               cx=0.0, cy=0.0, cz=0.0):
    """uses standard constructor for Shape extra Keyword arguments:

      *radius*
        Radius of disk.
      *sides*
        Number of sides to polygon representing disk.
    """
    super(Disk, self).__init__(camera, light, name, x, y, z, rx, ry, rz, sx, sy, sz,
                               cx, cy, cz)

    LOGGER.info("Creating disk ...")

    verts = []
    norms = []
    inds = []
    texcoords = []
    self.sides = sides

    st = 2 * pi / sides
    for j in range(-1, 1):
      verts.append((0.0, -0.1*j, 0.0))
      norms.append((0.0, -j, 0.0))
      texcoords.append((0.5, 0.5))
      for r in range(sides+1):
        ca, sa = Utility.from_polar_rad(r * st)
        verts.append((radius * sa, 0.0, radius * ca))
        norms.append((0.0, -j - 0.1*j, 0.0))
        texcoords.append((sa * 0.5 + 0.5, ca * 0.5 + 0.5))
      if j == -1:
        v0, v1, v2 = 0, 1, 2
      else:
        v0, v1, v2 = sides + 2, sides + 4, sides + 3 # i.e. reverse direction to show on back
      for r in range(sides):
        inds.append((v0, r + v1, r + v2))

    self.buf = [Buffer(self, verts, texcoords, inds, norms)]
コード例 #14
0
ファイル: Shape.py プロジェクト: JamesR1/pi3d
  def lathe(self, path, rise=0.0, loops=1.0, tris=True):
    s = len(path)
    rl = int(self.sides * loops)
    if tris:
      ssize = rl * 6 * (s - 1)
    else:
      ssize = rl * 2 * (s - 1) + (s * 2) - 2

    pn = 0
    pp = 0
    tcx = 1.0 / self.sides
    pr = (math.pi / self.sides) * 2
    rdiv = rise / rl
    ss = 0

    # Find largest and smallest y of the path used for stretching the texture over
    p = [i[1] for i in path]
    miny = min(*p)
    maxy = max(*p)

    verts = []
    norms = []
    idx = []
    tex_coords = []

    opx = path[0][0]
    opy = path[0][1]

    for p in range(s):
      px = path[p][0]
      py = path[p][1]

      tcy = 1.0 - ((py - miny) / (maxy - miny))

      #normal between path points
      if p > 0:
        dx, dy = normalize_vector((path[p-1][0], path[p-1][1]), (px, py))
      else:
        dx, dy = normalize_vector((px, py), (path[p+1][0], path[p+1][1]))

      for r in range (0, rl):
        cosr, sinr = Utility.from_polar_rad(pr * r)
        # TODO: why the reversal?

        verts.extend([px * sinr, py, px * cosr])
        norms.extend([-sinr * dy, dx, -cosr * dy])
        tex_coords.extend([tcx * r, tcy])
        py += rdiv

      #last path profile (tidies texture coords)
      verts.extend([0, py, px])
      norms.extend([0, dx, -dy])
      tex_coords.extend([1.0, tcy])

      if p < s-1:
        if tris:
          # Create indices for GL_TRIANGLES
          pn += (rl + 1)
          for r in range(rl):
            idx.extend([pp + r + 1, pp + r,
                        pn + r, pn + r,
                        pn + r + 1, pp + r + 1])
            ss += 6
          pp += (rl + 1)
        else:
          #Create indices for GL_TRIANGLE_STRIP
          pn += (rl + 1)
          for r in range(rl):
            idx.extend([pp + r, pn + r])
            ss += 2
          idx.extend([pp + self.sides, pn + self.sides])
          ss += 2
          pp += (rl + 1)

      opx = px
      opy = py

    if VERBOSE:
      print ssize, ss

    return (verts, norms, idx, tex_coords, ssize)