示例#1
0
    def initialize(self):

        self.setWindowTitle('Directional Light')
        self.setWindowSize(800, 800)

        self.renderer = Renderer()
        self.renderer.setViewportSize(800, 800)
        self.renderer.setClearColor(0.25, 0.25, 0.75)

        self.scene = Scene()

        self.camera = PerspectiveCamera()
        self.camera.transform.setPosition(0, 1, 7)
        self.camera.transform.lookAt(0, 0, 0)
        self.cameraControls = FirstPersonController(self.input, self.camera)

        ambientLight = AmbientLight(color=[0.1, 0.1, 0.2])
        self.scene.add(ambientLight)

        self.directionalLight = DirectionalLight(position=[2, 3, 0],
                                                 direction=[-1, -1, 0])
        self.scene.add(self.directionalLight)
        self.scene.add(DirectionalLightHelper(self.directionalLight))

        gridTexture = OpenGLUtils.initializeTexture("images/color-grid.png")
        lightMaterial = SurfaceLightMaterial(color=[1, 1, 1],
                                             texture=gridTexture)

        self.cube = Mesh(BoxGeometry(), lightMaterial)
        self.cube.transform.translate(1.5, 0, 0, Matrix.LOCAL)
        self.scene.add(self.cube)

        self.sphere = Mesh(SphereGeometry(), lightMaterial)
        self.sphere.transform.translate(-1.5, 0, 0, Matrix.LOCAL)
        self.scene.add(self.sphere)
示例#2
0
    def initialize(self):

        self.setWindowTitle('Lots of Dynamically Lit Cubes')
        self.setWindowSize(800, 800)

        self.renderer = Renderer()
        self.renderer.setViewportSize(800, 800)
        self.renderer.setClearColor(0.25, 0.25, 0.25)

        # self.renderer.setFog( Fog(startDistance=2, endDistance=20, color=[0,0,0.15]) )

        self.scene = Scene()

        self.scene.add(AmbientLight(strength=0.25))
        self.scene.add(DirectionalLight(direction=[-1, -1, 0], color=[1, 0,
                                                                      0]))
        self.scene.add(DirectionalLight(direction=[1, 1, 0], color=[0, 0, 1]))

        self.camera = PerspectiveCamera()
        self.camera.transform.setPosition(0, 0, 15)
        self.camera.transform.lookAt(0, 0, 0)
        self.cameraControls = FirstPersonController(self.input, self.camera)

        self.boxList = []

        boxGeo = BoxGeometry(width=1, height=1, depth=1)
        boxTexture = OpenGLUtils.initializeTexture("images/color-grid.png")
        boxMat = SurfaceLightMaterial(texture=boxTexture)

        for i in range(100):
            box = Mesh(boxGeo, boxMat)
            box.transform.setPosition(random.uniform(-5, 5),
                                      random.uniform(-5, 5),
                                      random.uniform(10, -10))
            box.transform.rotateX(random.uniform(0, 6.28), Matrix.LOCAL)
            box.transform.rotateY(random.uniform(0, 6.28), Matrix.LOCAL)
            self.scene.add(box)
            self.boxList.append(box)
    def initialize(self):

        self.setWindowTitle('OBJ Model Loader')
        self.setWindowSize(800, 800)

        self.renderer = Renderer()
        self.renderer.setViewportSize(800, 800)
        self.renderer.setClearColor(0.25, 0.25, 0.25)

        self.scene = Scene()

        self.camera = PerspectiveCamera()
        self.camera.transform.setPosition(0, 3, 7)
        self.camera.transform.lookAt(0, 0, 0)
        self.cameraControls = FirstPersonController(self.input, self.camera)

        ambientLight = AmbientLight(strength=0.25)
        directionalLight = DirectionalLight(direction=[-1, -1, -1])
        self.scene.add(ambientLight)
        self.scene.add(directionalLight)

        self.floorMesh = GridHelper(size=12,
                                    divisions=4,
                                    gridColor=[1, 1, 1],
                                    centerColor=[1, 0, 0])
        self.floorMesh.transform.rotateX(-3.14 / 2, Matrix.LOCAL)
        self.scene.add(self.floorMesh)

        mushroomTexture = OpenGLUtils.initializeTexture("models/mushroom.png")
        self.mushroom = Mesh(
            OBJGeometry("models/mushroom.obj", smoothNormals=True),
            SurfaceLightMaterial(texture=mushroomTexture))
        self.mushroom.transform.translate(-3, 0, 0)
        self.mushroom.transform.scaleUniform(0.8)
        self.scene.add(self.mushroom)

        fireflowerTexture = OpenGLUtils.initializeTexture(
            "models/fireflower.png")
        self.fireflower = Mesh(
            OBJGeometry("models/fireflower.obj", smoothNormals=False),
            SurfaceLightMaterial(texture=fireflowerTexture))
        self.fireflower.transform.scaleUniform(0.0005)
        self.scene.add(self.fireflower)

        starTexture = OpenGLUtils.initializeTexture("models/star.png")
        self.star = Mesh(OBJGeometry("models/star.obj", smoothNormals=False),
                         SurfaceLightMaterial(texture=starTexture))
        self.star.transform.translate(3, 0, 0)
        self.star.transform.scaleUniform(0.0005)
        self.scene.add(self.star)
