public override bool Calculate()
    {
        IModule3D value = Inputs[0].GetValue <IModule3D>();

        if (value == null)
        {
            return(false);
        }
        ControlPointList value2 = Inputs[1].GetValue <ControlPointList>();

        if (target.modifyType == ProcGen.Noise.Modifier.ModifyType.Curve && (value2 == null || value2.points.Count == 0))
        {
            return(false);
        }
        FloatList value3 = Inputs[2].GetValue <FloatList>();

        if (target.modifyType == ProcGen.Noise.Modifier.ModifyType.Terrace && (value3 == null || value3.points.Count == 0))
        {
            return(false);
        }
        IModule3D module3D = target.CreateModule(value);

        if (module3D == null)
        {
            return(false);
        }
        if (target.modifyType == ProcGen.Noise.Modifier.ModifyType.Curve)
        {
            Curve curve = module3D as Curve;
            curve.ClearControlPoints();
            List <ControlPoint> controls = value2.GetControls();
            foreach (ControlPoint item in controls)
            {
                curve.AddControlPoint(item);
            }
        }
        else if (target.modifyType == ProcGen.Noise.Modifier.ModifyType.Terrace)
        {
            Terrace terrace = module3D as Terrace;
            terrace.ClearControlPoints();
            foreach (float point in value3.points)
            {
                float input = point;
                terrace.AddControlPoint(input);
            }
        }
        Outputs[0].SetValue(module3D);
        return(true);
    }
 public void SetSouces(IModule3D target, IModule3D sourceModule, FloatList controlFloats, ControlPointList controlPoints)
 {
     (target as ModifierModule).SourceModule = sourceModule;
     if (modifyType == ModifyType.Curve)
     {
         Curve curve = target as Curve;
         curve.ClearControlPoints();
         List <ControlPoint> controls = controlPoints.GetControls();
         foreach (ControlPoint item in controls)
         {
             curve.AddControlPoint(item);
         }
     }
     else if (modifyType == ModifyType.Terrace)
     {
         Terrace terrace = target as Terrace;
         terrace.ClearControlPoints();
         foreach (float point in controlFloats.points)
         {
             float input = point;
             terrace.AddControlPoint(input);
         }
     }
 }
Пример #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();
    }