// Update is called once per frame
    void OnDrawGizmos()
    {
        // BezierCurve3
        curve = new THREE.CurvePath();

        // BezierCurve3
        if (curve != null)
        {
            Vector3 centerPosPre;
            Vector3 centerPosNext = Vector3.Lerp(points[1], points[2], 0.5f);

            THREE.QuadraticBezierCurve3 curveSegment = new THREE.QuadraticBezierCurve3(points[0], points[1], centerPosNext);
            curve.add(curveSegment);

            for (int i = 2; i < points.Count - 1; i++)
            {
                centerPosPre  = Vector3.Lerp(points[i - 1], points[i], 0.5f);
                centerPosNext = Vector3.Lerp(points[i], points[i + 1], 0.5f);
                THREE.QuadraticBezierCurve3 curveSegment1 = new THREE.QuadraticBezierCurve3(centerPosPre, points[i], centerPosNext);
                curve.add(curveSegment1);
            }
            //
            Gizmos.color = color;
            for (int i = 0; i < num; i++)
            {
                float   v = (float)i / num;
                Vector3 pt;
                if (useGetPointAt)
                {
                    pt = curve.getPointAt(v);
                }
                else
                {
                    pt = curve.getPoint(v);
                }
                Vector3 tangent = curve.getTangent(v);
                Gizmos.DrawRay(pt, tangent);
                Gizmos.DrawWireSphere(pt, 0.25f);
            }
        }

        // Spline3
        //		if (spline != null) {
        //			Gizmos.color = Color.green;
        //			for (int i = 0; i < num; i++) {
        //				float v = (float)i / num;
        //				Vector3 pt;
        //				if (useGetPointAt) {
        //					pt = spline.getPointAt(v);
        //				} else {
        //					pt = spline.getPoint(v);
        //				}
        //				Gizmos.DrawWireSphere(pt, 0.25f);
        //			}
        //		}
    }
Beispiel #2
0
    // Update is called once per frame
    void OnDrawGizmos()
    {
        // BezierCurve3
        curve = new THREE.CurvePath();

        // BezierCurve3
        if (curve != null) {

            Vector3 centerPosPre;
            Vector3 centerPosNext = Vector3.Lerp(points[1], points[2], 0.5f);

            THREE.QuadraticBezierCurve3 curveSegment = new THREE.QuadraticBezierCurve3(points[0], points[1], centerPosNext);
            curve.add(curveSegment);

            for (int i = 2; i < points.Count-1; i++) {
                centerPosPre = Vector3.Lerp(points[i - 1], points[i], 0.5f);
                centerPosNext = Vector3.Lerp(points[i], points[i + 1], 0.5f);
                THREE.QuadraticBezierCurve3 curveSegment1 = new THREE.QuadraticBezierCurve3(centerPosPre, points[i], centerPosNext);
                curve.add(curveSegment1);
            }
            //
            Gizmos.color = color;
            for (int i = 0; i < num; i++) {
                float v = (float)i / num;
                Vector3 pt;
                if (useGetPointAt) {
                    pt = curve.getPointAt(v);
                } else {
                    pt = curve.getPoint(v);
                }
                Vector3 tangent = curve.getTangent(v);
                Gizmos.DrawRay(pt, tangent);
                Gizmos.DrawWireSphere(pt, 0.25f);
            }
        }

        // Spline3
        //		if (spline != null) {
        //			Gizmos.color = Color.green;
        //			for (int i = 0; i < num; i++) {
        //				float v = (float)i / num;
        //				Vector3 pt;
        //				if (useGetPointAt) {
        //					pt = spline.getPointAt(v);
        //				} else {
        //					pt = spline.getPoint(v);
        //				}
        //				Gizmos.DrawWireSphere(pt, 0.25f);
        //			}
        //		}
    }
Beispiel #3
0
    // Use this for initialization
    void Start()
    {
        randomPoints = new List <Vector3>();
        for (int i = 0; i < 5; i++)
        {
            randomPoints.Add(new Vector3((i) * 10, Random.Range(-50.0f, 50.0f), Random.Range(-50.0f, 50.0f)));
            //randomPoints.Add(new Vector3(Random.Range(- 50.0f, 50.0f), Random.Range(- 50.0f, 50.0f), Random.Range(- 50.0f, 50.0f)) * 0.4f);
        }


        // BezierCurve3
        curve = new THREE.CurvePath();

//		Vector3 c = (randomPoints[1] - randomPoints[2]) * -1 + randomPoints[2];
//		for (int i = 2; i < randomPoints.Count-1; i++) {
//			c = (c - randomPoints[i]) * -1 + randomPoints[i];
//			THREE.QuadraticBezierCurve3 curveSegment1 = new THREE.QuadraticBezierCurve3(randomPoints[i], c, randomPoints[i + 1]);
//			curve.add(curveSegment1);
//		}
        Vector3 centerPosPre;
        Vector3 centerPosNext = Vector3.Lerp(randomPoints[1], randomPoints[2], 0.5f);

        THREE.QuadraticBezierCurve3 curveSegment = new THREE.QuadraticBezierCurve3(randomPoints[0], randomPoints[1], centerPosNext);
        curve.add(curveSegment);

        for (int i = 2; i < randomPoints.Count - 1; i++)
        {
            centerPosPre  = Vector3.Lerp(randomPoints[i - 1], randomPoints[i], 0.5f);
            centerPosNext = Vector3.Lerp(randomPoints[i], randomPoints[i + 1], 0.5f);
            THREE.QuadraticBezierCurve3 curveSegment1 = new THREE.QuadraticBezierCurve3(centerPosPre, randomPoints[i], centerPosNext);
            curve.add(curveSegment1);
        }

        // Spline3
        spline = new THREE.SplineCurve3(randomPoints);

        // ShapePath
        PointList pointList = new PointList();

        shapePath = pointList.GetShapePath(randomPoints.ToArray());
    }