Beispiel #1
0
        // GENERATE STEP_REPEATER
        public override GameObject generate(bool makeGameObjects, AXParametricObject initiator_po, bool isReplica)
        {
            if (parametricObject == null || !parametricObject.isActive)
            {
                return(null);
            }

            preGenerate();



            // NODE_MESH
            GameObject nodePlugGO = null;

            if (nodeSrc_p != null)
            {
                nodeSrc_po = nodeSrc_p.parametricObject;
                if (makeGameObjects && !parametricObject.combineMeshes)
                {
                    nodePlugGO = nodeSrc_po.generator.generate(true, initiator_po, isReplica);
                }
            }


            // 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, isReplica);
                }
            }



            if (nodeSrc_po == null && cellSrc_po == null)
            {
                if (P_Output != null)
                {
                    P_Output.meshes = null;
                }

                return(null);
            }



            GameObject go = null;

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



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

            Matrix4x4 localPlacement_mx = Matrix4x4.identity;

            // -----------------------------------



            shiftU = 0;
            //shiftU = (topStep) ? (-steps * actual_tread / 2) : (-(steps-1) * actual_tread / 2);


            AXMesh tmpMesh;


            // BOUNDING

            CombineInstance[] boundsCombinator = new CombineInstance[steps];



            // LOOP

            //Debug.Log(nodeSrc_po.Name + ": " + nodeSrc_po.boundsMesh.vertices.Length);
            //AXGeometryTools.Utilities
            for (int i = 0; i < steps; i++)
            {
                //Debug.Log("["+i+"] i*actualBay="+i*actualBay+", perval="+perlval);


                if (i == steps - 1 && !topStep)
                {
                    break;
                }



                // NODES
                if (nodeSrc_po != null && nodeSrc_p.meshes != null)
                {
                    string this_address = "node_" + i;


                    // LOCAL_PLACEMENT

                    localPlacement_mx = localMatrixFromAddress(RepeaterItem.Node, i);



                    // 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 MESHES

                    boundsCombinator[i].mesh      = nodeSrc_po.boundsMesh;
                    boundsCombinator[i].transform = localPlacement_mx * nodeSrc_po.generator.localMatrixWithAxisRotationAndAlignment;



                    // GAME_OBJECTS

                    if (nodePlugGO != null && makeGameObjects && !parametricObject.combineMeshes)
                    {
                        //Matrix4x4 mx = localPlacement_mx  * parametricObject.getTransMatrix() * source.getTransMatrix();

                        //Debug.Log(nodeSrc_po.getLocalMatrix());
                        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;


                                                #if UNITY_EDITOR
                        //if (parametricObject.model.isSelected(nodeSrc_po) && nodeSrc_po.selectedConsumerAddress == this_address)
                        //	Selection.activeGameObject = copyGO;
                                                #endif


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

                        copyGO.name             = copyGO.name + "_" + this_address;
                        copyGO.transform.parent = go.transform;
                    }
                }                 // \NODES



                // CELLS
                if (cellSrc_po != null && cellSrc_p.meshes != null)
                {
                    string this_address = "cell_" + i;


                    // LOCAL_PLACEMENT

                    localPlacement_mx = localMatrixFromAddress(RepeaterItem.Cell, i);


                    // 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 MESHES

                    boundsCombinator[i].mesh      = cellSrc_po.boundsMesh;
                    boundsCombinator[i].transform = localPlacement_mx * cellSrc_po.generator.localMatrixWithAxisRotationAndAlignment;



                    // GAME_OBJECTS

                    if (cellPlugGO != null && makeGameObjects && !parametricObject.combineMeshes)
                    {
                        //Matrix4x4 mx = localPlacement_mx  * parametricObject.getTransMatrix() * source.getTransMatrix();

                        //Debug.Log(cellSrc_po.getLocalMatrix());
                        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;


                                                #if UNITY_EDITOR
                        //if (parametricObject.model.isSelected(nodeSrc_po) && nodeSrc_po.selectedConsumerAddress == this_address)
                        //	Selection.activeGameObject = copyGO;
                                                #endif


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

                        copyGO.name             = copyGO.name + "_" + this_address;
                        copyGO.transform.parent = go.transform;
                    }
                }         // \CELLS
            }             //i



            //Debug.Log(parametricObject.Name + " : " + parametricObject.bounds);



            GameObject.DestroyImmediate(nodePlugGO);
            GameObject.DestroyImmediate(cellPlugGO);


            // FINNISH AX_MESHES

            parametricObject.finishMultiAXMeshAndOutput(ax_meshes, isReplica);



            // FINISH BOUNDARIES

            setBoundsWithCombinator(boundsCombinator);



            // Turn ax_meshes into GameObjects
            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);

                return(go);
            }


            return(null);
        }
Beispiel #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);
        }
