Exemple #1
0
    def loadscene(self, count=0, coord=[0, 0]):
        diffuseImage = QTextureImage()
        diffuseImage.setSource(QUrl.fromLocalFile(OUTPUT_DIR + 'output.png'))
        self.normalDiffuseSpecularMapMaterial.diffuse().addTextureImage(
            diffuseImage)
        background = QImage()
        background.load(OUTPUT_DIR + 'output.png')

        # Background Plane
        self.planeEntity.mesh().setWidth(20.0 * background.width() /
                                         background.height())
        self.planeEntity.addComponent(self.normalDiffuseSpecularMapMaterial)

        self.obj = MainObject(self.m_rootEntity)
        self.obj.loadObject(count)
        self.obj.setPosition(QVector3D(0.0, 0.0, 0.0))
        self.obj.setScale(self.planeEntity.mesh().height() /
                          background.height())

        coord = [
            (self.planeEntity.mesh().width() / background.width()) * coord[0],
            (self.planeEntity.mesh().height() / background.height()) * coord[1]
        ]
        self.obj.setPosition(QVector3D(float(coord[0]), -1.0,
                                       -float(coord[1])))

        self.listOfObjects.append(self.obj)
Exemple #2
0
    def __init__(self, rootEntity):
        super(SceneModifier, self).__init__()

        self.m_rootEntity = rootEntity
        self.listOfObjects = []
        self.switchModelCount = 0

        self.normalDiffuseSpecularMapMaterial = QNormalDiffuseSpecularMapMaterial(
        )
        self.normalDiffuseSpecularMapMaterial.setTextureScale(1.0)
        self.normalDiffuseSpecularMapMaterial.setShininess(80.0)
        self.normalDiffuseSpecularMapMaterial.setAmbient(
            QColor.fromRgbF(1.0, 1.0, 1.0, 1.0))

        diffuseImage = QTextureImage()
        diffuseImage.setSource(QUrl.fromLocalFile('loading.png'))
        self.normalDiffuseSpecularMapMaterial.diffuse().addTextureImage(
            diffuseImage)
        background = QImage()
        background.load('loading.png')

        self.planeEntity = PlaneEntity(self.m_rootEntity)
        self.planeEntity.mesh().setHeight(20.0)
        self.planeEntity.mesh().setWidth(20.0 * background.width() /
                                         background.height())
        self.planeEntity.mesh().setMeshResolution(QSize(5, 5))
        self.planeEntity.m_transform.setRotationZ(180.0)
        self.planeEntity.addComponent(self.normalDiffuseSpecularMapMaterial)
Exemple #3
0
class MainObject(QEntity):
    def __init__(self, parent=None):
        super(MainObject, self).__init__(parent)

        self.m_object = RenderableEntity(self)

        self.m_objectMaterial = QNormalDiffuseMapMaterial()

        self.m_objectImage = QTextureImage()
        self.m_objectNormalImage = QTextureImage()

        self.m_object.addComponent(self.m_objectMaterial)

        self.m_objectMaterial.diffuse().addTextureImage(self.m_objectImage)
        self.m_objectMaterial.normal().addTextureImage(
            self.m_objectNormalImage)

        self.m_objectMaterial.setShininess(80.0)
        # self.m_objectMaterial.setTextureScale(1.0)
        # self.m_objectMaterial.setAmbient(QColor.fromRgbF(1.0, 1.0, 1.0, 1.0))

    def loadObject(self, index):
        self.m_object.mesh().setSource(
            QUrl.fromLocalFile(OUTPUT_DIR + 'object' + str(index) + '.obj'))

        self.m_objectImage.setSource(
            QUrl.fromLocalFile(OUTPUT_DIR + 'object' + str(index) + '.png'))
        self.m_objectNormalImage.setSource(
            QUrl.fromLocalFile('qt_3dviewer/exampleresources/normal.png'))

    def setPosition(self, pos):
        self.m_object.transform().setTranslation(pos)

    def position(self):
        return self.m_object.transform().translation()

    def setScale(self, scale):
        self.m_object.transform().setScale(scale)

    def scale(self):
        return self.m_object.transform().scale()

    def setRotationX(self):
        self.m_object.transform().setRotationX(
            self.m_object.transform().rotationX() + 2)

    def setRotationY(self):
        self.m_object.transform().setRotationY(
            self.m_object.transform().rotationY() + 2)

    def setRotationZ(self):
        self.m_object.transform().setRotationZ(
            self.m_object.transform().rotationZ() + 2)