示例#4
0
    def initialize(self):

        self.setWindowTitle('Helpers')
        self.setWindowSize(800, 800)

        self.renderer = Renderer()
        self.renderer.setViewportSize(800, 800)

        self.scene = Scene()

        self.camera = PerspectiveCamera()
        self.camera.transform.setPosition(0, 1, 5)
        self.cameraControls = FirstPersonController(self.input, self.camera)

        self.scene.add(AmbientLight(strength=0.25))
        directionalLight = DirectionalLight(direction=[-1, -1, -1],
                                            position=[3, 4, -3])
        self.scene.add(directionalLight)
        self.scene.add(DirectionalLightHelper(directionalLight))

        floorMesh = GridHelper(size=10,
                               divisions=10,
                               gridColor=[0, 0, 0],
                               centerColor=[1, 0, 0])
        floorMesh.transform.rotateX(-3.14 / 2, Matrix.LOCAL)
        self.scene.add(floorMesh)

        gridTexture = OpenGLUtils.initializeTexture("images/color-grid.png")
        gridMaterial = SurfaceLambertMaterial(objTexture=gridTexture)
        self.cylinder = Mesh(
            CylinderGeometry(radiusTop=0.25, radiusBottom=1, heightSegments=6),
            gridMaterial)
        self.cylinder.transform.translate(0, 1, 0, Matrix.LOCAL)
        self.scene.add(self.cylinder)

        self.cylinder.add(AxesHelper(axisLength=2, lineWidth=4))

        self.scene.add(
            BoxHelper(self.cylinder, lineColor=[1, 1, 0], lineWidth=4))
        self.scene.add(
            VertexNormalHelper(self.cylinder,
                               lineLength=0.25,
                               lineColor=[0.5, 0.5, 1],
                               lineWidth=2))
