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



            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);
        }
Example #4
0
        // GENERATE REPLICANT
        public override GameObject generate(bool makeGameObjects, AXParametricObject initiator_po, bool renderToOutputParameter)
        {
            //Debug.Log ("===> " + parametricObject.Name + " generate");

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

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

            preGenerate();

            AXParameter input_p = parametricObject.getParameter("Input Mesh");

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

            AXParametricObject src_po = input_p.DependsOn.Parent;

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

            Matrix4x4 srcLocalM = src_po.getLocalMatrix().inverse;


            // 1. cache source object
            List <AXParameter> geometryControlParameterList = parametricObject.getAllParametersOfPType(AXParameter.ParameterType.GeometryControl);

            src_po.cacheAndSetParameters(geometryControlParameterList);

            if (!makeGameObjects)
            {
                // 2. re_generate source PO with temporary values set by this Replicant
                src_po.generateOutputNow(false, parametricObject, false);

                // 3. Now that the input_sourcePO has been regenerated,
                //    grab the temporaryOutputMeshes meshes
                //    from the input sources and add them here
                List <AXMesh> ax_meshes = new List <AXMesh>();
                if (src_po.temporaryOutputMeshes != null)
                {
                    for (int mi = 0; mi < src_po.temporaryOutputMeshes.Count; mi++)
                    {
                        AXMesh amesh = src_po.temporaryOutputMeshes [mi];
                        ax_meshes.Add(amesh.Clone(srcLocalM * amesh.transMatrix));
                    }
                }
                parametricObject.finishMultiAXMeshAndOutput(ax_meshes);

                setBoundaryFromAXMeshes(ax_meshes);
            }
            // 4. Make GAME OBJECTS
            GameObject go = null;

            if (makeGameObjects)
            {
                go      = src_po.generator.generate(true, initiator_po, false);
                go.name = src_po.Name + " Replicant";
                AXGameObject axgo = go.GetComponent <AXGameObject>();
                if (axgo != null)
                {
                    axgo.makerPO_GUID = parametricObject.Guid;
                }
            }



            //  5. restore source object; as though we were never here!
            src_po.revertParametersFromCache();


            // Turn ax_meshes into GameObjects
            if (makeGameObjects)
            {
                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);
        }