Exemple #1
0
        // GENERATE
        // This is the main function for generating a Shape, Mesh, or any other output that a node may be tasked with generating.
        // You can do pre processing of Inputs here, but that might best be done in an override of pollControlValuesFromParmeters().
        //
        // Often, you will be creating a list of AXMesh objects. AXMesh has a Mesh, a Matrix4x4 and a Material
        // to be used when drawing the ouput to the scene before creating GameObjects. Your list of AXMeshes generated
        // is pased to the model via parametricObject.finishMultiAXMeshAndOutput().
        //
        // When generate() is called by AX, it will be either with makeGameObjects set to true or false.
        // makeGameObjects=False is passed when the user is dragging a parameter and the model is regenerateing multiple times per second.
        // makeGameObjects=True is passed when the user has stopped editing (for example, OnMouseup from a Handle) and it is time to
        // build a GameObject hierarchy.

        public override GameObject generate(bool makeGameObjects, AXParametricObject initiator_po, bool isReplica)
        {
            planSrc_p  = P_Plan.DependsOn;                         // getUpstreamSourceParameter(P_Plan);
            planSrc_po = (planSrc_p != null)                                                           ? planSrc_p.parametricObject    : null;

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

            //Debug.Log("planSrc_po = " + planSrc_po.Name+"."+planSrc_p.Name + " ... " + planSrc_p.DependsOn.PType + " ..... " + planSrc_p.getPaths());

            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);
                    }
                }
            }



            // FOR EACH PATH
            for (int path_i = 0; path_i < planPaths.Count; path_i++)
            {
                Spline planSpline = planSplines[path_i];

                planSpline.breakAngleCorners = 35;
                planSpline.shapeState        = P_Plan.shapeState;


                //Matrix4x4 mm = planSpline.matrixAtLength(4.5f);
            }



            if (parametricObject == null || !parametricObject.hasInputMeshReady("Input Mesh"))
            {
                return(null);
            }

            // At this point the amount variable has been set to the FloatValue of its amount parameter.
            preGenerate();



            //Vector3 center = Vector3.zero;

            // AXMeshes are the key product of a Generator3D
            List <AXMesh> ax_meshes = new List <AXMesh>();

            AXParameter        inputSrc_p  = P_Input.DependsOn;
            AXParametricObject inputSrc_po = inputSrc_p.parametricObject;

            Spline planSpl = planSplines[0];


            if (inputSrc_p != null && inputSrc_p.meshes != null)              // Is there an input node connected to this node?
            {
                //Debug.Log("P_Input.DependsOn.meshes.Count="+P_Input.DependsOn.meshes.Count + ", "+ P_Input.DependsOn.meshes[0].GetType());
                AXMesh amesh = null;

                // EACH MESH
                for (int i = 0; i < P_Input.DependsOn.meshes.Count; i++)
                {
//					if (amount == 0)
//					{
//						amesh   = P_Input.DependsOn.meshes [i];
//					}
//					else{
                    // Instance does not inhereit and build on the transform of its source object.
                    amesh = P_Input.DependsOn.meshes [i].Clone();
                    Mesh      m     = amesh.mesh;
                    Vector3[] verts = m.vertices;


                    // ---------- EACH VERTEX ----------------------
                    for (int j = 0; j < verts.Length; j++)
                    {
                        Vector3 vert = new Vector3(verts[j].x, verts[j].y, verts[j].z);

                        vert = P_Input.DependsOn.meshes[i].drawMeshMatrix.MultiplyPoint3x4(vert);

                        //float scale = modifierCurve.Evaluate( vert.y)  * (1-(twist*vert.y));
                        float scale = modifierCurve.Evaluate(vert.x);


                        //vert = new Vector3(vert.x*scale, vert.y, vert.z*scale);

                        Matrix4x4 warperM = planSpl.matrixAtLength(vert.x);

                        if (turn != 0 || twist != 0 || scale != 0)
                        {
                            warperM *= Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(vert.x * twist + turn + scale, 0, 0), Vector3.one);
                        }

                        vert = warperM.MultiplyPoint3x4(new Vector3(0, vert.y, vert.z));;
//							float len = Mathf.Sqrt(vert.x*vert.x + vert.z*vert.z);
//
//							float new_x = vert.x;//+ pval;
//							float new_y = vert.y  -  factor*len*len*vert.y/5;// + pval;
//							float new_z = vert.z;//+ pval;
//
//							//Debug.Log(pval + " :::: " +  verts[j].x + " :: " + verts[j].z + " + " + Mathf.PerlinNoise (verts[j].x, verts[j].z));
//							verts [j] = new Vector3 (new_x, new_y, new_z);
                        verts [j] = P_Input.DependsOn.meshes[i].drawMeshMatrix.inverse.MultiplyPoint3x4(vert);
                    }
                    // ---------- EACH VERTEX ----------------------


                    m.vertices = verts;
                    //}

                    amesh.mesh.RecalculateNormals();
                    ax_meshes.Add(amesh);
                }

                parametricObject.bounds = inputSrc_po.bounds;
                parametricObject.finishMultiAXMeshAndOutput(ax_meshes, isReplica);


                if (makeGameObjects)
                {
                    return(parametricObject.makeGameObjectsFromAXMeshes(ax_meshes));
                }
            }

            return(null);
        }
