示例#1
0
文件: 10-unlit.py 项目: gkzscs/kuesa
    def __init__(self):
        super(Window, self).__init__()

        # Default set-up
        self.rootEntity = Kuesa.SceneEntity()
        self.rootEntity.addComponent(DefaultEnvMap(self.rootEntity))

        self.camera().setPosition(QVector3D(5, 1.5, 5))
        self.camera().setViewCenter(QVector3D(0, 0.5, 0))
        self.camera().setUpVector(QVector3D(0, 1, 0))
        self.camera().setAspectRatio(16. / 9.)

        self.camController = Qt3DExtras.QOrbitCameraController(self.rootEntity)
        self.camController.setCamera(self.camera())

        self.fg = Kuesa.ForwardRenderer()
        self.fg.setCamera(self.camera())
        self.fg.setClearColor("white")
        self.setActiveFrameGraph(self.fg)

        # Load a glTF model
        self.gltfImporter = Kuesa.GLTF2Importer(self.rootEntity)
        self.gltfImporter.setSceneEntity(self.rootEntity)
        self.gltfImporter.setSource(assetsUrl() + "/models/duck/Duck.glb")
        self.gltfImporter.statusChanged.connect(self.importerLoaded)

        # Skybox creation
        envmap_root = assetsUrl() + "/envmaps/pink_sunrise"
        envmap_name = "pink_sunrise" + ("_16f" if platform.system() == "Darwin"
                                        else "") + "_radiance"
        self.skybox = Kuesa.Skybox(self.rootEntity)
        self.skybox.setBaseName(envmap_root + "/" + envmap_name)
        self.skybox.setExtension(".dds")

        self.setRootEntity(self.rootEntity)
示例#2
0
    def __init__(self):
        super(Window, self).__init__()

        # Default set-up
        self.rootEntity = Kuesa.SceneEntity()
        self.rootEntity.addComponent(DefaultEnvMap(self.rootEntity))

        self.camera().setPosition(QVector3D(5, 1.5, 5))
        self.camera().setViewCenter(QVector3D(0, 0.5, 0))
        self.camera().setUpVector(QVector3D(0, 1, 0))
        self.camera().setAspectRatio(16. / 9.)

        self.camController = Qt3DExtras.QOrbitCameraController(self.rootEntity)
        self.camController.setCamera(self.camera())

        self.fg = Kuesa.ForwardRenderer()
        self.fg.setCamera(self.camera())
        self.fg.setClearColor("white")
        self.setActiveFrameGraph(self.fg)

        # Load a glTF model
        self.gltfImporter = Kuesa.GLTF2Importer(self.rootEntity)
        self.gltfImporter.setSceneEntity(self.rootEntity)
        self.gltfImporter.setSource(assetsUrl() + "/models/duck/Duck.glb")
        self.gltfImporter.statusChanged.connect(self.importerLoaded)

        # Skybox creation
        envmap_root = assetsUrl() + "/envmaps/pink_sunrise"
        envmap_name = "pink_sunrise" + ("_16f" if platform.system() == "Darwin"
                                        else "") + "_radiance"
        self.skybox = Kuesa.Skybox(self.rootEntity)
        self.skybox.setBaseName(envmap_root + "/" + envmap_name)
        self.skybox.setExtension(".dds")

        # Creation of a few post-processing effects
        self.blurFx = Kuesa.GaussianBlurEffect()
        self.blurFx.setBlurPassCount(8)

        self.dofFx = Kuesa.DepthOfFieldEffect()
        self.dofFx.setFocusRange(3.1)
        self.dofFx.setRadius(21.)
        self.dofFx.setFocusDistance(6.6)

        self.threshFx = Kuesa.ThresholdEffect()
        self.threshFx.setThreshold(.1)

        # self.fg.addPostProcessingEffect(self.blurFx)
        # self.fg.addPostProcessingEffect(self.dofFx)
        self.fg.addPostProcessingEffect(self.threshFx)

        self.setRootEntity(self.rootEntity)
