def _mainloopUpdate(self, dt): app.App._mainloopUpdate(self, dt) for w in self._windows: h3d.setNodeTransform(w.camera, self._x, self._y, self._z, self._rx, self._ry, 0, 1, 1, 1) h3d.setOption(h3d.Options.DebugViewMode, float(self._debugViewMode)) h3d.setOption(h3d.Options.WireframeMode, float(self._wireframeMode)) key = pyglet.window.key curVel = self._velocity * dt if w.keyboard[key.LSHIFT]: curVel *= 10 if w.keyboard[key.W]: self._x -= sin(radians(self._ry)) * cos(-radians(self._rx)) * curVel self._y -= sin(-radians(self._rx)) * curVel self._z -= cos(radians(self._ry)) * cos(-radians(self._rx)) * curVel if w.keyboard[key.S]: self._x += sin(radians(self._ry)) * cos(-radians(self._rx)) * curVel self._y += sin(-radians(self._rx)) * curVel self._z += cos(radians(self._ry)) * cos(-radians(self._rx)) * curVel if w.keyboard[key.A]: self._x += sin(radians(self._ry - 90)) * curVel self._z += cos(radians(self._ry - 90)) * curVel if w.keyboard[key.D]: self._x += sin(radians(self._ry + 90)) * curVel self._z += cos(radians(self._ry + 90)) * curVel break # we use only exactly ONE window
def update(self): if self._enable and self._animation: frame_time = h3d.getStat(h3d.Stats.FrameTime, False) self._rotate += (30.0 * frame_time) * 0.001 t, r, s = h3d.getNodeTransform(self.parent_id) h3d.setNodeTransform(self.parent_id, t[0], t[1], t[2], r[0], self._rotate, r[2], s[0], s[1], s[2])
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.23, 0.23, 0.23) # Add skybox self._sky = h3d.addNodes(h3d.RootNode, h3dres.skyBox) h3d.setNodeTransform(self._sky, 0, 0, 0, 0, 0, 0, 100, 50, 100) # Add light source self._light = h3d.addLightNode(h3d.RootNode, 'Light1', h3dres.lightMat, 'LIGHTING', 'SHADOWMAP') h3d.setNodeTransform(self._light, 50, 40, -50, -60, 130, 0, 1, 1, 1) h3d.setNodeParamF(self._light, h3d.Light.RadiusF, 0, 250) h3d.setNodeParamF(self._light, h3d.Light.FovF, 0, 90) h3d.setNodeParamI(self._light, h3d.Light.ShadowMapCountI, 3) 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.9) h3d.setNodeParamF(self._light, h3d.Light.ColorF3, 1, 0.9) h3d.setNodeParamF(self._light, h3d.Light.ColorF3, 2, 0.9) # Create volume data self._vol = h3d.addNodes(h3d.RootNode, h3dres.volBox) h3d.setNodeTransform(self._vol, 0, 3, 0, 0, 0, 0, 3, 3, 3) # Add a camera self.add_camera("MainCamera", h3dres.deferredPipe) h3d.setNodeTransform(self.camera, 9, 6.0, -14, -15, 145, 0, 1, 1, 1)
def set_particlesys(self, psys): # Attach particle system to hand joint h3d.findNodes(self._knight, 'Bip01_R_Hand', h3d.NodeTypes.Joint) hand = h3d.getNodeFindResult(0) if self._particleSystem is not None: h3d.removeNode(self._particleSystem) self._particleSystem = h3d.addNodes(hand, psys) h3d.setNodeTransform(self._particleSystem, 0, 40, 0, 90, 0, 0, 1, 1, 1)
def setup_scene(self) : h3dres = self._h3dres # Add terrain self.terrain = h3d.addNodes(h3d.RootNode, h3dres.terrain) # Set sun direction for ambient pass h3d.setMaterialUniform(h3dres.matRes, "sunDir", 1, -1, 0, 0 ); self.add_camera("MainCamera", h3dres.forwardPipe) h3d.setNodeTransform(self.camera, 512.0, 120.0, 512.0, 0, 2250.0, 0, 1, 1, 1)
def __init__(self, parent, a): # Add character to scene and apply animation self.node = h3d.addNodes(h3d.RootNode, parent.character) h3d.setupModelAnimStage(self.node, 0, parent.characterWalk, 0, "", False) # print "create 1" # Characters start in a circle formation self.px = sin(a * 6.28) * 10.0 self.pz = cos(a * 6.28) * 10.0 self.chooseDestination() h3d.setNodeTransform(self.node, self.px, 0.02, self.pz, 0, 0, 0, 1, 1, 1)
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 update(self) : self.time += 0.01 t, r, s = h3d.getNodeTransform(self.h3did) if self.x0y0 is None : self.x0y0 = t[0:2] h3d.setNodeTransform(self.h3did, self.x0y0[0] * (1.0 + cos(self.time)), self.x0y0[1] * (0.5 + sin(self.time)), t[2], r[0], r[1], r[2], s[0], s[1], s[2]) # send message i_time = int(self.time) if i_time % 1000 == 0 : self.sendMessage('printH3dId', self.h3did) if i_time == 5000: self.removeBehavior(self.recv_msg)
def _mainloopUpdate(self, dt): app.App._mainloopUpdate(self, dt) for w in self._windows: h3d.setNodeTransform(w.camera, self._x, self._y, self._z, self._rx, self._ry, 0, 1, 1, 1) if self._debugViewMode: h3d.setOption(h3d.Options.DebugViewMode, 1.0) else: h3d.setOption(h3d.Options.DebugViewMode, 0.0) if self._wireframeMode: h3d.setOption(h3d.Options.WireframeMode, 1.0) else: h3d.setOption(h3d.Options.WireframeMode, 0.0) key = pyglet.window.key curVel = self._velocity * dt if w.keyboard[key.LSHIFT]: curVel *= 5 if w.keyboard[key.W]: self._x -= sin(radians(self._ry)) * cos(-radians(self._rx)) * curVel self._y -= sin(-radians(self._rx)) * curVel self._z -= cos(radians(self._ry)) * cos(-radians(self._rx)) * curVel if w.keyboard[key.S]: self._x += sin(radians(self._ry)) * cos(-radians(self._rx)) * curVel self._y += sin(-radians(self._rx)) * curVel self._z += cos(radians(self._ry)) * cos(-radians(self._rx)) * curVel if w.keyboard[key.A]: self._x += sin(radians(self._ry - 90)) * curVel self._z += cos(radians(self._ry - 90)) * curVel if w.keyboard[key.D]: self._x += sin(radians(self._ry + 90)) * curVel self._z += cos(radians(self._ry + 90)) * curVel if w.keyboard[key._1]: self._weight += 2 * dt if self._weight > 1.0: self._weight = 1.0 if w.keyboard[key._2]: self._weight -= 2 * dt if self._weight < 0.0: self._weight = 0.0 break # we use only exactly ONE window if not self._freeze: self._animTime += dt h3d.setModelAnimParams(self._knight, 0, self._animTime * 24.0, self._weight) h3d.setModelAnimParams(self._knight, 1, self._animTime * 24.0, 1.0 - self._weight) count = h3d.findNodes(self._particleSystem, '', h3d.NodeTypes.Emitter) for i in range(count): h3d.advanceEmitterTime(h3d.getNodeFindResult(i), dt)
def update(self): self.time += 0.01 t, r, s = h3d.getNodeTransform(self.h3did) if self.x0y0 is None: self.x0y0 = t[0:2] h3d.setNodeTransform(self.h3did, self.x0y0[0] * (1.0 + cos(self.time)), self.x0y0[1] * (0.5 + sin(self.time)), t[2], r[0], r[1], r[2], s[0], s[1], s[2]) # send message i_time = int(self.time) if i_time % 1000 == 0: self.sendMessage('printH3dId', self.h3did) if i_time == 5000: self.removeBehavior(self.recv_msg)
def update_solids(self, curr_state): for solid_id, params in self.__solids.items(): solid_state = curr_state.get(solid_id, []) nodes = params['nodes'] scale = params['scale'] bscale = params['bscale'] CoM = params['com'] # translate to CoM tmat1 = np.mat(np.eye(4)) tmat1[0, 3], tmat1[1, 3], tmat1[2, 3] = -CoM # scale mat smat = np.mat(np.eye(4)) smat[0, 0], smat[1, 1], smat[2, 2] = scale if len(nodes) > len(solid_state): # remove extra solids for _ in range(len(nodes) - len(solid_state)): # print "remove node" h3d.removeNode(nodes.pop()) elif len(nodes) < len(solid_state): # add nodes for _ in range(len(solid_state) - len(nodes)): # print "add node" node = h3d.addNodes(h3d.RootNode, params['scnres']) if not node: print "failed to add solid node" return h3d.setNodeTransform(node, 0, 0, 0, 0, 0, 0, scale[0], scale[1], scale[2]) nodes.append(node) for i in range(len(solid_state)): node = nodes[i] cm, rot = solid_state[i] # rotation matrix rmat = np.mat(np.zeros((4, 4))) rmat[3, 3] = 1.0 rmat[0:3, 0:3] = np.mat(rot).T + rmat[0:3, 0:3] # print rmat # translate to pos pos = cm * bscale tmat2 = np.mat(np.eye(4)) tmat2[0, 3], tmat2[1, 3], tmat2[2, 3] = pos transform = (tmat2 * smat * rmat * tmat1) h3d.setNodeTransMat(node, transform)
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.23, 0.23, 0.23) # Add skybox self._sky = h3d.addNodes(h3d.RootNode, h3dres.skyBox) h3d.setNodeTransform(self._sky, 0, 0, 0, 0, 0, 0, 100, 50, 100) # Add light source self._light = h3d.addLightNode(h3d.RootNode, 'Light1', h3dres.lightMat, 'LIGHTING', 'SHADOWMAP') h3d.setNodeTransform(self._light, 50, 40, -50, -60, 130, 0, 1, 1, 1) h3d.setNodeParamF(self._light, h3d.Light.RadiusF, 0, 250) h3d.setNodeParamF(self._light, h3d.Light.FovF, 0, 90) h3d.setNodeParamI(self._light, h3d.Light.ShadowMapCountI, 3) 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.9) h3d.setNodeParamF(self._light, h3d.Light.ColorF3, 1, 0.9) h3d.setNodeParamF(self._light, h3d.Light.ColorF3, 2, 0.9) # Init character positions self._crowdSim.init() self.add_camera("MainCamera", h3dres.deferredPipe) h3d.setNodeTransform(self.camera, 15, 3.3, -16, 0, 130, 0, 1, 1, 1)
def _h3dSetupScene(self): h3dres = self._h3dres self._env = h3d.addNodes(h3d.RootNode, h3dres.env) h3d.setNodeTransform(self._env, 0, -20, 0, 0, 0, 0, 20, 20, 20) self._knight = h3d.addNodes(h3d.RootNode, h3dres.knight) h3d.setNodeTransform(self._knight, 0, 0, 0, 0, 180, 0, 0.1, 0.1, 0.1) h3d.setupModelAnimStage(self._knight, 0, h3dres.knightAnim1, 0, '', False) h3d.setupModelAnimStage(self._knight, 1, h3dres.knightAnim2, 0, '', False) # Attach particle system to hand joint h3d.findNodes(self._knight, 'Bip01_R_Hand', h3d.NodeTypes.Joint) hand = h3d.getNodeFindResult(0) self._particleSystem = h3d.addNodes(hand, h3dres.particleSys) h3d.setNodeTransform(self._particleSystem, 0, 40, 0, 90, 0, 0, 1, 1, 1) self._light = h3d.addLightNode(h3d.RootNode, 'Light1', 0, 'LIGHTING', 'SHADOWMAP') h3d.setNodeTransform(self._light, 0, 15, 10, -60, 0, 0, 1, 1, 1) h3d.setNodeParamF(self._light, h3d.Light.RadiusF, 0, 30) h3d.setNodeParamF(self._light, h3d.Light.FovF, 0, 90) h3d.setNodeParamI(self._light, h3d.Light.ShadowMapCountI, 1) h3d.setNodeParamF(self._light, h3d.Light.ShadowMapBiasF, 0, 0.01) h3d.setNodeParamF(self._light, h3d.Light.ColorF3, 0, 1.0) h3d.setNodeParamF(self._light, h3d.Light.ColorF3, 1, 0.8) h3d.setNodeParamF(self._light, h3d.Light.ColorF3, 2, 0.7) # Customize post processing effects mat = h3d.findResource(h3d.ResTypes.Material, 'pipelines/postHDR.material.xml') # hdrParams: exposure, brightpass threshold, brightpass offset (see shader for description) h3d.setMaterialUniform(mat, 'hdrExposure', 2.5, 0.0, 0.0, 0.0) h3d.setMaterialUniform(mat, 'hdrBrightThres', 0.5, 0.0, 0.0, 0.0) h3d.setMaterialUniform(mat, 'hdrBrightOffset', 0.08, 0.0, 0.0, 0.0)
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 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 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 setup_scene(self): h3dres = self._h3dres self._env = h3d.addNodes(h3d.RootNode, h3dres.env) #h3d.setNodeTransform(self._env, 0, 0, 0, 0, 0, 0, 0.23, 0.23, 0.23) h3d.setNodeTransform(self._env, 0, -20, 0, 0, 0, 0, 20, 20, 20) # Add skybox self._sky = h3d.addNodes(h3d.RootNode, h3dres.skyBox) h3d.setNodeTransform(self._sky, 0, 0, 0, 90, 0, 0, 50, 50, 50) self._knight = h3d.addNodes(h3d.RootNode, h3dres.knight) h3d.setNodeTransform(self._knight, 0, 0, 0, 0, 180, 0, 0.1, 0.1, 0.1) h3d.setupModelAnimStage(self._knight, 0, h3dres.knightAnim1, 0, '', False) h3d.setupModelAnimStage(self._knight, 1, h3dres.knightAnim2, 0, '', False) self._light = h3d.addLightNode(h3d.RootNode, 'Light1', h3dres.lightMat, 'LIGHTING', 'SHADOWMAP') h3d.setNodeTransform(self._light, 0, 15, 10, -60, 0, 0, 1, 1, 1) h3d.setNodeParamF(self._light, h3d.Light.RadiusF, 0, 30) h3d.setNodeParamF(self._light, h3d.Light.FovF, 0, 90) h3d.setNodeParamI(self._light, h3d.Light.ShadowMapCountI, 1) h3d.setNodeParamF(self._light, h3d.Light.ShadowMapBiasF, 0, 0.01) h3d.setNodeParamF(self._light, h3d.Light.ColorF3, 0, 1.0) h3d.setNodeParamF(self._light, h3d.Light.ColorF3, 1, 0.8) h3d.setNodeParamF(self._light, h3d.Light.ColorF3, 2, 0.7) # Customize post processing effects mat = h3d.findResource(h3d.ResTypes.Material, 'pipelines/postHDR.material.xml') # hdrParams: exposure, brightpass threshold, brightpass offset (see shader for description) h3d.setMaterialUniform(mat, 'hdrExposure', 2.5, 0.0, 0.0, 0.0) h3d.setMaterialUniform(mat, 'hdrBrightThres', 0.5, 0.0, 0.0, 0.0) h3d.setMaterialUniform(mat, 'hdrBrightOffset', 0.08, 0.0, 0.0, 0.0) # Attach particle system to hand joint self.set_particlesys(h3dres.particleSys2) self.add_camera("MainCamera", self.__rmode_dict[3][1]) h3d.setNodeTransform(self.camera, -25, 14, 9, -30, -60, 5, 1, 1, 1)
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 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.23, 0.23, 0.23) # Add skybox self._sky = h3d.addNodes(h3d.RootNode, h3dres.skyBox) h3d.setNodeTransform(self._sky, 0, 0, 0, 0, 0, 0, 100, 50, 100) # Add light source self._light = h3d.addLightNode(h3d.RootNode, 'Light1', h3dres.lightMat, 'LIGHTING', 'SHADOWMAP') h3d.setNodeTransform(self._light, 50, 40, -50, -60, 130, 0, 1, 1, 1) h3d.setNodeParamF(self._light, h3d.Light.RadiusF, 0, 250) h3d.setNodeParamF(self._light, h3d.Light.FovF, 0, 90) h3d.setNodeParamI(self._light, h3d.Light.ShadowMapCountI, 3) 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.9) h3d.setNodeParamF(self._light, h3d.Light.ColorF3, 1, 0.9) h3d.setNodeParamF(self._light, h3d.Light.ColorF3, 2, 0.9) # Init character positions self._crowdSim.init() self.add_camera("MainCamera", h3dres.deferredPipe) h3d.setNodeTransform(self.camera, 15, 3.3, -16, 0, 130, 0, 1, 1, 1)
def setup_scene(self) : h3dres = self._h3dres # Add skybox self._sky = h3d.addNodes(h3d.RootNode, h3dres.skyBox) h3d.setNodeTransform(self._sky, 0, 0, 0, 0, 0, 0, 500, 500, 500) # Add light source self._light = h3d.addLightNode(h3d.RootNode, 'Light1', h3dres.lightMat, 'LIGHTING', 'SHADOWMAP') h3d.setNodeTransform(self._light, 0, 20, 50, -30, 0, 0, 1, 1, 1) h3d.setNodeParamF(self._light, h3d.Light.RadiusF, 0, 200) h3d.setNodeParamF(self._light, h3d.Light.FovF, 0, 90) h3d.setNodeParamI(self._light, h3d.Light.ShadowMapCountI, 3) 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.9) h3d.setNodeParamF(self._light, h3d.Light.ColorF3, 1, 0.7) h3d.setNodeParamF(self._light, h3d.Light.ColorF3, 2, 0.75) # Add domino scene self._domino = h3d.addNodes(h3d.RootNode, h3dres.dominoRes ) # Add particle effects h3d.findNodes(self._domino, 'sphere', h3d.NodeTypes.Mesh) sphere = h3d.getNodeFindResult(0) self._particleSystem = h3d.addNodes(sphere, h3dres.particleSys) # Set particle parameter count = h3d.findNodes(self._particleSystem, '', h3d.NodeTypes.Emitter) for i in range(count): node = h3d.getNodeFindResult(i) h3d.setNodeParamF(node, h3d.Emitter.ForceF3, 1, 1.5) h3d.setNodeParamF(node, h3d.Emitter.EmissionRateF, 0, 200) h3d.setNodeParamF(node, h3d.Emitter.SpreadAngleF, 0, 45) # Customize post processing effects mat = h3d.findResource(h3d.ResTypes.Material, 'pipelines/postHDR.material.xml') # hdrParams: exposure, brightpass threshold, brightpass offset (see shader for description) h3d.setMaterialUniform(mat, 'hdrExposure', 2.5, 0.0, 0.0, 0.0) h3d.setMaterialUniform(mat, 'hdrBrightThres', 0.5, 0.0, 0.0, 0.0) h3d.setMaterialUniform(mat, 'hdrBrightOffset', 0.08, 0.0, 0.0, 0.0) self.add_camera("MainCamera", h3dres.hdrPipe) h3d.setNodeTransform(self.camera, -14.0, 40.0, 24.0, -50.0, -20, 1.3, 1, 1, 1)
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)
def update(self, dt): # Calculate distance to destination x = self.dx - self.px z = self.dz - self.pz d = sqrt(x * x + z * z) # On arrival choose a new destination for the next step if d <= 3.0: self.chooseDestination() x = self.dx - self.px z = self.dz - self.pz d = sqrt(x * x + z * z) # Calculate normalized attraction force to destination self.fx = x * 0.035 / d self.fz = z * 0.035 / d # Repulsion forces from other nearby particles for p in self.near: if p == self: continue x = self.px - p.px z = self.pz - p.pz d = x * x + z * z if d > dms: continue d = sqrt(d) # Use three zones with different repulsion strengths if d <= d1: s = m1 + t1 / d elif d <= d2: s = m2 + t2 / d else: s = m3 + t3 / d self.fx += x * s self.fz += z * s # Make movement frame rate independent dt *= 30 self.fx *= dt self.fz *= dt # Set new position self.px += self.fx self.pz += self.fz # Calculate orientation self.ox = (self.ox + self.fx) / 2 self.oz = (self.oz + self.fz) / 2 # Get rotation from orientation if self.oz == 0: ry = 0 else: ry = degrees(atan2(self.ox, self.oz)) # Update character scene node position h3d.setNodeTransform(self.node, self.px, 0.02, self.pz, 0, ry, 0, 1, 1, 1) # Update animation vel = sqrt(self.fx * self.fx + self.fz * self.fz) self.animTime += vel * 35.0 h3d.setModelAnimParams(self.node, 0, self.animTime, 1.0) h3d.updateModel( self.node, h3d.ModelUpdateFlags.Animation | h3d.ModelUpdateFlags.Geometry );
def add_camera(self, name, pipeRes): self.__camera = h3d.addCameraNode(h3d.RootNode, name, pipeRes) h3d.setNodeTransform(self.camera, 0, 0, 50, 0, 0, 0, 1, 1, 1)
def update(self, dt): # Calculate distance to destination x = self.dx - self.px z = self.dz - self.pz d = sqrt(x * x + z * z) # On arrival choose a new destination for the next step if d <= 3.0: self.chooseDestination() x = self.dx - self.px z = self.dz - self.pz d = sqrt(x * x + z * z) # Calculate normalized attraction force to destination self.fx = x * 0.035 / d self.fz = z * 0.035 / d # Repulsion forces from other nearby particles for p in self.near: if p == self: continue x = self.px - p.px z = self.pz - p.pz d = x * x + z * z if d > dms: continue d = sqrt(d) # Use three zones with different repulsion strengths if d <= d1: s = m1 + t1 / d elif d <= d2: s = m2 + t2 / d else: s = m3 + t3 / d self.fx += x * s self.fz += z * s # Make movement frame rate independent dt *= 30 self.fx *= dt self.fz *= dt # Set new position self.px += self.fx self.pz += self.fz # Calculate orientation self.ox = (self.ox + self.fx) / 2 self.oz = (self.oz + self.fz) / 2 # Get rotation from orientation if self.oz == 0: ry = 0 else: ry = degrees(atan2(self.ox, self.oz)) # Update character scene node position h3d.setNodeTransform(self.node, self.px, 0.02, self.pz, 0, ry, 0, 1, 1, 1) # Update animation vel = sqrt(self.fx * self.fx + self.fz * self.fz) self.animTime += vel * 35.0 h3d.setModelAnimParams(self.node, 0, self.animTime, 1.0) h3d.updateModel( self.node, h3d.ModelUpdateFlags.Animation | h3d.ModelUpdateFlags.Geometry)
def setupCamera(self, name, pipeRes): self.camera = h3d.addCameraNode(h3d.RootNode, name, pipeRes) h3d.setNodeTransform(self.camera, 0, 0, -100, 0, 0, 0, 1, 1, 1)
def update(self): if self._enable and self._animation : frame_time = h3d.getStat(h3d.Stats.FrameTime, False) self._rotate += (30.0 * frame_time) * 0.001 t,r,s = h3d.getNodeTransform(self.parent_id) h3d.setNodeTransform(self.parent_id, t[0], t[1], t[2], r[0], self._rotate, r[2], s[0], s[1], s[2])