def __init__(self, small=False): super(CompassNode, self).__init__() self.small = small v = QuadVertexArrayBuffer(1, textures=True) v.vertex[..., :2] = makeQuad(-.1, -.1, 0.2, 0.2) v.texcoord[:] = makeQuad(0, 0, 1, 1) v.rgba[:] = 0xff self.vertexNode = VertexNode([v]) self.pitchState = Rotate(0, (1., 0., 0.)) self.yawState = Rotate(0, (0., 0., 1.)) self.addState(Identity()) self.addState(Translate((0.9, 0.1, 0.0))) self.addState(self.pitchState) self.addState(self.yawState) self.addState(Disable(GL.GL_DEPTH_TEST)) self.addState(Enable(GL.GL_BLEND, GL.GL_TEXTURE_2D)) if small: filename = "compass_small.png" else: filename = "compass.png" self._tex = loadPNGTexture(filename, minFilter=GL.GL_LINEAR, magFilter=GL.GL_LINEAR) self.textureState = BindTexture(self._tex) self.addState(self.textureState) self.addChild(self.vertexNode)
def __init__(self): super(Rotate3DNode, self).__init__() self.anchor = Translate() self.rotX = Rotate(axis=(1, 0, 0)) self.rotY = Rotate(axis=(0, 1, 0)) self.rotZ = Rotate(axis=(0, 0, 1)) self.recenter = Translate() self.addState(self.anchor) self.addState(self.rotZ) self.addState(self.rotY) self.addState(self.rotX) self.addState(self.recenter)
def entityModelNode(ref, model, modelTex, chunk): modelVerts = numpy.array(model.vertices) modelVerts.shape = modelVerts.shape[0] // 4, 4, modelVerts.shape[1] # scale down modelVerts[..., :3] *= 1 / 16. modelVerts[..., 1] = -modelVerts[..., 1] + 1.5 + 1 / 64. modelVerts[..., 0] = -modelVerts[..., 0] vertexBuffer = QuadVertexArrayBuffer(len(modelVerts), lights=False, textures=True) vertexBuffer.vertex[:] = modelVerts[..., :3] vertexBuffer.texcoord[:] = modelVerts[..., 3:5] node = VertexNode([vertexBuffer]) rotate = Rotate(ref.Rotation[0], (0., 1., 0.)) node.addState(rotate) translate = Translate((ref.Position - (chunk.cx << 4, 0, chunk.cz << 4))) node.addState(translate) bindTexture = BindTexture(modelTex, (1. / model.texWidth, 1. / model.texHeight, 1)) node.addState(bindTexture) return node
def entityModelNode(ref, model, modelTex=None, chunk=None, flip=False): modelVerts = numpy.array(model.vertices) modelVerts.shape = modelVerts.shape[0] // 4, 4, modelVerts.shape[1] # scale down modelVerts[..., :3] *= 1 / 16. modelVerts[..., 1] = -modelVerts[..., 1] + 1.5 + 1 / 64. modelVerts[..., 0] = -modelVerts[..., 0] vertexBuffer = QuadVertexArrayBuffer(len(modelVerts), lights=False, textures=modelTex is not None) vertexBuffer.vertex[:] = modelVerts[..., :3] if modelTex is not None: vertexBuffer.texcoord[:] = modelVerts[..., 3:5] node = VertexNode([vertexBuffer]) pos = ref.Position if chunk is not None: pos = pos - (chunk.cx << 4, 0, chunk.cz << 4) translate = Translate(pos) node.addState(translate) rotate = Rotate(ref.Rotation[0], (0., 1., 0.)) node.addState(rotate) if modelTex is not None: bindTexture = BindTexture(modelTex, (1. / model.texWidth, 1. / model.texHeight * (-1 if flip else 1), 1)) node.addState(bindTexture) return node
def chestEntityModelNode(ref, model, modelTex, chunk, facing, largeX, largeZ): modelVerts = numpy.array(model.vertices) modelVerts.shape = modelVerts.shape[0] // 4, 4, modelVerts.shape[1] # scale down modelVerts[..., :3] *= 1 / 16. # modelVerts[..., 1] = -modelVerts[..., 1] # modelVerts[..., 0] = -modelVerts[..., 0] vertexBuffer = QuadVertexArrayBuffer(len(modelVerts), lights=False, textures=True) vertexBuffer.vertex[:] = modelVerts[..., :3] vertexBuffer.texcoord[:] = modelVerts[..., 3:5] node = VertexNode([vertexBuffer]) rotations = {"north": 180, "east": 270, "south": 0, "west": 90} decenterState = Translate((-0.5, -0.5, -0.5)) node.addState(decenterState) rotate = Rotate(rotations[facing], (0., 1., 0.)) node.addState(rotate) dx = dz = 0 if largeX and facing == "north": dx = 1. if largeZ and facing == "east": dz = -1. recenterState = Translate((0.5 + dx, 0.5, 0.5 + dz)) node.addState(recenterState) x, y, z = (ref.Position - (chunk.cx << 4, 0, chunk.cz << 4)) scale = Scale((1., -1., -1.)) node.addState(scale) posTranslate = Translate((x, y + 1., z + 1.)) node.addState(posTranslate) bindTexture = BindTexture(modelTex, (1. / model.texWidth, 1. / model.texHeight, 1)) node.addState(bindTexture) return node