Exemple #4
0
    def __init__(self, parent=None):
        super(MainObject, self).__init__(parent)

        self.m_object = RenderableEntity(self)

        self.m_objectMaterial = QNormalDiffuseMapMaterial()

        self.m_objectImage = QTextureImage()
        self.m_objectNormalImage = QTextureImage()

        self.m_object.addComponent(self.m_objectMaterial)

        self.m_objectMaterial.diffuse().addTextureImage(self.m_objectImage)
        self.m_objectMaterial.normal().addTextureImage(
            self.m_objectNormalImage)

        self.m_objectMaterial.setShininess(80.0)
    def __init__(self, parent=None):
        super(Barrel, self).__init__(parent)

        self.m_bumps = Barrel.NoBumps
        self.m_diffuseColor = Barrel.Red
        self.m_specularColor = Barrel.None_
        self.m_material = QNormalDiffuseSpecularMapMaterial()
        self.m_diffuseTexture = self.m_material.diffuse()
        self.m_normalTexture = self.m_material.normal()
        self.m_specularTexture = self.m_material.specular()
        self.m_diffuseTextureImage = QTextureImage()
        self.m_normalTextureImage = QTextureImage()
        self.m_specularTextureImage = QTextureImage()

        self.mesh().setSource(
            QUrl.fromLocalFile('assets/metalbarrel/metal_barrel.obj'))
        self.transform().setScale(0.03)

        self.m_diffuseTexture.addTextureImage(self.m_diffuseTextureImage)
        self.m_normalTexture.addTextureImage(self.m_normalTextureImage)
        self.m_specularTexture.addTextureImage(self.m_specularTextureImage)

        self.setNormalTextureSource()
        self.setDiffuseTextureSource()
        self.setSpecularTextureSource()
        self.m_material.setShininess(10.0)
        self.addComponent(self.m_material)
    def __init__(self, parent=None):
        super(HousePlant, self).__init__(parent)

        self.m_pot = RenderableEntity(self)
        self.m_plant = RenderableEntity(self.m_pot)
        self.m_cover = RenderableEntity(self.m_pot)

        self.m_potMaterial = QNormalDiffuseMapMaterial()
        self.m_plantMaterial = QNormalDiffuseMapAlphaMaterial()
        self.m_coverMaterial = QNormalDiffuseMapMaterial()

        self.m_potImage = QTextureImage()
        self.m_potNormalImage = QTextureImage()
        self.m_plantImage = QTextureImage()
        self.m_plantNormalImage = QTextureImage()
        self.m_coverImage = QTextureImage()
        self.m_coverNormalImage = QTextureImage()

        self.m_plantType = HousePlant.Bamboo
        self.m_potShape = HousePlant.Cross

        self.m_pot.transform().setScale(0.03)
        self.m_pot.addComponent(self.m_potMaterial)
        self.m_plant.addComponent(self.m_plantMaterial)
        self.m_cover.addComponent(self.m_coverMaterial)

        self.m_potMaterial.diffuse().addTextureImage(self.m_potImage)
        self.m_potMaterial.normal().addTextureImage(self.m_potNormalImage)
        self.m_plantMaterial.diffuse().addTextureImage(self.m_plantImage)
        self.m_plantMaterial.normal().addTextureImage(self.m_plantNormalImage)
        self.m_coverMaterial.diffuse().addTextureImage(self.m_coverImage)
        self.m_coverMaterial.normal().addTextureImage(self.m_coverNormalImage)

        self.updatePlantType()
        self.updatePotShape()

        self.m_coverImage.setSource(
            QUrl.fromLocalFile('assets/houseplants/cover.webp'))
        self.m_coverNormalImage.setSource(
            QUrl.fromLocalFile('assets/houseplants/cover_normal.webp'))
        self.m_potImage.setSource(
            QUrl.fromLocalFile('assets/houseplants/pot.webp'))
        self.m_potNormalImage.setSource(
            QUrl.fromLocalFile('assets/houseplants/pot_normal.webp'))

        self.m_potMaterial.setShininess(10.0)
        self.m_potMaterial.setSpecular(QColor.fromRgbF(0.75, 0.75, 0.75, 1.0))

        self.m_plantMaterial.setShininess(10.0)

        self.m_coverMaterial.setSpecular(QColor.fromRgbF(
            0.05, 0.05, 0.05, 1.0))
        self.m_coverMaterial.setShininess(5.0)
