Exemple #1
0
        /*
         * public override void initializeBays(string pName)
         * {
         *      if (parametricObject.isInitialized)
         *              return;
         *
         *      parametricObject.isInitialized = true;
         *
         *      RadialRepeaterTool gener = repeaterToolU as RadialRepeaterTool;
         *
         *      switch(pName)
         *      {
         *      case "Node Shape":
         *              if (repeaterToolU != null)
         *                      gener.radius = 3.5f * nodeSrc_p.parametricObject.bounds.size.x ;
         *              break;
         *      case "Cell Shape":
         *              if (repeaterToolU != null)
         *                      gener.radius = 2.5f * cellSrc_p.parametricObject.bounds.size.x ;
         *              break;
         *      }
         * }
         */



        // SHAPE_REPEATER_2D :: GENERATE
        public override GameObject generate(bool makeGameObjects, AXParametricObject initiator_po, bool isReplica)
        {
            if (parametricObject == null || !parametricObject.isActive)
            {
                return(null);
            }

            if ((P_Corner == null || cornerSrc_p == null) && (P_Node == null || inputSrc_p == null) && (P_Cell == null || cellSrc_p == null))
            {
                if (P_Output != null)
                {
                    P_Output.paths    = null;
                    P_Output.polyTree = null;
                }
                return(null);
            }


            // PRE_GENERATE
            preGenerate();


            planSrc_p  = P_Plan.DependsOn;                         // getUpstreamSourceParameter(P_Plan);
            planSrc_po = (planSrc_p != null)                                                           ? planSrc_p.parametricObject    : null;


            P_Plan.polyTree = null;
            AXShape.thickenAndOffset(ref P_Plan, planSrc_p);
            if (P_Plan.reverse)
            {
                P_Plan.doReverse();
            }


            planPaths = P_Plan.getPaths();

            if (planPaths == null || planPaths.Count == 0)
            {
                return(null);
            }



            // ** CREATE PLAN_SPLINES **

            if (planPaths != null && planPaths.Count > 0)
            {
                planSplines = new Spline[planPaths.Count];


                if (planSplines != null)
                {
                    for (int i = 0; i < planSplines.Length; i++)
                    {
                        planSplines[i] = new Spline(planPaths[i], (P_Plan.shapeState == ShapeState.Closed) ? true : false);
                    }
                }
            }



            AXParameter P_cornerOutput = new AXParameter();

            P_cornerOutput.parametricObject = parametricObject;

            AXParameter P_nodeOutput = new AXParameter();

            P_nodeOutput.parametricObject = parametricObject;


            AXParameter P_cellOutput = new AXParameter();

            P_cellOutput.parametricObject = parametricObject;



            // PROCESS SHAPE INPUTS

            if (cornerSrc_p != null)
            {
                P_Corner.polyTree = null;
                AXShape.thickenAndOffset(ref P_Corner, cornerSrc_p);
            }

            if (inputSrc_p != null)
            {
                P_Node.polyTree = null;
                AXShape.thickenAndOffset(ref P_Node, inputSrc_p);
            }


            if (cellSrc_p != null)
            {
                P_Cell.polyTree = null;
                AXShape.thickenAndOffset(ref P_Cell, cellSrc_p);
            }



            bool doPolyTreeNodes = false;
            //bool doPolyTreeCells = false;


            // NODE
            //Matrix4x4 tm = Matrix4x4.identity;



            //  NODE SHAPES
            Paths nodeSourcePaths = null;

            //Clipper nodeClipper = null;

            if (P_Node != null)
            {
                if (P_Node.polyTree != null)
                {
                    nodeSourcePaths = AXGeometryTools.Utilities.cleanPaths(Clipper.PolyTreeToPaths(P_Node.polyTree));
                    doPolyTreeNodes = true;
                    //nodeClipper =  new Clipper();
                }
                else
                {
                    nodeSourcePaths    = P_Node.getClonePaths();
                    P_nodeOutput.paths = new Paths();
                }
            }


            // CELL SHAPES
            Paths cellSourcePaths = null;

            //Clipper cellClipper = null;

            if (P_Cell != null)
            {
                if (P_Cell.polyTree != null)
                {
                    cellSourcePaths = AXGeometryTools.Utilities.cleanPaths(Clipper.PolyTreeToPaths(P_Cell.polyTree));
                    doPolyTreeNodes = true;
                    //cellClipper =  new Clipper();
                }
                else
                {
                    cellSourcePaths      = P_Cell.getClonePaths();
                    P_cornerOutput.paths = new Paths();
                }
            }



            // BREAK CORNER SHAPES
            Paths   cornerSourcePaths = null;
            Clipper cornerClipper     = null;

            if (P_Corner != null)
            {
                if (P_Corner.polyTree != null)
                {
                    cornerSourcePaths = AXGeometryTools.Utilities.cleanPaths(Clipper.PolyTreeToPaths(P_Corner.polyTree));
                    doPolyTreeNodes   = true;
                    cornerClipper     = new Clipper();
                }
                else
                {
                    cornerSourcePaths    = P_Corner.getClonePaths();
                    P_cornerOutput.paths = new Paths();
                }
            }



            // FOR EACH PATH

            for (int path_i = 0; path_i < planPaths.Count; path_i++)
            {
                // **** PREPARE EACH SPLINE *** //

                Spline planSpline = planSplines[path_i];

                planSpline.breakAngleCorners = cornerBreakAngle;
                planSpline.shapeState        = P_Plan.shapeState;

                // Create subsplines between each break point
                planSpline.getSmoothSubsplineIndicies(0, maxSegmentLength);

//					Debug.Log("planSpline.subsplines.Count="+ planSpline.subsplines.Count );
//					foreach(SubsplineIndices si in planSpline.subsplines)
//						si.print();

                planSpline.groupNearBreakAngleVertices(inset * 2);

                // **** PREPARE EACH SPLINE *** //



                Matrix4x4 localPlacement_mx = Matrix4x4.identity;



                if (planSpline.insetSpanSplines != null && planSpline.insetSpanSplines.Count > 0)
                {
                    for (int si = 0; si < planSpline.insetSpanSplines.Count; si++)
                    {
                        planSpline.insetSpanSplines[si].setRepeaterTransforms(si, inset, bay);
                    }



                    // SPAN NODES - SHAPES ALONG SUBSPLINES
                    if (nodeSrc_p != null && nodeSrc_p.meshes != null)
                    {
                        int endCount = (P_Plan != null && P_Plan.shapeState == ShapeState.Open) ?  planSpline.insetSpanSplines.Count - 1 : planSpline.insetSpanSplines.Count;

                        for (int i = 0; i < endCount; i++)
                        {
                            //SubsplineIndices rsi = planSpline.subsplines[i];
                            Spline           spanSpline   = planSpline.insetSpanSplines[i];
                            List <Matrix4x4> nodeMatrices = spanSpline.repeaterNodeTransforms;


                            // on each of these nodes, place a nodePlug instance.
                            bool spanNodesAtBreakCorners = true;

                            int starter = spanNodesAtBreakCorners ? 0 : 1;
                            int ender   = (inset > 0 || spanNodesAtBreakCorners) ? nodeMatrices.Count : nodeMatrices.Count - 1;

                            //string this_address = "";


                            if (nodeMatrices != null)
                            {
                                for (int ii = starter; ii < ender; ii++)
                                {
                                    //this_address = "node_"+path_i+"_"+i+"_"+ii;

                                    //Debug.Log("this_address="+this_address);
                                    // LOCAL_PLACEMENT

                                    localPlacement_mx = localMatrixFromAddress(RepeaterItem.Node, path_i, i, ii);

                                    if (doPolyTreeNodes)
                                    {
                                        cornerClipper.AddPaths(AX.Generators.Generator2D.transformPaths(nodeSourcePaths, localPlacement_mx), PolyType.ptSubject, true);
                                    }
                                    else
                                    {
                                        Paths tmp = AX.Generators.Generator2D.transformPaths(nodeSourcePaths, localPlacement_mx);
                                        P_cornerOutput.paths.AddRange(tmp);
                                    }
                                }
                            }
                        }
                    }



                    // CELL NODES - SHAPES ALONG SUBSPLINES
                    if (cellSrc_p != null && cellSrc_p.meshes != null)
                    {
                        int endCount = (P_Plan != null && P_Plan.shapeState == ShapeState.Open) ?  planSpline.insetSpanSplines.Count - 1 : planSpline.insetSpanSplines.Count;

                        for (int i = 0; i < endCount; i++)
                        {
                            //SubsplineIndices rsi = planSpline.subsplines[i];
                            Spline           spanSpline   = planSpline.insetSpanSplines[i];
                            List <Matrix4x4> cellMatrices = spanSpline.repeaterCellTransforms;


                            // on each of these nodes, place a nodePlug instance.
                            bool spanNodesAtBreakCorners = true;

                            int starter = spanNodesAtBreakCorners ? 0 : 1;
                            int ender   = (inset > 0 || spanNodesAtBreakCorners) ? cellMatrices.Count : cellMatrices.Count - 1;

                            //string this_address = "";


                            if (cellMatrices != null)
                            {
                                for (int ii = starter; ii < ender; ii++)
                                {
                                    //this_address = "cell_"+path_i+"_"+i+"_"+ii;

                                    //Debug.Log("this_address="+this_address);
                                    // LOCAL_PLACEMENT

                                    localPlacement_mx = localMatrixFromAddress(RepeaterItem.Cell, path_i, i, ii);

                                    if (doPolyTreeNodes)
                                    {
                                        cornerClipper.AddPaths(AX.Generators.Generator2D.transformPaths(cellSourcePaths, localPlacement_mx), PolyType.ptSubject, true);
                                    }
                                    else
                                    {
                                        Paths tmp = AX.Generators.Generator2D.transformPaths(nodeSourcePaths, localPlacement_mx);
                                        P_cornerOutput.paths.AddRange(tmp);
                                    }
                                }
                            }
                        }
                    }
                }



                if (cornerSourcePaths != null && cornerSourcePaths.Count > 0)
                {
                    // CORNERS

                    for (int bi = 0; bi < planSpline.breakIndices.Count; bi++)
                    {
                        //tm = Matrix4x4.TRS(new Vector3(2*i-2, 2*j-2, 0), Quaternion.identity, Vector3.one);
                        localPlacement_mx = localMatrixFromAddress(RepeaterItem.Corner, path_i, planSpline.breakIndices[bi]);


                        if (doPolyTreeNodes)
                        {
                            cornerClipper.AddPaths(AX.Generators.Generator2D.transformPaths(cornerSourcePaths, localPlacement_mx), PolyType.ptSubject, true);
                        }
                        else
                        {
                            Paths tmp = AX.Generators.Generator2D.transformPaths(cornerSourcePaths, localPlacement_mx);
                            P_cornerOutput.paths.AddRange(tmp);
                        }
                    }
                }



                if (doPolyTreeNodes)
                {
                    P_cornerOutput.polyTree = new AXClipperLib.PolyTree();
                    cornerClipper.Execute(ClipType.ctDifference, P_cornerOutput.polyTree, PolyFillType.pftNonZero, PolyFillType.pftNonZero);
                }
            }



            P_Output.polyTree = null;

            if (cornerSrc_p != null || cellSrc_p == null || nodeSrc_p == null)
            {
                // JUST NODES
                AXShape.thickenAndOffset(ref P_Output, P_cornerOutput);
            }

            /*
             * else if (nodeSrc_p != null && (cellSrc_p == null || (P_cellOutput.paths == null && P_cellOutput.polyTree == null)))
             * {
             *      // JUST NODES
             *      AXShape.thickenAndOffset(ref P_Output, P_nodeOutput);
             * }
             *
             * else if (nodeSrc_p == null && cellSrc_p != null)
             * {
             *      // JUST CELLS
             *      AXShape.thickenAndOffset(ref P_Output, P_cellOutput);
             * }
             * else
             * {
             *      // BOTH TO COMBINE
             *      clipper =  new Clipper();
             *
             *      if (P_nodeOutput.polyTree == null)
             *              clipper.AddPaths(P_nodeOutput.paths, PolyType.ptSubject, true);
             *      else
             *              clipper.AddPaths(AXGeometryTools.Utilities.cleanPaths(Clipper.PolyTreeToPaths(P_nodeOutput.polyTree)), PolyType.ptSubject, true);
             *
             *      if (P_cellOutput.polyTree == null)
             *              clipper.AddPaths(P_cellOutput.paths, PolyType.ptSubject, true);
             *      else
             *              clipper.AddPaths(AXGeometryTools.Utilities.cleanPaths(Clipper.PolyTreeToPaths(P_cellOutput.polyTree)), PolyType.ptSubject, true);
             *
             *
             *      P_Output.polyTree = new AXClipperLib.PolyTree();
             *      clipper.Execute(ClipType.ctUnion,   P_Output.polyTree,  PolyFillType.pftNonZero, PolyFillType.pftNonZero);
             *
             *      AXShape.thickenAndOffset(ref P_Output, P_Output);
             * }
             */

            if (P_Output.polyTree != null)
            {
                transformPolyTree(P_Output.polyTree, localMatrix);
            }
            else if (P_nodeOutput.paths != null)
            {
                P_Output.paths = transformPaths(P_nodeOutput.paths, localMatrix);
                P_Output.transformedControlPaths = P_nodeOutput.paths;
            }
            //base.generate(false, initiator_po, isReplica);
            calculateBounds();

            return(null);
        }         // \generate