示例#3
0
文件: 1-cube.py 项目: gkzscs/kuesa
    def __init__(self):
        super(Window, self).__init__()

        # Scene creation
        # Kuesa content must be child of a Kuesa.SceneEntity.
        # These entites are all themselves standard Qt3D::QEntity
        self.rootEntity = Kuesa.SceneEntity()

        # GLTF2Importer will load the glTF 2.0 content and add
        # it as a child in the SceneEntity.
        self.gltfImporter = Kuesa.GLTF2Importer(self.rootEntity)
        self.gltfImporter.setSceneEntity(self.rootEntity)
        self.gltfImporter.setSource(assetsUrl() + "/models/Box.glb")

        # Since Kuesa is based on a PBR pipeline, we need an environment map.
        self.rootEntity.addComponent(DefaultEnvMap(self.rootEntity))

        # Camera.
        self.camera().setPosition(QVector3D(10, 1.5, 10))
        self.camera().setViewCenter(QVector3D(0, .5, 0))
        self.camera().setUpVector(QVector3D(0, 1, 0))
        self.camera().setAspectRatio(16. / 9.)

        # Camera controls.
        self.camController = Qt3DExtras.QOrbitCameraController(self.rootEntity)
        self.camController.setCamera(self.camera())

        # Frame graph.
        self.fg = Kuesa.ForwardRenderer()
        self.fg.setCamera(self.camera())
        self.fg.setClearColor("white")
        self.setActiveFrameGraph(self.fg)

        self.setRootEntity(self.rootEntity)
示例#4
0
    def __init__(self):
        super(Window, self).__init__()

        # Since we are going to use animations, we need to register
        # the Qt3D animation aspect :
        self.animationAspect = Qt3DAnimation.QAnimationAspect(self)
        self.registerAspect(self.animationAspect)

        # Default set-up
        self.rootEntity = Kuesa.SceneEntity()
        self.rootEntity.addComponent(DefaultEnvMap(self.rootEntity))

        self.camera().setPosition(QVector3D(25, 1.5, 25))
        self.camera().setViewCenter(QVector3D(0, 3, 0))
        self.camera().setUpVector(QVector3D(0, 1, 0))
        self.camera().setAspectRatio(16. / 9.)

        self.camController = Qt3DExtras.QOrbitCameraController(self.rootEntity)
        self.camController.setCamera(self.camera())

        self.fg = Kuesa.ForwardRenderer()
        self.fg.setCamera(self.camera())
        self.fg.setClearColor("white")
        self.setActiveFrameGraph(self.fg)

        # Load a glTF model
        self.gltfImporter = Kuesa.GLTF2Importer(self.rootEntity)
        self.gltfImporter.setSceneEntity(self.rootEntity)
        self.gltfImporter.setSource(assetsUrl() +
                                    "/models/InterpolationTest.glb")
        self.gltfImporter.statusChanged.connect(self.on_sceneLoaded)

        self.setRootEntity(self.rootEntity)
示例#5
0
    def __init__(self):
        super(Window, self).__init__()

        # Default set-up
        self.rootEntity = Kuesa.SceneEntity()
        self.rootEntity.addComponent(DefaultEnvMap(self.rootEntity))

        self.camera().setPosition(QVector3D(5, 1.5, 5))
        self.camera().setViewCenter(QVector3D(0, 0.5, 0))
        self.camera().setUpVector(QVector3D(0, 1, 0))
        self.camera().setAspectRatio(16. / 9.)

        self.camController = Qt3DExtras.QOrbitCameraController(self.rootEntity)
        self.camController.setCamera(self.camera())

        self.fg = Kuesa.ForwardRenderer()
        self.fg.setCamera(self.camera())
        self.fg.setClearColor("white")
        self.setActiveFrameGraph(self.fg)

        # Load a glTF model
        self.gltfImporter = Kuesa.GLTF2Importer(self.rootEntity)
        self.gltfImporter.setSceneEntity(self.rootEntity)
        self.gltfImporter.setSource(assetsUrl() + "/models/duck/Duck.glb")

        # Skybox creation
        envmap_root = assetsUrl() + "/envmaps/pink_sunrise"
        envmap_name = "pink_sunrise" + ("_16f" if platform.system() == "Darwin"
                                        else "") + "_radiance"
        self.skybox = Kuesa.Skybox(self.rootEntity)
        self.skybox.setBaseName(envmap_root + "/" + envmap_name)
        self.skybox.setExtension(".dds")

        # Tonemapping and gamma correction
        self.toneMapAlgorithm = Kuesa.ToneMappingAndGammaCorrectionEffect.ToneMapping(
        )
        self.fg.setExposure(2)
        self.fg.setGamma(2.8)
        self.fg.setToneMappingAlgorithm(self.toneMapAlgorithm)

        # Cycle through the various tonemapping algorithms provided by Kuesa
        timer = QTimer(self)
        timer.setInterval(1000)
        timer.timeout.connect(self.changeTonemapping)
        timer.start()

        self.setRootEntity(self.rootEntity)
