Ejemplo n.º 1
0
def createScene():
    # Root entity.
    rootEntity = QEntity()

    # Material.
    material = QPhongMaterial(rootEntity)

    # Torus.
    torusEntity = QEntity(rootEntity)
    torusMesh = QTorusMesh()
    torusMesh.setRadius(5)
    torusMesh.setMinorRadius(1)
    torusMesh.setRings(100)
    torusMesh.setSlices(20)

    torusTransform = QTransform()
    torusTransform.setScale3D(QVector3D(1.5, 1.0, 0.5))
    torusTransform.setRotation(
        QQuaternion.fromAxisAndAngle(QVector3D(1.0, 0.0, 0.0), 45.0))

    torusEntity.addComponent(torusMesh)
    torusEntity.addComponent(torusTransform)
    torusEntity.addComponent(material)

    # Sphere.
    sphereEntity = QEntity(rootEntity)
    sphereMesh = QSphereMesh()
    sphereMesh.setRadius(3)

    sphereEntity.addComponent(sphereMesh)
    sphereEntity.addComponent(material)

    return rootEntity
Ejemplo n.º 2
0
    def createScene():
        # Root entity
        rootEntity = QEntity()

        # Material
        material = QPhongMaterial(rootEntity)

        # Torus
        torusEntity = QEntity(rootEntity)
        # Qt3DExtras.QTorusMesh *
        torusMesh = QTorusMesh()
        torusMesh.setRadius(5)
        torusMesh.setMinorRadius(1)
        torusMesh.setRings(100)
        torusMesh.setSlices(20)

        # Qt3DCore.QTransform *
        torusTransform = QTransform()
        torusTransform.setScale3D(QVector3D(1.5, 1, 0.5))
        torusTransform.setRotation(
            QQuaternion.fromAxisAndAngle(QVector3D(1, 0, 0), 45.0))

        torusEntity.addComponent(torusMesh)
        torusEntity.addComponent(torusTransform)
        torusEntity.addComponent(material)

        # Sphere
        sphereEntity = QEntity(rootEntity)
        sphereMesh = QSphereMesh()
        sphereMesh.setRadius(3)

        # Qt3DCore.QTransform *
        sphereTransform = QTransform()
        # OrbitTransformController *
        controller = OrbitTransformController(sphereTransform)
        controller.setTarget(sphereTransform)
        controller.setRadius(20.0)
        # QPropertyAnimation *
        sphereRotateTransformAnimation = QPropertyAnimation(sphereTransform)
        sphereRotateTransformAnimation.setTargetObject(controller)
        sphereRotateTransformAnimation.setPropertyName(b"angle")
        sphereRotateTransformAnimation.setStartValue(0)
        sphereRotateTransformAnimation.setEndValue(360)
        sphereRotateTransformAnimation.setDuration(10000)
        sphereRotateTransformAnimation.setLoopCount(-1)
        sphereRotateTransformAnimation.start()

        sphereEntity.addComponent(sphereMesh)
        sphereEntity.addComponent(sphereTransform)
        sphereEntity.addComponent(material)

        return rootEntity
Ejemplo n.º 3
0
    def create_atom(self, atom: Atom, root_entity, color: QColor):
        if atom.element in self._materials_dict:
            material = self._materials_dict[atom.element]
        else:
            material = QDiffuseSpecularMaterial(root_entity)
            material.setDiffuse(color)
            material.setAmbient(color.darker(200))
            self._materials_dict[atom.element] = material

        sphere_entity = QEntity(root_entity)
        sphere_mesh = QSphereMesh()
        sphere_mesh.setRadius(0.5)
        sphere_transform = QTransform()
        sphere_transform.setTranslation(QVector3D(*atom.coords_cartesian))

        sphere_entity.addComponent(sphere_mesh)
        sphere_entity.addComponent(sphere_transform)
        sphere_entity.addComponent(material)
Ejemplo n.º 4
0
    def add_sphere(self, r):
        """
        Helper method to add a sphere to the scene.

        Arguments:
            r: float, the radius of the sphere

        Returns:
            the QTransform of the sphere
        """
        sphere_entity = QEntity(self.scene)
        sphere_mesh = QSphereMesh()
        sphere_mesh.setRadius(r)
        sphere_entity.addComponent(sphere_mesh)
        sphere_transform = QTransform(self.scene)
        sphere_entity.addComponent(sphere_transform)
        if not hasattr(self, 'sphere_material'):
            self.sphere_material = QPhongMaterial(self.scene)
            self.sphere_material.setAmbient(util.hsl(0, 0, 50))
        sphere_entity.addComponent(self.sphere_material)

        return sphere_transform
Ejemplo n.º 5
0
    def add_sphere(self, color=util.hsl(0, 0, 50)):
        """
        Helper method to add a sphere to the scene.

        Arguments:
            color: QColor, the color of the sphere's material

        Returns:
            the QTransform of the sphere
        """
        sphere_entity = QEntity(self.scene)

        sphere_mesh = QSphereMesh()
        sphere_entity.addComponent(sphere_mesh)

        sphere_transform = QTransform(self.scene)
        sphere_entity.addComponent(sphere_transform)

        sphere_material = QPhongMaterial(self.scene)
        sphere_material.setDiffuse(color)
        sphere_entity.addComponent(sphere_material)

        return sphere_transform
