예제 #1
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);
        }