Beispiel #3
0
        // GROUPER::GENERATE
        public override GameObject generate(bool makeGameObjects, AXParametricObject initiator_po, bool isReplica)
        {
            //if (ArchimatixUtils.doDebug)
            //Debug.Log (parametricObject.Name + " generate +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");

            if (!parametricObject.isActive)
            {
                return(null);
            }

            if (parametricObject.Groupees == null)
            {
                return(null);
            }


            preGenerate();


            parametricObject.useMeshInputs = true;

            if (parametricObject.meshInputs == null)
            {
                parametricObject.meshInputs = new List <AXParameter>();
            }


            // PROCESS INPUT SHAPES

            // pass Input Shape through...


            //Debug.Log( parametricObject.Name + " <><><><><> PROCESS INPUT SHAPES");
            List <AXParameter> inputShapes = parametricObject.getAllInputShapes();

            for (int i = 0; i < inputShapes.Count; i++)
            {
                AXParameter inputShape = inputShapes[i];

                if (inputShape != null)
                {
                    inputShape.polyTree = null;
                    AXShape.thickenAndOffset(ref inputShape, inputShape.DependsOn);
                }
            }



            GameObject go = null;

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

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


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

            // for each input


            //List<AXParameter> inputMeshes = parametricObject.getAllInputMeshParameters();



            // Reinstate the original functionality of the Grouper as simple combiner in addition to Groupees.
            if (inputs != null && inputs.Count > 0)
            {
                for (int i = 0; i < inputs.Count; i++)
                {
                    if (inputs[i] != null && inputs[i].DependsOn != null)
                    {
                        if (inputs[i].Dependents != null || inputs[i].Dependents.Count == 0)
                        {
                            AXParameter        src_p  = inputs[i].DependsOn;
                            AXParametricObject src_po = inputs[i].DependsOn.parametricObject;
                            //if (! parametricObject.visited_pos.Contains (groupee))

                            //Debug.Log("groupee.generateOutputNow: " + groupee.Name + " isAltered="+groupee.isAltered);
                            if (src_po.isAltered)
                            {
                                src_po.generateOutputNow(makeGameObjects, initiator_po);
                                //Debug.Log("XXXXX: " + groupee.Output.meshes.Count);
                                src_po.isAltered = false;
                                parametricObject.model.AlteredPOs.Remove(src_po);
                            }

                            if (src_p != null && src_p.meshes != null)
                            {
                                for (int j = 0; j < src_p.meshes.Count; j++)
                                {
                                    AXMesh dep_amesh = src_p.meshes [j];
                                    ax_meshes.Add(dep_amesh.Clone(dep_amesh.transMatrix));
                                }
                            }

                            // BOUNDING MESHES
                            //boundsCombinator[i].mesh      = input_p.DependsOn.parametricObject.boundsMesh;
                            //boundsCombinator[i].transform     = input_p.DependsOn.parametricObject.generator.localMatrixWithAxisRotationAndAlignment;
                            if (src_po.boundsMesh != null)
                            {
                                boundingMeshes.Add(new AXMesh(src_po.boundsMesh, src_po.generator.localMatrixWithAxisRotationAndAlignment));
                            }



                            // GAME_OBJECTS

                            if (makeGameObjects && !parametricObject.combineMeshes)
                            {
                                GameObject plugGO = src_po.generator.generate(true, initiator_po, isReplica);
                                if (plugGO != null)
                                {
                                    plugGO.transform.parent = go.transform;
                                }
                            }
                        }
                    }
                }
            }



            // *** GROUPEES - Generate the groupees here
            // so that all the inputs (thicknesses, etc.) have been processed first.

            //List<AXParametricObject> visited_pos = new List<AXParametricObject>();
            if (parametricObject.Groupees != null && parametricObject.Groupees.Count > 0)
            {
                for (int i = 0; i < parametricObject.Groupees.Count; i++)
                {
                    AXParametricObject groupee = parametricObject.Groupees [i];
                    //if (! parametricObject.visited_pos.Contains (groupee))

                    //Debug.Log("groupee.generateOutputNow: " + groupee.Name + " isAltered="+groupee.isAltered);
                    if (groupee.isAltered)
                    {
                        groupee.generateOutputNow(makeGameObjects, initiator_po);
                        //Debug.Log("XXXXX: " + groupee.Output.meshes.Count);
                        groupee.isAltered = false;
                        parametricObject.model.AlteredPOs.Remove(groupee);
                    }
                }
            }



            // BOUNDING



            // Process
            for (int i = 0; i < parametricObject.Groupees.Count; i++)
            {
                AXParametricObject groupee = parametricObject.Groupees [i];


                //if (input_p != null && input_p.DependsOn != null && input_p.DependsOn.meshes != null && input_p.DependsOn.meshes.Count > 0) {
                //if (groupee != null && groupee.is3D() && ! groupee.hasDependents() && groupee.Output != null && groupee.Output.meshes != null)
                if (groupee != null && groupee.is3D() && groupee.shouldRenderSelf(true))
                {
                    // AX_MESHES
                    //Debug.Log("(*) (*) (*) (*) groupee: " + groupee.Name + " " +groupee.Output.meshes.Count + " isAltered = " + groupee.isAltered);
                    if (groupee.Output != null && groupee.Output.meshes != null)
                    {
                        for (int j = 0; j < groupee.Output.meshes.Count; j++)
                        {
                            AXMesh dep_amesh = groupee.Output.meshes [j];
                            ax_meshes.Add(dep_amesh.Clone(dep_amesh.transMatrix));
                        }
                    }


                    // BOUNDING MESHES
                    //boundsCombinator[i].mesh      = input_p.DependsOn.parametricObject.boundsMesh;
                    //boundsCombinator[i].transform     = input_p.DependsOn.parametricObject.generator.localMatrixWithAxisRotationAndAlignment;
                    if (groupee.boundsMesh != null)
                    {
                        boundingMeshes.Add(new AXMesh(groupee.boundsMesh, groupee.generator.localMatrixWithAxisRotationAndAlignment));
                    }



                    // GAME_OBJECTS

                    if (makeGameObjects && !parametricObject.combineMeshes)
                    {
                        GameObject plugGO = groupee.generator.generate(true, initiator_po, isReplica);
                        if (plugGO != null)
                        {
                            plugGO.transform.parent = go.transform;
                        }
                    }
                }
            }



            // FINISH AX_MESHES


            //Debug.Log("ORG: " + ax_meshes.Count);
            parametricObject.finishMultiAXMeshAndOutput(ax_meshes, isReplica);



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


            if (P_BoundsX != null && !P_BoundsX.hasRelations() && !P_BoundsX.hasExpressions())
            {
                P_BoundsX.FloatVal = parametricObject.bounds.size.x;
            }

            if (P_BoundsY != null && !P_BoundsY.hasRelations() && !P_BoundsY.hasExpressions())
            {
                P_BoundsY.FloatVal = parametricObject.bounds.size.y;
            }

            if (P_BoundsZ != null && !P_BoundsZ.hasRelations() && !P_BoundsZ.hasExpressions())
            {
                P_BoundsZ.FloatVal = parametricObject.bounds.size.z;
            }



            // FINISH GAME_OBJECTS

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


                    // COMBINE ALL THE MESHES
                    CombineInstance[] combine = new CombineInstance[ax_meshes.Count];

                    int combineCt = 0;
                    for (int i = 0; i < ax_meshes.Count; i++)
                    {
                        AXMesh _amesh = ax_meshes [i];
                        combine [combineCt].mesh      = _amesh.mesh;
                        combine [combineCt].transform = _amesh.transMatrix;
                        combineCt++;
                    }

                    Mesh combinedMesh = new Mesh();
                    combinedMesh.CombineMeshes(combine);

                    // If combine, use combined mesh as invisible collider
                    MeshFilter mf = (MeshFilter)go.GetComponent(typeof(MeshFilter));

                    if (mf == null)
                    {
                        mf = (MeshFilter)go.AddComponent(typeof(MeshFilter));
                    }

                    if (mf != null)
                    {
                        mf.sharedMesh = combinedMesh;
                        parametricObject.addCollider(go);
                    }
                }

                else
                {
                    Matrix4x4 tmx = parametricObject.getLocalMatrix();

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


            //parametricObject.model.sw.milestone(parametricObject.Name + " generate");


            return(null);
        }
