Exemplo n.º 1
0
        public unsafe NativeArray <BlobAssetReference <MeshSourceData> > LoadSources(int surfaceId)
        {
            string path;

            if (surfaceId == -1)
            {
                path = GetGlobalPath(typeof(MeshSourceData).Name);
            }
            else
            {
                path = GetPath(surfaceId, typeof(MeshSourceData).Name, null);
            }

            using (StreamBinaryReader reader = new StreamBinaryReader(path))
            {
                int sourceCount = reader.ReadInt();
                NativeArray <BlobAssetReference <MeshSourceData> > sources = new NativeArray <BlobAssetReference <MeshSourceData> >(sourceCount, Allocator.Temp);

                for (int i = 0; i < sourceCount; i++)
                {
                    int sizeInBytes           = reader.ReadInt();
                    NativeArray <int> indices = new NativeArray <int>(sizeInBytes, Allocator.Temp);
                    reader.ReadBytes(indices.GetUnsafePtr(), sizeInBytes);

                    sizeInBytes = reader.ReadInt();
                    NativeArray <float3> vertices = new NativeArray <float3>(sizeInBytes, Allocator.Temp);
                    reader.ReadBytes(vertices.GetUnsafePtr(), sizeInBytes);

                    sources[i] = MeshSourceData.Create(indices, vertices);
                    indices.Dispose();
                    vertices.Dispose();
                }
                return(sources);
            }
        }
Exemplo n.º 2
0
        public unsafe void TestSourceMap()
        {
            GameObject gameObject = GameObject.CreatePrimitive(PrimitiveType.Cube);
            Mesh       mesh       = gameObject.GetComponent <MeshFilter>().sharedMesh;

            Object.DestroyImmediate(gameObject);

            var sharedData = MeshSourceData.Create(mesh);

            MeshSourceMap map          = new MeshSourceMap(NavMeshBuildSettings.Default());
            float4x4      localToWorld = float4x4.TRS(default, default, new float3(40f, 40f, 40f));
Exemplo n.º 3
0
        public void Save()
        {
            NativeArray <BlobAssetReference <MeshSourceData> > blobs = new NativeArray <BlobAssetReference <MeshSourceData> >(Meshes.Count, Allocator.Temp);

            for (int i = 0; i < Meshes.Count; i++)
            {
                SharedMesh sharedMesh = Meshes[i];
                var        blob       = MeshSourceData.Create(sharedMesh.Mesh);
                blobs[i] = blob;
            }
            NavMeshStoreSystem.Instance.SaveSources(blobs, -1);
        }
Exemplo n.º 4
0
        public static MeshSource Create(float4x4 localToWorld, Mesh mesh, int layer, byte area, byte flag, int customData = 0)
        {
            MeshSource     source = new MeshSource();
            MeshSourceInfo info   = new MeshSourceInfo {
                Layer = layer, Area = area, Flag = flag, CustomData = customData
            };

            source.Value = MeshSourceData.Create(mesh, localToWorld);
            info.Bounds  = MeshSourceData.CalculateBounds(source.Value);

            source.Info = info;

            return(source);
        }