Skip to content

Commit

Permalink
v0.519
Browse files Browse the repository at this point in the history
  • Loading branch information
ozonexo3 committed May 14, 2018
1 parent 97c0a03 commit 2c2149b
Show file tree
Hide file tree
Showing 9 changed files with 295 additions and 77 deletions.
261 changes: 214 additions & 47 deletions Assets/MapEditor.unity

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void Awake()
protected float[] _NearCutOffLODValues;

public static float CameraNear;
public static float CameraFar;
public static float CameraFar = 1400;

private void OnEnable()
{
Expand Down
46 changes: 39 additions & 7 deletions Assets/Scripts/Ozone SCMAP Code/GetGamedataFile/GetGamedataFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
public partial struct GetGamedataFile
{
static bool DebugTextureLoad = false;
static bool IsDxt3 = false;

public static float MipmapBias = 0.0f;
public static int AnisoLevel = 6;
Expand All @@ -30,11 +29,16 @@ public static void CleanTextureMemory()

public static Texture2D LoadTexture2DFromGamedata(string scd, string LocalPath, bool NormalMap = false, bool StoreInMemory = true)
{
if (string.IsNullOrEmpty(LocalPath))
return Texture2D.whiteTexture;

string TextureKey = scd + "_" + LocalPath;

if (LoadedTextures.ContainsKey(TextureKey))
return LoadedTextures[TextureKey];

if (DebugTextureLoad)
Debug.Log(LocalPath);

byte[] FinalTextureData2 = LoadBytes(scd, LocalPath);

Expand All @@ -48,7 +52,6 @@ public static Texture2D LoadTexture2DFromGamedata(string scd, string LocalPath,
bool Mipmaps = LoadDDsHeader.mipmapcount > 0;
Texture2D texture = new Texture2D((int)LoadDDsHeader.width, (int)LoadDDsHeader.height, format, Mipmaps, false);


int DDS_HEADER_SIZE = 128;
byte[] dxtBytes = new byte[FinalTextureData2.Length - DDS_HEADER_SIZE];
Buffer.BlockCopy(FinalTextureData2, DDS_HEADER_SIZE, dxtBytes, 0, FinalTextureData2.Length - DDS_HEADER_SIZE);
Expand All @@ -70,8 +73,10 @@ public static Texture2D LoadTexture2DFromGamedata(string scd, string LocalPath,
}
}

if (NormalMap)
if (FlipBlueRed)
{
texture = CannelFlip(texture);

}

texture.mipMapBias = MipmapBias;
Expand All @@ -86,6 +91,24 @@ public static Texture2D LoadTexture2DFromGamedata(string scd, string LocalPath,
}


public static Texture2D CannelFlip(Texture2D Source)
{
int MipMapCount = Source.mipmapCount;
Texture2D ChannelFlip = new Texture2D(Source.width, Source.height, Source.format, Source.mipmapCount > 0, false);
for (int m = 0; m < MipMapCount; m++)
{
Color[] Pixels = Source.GetPixels(m);

for(int p = 0; p < Pixels.Length; p++)
{
Pixels[p] = new Color(Pixels[p].b, Pixels[p].g, Pixels[p].r);
}
ChannelFlip.SetPixels(Pixels, m);
}
ChannelFlip.Apply(false);
return ChannelFlip;
}

public static void LoadTextureFromGamedata(string scd, string LocalPath, int Id, bool NormalMap = false)
{
if (NormalMap)
Expand Down Expand Up @@ -170,7 +193,7 @@ static TextureFormat GetFormatOfDdsBytes(byte[] bytes)
BinaryReader Stream = new BinaryReader(ms);
LoadDDsHeader = BinaryStreamDdsHeader(Stream);

return ReadFourcc(LoadDDsHeader.pixelformatFourcc);
return ReadFourcc();
}

public static TextureFormat GetFormatOfDds(string FinalImagePath)
Expand All @@ -186,7 +209,7 @@ public static TextureFormat GetFormatOfDds(string FinalImagePath)
BinaryReader Stream = new BinaryReader(fs);
LoadDDsHeader = BinaryStreamDdsHeader(Stream);

return ReadFourcc(LoadDDsHeader.pixelformatFourcc);
return ReadFourcc();
}

public static HeaderClass GetDdsFormat(byte[] Bytes)
Expand Down Expand Up @@ -244,10 +267,12 @@ static HeaderClass BinaryStreamDdsHeader(BinaryReader Stream)
return DDsHeader;
}


static TextureFormat ReadFourcc(uint fourcc)
static bool IsDxt3 = false;
static bool FlipBlueRed = false;
static TextureFormat ReadFourcc()
{
IsDxt3 = false;
FlipBlueRed = false;
if (DebugTextureLoad) Debug.Log(
"Size: " + LoadDDsHeader.size +
" flags: " + LoadDDsHeader.flags +
Expand Down Expand Up @@ -286,6 +311,13 @@ static TextureFormat ReadFourcc(uint fourcc)
}
else if (LoadDDsHeader.pixelformatRgbBitCount == 24)
{
if (LoadDDsHeader.pixelformatRbitMask > LoadDDsHeader.pixelformatGbitMask && LoadDDsHeader.pixelformatGbitMask > LoadDDsHeader.pixelformatBbitMask) // BGR
{
FlipBlueRed = true;
Debug.Log("Flip blue and red channels");
return TextureFormat.RGB24;
}

return TextureFormat.RGB24;
}
else
Expand Down
27 changes: 15 additions & 12 deletions Assets/Scripts/Ozone SCMAP Code/MapLuaParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ public void SortArmys()

}

public Rect GetAreaRect()
public Rect GetAreaRect(bool Round = false)
{
if (SaveLuaFile.Data.areas.Length > 0 && !AreaInfo.HideArea)
{
Expand Down Expand Up @@ -578,6 +578,16 @@ public Rect GetAreaRect()
}
}

if (Round)
{
bigestAreaRect.x -= bigestAreaRect.x % 4;
bigestAreaRect.width -= bigestAreaRect.width % 4;

bigestAreaRect.y -= bigestAreaRect.y % 4;
bigestAreaRect.height -= bigestAreaRect.height % 4;

}

float LastY = bigestAreaRect.y;
bigestAreaRect.y = ScmapEditor.Current.map.Width - bigestAreaRect.height;
bigestAreaRect.height = ScmapEditor.Current.map.Width - LastY;
Expand All @@ -591,37 +601,30 @@ public Rect GetAreaRect()

}

