def findPosition(node, name, parentTransform=tr.identity()): foundTransform = findTransform(node, name, parentTransform) if isinstance(foundTransform, (np.ndarray, np.generic)): zero = np.array([[0, 0, 0, 1]], dtype=np.float32).T foundPosition = np.matmul(foundTransform, zero) return foundPosition return None
def __init__(self, n): gpu_chessboard = es.chessboard2GPUShape(bs.createChessboard(), n) chessboard = sg.SceneGraphNode("chessboard") chessboard.transform = tr.scale(1, d["w"] / d["h"], 1) chessboard.childs += [gpu_chessboard] chessboard_tr = sg.SceneGraphNode("chessboardTR") chessboard_tr.transfrom = tr.identity() chessboard_tr.childs += [chessboard] self.model = chessboard_tr
def __init__(self, path): gpu_part = es.toGPUShape(bs.createTextureQuad(path), GL_REPEAT, GL_NEAREST) part = sg.SceneGraphNode("part") part.transform = tr.matmul([ tr.scale(1, d["w"] / d["h"], 1), tr.scale(1 / d["n"], 1 / d["n"], 1) ]) part.childs += [gpu_part] part_tr = sg.SceneGraphNode("part_tr") part_tr.transform = tr.identity() part_tr.childs += [part] self.model = part_tr
def drawSceneGraphNode(node, pipeline, transformName, parentTransform=tr.identity()): assert (isinstance(node, SceneGraphNode)) # Composing the transformations through this path newTransform = np.matmul(parentTransform, node.transform) # If the child node is a leaf, it should be a GPUShape. # Hence, it can be drawn with drawShape if len(node.childs) == 1 and isinstance(node.childs[0], es.GPUShape): leaf = node.childs[0] glUniformMatrix4fv(glGetUniformLocation(pipeline.shaderProgram, transformName), 1, GL_TRUE, newTransform) pipeline.drawShape(leaf) # If the child node is not a leaf, it MUST be a SceneGraphNode, # so this draw function is called recursively else: for child in node.childs: drawSceneGraphNode(child, pipeline, transformName, newTransform)
def findTransform(node, name, parentTransform=tr.identity()): # The name was not found in this path if isinstance(node, es.GPUShape): return None newTransform = np.matmul(parentTransform, node.transform) # This is the requested node if node.name == name: return newTransform # All childs are checked for the requested name else: for child in node.childs: foundTransform = findTransform(child, name, newTransform) if isinstance(foundTransform, (np.ndarray, np.generic)): return foundTransform # No child of this node had the requested name return None
def __init__(self, name): self.name = name self.transform = tr.identity() self.childs = []