Ejemplo n.º 6
0
    def createScene(self):
        for row in self.rdb["objRoot"]:
            for col in row:
                if col == None:
                    continue
                for obj in col:
                    pos = obj["position"]
                    node = QEntity(self.scene)
                    nodeTransform = QTransform()
                    nodeTransform.setTranslation(
                        QVector3D(pos["X"], -pos["Y"], pos["Z"]))
                    if obj["type"] == Consts.MODEL_TYPE:
                        #model objects
                        try:
                            model = self.rdb["modelsRef"][obj["data"]
                                                          ["modelID"]]
                            modelID = int(model['type'] + model['id'])

                            rot = obj["data"]["rotation"]
                            nodeTransform.setRotationX((rot["X"] / 512) * 90)
                            nodeTransform.setRotationY(-(rot["Y"] / 512) * 90)
                            nodeTransform.setRotationZ((rot["Z"] / 512) * 90)

                            node.addComponent(meshObject.meshObject(modelID))
                            material = QDiffuseSpecularMaterial(self.scene)
                            if int(model['type']
                                   ) == Consts.MODEL_TYPE_DOOR:  #door
                                #door are green
                                material.setDiffuse(QColor(0, 240, 0, 255))
                                material.setAmbient(QColor(0, 240, 0, 255))
                            elif "action" in obj["data"]:
                                #actionables are red
                                material.setDiffuse(QColor(240, 0, 0, 255))
                                material.setAmbient(QColor(240, 0, 0, 255))
                            else:
                                #everything else is light grey
                                material.setDiffuse(QColor(240, 240, 240, 255))
                                material.setAmbient(QColor(240, 240, 240, 255))

                            if self.dbg_wire:
                                #draw wireframes
                                wireNode = QEntity(self.scene)
                                nodeTransform2 = QTransform()
                                nodeTransform2.setMatrix(
                                    nodeTransform.matrix())
                                wireNode.addComponent(nodeTransform2)
                                material2 = QDiffuseSpecularMaterial(
                                    self.scene)

                                if self.treeView.highlightedID == obj['id']:
                                    material2.setAmbient(QColor(
                                        255, 0, 0, 255))
                                    material2.setDiffuse(QColor(
                                        255, 0, 0, 255))
                                else:
                                    material2.setAmbient(QColor(0, 0, 0, 255))
                                    material2.setDiffuse(QColor(0, 0, 0, 255))
                                wireNode.addComponent(material2)
                                wireNode.addComponent(
                                    meshObject.meshWireframe(modelID))
                            if self.dbg_normals:
                                meshObject.addMeshNormals(
                                    self.scene, modelID, nodeTransform)

                        except Exception as e:
                            import traceback
                            print(traceback.format_exc())
                            continue
                    elif obj['type'] == Consts.LIGHT_TYPE:
                        # light marker
                        mesh = QSphereMesh()
                        mesh.setRadius(10)
                        node.addComponent(mesh)
                        material = QDiffuseSpecularMaterial(self.scene)
                        material.setDiffuse(QColor(0, 0, 240, 255))
                        material.setAmbient(QColor(0, 0, 240, 255))
                    else:
                        #skip billboard painting
                        continue

                    node.addComponent(nodeTransform)
                    node.addComponent(material)

        #bilboard should be rendered after solids to avoid alpha blending oddities
        for row in self.rdb["objRoot"]:
            for col in row:
                if col == None:
                    continue
                for obj in col:
                    pos = obj["position"]
                    node = QEntity(self.scene)
                    nodeTransform = QTransform()
                    nodeTransform.setTranslation(
                        QVector3D(pos["X"], -pos["Y"], pos["Z"]))
                    if obj['type'] == 3:
                        # flat marker
                        with open(
                                'media/textures/%d/%d-0.PNG' %
                            (obj['data']['findex'], obj['data']['type']),
                                'rb') as img:
                            img.seek(0x10)
                            x, y = struct.unpack('>ii', img.read(8))
                            mesh = self.getMarker(x, y)

                            material = QTextureMaterial(self.scene)
                            texture = QTextureLoader(mesh)
                            texture.setSource(QUrl().fromLocalFile(
                                'media/textures/%d/%d-0.PNG' %
                                (obj['data']['findex'], obj['data']['type'])))
                            material.setTexture(texture)
                            # material.setAlphaBlendingEnabled(True)
                    else:
                        continue
                    node.addComponent(nodeTransform)
                    node.addComponent(material)
                    node.addComponent(mesh)

        return