Beispiel #4
0
        // GENERATE GRID_REPEATER
        public override GameObject generate(bool makeGameObjects, AXParametricObject initiator_po, bool isReplica)
        {
            //Debug.Log(parametricObject.Name + " Generate");
            if (parametricObject == null || !parametricObject.isActive)
            {
                return(null);
            }

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

            preGenerate();


            // NODE_MESH
            AXParametricObject nodeSrc_po = null;
            GameObject         nodePlugGO = null;

            if (nodeSrc_p != null)
            {
                nodeSrc_po = nodeSrc_p.parametricObject;
                if (makeGameObjects && !parametricObject.combineMeshes)
                {
                    nodePlugGO = nodeSrc_po.generator.generate(true, initiator_po, isReplica);
                }
            }


            // CELL_MESH
            AXParametricObject cellSrc_po = null;
            GameObject         cellPlugGO = null;

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

            // BAY_SPAN_U
            AXParametricObject spanUSrc_po = null;
            GameObject         spanUPlugGO = null;

            if (spanUSrc_p != null)
            {
                spanUSrc_po = spanUSrc_p.parametricObject;
                if (makeGameObjects && !parametricObject.combineMeshes)
                {
                    spanUPlugGO = spanUSrc_po.generator.generate(true, initiator_po, isReplica);
                }
            }

            // BAY_SPAN_V
            AXParametricObject spanVSrc_po = null;
            GameObject         spanVPlugGO = null;

            if (spanVSrc_p != null)
            {
                spanVSrc_po = spanVSrc_p.parametricObject;
                if (makeGameObjects && !parametricObject.combineMeshes)
                {
                    spanVPlugGO = spanVSrc_po.generator.generate(true, initiator_po, isReplica);
                }
            }



            if (nodeSrc_po == null && cellSrc_po == null && spanUSrc_po == null && spanVSrc_po == null)
            {
                AXParameter output_p = getPreferredOutputParameter();
                if (output_p != null)
                {
                    output_p.meshes = null;
                }

                return(null);
            }


            GameObject go = null;

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



            // BOUNDING_SHAPE

            Paths boundingSolids = null;
            Paths boundingHoles  = null;


            if (P_BoundingShape != null && P_BoundingShape.DependsOn != null)
            {
                AXParameter bounding_src_p = null;
                if (P_BoundingShape != null)
                {
                    bounding_src_p = P_BoundingShape.DependsOn;                               // USING SINGLE SPLINE INPUT
                }
                boundingShapeSrc_po = bounding_src_p.parametricObject;

                AXShape.thickenAndOffset(ref P_BoundingShape, bounding_src_p);
                // now boundin_p has offset and thickened polytree or paths.

                boundingSolids = P_BoundingShape.getTransformedSubjPaths();
                boundingHoles  = P_BoundingShape.getTransformedHolePaths();
            }



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

            Matrix4x4 localPlacement_mx = Matrix4x4.identity;

            // -----------------------------------

            int max_reps = 150;

            int   cellsU     = Mathf.Clamp(repeaterToolU.cells, 1, max_reps);
            float actualBayU = repeaterToolU.actualBay;

            int   cellsV     = Mathf.Clamp(repeaterToolV.cells, 1, max_reps);
            float actualBayV = repeaterToolV.actualBay;

            shiftU = -cellsU * actualBayU / 2;
            shiftV = -cellsV * actualBayV / 2;


            // BAY SPAN
            // Spanners are meshers that get replicated and sized to fit the bay...

            // prepare mesh to iterate in each direction

            //List<AXMesh>  ax_meshes_X         = new List<AXMesh>();
            //List<AXMesh>  ax_meshes_Z         = new List<AXMesh>();



            AXMesh tmpMesh;

            if (spanUSrc_p != null)
            {
                //ax_meshes_X = spanUSrc_p.meshes;
                //ax_meshes_Z = spanUSrc_p.meshes;
            }

            /* NEED TO INTEGRATE THIS BACK IN IN THE FUTRE...
             * if (bay_span_source != null)
             * {
             *
             *      // 1. cache source object
             *      bay_span_source.cacheParameterValues();
             *
             *
             *      // Y_AXIS
             *
             *      AXParameter p_bayv = parametricObject.getParameter("actual_bay_V");
             *      AXParameter p_bayv_client = null;
             *      if (p_bayv != null)
             *      {
             *              foreach (AXRelation rel in p_bayv.relations)
             *              {
             *                      p_bayv_client = rel.getRelatedTo(p_bayv);
             *                      p_bayv_client.intiateRipple_setFloatValueFromGUIChange(abayy);
             *              }
             *      }
             *
             *
             *      AXParameter p_bayu = parametricObject.getParameter("actual_bay_U");
             *      AXParameter p_bayu_client = null;
             *
             *      // X-AXIS
             *      // For now, only set the boundaries.
             *      // Perhaps later, may want to set other like controls as in Replicant
             *
             *      // If there is a relation to actual_bay_U, propogate it
             *      if (p_bayu != null)
             *      {
             *              foreach (AXRelation rel in p_bayu.relations)
             *              {
             *                      p_bayu_client = rel.getRelatedTo(p_bayu);
             *                      p_bayu_client.intiateRipple_setFloatValueFromGUIChange(abayx);
             *              }
             *      }
             *
             *      //bay_span_source.propagateParameterByBinding(1, bayx);
             *      //bay_span_source.propagateParameterByBinding(2, bayy);
             *
             *      // 2. re_generate with temporary values set by this Replicant
             *      bay_span_source.generateOutputNow (makeGameObjects, parametricObject);
             *
             *      // 3. Now that the bay_span_source has been regergrab the meshes from the input sources and add them here
             *      AXParameter output_p = bay_span_source.getParameter("Output Mesh");
             *      foreach (AXMesh amesh in output_p.meshes)
             *              ax_meshes_X.Add (amesh.Clone(amesh.transMatrix));
             *
             *
             *
             *      // Z-AXIS
             *      // Use the bayz now to generate x
             *
             *      if (p_bayu != null)
             *      {
             *              foreach (AXRelation rel in p_bayu.relations)
             *              {
             *                      p_bayu_client = rel.getRelatedTo(p_bayu);
             *                      p_bayu_client.intiateRipple_setFloatValueFromGUIChange(abayz);
             *              }
             *      }
             *
             *      //bay_span_source.propagateParameterByBinding(1, bayz);
             *
             *
             *      // 2. re_generate with temporary values set by this Replicant
             *      bay_span_source.generateOutputNow (makeGameObjects, parametricObject);
             *
             *      // 3. Now that the bay_span_source has been regergrab the meshes from the input sources and add them here
             *      foreach (AXMesh amesh in output_p.meshes)
             *              ax_meshes_Z.Add (amesh.Clone(amesh.transMatrix));
             *
             *
             *      // 4. restore source object; as though we were never here!
             *      bay_span_source.revertParametersFromCache();
             *
             *      //Debug.Log ("HAVE BAY SPAN -- " + output_p.meshes.Count);
             *
             *
             * }
             */


            /* NEED TO INTEGRATE THIS BACK IN IN THE FUTRE...
             * if (cell_center_source != null)
             * {
             *      // Y-AXIS
             *      // For now, only set the boundaries.
             *      // Perhaps later, may want to set other like controls as in Replicant
             *      // 1. cache source object
             *      cell_center_source.cacheParameterValues();
             *
             *
             *
             *      //bay_center_source.propagateParameterByBinding(1, bayx);
             *      //bay_center_source.propagateParameterByBinding(3, bayz);
             *
             *      // 2. re_generate with temporary values set by this Replicant
             *      cell_center_source.generateOutputNow (makeGameObjects, parametricObject);
             *
             *      // 3. Now that the bay_span_source has been regenerted,  grab the meshes from the input sources and add them here
             *      AXParameter bc_output_p = cell_center_source.getParameter("Output Mesh");
             *      foreach (AXMesh amesh in bc_output_p.meshes)
             *              ax_meshes_Y.Add (amesh.Clone(amesh.transMatrix));
             *
             *      // 4. restore source object; as though we were never here!
             *      cell_center_source.revertParametersFromCache();
             *
             * }
             */



            // BOUNDING

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



            for (int i = 0; i <= cellsU; i++)
            {
                for (int k = 0; k <= cellsV; k++)
                {
                    bool exclude = false;

                    IntPoint ip = new IntPoint((i * actualBayU + shiftU) * AXGeometryTools.Utilities.IntPointPrecision, (k * actualBayV + shiftV) * AXGeometryTools.Utilities.IntPointPrecision);

                    if (boundingSolids != null)
                    {
                        exclude = true;

                        if (boundingSolids != null)
                        {
                            foreach (Path path in boundingSolids)
                            {
                                if (Clipper.PointInPolygon(ip, path) == 1 && Clipper.Orientation(path))
                                {
                                    exclude = false;
                                    break;
                                }
                            }
                        }

                        if (boundingHoles != null)
                        {
                            foreach (Path hole in boundingHoles)
                            {
                                if (Clipper.PointInPolygon(ip, hole) == 1)
                                {
                                    exclude = true;
                                    break;
                                }
                            }
                        }
                    }


                    exclude = (boundingIsVoid) ? !exclude : exclude;

                    if (exclude)
                    {
                        continue;
                    }


                    // NODES
                    if (nodeSrc_po != null && nodeSrc_p.meshes != null && ((i <= repeaterToolU.edgeCount || i >= cellsU - repeaterToolU.edgeCount) || (k <= repeaterToolV.edgeCount || k >= cellsV - repeaterToolV.edgeCount)))
                    {
                        string this_address = "node_" + i + "_" + k;

                        // LOCAL PLACEMENT NODE
                        localPlacement_mx = localNodeMatrixFromAddress(i, k);


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


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

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

                                                        #if UNITY_EDITOR
                            //if (parametricObject.model.isSelected(nodeSrc_po) && nodeSrc_po.selectedConsumerAddress == this_address)
                            //	Selection.activeGameObject = copyGO;
                                                        #endif

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

                            copyGO.name             = copyGO.name + "_" + this_address;
                            copyGO.transform.parent = go.transform;
                        }
                    }                     // \NODES



                    // CELL CENTERS
                    if (cellSrc_po != null && cellSrc_p.meshes != null && i < cellsU && k < cellsV && ((i < repeaterToolU.edgeCount || i > cellsU - repeaterToolU.edgeCount - 1) || (k < repeaterToolV.edgeCount || k > cellsV - repeaterToolV.edgeCount - 1)))
                    {
                        string this_address = "cell_" + i + "_" + k;

                        // LOCAL PLACEMENT

                        localPlacement_mx = localCellMatrixFromAddress(i, k);


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

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

                                                        #if UNITY_EDITOR
                            //if (parametricObject.model.isSelected(cellSrc_po) && cellSrc_po.selectedConsumerAddress == this_address)
                            //Selection.activeGameObject = copyGO;
                                                        #endif

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

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



                    // SPAN_U
                    if (spanUSrc_po != null && spanUSrc_p.meshes != null && i < cellsU && k <= cellsV && ((i < repeaterToolV.edgeCount || i > cellsU - repeaterToolU.edgeCount - 1) || (k <= repeaterToolV.edgeCount || k > cellsV - repeaterToolV.edgeCount - 1)))
                    {
                        string this_address = "spanU_" + i + "_" + k;

                        // LOCAL PLACEMENT SPAN_U

                        localPlacement_mx = localSpanUMatrixFromAddress(i, k);


                        // AX_MESHES

                        for (int mi = 0; mi < spanUSrc_p.meshes.Count; mi++)
                        {
                            AXMesh dep_amesh = spanUSrc_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(spanUSrc_po.boundsMesh, localPlacement_mx * spanUSrc_po.generator.localMatrix));



                        // GAME_OBJECTS

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


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

                                                        #if UNITY_EDITOR
                            //if (parametricObject.model.isSelected(spanUSrc_po) && spanUSrc_po.selectedConsumerAddress == this_address)
                            //	Selection.activeGameObject = copyGO;
                                                        #endif

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

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

                    // SPAN_V
                    if (spanVSrc_po != null && spanVSrc_p.meshes != null && i <= cellsU && k < cellsV && ((i <= repeaterToolU.edgeCount || i > cellsU - repeaterToolU.edgeCount - 1) || (k < repeaterToolV.edgeCount || k > cellsV - repeaterToolV.edgeCount - 1)))
                    {
                        string this_address = "spanV_" + i + "_" + k;

                        // LOCAL PLACEMENT SPAN_U
                        localPlacement_mx = localSpanVMatrixFromAddress(i, k);



                        // AX_MESHES

                        for (int mi = 0; mi < spanVSrc_p.meshes.Count; mi++)
                        {
                            AXMesh dep_amesh = spanVSrc_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(spanVSrc_po.boundsMesh, localPlacement_mx * spanVSrc_po.generator.localMatrix));



                        // GAME_OBJECTS

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


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

                                                        #if UNITY_EDITOR
                            //if (parametricObject.model.isSelected(spanVSrc_po) && spanVSrc_po.selectedConsumerAddress == this_address)
                            //	Selection.activeGameObject = copyGO;
                                                        #endif

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

                            copyGO.name             = copyGO.name + "_" + this_address;
                            copyGO.transform.parent = go.transform;
                        }
                    }
                }         // k
            }             //i


            GameObject.DestroyImmediate(nodePlugGO);
            GameObject.DestroyImmediate(cellPlugGO);
            GameObject.DestroyImmediate(spanUPlugGO);
            GameObject.DestroyImmediate(spanVPlugGO);



            // FINISH AX_MESHES

            parametricObject.finishMultiAXMeshAndOutput(ax_meshes, isReplica);



            // 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.generator.localMatrixWithAxisRotationAndAlignment;

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

                return(go);
            }

            return(null);
        }
        // GROUPER::GENERATE
        public override GameObject generate(bool makeGameObjects, AXParametricObject initiator_po, bool isReplica)
        {
            //if (ArchimatixUtils.doDebug)
            //Debug.Log (parametricObject.Name + " generate +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");


            if (!parametricObject.isActive)
            {
                return(null);
            }



            preGenerate();


            GameObject go = null;

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


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


            // BOUNDING

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



            // Reinstate the original functionality of the Grouper as simple combiner in addition to Groupees.
            if (inputs != null && inputs.Count > 0)
            {
                // ALL
                if (channel == inputs.Count)
                {
                    for (int i = 0; i < inputs.Count; i++)
                    {
                        if (inputs[i] != null && inputs[i].DependsOn != null)
                        {
                            if (inputs[i].Dependents != null || inputs[i].Dependents.Count == 0)
                            {
                                AXParameter        src_p  = inputs[i].DependsOn;
                                AXParametricObject src_po = inputs[i].DependsOn.parametricObject;
                                //if (! parametricObject.visited_pos.Contains (groupee))

                                //Debug.Log("groupee.generateOutputNow: " + groupee.Name + " isAltered="+groupee.isAltered);
                                if (src_po.isAltered)
                                {
                                    src_po.generateOutputNow(makeGameObjects, initiator_po);
                                    //Debug.Log("XXXXX: " + groupee.Output.meshes.Count);
                                    src_po.isAltered = false;
                                    parametricObject.model.AlteredPOs.Remove(src_po);
                                }

                                if (src_p != null && src_p.meshes != null)
                                {
                                    for (int j = 0; j < src_p.meshes.Count; j++)
                                    {
                                        AXMesh dep_amesh = src_p.meshes [j];
                                        ax_meshes.Add(dep_amesh.Clone(dep_amesh.transMatrix));
                                    }
                                }

                                // BOUNDING MESHES
                                //boundsCombinator[i].mesh      = input_p.DependsOn.parametricObject.boundsMesh;
                                //boundsCombinator[i].transform     = input_p.DependsOn.parametricObject.generator.localMatrixWithAxisRotationAndAlignment;
                                if (src_po.boundsMesh != null)
                                {
                                    boundingMeshes.Add(new AXMesh(src_po.boundsMesh, src_po.generator.localMatrixWithAxisRotationAndAlignment));
                                }



                                // GAME_OBJECTS

                                if (makeGameObjects && !parametricObject.combineMeshes)
                                {
                                    GameObject plugGO = src_po.generator.generate(true, initiator_po, isReplica);
                                    if (plugGO != null)
                                    {
                                        plugGO.transform.parent = go.transform;
                                    }
                                }
                            }
                        }
                    }
                }



                // JUST ONE CHANNEL
                else if (inputs.Count > channel && inputs[channel] != null)
                {
                    AXParameter src_p = inputs[channel].DependsOn;

                    if (src_p != null)
                    {
                        AXParametricObject src_po = src_p.parametricObject;

                        if (src_po.is3D())
                        {
                            if (src_po.Output != null && src_po.Output.meshes != null)
                            {
                                for (int j = 0; j < src_po.Output.meshes.Count; j++)
                                {
                                    AXMesh dep_amesh = src_po.Output.meshes [j];
                                    ax_meshes.Add(dep_amesh.Clone(dep_amesh.transMatrix));
                                }
                            }


                            // BOUNDING MESHES
                            //boundsCombinator[i].mesh      = input_p.DependsOn.parametricObject.boundsMesh;
                            //boundsCombinator[i].transform     = input_p.DependsOn.parametricObject.generator.localMatrixWithAxisRotationAndAlignment;
                            if (src_po.boundsMesh != null)
                            {
                                boundingMeshes.Add(new AXMesh(src_po.boundsMesh, src_po.generator.localMatrixWithAxisRotationAndAlignment));
                            }


                            // GAME_OBJECTS

                            if (makeGameObjects && !parametricObject.combineMeshes)
                            {
                                GameObject plugGO = src_po.generator.generate(true, initiator_po, isReplica);
                                if (plugGO != null)
                                {
                                    plugGO.transform.parent = go.transform;
                                }
                            }
                        }



                        P_Output.meshes = src_p.meshes;
                    }
                }


                // FINISH AX_MESHES


                //Debug.Log("ORG: " + ax_meshes.Count);
                parametricObject.finishMultiAXMeshAndOutput(ax_meshes, isReplica);



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


                if (P_BoundsX != null && !P_BoundsX.hasRelations() && !P_BoundsX.hasExpressions())
                {
                    P_BoundsX.FloatVal = parametricObject.bounds.size.x;
                }

                if (P_BoundsY != null && !P_BoundsY.hasRelations() && !P_BoundsY.hasExpressions())
                {
                    P_BoundsY.FloatVal = parametricObject.bounds.size.y;
                }

                if (P_BoundsZ != null && !P_BoundsZ.hasRelations() && !P_BoundsZ.hasExpressions())
                {
                    P_BoundsZ.FloatVal = parametricObject.bounds.size.z;
                }
            }



            // FINISH GAME_OBJECTS

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


                    // COMBINE ALL THE MESHES
                    CombineInstance[] combine = new CombineInstance[ax_meshes.Count];

                    int combineCt = 0;
                    for (int i = 0; i < ax_meshes.Count; i++)
                    {
                        AXMesh _amesh = ax_meshes [i];
                        combine [combineCt].mesh      = _amesh.mesh;
                        combine [combineCt].transform = _amesh.transMatrix;
                        combineCt++;
                    }

                    Mesh combinedMesh = new Mesh();
                    combinedMesh.CombineMeshes(combine);

                    // If combine, use combined mesh as invisible collider
                    MeshFilter mf = (MeshFilter)go.GetComponent(typeof(MeshFilter));

                    if (mf == null)
                    {
                        mf = (MeshFilter)go.AddComponent(typeof(MeshFilter));
                    }

                    if (mf != null)
                    {
                        mf.sharedMesh = combinedMesh;
                        parametricObject.addCollider(go);
                    }
                }

                else
                {
                    Matrix4x4 tmx = parametricObject.getLocalMatrix();

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



            return(null);
        }
