Ejemplo n.º 1
0
    void Extrude(PrinterExtruder anExtruder)
    {
        List <Vector4> points    = extrudedPoints[anExtruder.id];
        int            prevIndex = points.Count - 1;

        int pressureDelta = anExtruder.stepDirection == StepDirection.Ccw ? 1 : -1;

        anExtruder.pressureRequired = Mathf.Clamp(anExtruder.pressureRequired - pressureDelta,
                                                  0, TickProfile.kPressureSteps);

        if (onlyCollectExtruded && anExtruder.pressureRequired > 0)
        {
            if (prevIndex >= 0 && points[prevIndex] != gap)
            {
                points.Add(gap);
            }
            return;
        }

        float relativePosition = -(m_simulation.platformRadiusInMm - (float)m_simulation.horizTrack.position);
        float distFromCenter   = anExtruder.DistanceFromPlatCenterInMm(relativePosition);
        float angleInRad       = m_simulation.platform.rotationInDegrees * Mathf.Deg2Rad;

        float colorIndex = ((anExtruder.id - kExtruderBase) * 2)
                           + ((anExtruder.stepDirection == StepDirection.Ccw) ? 0 : 1);

        Vector4 point = new Vector4(distFromCenter * Mathf.Cos(angleInRad) + m_simulation.platformRadiusInMm,
                                    m_trans.position.y,
                                    distFromCenter * Mathf.Sin(angleInRad),
                                    colorIndex);

        /*
         * if (points.Count > 1
         *      && (points[prevIndex].w == point.w)
         *      && ((Vector3)(point - points[prevIndex])).sqrMagnitude < kSqrThreshold) return;
         */
        extrudedPoints[anExtruder.id].Add(point);
    }
Ejemplo n.º 2
0
    void StepMotors()
    {
        //Text.Log(string.Format("Steps remaining: {0}, {1}", m_motorSteps[0], m_motorSteps[1]));
        for (int aMotorId = 0; aMotorId < m_motors.Length; ++aMotorId)
        {
            PrinterMotor aMotor = m_motors[aMotorId];
            if (aMotor.stepRate == 0)
            {
                continue;
            }

            --aMotor.stepCounter;
            if (aMotor.stepCounter == 0)
            {
                aMotor.stepCounter     = aMotor.stepRate;
                m_motorSteps[aMotorId] = 1;
            }
        }
        bool hasMoved = false;

        for (int aMotorId = 0; aMotorId < kExtruderBase; ++aMotorId)
        {
            if (m_motorSteps[aMotorId] > 0)
            {
                m_motors[aMotorId].Step();
                --m_motorSteps[aMotorId];
                hasMoved = true;
            }
        }
        for (int aMotorId = kExtruderBase; aMotorId < m_motorSteps.Length; ++aMotorId)
        {
            if (m_motorSteps[aMotorId] > 0)
            {
                m_motors[aMotorId].Step();
                --m_motorSteps[aMotorId];
                Extrude((PrinterExtruder)m_motors[aMotorId]);
                hasMoved = false;
            }
        }

        if (hasMoved && !onlyCollectExtruded)
        {
            PrinterExtruder anExtruder       = (PrinterExtruder)m_motors[4];
            float           relativePosition = m_simulation.platformRadiusInMm - (float)m_simulation.horizTrack.position;
            float           distFromCenter   = anExtruder.DistanceFromPlatCenterInMm(relativePosition);
            float           angleInRad       = m_simulation.platform.rotationInDegrees * Mathf.Deg2Rad;

            Vector4 point = new Vector4(distFromCenter * Mathf.Cos(angleInRad) + m_simulation.platformRadiusInMm,
                                        -m_trans.position.y,
                                        distFromCenter * Mathf.Sin(angleInRad),
                                        4);
            movementWithoutExtrusion.Add(point);
        }

        m_globalSteps = (m_globalSteps + 1) & 0xFFFFFFFF;

        Vector3 platformPosition = new Vector3(-(float)m_simulation.horizTrack.position,
                                               (float)m_simulation.vertTrack[0].position, 0);

        m_trans.position = platformPosition;
        m_trans.rotation = Quaternion.Euler(0, m_simulation.platform.rotationInDegrees, 0);
    }