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