class HousePlant(QEntity):

    # PotShape
    (Cross, Square, Triangle, Sphere) = range(4)

    potNames = ('cross', 'square', 'triangle', 'sphere')

    # Plant
    (Bamboo, Palm, Pine, Spikes, Shrub) = range(5)

    plantNames = ('bamboo', 'palm', 'pine', 'spikes', 'shrub')

    def __init__(self, parent=None):
        super(HousePlant, self).__init__(parent)

        self.m_pot = RenderableEntity(self)
        self.m_plant = RenderableEntity(self.m_pot)
        self.m_cover = RenderableEntity(self.m_pot)

        self.m_potMaterial = QNormalDiffuseMapMaterial()
        self.m_plantMaterial = QNormalDiffuseMapAlphaMaterial()
        self.m_coverMaterial = QNormalDiffuseMapMaterial()

        self.m_potImage = QTextureImage()
        self.m_potNormalImage = QTextureImage()
        self.m_plantImage = QTextureImage()
        self.m_plantNormalImage = QTextureImage()
        self.m_coverImage = QTextureImage()
        self.m_coverNormalImage = QTextureImage()

        self.m_plantType = HousePlant.Bamboo
        self.m_potShape = HousePlant.Cross

        self.m_pot.transform().setScale(0.03)
        self.m_pot.addComponent(self.m_potMaterial)
        self.m_plant.addComponent(self.m_plantMaterial)
        self.m_cover.addComponent(self.m_coverMaterial)

        self.m_potMaterial.diffuse().addTextureImage(self.m_potImage)
        self.m_potMaterial.normal().addTextureImage(self.m_potNormalImage)
        self.m_plantMaterial.diffuse().addTextureImage(self.m_plantImage)
        self.m_plantMaterial.normal().addTextureImage(self.m_plantNormalImage)
        self.m_coverMaterial.diffuse().addTextureImage(self.m_coverImage)
        self.m_coverMaterial.normal().addTextureImage(self.m_coverNormalImage)

        self.updatePlantType()
        self.updatePotShape()

        self.m_coverImage.setSource(
            QUrl.fromLocalFile('assets/houseplants/cover.webp'))
        self.m_coverNormalImage.setSource(
            QUrl.fromLocalFile('assets/houseplants/cover_normal.webp'))
        self.m_potImage.setSource(
            QUrl.fromLocalFile('assets/houseplants/pot.webp'))
        self.m_potNormalImage.setSource(
            QUrl.fromLocalFile('assets/houseplants/pot_normal.webp'))

        self.m_potMaterial.setShininess(10.0)
        self.m_potMaterial.setSpecular(QColor.fromRgbF(0.75, 0.75, 0.75, 1.0))

        self.m_plantMaterial.setShininess(10.0)

        self.m_coverMaterial.setSpecular(QColor.fromRgbF(
            0.05, 0.05, 0.05, 1.0))
        self.m_coverMaterial.setShininess(5.0)

    def setPotShape(self, shape):
        if self.m_potShape != shape:
            self.m_potShape = shape
            self.updatePotShape()

    def potShape(self):
        return self.m_potShape

    def setPlantType(self, plant):
        if self.m_plantType != plant:
            self.m_plantType = plant
            self.updatePlantType()

    def plantType(self):
        return self.m_plantType

    def setPosition(self, pos):
        self.m_pot.transform().setTranslation(pos)

    def position(self):
        return self.m_pot.transform().translation()

    def setScale(self, scale):
        self.m_pot.transform().setScale(scale)

    def scale(self):
        return self.m_pot.transform().scale()

    def updatePotShape(self):
        self.m_pot.mesh().setSource(
            QUrl.fromLocalFile('assets/houseplants/' +
                               HousePlant.potNames[self.m_potShape] +
                               '-pot.obj'))
        self.m_plant.mesh().setSource(
            QUrl.fromLocalFile('assets/houseplants/' +
                               HousePlant.potNames[self.m_potShape] + '-' +
                               HousePlant.plantNames[self.m_plantType] +
                               '.obj'))

    def updatePlantType(self):
        self.m_plant.mesh().setSource(
            QUrl.fromLocalFile('assets/houseplants/' +
                               HousePlant.potNames[self.m_potShape] + '-' +
                               HousePlant.plantNames[self.m_plantType] +
                               '.obj'))

        self.m_plantImage.setSource(
            QUrl.fromLocalFile('assets/houseplants/' +
                               HousePlant.plantNames[self.m_plantType] +
                               '.webp'))
        self.m_plantNormalImage.setSource(
            QUrl.fromLocalFile('assets/houseplants/' +
                               HousePlant.plantNames[self.m_plantType] +
                               '_normal.webp'))
