Exemple #1
0
        public override void connectionMadeWith(AXParameter to_p, AXParameter from_p)
        {
            if (from_p == null)            // || from_p.DependsOn == null)
            {
                return;
            }

            AXParameter this_p = (to_p.parametricObject == parametricObject) ? to_p   : from_p;

            //AXParameter src_p  = (to_p.parametricObject == parametricObject) ? from_p : to_p;


            base.connectionMadeWith(to_p, from_p);


            if (parametricObject.is2D())
            {
                return;
            }

            switch (this_p.Name)
            {
            case "Node Mesh":
                if (nodeSrc_po != null)
                {
                    P_Seperation.initiateRipple_setFloatValueFromGUIChange(nodeSrc_po.getBoundsAdjustedForAxis().size.x *1.1f);
                }
                break;

            case "Cell Mesh":

                if (cellSrc_p != null)
                {
                    P_Seperation.initiateRipple_setFloatValueFromGUIChange(cellSrc_p.parametricObject.bounds.size.x * 1.1f);
                }
                break;
            }
        }
Exemple #2
0
    // Use this for initialization
    void Start()
    {
        // Establish refernces to AXModel parameters.


        // EXPOSED PARAMETERS

        if (model != null)
        {
            P_Channel = model.getParameter("EngineSwitch.Channel");
            if (P_Channel != null)
            {
                P_Channel.WasAltered += OnEngineChannelChanged;
            }


            P_EngineSize = model.getParameter("Engine.radius");
            if (P_EngineSize != null)
            {
                P_EngineSize.WasAltered += OnEngineSizeChanged;
            }


            P_HullShape = model.getParameter("HullShape");
            if (P_HullShape != null)
            {
                P_HullShape.WasAltered += OnHullChanged;
            }


            P_WeaponSize = model.getParameter("BigGuns.radius");
            if (P_WeaponSize != null)
            {
                P_WeaponSize.WasAltered += OnWeaponsChanged;
            }
        }


        // UI CALLBACKS FOR RUNTIME PARAMETERS
        // Bind UI elements to local methods (this could also be done in the Inspector for each UI item.

        if (shipNameText != null)
        {
            shipNameText.onEndEdit.AddListener(
                delegate {
                shipNameUpdate();
            }
                );
        }

        if (engineTypeDropdown != null)
        {
            engineTypeDropdown.onValueChanged.AddListener(
                delegate {
                engineTypeDropdownUpdate();
            }
                );
        }

        if (radiusSlider != null)
        {
            radiusSlider.onValueChanged.AddListener(
                delegate {
                radiusSliderUpdate();
            }
                );
        }

        if (bigGunsSlider != null)
        {
            bigGunsSlider.onValueChanged.AddListener(
                delegate {
                bigGunsSliderUpdate();
            }
                );
        }


        //Initialize AXModel parameters based on UI elements.

        if (P_EngineSize != null)
        {
            P_EngineSize.initiateRipple_setFloatValueFromGUIChange(radiusSlider.value);
        }

        if (P_Channel != null)
        {
            P_Channel.initiateRipple_setIntValueFromGUIChange(engineTypeDropdown.value);
        }

        if (P_WeaponSize != null)
        {
            P_WeaponSize.initiateRipple_setFloatValueFromGUIChange(bigGunsSlider.value);
        }



        // GENERATE THE AX_MODEL.
        model.autobuild();


        // CALCULATE VALUES FOR THE UI DISPLAY
        recalculate();
    }
Exemple #3
0
 public void processFloat(AXParameter p, float value)
 {
     p.initiateRipple_setFloatValueFromGUIChange(value);
     model.autobuild();
 }
Exemple #4
0
 public void UpdateThickness(float val)
 {
     p_thickness.initiateRipple_setFloatValueFromGUIChange(val);
     model.isAltered();
 }
Exemple #5
0
 public void UpdateHeight(float val)
 {
     p_height.initiateRipple_setFloatValueFromGUIChange(val);
     model.isAltered();
 }