public void UpdateArea()
public void UpdateArea(bool Round = true)
{
if (SaveLuaFile.Data.areas.Length > 0 && !AreaInfo.HideArea)
{
//int bigestAreaId = 0;
Rect bigestAreaRect = GetAreaRect();
Rect bigestAreaRect = GetAreaRect(Round);

if (bigestAreaRect.width > 0 && bigestAreaRect.height > 0)
{

// Set shaders
Shader.SetGlobalInt("_Area", 1);
Shader.SetGlobalVector("_AreaRect", new Vector4(bigestAreaRect.x / 10f, bigestAreaRect.y / 10f, bigestAreaRect.width / 10f, bigestAreaRect.height / 10f));

/*
HeightmapControler.TerrainMaterial.SetInt("_Area", 1);
HeightmapControler.TerrainMaterial.SetFloat("_AreaX", bigestAreaRect.x / 10f);
HeightmapControler.TerrainMaterial.SetFloat("_AreaY", bigestAreaRect.y / 10f);
HeightmapControler.TerrainMaterial.SetFloat("_AreaWidht", bigestAreaRect.width / 10f);
HeightmapControler.TerrainMaterial.SetFloat("_AreaHeight", bigestAreaRect.height / 10f);
*/
}
else
{
//HeightmapControler.TerrainMaterial.SetInt("_Area", 0);
Shader.SetGlobalInt("_Area", 0);
}

}
else
{
Shader.SetGlobalInt("_Area", 0);
//HeightmapControler.TerrainMaterial.SetInt("_Area", 0);
}
}
#endregion
Expand Down
8 changes: 8 additions & 0 deletions Assets/Scripts/Ozone SCMAP Code/MapLuaParser_App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ public IEnumerator RenderImageAndClose(bool Props, bool Decals, int Width, int H
CameraControler.Current.RenderCamera(Width, Height, ImagePath);
//ScmapEditor.Current.PreviewRenderer.RenderPreview()


if (Decals)
{
OzoneDecals.OzoneDecalRenderer.CutoffMultiplier = 1;


}

Debug.Log("Success! Preview rendered to: " + ImagePath);

OnFafEditorQuit.ForceQuit();
Expand Down
8 changes: 4 additions & 4 deletions Assets/Scripts/Ozone SCMAP Code/ScmapEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,6 @@ public void LoadStratumScdTextures(bool Loading = true)
{
// Load Stratum Textures Paths


for (int i = 0; i < Textures.Length; i++)
{
if (Loading)
Expand Down Expand Up @@ -303,6 +302,7 @@ public void LoadStratumScdTextures(bool Loading = true)

try
{

GetGamedataFile.LoadTextureFromGamedata(Env, Textures[i].AlbedoPath, i, false);
}
catch (System.Exception e)
Expand All @@ -325,6 +325,7 @@ public void LoadStratumScdTextures(bool Loading = true)
Debug.LogError(e);
}
}

}