示例#5
0
    def initialize(self):

        self.setWindowTitle('Shadows')
        self.setWindowSize(800,800)

        self.renderer = Renderer()
        self.renderer.setViewportSize(800,800)
        self.renderer.setClearColor(0.5,0.5,0.75)

        # to render shadows, the renderer has to do an additional pass
        #   to store depth data in a shadowmap texture;
        #   this is indicated by setting shadowMapEnabled to True.
        self.renderer.shadowMapEnabled = True
        
        self.scene = Scene() 

        self.camera = PerspectiveCamera()
        self.camera.transform.setPosition(0, 3, 5)
        self.camera.transform.lookAt(0, 1, 0)
        self.cameraControls = FirstPersonController(self.input, self.camera)

        self.scene.add( AmbientLight(strength=0.5) )
        
        # setup directional light that casts shadows
        directionalLight = DirectionalLight(position=[2,2,0], direction=[-2,-1,0])
        directionalLight.enableShadows(strength=0.5)
        # the tighter the fit on the shadow region,
        #   the better the shadow resolution will be.
        # adjust as necessary according to the contents of the scene
        directionalLight.shadowCamera.setViewRegion(
            left=-2, right=2, top=2, bottom=-2, near=10, far=0)
        self.scene.add( directionalLight )

        self.scene.add( DirectionalLightHelper(directionalLight) )
        self.scene.add( OrthographicCameraHelper(directionalLight.shadowCamera) )
        
        gridTexture  = OpenGLUtils.initializeTexture("images/color-grid.png")

        geo = QuadGeometry(width=4,height=4)
        mat = SurfaceLightMaterial(texture=gridTexture)
        
        floor = Mesh( geo, SurfaceLightMaterial(texture=gridTexture) )
        floor.transform.rotateX(-3.14/2)        
        floor.setReceiveShadow()
        self.scene.add( floor )

        # illustrate the contents of the shadowMap
        backWall = Mesh(geo,
            SurfaceBasicMaterial(texture=directionalLight.shadowRenderTarget.textureID))
        backWall.transform.translate(0,2,-2)
        self.scene.add(backWall)

        sideWall = Mesh(geo, mat)
        sideWall.transform.translate(-2,2,0)
        sideWall.transform.rotateY(3.14/2, Matrix.LOCAL)
        sideWall.setReceiveShadow()
        self.scene.add(sideWall)

        sphere = Mesh( SphereGeometry(radius=0.3), mat )
        sphere.transform.setPosition(1,2.1,0)
        sphere.setCastShadow()
        self.scene.add( sphere )
        
        self.box = Mesh( BoxGeometry(1,1,1), mat )
        self.box.transform.setPosition(0,1,0)
        self.box.setCastShadow()
        self.box.setReceiveShadow()
        self.scene.add( self.box )
