def createStoreModel(pipeline): # Se crea la tiendo con un grafo de escena a base de shapes redQuadShape = bs.createColorQuad(255 / 255, 105 / 255, 105 / 255) lBlueQuadShape = bs.createColorQuad(133 / 255, 255 / 255, 253 / 255) darkGreenQuadShape = bs.createColorQuad(0, 125 / 255, 0) blackQuadShape = bs.createColorQuad(0, 0, 0) gpuRedQuad = createGPUShape(redQuadShape, pipeline) gpuLBlueQuad = createGPUShape(lBlueQuadShape, pipeline) gpuDarkGreenQuad = createGPUShape(darkGreenQuadShape, pipeline) gpuBlackQuad = createGPUShape(blackQuadShape, pipeline) frontNode = csg.CustomSceneGraphNode("front") frontNode.transform = tr.scale(0.3, 0.6, 1) frontNode.childs = [gpuRedQuad] windowNode = csg.CustomSceneGraphNode("window") windowNode.transform = tr.scale(0.1, 0.2, 1) windowNode.childs = [gpuLBlueQuad] windowDoorNode = csg.CustomSceneGraphNode("door") windowDoorNode.transform = tr.matmul( [tr.translate(0.024, 0.1, 0), tr.scale(0.15, 0.1, 1)]) windowDoorNode.childs = [gpuLBlueQuad] windowNode1 = csg.CustomSceneGraphNode("window2") windowNode1.transform = tr.translate(0, -0.15, 0) windowNode1.childs = [windowNode] windowGroupNode = csg.CustomSceneGraphNode("windowGroup") windowGroupNode.transform = tr.translate(0.05, 0, 0) windowGroupNode.childs = [windowNode1, windowDoorNode] signGreenNode = csg.CustomSceneGraphNode("greenSign") signGreenNode.transform = tr.scale(0.1, 0.7, 1) signGreenNode.childs = [gpuDarkGreenQuad] signBlackNode = csg.CustomSceneGraphNode("blackSign") signBlackNode.transform = tr.scale(0.11, 0.71, 1) signBlackNode.childs = [gpuBlackQuad] signNode = csg.CustomSceneGraphNode("sign") signNode.transform = tr.translate(-0.2, 0, 0) signNode.childs = [signBlackNode, signGreenNode] storeNode = csg.CustomSceneGraphNode("store") storeNode.childs = [frontNode, windowGroupNode, signNode] regularNode = csg.CustomSceneGraphNode("regularStore") regularNode.childs = [storeNode] finalNode = csg.CustomSceneGraphNode("finalStore") finalNode.transform = tr.translate(0, 2, 0) finalNode.childs = [regularNode] return finalNode
def createBackground(pipeline, i): # Se crea el fondo con un grafo de escena de shapes greenQuad = bs.createColorQuad(0.0, 0.6, 0.0) greyQuad = bs.createColorQuad(0.6, 0.6, 0.6) whiteQuad = bs.createColorQuad(255 / 255, 242 / 255, 0) gpuGrass = createGPUShape(greenQuad, pipeline) gpuStreet = createGPUShape(greyQuad, pipeline) gpuLine = createGPUShape(whiteQuad, pipeline) grassNode = sg.SceneGraphNode("grass") grassNode.transform = tr.scale(4, 2, 1) grassNode.childs = [gpuGrass] streetNode = sg.SceneGraphNode("street") streetNode.transform = tr.scale(1, 2, 1) streetNode.childs = [gpuStreet] lineNode = sg.SceneGraphNode("line") lineNode.transform = tr.scale(0.1, 0.25, 1) lineNode.childs = [gpuLine] trLineNode1 = sg.SceneGraphNode("trline1") trLineNode1.transform = tr.identity() trLineNode1.childs = [lineNode] trLineNode2 = sg.SceneGraphNode("trline2") trLineNode2.transform = tr.translate(0, 0.4, 0) trLineNode2.childs = [lineNode] trLineNode3 = sg.SceneGraphNode("trline3") trLineNode3.transform = tr.translate(0, -0.4, 0) trLineNode3.childs = [lineNode] trLineNode4 = sg.SceneGraphNode("trline4") trLineNode4.transform = tr.translate(0, -0.8, 0) trLineNode4.childs = [lineNode] trLineNode5 = sg.SceneGraphNode("trline5") trLineNode5.transform = tr.translate(0, 0.8, 0) trLineNode5.childs = [lineNode] lineGroupNode = sg.SceneGraphNode("lineGroup") lineGroupNode.transform = tr.translate(0, 0, 0) lineGroupNode.childs = [ trLineNode1, trLineNode2, trLineNode3, trLineNode4, trLineNode5 ] finalNode = sg.SceneGraphNode("final" + str(i)) finalNode.childs = [grassNode, streetNode, lineGroupNode] return finalNode
def createGPUColorQuad(r, g, b): shapeQuad = bs.createColorQuad(r, g, b) gpuQuad = es.GPUShape().initBuffers() pipeline.setupVAO(gpuQuad) gpuQuad.fillBuffers(shapeQuad.vertices, shapeQuad.indices, GL_STATIC_DRAW) return gpuQuad
def createCar(pipeline): # Creating shapes on GPU memory blackQuad = bs.createColorQuad(0, 0, 0) gpuBlackQuad = es.GPUShape().initBuffers() pipeline.setupVAO(gpuBlackQuad) gpuBlackQuad.fillBuffers(blackQuad.vertices, blackQuad.indices, GL_STATIC_DRAW) redQuad = bs.createColorQuad(1, 0, 0) gpuRedQuad = es.GPUShape().initBuffers() pipeline.setupVAO(gpuRedQuad) gpuRedQuad.fillBuffers(redQuad.vertices, redQuad.indices, GL_STATIC_DRAW) # Cheating a single wheel wheel = sg.SceneGraphNode("wheel") wheel.transform = tr.uniformScale(0.2) wheel.childs += [gpuBlackQuad] wheelRotation = sg.SceneGraphNode("wheelRotation") wheelRotation.childs += [wheel] # Instanciating 2 wheels, for the front and back parts frontWheel = sg.SceneGraphNode("frontWheel") frontWheel.transform = tr.translate(0.3, -0.3, 0) frontWheel.childs += [wheelRotation] backWheel = sg.SceneGraphNode("backWheel") backWheel.transform = tr.translate(-0.3, -0.3, 0) backWheel.childs += [wheelRotation] # Creating the chasis of the car chasis = sg.SceneGraphNode("chasis") chasis.transform = tr.scale(1, 0.5, 1) chasis.childs += [gpuRedQuad] car = sg.SceneGraphNode("car") car.childs += [chasis] car.childs += [frontWheel] car.childs += [backWheel] traslatedCar = sg.SceneGraphNode("traslatedCar") traslatedCar.transform = tr.translate(0, 0.3, 0) traslatedCar.childs += [car] return traslatedCar
def createDecorations(pipeline, tex_pipeline, x_range, y_range, n, i_z): # Se crean las decoraciones con un grafo de escena que admite shapes y texturas triangleShape = createTriangle() quadShape = createQuad() whiteQuad = bs.createColorQuad(1, 1, 1) greyQuad = bs.createColorQuad(0.8, 0.8, 0.8) umbrellaShape = createUmbrellaCircle() gpuLeaves = createTextureGPUShape(triangleShape, tex_pipeline, getAssetPath("hojas_arboles.jpg")) gpuTrunk = createTextureGPUShape(quadShape, tex_pipeline, getAssetPath("tronco.jpeg")) gpuWhiteQuad = createGPUShape(whiteQuad, pipeline) gpuGreyQuad = createGPUShape(greyQuad, pipeline) gpuUmbrella = createGPUShape(umbrellaShape, pipeline) leavesNode = csg.CustomSceneGraphNode("hojas") leavesNode.transform = tr.translate(0, 0.5, 0) leavesNode.childs = [gpuLeaves] trunkNode = csg.CustomSceneGraphNode("tronco") trunkNode.transform = tr.matmul( [tr.translate(0, -0.25, 0), tr.scale(0.3, 0.5, 1)]) trunkNode.childs = [gpuTrunk] scaledTreeNode = csg.CustomSceneGraphNode("arbol_escalado") scaledTreeNode.transform = tr.uniformScale(0.3) scaledTreeNode.childs = [trunkNode, leavesNode] treeGroupNode = csg.CustomSceneGraphNode("grupo_arboles") # Se crean arboles en posiciones generadas al azar for i in range(n): x = 100 - x_range * 100 x_rand = rd.randint(0, x) * 0.01 r_x = x_rand + x_range coin = rd.randint(0, 1) if coin: r_x *= -1 r_y = rd.randint(y_range[0] * 100, y_range[1] * 100) * 0.01 treeNode = csg.CustomSceneGraphNode("arbol_" + str(i)) treeNode.transform = tr.translate(r_x, r_y, 0) treeNode.childs = [scaledTreeNode] treeGroupNode.childs += [treeNode] treeGroupNode.childs.sort(reverse=True, key=height) cartBodyNode = csg.CustomSceneGraphNode("ej") cartBodyNode.transform = tr.scale(0.3, 0.5, 1) cartBodyNode.childs = [gpuWhiteQuad] cartInsideNode = csg.CustomSceneGraphNode("inside") cartInsideNode.transform = tr.scale(0.2, 0.3, 1) cartInsideNode.childs = [gpuGreyQuad] umbrellaNode = csg.CustomSceneGraphNode("umbrella") umbrellaNode.transform = tr.rotationZ(math.pi / 8) umbrellaNode.childs = [gpuUmbrella] umbrellaScaled = csg.CustomSceneGraphNode("umbrellaS") umbrellaScaled.transform = tr.scale(0.3, 0.3, 1) umbrellaScaled.childs = [umbrellaNode] umbrellaTranslated = csg.CustomSceneGraphNode("umbrellaT") umbrellaTranslated.transform = tr.translate(-0.1, 0.1, 0) umbrellaTranslated.childs = [umbrellaScaled] cartNode = csg.CustomSceneGraphNode("cart") cartNode.transform = tr.translate(0.8, -0.5, 0) cartNode.childs = [cartBodyNode, cartInsideNode, umbrellaTranslated] regularNode = csg.CustomSceneGraphNode("regular") regularNode.transform = tr.identity() regularNode.childs = [cartNode] regularNode.curr_pipeline = pipeline texNode = csg.CustomSceneGraphNode("tex") texNode.childs = [treeGroupNode] texNode.curr_pipeline = tex_pipeline decNode = csg.CustomSceneGraphNode("decorations" + str(i_z)) decNode.childs = [regularNode, texNode] return decNode
def createSnowman(pipeline): # Convenience function to ease initialization def createGPUShape(shape): gpuShape = es.GPUShape().initBuffers() pipeline.setupVAO(gpuShape) gpuShape.fillBuffers(shape.vertices, shape.indices, GL_STATIC_DRAW) return gpuShape # basic GPUShapes gpuWhiteCircle = createGPUShape(createColorCircle(30, 1, 1, 1, 1)) gpuBlackCircle = createGPUShape(createColorCircle(10, 1, 0, 0, 0)) gpuBrownQuad = createGPUShape(bs.createColorQuad(0.6, 0.3, 0)) gpuOrangeTriangle = createGPUShape(createColorTriangle(1, 0.6, 0)) # Leaf nodes whiteCircleNode = sg.SceneGraphNode("whiteCircleNode") whiteCircleNode.childs = [gpuWhiteCircle] blackCircleNode = sg.SceneGraphNode("blackCircleNode") blackCircleNode.childs = [gpuBlackCircle] brownQuadNode = sg.SceneGraphNode("brownQuadNode") brownQuadNode.childs = [gpuBrownQuad] orangeTriangleNode = sg.SceneGraphNode("orangeTriangleNode") orangeTriangleNode.childs = [gpuOrangeTriangle] # Body snowballBody = sg.SceneGraphNode("snowballBody") snowballBody.transform = tr.scale(10, 10, 0) snowballBody.childs = [whiteCircleNode] arm = sg.SceneGraphNode("arm") arm.transform = tr.matmul([ tr.translate(0, 5, 0), #tr.rotationZ(0), tr.scale(2, 10, 1) ]) arm.childs = [brownQuadNode] leftArm = sg.SceneGraphNode("leftArm") leftArm.transform = tr.matmul([ tr.translate(-7, 7, 0), tr.rotationZ(60 * np.pi / 180), #tr.scale(1, 1, 1) ]) leftArm.childs = [arm] rightArm = sg.SceneGraphNode("rightArm") rightArm.transform = tr.matmul([ tr.translate(7, 7, 0), tr.rotationZ(-60 * np.pi / 180), #tr.scale(1, 1, 1) ]) rightArm.childs = [arm] body = sg.SceneGraphNode("body") body.transform = tr.translate(0,10,0) body.childs = [snowballBody, leftArm, rightArm] # Head snowballHead = sg.SceneGraphNode("snowballHead") snowballHead.transform = tr.scale(8, 8, 0) snowballHead.childs = [whiteCircleNode] leftEye = sg.SceneGraphNode("leftEye") leftEye.transform = tr.matmul([ tr.translate(0, 5, 0), #tr.rotationZ(0), tr.scale(2, 2, 1) ]) leftEye.childs = [blackCircleNode] rightEye = sg.SceneGraphNode("rightEye") rightEye.transform = tr.matmul([ tr.translate(5, 5, 0), #tr.rotationZ(0), tr.scale(2, 2, 1) ]) rightEye.childs = [blackCircleNode] baseTriangle = sg.SceneGraphNode("baseTriangle") baseTriangle.transform = tr.matmul([ tr.translate(0, 3.5, 0), #tr.rotationZ(0), tr.scale(2, 7, 1) ]) baseTriangle.childs = [orangeTriangleNode] nose = sg.SceneGraphNode("nose") nose.transform = tr.matmul([ tr.translate(2, 0, 0), tr.rotationZ(-70 * np.pi / 180), #tr.scale(1, 1, 1) ]) nose.childs = [baseTriangle] head = sg.SceneGraphNode("head") head.transform = tr.translate(0, 27, 0) head.childs = [snowballHead, leftEye, rightEye, nose] # Snowman, the one and only snowman = sg.SceneGraphNode("snowman") snowman.childs = [body, head] return snowman