Пример #1
0
    def __init__(self):
        super(Scale3DNode, self).__init__()
        self.anchor = Translate()
        self.scale = Scale()
        self.recenter = Translate()

        self.addState(self.anchor)
        self.addState(self.scale)
        self.addState(self.recenter)
Пример #2
0
    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)
Пример #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])

    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
Пример #4
0
    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)
Пример #5
0
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
Пример #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}
    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
Пример #7
0
    def __init__(self, chunkPosition):
        """

        :param chunkPosition:
        :type chunkPosition: (int, int)
        :return:
        :rtype:
        """
        super(ChunkNode, self).__init__()
        self.chunkPosition = chunkPosition
        cx, cz = chunkPosition
        self.translate = Translate()
        self.translate.translateOffset = (cx << 4, 0, cz << 4)
        self.addState(self.translate)
        self.name = str(chunkPosition)
Пример #8
0
    def __init__(self, editorSession, *args, **kwargs):
        super(BrushTool, self).__init__(editorSession, *args, **kwargs)
        self.toolWidget = BrushToolWidget()
        self.brushMode = None
        self.brushLoader = None

        self.brushModesByName = {
            cls.name: cls(self)
            for cls in BrushModeClasses
        }
        brushModes = self.brushModesByName.values()
        self.toolWidget.brushModeInput.setModes(brushModes)
        BrushModeSetting.connectAndCall(self.modeSettingChanged)

        self.cursorWorldScene = None
        self.cursorNode = Node("brushCursor")
        self.cursorTranslate = Translate()
        self.cursorNode.addState(self.cursorTranslate)

        self.toolWidget.xSpinSlider.setMinimum(1)
        self.toolWidget.ySpinSlider.setMinimum(1)
        self.toolWidget.zSpinSlider.setMinimum(1)

        self.toolWidget.xSpinSlider.valueChanged.connect(self.setX)
        self.toolWidget.ySpinSlider.valueChanged.connect(self.setY)
        self.toolWidget.zSpinSlider.valueChanged.connect(self.setZ)

        self.toolWidget.brushShapeInput.shapeChanged.connect(self.updateCursor)
        self.toolWidget.brushShapeInput.shapeOptionsChanged.connect(
            self.updateCursor)

        self.fillBlock = editorSession.worldEditor.blocktypes["stone"]

        self.brushSize = BrushSizeSetting.value(QtGui.QVector3D(
            5, 5, 5)).toTuple()  # calls updateCursor

        self.toolWidget.xSpinSlider.setValue(self.brushSize[0])
        self.toolWidget.ySpinSlider.setValue(self.brushSize[1])
        self.toolWidget.zSpinSlider.setValue(self.brushSize[2])
        self.toolWidget.hoverSpinSlider.setValue(1)

        self.dragPoints = []
Пример #9
0
    def __init__(self, *args, **kwargs):
        EditorTool.__init__(self, *args, **kwargs)
        self.livePreview = False
        self.blockPreview = False
        self.glPreview = True

        toolWidget = QtGui.QWidget()

        self.toolWidget = toolWidget

        column = []
        self.generatorTypes = [
            pluginClass(self)
            for pluginClass in GeneratePlugins.registeredPlugins
        ]
        self.currentGenerator = None
        if len(self.generatorTypes):
            self.currentGenerator = self.generatorTypes[0]

        self.generatorTypeInput = QtGui.QComboBox()
        self.generatorTypesChanged()

        self.generatorTypeInput.currentIndexChanged.connect(
            self.currentTypeChanged)

        self.livePreviewCheckbox = QtGui.QCheckBox("Live Preview")
        self.livePreviewCheckbox.setChecked(self.livePreview)
        self.livePreviewCheckbox.toggled.connect(self.livePreviewToggled)

        self.blockPreviewCheckbox = QtGui.QCheckBox("Block Preview")
        self.blockPreviewCheckbox.setChecked(self.blockPreview)
        self.blockPreviewCheckbox.toggled.connect(self.blockPreviewToggled)

        self.glPreviewCheckbox = QtGui.QCheckBox("GL Preview")
        self.glPreviewCheckbox.setChecked(self.glPreview)
        self.glPreviewCheckbox.toggled.connect(self.glPreviewToggled)

        self.optionsHolder = QtGui.QStackedWidget()
        self.optionsHolder.setSizePolicy(QtGui.QSizePolicy.Preferred,
                                         QtGui.QSizePolicy.Expanding)

        self.generateButton = QtGui.QPushButton(self.tr("Generate"))
        self.generateButton.clicked.connect(self.generateClicked)

        column.append(self.generatorTypeInput)
        column.append(self.livePreviewCheckbox)
        column.append(self.blockPreviewCheckbox)
        column.append(self.glPreviewCheckbox)
        column.append(self.optionsHolder)
        column.append(self.generateButton)

        self.toolWidget.setLayout(Column(*column))

        self.overlayNode = scenenode.Node("generateOverlay")

        self.sceneHolderNode = Node("sceneHolder")
        self.sceneTranslate = Translate()
        self.sceneHolderNode.addState(self.sceneTranslate)

        self.overlayNode.addChild(self.sceneHolderNode)

        self.previewNode = None

        self.boxHandleNode = BoxHandle()
        self.boxHandleNode.boundsChanged.connect(self.boundsDidChange)
        self.boxHandleNode.boundsChangedDone.connect(self.boundsDidChangeDone)
        self.overlayNode.addChild(self.boxHandleNode)

        self.worldScene = None
        self.loader = None

        self.previewBounds = None
        self.schematicBounds = None
        self.currentSchematic = None

        self.currentTypeChanged(0)

        # Name of last selected generator plugin is saved after unloading
        # so it can be reselected if it is immediately reloaded
        self._lastTypeName = None

        GeneratePlugins.pluginAdded.connect(self.addPlugin)
        GeneratePlugins.pluginRemoved.connect(self.removePlugin)