Exemple #2
0
        // SHAPE_REPEATER_2D :: GENERATE
        public override GameObject generate(bool makeGameObjects, AXParametricObject initiator_po, bool isReplica)
        {
            if (parametricObject == null || !parametricObject.isActive)
            {
                return(null);
            }

            if ((P_Node == null || inputSrc_p == null) && (P_Cell == null || cellSrc_p == null))
            {
                if (P_Output != null)
                {
                    P_Output.paths    = null;
                    P_Output.polyTree = null;
                }
                return(null);
            }

            if (repeaterToolU == null)
            {
                return(null);
            }

            // PRE_GENERATE
            preGenerate();



            AXParameter P_nodeOutput = new AXParameter();

            P_nodeOutput.parametricObject = parametricObject;


            AXParameter P_cellOutput = new AXParameter();

            P_cellOutput.parametricObject = parametricObject;



            // PROCESS NODE INPUT

            if (inputSrc_p != null)
            {
                P_Node.polyTree = null;
                AXShape.thickenAndOffset(ref P_Node, inputSrc_p);

                //P_nodeOutput.polyTree = null;
                //AXShape.thickenAndOffset(ref P_nodeOutput, P_Node);
            }

            if (cellSrc_p != null)
            {
                P_Cell.polyTree = null;
                AXShape.thickenAndOffset(ref P_Cell, cellSrc_p);

                //P_cellOutput.polyTree = null;
                //AXShape.thickenAndOffset(ref P_cellOutput, P_Cell);
            }



            bool doPolyTreeNodes = false;
            bool doPolyTreeCells = false;


            // NODE
            Matrix4x4 tm = Matrix4x4.identity;

            Paths tmpPaths = null;

            Clipper clipper = null;


            if (nodeSrc_p != null)
            {
                if (P_Node.polyTree != null)
                {
                    tmpPaths        = AXGeometryTools.Utilities.cleanPaths(Clipper.PolyTreeToPaths(P_Node.polyTree));
                    doPolyTreeNodes = true;
                    clipper         = new Clipper();
                }
                else
                {
                    tmpPaths           = P_Node.getClonePaths();
                    P_nodeOutput.paths = new Paths();
                }


                if (tmpPaths != null && tmpPaths.Count > 0)
                {
                    for (int i = 0; i <= repeaterToolU.cells; i++)
                    {
                        //tm = Matrix4x4.TRS(new Vector3(2*i-2, 2*j-2, 0), Quaternion.identity, Vector3.one);
                        tm = localMatrixFromAddress(RepeaterItem.Node, i);


                        if (doPolyTreeNodes)
                        {
                            clipper.AddPaths(AX.Generators.Generator2D.transformPaths(tmpPaths, tm), PolyType.ptSubject, true);
                        }
                        else
                        {
                            Paths tmp = AX.Generators.Generator2D.transformPaths(tmpPaths, tm);


                            P_nodeOutput.paths.AddRange(tmp);
                        }
                    }

                    if (doPolyTreeNodes)
                    {
                        P_nodeOutput.polyTree = new AXClipperLib.PolyTree();
                        clipper.Execute(ClipType.ctDifference, P_nodeOutput.polyTree, PolyFillType.pftNonZero, PolyFillType.pftNonZero);
                    }
                }
            }


            // CELL
            // PROCESS CELL INPUT

            if (cellSrc_p != null)
            {
                if (P_Cell.polyTree != null)
                {
                    tmpPaths        = AXGeometryTools.Utilities.cleanPaths(Clipper.PolyTreeToPaths(P_Cell.polyTree));
                    doPolyTreeCells = true;
                    clipper         = new Clipper();
                }
                else
                {
                    tmpPaths           = P_Cell.getClonePaths();
                    P_cellOutput.paths = new Paths();
                }


                if (tmpPaths != null && tmpPaths.Count > 0)
                {
                    for (int i = 0; i < repeaterToolU.cells; i++)
                    {
                        tm = localMatrixFromAddress(RepeaterItem.Cell, i);

                        if (doPolyTreeCells)
                        {
                            clipper.AddPaths(AX.Generators.Generator2D.transformPaths(tmpPaths, tm), PolyType.ptSubject, true);
                        }
                        else
                        {
                            Paths tmp = AX.Generators.Generator2D.transformPaths(tmpPaths, tm);
                            P_cellOutput.paths.AddRange(tmp);
                        }
                    }

                    if (doPolyTreeCells)
                    {
                        P_cellOutput.polyTree = new AXClipperLib.PolyTree();
                        clipper.Execute(ClipType.ctDifference, P_cellOutput.polyTree, PolyFillType.pftNonZero, PolyFillType.pftNonZero);
                    }
                }
            }



            P_Output.polyTree = null;

            if (nodeSrc_p != null && cellSrc_p == null)
            {
                // JUST NODES
                AXShape.thickenAndOffset(ref P_Output, P_nodeOutput);
            }

            else if (nodeSrc_p == null && cellSrc_p != null)
            {
                // JUST CELLS
                AXShape.thickenAndOffset(ref P_Output, P_cellOutput);
            }
            else
            {
                // BOTH TO COMBINE
                clipper = new Clipper();

                if (P_nodeOutput.polyTree == null)
                {
                    clipper.AddPaths(P_nodeOutput.paths, PolyType.ptSubject, true);
                }
                else
                {
                    clipper.AddPaths(AXGeometryTools.Utilities.cleanPaths(Clipper.PolyTreeToPaths(P_nodeOutput.polyTree)), PolyType.ptSubject, true);
                }

                if (P_cellOutput.polyTree == null)
                {
                    clipper.AddPaths(P_cellOutput.paths, PolyType.ptSubject, true);
                }
                else
                {
                    clipper.AddPaths(AXGeometryTools.Utilities.cleanPaths(Clipper.PolyTreeToPaths(P_cellOutput.polyTree)), PolyType.ptSubject, true);
                }


                P_Output.polyTree = new AXClipperLib.PolyTree();
                clipper.Execute(ClipType.ctUnion, P_Output.polyTree, PolyFillType.pftNonZero, PolyFillType.pftNonZero);

                AXShape.thickenAndOffset(ref P_Output, P_Output);
            }


            if (P_Output.polyTree != null)
            {
                transformPolyTree(P_Output.polyTree, localMatrix);
            }
            else if (P_nodeOutput.paths != null)
            {
                P_Output.paths = transformPaths(P_nodeOutput.paths, localMatrix);
                P_Output.transformedControlPaths = P_nodeOutput.paths;
            }
            //base.generate(false, initiator_po, isReplica);
            calculateBounds();

            return(null);
        }         // \generate