How to use the panda3d.core.Geom function in Panda3D

To help you get started, we’ve selected a few Panda3D examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gamingrobot / second-sunrise / game / plugins / Core / meshgeneration / meshgeneration.py View on Github external
elif self.meshgentype == "dual":
            mesher = DualContour()
        else:
            mesher = Voxel()

        triangles = mesher.generateMesh(terrain, size, lod)

        #format = GeomVertexFormat.registerFormat(GeomVertexFormat.getV3n3c4t2())
        format = GeomVertexFormat.registerFormat(GeomVertexFormat.getV3n3c4())
        vdata = GeomVertexData('chunk_mesh', format, Geom.UHStatic)

        vertex = GeomVertexWriter(vdata, 'vertex')
        normal = GeomVertexWriter(vdata, 'normal')
        color = GeomVertexWriter(vdata, 'color')
        texcoord = GeomVertexWriter(vdata, 'texcoord')
        prim = GeomTriangles(Geom.UHStatic)

        vertexcount = 0
        for triangle in triangles:
            for avertex in triangle:
                #print triangle
                #make vertices here
                shade = 0.5
                vertex.addData3f(avertex[0], avertex[1], avertex[2])
                #fix normals
                x1, y1, z1 = triangle[0][0], triangle[0][1], triangle[0][2]
                x2, y2, z2 = triangle[1][0], triangle[1][1], triangle[1][2]
                x3, y3, z3 = triangle[2][0], triangle[2][1], triangle[2][2]
                normx = (z1 - z2) * (y3 - y2) - (y1 - y2) * (z3 - z2)
                normy = (x1 - x2) * (z3 - z2) - (z1 - z2) * (x3 - x2)
                normz = (y1 - y2) * (x3 - x2) - (x1 - x2) * (y3 - y2)
                normlength = math.sqrt(normx ** 2 + normy ** 2 + normz ** 2)
github pokepetter / ursina / ursina / mesh.py View on Github external
if len(t) == 3:
                            for e in t:
                                prim.addVertex(e)
                        elif len(t) == 4: # turn quad into tris
                            prim.addVertex(t[0])
                            prim.addVertex(t[1])
                            prim.addVertex(t[2])
                            prim.addVertex(t[2])
                            prim.addVertex(t[3])
                            prim.addVertex(t[0])

            else:
                prim.addConsecutiveVertices(0, len(self.vertices))

            prim.close_primitive()
            geom = Geom(vdata)
            geom.addPrimitive(prim)
            self.geomNode.addGeom(geom)

        else:   # line with segments defined in triangles
            for line in self._triangles:
                prim = Mesh._modes[self.mode](static_mode)
                for e in line:
                    prim.addVertex(e)
                prim.close_primitive()
                geom = Geom(vdata)
                geom.addPrimitive(prim)
                self.geomNode.addGeom(geom)

        if self.mode == 'point':
            self.setTexGen(TextureStage.getDefault(), TexGenAttrib.MPointSprite)
            # self.set_render_mode_perspective(True)
github gamingrobot / second-sunrise / Player.py View on Github external
#bottom side
        prim.addVertices(4, 5)
        prim.addVertices(5, 6)
        prim.addVertices(6, 7)
        prim.addVertices(7, 4)

        #other sides
        prim.addVertices(0, 4)
        prim.addVertices(1, 5)
        prim.addVertices(2, 6)
        prim.addVertices(3, 7)

        prim.closePrimitive()
        #attach primitives and render
        geom = Geom(vdata)
        geom.addPrimitive(prim)

        #add bullet
        """col = BulletTriangleMesh()
        col.addGeom(geom)
        shape = BulletTriangleMeshShape(col, dynamic=False)
        bulletnode = BulletRigidBodyNode('Chunk')
        bulletnode.addShape(shape)
        bulletnp = self.planetNode.attachNewNode(bulletnode)
        bulletnp.setPos(self.x + self.size, self.y + self.size, self.z + self.size)
        self.root.bulletworld.attachRigidBody(bulletnode)"""

        node = GeomNode('picker')
        node.addGeom(geom)
        self.select = self.root.render.attachNewNode(node)
        self.select.setPos(0, 0, 0)
github cosmonium / cosmonium / cosmonium / pointsset.py View on Github external
def makeGeom(self, points, colors, sizes):
        #format = GeomVertexFormat.getV3c4()
        array = GeomVertexArrayFormat()
        array.addColumn(InternalName.make('vertex'), 3, Geom.NTFloat32, Geom.CPoint)
        array.addColumn(InternalName.make('color'), 4, Geom.NTFloat32, Geom.CColor)
        if self.use_sizes:
            array.addColumn(InternalName.make('size'), 1, Geom.NTFloat32, Geom.COther)
        format = GeomVertexFormat()
        format.addArray(array)
        format = GeomVertexFormat.registerFormat(format)
        vdata = GeomVertexData('vdata', format, Geom.UH_static)
        vdata.unclean_set_num_rows(len(points))
        self.vwriter = GeomVertexWriter(vdata, 'vertex')
        self.colorwriter = GeomVertexWriter(vdata, 'color')
        if self.use_sizes:
            self.sizewriter = GeomVertexWriter(vdata, 'size')
        geompoints = GeomPoints(Geom.UH_static)
        geompoints.reserve_num_vertices(len(points))
        index = 0
        for (point, color, size) in zip(points, colors, sizes):
            self.vwriter.addData3f(*point)
