Exemplo n.º 1
0
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])
    rotateNode = RotateNode(ref.Rotation[0], (0., 1., 0.))
    rotateNode.addChild(node)
    translateNode = TranslateNode(
        (ref.Position - (chunk.cx << 4, 0, chunk.cz << 4)))
    translateNode.addChild(rotateNode)

    textureNode = BindTextureNode(
        modelTex, (1. / model.texWidth, 1. / model.texHeight, 1))
    textureNode.addChild(translateNode)
    return textureNode
Exemplo n.º 2
0
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
    }
    decenterTranslateNode = TranslateNode((-0.5, -0.5, -0.5))
    decenterTranslateNode.addChild(node)

    rotateNode = RotateNode(rotations[facing], (0., 1., 0.))
    # rotateNode = RotateNode(0, (0., 1., 0.))
    rotateNode.addChild(decenterTranslateNode)
    dx = dz = 0
    if largeX and facing == "north":
        dx = 1.
    if largeZ and facing == "east":
        dz = -1.
    recenterTranslateNode = TranslateNode((0.5+dx, 0.5, 0.5+dz))
    recenterTranslateNode.addChild(rotateNode)
    x, y, z = (ref.Position - (chunk.cx << 4, 0, chunk.cz << 4))
    scaleNode = ScaleNode((1., -1., -1.))
    scaleNode.addChild(recenterTranslateNode)
    posTranslateNode = TranslateNode((x, y+1., z+1.))
    posTranslateNode.addChild(scaleNode)

    textureNode = BindTextureNode(modelTex, (1./model.texWidth, 1./model.texHeight, 1))
    textureNode.addChild(posTranslateNode)
    return textureNode
Exemplo n.º 3
0
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])
    rotateNode = RotateNode(ref.Rotation[0], (0., 1., 0.))
    rotateNode.addChild(node)
    translateNode = TranslateNode((ref.Position - (chunk.cx << 4, 0, chunk.cz << 4)))
    translateNode.addChild(rotateNode)

    textureNode = BindTextureNode(modelTex, (1./model.texWidth, 1./model.texHeight, 1))
    textureNode.addChild(translateNode)
    return textureNode
Exemplo n.º 4
0
class Rotate3DNode(Node):
    def __init__(self):
        super(Rotate3DNode, self).__init__()
        self.anchorNode = TranslateNode()
        self.rotXNode = RotateNode(axis=(1, 0, 0))
        self.rotYNode = RotateNode(axis=(0, 1, 0))
        self.rotZNode = RotateNode(axis=(0, 0, 1))
        self.recenterNode = TranslateNode()

        super(Rotate3DNode, self).addChild(self.anchorNode)
        self.anchorNode.addChild(self.rotZNode)
        self.rotZNode.addChild(self.rotYNode)
        self.rotYNode.addChild(self.rotXNode)
        self.rotXNode.addChild(self.recenterNode)

    def addChild(self, node):
        self.recenterNode.addChild(node)

    def removeChild(self, node):
        self.recenterNode.removeChild(node)

    def setRotation(self, rots):
        rx, ry, rz = rots
        self.rotXNode.degrees = rx
        self.rotYNode.degrees = ry
        self.rotZNode.degrees = rz

    def setAnchor(self, point):
        self.anchorNode.translateOffset = point
        self.recenterNode.translateOffset = -point
Exemplo n.º 5
0
class Rotate3DNode(Node):
    def __init__(self):
        super(Rotate3DNode, self).__init__()
        self.anchorNode = TranslateNode()
        self.rotXNode = RotateNode(axis=(1, 0, 0))
        self.rotYNode = RotateNode(axis=(0, 1, 0))
        self.rotZNode = RotateNode(axis=(0, 0, 1))
        self.recenterNode = TranslateNode()

        super(Rotate3DNode, self).addChild(self.anchorNode)
        self.anchorNode.addChild(self.rotZNode)
        self.rotZNode.addChild(self.rotYNode)
        self.rotYNode.addChild(self.rotXNode)
        self.rotXNode.addChild(self.recenterNode)

    def addChild(self, node):
        self.recenterNode.addChild(node)

    def removeChild(self, node):
        self.recenterNode.removeChild(node)

    def setRotation(self, rots):
        rx, ry, rz = rots
        self.rotXNode.degrees = rx
        self.rotYNode.degrees = ry
        self.rotZNode.degrees = rz

    def setAnchor(self, point):
        self.anchorNode.translateOffset = point
        self.recenterNode.translateOffset = -point
Exemplo n.º 6
0
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}
    decenterTranslateNode = TranslateNode((-0.5, -0.5, -0.5))
    decenterTranslateNode.addChild(node)

    rotateNode = RotateNode(rotations[facing], (0., 1., 0.))
    # rotateNode = RotateNode(0, (0., 1., 0.))
    rotateNode.addChild(decenterTranslateNode)
    dx = dz = 0
    if largeX and facing == "north":
        dx = 1.
    if largeZ and facing == "east":
        dz = -1.
    recenterTranslateNode = TranslateNode((0.5 + dx, 0.5, 0.5 + dz))
    recenterTranslateNode.addChild(rotateNode)
    x, y, z = (ref.Position - (chunk.cx << 4, 0, chunk.cz << 4))
    scaleNode = ScaleNode((1., -1., -1.))
    scaleNode.addChild(recenterTranslateNode)
    posTranslateNode = TranslateNode((x, y + 1., z + 1.))
    posTranslateNode.addChild(scaleNode)

    textureNode = BindTextureNode(
        modelTex, (1. / model.texWidth, 1. / model.texHeight, 1))
    textureNode.addChild(posTranslateNode)
    return textureNode