예제 #1
0
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();
        Yarn yarn = (Yarn)target;

        if (GUILayout.Button("Update"))
        {
            yarn.UpdateMesh();
        }
    }
예제 #2
0
    private void WeavePictoricalEspolin(Pictorial pictorial, Transform parent, int index, Rect rect)
    {
        YarnPictorial yarnPictorial = pictorial.processedPictorials[index];

        yarnPictorial.Prepare();
        // // Create each horizontal yarm (pictorical)
        GameObject go = Instantiate(Resources.Load("Yarn"), parent) as GameObject;

        yarnPictorial.curve = go.GetComponent <Curve>();
        yarnPictorial.curve.speedMultiplier *= gap.x;
        go.name = "P" + index;
        Yarn yarn = go.GetComponent <Yarn>();

        yarn.attributes = yarnPictorial.yarn;
        //Just for debug
        if (yarnPictorial.debugColor != Color.black)
        {
            yarn.attributes.color = yarnPictorial.debugColor;
        }

        for (int row = (int)rect.yMin; row < rect.yMax; row++)
        {
            if (yarnPictorial.firstPoint[row] != -1 && (yarnPictorial.lastPoint[row] - yarnPictorial.firstPoint[row]) > 2)
            {
                bool lastUpDown = false;
                bool healed, healed2;
                // For each cross with a vertical yarm (warp)
                if ((row % 2) == 0)
                {
                    for (var column = yarnPictorial.firstPoint[row]; column <= yarnPictorial.lastPoint[row]; column++)
                    {
                        bool upDown     = pictoricalValueAtPixel(yarnPictorial, column, row, out healed);
                        bool nextUpDown = pictoricalValueAtPixel(yarnPictorial, column + 1, row, out healed2);

                        // If the yarm doesn't change is not neccesary a control point
                        if ((column != yarnPictorial.firstPoint[row]) && (column != yarnPictorial.lastPoint[row] - 1) && column < resolution.x - 1)
                        {
                            if ((upDown == lastUpDown) && (upDown == nextUpDown)) // && depth[column,row] == depth[column+1,row])
                            {
                                continue;
                            }
                        }
                        float up;
                        if (upDown)
                        {
                            up = 2.0f;
                        }
                        else
                        {
                            up = yarnPictorial.CalculateBackDepth(this, index, column, row);
                        }
                        if (healed)
                        {
                            up *= 0.2f;
                        }
                        yarnPictorial.curve.AddControlPoint(
                            new Vector3(
                                (column - rect.x - rect.width * 0.5f) * gap.x,
                                up * gap.y * 0.5f,
                                (row - rect.y - rect.height * 0.5f) * gap.z),
                            Quaternion.LookRotation(Vector3.right, Vector3.forward),
                            lastUpDown != upDown,
                            "Control Point_" + row + "_" + column + " " + healed);

                        lastUpDown = upDown;
                    }
                }
                else
                {
                    for (var column = yarnPictorial.lastPoint[row]; column >= yarnPictorial.firstPoint[row]; column--)
                    {
                        bool upDown     = pictoricalValueAtPixel(yarnPictorial, column, row, out healed);
                        bool nextUpDown = pictoricalValueAtPixel(yarnPictorial, column - 1, row, out healed2);
                        // If the yarm doesn't change is not neccesary a control point
                        if ((column != yarnPictorial.firstPoint[row]) && (column != yarnPictorial.lastPoint[row] - 1) && column != resolution.x && column != 0)
                        {
                            if ((upDown == lastUpDown) && (upDown == nextUpDown))// && depth[column,row] == depth[column-1,row])
                            {
                                continue;
                            }
                        }
                        float up;
                        if (upDown)
                        {
                            up = 2.0f;
                        }
                        else
                        {
                            up = yarnPictorial.CalculateBackDepth(this, index, column, row);
                        }
                        if (healed)
                        {
                            up *= 0.2f;
                        }
                        yarnPictorial.curve.AddControlPoint(
                            new Vector3(
                                (column - rect.x - rect.width * 0.5f) * gap.x,
                                up * gap.y * 0.5f,
                                (row - rect.y - rect.height * 0.5f) * gap.z),
                            Quaternion.LookRotation(Vector3.left, Vector3.back),
                            lastUpDown != upDown,
                            "Control Point_" + row + "_" + column + " " + healed);

                        lastUpDown = upDown;
                    }
                }
            }
        }
        yarn.UpdateMesh();
        bounds.Encapsulate(yarn.bounds);
        yarnPictorial.ReleaseMem();
        //Split mesh
        //go.GetComponentInChildren<SplitMeshRenderer>().Split();
    }
예제 #3
0
    private void WeaveWeft(Rect rect)
    {
        // // Create each horizontal yarm (weft)
        GameObject go = null;

        go      = Instantiate(Resources.Load("Yarn"), transform) as GameObject;
        go.name = "Weft";
        Yarn yarn = go.GetComponent <Yarn>();

        yarn.attributes       = weftYarn;
        weft                  = go.GetComponent <Curve>();
        weft.speedMultiplier *= gap.x;
        for (var row = (int)rect.yMin; row < rect.yMax; row++)
        {
            bool currentUpDown = false;
            // For each cross with a vertical yarm (warp)
            if (row % 2 == 0)
            {
                for (int column = (int)rect.xMin; column < rect.xMax; column++)
                {
                    bool upDown     = valueAtPixel(column, row);
                    bool nextUpDown = valueAtPixel(column + 1, row);
                    // If the yarm doesn't change is not neccesary a control point
                    if ((column != rect.xMin) && (column != rect.xMax - 1))
                    {
                        if ((upDown == currentUpDown) && (upDown == nextUpDown))
                        {
                            continue;
                        }
                    }
                    float up = -1.0f;
                    if (!upDown)
                    {
                        up = 1.0f;
                    }

                    weft.AddControlPoint(
                        new Vector3(
                            (column - rect.x - (rect.width) * 0.5f) * gap.x,
                            up * gap.y * 0.5f,
                            (row - rect.y - (rect.height) * 0.5f) * gap.z),
                        Quaternion.LookRotation(Vector3.right, Vector3.forward),
                        currentUpDown != upDown);

                    currentUpDown = upDown;
                }
            }
            else
            {
                for (int column = (int)rect.xMax; column >= rect.xMin; column--)
                {
                    bool upDown     = valueAtPixel(column, row);
                    bool nextUpDown = valueAtPixel(column - 1, row);
                    // If the yarm doesn't change is not neccesary a control point
                    if ((column != rect.xMin) && (column != rect.xMax - 1))
                    {
                        if ((upDown == currentUpDown) && (upDown == nextUpDown))
                        {
                            continue;
                        }
                    }
                    float up = -1.0f;
                    if (!upDown)
                    {
                        up = 1.0f;
                    }

                    weft.AddControlPoint(
                        new Vector3(
                            (column - rect.x - (rect.width) * 0.5f) * gap.x,
                            up * gap.y * 0.5f,
                            (row - rect.y - (rect.height) * 0.5f) * gap.z),
                        Quaternion.LookRotation(Vector3.left, Vector3.back),
                        currentUpDown != upDown);

                    currentUpDown = upDown;
                }
            }
        }
        yarn.UpdateMesh();
        bounds.Encapsulate(yarn.bounds);
        //Split mesh
        //go.GetComponentInChildren<SplitMeshRenderer>().Split();
    }