예제 #1
0
    def _rotateCamera(self, x: float, y: float) -> None:
        camera = self._scene.getActiveCamera()
        if not camera or not camera.isEnabled():
            return

        self._scene.getSceneLock().acquire()

        dx = math.radians(x * 180.0)
        dy = math.radians(y * 180.0)

        diff = camera.getPosition() - self._origin
        my = Matrix()
        my.setByRotationAxis(dx, Vector.Unit_Y)

        mx = Matrix(my.getData())
        mx.rotateByAxis(dy, Vector.Unit_Y.cross(diff).normalized())

        n = diff.multiply(mx)

        try:
            angle = math.acos(Vector.Unit_Y.dot(n.normalized()))
        except ValueError:
            return

        if angle < 0.1 or angle > math.pi - 0.1:
            n = diff.multiply(my)

        n += self._origin

        camera.setPosition(n)
        camera.lookAt(self._origin)

        self._scene.getSceneLock().release()
예제 #2
0
    def _rotateCamera(self, x: float, y: float) -> None:
        """Rotate the camera in response to a mouse event.
        
        :param x: Amount by which the camera should be rotated horizontally, expressed in pixelunits
        :param y: Amount by which the camera should be rotated vertically, expressed in pixelunits
        """

        camera = self._scene.getActiveCamera()
        if not camera or not camera.isEnabled():
            return

        dx = math.radians(x * 180.0)
        dy = math.radians(y * 180.0)

        diff = camera.getPosition() - self._origin
        my = Matrix()
        my.setByRotationAxis(dx, Vector.Unit_Y)

        mx = Matrix(my.getData())
        mx.rotateByAxis(dy, Vector.Unit_Y.cross(diff).normalized())

        n = diff.multiply(mx)

        try:
            angle = math.acos(Vector.Unit_Y.dot(n.normalized()))
        except ValueError:
            return

        if angle < 0.1 or angle > math.pi - 0.1:
            n = diff.multiply(my)

        n += self._origin

        camera.setPosition(n)
        camera.lookAt(self._origin)
예제 #3
0
    def _rotateCamera(self, x, y):
        camera = self._scene.getActiveCamera()
        if not camera or not camera.isEnabled():
            return

        self._scene.acquireLock()

        dx = math.radians(x * 180.0)
        dy = math.radians(y * 180.0)

        diff = camera.getPosition() - self._origin
        my = Matrix()
        my.setByRotationAxis(dx, Vector.Unit_Y)

        mx = Matrix(my.getData())
        mx.rotateByAxis(dy, Vector.Unit_Y.cross(diff).normalized())

        n = diff.multiply(mx)

        try:
            angle = math.acos(Vector.Unit_Y.dot(n.normalized()))
        except ValueError:
            return

        if angle < 0.1 or angle > math.pi - 0.1:
            n = diff.multiply(my)

        n += self._origin

        camera.setPosition(n)
        camera.lookAt(self._origin)

        self._scene.releaseLock()
예제 #4
0
    def _rotateCamera(self, x, y):
        camera = self._scene.getActiveCamera()
        if not camera or not camera.isEnabled():
            return

        self._scene.acquireLock()

        dx = math.radians(x * 180.0)
        dy = math.radians(y * 180.0)

        diff = camera.getPosition() - self._origin

        diff_flat = Vector(diff.x, 0.0, diff.z).getNormalized()
        try:
            new_angle = math.acos(diff_flat.dot(diff.getNormalized())) + dy
        except ValueError:
            return

        m = Matrix()
        m.setByRotationAxis(dx, Vector.Unit_Y)
        if new_angle < (math.pi / 2 - 0.01):
            m.rotateByAxis(dy, Vector.Unit_Y.cross(diff).normalize())

        n = diff.multiply(m)
        n += self._origin

        camera.setPosition(n)
        camera.lookAt(self._origin)

        self._scene.releaseLock()
    def _rotateCameraConstrained(angleAzim: float, angleIncl: float) -> None:
        if SpaceMouseTool._rotationLocked:
            return
        camera = SpaceMouseTool._scene.getActiveCamera()
        if not camera or not camera.isEnabled():
            return

        # we need to compute the translation and lookAt in one step as we otherwise get artifacts
        # from first setting the camera to a new position and then telling it to look at the
        # rotation center

        up = Vector.Unit_Y
        target = SpaceMouseTool._cameraTool.getOrigin()

        oldEye = camera.getWorldPosition()
        camToTarget = (target - oldEye).normalized()

        # compute angle between up axis and current camera ray
        try:
            angleToY = math.acos(up.dot(camToTarget))
        except ValueError:
            return

        # compute new position of camera
        rotMat = Matrix()
        rotMat.rotateByAxis(angleAzim, up, target.getData())
        # prevent camera from rotating to close to the poles
        if (angleToY > 0.1 or angleIncl > 0) and (angleToY < math.pi - 0.1
                                                  or angleIncl < 0):
            rotMat.rotateByAxis(angleIncl,
                                up.cross(camToTarget).normalized(),
                                target.getData())
        newEye = oldEye.preMultiply(rotMat)

        # look at (from UM.Scene.SceneNode)
        f = (target - newEye).normalized()
        s = f.cross(up).normalized()
        u = s.cross(f).normalized()

        # construct new matrix for camera including the new position and orientation from looking at
        # the rotation center
        newTrafo = Matrix([[s.x, u.x, -f.x, newEye.x],
                           [s.y, u.y, -f.y, newEye.y],
                           [s.z, u.z, -f.z, newEye.z], [0.0, 0.0, 0.0, 1.0]])

        camera.setTransformation(newTrafo)