class Barrel(RenderableEntity):

    # DiffuseColor
    (Red, Blue, Green, RustDiffuse, StainlessSteelDiffuse) = range(5)

    diffuseColorsName = ('red', 'blue', 'green', 'rust', 'stainless_steel')

    # SpecularColor
    (RustSpecular, StainlessSteelSpecular, None_) = range(3)

    specularColorsName = ('_rust', '_stainless_steel', '')

    # Bumps
    (NoBumps, SoftBumps, MiddleBumps, HardBumps) = range(4)

    bumpsName = ('no_bumps', 'soft_bumps', 'middle_bumps', 'hard_bumps')

    def __init__(self, parent=None):
        super(Barrel, self).__init__(parent)

        self.m_bumps = Barrel.NoBumps
        self.m_diffuseColor = Barrel.Red
        self.m_specularColor = Barrel.None_
        self.m_material = QNormalDiffuseSpecularMapMaterial()
        self.m_diffuseTexture = self.m_material.diffuse()
        self.m_normalTexture = self.m_material.normal()
        self.m_specularTexture = self.m_material.specular()
        self.m_diffuseTextureImage = QTextureImage()
        self.m_normalTextureImage = QTextureImage()
        self.m_specularTextureImage = QTextureImage()

        self.mesh().setSource(
            QUrl.fromLocalFile('assets/metalbarrel/metal_barrel.obj'))
        self.transform().setScale(0.03)

        self.m_diffuseTexture.addTextureImage(self.m_diffuseTextureImage)
        self.m_normalTexture.addTextureImage(self.m_normalTextureImage)
        self.m_specularTexture.addTextureImage(self.m_specularTextureImage)

        self.setNormalTextureSource()
        self.setDiffuseTextureSource()
        self.setSpecularTextureSource()
        self.m_material.setShininess(10.0)
        self.addComponent(self.m_material)

    def setDiffuse(self, diffuse):
        if self.m_diffuseColor != diffuse:
            self.m_diffuseColor = diffuse
            self.setDiffuseTextureSource()

    def diffuse(self):
        return self.m_diffuseColor

    def setSpecular(self, specular):
        if self.m_specularColor != specular:
            self.m_specularColor = specular
            self.setSpecularTextureSource()

    def specular(self):
        return self.m_specularColor

    def setBumps(self, bumps):
        if self.m_bumps != bumps:
            self.m_bumps = bumps
            self.setNormalTextureSource()

    def bumps(self):
        return self.m_bumps

    def setShininess(self, shininess):
        if self.m_material.shininess() != shininess:
            self.m_material.setShininess(shininess)

    def shininess(self):
        return self.m_material.shininess()

    def setNormalTextureSource(self):
        self.m_normalTextureImage.setSource(
            QUrl.fromLocalFile('assets/metalbarrel/normal_' +
                               Barrel.bumpsName[self.m_bumps] + '.webp'))

    def setDiffuseTextureSource(self):
        self.m_diffuseTextureImage.setSource(
            QUrl.fromLocalFile('assets/metalbarrel/diffus_' +
                               Barrel.diffuseColorsName[self.m_diffuseColor] +
                               '.webp'))

    def setSpecularTextureSource(self):
        self.m_specularTextureImage.setSource(
            QUrl.fromLocalFile(
                'assets/metalbarrel/specular' +
                Barrel.specularColorsName[self.m_specularColor] + '.webp'))
camController = QFirstPersonCameraController(sceneRoot)
camController.setCamera(basicCamera)

# Scene floor.
planeEntity = PlaneEntity(sceneRoot)
planeEntity.mesh().setHeight(100.0)
planeEntity.mesh().setWidth(100.0)
planeEntity.mesh().setMeshResolution(QSize(20, 20))

normalDiffuseSpecularMapMaterial = QNormalDiffuseSpecularMapMaterial()
normalDiffuseSpecularMapMaterial.setTextureScale(10.0)
normalDiffuseSpecularMapMaterial.setShininess(80.0)
normalDiffuseSpecularMapMaterial.setAmbient(QColor.fromRgbF(
    0.2, 0.2, 0.2, 1.0))

diffuseImage = QTextureImage()
diffuseImage.setSource(
    QUrl.fromLocalFile('assets/textures/pattern_09/diffuse.webp'))
normalDiffuseSpecularMapMaterial.diffuse().addTextureImage(diffuseImage)

specularImage = QTextureImage()
specularImage.setSource(
    QUrl.fromLocalFile('assets/textures/pattern_09/specular.webp'))
normalDiffuseSpecularMapMaterial.specular().addTextureImage(specularImage)

normalImage = QTextureImage()
normalImage.setSource(
    QUrl.fromLocalFile('assets/textures/pattern_09/normal.webp'))
normalDiffuseSpecularMapMaterial.normal().addTextureImage(normalImage)

planeEntity.addComponent(normalDiffuseSpecularMapMaterial)