def augmentEvent(self, x, y, event): ray = self.rayAtPosition(x, y) event.ray = ray event.view = self try: result = raycast.rayCastInBounds(ray, self.dimension, maxDistance=2000) position, face = result except (raycast.MaxDistanceError, ValueError): # GL.glReadBuffer(GL.GL_BACK) # pixel = GL.glReadPixels(x, self.height() - y, 1, 1, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT) # depth = -1 + 2 * pixel[0, 0] # p = self.pointsAtPositions((x, y, depth))[0] # # face = faces.FaceYIncreasing # position = p.intfloor() defaultDistance = 20 position = (ray.point + ray.vector * defaultDistance).intfloor() face = faces.FaceUp self.mouseBlockPos = event.blockPosition = position self.mouseBlockFace = event.blockFace = face self.mouseRay = ray
def importSchematic(self, filename): schematic = WorldEditor(filename, readonly=True) ray = self.editorTab.currentView().rayAtCenter() pos, face = rayCastInBounds(ray, self.currentDimension) if pos is None: pos = ray.point name = os.path.basename(filename) imp = PendingImport(schematic, pos, name) command = PasteImportCommand(self, imp, "Import %s" % name) self.undoStack.push(command)
def currentViewMatrixChanged(self, currentView): self.viewCornersNode.corners = currentView.getViewCorners() try: targetPoint, face = rayCastInBounds(Ray(currentView.centerPoint, currentView.cameraVector), self.dimension, 100) if targetPoint is None: raise MaxDistanceError planeHeight = targetPoint.y except MaxDistanceError: planeDistance = 20 planeHeight = (currentView.centerPoint + currentView.cameraVector * planeDistance).y self.viewCornersNode.planeHeight = planeHeight
def rayCastInView(self, ray): try: result = raycast.rayCastInBounds(ray, self.dimension, maxDistance=200) position, face = result except (raycast.MaxDistanceError, ValueError): # GL.glReadBuffer(GL.GL_BACK) # pixel = GL.glReadPixels(x, self.height() - y, 1, 1, GL.GL_DEPTH_COMPONENT, GL.GL_FLOAT) # depth = -1 + 2 * pixel[0, 0] # p = self.pointsAtPositions((x, y, depth))[0] # # face = faces.FaceYIncreasing # position = p.intfloor() defaultDistance = 200 position = (ray.point + ray.vector * defaultDistance).intfloor() face = faces.FaceUp return position, face