#region Water
Expand Down Expand Up @@ -469,7 +470,6 @@ void GenerateArrays()
}
}


Texture2DArray AlbedoArray = new Texture2DArray(AlbedoSize, AlbedoSize, 8, TextureFormat.RGBA32, true);

for (int i = 0; i < 8; i++)
Expand Down Expand Up @@ -497,8 +497,8 @@ void GenerateArrays()

//AlbedoArray.mipMapBias = 0.5f;
AlbedoArray.filterMode = FilterMode.Bilinear;
AlbedoArray.anisoLevel = 2;
AlbedoArray.mipMapBias = 0.5f;
AlbedoArray.anisoLevel = 4;
AlbedoArray.mipMapBias = 0.0f;

AlbedoArray.Apply(false);
TerrainMaterial.SetTexture("_SplatAlbedoArray", AlbedoArray);
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/Tes/Texture2DInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public Texture2D ToTexture2D()
if(rawData != null)
{
texture.LoadRawTextureData(rawData);
texture.Apply(true);
texture.Apply(!hasMipmaps);
}

return texture;
Expand Down
16 changes: 12 additions & 4 deletions Assets/Scripts/UI/Tools/AreaInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class AreaInfo : MonoBehaviour {
public static AreaInfo Current;

public Toggle BorderRelative;
public Toggle Rounding;
public Toggle AreaHide;
public Toggle AreaDefault;
public GameObject AreaPrefab;
Expand Down Expand Up @@ -46,12 +47,19 @@ public void SwitchBorderRelative()
UpdateList();
}

public void SwitchPlayableAreaRounding()
{
//Rounding.isOn = !Rounding.isOn;

MapLuaParser.Current.UpdateArea(Rounding.isOn);
}

public void UpdateList()
{
Clean();
Generate();

MapLuaParser.Current.UpdateArea();
MapLuaParser.Current.UpdateArea(Rounding.isOn);
}

void Clean()
Expand Down Expand Up @@ -124,13 +132,13 @@ public void ToggleSelected()
{
SelectedArea = null;
}
MapLuaParser.Current.UpdateArea();
MapLuaParser.Current.UpdateArea(Rounding.isOn);
}

public void SelectArea(int InstanceID)
{
SelectedArea = MapLuaParser.Current.SaveLuaFile.Data.areas[InstanceID];
MapLuaParser.Current.UpdateArea();
MapLuaParser.Current.UpdateArea(Rounding.isOn);
}


Expand Down Expand Up @@ -165,7 +173,7 @@ public void OnValuesChange(int instanceID)

if (SelectedArea == MapLuaParser.Current.SaveLuaFile.Data.areas[instanceID])
{
MapLuaParser.Current.UpdateArea();
MapLuaParser.Current.UpdateArea(Rounding.isOn);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/UI/Tools/Markers/NewMarkersInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public void Place(Vector3[] Positions, Quaternion[] Rotations, Vector3[] Scales)
snapToWater = false;

if (SelectionManager.Current.SnapToGrid)
Positions[i] = ScmapEditor.SnapToGridCenter(Positions[i], true, SelectionManager.Current.SnapToWater);
Positions[i] = ScmapEditor.SnapToGridCenter(Positions[i], true, snapToWater);

//Positions[i].y = ScmapEditor.Current.Teren.SampleHeight(Positions[i]);

Expand Down

0 comments on commit 2c2149b

Please sign in to comment.