示例#1
0
        public Atlas GetAtlas(LoadedVoxelMaterial loadedVoxelMaterial)
        {
            var atlas = Atlases.FirstOrDefault(a => a.Material.Equals(loadedVoxelMaterial.Material) && loadedVoxelMaterial.TextureSize.Equals(a.TextureSize));

            if (atlas == null)
            {
                atlas = new Atlas(loadedVoxelMaterial.Material, loadedVoxelMaterial.TextureSize);
                Atlases.Add(atlas);
            }
            return(atlas);
        }
示例#2
0
        public void LoadVoxelMaterial(VoxelMaterial voxelMaterial)
        {
            if (VoxelMaterialIndex.ContainsKey(voxelMaterial.Name))
            {
                return;
            }
            var loadedVoxelMaterial = new LoadedVoxelMaterial(voxelMaterial);

            if (GetAtlas(loadedVoxelMaterial).AddVoxelMaterial(loadedVoxelMaterial))
            {
                loadedVoxelMaterial.Id = (ushort)VoxelMaterials.Count;
                VoxelMaterials.Add(loadedVoxelMaterial);
                VoxelMaterialIndex[voxelMaterial.Name] = loadedVoxelMaterial;
            }
        }
示例#3
0
        public void LoadVoxelMaterial(VoxelMaterial voxelMaterial)
        {
            if (VoxelMaterialIndex.ContainsKey(voxelMaterial.name.ToLower()))
            {
                return;
            }
            var loadedVoxelMaterial = new LoadedVoxelMaterial(voxelMaterial);

            if (!Atlases.ContainsKey(loadedVoxelMaterial.Material))
            {
                Atlases[loadedVoxelMaterial.Material] = new Atlas(loadedVoxelMaterial.Material);
            }
            if (Atlases[loadedVoxelMaterial.Material].AddVoxelMaterial(loadedVoxelMaterial))
            {
                loadedVoxelMaterial.Id = (ushort)VoxelMaterials.Count;
                VoxelMaterials.Add(loadedVoxelMaterial);
                VoxelMaterialIndex[voxelMaterial.name.ToLower()] = loadedVoxelMaterial;
            }
        }
示例#4
0
        public bool AddVoxelMaterial(LoadedVoxelMaterial loadedVoxelMaterial)
        {
            if (Colors.Contains(loadedVoxelMaterial.Color))
            {
                return(false);
            }
            loadedVoxelMaterial.AtlasPosition = Count++;

            var texture = (Texture2D)loadedVoxelMaterial.Material.mainTexture;

            if (texture == null)
            {
                texture = new Texture2D(MaterialCollectionSettings.AtlasSize * TextureSize.x, MaterialCollectionSettings.AtlasSize * TextureSize.y, TextureFormat.ARGB32, false);
            }
            SetPixels(texture, loadedVoxelMaterial);

            texture.wrapMode   = TextureWrapMode.Clamp;
            texture.filterMode = FilterMode.Point;
            texture.Apply();
            loadedVoxelMaterial.Material.mainTexture = texture;
            return(true);
        }
示例#5
0
 private void SetPixels(Texture2D texture, LoadedVoxelMaterial loadedVoxelMaterial)
 {
     texture.SetPixels((loadedVoxelMaterial.AtlasPosition / MaterialCollectionSettings.AtlasSize) * TextureSize.x, (loadedVoxelMaterial.AtlasPosition % MaterialCollectionSettings.AtlasSize) * TextureSize.y, TextureSize.x, TextureSize.y, loadedVoxelMaterial.Color);
     Colors.Add(loadedVoxelMaterial.Color);
 }