예제 #6
0
    def _createPolygon(self, layer_thickness: float, path: List[List[Union[float, int]]], extruder_offsets: List[float]) -> bool:
        countvalid = 0
        for point in path:
            if point[8] > 0:
                countvalid += 1
                if countvalid >= 2:
                    # we know what to do now, no need to count further
                    continue
        if countvalid < 2:
            return False
        try:
            self._layer_data_builder.addLayer(self._layer_number)
            self._layer_data_builder.setLayerHeight(self._layer_number, path[0][2])
            self._layer_data_builder.setLayerThickness(self._layer_number, layer_thickness)
            this_layer = self._layer_data_builder.getLayer(self._layer_number)
        except ValueError:
            return False
        count = len(path)
        line_types = numpy.empty((count - 1, 1), numpy.int32)
        line_widths = numpy.empty((count - 1, 1), numpy.float32)
        line_thicknesses = numpy.empty((count - 1, 1), numpy.float32)
        line_feedrates = numpy.empty((count - 1, 1), numpy.float32)
        line_widths[:, 0] = 0.35  # Just a guess
        line_thicknesses[:, 0] = layer_thickness
        points = numpy.empty((count, 6), numpy.float32)
        extrusion_values = numpy.empty((count, 1), numpy.float32)
        i = 0
        for point in path:
            matrix = Matrix([[point[0], point[1], point[2], 1]])
            vector_matrix = Matrix([[0,0,1,1]])
            matrix.rotateByAxis(radians(point[3]), Vector.Unit_X)
            matrix.rotateByAxis(radians(point[4]), Vector.Unit_Y)
            matrix.rotateByAxis(radians(point[5]), Vector.Unit_Z)
            vector_matrix.rotateByAxis(radians(point[3]), Vector.Unit_X)
            vector_matrix.rotateByAxis(radians(point[4]), Vector.Unit_Y)
            vector_matrix.rotateByAxis(radians(point[5]), Vector.Unit_Z)
            #points[i, :] = [point[0] + extruder_offsets[0], point[2], -point[1] - extruder_offsets[1]]
            points[i, :] = [matrix.at(0,0) + extruder_offsets[0], matrix.at(0,2), -matrix.at(0,1)-extruder_offsets[1], 
                            -vector_matrix.at(0,1), vector_matrix.at(0,2), -vector_matrix.at(0,0)]
            extrusion_values[i] = point[7]
            if i > 0:
                line_feedrates[i - 1] = point[6]
                line_types[i - 1] = point[8]
                if point[8] in [LayerPolygon.MoveCombingType, LayerPolygon.MoveRetractionType]:
                    line_widths[i - 1] = 0.1
                    line_thicknesses[i - 1] = 0.0 # Travels are set as zero thickness lines
                else:
                    line_widths[i - 1] = self._calculateLineWidth(points[i], points[i-1], extrusion_values[i], extrusion_values[i-1], layer_thickness)
            i += 1

        this_poly = LayerPolygon(self._extruder_number, line_types, points, line_widths, line_thicknesses, line_feedrates)
        this_poly.buildCache()

        this_layer.polygons.append(this_poly)
        return True
예제 #7
0
    def _rotateCamera(self, x, y):
        camera = self._scene.getActiveCamera()
        if not camera or not camera.isEnabled():
            return

        self._scene.acquireLock()

        dx = math.radians(x * 180.0)
        dy = math.radians(y * 180.0)

        diff = camera.getPosition() - self._origin

        m = Matrix()
        m.setByRotationAxis(dx, Vector.Unit_Y)
        m.rotateByAxis(dy, Vector.Unit_Y.cross(diff).normalize())

        n = diff.multiply(m)
        n += self._origin

        camera.setPosition(n)
        camera.lookAt(self._origin)

        self._scene.releaseLock()
예제 #8
0
    def _rotateCamera(self, yaw: float, pitch: float, roll: float) -> None:
        camera = self._scene.getActiveCamera()
        if not camera or not camera.isEnabled():
            return

        dyaw = math.radians(yaw * 180.0)
        dpitch = math.radians(pitch * 180.0)
        droll = math.radians(roll * 180.0)

        diff = camera.getPosition() - self._camera_tool._origin

        myaw = Matrix()
        myaw.setByRotationAxis(dyaw, Vector.Unit_Y)

        mpitch = Matrix(myaw.getData())
        mpitch.rotateByAxis(dpitch, Vector.Unit_Y.cross(diff))

        n = diff.multiply(mpitch)

        try:
            angle = math.acos(Vector.Unit_Y.dot(n.normalized()))
        except ValueError:
            return

        if angle < 0.1 or angle > math.pi - 0.1:
            n = diff.multiply(myaw)

        n += self._camera_tool._origin

        camera.setPosition(n)

        if abs(self._roll + droll) < math.pi * 0.45:
            self._roll += droll
        mroll = Matrix()
        mroll.setByRotationAxis(self._roll, (n - self._camera_tool._origin))
        camera.lookAt(self._camera_tool._origin, Vector.Unit_Y.multiply(mroll))