Пример #1
0
    def load(self, file):
        """Load a scene from file or string"""
        # keep root node instance and copy children instead so root variable in console stays valid
        del self._root[:]
        self._root += iv.read(file)[:]
        if self._root is not None:
            if file[0] is not '#':
                self._filePath = file
            else:
                self._filePath = ""

            self.parent().setWindowTitle(self.applicationTitle())
            del self.previewWidget.sceneManager.scene[:]
            resetCamera = False

            if (iv.search(self._root, type="DirectionalLight") is None):
                self.previewWidget.sceneManager.scene += iv.DirectionalLight()
            if (iv.search(self._root, type="Camera") is None):
                self.previewWidget.sceneManager.scene += [
                    iv.OrthographicCamera(), self._root
                ]
                resetCamera = True

            self.previewWidget.sceneManager.scene += self._root

            if resetCamera:
                self.previewWidget.sceneManager.view_all()

            self.inspectorWidget.attach(self._root)
Пример #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
Пример #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
Пример #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
Пример #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
Пример #6
0
 def loadScene(self, file):
     root = iv.read(file)
     if root:
         self.glWidget.sceneManager.scene = root
         if (len(iv.search(self.glWidget.sceneManager.scene,
                           type="Camera")) == 0):
             self.glWidget.sceneManager.scene.insert(
                 0, iv.OrthographicCamera())
         if (len(
                 iv.search(self.glWidget.sceneManager.scene,
                           type="DirectionalLight")) == 0):
             self.glWidget.sceneManager.scene.insert(
                 0, iv.DirectionalLight())
         self.glWidget.sceneManager.view_all()