示例#6
0
    #ground = Entity(model='plane',shader=lit_with_shadows_shader, texture='white_cube',scale=(32,1,32),texture_scale=(32,32), collider='mesh',color=color.white)
    #ground = Entity(model='plane',texture="track", scale=(200,1,200), collider='box',shader=lit_with_shadows_shader)
    #ground = Entity(model='plane', scale=(20,1,20),texture_scale=(200,200), texture='road',  collider='box')
    #my_scene = load_blender_scene('gmae')

    ground = Entity(
        model='plane',
        y=-0.1,
        scale=(1000, 1, 1000),
        color=color.rgb(60, 60, 60),
        texture='white_cube',
        texture_scale=(
            1000, 1000))  #, collider='box')#,shader=lit_with_shadows_shader)
    sun = DirectionalLight(y=50,
                           x=400,
                           z=400,
                           scale=(100, 100, 100),
                           rotation=(160, 30, 0))
    sun._light.show_frustum()
    Sky(color=color.rgb(200, 200, 220, a=255))
    #player = FirstPersonController(model='cube', y=1, origin_y=-.5)

    #player.smokeParticles=0.5

    print(hosting)
    players = [[
        identification,
        str(round(player.body.world_x, 4)),
        str(round(player.body.world_y, 4)),
        str(round(player.body.world_z, 4)),
        str(round(player.body.world_rotation_y, 4)),
    def initialize(self):

        self.setWindowTitle('Surface Geometry')
        self.setWindowSize(800, 800)

        self.renderer = Renderer()
        self.renderer.setViewportSize(800, 800)
        self.renderer.setClearColor(0.25, 0.25, 0.25)

        self.scene = Scene()

        self.camera = PerspectiveCamera()
        self.camera.transform.setPosition(0, 9, 12)
        self.camera.transform.lookAt(0, 0, 0)
        self.cameraControls = FirstPersonController(self.input, self.camera)

        self.scene.add(AmbientLight(strength=0.25))
        self.scene.add(DirectionalLight(direction=[-1, -1, -1]))

        gridTexture = OpenGLUtils.initializeTexture("images/color-grid.png")
        gridMaterial = SurfaceLambertMaterial(objTexture=gridTexture)

        self.meshList = []

        # pyramid, cone, cylinder, cylinder

        pyramid = Mesh(PyramidGeometry(numberSides=4), gridMaterial)
        pyramid.transform.translate(-4.5, 0, 4.5, Matrix.LOCAL)
        self.meshList.append(pyramid)

        cone = Mesh(ConeGeometry(), gridMaterial)
        cone.transform.translate(-1.5, 0, 4.5, Matrix.LOCAL)
        self.meshList.append(cone)

        cylinder2 = Mesh(CylinderGeometry(radiusTop=0.25, radiusBottom=1),
                         gridMaterial)
        cylinder2.transform.translate(1.5, 0, 4.5, Matrix.LOCAL)
        self.meshList.append(cylinder2)

        cylinder = Mesh(CylinderGeometry(), gridMaterial)
        cylinder.transform.translate(4.5, 0, 4.5, Matrix.LOCAL)
        self.meshList.append(cylinder)

        # Octahedron, Icosahedron, Prism, Cube

        octa = Mesh(OctahedronGeometry(), gridMaterial)
        octa.transform.translate(-4.5, 0, 1.5, Matrix.LOCAL)
        self.meshList.append(octa)

        icosa = Mesh(IcosahedronGeometry(), gridMaterial)
        icosa.transform.translate(-1.5, 0, 1.5, Matrix.LOCAL)
        self.meshList.append(icosa)

        prism = Mesh(PrismGeometry(numberSides=6), gridMaterial)
        prism.transform.translate(1.5, 0, 1.5, Matrix.LOCAL)
        self.meshList.append(prism)

        cube = Mesh(BoxGeometry(), gridMaterial)
        cube.transform.translate(4.5, 0, 1.5, Matrix.LOCAL)
        self.meshList.append(cube)

        # Circle, Ring, Hexagon, Quad

        circle = Mesh(CircleGeometry(), gridMaterial)
        circle.transform.translate(-4.5, 0, -1.5, Matrix.LOCAL)
        self.meshList.append(circle)

        ring = Mesh(RingGeometry(), gridMaterial)
        ring.transform.translate(-1.5, 0, -1.5, Matrix.LOCAL)
        self.meshList.append(ring)

        polygon = Mesh(PolygonGeometry(numberSides=6), gridMaterial)
        polygon.transform.translate(1.5, 0, -1.5, Matrix.LOCAL)
        self.meshList.append(polygon)

        quad = Mesh(QuadGeometry(), gridMaterial)
        quad.transform.translate(4.5, 0, -1.5, Matrix.LOCAL)
        self.meshList.append(quad)

        # Sphere, Torus, Tube(Helix), Tube(Knot)

        sphere = Mesh(SphereGeometry(), gridMaterial)
        sphere.transform.translate(-4.5, 0, -4.5, Matrix.LOCAL)
        self.meshList.append(sphere)

        torus = Mesh(TorusGeometry(), gridMaterial)
        torus.transform.translate(-1.5, 0, -4.5, Matrix.LOCAL)
        self.meshList.append(torus)

        curve1 = CurveFactory.makeHelix(radius=0.75)
        helix = Mesh(TubeGeometry(curve1, 0.1, 6), gridMaterial)
        helix.transform.translate(1.5, 0, -4.5, Matrix.GLOBAL)
        self.meshList.append(helix)

        curve2 = CurveFactory.makeTorusKnot(3, 5)
        knot = Mesh(TubeGeometry(curve2, 0.1, 6), gridMaterial)
        knot.transform.translate(4.5, 0, -4.5, Matrix.GLOBAL)
        self.meshList.append(knot)

        for mesh in self.meshList:
            self.scene.add(mesh)
示例#8
0
    def initialize(self):

        self.setWindowTitle('Juggling Paths')
        self.setWindowSize(800, 800)

        self.renderer = Renderer()
        self.renderer.setViewportSize(800, 800)
        self.renderer.setClearColor(0.25, 0.25, 0.25)

        self.scene = Scene()

        self.camera = PerspectiveCamera()
        self.camera.transform.setPosition(0, 1, 5)
        self.camera.transform.lookAt(0, 0, 0)
        self.cameraControls = FirstPersonController(self.input, self.camera)

        self.scene.add(AmbientLight(strength=0.25))
        self.scene.add(DirectionalLight(direction=[-1, -1, -2]))

        starTexture = OpenGLUtils.initializeTexture("images/stars.jpg")
        stars = Mesh(SphereGeometry(200, 64, 64),
                     SurfaceBasicMaterial(texture=starTexture))
        self.scene.add(stars)

        floorMesh = GridHelper(size=10,
                               divisions=10,
                               gridColor=[0.5, 0.5, 0.5],
                               centerColor=[1, 1, 1])
        floorMesh.transform.rotateX(-3.14 / 2, Matrix.LOCAL)
        self.scene.add(floorMesh)

        ballGeometry = SphereGeometry(radius=0.1)
        self.ball1 = Mesh(ballGeometry,
                          SurfaceLambertMaterial(objColor=[1, 0.2, 0.2]))
        self.ball3 = Mesh(ballGeometry,
                          SurfaceLambertMaterial(objColor=[0.2, 1, 0.2]))
        self.ball2 = Mesh(ballGeometry,
                          SurfaceLambertMaterial(objColor=[0.2, 0.2, 1]))
        self.scene.add(self.ball1)
        self.scene.add(self.ball2)
        self.scene.add(self.ball3)

        handGeometry = BoxGeometry(width=0.4, height=0.1, depth=0.4)
        self.handL = Mesh(handGeometry,
                          SurfaceLambertMaterial(objColor=[0.9, 0.9, 0.9]))
        self.handR = Mesh(handGeometry,
                          SurfaceLambertMaterial(objColor=[0.9, 0.9, 0.9]))
        self.scene.add(self.handL)
        self.scene.add(self.handR)

        ballHeight = 3
        carryDepth = 0.5
        # all throw/catch occurs at y=0
        throwPosition = 2
        catchPosition = 3
        midPosition = (throwPosition + catchPosition) / 2

        A = [throwPosition, 0, 0]
        B = [-midPosition, ballHeight, 0]
        C = [-catchPosition, ballHeight, 0]
        D = [-catchPosition, 0, 0]
        E = [-catchPosition, -carryDepth, 0]
        F = [-midPosition, -carryDepth, 0]
        G = [-throwPosition, 0, 0]
        H = [midPosition, ballHeight, 0]
        I = [catchPosition, ballHeight, 0]
        J = [catchPosition, 0, 0]
        K = [catchPosition, -carryDepth, 0]
        L = [midPosition, -carryDepth, 0]

        curve1 = CurveFactory.makeCubicBezier(A, B, C, D)
        curve2 = CurveFactory.makeCubicBezier(D, E, F, G)
        curve3 = CurveFactory.makeCubicBezier(G, H, I, J)
        curve4 = CurveFactory.makeCubicBezier(J, K, L, A)

        self.ballCurve = Multicurve([curve1, curve2, curve3, curve4])
        self.handCurveL = Multicurve(
            [CurveFactory.makeLineSegment(G, D), curve2])
        self.handCurveR = Multicurve(
            [CurveFactory.makeLineSegment(A, J), curve4])

        # draw ball curve path  for illustration
        path = Mesh(
            CurveGeometry(self.ballCurve),
            LineDashedMaterial(color=[1, 1, 0.5],
                               dashLength=0.05,
                               gapLength=0.05,
                               lineWidth=1))
        self.scene.add(path)

        scale = 0.8
        airTime = 3 * scale
        holdTime = 1 * scale
        self.orbitTime = 2 * (airTime + holdTime)
        self.ballTimeTween = Tween(timeList=[
            0, airTime, airTime + holdTime, 2 * airTime + holdTime,
            self.orbitTime
        ],
                                   valueList=[0, 0.25, 0.50, 0.75, 1],
                                   loop=True)

        self.handTimeTween = Tween(
            timeList=[0, self.orbitTime / 3 - holdTime, self.orbitTime / 3],
            valueList=[0, 0.5, 1],
            loop=True)

        self.time = 0