def makeQuad(renderVP, collisionVP, bl=None, tr=None, br=None, tl=None): """Return a tuple of EggPolygons (renderQuad,collisionQuad): renderable and collision geometry for a 4-vertex polygon. Keyword arguments: renderVP -- EggVertexPool to which vertices will be added for the renderable quad collisionVP -- EggVertexPool to which vertices will be added for the collidable quad bl -- bottom-left vertex of quad (Point3D). Default (-10,-10,0) tr -- top-right vertex of quad (Point3D). Default (10,10,0) br -- bottom-right vertex of quad (Point3D) tl -- top-left vertex of quad (Point3D) If either of br or tl is None then sensible defaults will be computed according to the values of bl and tr. """ if bl is None: bl = P.Point3D(-10, -10, 0) if tr is None: tr = P.Point3D(10, 10, 0) if br is None: l = tr.getX() - bl.getX() br = bl + P.Vec3D(l, 0, 0) if tl is None: w = tr.getY() - bl.getY() tl = bl + P.Vec3D(0, w, 0) renderQuad = P.EggPolygon() collisionQuad = P.EggPolygon() for corner in [bl, br, tr, tl]: vertex = P.EggVertex() vertex.setPos(corner) collisionVertex = P.EggVertex() collisionVertex.setPos(corner) renderQuad.addVertex(renderVP.addVertex(vertex)) collisionQuad.addVertex(collisionVP.addVertex(collisionVertex)) # A bug in Panda3D means that auto-triangulation of concave polygons # fails for some combinations of vertices (the polygon is not properly # transformed into triangles) creating gaps in a model where polygons are # missing. We can check for this failure by calling # EggPolygon.triangulateInto() and checking its return value. If False is # returned we reverse the vertex order of the polygon (so it now faces # downward instead of up) and reverse the backface flag so the downside # (which is now facing up) is rendered instead of the upside (which is now # facing down). The result looks more or less the same as if the polygon # had triangulated correctly in the first place (except the shading will be # different). Thanks to ynjh_jo for this workaround. egn = P.EggGroupNode( ) # triangulateInto() stores the resulting polygons in # an EggGroupNode, which we discard, we only care # about the True or False return value if not renderQuad.triangulateInto(egn, 0): # Triangulation failed, fix it. renderQuad.reverseVertexOrdering() renderQuad.setBfaceFlag(1) collisionQuad.reverseVertexOrdering() collisionQuad.setBfaceFlag(1) renderQuad.recomputePolygonNormal() # Use faceted not smoothed lighting return renderQuad, collisionQuad