Ejemplo n.º 1
0
        public void FilteredCopyJob_Should_CopySlicesOfInputThatCorrespondToSpecifiedIndices(
            Point[] inputPoints, LatticeInfo[] inputLattices, int size, Point[] expectedOutputPoints, LatticeInfo[] expectedOutputLattices)
        {
            NativeArray <Point>       points         = new NativeArray <Point>(inputPoints, Allocator.TempJob);
            NativeArray <LatticeInfo> lattices       = new NativeArray <LatticeInfo>(inputLattices, Allocator.TempJob);
            NativeArray <Point>       ouputPoints    = new NativeArray <Point>(points.Length * 4, Allocator.TempJob);
            NativeArray <LatticeInfo> outputLattices = new NativeArray <LatticeInfo>(lattices.Length * 4, Allocator.TempJob);

            LatticeJob latticeJob = new LatticeJob()
            {
                points            = points,
                lattices          = lattices,
                outputPoints      = ouputPoints,
                outputLattices    = outputLattices,
                size              = size,
                nextIsHydrophobic = false
            };

            JobHandle jobHandle = latticeJob.Schedule(lattices.Length, 1);

            jobHandle.Complete();

            Assert.That(ouputPoints.ToArray(), Is.EqualTo(expectedOutputPoints));
            Assert.That(outputLattices.ToArray(), Is.EqualTo(expectedOutputLattices));

            points.Dispose();
            lattices.Dispose();
            ouputPoints.Dispose();
            outputLattices.Dispose();
        }
Ejemplo n.º 2
0
        public void GenerateControlPoints(Vector3Int newResolution, float3[] resampleOriginalPoints, Vector3Int resampleOriginalResolution)
        {
            resolution = newResolution;

            controlPoints = new float3[resolution.x * resolution.y * resolution.z];
            for (int z = 0; z < resolution.z; z++)
            {
                for (int y = 0; y < resolution.y; y++)
                {
                    for (int x = 0; x < resolution.x; x++)
                    {
                        int index = GetIndex(x, y, z);

                        controlPoints[index] = new float3(x / (float)(newResolution.x - 1) - 0.5f,
                                                          y / (float)(newResolution.y - 1) - 0.5f, z / (float)(newResolution.z - 1) - 0.5f);
                    }
                }
            }

            if (resampleOriginalPoints != null)
            {
                var nativeArray = new NativeArray <float3>(controlPoints, Allocator.TempJob);
                var latticeJob  = new LatticeJob
                {
                    controlPoints = new NativeArray <float3>(resampleOriginalPoints, Allocator.TempJob),
                    resolution    = new int3(resampleOriginalResolution.x, resampleOriginalResolution.y, resampleOriginalResolution.z),
                    meshToTarget  = float4x4.identity,
                    targetToMesh  = float4x4.identity,
                    vertices      = nativeArray
                };
                latticeJob.Run(controlPoints.Length);
                resolution = newResolution;

                nativeArray.CopyTo(controlPoints);
                nativeArray.Dispose();
            }
        }