Exemple #6
0
 public void UpdateRadius(float val)
 {
     p_radius.initiateRipple_setFloatValueFromGUIChange(val);
     model.isAltered();
 }
Exemple #7
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);
        }
Exemple #8
0
        // GENERATE
        // This is the main function for generating a Shape, Mesh, or any other output that a node may be tasked with generating.
        // You can do pre processing of Inputs here, but that might best be done in an override of pollControlValuesFromParmeters().
        //
        // Often, you will be creating a list of AXMesh objects. AXMesh has a Mesh, a Matrix4x4 and a Material
        // to be used when drawing the ouput to the scene before creating GameObjects. Your list of AXMeshes generated
        // is pased to the model via parametricObject.finishMultiAXMeshAndOutput().
        //
        // When generate() is called by AX, it will be either with makeGameObjects set to true or false.
        // makeGameObjects=False is passed when the user is dragging a parameter and the model is regenerateing multiple times per second.
        // makeGameObjects=True is passed when the user has stopped editing (for example, OnMouseup from a Handle) and it is time to
        // build a GameObject hierarchy.

        public override GameObject generate(bool makeGameObjects, AXParametricObject initiator_po, bool isReplica)
        {
            if (parametricObject == null || !parametricObject.hasInputMeshReady("Input Mesh"))
            {
                return(null);
            }

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



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

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

            Perlin perlin = new Perlin();

            perlin.Frequency = .1f;
            float factor = amount / 100;

            if (inputSrc_p != null && inputSrc_p.meshes != null)              // Is there an input node connected to this node?
            {
                //Debug.Log("P_Input.DependsOn.meshes.Count="+P_Input.DependsOn.meshes.Count + ", "+ P_Input.DependsOn.meshes[0].GetType());
                AXMesh amesh = null;
                for (int i = 0; i < P_Input.DependsOn.meshes.Count; i++)
                {
                    if (amount == 0)
                    {
                        amesh = P_Input.DependsOn.meshes [i];
                    }
                    else
                    {
                        // Instance does not inhereit and build on the transform of its source object.
                        amesh = P_Input.DependsOn.meshes [i].Clone();
                        Mesh      m     = amesh.mesh;
                        Vector3[] verts = m.vertices;

                        for (int j = 0; j < verts.Length; j++)
                        {
                            //Debug.Log(verts[j] + " " + perlin.GetValue(verts[j]));
//							float pval = factor * 100 *(float) perlin.GetValue(verts[j]);

                            //						float new_x = verts [j].x + pval;
                            //						float new_y = verts [j].y + pval;
                            //						float new_z = verts [j].z + pval;
                            Vector3 vert = new Vector3(verts[j].x, verts[j].y, verts[j].z);

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

                            //float len = Mathf.Sqrt(verts[j].x*verts[j].x + verts[j].z*verts[j].z);
                            float len = Mathf.Sqrt(vert.x * vert.x + vert.z * vert.z);

                            float new_x = vert.x;                            //+ pval;
                            //float new_y = verts[j].y  -  factor*len*len*verts[j].y/5;
                            //float new_y = vert.y  -  factor*len*len + pval;
                            float new_y = vert.y - factor * len * len;       // * vert.y/5;// + pval;

                            float new_z = vert.z;                            //+ pval;

                            //Debug.Log(pval + " :::: " +  verts[j].x + " :: " + verts[j].z + " + " + Mathf.PerlinNoise (verts[j].x, verts[j].z));
                            verts [j] = new Vector3(new_x, new_y, new_z);
                            verts [j] = P_Input.DependsOn.meshes[i].drawMeshMatrix.inverse.MultiplyPoint3x4(verts[j]);
                        }
                        m.vertices = verts;
                    }
                    ax_meshes.Add(amesh);
                }

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

                AXParameter p = parametricObject.getParameter("Amount");
                p.initiateRipple_setFloatValueFromGUIChange(5);

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

            return(null);
        }