Example #1
0
    private void WeavePictorical(int index, Rect rect)
    {
        Pictorial  pictorial = pictorials[index];
        int        i         = 0;
        GameObject go        = new GameObject();
        Transform  p         = go.transform;

        go.name  = "Pictorical" + index;
        p.parent = transform;
        foreach (var pp in pictorial.processedPictorials)
        {
            WeavePictoricalEspolin(pictorial, p, i++, rect);
        }
    }
Example #2
0
 public YarnPictorial(Pictorial copy)
 {
     if (copy.curve == null)
     {
         curve = null;
     }
     else
     {
         GameObject.Instantiate(copy.curve);
     }
     drawing       = copy.drawing;
     debugColor    = copy.debugColor;
     contour       = null;
     yarn          = copy.yarn;
     adjusted      = copy.adjusted;
     healedStep    = copy.healedStep;
     healedStepGap = copy.healedStepGap;
     doubleHealed  = copy.doubleHealed;
 }
Example #3
0
    IEnumerator WeavePatch(float delayTime)
    {
        yield return(new WaitForSeconds(delayTime));

        if (instantiatedPatch == null)
        {
            var go = Instantiate(patchPrefab, Vector3.zero, Quaternion.identity);
            instantiatedPatch = go.GetComponent <Patch>();
        }

        var patch = instantiatedPatch;

        //Reset Patch Parent Rotation
        instantiatedPatch.transform.parent.rotation = Quaternion.identity;
        instantiatedPatch.transform.parent.GetComponent <RotatePatch>().targetRotation = 0;

        //Background Pattern
        var background = yarnEntities.First(y => y.yarnPanel.isBackground && y.yarnPanel.yarnZone == YarnPanel.YarnZone.Weft);

        if (selectedTechniqueRestrictions.uniformBackground)
        {
            patch.backgroundPattern.pattern = backgroundWhiteTexture;
        }
        else if (selectedTechniqueRestrictions.technique == GeneralTechnique.SpolinedDamask)
        {
            var pictbackground = yarnEntities.Last(y => y.yarnPanel.isBackground && y.yarnPanel.yarnZone == YarnPanel.YarnZone.Weft);
            var matDamasse     = new Mat();
            OpenCVForUnity.CoreModule.Core.bitwise_not(imageProcessingResults[pictbackground.clusterId], matDamasse);
            patch.backgroundPattern.pattern = matDamasse;
        }
        else
        {
            patch.backgroundPattern.pattern = imageProcessingResults[background.clusterId];
        }

        background.geometryIndex = 1;


        patch.warpYarn = warpPanel.GetScriptableYarn();

        if (_generalTechnique == GeneralTechnique.Damask)
        {
            var damaskBg = yarnEntities.First(y => y.yarnPanel.yarnZone == YarnPanel.YarnZone.Pictorial);
            patch.weftYarn           = damaskBg.yarnPanel.GetScriptableYarn();
            background.geometryIndex = 0;
            damaskBg.geometryIndex   = 1;
        }
        else if (!selectedTechniqueRestrictions.uniformBackground)
        {
            var pictorialBg = yarnEntities.FindLast(y =>
                                                    y.yarnPanel.isBackground && y.yarnPanel.yarnZone == YarnPanel.YarnZone.Weft);

            patch.weftYarn            = pictorialBg.yarnPanel.GetScriptableYarn();
            background.geometryIndex  = 0;
            pictorialBg.geometryIndex = 1;
        }
        else
        {
            patch.weftYarn = background.yarnPanel.GetScriptableYarn();
        }

        patch.technique.pattern = new Mat(selectedWeave.weavePattern.texture.height, selectedWeave.weavePattern.texture.width, CvType.CV_8U);
        Utils.texture2DToMat(selectedWeave.weavePattern.texture, patch.technique.pattern);

        patch.pictorials.Clear();
        var geometryIndex = 2;

        for (var i = 0; i < yarnEntities.Count; i++)
        {
            if (_generalTechnique == GeneralTechnique.Damask || yarnEntities[i].yarnPanel.yarnZone != YarnPanel.YarnZone.Pictorial)
            {
                continue;
            }
            var tex = imageProcessingResults[i];

            var picto = new Pictorial();
            picto.drawing         = new Pattern();
            picto.drawing.pattern = tex;


            picto.yarn = yarnEntities[i].yarnPanel.GetScriptableYarn();
            if (bindingWarp)
            {
                picto.healedStep    = 6;
                picto.healedStepGap = 2;
            }
            else if (_generalTechnique == GeneralTechnique.Lampas || _generalTechnique == GeneralTechnique.Brocade)
            {
                picto.healedStep    = 6;
                picto.healedStepGap = 2;
                picto.doubleHealed  = true;
            }
            else
            {
                picto.healedStep = -1;
            }

            //Revisar Freestyle Brocaded
            picto.adjusted = _generalTechnique == GeneralTechnique.Spolined ||
                             _generalTechnique == GeneralTechnique.SpolinedDamask ||
                             (_generalTechnique == GeneralTechnique.Freestyle && brocadedFreestyle);


            patch.pictorials.Add(picto);
            yarnEntities[i].geometryIndex = geometryIndex;
            geometryIndex++;
        }

        //patch.divider = -1;
        patch.divider = -1f;


        patch.Weave();

        TogglePatchActive(true);
        ToggleProcessingWindow();
        SetVisualizationState(true);
        //visualizationWindow.SetActive(true);
    }
Example #4
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();
    }