コード例 #1
0
ファイル: NavMeshStoreSystem.cs プロジェクト: taotao111/ainav
        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);
            }
        }
コード例 #2
0
ファイル: AiNavTests.cs プロジェクト: taotao111/ainav
        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));
コード例 #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);
        }
コード例 #4
0
ファイル: MeshSource.cs プロジェクト: taotao111/ainav
        public static MeshSource CreateShared(float4x4 localToWorld, BlobAssetReference <MeshSourceData> sharedData, int layer, byte area, byte flag, int sharedMeshId, int customData = 0)
        {
            MeshSourceInfo info = new MeshSourceInfo {
                Layer = layer, Area = area, Flag = flag, CustomData = customData
            };

            info.Bounds       = MeshSourceData.CalculateBounds(localToWorld, sharedData);
            info.TRS          = localToWorld;
            info.SharedMeshId = sharedMeshId;

            return(new MeshSource {
                Info = info
            });
        }
コード例 #5
0
ファイル: MeshSource.cs プロジェクト: taotao111/ainav
        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);
        }
コード例 #6
0
            public void Execute()
            {
                NativeList <MeshSource> sources = MeshSourceMap.GetSources(TileBounds.Coord);

                for (int i = 0; i < sources.Length; i++)
                {
                    MeshSource source = sources[i];

                    if (!IncludeMask.HasLayer(source.Info.Layer))
                    {
                        continue;
                    }

                    NativeArray <int>    indices;
                    NativeArray <float3> vertices;

                    if (source.Info.Shared)
                    {
                        if (!SharedMeshSources.TryGetValue(source.Info.SharedMeshId, out BlobAssetReference <MeshSourceData> data))
                        {
                            continue;
                        }

                        MeshSourceData.GetData(data, out indices, out vertices);
                        MeshSourceData.TransformInPlace(source.Info.TRS, vertices);
                        InputBuilder.Append(vertices, indices, source.Info.Area);
                    }
                    else
                    {
                        MeshSourceData.GetData(source.Value, out indices, out vertices);
                        InputBuilder.Append(vertices, indices, source.Info.Area);
                    }

                    vertices.Dispose();
                    indices.Dispose();
                }
            }
コード例 #7
0
        public void AddPrimitives()
        {
            SharedMesh sm = new SharedMesh {
                Id = (int)PrimitiveType.Capsule + 1, Mesh = MeshSourceData.CreateMesh(PrimitiveType.Capsule), Name = PrimitiveType.Capsule.ToString()
            };

            Meshes.Add(sm);
            sm = new SharedMesh {
                Id = (int)PrimitiveType.Cube + 1, Mesh = MeshSourceData.CreateMesh(PrimitiveType.Cube), Name = PrimitiveType.Cube.ToString()
            };
            Meshes.Add(sm);
            sm = new SharedMesh {
                Id = (int)PrimitiveType.Cylinder + 1, Mesh = MeshSourceData.CreateMesh(PrimitiveType.Cylinder), Name = PrimitiveType.Cylinder.ToString()
            };
            Meshes.Add(sm);
            sm = new SharedMesh {
                Id = (int)PrimitiveType.Sphere + 1, Mesh = MeshSourceData.CreateMesh(PrimitiveType.Sphere), Name = PrimitiveType.Sphere.ToString()
            };
            Meshes.Add(sm);

#if UNITY_EDITOR
            UnityEditor.EditorUtility.SetDirty(this);
#endif
        }