Esempio n. 1
0
        void MakePlant(Vector2 basePosition, int joints, float baseAngle)
        {
            Particle root = new Particle(basePosition);

            particleIndices.Add(composite.elemNum);
            composite.AddSimElement(root);

            Particle      prev     = root;
            Particle      prev2    = root;
            Particle      current  = root;
            PinConstraint firstPin = null;
            float         angle    = baseAngle;

            for (var i = 0; i <= joints; ++i)
            {
                angle += angleRange.random * Mathf.Deg2Rad;
                if (i == joints)
                {
                    Particle leaf = new Particle(prev.pos + AngleToVector2(angle) * branchLengthRange.random);
                    particleIndices.Add(composite.elemNum);
                    composite.AddSimElement(leaf);

                    SpringConstraint leafSpring = new SpringConstraint(prev, leaf, springStiffness);
                    leafSpringIndices.Add(composite.elemNum);
                    composite.AddSimElement(leafSpring);

                    current = leaf;
                }
                else
                {
                    Particle joint = new Particle(prev.pos + AngleToVector2(angle) * branchLengthRange.random);
                    particleIndices.Add(composite.elemNum);
                    composite.AddSimElement(joint);

                    SpringConstraint spring = new SpringConstraint(prev, joint, springStiffness);
                    branchSpringIndices.Add(composite.elemNum);
                    composite.AddSimElement(spring);

                    current = joint;

                    if (i == 0)
                    {
                        firstPin = new PinConstraint(joint);
                    }
                }
                if (i > 0)
                {
                    AngleConstraint ac = new AngleConstraint(prev2, current, prev, angleStiffness);
                    composite.AddSimElement(ac);
                }
                prev2 = prev;
                prev  = current;
            }

            PinConstraint rootPin = new PinConstraint(root);

            composite.AddSimElement(rootPin);

            composite.AddSimElement(firstPin);
        }
Esempio n. 2
0
        /*
         * Angle related
         */

        public void MakeAngleMarker(AngleConstraint a)
        {
            Vector3 pos = a.m.pos;

            pos.z = angleMarkerDepth;

            var marker = (AngleConstraintMarker)MakeMarker(ANGLE_ID, a, pos);

            marker.SetAngle(a);
        }
Esempio n. 3
0
        void ICommand.Undo()
        {
            var current = _sim.uidDistributer.current;

            _a = _sim.MakeAngleByUID(_aUID, _bUID, _mUID, _stiffness);
            _a.OverrideUID(_uid);

            _sim.uidDistributer.SetCounter(current);

            _marker.MakeAngleMarker(_a);
        }
Esempio n. 4
0
    void EditRotateAxis(AngleConstraint constraint)
    {
        EditorGUI.BeginChangeCheck();
        _rotateAxisQ = Handles.RotationHandle(_rotateAxisQ, constraint.transform.position);

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(constraint, "Rotate Rotation Axis");
            constraint.rotateAxis = Quaternion.Inverse(constraint.transform.rotation) * _rotateAxisQ * _savedRotateAxis;
        }
    }
Esempio n. 5
0
        /*
         * Methods
         */

        public override SimElement MakeSimElement(AlignedEditableForm aef, List <SimElement> simElements)
        {
            var a = simElements[aef.uid2idxDic[_aUID]] as Particle;
            var b = simElements[aef.uid2idxDic[_bUID]] as Particle;
            var m = simElements[aef.uid2idxDic[_mUID]] as Particle;

            var ac = new AngleConstraint(a, b, m, _stiffness);

            ac.OverrideUID(uid);

            return(ac);
        }
Esempio n. 6
0
        public DeleteAngleCommand(Simulator sim, MarkerManager marker, int uid)
        {
            _sim    = sim;
            _marker = marker;
            _uid    = uid;

            _a         = _sim.GetAngleByUID(uid);
            _aUID      = _a.a.uid;
            _bUID      = _a.b.uid;
            _mUID      = _a.m.uid;
            _stiffness = _a.stiffness;
        }
        public void SetAngle(AngleConstraint angle)
        {
            var aAngle = angle.aAngle;
            var bAngle = angle.bAngle;
            var aLen   = (angle.a.pos - angle.m.pos).magnitude;
            var bLen   = (angle.b.pos - angle.m.pos).magnitude;

            _minAngle = Mathf.Min(aAngle, bAngle);
            _maxAngle = Mathf.Max(aAngle, bAngle);
            _radius   = Mathf.Max(minRadius, Mathf.Min(aLen, bLen) * 0.2f);

            SetMesh(_minAngle, _maxAngle, _radius, 10, activeColor);
        }
Esempio n. 8
0
        public void updateAngleByConstraints(string p1, int angle)
        {
            a        = (AngleConstraint)constraintList[p1];
            oEntity2 = a.EntityTwo;
            oEntity1 = a.EntityOne;
            String sVal = "" + angle + " deg";

            a.Delete();
            constraintList.Remove(p1);
            AngleConstraint d = assemblyComp.Constraints.AddAngleConstraint(oEntity1, oEntity2, sVal);

            d.Name = p1;
            constraintList.Add(p1, (AssemblyConstraint)d);
        }
