예제 #1
0
        public AXHandle clone()
        {
            AXHandle h = new AXHandle();

            h.Name = Name;
            h.Type = Type;

            h.pos_x = pos_x;
            h.pos_y = pos_y;
            h.pos_z = pos_z;

            h.radius  = radius;
            h.tangent = tangent;

            h.angle = angle;
            h.len   = len;

            h.expressions = new List <string>(expressions);

            return(h);
        }
예제 #2
0
        public static AXHandle fromJSON(AX.SimpleJSON.JSONNode jn)
        {
            AXHandle h = new AXHandle();

            h.Name = jn["name"].Value;

            h.Type = (AXHandle.HandleType)jn["type"].AsInt;

            h.pos_x   = jn["pos_x"].Value;
            h.pos_y   = jn["pos_y"].Value;
            h.pos_z   = jn["pos_z"].Value;
            h.radius  = jn["radius"].Value;
            h.tangent = jn["tangent"].Value;

            h.angle = jn["angle"].Value;
            h.len   = jn["len"].Value;

            if (jn["expressions"] != null)
            {
                h.expressions = AXJson.StringListFromJSON(jn["expressions"]);
            }

            return(h);
        }
        // Update is called once per frame
        void Update()
        {
            if (!Application.isPlaying)
            {
                return;
            }


            bool byPlane = true;


            if (handle == null)
            {
                return;
            }

            AXParametricObject parametricObject = handle.parametricObject;



            // GET POSITION

            if (parametricObject.is2D())
            {
                context = parametricObject.model.transform.localToWorldMatrix * parametricObject.worldDisplayMatrix;

                if (parametricObject.generator.hasOutputsConnected() || parametricObject.is2D())
                {
                    context *= parametricObject.generator.localMatrix.inverse;
                }
                else
                {
                    context *= parametricObject.getAxisRotationMatrix().inverse *parametricObject.generator.localMatrix.inverse *parametricObject.getAxisRotationMatrix();
                }
            }
            else
            {
                // GROUPER MATRIX NOT WORKING....
                context = parametricObject.model.transform.localToWorldMatrix * parametricObject.generator.parametricObject.worldDisplayMatrix * (parametricObject.getAxisRotationMatrix() * parametricObject.generator.getLocalAlignMatrix()).inverse * parametricObject.generator.localMatrix.inverse;
            }


            // position handle by parmeters.
            positionHandleGameObject();



            double h_diff = 0;
            double v_diff = 0;


            if (mouseIsDown)
            {
                if (Input.touchCount == 1)
                {
                    // touch input - works better with deltaPosition
                    var touch = Input.GetTouch(0);
                    //var dx = touch.deltaPosition.x;
                    h_diff = (100.0 / Screen.width) * touch.deltaPosition.x;
                    v_diff = (100.0 / Screen.width) * touch.deltaPosition.y;
                }
                else
                {
                    // 0 touches: must be mouse input
                    h_diff = (5000 / Screen.width) * Input.GetAxis("Mouse X");
                    v_diff = (5000 / Screen.width) * Input.GetAxis("Mouse Y");
                }
                h_diff /= 5;
                v_diff /= 5;
                //Debug.Log(h_diff +", " + v_diff);



                //using plane
                if (byPlane)
                {
                    establishDrawingSurface();
                    //Vector3 prevPosition = transform.position;
                }



                // BASED ON PLANE
                Vector3 world_pos = transform.position;

                if (byPlane)
                {
                    Vector3 hit_position3D = sampleHitPoint();
                    world_pos          = hit_position3D - mouseDownDiff;
                    transform.position = world_pos;
                }



                Vector3 localPosition = context.inverse.MultiplyPoint3x4(world_pos);



                //transform.position = world_pos;

                //if (transform.position != prevPosition)
                if (h_diff != 0 || v_diff != 0)
                {
                    //Debug.Log("moved");



                    // Determine the orientation of the camera


                    //The normal OperatingSystemFamily the handle plane
                    //Debug.Log (lookV);

                    float threshold = .707f;

                    double diffX = -v_diff;
                    double diffZ = h_diff;

                    // This logic works with a normal vector

                    if (!byPlane)
                    {
                        if (lookV.x > 0 && lookV.z < 0)
                        {
                            diffX = (1 - lookV.x) * h_diff - lookV.x * v_diff;
                            diffZ = (1 + lookV.z) * h_diff - lookV.z * v_diff;
                        }
                        else if (lookV.x > 0 && lookV.z > 0)
                        {
                            diffX = -((lookV.x)) * h_diff - lookV.x * v_diff;
                            diffZ = (1 + lookV.z) * h_diff - lookV.z * v_diff;
                        }
                        else if (lookV.x < 0 && lookV.z > 0)
                        {
                            diffX = (1 + lookV.x) * h_diff + lookV.x * v_diff;
                            diffZ = (1 - lookV.z) * h_diff + lookV.z * v_diff;
                        }
                        else if (lookV.x > 0 && lookV.z > 0)
                        {
                            diffX = -((lookV.x)) * h_diff - (lookV.x) * v_diff;
                            diffZ = (1 + lookV.z) * h_diff - lookV.z * v_diff;    //(-lookV.x + lookV.z) * v_diff;
                        }
                        else if (lookV.z > threshold)                             // pointing forwards
                        {
                            diffX = -h_diff;
                            diffZ = -v_diff;
                        }
                        else if (lookV.z < -threshold)
                        {
                            // pointing backwards
                            diffX = h_diff;
                            diffZ = v_diff;
                        }
                        else if (lookV.x > 0)
                        {
                            // pointing right
                            diffX = -h_diff;
                            diffZ = v_diff;
                        }
                        else
                        {
                            // pointing left
                            diffX = v_diff;
                            diffZ = -h_diff;
                        }
                    }



                    AXHandle han = handle;


                    string hanString = "han_y";
                    float  posV      = localPosition.y;

                    if (parametricObject.is3D())
                    {
                        hanString = "han_z";
                        posV      = localPosition.z;
                    }

                    if (byPlane)
                    {
                        parametricObject.setVar("han_x", (localPosition.x));
                        if (parametricObject.is3D())
                        {
                            parametricObject.setVar("han_z", world_pos.z);
                        }
                        else
                        {
                            parametricObject.setVar("han_y", localPosition.y);
                        }
                    }
                    else
                    {
                        // Relative slide of cursor
                        parametricObject.setVar("han_x", (localPosition.x + (float)diffX));
                        parametricObject.setVar(hanString, (posV + (float)diffZ));
                    }

                    // From plane
//					parametricObject.setVar("han_x", localPosition.x);
//					parametricObject.setVar("han_y", localPosition.y);
//					parametricObject.setVar("han_z", localPosition.z);


                    // EACH EXPRESSION
                    for (int i = 0; i < han.expressions.Count; i++)
                    {
                        if (han.expressions [i] == "")
                        {
                            continue;
                        }

                        string expression = Regex.Replace(han.expressions [i], @"\s+", "");

                        string paramName  = expression.Substring(0, expression.IndexOf("="));
                        string definition = expression.Substring(expression.IndexOf("=") + 1);
                        //Debug.Log (param + " --- " + definition);

                        try {
                            if (parametricObject.getParameter(paramName).Type == AXParameter.DataType.Int)
                            {
                                parametricObject.initiateRipple_setIntValueFromGUIChange(paramName, Mathf.RoundToInt((float)parametricObject.parseMath(definition)));
                            }
                            else
                            {
                                parametricObject.initiateRipple_setFloatValueFromGUIChange(paramName, (float)parametricObject.parseMath(definition));
                            }
                        } catch (System.Exception e) {
                            parametricObject.codeWarning = "10. Handle error: Please check syntax of: \"" + definition + "\" " + e.Message;
                        }
                    }

                    parametricObject.model.isAltered();
                    //parametricObject.model.autobuild();
                }
            }
        }
