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 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 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 remove(self): h3d.removeNode(self.node)