private static void BackupAlbedoMap(GStylizedTerrain t, string backupName) { Color32[] albedoColor = t.TerrainData.Shading.AlbedoMap.GetPixels32(); byte[] albedoR = new byte[albedoColor.Length]; byte[] albedoG = new byte[albedoColor.Length]; byte[] albedoB = new byte[albedoColor.Length]; byte[] albedoA = new byte[albedoColor.Length]; for (int i = 0; i < albedoColor.Length; ++i) { albedoR[i] = albedoColor[i].r; albedoG[i] = albedoColor[i].g; albedoB[i] = albedoColor[i].b; albedoA[i] = albedoColor[i].a; } albedoR = GCompressor.Compress(albedoR); albedoG = GCompressor.Compress(albedoG); albedoB = GCompressor.Compress(albedoB); albedoA = GCompressor.Compress(albedoA); GBackupFile.Create( backupName, string.Format("{0}_{1}", t.TerrainData.Id, GBackupFile.ALBEDO_R_SUFFIX), albedoR); GBackupFile.Create( backupName, string.Format("{0}_{1}", t.TerrainData.Id, GBackupFile.ALBEDO_G_SUFFIX), albedoG); GBackupFile.Create( backupName, string.Format("{0}_{1}", t.TerrainData.Id, GBackupFile.ALBEDO_B_SUFFIX), albedoB); GBackupFile.Create( backupName, string.Format("{0}_{1}", t.TerrainData.Id, GBackupFile.ALBEDO_A_SUFFIX), albedoA); }
private static void BackupSplatControlMaps(GStylizedTerrain t, string backupName) { int splatControlCount = t.TerrainData.Shading.SplatControlMapCount; for (int controlMapIndex = 0; controlMapIndex < splatControlCount; ++controlMapIndex) { Texture2D controlMap = t.TerrainData.Shading.GetSplatControl(controlMapIndex); Color32[] controlMapColor = controlMap.GetPixels32(); byte[] controlr = new byte[controlMapColor.Length]; byte[] controlg = new byte[controlMapColor.Length]; byte[] controlb = new byte[controlMapColor.Length]; byte[] controla = new byte[controlMapColor.Length]; for (int i = 0; i < controlMapColor.Length; ++i) { controlr[i] = controlMapColor[i].r; controlg[i] = controlMapColor[i].g; controlb[i] = controlMapColor[i].b; controla[i] = controlMapColor[i].a; } controlr = GCompressor.Compress(controlr); controlg = GCompressor.Compress(controlg); controlb = GCompressor.Compress(controlb); controla = GCompressor.Compress(controla); GBackupFile.Create( backupName, string.Format("{0}_{1}_{2}", t.TerrainData.Id, GBackupFile.CONTROL_R_SUFFIX, controlMapIndex), controlr); GBackupFile.Create( backupName, string.Format("{0}_{1}_{2}", t.TerrainData.Id, GBackupFile.CONTROL_G_SUFFIX, controlMapIndex), controlg); GBackupFile.Create( backupName, string.Format("{0}_{1}_{2}", t.TerrainData.Id, GBackupFile.CONTROL_B_SUFFIX, controlMapIndex), controlb); GBackupFile.Create( backupName, string.Format("{0}_{1}_{2}", t.TerrainData.Id, GBackupFile.CONTROL_A_SUFFIX, controlMapIndex), controla); } }
private static void BackupMetallicMap(GStylizedTerrain t, string backupName) { Color32[] metallicColor = t.TerrainData.Shading.MetallicMap.GetPixels32(); byte[] metallic = new byte[metallicColor.Length]; byte[] smoothness = new byte[metallicColor.Length]; for (int i = 0; i < metallicColor.Length; ++i) { metallic[i] = metallicColor[i].r; smoothness[i] = metallicColor[i].a; } metallic = GCompressor.Compress(metallic); smoothness = GCompressor.Compress(smoothness); GBackupFile.Create( backupName, string.Format("{0}_{1}", t.TerrainData.Id, GBackupFile.METALLIC_SUFFIX), metallic); GBackupFile.Create( backupName, string.Format("{0}_{1}", t.TerrainData.Id, GBackupFile.SMOOTHNESS_SUFFIX), smoothness); }
private static void BackupHeightMap(GStylizedTerrain t, string backupName) { Color32[] heightmapData = t.TerrainData.Geometry.HeightMap.GetPixels32(); byte[] dataR = new byte[heightmapData.Length]; byte[] dataG = new byte[heightmapData.Length]; byte[] dataB = new byte[heightmapData.Length]; byte[] dataA = new byte[heightmapData.Length]; for (int i = 0; i < heightmapData.Length; ++i) { dataR[i] = heightmapData[i].r; dataG[i] = heightmapData[i].g; dataB[i] = heightmapData[i].b; dataA[i] = heightmapData[i].a; } dataR = GCompressor.Compress(dataR); dataG = GCompressor.Compress(dataG); dataB = GCompressor.Compress(dataB); dataA = GCompressor.Compress(dataA); GBackupFile.Create( backupName, string.Format("{0}_{1}", t.TerrainData.Id, GBackupFile.HEIGHT_R_SUFFIX), dataR); GBackupFile.Create( backupName, string.Format("{0}_{1}", t.TerrainData.Id, GBackupFile.HEIGHT_G_SUFFIX), dataG); GBackupFile.Create( backupName, string.Format("{0}_{1}", t.TerrainData.Id, GBackupFile.HEIGHT_B_SUFFIX), dataB); GBackupFile.Create( backupName, string.Format("{0}_{1}", t.TerrainData.Id, GBackupFile.HEIGHT_A_SUFFIX), dataA); }
private static void BackupMaskMap(GStylizedTerrain t, string backupName) { Color32[] maskmapData = t.TerrainData.Mask.MaskMap.GetPixels32(); byte[] dataR = new byte[maskmapData.Length]; byte[] dataG = new byte[maskmapData.Length]; byte[] dataB = new byte[maskmapData.Length]; byte[] dataA = new byte[maskmapData.Length]; for (int i = 0; i < maskmapData.Length; ++i) { dataR[i] = maskmapData[i].r; dataG[i] = maskmapData[i].g; dataB[i] = maskmapData[i].b; dataA[i] = maskmapData[i].a; } dataR = GCompressor.Compress(dataR); dataG = GCompressor.Compress(dataG); dataB = GCompressor.Compress(dataB); dataA = GCompressor.Compress(dataA); GBackupFile.Create( backupName, string.Format("{0}_{1}", t.TerrainData.Id, GBackupFile.MASK_R_SUFFIX), dataR); GBackupFile.Create( backupName, string.Format("{0}_{1}", t.TerrainData.Id, GBackupFile.MASK_G_SUFFIX), dataG); GBackupFile.Create( backupName, string.Format("{0}_{1}", t.TerrainData.Id, GBackupFile.MASK_B_SUFFIX), dataB); GBackupFile.Create( backupName, string.Format("{0}_{1}", t.TerrainData.Id, GBackupFile.MASK_A_SUFFIX), dataA); }
private static void BackupGrassInstances(GStylizedTerrain t, string backupName) { if (t.TerrainData.Foliage.Grasses == null) { return; } List <GGrassInstance> grasses = new List <GGrassInstance>(); GGrassPatch[] patches = t.TerrainData.Foliage.GrassPatches; for (int i = 0; i < patches.Length; ++i) { grasses.AddRange(patches[i].Instances); } int[] protoIndices = new int[grasses.Count]; float[] positions = new float[grasses.Count * 3]; float[] rotations = new float[grasses.Count * 4]; float[] scales = new float[grasses.Count * 3]; for (int i = 0; i < grasses.Count; ++i) { GGrassInstance grass = grasses[i]; protoIndices[i] = grass.PrototypeIndex; positions[i * 3 + 0] = grass.Position.x; positions[i * 3 + 1] = grass.Position.y; positions[i * 3 + 2] = grass.Position.z; rotations[i * 4 + 0] = grass.Rotation.x; rotations[i * 4 + 1] = grass.Rotation.y; rotations[i * 4 + 2] = grass.Rotation.z; rotations[i * 4 + 3] = grass.Rotation.w; scales[i * 3 + 0] = grass.Scale.x; scales[i * 3 + 1] = grass.Scale.y; scales[i * 3 + 2] = grass.Scale.z; } byte[] protoIndicesData = new byte[Buffer.ByteLength(protoIndices)]; Buffer.BlockCopy(protoIndices, 0, protoIndicesData, 0, protoIndicesData.Length); protoIndicesData = GCompressor.Compress(protoIndicesData); byte[] positionsData = new byte[Buffer.ByteLength(positions)]; Buffer.BlockCopy(positions, 0, positionsData, 0, positionsData.Length); positionsData = GCompressor.Compress(positionsData); byte[] rotationsData = new byte[Buffer.ByteLength(rotations)]; Buffer.BlockCopy(rotations, 0, rotationsData, 0, rotationsData.Length); rotationsData = GCompressor.Compress(rotationsData); byte[] scalesData = new byte[Buffer.ByteLength(scales)]; Buffer.BlockCopy(scales, 0, scalesData, 0, scalesData.Length); scalesData = GCompressor.Compress(scalesData); GBackupFile.Create( backupName, string.Format("{0}_{1}_{2}", t.TerrainData.Id, GBackupFile.GRASS_SUFFIX, GBackupFile.PROTOTYPEINDEX_SUFFIX), protoIndicesData); GBackupFile.Create( backupName, string.Format("{0}_{1}_{2}", t.TerrainData.Id, GBackupFile.GRASS_SUFFIX, GBackupFile.POSITION_SUFFIX), positionsData); GBackupFile.Create( backupName, string.Format("{0}_{1}_{2}", t.TerrainData.Id, GBackupFile.GRASS_SUFFIX, GBackupFile.ROTATION_SUFFIX), rotationsData); GBackupFile.Create( backupName, string.Format("{0}_{1}_{2}", t.TerrainData.Id, GBackupFile.GRASS_SUFFIX, GBackupFile.SCALE_SUFFIX), scalesData); }