Beispiel #6
0
        // GENERATE LATHE

        // The only thing a Lathe Node does is prepare a circular Section. Otherwise it is simple a PlanSweep.

        public override GameObject generate(bool makeGameObjects, AXParametricObject initiator_po, bool renderToOutputParameter)
        {
            if (parametricObject == null || !parametricObject.isActive)
            {
                return(null);
            }

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



            preGenerate();


            // PLAN - is an arc or circle
            // generate the plane shape. A circle at .5 radius
            AXParameter plan_p = new AXParameter();

            plan_p.Parent = parametricObject;
            plan_p.Type   = AXParameter.DataType.Shape;
            plan_p.paths  = new Paths();


            float actingRadius = radius + MIN_RAD;
            //Debug.Log("actingRadius="+actingRadius);


            int msegs = Mathf.Max(1, Mathf.FloorToInt(((float)segs * parametricObject.model.segmentReductionFactor)));

            if (snappedSweepAngle == 360)
            {
                plan_p.paths.Add(AXTurtle.Circle(actingRadius, msegs));
                plan_p.shapeState = ShapeState.Closed;
            }
            else
            {
                plan_p.paths.Add(AXTurtle.Arc(actingRadius, 0, snappedSweepAngle, msegs));
                plan_p.shapeState = ShapeState.Open;
            }



            //plan_p.breakGeom = 10;
            plan_p.breakNorm = (faceted ? 10 : 135);
            plan_p.breakGeom = (continuousU         ? 100 :   10);



            // In order to conceptualize the section as at a vert rather than the normal case for PlanSweep where it is on a length,
            // shift the section out by: dx = R ( 1 - cos(ß/2))
            // http://www.archimatix.com/geometry/compensating-for-plansweep-in-a-lathe-mesher

            float beta = snappedSweepAngle / segs;
            float dx   = actingRadius * (1 - Mathf.Cos(Mathf.Deg2Rad * beta / 2));

            //Debug.Log("actingRadius="+actingRadius+", beta="+beta+", dx="+dx);


            ShiftRadMatrix = Matrix4x4.TRS(new Vector3(-MIN_RAD + dx, 0, 0), Quaternion.identity, Vector3.one);

            // SECTION

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

            if (P_Section == null || sectionSrc_p == null || !sectionSrc_p.parametricObject.isActive)
            {
                return(null);
            }

            P_Section.polyTree  = null;
            P_Section.thickness = 0;
            P_Section.offset    = 0;

            AXShape.thickenAndOffset(ref P_Section, sectionSrc_p);

            //Debug.Log(parametricObject.Name);
            //Debug.Log(ShiftRadMatrix);
            if (P_Section.polyTree != null)
            {
                AX.Generators.Generator2D.transformPolyTree(P_Section.polyTree, ShiftRadMatrix);
            }
            else
            {
                P_Section.paths = AX.Generators.Generator2D.transformPaths(P_Section.paths, ShiftRadMatrix);
            }



            GameObject retGO = null;

            if (makeGameObjects && P_Section.polyTree == null && P_Section.paths != null && P_Section.paths.Count > 1)
            {
                //Debug.Log("make one for each section");
                retGO = ArchimatixUtils.createAXGameObject(parametricObject.Name, parametricObject);

                for (int i = 0; i < P_Section.paths.Count; i++)
                {
                    AXParameter tmpSecP = new AXParameter();
                    tmpSecP.shapeState       = ShapeState.Open;
                    tmpSecP.parametricObject = parametricObject;
                    Paths tmpPaths = new Paths();
                    tmpPaths.Add(P_Section.paths[i]);
                    tmpSecP.paths = tmpPaths;
                    GameObject tmpObj = generateFirstPass(initiator_po, makeGameObjects, plan_p, tmpSecP, ShiftRadMatrix, renderToOutputParameter);

                    tmpObj.transform.parent = retGO.transform;
                }
            }
            else
            {
                retGO = generateFirstPass(initiator_po, makeGameObjects, plan_p, P_Section, ShiftRadMatrix, renderToOutputParameter);
            }



            // FINISH AX_MESHES

            parametricObject.finishMultiAXMeshAndOutput(ax_meshes, renderToOutputParameter);



            // FINISH BOUNDING

            setBoundaryFromAXMeshes(ax_meshes);


            if (P_Section.polyTree != null)
            {
                AX.Generators.Generator2D.transformPolyTree(P_Section.polyTree, ShiftRadMatrix.inverse);
            }
            //else
            //	P_Section.paths = AX.Generators.Generator2D.transformPaths(P_Section.paths, ShiftRadMatrix);


            return(retGO);
        }
        // GENERATE PHYSICS_JOINER
        public override GameObject generate(bool makeGameObjects, AXParametricObject initiator_po, bool isReplica)
        {
            if (toSrc_po == null || fromSrc_po == null)
                return null;

            if (parametricObject == null || ! parametricObject.isActive)
                return null;

            preGenerate();

            // FROM_MESH
            GameObject 			fromPlugGO 		= null;
            if (fromSrc_p != null && fromSrc_po != null)
            {
                if (makeGameObjects && ! parametricObject.combineMeshes)
                    fromPlugGO = fromSrc_po.generator.generate(true,  initiator_po,  isReplica);
            }

            // TO_MESH
            GameObject 			toPlugGO 		= null;
            if (toSrc_p != null && toSrc_po != null)
            {
                if (makeGameObjects && ! parametricObject.combineMeshes)
                    toPlugGO = toSrc_po.generator.generate(true,  initiator_po,  isReplica);
            }

            // LIVE MESHES
            List<AXMesh> 	ax_meshes 		= new List<AXMesh>(fromSrc_p.meshes);

            if (toSrc_p != null)
                ax_meshes.AddRange(toSrc_p.meshes);

            List<AXMesh> boundingMeshes 	= new List<AXMesh>();
            boundingMeshes.Add(new AXMesh(fromSrc_po.boundsMesh, fromSrc_po.generator.localMatrixWithAxisRotationAndAlignment));

            if (toSrc_po != null)
                boundingMeshes.Add(new AXMesh(toSrc_po.boundsMesh,  toSrc_po.generator.localMatrixWithAxisRotationAndAlignment));

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

            GameObject go 		= null;

            if (toSrc_po != null && fromSrc_po != null)
            {

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

                    toPlugGO.transform.parent = go.transform;

                    // CONNECT RIGIDBODIES WITH FIXED_JOINT COMPONENT
                    Rigidbody[] fromRBs = fromPlugGO.GetComponentsInChildren<Rigidbody>();
                    Rigidbody[] toRBs 	= toPlugGO.GetComponentsInChildren<Rigidbody>();

                    if (fromRBs != null && fromRBs.Length>0 && toRBs != null && toRBs.Length>0)
                    {
                        for(int i=0; i<toRBs.Length; i++)
                        {
                            FixedJoint fj = fromRBs[0].gameObject.AddComponent<FixedJoint>();
                            fj.connectedBody = toRBs[i];
                            fj.breakForce = breakForce;
                        }
                    }
                }
            }

            parametricObject.finishMultiAXMeshAndOutput(ax_meshes, isReplica);

            //GameObject.DestroyImmediate(fromPlugGO);

            return go;
        }
