Exemple #1
0
    def __init__(self, parent=None):
        """Initializes widgets of scene graph editor"""
        QtGui.QWidget.__init__(self, parent)

        self._root = iv.Separator()
        self._filePath = ""
        self.inspectorWidget = QInspectorWidget()
        self.previewWidget = QIVWidget(
            format=QtOpenGL.QGLFormat(QtOpenGL.QGL.SampleBuffers))
        self.previewWidget.sceneManager.background = ((0.7, 0.7, 0.8),
                                                      (0.0, 0.1, 0.3))

        mainLayout = QtGui.QVBoxLayout()
        mainLayout.setContentsMargins(2, 2, 0, 0)
        mainLayout.setSpacing(0)

        self._horiSplitter = QtGui.QSplitter(QtCore.Qt.Horizontal)
        self._horiSplitter.addWidget(self.inspectorWidget)
        self._horiSplitter.addWidget(self.previewWidget)

        self._vertSplitter = QtGui.QSplitter(QtCore.Qt.Vertical)
        self._vertSplitter.addWidget(self._horiSplitter)

        mainLayout.addWidget(self._vertSplitter)

        self.setLayout(mainLayout)
        self.setWindowTitle(self.applicationTitle())

        self.inspectorWidget.attach(self.previewWidget.sceneManager.scene)

        # timer for inventor queue processing (delay, timer and idle queues)
        self.idleTimer = QtCore.QTimer()
        self.idleTimer.timeout.connect(iv.process_queues)
        self.idleTimer.start()
Exemple #2
0
def create_scene():
    '''Returns a simple scene (light, camera, manip, material, cone)'''
    root = iv.Separator()
    root += iv.DirectionalLight()
    root += iv.OrthographicCamera()
    root += iv.TrackballManip()
    root += iv.Material("diffuseColor 1 0 0")
    root += iv.Cone()
    return root
Exemple #3
0
 def create_scene(self):
     '''Returns a simple scene (light, camera, manip, material, cone)'''
     root = inventor.Separator()
     root += inventor.DirectionalLight()
     root += inventor.OrthographicCamera()
     root += inventor.Selection("policy SINGLE")
     root[-1] += inventor.Material("diffuseColor 1 0 0")
     root[-1] += inventor.Cone()
     return root
Exemple #4
0
def makeSphericalHarmonicsScene(index):
    """Returns a spherical harmonics surface surrounded by trackball"""
    nu = 2**(4 + index) + 1
    nv = nu
    xyzs, colors = sphericalHarmonics(nu, nv, CircularColorMap())
    surf = makeSurface(nu, nv, xyzs, colors)

    root = iv.Separator()
    root += iv.DirectionalLight()
    root += iv.OrthographicCamera()
    root += iv.TrackballManip()
    root += surf
    return root
Exemple #5
0
def makeRandomScene(n):
    """Returns a scene with randomly placed discs"""
    root = iv.Separator()
    root += iv.DirectionalLight()
    root += iv.OrthographicCamera(
        "position 0 0 100 nearDistance 20 focalDistance 60 farDistance 100 height 80"
    )
    root += iv.ShapeHints(
        "vertexOrdering COUNTERCLOCKWISE shapeType SOLID faceType CONVEX")
    root += iv.Complexity("value 1")
    shape = iv.Sphere()

    # color table
    cmap = np.array([
        [0, 0, 1],  # blue
        [1, 0, 1],  # magenta
        [1, 0, 0],  # red
        [1, 1, 0],  # yellow
        [0, 1, 0],  # green
        [0, 1, 1],  # cyan
    ])
    cred = cmap[:, 0]
    cgreen = cmap[:, 1]
    cblue = cmap[:, 2]
    cidx = np.linspace(0, 1, len(cmap))

    # visualize random numbers as discs in space using the random values for position and size
    # discs are oriented towards origin but could also represent other dimensions
    rand = np.random.rand(n, 4)
    for (r1, r2, r3, r4) in rand:
        theta = 2 * np.pi * r1
        phi = np.pi * r2
        r = np.sqrt(r3)
        scale = 3 * (0.2 + r4)
        trans = np.array([
            r * np.sin(theta) * np.cos(phi), r * np.sin(theta) * np.sin(phi),
            r * np.cos(theta)
        ])
        color = (np.interp(r4, cidx, cred), np.interp(r4, cidx, cgreen),
                 np.interp(r4, cidx, cblue))

        disc = iv.ShapeKit()
        disc.shape = shape
        disc.transform.translation = trans * 40.0
        disc.transform.scaleFactor = (scale, 0.3 * scale, scale)
        disc.transform.rotation = ((0.0, 1.0, 0.0), trans)
        disc.appearance.material.diffuseColor = color
        disc.appearance.material.ambientColor = (0.7, 0.7, 0.7)
        root += disc

    return root