Пример #10
0
    def __init__(self, pendingImport, textureAtlas, hasHandle=True):
        """
        A scenegraph node displaying an object that will be imported later, including
        live and deferred views of the object with transformed items, and a BoxHandle
        for moving the item.

        Parameters
        ----------

        pendingImport: PendingImport
            The object to be imported. The PendingImportNode responds to changes in this
            object's position, rotation, and scale.
        textureAtlas: TextureAtlas
            The textures and block models used to render the preview of the object.

        Attributes
        ----------

        basePosition: Vector
            The pre-transform position of the pending import. This is equal to
            `self.pendingImport.basePosition` except when the node is currently being
            dragged.
        transformedPosition: Vector
            The post-transform position of the pending import. This is equal to
            `self.pendingImport.importPos` except when the node is currently being
            dragged, scaled, or rotated.
        """
        super(PendingImportNode, self).__init__()

        self.textureAtlas = textureAtlas
        self.pendingImport = pendingImport
        self.hasHandle = hasHandle

        dim = pendingImport.sourceDim

        self.transformedPosition = Vector(0, 0, 0)

        # worldScene is contained by rotateNode, and
        # translates the world scene back to 0, 0, 0 so the rotateNode can
        # rotate it around the anchor, and the plainSceneNode can translate
        # it to the current position.

        self.worldScene = WorldScene(dim, textureAtlas, bounds=pendingImport.selection)
        self.worldScene.depthOffset.depthOffset = DepthOffsets.PreviewRenderer

        self.worldSceneTranslate = Translate(-self.pendingImport.selection.origin)
        self.worldScene.addState(self.worldSceneTranslate)

        # rotateNode is used to rotate the non-transformed preview during live rotation

        self.rotateNode = Rotate3DNode()
        self.rotateNode.setAnchor(self.pendingImport.selection.size * 0.5)
        self.rotateNode.addChild(self.worldScene)

        # plainSceneNode contains the non-transformed preview of the imported
        # object, including its world scene. This preview will be rotated model-wise
        # while the user is dragging the rotate controls.

        self.plainSceneNode = Node("plainScene")
        self.positionTranslate = Translate()
        self.plainSceneNode.addState(self.positionTranslate)
        self.plainSceneNode.addChild(self.rotateNode)

        self.addChild(self.plainSceneNode)

        # transformedSceneNode contains the transformed preview of the imported
        # object, including a world scene that displays the object wrapped by a
        # DimensionTransform.

        self.transformedSceneNode = Node("transformedScene")
        self.transformedSceneTranslate = Translate()
        self.transformedSceneNode.addState(self.transformedSceneTranslate)

        self.transformedWorldScene = None
        self.addChild(self.transformedSceneNode)

        box = BoundingBox(pendingImport.importPos, pendingImport.importBounds.size)

        if hasHandle:
            # handleNode displays a bounding box that can be moved around, and responds
            # to mouse events.
            self.handleNode = BoxHandle()
            self.handleNode.bounds = box
            self.handleNode.resizable = False
            self.boxNode = None
        else:
            # boxNode displays a plain, non-movable bounding box
            self.boxNode = SelectionBoxNode()
            self.boxNode.wireColor = (1, 1, 1, .2)
            self.boxNode.filled = False
            self.handleNode = None
            self.addChild(self.boxNode)

        self.updateTransformedScene()
        self.basePosition = pendingImport.basePosition

        if hasHandle:
            self.handleNode.boundsChanged.connect(self.handleBoundsChanged)
            self.handleNode.boundsChangedDone.connect(self.handleBoundsChangedDone)

            self.addChild(self.handleNode)

        # loads the non-transformed world scene asynchronously.
        self.loader = WorldLoader(self.worldScene,
                                  list(pendingImport.selection.chunkPositions()))
        self.loader.startLoader(0.1 if self.hasHandle else 0.0)

        self.pendingImport.positionChanged.connect(self.setPosition)
        self.pendingImport.rotationChanged.connect(self.setRotation)