Esempio n. 1
0
        /// <summary>
        /// Create a spline job from this spline
        /// </summary>
        /// <param name="spline">spline to generate a job from</param>
        /// <param name="progress">progress to use when initializing job</param>
        /// <param name="allocator">allocator to use for result values</param>
        /// <returns>spline point retrieval job</returns>
        public static ISplineJob3D ExtractJob(this ISpline3D spline, SplineProgress progress = default, Allocator allocator = Allocator.None)
        {
            switch (spline.SplineDataType)
            {
            case SplineType.Empty:
                return(new Empty3DPointJob(spline, allocator));

            case SplineType.Single:
                return(new SinglePoint3DPointJob(spline, allocator));

            case SplineType.Bezier:
                return(new BezierSpline3DPointJob(spline, progress, allocator));

            case SplineType.CubicLinear:
                return(new LinearCubicSpline3DPointJob(spline, progress, allocator));

            case SplineType.Cubic:
            //todo
            case SplineType.BSpline:
            //todo
            case SplineType.CatmullRom:
            //todo
            case SplineType.Linear:     // falls over to the default by design
            default:
                return(new LinearSpline3DPointJob(spline, progress, allocator));
            }
        }
Esempio n. 2
0
        protected override int SplineSegmentPointCount(ISpline spline)
        {
            ISpline3D spline3D = (spline as ISpline3D);

            Assert.NotNull(spline3D, "Unable to convert spline");
            Assert.NotNull(spline3D.SplineEntityData3D, "spline failed to generate data");

            return(spline3D.SplineEntityData3D.Value.Points.Length);
        }
Esempio n. 3
0
        /// <summary>
        /// Renders points along the spline to demonstrate possible point bunching along the splines length
        /// </summary>
        /// <param name="quantity">amount of points to render</param>
        /// <param name="spline">spline to render on</param>
        protected static void RenderIntermediateSplinePoints(float quantity, ISpline3D spline)
        {
            Handles.color = Color.red;
            const float multiplier = 0.3f;

            // use the jobs as they support all the possible settings that a spline can have
            Dynamic3DJob job = new Dynamic3DJob(spline, 0f, Allocator.Temp);

            for (int i = 0; i <= quantity; i++)
            {
                float          progress          = i == 0 ? 0f : i / (quantity - 1f);
                SplineProgress jobSplineProgress = job.SplineProgress;
                jobSplineProgress.Progress = progress;
                job.SplineProgress         = jobSplineProgress;

                job.Execute();
                HandleDrawCross(job.Result, multiplier);
            }

            job.Dispose();
        }
Esempio n. 4
0
    // Start is called before the first frame update
    void Start()
    {
        const float progress = 0.3f;
        ISpline3D   spline3D = GetComponent <ISpline3D>();

        // calculate the point manually
        Dynamic3DJob dynamic2 = new Dynamic3DJob(spline3D, progress, Allocator.Temp);

        dynamic2.Execute();
        float3 manualResult = dynamic2.Result;

        dynamic2.Dispose();

        // calculate the point using dynamic job
        Dynamic3DJob dynamic = new Dynamic3DJob(spline3D, progress, Allocator.TempJob);
        JobHandle    handle  = dynamic.Schedule();

        handle.Complete();
        float3 dynamicJobResult = dynamic.Result;

        dynamic.Dispose();

        // calculate the point using specific job type
        BezierSpline3DPointJob direct = new BezierSpline3DPointJob(spline3D, progress, Allocator.TempJob);
        JobHandle handle2             = direct.Schedule(handle);

        handle2.Complete();
        float3 directJobResult = direct.Result;

        direct.Dispose();

        if (handle2.IsCompleted)
        {
            Assert.AreEqual(manualResult, directJobResult);
            Assert.AreEqual(manualResult, dynamicJobResult);
        }
    }
Esempio n. 5
0
        protected override IEnumerable <float3> PointData(ISpline spline)
        {
            ISpline3D spline3D = (spline as ISpline3D);

            return(spline3D.SplineEntityData3D.Value.Points);
        }
Esempio n. 6
0
 /// <summary>
 /// Create a spline job from this spline
 /// </summary>
 /// <param name="spline">spline to generate a job from</param>
 /// <param name="progress">progress to use when initializing job</param>
 /// <param name="allocator">allocator to use for result values</param>
 /// <returns>spline point retrieval job</returns>
 public static ISplineJob3D ExtractJob(this ISpline3D spline, float progress, Allocator allocator = Allocator.None)
 {
     return(ExtractJob(spline, new SplineProgress(progress), allocator));
 }