Exemple #6
0
def makeTexturedCubeScene():
    """Returns a scene with randomly placed discs"""
    root = iv.Separator()
    root += iv.DirectionalLight()
    root += iv.PerspectiveCamera("orientation 1 0 0 -0.2 heightAngle 0.4")
    root += iv.Rotor("rotation 0 1 0 0.2 speed 0.1")
    # Coin3D:
    root += iv.SceneTexture2("model DECAL")
    root[-1].scene = makeRandomScene(150)
    # VSG:
    # root += iv.Texture2("model DECAL")
    # root[-1].renderToTextureProperty = makeRandomScene(150)
    root += iv.Material("diffuseColor 0.2 0.3 0.4 ambientColor 0.1 0.1 0.1")
    root += iv.Cube()

    return root
Exemple #7
0
def makeSurface(nu, nv, xyzs, colors):
    """Create a scene graph from vertex and color data."""

    result = iv.Separator()
    result += iv.ShapeHints(
        "vertexOrdering COUNTERCLOCKWISE shapeType UNKNOWN_SHAPE_TYPE")

    vertexProperty = iv.VertexProperty("materialBinding PER_VERTEX_INDEXED")
    vertexProperty.orderedRGBA = colors
    vertexProperty.vertex = xyzs

    # Define the QuadMesh.
    quadMesh = iv.QuadMesh()
    quadMesh.verticesPerRow = nu
    quadMesh.verticesPerColumn = nv
    quadMesh.vertexProperty = vertexProperty
    result += quadMesh

    return result
Exemple #8
0
def makeTexturedCubeScene(img):
    """Returns a scene with randomly placed discs"""
    # make sure we have 8 bit per channel for RGBA
    tmp = img.convertToFormat(
        QtGui.QImage.Format_ARGB32).mirrored().rgbSwapped()

    # to get image without alpha:
    # tmp = img.convertToFormat(QtGui.QImage.Format_RGB888).mirrored()

    root = iv.Separator()
    root += iv.DirectionalLight()
    root += iv.PerspectiveCamera("orientation 1 0 0 -0.2 heightAngle 0.4")
    root += iv.Rotor("rotation 0 1 0 0.2 speed 0.1")
    root += iv.Texture2("model DECAL")
    root[-1].image = (tmp.width(), tmp.height(), 3 + tmp.hasAlphaChannel(),
                      tmp.constBits())
    root += iv.Material("diffuseColor 0.2 0.3 0.4 ambientColor 0.1 0.1 0.1")
    root += iv.Cube()

    return root
    def __init__(self, parent=None):
        """Initializes inspector widget consisting of scene and field editor"""
        super(QInspectorWidget, self).__init__(QtCore.Qt.Vertical, parent)

        self._filterEdit = QtGui.QLineEdit()
        self._graphView = QtGui.QTreeView()
        self._fieldView = QtGui.QTableView()

        ctrlLayout = QtGui.QVBoxLayout()
        ctrlLayout.setContentsMargins(0, 0, 0, 0)
        ctrlLayout.setSpacing(1)

        self._filterEdit.setPlaceholderText("Search All Scene Objects")
        ctrlLayout.addWidget(self._filterEdit)
        ctrlLayout.addWidget(self._graphView)

        ctrlWidget = QtGui.QWidget()
        ctrlWidget.setLayout(ctrlLayout)
        self.addWidget(ctrlWidget)
        self.addWidget(self._fieldView)
        self.setStretchFactor(0, 2)

        self._proxyModel = QSceneGraphFilter(self)
        self._sceneModel = QSceneGraphModel(iv.Separator(), self)
        self._fieldsModel = None

        self._proxyModel.setSourceModel(self._sceneModel)
        self._proxyModel.setDynamicSortFilter(True)
        self._proxyModel.setFilterCaseSensitivity(QtCore.Qt.CaseInsensitive)
        self._proxyModel.setSortRole(QSceneGraphModel.sortRole)
        self._proxyModel.setFilterRole(QSceneGraphModel.filterRole)
        self._proxyModel.setFilterKeyColumn(0)

        self._graphView.setModel(self._proxyModel)
        self._graphView.setDragEnabled(True)
        self._graphView.setAcceptDrops(True)
        self._graphView.setDropIndicatorShown(True)
        self._graphView.setDragDropMode(QtGui.QAbstractItemView.DragDrop)
        self._graphView.setDefaultDropAction(QtCore.Qt.MoveAction)
        self._graphView.setItemDelegateForColumn(
            0, QSceneObjectTypeDelegate(self))
        self._graphView.setSelectionMode(
            QtGui.QAbstractItemView.SelectionMode.ExtendedSelection)

        self._fieldView.horizontalHeader().setStretchLastSection(True)
        self._fieldView.verticalHeader().setResizeMode(QtGui.QHeaderView.Fixed)
        self._fieldView.verticalHeader().setDefaultSectionSize(
            0.8 * self._fieldView.verticalHeader().defaultSectionSize())
        self._fieldView.verticalHeader().hide()
        self._fieldView.setAlternatingRowColors(True)
        self._fieldView.setWordWrap(False)
        self._fieldView.setShowGrid(False)
        self._fieldView.setItemDelegateForColumn(1, QFieldValueDelegate(self))

        QtCore.QObject.connect(
            self._graphView.selectionModel(),
            QtCore.SIGNAL("currentChanged(QModelIndex, QModelIndex)"),
            self.setSelection)
        QtCore.QObject.connect(self._filterEdit,
                               QtCore.SIGNAL("textChanged(QString)"),
                               self.setFilter)