Exemplo n.º 1
0
def construct_tree(root):
    # get a plain list of current scene
    cnt = h3d.findNodes(h3d.RootNode, "", h3d.NodeTypes.Undefined)
    if cnt == 0: return

    local_dict = {}
    for i in range(cnt):
        node_id = h3d.getNodeFindResult(i)
        if node_id == h3d.RootNode:
            continue
        node_name = h3d.getNodeParamStr(node_id, h3d.NodeParams.NameStr)
        # sikp the editor's interal nodes
        if node_name.startswith('__') and node_name.endswith('__'):
            continue
        local_dict[node_id] = gModel.createItem(node_name, node_id)

    # add children recursively
    for nid, item in local_dict.iteritems():
        pid = h3d.getNodeParent(nid)
        try:
            parent = gModel.getItem(local_dict[pid])
            parent.appendRow(gModel.getItem(item))
        except KeyError:
            # it's top level node, or its parent is a editor node
            root.appendRow(gModel.getItem(item))
Exemplo n.º 2
0
def construct_tree(root) :
    # get a plain list of current scene
    cnt = h3d.findNodes(h3d.RootNode, "", h3d.NodeTypes.Undefined)
    if cnt == 0 : return
    
    local_dict = {}
    for i in range(cnt) :
        node_id = h3d.getNodeFindResult(i)
        if node_id == h3d.RootNode : 
            continue
        node_name = h3d.getNodeParamStr(node_id, h3d.NodeParams.NameStr)
        # sikp the editor's interal nodes
        if node_name.startswith('__') and node_name.endswith('__') : 
            continue
        local_dict[node_id] = gModel.createItem(node_name, node_id)

    # add children recursively
    for nid, item in local_dict.iteritems() :
        pid = h3d.getNodeParent(nid)
        try :
            parent = gModel.getItem(local_dict[pid])
            parent.appendRow(gModel.getItem(item))
        except KeyError :
            # it's top level node, or its parent is a editor node
            root.appendRow(gModel.getItem(item))
Exemplo n.º 3
0
 def start(self):
     # get horde id
     h3did = self.gocBehavior('Object3D').horde_id
     self.parent_id = h3d.getNodeParent(h3did)
     self._enable = self.parent_id != 0
     # print self._enable, h3did, self.parent_id
     self._rotate = 0.0
     self._animation = False
Exemplo n.º 4
0
 def start(self):
     # get horde id
     h3did = self.gocBehavior('Object3D').horde_id
     self.parent_id = h3d.getNodeParent(h3did)
     self._enable = self.parent_id != 0
     # print self._enable, h3did, self.parent_id
     self._rotate = 0.0
     self._animation = False
Exemplo n.º 5
0
    def graphic_update(self, cur_fps, ani_time, weight):
        forward = h3d.getNodeParamI( self.camera, h3d.Camera.PipeResI ) == self._h3dres.forwardPipe 
        
        if (PIWIO.key_clicked() and PIWIO.clicked_key() == Qt.Key_F5) :self.__mode += 1
        
        if self.__mode > 0 :
            if forward:
                h3d.utils.showText( "Pipeline: forward", 0.03, 0.24, 0.026, 1, 1, 1, self._h3dres.fontMat )
            else:
                h3d.utils.showText( "Pipeline: deferred", 0.03, 0.24, 0.026, 1, 1, 1, self._h3dres.fontMat )
        
        if self.__mode == 3 : self.__mode = 0

        if PIWIO.key_clicked():
            if PIWIO.clicked_key() == Qt.Key_F3 :
                if forward :
                    h3d.setNodeParamI( self.camera, h3d.Camera.PipeResI, self._h3dres.deferredPipe )
                else :
                    h3d.setNodeParamI( self.camera, h3d.Camera.PipeResI, self._h3dres.forwardPipe )
                SetCamera(self.camera)

            elif PIWIO.clicked_key() == Qt.Key_1 :
                self.change_skybox(self._h3dres.skyBox)
            elif PIWIO.clicked_key() == Qt.Key_2 :
                self.change_skybox(self._h3dres.skyBox2)

            elif PIWIO.clicked_key() == Qt.Key_3 :
                mtl = h3d.getNodeParamI(self._vol, 20001)
                h3d.setMaterialUniform(mtl, "FluidColor", 0.59, 0.69, 0.99, 1.0)
                h3d.setMaterialUniform(mtl, "absorptionIdx", 2.0, 1.1, 0.45, 0.0)
            elif PIWIO.clicked_key() == Qt.Key_4 :
                mtl = h3d.getNodeParamI(self._vol, 20001)
                h3d.setMaterialUniform(mtl, "FluidColor", 0.0, 0.0, 0.0, 0.0)
                h3d.setMaterialUniform(mtl, "absorptionIdx", 0.0, 0.0, 0.0, 0.0)

        if self.animation :
            self.__rotate += 30.0/cur_fps 
            anchor = h3d.getNodeParent(self.camera)
            t,r,s = h3d.getNodeTransform(anchor)
            h3d.setNodeTransform(anchor, t[0], t[1], t[2], r[0], self.__rotate, r[2], s[0], s[1], s[2])

        if len(self.__data_list) > 0:
            self.__file_ptr += self.__skip
            self.__file_ptr %= len(self.__data_list)
            fn = self.__data_list[self.__file_ptr]
            if not SPH.UpdateSphData(self._sphdata, fn) :
                print "can not load file {}".format(fn)
            else :
                SPH.AdvanceSph(self._vol)

        if not forward and self.create_cmap :
            self.update_shader_fov(self.light_fov)
            h3d.render(self._light_camera)
            # restore
            self.update_shader_fov(45.0)