Beispiel #8
0
        // GENERATE LINEAR_REPEATER
        public override GameObject generate(bool makeGameObjects, AXParametricObject initiator_po, bool isReplica)
        {
            //Debug.Log("repeaterToolU="+repeaterToolU+", repeaterToolV="+repeaterToolV);
            if (parametricObject == null || !parametricObject.isActive)
            {
                return(null);
            }

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


            preGenerate();



            // FLOOR_MESH (NODE_MESH)
            AXParametricObject nodeSrc_po = null;
            GameObject         nodePlugGO = null;

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



            // STORY MESH (CELL_MESH)
            AXParametricObject storySrc_po = null;
            GameObject         storyPlugGO = null;

            if (storySrc_p != null)
            {
                storySrc_po = storySrc_p.parametricObject;
                if (makeGameObjects && !parametricObject.combineMeshes)
                {
                    storyPlugGO = storySrc_po.generator.generate(true, initiator_po, isReplica);
                }
            }

            // TOP_FLOOR
            AXParametricObject topSrc_po = null;
            GameObject         topPlugGO = null;

            if (topSrc_p != null)
            {
                topSrc_po = topSrc_p.parametricObject;
                if (makeGameObjects && !parametricObject.combineMeshes)
                {
                    topPlugGO = topSrc_po.generator.generate(true, initiator_po, isReplica);
                }
            }
            // BOTTOM_FLOOR
            AXParametricObject bottomSrc_po = null;
            GameObject         bottomPlugGO = null;

            if (bottomSrc_p != null)
            {
                bottomSrc_po = bottomSrc_p.parametricObject;
                if (makeGameObjects && !parametricObject.combineMeshes)
                {
                    bottomPlugGO = bottomSrc_po.generator.generate(true, initiator_po, isReplica);
                }
            }



            if (nodeSrc_po == null && storySrc_po == null && topSrc_po == null && bottomSrc_po == null)
            {
                if (P_Output != null)
                {
                    P_Output.meshes = null;
                }

                return(null);
            }


            GameObject go = null;

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



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

            Matrix4x4 localPlacement_mx = Matrix4x4.identity;

            // -----------------------------------


            int max_reps = 150;

            int   cellsU     = Mathf.Clamp(repeaterTool.cells, 1, max_reps);
            float actualBayU = repeaterTool.actualBay;

            shiftU = -cellsU * actualBayU / 2;

            AXMesh tmpMesh;



            // BAY SPAN
            // Spanners are meshers that get replicated and sized to fit the bay...

            // prepare mesh to iterate in each direction



            // BOUNDING

            int boundingObjectCount = 0;

            if (nodeSrc_po != null && nodeSrc_p.meshes != null)
            {
                boundingObjectCount += cellsU + 1;

                if (!topFloor)
                {
                    boundingObjectCount--;
                }

                if (!bottomFloor)
                {
                    boundingObjectCount--;
                }
            }

            if (storySrc_p != null && storySrc_p.meshes != null)
            {
                boundingObjectCount += cellsU;

                if (!topStory)
                {
                    boundingObjectCount--;
                }

                if (!bottomStory)
                {
                    boundingObjectCount--;
                }
            }

            //Debug.Log(cellsU + " :::::: " + boundingObjectCount);

            CombineInstance[] boundsCombinator = new CombineInstance[boundingObjectCount];
            int boundingCursor = 0;

            // LOOP
            for (int i = 0; i <= cellsU; i++)
            {
                // FLOORS (NODES)
                if ((i == 0 && bottomFloor) || (i == cellsU && topFloor) || (i > 0 && i < cellsU))
                {
                    AXParameter        tmpSrc_p  = nodeSrc_p;
                    AXParametricObject tmpSrc_po = nodeSrc_po;
                    GameObject         tmpPlugGO = nodePlugGO;
                    if (i == 0 && bottomSrc_p != null)
                    {
                        tmpSrc_p  = bottomSrc_p;
                        tmpSrc_po = bottomSrc_po;
                        tmpPlugGO = bottomPlugGO;
                    }
                    else if (i == cellsU && topSrc_p != null)
                    {
                        tmpSrc_p  = topSrc_p;
                        tmpSrc_po = topSrc_po;
                        tmpPlugGO = topPlugGO;
                    }

                    if (tmpSrc_po != null && tmpSrc_p.meshes != null)
                    {
                        string this_address = "node_" + i;



                        localPlacement_mx = localNodeMatrixFromAddress(i);


                        // AX_MESHES

                        for (int j = 0; j < tmpSrc_p.meshes.Count; j++)
                        {
                            AXMesh dep_amesh = tmpSrc_p.meshes [j];

                            tmpMesh = dep_amesh.Clone(localPlacement_mx * dep_amesh.transMatrix);
                            tmpMesh.subItemAddress = this_address;
                            ax_meshes.Add(tmpMesh);
                        }



                        // BOUNDING MESHES

                        boundsCombinator[boundingCursor].mesh      = tmpSrc_po.boundsMesh;
                        boundsCombinator[boundingCursor].transform = localPlacement_mx * tmpSrc_po.generator.localMatrixWithAxisRotationAndAlignment;
                        boundingCursor++;


                        // GAME_OBJECTS

                        if (tmpPlugGO != null && makeGameObjects && !parametricObject.combineMeshes)
                        {
                            //Matrix4x4 mx = localPlacement_mx  * parametricObject.getTransMatrix() * source.getTransMatrix();

                            //Debug.Log(nodeSrc_po.getLocalMatrix());
                            Matrix4x4  mx     = localPlacement_mx * tmpSrc_po.generator.localMatrixWithAxisRotationAndAlignment;
                            GameObject copyGO = (GameObject)GameObject.Instantiate(tmpPlugGO, AXUtilities.GetPosition(mx), AXUtilities.QuaternionFromMatrix(mx));

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



                                                        #if UNITY_EDITOR
                            //if (parametricObject.model.isSelected(tmpSrc_po) && tmpSrc_po.selectedConsumerAddress == this_address)
                            //	Selection.activeGameObject = copyGO;
                                                        #endif


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

                            copyGO.name             = copyGO.name + "_" + this_address;
                            copyGO.transform.parent = go.transform;
                        }
                    }                     // \NODES
                }



                // STORIES (CELLS)
                if ((i == 0 && bottomStory) || (i == cellsU - 1 && topStory) || (i > 0 && i < cellsU - 1))
                {
                    if (storySrc_p != null && storySrc_p.meshes != null && i < cellsU)
                    {
                        string this_address = "cell_" + i;


                        // LOCAL_PLACEMENT
                        localPlacement_mx = localCellMatrixFromAddress(i);


                        // AX_MESHES

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



                        // BOUNDING MESHES
                        if (boundsCombinator.Length > boundingCursor)
                        {
                            boundsCombinator[boundingCursor].mesh      = storySrc_po.boundsMesh;
                            boundsCombinator[boundingCursor].transform = localPlacement_mx * storySrc_po.generator.localMatrixWithAxisRotationAndAlignment;
                            boundingCursor++;
                        }


                        // GAME_OBJECTS

                        if (storyPlugGO != null && makeGameObjects && !parametricObject.combineMeshes)
                        {
                            //Matrix4x4 mx = localPlacement_mx  * parametricObject.getTransMatrix() * source.getTransMatrix();
                            Matrix4x4  mx     = localPlacement_mx * storySrc_po.generator.localMatrixWithAxisRotationAndAlignment;
                            GameObject copyGO = (GameObject)GameObject.Instantiate(storyPlugGO, AXUtilities.GetPosition(mx), AXUtilities.QuaternionFromMatrix(mx));

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

                            copyGO.name             = copyGO.name + "_" + this_address;
                            copyGO.transform.parent = go.transform;
                        }
                    }     // \ STORIES (CELLS)
                }
            }             //i


            GameObject.DestroyImmediate(nodePlugGO);
            GameObject.DestroyImmediate(storyPlugGO);
            GameObject.DestroyImmediate(topPlugGO);
            GameObject.DestroyImmediate(bottomPlugGO);

            parametricObject.finishMultiAXMeshAndOutput(ax_meshes, isReplica);

            setBoundsWithCombinator(boundsCombinator);

            // Turn ax_meshes into GameObjects
            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);

                return(go);
            }


            return(null);
        }