Exemple #2
0
        // GENERATE PLAN_REPEATER
        public override GameObject generate(bool makeGameObjects, AXParametricObject initiator_po, bool renderToOutputParameter)
        {
            if (parametricObject == null || !parametricObject.isActive)
            {
                return(null);
            }
            //Debug.Log("yo ******* makeGameObjects="+makeGameObjects);


            // RESULTING MESHES
            ax_meshes = new List <AXMesh>();

            paths_SubsplineIndices = new List <SubsplineIndices[]>();

            preGenerate();



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

            //Debug.Log("planSrc_po = " + planSrc_po.Name+"."+planSrc_p.Name + " ... " + planSrc_p.DependsOn.PType + " ..... " + planSrc_p.getPaths());

            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);
                    }
                }
            }



            //Debug.Log("controlVertices="+ planSplines[0].controlVertices.Count);



            // CORNER_MESH
            GameObject cornerPlugGO = null;

            if (cornerSrc_p != null)
            {
                cornerSrc_po = cornerSrc_p.parametricObject;
                if (makeGameObjects && !parametricObject.combineMeshes)
                {
                    cornerPlugGO = cornerSrc_po.generator.generate(true, initiator_po, renderToOutputParameter);
                }
            }



            // NODE_MESH

            GameObject nodePlugGO = null;

            if (nodeSrc_p != null)
            {
                nodeSrc_po = nodeSrc_p.parametricObject;
                //Debug.Log("yo makeGameObjects="+makeGameObjects+", parametricObject.combineMeshes="+parametricObject.combineMeshes);
                if (makeGameObjects && !parametricObject.combineMeshes)
                {
                    nodePlugGO = nodeSrc_po.generator.generate(true, initiator_po, renderToOutputParameter);
                }
            }



            // CELL_MESH

            GameObject cellPlugGO = null;

            if (cellSrc_p != null)
            {
                cellSrc_po = cellSrc_p.parametricObject;
                if (makeGameObjects && !parametricObject.combineMeshes)
                {
                    cellPlugGO = cellSrc_po.generator.generate(true, initiator_po, renderToOutputParameter);
                }
            }



            // Plan
            // This is the main spline used for the iteration



            //AXParameter plan_p = ip.DependsOn;



            // The section spline is used to provide the connective tissue around corners

            // SECTION

            // The plan may have multiple paths. Each may generate a separate GO.

            sectionSrc_p  = P_Section.DependsOn;              //getUpstreamSourceParameter(P_Section);
            sectionSrc_po = (sectionSrc_p != null) ? sectionSrc_p.parametricObject : null;

            if (sectionSrc_po != null)
            {
                P_Section.polyTree = null;
                AXShape.thickenAndOffset(ref P_Section, sectionSrc_p);
                if (P_Section.reverse)
                {
                    P_Section.doReverse();
                }
            }



            float bay_U = parametricObject.floatValue("bay_U");
            float bay_V = parametricObject.floatValue("bay_V");

            if (bay_U == 0)
            {
                bay_U = .1f;
            }
            if (bay_V == 0)
            {
                bay_V = 10f;
            }

            float margin_U = parametricObject.floatValue("margin_U");



            Vector2 prevV = new Vector2();

            //Vector3 scaler1   = Vector3.one;


            //float margin = 2.5f;

            Vector2 firstPM = new Vector2();
            Vector2 prevVM  = new Vector2();



            AXSpline secSpline = null;
            AXSplineExtrudeGenerator tmpEXSP = null;

            if (sectionSrc_p != null && sectionSrc_p.spline != null && sectionSrc_p.spline.vertCount > 0)
            {
                secSpline = sectionSrc_p.spline;
            }



            tmpEXSP = new AXSplineExtrudeGenerator();

            Material tmp_mat = parametricObject.axMat.mat;

            if (parametricObject.axTex != null)
            {
                tmpEXSP.uScale = parametricObject.axTex.scale.x;
                tmpEXSP.vScale = parametricObject.axTex.scale.y;
                tmpEXSP.uShift = -parametricObject.axTex.shift.x;
                tmpEXSP.vShift = parametricObject.axTex.shift.y;
            }



            float runningU = 0;



            //ip.spline.getAnglesArray();

            //Spline sectionSpline = null;
            //	= new Spline(sectionPath, sectionIsClosed,  sec_p.breakGeom, sec_p.breakNorm);



            GameObject go     = null;
            GameObject planGO = null;

            if (makeGameObjects && !parametricObject.combineMeshes)
            {
                go = ArchimatixUtils.createAXGameObject(parametricObject.Name, parametricObject);
            }



            // BOUNDING

            List <AXMesh> boundingMeshes = new List <AXMesh>();



            // FOR EACH PATH
            for (int path_i = 0; path_i < planPaths.Count; path_i++)
            {
                if (makeGameObjects && !parametricObject.combineMeshes)
                {
                    planGO = ArchimatixUtils.createAXGameObject(parametricObject.Name + "_" + path_i, parametricObject);
                }



                // **** 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
                //Pather.printPaths(planPaths);


                planSpline.groupNearBreakAngleVertices(inset * 2);

                if (planSpline.groupedCornerNodes == null || planSpline.groupedCornerNodes.Count == 0)
                {
                    inset = 0;
                }



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



                Matrix4x4 localPlacement_mx = Matrix4x4.identity;



                //  INSET PLANSWEEPS
                GameObject plansweepGO = null;

                if (sectionSrc_p != null && inset > 0 && planSpline.insetSplines != null)
                {
                    // convert planSpline.insetSplines to Paths
                    Paths insetPaths = AXGeometryTools.Utilities.Splines2Paths(planSpline.insetSplines);

                    AXParameter tmpPlanP = new AXParameter();
                    tmpPlanP.parametricObject = parametricObject;
                    tmpPlanP.paths            = insetPaths;
                    tmpPlanP.Type             = AXParameter.DataType.Shape;
                    tmpPlanP.shapeState       = ShapeState.Open;
                    tmpPlanP.breakGeom        = 0;

                    if (planSpline.insetSplines.Count == 1)
                    {
                        tmpPlanP.shapeState = planSpline.insetSplines[0].shapeState;
                    }

                    topCap = false;
                    botCap = false;

                    plansweepGO = generateFirstPass(initiator_po, makeGameObjects, tmpPlanP, P_Section, Matrix4x4.identity, renderToOutputParameter, false);



                    if (makeGameObjects && !parametricObject.combineMeshes && plansweepGO != null)
                    {
                        plansweepGO.transform.parent = go.transform;
                    }
                }



                AXMesh tmpMesh = null;



                if (planSpline.insetSpanSplines != null && planSpline.insetSpanSplines.Count > 0)
                {
                    //Debug.Log(".....????>> spanSpline.subsplines.Count="+ planSpline.insetSpanSplines.Count + " --- " + planSpline.subsplines.Count );
                    for (int si = 0; si < planSpline.insetSpanSplines.Count; si++)
                    {
                        planSpline.insetSpanSplines[si].setRepeaterTransforms(si, inset, bay);
                    }


                    // SPAN NODES - MESHES ALONG SUBSPLINES
                    if (nodeSrc_p != null && nodeSrc_p.meshes != null)
                    {
                        //int endCount = (P_Plan != null && P_Plan.shapeState == ShapeState.Open) ?  planSpline.subsplines.Count-1 : planSpline.subsplines.Count;
                        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];


                            //Debug.Log(i + "||||||||||> " + spanSpline.toString());

                            List <Matrix4x4> nodeMatrices = spanSpline.repeaterNodeTransforms;


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

                            int starter = (inset > 0 || spanNodesAtBreakCorners) ? 0 : 1;
                            //Debug.Log("starter="+starter);

                            int ender = (inset > 0 || spanSpline.shapeState == ShapeState.Open || planSpline.subsplines.Count == 1) ? nodeMatrices.Count : nodeMatrices.Count - 1;


                            //Debug.Log("starter="+starter +", ender="+ender + ", nodeMatrices.Count=" + nodeMatrices.Count);

                            //Debug.Log("(inset > 0 && spanNodesAtBreakCorners)="+(inset > 0 && spanNodesAtBreakCorners)+", nodeMatrices.Length="+nodeMatrices.Length+", starter="+starter+", ender="+ender);

                            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);


                                    // AX_MESHES

                                    for (int mi = 0; mi < nodeSrc_p.meshes.Count; mi++)
                                    {
                                        AXMesh dep_amesh = nodeSrc_p.meshes [mi];
                                        tmpMesh = dep_amesh.Clone(localPlacement_mx * dep_amesh.transMatrix);
                                        tmpMesh.subItemAddress = this_address;
                                        ax_meshes.Add(tmpMesh);
                                    }



                                    // BOUNDING
                                    boundingMeshes.Add(new AXMesh(nodeSrc_po.boundsMesh, localPlacement_mx * nodeSrc_po.generator.localMatrix));

                                    //Debug.Log("boundingMeshes: " + boundingMeshes.Count);

                                    // GAME_OBJECTS

                                    if (nodePlugGO != null && makeGameObjects && !parametricObject.combineMeshes)
                                    {
                                        Matrix4x4  mx     = localPlacement_mx * nodeSrc_po.generator.localMatrixWithAxisRotationAndAlignment;
                                        GameObject copyGO = (GameObject)GameObject.Instantiate(nodePlugGO, AXUtilities.GetPosition(mx), AXUtilities.QuaternionFromMatrix(mx));


                                        Vector3 newJitterScale = jitterScale + Vector3.one;
                                        copyGO.transform.localScale  = new Vector3(copyGO.transform.localScale.x * newJitterScale.x, copyGO.transform.localScale.y * newJitterScale.y, copyGO.transform.localScale.z * newJitterScale.z);
                                        copyGO.transform.localScale += jitterScale;

                                        AXGameObject axgo = copyGO.GetComponent <AXGameObject>();


                                        if (axgo != null)
                                        {
                                            axgo.consumerAddress = this_address;
                                            //Debug.Log("ADD ADDRESS: " + this_address);
                                        }
                                        copyGO.name = copyGO.name + "_" + this_address;

                                        //Debug.Log("copyGO.name = "+copyGO.name);

                                        copyGO.transform.parent = planGO.transform;
                                    }
                                }
                            }
                        }
                    }                     // \NODE MESHES



                    // CELL NODES - MESHES ALONG SUBSPLINES
                    if (cellSrc_p != null && cellSrc_p.meshes != null)
                    {
                        //int endCount = (P_Plan != null && P_Plan.shapeState == ShapeState.Open) ?  planSpline.subsplines.Count-1 : planSpline.subsplines.Count;
                        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];

                            spanSpline.setRepeaterTransforms(i, inset, bay);


                            List <Matrix4x4> cellMatrices = spanSpline.repeaterCellTransforms;



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

                            int starter = 0;                            //spanNodesAtBreakCorners ? 0 : 1;


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

                            //Debug.Log("(inset > 0 && spanNodesAtBreakCorners)="+(inset > 0 && spanNodesAtBreakCorners)+", nodeMatrices.Length="+nodeMatrices.Length+", starter="+starter+", ender="+ender);

                            string this_address = "";

                            if (cellMatrices != null)
                            {
                                for (int ii = starter; ii < ender; ii++)
                                {
                                    // ADDRESS

                                    this_address = "cell_" + path_i + "_" + i + "_" + ii;


                                    // LOCAL_PLACEMENT

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



                                    // AX_MESHES

                                    for (int mi = 0; mi < cellSrc_p.meshes.Count; mi++)
                                    {
                                        AXMesh dep_amesh = cellSrc_p.meshes [mi];
                                        tmpMesh = dep_amesh.Clone(localPlacement_mx * dep_amesh.transMatrix);
                                        tmpMesh.subItemAddress = this_address;
                                        ax_meshes.Add(tmpMesh);
                                    }



                                    // BOUNDING
                                    boundingMeshes.Add(new AXMesh(cellSrc_po.boundsMesh, localPlacement_mx * cellSrc_po.generator.localMatrix));


                                    // GAME_OBJECTS

                                    if (cellPlugGO != null && makeGameObjects && !parametricObject.combineMeshes)
                                    {
                                        Matrix4x4  mx     = localPlacement_mx * cellSrc_po.generator.localMatrixWithAxisRotationAndAlignment;
                                        GameObject copyGO = (GameObject)GameObject.Instantiate(cellPlugGO, AXUtilities.GetPosition(mx), AXUtilities.QuaternionFromMatrix(mx));


                                        Vector3 newJitterScale = jitterScale + Vector3.one;
                                        copyGO.transform.localScale  = new Vector3(copyGO.transform.localScale.x * newJitterScale.x, copyGO.transform.localScale.y * newJitterScale.y, copyGO.transform.localScale.z * newJitterScale.z);
                                        copyGO.transform.localScale += jitterScale;

                                        AXGameObject axgo = copyGO.GetComponent <AXGameObject>();


                                        if (axgo != null)
                                        {
                                            axgo.consumerAddress = this_address;
                                            //Debug.Log("ADD ADDRESS: " + this_address);
                                        }
                                        copyGO.name = copyGO.name + "_";                                      // + this_address;

                                        //Debug.Log("copyGO.name = "+copyGO.name);

                                        copyGO.transform.parent = planGO.transform;
                                    }
                                }
                            }
                        }
                    }             // \CELL MESHES
                }                 // \each spanSpline



                // BREAK CORNER MESHES

                if (cornerSrc_p != null && cornerSrc_p.meshes != null)
                {
                    for (int bi = 0; bi < planSpline.breakIndices.Count; bi++)
                    {
                        // ADDRESS

                        string this_address = "corner_" + path_i + "_" + planSpline.breakIndices[bi];

                        // LOCAL_PLACEMENT

                        localPlacement_mx = localMatrixFromAddress(RepeaterItem.Corner, path_i, planSpline.breakIndices[bi]);


                        // AX_MESHES

                        for (int mi = 0; mi < cornerSrc_p.meshes.Count; mi++)
                        {
                            AXMesh dep_amesh = cornerSrc_p.meshes [mi];
                            tmpMesh = dep_amesh.Clone(localPlacement_mx * dep_amesh.transMatrix);
                            tmpMesh.subItemAddress = this_address;
                            ax_meshes.Add(tmpMesh);
                        }



                        // BOUNDING
                        boundingMeshes.Add(new AXMesh(cornerSrc_po.boundsMesh, localPlacement_mx * cornerSrc_po.generator.localMatrix));



                        // GAME_OBJECTS

                        if (cornerPlugGO != null && makeGameObjects && !parametricObject.combineMeshes)
                        {
                            Matrix4x4  mx     = localPlacement_mx * cornerSrc_po.generator.localMatrixWithAxisRotationAndAlignment;
                            GameObject copyGO = (GameObject)GameObject.Instantiate(cornerPlugGO, AXUtilities.GetPosition(mx), AXUtilities.QuaternionFromMatrix(mx));


                            Vector3 newJitterScale = jitterScale + Vector3.one;
                            copyGO.transform.localScale  = new Vector3(copyGO.transform.localScale.x * newJitterScale.x, copyGO.transform.localScale.y * newJitterScale.y, copyGO.transform.localScale.z * newJitterScale.z);
                            copyGO.transform.localScale += jitterScale;

                            AXGameObject axgo = copyGO.GetComponent <AXGameObject>();
                            if (axgo != null)
                            {
                                axgo.consumerAddress = this_address;
                            }

                            copyGO.name             = copyGO.name + "_" + this_address;
                            copyGO.transform.parent = planGO.transform;
                        }
                    }
                }



                /*
                 * int cells = Mathf.CeilToInt( md/bay_U );
                 * int nby = Mathf.CeilToInt( height/bay_V );
                 *
                 * //Debug.Log ("d="+d+", md="+md);
                 *
                 * float actual_bayx = md/cells;
                 * float actual_bayy = height/nby;
                 *
                 * // CREATE VERSIONS OF INPUT BAY_CENTER MESH(ES) USING BOUNDING BOX
                 * // ******************************************************************************
                 * // someting similar shoud be added to griditerator, stepiterator, and where else?
                 *
                 * // instead of prev, would be better to create a dictionary of bounds and AXMeshes?
                 * if (bay_span_p != null && (prevActuralBayx != actual_bayx || prevActuralBayx != actual_bayy))
                 * {
                 *      // regnerate the input meshes using actual_bayx
                 *      bay_span_p.Parent.setParameterValueByName("uScale", parametricObject.floatValue("uScale"));
                 *      bay_span_p.Parent.setParameterValueByName("vScale", parametricObject.floatValue("vScale"));
                 *      bay_span_p.Parent.setParameterValueByName("uShift", parametricObject.floatValue("uShift"));
                 *      bay_span_p.Parent.setParameterValueByName("vShift", parametricObject.floatValue("vShift"));
                 *
                 *      //bay_span_p.Parent.generateOutputNow (makeGameObjects, parametricObject, true);//, new Vector3(actual_bayx, actual_bayy, margin_th));
                 *
                 * }
                 * // ******************************************************************************
                 *
                 *
                 * // CREATE VERSIONS OF INPUT BAY_CENTER MESH(ES) USING BOUNDING BOX
                 * // ******************************************************************************
                 * // someting similar shoud be added to griditerator, stepiterator, and where else?
                 *
                 * // instead of prev, would be better to create a dictionary of bounds and AXMeshes?
                 * if (node_p != null && (prevActuralBayx != actual_bayx || prevActuralBayx != actual_bayy))
                 * {
                 *      // regnerate the input meshes using actual_bayx
                 *      node_p.Parent.setParameterValueByName("uScale", parametricObject.floatValue("uScale"));
                 *      node_p.Parent.setParameterValueByName("vScale", parametricObject.floatValue("vScale"));
                 *      node_p.Parent.setParameterValueByName("uShift", parametricObject.floatValue("uShift"));
                 *      node_p.Parent.setParameterValueByName("vShift", parametricObject.floatValue("vShift"));
                 *
                 *      //node_p.Parent.generateOutputNow (makeGameObjects, parametricObject, true);//, new Vector3(actual_bayx, actual_bayy, margin_th));
                 *
                 * }
                 * // ******************************************************************************
                 */



                //margin_U = .5f;
                if (margin_U > 0 && planSpline.isClosed)
                {
                    AXSpline connSpline2 = new AXSpline();
                    connSpline2.Push(prevVM);
                    connSpline2.Push(prevV);
                    connSpline2.Push(firstPM);
                    connSpline2.isClosed = false;

                    tmpEXSP.uShift = parametricObject.floatValue("uShift") + (runningU) / tmpEXSP.uScale;

                    Mesh mesh = tmpEXSP.generate(connSpline2, secSpline);
                    ax_meshes.Add(new AXMesh(mesh, Matrix4x4.identity, tmp_mat));
                }


                if (makeGameObjects && !parametricObject.combineMeshes)
                {
                    planGO.transform.parent = go.transform;
                }
            }            // end paths



            //GameObject.DestroyImmediate(bay_spanPlugGO);
            GameObject.DestroyImmediate(cornerPlugGO);
            GameObject.DestroyImmediate(nodePlugGO);
            GameObject.DestroyImmediate(cellPlugGO);



            // FINISH AX_MESHES
            //Debug.Log("finish " + ax_meshes.Count);
            parametricObject.finishMultiAXMeshAndOutput(ax_meshes, renderToOutputParameter);


            // FINISH BOUNDS

            CombineInstance[] boundsCombinator = new CombineInstance[boundingMeshes.Count];
            for (int bb = 0; bb < boundsCombinator.Length; bb++)
            {
                boundsCombinator[bb].mesh      = boundingMeshes[bb].mesh;
                boundsCombinator[bb].transform = boundingMeshes[bb].transMatrix;
            }
            setBoundsWithCombinator(boundsCombinator);



            // FINISH GAME_OBJECTS

            if (makeGameObjects)
            {
                if (parametricObject.combineMeshes)
                {
                    go = parametricObject.makeGameObjectsFromAXMeshes(ax_meshes, true);
                }

                Matrix4x4 tmx = parametricObject.getLocalMatrix();

                go.transform.rotation   = AXUtilities.QuaternionFromMatrix(tmx);
                go.transform.position   = AXUtilities.GetPosition(tmx);
                go.transform.localScale = parametricObject.getLocalScaleAxisRotated();                        //AXUtilities.GetScale(tmx);

                if (P_Plan.reverse)
                {
                    P_Plan.doReverse();
                }

                if (P_Section != null && P_Section.reverse)
                {
                    P_Section.doReverse();
                }

                return(go);
            }
            else
            {
                // Submit AXMeshes for realtime rendering
                //parametricObject.finishMultiAXMeshAndOutput(ax_meshes, renderToOutputParameter);
                //setBoundaryFromMeshes(ax_meshes);
            }



            if (P_Plan.reverse)
            {
                P_Plan.doReverse();
            }

            if (P_Section != null && P_Section.reverse)
            {
                P_Section.doReverse();
            }

            return(null);
        }
Exemple #3
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