示例#6
0
文件: 10-unlit.py 项目: gkzscs/kuesa
    def importerLoaded(self, status):
        if status != Kuesa.GLTF2Importer.Status.Ready:
            return

        parent = self.rootEntity.entity("KuesaEntity_0")

        parent.setObjectName("KuesaEntity_0")
        orig_entity = self.rootEntity.entity("KuesaEntity_2").childNodes()[1]
        orig_geometry = orig_entity.childNodes()[0]
        orig_material = orig_entity.childNodes()[1]
        orig_entity.removeComponent(orig_material)

        new_material = Kuesa.UnlitMaterial(orig_material.parent())

        # Materials need both an effect and material properties.
        # First create the Effect
        new_effect = Kuesa.UnlitEffect(new_material)

        new_effect.setBaseColorMapEnabled(False)
        new_effect.setUsingColorAttribute(True)
        new_effect.setDoubleSided(True)
        new_effect.setUseSkinning(False)
        new_effect.setOpaque(True)
        new_effect.setAlphaCutoffEnabled(True)

        new_material.setEffect(new_effect)

        # Then the properties
        new_props = Kuesa.UnlitProperties(new_material)

        new_props.setBaseColorUsesTexCoord1(True)
        new_props.setBaseColorFactor("white")

        # Load a texture
        new_tex = Qt3DRender.QTextureLoader(self.rootEntity)
        new_tex.setSource(assetsUrl() + "/models/car/KDAB.png")
        new_tex.setMinificationFilter(
            Qt3DRender.QAbstractTexture.LinearMipMapLinear)
        new_tex.setMagnificationFilter(Qt3DRender.QAbstractTexture.Linear)
        new_tex.wrapMode().setX(Qt3DRender.QTextureWrapMode.Repeat)
        new_tex.wrapMode().setY(Qt3DRender.QTextureWrapMode.Repeat)
        new_tex.setGenerateMipMaps(1)

        new_props.setBaseColorMap(new_tex)

        new_material.setUnlitProperties(new_props)

        orig_entity.addComponent(new_material)
示例#7
0
    def __init__(self):
        super(Window, self).__init__()

        # Default set-up
        self.rootEntity = Kuesa.SceneEntity()
        self.rootEntity.addComponent(DefaultEnvMap(self.rootEntity))

        self.camera().setPosition(QVector3D(25, 1.5, 25))
        self.camera().setViewCenter(QVector3D(0, 3, 0))
        self.camera().setUpVector(QVector3D(0, 1, 0))
        self.camera().setAspectRatio(16. / 9.)

        self.camController = Qt3DExtras.QOrbitCameraController(self.rootEntity)
        self.camController.setCamera(self.camera())

        self.fg = Kuesa.ForwardRenderer()
        self.fg.setCamera(self.camera())
        self.fg.setClearColor("white")
        self.setActiveFrameGraph(self.fg)

        # Load a glTF model
        self.gltfImporter = Kuesa.GLTF2Importer(self.rootEntity)
        self.gltfImporter.setSceneEntity(self.rootEntity)
        self.gltfImporter.setSource(assetsUrl() +
                                    "/models/InterpolationTest.glb")

        # When opening this model in gltfEditor, we can see :
        # - Multiple entities :
        #   Cube, Cube.001, Cube.002, Light, Plane...
        # - Multiple meshes :
        #   Cube.001_0, Cube.002_0, ...
        # - Multiple materials :
        #   Material, Material.001, ...
        # etc.

        # Let's use Kuesa to change one of these entities on-the-fly.
        # We need to wait for the glTF file to be fully loaded in order to do that :
        self.gltfImporter.statusChanged.connect(self.on_sceneLoaded)

        self.setRootEntity(self.rootEntity)