github panda3d / panda3d / samples / fractal-plants / main.py View on Github external
def drawBody(nodePath, vdata, pos, vecList, radius=1, keepDrawing=True, numVertices=8):

    circleGeom = Geom(vdata)

    vertWriter = GeomVertexWriter(vdata, "vertex")
    colorWriter = GeomVertexWriter(vdata, "color")
    normalWriter = GeomVertexWriter(vdata, "normal")
    drawReWriter = GeomVertexRewriter(vdata, "drawFlag")
    texReWriter = GeomVertexRewriter(vdata, "texcoord")

    startRow = vdata.getNumRows()
    vertWriter.setRow(startRow)
    colorWriter.setRow(startRow)
    normalWriter.setRow(startRow)

    sCoord = 0

    if (startRow != 0):
        texReWriter.setRow(startRow - numVertices)
github Craig-Macomber / Panda3D-Terrain-System / meshManager / meshManager.py View on Github external
def _getGeom(self):
        if self.geom is None:
            self.vdata = GeomVertexData("verts", self.geomRequirements.geomVertexFormat, Geom.UHStatic) 
            self.node.addGeom(Geom(self.vdata))
            self.geom=self.node.modifyGeom(self.node.getNumGeoms()-1)
        return self.geom
github RealHacker / python-gems / Pycraft / pycraft.py View on Github external
# adding different colors to the vertex for visibility
    # color.addData4f(1.0, 0.0, 0.0, 1.0)
    # color.addData4f(0.0, 1.0, 0.0, 1.0)
    # color.addData4f(0.0, 0.0, 1.0, 1.0)
    # color.addData4f(1.0, 0.0, 1.0, 1.0)

    texcoord.addData2f(0.0, 1.0)
    texcoord.addData2f(0.0, 0.0)
    texcoord.addData2f(1.0, 0.0)
    texcoord.addData2f(1.0, 1.0)

    # Quads aren't directly supported by the Geom interface
    # you might be interested in the CardMaker class if you are
    # interested in rectangle though
    tris = GeomTriangles(Geom.UHDynamic)
    tris.addVertices(0, 1, 3)
    tris.addVertices(1, 2, 3)

    square = Geom(vdata)
    square.addPrimitive(tris)
    return square
github gamingrobot / second-sunrise / PChunk.py View on Github external
elif meshtype == MeshType.DualContour:
            mesher = DualContour(self, self.size, self.chunks, self.radius, self.noise)
        else:
            mesher = Voxel(self, self.size, self.chunks, self.radius, self.noise)

        triangles = mesher.generateMesh()

        #format = GeomVertexFormat.registerFormat(GeomVertexFormat.getV3n3c4t2())
        format = GeomVertexFormat.registerFormat(GeomVertexFormat.getV3n3c4())
        vdata = GeomVertexData('chunk', format, Geom.UHStatic)

        vertex = GeomVertexWriter(vdata, 'vertex')
        normal = GeomVertexWriter(vdata, 'normal')
        color = GeomVertexWriter(vdata, 'color')
        texcoord = GeomVertexWriter(vdata, 'texcoord')
        prim = GeomTriangles(Geom.UHStatic)

        self.vertexcount = 0
        for triangle in triangles:
            for avertex in triangle:
                #print triangle
                #make vertices here
                shade = 0.5
                vertex.addData3f(avertex[0], avertex[1], avertex[2])
                #fix normals
                x1, y1, z1 = triangle[0][0], triangle[0][1], triangle[0][2]
                x2, y2, z2 = triangle[1][0], triangle[1][1], triangle[1][2]
                x3, y3, z3 = triangle[2][0], triangle[2][1], triangle[2][2]
                normx = (z1 - z2) * (y3 - y2) - (y1 - y2) * (z3 - z2)
                normy = (x1 - x2) * (z3 - z2) - (z1 - z2) * (x3 - x2)
                normz = (y1 - y2) * (x3 - x2) - (x1 - x2) * (y3 - y2)
                normlength = math.sqrt(normx ** 2 + normy ** 2 + normz ** 2)
github pycollada / pycollada / examples / panda_display_collada.py View on Github external
type(prim) is collada.polygons.BoundPolygons:
            
            triset = prim.triangleset()
            (vdata, gprim) = getPrimAndDataFromTri(triset)
            
        elif type(prim) is collada.lineset.BoundLineSet:
            
            vdata = getVertexData(prim.vertex, prim.vertex_index)           
            gprim = GeomLines(Geom.UHStatic)
            gprim.addConsecutiveVertices(0, 2*prim.nlines)
            gprim.closePrimitive()
            
        else:
            raise Exception("Error: Unsupported primitive type. Exiting.")
            
        pgeom = Geom(vdata)
        pgeom.addPrimitive(gprim)
        
        render_state = getStateFromMaterial(prim.material)
        node = GeomNode("primitive")
        node.addGeom(pgeom, render_state)
        
        return node
github pycollada / pycollada / examples / panda_display_collada.py View on Github external
def getPrimAndDataFromTri(triset):
        if triset.normal is None:
            triset.generateNormals()

        vdata = getVertexData(triset.vertex, triset.vertex_index,
                              triset.normal, triset.normal_index,
                              triset.texcoordset, triset.texcoord_indexset)

        gprim = GeomTriangles(Geom.UHStatic)
        gprim.addConsecutiveVertices(0, 3*triset.ntriangles)
        gprim.closePrimitive()
        
        return (vdata, gprim)