當前位置: 首頁>>代碼示例>>Python>>正文


Python Utility.normalize_v3方法代碼示例

本文整理匯總了Python中pi3d.util.Utility.normalize_v3方法的典型用法代碼示例。如果您正苦於以下問題:Python Utility.normalize_v3方法的具體用法?Python Utility.normalize_v3怎麽用?Python Utility.normalize_v3使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pi3d.util.Utility的用法示例。


在下文中一共展示了Utility.normalize_v3方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: calc_normals

# 需要導入模塊: from pi3d.util import Utility [as 別名]
# 或者: from pi3d.util.Utility import normalize_v3 [as 別名]
 def calc_normals(self):
   normals = np.zeros((len(self.array_buffer), 3), dtype="float32") #empty array rights size
   fv = self.array_buffer[self.element_array_buffer,0:3] #expand faces with x,y,z values for each vertex
   #cross product of two edges of triangles
   fn = np.cross(fv[:,1] - fv[:,0], fv[:,2] - fv[:,0])
   fn = Utility.normalize_v3(fn)
   normals[self.element_array_buffer[:,0]] += fn #add up all normal vectors for a vertex
   normals[self.element_array_buffer[:,1]] += fn
   normals[self.element_array_buffer[:,2]] += fn
   return Utility.normalize_v3(normals)
開發者ID:agarmart,項目名稱:pi3d,代碼行數:12,代碼來源:Buffer.py

示例2: __init__

# 需要導入模塊: from pi3d.util import Utility [as 別名]
# 或者: from pi3d.util.Utility import normalize_v3 [as 別名]
  def __init__(self, shape, pts, texcoords, faces, normals=None, smooth=True):
    """Generate a vertex buffer to hold data and indices. If no normals
    are provided then these are generated.

    Arguments:
      *shape*
        Shape object that this Buffer is a child of
      *pts*
        array of vertices tuples i.e. [(x0,y0,z0), (x1,y1,z1),...]
      *texcoords*
        array of texture (uv) coordinates tuples
        i.e. [(u0,v0), (u1,v1),...]
      *faces*
        array of indices (of pts array) defining triangles
        i.e. [(a0,b0,c0), (a1,b1,c1),...]

    Keyword arguments:
      *normals*
        array of vector component tuples defining normals at each
        vertex i.e. [(x0,y0,z0), (x1,y1,z1),...]
      *smooth*
        if calculating normals then average normals for all faces
        meeting at this vertex, otherwise just use first (for speed).

    """
    super(Buffer, self).__init__()

    # Uniform variables all in one array!
    self.unib = (c_float * 12)(0.0, 0.0, 0.0,
                              0.5, 0.5, 0.5,
                              1.0, 1.0, 0.0,
                              0.0, 0.0, 0.0)
    """ pass to shader array of vec3 uniform variables:

    ===== ============================ ==== ==
    vec3        description            python
    ----- ---------------------------- -------
    index                              from to
    ===== ============================ ==== ==
        0  ntile, shiny, blend           0   2
        1  material                      3   5
        2  umult, vmult, point_size      6   8
        3  u_off, v_off (only 2 used)    9  10
    ===== ============================ ==== ==
    """
    #self.shape = shape
    self.textures = []
    pts = np.array(pts)
    texcoords = np.array(texcoords)
    faces = np.array(faces)

    if normals == None: #i.e. normals will only be generated if explictly None
      LOGGER.debug('Calculating normals ...')

      normals = np.zeros(pts.shape, dtype=pts.dtype) #empty array rights size

      fv = pts[faces] #expand faces with x,y,z values for each vertex
      #cross product of two edges of triangles
      fn = np.cross(fv[:][:][:,1] - fv[:][:][:,0], fv[:][:][:,2] - fv[:][:][:,0])
      fn = Utility.normalize_v3(fn)
      normals[faces[:,0]] += fn #add up all normal vectors for a vertex
      normals[faces[:,1]] += fn
      normals[faces[:,2]] += fn
      Utility.normalize_v3(normals)
    else:
      normals = np.array(normals)
      
    # keep a copy for speeding up the collision testing of ElevationMap
    self.vertices = pts
    self.normals = normals
    self.tex_coords = texcoords
    self.indices = faces
    self.material = (0.5, 0.5, 0.5, 1.0)

    # Pack points,normals and texcoords into tuples and convert to ctype floats.
    n_verts = len(pts)
    if len(texcoords) != n_verts:
      if len(normals) != n_verts:
        self.N_BYTES = 12 # only use pts
        self.array_buffer = c_floats(pts.reshape(-1).tolist())
      else:
        self.N_BYTES = 24 # use pts and normals
        self.array_buffer = c_floats(np.concatenate((pts, normals),
                            axis=1).reshape(-1).tolist())
    else:
      self.N_BYTES = 32 # use all three NB doesn't check that normals are there
      self.array_buffer = c_floats(np.concatenate((pts, normals, texcoords),
                          axis=1).reshape(-1).tolist())

    self.ntris = len(faces)
    self.element_array_buffer = c_shorts(faces.reshape(-1))
開發者ID:BirdAPI,項目名稱:pi3d,代碼行數:93,代碼來源:Buffer.py


注:本文中的pi3d.util.Utility.normalize_v3方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。