Пример #1
0
def DisplacementUVSphere(radius,
                         heightmap,
                         scale,
                         rings=5,
                         sectors=5,
                         inv_texture_u=False,
                         inv_texture_v=True):
    data = EggData()
    pool = EggVertexPool('pool')
    vertices = []
    data.addChild(pool)
    R = 1. / (rings)
    S = 1. / (sectors)
    for r in range(0, rings + 1):
        for s in range(0, sectors + 1):
            cos_s = cos(2 * pi * s * S + pi)
            sin_s = sin(2 * pi * s * S + pi)
            sin_r = sin(pi * r * R)
            cos_r = cos(pi * r * R)
            x = cos_s * sin_r
            y = sin_s * sin_r
            z = cos_r
            vertex = EggVertex()
            u = s * S
            v = r * R
            height = radius + heightmap.get_height_uv(u, v) * scale
            vertex.setPos(LPoint3d(x * height, y * height, z * height))
            if inv_texture_v:
                v = 1.0 - v
            if inv_texture_u:
                u = 1.0 - u
            vertex.setUv(LPoint2d(u, v))
            pool.addVertex(vertex)
            vertices.append(vertex)

    index = 0
    for r in range(0, rings):
        for s in range(0, sectors):
            poly = EggPolygon()
            data.addChild(poly)
            poly.addVertex(vertices[index + sectors + 1])
            poly.addVertex(vertices[index])
            poly.addVertex(vertices[index + sectors])

            poly = EggPolygon()
            data.addChild(poly)
            poly.addVertex(vertices[index + sectors + 1])
            poly.addVertex(vertices[index + 1])
            poly.addVertex(vertices[index])
            index += 1
    data.removeUnusedVertices(True)
    data.recomputeVertexNormals(45)
    data.recomputeTangentBinormal(GlobPattern(""))
    node = loadEggData(data)
    path = NodePath(node)
    path.flattenStrong()
    return path
Пример #2
0
 def __eggifyverts(self, eprim, evpool, vlist):
     for vertex in vlist:
         ixyz = vertex['v']
         vinfo = self.points[ixyz - 1]
         vxyz, _ = vinfo
         ev = EggVertex()
         ev.setPos(Point3D(vxyz[0], vxyz[1], vxyz[2]))
         iuv = vertex['vt']
         if iuv is not None:
             vuv = self.uvs[iuv - 1]
             ev.setUv(Point2D(vuv[0], vuv[1]))
         inormal = vertex['vn']
         if inormal is not None:
             vn = self.normals[inormal - 1]
             ev.setNormal(Vec3D(vn[0], vn[1], vn[2]))
         evpool.addVertex(ev)
         eprim.addVertex(ev)
     return self