Exemple #1
0
        public void CollectUsingComputeShader()
        {
            float maxSlopeCos = Mathf.Cos((float)((double)template.maxSlope * Math.PI / 180.0));
            int   vSizeX      = template.lengthX_extra;
            int   vSizeZ      = template.lengthZ_extra;

            Vector3 realChunkPos = template.realOffsetedPosition;
            float   chunkPosX    = realChunkPos.x;
            float   chunkPosZ    = realChunkPos.z;

            foreach (var terrain in terrainsInfo)
            {
                //int hSizeX = terrain.hSizeX;
                //int hSizeZ = terrain.hSizeZ;
                //int resolution = terrain.resolution;
                //float[,] heightMap = terrain.heightMap;
                //Matrix4x4 heightMatrix = terrain.heightMatrix;

                Vector3[] verts;
                int[]     tris;
                base.GetTerrainMesh(terrain, out verts, out tris);

                //Volume terrainVolume;
                //if (terrain.alphaMap != null)
                //    terrainVolume = new Volume(template.lengthX_extra, template.lengthZ_extra, terrain.possibleArea);
                //else
                //    terrainVolume = new Volume(template.lengthX_extra, template.lengthZ_extra, defaultArea);

                //terrainVolume.terrain = true;


                CSRasterization2DResult   resultTerrain = PathFinder.scene.Rasterize2D(verts, tris, vSizeX, vSizeZ, chunkPosX, chunkPosZ, template.voxelSize, maxSlopeCos);
                CSRasterization3DResult[] resultTrees   = null;

                List <Bounds> treeData = terrain.treeData;

                if (treeData != null && treeData.Count > 0)
                {
                    resultTrees = new CSRasterization3DResult[treeData.Count];

                    for (int i = 0; i < treeData.Count; i++)
                    {
                        Bounds    bound = treeData[i];
                        Matrix4x4 m     = Matrix4x4.TRS(bound.center, Quaternion.identity, new Vector3(bound.size.x, bound.size.y * 0.5f, bound.size.z));
                        resultTrees[i] = PathFinder.scene.Rasterize3D(fancyVerts, fancyTris, bound, m, vSizeX, vSizeZ, chunkPosX, chunkPosZ, template.voxelSize, maxSlopeCos);
                    }
                }
                _collectedTerrainUsingComputeShader.Add(new TerrainInfoCSR(terrain, resultTerrain, resultTrees));
            }
        }
        //for terrain with single area
        public void AppendComputeShaderResult(CSRasterization2DResult data, byte area)
        {
            var voxels = data.voxels;

            for (int x = 0; x < sizeX; x++)
            {
                for (int z = 0; z < sizeZ; z++)
                {
                    var curVoxel = voxels[x + (z * sizeX)];
                    if (curVoxel.passability != -1)
                    {
                        SetVoxel(x, z, curVoxel.height - 20f, curVoxel.height, (sbyte)curVoxel.passability, area);
                    }
                }
            }
        }
Exemple #3
0
 public TerrainInfoCSR(TerrainColliderInfoMesh colliderInfo, CSRasterization2DResult voxelsTerrain, CSRasterization3DResult[] voxelsTrees)
 {
     this.colliderInfo  = colliderInfo;
     this.voxelsTerrain = voxelsTerrain;
     this.voxelsTrees   = voxelsTrees;
 }