コード例 #1
0
ファイル: entitymesh.py プロジェクト: brennced/mcedit2
    def makeChunkVertices(self, chunk, limitBox):
        mapTiles = []
        for i, ref in enumerate(chunk.Entities):
            if ref.id != "ItemFrame":
                continue

            if i % 10 == 0:
                yield

            if limitBox and ref.Position not in limitBox:
                continue

            try:
                item = ref.Item
                if item.itemType.internalName != "minecraft:filled_map":
                    continue
            except KeyError:
                log.exception(
                    "Error while getting ItemFrame item ID in frame at %s",
                    ref.TilePos)
                continue

            mapID = item.Damage

            mapTex = self.chunkUpdate.updateTask.getMapTexture(mapID)
            # xxx if mapTex is None: mapTex = missingNoTex

            # xxxx assumes 1.8 TilePos - fix this in ref??
            mapTiles.append((mapTex, ref.TilePos, ref.Facing))

        if not len(mapTiles):
            return

        nodes = []

        for mapTex, (x, y, z), facing in mapTiles:
            vertexBuffer = QuadVertexArrayBuffer(1,
                                                 lights=False,
                                                 textures=True)

            # chunk is already translated - why?
            x -= chunk.cx << 4
            z -= chunk.cz << 4

            vertexBuffer.vertex[:] = x, y, z
            corners = self.faceCorners[facing]
            vertexBuffer.vertex[:] += corners
            texCorners = [(1, 1), (1, 0), (0, 0), (0, 1)]
            vertexBuffer.texcoord[:] += texCorners

            vertexNode = VertexNode([vertexBuffer])
            if mapTex is not None:
                bindTexture = BindTexture(mapTex)
                vertexNode.addState(bindTexture)
            nodes.append(vertexNode)

        self.sceneNode = scenenode.Node("itemFrames")
        for node in nodes:
            self.sceneNode.addChild(node)
コード例 #2
0
ファイル: entitymesh.py プロジェクト: KevinKelley/mcedit2
    def makeChunkVertices(self, chunk, limitBox):
        mapTiles = []
        for i, ref in enumerate(chunk.Entities):
            if ref.id != "ItemFrame":
                continue

            if i % 10 == 0:
                yield

            if limitBox and ref.Position not in limitBox:
                continue

            try:
                item = ref.Item
                if item.itemType.internalName != "minecraft:filled_map":
                    continue
            except KeyError:
                log.exception("Error while getting ItemFrame item ID in frame at %s", ref.TilePos)
                continue

            mapID = item.Damage

            mapTex = self.chunkUpdate.updateTask.getMapTexture(mapID)
            # xxx if mapTex is None: mapTex = missingNoTex

            # xxxx assumes 1.8 TilePos - fix this in ref??
            mapTiles.append((mapTex, ref.TilePos, ref.Facing))

        if not len(mapTiles):
            return

        nodes = []

        for mapTex, (x, y, z), facing in mapTiles:
            vertexBuffer = QuadVertexArrayBuffer(1, lights=False, textures=True)

            # chunk is already translated - why?
            x -= chunk.cx << 4
            z -= chunk.cz << 4

            vertexBuffer.vertex[:] = x, y, z
            corners = self.faceCorners[facing]
            vertexBuffer.vertex[:] += corners
            texCorners = [(1, 1), (1, 0), (0, 0), (0, 1)]
            vertexBuffer.texcoord[:] += texCorners

            vertexNode = VertexNode([vertexBuffer])
            if mapTex is not None:
                bindTexture = BindTexture(mapTex)
                vertexNode.addState(bindTexture)
            nodes.append(vertexNode)

        self.sceneNode = scenenode.Node("itemFrames")
        for node in nodes:
            self.sceneNode.addChild(node)
コード例 #3
0
ファイル: entitymesh.py プロジェクト: brennced/mcedit2
    def makeChunkVertices(self, chunk, limitBox):
        monsterPositions = []
        for i, entityRef in enumerate(chunk.Entities):
            if i % 10 == 0:
                yield
            ID = entityRef.id

            if ID in self.notMonsters:
                continue
            pos = entityRef.Position
            if limitBox and pos not in limitBox:
                continue
            monsterPositions.append(pos)

        if not len(monsterPositions):
            return

        monsters = self._computeVertices(monsterPositions,
                                         (0xff, 0x22, 0x22, 0x44),
                                         offset=True,
                                         chunkPosition=chunk.chunkPosition)
        yield

        vertexNode = VertexNode(monsters)
        vertexNode.addState(PolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE))
        vertexNode.addState(LineWidth(2.0))
        vertexNode.addState(DepthFunc(GL.GL_ALWAYS))

        self.sceneNode = Node("monsterLocations")
        self.sceneNode.addChild(vertexNode)

        vertexNode = VertexNode(monsters)
        self.sceneNode.addChild(vertexNode)
コード例 #4
0
ファイル: entitymesh.py プロジェクト: brennced/mcedit2
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
コード例 #5
0
ファイル: entitymesh.py プロジェクト: brennced/mcedit2
    def makeChunkVertices(self, chunk, limitBox):
        tilePositions = []
        defaultColor = (0xff, 0xff, 0x33, 0x44)
        for i, ref in enumerate(chunk.TileEntities):
            if i % 10 == 0:
                yield

            if limitBox and ref.Position not in limitBox:
                continue
            if ref.id == "Control":
                continue
            tilePositions.append(ref.Position)

        if not len(tilePositions):
            return

        tiles = self._computeVertices(tilePositions,
                                      defaultColor,
                                      chunkPosition=chunk.chunkPosition)

        vertexNode = VertexNode([tiles])
        polygonMode = PolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE)
        vertexNode.addState(polygonMode)
        lineWidth = LineWidth(2.0)
        vertexNode.addState(lineWidth)
        depthFunc = DepthFunc(GL.GL_ALWAYS)
        vertexNode.addState(depthFunc)

        self.sceneNode = Node("tileEntityLocations")
        self.sceneNode.addChild(vertexNode)

        vertexNode = VertexNode([tiles])
        self.sceneNode.addChild(vertexNode)