Ejemplo n.º 7
0
    def __init__(self, rootEntity):
        super(SceneModifier, self).__init__()

        self.m_rootEntity = rootEntity

        # Torus shape data.
        self.m_torus = QTorusMesh()
        self.m_torus.setRadius(1.0)
        self.m_torus.setMinorRadius(0.4)
        self.m_torus.setRings(100)
        self.m_torus.setSlices(20)

        # TorusMesh transform.
        torusTransform = QTransform()
        torusTransform.setScale(2.0)
        torusTransform.setRotation(
            QQuaternion.fromAxisAndAngle(QVector3D(0.0, 1.0, 0.0), 25.0))
        torusTransform.setTranslation(QVector3D(5.0, 4.0, 0.0))

        torusMaterial = QPhongMaterial()
        torusMaterial.setDiffuse(QColor(0xbeb32b))

        # Torus.
        self.m_torusEntity = QEntity(self.m_rootEntity)
        self.m_torusEntity.addComponent(self.m_torus)
        self.m_torusEntity.addComponent(torusMaterial)
        self.m_torusEntity.addComponent(torusTransform)

        # Cone shape data.
        cone = QConeMesh()
        cone.setTopRadius(0.5)
        cone.setBottomRadius(1)
        cone.setLength(3)
        cone.setRings(50)
        cone.setSlices(20)

        # ConeMesh transform.
        coneTransform = QTransform()
        coneTransform.setScale(1.5)
        coneTransform.setRotation(
            QQuaternion.fromAxisAndAngle(QVector3D(1.0, 0.0, 0.0), 45.0))
        coneTransform.setTranslation(QVector3D(0.0, 4.0, -1.5))

        coneMaterial = QPhongMaterial()
        coneMaterial.setDiffuse(QColor(0x928327))

        # Cone.
        self.m_coneEntity = QEntity(self.m_rootEntity)
        self.m_coneEntity.addComponent(cone)
        self.m_coneEntity.addComponent(coneMaterial)
        self.m_coneEntity.addComponent(coneTransform)

        # Cylinder shape data.
        cylinder = QCylinderMesh()
        cylinder.setRadius(1)
        cylinder.setLength(3)
        cylinder.setRings(100)
        cylinder.setSlices(20)

        # CylinderMesh transform.
        cylinderTransform = QTransform()
        cylinderTransform.setScale(1.5)
        cylinderTransform.setRotation(
            QQuaternion.fromAxisAndAngle(QVector3D(1.0, 0.0, 0.0), 45.0))
        cylinderTransform.setTranslation(QVector3D(-5.0, 4.0, -1.5))

        cylinderMaterial = QPhongMaterial()
        cylinderMaterial.setDiffuse(QColor(0x928327))

        # Cylinder.
        self.m_cylinderEntity = QEntity(self.m_rootEntity)
        self.m_cylinderEntity.addComponent(cylinder)
        self.m_cylinderEntity.addComponent(cylinderMaterial)
        self.m_cylinderEntity.addComponent(cylinderTransform)

        # Cuboid shape data.
        cuboid = QCuboidMesh()

        # CuboidMesh transform.
        cuboidTransform = QTransform()
        cuboidTransform.setScale(4.0)
        cuboidTransform.setTranslation(QVector3D(5.0, -4.0, 0.0))

        cuboidMaterial = QPhongMaterial()
        cuboidMaterial.setDiffuse(QColor(0x665423))

        # Cuboid.
        self.m_cuboidEntity = QEntity(self.m_rootEntity)
        self.m_cuboidEntity.addComponent(cuboid)
        self.m_cuboidEntity.addComponent(cuboidMaterial)
        self.m_cuboidEntity.addComponent(cuboidTransform)

        # Plane shape data.
        planeMesh = QPlaneMesh()
        planeMesh.setWidth(2)
        planeMesh.setHeight(2)

        # Plane mesh transform.
        planeTransform = QTransform()
        planeTransform.setScale(1.3)
        planeTransform.setRotation(
            QQuaternion.fromAxisAndAngle(QVector3D(1.0, 0.0, 0.0), 45.0))
        planeTransform.setTranslation(QVector3D(0.0, -4.0, 0.0))

        planeMaterial = QPhongMaterial()
        planeMaterial.setDiffuse(QColor(0xa69929))

        # Plane.
        self.m_planeEntity = QEntity(self.m_rootEntity)
        self.m_planeEntity.addComponent(planeMesh)
        self.m_planeEntity.addComponent(planeMaterial)
        self.m_planeEntity.addComponent(planeTransform)

        # Sphere shape data.
        sphereMesh = QSphereMesh()
        sphereMesh.setRings(20)
        sphereMesh.setSlices(20)
        sphereMesh.setRadius(2)

        # Sphere mesh transform.
        sphereTransform = QTransform()
        sphereTransform.setScale(1.3)
        sphereTransform.setTranslation(QVector3D(-5.0, -4.0, 0.0))

        sphereMaterial = QPhongMaterial()
        sphereMaterial.setDiffuse(QColor(0xa69929))

        # Sphere.
        self.m_sphereEntity = QEntity(self.m_rootEntity)
        self.m_sphereEntity.addComponent(sphereMesh)
        self.m_sphereEntity.addComponent(sphereMaterial)
        self.m_sphereEntity.addComponent(sphereTransform)