public void OnEnable()
 {
     spline           = (ObiCatmullRomCurve)target;
     hideSplineHandle = false;
     selectedStatus   = new bool[spline.controlPoints.Count];
     handleVectors    = new Vector3[spline.controlPoints.Count];
 }
        private static void GizmoTest(ObiCatmullRomCurve spline, GizmoType gizmoType)
        {
            Matrix4x4 prevMatrix = Handles.matrix;
            Color     oldColor   = Handles.color;

            // Draw the curve:
            int curveSegments = spline.GetNumSpans() * curvePreviewResolution;

            Vector3[] samples = new Vector3[curveSegments + 1];
            for (int i = 0; i <= curveSegments; ++i)
            {
                samples[i] = spline.GetPositionAt(i / (float)curveSegments);
            }

            Handles.matrix = spline.transform.localToWorldMatrix;
            Handles.color  = Color.white;
            Handles.zTest  = UnityEngine.Rendering.CompareFunction.LessEqual;
            Handles.DrawPolyLine(samples);

            Handles.color = new Color(1, 1, 1, 0.25f);
            Handles.zTest = UnityEngine.Rendering.CompareFunction.Greater;
            Handles.DrawPolyLine(samples);

            Handles.color  = oldColor;
            Handles.matrix = prevMatrix;
        }
Exemplo n.º 3
0
        void Start()
        {
            // Get all needed components and interconnect them:
            rope          = GetComponent <ObiRope>();
            path          = GetComponent <ObiCatmullRomCurve>();
            rope.Solver   = solver;
            rope.ropePath = path;
            rope.Section  = section;
            GetComponent <MeshRenderer>().material = material;

            // Calculate rope start/end and direction in local space:
            Vector3 localStart = transform.InverseTransformPoint(start.position);
            Vector3 localEnd   = transform.InverseTransformPoint(end.position);
            Vector3 direction  = (localEnd - localStart).normalized;

            // Generate rope path:
            path.controlPoints.Clear();
            path.controlPoints.Add(localStart - direction);
            path.controlPoints.Add(localStart);
            path.controlPoints.Add(localEnd);
            path.controlPoints.Add(localEnd + direction);

            // Setup the simulation:
            StartCoroutine(Setup());
        }
Exemplo n.º 4
0
        static void CreateObiRope()
        {
            GameObject c = new GameObject("Obi Rope");

            Undo.RegisterCreatedObjectUndo(c, "Create Obi Rope");
            ObiRope            rope   = c.AddComponent <ObiRope>();
            ObiCatmullRomCurve path   = c.AddComponent <ObiCatmullRomCurve>();
            ObiSolver          solver = c.AddComponent <ObiSolver>();

            rope.Solver   = solver;
            rope.section  = Resources.Load <ObiRopeSection>("DefaultRopeSection");
            rope.ropePath = path;
        }