Esempio n. 9
0
    void OnEnable()
    {
        AngleConstraint constraint = target as AngleConstraint;

        // Set up serialized properties.
        // Accessing properties through serialized properties rather through
        // target is because undo, multi-editing is handled automatically.
        _rotateAxisP = serializedObject.FindProperty("rotateAxis");
        _twistAxisP  = serializedObject.FindProperty("twistAxis");

        _rotateAxisQ     = constraint.transform.rotation;
        _twistAxisQ      = constraint.transform.rotation;
        _savedRotateAxis = constraint.rotateAxis;
        _savedTwistAxis  = constraint.twistAxis;
    }
Esempio n. 10
0
    void EditTwistAxis(AngleConstraint constraint)
    {
        EditorGUI.BeginChangeCheck();
        //_twistAxisQ = Handles.RotationHandle(_twistAxisQ, constraint.transform.position);

        // Let q2 = Handles.RotationHandle(q1);
        // q2 is not the delta rotation between q1 and q2. q2 is the modified
        // rotation of q1.
        _twistAxisQ = Handles.RotationHandle(_twistAxisQ, constraint.transform.position);

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(constraint, "Rotate Twist Axis");
            constraint.twistAxis = Quaternion.Inverse(constraint.transform.rotation) * _twistAxisQ * _savedTwistAxis;
        }
    }
Esempio n. 11
0
    void ShowAxis(AngleConstraint constraint)
    {
        // draw rotation axis
        Vector3 axis = constraint.transform.TransformDirection(
            constraint.rotateAxis);

        Handles.color = Color.red;
        Handles.DrawLine(constraint.transform.position - axis,
                         constraint.transform.position + axis);

        // draw twist axis
        axis = constraint.transform.TransformDirection(
            constraint.twistAxis);
        Handles.color = Color.yellow;
        Handles.DrawLine(constraint.transform.position,
                         constraint.transform.position + axis);
    }
Esempio n. 12
0
    protected override void OnMouseDown(Vector3 pos, ICADObject sko)
    {
        click = WorldPlanePos;
        if (constraint != null)
        {
            MoveTool.instance.EditConstraintValue(constraint);

            constraint = null;
            return;
        }
        var entity = sko as IEntity;

        if (entity == null)
        {
            return;
        }

        if (l0 == null && entity.type == IEntityType.Arc)
        {
            constraint     = new AngleConstraint(DetailEditor.instance.currentSketch.GetSketch(), entity);
            constraint.pos = WorldPlanePos;
        }

        if (entity.type != IEntityType.Line)
        {
            return;
        }
        if (l0 != null)
        {
            if (l0 is LineEntity && entity is LineEntity)
            {
                var pts = GetPoints(l0 as LineEntity, entity as LineEntity);
                constraint = new AngleConstraint(DetailEditor.instance.currentSketch.GetSketch(), pts);
            }
            else
            {
                constraint = new AngleConstraint(DetailEditor.instance.currentSketch.GetSketch(), l0, entity);
            }
            constraint.pos = WorldPlanePos;
            l0             = null;
        }
        else
        {
            l0 = entity;
        }
    }
Esempio n. 13
0
    public void OnSceneGUI()
    {
        AngleConstraint constraint = target as AngleConstraint;

        if (_showAxis)
        {
            ShowAxis(constraint);
        }

        // enable twist axis editing
        if (_editingTwistAxis)
        {
            EditTwistAxis(constraint);
        }

        // enable rotation axis editing
        if (_editingRotateAxis)
        {
            EditRotateAxis(constraint);
        }
    }
Esempio n. 14
0
    protected override void OnMouseDown(Vector3 pos, ICADObject sko)
    {
        click = WorldPlanePos;
        if (constraint != null)
        {
            MoveTool.instance.EditConstraintValue(constraint, pushUndo: false);
            constraint = null;
            return;
        }
        var entity = sko as IEntity;

        if (entity == null)
        {
            return;
        }

        if (l0 == null && entity.type == IEntityType.Arc)
        {
            editor.PushUndo();
            constraint     = new AngleConstraint(DetailEditor.instance.currentSketch.GetSketch(), entity);
            constraint.pos = WorldPlanePos;
        }

        if (entity.type != IEntityType.Line)
        {
            return;
        }
        if (l0 != null)
        {
            editor.PushUndo();
            constraint     = CreateConstraint(l0, entity);
            constraint.pos = WorldPlanePos;
            l0             = null;
        }
        else
        {
            l0 = entity;
        }
    }
Esempio n. 15
0
        bool ICommand.Do()
        {
            if (_uid == -1)
            {
                Debug.Log(_aUID + " -> " + _bUID + " + " + _mUID);
                _a   = _sim.MakeAngleByUID(_aUID, _bUID, _mUID, _stiffness);
                _uid = _a.uid;
            }
            else
            {
                var current = _sim.uidDistributer.current;

                _a = _sim.MakeAngleByUID(_aUID, _bUID, _mUID, _stiffness);
                _a.OverrideUID(_uid);

                _sim.uidDistributer.SetCounter(current);

                _marker.MakeAngleMarker(_a);
            }

            _marker.MakeAngleMarker(_a);
            return(true);
        }