예제 #4
0
        public static AXParametricObject ParametricObjectFromJSON(AX.SimpleJSON.JSONNode jn)
        {
            AXParametricObject po = new AXParametricObject(jn["type"], jn["name"]);


            po.Guid = jn["guid"].Value;

            po.basedOnAssetWithGUID = jn["basedOnAssetWithGUID"].Value;

            po.description      = jn["description"].Value;
            po.author           = jn["author"].Value;
            po.tags             = jn["tags"].Value;
            po.documentationURL = jn["documentationURL"].Value;

            if (jn["includeInSidebarMenu"] != null)
            {
                po.includeInSidebarMenu = jn["includeInSidebarMenu"].AsBool;
            }
            else
            {
                po.includeInSidebarMenu = true;
            }

            po.isInitialized = jn["isInitialized"].AsBool;


            po.grouperKey = jn["grouperKey"].Value;

            if (jn["sortval"] != null)
            {
                po.sortval = jn["sortval"].AsFloat;
            }

            po.curve = AXJson.CurveFromJSON(jn["curve"]);

            po.rect        = AXJson.RectFromJSON(jn["rect"]);
            po.bounds      = AXJson.BoundsFromJSON(jn["bounds"]);
            po.transMatrix = AXJson.Matrix4x4FromJSON(jn["transMatrix"]);

            po.combineMeshes = jn["combineMeshes"].AsBool;
            po.isRigidbody   = jn["isRigidbody"].AsBool;
            po.colliderType  = (AXGeometryTools.ColliderType)jn["colliderType"].AsInt;

            po.axStaticEditorFlags = (AXStaticEditorFlags)jn["axStaticEditorFlags"].AsInt;

            //Debug.Log(po.Name + " " + po.grouperKey);

            // material
            // look to see if there is a material matching this name....
                        #if UNITY_EDITOR
            if (jn["material_assetGUID"] != null)
            {
                string path = AssetDatabase.GUIDToAssetPath(jn["material_assetGUID"].Value);

                //Debug.Log("AssetDatabase.GUIDToAssetPath("+jn["material_assetGUID"].Value+") has path: "  + path);


                // REDO
                if (path != null)
                {
                    //Debug.Log(jn["Name"] + ": path="+path);
                    Material matter = (Material)AssetDatabase.LoadAssetAtPath(path, typeof(Material));

                    //Debug.Log("..."+matter);
                    //po.axMat.mat = (Material) AssetDatabase.LoadAssetAtPath(path, typeof(Material)) ;
                    if (po.axMat == null)
                    {
                        po.axMat = new AXMaterial();
                    }
                    po.axMat.mat = matter;
                }
            }
                        #endif



            // code
            if (jn["code"] != null)
            {
                po.code = jn["code"].Value.Replace(";", "\n");
            }
            // parameters

            if (jn["parameters"] != null)
            {
                po.parameters = new List <AXParameter>();

                foreach (AX.SimpleJSON.JSONNode jn_p in jn["parameters"].AsArray)
                {
                    po.addParameter(AXParameter.fromJSON(jn_p));
                }
            }
            // shapes
            if (jn["shapes"] != null)
            {
                po.shapes = new List <AXShape>();
                foreach (AX.SimpleJSON.JSONNode jn_p in jn["shapes"].AsArray)
                {
                    po.shapes.Add(AXShape.fromJSON(po, jn_p));
                }
            }



            // handles
            if (jn["handles"] != null)
            {
                po.handles = new List <AXHandle>();
                foreach (AX.SimpleJSON.JSONNode jn_h in jn["handles"].AsArray)
                {
                    po.handles.Add(AXHandle.fromJSON(jn_h));
                }
            }

            // cameraSettings
            if (jn["cameraSettings"] != null)
            {
                po.cameraSettings = JSONSerializersAX.AXCameraFromJSON(jn["cameraSettings"]);
                po.cameraSettings.setPosition();
            }


            // make the generator for this po
            po.instantiateGenerator();

            return(po);
        }