Exemplo n.º 6
0
def on_changed(item):
    # remove or change its name
    if not item.data():
        gModel.removeRow(item.row(), item.index().parent())
    else:
        # change node name or its parent
        node_id = item.data()
        pid = h3d.getNodeParent(node_id)
        node_name = h3d.getNodeParamStr(node_id, h3d.NodeParams.NameStr)
        # change parent
        if not item.parent() and pid != h3d.RootNode:
            _, mat_abs = h3d.getNodeTransMats(node_id)
            h3d.setNodeParent(node_id, h3d.RootNode)
            h3d.setNodeTransMat(node_id, mat_abs)
        elif item.parent().data() != pid:
            new_pid = item.parent().data()
            _, pmat_abs = h3d.getNodeTransMats(new_pid)
            _, mat_abs = h3d.getNodeTransMats(node_id)
            h3d.setNodeParent(node_id, new_pid)
            h3d.setNodeTransMat(node_id, (pmat_abs**-1) * mat_abs)
        # change parent
        if node_name != item.text():
            h3d.setNodeParamStr(node_id, h3d.NodeParams.NameStr, item.text())
        on_activate(item.index())
Exemplo n.º 7
0
def on_changed(item):
    # remove or change its name
    if not item.data() :
        gModel.removeRow(item.row(), item.index().parent())
    else :
        # change node name or its parent
        node_id = item.data()
        pid = h3d.getNodeParent(node_id)
        node_name = h3d.getNodeParamStr(node_id, h3d.NodeParams.NameStr)
        # change parent
        if not item.parent() and pid != h3d.RootNode :
            _, mat_abs = h3d.getNodeTransMats(node_id)
            h3d.setNodeParent(node_id, h3d.RootNode)
            h3d.setNodeTransMat(node_id, mat_abs)
        elif item.parent().data() != pid :
            new_pid = item.parent().data()
            _, pmat_abs = h3d.getNodeTransMats(new_pid)
            _, mat_abs = h3d.getNodeTransMats(node_id)
            h3d.setNodeParent(node_id, new_pid)
            h3d.setNodeTransMat(node_id, (pmat_abs**-1)*mat_abs)
        # change parent
        if node_name != item.text() :
            h3d.setNodeParamStr(node_id, h3d.NodeParams.NameStr, item.text())
        on_activate(item.index())
Exemplo n.º 8
0
    def graphic_update(self, cur_fps, ani_time, weight):
        forward = h3d.getNodeParamI(
            self.camera, h3d.Camera.PipeResI) == self._h3dres.forwardPipe

        if (PIWIO.key_clicked() and PIWIO.clicked_key() == Qt.Key_F5):
            self.__mode += 1

        if self.__mode > 0:
            if forward:
                h3d.utils.showText("Pipeline: forward", 0.03, 0.24, 0.026, 1,
                                   1, 1, self._h3dres.fontMat)
            else:
                h3d.utils.showText("Pipeline: deferred", 0.03, 0.24, 0.026, 1,
                                   1, 1, self._h3dres.fontMat)

        if self.__mode == 3: self.__mode = 0

        if PIWIO.key_clicked():
            if PIWIO.clicked_key() == Qt.Key_F3:
                if forward:
                    h3d.setNodeParamI(self.camera, h3d.Camera.PipeResI,
                                      self._h3dres.deferredPipe)
                else:
                    h3d.setNodeParamI(self.camera, h3d.Camera.PipeResI,
                                      self._h3dres.forwardPipe)
                SetCamera(self.camera)

            elif PIWIO.clicked_key() == Qt.Key_1:
                self.change_skybox(self._h3dres.skyBox)
            elif PIWIO.clicked_key() == Qt.Key_2:
                self.change_skybox(self._h3dres.skyBox2)

            elif PIWIO.clicked_key() == Qt.Key_3:
                mtl = h3d.getNodeParamI(self._vol, 20001)
                h3d.setMaterialUniform(mtl, "FluidColor", 0.59, 0.69, 0.99,
                                       1.0)
                h3d.setMaterialUniform(mtl, "absorptionIdx", 2.0, 1.1, 0.45,
                                       0.0)
            elif PIWIO.clicked_key() == Qt.Key_4:
                mtl = h3d.getNodeParamI(self._vol, 20001)
                h3d.setMaterialUniform(mtl, "FluidColor", 0.0, 0.0, 0.0, 0.0)
                h3d.setMaterialUniform(mtl, "absorptionIdx", 2.0, 1.1, 0.45,
                                       0.0)

        if self.animation:
            self.__rotate += 30.0 / cur_fps
            anchor = h3d.getNodeParent(self.camera)
            t, r, s = h3d.getNodeTransform(anchor)
            h3d.setNodeTransform(anchor, t[0], t[1], t[2], r[0], self.__rotate,
                                 r[2], s[0], s[1], s[2])

        if len(self.__data_list) > 0:
            self.__file_ptr += self.__skip
            self.__file_ptr %= len(self.__data_list)
            fn = self.__data_list[self.__file_ptr]
            if not SPH.UpdateSphData(self._sphdata, fn):
                print "can not load file {}".format(fn)
            else:
                SPH.AdvanceSph(self._vol)
                if self.__shot_dir != '' and self.__file_ptr > 0:
                    fn = self.__data_list[self.__file_ptr - 1]
                    fn = os.path.join(self.__shot_dir,
                                      '{}.tga'.format(os.path.split(fn)[-1]))
                    utils.screenshot(fn)

        if not forward and self.create_cmap:
            self.update_shader_fov(self.light_fov)
            h3d.render(self._light_camera)
            # restore
            self.update_shader_fov(45.0)