示例#8
0
    def __init__(self):
        super(Window, self).__init__()

        # Default set-up - by now you know the drill :-)
        self.rootEntity = Kuesa.SceneEntity()
        self.rootEntity.addComponent(DefaultEnvMap(self.rootEntity))

        self.gltfImporter = Kuesa.GLTF2Importer(self.rootEntity)
        self.gltfImporter.setSceneEntity(self.rootEntity)
        self.gltfImporter.setSource(assetsUrl() + "/models/duck/Duck.glb")

        self.camera().setPosition(QVector3D(10, 1.5, 10))
        self.camera().setViewCenter(QVector3D(0, .5, 0))
        self.camera().setUpVector(QVector3D(0, 1, 0))
        self.camera().setAspectRatio(16. / 9.)

        self.camController = Qt3DExtras.QOrbitCameraController(self.rootEntity)
        self.camController.setCamera(self.camera())

        self.fg = Kuesa.ForwardRenderer()
        self.fg.setCamera(self.camera())
        self.fg.setClearColor("white")
        self.setActiveFrameGraph(self.fg)

        envmap_root = assetsUrl() + "/envmaps/pink_sunrise"
        envmap_name = "pink_sunrise" + ("_16f" if platform.system() == "Darwin"
                                        else "") + "_radiance"
        self.skybox = Kuesa.Skybox(self.rootEntity)
        self.skybox.setBaseName(envmap_root + "/" + envmap_name)
        self.skybox.setExtension(".dds")

        # Now we create some lights.
        # All lights have an intensity and a color.
        # Specific light types have relevant additional properties.
        # Point light
        self.pointLightEntity = Qt3DCore.QEntity(self.rootEntity)
        self.pointLightTransform = Qt3DCore.QTransform(self.pointLightEntity)
        self.pointLightTransform.setTranslation(QVector3D(20, -10, -10))

        self.pointLight = Kuesa.PointLight(self.pointLightEntity)
        self.pointLight.setIntensity(1000.0)
        self.pointLight.setColor("red")

        self.pointLightEntity.addComponent(self.pointLightTransform)
        self.pointLightEntity.addComponent(self.pointLight)

        # Spot light
        self.spotLightEntity = Qt3DCore.QEntity(self.rootEntity)
        self.spotLightTransform = Qt3DCore.QTransform(self.spotLightEntity)
        self.spotLightTransform.setTranslation(QVector3D(-10, 10, 10))

        self.spotLight = Kuesa.SpotLight(self.spotLightEntity)
        self.spotLight.setIntensity(1000.0)
        self.spotLight.setColor("green")
        self.spotLight.setInnerConeAngle(50)
        self.spotLight.setOuterConeAngle(100)
        self.spotLight.setRange(1000)

        self.spotLightEntity.addComponent(self.spotLightTransform)
        self.spotLightEntity.addComponent(self.spotLight)

        # Directional light
        self.directionalLightEntity = Qt3DCore.QEntity(self.rootEntity)
        self.directionalLightTransform = Qt3DCore.QTransform(
            self.directionalLightEntity)

        self.directionalLight = Kuesa.DirectionalLight(
            self.directionalLightEntity)
        self.directionalLight.setIntensity(100.0)
        self.directionalLight.setColor("blue")
        self.directionalLight.setDirection(QVector3D(10, 10, -10))

        self.directionalLightEntity.addComponent(
            self.directionalLightTransform)
        self.directionalLightEntity.addComponent(self.directionalLight)

        self.setRootEntity(self.rootEntity)