コード例 #6
0
ファイル: entitymesh.py プロジェクト: KevinKelley/mcedit2
    def makeChunkVertices(self, chunk, limitBox):
        monsterPositions = []
        for i, entityRef in enumerate(chunk.Entities):
            if i % 10 == 0:
                yield
            ID = entityRef.id

            if ID in self.notMonsters:
                continue
            pos = entityRef.Position
            if limitBox and pos not in limitBox:
                continue
            monsterPositions.append(pos)

        if not len(monsterPositions):
            return

        monsters = self._computeVertices(monsterPositions,
                                         (0xff, 0x22, 0x22, 0x44),
                                         offset=True,
                                         chunkPosition=chunk.chunkPosition)
        yield

        vertexNode = VertexNode(monsters)
        vertexNode.addState(PolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE))
        vertexNode.addState(LineWidth(2.0))
        vertexNode.addState(DepthFunc(GL.GL_ALWAYS))

        self.sceneNode = Node("monsterLocations")
        self.sceneNode.addChild(vertexNode)

        vertexNode = VertexNode(monsters)
        self.sceneNode.addChild(vertexNode)
コード例 #7
0
ファイル: entitymesh.py プロジェクト: KevinKelley/mcedit2
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
コード例 #8
0
ファイル: entitymesh.py プロジェクト: KevinKelley/mcedit2
    def makeChunkVertices(self, chunk, limitBox):
        tilePositions = []
        defaultColor = (0xff, 0xff, 0x33, 0x44)
        for i, ref in enumerate(chunk.TileEntities):
            if i % 10 == 0:
                yield

            if limitBox and ref.Position not in limitBox:
                continue
            if ref.id == "Control":
                continue
            tilePositions.append(ref.Position)

        if not len(tilePositions):
            return

        tiles = self._computeVertices(tilePositions, defaultColor, chunkPosition=chunk.chunkPosition)

        vertexNode = VertexNode([tiles])
        polygonMode = PolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE)
        vertexNode.addState(polygonMode)
        lineWidth = LineWidth(2.0)
        vertexNode.addState(lineWidth)
        depthFunc = DepthFunc(GL.GL_ALWAYS)
        vertexNode.addState(depthFunc)

        self.sceneNode = Node("tileEntityLocations")
        self.sceneNode.addChild(vertexNode)

        vertexNode = VertexNode([tiles])
        self.sceneNode.addChild(vertexNode)
コード例 #9
0
ファイル: entitymesh.py プロジェクト: wcpe/mcedit2
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
コード例 #10
0
ファイル: entitymesh.py プロジェクト: Dunimark/mcedit2
    def makeChunkVertices(self, chunk, limitBox):
        tilePositions = []
        tileColors = []
        defaultColor = (0xff, 0x33, 0x33, 0x44)
        for i, ref in enumerate(chunk.TileEntities):
            if i % 10 == 0:
                yield

            if limitBox and ref.Position not in limitBox:
                continue
            if ref.id == "Control":
                tilePositions.append(ref.Position)
                cmdText = ref.Command
                if len(cmdText):
                    if cmdText[0] == "/":
                        cmdText = cmdText[1:]
                    command, _ = cmdText.split(None, 1)
                    color = commandColor(command)
                    tileColors.append(color + (0x44,))
                else:
                    tileColors.append(defaultColor)
            else:
                continue

        tiles = self._computeVertices(tilePositions, tileColors, chunkPosition=chunk.chunkPosition)

        vertexNode = VertexNode([tiles])
        vertexNode.addState(PolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE))
        vertexNode.addState(LineWidth(2.0))
        vertexNode.addState(DepthFunc(GL.GL_ALWAYS))

        self.sceneNode = Node()
        self.sceneNode.addChild(vertexNode)
コード例 #11
0
ファイル: entitymesh.py プロジェクト: brennced/mcedit2
    def makeChunkVertices(self, chunk, limitBox):
        tilePositions = []
        tileColors = []
        defaultColor = (0xff, 0x33, 0x33, 0x44)
        for i, ref in enumerate(chunk.TileEntities):
            if i % 10 == 0:
                yield

            if limitBox and ref.Position not in limitBox:
                continue
            if ref.id == "Control":
                tilePositions.append(ref.Position)
                cmdText = ref.Command
                if len(cmdText):
                    if cmdText[0] == "/":
                        cmdText = cmdText[1:]
                    command, _ = cmdText.split(None, 1)
                    color = commandColor(command)
                    tileColors.append(color + (0x44, ))
                else:
                    tileColors.append(defaultColor)
            else:
                continue

        if not len(tileColors):
            return

        tiles = self._computeVertices(tilePositions,
                                      tileColors,
                                      chunkPosition=chunk.chunkPosition)

        vertexNode = VertexNode([tiles])
        vertexNode.addState(PolygonMode(GL.GL_FRONT_AND_BACK, GL.GL_LINE))
        vertexNode.addState(LineWidth(2.0))
        vertexNode.addState(DepthFunc(GL.GL_ALWAYS))

        self.sceneNode = Node("commandBlockLocations")
        self.sceneNode.addChild(vertexNode)
コード例 #12
0
ファイル: entitymesh.py プロジェクト: brennced/mcedit2
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
コード例 #13
0
ファイル: entitymesh.py プロジェクト: brennced/mcedit2
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
コード例 #14
0
ファイル: entitymesh.py プロジェクト: KevinKelley/mcedit2
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