当前位置: 首页>>代码示例>>Python>>正文


Python GeomTriangles.add_vertex方法代码示例

本文整理汇总了Python中panda3d.core.GeomTriangles.add_vertex方法的典型用法代码示例。如果您正苦于以下问题:Python GeomTriangles.add_vertex方法的具体用法?Python GeomTriangles.add_vertex怎么用?Python GeomTriangles.add_vertex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在panda3d.core.GeomTriangles的用法示例。


在下文中一共展示了GeomTriangles.add_vertex方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create_model

# 需要导入模块: from panda3d.core import GeomTriangles [as 别名]
# 或者: from panda3d.core.GeomTriangles import add_vertex [as 别名]
 def create_model(self):
     # Set up the vertex arrays
     vformat = GeomVertexFormat.get_v3c4()
     vdata = GeomVertexData("Data", vformat, Geom.UHStatic)
     vertex = GeomVertexWriter(vdata, 'vertex')
     color = GeomVertexWriter(vdata, 'color')
     geom = Geom(vdata)
     # Vertex data
     vertex.addData3f(1.5, 0, -1)
     color.addData4f(1, 0, 0, 1)
     vertex.addData3f(-1.5, 0, -1)
     color.addData4f(0, 1, 0, 1)
     vertex.addData3f(0, 0, 1)
     color.addData4f(0, 0, 1, 1)
     # Primitive
     tri = GeomTriangles(Geom.UHStatic)
     tri.add_vertex(2)
     tri.add_vertex(1)
     tri.add_vertex(0)
     tri.close_primitive()
     geom.addPrimitive(tri)
     # Create the actual node
     node = GeomNode('geom_node')
     node.addGeom(geom)
     np = NodePath(node)
     # Shader and initial shader vars
     np.set_shader(Shader.load(Shader.SL_GLSL, "shader/shader.vert", "shader/shader.frag"))
     np.set_shader_input("time", 0.0)
     # No instancing necessary
     #np.set_instance_count(27)
     # return np
     np.reparent_to(base.render)
     self.model = np
开发者ID:TheCheapestPixels,项目名称:panda_examples,代码行数:35,代码来源:shader.py

示例2: GeomBuilder

# 需要导入模块: from panda3d.core import GeomTriangles [as 别名]
# 或者: from panda3d.core.GeomTriangles import add_vertex [as 别名]
class GeomBuilder(object):

    def __init__(self, name='tris'):
        self.name = name
        self.vdata = GeomVertexData(name, GeomVertexFormat.get_v3n3cpt2(), Geom.UHDynamic)
        self.writer = VertexDataWriter(self.vdata)
        self.tris = GeomTriangles(Geom.UHDynamic)

    def _commit_polygon(self, poly, color):
        """
        Transmutes colors and vertices for tris and quads into visible geometry.
        """
        point_id = self.writer.count
        for p in poly.points:
            self.writer.add_vertex(p, poly.get_normal(), color, (0.0, 1.0))
        if len(poly.points) == 3:
            self.tris.add_consecutive_vertices(point_id, 3)
            self.tris.close_primitive()
        elif len(poly.points) == 4:
            self.tris.add_vertex(point_id)
            self.tris.add_vertex(point_id + 1)
            self.tris.add_vertex(point_id + 3)
            self.tris.close_primitive()
            self.tris.add_consecutive_vertices(point_id + 1, 3)
            self.tris.close_primitive()
        else:
            raise InvalidPrimitive

    def add_tri(self, color, points):
        self._commit_polygon(Polygon(points), color)
        self._commit_polygon(Polygon(points[::-1]), color)
        return self

    def add_rect(self, color, x1, y1, z1, x2, y2, z2):
        p1 = Point3(x1, y1, z1)
        p3 = Point3(x2, y2, z2)

        # Make sure we draw the rect in the right plane.
        if x1 != x2:
            p2 = Point3(x2, y1, z1)
            p4 = Point3(x1, y2, z2)
        else:
            p2 = Point3(x2, y2, z1)
            p4 = Point3(x1, y1, z2)

        self._commit_polygon(Polygon([p1, p2, p3, p4]), color)

        return self

    def add_block(self, color, center, size, rot=None):
        x_shift = size[0] / 2.0
        y_shift = size[1] / 2.0
        z_shift = size[2] / 2.0
        rot = LRotationf(0, 0, 0) if rot is None else rot

        vertices = (
            Point3(-x_shift, +y_shift, +z_shift),
            Point3(-x_shift, -y_shift, +z_shift),
            Point3(+x_shift, -y_shift, +z_shift),
            Point3(+x_shift, +y_shift, +z_shift),
            Point3(+x_shift, +y_shift, -z_shift),
            Point3(+x_shift, -y_shift, -z_shift),
            Point3(-x_shift, -y_shift, -z_shift),
            Point3(-x_shift, +y_shift, -z_shift),
        )
        vertices = [rot.xform(v) + LVector3f(*center) for v in vertices]

        faces = (
            # XY
            [vertices[0], vertices[1], vertices[2], vertices[3]],
            [vertices[4], vertices[5], vertices[6], vertices[7]],
            # XZ
            [vertices[0], vertices[3], vertices[4], vertices[7]],
            [vertices[6], vertices[5], vertices[2], vertices[1]],
            # YZ
            [vertices[5], vertices[4], vertices[3], vertices[2]],
            [vertices[7], vertices[6], vertices[1], vertices[0]],
        )

        if size[0] and size[1]:
            self._commit_polygon(Polygon(faces[0]), color)
            self._commit_polygon(Polygon(faces[1]), color)
        if size[0] and size[2]:
            self._commit_polygon(Polygon(faces[2]), color)
            self._commit_polygon(Polygon(faces[3]), color)
        if size[1] and size[2]:
            self._commit_polygon(Polygon(faces[4]), color)
            self._commit_polygon(Polygon(faces[5]), color)

        return self

    def add_ramp(self, color, base, top, width, thickness, rot=None):
        midpoint = Point3((top + base) / 2.0)
        rot = LRotationf(0, 0, 0) if rot is None else rot

        # Temporarily move `base` and `top` to positions relative to a midpoint
        # at (0, 0, 0).
        if midpoint != Point3(0, 0, 0):
            base = Point3(base - (midpoint - Point3(0, 0, 0)))
            top = Point3(top - (midpoint - Point3(0, 0, 0)))
#.........这里部分代码省略.........
开发者ID:dcwatson,项目名称:pavara,代码行数:103,代码来源:geom.py


注:本文中的panda3d.core.GeomTriangles.add_vertex方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。