Beispiel #9
0
        public override GameObject generate(bool makeGameObjects, AXParametricObject initiator_po, bool isReplica)
        {
            if (parametricObject == null || !parametricObject.isActive)
            {
                return(null);
            }

            if (P_PrototypePlan == null || P_Prototype == null)
            {
                return(null);
            }



            preGenerate();


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

            planPaths = P_Plan.getPaths();

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



            prototypePlanSrc_p  = P_PrototypePlan.DependsOn;
            prototypePlanSrc_po = (prototypePlanSrc_p != null) ? prototypePlanSrc_p.parametricObject        : null;

            prototypeSrc_p      = P_Prototype.DependsOn;
            prototypePlanSrc_po = (prototypeSrc_p != null) ? prototypeSrc_p.parametricObject        : null;


            if (prototypePlanSrc_p == null || prototypePlanSrc_po == null || prototypeSrc_po == null)
            {
                return(null);
            }

            AXParameter srcSrc_p = prototypePlanSrc_p.DependsOn;

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



            // AX_MESHES
            List <AXMesh> ax_meshes = new List <AXMesh>();


            GameObject go = null;

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


            Perlin perlin = new Perlin();

            perlin.OctaveCount = 1;
            perlin.Frequency   = .05f;

            GameObject replicant = null;

            foreach (Path plan in planPaths)
            {
                // 1. cache source object
                //prototypeSrc_po.cacheParameterValues();

                Paths tmpPaths = new Paths();
                tmpPaths.Add(plan);

                IntPoint planCenter = AXGeometryTools.Utilities.getCenter(tmpPaths);
                Vector3  centerPt   = AXGeometryTools.Utilities.IntPt2Vec3(planCenter);

                //Debug.Log("Center: " + centerPt);

                srcSrc_p.paths = tmpPaths;

                float area = ((float)Clipper.Area(plan)) / 1000000000;

                //Debug.Log(area);
                float perlinVal = (float)perlin.GetValue(centerPt);



                float h = 3 + 100 * (float)Math.Exp(-(.1f * area)) + 5 * perlinVal;             // (float) perlin.GetValue(2,3,4);

                AXParameter sHeight = prototypeSrc_po.getParameter("Height");
                sHeight.initiateRipple_setFloatValueFromGUIChange(h);

                prototypeSrc_po.generator.pollControlValuesFromParmeters();
                prototypeSrc_po.isAltered = true;



                replicant = prototypeSrc_po.generateOutputNow(makeGameObjects, parametricObject, true);

                if (replicant != null)
                {
                    replicant.transform.parent = go.transform;
                }

                AXParameter output_p = prototypeSrc_po.getParameter("Output Mesh");
                foreach (AXMesh amesh in output_p.meshes)
                {
                    ax_meshes.Add(amesh.Clone(amesh.transMatrix));
                }
            }


            // FINISH AX_MESHES

            parametricObject.finishMultiAXMeshAndOutput(ax_meshes, isReplica);


            if (makeGameObjects)
            {
                return(go);
            }



            return(null);
        }
