Example #1
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);
    }