def createSceneGraph(self): sceneGraph = scenenode.Node("WorldView SceneGraph") self.worldScene = self.createWorldScene() self.worldScene.setVisibleLayers( self.layerToggleGroup.getVisibleLayers()) clearNode = ClearNode() self.skyNode = sky.SkyNode() self.loadableChunksNode = loadablechunks.LoadableChunksNode( self.dimension) self.worldNode = Node("World Container") self.matrixState = MatrixState() self.worldNode.addState(self.matrixState) self._updateMatrices() self.worldNode.addChild(self.loadableChunksNode) self.worldNode.addChild(self.worldScene) self.worldNode.addChild(self.overlayNode) sceneGraph.addChild(clearNode) sceneGraph.addChild(self.skyNode) sceneGraph.addChild(self.worldNode) sceneGraph.addChild(self.compassNode) if self.cursorNode: self.worldNode.addChild(self.cursorNode) return sceneGraph
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)
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)
def CommandVisuals(pos, commandObj): visualCls = _visualClasses.get(commandObj.name) if visualCls is None: log.warn("No command found for %s", commandObj.name) return Node("nullCommandVisuals") else: return visualCls(pos, commandObj)
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) monsters = self._computeVertices(monsterPositions, (0xff, 0x22, 0x22, 0x44), offset=True, chunkPosition=chunk.chunkPosition) yield vertexNode = VertexNode(monsters) polyNode = PolygonModeNode(GL.GL_FRONT_AND_BACK, GL.GL_LINE) polyNode.addChild(vertexNode) lineNode = LineWidthNode(2.0) lineNode.addChild(polyNode) depthNode = DepthFuncNode(GL.GL_ALWAYS) depthNode.addChild(lineNode) self.sceneNode = Node() self.sceneNode.addChild(depthNode) vertexNode = VertexNode(monsters) self.sceneNode.addChild(vertexNode)
def LineArcNode(p1, p2, color): arcSegments = 20 rgba = [c * 255 for c in color] points = [p1] x, y, z = p1 dx = p2[0] - p1[0] dz = p2[2] - p1[2] dx /= arcSegments dz /= arcSegments heightDiff = p2[1] - p1[1] # maxRise = 8 # initial y-velocity dy = 0.3 if heightDiff >= 0 else -0.3 dy += 2 * heightDiff / arcSegments # the height of p2 without gravity overshot = y + dy * arcSegments - p2[1] # needed gravity so the last point is p2 ddy = -overshot / (arcSegments * (arcSegments - 1) / 2) for i in range(arcSegments): y += dy dy += ddy x += dx z += dz points.append((x, y, z)) arcNode = Node("lineArc") lineNode = LineStripNode(points, rgba) arcNode.addChild(lineNode) arcNode.addState(LineWidth(3.0)) backLineNode = Node("lineArcBack") backLineNode.addChild(lineNode) arcNode.addChild(backLineNode) backLineNode.addState(DepthFunc(GL.GL_GREATER)) backLineNode.addState(LineWidth(1.0)) return arcNode
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 = []
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)
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)
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)