Beispiel #10
0
        // GENERATE PAIR_REPEATER
        public override GameObject generate(bool makeGameObjects, AXParametricObject initiator_po, bool isReplica)
        {
            //Debug.Log ("PairRepeater::Generate ");
            if (parametricObject == null || !parametricObject.isActive)
            {
                return(null);
            }

            preGenerate();

            if ((nodeSrc_p == null || nodeSrc_p.meshes == null || nodeSrc_p.meshes.Count == 0) && (nodeSrc_po != null && !(nodeSrc_po.generator is PrefabInstancer)))
            {
                return(null);
            }


            if (P_Node == null || P_Node.DependsOn == null)
            {
                return(null);
            }

            GameObject go = null;

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


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

            GameObject plugGO = null;

            if (makeGameObjects && !parametricObject.combineMeshes)
            {
                plugGO = nodeSrc_po.generator.generate(true, initiator_po, isReplica);


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



            float separationX = zAxis ? 0 : separation;
            float separationZ = zAxis ? -separation : 0;


            CombineInstance[] boundsCombinator = new CombineInstance[2];



            // * RIGHT INSTANCE	*
            // --------------------------------------------------------------------


            // Right Instance is at Address 0...
            Matrix4x4 localPlacement_mx = localNodeMatrixFromAddress(0);

            // use submeshes for right instance

            // AX_MESHES

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


            // BOUNDING MESHES

            boundsCombinator[0].mesh      = nodeSrc_po.boundsMesh;
            boundsCombinator[0].transform = localPlacement_mx * nodeSrc_po.generator.localMatrixWithAxisRotationAndAlignment;



            // GAME_OBJECTS

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

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


                copyGO.name             = copyGO.name + "_node_right";
                copyGO.transform.parent = go.transform;
            }



            // * INVERSE (LEFT) INSTANCE
            // --------------------------------------------------------------------

            // ***--- AX_MESHES - INVERSE (LEFT) ---***



            translate = new Vector3(-separationX / 2, 0, -separationZ / 2);

            // LOCAL PLACEMENT
            localPlacement_mx = localNodeMatrixFromAddress(1);

            // use submeshes for left instance
            for (int mi = 0; mi < P_Node.DependsOn.meshes.Count; mi++)
            {
                // CLONE
                AXMesh dep_amesh = P_Node.DependsOn.meshes [mi];
                AXMesh clone     = dep_amesh.Clone();
                // SYMETRICAL?
                if (symmetrical)
                {
                    clone.mesh        = AXMesh.freezeWithMatrix(dep_amesh.mesh, symmetryM * dep_amesh.transMatrix);
                    clone.transMatrix = localPlacement_mx * symmetryM.inverse;
                }
                else
                {
                    clone = dep_amesh.Clone(localPlacement_mx * symmetryM.inverse * dep_amesh.transMatrix);
                }
                // ADD TO AX_MESHES
                ax_meshes.Add(clone);
            }



            // BOUNDING MESHES

            boundsCombinator[1].mesh      = nodeSrc_po.boundsMesh;
            boundsCombinator[1].transform = localPlacement_mx * nodeSrc_po.generator.localMatrixWithAxisRotationAndAlignment;



            //   *** --- INVERSE (LEFT) - GAME_OBJECT ---**
            if (plugGO != null && makeGameObjects && !parametricObject.combineMeshes)
            {
                // LOCAL PLACEMENT
                //Matrix4x4 mx = localPlacement_mx  * symmetryM * nodeSrc_po.generator.localMatrixWithAxisRotationAndAlignment;
                Matrix4x4 mx = localPlacement_mx * nodeSrc_po.generator.localMatrixWithAxisRotationAndAlignment;



                // GAME_OBJECT
                GameObject copyGO = (GameObject)GameObject.Instantiate(plugGO, AXUtilities.GetPosition(mx), AXUtilities.QuaternionFromMatrix(mx));
                copyGO.transform.localScale = nodeSrc_po.getLocalScaleAxisRotated();

                // SYMETRICAL?
                if (symmetrical)
                {
                    copyGO.transform.localScale = copyGO.transform.localScale * -1;
                    if (zAxis)
                    {
                        copyGO.transform.Rotate(0, 180, 180);
                    }
                    else
                    {
                        copyGO.transform.Rotate(180, 0, 0);
                    }
                }


                // Force a refreshing of the colliders down the instatiatined hierachy
                // Based on a solution provided by pkamat here:http://forum.unity3d.com/threads/how-to-update-a-mesh-collider.32467/

                foreach (MeshCollider mc in copyGO.GetComponentsInChildren <MeshCollider>())
                {
                    mc.sharedMesh = null;
                    mc.sharedMesh = mc.gameObject.GetComponent <MeshFilter>().sharedMesh;
                }


                // ADD GAME_OBJECT
                AXGameObject axgo = copyGO.GetComponent <AXGameObject>();
                if (axgo != null)
                {
                    axgo.consumerAddress = "node_1";
                }

                copyGO.name             = copyGO.name + "_node_left";
                copyGO.transform.parent = go.transform;
            }



            GameObject.DestroyImmediate(plugGO);



            // COMBINE ALL THE MESHES
            CombineInstance[] combine = new CombineInstance[ax_meshes.Count];

            int combineCt = 0;

            for (int i = 0; i < ax_meshes.Count; i++)
            {
                AXMesh _amesh = ax_meshes [i];
                combine [combineCt].mesh      = _amesh.mesh;
                combine [combineCt].transform = _amesh.transMatrix;
                combineCt++;
            }
            Mesh combinedMesh = new Mesh();

            combinedMesh.CombineMeshes(combine);
            combinedMesh.RecalculateBounds();

            // BOUNDARY - Use combined meshes for boundary
            setBoundsWithCombinator(boundsCombinator);

            /*
             * // BOUNDS & CENTER
             *
             * Vector3 margin = new Vector3(source_po.bounds.size.x, source_po.bounds.size.y, source_po.bounds.size.z);
             * Bounds b = new Bounds();
             * b.size = new Vector3(separationX + margin.x, margin.y, separationZ + margin.z);
             * b.extents = b.size/2;
             * b.center = source_po.bounds.center;// + new Vector3(0, b.extents.y, 0);
             *
             * parametricObject.margin = margin;
             * parametricObject.bounds = b;
             */

            // FINISH
            parametricObject.finishMultiAXMeshAndOutput(ax_meshes, isReplica);


            // Turn ax_meshes into GameObjects
            if (makeGameObjects)
            {
                if (parametricObject.combineMeshes)
                {
                    go = parametricObject.makeGameObjectsFromAXMeshes(ax_meshes, true, false);

                    // If combine, use combined mesh as invisible collider
                    MeshFilter mf = (MeshFilter)go.GetComponent(typeof(MeshFilter));
                    if (mf == null)
                    {
                        mf = (MeshFilter)go.AddComponent(typeof(MeshFilter));
                    }
                    if (mf != null)
                    {
                        mf.sharedMesh = combinedMesh;

                        parametricObject.addCollider(go);
                    }
                }

                //Matrix4x4 tmx = parametricObject.generator.localMatrix;
                Matrix4x4 tmx = parametricObject.getLocalMatrix();

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



                return(go);
            }


            return(null);
        }
        // GENERATE LINEAR_REPEATER
        public override GameObject generate(bool makeGameObjects, AXParametricObject initiator_po, bool isReplica)
        {
            //Debug.Log("repeaterToolU="+repeaterToolU+", repeaterToolV="+repeaterToolV);

            //Debug.Log("LINEAR REPEATER: Gentrate");



            if (parametricObject == null || !parametricObject.isActive)
            {
                return(null);
            }

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


            preGenerate();


            repeaterTool = (zAxis) ? repeaterToolV : repeaterToolU;

            repeaterTool = repeaterToolU;



            //Terrain terrain = Terrain.activeTerrain;


            // NODE_MESH
            AXParametricObject nodeSrc_po = null;
            GameObject         nodePlugGO = null;

            if (nodeSrc_p != null)
            {
                nodeSrc_po = nodeSrc_p.parametricObject;
                if (makeGameObjects && !parametricObject.combineMeshes)
                {
                    nodePlugGO = nodeSrc_po.generator.generate(true, initiator_po, isReplica);
                }
            }

            // CELL_MESH
            AXParametricObject cellSrc_po = null;
            GameObject         cellPlugGO = null;

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

            // BAY_SPAN
            AXParametricObject spanSrc_po = null;
            GameObject         spanPlugGO = null;

            if (spanUSrc_p != null)
            {
                spanSrc_po = spanUSrc_p.parametricObject;
                if (makeGameObjects && !parametricObject.combineMeshes)
                {
                    spanPlugGO = spanSrc_po.generator.generate(true, initiator_po, isReplica);
                }
            }



            if (nodeSrc_po == null && spanSrc_po == null && cellSrc_po == null)
            {
                if (P_Output != null)
                {
                    P_Output.meshes = null;
                }

                return(null);
            }


            GameObject go = null;

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



            Paths boundingSolids = null;
            Paths boundingHoles  = null;



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

            Matrix4x4 localPlacement_mx = Matrix4x4.identity;

            // -----------------------------------


            int max_reps = 150;

            int   cellsU     = Mathf.Clamp(repeaterTool.cells, 1, max_reps);
            float actualBayU = repeaterTool.actualBay;

            if (float.IsNaN(actualBayU))
            {
                return(null);
            }

            shiftU = -cellsU * actualBayU / 2;

            AXMesh tmpMesh;


            // BAY SPAN
            // Spanners are meshers that get replicated and sized to fit the bay...

            // prepare mesh to iterate in each direction

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



            if (spanUSrc_p != null)
            {
                ax_meshes_X = spanUSrc_p.meshes;
            }



            /* NEED TO INTEGRATE THIS BACK IN IN THE FUTRE...
             * if (cell_center_source != null)
             * {
             *      // Y-AXIS
             *      // For now, only set the boundaries.
             *      // Perhaps later, may want to set other like controls as in Replicant
             *      // 1. cache source object
             *      cell_center_source.cacheParameterValues();
             *
             *
             *
             *      //bay_center_source.propagateParameterByBinding(1, bayx);
             *      //bay_center_source.propagateParameterByBinding(3, bayz);
             *
             *      // 2. re_generate with temporary values set by this Replicant
             *      cell_center_source.generateOutputNow (makeGameObjects, parametricObject);
             *
             *      // 3. Now that the bay_span_source has been regenerted,  grab the meshes from the input sources and add them here
             *      AXParameter bc_output_p = cell_center_source.getParameter("Output Mesh");
             *      foreach (AXMesh amesh in bc_output_p.meshes)
             *              ax_meshes_Y.Add (amesh.Clone(amesh.transMatrix));
             *
             *      // 4. restore source object; as though we were never here!
             *      cell_center_source.revertParametersFromCache();
             *
             * }
             */



            // BOUNDING

            int boundingObjectCount = 0;

            if (nodeSrc_po != null && nodeSrc_p.meshes != null)
            {
                boundingObjectCount += cellsU + 1;

                if (!doFirstNode)
                {
                    boundingObjectCount--;
                }

                if (!doLastNode)
                {
                    boundingObjectCount--;
                }
            }


            else if (cellSrc_p != null && cellSrc_p.meshes != null)
            {
                boundingObjectCount += cellsU;
            }

            if (spanUSrc_p != null && spanUSrc_p.meshes != null)
            {
                boundingObjectCount += cellsU;
            }

            CombineInstance[] boundsCombinator = new CombineInstance[boundingObjectCount];


            // FOR EACH ADDRESS

            for (int i = 0; i <= cellsU; i++)
            {
                //Debug.Log("["+i+"] i*actualBay="+i*actualBay+", perval="+perlval);

                if (boundingSolids != null)
                {
                    IntPoint ip = new IntPoint((i * repeaterToolU.actualBay + shiftU) * AXGeometryTools.Utilities.IntPointPrecision, 0);

                    bool exclude = true;

                    if (boundingSolids != null)
                    {
                        foreach (Path path in boundingSolids)
                        {
                            if (Clipper.PointInPolygon(ip, path) == 1 && Clipper.Orientation(path))
                            {
                                exclude = false;
                                break;
                            }
                        }
                    }

                    if (boundingHoles != null)
                    {
                        foreach (Path hole in boundingHoles)
                        {
                            if (Clipper.PointInPolygon(ip, hole) == 1)
                            {
                                exclude = true;
                                break;
                            }
                        }
                    }

                    if (exclude)
                    {
                        continue;
                    }
                }



                //Debug.Log(" ** ** ** * " + nodeSrc_p.meshes);

                // NODES
                if (nodeSrc_po != null && nodeSrc_p.meshes != null)
                {
                    // Debug.Log("nodeSrc_po.getLocalAlignMatrix()"+nodeSrc_po.getLocalAlignMatrix());
                    if ((i > 0 && i < cellsU) || (i == 0 && doFirstNode) || (i == (cellsU) && doLastNode))
                    {
                        string this_address = "node_" + i;

                        int ni = doFirstNode ? i : i - 1;


                        // LOCAL_PLACEMENT //

                        localPlacement_mx = localNodeMatrixFromAddress(i);


                        if (float.IsNaN(localPlacement_mx.m00))
                        {
                            continue;
                        }


                        // AX_MESHES

                        for (int mi = 0; mi < nodeSrc_p.meshes.Count; mi++)
                        {
                            AXMesh dep_amesh = nodeSrc_p.meshes [mi];

                            //tmpMesh = dep_amesh.CloneTransformed (localPlacement_mx * dep_amesh.transMatrix);
                            tmpMesh = dep_amesh.Clone(localPlacement_mx * dep_amesh.transMatrix);
                            tmpMesh.subItemAddress = this_address;
                            ax_meshes.Add(tmpMesh);
                        }



                        // BOUNDING MESHES

                        boundsCombinator[ni].mesh      = nodeSrc_po.boundsMesh;
                        boundsCombinator[ni].transform = localPlacement_mx * nodeSrc_po.generator.localMatrixWithAxisRotationAndAlignment;


                        // GAME_OBJECTS

                        if (nodePlugGO != null && makeGameObjects && !parametricObject.combineMeshes)
                        {
                            //Matrix4x4 mx = localPlacement_mx  * parametricObject.getTransMatrix() * source.getTransMatrix();

                            //Debug.Log(nodeSrc_po.getLocalMatrix());
                            Matrix4x4 mx = localPlacement_mx * nodeSrc_po.generator.localMatrixWithAxisRotationAndAlignment;


                            GameObject copyGO = (GameObject)GameObject.Instantiate(nodePlugGO, AXUtilities.GetPosition(mx), AXUtilities.QuaternionFromMatrix(mx));

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

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

                            copyGO.name             = copyGO.name + "_" + this_address;
                            copyGO.transform.parent = go.transform;
                        }
                    }
                }                 // \NODES



                // CELL CENTERS
                if (cellSrc_p != null && cellSrc_p.meshes != null && i < cellsU)
                {
                    string this_address = "cell_" + i;

                    //Debug.Log("Here");
                    // LOCAL_PLACEMENT
                    localPlacement_mx = localCellMatrixFromAddress(i);


                    // ACTUAL 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 MESHES

                    boundsCombinator[i].mesh      = cellSrc_po.boundsMesh;
                    boundsCombinator[i].transform = localPlacement_mx * cellSrc_po.generator.localMatrixWithAxisRotationAndAlignment;;



                    // GAME_OBJECTS

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

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

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

                        copyGO.name             = copyGO.name + "_" + this_address;
                        copyGO.transform.parent = go.transform;

                        //Debug.Log("LINEAR: " + axgo.consumerAddress);
                    }
                }                 // \CELLS



                // SPANS

                if (spanUSrc_p != null && spanUSrc_p.meshes != null && i < cellsU)
                {
                    string this_address = "spanU_" + i;
                    // X-AXIS

                    // LOCAL_PLACEMENT

                    localPlacement_mx = localCellMatrixFromAddress(i);



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



                    // BOUNDING MESHES

                    boundsCombinator[i].mesh      = spanUSrc_po.boundsMesh;
                    boundsCombinator[i].transform = localPlacement_mx * spanUSrc_po.generator.localMatrixWithAxisRotationAndAlignment;


                    // GAME_OBJECTS

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

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


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

                        copyGO.name = copyGO.name + "_" + this_address;

                        copyGO.transform.parent = go.transform;
                    }
                }         // \SPANS
            }             //i


            GameObject.DestroyImmediate(nodePlugGO);
            GameObject.DestroyImmediate(cellPlugGO);
            GameObject.DestroyImmediate(spanPlugGO);


            parametricObject.finishMultiAXMeshAndOutput(ax_meshes, isReplica);


            setBoundsWithCombinator(boundsCombinator);

            // Turn ax_meshes into GameObjects
            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);

                return(go);
            }


            return(null);
        }