Esempio n. 16
0
        Particle MakeBranch(Particle baseParticle, int depth, float branchLength, float angle, float angleStiffness)
        {
            Particle p = new Particle(baseParticle.pos + AngleToVector2(angle) * branchLength);

            if (depth > 0)
            {
                branchParticleIndices.Add(composite.elemNum);
            }
            composite.AddSimElement(p);

            SpringConstraint s = new SpringConstraint(baseParticle, p, springStiffness);

            if (depth > 0)
            {
                springIndices.Add(composite.elemNum);
            }
            else
            {
                leafSpringIndices.Add(composite.elemNum);
            }
            composite.AddSimElement(s);

            if (depth > 0)
            {
                Particle        lp  = MakeBranch(p, depth - 1, branchLength, angle + Mathf.PI * 0.1f, angleStiffness * angleSoftness);
                AngleConstraint lac = new AngleConstraint(baseParticle, lp, p, angleStiffness);
                composite.AddSimElement(lac);

                Particle        rp  = MakeBranch(p, depth - 1, branchLength, angle - Mathf.PI * 0.1f, angleStiffness * angleSoftness);
                AngleConstraint rac = new AngleConstraint(baseParticle, rp, p, angleStiffness);
                composite.AddSimElement(rac);

                AngleConstraint cac = new AngleConstraint(lp, rp, p, angleStiffness);
                composite.AddSimElement(cac);
            }
            return(p);
        }
Esempio n. 17
0
    public override void OnInspectorGUI()
    {
        AngleConstraint constraint = target as AngleConstraint;

        // toggle to show axis
        _showAxis = EditorGUILayout.Toggle("Show Axis", _showAxis);

        // Since ChildJoint is a property (actually a method) of AngleConstraint,
        // it cannot be serialized. So we have to access it through target.
        // The bad thing is we have to do all the undo dirty stuff on our own.
        EditorGUI.BeginChangeCheck();
        Transform t = EditorGUILayout.ObjectField("Child Joint",
                                                  constraint.ChildJoint, typeof(Transform), true) as Transform;

        if (EditorGUI.EndChangeCheck())
        {
            // since ChildJoint property cannot be serialized,
            // make sure its counterpart private field is serialized.
            // Otherwise Undo.RecordObject won't record anything.
            Undo.RecordObject(constraint, "Change Child Joint");
            constraint.ChildJoint = t;
        }

        // Use serialized properties to access other public fields of
        // AngleConstraint.

        // Update the serializedProperty - always do this in the beginning
        // of OnInspectorGUI.
        serializedObject.Update();

        // twist axis
        // If child joint is specified, then only display twist axis (read only).
        // Otherwise, let user edit twist axis.
        EditorGUILayout.BeginHorizontal();
        if (constraint.ChildJoint)
        {
            _editingTwistAxis = false;
            GUI.enabled       = false;
            EditorGUILayout.PropertyField(_twistAxisP, new GUIContent("Twist Axis"));
            _editingTwistAxis = GUILayout.Toggle(_editingTwistAxis, "Edit", "Button",
                                                 GUILayout.Width(50));
            GUI.enabled = true;
        }
        else
        {
            EditorGUILayout.PropertyField(_twistAxisP, new GUIContent("Twist Axis"));
            _editingTwistAxis = GUILayout.Toggle(_editingTwistAxis, "Edit", "Button",
                                                 GUILayout.Width(50));
        }
        EditorGUILayout.EndHorizontal();
        if (_editingTwistAxis)
        {
            _editingRotateAxis = false;
        }

        // rotate axis
        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.PropertyField(_rotateAxisP, new GUIContent("Rotate Axis"));
        _editingRotateAxis = GUILayout.Toggle(_editingRotateAxis, "Edit", "Button",
                                              GUILayout.Width(50));
        EditorGUILayout.EndHorizontal();
        if (_editingRotateAxis)
        {
            _editingTwistAxis = false;
        }

        // Apply changes to the serializedProperty - always do this in the end
        // of OnInspectorGUI.
        serializedObject.ApplyModifiedProperties();
    }
 public void OnEnable()
 {
     m_This = target as AngleConstraint;
 }
 public void OnEnable()
 {
     m_This = target as AngleConstraint;
 }
Esempio n. 20
0
 public void DeleteAngleMarker(AngleConstraint a)
 {
     DeleteMarker(ANGLE_ID, a);
 }
Esempio n. 21
0
 protected override void OnDeactivate()
 {
     l0         = null;
     constraint = null;
 }
 public void updateAngleByConstraints(string p1, int angle)
 {
     a = (AngleConstraint)constraintList[p1];
     oEntity2 = a.EntityTwo;
     oEntity1 = a.EntityOne;
     String sVal = "" + angle + " deg";
     a.Delete();
     constraintList.Remove(p1);
     AngleConstraint d = assemblyComp.Constraints.AddAngleConstraint(oEntity1, oEntity2, sVal);
     d.Name = p1;
     constraintList.Add(p1, (AssemblyConstraint)d);
 }