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)
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() and 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) self._crowdSim.update(1.0 / cur_fps)
def setup_scene(self): h3dres = self._h3dres # Add environment #self._env = h3d.addNodes(h3d.RootNode, h3dres.env) #h3d.setNodeTransform(self._env, 0, 0, 0, 0, 0, 0, 0.08, 0.08, 0.08) # Add skybox self.change_skybox(h3dres.skyBox) # Add light source self._light = h3d.addLightNode(h3d.RootNode, 'Light1', h3dres.lightMat, 'LIGHTING', 'SHADOWMAP') h3d.setNodeTransform(self._light, 15, 10, -5, -40, 120, 0, 1, 1, 1) h3d.setNodeParamF(self._light, h3d.Light.RadiusF, 0, 100) h3d.setNodeParamF(self._light, h3d.Light.FovF, 0, self.light_fov) h3d.setNodeParamI(self._light, h3d.Light.ShadowMapCountI, 1) h3d.setNodeParamF(self._light, h3d.Light.ShadowSplitLambdaF, 0, 0.9) h3d.setNodeParamF(self._light, h3d.Light.ShadowMapBiasF, 0, 0.001) h3d.setNodeParamF(self._light, h3d.Light.ColorF3, 0, 0.95) h3d.setNodeParamF(self._light, h3d.Light.ColorF3, 1, 0.95) h3d.setNodeParamF(self._light, h3d.Light.ColorF3, 2, 0.85) if self.create_cmap: # Light camera self._light_camera = h3d.addCameraNode(self._light, "light_camera", h3dres.deferredPipe2) h3d.setNodeParamI(self._light_camera, h3d.Camera.OutTexResI, h3dres.cmap) h3d.setNodeParamI(self._light_camera, h3d.Camera.ViewportXI, 0) h3d.setNodeParamI(self._light_camera, h3d.Camera.ViewportXI, 0) h3d.setNodeParamI(self._light_camera, h3d.Camera.ViewportWidthI, self.cmap_size) h3d.setNodeParamI(self._light_camera, h3d.Camera.ViewportHeightI, self.cmap_size) h3d.resizePipelineBuffers(h3dres.deferredPipe2, self.cmap_size, self.cmap_size) h3d.setupCameraView(self._light_camera, self.light_fov, 1.0, 0.1, 1000.0) # Update ligth shader uniforms self.update_cmap_res() # Create volume data self._vol = h3d.addNodes(h3d.RootNode, h3dres.volBox) self._sphdata = h3d.getNodeParamI(self._vol, 20000) # for VolumeResI = 20000 self._room = h3d.addNodes(h3d.RootNode, h3dres.roomBox) h3d.setNodeTransform(self._room, 0, -0.01, 0, 0, 0, 0, 20, 20, 20) self._plane = h3d.addNodes(h3d.RootNode, h3dres.plane) h3d.setNodeTransform(self._plane, 0, 0, 0, 0, 0, 0, 0.2, 0.2, 0.2) # Add a camera self.add_camera("MainCamera", h3dres.deferredPipe) h3d.setNodeTransform(self.camera, -2.0, 1.2, -6.5, -13, -170, 0, 1, 1, 1) #h3d.setNodeTransform(self.camera, -0.8, 1.06, -1.08, -41, -154, -6.4, 1, 1, 1) #h3d.setNodeTransform(self.camera, -0.32, 0.23, -0.54, -19, -174, -0.01, 1, 1, 1) self.__mode = 0
def start(self): # save hordeid obj3d = self.gocBehavior('Object3D') self._sky = obj3d.horde_id self.light_mat_res = h3d.findResource(h3d.ResTypes.Material, "materials/sphLight.material.xml") # set up skybox mesh = h3d.getNodeChild(self._sky, 0) res = h3d.getNodeParamI(mesh, h3d.Mesh.MatResI) idx = get_smapler_by_name(res, "albedoMap") if idx != -1 : evn_map = h3d.getResParamI(res, h3d.MatRes.SamplerElem, idx, h3d.MatRes.SampTexResI) idx = get_smapler_by_name(self.light_mat_res, "envMap") if idx != -1: h3d.setResParamI(self.light_mat_res, h3d.MatRes.SamplerElem, idx, h3d.MatRes.SampTexResI, evn_map)
def setup_scene(self) : h3dres = self._h3dres # Add environment #self._env = h3d.addNodes(h3d.RootNode, h3dres.env) #h3d.setNodeTransform(self._env, 0, 0, 0, 0, 0, 0, 0.08, 0.08, 0.08) # Add skybox self.change_skybox(h3dres.skyBox) # Add light source self._light = h3d.addLightNode(h3d.RootNode, 'Light1', h3dres.lightMat, 'LIGHTING', 'SHADOWMAP') h3d.setNodeTransform(self._light, 15, 10, -5, -40, 120, 0, 1, 1, 1) h3d.setNodeParamF(self._light, h3d.Light.RadiusF, 0, 100) h3d.setNodeParamF(self._light, h3d.Light.FovF, 0, self.light_fov) h3d.setNodeParamI(self._light, h3d.Light.ShadowMapCountI, 1) h3d.setNodeParamF(self._light, h3d.Light.ShadowSplitLambdaF, 0, 0.9) h3d.setNodeParamF(self._light, h3d.Light.ShadowMapBiasF, 0, 0.001) h3d.setNodeParamF(self._light, h3d.Light.ColorF3, 0, 0.95) h3d.setNodeParamF(self._light, h3d.Light.ColorF3, 1, 0.95) h3d.setNodeParamF(self._light, h3d.Light.ColorF3, 2, 0.85) if self.create_cmap : # Light camera self._light_camera = h3d.addCameraNode(self._light, "light_camera", h3dres.deferredPipe2) h3d.setNodeParamI(self._light_camera, h3d.Camera.OutTexResI, h3dres.cmap) h3d.setNodeParamI(self._light_camera, h3d.Camera.ViewportXI, 0) h3d.setNodeParamI(self._light_camera, h3d.Camera.ViewportXI, 0) h3d.setNodeParamI(self._light_camera, h3d.Camera.ViewportWidthI, self.cmap_size) h3d.setNodeParamI(self._light_camera, h3d.Camera.ViewportHeightI, self.cmap_size) h3d.resizePipelineBuffers(h3dres.deferredPipe2, self.cmap_size, self.cmap_size ) h3d.setupCameraView(self._light_camera, self.light_fov, 1.0, 0.1, 1000.0) # Update ligth shader uniforms self.update_cmap_res() # Create volume data self._vol = h3d.addNodes(h3d.RootNode, h3dres.volBox) self._sphdata = h3d.getNodeParamI(self._vol, 20000) # for VolumeResI = 20000 self._room = h3d.addNodes(h3d.RootNode, h3dres.roomBox) h3d.setNodeTransform(self._room, 0, -0.01, 0, 0, 0, 0, 20, 20, 20) self._plane = h3d.addNodes(h3d.RootNode, h3dres.plane) h3d.setNodeTransform(self._plane, 0, 0, 0, 0, 0, 0, 0.2, 0.2, 0.2) # Add a camera self.add_camera("MainCamera", h3dres.deferredPipe) h3d.setNodeTransform(self.camera, -2.0, 1.2, -6.5, -13, -170, 0, 1, 1, 1) #h3d.setNodeTransform(self.camera, -0.8, 1.06, -1.08, -41, -154, -6.4, 1, 1, 1) #h3d.setNodeTransform(self.camera, -0.32, 0.23, -0.54, -19, -174, -0.01, 1, 1, 1) self.__mode = 0
def start(self): # get horde id obj3d = self.gocBehavior('Object3D') self.h3did = obj3d.horde_id self._enable = h3d.getNodeType(self.h3did) == h3d.sph.H3DEXT_NodeType_Sph # print self.fr_dir, self.play, dir(self._piw_prop_fr_dir) # init self.__data_list = [] self.__file_ptr = 0 self.__skip = 1 # print "changed!" if self._enable : if self.fr_dir != "" : self.change_fr_dir(self.fr_dir, self.__skip) self._sphdata = h3d.getNodeParamI(self.h3did, h3d.sph.H3DEXTSph.VolumeResI) else : print "PlayFrFiles attached to a wrong type of node, please specify a SPH node instead!"
def start(self): # get horde id obj3d = self.gocBehavior('Object3D') self.h3did = obj3d.horde_id self._enable = h3d.getNodeType( self.h3did) == h3d.sph.H3DEXT_NodeType_Sph # print self.fr_dir, self.play, dir(self._piw_prop_fr_dir) # init self.__data_list = [] self.__file_ptr = 0 self.__skip = 1 self.__solids = {} # print self.cm if self._enable: if self.fr_dir != "": self.change_fr_dir(self.fr_dir, self.__skip) self._sphdata = h3d.getNodeParamI(self.h3did, h3d.sph.H3DEXTSph.VolumeResI) # parse template if self.template: solids = [x.split(':') for x in self.template.split()] for kind, params in solids: scngraph, cx, cy, cz, sx, sy, sz, bx, by, bz = params.split( ';') scnres = h3d.findResource(h3d.ResTypes.SceneGraph, scngraph) if not scnres: print "Can not find template's scene graph" return # print scngraph, scnres, cx, cy, cz, sx, sy, sz self.__solids[int(kind)] = dict( scnres=scnres, com=np.array([float(cx), float(cy), float(cz)]), scale=np.array([float(sx), float(sy), float(sz)]), bscale=np.array([float(bx), float(by), float(bz)]), nodes=[]) else: print "PlayFrFiles attached to a wrong type of node, please specify a SPH node instead!"
def start(self): # save hordeid obj3d = self.gocBehavior('Object3D') self._sky = obj3d.horde_id self.light_mat_res = h3d.findResource( h3d.ResTypes.Material, "materials/sphLight.material.xml") # set up skybox mesh = h3d.getNodeChild(self._sky, 0) res = h3d.getNodeParamI(mesh, h3d.Mesh.MatResI) idx = get_smapler_by_name(res, "albedoMap") if idx != -1: evn_map = h3d.getResParamI(res, h3d.MatRes.SamplerElem, idx, h3d.MatRes.SampTexResI) idx = get_smapler_by_name(self.light_mat_res, "envMap") if idx != -1: h3d.setResParamI(self.light_mat_res, h3d.MatRes.SamplerElem, idx, h3d.MatRes.SampTexResI, evn_map)
def change_skybox(self, skyres): if self._sky != 0: # remove the old sky box h3d.removeNode(self._sky) h3dres = self._h3dres # Add skybox self._sky = h3d.addNodes(h3d.RootNode, skyres) h3d.setNodeTransform(self._sky, 0, 0, 0, 0, 0, 0, 20, 20, 20) # Set ligth envmap mesh = h3d.getNodeChild(self._sky, 0) res = h3d.getNodeParamI(mesh, h3d.Mesh.MatResI) idx = self.get_smapler_by_name(res, "albedoMap") if idx != -1 : evn_map = h3d.getResParamI(res, h3d.MatRes.SamplerElem, idx, h3d.MatRes.SampTexResI) idx = self.get_smapler_by_name(h3dres.lightMat, "envMap") if idx != -1: h3d.setResParamI(h3dres.lightMat, h3d.MatRes.SamplerElem, idx, h3d.MatRes.SampTexResI, evn_map)
def start(self): # get horde id obj3d = self.gocBehavior('Object3D') self.h3did = obj3d.horde_id self._enable = h3d.getNodeType( self.h3did) == h3d.sph.H3DEXT_NodeType_Sph # print self.fr_dir, self.play, dir(self._piw_prop_fr_dir) # init self.__data_list = [] self.__file_ptr = 0 self.__skip = 1 # print "changed!" if self._enable: if self.fr_dir != "": self.change_fr_dir(self.fr_dir, self.__skip) self._sphdata = h3d.getNodeParamI(self.h3did, h3d.sph.H3DEXTSph.VolumeResI) else: print "PlayFrFiles attached to a wrong type of node, please specify a SPH node instead!"
def change_skybox(self, skyres): if self._sky != 0: # remove the old sky box h3d.removeNode(self._sky) h3dres = self._h3dres # Add skybox self._sky = h3d.addNodes(h3d.RootNode, skyres) h3d.setNodeTransform(self._sky, 0, 0, 0, 0, 0, 0, 20, 20, 20) # Set ligth envmap mesh = h3d.getNodeChild(self._sky, 0) res = h3d.getNodeParamI(mesh, h3d.Mesh.MatResI) idx = self.get_smapler_by_name(res, "albedoMap") if idx != -1: evn_map = h3d.getResParamI(res, h3d.MatRes.SamplerElem, idx, h3d.MatRes.SampTexResI) idx = self.get_smapler_by_name(h3dres.lightMat, "envMap") if idx != -1: h3d.setResParamI(h3dres.lightMat, h3d.MatRes.SamplerElem, idx, h3d.MatRes.SampTexResI, evn_map)
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() and 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) self._crowdSim.update(1.0/cur_fps)
def on_key_press(self, symbol, modifiers): key = pyglet.window.key if symbol == key.ESCAPE: self.has_exit = True elif symbol == key.SPACE: self._app._freeze = not self._app._freeze elif symbol == key.F3: p = h3d.getNodeParamI(self.camera, h3d.Camera.PipeResI) if p == self._app._h3dres.hdrPipe: h3d.setNodeParamI(self.camera, h3d.Camera.PipeResI, self._app._h3dres.forwardPipe) else: h3d.setNodeParamI(self.camera, h3d.Camera.PipeResI, self._app._h3dres.hdrPipe) elif symbol == key.F7: self._app._debugViewMode = not self._app._debugViewMode elif symbol == key.F8: self._app._wireframeMode = not self._app._wireframeMode elif symbol == key.F9: self._app._showStats = True self._app._statMode = 1 - self._app._statMode
def graphic_update(self, cur_fps, ani_time, weight): hdr = h3d.getNodeParamI( self.camera, h3d.Camera.PipeResI ) == self._h3dres.hdrPipe if (PIWIO.key_clicked() and PIWIO.clicked_key() == Qt.Key_F5) :self.__mode += 1 if self.__mode > 0 : if hdr: h3d.utils.showText( "Pipeline: hdr", 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() and PIWIO.clicked_key() == Qt.Key_F3 : if hdr : h3d.setNodeParamI( self.camera, h3d.Camera.PipeResI, self._h3dres.deferredPipe ) else : h3d.setNodeParamI( self.camera, h3d.Camera.PipeResI, self._h3dres.hdrPipe ) SetCamera(self.camera) count = h3d.findNodes(self._particleSystem, '', h3d.NodeTypes.Emitter) for i in range(count): h3d.updateEmitter(h3d.getNodeFindResult(i), 1.0/cur_fps)
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)