def __init__(self): formatArray=GeomVertexArrayFormat() formatArray.addColumn(InternalName.make("drawFlag"), 1, Geom.NTUint8, Geom.COther) format=GeomVertexFormat(GeomVertexFormat.getV3n3cpt2()) format.addArray(formatArray) self.format=GeomVertexFormat.registerFormat(format) bodydata=GeomVertexData("body vertices", format, Geom.UHStatic) self.barkTexture=loader.loadTexture( \ "models/samples/fractal_plants/bark.jpg") treeNodePath=NodePath("Tree Holder") makeFractalTree(bodydata,treeNodePath,Vec3(4,4,7)) treeNodePath.setTexture(self.barkTexture,1) treeNodePath.reparentTo(render) self.accept("q", self.regenTree) self.accept("w", self.addTree) self.accept("arrow_up", self.upIterations) self.accept("arrow_down", self.downIterations) self.accept("arrow_right", self.upCopies) self.accept("arrow_left", self.downCopies) self.numIterations=11 self.numCopies=4 self.upDownEvent = OnscreenText( text="Up/Down: Increase/Decrease the number of iterations ("+str(self.numIterations)+")", style=1, fg=(1,1,1,1), pos=(-1.3, 0.85), font = font, align=TextNode.ALeft, scale = .05, mayChange=True) self.leftRightEvent = OnscreenText( text="Left/Right: Increase/Decrease branching("+str(self.numCopies)+")", style=1, fg=(1,1,1,1), pos=(-1.3, 0.80), font = font, align=TextNode.ALeft, scale = .05, mayChange=True)
def makeSquare(x1, y1, z1, x2, y2, z2): format = GeomVertexFormat.getV3n3cpt2() vdata = GeomVertexData('square', format, Geom.UHDynamic) vertex = GeomVertexWriter(vdata, 'vertex') normal = GeomVertexWriter(vdata, 'normal') color = GeomVertexWriter(vdata, 'color') texcoord = GeomVertexWriter(vdata, 'texcoord') #make sure we draw the sqaure in the right plane if x1 != x2: vertex.addData3f(x1, y1, z1) vertex.addData3f(x2, y1, z1) vertex.addData3f(x2, y2, z2) vertex.addData3f(x1, y2, z2) normal.addData3f(myNormalize(Vec3(2 * x1 - 1, 2 * y1 - 1, 2 * z1 - 1))) normal.addData3f(myNormalize(Vec3(2 * x2 - 1, 2 * y1 - 1, 2 * z1 - 1))) normal.addData3f(myNormalize(Vec3(2 * x2 - 1, 2 * y2 - 1, 2 * z2 - 1))) normal.addData3f(myNormalize(Vec3(2 * x1 - 1, 2 * y2 - 1, 2 * z2 - 1))) else: vertex.addData3f(x1, y1, z1) vertex.addData3f(x2, y2, z1) vertex.addData3f(x2, y2, z2) vertex.addData3f(x1, y1, z2) normal.addData3f(myNormalize(Vec3(2 * x1 - 1, 2 * y1 - 1, 2 * z1 - 1))) normal.addData3f(myNormalize(Vec3(2 * x2 - 1, 2 * y2 - 1, 2 * z1 - 1))) normal.addData3f(myNormalize(Vec3(2 * x2 - 1, 2 * y2 - 1, 2 * z2 - 1))) normal.addData3f(myNormalize(Vec3(2 * x1 - 1, 2 * y1 - 1, 2 * z2 - 1))) #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 arent directly supported by the Geom interface #you might be interested in the CardMaker class if you are #interested in rectangle though tri1 = GeomTriangles(Geom.UHDynamic) tri2 = GeomTriangles(Geom.UHDynamic) tri1.addVertex(0) tri1.addVertex(1) tri1.addVertex(3) tri2.addConsecutiveVertices(1, 3) tri1.closePrimitive() tri2.closePrimitive() square = Geom(vdata) square.addPrimitive(tri1) square.addPrimitive(tri2) return square
def makeSquare(x1,y1,z1, x2,y2,z2): format=GeomVertexFormat.getV3n3cpt2() vdata=GeomVertexData('square', format, Geom.UHDynamic) vertex=GeomVertexWriter(vdata, 'vertex') normal=GeomVertexWriter(vdata, 'normal') color=GeomVertexWriter(vdata, 'color') texcoord=GeomVertexWriter(vdata, 'texcoord') #make sure we draw the sqaure in the right plane if x1!=x2: vertex.addData3f(x1, y1, z1) vertex.addData3f(x2, y1, z1) vertex.addData3f(x2, y2, z2) vertex.addData3f(x1, y2, z2) normal.addData3f(myNormalize(Vec3(2*x1-1, 2*y1-1, 2*z1-1))) normal.addData3f(myNormalize(Vec3(2*x2-1, 2*y1-1, 2*z1-1))) normal.addData3f(myNormalize(Vec3(2*x2-1, 2*y2-1, 2*z2-1))) normal.addData3f(myNormalize(Vec3(2*x1-1, 2*y2-1, 2*z2-1))) else: vertex.addData3f(x1, y1, z1) vertex.addData3f(x2, y2, z1) vertex.addData3f(x2, y2, z2) vertex.addData3f(x1, y1, z2) normal.addData3f(myNormalize(Vec3(2*x1-1, 2*y1-1, 2*z1-1))) normal.addData3f(myNormalize(Vec3(2*x2-1, 2*y2-1, 2*z1-1))) normal.addData3f(myNormalize(Vec3(2*x2-1, 2*y2-1, 2*z2-1))) normal.addData3f(myNormalize(Vec3(2*x1-1, 2*y1-1, 2*z2-1))) #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 arent directly supported by the Geom interface #you might be interested in the CardMaker class if you are #interested in rectangle though tri1=GeomTriangles(Geom.UHDynamic) tri2=GeomTriangles(Geom.UHDynamic) tri1.addVertex(0) tri1.addVertex(1) tri1.addVertex(3) tri2.addConsecutiveVertices(1,3) tri1.closePrimitive() tri2.closePrimitive() square=Geom(vdata) square.addPrimitive(tri1) square.addPrimitive(tri2) return square