diff --git a/.idea/.idea.Materialize/.idea/contentModel.xml b/.idea/.idea.Materialize/.idea/contentModel.xml new file mode 100644 index 00000000..8ce1d54d --- /dev/null +++ b/.idea/.idea.Materialize/.idea/contentModel.xml @@ -0,0 +1,172 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/.idea.Materialize/.idea/dictionaries/maikeu.xml b/.idea/.idea.Materialize/.idea/dictionaries/maikeu.xml new file mode 100644 index 00000000..faeec120 --- /dev/null +++ b/.idea/.idea.Materialize/.idea/dictionaries/maikeu.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/.idea.Materialize/.idea/encodings.xml b/.idea/.idea.Materialize/.idea/encodings.xml new file mode 100644 index 00000000..15a15b21 --- /dev/null +++ b/.idea/.idea.Materialize/.idea/encodings.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/.idea.Materialize/.idea/indexLayout.xml b/.idea/.idea.Materialize/.idea/indexLayout.xml new file mode 100644 index 00000000..27ba142e --- /dev/null +++ b/.idea/.idea.Materialize/.idea/indexLayout.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/.idea.Materialize/.idea/misc.xml b/.idea/.idea.Materialize/.idea/misc.xml new file mode 100644 index 00000000..1d8c84d0 --- /dev/null +++ b/.idea/.idea.Materialize/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/.idea.Materialize/.idea/modules.xml b/.idea/.idea.Materialize/.idea/modules.xml new file mode 100644 index 00000000..c54070a4 --- /dev/null +++ b/.idea/.idea.Materialize/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/.idea.Materialize/.idea/vcs.xml b/.idea/.idea.Materialize/.idea/vcs.xml new file mode 100644 index 00000000..94a25f7f --- /dev/null +++ b/.idea/.idea.Materialize/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/.idea.Materialize/.idea/workspace.xml b/.idea/.idea.Materialize/.idea/workspace.xml new file mode 100644 index 00000000..f78fc236 --- /dev/null +++ b/.idea/.idea.Materialize/.idea/workspace.xml @@ -0,0 +1,1723 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + format + original + temp + saveall + png + save pro + bmp + fil + CameraOffsetPos + alpha + CIH + CommandListExecutorScript + _jpgSelected + PostProcessGuiObject + clipboard + testObject + show full + show + materialgui + sample + MainGuiScript + suges + MGS + texture + key + windows.forms + _mainGui + smoothness + start + prev + + + MainGui.Instance + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + + true + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1541032378210 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/.idea.Materialize/riderModule.iml b/.idea/.idea.Materialize/riderModule.iml new file mode 100644 index 00000000..c63f8321 --- /dev/null +++ b/.idea/.idea.Materialize/riderModule.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.jpg.jpg b/.jpg.jpg new file mode 100644 index 00000000..2991395a Binary files /dev/null and b/.jpg.jpg differ diff --git a/.mtz b/.mtz new file mode 100644 index 00000000..20072d0d --- /dev/null +++ b/.mtz @@ -0,0 +1,91 @@ + + + + 0.0 + 0.0 + + 0 + 0 + 0 + 1 + + + 0 + 0 + + + 0 + 0 + 0 + 1 + + + 0 + 0 + + 0.3 + + null + + 0 + + null + null + + null + + + 0 + 0 + 0 + 1 + + + 0 + 0 + + + null + + + 0 + 0 + 0 + 1 + + + 0 + 0 + + + 0 + 0 + 0 + 1 + + + 0 + 0 + + + 0 + 0 + 0 + 1 + + + 0 + 0 + + + null + + null + + 50 + 0 + 0.0 + + null + + \ No newline at end of file diff --git a/Assembly-CSharp.csproj.DotSettings b/Assembly-CSharp.csproj.DotSettings new file mode 100644 index 00000000..9eaa43cb --- /dev/null +++ b/Assembly-CSharp.csproj.DotSettings @@ -0,0 +1,2 @@ + + True \ No newline at end of file diff --git a/Assets/FileBrowser/DefaultIcons/addToFavorites.psd b/Assets/FileBrowser/DefaultIcons/addToFavorites.psd deleted file mode 100644 index e584b7cc..00000000 Binary files a/Assets/FileBrowser/DefaultIcons/addToFavorites.psd and /dev/null differ diff --git a/Assets/FileBrowser/DefaultIcons/addToFavorites.psd.meta b/Assets/FileBrowser/DefaultIcons/addToFavorites.psd.meta deleted file mode 100644 index bfb07ee2..00000000 --- a/Assets/FileBrowser/DefaultIcons/addToFavorites.psd.meta +++ /dev/null @@ -1,57 +0,0 @@ -fileFormatVersion: 2 -guid: 899b6c62f8495cb49b5cdf4af01b0c90 -timeCreated: 1461803142 -licenseType: Pro -TextureImporter: - fileIDToRecycleName: {} - serializedVersion: 2 - mipmaps: - mipMapMode: 0 - enableMipMap: 0 - linearTexture: 1 - correctGamma: 0 - fadeOut: 0 - borderMipMap: 0 - mipMapFadeDistanceStart: 1 - mipMapFadeDistanceEnd: 3 - bumpmap: - convertToNormalMap: 0 - externalNormalMap: 0 - heightScale: 0.25 - normalMapFilter: 0 - isReadable: 0 - grayScaleToAlpha: 0 - generateCubemap: 0 - cubemapConvolution: 0 - cubemapConvolutionSteps: 4 - cubemapConvolutionExponent: 1.5 - seamlessCubemap: 0 - textureFormat: -1 - maxTextureSize: 2048 - textureSettings: - filterMode: -1 - aniso: 1 - mipBias: -1 - wrapMode: 1 - nPOTScale: 0 - lightmap: 0 - rGBM: 0 - compressionQuality: 50 - allowsAlphaSplitting: 0 - spriteMode: 0 - spriteExtrude: 1 - spriteMeshType: 1 - alignment: 0 - spritePivot: {x: 0.5, y: 0.5} - spriteBorder: {x: 0, y: 0, z: 0, w: 0} - spritePixelsToUnits: 100 - alphaIsTransparency: 1 - textureType: 2 - buildTargetSettings: [] - spriteSheet: - sprites: [] - outline: [] - spritePackingTag: - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/FileBrowser/DefaultIcons/fileIcon.psd b/Assets/FileBrowser/DefaultIcons/fileIcon.psd deleted file mode 100644 index 422d6ec9..00000000 Binary files a/Assets/FileBrowser/DefaultIcons/fileIcon.psd and /dev/null differ diff --git a/Assets/FileBrowser/DefaultIcons/fileIcon.psd.meta b/Assets/FileBrowser/DefaultIcons/fileIcon.psd.meta deleted file mode 100644 index b18d618f..00000000 --- a/Assets/FileBrowser/DefaultIcons/fileIcon.psd.meta +++ /dev/null @@ -1,55 +0,0 @@ -fileFormatVersion: 2 -guid: 39a095224be0beb409f5b61cd02f4579 -TextureImporter: - fileIDToRecycleName: {} - serializedVersion: 2 - mipmaps: - mipMapMode: 0 - enableMipMap: 0 - linearTexture: 1 - correctGamma: 0 - fadeOut: 0 - borderMipMap: 0 - mipMapFadeDistanceStart: 1 - mipMapFadeDistanceEnd: 3 - bumpmap: - convertToNormalMap: 0 - externalNormalMap: 0 - heightScale: 0.25 - normalMapFilter: 0 - isReadable: 0 - grayScaleToAlpha: 0 - generateCubemap: 0 - cubemapConvolution: 0 - cubemapConvolutionSteps: 4 - cubemapConvolutionExponent: 1.5 - seamlessCubemap: 0 - textureFormat: -1 - maxTextureSize: 1024 - textureSettings: - filterMode: -1 - aniso: 1 - mipBias: -1 - wrapMode: 1 - nPOTScale: 0 - lightmap: 0 - rGBM: 0 - compressionQuality: 50 - allowsAlphaSplitting: 0 - spriteMode: 0 - spriteExtrude: 1 - spriteMeshType: 1 - alignment: 0 - spritePivot: {x: 0.5, y: 0.5} - spriteBorder: {x: 0, y: 0, z: 0, w: 0} - spritePixelsToUnits: 100 - alphaIsTransparency: 1 - textureType: 2 - buildTargetSettings: [] - spriteSheet: - sprites: [] - outline: [] - spritePackingTag: - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/FileBrowser/DefaultIcons/folderIcon.psd b/Assets/FileBrowser/DefaultIcons/folderIcon.psd deleted file mode 100644 index b8eaccbb..00000000 Binary files a/Assets/FileBrowser/DefaultIcons/folderIcon.psd and /dev/null differ diff --git a/Assets/FileBrowser/DefaultIcons/folderIcon.psd.meta b/Assets/FileBrowser/DefaultIcons/folderIcon.psd.meta deleted file mode 100644 index ef98a30a..00000000 --- a/Assets/FileBrowser/DefaultIcons/folderIcon.psd.meta +++ /dev/null @@ -1,55 +0,0 @@ -fileFormatVersion: 2 -guid: c8135945c98cc94429ae7806d04b5b8b -TextureImporter: - fileIDToRecycleName: {} - serializedVersion: 2 - mipmaps: - mipMapMode: 0 - enableMipMap: 0 - linearTexture: 1 - correctGamma: 0 - fadeOut: 0 - borderMipMap: 0 - mipMapFadeDistanceStart: 1 - mipMapFadeDistanceEnd: 3 - bumpmap: - convertToNormalMap: 0 - externalNormalMap: 0 - heightScale: 0.25 - normalMapFilter: 0 - isReadable: 0 - grayScaleToAlpha: 0 - generateCubemap: 0 - cubemapConvolution: 0 - cubemapConvolutionSteps: 4 - cubemapConvolutionExponent: 1.5 - seamlessCubemap: 0 - textureFormat: -1 - maxTextureSize: 1024 - textureSettings: - filterMode: -1 - aniso: 1 - mipBias: -1 - wrapMode: 1 - nPOTScale: 0 - lightmap: 0 - rGBM: 0 - compressionQuality: 50 - allowsAlphaSplitting: 0 - spriteMode: 0 - spriteExtrude: 1 - spriteMeshType: 1 - alignment: 0 - spritePivot: {x: 0.5, y: 0.5} - spriteBorder: {x: 0, y: 0, z: 0, w: 0} - spritePixelsToUnits: 100 - alphaIsTransparency: 1 - textureType: 2 - buildTargetSettings: [] - spriteSheet: - sprites: [] - outline: [] - spritePackingTag: - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/FileBrowser/DefaultIcons/listItemHover.psd b/Assets/FileBrowser/DefaultIcons/listItemHover.psd deleted file mode 100644 index 6b1049ba..00000000 Binary files a/Assets/FileBrowser/DefaultIcons/listItemHover.psd and /dev/null differ diff --git a/Assets/FileBrowser/DefaultIcons/listItemHover.psd.meta b/Assets/FileBrowser/DefaultIcons/listItemHover.psd.meta deleted file mode 100644 index 6ad8395b..00000000 --- a/Assets/FileBrowser/DefaultIcons/listItemHover.psd.meta +++ /dev/null @@ -1,55 +0,0 @@ -fileFormatVersion: 2 -guid: 4325cb797ef078b49bb0efb0fb870da8 -TextureImporter: - fileIDToRecycleName: {} - serializedVersion: 2 - mipmaps: - mipMapMode: 0 - enableMipMap: 0 - linearTexture: 1 - correctGamma: 0 - fadeOut: 0 - borderMipMap: 0 - mipMapFadeDistanceStart: 1 - mipMapFadeDistanceEnd: 3 - bumpmap: - convertToNormalMap: 0 - externalNormalMap: 0 - heightScale: 0.25 - normalMapFilter: 0 - isReadable: 0 - grayScaleToAlpha: 0 - generateCubemap: 0 - cubemapConvolution: 0 - cubemapConvolutionSteps: 4 - cubemapConvolutionExponent: 1.5 - seamlessCubemap: 0 - textureFormat: -1 - maxTextureSize: 1024 - textureSettings: - filterMode: -1 - aniso: 1 - mipBias: -1 - wrapMode: 1 - nPOTScale: 0 - lightmap: 0 - rGBM: 0 - compressionQuality: 50 - allowsAlphaSplitting: 0 - spriteMode: 0 - spriteExtrude: 1 - spriteMeshType: 1 - alignment: 0 - spritePivot: {x: 0.5, y: 0.5} - spriteBorder: {x: 0, y: 0, z: 0, w: 0} - spritePixelsToUnits: 100 - alphaIsTransparency: 1 - textureType: 2 - buildTargetSettings: [] - spriteSheet: - sprites: [] - outline: [] - spritePackingTag: - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/FileBrowser/DefaultIcons/listItemSelected.psd b/Assets/FileBrowser/DefaultIcons/listItemSelected.psd deleted file mode 100644 index 4aa3a111..00000000 Binary files a/Assets/FileBrowser/DefaultIcons/listItemSelected.psd and /dev/null differ diff --git a/Assets/FileBrowser/DefaultIcons/listItemSelected.psd.meta b/Assets/FileBrowser/DefaultIcons/listItemSelected.psd.meta deleted file mode 100644 index 5cacf8e3..00000000 --- a/Assets/FileBrowser/DefaultIcons/listItemSelected.psd.meta +++ /dev/null @@ -1,55 +0,0 @@ -fileFormatVersion: 2 -guid: d92388cf1d1be28458d673a546ed4a61 -TextureImporter: - fileIDToRecycleName: {} - serializedVersion: 2 - mipmaps: - mipMapMode: 0 - enableMipMap: 0 - linearTexture: 1 - correctGamma: 0 - fadeOut: 0 - borderMipMap: 0 - mipMapFadeDistanceStart: 1 - mipMapFadeDistanceEnd: 3 - bumpmap: - convertToNormalMap: 0 - externalNormalMap: 0 - heightScale: 0.25 - normalMapFilter: 0 - isReadable: 0 - grayScaleToAlpha: 0 - generateCubemap: 0 - cubemapConvolution: 0 - cubemapConvolutionSteps: 4 - cubemapConvolutionExponent: 1.5 - seamlessCubemap: 0 - textureFormat: -1 - maxTextureSize: 1024 - textureSettings: - filterMode: -1 - aniso: 1 - mipBias: -1 - wrapMode: 1 - nPOTScale: 0 - lightmap: 0 - rGBM: 0 - compressionQuality: 50 - allowsAlphaSplitting: 0 - spriteMode: 0 - spriteExtrude: 1 - spriteMeshType: 1 - alignment: 0 - spritePivot: {x: 0.5, y: 0.5} - spriteBorder: {x: 0, y: 0, z: 0, w: 0} - spritePixelsToUnits: 100 - alphaIsTransparency: 1 - textureType: 2 - buildTargetSettings: [] - spriteSheet: - sprites: [] - outline: [] - spritePackingTag: - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/FileBrowser/DefaultIcons/placesDesktop.psd b/Assets/FileBrowser/DefaultIcons/placesDesktop.psd deleted file mode 100644 index 32553399..00000000 Binary files a/Assets/FileBrowser/DefaultIcons/placesDesktop.psd and /dev/null differ diff --git a/Assets/FileBrowser/DefaultIcons/placesDesktop.psd.meta b/Assets/FileBrowser/DefaultIcons/placesDesktop.psd.meta deleted file mode 100644 index 197c7a92..00000000 --- a/Assets/FileBrowser/DefaultIcons/placesDesktop.psd.meta +++ /dev/null @@ -1,55 +0,0 @@ -fileFormatVersion: 2 -guid: e09026654626d284eb4b90ad872d8b6a -TextureImporter: - fileIDToRecycleName: {} - serializedVersion: 2 - mipmaps: - mipMapMode: 0 - enableMipMap: 0 - linearTexture: 1 - correctGamma: 0 - fadeOut: 0 - borderMipMap: 0 - mipMapFadeDistanceStart: 1 - mipMapFadeDistanceEnd: 3 - bumpmap: - convertToNormalMap: 0 - externalNormalMap: 0 - heightScale: 0.25 - normalMapFilter: 0 - isReadable: 0 - grayScaleToAlpha: 0 - generateCubemap: 0 - cubemapConvolution: 0 - cubemapConvolutionSteps: 4 - cubemapConvolutionExponent: 1.5 - seamlessCubemap: 0 - textureFormat: -1 - maxTextureSize: 1024 - textureSettings: - filterMode: -1 - aniso: 1 - mipBias: -1 - wrapMode: 1 - nPOTScale: 0 - lightmap: 0 - rGBM: 0 - compressionQuality: 50 - allowsAlphaSplitting: 0 - spriteMode: 0 - spriteExtrude: 1 - spriteMeshType: 1 - alignment: 0 - spritePivot: {x: 0.5, y: 0.5} - spriteBorder: {x: 0, y: 0, z: 0, w: 0} - spritePixelsToUnits: 100 - alphaIsTransparency: 1 - textureType: 2 - buildTargetSettings: [] - spriteSheet: - sprites: [] - outline: [] - spritePackingTag: - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/FileBrowser/DefaultIcons/placesFavorites.psd b/Assets/FileBrowser/DefaultIcons/placesFavorites.psd deleted file mode 100644 index 3c2c0821..00000000 Binary files a/Assets/FileBrowser/DefaultIcons/placesFavorites.psd and /dev/null differ diff --git a/Assets/FileBrowser/DefaultIcons/placesFavorites.psd.meta b/Assets/FileBrowser/DefaultIcons/placesFavorites.psd.meta deleted file mode 100644 index aa7bebaa..00000000 --- a/Assets/FileBrowser/DefaultIcons/placesFavorites.psd.meta +++ /dev/null @@ -1,57 +0,0 @@ -fileFormatVersion: 2 -guid: 7965ffbc350699b4183ece4d8e870c1f -timeCreated: 1461803142 -licenseType: Pro -TextureImporter: - fileIDToRecycleName: {} - serializedVersion: 2 - mipmaps: - mipMapMode: 0 - enableMipMap: 0 - linearTexture: 1 - correctGamma: 0 - fadeOut: 0 - borderMipMap: 0 - mipMapFadeDistanceStart: 1 - mipMapFadeDistanceEnd: 3 - bumpmap: - convertToNormalMap: 0 - externalNormalMap: 0 - heightScale: 0.25 - normalMapFilter: 0 - isReadable: 0 - grayScaleToAlpha: 0 - generateCubemap: 0 - cubemapConvolution: 0 - cubemapConvolutionSteps: 4 - cubemapConvolutionExponent: 1.5 - seamlessCubemap: 0 - textureFormat: -1 - maxTextureSize: 2048 - textureSettings: - filterMode: -1 - aniso: 1 - mipBias: -1 - wrapMode: 1 - nPOTScale: 0 - lightmap: 0 - rGBM: 0 - compressionQuality: 50 - allowsAlphaSplitting: 0 - spriteMode: 0 - spriteExtrude: 1 - spriteMeshType: 1 - alignment: 0 - spritePivot: {x: 0.5, y: 0.5} - spriteBorder: {x: 0, y: 0, z: 0, w: 0} - spritePixelsToUnits: 100 - alphaIsTransparency: 1 - textureType: 2 - buildTargetSettings: [] - spriteSheet: - sprites: [] - outline: [] - spritePackingTag: - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/FileBrowser/DefaultIcons/placesHD.psd b/Assets/FileBrowser/DefaultIcons/placesHD.psd deleted file mode 100644 index 91a1b6bc..00000000 Binary files a/Assets/FileBrowser/DefaultIcons/placesHD.psd and /dev/null differ diff --git a/Assets/FileBrowser/DefaultIcons/placesHD.psd.meta b/Assets/FileBrowser/DefaultIcons/placesHD.psd.meta deleted file mode 100644 index 74986206..00000000 --- a/Assets/FileBrowser/DefaultIcons/placesHD.psd.meta +++ /dev/null @@ -1,55 +0,0 @@ -fileFormatVersion: 2 -guid: 6576d7fa26628104986879a9195197b4 -TextureImporter: - fileIDToRecycleName: {} - serializedVersion: 2 - mipmaps: - mipMapMode: 0 - enableMipMap: 0 - linearTexture: 1 - correctGamma: 0 - fadeOut: 0 - borderMipMap: 0 - mipMapFadeDistanceStart: 1 - mipMapFadeDistanceEnd: 3 - bumpmap: - convertToNormalMap: 0 - externalNormalMap: 0 - heightScale: 0.25 - normalMapFilter: 0 - isReadable: 0 - grayScaleToAlpha: 0 - generateCubemap: 0 - cubemapConvolution: 0 - cubemapConvolutionSteps: 4 - cubemapConvolutionExponent: 1.5 - seamlessCubemap: 0 - textureFormat: -1 - maxTextureSize: 1024 - textureSettings: - filterMode: -1 - aniso: 1 - mipBias: -1 - wrapMode: 1 - nPOTScale: 0 - lightmap: 0 - rGBM: 0 - compressionQuality: 50 - allowsAlphaSplitting: 0 - spriteMode: 0 - spriteExtrude: 1 - spriteMeshType: 1 - alignment: 0 - spritePivot: {x: 0.5, y: 0.5} - spriteBorder: {x: 0, y: 0, z: 0, w: 0} - spritePixelsToUnits: 100 - alphaIsTransparency: 1 - textureType: 2 - buildTargetSettings: [] - spriteSheet: - sprites: [] - outline: [] - spritePackingTag: - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/FileBrowser/DefaultIcons/placesMyDocs.psd b/Assets/FileBrowser/DefaultIcons/placesMyDocs.psd deleted file mode 100644 index 0a2ff5bd..00000000 Binary files a/Assets/FileBrowser/DefaultIcons/placesMyDocs.psd and /dev/null differ diff --git a/Assets/FileBrowser/DefaultIcons/placesMyDocs.psd.meta b/Assets/FileBrowser/DefaultIcons/placesMyDocs.psd.meta deleted file mode 100644 index 4139a465..00000000 --- a/Assets/FileBrowser/DefaultIcons/placesMyDocs.psd.meta +++ /dev/null @@ -1,55 +0,0 @@ -fileFormatVersion: 2 -guid: a0bfbc70c5b63284b84f5df326d3668a -TextureImporter: - fileIDToRecycleName: {} - serializedVersion: 2 - mipmaps: - mipMapMode: 0 - enableMipMap: 0 - linearTexture: 1 - correctGamma: 0 - fadeOut: 0 - borderMipMap: 0 - mipMapFadeDistanceStart: 1 - mipMapFadeDistanceEnd: 3 - bumpmap: - convertToNormalMap: 0 - externalNormalMap: 0 - heightScale: 0.25 - normalMapFilter: 0 - isReadable: 0 - grayScaleToAlpha: 0 - generateCubemap: 0 - cubemapConvolution: 0 - cubemapConvolutionSteps: 4 - cubemapConvolutionExponent: 1.5 - seamlessCubemap: 0 - textureFormat: -1 - maxTextureSize: 1024 - textureSettings: - filterMode: -1 - aniso: 1 - mipBias: -1 - wrapMode: 1 - nPOTScale: 0 - lightmap: 0 - rGBM: 0 - compressionQuality: 50 - allowsAlphaSplitting: 0 - spriteMode: 0 - spriteExtrude: 1 - spriteMeshType: 1 - alignment: 0 - spritePivot: {x: 0.5, y: 0.5} - spriteBorder: {x: 0, y: 0, z: 0, w: 0} - spritePixelsToUnits: 100 - alphaIsTransparency: 1 - textureType: 2 - buildTargetSettings: [] - spriteSheet: - sprites: [] - outline: [] - spritePackingTag: - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/FileBrowser/DefaultIcons/placesMyPics.psd b/Assets/FileBrowser/DefaultIcons/placesMyPics.psd deleted file mode 100644 index d5fe79fe..00000000 Binary files a/Assets/FileBrowser/DefaultIcons/placesMyPics.psd and /dev/null differ diff --git a/Assets/FileBrowser/DefaultIcons/placesMyPics.psd.meta b/Assets/FileBrowser/DefaultIcons/placesMyPics.psd.meta deleted file mode 100644 index 43f37190..00000000 --- a/Assets/FileBrowser/DefaultIcons/placesMyPics.psd.meta +++ /dev/null @@ -1,55 +0,0 @@ -fileFormatVersion: 2 -guid: fcd61eae31be0844fb0164aaa667af8b -TextureImporter: - fileIDToRecycleName: {} - serializedVersion: 2 - mipmaps: - mipMapMode: 0 - enableMipMap: 0 - linearTexture: 1 - correctGamma: 0 - fadeOut: 0 - borderMipMap: 0 - mipMapFadeDistanceStart: 1 - mipMapFadeDistanceEnd: 3 - bumpmap: - convertToNormalMap: 0 - externalNormalMap: 0 - heightScale: 0.25 - normalMapFilter: 0 - isReadable: 0 - grayScaleToAlpha: 0 - generateCubemap: 0 - cubemapConvolution: 0 - cubemapConvolutionSteps: 4 - cubemapConvolutionExponent: 1.5 - seamlessCubemap: 0 - textureFormat: -1 - maxTextureSize: 1024 - textureSettings: - filterMode: -1 - aniso: 1 - mipBias: -1 - wrapMode: 1 - nPOTScale: 0 - lightmap: 0 - rGBM: 0 - compressionQuality: 50 - allowsAlphaSplitting: 0 - spriteMode: 0 - spriteExtrude: 1 - spriteMeshType: 1 - alignment: 0 - spritePivot: {x: 0.5, y: 0.5} - spriteBorder: {x: 0, y: 0, z: 0, w: 0} - spritePixelsToUnits: 100 - alphaIsTransparency: 1 - textureType: 2 - buildTargetSettings: [] - spriteSheet: - sprites: [] - outline: [] - spritePackingTag: - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/FileBrowser/DefaultIcons/resizeHandle.psd b/Assets/FileBrowser/DefaultIcons/resizeHandle.psd deleted file mode 100644 index e81d0ee9..00000000 Binary files a/Assets/FileBrowser/DefaultIcons/resizeHandle.psd and /dev/null differ diff --git a/Assets/FileBrowser/DefaultIcons/resizeHandle.psd.meta b/Assets/FileBrowser/DefaultIcons/resizeHandle.psd.meta deleted file mode 100644 index a1008e3d..00000000 --- a/Assets/FileBrowser/DefaultIcons/resizeHandle.psd.meta +++ /dev/null @@ -1,57 +0,0 @@ -fileFormatVersion: 2 -guid: 38067483befc94e4a876017a496350f7 -timeCreated: 1433744190 -licenseType: Pro -TextureImporter: - fileIDToRecycleName: {} - serializedVersion: 2 - mipmaps: - mipMapMode: 0 - enableMipMap: 0 - linearTexture: 1 - correctGamma: 0 - fadeOut: 0 - borderMipMap: 0 - mipMapFadeDistanceStart: 1 - mipMapFadeDistanceEnd: 3 - bumpmap: - convertToNormalMap: 0 - externalNormalMap: 0 - heightScale: 0.25 - normalMapFilter: 0 - isReadable: 0 - grayScaleToAlpha: 0 - generateCubemap: 0 - cubemapConvolution: 0 - cubemapConvolutionSteps: 4 - cubemapConvolutionExponent: 1.5 - seamlessCubemap: 0 - textureFormat: -1 - maxTextureSize: 2048 - textureSettings: - filterMode: -1 - aniso: 1 - mipBias: -1 - wrapMode: 1 - nPOTScale: 0 - lightmap: 0 - rGBM: 0 - compressionQuality: 50 - allowsAlphaSplitting: 0 - spriteMode: 0 - spriteExtrude: 1 - spriteMeshType: 1 - alignment: 0 - spritePivot: {x: 0.5, y: 0.5} - spriteBorder: {x: 0, y: 0, z: 0, w: 0} - spritePixelsToUnits: 100 - alphaIsTransparency: 1 - textureType: 2 - buildTargetSettings: [] - spriteSheet: - sprites: [] - outline: [] - spritePackingTag: - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/FileBrowser/FileBrowser.cs b/Assets/FileBrowser/FileBrowser.cs deleted file mode 100644 index 72b3d037..00000000 --- a/Assets/FileBrowser/FileBrowser.cs +++ /dev/null @@ -1,1678 +0,0 @@ -using UnityEngine; -using System; -using System.IO; -using System.Text; -using System.Collections; -using System.Collections.Generic; -using System.Text.RegularExpressions; - -using System.Net; -using FreeImageAPI; -using System.Runtime.InteropServices; - -using System.Linq; -using System.Diagnostics; - -//=========================================================================== -public class FileBrowser : MonoBehaviour { - - [DllImport ("FreeImage")] - private static extern FIBITMAP FreeImage_Load( FREE_IMAGE_FORMAT fif, string filename, int flags ); - - [DllImport ("FreeImage")] - private static extern void FreeImage_Unload( FIBITMAP dib ); - - [DllImport ("FreeImage")] - private static extern bool FreeImage_Save( FREE_IMAGE_FORMAT fif, FIBITMAP dib, string filename, FREE_IMAGE_SAVE_FLAGS flags ); - - [DllImport ("FreeImage")] - private static extern int FreeImage_GetHeight( FIBITMAP dib ); - - [DllImport ("FreeImage")] - private static extern int FreeImage_GetWidth( FIBITMAP dib ); - - [DllImport ("FreeImage")] - private static extern bool FreeImage_GetPixelColor( FIBITMAP dib, int x, int y, RGBQUAD value ); - - [DllImport ("FreeImage")] - private static extern FIBITMAP FreeImage_MakeThumbnail( FIBITMAP dib, int max_pixel_size, bool convert ); - - - - // DEBUG: Use this to help visualize changes when modifying a GUI skin for the File Browser on the fly - private const bool REFRESH_STYLES_EVERY_FRAME = true; - - // Functional Customizations - public bool showPlaces = true; - public bool dirExplorer = true; - public bool acceptsDirectories = false; - public bool enableFileDelete = true; - public bool hideExtensions = true; - public bool showTextInput = true; // Needed for write dialogs to create new files - public bool inputMustExist = true; // Only makes sense for read dialogs, which we'll assume is the default - public bool overwriteWarn = true; // Only checked if inputMustExist==false. Only makes sense for write dialogs - public string fileMasks = "*.png;*.jpg;*.jpeg"; // Comma or Semicolon separated - public bool showHiddenFiles = false; - - public string startingFileName = ""; - public Collider UIBlocker = null; - - // Only used for the short version of ShowBrowser. Defaults to CWD if not set - public string defaultDir = ""; - - public bool rememberLastDir = true; - - // The default of this should be true, but I'm leaving at false to make it behave the same as the old versions - public bool relativizePaths = false; - - // Look & Feel Customizations - public GUISkin skin = null; - public Texture2D itemHoverImage; - public Color itemHoverTextColor = _uninitColor; - public Texture2D itemSelectedImage; - public Color itemSelectedTextColor = _uninitColor; - - public Texture2D dirImage; - public Texture2D fileImage; - public int dirsHeight = 22; - public int filesHeight = 52; - - public Texture2D placesHDIcon; - public Texture2D placesDesktopIcon; - public Texture2D placesMyDocsIcon; - public Texture2D placesMyPicsIcon; - public Texture2D placesFavoritesIcon; - public Texture2D addFavoritesIcon; - - public Texture2D resizeHandleImage; - - public Rect browserRect = new Rect (300, 400, 600, 400); - public Rect errorRect = new Rect (300, 400, 400, 300); - - public Rect newFolderRect = new Rect (300, 400, 400, 200); - bool showingDialogue = false; - - bool createNewFolder = false; - string newFolderName = "NewFolder"; - - enum DialogueType { - None = 0, - Delete = 1, - Overwrite = 2 - } - - DialogueType dialogueType = DialogueType.None; - - // Sound Previewer customizations - public SoundViewer.SoundViewerConfig soundPreviewOptions; - public int soundPreviewVertOffset = 150; - - // Called when the user clicks cancel or select (path will be null when cancel clicked) - public delegate void FinishedCallback(string path); - - // Callback used to return results from a call to FileBrowser.LoadTexture() - public delegate void TextureLoadedCallback(Texture2D texture); - - public bool Active { - get { return this.isActive; } - } - - // Returns true whenever there's ANY FileBrowser active somewhere - public static bool HasActive() { return FileBrowser._hasActive; } - private static bool _hasActive = false; - - // When using custom styles, tweak these to help properly divide the horizontal boxes among the window space - public int extraPadding = 5; - public int extraPaddingPlaces = 5; // Used only when the browser is showing the places column - - //bool showingError = false; - - //=========================================================================== - // Base FileBrowser show function - public void ShowBrowser(string title, FinishedCallback callback, string startingDir, Rect screenRect, string okString) - { - if (this.rememberLastDir && this.lastOkDirectory != "") { - startingDir = this.lastOkDirectory; - } - - startingDir = startingDir.FixPathSeparators(); - if (!Directory.Exists(startingDir)) { - UnityEngine.Debug.LogError("Starting FileBrowser directory " + startingDir + " does not exist"); - return; - } - - this.title = title; - this.callback = callback; - this.newDirectory = startingDir; - this.screenRect = screenRect; - this.okButtonString = okString; - - this.currentDirectory = ""; - this.isActive = true; - this.saveMode = false; - this.saveScreenshot = null; - - if (this.inputMustExist) this.overwriteWarn = false; - if (!this.dirExplorer) this.rememberLastDir = false; - - this.typedFilename = this.startingFileName; - - if (this.UIBlocker) this.UIBlocker.gameObject.SetActive(true); - - this.deleteSelected = false; - this.SwitchDirectory(); - } - - //=========================================================================== - // Shows a file browser at current working dir, centered on screen occupying 2/3 of w and h (or more on low resolutions), Ok button string "Select" - public void ShowBrowser(string title, FinishedCallback callback) { - string dir = this.defaultDir == "" ? Directory.GetCurrentDirectory() : this.defaultDir.FixPathSeparators(); - - if (firstUse) { - screenRect = this.GetDefaultRect (); - firstUse = false; - } - this.ShowBrowser(title, callback, dir, screenRect, "Select"); - } - public void ShowBrowser(string title, FinishedCallback callback, string okString) { - string dir = this.defaultDir == "" ? Directory.GetCurrentDirectory() : this.defaultDir.FixPathSeparators(); - - if (firstUse) { - screenRect = this.GetDefaultRect (); - firstUse = false; - } - this.ShowBrowser(title, callback, dir, screenRect, okString); - } - - //=========================================================================== - // Shows a save-game file Browser: - // - no directory changes, hide extensions, show text input, png and jpeg filter, overwrite warns, ok button string "Save" - // Takes a screenshot and saves it into the saveBaseDir with the user-specified name. If screenshot if null, takes a screenshot at half resolution - // On ok calls the callback with a file with the same name, on the saveDataDir (which must be diferent then saveBaseDir) - public void ShowSaveBrowser(string title, FinishedCallback callback, string saveBaseDir, string saveDataDir, Rect screenRect, Texture2D screenshot) - { - this.dirExplorer = false; - this.acceptsDirectories = false; - this.hideExtensions = false; - this.showTextInput = true; - this.inputMustExist = false; - this.overwriteWarn = true; - this.fileMasks = "*.png;*.jpg;*.jpeg;*.tga;*.bmp;*.tiff"; - - saveBaseDir = saveBaseDir.FixPathSeparators(); - if (!Directory.Exists(saveBaseDir)) { - Directory.CreateDirectory(saveBaseDir); - } - - this.ShowBrowser(title, callback, saveBaseDir, screenRect, "Save"); - //this.saveMode = true; - this.saveMode = false; - this.savedDataDir = saveDataDir.FixPathSeparators(); - - this.saveScreenshot = screenshot; - if (screenshot == null) { - this.StartCoroutine(this.TakeHalfScreenshot()); - } - } - - //=========================================================================== - // Simplified signature of ShowSaveBrowser. save dir is ./saves, save data is ./saves/data, auto takes the screenshot - public void ShowSaveBrowser(string title, FinishedCallback callback) - { - string saveBaseDir = this.defaultDir == "" ? Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "saves" : this.defaultDir.FixPathSeparators(); - string saveDataDir = saveBaseDir + Path.DirectorySeparatorChar + "data"; - - if (firstUse) { - screenRect = this.GetDefaultRect (); - firstUse = false; - } - this.ShowSaveBrowser(title, callback, saveBaseDir, saveDataDir, screenRect, null); - } - - //=========================================================================== - // Shows a load-game file Browser: - // - no directory changes, hide extensions, png and jpeg filter, file must exist - // Calls the callback with a file with the same name, on the saveDataDir (which must be diferent then saveBaseDir) - // - public void ShowLoadBrowser(string title, FinishedCallback callback, string saveBaseDir, string saveDataDir, Rect screenRect) - { - this.dirExplorer = false; - this.acceptsDirectories = false; - this.hideExtensions = false; - this.inputMustExist = true; - this.overwriteWarn = false; - this.fileMasks = "*.png;*.jpg;*.jpeg;*.tga;*.bmp;*.tiff"; - - saveBaseDir = saveBaseDir.FixPathSeparators(); - if (!Directory.Exists(saveBaseDir)) { - Directory.CreateDirectory(saveBaseDir); - } - - this.ShowBrowser(title, callback, saveBaseDir, screenRect, "Load"); - this.saveMode = false; - this.savedDataDir = saveDataDir; - } - - //=========================================================================== - // Simplified signature of ShowLoadBrowser. save dir is ./saves, save data is ./saves/data - public void ShowLoadBrowser(string title, FinishedCallback callback) - { - string saveBaseDir = this.defaultDir == "" ? Directory.GetCurrentDirectory() + Path.DirectorySeparatorChar + "saves" : this.defaultDir.FixPathSeparators(); - string saveDataDir = saveBaseDir + Path.DirectorySeparatorChar + "data"; - - if (firstUse) { - screenRect = this.GetDefaultRect (); - firstUse = false; - } - this.ShowLoadBrowser(title, callback, saveBaseDir, saveDataDir, screenRect); - } - - //=========================================================================== - // Returns a rectangle centered in the screen, with 2/3 of the screen size - // But with minimum size of 600x450 (or actual Screen size if it's lower than that) - public static Rect GetDefaultRect_() - { - int w = Screen.width / 3 * 2; - int h = Screen.height / 3 * 2; - w = Mathf.Clamp(w, _minWidth, Screen.width); - h = Mathf.Clamp(h, _minHeight, Screen.height); - int x = (Screen.width - w) / 2; - int y = (Screen.height - h) / 2; - return new Rect(x, y, w, h); - } - public Rect GetDefaultRect() { return FileBrowser.GetDefaultRect_(); } - - //=========================================================================== - public void RefreshStyles() { - this.setupCustomStyles(); - - for (int i = 0; i < this.filesWithImages.Length; i++) { - string displayName = this.hideExtensions ? Path.GetFileNameWithoutExtension(this.files[i]) : this.files[i]; - this.filesWithImages[i].text = displayName; - } - } - - //=========================================================================== - public void RefreshContents() { - this.newDirectory = this.currentDirectory; - this.currentDirectory = ""; - this.SwitchDirectory(); - } - - //=========================================================================== - // Private Interface follows - // You can safelly ignore everything from here on - //=========================================================================== - - //=========================================================================== - // Privates - We hold a lot of privates, to make fewer computations inside OnGUI - - // bools so gui can access key events - private bool keyReturn = false; - - - private static Color _uninitColor = new Color(1, 0, 1, 0); - private static int _minWidth = 800; - private static int _minHeight = 480; - private static int _placesSize = 48; - - private GUIStyle styleListItem; - private GUIStyle styleDirsTop; - private GUIStyle styleDirsTopBut; - private GUIStyle styleDirsBrowser; - private GUIStyle styleFileBrowser; - private GUIStyle stylePreviewer; - private GUIStyle stylePreviewTitle; - - private Texture2D previewTexture; - private string previewText = ""; - - private string newDirectory; - private string currentDirectory; - private string[] currentDirectoryParts; - private bool currentDirectoryMatches; - private string lastOkDirectory = ""; - - private string[] files; - private GUIContent[] filesWithImages; - private int selectedFile; - private string typedFilename = ""; - - private string[] directories; - private GUIContent[] directoriesWithImages; - private GUIContent[] directoriesWithImagesRemove; - private int selectedDirectory; - - private bool isActive; - private string title; - private Rect screenRect; - private bool firstUse = true; - private string okButtonString = "Select"; - - private bool saveMode = false; - private string savedDataDir; - private Texture2D saveScreenshot; - - private Vector2 scrollPosition1; - private Vector2 scrollPosition2; - private Vector2 scrollPosition3; - - private FinishedCallback callback; - - private string[] fileMaskList; - private string[] drivesList; - - private SoundViewer soundPreviewer; - - // TODO: A Proper MessageBox class would come in handy instead of these - private string userError = ""; - private bool deleteSelected = false; - private bool overwriteSelected = false; - private string overwriteFileName = ""; - - //=========================================================================== - // Helper struct to hold places (drives and special folders) data - private struct PlacesData { - public PlacesData(string _path, string _name, Texture2D _icon) { - path = _path; name = _name; icon = _icon; - } - public string path; - public string name; - public Texture2D icon; - } - private PlacesData[] placesList; - private GUIStyle placesIconStyle; - private GUIStyle placesLabelStyle; - - private int availableSpace; - private int windowPadding; - - //========================================================================= - // Saves a half-res screenshot into member this.saveScreenshot. Sets a flag to ignore GUI draw this frame - private bool __ignoreGUI = false; - IEnumerator TakeHalfScreenshot() - { - this.__ignoreGUI = true; - yield return new WaitForEndOfFrame(); - - Texture2D fullScreenshot = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, true, true); - fullScreenshot.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0); - this.__ignoreGUI = false; - - // Save with lower res to save disk space - this.saveScreenshot = new Texture2D(Screen.width / 2, Screen.height / 2, TextureFormat.RGB24, false, true); - this.saveScreenshot.SetPixels(fullScreenshot.GetPixels(1)); - this.saveScreenshot.Apply(); - - Destroy(fullScreenshot); - yield break; - } - - //=========================================================================== - void Start() - { - // Fill out the list of places - List _placesList = new List(); - - // Adding a special "My Computer"-type dir, which we'll mark with the string %%ROOT%%, - // to list all the available drives, in addition to the special folder, whitout adding a combo box anywhere - _placesList.Add(new PlacesData("%%ROOT%%", "Drives", this.placesHDIcon)); - - this.__AddSpecialFolder(Environment.SpecialFolder.Desktop, "Desktop", this.placesDesktopIcon, ref _placesList); - this.__AddSpecialFolder(Environment.SpecialFolder.MyDocuments, "My Docs", this.placesMyDocsIcon, ref _placesList); - this.__AddSpecialFolder(Environment.SpecialFolder.MyPictures, "My Pics", this.placesMyPicsIcon, ref _placesList); - //this.__AddSpecialFolder("Favorites", "Favorites", this.placesFavoritesIcon, ref _placesList); - - this.placesList = new PlacesData[_placesList.Count]; - for (int i = 0; i < _placesList.Count; i++) { - this.placesList[i] = _placesList[i]; - } - - this.drivesList = Environment.GetLogicalDrives(); - - if (this.fileMasks == null) this.fileMasks = "*"; - - if (this.UIBlocker) this.UIBlocker.gameObject.SetActive(false); - - this.soundPreviewer = this.gameObject.AddComponent(); - this.soundPreviewer.configs = this.soundPreviewOptions; - this.soundPreviewer.Disable(); - this.soundPreviewer.Start(); - } - - //=========================================================================== - // If the folder exists on this machine, add it the the list of places - private void __AddSpecialFolder(Environment.SpecialFolder folder, string name, Texture2D icon, ref List placesList) - { - string dir = Environment.GetFolderPath(folder); - if (dir != "") { - placesList.Add(new PlacesData(dir, name, icon)); - } - } - - string GetPathToFavorites(){ - string pathToFile = Application.dataPath; - //string pathToFile = Application.persistentDataPath; - if (Application.isEditor) { - pathToFile = pathToFile + "\\favorites.txt"; - } else { - pathToFile = pathToFile.Substring (0, pathToFile.Length - 16) + "favorites.txt"; - } - return pathToFile; - } - - List GetFavorites(){ - List allDirectories = new List(); - - string favoritesPath = GetPathToFavorites (); - - if (File.Exists (favoritesPath)) { - StreamReader theReader = new StreamReader(favoritesPath, Encoding.Default); - string line; - do { - line = theReader.ReadLine(); - if (line != null) - { - if( IsLegitDirectory(line) ){ - allDirectories.Add(line); - } - } - } - while (line != null); - theReader.Close (); - }else{ - File.Create(favoritesPath); - } - - return allDirectories; - } - - void SaveFavorites( List allDirectories ){ - - string favoritesPath = GetPathToFavorites (); - - if (!File.Exists (favoritesPath)) { - File.Create(favoritesPath); - } - StreamWriter theWriter = new StreamWriter(favoritesPath); - foreach (var dir in allDirectories) { - theWriter.WriteLine (dir); - } - - theWriter.Close(); - } - - void AddFavorite( string newFolder ){ - - List allDirectories = GetFavorites (); - bool append = true; - foreach(var dir in allDirectories) { - if (dir == newFolder) { - append = false; - } - } - - if( append == true ){ - allDirectories.Add (newFolder); - } - - this.SaveFavorites (allDirectories); - - } - - bool IsLegitDirectory ( string dir ){ - if (dir != "Favorites" && dir != "%%ROOT%%") { - if (Directory.Exists (dir)) { - return true; - } - } - return false; - } - - void AddCurrentDirToFavorites() { - - if ( IsLegitDirectory(this.currentDirectory) ) { - this.AddFavorite (this.currentDirectory); - //this.RefreshContents (); - //this.SwitchDirectory (); - } - } - - void RemoveFavorite( int dirToRemove ){ - List allDirectories = GetFavorites (); - allDirectories.RemoveAt (dirToRemove + 1); - SaveFavorites (allDirectories); - this.RefreshContents (); - } - - //=========================================================================== - private void SwitchDirectory() - { - if (this.newDirectory == null || this.currentDirectory == this.newDirectory) { - return; - } - - if (this.newDirectory == "%%ROOT%%") { - this.currentDirectory = this.newDirectory; - } else if (this.newDirectory == "Favorites") { - this.currentDirectory = this.newDirectory; - } else { - this.currentDirectory = Path.GetFullPath(this.newDirectory); - } - - this.scrollPosition1 = Vector2.zero; - this.scrollPosition2 = Vector2.zero; - this.selectedDirectory = -1; - this.selectedFile = -1; - this.userError = ""; - - string[] directories; - if (this.currentDirectory == "%%ROOT%%") { - directories = this.drivesList.Clone () as string[]; - } else if (this.currentDirectory == "Favorites"){ - try { - List allDirectories = GetFavorites(); - List dirsList = new List(); - foreach(var dir in allDirectories) { - bool isHidden = (File.GetAttributes(dir) & FileAttributes.Hidden) == FileAttributes.Hidden; - if (!this.showHiddenFiles && isHidden) continue; - dirsList.Add(dir); - } - directories = dirsList.ToArray(); - } catch(IOException) { - this.userError = "Unable to access drive " + this.newDirectory; - UnityEngine.Debug.LogWarning(this.userError); - //TODO Keep this from repainting or whatever - this.newDirectory = null; - return; - } catch(UnauthorizedAccessException) { - this.userError = "Access denied to directory " + this.newDirectory; - UnityEngine.Debug.LogWarning(this.userError); - this.newDirectory = null; - return; - } - } else { - try { - string[] allDirectories = Directory.GetDirectories(this.newDirectory); - List dirsList = new List(); - foreach(var dir in allDirectories) { - bool isHidden = (File.GetAttributes(dir) & FileAttributes.Hidden) == FileAttributes.Hidden; - if (!this.showHiddenFiles && isHidden) continue; - dirsList.Add(dir); - } - directories = dirsList.ToArray(); - } catch(IOException) { - this.userError = "Unable to access drive " + this.newDirectory; - UnityEngine.Debug.LogWarning(this.userError); - //TODO Keep this from repainting or whatever - this.newDirectory = null; - return; - } catch(UnauthorizedAccessException) { - this.userError = "Access denied to directory " + this.newDirectory; - UnityEngine.Debug.LogWarning(this.userError); - this.newDirectory = null; - return; - } - } - - // Needed to avoid leaking memory - Resources.UnloadUnusedAssets(); - - if (this.currentDirectory == "%%ROOT%%") { - this.currentDirectoryParts = new string[] {"Drives"}; - } else if (this.currentDirectory == "/") { - this.currentDirectoryParts = new string[] {""}; - } else if (this.currentDirectory == "Favorites") { - this.currentDirectoryParts = new string[] {"Favorites"}; - } else { - // Remove a trailing separator to avoid having a dangling directory part - // But don't remove it from the currentDirectory string itself or it would break when getting entries of the root drive - string path = this.currentDirectory; - if (this.currentDirectory.EndsWith(Path.DirectorySeparatorChar.ToString())) { - path = this.currentDirectory.Remove(this.currentDirectory.Length - 1); - } - this.currentDirectoryParts = path.Split(Path.DirectorySeparatorChar); - } - - for (int i = 0; i < directories.Length; ++i) { - if (this.currentDirectory == "%%ROOT%%") { - directories [i] = directories [i].Replace (Path.DirectorySeparatorChar.ToString (), ""); - } else if (this.currentDirectory == "Favorites") { - // do nothing - } else { - directories[i] = directories[i].Substring(directories[i].LastIndexOf(Path.DirectorySeparatorChar) + 1); - } - } - Array.Sort(directories); - - // Adding '..' to the list of directories (if we are not at drive root) - bool addParent = this.currentDirectoryParts.Length > 1; - this.directories = new string[directories.Length + (addParent ? 1 : 0)]; - if (addParent) { - this.directories[0] = ".."; - } - for (int i = 0; i < directories.Length; ++i) { - this.directories[i + (addParent ? 1 : 0)] = directories[i]; - } - - // Multiple file masks accepted - this.fileMasks = this.fileMasks.Replace(',', ';'); - this.fileMaskList = this.fileMasks.Split(';'); - List fileList = new List(); - if (this.currentDirectory != "%%ROOT%%" && this.currentDirectory != "Favorites") { - for (int i = 0; i < this.fileMaskList.Length; ++i) { - fileList.AddRange(Directory.GetFiles(this.currentDirectory, this.fileMaskList[i])); - } - } - this.files = fileList.ToArray(); - - for (int i = 0; i < this.files.Length; ++i) { - this.files[i] = Path.GetFileName(this.files[i]); - } - Array.Sort(this.files); - - this.newDirectory = null; - - // Create the folder and files GUIContent with the icons and strings - this.StopAllCoroutines(); - this.directoriesWithImages = new GUIContent[this.directories.Length]; - for (int i = 0; i < this.directoriesWithImages.Length; i++) { - this.directoriesWithImages[i] = new GUIContent(this.directories[i], dirImage); - } - - this.filesWithImages = new GUIContent[this.files.Length]; - for (int i = 0; i < this.filesWithImages.Length; i++) { - string displayName = this.hideExtensions ? Path.GetFileNameWithoutExtension(this.files[i]) : this.files[i]; - this.filesWithImages[i] = new GUIContent(displayName, fileImage); - } - - this.availableSpace = -1; - this.soundPreviewer.Disable(); - - // Load icons in coroutines to avoid taking too long and lock the GUI - this.StartCoroutine(this.loadIcons()); - } - - //=========================================================================== - // Load images into the file icons themselves - // Loading in sequence in a single coroutine instead of creating one for each icon is better - - string MakeNewThumb( string filename, string tempName, string fileLower, int size ){ - - //string newFilename = Application.persistentDataPath + "/" + tempName + ".png"; - string newFilename = Application.dataPath + "/" + tempName + ".png"; - - if (fileLower.EndsWith (".mtz")) { - - string imageFileName = filename.Substring(0, filename.LastIndexOf(".mtz" ) ); - - if( File.Exists( imageFileName + "_diffuseOriginal.bmp" ) ){ - imageFileName += "_diffuseOriginal.bmp"; - }else if( File.Exists( imageFileName + "_diffuse.bmp" ) ){ - imageFileName += "_diffuse.bmp"; - }else if( File.Exists( imageFileName + "_diffuseOriginal.jpg" ) ){ - imageFileName += "_diffuseOriginal.jpg"; - }else if( File.Exists( imageFileName + "_diffuse.jpg" ) ){ - imageFileName += "_diffuse.jpg"; - }else if( File.Exists( imageFileName + "_diffuseOriginal.png" ) ){ - imageFileName += "_diffuseOriginal.png"; - }else if( File.Exists( imageFileName + "_diffuse.png" ) ){ - imageFileName += "_diffuse.png"; - }else if( File.Exists( imageFileName + "_diffuseOriginal.tga" ) ){ - imageFileName += "_diffuseOriginal.tga"; - }else if( File.Exists( imageFileName + "_diffuse.tga" ) ){ - imageFileName += "_diffuse.tga"; - }else if( File.Exists( imageFileName + "_diffuseOriginal.tif" ) ){ - imageFileName += "_diffuseOriginal.tif"; - }else if( File.Exists( imageFileName + "_diffuse.tif" ) ){ - imageFileName += "_diffuse.tif"; - }else if( File.Exists( imageFileName + "_diffuseOriginal.tiff" ) ){ - imageFileName += "_diffuseOriginal.tiff"; - }else if( File.Exists( imageFileName + "_diffuse.tiff" ) ){ - imageFileName += "_diffuse.tiff"; - }else{ - return "null"; - } - - filename = imageFileName; - fileLower = imageFileName.ToLower(); - } - - try{ - FREE_IMAGE_FORMAT imageFormat = FREE_IMAGE_FORMAT.FIF_UNKNOWN; - if( fileLower.EndsWith(".bmp") ){ - imageFormat = FREE_IMAGE_FORMAT.FIF_BMP; - }else if( fileLower.EndsWith(".tga") ){ - imageFormat = FREE_IMAGE_FORMAT.FIF_TARGA; - }else if( fileLower.EndsWith(".tif") || fileLower.EndsWith(".tiff") ){ - imageFormat = FREE_IMAGE_FORMAT.FIF_TIFF; - }else if( fileLower.EndsWith(".png") ){ - imageFormat = FREE_IMAGE_FORMAT.FIF_PNG; - }else if( fileLower.EndsWith(".jpg") || fileLower.EndsWith(".jpeg") ){ - imageFormat = FREE_IMAGE_FORMAT.FIF_JPEG; - }else{ - imageFormat = FREE_IMAGE_FORMAT.FIF_UNKNOWN; - } - FIBITMAP fiBitmap = FreeImage_Load (imageFormat, filename, 0); - FIBITMAP fiThumbnail = FreeImage_MakeThumbnail(fiBitmap, size, true); - - //newFilename = Application.dataPath + "/tempThumb.png"; - - if( File.Exists( newFilename ) ){ - File.SetAttributes(newFilename, FileAttributes.Normal ); - } - - bool thumbnailSuccess = FreeImage_Save( FREE_IMAGE_FORMAT.FIF_PNG, fiThumbnail, newFilename, 0); - - FreeImage_Unload(fiBitmap); - FreeImage_Unload(fiThumbnail); - } - - catch (System.Exception e) { - UnityEngine.Debug.Log( e ); - UnityEngine.Debug.Log( "Could not import with Free Image Importer" ); - } - - - return newFilename; - } - - IEnumerator loadIcons() - { - for (int i = 0; i < this.filesWithImages.Length; i++) { - yield return null; - Resources.UnloadUnusedAssets(); - - string filename = this.currentDirectory + Path.DirectorySeparatorChar + this.files[i]; - string fileLower = filename.ToLower(); - if (!fileLower.EndsWith(".jpg") && !fileLower.EndsWith(".jpeg") && !fileLower.EndsWith(".png") && !fileLower.EndsWith(".bmp") && !fileLower.EndsWith(".tga") && !fileLower.EndsWith(".tiff") && !fileLower.EndsWith(".tif") && !fileLower.EndsWith(".mtz") ) { - continue; - } - - UnityEngine.Debug.Log("Loading Icons"); - - filename = MakeNewThumb( filename, "tempThumb", fileLower, 128 ); - - if( filename != "null" ){ - - WWW www = new WWW("file://" + filename); - yield return www; - - GUIContent item = this.filesWithImages[i]; - Texture2D tex = new Texture2D(www.texture.width, www.texture.height, TextureFormat.ARGB32, false, true); - www.LoadImageIntoTexture(tex); - - //File.Delete(filename); - - // Scale down to the file icons height - float ratio = (float)tex.width / tex.height; - int h = this.filesHeight; - item.image = tex.ScaleTexture((int)(ratio * h), h); - - }else{ - yield return null; - } - - } - Resources.UnloadUnusedAssets(); - } - - //=========================================================================== - // Update checks for Delete pressings to update the delete flag, and arows and enter for keyboard navigation - void Update() - { - if (!this.isActive) return; - - if (this.enableFileDelete && Input.GetKeyUp(KeyCode.Delete)) { - CenterErrorWindow(); - if (this.currentDirectory == "Favorites") { - if ( this.selectedDirectory > -1) { - this.deleteSelected = true; - } - }else if (this.selectedFile > -1 || this.selectedDirectory > 0 ) { - this.deleteSelected = true; - } - } - - if (Input.GetKeyUp (KeyCode.Return)) { - this.keyReturn = true; - } else { - this.keyReturn = false; - } - - /* - if (this.keyReturn && this.selectedDirectory > -1) { - this.DirectoryDoubleClickCallback(this.selectedDirectory); - return; - } - if (this.keyReturn && this.selectedFile > -1) { - this.FileDoubleClickCallback(this.selectedFile); - return; - } - */ - - int movedIndex = 0; - if (Input.GetKeyDown(KeyCode.UpArrow)) movedIndex--; - if (Input.GetKeyDown(KeyCode.DownArrow)) movedIndex++; - - if (movedIndex == 0) return; - - if (this.selectedFile > -1) { - this.selectedFile += movedIndex; - this.selectedFile = Mathf.Clamp(this.selectedFile, 0, this.files.Length - 1); - this.FileSingleClickCallback(this.selectedFile); - } - - if (this.selectedDirectory > -1) { - this.selectedDirectory += movedIndex; - } - } - - //=========================================================================== - private void setupCustomStyles() - { - // Use the "List Item" custom style if one is defined, or create one based on Label style if not - this.styleListItem = this.skin.FindStyle("List Item"); - if (this.styleListItem == null) { - this.styleListItem = new GUIStyle(this.skin.label); - } - this.styleListItem.alignment = TextAnchor.MiddleLeft; - - // Overwrite hover and toggled backgrounds and text colors if they are set - if (this.itemHoverTextColor == _uninitColor) this.itemHoverTextColor = this.skin.label.hover.textColor; - if (this.itemSelectedTextColor == _uninitColor) this.itemSelectedTextColor = this.skin.label.onNormal.textColor; - - if (this.itemHoverImage != null) this.styleListItem.hover.background = this.itemHoverImage; - if (this.itemSelectedImage != null) { - this.styleListItem.onNormal.background = this.itemSelectedImage; - this.styleListItem.onHover.background = this.itemSelectedImage; - } - this.styleListItem.hover.textColor = this.itemHoverTextColor; - this.styleListItem.onNormal.textColor = this.itemSelectedTextColor; - this.styleListItem.onHover.textColor = this.itemSelectedTextColor; - - // Other custom styles - this.styleDirsTop = new GUIStyle(this.skin.label); - this.styleDirsTopBut = new GUIStyle(this.skin.button); - this.stylePreviewer = new GUIStyle(this.skin.label); - this.styleDirsBrowser = new GUIStyle(this.styleListItem); - this.styleFileBrowser = new GUIStyle(this.styleListItem); - this.stylePreviewTitle= new GUIStyle(this.skin.label); - - this.styleDirsTop.alignment = TextAnchor.MiddleCenter; - this.styleDirsTopBut.alignment = TextAnchor.MiddleCenter; - this.stylePreviewTitle.alignment= TextAnchor.UpperCenter; - this.stylePreviewer.alignment = TextAnchor.MiddleCenter; - - this.styleDirsTop.wordWrap = false; - this.styleDirsTop.stretchWidth = true; - this.styleDirsTop.fixedHeight = this.skin.button.fixedHeight; - this.styleDirsTopBut.fixedHeight = this.skin.button.fixedHeight; - this.styleDirsBrowser.fixedHeight = this.dirsHeight; - this.styleFileBrowser.fixedHeight = this.filesHeight; - - this.stylePreviewer.fixedHeight = 0; - this.stylePreviewer.fixedWidth = 0; - this.stylePreviewer.stretchHeight = true; - this.stylePreviewer.stretchWidth = true; - - this.styleDirsTopBut.padding = new RectOffset(10, 10, 5, 5); - this.styleDirsTop.padding = new RectOffset(5, 5, 5, 5); - this.styleDirsTop.margin.bottom = 10; - this.styleDirsTopBut.margin.bottom = 10; - this.stylePreviewTitle.margin.bottom = 0; - - this.placesIconStyle = new GUIStyle(this.skin.button); - this.placesIconStyle.fixedHeight = _placesSize; - this.placesIconStyle.fixedWidth = _placesSize; - this.placesIconStyle.alignment = TextAnchor.MiddleCenter; - - this.placesLabelStyle = new GUIStyle(this.skin.label); - this.placesLabelStyle.padding.top = 0; - this.placesLabelStyle.alignment = TextAnchor.UpperLeft; - this.placesLabelStyle.fixedWidth = 55; - } - - //=========================================================================== - // Discounts GUI style paddings, and the places column - private int _CalcAvailableWidth() { - int winPad = (GUI.skin.window.padding.left - GUI.skin.window.overflow.left) * 2; - int boxPad = (GUI.skin.box.padding.left - GUI.skin.box.overflow.left) * 6; - int placesSize = (int) GUI.skin.label.CalcSize(new GUIContent("My Docs")).x + this.extraPaddingPlaces; - - bool _showPlaces = this.showPlaces && this.dirExplorer; - return (int) (this.screenRect.width - winPad - boxPad - (_showPlaces ? placesSize : 0) - this.extraPadding); - } - - //=========================================================================== - void UpdateSoundPreviewRect() { - float slice8 = this.availableSpace / (this.dirExplorer ? 8.0f : 6.0f); - - float w = slice8 * 3 - 30; - float x = this.screenRect.x + this.screenRect.width - w - windowPadding - 15; - float y = this.screenRect.y + this.soundPreviewVertOffset; - float h = this.screenRect.height - (y - this.screenRect.y) * 2; - this.soundPreviewer.viewRect = new Rect(x / Screen.width, y / Screen.height, w / Screen.width, h / Screen.height); - } - - - void GuiWindow( int windowID ){ - - bool showingError = this.userError.Length > 1 || this.deleteSelected || this.createNewFolder; - GUI.enabled = !showingError; - - GUILayout.Space (8); - - // Top directory parts - if (this.dirExplorer) { - GUILayout.BeginHorizontal (); - for (int parentIndex = 0; parentIndex < this.currentDirectoryParts.Length; ++parentIndex) { - if (parentIndex == this.currentDirectoryParts.Length - 1) { - GUILayout.Label (this.currentDirectoryParts [parentIndex], this.styleDirsTop); - } else if (GUILayout.Button (this.currentDirectoryParts [parentIndex], this.styleDirsTopBut)) { - string parentDirectoryName = this.currentDirectory; - for (int i = this.currentDirectoryParts.Length - 1; i > parentIndex; --i) { - parentDirectoryName = Path.GetDirectoryName (parentDirectoryName); - } - this.newDirectory = parentDirectoryName; - } - } - GUILayout.FlexibleSpace (); - GUILayout.EndHorizontal (); - } - - GUILayout.BeginHorizontal(); - - // This holds 1/8 of the remaining size, discounting the places column and paddings - // 1/6 if directory browser won't show. Discount extra width if the places column will show - float slice8 = this.availableSpace / (this.dirExplorer ? 8.0f : 6.0f); - - int vBarPad = (int) GUI.skin.verticalScrollbar.fixedWidth; - this.styleFileBrowser.fixedWidth = slice8 * 3 - vBarPad * 2; - - if (this.soundPreviewer.enabled) { - this.UpdateSoundPreviewRect(); - } - - // Places (Drives and Special Folders) - if (this.showPlaces && this.dirExplorer) { - GUILayout.BeginVertical(); - for (int i = 0; i < this.placesList.Length; i++) { - if (GUILayout.Button(this.placesList[i].icon, this.placesIconStyle)) { - this.newDirectory = this.placesList[i].path; - } - GUILayout.Label (this.placesList[i].name, this.placesLabelStyle, GUILayout.MaxHeight(18)); - } - - // Favorites Icon - if (GUILayout.Button(this.placesFavoritesIcon, this.placesIconStyle)) { - this.newDirectory = "Favorites"; - } - GUILayout.Label ("Favorites", this.placesLabelStyle, GUILayout.MaxHeight(18)); - - // Add to Favorites Icon - if (GUILayout.Button(this.addFavoritesIcon, this.placesIconStyle)) { - AddCurrentDirToFavorites (); - } - GUILayout.Label ("Add To Favorites", this.placesLabelStyle, GUILayout.MaxHeight(18)); - - GUILayout.FlexibleSpace(); - GUILayout.EndVertical(); - } - - // Directory browser - if (this.dirExplorer) { - this.scrollPosition1 = GUILayout.BeginScrollView( - this.scrollPosition1, false, false, this.skin.horizontalScrollbar, this.skin.verticalScrollbar, - GUI.skin.box, GUILayout.Width(slice8 * 2) - ); - if (this.currentDirectory == "Favorites") { - this.selectedDirectory = GUILayoutx.SelectionList( - this.selectedDirectory, this.directoriesWithImages, this.styleDirsBrowser, - DirectoryDoubleClickCallback, null - ); - if (this.selectedDirectory > -1) this.selectedFile = -1; - } else { - this.selectedDirectory = GUILayoutx.SelectionList( - this.selectedDirectory, this.directoriesWithImages, this.styleDirsBrowser, - DirectoryDoubleClickCallback, null - ); - if (this.selectedDirectory > -1) this.selectedFile = -1; - } - GUILayout.EndScrollView(); - } - - - // Files browser - this.scrollPosition2 = GUILayout.BeginScrollView( - this.scrollPosition2, false, false, this.skin.horizontalScrollbar, this.skin.verticalScrollbar, - this.skin.box, GUILayout.Width(slice8 * 3) - ); - if (this.filesWithImages.Length == 0) { - GUILayout.Label("No entries", this.styleDirsTop, GUILayout.Width(slice8 * 3 - 30)); - } else { - this.selectedFile = GUILayoutx.SelectionList( - this.selectedFile, this.filesWithImages, this.styleFileBrowser, - FileDoubleClickCallback, FileSingleClickCallback - ); - if (this.selectedFile > -1) this.selectedDirectory = -1; - } - GUILayout.EndScrollView(); - - GUILayout.FlexibleSpace(); - - // Previewer - int vBarW = (int)GUI.skin.verticalScrollbar.fixedWidth; - int previewW = (int)(slice8 * 3 - vBarW); - GUILayout.BeginVertical(); - if (this.selectedFile < 0) { - string previewString = this.saveMode ? "" : "Nothing to preview"; - GUILayout.Label(previewString, this.stylePreviewTitle, GUILayout.Width(previewW)); - this.previewTexture = null; - } else { - string filename = this.files[this.selectedFile]; - #if UNITY_WEBPLAYER - string filetime = ""; - #else - string fullname = Path.Combine(this.currentDirectory, filename); - string filetime = System.IO.File.GetLastWriteTime(fullname).ToString(); - string filesize = ((new System.IO.FileInfo(fullname)).Length / 1000).ToString(); - filename += " (" + filesize + " KB"; - if (this.previewTexture) { - filename += ", " + this.previewTexture.width + " x " + this.previewTexture.height; - } - filename += ")"; - #endif - - if (this.soundPreviewer.enabled) { - AudioClip clip = this.soundPreviewer.configs.aSource.clip; - string channels = clip.channels == 1 ? "Mono, " : "Stereo, "; - TimeSpan t = TimeSpan.FromSeconds(clip.length); - string niceTime = string.Format("{0:D2}:{1:D2}.{2:D3}", t.Minutes, t.Seconds, t.Milliseconds); - filename += "\n" + clip.frequency + " Hz, " + channels + niceTime; - } - - GUILayout.Label(filename, this.stylePreviewTitle, GUILayout.Width(previewW)); - GUILayout.Label(filetime, this.stylePreviewTitle, GUILayout.Width(previewW)); - GUILayout.FlexibleSpace(); - } - this.scrollPosition3 = GUILayout.BeginScrollView( - this.scrollPosition3, this.skin.scrollView, GUILayout.Width(previewW + vBarW + 6) - ); - if (this.saveMode && this.selectedFile < 0) { - this.previewTexture = this.saveScreenshot; - } - - - if (this.previewTexture != null) { - GUILayout.FlexibleSpace(); - GUILayout.BeginHorizontal(); - GUILayout.FlexibleSpace(); - float hFactor = (float)this.previewTexture.height / this.previewTexture.width; - GUILayout.Label( - this.previewTexture, this.stylePreviewer, - GUILayout.Width(previewW), GUILayout.Height(previewW * hFactor) - ); - GUILayout.FlexibleSpace(); - GUILayout.EndHorizontal(); - GUILayout.FlexibleSpace(); - } else if (this.previewText.Length > 0) { - GUILayout.TextArea(this.previewText); - } - GUILayout.EndScrollView(); - GUILayout.EndVertical(); - - GUILayout.EndHorizontal(); - - // Bottom part: text input, ok / cancel - GUILayout.BeginHorizontal(); - - GUILayout.Space(60); - if( GUILayout.Button("Paste Directory", GUILayout.Width(120))) { - PasteDirCallback(); - } - - if (GUILayout.Button ("Create New Folder", GUILayout.Width (120))) { - CenterNewFolderWindow(); - this.createNewFolder = true; - } - - if (this.showTextInput) { - GUILayout.Space(10); - GUILayout.Label("Filename: ", GUILayout.Width(60)); - - GUI.SetNextControlName("FilenameTextField"); - string newName = GUILayout.TextField(this.typedFilename); - - if (this.typedFilename != newName) { - this.typedFilename = newName; - this.selectedFile = -1; - for (int i = 0; i < this.filesWithImages.Length; i++) { - if (this.filesWithImages[i].text.ToLower() == newName.ToLower()) { - this.selectedFile = i; - this.FileSingleClickCallback(i); - } - } - } - GUILayout.Space(20); - } else { - GUILayout.FlexibleSpace(); - } - - if (GUILayout.Button("Cancel", GUILayout.Width(80))) { - this.Close(); - this.callback(null); - } - - bool dirEnables = this.acceptsDirectories && this.typedFilename.Length == 0; - bool fileEnables = this.selectedFile > -1 || (this.inputMustExist == false && this.typedFilename.Length > 0); - GUI.enabled = (dirEnables || fileEnables) && !showingError; - - bool enterPressed = (Event.current.type == EventType.KeyDown && Event.current.character == '\n'); - - // OK Button - if (GUILayout.Button(this.okButtonString, GUILayout.Width(80)) || ( enterPressed && GUI.enabled ) ) { - this.soundPreviewer.Disable(); - this.StartCoroutine(this.FileSelected()); - } - GUI.enabled = true; - GUILayout.Space(20); - GUILayout.EndHorizontal(); - - Rect dragRect = new Rect( 0, 0, this.screenRect.width, this.screenRect.height - 25 ); - GUI.DragWindow( dragRect ); - dragRect = new Rect( 0, 0, this.screenRect.width - 25, this.screenRect.height ); - GUI.DragWindow( dragRect ); - - GUI.DrawTexture (new Rect (this.screenRect.width - 32, this.screenRect.height - 32, 32, 32), resizeHandleImage); - } - - - void ErrorWindow( int windowID){ - - string text = this.userError; - string filename = ""; - if(this.selectedFile > -1) { - filename = Path.Combine(this.currentDirectory, this.files[this.selectedFile]); - } - - string folderName = ""; - if(this.selectedDirectory > 0) { - folderName = Path.Combine(this.currentDirectory, this.directories[this.selectedDirectory]); - } - - if (this.overwriteSelected) filename = this.overwriteFileName; - - if (this.deleteSelected) { - if (this.currentDirectory == "Favorites") { - if (this.selectedDirectory > -1) { - text = "Remove " + this.directoriesWithImages [this.selectedDirectory].text + " From Favorites?"; - } else { - this.deleteSelected = false; - } - } else { - if (this.selectedDirectory > 0) { - text = "Delete " + this.directoriesWithImages [this.selectedDirectory].text + "?"; - } else if (this.selectedFile > -1) { - text = "Delete " + this.filesWithImages [this.selectedFile].text + "?"; - } else { - this.deleteSelected = false; - } - } - - } - - GUILayout.FlexibleSpace(); - GUILayout.Label(text, this.styleDirsTop); - GUILayout.FlexibleSpace(); - - GUILayout.BeginHorizontal(); - GUILayout.FlexibleSpace(); - - if (!this.deleteSelected && !this.overwriteSelected) { - if (GUILayout.Button("Ok", this.styleDirsTopBut, GUILayout.Width(80))) { - this.userError = ""; - } - } else { - if (GUILayout.Button("Confirm", this.styleDirsTopBut, GUILayout.Width(80))) { - - if (this.currentDirectory == "Favorites") { - RemoveFavorite (this.selectedDirectory); - } else { - if (this.selectedDirectory > 0) { - //Directory.Delete (folderName); - try{ - Process myProcess = new Process (); - myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; - myProcess.StartInfo.CreateNoWindow = true; - myProcess.StartInfo.UseShellExecute = false; - myProcess.StartInfo.FileName = Application.streamingAssetsPath.Replace ("/", "\\") + "\\f2rb.exe"; - myProcess.StartInfo.Arguments = folderName.Replace ("/", "\\"); - myProcess.EnableRaisingEvents = true; - myProcess.Start(); - myProcess.WaitForExit (); - } catch (Exception e ){ - UnityEngine.Debug.Log (e); - } - } else if (this.selectedFile > -1) { - //File.Delete (filename); - try{ - Process myProcess = new Process (); - myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; - myProcess.StartInfo.CreateNoWindow = true; - myProcess.StartInfo.UseShellExecute = false; - myProcess.StartInfo.FileName = Application.streamingAssetsPath.Replace ("/", "\\") + "\\f2rb.exe"; - myProcess.StartInfo.Arguments = filename.Replace ("/", "\\"); - myProcess.EnableRaisingEvents = true; - myProcess.Start(); - myProcess.WaitForExit (); - } catch (Exception e ){ - UnityEngine.Debug.Log (e); - } - } - } - - if (this.deleteSelected) { - this.RefreshContents(); - } - - this.deleteSelected = false; - this.overwriteSelected = true; - this.userError = ""; - } - if (GUILayout.Button("Cancel", this.styleDirsTopBut, GUILayout.Width(80))) { - this.deleteSelected = false; - this.overwriteSelected = false; - this.userError = ""; - } - } - - GUILayout.FlexibleSpace(); - GUILayout.EndHorizontal(); - - GUI.DragWindow (); - - } - - void CreateFolder ( string folderPath, string folderName ){ - - Directory.CreateDirectory (Path.Combine (folderPath, folderName)); - - } - - void NewFolderWindow( int windowID ){ - - string folderPath = this.currentDirectory; - - GUILayout.FlexibleSpace(); - - GUILayout.BeginHorizontal(); - GUILayout.FlexibleSpace(); - newFolderName = GUILayout.TextField (newFolderName, GUILayout.Width(200)); - GUILayout.FlexibleSpace(); - GUILayout.EndHorizontal(); - - GUILayout.FlexibleSpace(); - - GUILayout.BeginHorizontal(); - GUILayout.FlexibleSpace(); - if (GUILayout.Button("Confirm", this.styleDirsTopBut, GUILayout.Width(80))) { - CreateFolder( folderPath, newFolderName ); - newFolderName = "NewFolder"; - this.createNewFolder = false; - this.RefreshContents(); - } - GUILayout.FlexibleSpace(); - if (GUILayout.Button("Cancel", this.styleDirsTopBut, GUILayout.Width(80))) { - newFolderName = "NewFolder"; - this.createNewFolder = false; - } - GUILayout.FlexibleSpace(); - GUILayout.EndHorizontal(); - - GUI.DragWindow (); - - } - - - Vector3 mousePos; - Vector3 clickedPosition; - int minWindowWidth = 500; - int minWindowHeight = 400; - Rect originalWindowRect; - bool allowWindowResize = true; - bool handleClicked = false; - - //=========================================================================== - void OnGUI() { - if (!this.Active || this.__ignoreGUI) return; - FileBrowser._hasActive = true; - - if (this.availableSpace == -1 || REFRESH_STYLES_EVERY_FRAME) { - this.availableSpace = this._CalcAvailableWidth(); - this.windowPadding = GUI.skin.window.padding.left - GUI.skin.window.overflow.left; - } - - // Use a custom skin if set, or the default one if not - if (this.skin == null) { - this.skin = GUI.skin; - GUI.FocusControl("FilenameTextField"); - } - - GUI.skin = this.skin; - if (this.styleListItem == null || REFRESH_STYLES_EVERY_FRAME) this.setupCustomStyles(); - - this.screenRect = GUI.Window(100, this.screenRect, GuiWindow, this.title); - - // Resize window by dragging corner...must be done outside window code, or else mouse drag events outside the window are unrecognized - //mousePos = GUIUtility.ScreenToGUIPoint(new Vector2( Input.mousePosition.x, Screen.height - Input.mousePosition.y )); - mousePos = Event.current.mousePosition; - if (allowWindowResize) { - if (Event.current.type == EventType.MouseDown && new Rect(this.screenRect.width + this.screenRect.x - 25, this.screenRect.height + this.screenRect.y - 25, 25, 25).Contains (mousePos)) { - handleClicked = true; - clickedPosition = mousePos; - originalWindowRect = this.screenRect; - } - if (handleClicked) { - if (Event.current.type == EventType.MouseDrag) { - this.screenRect.width = Mathf.Clamp (originalWindowRect.width + (mousePos.x - clickedPosition.x), minWindowWidth, 1600); - this.screenRect.height = Mathf.Clamp (originalWindowRect.height + (mousePos.y - clickedPosition.y), minWindowHeight, 1200); - //UpdateRects(); - } - else if (Event.current.type == EventType.MouseUp) { - handleClicked = false; - } - } - } - - - // Make new Folder - if ( this.createNewFolder ) { - newFolderRect = GUI.Window (101, newFolderRect, NewFolderWindow, "Create New Folder"); - } - - - // Crude message box to display IO errors and delete/overwrite confirmation - bool showingError = this.userError.Length > 1 || this.deleteSelected; - if (showingError) { - - //errorRect.width = this.screenRect.width * 0.5f; - //errorRect.height = this.screenRect.height * 0.5f; - errorRect = GUI.Window (102, errorRect, ErrorWindow, "Error"); - } - - - if (Event.current.type == EventType.Repaint) { - this.SwitchDirectory(); - } - } - - void CenterNewFolderWindow(){ - this.newFolderRect.center = this.screenRect.center; - } - - void CenterErrorWindow(){ - this.errorRect.center = this.screenRect.center; - } - - //=========================================================================== - // Checks for confirmation of overwriteWarn is true and the file already exists - IEnumerator FileSelected() - { - string saveName = ""; - string finalName = ""; - string saveShotName = ""; - - //UnityEngine.Debug.Log ("Is this save mode? " + this.saveMode); - - if (this.saveMode) { - saveName = this.selectedFile > -1 ? this.filesWithImages[this.selectedFile].text : this.typedFilename; - saveName = saveName.ReplaceInsensitive(".png", "").ReplaceInsensitive(".jpg", "").ReplaceInsensitive(".jpeg", ""); - - saveShotName = Path.Combine(this.currentDirectory, saveName + ".png"); - finalName = Path.Combine(this.savedDataDir, saveName); - - saveShotName = Path.GetFullPath(saveShotName); - - } else { - if (this.selectedFile > -1) { - finalName = Path.Combine(this.currentDirectory, this.files[this.selectedFile]); - } else if (this.typedFilename.Length > 0) { - finalName = Path.Combine(this.currentDirectory, this.typedFilename); - } else if (this.selectedDirectory > -1) { - finalName = Path.Combine(this.currentDirectory, this.directories[this.selectedDirectory]); - } else { - finalName = this.currentDirectory; - } - } - - try { - finalName = Path.GetFullPath(finalName); - } catch (ArgumentException) {} - - if (this.overwriteWarn && (File.Exists(finalName) || File.Exists(saveShotName))) { - this.overwriteSelected = true; - this.overwriteFileName = finalName; - this.userError = "Overwrite " + (this.saveMode ? saveName : finalName) + "?"; - while (this.userError.Length > 0) { // Wait for user confirmation - yield return null; - } - if (!this.overwriteSelected) yield break; - this.overwriteSelected = false; - } - - this.SelectConfirmed(finalName, saveShotName); - } - - //-------------- - void SelectConfirmed(string finalName, string saveShotName) - { - if (this.saveMode && this.saveScreenshot) { -#if UNITY_WEBPLAYER - UnityEngine.Debug.LogError("Webplayer does not support FileSystem write"); -#else - byte[] png = this.saveScreenshot.EncodeToPNG(); - File.WriteAllBytes(saveShotName, png); -#endif - } - - //UnityEngine.Debug.Log ("Name Coming From File Borwser: " + finalName); - - this.lastOkDirectory = Path.GetDirectoryName(finalName); - - if (this.relativizePaths) RelativizatePath(ref finalName); - this.callback(finalName); - - this.Close(); - } - - //=========================================================================== - void Close() { - this.soundPreviewer.Disable(); - this.isActive = false; - FileBrowser._hasActive = false; - Resources.UnloadUnusedAssets(); - if (this.UIBlocker) this.UIBlocker.gameObject.SetActive(false); - } - - //=========================================================================== - IEnumerator loadPreview(string filename) - { - string lower = filename.ToLower(); - - bool isImage = lower.EndsWith(".jpg") || lower.EndsWith(".jpeg") || lower.EndsWith(".png") || lower.EndsWith(".tga") || lower.EndsWith(".bmp") || lower.EndsWith(".tif") || lower.EndsWith(".tiff"); - bool isSound = lower.EndsWith(".wav") || lower.EndsWith(".ogg"); - bool isMaterial = lower.EndsWith(".mtz"); - - //string newFilename = Application.dataPath + "/tempPreview.png"; - - // Load preview images - if ( isMaterial || isImage ) { - string newFilename = MakeNewThumb(filename, "tempPreview", lower, 512 ); - if( newFilename != "null" ){ - WWW www = new WWW("file://" + newFilename); - yield return www; - this.previewTexture = www.texture; - //File.Delete(newFilename); - } - yield break; - } - - // Load preview sounds - if ( isSound ) { - WWW www = new WWW("file://" + filename); - yield return www; - - this.UpdateSoundPreviewRect(); - this.soundPreviewer.enabled = true; - this.soundPreviewer.configs = this.soundPreviewOptions; - this.soundPreviewer.PreviewClip(www.GetAudioClip(false, false)); - yield break; - } - - // Check if we want to try previewing with text it anyway - string[] texts = { "txt", "rtf", "doc", "xml", "html", "cs", "java", "py", "cpp", "c", "php", "ini", "reg", "odf", "ods", "meta" }; - string ext = Path.GetExtension(lower); - bool doTextPreview = texts.Any(ext.Contains); - - if (!doTextPreview) { - // If it's not too big and doesn't have a lot of \0's in it, go for it - FileInfo fi = new FileInfo(filename); - if (fi.Length < 1000000) { - try { - Byte[] bytes = File.ReadAllBytes(filename); - doTextPreview = true; - for (int i = 0; i < (bytes.Length - 2); i++) { - if (bytes[i] == '\0' && bytes[i+1] == '\0') { - doTextPreview = false; - break; - } - } - } catch (IOException) { - doTextPreview = false; - } - } - } - - this.previewText = ""; - - // Preview everything else as text? - if (doTextPreview) { - try { - StreamReader stream = new StreamReader(filename); - Char[] buffer = new Char[2050]; - stream.Read(buffer, 0, 2048); - stream.Close(); - this.previewText = new string(buffer); - } catch (IOException) { - this.previewText = "Unable to preview"; - } - } - } - - //=========================================================================== - private void FileSingleClickCallback(int i) { - this.previewText = ""; - this.previewTexture = null; - this.scrollPosition3 = Vector2.zero; - this.soundPreviewer.Disable(); - - this.typedFilename = this.files[i]; - - this.StartCoroutine(loadPreview(Path.Combine(this.currentDirectory, this.files[i]))); - } - - //=========================================================================== - private void FileDoubleClickCallback(int i) { - this.soundPreviewer.Disable(); - this.StopAllCoroutines(); - this.StartCoroutine(this.FileSelected()); - } - - //=========================================================================== - private void DirectoryDoubleClickCallback(int i) { - this.newDirectory = Path.Combine(this.currentDirectory, this.directories[i]); - this.newDirectory = Path.GetFullPath(this.newDirectory); - this.SwitchDirectory(); - } - - //=========================================================================== - private void PasteDirCallback() { - string newDir = ClipboardHelper.clipBoard; - if (Path.HasExtension (newDir)) { - newDir = Path.GetDirectoryName (newDir); - }else if (!newDir.EndsWith (Path.DirectorySeparatorChar.ToString())) { - newDir += Path.DirectorySeparatorChar; - } - this.newDirectory = newDir; - this.SwitchDirectory(); - } - - //=========================================================================== - // Call this function to load the contents of the path image file into a new Texture2D - // Assyncronous, returns the results calling a TextureLoadedCallback - //=========================================================================== - public void GetTexture(string path, TextureLoadedCallback callback) { - this.StartCoroutine(this.__GetTexture(path, callback)); - } - - //-------------- - IEnumerator __GetTexture(string path, TextureLoadedCallback callback) - { - path = Path.GetFullPath(path); - - WWW www = new WWW("file://" + path); - yield return www; - Texture2D texture = new Texture2D(www.texture.width, www.texture.height, TextureFormat.ARGB32, false, true); - texture.wrapMode = TextureWrapMode.Clamp; - www.LoadImageIntoTexture(texture); - - callback(texture); - } - - //========================================================================= - // Removes the current working dir from path, making it relative to it - public static string RelativizatePath(ref string path) - { - path = path.FixPathSeparators(); - string cwd = System.IO.Directory.GetCurrentDirectory(); - path = path.Replace(cwd, "."); - return path; - } -} - -//=========================================================================== -// Changes all forward and backward slashes of this string to the current system's proper path separator -static public class FileBrowserExtensions -{ - //========================================================================= - static public string FixPathSeparators(this string path) - { - string str = path.Replace('/', Path.DirectorySeparatorChar); - return str .Replace('\\', Path.DirectorySeparatorChar); - } - - //========================================================================= - static public Texture2D ScaleTexture(this Texture2D source, int targetWidth, int targetHeight) - { - Texture2D result = new Texture2D(targetWidth, targetHeight, source.format, false, true); - Color[] rpixels = result.GetPixels(0); - float incX = ((float)1 / source.width) * ((float)source.width / targetWidth); - float incY = ((float)1 / source.height) * ((float)source.height / targetHeight); - for(int px = 0; px < rpixels.Length; px++) { - rpixels[px] = source.GetPixelBilinear(incX * ((float)px % targetWidth), - incY * ((float)Mathf.Floor(px / targetWidth))); - } - result.SetPixels(rpixels, 0); - result.Apply(); - return result; - } - - //========================================================================= - static public string ReplaceInsensitive(this string str, string from, string to) - { - str = Regex.Replace(str, from, to, RegexOptions.IgnoreCase); - return str; - } -} - diff --git a/Assets/FileBrowser/FileBrowser.cs.meta b/Assets/FileBrowser/FileBrowser.cs.meta deleted file mode 100644 index f9a142ab..00000000 --- a/Assets/FileBrowser/FileBrowser.cs.meta +++ /dev/null @@ -1,19 +0,0 @@ -fileFormatVersion: 2 -guid: 3f8b66db80454d649bce4ec20dbaf678 -MonoImporter: - serializedVersion: 2 - defaultReferences: - - skin: {instanceID: 0} - - itemHoverImage: {fileID: 2800000, guid: 4325cb797ef078b49bb0efb0fb870da8, type: 3} - - itemSelectedImage: {fileID: 2800000, guid: d92388cf1d1be28458d673a546ed4a61, type: 3} - - dirImage: {fileID: 2800000, guid: c8135945c98cc94429ae7806d04b5b8b, type: 3} - - fileImage: {fileID: 2800000, guid: 39a095224be0beb409f5b61cd02f4579, type: 3} - - placesHDIcon: {fileID: 2800000, guid: 6576d7fa26628104986879a9195197b4, type: 3} - - placesDesktopIcon: {fileID: 2800000, guid: e09026654626d284eb4b90ad872d8b6a, type: 3} - - placesMyDocsIcon: {fileID: 2800000, guid: a0bfbc70c5b63284b84f5df326d3668a, type: 3} - - placesMyPicsIcon: {fileID: 2800000, guid: fcd61eae31be0844fb0164aaa667af8b, type: 3} - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/FileBrowser/ReadMe.rtf b/Assets/FileBrowser/ReadMe.rtf deleted file mode 100644 index f62b95da..00000000 --- a/Assets/FileBrowser/ReadMe.rtf +++ /dev/null @@ -1,359 +0,0 @@ -{\rtf1\ansi\deff3\adeflang1025 -{\fonttbl{\f0\froman\fprq2\fcharset0 Times New Roman;}{\f1\froman\fprq2\fcharset2 Symbol;}{\f2\fswiss\fprq2\fcharset0 Arial;}{\f3\fswiss\fprq0\fcharset0 Arial;}{\f4\fnil\fprq0\fcharset128 OpenSymbol{\*\falt Arial Unicode MS};}{\f5\fmodern\fprq1\fcharset0 Courier{\*\falt Courier New};}{\f6\fmodern\fprq1\fcharset0 Courier New;}{\f7\fnil\fprq2\fcharset0 Mangal;}{\f8\fnil\fprq0\fcharset128 Mangal;}{\f9\fnil\fprq2\fcharset0 Microsoft YaHei;}} -{\colortbl;\red0\green0\blue0;\red0\green0\blue128;\red0\green77\blue187;\red128\green128\blue128;} -{\stylesheet{\s0\snext0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046 Padro;} -{\*\cs15\snext15\cf2\ul\ulc0\langfe255\lang255 Link da Internet;} -{\*\cs16\snext16\hich\af4\dbch\af4\loch\f4 Marcadores;} -{\s17\sbasedon0\snext18{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\sb240\sa120\keepn\cf0\kerning1\hich\af7\langfe2052\dbch\af9\loch\f2\fs28\lang1046 Ttulo;} -{\s18\sbasedon0\snext18{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\sb0\sa120\cf0\kerning1\hich\af3\langfe2052\dbch\af3\loch\f3\fs24\lang1046 Corpo do texto;} -{\s19\sbasedon18\snext19{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\sb0\sa120\cf0\kerning1\hich\af8\langfe2052\dbch\af3\loch\f3\fs24\lang1046 Lista;} -{\s20\sbasedon0\snext20{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\sb120\sa120\cf0\i\kerning1\hich\af8\langfe2052\dbch\af3\ai\loch\f3\fs24\lang1046 Legenda;} -{\s21\sbasedon0\snext21{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\cf0\kerning1\hich\af8\langfe2052\dbch\af3\loch\f3\fs24\lang1046 ndice;} -}{\info{\creatim\yr0\mo0\dy0\hr0\min0}{\revtim\yr0\mo0\dy0\hr0\min0}{\printim\yr0\mo0\dy0\hr0\min0}{\comment OpenOffice.org}{\vern3410}}\deftab720\deftab720\deftab720\deftab720\deftab720\deftab720\deftab720\deftab720\deftab720\deftab720\deftab720\deftab720\deftab720\deftab720\deftab720\deftab720\deftab720\deftab720\deftab720\deftab720 - -{\*\pgdsctbl -{\pgdsc0\pgdscuse195\pgwsxn12240\pghsxn15840\marglsxn1800\margrsxn1800\margtsxn1440\margbsxn1440\pgdscnxt0 Padr\'e3o;}} -\formshade{\*\pgdscno0}\paperh15840\paperw12240\margl1800\margr1800\margt1440\margb1440\sectd\sbknone\sectunlocked1\pgndec\pgwsxn12240\pghsxn15840\marglsxn1800\margrsxn1800\margtsxn1440\margbsxn1440\ftnbj\ftnstart1\ftnrstcont\ftnnar\aenddoc\aftnrstcont\aftnstart1\aftnnrlc -\pgndec\pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046\qc{\b\ab\rtlch \ltrch\loch\lang1033 -Unity File Brower & Save/Load UI} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046\qc{\afs22\rtlch \ltrch\loch\fs22\lang1033 -Copyright \'a9 2012 Pigasus Games} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046\qc{\afs22\rtlch \ltrch\loch\fs22\lang1033 -Version 1.1.1.9} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046\qc{\afs22\rtlch \ltrch\loch\fs22\lang1033 -petrucio@pigasusgames.com} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\rtlch \ltrch\loch -} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\rtlch \ltrch\loch -} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\afs22\rtlch \ltrch\loch\fs22\lang1033 -Thank you for buying the File Browser and Save/Load UI!} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\rtlch \ltrch\loch -} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\afs22\rtlch \ltrch\loch\fs22\lang1033 -The File Browser provides an User Interface to browse for files in the user's filesystem, using the standard Unity GUI system, so it doesn't use any dll (and can run in both Pro or Free versions of Unity), doesn't require any external UI library, and can be styled to have the same Look & Feel as your game.} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\rtlch \ltrch\loch -} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\afs22\rtlch \ltrch\loch\fs22\lang1033 -It shows large previews for image files (jpeg and png), as well as smaller previews in the entry for the files themselves (the height of the file entries can be configured to fine-tune the previews).} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\rtlch \ltrch\loch -} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\afs22\rtlch \ltrch\loch\fs22\lang1033 -It also provides Save and Load mode UIs, including taking and saving screenshots to use as Save Previews.} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\rtlch \ltrch\loch -} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\afs22\rtlch \ltrch\loch\fs22\lang1033 -As of version 1.1, it also previews sound files, with channel previews and FTTWindow visualization.} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\rtlch \ltrch\loch -} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\afs22\rtlch \ltrch\loch\fs22\lang1033 -Notes on supported platforms:} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\afs22\rtlch \ltrch\loch\fs22\lang1033 -- Does not work on webplayers, as these do not have access to the filesystem.} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\afs22\rtlch \ltrch\loch\fs22\lang1033 -- Mobile support is planned for Version 1.2 (no time estimate on that)} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\rtlch \ltrch\loch -} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\rtlch \ltrch\loch -} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\b\afs22\ab\rtlch \ltrch\loch\fs22\lang1033 -Getting started - if you are in a real hurry:} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\rtlch \ltrch\loch -} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\afs22\rtlch \ltrch\loch\fs22\lang1033 -To create a File Browser:} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\afs22\rtlch \ltrch\loch\fs22\lang1033 -1. Simply drag the FileBrowser.cs script into a GameObject} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\afs22\rtlch \ltrch\loch\fs22\lang1033 -2. Implement a function with this signature:} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\hich\af5\dbch\af5\rtlch \ltrch\lang1033\loch\f5 - }{\cf3\hich\af6\dbch\af6\rtlch \ltrch\loch\fs22\lang1033\loch\f6 -void YourCallback (string filename)} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\afs22\rtlch \ltrch\loch\fs22\lang1033 -3. Call }{\cf3\hich\af6\dbch\af6\rtlch \ltrch\loch\fs22\lang1033\loch\f6 -ShowBrowser("A Title", YourCallback);} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\afs22\rtlch \ltrch\loch\fs22\lang1033 -\tab (Or ShowSaveBrowser / ShowLoadBrowser)} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\rtlch \ltrch\loch -} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\rtlch \ltrch\loch -} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\b\afs22\ab\rtlch \ltrch\loch\fs22\lang1033 -Getting properly started} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\rtlch \ltrch\loch -} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\afs22\rtlch \ltrch\loch\fs22\lang1033 -To setup a File Browser, drag the script FileBroser.cs into a GameObject. You can do this in two ways:} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\afs22\rtlch \ltrch\loch\fs22\lang1033 -- You can drag in over the existing GameObject that has the code that will handle the file returned by the browser, and access it by calling }{\cf3\hich\af6\dbch\af6\rtlch \ltrch\loch\fs22\lang1033\loch\f6 -GetComponent()} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\afs22\rtlch \ltrch\loch\fs22\lang1033 -- You can drag it into an empty GameObject to keep things clear and organized, and access it by exposing a public FileBrowser variable in one of your scripts and assigning it via the inspector} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\rtlch \ltrch\loch -} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\afs22\rtlch \ltrch\loch\fs22\lang1033 -To receive results from the FileBrowser when the user clicks Ok or Cancel, implement a callback function receiving a string:} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\cf3\hich\af6\dbch\af6\rtlch \ltrch\loch\fs20\lang1033\loch\f6 -void FileBrowserCallback(string filename) \{} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\cf3\hich\af6\dbch\af6\rtlch \ltrch\loch\fs20\lang1033\loch\f6 -\tab print(filename);\tab \tab // Do something interesting with the file} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\cf3\hich\af6\dbch\af6\rtlch \ltrch\loch\fs20\lang1033\loch\f6 -\}} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\afs22\rtlch \ltrch\loch\fs22\lang1033 -filename will be }{\cf3\hich\af5\dbch\af5\rtlch \ltrch\loch\fs22\lang1033\loch\f5 -null }{\afs22\rtlch \ltrch\loch\fs22\lang1033 -if the user clicks Cancel instead of Ok.} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\rtlch \ltrch\loch -} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\afs22\rtlch \ltrch\loch\fs22\lang1033 -To show the FileBrowser, call one of these functions:} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\cf3\hich\af6\dbch\af6\rtlch \ltrch\loch\fs20\lang1033\loch\f6 -void ShowBrowser (string title, FinishedCallback callback)} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\cf3\hich\af6\dbch\af6\rtlch \ltrch\loch\fs20\lang1033\loch\f6 -void ShowBrowser (string title, FinishedCallback callback, string startingDir, Rect screenRect, string okString)} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\cf3\hich\af6\dbch\af6\rtlch \ltrch\loch\fs20\lang1033\loch\f6 -void ShowSaveBrowser(string title, FinishedCallback callback)} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\cf3\hich\af6\dbch\af6\rtlch \ltrch\loch\fs20\lang1033\loch\f6 -void ShowSaveBrowser(string title, FinishedCallback callback, string saveBaseDir, string saveDataDir, Rect screenRect, Texture2D screenshot)} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\cf3\hich\af6\dbch\af6\rtlch \ltrch\loch\fs20\lang1033\loch\f6 -void ShowLoadBrowser(string title, FinishedCallback callback)} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\cf3\hich\af6\dbch\af6\rtlch \ltrch\loch\fs20\lang1033\loch\f6 -void ShowLoadBrowser(string title, FinishedCallback callback, string saveBaseDir, string saveDataDir, Rect screenRect)} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\rtlch \ltrch\loch -} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\ul\ulc0\afs22\rtlch \ltrch\loch\fs22\lang1033 -Save / Load Browsers:} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\rtlch \ltrch\loch -} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\afs22\rtlch \ltrch\loch\fs22\lang1033 -Save / Load Browsers work by taking screenshots and saving them in one directory (the one which the user will browse), and saving the data files in another directory.} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\afs22\rtlch \ltrch\loch\fs22\lang1033 -The Save Browser can automatically take the screenshot, or a Texture2D can be provided for this purpose. It will save it as a .png file into the directory being browsed, and call the callback with a file named with the same name, without extension, into the data dir.} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\rtlch \ltrch\loch -} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\ul\ulc0\afs22\rtlch \ltrch\loch\fs22\lang1033 -Save example:} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\afs22\rtlch \ltrch\loch\fs22\lang1033 -If you make this call:} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\cf3\hich\af6\dbch\af6\rtlch \ltrch\loch\fs20\lang1033\loch\f6 -ShowSaveBrowser("title", Callback, "savesDir", "savesDir/data", FileBrowser.GetDefaultRect(), null)} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\afs22\rtlch \ltrch\loch\fs22\lang1033 -and the user chooses a name Foo Bar for his save, the callback will get called with the string:} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\cf3\hich\af6\dbch\af6\rtlch \ltrch\loch\fs22\lang1033\loch\f6 -"savesDir/data/Foo Bar"} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\afs22\rtlch \ltrch\loch\fs22\lang1033 -and a .png preview file (at half screen resolutions) will be automatically created at:} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\afs22\rtlch \ltrch\loch\fs22\lang1033 -savesDir/Foo Bar.png} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\rtlch \ltrch\loch -} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\afs22\rtlch \ltrch\loch\fs22\lang1033 -Note: The File Browser doesn't do any actual saving inside the file "savesDir/data/Foo Bar" - that's your responsibility} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\rtlch \ltrch\loch -} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\afs22\rtlch \ltrch\loch\fs22\lang1033 -Parameter descriptions:} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\b\afs22\ab\rtlch \ltrch\loch\fs22\lang1033 -title }{\afs22\rtlch \ltrch\loch\fs22\lang1033 -- The string at the File Browser's window title bar (Duuh)} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\b\afs22\ab\rtlch \ltrch\loch\fs22\lang1033 -callback }{\afs22\rtlch \ltrch\loch\fs22\lang1033 -- Function to call when the File Browser is done} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\b\afs22\ab\rtlch \ltrch\loch\fs22\lang1033 -startingDir }{\afs22\rtlch \ltrch\loch\fs22\lang1033 -- Initial directory the File Browser will start in. Defaults to the current working directory.} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\b\afs22\ab\rtlch \ltrch\loch\fs22\lang1033 -screenRect }{\afs22\rtlch \ltrch\loch\fs22\lang1033 -- Rectangle defining the File Browser's boundaries. Dimensions should not be less than (780x460). Defaults to a centered window occupying 2/3 of the Screen width and height (or more for lower resolutions). Call FileBrowser.GetDefaultRect() to get this default rect.} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\b\afs22\ab\rtlch \ltrch\loch\fs22\lang1033 -okString }{\afs22\rtlch \ltrch\loch\fs22\lang1033 -- the string displayed on the 'Ok' button. Defaults to "Select".} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\b\afs22\ab\rtlch \ltrch\loch\fs22\lang1033 -saveBaseDir }{\afs22\rtlch \ltrch\loch\fs22\lang1033 -- For Save and Load browsers, specifies the directory where the previews will stay. Defaults to "saves".} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\b\afs22\ab\rtlch \ltrch\loch\fs22\lang1033 -saveDataDir }{\afs22\rtlch \ltrch\loch\fs22\lang1033 -- For Save and Load browsers, specifies the directory where the data files will stay. Defaults to "saves/data".} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\b\afs22\ab\rtlch \ltrch\loch\fs22\lang1033 -screenshot }{\afs22\rtlch \ltrch\loch\fs22\lang1033 -- For Save Browsers, specifies a texture to use as the save slot preview screenshot. Defaults to a standard screenshot at half screen resolution to reduce disk space and load times. Pass null to generate this default.} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\rtlch \ltrch\loch -} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\rtlch \ltrch\loch -} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\b\afs22\ab\rtlch \ltrch\loch\fs22\lang1033 -File Browser public options} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\rtlch \ltrch\loch -} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\b\afs22\ab\rtlch \ltrch\loch\fs22\lang1033 -Show Places:}{\afs22\rtlch \ltrch\loch\fs22\lang1033 - Show the leftmost column with the list of drives and special folders (My Pictures, etc). This is needed to enable logical drive changes under Windows.} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\b\afs22\ab\rtlch \ltrch\loch\fs22\lang1033 -Dir Explorer:}{\afs22\rtlch \ltrch\loch\fs22\lang1033 - Allow the user to change directory. When false, hides the top navigation buttons, the places list, and the left directory list.} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\b\afs22\ab\rtlch \ltrch\loch\fs22\lang1033 -Accepts Directories:}{\afs22\rtlch \ltrch\loch\fs22\lang1033 - If true, enables the 'Ok' button even if no file is selected / typed. (Default = false)} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\b\afs22\ab\rtlch \ltrch\loch\fs22\lang1033 -Enable File Delete:}{\afs22\rtlch \ltrch\loch\fs22\lang1033 - If true, the user will be able to delete files from inside the File Browser by pressing the Delete key and then confirming.} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\b\afs22\ab\rtlch \ltrch\loch\fs22\lang1033 -Hide Extensions:}{\afs22\rtlch \ltrch\loch\fs22\lang1033 - Hide or show file extensions} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\b\afs22\ab\rtlch \ltrch\loch\fs22\lang1033 -Show Text Input:}{\afs22\rtlch \ltrch\loch\fs22\lang1033 - If true, shows a text field for the user to type a file name. Always true for Save Browsers. (default = false for others)} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\b\afs22\ab\rtlch \ltrch\loch\fs22\lang1033 -Input Must Exist:}{\afs22\rtlch \ltrch\loch\fs22\lang1033 - Do not enable the 'Ok' button if there's no valid file selection. Always true for Load Browsers.} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\b\afs22\ab\rtlch \ltrch\loch\fs22\lang1033 -Overwrite Warn:}{\afs22\rtlch \ltrch\loch\fs22\lang1033 - If the file selected already exists, pops a confirmation dialog before calling back.} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\b\afs22\ab\rtlch \ltrch\loch\fs22\lang1033 -File Masks:}{\afs22\rtlch \ltrch\loch\fs22\lang1033 - comma or semicolon-separated list of accepted file masks. Files not matching any pattern will not be shown.} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\b\afs22\ab\rtlch \ltrch\loch\fs22\lang1033 -Default Dir:}{\afs22\rtlch \ltrch\loch\fs22\lang1033 - Default starting dir for this browser, when using one of the simpler show functions.} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\b\afs22\ab\rtlch \ltrch\loch\fs22\lang1033 -Remember Last Dir:}{\afs22\rtlch \ltrch\loch\fs22\lang1033 - If true, restarts at the same directory as when the user last clicked Ok.} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\rtlch \ltrch\loch -} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\ul\ulc0\afs22\rtlch \ltrch\loch\fs22\lang1033 -Look and Feel customization options:} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\rtlch \ltrch\loch -} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\b\afs22\ab\rtlch \ltrch\loch\fs22\lang1033 -Skin:}{\afs22\rtlch \ltrch\loch\fs22\lang1033 - The skin to use for the browser. Default to the currently set GUI.skin. An optional custom style "List Item", if provided, will be used to style the browsers items (if not, the Label style will be used)} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\b\afs22\ab\rtlch \ltrch\loch\fs22\lang1033 -Item Hover Image:}{\afs22\rtlch \ltrch\loch\fs22\lang1033 - An image to use on top of hovered items. Will get stretched indefinetely on it's width.} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\b\afs22\ab\rtlch \ltrch\loch\fs22\lang1033 -Item Hover Text Color:}{\afs22\rtlch \ltrch\loch\fs22\lang1033 - Color to use for hovered items. Leave at (255,0,255) to use the Label style hover color.} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\b\afs22\ab\rtlch \ltrch\loch\fs22\lang1033 -Item Selected Image / Text Color:}{\afs22\rtlch \ltrch\loch\fs22\lang1033 - Same as above, but for the selected item} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\b\afs22\ab\rtlch \ltrch\loch\fs22\lang1033 -Dir Image:}{\afs22\rtlch \ltrch\loch\fs22\lang1033 - Image to use for directory icons} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\b\afs22\ab\rtlch \ltrch\loch\fs22\lang1033 -File Icon:}{\afs22\rtlch \ltrch\loch\fs22\lang1033 - Image to use for non-jpeg or png file icons} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\b\afs22\ab\rtlch \ltrch\loch\fs22\lang1033 -Dirs Height:}{\afs22\rtlch \ltrch\loch\fs22\lang1033 - Height for each directory entry} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\b\afs22\ab\rtlch \ltrch\loch\fs22\lang1033 -Files Height:}{\afs22\rtlch \ltrch\loch\fs22\lang1033 - Height for each file entry} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\b\afs22\ab\rtlch \ltrch\loch\fs22\lang1033 -Places HD Icon:}{\afs22\rtlch \ltrch\loch\fs22\lang1033 - Icon to use for the 'Drives' button} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\b\afs22\ab\rtlch \ltrch\loch\fs22\lang1033 -Places Desktop Icon:}{\afs22\rtlch \ltrch\loch\fs22\lang1033 - Icon to use for the 'Desktop' special directory button} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\b\afs22\ab\rtlch \ltrch\loch\fs22\lang1033 -Places My Docs Icon:}{\afs22\rtlch \ltrch\loch\fs22\lang1033 - Icon to use for the 'My Documents' special directory button} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\b\afs22\ab\rtlch \ltrch\loch\fs22\lang1033 -Places My Pics Icon:}{\afs22\rtlch \ltrch\loch\fs22\lang1033 - Icon to use for the 'My Pictures' special directory button} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\rtlch \ltrch\loch -} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\ul\ulc0\afs22\rtlch \ltrch\loch\fs22\lang1033 -Sound Preview customization options:} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\rtlch \ltrch\loch -} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\b\afs22\ab\rtlch \ltrch\loch\fs22\lang1033 -ASource:}{\afs22\rtlch \ltrch\loch\fs22\lang1033 - AudioSource to use for previewing (if not set, tries to find an AudioSource in: a. itself, b. it's childen, or c. the scene)} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\b\afs22\ab\rtlch \ltrch\loch\fs22\lang1033 -Fall Speed:}{\afs22\rtlch \ltrch\loch\fs22\lang1033 - Speed in which the spectrum visualization vertices fall (in window-heights per second)} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\b\afs22\ab\rtlch \ltrch\loch\fs22\lang1033 -Samples Size:}{\afs22\rtlch \ltrch\loch\fs22\lang1033 - spectrum visualization vertice count (power of 2, >= 64)} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\b\afs22\ab\rtlch \ltrch\loch\fs22\lang1033 -Bg Color:}{\afs22\rtlch \ltrch\loch\fs22\lang1033 - Sound preview rectangles background} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\b\afs22\ab\rtlch \ltrch\loch\fs22\lang1033 -Border Color:}{\afs22\rtlch \ltrch\loch\fs22\lang1033 - Sound preview rectangles border} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\b\afs22\ab\rtlch \ltrch\loch\fs22\lang1033 -Samples Color:}{\afs22\rtlch \ltrch\loch\fs22\lang1033 - Color used to draw the audio clip's samples and spectrum} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\b\afs22\ab\rtlch \ltrch\loch\fs22\lang1033 -Markers Color:}{\afs22\rtlch \ltrch\loch\fs22\lang1033 - Color used to draw the Play Bar and the spectrum visualization vertices} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\b\afs22\ab\rtlch \ltrch\loch\fs22\lang1033 -Sound Preview Vert Offset:}{\afs22\rtlch \ltrch\loch\fs22\lang1033 - Vertical offset, starting from the top of the File Browser window, to draw the sound previews. May need to be changed depending on the skin being used.} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\rtlch \ltrch\loch -} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\rtlch \ltrch\loch -} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\b\afs22\ab\rtlch \ltrch\loch\fs22\lang1033 -Support and Feedback} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\rtlch \ltrch\loch -} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\afs22\rtlch \ltrch\loch\fs22\lang1033 -If you have any questions, suggestions, comments or feature requests:} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\afs22\rtlch \ltrch\loch\fs22\lang1033 -- email petrucio@pigasusgames.com} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\afs22\rtlch \ltrch\loch\fs22\lang1033 -- post on the official thread: }{{\field{\*\fldinst HYPERLINK "http://forum.unity3d.com/threads/154049-File-Browser-amp-Save-Load-UI" }\cf2\ul\ulc0\langfe255\afs22{\fldrslt \cf2\ul\ulc0\langfe255\lang255\rtlch \ltrch\loch\fs22\lang1033 -http://forum.unity3d.com/threads/154049-File-Browser-amp-Save-Load-UI}}} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046{\afs22\rtlch \ltrch\loch\fs22\lang1033 -- or PM 'Petrucio' on the Unity forums} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046\sl240\slmult1{\rtlch \ltrch\loch -} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046\sl240\slmult1{\rtlch \ltrch\loch -} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046\sl240\slmult1{\b\afs22\ab\rtlch \ltrch\loch\fs22\lang1033 -Change Log:} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046\sl240\slmult1{\rtlch \ltrch\loch -} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046\sl240\slmult1{\afs22\rtlch \ltrch\loch\fs22\lang1033 -1.1.1.10, Feb-19-2014:} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046\sl240\slmult1{\afs22\rtlch \ltrch\loch\fs22\lang1033 -- Added: Tweak styles on the fly with }{\hich\af6\dbch\af6\rtlch \ltrch\loch\fs22\loch\f6 -REFRESH_STYLES_EVERY_FRAME = true} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046\sl240\slmult1{\afs22\rtlch \ltrch\loch\fs22\lang1033 -- Minor fixes and improvements} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046\sl240\slmult1{\afs22\rtlch \ltrch\loch\fs22\lang1033 -} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046\sl240\slmult1{\afs22\rtlch \ltrch\loch\fs22\lang1033 -1.1.0.9, Apr-17-2013:\line - Performance: Added thumbnail caching\line - Other minor fixes and improvements} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046\sl240\slmult1{\afs22\rtlch \ltrch\loch\fs22\lang1033 -\line 1.1.0.7, Jan-08-2013:} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046\sl240\slmult1{\rtlch \ltrch\loch -- Added: Sound files Previewer (major)} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046\sl240\slmult1{\rtlch \ltrch\loch -- Added: Remember Last Dir option} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046\sl240\slmult1{\rtlch \ltrch\loch -- Fixed: MacOS / Linux path separator issues} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046\sl240\slmult1{\rtlch \ltrch\loch -- Several other minor fixes and improvements} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046\sl240\slmult1{\rtlch \ltrch\loch -} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046\sl240\slmult1{\afs22\rtlch \ltrch\loch\fs22\lang1033 -1.0.0.6, Oct-08-2012:} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046\sl240\slmult1{\afs22\rtlch \ltrch\loch\fs22\lang1033 -- Initial Release} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046\sl240\slmult1{\rtlch \ltrch\loch -} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046\sl240\slmult1{{\*\bkmkstart __DdeLink__0_914678638}{\*\bkmkend __DdeLink__0_914678638}{\*\bkmkstart __DdeLink__0_914678638}{\*\bkmkend __DdeLink__0_914678638}\rtlch \ltrch\loch -} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046\sl240\slmult1{\rtlch \ltrch\loch -\line } -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046\sl240\slmult1{\rtlch \ltrch\loch -} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046\sl240\slmult1{\rtlch \ltrch\loch -} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046\sl240\slmult1{\rtlch \ltrch\loch -} -\par \pard\plain \s0{\*\hyphen2\hyphlead2\hyphtrail2\hyphmax0}\nowidctlpar\cf0\kerning1\hich\af3\langfe2052\dbch\af3\afs24\lang1081\loch\f3\fs24\lang1046\sl240\slmult1{\rtlch \ltrch\loch -} -\par } \ No newline at end of file diff --git a/Assets/FileBrowser/internals/GLUtils.cs b/Assets/FileBrowser/internals/GLUtils.cs deleted file mode 100644 index b55d5d52..00000000 --- a/Assets/FileBrowser/internals/GLUtils.cs +++ /dev/null @@ -1,125 +0,0 @@ -using UnityEngine; -using System.Collections; - -public static class GLUtils { - - //========================================================================= - static Material glMaterial = null; - private static Material GetGLMaterial() { - if (glMaterial != null) return glMaterial; - glMaterial = new Material( "Shader \"Lines/Colored Blended\" {" + - "SubShader { Pass { " + - " Blend SrcAlpha OneMinusSrcAlpha " + - " ZWrite Off Cull Off Fog { Mode Off } " + - " BindChannels {" + - " Bind \"vertex\", vertex Bind \"color\", color }" + - "} } }" ); - return glMaterial; - } - - //============================================================================= - // Render lines in OpenGL - Call these functions inside a PostRender pass - // Points in screen coordinates - public static void RenderLines(Vector2[] points, Color color) { - RenderLines(points, color, false); - } - // disconnectSegments: if true, do not connect the end of the previous segment with the start of the next one - public static void RenderLines(Vector2[] points, Color color, bool disconnectSegments) - { - if (points.Length < 2) return; - - GetGLMaterial().SetPass(0); - GL.PushMatrix(); - GL.LoadPixelMatrix(); - - GL.Begin(GL.LINES); - GL.Color(color); - int increment = disconnectSegments ? 2 : 1; - for (int i = 0; i < points.Length - 1; i += increment) { - GL.Vertex3(points[i].x, points[i].y +1.5f, 0); - GL.Vertex3(points[i+1].x, points[i+1].y+1.5f, 0); - } - GL.End(); - GL.PopMatrix(); - } - - //============================================================================= - // Similar to RenderLines, but make segments in pairs (0-1, 2-3, 4-5, etc) - public static void RenderSegments(Vector2[] points, Color color) { - RenderLines(points, color, true); - } - - //============================================================================= - // Render vertices in OpenGL - Call these functions inside a PostRender pass - // Points in screen coordinates - public static void RenderVertices(Vector2[] points, Color color) - { - if (points.Length < 1) return; - - GetGLMaterial().SetPass(0); - GL.PushMatrix(); - GL.LoadPixelMatrix(); - - GL.Begin(GL.LINES); - GL.Color(color); - for (int i = 0; i < points.Length; i++) - { - float x = ((int) points[i].x) + 0.5f; - float y = ((int) points[i].y) + 0.5f; - - Vector2 pos1 = new Vector2(x, y-0f); - Vector2 pos2 = new Vector2(x+1f, y+1); - Vector2 pos3 = new Vector2(x, y+2f); - Vector2 pos4 = new Vector2(x-1f, y+1); - - GL.Vertex(pos1); - GL.Vertex(pos2); - GL.Vertex(pos2); - GL.Vertex(pos3); - GL.Vertex(pos3); - GL.Vertex(pos4); - GL.Vertex(pos4); - GL.Vertex(pos1); - } - GL.End(); - GL.PopMatrix(); - } - - //============================================================================= - // Renders a rectangle in OpenGL (call on a OnPostRender; screen coords) - public static void RenderRect(Rect rect, Color bgColor, Color borderColor) - { - Vector2 pos1 = new Vector2(rect.xMin, rect.yMin + 1.5f); - Vector2 pos2 = new Vector2(rect.xMax, rect.yMin + 1.5f); - Vector2 pos3 = new Vector2(rect.xMax, rect.yMax + 1.5f); - Vector2 pos4 = new Vector2(rect.xMin, rect.yMax + 1.5f); - - GetGLMaterial().SetPass(0); - GL.PushMatrix(); - GL.LoadPixelMatrix(); - - GL.Begin(GL.QUADS); - GL.Color(bgColor); - GL.Vertex(pos1); - GL.Vertex(pos2); - GL.Vertex(pos3); - GL.Vertex(pos4); - GL.End(); - - GL.Begin(GL.LINES); - GL.Color(borderColor); - GL.Vertex(pos1); - GL.Vertex(pos2); - GL.Vertex(pos2); - GL.Vertex(pos3); - GL.Vertex(pos3); - GL.Vertex(pos4); - pos4.y += 0.5f; - GL.Vertex(pos4); - GL.Vertex(pos1); - GL.End(); - - GL.PopMatrix(); - } - -} diff --git a/Assets/FileBrowser/internals/GUILayoutx.cs b/Assets/FileBrowser/internals/GUILayoutx.cs deleted file mode 100644 index 918bf992..00000000 --- a/Assets/FileBrowser/internals/GUILayoutx.cs +++ /dev/null @@ -1,89 +0,0 @@ -//------------------------------------------------------------------------------ -// Based on ImprovedSelectionList, by Daniel Brauer: -// http://wiki.unity3d.com/index.php/ImprovedSelectionList -// Licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License. -// -// Modifications by Petrucio: -// -Added a default List Item style when one is not present in the current GUI style -// -Added callback for item selection (single click) -// -Added support for touches / mobile -// -Refactored duplicated code into a single function -// -Added Pablo Bollansée (The Oddler)'s double click fix -//------------------------------------------------------------------------------ -using UnityEngine; - -public class GUILayoutx { - - private static GUIStyle defaultListItemStyle = new GUIStyle(GUI.skin.label); - - public delegate void DoubleClickCallback(int index); - public delegate void SingleClickCallback(int index); - - public static float maxListWidth = 10000; - - private static GUIStyle getListItemStyle(string styleStr) { - GUIStyle style = GUI.skin.FindStyle(styleStr); - if (style != null) return style; - - defaultListItemStyle.fixedHeight = 20; - return defaultListItemStyle; - } - - public static int SelectionList(int selected, GUIContent[] list) { - return SelectionList(selected, list, getListItemStyle("List Item"), null, null); - } - public static int SelectionList(int selected, GUIContent[] list, GUIStyle elementStyle) { - return SelectionList(selected, list, elementStyle, null, null); - } - public static int SelectionList(int selected, GUIContent[] list, DoubleClickCallback callback) { - return SelectionList(selected, list, getListItemStyle("List Item"), callback, null); - } - public static int SelectionList(int selected, GUIContent[] list, DoubleClickCallback callback, SingleClickCallback selCallback) { - return SelectionList(selected, list, getListItemStyle("List Item"), callback, selCallback); - } - - public static int SelectionList(int selected, string[] list) { - return SelectionList(selected, list, getListItemStyle("List Item"), null, null); - } - public static int SelectionList(int selected, string[] list, GUIStyle elementStyle) { - return SelectionList(selected, list, elementStyle, null, null); - } - public static int SelectionList(int selected, string[] list, DoubleClickCallback callback) { - return SelectionList(selected, list, getListItemStyle("List Item"), callback, null); - } - public static int SelectionList(int selected, string[] list, DoubleClickCallback callback, SingleClickCallback selCallback) { - return SelectionList(selected, list, getListItemStyle("List Item"), callback, selCallback); - } - - public static int SelectionList(int selected, GUIContent[] list, GUIStyle elementStyle, DoubleClickCallback callback, SingleClickCallback selCallback) { - for (int i = 0; i < list.Length; ++i) { - Rect elementRect = GUILayoutUtility.GetRect(list[i], elementStyle); - if (elementRect.width > maxListWidth) elementRect.width = maxListWidth; - - bool hover = elementRect.Contains(Event.current.mousePosition); - if (hover && Event.current.type == EventType.MouseDown && Event.current.clickCount == 1) { - selected = i; - Event.current.Use(); - if (selCallback != null) { - selCallback(i); - } - } else if (hover && callback != null && Event.current.type == EventType.MouseDown && Event.current.clickCount == 2) { - callback(i); - Event.current.Use(); - } else if (Event.current.type == EventType.Repaint) { - elementStyle.Draw(elementRect, list[i], hover, false, i == selected, false); - } - } - return selected; - } - - public static int SelectionList(int selected, string[] list, GUIStyle elementStyle, DoubleClickCallback callback, SingleClickCallback selCallback) { - GUIContent[] contentList = new GUIContent[list.Length]; - for (int i = 0; i < list.Length; ++i) { - contentList[i] = new GUIContent(list[i]); - } - return SelectionList(selected, contentList, elementStyle, callback, selCallback); - } - -} - diff --git a/Assets/FileBrowser/internals/SoundViewer.cs b/Assets/FileBrowser/internals/SoundViewer.cs deleted file mode 100644 index 862e860f..00000000 --- a/Assets/FileBrowser/internals/SoundViewer.cs +++ /dev/null @@ -1,252 +0,0 @@ -using UnityEngine; -using System.Collections; - -//============================================================================= -public class SoundViewer : MonoBehaviour -{ - // Visualization rectangle, in normalized coordinates (0-1) - public Rect viewRect = new Rect(0.25f, 0.25f, 0.5f, 0.5f); - - [System.Serializable] - public class SoundViewerConfig { - public bool previewSounds = true; - - // An AudioSource object so the music can be played - public AudioSource aSource; - // Speed in which the dots fall (in view rect height per second) - public float fallSpeed = 1f; - // Number of point viewers (power of two) - public int samplesSize = 128; - - // Customize viewing colors - public Color bgColor = new Color(0.5f, 0.5f, 0.5f, 0.5f); - public Color borderColor = Color.black; - public Color samplesColor = Color.blue; - public Color markersColor = Color.black; - - public FFTWindow fftWindow = FFTWindow.BlackmanHarris; - } - - public SoundViewerConfig configs; - - // A float array that stores the audio samples - private float[] samples; - - // FTTWindow view - private Vector2[] vertices; // Vertices of the actual position of the samples - private Vector2[] viewers; // Vertices with With falling inertia - - // Clip view - private Vector2[] verticesLeft; // Vertices of the actual position of the samples - private Vector2[] verticesRight; - private Vector2[] playingBar; // Vertical bar showing the play location of the current clip - - //============================================================================= - // Returns an actual screen visualization rect, from the normalized rect area in this.viewRect - // The total view rect is divided in viewParts parts, and this function returns the part pertaining to partIndex (zero-based) - Rect __GetRect(float partIndex, float parts, float myPart) { - Rect view = this.viewRect; - int partH = (int)(view.height * Screen.height * (1.0f / parts)); - int y = (int)(view.y * Screen.height + partH * partIndex); - return new Rect((int)(view.x * Screen.width), y, (int)(view.width * Screen.width), (int)(partH * myPart)); - } - Rect GetLeftRect(bool stereo) { return this.__GetRect(1.1f, 3.1f, stereo ? 1.0f : 2.0f); } - Rect GetRightRect() { return this.__GetRect(2.1f, 3.1f, 1.0f); } - Rect GetFFTRect() { return this.__GetRect(0.0f, 3.1f, 1.0f); } - - //============================================================================= - // Plays the audio clip one time, then disable the previewer when done playing - public void PreviewClip(AudioClip clip) { - this.StopCoroutine("__PreviewClip"); - this.configs.aSource.Stop(); - this.configs.aSource.loop = false; - this.configs.aSource.clip = clip; - this.StartCoroutine("__PreviewClip"); - } - IEnumerator __PreviewClip() { - while(!this.configs.aSource.clip.isReadyToPlay) { - yield return null; - } - this.ResetClipView(this.configs.aSource.clip); - this.configs.aSource.Play(); - } - - //============================================================================= - // Use this instead of setting .enable directly, to stop any playing samples - public void Disable() { - if (this.configs.aSource && this.configs.aSource.clip != null) { - this.configs.aSource.Stop(); - } - this.enabled = false; - } - - //============================================================================= - public void Start() { - if (!this.configs.previewSounds) return; - this.StartCoroutine(this.__Start()); - } - private IEnumerator __Start() - { - if (!this.configs.aSource) this.configs.aSource = this.GetComponent(); - if (!this.configs.aSource) this.configs.aSource = this.GetComponentInChildren(); - if (!this.configs.aSource) this.configs.aSource = GameObject.FindObjectOfType(typeof(AudioSource)) as AudioSource; - if (!this.configs.aSource) { - Debug.LogError("No Audio Source in the scene found to use for Sound Previews"); - yield break; - } - - if (this.configs.aSource.clip && this.enabled) { - this.ResetClipView(this.configs.aSource.clip); - } - - while(true) - { - yield return new WaitForEndOfFrame(); - if (!enabled) continue; - - if (this.configs.aSource.isPlaying) { - GLUtils.RenderLines (this.vertices, this.configs.samplesColor); - GLUtils.RenderVertices(this.viewers, this.configs.markersColor); - GLUtils.RenderRect (this.GetFFTRect(), this.configs.bgColor, this.configs.borderColor); - } - bool stereo = this.verticesRight != null; - GLUtils.RenderLines(this.verticesLeft, this.configs.samplesColor); - GLUtils.RenderRect (this.GetLeftRect(stereo), this.configs.bgColor, this.configs.borderColor); - if (stereo) { - GLUtils.RenderLines(this.verticesRight, this.configs.samplesColor); - GLUtils.RenderRect (this.GetRightRect(), this.configs.bgColor, this.configs.borderColor); - } - GLUtils.RenderLines(this.playingBar, this.configs.markersColor); - } - } - - //============================================================================= - // Calculates the 'clip view' for the given AudioClip - // This is an intensive operation, but only gets done once per clip - // - // TODO_WISH: Save this to a texture instead of vertices, for faster and drawing, and with more precision - void ResetClipView(AudioClip clip) - { - int size = Mathf.NextPowerOfTwo(this.configs.samplesSize); - if (size < 64) size = 64; - - this.samples = new float[size]; - this.vertices = new Vector2[size]; - this.viewers = new Vector2[size]; - this.playingBar = new Vector2[4]; - - bool stereo = clip.channels > 1; - Rect screenViewRect = this.GetLeftRect(stereo); - float viewX = screenViewRect.x; - float viewY = screenViewRect.y; - float viewW = screenViewRect.width; - float viewH = screenViewRect.height; - - // A sample rate of 100Hz should give us close enough results while keeping acceptable performance on long samples - // Ideally we should render this info baked in a texture for this, but that'd be too much trouble to go to using unity - int sampleRate = 1000; - if (clip.length > 5) sampleRate = 300; - if (clip.length > 30) sampleRate = 100; - if (clip.length < 0.5f) sampleRate = 3000; - if (clip.length < 0.05f) sampleRate = clip.frequency; - int sampleSize = (int) (sampleRate * clip.length); - - // Read samples info - float[] clipSamples = new float[clip.samples * clip.channels]; - clip.GetData(clipSamples, 0); - - this.verticesLeft = new Vector2[sampleSize]; - this.verticesRight = null; - if (stereo) { - this.verticesRight = new Vector2[sampleSize]; - } - - // Plot wave form - for (int i = 0; i < sampleSize; i++) - { - int sampleIdx = (int)(clip.samples / (float)sampleSize * i * clip.channels); - float x = viewW / sampleSize * i + viewX; - - float normalVal = clipSamples[sampleIdx] * 0.5f + 0.5f; - float y = normalVal * viewH + viewY; - this.verticesLeft[i] = new Vector2(x, y); - - if (stereo) { - normalVal = clipSamples[sampleIdx+1] * 0.5f + 0.5f; - float y2 = normalVal * viewH + viewY + viewH; - this.verticesRight[i] = new Vector2(x, y2); - } - } - - } - - //============================================================================= - // Updates the frequency profile for the current playing frame - void Update() - { - if (!enabled || !this.configs.previewSounds) return; - - AudioSource aSource = this.configs.aSource; - - Rect screenViewRect = this.GetFFTRect(); // Get lower-part rectangle - float viewX = screenViewRect.x; - float viewY = screenViewRect.y + 5; - float viewW = screenViewRect.width; - float viewH = screenViewRect.height - 10; - - if (aSource.isPlaying) - { - // Obtain the samples from the frequency bands of the attached AudioSource - aSource.GetSpectrumData(this.samples, 0, this.configs.fftWindow); - - Vector2 gravity = new Vector3(0.0f, this.configs.fallSpeed * viewH); - for (int i = 0; i < this.samples.Length; i++) - { - // Change this viewers position Y according to the current sample (0 - 50) - float val = Mathf.Clamp(samples[i] * (50 + i * i), 0, 25) * 2; - if (val < 0.5f) val = 0; // Avoids flickering at the bottom bar - - float x = viewW / this.samples.Length * (i + 0.5f) + viewX; - float y = val / 50.0f * viewH + viewY; - Vector2 newPos = new Vector3(x, y); - - this.vertices[i] = newPos; - - if (y >= this.viewers[i].y) { - this.viewers[i] = newPos; - } else { - this.viewers[i] -= gravity * Time.deltaTime; - this.viewers[i].y = Mathf.Max(viewY, this.viewers[i].y); - } - } - } - - Rect playRect = this.GetLeftRect(false); - viewY = playRect.y + 1; - viewH = playRect.height - 1; - - // Update the position of the 'play bar' - float t = 0; - if (aSource.isPlaying) { - t = aSource.time / aSource.clip.length; - } - this.playingBar[0] = new Vector2((int)(viewX + t * viewW), (int)(viewY)); - this.playingBar[1] = new Vector2((int)(viewX + t * viewW), (int)(viewY + viewH)); - this.playingBar[2] = new Vector2(this.playingBar[0].x + 1, this.playingBar[0].y); // two pixels - this.playingBar[3] = new Vector2(this.playingBar[1].x + 1, this.playingBar[1].y); - - // If the user clicks over the play bar, jump to that position - if (Input.GetMouseButtonDown(0)) { - Vector2 mousePos = Input.mousePosition; - if (mousePos.x > viewX && mousePos.x < (viewX + viewW) && - mousePos.y > viewY && mousePos.y < (viewY + viewH)) - { - // Note: time wouldn't replect actual time on compressed audio - timeSamples is better - aSource.timeSamples = (int) ((mousePos.x - viewX) / viewW * aSource.clip.samples); - } - } - - } - -} - diff --git a/Assets/FlipUIElement.cs b/Assets/FlipUIElement.cs new file mode 100644 index 00000000..011cebea --- /dev/null +++ b/Assets/FlipUIElement.cs @@ -0,0 +1,11 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class FlipUIElement : MonoBehaviour +{ + public void FlipUiElement(GameObject Obj) + { + Obj.SetActive(!Obj.active); + } +} diff --git a/Assets/Main Canvas.prefab b/Assets/Main Canvas.prefab new file mode 100644 index 00000000..4bff69bf Binary files /dev/null and b/Assets/Main Canvas.prefab differ diff --git a/Assets/Main Canvas.prefab.meta b/Assets/Main Canvas.prefab.meta new file mode 100644 index 00000000..98baee7c --- /dev/null +++ b/Assets/Main Canvas.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 550b3105395d6af4893f2808748ae4f0 +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/MainScene.unity b/Assets/MainScene.unity index 57823e6c..775c0554 100644 Binary files a/Assets/MainScene.unity and b/Assets/MainScene.unity differ diff --git a/Assets/MainScene/LightingData.asset b/Assets/MainScene/LightingData.asset index adb55715..bc7ead43 100644 Binary files a/Assets/MainScene/LightingData.asset and b/Assets/MainScene/LightingData.asset differ diff --git a/Assets/MainScene/LightingData.asset.meta b/Assets/MainScene/LightingData.asset.meta index e02e5d60..edcf5969 100644 --- a/Assets/MainScene/LightingData.asset.meta +++ b/Assets/MainScene/LightingData.asset.meta @@ -1,10 +1,8 @@ fileFormatVersion: 2 guid: b3d6613445502a54fadf38b0b944a51e -timeCreated: 1530552133 -licenseType: Pro NativeFormatImporter: externalObjects: {} - mainObjectFileID: 25800000 + mainObjectFileID: 112000000 userData: assetBundleName: assetBundleVariant: diff --git a/Assets/MainScene/ReflectionProbe-0.exr b/Assets/MainScene/ReflectionProbe-0.exr index e37ccd29..0638ee41 100644 Binary files a/Assets/MainScene/ReflectionProbe-0.exr and b/Assets/MainScene/ReflectionProbe-0.exr differ diff --git a/Assets/MainScene/ReflectionProbe-0.exr.meta b/Assets/MainScene/ReflectionProbe-0.exr.meta index da532443..6ea2b112 100644 --- a/Assets/MainScene/ReflectionProbe-0.exr.meta +++ b/Assets/MainScene/ReflectionProbe-0.exr.meta @@ -1,12 +1,9 @@ fileFormatVersion: 2 guid: 9e465a3418e37f542873f8deb0657be5 -timeCreated: 1530552132 -licenseType: Pro TextureImporter: - fileIDToRecycleName: - 8900000: generatedCubemap + internalIDToNameTable: [] externalObjects: {} - serializedVersion: 4 + serializedVersion: 10 mipmaps: mipMapMode: 0 enableMipMap: 1 @@ -24,6 +21,8 @@ TextureImporter: heightScale: 0.25 normalMapFilter: 0 isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 grayScaleToAlpha: 0 generateCubemap: 6 cubemapConvolution: 1 @@ -54,11 +53,13 @@ TextureImporter: spriteTessellationDetail: -1 textureType: 0 textureShape: 2 + singleChannelComponent: 0 maxTextureSizeSet: 0 compressionQualitySet: 0 textureFormatSet: 0 platformSettings: - - buildTarget: DefaultTexturePlatform + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform maxTextureSize: 2048 resizeAlgorithm: 0 textureFormat: -1 @@ -68,12 +69,23 @@ TextureImporter: allowsAlphaSplitting: 0 overridden: 0 androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 spriteSheet: serializedVersion: 2 sprites: [] outline: [] physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] spritePackingTag: + pSDRemoveMatte: 0 + pSDShowRemoveMatteOption: 0 userData: assetBundleName: assetBundleVariant: diff --git a/Assets/MainScene_Profiles.meta b/Assets/MainScene_Profiles.meta new file mode 100644 index 00000000..80b5fd2d --- /dev/null +++ b/Assets/MainScene_Profiles.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: ccf23c25d76140449815b040bfb128aa +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/MainScene_Profiles/Main Camera Profile.asset b/Assets/MainScene_Profiles/Main Camera Profile.asset new file mode 100644 index 00000000..7bcd986f Binary files /dev/null and b/Assets/MainScene_Profiles/Main Camera Profile.asset differ diff --git a/Assets/MainScene_Profiles/Main Camera Profile.asset.meta b/Assets/MainScene_Profiles/Main Camera Profile.asset.meta new file mode 100644 index 00000000..0ec18e29 --- /dev/null +++ b/Assets/MainScene_Profiles/Main Camera Profile.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 57a4cc51dbe85b74aa896f7f6bf76180 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Materials/AO_Preview.mat b/Assets/Materials/AO_Preview.mat index f364cbc2..ea474221 100644 Binary files a/Assets/Materials/AO_Preview.mat and b/Assets/Materials/AO_Preview.mat differ diff --git a/Assets/Materials/Alignment_Material.mat b/Assets/Materials/Alignment_Material.mat index 30b88c41..d71f0f97 100644 Binary files a/Assets/Materials/Alignment_Material.mat and b/Assets/Materials/Alignment_Material.mat differ diff --git a/Assets/Materials/Edge_Preview.mat b/Assets/Materials/Edge_Preview.mat index 70cd8db9..1e44c2a8 100644 Binary files a/Assets/Materials/Edge_Preview.mat and b/Assets/Materials/Edge_Preview.mat differ diff --git a/Assets/Materials/Edit_Diffuse_Preview.mat b/Assets/Materials/Edit_Diffuse_Preview.mat index 80b49a85..866697d0 100644 Binary files a/Assets/Materials/Edit_Diffuse_Preview.mat and b/Assets/Materials/Edit_Diffuse_Preview.mat differ diff --git a/Assets/Materials/Height_Preview.mat b/Assets/Materials/Height_Preview.mat index 4cee03cb..374a5a2a 100644 Binary files a/Assets/Materials/Height_Preview.mat and b/Assets/Materials/Height_Preview.mat differ diff --git a/Assets/Materials/Metallic_Preview.mat b/Assets/Materials/Metallic_Preview.mat index ecc36e93..dc5bc1b5 100644 Binary files a/Assets/Materials/Metallic_Preview.mat and b/Assets/Materials/Metallic_Preview.mat differ diff --git a/Assets/Materials/Normal_Preview.mat b/Assets/Materials/Normal_Preview.mat index 31042ed9..27754d61 100644 Binary files a/Assets/Materials/Normal_Preview.mat and b/Assets/Materials/Normal_Preview.mat differ diff --git a/Assets/Materials/Skybox.mat b/Assets/Materials/Skybox.mat index a5759472..47fb4cac 100644 Binary files a/Assets/Materials/Skybox.mat and b/Assets/Materials/Skybox.mat differ diff --git a/Assets/Materials/Smoothness_Preview.mat b/Assets/Materials/Smoothness_Preview.mat index ffdef11f..1893175f 100644 Binary files a/Assets/Materials/Smoothness_Preview.mat and b/Assets/Materials/Smoothness_Preview.mat differ diff --git a/Assets/MouseWatcher.cs b/Assets/MouseWatcher.cs new file mode 100644 index 00000000..2ff0ab07 --- /dev/null +++ b/Assets/MouseWatcher.cs @@ -0,0 +1,19 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.EventSystems; + +public class MouseWatcher : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler +{ + public void OnPointerEnter(PointerEventData eventData) + { + this.gameObject.SetActive(true); + + } + + //Detect when Cursor leaves the GameObject + public void OnPointerExit(PointerEventData eventData) + { + this.gameObject.SetActive(false); + } +} diff --git a/Assets/OBJ-IO.meta b/Assets/OBJ-IO.meta index 21da7621..885157c8 100644 --- a/Assets/OBJ-IO.meta +++ b/Assets/OBJ-IO.meta @@ -1,9 +1,8 @@ fileFormatVersion: 2 -guid: f460244cc224844489a15c5ba41d24ef +guid: 8cc1f238b81a847b5a74f6173dbb8a21 folderAsset: yes -timeCreated: 1432869564 -licenseType: Pro DefaultImporter: + externalObjects: {} userData: assetBundleName: assetBundleVariant: diff --git a/Assets/OBJ-IO/Editor.meta b/Assets/OBJ-IO/Editor.meta index 25741c41..72a8b3bb 100644 --- a/Assets/OBJ-IO/Editor.meta +++ b/Assets/OBJ-IO/Editor.meta @@ -1,9 +1,8 @@ fileFormatVersion: 2 -guid: 5c86e6fe65d4e4946b243172e73ba161 +guid: 5681dd42115184c74aeeba051dbf328b folderAsset: yes -timeCreated: 1432869564 -licenseType: Pro DefaultImporter: + externalObjects: {} userData: assetBundleName: assetBundleVariant: diff --git a/Assets/OBJ-IO/Editor/OBJEditor.cs.meta b/Assets/OBJ-IO/Editor/OBJEditor.cs.meta index edb50dcb..7800fa4e 100644 --- a/Assets/OBJ-IO/Editor/OBJEditor.cs.meta +++ b/Assets/OBJ-IO/Editor/OBJEditor.cs.meta @@ -1,6 +1,7 @@ fileFormatVersion: 2 guid: 5cb377fb273c8634296cc421905b1d34 MonoImporter: + externalObjects: {} serializedVersion: 2 defaultReferences: [] executionOrder: 0 diff --git a/Assets/OBJ-IO/Examples.meta b/Assets/OBJ-IO/Examples.meta index f3f814ee..6bbd8c05 100644 --- a/Assets/OBJ-IO/Examples.meta +++ b/Assets/OBJ-IO/Examples.meta @@ -1,9 +1,8 @@ fileFormatVersion: 2 -guid: 33368388f581b994fab7f5ef248c0f63 +guid: 20713fdc3f9ab41ad8493b8513679701 folderAsset: yes -timeCreated: 1432869564 -licenseType: Pro DefaultImporter: + externalObjects: {} userData: assetBundleName: assetBundleVariant: diff --git a/Assets/OBJ-IO/Examples/Meshes.meta b/Assets/OBJ-IO/Examples/Meshes.meta index de139ae4..ef0a288d 100644 --- a/Assets/OBJ-IO/Examples/Meshes.meta +++ b/Assets/OBJ-IO/Examples/Meshes.meta @@ -1,9 +1,8 @@ fileFormatVersion: 2 -guid: e0433cb2bd36d3942883bf0f0998e2bb +guid: 8154598e50f36402e8438a5b186fe65a folderAsset: yes -timeCreated: 1432869564 -licenseType: Pro DefaultImporter: + externalObjects: {} userData: assetBundleName: assetBundleVariant: diff --git a/Assets/OBJ-IO/Examples/Meshes/Materials.meta b/Assets/OBJ-IO/Examples/Meshes/Materials.meta index b422bc96..98274be8 100644 --- a/Assets/OBJ-IO/Examples/Meshes/Materials.meta +++ b/Assets/OBJ-IO/Examples/Meshes/Materials.meta @@ -1,9 +1,8 @@ fileFormatVersion: 2 -guid: 5fea4137d2a77354b9aa985c717be982 +guid: 24829d5ac0ba34bccb159269f42b9e22 folderAsset: yes -timeCreated: 1432869564 -licenseType: Pro DefaultImporter: + externalObjects: {} userData: assetBundleName: assetBundleVariant: diff --git a/Assets/OBJ-IO/Examples/Meshes/Materials/Teapot001Mat.mat b/Assets/OBJ-IO/Examples/Meshes/Materials/Teapot001Mat.mat index 661c18cd..64443c9b 100644 Binary files a/Assets/OBJ-IO/Examples/Meshes/Materials/Teapot001Mat.mat and b/Assets/OBJ-IO/Examples/Meshes/Materials/Teapot001Mat.mat differ diff --git a/Assets/OBJ-IO/Examples/Meshes/Materials/Teapot001Mat.mat.meta b/Assets/OBJ-IO/Examples/Meshes/Materials/Teapot001Mat.mat.meta index 2100a9af..08462fb7 100644 --- a/Assets/OBJ-IO/Examples/Meshes/Materials/Teapot001Mat.mat.meta +++ b/Assets/OBJ-IO/Examples/Meshes/Materials/Teapot001Mat.mat.meta @@ -1,8 +1,8 @@ fileFormatVersion: 2 -guid: 52da82a2947fb72429508b5742bae229 -timeCreated: 1432869564 -licenseType: Pro +guid: 475d2a47366f54519aa0108ba94c7ca9 NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 2100000 userData: assetBundleName: assetBundleVariant: diff --git a/Assets/OBJ-IO/Examples/Meshes/Materials/Teapot001_Instance_0Mat.mat b/Assets/OBJ-IO/Examples/Meshes/Materials/Teapot001_Instance_0Mat.mat deleted file mode 100644 index 27a1d092..00000000 Binary files a/Assets/OBJ-IO/Examples/Meshes/Materials/Teapot001_Instance_0Mat.mat and /dev/null differ diff --git a/Assets/OBJ-IO/Examples/Meshes/Teapot.obj.meta b/Assets/OBJ-IO/Examples/Meshes/Teapot.obj.meta index c30c0cf2..7a2a3c2c 100644 --- a/Assets/OBJ-IO/Examples/Meshes/Teapot.obj.meta +++ b/Assets/OBJ-IO/Examples/Meshes/Teapot.obj.meta @@ -1,7 +1,7 @@ fileFormatVersion: 2 guid: 53158f4ed39ed53448df438bc212f7e8 ModelImporter: - serializedVersion: 18 + serializedVersion: 23 fileIDToRecycleName: 100000: //RootNode 100002: Teapot001 @@ -11,21 +11,33 @@ ModelImporter: 3300000: Teapot001 4300000: Teapot001 9500000: //RootNode + externalObjects: {} materials: importMaterials: 1 materialName: 0 materialSearch: 1 + materialLocation: 0 animations: legacyGenerateAnimations: 4 bakeSimulation: 0 + resampleCurves: 1 optimizeGameObjects: 0 motionNodeName: + rigImportErrors: + rigImportWarnings: + animationImportErrors: + animationImportWarnings: + animationRetargetingWarnings: + animationDoRetargetingWarnings: 0 + importAnimatedCustomProperties: 0 + importConstraints: 0 animationCompression: 1 - animationRotationError: .5 - animationPositionError: .5 - animationScaleError: .5 + animationRotationError: 0.5 + animationPositionError: 0.5 + animationScaleError: 0.5 animationWrapMode: 0 extraExposedTransformPaths: [] + extraUserProperties: [] clipAnimations: [] isReadable: 1 meshes: @@ -33,38 +45,51 @@ ModelImporter: globalScale: 1 meshCompression: 0 addColliders: 0 + importVisibility: 0 importBlendShapes: 1 + importCameras: 0 + importLights: 0 swapUVChannels: 0 generateSecondaryUV: 0 useFileUnits: 1 optimizeMeshForGPU: 1 keepQuads: 0 weldVertices: 1 + preserveHierarchy: 0 + indexFormat: 1 secondaryUVAngleDistortion: 8 secondaryUVAreaDistortion: 15.000001 secondaryUVHardAngle: 88 secondaryUVPackMargin: 4 useFileScale: 0 + previousCalculatedGlobalScale: 1 + hasPreviousCalculatedGlobalScale: 0 tangentSpace: normalSmoothAngle: 60 - splitTangentsAcrossUV: 1 normalImportMode: 1 - tangentImportMode: 1 + tangentImportMode: 4 + normalCalculationMode: 0 importAnimation: 1 copyAvatar: 0 humanDescription: + serializedVersion: 2 human: [] skeleton: [] - armTwist: .5 - foreArmTwist: .5 - upperLegTwist: .5 - legTwist: .5 - armStretch: .0500000007 - legStretch: .0500000007 + armTwist: 0.5 + foreArmTwist: 0.5 + upperLegTwist: 0.5 + legTwist: 0.5 + armStretch: 0.05 + legStretch: 0.05 feetSpacing: 0 rootMotionBoneName: + rootMotionBoneRotation: {x: 0, y: 0, z: 0, w: 1} + hasTranslationDoF: 0 + hasExtraRoot: 0 + skeletonHasParents: 0 lastHumanDescriptionAvatarSource: {instanceID: 0} animationType: 0 + humanoidOversampling: 1 additionalBone: 0 userData: assetBundleName: diff --git a/Assets/OBJ-IO/Examples/Meshes/Teapot_Modified.obj b/Assets/OBJ-IO/Examples/Meshes/Teapot_Modified.obj deleted file mode 100644 index 91b1476d..00000000 --- a/Assets/OBJ-IO/Examples/Meshes/Teapot_Modified.obj +++ /dev/null @@ -1,2878 +0,0 @@ -# File exported by Unity3D version 5.0.0f4 -v 17.34540000 -10.92652000 33.21890000 -v 18.78210000 0.07088360 33.21890000 -v 19.04430000 1.11456200 32.22750000 -v 17.58740000 -10.84929000 32.22750000 -v 17.62610000 -10.81592000 33.54940000 -v 19.08630000 1.27865500 33.54940000 -v 18.19710000 -9.72625900 33.21890000 -v 19.70530000 3.36073400 33.21890000 -v 18.82610000 -7.65921800 32.22750000 -v 20.38720000 4.33830200 32.22750000 -v 13.40630000 -9.84251700 33.21890000 -v 13.59250000 -9.58590100 32.22750000 -v 13.62230000 -9.55546600 33.54940000 -v 14.06180000 -9.48775500 33.21890000 -v 14.54590000 -10.29000000 32.22750000 -v 7.52080000 -12.97997000 33.21890000 -v 7.62370000 -13.10759000 32.22750000 -v 7.64020000 -13.13176000 33.54940000 -v 7.88310000 -13.61340000 33.21890000 -v 8.15080000 -14.41561000 32.22750000 -v 0.24490000 -17.22686000 33.21890000 -v 0.24490000 -17.48906000 32.22750000 -v 0.24490000 -17.53106000 33.54940000 -v 0.24490000 -18.15006000 33.21890000 -v 0.24490000 -18.83196000 32.22750000 -v -7.24600000 -20.04321000 33.21890000 -v -7.64370000 -20.91389000 32.22750000 -v -7.21400000 -20.24913000 33.54940000 -v -7.40120000 -21.20864000 33.21890000 -v -7.66090000 -22.16637000 32.22750000 -v -13.10760000 -14.88166000 33.21890000 -v -13.55580000 -16.34995000 32.22750000 -v -13.18910000 -15.36992000 33.54940000 -v -13.57900000 -16.86931000 33.21890000 -v -14.05600000 -17.94733000 32.22750000 -v -16.92720000 -3.18005300 33.21890000 -v -17.26740000 -3.03855800 32.22750000 -v -17.15740000 -3.08422000 33.54940000 -v -17.70980000 -3.66357500 33.21890000 -v -18.33620000 -5.60098900 32.22750000 -v -18.29220000 2.45627600 33.21890000 -v -18.55440000 1.50405800 32.22750000 -v -18.59640000 1.34234500 33.54940000 -v -19.21540000 -1.09045300 33.21890000 -v -19.89730000 -3.12469600 32.22750000 -v -16.85560000 11.26348000 33.21890000 -v -18.29220000 2.45627600 33.21890000 -v -18.55440000 1.50405800 32.22750000 -v -17.09750000 11.65367000 32.22750000 -v -17.13620000 11.69512000 33.54940000 -v -18.59640000 1.34234500 33.54940000 -v -17.70720000 11.61706000 33.21890000 -v -19.21540000 -1.09045300 33.21890000 -v -18.33620000 10.21071000 32.22750000 -v -19.89730000 -3.12469600 32.22750000 -v -12.91640000 12.13010000 33.21890000 -v -13.10260000 11.64441000 32.22750000 -v -13.13240000 11.57266000 33.54940000 -v -13.57190000 10.77952000 33.21890000 -v -14.05600000 10.65457000 32.22750000 -v -7.03090000 14.72114000 33.21890000 -v -7.13380000 14.67616000 32.22750000 -v -7.15030000 14.67174000 33.54940000 -v -7.39320000 14.70978000 33.21890000 -v -7.66090000 14.99593000 32.22750000 -v 0.24490000 19.84744000 33.21890000 -v 0.24490000 20.10974000 32.22750000 -v 0.24490000 20.15164000 33.54940000 -v 0.24490000 20.77064000 33.21890000 -v 0.24490000 21.45254000 32.22750000 -v 7.52080000 21.22103000 33.21890000 -v 7.62370000 21.57731000 32.22750000 -v 7.64020000 21.63054000 33.54940000 -v 7.88310000 22.29090000 33.21890000 -v 8.15080000 22.74669000 32.22750000 -v 13.40630000 16.48018000 33.21890000 -v 13.59250000 17.10920000 32.22750000 -v 13.62230000 17.19923000 33.54940000 -v 14.06180000 18.14594000 33.21890000 -v 14.54590000 18.31190000 32.22750000 -v 17.34550000 3.62520600 33.21890000 -v 17.58740000 3.90821100 32.22750000 -v 17.62610000 3.97457600 33.54940000 -v 18.19710000 5.55004000 33.21890000 -v 18.82610000 8.15248200 32.22750000 -v 18.78210000 0.07088360 33.21890000 -v 19.04430000 1.11456200 32.22750000 -v 19.08630000 1.27865500 33.54940000 -v 19.70530000 3.36073400 33.21890000 -v 20.38720000 4.33830200 32.22750000 -v 21.10040000 -5.42283200 26.95590000 -v 22.85250000 -2.69439700 26.95590000 -v 23.08430000 -12.92942000 21.77880000 -v 25.00310000 -0.17661580 21.77880000 -v 24.48760000 -12.37944000 16.79040000 -v 26.52420000 4.27634900 16.79040000 -v 25.01990000 -10.65101000 12.08530000 -v 27.10120000 4.02837500 12.08530000 -v 16.29630000 -17.93082000 26.95590000 -v 17.82320000 -20.65947000 21.77880000 -v 18.90320000 -18.10333000 16.79040000 -v 19.31290000 -16.93973000 12.08530000 -v 9.11840000 -19.30857000 26.95590000 -v 9.96250000 -24.54762000 21.77880000 -v 10.55960000 -27.52804000 16.79040000 -v 10.78600000 -28.34698000 12.08530000 -v 0.24490000 -21.29726000 26.95590000 -v 0.24490000 -23.44786000 21.77880000 -v 0.24490000 -24.96896000 16.79040000 -v 0.24490000 -25.54596000 12.08530000 -v -8.62850000 -23.37403000 26.95590000 -v -9.47260000 -22.30768000 21.77880000 -v -10.06970000 -21.49766000 16.79040000 -v -10.29610000 -21.37378000 12.08530000 -v -15.80640000 -15.31779000 26.95590000 -v -17.33330000 -13.24375000 21.77880000 -v -18.41330000 -16.62760000 16.79040000 -v -18.82300000 -18.62129000 12.08530000 -v -20.61050000 -12.46091000 26.95590000 -v -22.59440000 -7.10780700 21.77880000 -v -23.99770000 -6.34799400 16.79040000 -v -24.53000000 -7.93299100 12.08530000 -v -22.36260000 1.79237400 26.95590000 -v -24.51320000 2.66314500 21.77880000 -v -26.03430000 -2.79667900 16.79040000 -v -26.61130000 -3.64249700 12.08530000 -v -20.61050000 5.28599500 26.95590000 -v -22.36260000 1.79237400 26.95590000 -v -22.59440000 12.32729000 21.77880000 -v -24.51320000 2.66314500 21.77880000 -v -23.99770000 14.28131000 16.79040000 -v -26.03430000 -2.79667900 16.79040000 -v -24.53000000 13.14911000 12.08530000 -v -26.61130000 -3.64249700 12.08530000 -v -15.80640000 16.78491000 26.95590000 -v -17.33330000 21.91275000 21.77880000 -v -18.41330000 20.68900000 16.79040000 -v -18.82300000 19.51461000 12.08530000 -v -8.62850000 18.33687000 26.95590000 -v -9.47260000 23.37102000 21.77880000 -v -10.06970000 26.98764000 16.79040000 -v -10.29610000 28.17612000 12.08530000 -v 0.24490000 23.91784000 26.95590000 -v 0.24490000 26.06844000 21.77880000 -v 0.24490000 27.58954000 16.79040000 -v 0.24490000 28.16654000 12.08530000 -v 9.11840000 22.40233000 26.95590000 -v 9.96250000 21.13108000 21.77880000 -v 10.55960000 20.95726000 16.79040000 -v 10.78600000 21.20292000 12.08530000 -v 16.29630000 14.17188000 26.95590000 -v 17.82320000 14.49703000 21.77880000 -v 18.90320000 19.21327000 16.79040000 -v 19.31290000 21.19617000 12.08530000 -v 21.10040000 12.32407000 26.95590000 -v 23.08430000 6.50568100 21.77880000 -v 24.48760000 8.24985600 16.79040000 -v 25.01990000 10.43109000 12.08530000 -v 22.85250000 -2.69439700 26.95590000 -v 25.00310000 -0.17661580 21.77880000 -v 26.52420000 4.27634900 16.79040000 -v 27.10120000 4.02837500 12.08530000 -v 24.05210000 -13.31794000 8.10410000 -v 26.05220000 3.52159500 8.10410000 -v 21.92300000 -8.61061900 5.16140000 -v 23.74420000 -3.59325000 5.16140000 -v 19.79390000 -4.73665000 3.16300000 -v 21.43620000 2.44810100 3.16300000 -v 18.82610000 -7.65921800 2.01420000 -v 20.38720000 4.33830200 2.01420000 -v 18.56810000 -19.09372000 8.10410000 -v 16.92940000 -20.10237000 5.16140000 -v 15.29080000 -13.08473000 3.16300000 -v 14.54590000 -10.29000000 2.01420000 -v 10.37430000 -26.71925000 8.10410000 -v 9.46840000 -21.51203000 5.16140000 -v 8.56250000 -16.17119000 3.16300000 -v 8.15080000 -14.41561000 2.01420000 -v 0.24490000 -24.49696000 8.10410000 -v 0.24490000 -22.18896000 5.16140000 -v 0.24490000 -19.88096000 3.16300000 -v 0.24490000 -18.83196000 2.01420000 -v -9.88440000 -21.69226000 8.10410000 -v -8.97850000 -23.06404000 5.16140000 -v -8.07260000 -23.11329000 3.16300000 -v -7.66090000 -22.16637000 2.01420000 -v -18.07820000 -15.19427000 8.10410000 -v -16.43950000 -13.67194000 5.16140000 -v -14.80090000 -17.85619000 3.16300000 -v -14.05600000 -17.94733000 2.01420000 -v -23.56220000 -5.78890000 8.10410000 -v -21.43310000 -11.00113000 5.16140000 -v -19.30400000 -9.73295400 3.16300000 -v -18.33620000 -5.60098900 2.01420000 -v -25.56230000 -1.32537800 8.10410000 -v -23.25430000 4.15269700 5.16140000 -v -20.94630000 -3.11889300 3.16300000 -v -19.89730000 -3.12469600 2.01420000 -v -23.56220000 14.46980000 8.10410000 -v -25.56230000 -1.32537800 8.10410000 -v -21.43310000 7.44577200 5.16140000 -v -23.25430000 4.15269700 5.16140000 -v -19.30400000 6.90214500 3.16300000 -v -20.94630000 -3.11889300 3.16300000 -v -18.33620000 10.21071000 2.01420000 -v -19.89730000 -3.12469600 2.01420000 -v -18.07820000 21.45203000 8.10410000 -v -16.43950000 19.69696000 5.16140000 -v -14.80090000 12.23551000 3.16300000 -v -14.05600000 10.65457000 2.01420000 -v -9.88440000 25.92204000 8.10410000 -v -8.97850000 20.29206000 5.16140000 -v -8.07260000 15.98461000 3.16300000 -v -7.66090000 14.99593000 2.01420000 -v 0.24490000 27.11754000 8.10410000 -v 0.24490000 24.80954000 5.16140000 -v 0.24490000 22.50154000 3.16300000 -v 0.24490000 21.45254000 2.01420000 -v 10.37430000 20.89505000 8.10410000 -v 9.46840000 21.84407000 5.16140000 -v 8.56250000 22.92671000 3.16300000 -v 8.15080000 22.74669000 2.01420000 -v 18.56810000 17.55258000 8.10410000 -v 16.92940000 13.26653000 5.16140000 -v 15.29080000 17.00697000 3.16300000 -v 14.54590000 18.31190000 2.01420000 -v 24.05210000 6.94075900 8.10410000 -v 21.92300000 9.83628200 5.16140000 -v 19.79390000 11.89845000 3.16300000 -v 18.82610000 8.15248200 2.01420000 -v 26.05220000 3.52159500 8.10410000 -v 23.74420000 -3.59325000 5.16140000 -v 21.43620000 2.44810100 3.16300000 -v 20.38720000 4.33830200 2.01420000 -v 18.40520000 -9.10570900 1.27460000 -v 19.93080000 3.87067300 1.27460000 -v 16.15510000 -8.15844200 0.62940000 -v 17.49170000 -3.56915600 0.62940000 -v 10.59530000 -7.74711600 0.17310000 -v 11.46480000 -3.22717500 0.17310000 -v 0.24490000 1.31033700 0.00000000 -v 14.22190000 -9.65085100 1.27460000 -v 12.49020000 -12.20919000 0.62940000 -v 8.21100000 -3.87782800 0.17310000 -v 0.24490000 1.31033700 0.00000000 -v 7.97170000 -13.84748000 1.27460000 -v 7.01430000 -12.89890000 0.62940000 -v 4.64870000 -14.00169000 0.17310000 -v 0.24490000 1.31033700 0.00000000 -v 0.24490000 -18.37556000 1.27460000 -v 0.24490000 -15.93646000 0.62940000 -v 0.24490000 -9.90956300 0.17310000 -v 0.24490000 1.31033700 0.00000000 -v -7.48180000 -21.54594000 1.27460000 -v -6.52440000 -16.52523000 0.62940000 -v -4.15880000 -6.60722700 0.17310000 -v 0.24490000 1.31033700 0.00000000 -v -13.73200000 -17.31265000 1.27460000 -v -12.00030000 -9.75952300 0.62940000 -v -7.72110000 -11.59034000 0.17310000 -v 0.24490000 1.31033700 0.00000000 -v -17.91530000 -4.16957300 1.27460000 -v -15.66520000 -6.59990000 0.62940000 -v -10.10540000 -1.54619400 0.17310000 -v 0.24490000 1.31033700 0.00000000 -v -19.44090000 -1.88941200 1.27460000 -v -17.00180000 4.18806600 0.62940000 -v -10.97490000 4.33964500 0.17310000 -v 0.24490000 1.31033700 0.00000000 -v -17.91530000 11.28383000 1.27460000 -v -19.44090000 -1.88941200 1.27460000 -v -15.66520000 6.93880000 0.62940000 -v -17.00180000 4.18806600 0.62940000 -v -10.10540000 7.26130700 0.17310000 -v -10.97490000 4.33964500 0.17310000 -v -13.73200000 10.64125000 1.27460000 -v -12.00030000 14.73098000 0.62940000 -v -7.72110000 4.34176300 0.17310000 -v -7.48180000 14.77456000 1.27460000 -v -6.52440000 15.29507000 0.62940000 -v -4.15880000 14.09337000 0.17310000 -v 0.24490000 20.99614000 1.27460000 -v 0.24490000 18.55704000 0.62940000 -v 0.24490000 12.53014000 0.17310000 -v 7.97170000 22.47302000 1.27460000 -v 7.01430000 18.92140000 0.62940000 -v 4.64870000 6.69891000 0.17310000 -v 14.22190000 18.30305000 1.27460000 -v 12.49020000 12.28131000 0.62940000 -v 8.21100000 12.05427000 0.17310000 -v 18.40520000 6.34769100 1.27460000 -v 16.15510000 5.38025800 0.62940000 -v 10.59530000 1.06038400 0.17310000 -v 19.93080000 3.87067300 1.27460000 -v 17.49170000 -3.56915600 0.62940000 -v 11.46480000 -3.22717500 0.17310000 -v -27.70040000 -4.09726100 27.60950000 -v -27.51350000 -2.41760200 27.14480000 -v -21.24010000 -2.38912000 27.19200000 -v -21.03030000 -5.20421200 27.66410000 -v -32.59630000 -5.62449000 27.22740000 -v -32.15040000 -2.34028100 26.81430000 -v -35.61170000 1.55248000 26.19030000 -v -35.02490000 2.14269300 25.91740000 -v -36.64050000 1.56120600 24.17070000 -v -36.01100000 4.31300600 24.17070000 -v -28.11150000 -3.32936200 28.63180000 -v -20.56870000 -6.63696600 28.70270000 -v -33.57720000 -6.00359600 28.13620000 -v -36.90270000 0.17851040 26.79070000 -v -38.02520000 -3.96225900 24.17070000 -v -28.52260000 -0.94260490 29.65420000 -v -20.10710000 -5.73084500 29.74120000 -v -34.55810000 -1.92317000 29.04490000 -v -38.19380000 -3.82453500 27.39110000 -v -39.41000000 -5.88631300 24.17070000 -v -28.70950000 2.02674200 30.11890000 -v -19.89730000 -3.12469600 30.21330000 -v -35.00390000 2.06731000 29.45800000 -v -38.78060000 -3.19013600 27.66410000 -v -40.03950000 -2.53227600 24.17070000 -v -28.52260000 3.58939500 29.65420000 -v -20.10710000 -1.19884500 29.74120000 -v -34.55810000 2.60883000 29.04490000 -v -38.19380000 0.70746450 27.39110000 -v -39.41000000 -1.35431300 24.17070000 -v -28.11150000 2.71333800 28.63180000 -v -20.56870000 -0.59426620 28.70270000 -v -33.57720000 0.03910351 28.13620000 -v -36.90270000 6.22121000 26.79070000 -v -38.02530000 2.08006500 24.17070000 -v -27.70040000 0.43473860 27.60950000 -v -21.03030000 -0.67221160 27.66410000 -v -32.59630000 -1.09249000 27.22740000 -v -35.61170000 6.08448000 26.19030000 -v -36.64050000 6.09320500 24.17070000 -v -27.51350000 -2.41760200 27.14480000 -v -21.24010000 -2.38912000 27.19200000 -v -32.15040000 -2.34028100 26.81430000 -v -35.02490000 2.14269300 25.91740000 -v -36.01100000 4.31300600 24.17070000 -v -36.05860000 2.06478400 21.16830000 -v -35.48650000 3.54454000 21.43260000 -v -34.23550000 -3.19142900 17.72480000 -v -33.82900000 -2.32256600 18.12800000 -v -31.05510000 -0.51330750 14.32550000 -v -30.91250000 2.27021800 14.82340000 -v -26.40150000 -5.74443100 11.45590000 -v -26.61130000 -3.64249700 12.08530000 -v -37.31710000 -1.18975000 20.58680000 -v -35.12980000 -0.51470040 16.83760000 -v -31.36890000 -2.49286400 13.23010000 -v -25.93990000 -5.57019900 10.07110000 -v -38.57570000 -4.99973900 20.00530000 -v -36.02410000 2.05279800 15.95050000 -v -31.68260000 -2.97959600 12.13470000 -v -25.47830000 -3.28039000 8.68630000 -v -39.14780000 -3.62971600 19.74090000 -v -36.43070000 4.15901900 15.54730000 -v -31.82520000 -1.25126800 11.63680000 -v -25.26850000 -0.20086610 8.05690000 -v -38.57570000 -0.46773930 20.00530000 -v -36.02410000 6.58479800 15.95050000 -v -31.68260000 1.55240400 12.13470000 -v -25.47830000 1.25161000 8.68630000 -v -37.31710000 4.85295000 20.58680000 -v -35.12980000 5.52800000 16.83760000 -v -31.36890000 3.54983600 13.23010000 -v -25.93990000 0.47250060 10.07110000 -v -36.05860000 6.59678400 21.16830000 -v -34.23550000 1.34057100 17.72480000 -v -31.05510000 4.01869200 14.32550000 -v -26.40150000 -1.21243000 11.45590000 -v -35.48650000 3.54454000 21.43260000 -v -33.82900000 -2.32256600 18.12800000 -v -30.91250000 2.27021800 14.82340000 -v -26.61130000 -3.64249700 12.08530000 -v 30.00580000 -8.10938200 19.33080000 -v 29.51410000 -3.44233100 20.61430000 -v 23.07280000 -3.19043900 19.13510000 -v 23.07280000 -8.17563900 17.40410000 -v 32.93410000 0.89816330 23.42320000 -v 32.30460000 3.44544400 24.17070000 -v 34.60340000 -2.21526400 28.21190000 -v 33.83630000 2.98170300 28.48230000 -v 37.75980000 -1.30529700 32.22750000 -v 36.50090000 -3.38505800 32.22750000 -v 31.08770000 -6.95075900 16.50720000 -v 23.07280000 -9.83744000 13.59600000 -v 34.31890000 -3.29645900 21.77880000 -v 36.29110000 -6.76962000 27.61690000 -v 40.52940000 -0.95209670 32.22750000 -v 32.16960000 -1.42360800 13.68350000 -v 23.07280000 -8.17563900 9.78790000 -v 35.70360000 -6.74092700 20.13430000 -v 37.97880000 -0.92756960 27.02180000 -v 43.29890000 -4.07362200 32.22750000 -v 32.66130000 4.13056300 12.40010000 -v 23.07280000 -3.19043900 8.05690000 -v 36.33310000 -3.57592000 19.38690000 -v 38.74590000 3.80378100 26.75140000 -v 44.55780000 2.51752800 32.22750000 -v 32.16960000 7.57909200 13.68350000 -v 32.66130000 4.13056300 12.40010000 -v 23.07280000 -3.19043900 8.05690000 -v 23.07280000 1.79476000 9.78790000 -v 35.70360000 0.13257290 20.13430000 -v 36.33310000 -3.57592000 19.38690000 -v 37.97880000 3.81693000 27.02180000 -v 38.74590000 3.80378100 26.75140000 -v 43.29890000 -0.29692170 32.22750000 -v 44.55780000 2.51752800 32.22750000 -v 31.08770000 5.05274100 16.50720000 -v 23.07280000 3.45646100 13.59600000 -v 34.31890000 5.86824000 21.77880000 -v 36.29110000 -0.44371960 27.61690000 -v 40.52940000 4.08340400 32.22750000 -v 30.00580000 0.89331890 19.33080000 -v 23.07280000 1.79476000 17.40410000 -v 32.93410000 7.77166300 23.42320000 -v 34.60340000 2.52923600 28.21190000 -v 37.75980000 2.47140400 32.22750000 -v 38.81430000 2.16207500 32.82170000 -v 37.46610000 -0.58314080 32.79400000 -v 39.44490000 2.76871200 33.02710000 -v 38.17940000 2.18864400 32.98290000 -v 39.46370000 3.01452500 32.83280000 -v 38.38930000 2.88723300 32.79400000 -v 38.68300000 2.53812500 32.22750000 -v 37.84370000 0.91684120 32.22750000 -v 41.78040000 -5.24951200 32.88260000 -v 42.22890000 -5.60730000 33.12450000 -v 41.82760000 -4.66487100 32.91800000 -v 40.52940000 0.05500329 32.22750000 -v 44.74650000 1.33794100 32.94340000 -v 45.01290000 2.26024000 33.22190000 -v 44.19150000 -0.07987291 33.00320000 -v 42.37570000 -4.78993700 32.22750000 -v 46.09470000 3.76802700 32.97110000 -v 46.27830000 3.33394700 33.26610000 -v 45.26590000 4.17667000 33.04190000 -v 43.21500000 -2.43626900 32.22750000 -v 44.74650000 4.87864100 32.94340000 -v 46.09470000 3.76802700 32.97110000 -v 45.01290000 5.28153900 33.22190000 -v 46.27830000 3.33394700 33.26610000 -v 44.19150000 2.42222700 33.00320000 -v 45.26590000 4.17667000 33.04190000 -v 42.37570000 -2.52393700 32.22750000 -v 43.21500000 -2.43626900 32.22750000 -v 41.78040000 -0.52861210 32.88260000 -v 42.22890000 -1.57879900 33.12450000 -v 41.82760000 -1.32877100 32.91800000 -v 40.52940000 3.07630300 32.22750000 -v 38.81430000 5.70277500 32.82170000 -v 39.44490000 5.79001100 33.02710000 -v 39.46370000 5.51662400 32.83280000 -v 38.68300000 4.80412500 32.22750000 -v 4.46600000 -5.33879800 41.63770000 -v 4.81890000 -3.63683200 41.63770000 -v 0.24490000 1.31033700 42.29860000 -v 4.27230000 -4.99555400 40.03260000 -v 4.60910000 -3.63818200 40.03260000 -v 2.68430000 1.06728200 38.04990000 -v 2.88860000 1.34170900 38.04990000 -v 2.72240000 0.91439280 36.25600000 -v 2.93060000 1.17822300 36.25600000 -v 3.49670000 -4.30206400 41.63770000 -v 0.24490000 1.31033700 42.29860000 -v 3.34730000 -3.57893900 40.03260000 -v 2.12340000 1.86664300 38.04990000 -v 2.15170000 1.77756800 36.25600000 -v 2.04500000 -0.32197360 41.63770000 -v 0.24490000 1.31033700 42.29860000 -v 1.96210000 0.01075053 40.03260000 -v 1.28420000 1.73794600 38.04990000 -v 1.29910000 1.71626800 36.25600000 -v 0.24490000 -3.26366300 41.63770000 -v 0.24490000 1.31033700 42.29860000 -v 0.24490000 -3.05386300 40.03260000 -v 0.24490000 -1.33336300 38.04990000 -v 0.24490000 -1.37536300 36.25600000 -v -1.55510000 -7.88010700 41.63770000 -v 0.24490000 1.31033700 42.29860000 -v -1.47220000 -7.66747300 40.03260000 -v -0.79430000 -4.95239300 38.04990000 -v -0.80920000 -5.03194100 36.25600000 -v -3.00680000 -3.44884000 41.63770000 -v 0.24490000 1.31033700 42.29860000 -v -2.85740000 -3.88343000 40.03260000 -v -1.63350000 -5.53013900 38.04990000 -v -1.66180000 -5.54974800 36.25600000 -v -3.97610000 1.50426300 41.63770000 -v 0.24490000 1.31033700 42.29860000 -v -3.78240000 1.01467100 40.03260000 -v -2.19440000 -3.94591700 38.04990000 -v -2.23250000 -3.86948600 36.25600000 -v -4.32900000 4.05010900 41.63770000 -v 0.24490000 1.31033700 42.29860000 -v -4.11920000 3.65714900 40.03260000 -v -2.39870000 -2.36518500 38.04990000 -v -2.44070000 -2.23910000 36.25600000 -v -3.97610000 5.10436300 41.63770000 -v -4.32900000 4.05010900 41.63770000 -v -3.78240000 4.44897100 40.03260000 -v -4.11920000 3.65714900 40.03260000 -v -2.19440000 -1.86741700 38.04990000 -v -2.39870000 -2.36518500 38.04990000 -v -2.23250000 -1.76118600 36.25600000 -v -2.44070000 -2.23910000 36.25600000 -v -3.00680000 3.05466000 41.63770000 -v -2.85740000 2.32127000 40.03260000 -v -1.63350000 -1.77323900 38.04990000 -v -1.66180000 -1.73614800 36.25600000 -v -1.55510000 0.56199290 41.63770000 -v -1.47220000 0.38722710 40.03260000 -v -0.79430000 -0.07369304 38.04990000 -v -0.80920000 -0.07704139 36.25600000 -v 0.24490000 5.88423700 41.63770000 -v 0.24490000 5.67443700 40.03260000 -v 0.24490000 3.95393700 38.04990000 -v 0.24490000 3.99593700 36.25600000 -v 2.04500000 8.12012700 41.63770000 -v 1.96210000 8.06545100 40.03260000 -v 1.28420000 6.61664600 38.04990000 -v 1.29910000 6.67116800 36.25600000 -v 3.49670000 2.20143600 41.63770000 -v 3.34730000 2.62576100 40.03260000 -v 2.12340000 5.62354300 38.04990000 -v 2.15170000 5.59116800 36.25600000 -v 4.46600000 -1.73869800 41.63770000 -v 4.27230000 -1.56125500 40.03260000 -v 2.68430000 3.14578200 38.04990000 -v 2.72240000 3.02269300 36.25600000 -v 4.81890000 -3.63683200 41.63770000 -v 4.60910000 -3.63818200 40.03260000 -v 2.88860000 1.34170900 38.04990000 -v 2.93060000 1.17822300 36.25600000 -v 5.89670000 -3.57194100 35.06000000 -v 6.37150000 0.69329980 35.06000000 -v 2.93060000 1.17822300 36.25600000 -v 2.72240000 0.91439280 36.25600000 -v 10.46460000 -7.45695600 34.24180000 -v 11.32320000 -3.44673600 34.24180000 -v 14.56790000 -2.11896000 33.42350000 -v 15.77120000 0.08772090 33.42350000 -v 16.34860000 -8.90212500 32.22750000 -v 17.70150000 -3.30737300 32.22750000 -v 4.59480000 -7.98177700 35.06000000 -v 2.15170000 1.77756800 36.25600000 -v 8.11050000 -3.65598400 34.24180000 -v 11.26860000 -14.53504000 33.42350000 -v 12.63910000 -11.76304000 32.22750000 -v 2.64960000 -3.42176700 35.06000000 -v 1.29910000 1.71626800 36.25600000 -v 4.59310000 -13.85077000 34.24180000 -v 6.33900000 -13.75936000 33.42350000 -v 7.09670000 -12.85637000 32.22750000 -v 0.24490000 -4.81626300 35.06000000 -v 0.24490000 -1.37536300 36.25600000 -v 0.24490000 -9.76796200 34.24180000 -v 0.24490000 -14.21596000 33.42350000 -v 0.24490000 -16.14626000 32.22750000 -v -2.15970000 -8.63750100 35.06000000 -v -0.80920000 -5.03194100 36.25600000 -v -4.10330000 -6.59852100 34.24180000 -v -5.84910000 -12.30018000 33.42350000 -v -6.60680000 -17.03518000 32.22750000 -v -4.10490000 -0.72506450 35.06000000 -v -1.66180000 -5.54974800 36.25600000 -v -7.62060000 -11.41666000 34.24180000 -v -10.77870000 -6.77690100 33.42350000 -v -12.14920000 -10.43300000 32.22750000 -v -5.40680000 1.00952400 35.06000000 -v -2.23250000 -3.86948600 36.25600000 -v -9.97470000 -1.91721700 34.24180000 -v -14.07810000 -9.74662400 33.42350000 -v -15.85870000 -5.91063500 32.22750000 -v -5.88160000 1.90401200 35.06000000 -v -2.44070000 -2.23910000 36.25600000 -v -10.83330000 4.28795000 34.24180000 -v -15.28130000 -1.31484400 33.42350000 -v -17.21160000 4.33148200 32.22750000 -v -5.40680000 5.81882400 35.06000000 -v -5.88160000 1.90401200 35.06000000 -v -2.44070000 -2.23910000 36.25600000 -v -2.23250000 -1.76118600 36.25600000 -v -9.97470000 6.77918300 34.24180000 -v -10.83330000 4.28795000 34.24180000 -v -14.07810000 2.44147600 33.42350000 -v -15.28130000 -1.31484400 33.42350000 -v -15.85870000 7.79286600 32.22750000 -v -17.21160000 4.33148200 32.22750000 -v -4.10490000 7.97463500 35.06000000 -v -1.66180000 -1.73614800 36.25600000 -v -7.62060000 4.31444100 34.24180000 -v -10.77870000 15.27040000 33.42350000 -v -12.14920000 14.35530000 32.22750000 -v -2.15970000 2.66599900 35.06000000 -v -0.80920000 -0.07704139 36.25600000 -v -4.10330000 13.84078000 34.24180000 -v -5.84910000 16.34582000 33.42350000 -v -6.60680000 15.17222000 32.22750000 -v 0.24490000 7.43683700 35.06000000 -v 0.24490000 3.99593700 36.25600000 -v 0.24490000 12.38854000 34.24180000 -v 0.24490000 16.83654000 33.42350000 -v 0.24490000 18.76684000 32.22750000 -v 2.64960000 7.88173200 35.06000000 -v 1.29910000 6.67116800 36.25600000 -v 4.59310000 6.58852600 34.24180000 -v 6.33900000 14.88664000 33.42350000 -v 7.09670000 19.35102000 32.22750000 -v 4.59480000 0.71792240 35.06000000 -v 2.15170000 5.59116800 36.25600000 -v 8.11050000 12.07512000 34.24180000 -v 11.26860000 7.51226300 33.42350000 -v 12.63910000 13.02526000 32.22750000 -v 5.89670000 1.23735800 35.06000000 -v 2.72240000 3.02269300 36.25600000 -v 10.46460000 1.23944400 34.24180000 -v 14.56790000 10.06914000 33.42350000 -v 16.34860000 4.80137400 32.22750000 -v 6.37150000 0.69329980 35.06000000 -v 2.93060000 1.17822300 36.25600000 -v 11.32320000 -3.44673600 34.24180000 -v 15.77120000 0.08772090 33.42350000 -v 17.70150000 -3.30737300 32.22750000 -vt 1.75000 1.97500 -vt 2.00000 1.97500 -vt 2.00000 2.00000 -vt 1.75000 2.00000 -vt 1.75000 1.95000 -vt 2.00000 1.95000 -vt 1.75000 1.92500 -vt 2.00000 1.92500 -vt 1.75000 1.90000 -vt 2.00000 1.90000 -vt 1.50000 1.97500 -vt 1.50000 2.00000 -vt 1.50000 1.95000 -vt 1.50000 1.92500 -vt 1.50000 1.90000 -vt 1.25000 1.97500 -vt 1.25000 2.00000 -vt 1.25000 1.95000 -vt 1.25000 1.92500 -vt 1.25000 1.90000 -vt 1.00000 1.97500 -vt 1.00000 2.00000 -vt 1.00000 1.95000 -vt 1.00000 1.92500 -vt 1.00000 1.90000 -vt 0.75000 1.97500 -vt 0.75000 2.00000 -vt 0.75000 1.95000 -vt 0.75000 1.92500 -vt 0.75000 1.90000 -vt 0.50000 1.97500 -vt 0.50000 2.00000 -vt 0.50000 1.95000 -vt 0.50000 1.92500 -vt 0.50000 1.90000 -vt 0.25000 1.97500 -vt 0.25000 2.00000 -vt 0.25000 1.95000 -vt 0.25000 1.92500 -vt 0.25000 1.90000 -vt 0.00000 1.97500 -vt 0.00000 2.00000 -vt 0.00000 1.95000 -vt 0.00000 1.92500 -vt 0.00000 1.90000 -vt 1.75000 1.97500 -vt 2.00000 1.97500 -vt 2.00000 2.00000 -vt 1.75000 2.00000 -vt 1.75000 1.95000 -vt 2.00000 1.95000 -vt 1.75000 1.92500 -vt 2.00000 1.92500 -vt 1.75000 1.90000 -vt 2.00000 1.90000 -vt 1.50000 1.97500 -vt 1.50000 2.00000 -vt 1.50000 1.95000 -vt 1.50000 1.92500 -vt 1.50000 1.90000 -vt 1.25000 1.97500 -vt 1.25000 2.00000 -vt 1.25000 1.95000 -vt 1.25000 1.92500 -vt 1.25000 1.90000 -vt 1.00000 1.97500 -vt 1.00000 2.00000 -vt 1.00000 1.95000 -vt 1.00000 1.92500 -vt 1.00000 1.90000 -vt 0.75000 1.97500 -vt 0.75000 2.00000 -vt 0.75000 1.95000 -vt 0.75000 1.92500 -vt 0.75000 1.90000 -vt 0.50000 1.97500 -vt 0.50000 2.00000 -vt 0.50000 1.95000 -vt 0.50000 1.92500 -vt 0.50000 1.90000 -vt 0.25000 1.97500 -vt 0.25000 2.00000 -vt 0.25000 1.95000 -vt 0.25000 1.92500 -vt 0.25000 1.90000 -vt 0.00000 1.97500 -vt 0.00000 2.00000 -vt 0.00000 1.95000 -vt 0.00000 1.92500 -vt 0.00000 1.90000 -vt 1.75000 1.67500 -vt 2.00000 1.67500 -vt 1.75000 1.45000 -vt 2.00000 1.45000 -vt 1.75000 1.22500 -vt 2.00000 1.22500 -vt 1.75000 1.00000 -vt 2.00000 1.00000 -vt 1.50000 1.67500 -vt 1.50000 1.45000 -vt 1.50000 1.22500 -vt 1.50000 1.00000 -vt 1.25000 1.67500 -vt 1.25000 1.45000 -vt 1.25000 1.22500 -vt 1.25000 1.00000 -vt 1.00000 1.67500 -vt 1.00000 1.45000 -vt 1.00000 1.22500 -vt 1.00000 1.00000 -vt 0.75000 1.67500 -vt 0.75000 1.45000 -vt 0.75000 1.22500 -vt 0.75000 1.00000 -vt 0.50000 1.67500 -vt 0.50000 1.45000 -vt 0.50000 1.22500 -vt 0.50000 1.00000 -vt 0.25000 1.67500 -vt 0.25000 1.45000 -vt 0.25000 1.22500 -vt 0.25000 1.00000 -vt 0.00000 1.67500 -vt 0.00000 1.45000 -vt 0.00000 1.22500 -vt 0.00000 1.00000 -vt 1.75000 1.67500 -vt 2.00000 1.67500 -vt 1.75000 1.45000 -vt 2.00000 1.45000 -vt 1.75000 1.22500 -vt 2.00000 1.22500 -vt 1.75000 1.00000 -vt 2.00000 1.00000 -vt 1.50000 1.67500 -vt 1.50000 1.45000 -vt 1.50000 1.22500 -vt 1.50000 1.00000 -vt 1.25000 1.67500 -vt 1.25000 1.45000 -vt 1.25000 1.22500 -vt 1.25000 1.00000 -vt 1.00000 1.67500 -vt 1.00000 1.45000 -vt 1.00000 1.22500 -vt 1.00000 1.00000 -vt 0.75000 1.67500 -vt 0.75000 1.45000 -vt 0.75000 1.22500 -vt 0.75000 1.00000 -vt 0.50000 1.67500 -vt 0.50000 1.45000 -vt 0.50000 1.22500 -vt 0.50000 1.00000 -vt 0.25000 1.67500 -vt 0.25000 1.45000 -vt 0.25000 1.22500 -vt 0.25000 1.00000 -vt 0.00000 1.67500 -vt 0.00000 1.45000 -vt 0.00000 1.22500 -vt 0.00000 1.00000 -vt 1.75000 0.85000 -vt 2.00000 0.85000 -vt 1.75000 0.70000 -vt 2.00000 0.70000 -vt 1.75000 0.55000 -vt 2.00000 0.55000 -vt 1.75000 0.40000 -vt 2.00000 0.40000 -vt 1.50000 0.85000 -vt 1.50000 0.70000 -vt 1.50000 0.55000 -vt 1.50000 0.40000 -vt 1.25000 0.85000 -vt 1.25000 0.70000 -vt 1.25000 0.55000 -vt 1.25000 0.40000 -vt 1.00000 0.85000 -vt 1.00000 0.70000 -vt 1.00000 0.55000 -vt 1.00000 0.40000 -vt 0.75000 0.85000 -vt 0.75000 0.70000 -vt 0.75000 0.55000 -vt 0.75000 0.40000 -vt 0.50000 0.85000 -vt 0.50000 0.70000 -vt 0.50000 0.55000 -vt 0.50000 0.40000 -vt 0.25000 0.85000 -vt 0.25000 0.70000 -vt 0.25000 0.55000 -vt 0.25000 0.40000 -vt 0.00000 0.85000 -vt 0.00000 0.70000 -vt 0.00000 0.55000 -vt 0.00000 0.40000 -vt 1.75000 0.85000 -vt 2.00000 0.85000 -vt 1.75000 0.70000 -vt 2.00000 0.70000 -vt 1.75000 0.55000 -vt 2.00000 0.55000 -vt 1.75000 0.40000 -vt 2.00000 0.40000 -vt 1.50000 0.85000 -vt 1.50000 0.70000 -vt 1.50000 0.55000 -vt 1.50000 0.40000 -vt 1.25000 0.85000 -vt 1.25000 0.70000 -vt 1.25000 0.55000 -vt 1.25000 0.40000 -vt 1.00000 0.85000 -vt 1.00000 0.70000 -vt 1.00000 0.55000 -vt 1.00000 0.40000 -vt 0.75000 0.85000 -vt 0.75000 0.70000 -vt 0.75000 0.55000 -vt 0.75000 0.40000 -vt 0.50000 0.85000 -vt 0.50000 0.70000 -vt 0.50000 0.55000 -vt 0.50000 0.40000 -vt 0.25000 0.85000 -vt 0.25000 0.70000 -vt 0.25000 0.55000 -vt 0.25000 0.40000 -vt 0.00000 0.85000 -vt 0.00000 0.70000 -vt 0.00000 0.55000 -vt 0.00000 0.40000 -vt 1.75000 0.30000 -vt 2.00000 0.30000 -vt 1.75000 0.20000 -vt 2.00000 0.20000 -vt 1.75000 0.10000 -vt 2.00000 0.10000 -vt 1.75000 0.00000 -vt 1.50000 0.30000 -vt 1.50000 0.20000 -vt 1.50000 0.10000 -vt 1.50000 0.00000 -vt 1.25000 0.30000 -vt 1.25000 0.20000 -vt 1.25000 0.10000 -vt 1.25000 0.00000 -vt 1.00000 0.30000 -vt 1.00000 0.20000 -vt 1.00000 0.10000 -vt 1.00000 0.00000 -vt 0.75000 0.30000 -vt 0.75000 0.20000 -vt 0.75000 0.10000 -vt 0.75000 0.00000 -vt 0.50000 0.30000 -vt 0.50000 0.20000 -vt 0.50000 0.10000 -vt 0.50000 0.00000 -vt 0.25000 0.30000 -vt 0.25000 0.20000 -vt 0.25000 0.10000 -vt 0.25000 0.00000 -vt 0.00000 0.30000 -vt 0.00000 0.20000 -vt 0.00000 0.10000 -vt 0.00000 0.00000 -vt 1.75000 0.30000 -vt 2.00000 0.30000 -vt 1.75000 0.20000 -vt 2.00000 0.20000 -vt 1.75000 0.10000 -vt 2.00000 0.10000 -vt 1.50000 0.30000 -vt 1.50000 0.20000 -vt 1.50000 0.10000 -vt 1.25000 0.30000 -vt 1.25000 0.20000 -vt 1.25000 0.10000 -vt 1.00000 0.30000 -vt 1.00000 0.20000 -vt 1.00000 0.10000 -vt 0.75000 0.30000 -vt 0.75000 0.20000 -vt 0.75000 0.10000 -vt 0.50000 0.30000 -vt 0.50000 0.20000 -vt 0.50000 0.10000 -vt 0.25000 0.30000 -vt 0.25000 0.20000 -vt 0.25000 0.10000 -vt 0.00000 0.30000 -vt 0.00000 0.20000 -vt 0.00000 0.10000 -vt 0.87500 0.87500 -vt 1.00000 0.87500 -vt 1.00000 1.00000 -vt 0.87500 1.00000 -vt 0.87500 0.75000 -vt 1.00000 0.75000 -vt 0.87500 0.62500 -vt 1.00000 0.62500 -vt 0.87500 0.50000 -vt 1.00000 0.50000 -vt 0.75000 0.87500 -vt 0.75000 1.00000 -vt 0.75000 0.75000 -vt 0.75000 0.62500 -vt 0.75000 0.50000 -vt 0.62500 0.87500 -vt 0.62500 1.00000 -vt 0.62500 0.75000 -vt 0.62500 0.62500 -vt 0.62500 0.50000 -vt 0.50000 0.87500 -vt 0.50000 1.00000 -vt 0.50000 0.75000 -vt 0.50000 0.62500 -vt 0.50000 0.50000 -vt 0.37500 0.87500 -vt 0.37500 1.00000 -vt 0.37500 0.75000 -vt 0.37500 0.62500 -vt 0.37500 0.50000 -vt 0.25000 0.87500 -vt 0.25000 1.00000 -vt 0.25000 0.75000 -vt 0.25000 0.62500 -vt 0.25000 0.50000 -vt 0.12500 0.87500 -vt 0.12500 1.00000 -vt 0.12500 0.75000 -vt 0.12500 0.62500 -vt 0.12500 0.50000 -vt 0.00000 0.87500 -vt 0.00000 1.00000 -vt 0.00000 0.75000 -vt 0.00000 0.62500 -vt 0.00000 0.50000 -vt 0.87500 0.37500 -vt 1.00000 0.37500 -vt 0.87500 0.25000 -vt 1.00000 0.25000 -vt 0.87500 0.12500 -vt 1.00000 0.12500 -vt 0.87500 0.00000 -vt 1.00000 0.00000 -vt 0.75000 0.37500 -vt 0.75000 0.25000 -vt 0.75000 0.12500 -vt 0.75000 0.00000 -vt 0.62500 0.37500 -vt 0.62500 0.25000 -vt 0.62500 0.12500 -vt 0.62500 0.00000 -vt 0.50000 0.37500 -vt 0.50000 0.25000 -vt 0.50000 0.12500 -vt 0.50000 0.00000 -vt 0.37500 0.37500 -vt 0.37500 0.25000 -vt 0.37500 0.12500 -vt 0.37500 0.00000 -vt 0.25000 0.37500 -vt 0.25000 0.25000 -vt 0.25000 0.12500 -vt 0.25000 0.00000 -vt 0.12500 0.37500 -vt 0.12500 0.25000 -vt 0.12500 0.12500 -vt 0.12500 0.00000 -vt 0.00000 0.37500 -vt 0.00000 0.25000 -vt 0.00000 0.12500 -vt 0.00000 0.00000 -vt 0.62500 0.22500 -vt 0.50000 0.22500 -vt 0.50000 0.00000 -vt 0.62500 0.00000 -vt 0.62500 0.45000 -vt 0.50000 0.45000 -vt 0.62500 0.67500 -vt 0.50000 0.67500 -vt 0.62500 0.90000 -vt 0.50000 0.90000 -vt 0.75000 0.22500 -vt 0.75000 0.00000 -vt 0.75000 0.45000 -vt 0.75000 0.67500 -vt 0.75000 0.90000 -vt 0.87500 0.22500 -vt 0.87500 0.00000 -vt 0.87500 0.45000 -vt 0.87500 0.67500 -vt 0.87500 0.90000 -vt 1.00000 0.22500 -vt 1.00000 0.00000 -vt 1.00000 0.45000 -vt 1.00000 0.67500 -vt 1.00000 0.90000 -vt 0.12500 0.22500 -vt 0.00000 0.22500 -vt 0.00000 0.00000 -vt 0.12500 0.00000 -vt 0.12500 0.45000 -vt 0.00000 0.45000 -vt 0.12500 0.67500 -vt 0.00000 0.67500 -vt 0.12500 0.90000 -vt 0.00000 0.90000 -vt 0.25000 0.22500 -vt 0.25000 0.00000 -vt 0.25000 0.45000 -vt 0.25000 0.67500 -vt 0.25000 0.90000 -vt 0.37500 0.22500 -vt 0.37500 0.00000 -vt 0.37500 0.45000 -vt 0.37500 0.67500 -vt 0.37500 0.90000 -vt 0.62500 0.92500 -vt 0.50000 0.92500 -vt 0.62500 0.95000 -vt 0.50000 0.95000 -vt 0.62500 0.97500 -vt 0.50000 0.97500 -vt 0.62500 1.00000 -vt 0.50000 1.00000 -vt 0.75000 0.92500 -vt 0.75000 0.95000 -vt 0.75000 0.97500 -vt 0.75000 1.00000 -vt 0.87500 0.92500 -vt 0.87500 0.95000 -vt 0.87500 0.97500 -vt 0.87500 1.00000 -vt 1.00000 0.92500 -vt 1.00000 0.95000 -vt 1.00000 0.97500 -vt 1.00000 1.00000 -vt 0.12500 0.92500 -vt 0.00000 0.92500 -vt 0.12500 0.95000 -vt 0.00000 0.95000 -vt 0.12500 0.97500 -vt 0.00000 0.97500 -vt 0.12500 1.00000 -vt 0.00000 1.00000 -vt 0.25000 0.92500 -vt 0.25000 0.95000 -vt 0.25000 0.97500 -vt 0.25000 1.00000 -vt 0.37500 0.92500 -vt 0.37500 0.95000 -vt 0.37500 0.97500 -vt 0.37500 1.00000 -vt 0.87500 0.75000 -vt 1.00000 0.75000 -vt 1.00000 1.00000 -vt 0.87500 0.50000 -vt 1.00000 0.50000 -vt 0.87500 0.25000 -vt 1.00000 0.25000 -vt 0.87500 0.00000 -vt 1.00000 0.00000 -vt 0.75000 0.75000 -vt 0.87500 1.00000 -vt 0.75000 0.50000 -vt 0.75000 0.25000 -vt 0.75000 0.00000 -vt 0.62500 0.75000 -vt 0.75000 1.00000 -vt 0.62500 0.50000 -vt 0.62500 0.25000 -vt 0.62500 0.00000 -vt 0.50000 0.75000 -vt 0.62500 1.00000 -vt 0.50000 0.50000 -vt 0.50000 0.25000 -vt 0.50000 0.00000 -vt 0.37500 0.75000 -vt 0.50000 1.00000 -vt 0.37500 0.50000 -vt 0.37500 0.25000 -vt 0.37500 0.00000 -vt 0.25000 0.75000 -vt 0.37500 1.00000 -vt 0.25000 0.50000 -vt 0.25000 0.25000 -vt 0.25000 0.00000 -vt 0.12500 0.75000 -vt 0.25000 1.00000 -vt 0.12500 0.50000 -vt 0.12500 0.25000 -vt 0.12500 0.00000 -vt 0.00000 0.75000 -vt 0.12500 1.00000 -vt 0.00000 0.50000 -vt 0.00000 0.25000 -vt 0.00000 0.00000 -vt 0.87500 0.75000 -vt 1.00000 0.75000 -vt 0.87500 0.50000 -vt 1.00000 0.50000 -vt 0.87500 0.25000 -vt 1.00000 0.25000 -vt 0.87500 0.00000 -vt 1.00000 0.00000 -vt 0.75000 0.75000 -vt 0.75000 0.50000 -vt 0.75000 0.25000 -vt 0.75000 0.00000 -vt 0.62500 0.75000 -vt 0.62500 0.50000 -vt 0.62500 0.25000 -vt 0.62500 0.00000 -vt 0.50000 0.75000 -vt 0.50000 0.50000 -vt 0.50000 0.25000 -vt 0.50000 0.00000 -vt 0.37500 0.75000 -vt 0.37500 0.50000 -vt 0.37500 0.25000 -vt 0.37500 0.00000 -vt 0.25000 0.75000 -vt 0.25000 0.50000 -vt 0.25000 0.25000 -vt 0.25000 0.00000 -vt 0.12500 0.75000 -vt 0.12500 0.50000 -vt 0.12500 0.25000 -vt 0.12500 0.00000 -vt 0.00000 0.75000 -vt 0.00000 0.50000 -vt 0.00000 0.25000 -vt 0.00000 0.00000 -vt 0.87500 0.75000 -vt 1.00000 0.75000 -vt 1.00000 1.00000 -vt 0.87500 1.00000 -vt 0.87500 0.50000 -vt 1.00000 0.50000 -vt 0.87500 0.25000 -vt 1.00000 0.25000 -vt 0.87500 0.00000 -vt 1.00000 0.00000 -vt 0.75000 0.75000 -vt 0.75000 1.00000 -vt 0.75000 0.50000 -vt 0.75000 0.25000 -vt 0.75000 0.00000 -vt 0.62500 0.75000 -vt 0.62500 1.00000 -vt 0.62500 0.50000 -vt 0.62500 0.25000 -vt 0.62500 0.00000 -vt 0.50000 0.75000 -vt 0.50000 1.00000 -vt 0.50000 0.50000 -vt 0.50000 0.25000 -vt 0.50000 0.00000 -vt 0.37500 0.75000 -vt 0.37500 1.00000 -vt 0.37500 0.50000 -vt 0.37500 0.25000 -vt 0.37500 0.00000 -vt 0.25000 0.75000 -vt 0.25000 1.00000 -vt 0.25000 0.50000 -vt 0.25000 0.25000 -vt 0.25000 0.00000 -vt 0.12500 0.75000 -vt 0.12500 1.00000 -vt 0.12500 0.50000 -vt 0.12500 0.25000 -vt 0.12500 0.00000 -vt 0.00000 0.75000 -vt 0.00000 1.00000 -vt 0.00000 0.50000 -vt 0.00000 0.25000 -vt 0.00000 0.00000 -vt 0.87500 0.75000 -vt 1.00000 0.75000 -vt 1.00000 1.00000 -vt 0.87500 1.00000 -vt 0.87500 0.50000 -vt 1.00000 0.50000 -vt 0.87500 0.25000 -vt 1.00000 0.25000 -vt 0.87500 0.00000 -vt 1.00000 0.00000 -vt 0.75000 0.75000 -vt 0.75000 1.00000 -vt 0.75000 0.50000 -vt 0.75000 0.25000 -vt 0.75000 0.00000 -vt 0.62500 0.75000 -vt 0.62500 1.00000 -vt 0.62500 0.50000 -vt 0.62500 0.25000 -vt 0.62500 0.00000 -vt 0.50000 0.75000 -vt 0.50000 1.00000 -vt 0.50000 0.50000 -vt 0.50000 0.25000 -vt 0.50000 0.00000 -vt 0.37500 0.75000 -vt 0.37500 1.00000 -vt 0.37500 0.50000 -vt 0.37500 0.25000 -vt 0.37500 0.00000 -vt 0.25000 0.75000 -vt 0.25000 1.00000 -vt 0.25000 0.50000 -vt 0.25000 0.25000 -vt 0.25000 0.00000 -vt 0.12500 0.75000 -vt 0.12500 1.00000 -vt 0.12500 0.50000 -vt 0.12500 0.25000 -vt 0.12500 0.00000 -vt 0.00000 0.75000 -vt 0.00000 1.00000 -vt 0.00000 0.50000 -vt 0.00000 0.25000 -vt 0.00000 0.00000 -vn -0.89340000 0.36910000 0.25600000 -vn -0.96680000 0.00000000 0.25540000 -vn -0.96670000 0.00000000 -0.25580000 -vn -0.89300000 0.36990000 -0.25630000 -vn -0.08390000 0.03550000 0.99580000 -vn -0.09210000 0.00000000 0.99580000 -vn 0.62970000 -0.26040000 0.73190000 -vn 0.68200000 0.00000000 0.73130000 -vn 0.80370000 -0.33260000 0.49340000 -vn 0.87030000 0.00000000 0.49250000 -vn -0.68350000 0.68350000 0.25610000 -vn -0.68340000 0.68340000 -0.25670000 -vn -0.06490000 0.06490000 0.99580000 -vn 0.48140000 -0.48140000 0.73250000 -vn 0.61480000 -0.61480000 0.49400000 -vn -0.36910000 0.89340000 0.25600000 -vn -0.36990000 0.89300000 -0.25630000 -vn -0.03550000 0.08390000 0.99580000 -vn 0.26040000 -0.62970000 0.73190000 -vn 0.33260000 -0.80370000 0.49340000 -vn -0.00190000 0.96700000 0.25470000 -vn -0.00280000 0.96620000 -0.25790000 -vn -0.00030000 0.09230000 0.99570000 -vn 0.00000000 -0.68210000 0.73130000 -vn 0.00000000 -0.87030000 0.49250000 -vn 0.37710000 0.91410000 0.14910000 -vn 0.37910000 0.85280000 -0.35930000 -vn 0.02750000 0.12260000 0.99210000 -vn -0.26100000 -0.63540000 0.72680000 -vn -0.33250000 -0.80430000 0.49250000 -vn 0.71270000 0.69760000 0.07370000 -vn 0.66350000 0.62530000 -0.41080000 -vn 0.09970000 0.12200000 0.98750000 -vn -0.48730000 -0.48860000 0.72380000 -vn -0.61520000 -0.61550000 0.49260000 -vn 0.91730000 0.36150000 0.16710000 -vn 0.88000000 0.33870000 -0.33290000 -vn 0.11360000 0.04810000 0.99240000 -vn -0.63410000 -0.26190000 0.72750000 -vn -0.80410000 -0.33270000 0.49260000 -vn 0.96740000 -0.00810000 0.25300000 -vn 0.96670000 -0.01050000 -0.25570000 -vn 0.09340000 -0.00130000 0.99560000 -vn -0.68220000 0.00030000 0.73120000 -vn -0.87030000 0.00010000 0.49250000 -vn 0.89340000 -0.36910000 0.25600000 -vn 0.96740000 -0.00810000 0.25300000 -vn 0.96670000 -0.01050000 -0.25570000 -vn 0.89300000 -0.36990000 -0.25630000 -vn 0.08390000 -0.03550000 0.99580000 -vn 0.09340000 -0.00130000 0.99560000 -vn -0.62970000 0.26040000 0.73190000 -vn -0.68220000 0.00030000 0.73120000 -vn -0.80370000 0.33260000 0.49340000 -vn -0.87030000 0.00010000 0.49250000 -vn 0.68350000 -0.68350000 0.25610000 -vn 0.68340000 -0.68340000 -0.25670000 -vn 0.06490000 -0.06490000 0.99580000 -vn -0.48140000 0.48140000 0.73250000 -vn -0.61480000 0.61480000 0.49400000 -vn 0.36910000 -0.89340000 0.25600000 -vn 0.36990000 -0.89300000 -0.25630000 -vn 0.03550000 -0.08390000 0.99580000 -vn -0.26040000 0.62970000 0.73190000 -vn -0.33260000 0.80370000 0.49340000 -vn 0.00000000 -0.96680000 0.25540000 -vn 0.00000000 -0.96670000 -0.25580000 -vn 0.00000000 -0.09210000 0.99580000 -vn 0.00000000 0.68200000 0.73130000 -vn 0.00000000 0.87030000 0.49250000 -vn -0.36910000 -0.89340000 0.25600000 -vn -0.36990000 -0.89300000 -0.25630000 -vn -0.03550000 -0.08390000 0.99580000 -vn 0.26040000 0.62970000 0.73190000 -vn 0.33260000 0.80370000 0.49340000 -vn -0.68350000 -0.68350000 0.25610000 -vn -0.68340000 -0.68340000 -0.25670000 -vn -0.06490000 -0.06490000 0.99580000 -vn 0.48140000 0.48140000 0.73250000 -vn 0.61480000 0.61480000 0.49400000 -vn -0.89340000 -0.36910000 0.25600000 -vn -0.89300000 -0.36990000 -0.25630000 -vn -0.08390000 -0.03550000 0.99580000 -vn 0.62970000 0.26040000 0.73190000 -vn 0.80370000 0.33260000 0.49340000 -vn -0.96680000 0.00000000 0.25540000 -vn -0.96670000 0.00000000 -0.25580000 -vn -0.09210000 0.00000000 0.99580000 -vn 0.68200000 0.00000000 0.73130000 -vn 0.87030000 0.00000000 0.49250000 -vn 0.84540000 -0.34980000 0.40350000 -vn 0.91530000 0.00000000 0.40270000 -vn 0.87000000 -0.36000000 0.33690000 -vn 0.94180000 0.00000000 0.33620000 -vn 0.90420000 -0.37430000 0.20580000 -vn 0.97870000 0.00000000 0.20530000 -vn 0.92190000 -0.38180000 -0.06640000 -vn 0.99780000 0.00000000 -0.06620000 -vn 0.64680000 -0.64680000 0.40410000 -vn 0.66570000 -0.66570000 0.33740000 -vn 0.69190000 -0.69190000 0.20610000 -vn 0.70550000 -0.70550000 -0.06650000 -vn 0.34980000 -0.84540000 0.40350000 -vn 0.36000000 -0.87000000 0.33690000 -vn 0.37430000 -0.90420000 0.20580000 -vn 0.38180000 -0.92190000 -0.06640000 -vn 0.00000000 -0.91530000 0.40270000 -vn 0.00000000 -0.94180000 0.33620000 -vn 0.00000000 -0.97870000 0.20530000 -vn 0.00000000 -0.99780000 -0.06620000 -vn -0.34980000 -0.84540000 0.40350000 -vn -0.36000000 -0.87000000 0.33690000 -vn -0.37430000 -0.90420000 0.20580000 -vn -0.38180000 -0.92190000 -0.06640000 -vn -0.64680000 -0.64680000 0.40410000 -vn -0.66570000 -0.66570000 0.33740000 -vn -0.69190000 -0.69190000 0.20610000 -vn -0.70550000 -0.70550000 -0.06650000 -vn -0.84540000 -0.34980000 0.40350000 -vn -0.87000000 -0.36000000 0.33690000 -vn -0.90420000 -0.37430000 0.20580000 -vn -0.92190000 -0.38180000 -0.06640000 -vn -0.91530000 0.00000000 0.40270000 -vn -0.94180000 0.00000000 0.33620000 -vn -0.97870000 0.00000000 0.20530000 -vn -0.99780000 0.00000000 -0.06620000 -vn -0.84540000 0.34980000 0.40350000 -vn -0.91530000 0.00000000 0.40270000 -vn -0.87000000 0.36000000 0.33690000 -vn -0.94180000 0.00000000 0.33620000 -vn -0.90420000 0.37430000 0.20580000 -vn -0.97870000 0.00000000 0.20530000 -vn -0.92190000 0.38180000 -0.06640000 -vn -0.99780000 0.00000000 -0.06620000 -vn -0.64680000 0.64680000 0.40410000 -vn -0.66570000 0.66570000 0.33740000 -vn -0.69190000 0.69190000 0.20610000 -vn -0.70550000 0.70550000 -0.06650000 -vn -0.34980000 0.84540000 0.40350000 -vn -0.36000000 0.87000000 0.33690000 -vn -0.37430000 0.90420000 0.20580000 -vn -0.38180000 0.92190000 -0.06640000 -vn 0.00000000 0.91530000 0.40270000 -vn 0.00000000 0.94180000 0.33620000 -vn 0.00000000 0.97870000 0.20530000 -vn 0.00000000 0.99780000 -0.06620000 -vn 0.34980000 0.84540000 0.40350000 -vn 0.36000000 0.87000000 0.33690000 -vn 0.37430000 0.90420000 0.20580000 -vn 0.38180000 0.92190000 -0.06640000 -vn 0.64680000 0.64680000 0.40410000 -vn 0.66570000 0.66570000 0.33740000 -vn 0.69190000 0.69190000 0.20610000 -vn 0.70550000 0.70550000 -0.06650000 -vn 0.84540000 0.34980000 0.40350000 -vn 0.87000000 0.36000000 0.33690000 -vn 0.90420000 0.37430000 0.20580000 -vn 0.92190000 0.38180000 -0.06640000 -vn 0.91530000 0.00000000 0.40270000 -vn 0.94180000 0.00000000 0.33620000 -vn 0.97870000 0.00000000 0.20530000 -vn 0.99780000 0.00000000 -0.06620000 -vn 0.83140000 -0.34420000 -0.43620000 -vn 0.90020000 0.00000000 -0.43550000 -vn 0.67350000 -0.27860000 -0.68470000 -vn 0.72960000 0.00000000 -0.68390000 -vn 0.64040000 -0.26490000 -0.72090000 -vn 0.69400000 0.00000000 -0.72000000 -vn 0.73290000 -0.30320000 -0.60900000 -vn 0.79390000 0.00000000 -0.60800000 -vn 0.63610000 -0.63610000 -0.43680000 -vn 0.51500000 -0.51500000 -0.68530000 -vn 0.48970000 -0.48970000 -0.72140000 -vn 0.56060000 -0.56060000 -0.60960000 -vn 0.34420000 -0.83140000 -0.43620000 -vn 0.27860000 -0.67350000 -0.68470000 -vn 0.26490000 -0.64040000 -0.72090000 -vn 0.30320000 -0.73290000 -0.60900000 -vn 0.00000000 -0.90020000 -0.43550000 -vn 0.00000000 -0.72960000 -0.68390000 -vn 0.00000000 -0.69400000 -0.72000000 -vn 0.00000000 -0.79390000 -0.60800000 -vn -0.34420000 -0.83140000 -0.43620000 -vn -0.27860000 -0.67350000 -0.68470000 -vn -0.26490000 -0.64040000 -0.72090000 -vn -0.30320000 -0.73290000 -0.60900000 -vn -0.63610000 -0.63610000 -0.43680000 -vn -0.51500000 -0.51500000 -0.68530000 -vn -0.48970000 -0.48970000 -0.72140000 -vn -0.56060000 -0.56060000 -0.60960000 -vn -0.83140000 -0.34420000 -0.43620000 -vn -0.67350000 -0.27860000 -0.68470000 -vn -0.64040000 -0.26490000 -0.72090000 -vn -0.73290000 -0.30320000 -0.60900000 -vn -0.90020000 0.00000000 -0.43550000 -vn -0.72960000 0.00000000 -0.68390000 -vn -0.69400000 0.00000000 -0.72000000 -vn -0.79390000 0.00000000 -0.60800000 -vn -0.83140000 0.34420000 -0.43620000 -vn -0.90020000 0.00000000 -0.43550000 -vn -0.67350000 0.27860000 -0.68470000 -vn -0.72960000 0.00000000 -0.68390000 -vn -0.64040000 0.26490000 -0.72090000 -vn -0.69400000 0.00000000 -0.72000000 -vn -0.73290000 0.30320000 -0.60900000 -vn -0.79390000 0.00000000 -0.60800000 -vn -0.63610000 0.63610000 -0.43680000 -vn -0.51500000 0.51500000 -0.68530000 -vn -0.48970000 0.48970000 -0.72140000 -vn -0.56060000 0.56060000 -0.60960000 -vn -0.34420000 0.83140000 -0.43620000 -vn -0.27860000 0.67350000 -0.68470000 -vn -0.26490000 0.64040000 -0.72090000 -vn -0.30320000 0.73290000 -0.60900000 -vn 0.00000000 0.90020000 -0.43550000 -vn 0.00000000 0.72960000 -0.68390000 -vn 0.00000000 0.69400000 -0.72000000 -vn 0.00000000 0.79390000 -0.60800000 -vn 0.34420000 0.83140000 -0.43620000 -vn 0.27860000 0.67350000 -0.68470000 -vn 0.26490000 0.64040000 -0.72090000 -vn 0.30320000 0.73290000 -0.60900000 -vn 0.63610000 0.63610000 -0.43680000 -vn 0.51500000 0.51500000 -0.68530000 -vn 0.48970000 0.48970000 -0.72140000 -vn 0.56060000 0.56060000 -0.60960000 -vn 0.83140000 0.34420000 -0.43620000 -vn 0.67350000 0.27860000 -0.68470000 -vn 0.64040000 0.26490000 -0.72090000 -vn 0.73290000 0.30320000 -0.60900000 -vn 0.90020000 0.00000000 -0.43550000 -vn 0.72960000 0.00000000 -0.68390000 -vn 0.69400000 0.00000000 -0.72000000 -vn 0.79390000 0.00000000 -0.60800000 -vn 0.57620000 -0.23820000 -0.78180000 -vn 0.62390000 0.00000000 -0.78150000 -vn 0.16360000 -0.06750000 -0.98420000 -vn 0.17730000 0.00000000 -0.98420000 -vn 0.04540000 -0.01870000 -0.99880000 -vn 0.04920000 0.00000000 -0.99880000 -vn 0.00000000 0.00000000 -1.00000000 -vn 0.44040000 -0.44040000 -0.78230000 -vn 0.12490000 -0.12490000 -0.98430000 -vn 0.03470000 -0.03470000 -0.99880000 -vn 0.00000000 0.00000000 -1.00000000 -vn 0.23820000 -0.57620000 -0.78180000 -vn 0.06750000 -0.16360000 -0.98420000 -vn 0.01870000 -0.04540000 -0.99880000 -vn 0.00000000 0.00000000 -1.00000000 -vn 0.00000000 -0.62390000 -0.78150000 -vn 0.00000000 -0.17730000 -0.98420000 -vn 0.00000000 -0.04920000 -0.99880000 -vn 0.00000000 0.00000000 -1.00000000 -vn -0.23820000 -0.57620000 -0.78180000 -vn -0.06750000 -0.16360000 -0.98420000 -vn -0.01870000 -0.04540000 -0.99880000 -vn 0.00000000 0.00000000 -1.00000000 -vn -0.44040000 -0.44040000 -0.78230000 -vn -0.12490000 -0.12490000 -0.98430000 -vn -0.03470000 -0.03470000 -0.99880000 -vn 0.00000000 0.00000000 -1.00000000 -vn -0.57620000 -0.23820000 -0.78180000 -vn -0.16360000 -0.06750000 -0.98420000 -vn -0.04540000 -0.01870000 -0.99880000 -vn 0.00000000 0.00000000 -1.00000000 -vn -0.62390000 0.00000000 -0.78150000 -vn -0.17730000 0.00000000 -0.98420000 -vn -0.04920000 0.00000000 -0.99880000 -vn 0.00000000 0.00000000 -1.00000000 -vn -0.57620000 0.23820000 -0.78180000 -vn -0.62390000 0.00000000 -0.78150000 -vn -0.16360000 0.06750000 -0.98420000 -vn -0.17730000 0.00000000 -0.98420000 -vn -0.04540000 0.01870000 -0.99880000 -vn -0.04920000 0.00000000 -0.99880000 -vn -0.44040000 0.44040000 -0.78230000 -vn -0.12490000 0.12490000 -0.98430000 -vn -0.03470000 0.03470000 -0.99880000 -vn -0.23820000 0.57620000 -0.78180000 -vn -0.06750000 0.16360000 -0.98420000 -vn -0.01870000 0.04540000 -0.99880000 -vn 0.00000000 0.62390000 -0.78150000 -vn 0.00000000 0.17730000 -0.98420000 -vn 0.00000000 0.04920000 -0.99880000 -vn 0.23820000 0.57620000 -0.78180000 -vn 0.06750000 0.16360000 -0.98420000 -vn 0.01870000 0.04540000 -0.99880000 -vn 0.44040000 0.44040000 -0.78230000 -vn 0.12490000 0.12490000 -0.98430000 -vn 0.03470000 0.03470000 -0.99880000 -vn 0.57620000 0.23820000 -0.78180000 -vn 0.16360000 0.06750000 -0.98420000 -vn 0.04540000 0.01870000 -0.99880000 -vn 0.62390000 0.00000000 -0.78150000 -vn 0.17730000 0.00000000 -0.98420000 -vn 0.04920000 0.00000000 -0.99880000 -vn 0.03610000 -0.54560000 -0.83730000 -vn 0.03910000 0.00100000 -0.99920000 -vn 0.00780000 0.00020000 -1.00000000 -vn 0.00700000 -0.58290000 -0.81250000 -vn 0.16180000 -0.56300000 -0.81040000 -vn 0.17950000 0.00440000 -0.98370000 -vn 0.48240000 -0.64270000 -0.59510000 -vn 0.61230000 0.01050000 -0.79060000 -vn 0.73870000 -0.66420000 -0.11460000 -vn 0.98620000 0.00670000 -0.16570000 -vn 0.00280000 -0.99980000 0.01710000 -vn -0.00190000 -0.98680000 0.16210000 -vn 0.01050000 -0.99720000 0.07340000 -vn -0.06600000 -0.98930000 0.13010000 -vn -0.09440000 -0.99540000 0.01660000 -vn -0.04860000 -0.53950000 0.84060000 -vn -0.00920000 -0.49030000 0.87150000 -vn -0.22330000 -0.55270000 0.80290000 -vn -0.59640000 -0.57510000 0.56000000 -vn -0.80330000 -0.59160000 0.06820000 -vn -0.05880000 -0.00070000 0.99830000 -vn -0.01060000 -0.00010000 0.99990000 -vn -0.28070000 -0.00330000 0.95980000 -vn -0.74970000 -0.00430000 0.66170000 -vn -0.99740000 -0.00210000 0.07270000 -vn -0.04650000 0.53880000 0.84120000 -vn -0.00880000 0.49030000 0.87150000 -vn -0.21790000 0.54920000 0.80680000 -vn -0.59730000 0.57410000 0.56000000 -vn -0.80400000 0.59130000 0.06290000 -vn 0.00200000 0.99990000 0.01460000 -vn -0.00180000 0.98680000 0.16170000 -vn 0.00920000 0.99820000 0.06010000 -vn -0.05930000 0.99170000 0.11390000 -vn -0.08690000 0.99610000 0.01230000 -vn 0.03380000 0.54540000 -0.83750000 -vn 0.00640000 0.58310000 -0.81240000 -vn 0.15710000 0.56220000 -0.81190000 -vn 0.48440000 0.64650000 -0.58940000 -vn 0.73890000 0.66620000 -0.10130000 -vn 0.03910000 0.00100000 -0.99920000 -vn 0.00780000 0.00020000 -1.00000000 -vn 0.17950000 0.00440000 -0.98370000 -vn 0.61230000 0.01050000 -0.79060000 -vn 0.98620000 0.00670000 -0.16570000 -vn 0.72560000 -0.63740000 0.25940000 -vn 0.94650000 0.00340000 0.32270000 -vn 0.64590000 -0.60770000 0.46200000 -vn 0.82580000 0.00750000 0.56390000 -vn 0.53160000 -0.55860000 0.63670000 -vn 0.65000000 0.00690000 0.75990000 -vn 0.42500000 -0.59550000 0.68170000 -vn 0.53240000 0.00520000 0.84650000 -vn -0.04960000 -0.99860000 -0.01980000 -vn -0.03780000 -0.99860000 -0.03560000 -vn -0.03790000 -0.99860000 -0.03650000 -vn -0.16890000 -0.93950000 -0.29790000 -vn -0.74230000 -0.59950000 -0.29920000 -vn -0.61960000 -0.57950000 -0.52940000 -vn -0.48370000 -0.54380000 -0.68580000 -vn -0.44530000 -0.41320000 -0.79440000 -vn -0.92650000 -0.00200000 -0.37630000 -vn -0.75390000 -0.00430000 -0.65700000 -vn -0.56620000 -0.00350000 -0.82420000 -vn -0.48180000 -0.00190000 -0.87630000 -vn -0.74470000 0.59900000 -0.29440000 -vn -0.62190000 0.57820000 -0.52810000 -vn -0.48120000 0.54280000 -0.68830000 -vn -0.43810000 0.41570000 -0.79700000 -vn -0.04430000 0.99890000 -0.01710000 -vn -0.02620000 0.99930000 -0.02820000 -vn -0.02530000 0.99930000 -0.02830000 -vn -0.15750000 0.94420000 -0.28940000 -vn 0.72820000 0.63710000 0.25240000 -vn 0.64710000 0.60830000 0.45970000 -vn 0.52300000 0.56220000 0.64070000 -vn 0.41000000 0.60470000 0.68290000 -vn 0.94650000 0.00340000 0.32270000 -vn 0.82580000 0.00750000 0.56390000 -vn 0.65000000 0.00690000 0.75990000 -vn 0.53240000 0.00520000 0.84650000 -vn -0.31670000 -0.70210000 0.63780000 -vn -0.54890000 0.00150000 0.83590000 -vn -0.23080000 0.00650000 0.97300000 -vn -0.15290000 -0.71020000 0.68720000 -vn -0.60110000 -0.64530000 0.47150000 -vn -0.87570000 -0.00990000 0.48280000 -vn -0.63590000 -0.62980000 0.44610000 -vn -0.87760000 -0.01910000 0.47910000 -vn -0.43570000 -0.67000000 0.60100000 -vn -0.69620000 -0.02450000 0.71740000 -vn 0.22330000 -0.97470000 0.00650000 -vn 0.11110000 -0.99020000 -0.08510000 -vn 0.19010000 -0.96950000 0.15500000 -vn 0.00530000 -0.98190000 0.18950000 -vn -0.01180000 -0.96900000 0.24670000 -vn 0.57250000 -0.59160000 -0.56770000 -vn 0.34390000 -0.59940000 -0.72280000 -vn 0.78740000 -0.56050000 -0.25650000 -vn 0.64710000 -0.69810000 -0.30640000 -vn 0.42750000 -0.75360000 -0.49930000 -vn 0.67150000 0.00090000 -0.74100000 -vn 0.41090000 -0.00130000 -0.91170000 -vn 0.92200000 0.00730000 -0.38710000 -vn 0.84690000 0.01390000 -0.53160000 -vn 0.53590000 0.01050000 -0.84420000 -vn 0.57870000 0.59180000 -0.56110000 -vn 0.67150000 0.00090000 -0.74100000 -vn 0.41090000 -0.00130000 -0.91170000 -vn 0.34120000 0.60090000 -0.72280000 -vn 0.78490000 0.56650000 -0.25100000 -vn 0.92200000 0.00730000 -0.38710000 -vn 0.64270000 0.70400000 -0.30230000 -vn 0.84690000 0.01390000 -0.53160000 -vn 0.41860000 0.75810000 -0.50000000 -vn 0.53590000 0.01050000 -0.84420000 -vn 0.23280000 0.97240000 0.01260000 -vn 0.11580000 0.99010000 -0.07910000 -vn 0.20670000 0.96630000 0.15360000 -vn 0.02450000 0.98660000 0.16140000 -vn 0.00340000 0.97750000 0.21110000 -vn -0.31950000 0.70510000 0.63310000 -vn -0.13490000 0.71360000 0.68750000 -vn -0.60390000 0.64990000 0.46140000 -vn -0.63180000 0.64010000 0.43720000 -vn -0.42430000 0.66670000 0.61270000 -vn -0.25990000 -0.55250000 0.79190000 -vn -0.42580000 -0.01080000 0.90480000 -vn 0.00950000 0.02170000 0.99970000 -vn 0.02200000 -0.00160000 0.99980000 -vn 0.41020000 0.84910000 0.33290000 -vn 0.99960000 -0.01160000 0.02590000 -vn 0.54150000 0.63700000 -0.54860000 -vn 0.70960000 -0.00970000 -0.70460000 -vn 0.04630000 -0.88920000 0.45520000 -vn -0.01070000 -0.14890000 0.98880000 -vn -0.04440000 0.72910000 0.68290000 -vn 0.12280000 0.99240000 0.00920000 -vn 0.48180000 -0.85750000 -0.18040000 -vn 0.45530000 -0.49990000 0.73670000 -vn -0.22050000 0.35830000 0.90720000 -vn -0.23590000 0.71580000 0.65730000 -vn 0.72810000 0.01560000 -0.68530000 -vn 0.88870000 0.01670000 0.45810000 -vn -0.26010000 -0.00080000 0.96560000 -vn -0.37160000 0.00440000 0.92840000 -vn 0.48020000 0.85890000 -0.17840000 -vn 0.72810000 0.01560000 -0.68530000 -vn 0.48810000 0.49800000 0.71680000 -vn 0.88870000 0.01670000 0.45810000 -vn -0.22200000 -0.36190000 0.90540000 -vn -0.26010000 -0.00080000 0.96560000 -vn -0.23540000 -0.71050000 0.66320000 -vn -0.37160000 0.00440000 0.92840000 -vn 0.05870000 0.89720000 0.43770000 -vn 0.00130000 0.16400000 0.98650000 -vn -0.04420000 -0.73030000 0.68170000 -vn 0.13880000 -0.98970000 -0.03420000 -vn -0.25890000 0.54540000 0.79720000 -vn 0.01230000 -0.01930000 0.99970000 -vn 0.39860000 -0.84570000 0.35490000 -vn 0.53760000 -0.61070000 -0.58140000 -vn 0.76260000 -0.31480000 0.56500000 -vn 0.82450000 0.00000000 0.56580000 -vn 0.00000000 0.00000000 1.00000000 -vn 0.84800000 -0.35000000 -0.39800000 -vn 0.91770000 0.00000000 -0.39730000 -vn 0.86410000 -0.35640000 -0.35530000 -vn 0.93530000 -0.00010000 -0.35390000 -vn 0.72100000 -0.29790000 0.62560000 -vn 0.78070000 -0.00010000 0.62490000 -vn 0.58340000 -0.58330000 0.56520000 -vn 0.00000000 0.00000000 1.00000000 -vn 0.64850000 -0.64840000 -0.39870000 -vn 0.66090000 -0.66070000 -0.35590000 -vn 0.55190000 -0.55180000 0.62530000 -vn 0.31480000 -0.76260000 0.56510000 -vn 0.00000000 0.00000000 1.00000000 -vn 0.35000000 -0.84800000 -0.39800000 -vn 0.35650000 -0.86420000 -0.35520000 -vn 0.29800000 -0.72110000 0.62550000 -vn 0.00000000 -0.82450000 0.56580000 -vn 0.00000000 0.00000000 1.00000000 -vn 0.00000000 -0.91770000 -0.39730000 -vn -0.00010000 -0.93530000 -0.35390000 -vn -0.00010000 -0.78070000 0.62490000 -vn -0.31480000 -0.76260000 0.56500000 -vn 0.00000000 0.00000000 1.00000000 -vn -0.35000000 -0.84800000 -0.39800000 -vn -0.35640000 -0.86410000 -0.35530000 -vn -0.29790000 -0.72100000 0.62560000 -vn -0.58330000 -0.58340000 0.56520000 -vn 0.00000000 0.00000000 1.00000000 -vn -0.64840000 -0.64850000 -0.39870000 -vn -0.66070000 -0.66090000 -0.35590000 -vn -0.55180000 -0.55190000 0.62530000 -vn -0.76260000 -0.31480000 0.56510000 -vn 0.00000000 0.00000000 1.00000000 -vn -0.84800000 -0.35000000 -0.39800000 -vn -0.86420000 -0.35650000 -0.35520000 -vn -0.72110000 -0.29800000 0.62550000 -vn -0.82450000 0.00000000 0.56580000 -vn 0.00000000 0.00000000 1.00000000 -vn -0.91770000 0.00000000 -0.39730000 -vn -0.93530000 0.00010000 -0.35390000 -vn -0.78070000 0.00010000 0.62490000 -vn -0.76260000 0.31480000 0.56500000 -vn -0.82450000 0.00000000 0.56580000 -vn -0.84800000 0.35000000 -0.39800000 -vn -0.91770000 0.00000000 -0.39730000 -vn -0.86410000 0.35640000 -0.35530000 -vn -0.93530000 0.00010000 -0.35390000 -vn -0.72100000 0.29790000 0.62560000 -vn -0.78070000 0.00010000 0.62490000 -vn -0.58340000 0.58330000 0.56520000 -vn -0.64850000 0.64840000 -0.39870000 -vn -0.66090000 0.66070000 -0.35590000 -vn -0.55190000 0.55180000 0.62530000 -vn -0.31480000 0.76260000 0.56510000 -vn -0.35000000 0.84800000 -0.39800000 -vn -0.35650000 0.86420000 -0.35520000 -vn -0.29800000 0.72110000 0.62550000 -vn 0.00000000 0.82450000 0.56580000 -vn 0.00000000 0.91770000 -0.39730000 -vn 0.00010000 0.93530000 -0.35390000 -vn 0.00010000 0.78070000 0.62490000 -vn 0.31480000 0.76260000 0.56500000 -vn 0.35000000 0.84800000 -0.39800000 -vn 0.35640000 0.86410000 -0.35530000 -vn 0.29790000 0.72100000 0.62560000 -vn 0.58330000 0.58340000 0.56520000 -vn 0.64840000 0.64850000 -0.39870000 -vn 0.66070000 0.66090000 -0.35590000 -vn 0.55180000 0.55190000 0.62530000 -vn 0.76260000 0.31480000 0.56510000 -vn 0.84800000 0.35000000 -0.39800000 -vn 0.86420000 0.35650000 -0.35520000 -vn 0.72110000 0.29800000 0.62550000 -vn 0.82450000 0.00000000 0.56580000 -vn 0.91770000 0.00000000 -0.39730000 -vn 0.93530000 -0.00010000 -0.35390000 -vn 0.78070000 -0.00010000 0.62490000 -vn 0.21800000 -0.09020000 0.97180000 -vn 0.23660000 0.00000000 0.97160000 -vn 0.78070000 -0.00010000 0.62490000 -vn 0.72100000 -0.29790000 0.62560000 -vn 0.15960000 -0.06600000 0.98500000 -vn 0.17310000 0.00000000 0.98490000 -vn 0.35050000 -0.14470000 0.92530000 -vn 0.37970000 0.00000000 0.92510000 -vn 0.48560000 -0.20150000 0.85070000 -vn 0.52670000 0.00000000 0.85010000 -vn 0.16660000 -0.16660000 0.97180000 -vn 0.55190000 -0.55180000 0.62530000 -vn 0.12190000 -0.12190000 0.98500000 -vn 0.26770000 -0.26770000 0.92560000 -vn 0.37130000 -0.37130000 0.85100000 -vn 0.09020000 -0.21800000 0.97180000 -vn 0.29800000 -0.72110000 0.62550000 -vn 0.06600000 -0.15960000 0.98500000 -vn 0.14470000 -0.35050000 0.92530000 -vn 0.20150000 -0.48560000 0.85070000 -vn 0.00000000 -0.23660000 0.97160000 -vn -0.00010000 -0.78070000 0.62490000 -vn 0.00000000 -0.17310000 0.98490000 -vn 0.00000000 -0.37970000 0.92510000 -vn 0.00000000 -0.52670000 0.85010000 -vn -0.09020000 -0.21800000 0.97180000 -vn -0.29790000 -0.72100000 0.62560000 -vn -0.06600000 -0.15960000 0.98500000 -vn -0.14470000 -0.35050000 0.92530000 -vn -0.20150000 -0.48560000 0.85070000 -vn -0.16660000 -0.16660000 0.97180000 -vn -0.55180000 -0.55190000 0.62530000 -vn -0.12190000 -0.12190000 0.98500000 -vn -0.26770000 -0.26770000 0.92560000 -vn -0.37130000 -0.37130000 0.85100000 -vn -0.21800000 -0.09020000 0.97180000 -vn -0.72110000 -0.29800000 0.62550000 -vn -0.15960000 -0.06600000 0.98500000 -vn -0.35050000 -0.14470000 0.92530000 -vn -0.48560000 -0.20150000 0.85070000 -vn -0.23660000 0.00000000 0.97160000 -vn -0.78070000 0.00010000 0.62490000 -vn -0.17310000 0.00000000 0.98490000 -vn -0.37970000 0.00000000 0.92510000 -vn -0.52670000 0.00000000 0.85010000 -vn -0.21800000 0.09020000 0.97180000 -vn -0.23660000 0.00000000 0.97160000 -vn -0.78070000 0.00010000 0.62490000 -vn -0.72100000 0.29790000 0.62560000 -vn -0.15960000 0.06600000 0.98500000 -vn -0.17310000 0.00000000 0.98490000 -vn -0.35050000 0.14470000 0.92530000 -vn -0.37970000 0.00000000 0.92510000 -vn -0.48560000 0.20150000 0.85070000 -vn -0.52670000 0.00000000 0.85010000 -vn -0.16660000 0.16660000 0.97180000 -vn -0.55190000 0.55180000 0.62530000 -vn -0.12190000 0.12190000 0.98500000 -vn -0.26770000 0.26770000 0.92560000 -vn -0.37130000 0.37130000 0.85100000 -vn -0.09020000 0.21800000 0.97180000 -vn -0.29800000 0.72110000 0.62550000 -vn -0.06600000 0.15960000 0.98500000 -vn -0.14470000 0.35050000 0.92530000 -vn -0.20150000 0.48560000 0.85070000 -vn 0.00000000 0.23660000 0.97160000 -vn 0.00010000 0.78070000 0.62490000 -vn 0.00000000 0.17310000 0.98490000 -vn 0.00000000 0.37970000 0.92510000 -vn 0.00000000 0.52670000 0.85010000 -vn 0.09020000 0.21800000 0.97180000 -vn 0.29790000 0.72100000 0.62560000 -vn 0.06600000 0.15960000 0.98500000 -vn 0.14470000 0.35050000 0.92530000 -vn 0.20150000 0.48560000 0.85070000 -vn 0.16660000 0.16660000 0.97180000 -vn 0.55180000 0.55190000 0.62530000 -vn 0.12190000 0.12190000 0.98500000 -vn 0.26770000 0.26770000 0.92560000 -vn 0.37130000 0.37130000 0.85100000 -vn 0.21800000 0.09020000 0.97180000 -vn 0.72110000 0.29800000 0.62550000 -vn 0.15960000 0.06600000 0.98500000 -vn 0.35050000 0.14470000 0.92530000 -vn 0.48560000 0.20150000 0.85070000 -vn 0.23660000 0.00000000 0.97160000 -vn 0.78070000 -0.00010000 0.62490000 -vn 0.17310000 0.00000000 0.98490000 -vn 0.37970000 0.00000000 0.92510000 -vn 0.52670000 0.00000000 0.85010000 -g Teapot001 Instance_0 -f 1/1/1 2/2/2 3/3/3 -f 3/3/3 4/4/4 1/1/1 -f 5/5/5 6/6/6 2/2/2 -f 2/2/2 1/1/1 5/5/5 -f 7/7/7 8/8/8 6/6/6 -f 6/6/6 5/5/5 7/7/7 -f 9/9/9 10/10/10 8/8/8 -f 8/8/8 7/7/7 9/9/9 -f 11/11/11 1/1/1 4/4/4 -f 4/4/4 12/12/12 11/11/11 -f 13/13/13 5/5/5 1/1/1 -f 1/1/1 11/11/11 13/13/13 -f 14/14/14 7/7/7 5/5/5 -f 5/5/5 13/13/13 14/14/14 -f 15/15/15 9/9/9 7/7/7 -f 7/7/7 14/14/14 15/15/15 -f 16/16/16 11/11/11 12/12/12 -f 12/12/12 17/17/17 16/16/16 -f 18/18/18 13/13/13 11/11/11 -f 11/11/11 16/16/16 18/18/18 -f 19/19/19 14/14/14 13/13/13 -f 13/13/13 18/18/18 19/19/19 -f 20/20/20 15/15/15 14/14/14 -f 14/14/14 19/19/19 20/20/20 -f 21/21/21 16/16/16 17/17/17 -f 17/17/17 22/22/22 21/21/21 -f 23/23/23 18/18/18 16/16/16 -f 16/16/16 21/21/21 23/23/23 -f 24/24/24 19/19/19 18/18/18 -f 18/18/18 23/23/23 24/24/24 -f 25/25/25 20/20/20 19/19/19 -f 19/19/19 24/24/24 25/25/25 -f 26/26/26 21/21/21 22/22/22 -f 22/22/22 27/27/27 26/26/26 -f 28/28/28 23/23/23 21/21/21 -f 21/21/21 26/26/26 28/28/28 -f 29/29/29 24/24/24 23/23/23 -f 23/23/23 28/28/28 29/29/29 -f 30/30/30 25/25/25 24/24/24 -f 24/24/24 29/29/29 30/30/30 -f 31/31/31 26/26/26 27/27/27 -f 27/27/27 32/32/32 31/31/31 -f 33/33/33 28/28/28 26/26/26 -f 26/26/26 31/31/31 33/33/33 -f 34/34/34 29/29/29 28/28/28 -f 28/28/28 33/33/33 34/34/34 -f 35/35/35 30/30/30 29/29/29 -f 29/29/29 34/34/34 35/35/35 -f 36/36/36 31/31/31 32/32/32 -f 32/32/32 37/37/37 36/36/36 -f 38/38/38 33/33/33 31/31/31 -f 31/31/31 36/36/36 38/38/38 -f 39/39/39 34/34/34 33/33/33 -f 33/33/33 38/38/38 39/39/39 -f 40/40/40 35/35/35 34/34/34 -f 34/34/34 39/39/39 40/40/40 -f 41/41/41 36/36/36 37/37/37 -f 37/37/37 42/42/42 41/41/41 -f 43/43/43 38/38/38 36/36/36 -f 36/36/36 41/41/41 43/43/43 -f 44/44/44 39/39/39 38/38/38 -f 38/38/38 43/43/43 44/44/44 -f 45/45/45 40/40/40 39/39/39 -f 39/39/39 44/44/44 45/45/45 -f 46/46/46 47/47/47 48/48/48 -f 48/48/48 49/49/49 46/46/46 -f 50/50/50 51/51/51 47/47/47 -f 47/47/47 46/46/46 50/50/50 -f 52/52/52 53/53/53 51/51/51 -f 51/51/51 50/50/50 52/52/52 -f 54/54/54 55/55/55 53/53/53 -f 53/53/53 52/52/52 54/54/54 -f 56/56/56 46/46/46 49/49/49 -f 49/49/49 57/57/57 56/56/56 -f 58/58/58 50/50/50 46/46/46 -f 46/46/46 56/56/56 58/58/58 -f 59/59/59 52/52/52 50/50/50 -f 50/50/50 58/58/58 59/59/59 -f 60/60/60 54/54/54 52/52/52 -f 52/52/52 59/59/59 60/60/60 -f 61/61/61 56/56/56 57/57/57 -f 57/57/57 62/62/62 61/61/61 -f 63/63/63 58/58/58 56/56/56 -f 56/56/56 61/61/61 63/63/63 -f 64/64/64 59/59/59 58/58/58 -f 58/58/58 63/63/63 64/64/64 -f 65/65/65 60/60/60 59/59/59 -f 59/59/59 64/64/64 65/65/65 -f 66/66/66 61/61/61 62/62/62 -f 62/62/62 67/67/67 66/66/66 -f 68/68/68 63/63/63 61/61/61 -f 61/61/61 66/66/66 68/68/68 -f 69/69/69 64/64/64 63/63/63 -f 63/63/63 68/68/68 69/69/69 -f 70/70/70 65/65/65 64/64/64 -f 64/64/64 69/69/69 70/70/70 -f 71/71/71 66/66/66 67/67/67 -f 67/67/67 72/72/72 71/71/71 -f 73/73/73 68/68/68 66/66/66 -f 66/66/66 71/71/71 73/73/73 -f 74/74/74 69/69/69 68/68/68 -f 68/68/68 73/73/73 74/74/74 -f 75/75/75 70/70/70 69/69/69 -f 69/69/69 74/74/74 75/75/75 -f 76/76/76 71/71/71 72/72/72 -f 72/72/72 77/77/77 76/76/76 -f 78/78/78 73/73/73 71/71/71 -f 71/71/71 76/76/76 78/78/78 -f 79/79/79 74/74/74 73/73/73 -f 73/73/73 78/78/78 79/79/79 -f 80/80/80 75/75/75 74/74/74 -f 74/74/74 79/79/79 80/80/80 -f 81/81/81 76/76/76 77/77/77 -f 77/77/77 82/82/82 81/81/81 -f 83/83/83 78/78/78 76/76/76 -f 76/76/76 81/81/81 83/83/83 -f 84/84/84 79/79/79 78/78/78 -f 78/78/78 83/83/83 84/84/84 -f 85/85/85 80/80/80 79/79/79 -f 79/79/79 84/84/84 85/85/85 -f 86/86/86 81/81/81 82/82/82 -f 82/82/82 87/87/87 86/86/86 -f 88/88/88 83/83/83 81/81/81 -f 81/81/81 86/86/86 88/88/88 -f 89/89/89 84/84/84 83/83/83 -f 83/83/83 88/88/88 89/89/89 -f 90/90/90 85/85/85 84/84/84 -f 84/84/84 89/89/89 90/90/90 -f 91/91/91 92/92/92 10/10/10 -f 10/10/10 9/9/9 91/91/91 -f 93/93/93 94/94/94 92/92/92 -f 92/92/92 91/91/91 93/93/93 -f 95/95/95 96/96/96 94/94/94 -f 94/94/94 93/93/93 95/95/95 -f 97/97/97 98/98/98 96/96/96 -f 96/96/96 95/95/95 97/97/97 -f 99/99/99 91/91/91 9/9/9 -f 9/9/9 15/15/15 99/99/99 -f 100/100/100 93/93/93 91/91/91 -f 91/91/91 99/99/99 100/100/100 -f 101/101/101 95/95/95 93/93/93 -f 93/93/93 100/100/100 101/101/101 -f 102/102/102 97/97/97 95/95/95 -f 95/95/95 101/101/101 102/102/102 -f 103/103/103 99/99/99 15/15/15 -f 15/15/15 20/20/20 103/103/103 -f 104/104/104 100/100/100 99/99/99 -f 99/99/99 103/103/103 104/104/104 -f 105/105/105 101/101/101 100/100/100 -f 100/100/100 104/104/104 105/105/105 -f 106/106/106 102/102/102 101/101/101 -f 101/101/101 105/105/105 106/106/106 -f 107/107/107 103/103/103 20/20/20 -f 20/20/20 25/25/25 107/107/107 -f 108/108/108 104/104/104 103/103/103 -f 103/103/103 107/107/107 108/108/108 -f 109/109/109 105/105/105 104/104/104 -f 104/104/104 108/108/108 109/109/109 -f 110/110/110 106/106/106 105/105/105 -f 105/105/105 109/109/109 110/110/110 -f 111/111/111 107/107/107 25/25/25 -f 25/25/25 30/30/30 111/111/111 -f 112/112/112 108/108/108 107/107/107 -f 107/107/107 111/111/111 112/112/112 -f 113/113/113 109/109/109 108/108/108 -f 108/108/108 112/112/112 113/113/113 -f 114/114/114 110/110/110 109/109/109 -f 109/109/109 113/113/113 114/114/114 -f 115/115/115 111/111/111 30/30/30 -f 30/30/30 35/35/35 115/115/115 -f 116/116/116 112/112/112 111/111/111 -f 111/111/111 115/115/115 116/116/116 -f 117/117/117 113/113/113 112/112/112 -f 112/112/112 116/116/116 117/117/117 -f 118/118/118 114/114/114 113/113/113 -f 113/113/113 117/117/117 118/118/118 -f 119/119/119 115/115/115 35/35/35 -f 35/35/35 40/40/40 119/119/119 -f 120/120/120 116/116/116 115/115/115 -f 115/115/115 119/119/119 120/120/120 -f 121/121/121 117/117/117 116/116/116 -f 116/116/116 120/120/120 121/121/121 -f 122/122/122 118/118/118 117/117/117 -f 117/117/117 121/121/121 122/122/122 -f 123/123/123 119/119/119 40/40/40 -f 40/40/40 45/45/45 123/123/123 -f 124/124/124 120/120/120 119/119/119 -f 119/119/119 123/123/123 124/124/124 -f 125/125/125 121/121/121 120/120/120 -f 120/120/120 124/124/124 125/125/125 -f 126/126/126 122/122/122 121/121/121 -f 121/121/121 125/125/125 126/126/126 -f 127/127/127 128/128/128 55/55/55 -f 55/55/55 54/54/54 127/127/127 -f 129/129/129 130/130/130 128/128/128 -f 128/128/128 127/127/127 129/129/129 -f 131/131/131 132/132/132 130/130/130 -f 130/130/130 129/129/129 131/131/131 -f 133/133/133 134/134/134 132/132/132 -f 132/132/132 131/131/131 133/133/133 -f 135/135/135 127/127/127 54/54/54 -f 54/54/54 60/60/60 135/135/135 -f 136/136/136 129/129/129 127/127/127 -f 127/127/127 135/135/135 136/136/136 -f 137/137/137 131/131/131 129/129/129 -f 129/129/129 136/136/136 137/137/137 -f 138/138/138 133/133/133 131/131/131 -f 131/131/131 137/137/137 138/138/138 -f 139/139/139 135/135/135 60/60/60 -f 60/60/60 65/65/65 139/139/139 -f 140/140/140 136/136/136 135/135/135 -f 135/135/135 139/139/139 140/140/140 -f 141/141/141 137/137/137 136/136/136 -f 136/136/136 140/140/140 141/141/141 -f 142/142/142 138/138/138 137/137/137 -f 137/137/137 141/141/141 142/142/142 -f 143/143/143 139/139/139 65/65/65 -f 65/65/65 70/70/70 143/143/143 -f 144/144/144 140/140/140 139/139/139 -f 139/139/139 143/143/143 144/144/144 -f 145/145/145 141/141/141 140/140/140 -f 140/140/140 144/144/144 145/145/145 -f 146/146/146 142/142/142 141/141/141 -f 141/141/141 145/145/145 146/146/146 -f 147/147/147 143/143/143 70/70/70 -f 70/70/70 75/75/75 147/147/147 -f 148/148/148 144/144/144 143/143/143 -f 143/143/143 147/147/147 148/148/148 -f 149/149/149 145/145/145 144/144/144 -f 144/144/144 148/148/148 149/149/149 -f 150/150/150 146/146/146 145/145/145 -f 145/145/145 149/149/149 150/150/150 -f 151/151/151 147/147/147 75/75/75 -f 75/75/75 80/80/80 151/151/151 -f 152/152/152 148/148/148 147/147/147 -f 147/147/147 151/151/151 152/152/152 -f 153/153/153 149/149/149 148/148/148 -f 148/148/148 152/152/152 153/153/153 -f 154/154/154 150/150/150 149/149/149 -f 149/149/149 153/153/153 154/154/154 -f 155/155/155 151/151/151 80/80/80 -f 80/80/80 85/85/85 155/155/155 -f 156/156/156 152/152/152 151/151/151 -f 151/151/151 155/155/155 156/156/156 -f 157/157/157 153/153/153 152/152/152 -f 152/152/152 156/156/156 157/157/157 -f 158/158/158 154/154/154 153/153/153 -f 153/153/153 157/157/157 158/158/158 -f 159/159/159 155/155/155 85/85/85 -f 85/85/85 90/90/90 159/159/159 -f 160/160/160 156/156/156 155/155/155 -f 155/155/155 159/159/159 160/160/160 -f 161/161/161 157/157/157 156/156/156 -f 156/156/156 160/160/160 161/161/161 -f 162/162/162 158/158/158 157/157/157 -f 157/157/157 161/161/161 162/162/162 -f 163/163/163 164/164/164 98/98/98 -f 98/98/98 97/97/97 163/163/163 -f 165/165/165 166/166/166 164/164/164 -f 164/164/164 163/163/163 165/165/165 -f 167/167/167 168/168/168 166/166/166 -f 166/166/166 165/165/165 167/167/167 -f 169/169/169 170/170/170 168/168/168 -f 168/168/168 167/167/167 169/169/169 -f 171/171/171 163/163/163 97/97/97 -f 97/97/97 102/102/102 171/171/171 -f 172/172/172 165/165/165 163/163/163 -f 163/163/163 171/171/171 172/172/172 -f 173/173/173 167/167/167 165/165/165 -f 165/165/165 172/172/172 173/173/173 -f 174/174/174 169/169/169 167/167/167 -f 167/167/167 173/173/173 174/174/174 -f 175/175/175 171/171/171 102/102/102 -f 102/102/102 106/106/106 175/175/175 -f 176/176/176 172/172/172 171/171/171 -f 171/171/171 175/175/175 176/176/176 -f 177/177/177 173/173/173 172/172/172 -f 172/172/172 176/176/176 177/177/177 -f 178/178/178 174/174/174 173/173/173 -f 173/173/173 177/177/177 178/178/178 -f 179/179/179 175/175/175 106/106/106 -f 106/106/106 110/110/110 179/179/179 -f 180/180/180 176/176/176 175/175/175 -f 175/175/175 179/179/179 180/180/180 -f 181/181/181 177/177/177 176/176/176 -f 176/176/176 180/180/180 181/181/181 -f 182/182/182 178/178/178 177/177/177 -f 177/177/177 181/181/181 182/182/182 -f 183/183/183 179/179/179 110/110/110 -f 110/110/110 114/114/114 183/183/183 -f 184/184/184 180/180/180 179/179/179 -f 179/179/179 183/183/183 184/184/184 -f 185/185/185 181/181/181 180/180/180 -f 180/180/180 184/184/184 185/185/185 -f 186/186/186 182/182/182 181/181/181 -f 181/181/181 185/185/185 186/186/186 -f 187/187/187 183/183/183 114/114/114 -f 114/114/114 118/118/118 187/187/187 -f 188/188/188 184/184/184 183/183/183 -f 183/183/183 187/187/187 188/188/188 -f 189/189/189 185/185/185 184/184/184 -f 184/184/184 188/188/188 189/189/189 -f 190/190/190 186/186/186 185/185/185 -f 185/185/185 189/189/189 190/190/190 -f 191/191/191 187/187/187 118/118/118 -f 118/118/118 122/122/122 191/191/191 -f 192/192/192 188/188/188 187/187/187 -f 187/187/187 191/191/191 192/192/192 -f 193/193/193 189/189/189 188/188/188 -f 188/188/188 192/192/192 193/193/193 -f 194/194/194 190/190/190 189/189/189 -f 189/189/189 193/193/193 194/194/194 -f 195/195/195 191/191/191 122/122/122 -f 122/122/122 126/126/126 195/195/195 -f 196/196/196 192/192/192 191/191/191 -f 191/191/191 195/195/195 196/196/196 -f 197/197/197 193/193/193 192/192/192 -f 192/192/192 196/196/196 197/197/197 -f 198/198/198 194/194/194 193/193/193 -f 193/193/193 197/197/197 198/198/198 -f 199/199/199 200/200/200 134/134/134 -f 134/134/134 133/133/133 199/199/199 -f 201/201/201 202/202/202 200/200/200 -f 200/200/200 199/199/199 201/201/201 -f 203/203/203 204/204/204 202/202/202 -f 202/202/202 201/201/201 203/203/203 -f 205/205/205 206/206/206 204/204/204 -f 204/204/204 203/203/203 205/205/205 -f 207/207/207 199/199/199 133/133/133 -f 133/133/133 138/138/138 207/207/207 -f 208/208/208 201/201/201 199/199/199 -f 199/199/199 207/207/207 208/208/208 -f 209/209/209 203/203/203 201/201/201 -f 201/201/201 208/208/208 209/209/209 -f 210/210/210 205/205/205 203/203/203 -f 203/203/203 209/209/209 210/210/210 -f 211/211/211 207/207/207 138/138/138 -f 138/138/138 142/142/142 211/211/211 -f 212/212/212 208/208/208 207/207/207 -f 207/207/207 211/211/211 212/212/212 -f 213/213/213 209/209/209 208/208/208 -f 208/208/208 212/212/212 213/213/213 -f 214/214/214 210/210/210 209/209/209 -f 209/209/209 213/213/213 214/214/214 -f 215/215/215 211/211/211 142/142/142 -f 142/142/142 146/146/146 215/215/215 -f 216/216/216 212/212/212 211/211/211 -f 211/211/211 215/215/215 216/216/216 -f 217/217/217 213/213/213 212/212/212 -f 212/212/212 216/216/216 217/217/217 -f 218/218/218 214/214/214 213/213/213 -f 213/213/213 217/217/217 218/218/218 -f 219/219/219 215/215/215 146/146/146 -f 146/146/146 150/150/150 219/219/219 -f 220/220/220 216/216/216 215/215/215 -f 215/215/215 219/219/219 220/220/220 -f 221/221/221 217/217/217 216/216/216 -f 216/216/216 220/220/220 221/221/221 -f 222/222/222 218/218/218 217/217/217 -f 217/217/217 221/221/221 222/222/222 -f 223/223/223 219/219/219 150/150/150 -f 150/150/150 154/154/154 223/223/223 -f 224/224/224 220/220/220 219/219/219 -f 219/219/219 223/223/223 224/224/224 -f 225/225/225 221/221/221 220/220/220 -f 220/220/220 224/224/224 225/225/225 -f 226/226/226 222/222/222 221/221/221 -f 221/221/221 225/225/225 226/226/226 -f 227/227/227 223/223/223 154/154/154 -f 154/154/154 158/158/158 227/227/227 -f 228/228/228 224/224/224 223/223/223 -f 223/223/223 227/227/227 228/228/228 -f 229/229/229 225/225/225 224/224/224 -f 224/224/224 228/228/228 229/229/229 -f 230/230/230 226/226/226 225/225/225 -f 225/225/225 229/229/229 230/230/230 -f 231/231/231 227/227/227 158/158/158 -f 158/158/158 162/162/162 231/231/231 -f 232/232/232 228/228/228 227/227/227 -f 227/227/227 231/231/231 232/232/232 -f 233/233/233 229/229/229 228/228/228 -f 228/228/228 232/232/232 233/233/233 -f 234/234/234 230/230/230 229/229/229 -f 229/229/229 233/233/233 234/234/234 -f 235/235/235 236/236/236 170/170/170 -f 170/170/170 169/169/169 235/235/235 -f 237/237/237 238/238/238 236/236/236 -f 236/236/236 235/235/235 237/237/237 -f 239/239/239 240/240/240 238/238/238 -f 238/238/238 237/237/237 239/239/239 -f 240/240/240 239/239/239 241/241/241 -f 242/242/242 235/235/235 169/169/169 -f 169/169/169 174/174/174 242/242/242 -f 243/243/243 237/237/237 235/235/235 -f 235/235/235 242/242/242 243/243/243 -f 244/244/244 239/239/239 237/237/237 -f 237/237/237 243/243/243 244/244/244 -f 239/239/239 244/244/244 245/245/245 -f 246/246/246 242/242/242 174/174/174 -f 174/174/174 178/178/178 246/246/246 -f 247/247/247 243/243/243 242/242/242 -f 242/242/242 246/246/246 247/247/247 -f 248/248/248 244/244/244 243/243/243 -f 243/243/243 247/247/247 248/248/248 -f 244/244/244 248/248/248 249/249/249 -f 250/250/250 246/246/246 178/178/178 -f 178/178/178 182/182/182 250/250/250 -f 251/251/251 247/247/247 246/246/246 -f 246/246/246 250/250/250 251/251/251 -f 252/252/252 248/248/248 247/247/247 -f 247/247/247 251/251/251 252/252/252 -f 248/248/248 252/252/252 253/253/253 -f 254/254/254 250/250/250 182/182/182 -f 182/182/182 186/186/186 254/254/254 -f 255/255/255 251/251/251 250/250/250 -f 250/250/250 254/254/254 255/255/255 -f 256/256/256 252/252/252 251/251/251 -f 251/251/251 255/255/255 256/256/256 -f 252/252/252 256/256/256 257/257/257 -f 258/258/258 254/254/254 186/186/186 -f 186/186/186 190/190/190 258/258/258 -f 259/259/259 255/255/255 254/254/254 -f 254/254/254 258/258/258 259/259/259 -f 260/260/260 256/256/256 255/255/255 -f 255/255/255 259/259/259 260/260/260 -f 256/256/256 260/260/260 261/261/261 -f 262/262/262 258/258/258 190/190/190 -f 190/190/190 194/194/194 262/262/262 -f 263/263/263 259/259/259 258/258/258 -f 258/258/258 262/262/262 263/263/263 -f 264/264/264 260/260/260 259/259/259 -f 259/259/259 263/263/263 264/264/264 -f 260/260/260 264/264/264 265/265/265 -f 266/266/266 262/262/262 194/194/194 -f 194/194/194 198/198/198 266/266/266 -f 267/267/267 263/263/263 262/262/262 -f 262/262/262 266/266/266 267/267/267 -f 268/268/268 264/264/264 263/263/263 -f 263/263/263 267/267/267 268/268/268 -f 264/264/264 268/268/268 269/269/269 -f 270/270/270 271/271/271 206/206/206 -f 206/206/206 205/205/205 270/270/270 -f 272/272/272 273/273/273 271/271/271 -f 271/271/271 270/270/270 272/272/272 -f 274/274/274 275/275/275 273/273/273 -f 273/273/273 272/272/272 274/274/274 -f 275/275/275 274/274/274 241/241/241 -f 276/276/276 270/270/270 205/205/205 -f 205/205/205 210/210/210 276/276/276 -f 277/277/277 272/272/272 270/270/270 -f 270/270/270 276/276/276 277/277/277 -f 278/278/278 274/274/274 272/272/272 -f 272/272/272 277/277/277 278/278/278 -f 274/274/274 278/278/278 245/245/245 -f 279/279/279 276/276/276 210/210/210 -f 210/210/210 214/214/214 279/279/279 -f 280/280/280 277/277/277 276/276/276 -f 276/276/276 279/279/279 280/280/280 -f 281/281/281 278/278/278 277/277/277 -f 277/277/277 280/280/280 281/281/281 -f 278/278/278 281/281/281 249/249/249 -f 282/282/282 279/279/279 214/214/214 -f 214/214/214 218/218/218 282/282/282 -f 283/283/283 280/280/280 279/279/279 -f 279/279/279 282/282/282 283/283/283 -f 284/284/284 281/281/281 280/280/280 -f 280/280/280 283/283/283 284/284/284 -f 281/281/281 284/284/284 253/253/253 -f 285/285/285 282/282/282 218/218/218 -f 218/218/218 222/222/222 285/285/285 -f 286/286/286 283/283/283 282/282/282 -f 282/282/282 285/285/285 286/286/286 -f 287/287/287 284/284/284 283/283/283 -f 283/283/283 286/286/286 287/287/287 -f 284/284/284 287/287/287 257/257/257 -f 288/288/288 285/285/285 222/222/222 -f 222/222/222 226/226/226 288/288/288 -f 289/289/289 286/286/286 285/285/285 -f 285/285/285 288/288/288 289/289/289 -f 290/290/290 287/287/287 286/286/286 -f 286/286/286 289/289/289 290/290/290 -f 287/287/287 290/290/290 261/261/261 -f 291/291/291 288/288/288 226/226/226 -f 226/226/226 230/230/230 291/291/291 -f 292/292/292 289/289/289 288/288/288 -f 288/288/288 291/291/291 292/292/292 -f 293/293/293 290/290/290 289/289/289 -f 289/289/289 292/292/292 293/293/293 -f 290/290/290 293/293/293 265/265/265 -f 294/294/294 291/291/291 230/230/230 -f 230/230/230 234/234/234 294/294/294 -f 295/295/295 292/292/292 291/291/291 -f 291/291/291 294/294/294 295/295/295 -f 296/296/296 293/293/293 292/292/292 -f 292/292/292 295/295/295 296/296/296 -f 293/293/293 296/296/296 269/269/269 -f 297/297/297 298/298/298 299/299/299 -f 299/299/299 300/300/300 297/297/297 -f 301/301/301 302/302/302 298/298/298 -f 298/298/298 297/297/297 301/301/301 -f 303/303/303 304/304/304 302/302/302 -f 302/302/302 301/301/301 303/303/303 -f 305/305/305 306/306/306 304/304/304 -f 304/304/304 303/303/303 305/305/305 -f 307/307/307 297/297/297 300/300/300 -f 300/300/300 308/308/308 307/307/307 -f 309/309/309 301/301/301 297/297/297 -f 297/297/297 307/307/307 309/309/309 -f 310/310/310 303/303/303 301/301/301 -f 301/301/301 309/309/309 310/310/310 -f 311/311/311 305/305/305 303/303/303 -f 303/303/303 310/310/310 311/311/311 -f 312/312/312 307/307/307 308/308/308 -f 308/308/308 313/313/313 312/312/312 -f 314/314/314 309/309/309 307/307/307 -f 307/307/307 312/312/312 314/314/314 -f 315/315/315 310/310/310 309/309/309 -f 309/309/309 314/314/314 315/315/315 -f 316/316/316 311/311/311 310/310/310 -f 310/310/310 315/315/315 316/316/316 -f 317/317/317 312/312/312 313/313/313 -f 313/313/313 318/318/318 317/317/317 -f 319/319/319 314/314/314 312/312/312 -f 312/312/312 317/317/317 319/319/319 -f 320/320/320 315/315/315 314/314/314 -f 314/314/314 319/319/319 320/320/320 -f 321/321/321 316/316/316 315/315/315 -f 315/315/315 320/320/320 321/321/321 -f 322/322/322 317/317/317 318/318/318 -f 318/318/318 323/323/323 322/322/322 -f 324/324/324 319/319/319 317/317/317 -f 317/317/317 322/322/322 324/324/324 -f 325/325/325 320/320/320 319/319/319 -f 319/319/319 324/324/324 325/325/325 -f 326/326/326 321/321/321 320/320/320 -f 320/320/320 325/325/325 326/326/326 -f 327/327/327 322/322/322 323/323/323 -f 323/323/323 328/328/328 327/327/327 -f 329/329/329 324/324/324 322/322/322 -f 322/322/322 327/327/327 329/329/329 -f 330/330/330 325/325/325 324/324/324 -f 324/324/324 329/329/329 330/330/330 -f 331/331/331 326/326/326 325/325/325 -f 325/325/325 330/330/330 331/331/331 -f 332/332/332 327/327/327 328/328/328 -f 328/328/328 333/333/333 332/332/332 -f 334/334/334 329/329/329 327/327/327 -f 327/327/327 332/332/332 334/334/334 -f 335/335/335 330/330/330 329/329/329 -f 329/329/329 334/334/334 335/335/335 -f 336/336/336 331/331/331 330/330/330 -f 330/330/330 335/335/335 336/336/336 -f 337/337/337 332/332/332 333/333/333 -f 333/333/333 338/338/338 337/337/337 -f 339/339/339 334/334/334 332/332/332 -f 332/332/332 337/337/337 339/339/339 -f 340/340/340 335/335/335 334/334/334 -f 334/334/334 339/339/339 340/340/340 -f 341/341/341 336/336/336 335/335/335 -f 335/335/335 340/340/340 341/341/341 -f 342/342/342 343/343/343 306/306/306 -f 306/306/306 305/305/305 342/342/342 -f 344/344/344 345/345/345 343/343/343 -f 343/343/343 342/342/342 344/344/344 -f 346/346/346 347/347/347 345/345/345 -f 345/345/345 344/344/344 346/346/346 -f 348/348/348 349/349/349 347/347/347 -f 347/347/347 346/346/346 348/348/348 -f 350/350/350 342/342/342 305/305/305 -f 305/305/305 311/311/311 350/350/350 -f 351/351/351 344/344/344 342/342/342 -f 342/342/342 350/350/350 351/351/351 -f 352/352/352 346/346/346 344/344/344 -f 344/344/344 351/351/351 352/352/352 -f 353/353/353 348/348/348 346/346/346 -f 346/346/346 352/352/352 353/353/353 -f 354/354/354 350/350/350 311/311/311 -f 311/311/311 316/316/316 354/354/354 -f 355/355/355 351/351/351 350/350/350 -f 350/350/350 354/354/354 355/355/355 -f 356/356/356 352/352/352 351/351/351 -f 351/351/351 355/355/355 356/356/356 -f 357/357/357 353/353/353 352/352/352 -f 352/352/352 356/356/356 357/357/357 -f 358/358/358 354/354/354 316/316/316 -f 316/316/316 321/321/321 358/358/358 -f 359/359/359 355/355/355 354/354/354 -f 354/354/354 358/358/358 359/359/359 -f 360/360/360 356/356/356 355/355/355 -f 355/355/355 359/359/359 360/360/360 -f 361/361/361 357/357/357 356/356/356 -f 356/356/356 360/360/360 361/361/361 -f 362/362/362 358/358/358 321/321/321 -f 321/321/321 326/326/326 362/362/362 -f 363/363/363 359/359/359 358/358/358 -f 358/358/358 362/362/362 363/363/363 -f 364/364/364 360/360/360 359/359/359 -f 359/359/359 363/363/363 364/364/364 -f 365/365/365 361/361/361 360/360/360 -f 360/360/360 364/364/364 365/365/365 -f 366/366/366 362/362/362 326/326/326 -f 326/326/326 331/331/331 366/366/366 -f 367/367/367 363/363/363 362/362/362 -f 362/362/362 366/366/366 367/367/367 -f 368/368/368 364/364/364 363/363/363 -f 363/363/363 367/367/367 368/368/368 -f 369/369/369 365/365/365 364/364/364 -f 364/364/364 368/368/368 369/369/369 -f 370/370/370 366/366/366 331/331/331 -f 331/331/331 336/336/336 370/370/370 -f 371/371/371 367/367/367 366/366/366 -f 366/366/366 370/370/370 371/371/371 -f 372/372/372 368/368/368 367/367/367 -f 367/367/367 371/371/371 372/372/372 -f 373/373/373 369/369/369 368/368/368 -f 368/368/368 372/372/372 373/373/373 -f 374/374/374 370/370/370 336/336/336 -f 336/336/336 341/341/341 374/374/374 -f 375/375/375 371/371/371 370/370/370 -f 370/370/370 374/374/374 375/375/375 -f 376/376/376 372/372/372 371/371/371 -f 371/371/371 375/375/375 376/376/376 -f 377/377/377 373/373/373 372/372/372 -f 372/372/372 376/376/376 377/377/377 -f 378/378/378 379/379/379 380/380/380 -f 380/380/380 381/381/381 378/378/378 -f 382/382/382 383/383/383 379/379/379 -f 379/379/379 378/378/378 382/382/382 -f 384/384/384 385/385/385 383/383/383 -f 383/383/383 382/382/382 384/384/384 -f 386/386/386 387/387/387 385/385/385 -f 385/385/385 384/384/384 386/386/386 -f 388/388/388 378/378/378 381/381/381 -f 381/381/381 389/389/389 388/388/388 -f 390/390/390 382/382/382 378/378/378 -f 378/378/378 388/388/388 390/390/390 -f 391/391/391 384/384/384 382/382/382 -f 382/382/382 390/390/390 391/391/391 -f 392/392/392 386/386/386 384/384/384 -f 384/384/384 391/391/391 392/392/392 -f 393/393/393 388/388/388 389/389/389 -f 389/389/389 394/394/394 393/393/393 -f 395/395/395 390/390/390 388/388/388 -f 388/388/388 393/393/393 395/395/395 -f 396/396/396 391/391/391 390/390/390 -f 390/390/390 395/395/395 396/396/396 -f 397/397/397 392/392/392 391/391/391 -f 391/391/391 396/396/396 397/397/397 -f 398/398/398 393/393/393 394/394/394 -f 394/394/394 399/399/399 398/398/398 -f 400/400/400 395/395/395 393/393/393 -f 393/393/393 398/398/398 400/400/400 -f 401/401/401 396/396/396 395/395/395 -f 395/395/395 400/400/400 401/401/401 -f 402/402/402 397/397/397 396/396/396 -f 396/396/396 401/401/401 402/402/402 -f 403/403/403 404/404/404 405/405/405 -f 405/405/405 406/406/406 403/403/403 -f 407/407/407 408/408/408 404/404/404 -f 404/404/404 403/403/403 407/407/407 -f 409/409/409 410/410/410 408/408/408 -f 408/408/408 407/407/407 409/409/409 -f 411/411/411 412/412/412 410/410/410 -f 410/410/410 409/409/409 411/411/411 -f 413/413/413 403/403/403 406/406/406 -f 406/406/406 414/414/414 413/413/413 -f 415/415/415 407/407/407 403/403/403 -f 403/403/403 413/413/413 415/415/415 -f 416/416/416 409/409/409 407/407/407 -f 407/407/407 415/415/415 416/416/416 -f 417/417/417 411/411/411 409/409/409 -f 409/409/409 416/416/416 417/417/417 -f 418/418/418 413/413/413 414/414/414 -f 414/414/414 419/419/419 418/418/418 -f 420/420/420 415/415/415 413/413/413 -f 413/413/413 418/418/418 420/420/420 -f 421/421/421 416/416/416 415/415/415 -f 415/415/415 420/420/420 421/421/421 -f 422/422/422 417/417/417 416/416/416 -f 416/416/416 421/421/421 422/422/422 -f 379/379/379 418/418/418 419/419/419 -f 419/419/419 380/380/380 379/379/379 -f 383/383/383 420/420/420 418/418/418 -f 418/418/418 379/379/379 383/383/383 -f 385/385/385 421/421/421 420/420/420 -f 420/420/420 383/383/383 385/385/385 -f 387/387/387 422/422/422 421/421/421 -f 421/421/421 385/385/385 387/387/387 -f 423/423/423 424/424/424 387/387/387 -f 387/387/387 386/386/386 423/423/423 -f 425/425/425 426/426/426 424/424/424 -f 424/424/424 423/423/423 425/425/425 -f 427/427/427 428/428/428 426/426/426 -f 426/426/426 425/425/425 427/427/427 -f 429/429/429 430/430/430 428/428/428 -f 428/428/428 427/427/427 429/429/429 -f 431/431/431 423/423/423 386/386/386 -f 386/386/386 392/392/392 431/431/431 -f 432/432/432 425/425/425 423/423/423 -f 423/423/423 431/431/431 432/432/432 -f 433/433/433 427/427/427 425/425/425 -f 425/425/425 432/432/432 433/433/433 -f 434/434/434 429/429/429 427/427/427 -f 427/427/427 433/433/433 434/434/434 -f 435/435/435 431/431/431 392/392/392 -f 392/392/392 397/397/397 435/435/435 -f 436/436/436 432/432/432 431/431/431 -f 431/431/431 435/435/435 436/436/436 -f 437/437/437 433/433/433 432/432/432 -f 432/432/432 436/436/436 437/437/437 -f 438/438/438 434/434/434 433/433/433 -f 433/433/433 437/437/437 438/438/438 -f 439/439/439 435/435/435 397/397/397 -f 397/397/397 402/402/402 439/439/439 -f 440/440/440 436/436/436 435/435/435 -f 435/435/435 439/439/439 440/440/440 -f 441/441/441 437/437/437 436/436/436 -f 436/436/436 440/440/440 441/441/441 -f 442/442/442 438/438/438 437/437/437 -f 437/437/437 441/441/441 442/442/442 -f 443/443/443 444/444/444 412/412/412 -f 412/412/412 411/411/411 443/443/443 -f 445/445/445 446/446/446 444/444/444 -f 444/444/444 443/443/443 445/445/445 -f 447/447/447 448/448/448 446/446/446 -f 446/446/446 445/445/445 447/447/447 -f 449/449/449 450/450/450 448/448/448 -f 448/448/448 447/447/447 449/449/449 -f 451/451/451 443/443/443 411/411/411 -f 411/411/411 417/417/417 451/451/451 -f 452/452/452 445/445/445 443/443/443 -f 443/443/443 451/451/451 452/452/452 -f 453/453/453 447/447/447 445/445/445 -f 445/445/445 452/452/452 453/453/453 -f 454/454/454 449/449/449 447/447/447 -f 447/447/447 453/453/453 454/454/454 -f 455/455/455 451/451/451 417/417/417 -f 417/417/417 422/422/422 455/455/455 -f 456/456/456 452/452/452 451/451/451 -f 451/451/451 455/455/455 456/456/456 -f 457/457/457 453/453/453 452/452/452 -f 452/452/452 456/456/456 457/457/457 -f 458/458/458 454/454/454 453/453/453 -f 453/453/453 457/457/457 458/458/458 -f 424/424/424 455/455/455 422/422/422 -f 422/422/422 387/387/387 424/424/424 -f 426/426/426 456/456/456 455/455/455 -f 455/455/455 424/424/424 426/426/426 -f 428/428/428 457/457/457 456/456/456 -f 456/456/456 426/426/426 428/428/428 -f 430/430/430 458/458/458 457/457/457 -f 457/457/457 428/428/428 430/430/430 -f 459/459/459 460/460/460 461/461/461 -f 462/462/462 463/463/463 460/460/460 -f 460/460/460 459/459/459 462/462/462 -f 464/464/464 465/465/465 463/463/463 -f 463/463/463 462/462/462 464/464/464 -f 466/466/466 467/467/467 465/465/465 -f 465/465/465 464/464/464 466/466/466 -f 468/468/468 459/459/459 469/469/469 -f 470/470/470 462/462/462 459/459/459 -f 459/459/459 468/468/468 470/470/470 -f 471/471/471 464/464/464 462/462/462 -f 462/462/462 470/470/470 471/471/471 -f 472/472/472 466/466/466 464/464/464 -f 464/464/464 471/471/471 472/472/472 -f 473/473/473 468/468/468 474/474/474 -f 475/475/475 470/470/470 468/468/468 -f 468/468/468 473/473/473 475/475/475 -f 476/476/476 471/471/471 470/470/470 -f 470/470/470 475/475/475 476/476/476 -f 477/477/477 472/472/472 471/471/471 -f 471/471/471 476/476/476 477/477/477 -f 478/478/478 473/473/473 479/479/479 -f 480/480/480 475/475/475 473/473/473 -f 473/473/473 478/478/478 480/480/480 -f 481/481/481 476/476/476 475/475/475 -f 475/475/475 480/480/480 481/481/481 -f 482/482/482 477/477/477 476/476/476 -f 476/476/476 481/481/481 482/482/482 -f 483/483/483 478/478/478 484/484/484 -f 485/485/485 480/480/480 478/478/478 -f 478/478/478 483/483/483 485/485/485 -f 486/486/486 481/481/481 480/480/480 -f 480/480/480 485/485/485 486/486/486 -f 487/487/487 482/482/482 481/481/481 -f 481/481/481 486/486/486 487/487/487 -f 488/488/488 483/483/483 489/489/489 -f 490/490/490 485/485/485 483/483/483 -f 483/483/483 488/488/488 490/490/490 -f 491/491/491 486/486/486 485/485/485 -f 485/485/485 490/490/490 491/491/491 -f 492/492/492 487/487/487 486/486/486 -f 486/486/486 491/491/491 492/492/492 -f 493/493/493 488/488/488 494/494/494 -f 495/495/495 490/490/490 488/488/488 -f 488/488/488 493/493/493 495/495/495 -f 496/496/496 491/491/491 490/490/490 -f 490/490/490 495/495/495 496/496/496 -f 497/497/497 492/492/492 491/491/491 -f 491/491/491 496/496/496 497/497/497 -f 498/498/498 493/493/493 499/499/499 -f 500/500/500 495/495/495 493/493/493 -f 493/493/493 498/498/498 500/500/500 -f 501/501/501 496/496/496 495/495/495 -f 495/495/495 500/500/500 501/501/501 -f 502/502/502 497/497/497 496/496/496 -f 496/496/496 501/501/501 502/502/502 -f 503/503/503 504/504/504 461/461/461 -f 505/505/505 506/506/506 504/504/504 -f 504/504/504 503/503/503 505/505/505 -f 507/507/507 508/508/508 506/506/506 -f 506/506/506 505/505/505 507/507/507 -f 509/509/509 510/510/510 508/508/508 -f 508/508/508 507/507/507 509/509/509 -f 511/511/511 503/503/503 469/469/469 -f 512/512/512 505/505/505 503/503/503 -f 503/503/503 511/511/511 512/512/512 -f 513/513/513 507/507/507 505/505/505 -f 505/505/505 512/512/512 513/513/513 -f 514/514/514 509/509/509 507/507/507 -f 507/507/507 513/513/513 514/514/514 -f 515/515/515 511/511/511 474/474/474 -f 516/516/516 512/512/512 511/511/511 -f 511/511/511 515/515/515 516/516/516 -f 517/517/517 513/513/513 512/512/512 -f 512/512/512 516/516/516 517/517/517 -f 518/518/518 514/514/514 513/513/513 -f 513/513/513 517/517/517 518/518/518 -f 519/519/519 515/515/515 479/479/479 -f 520/520/520 516/516/516 515/515/515 -f 515/515/515 519/519/519 520/520/520 -f 521/521/521 517/517/517 516/516/516 -f 516/516/516 520/520/520 521/521/521 -f 522/522/522 518/518/518 517/517/517 -f 517/517/517 521/521/521 522/522/522 -f 523/523/523 519/519/519 484/484/484 -f 524/524/524 520/520/520 519/519/519 -f 519/519/519 523/523/523 524/524/524 -f 525/525/525 521/521/521 520/520/520 -f 520/520/520 524/524/524 525/525/525 -f 526/526/526 522/522/522 521/521/521 -f 521/521/521 525/525/525 526/526/526 -f 527/527/527 523/523/523 489/489/489 -f 528/528/528 524/524/524 523/523/523 -f 523/523/523 527/527/527 528/528/528 -f 529/529/529 525/525/525 524/524/524 -f 524/524/524 528/528/528 529/529/529 -f 530/530/530 526/526/526 525/525/525 -f 525/525/525 529/529/529 530/530/530 -f 531/531/531 527/527/527 494/494/494 -f 532/532/532 528/528/528 527/527/527 -f 527/527/527 531/531/531 532/532/532 -f 533/533/533 529/529/529 528/528/528 -f 528/528/528 532/532/532 533/533/533 -f 534/534/534 530/530/530 529/529/529 -f 529/529/529 533/533/533 534/534/534 -f 535/535/535 531/531/531 499/499/499 -f 536/536/536 532/532/532 531/531/531 -f 531/531/531 535/535/535 536/536/536 -f 537/537/537 533/533/533 532/532/532 -f 532/532/532 536/536/536 537/537/537 -f 538/538/538 534/534/534 533/533/533 -f 533/533/533 537/537/537 538/538/538 -f 539/539/539 540/540/540 541/541/541 -f 541/541/541 542/542/542 539/539/539 -f 543/543/543 544/544/544 540/540/540 -f 540/540/540 539/539/539 543/543/543 -f 545/545/545 546/546/546 544/544/544 -f 544/544/544 543/543/543 545/545/545 -f 547/547/547 548/548/548 546/546/546 -f 546/546/546 545/545/545 547/547/547 -f 549/549/549 539/539/539 542/542/542 -f 542/542/542 550/550/550 549/549/549 -f 551/551/551 543/543/543 539/539/539 -f 539/539/539 549/549/549 551/551/551 -f 552/552/552 545/545/545 543/543/543 -f 543/543/543 551/551/551 552/552/552 -f 553/553/553 547/547/547 545/545/545 -f 545/545/545 552/552/552 553/553/553 -f 554/554/554 549/549/549 550/550/550 -f 550/550/550 555/555/555 554/554/554 -f 556/556/556 551/551/551 549/549/549 -f 549/549/549 554/554/554 556/556/556 -f 557/557/557 552/552/552 551/551/551 -f 551/551/551 556/556/556 557/557/557 -f 558/558/558 553/553/553 552/552/552 -f 552/552/552 557/557/557 558/558/558 -f 559/559/559 554/554/554 555/555/555 -f 555/555/555 560/560/560 559/559/559 -f 561/561/561 556/556/556 554/554/554 -f 554/554/554 559/559/559 561/561/561 -f 562/562/562 557/557/557 556/556/556 -f 556/556/556 561/561/561 562/562/562 -f 563/563/563 558/558/558 557/557/557 -f 557/557/557 562/562/562 563/563/563 -f 564/564/564 559/559/559 560/560/560 -f 560/560/560 565/565/565 564/564/564 -f 566/566/566 561/561/561 559/559/559 -f 559/559/559 564/564/564 566/566/566 -f 567/567/567 562/562/562 561/561/561 -f 561/561/561 566/566/566 567/567/567 -f 568/568/568 563/563/563 562/562/562 -f 562/562/562 567/567/567 568/568/568 -f 569/569/569 564/564/564 565/565/565 -f 565/565/565 570/570/570 569/569/569 -f 571/571/571 566/566/566 564/564/564 -f 564/564/564 569/569/569 571/571/571 -f 572/572/572 567/567/567 566/566/566 -f 566/566/566 571/571/571 572/572/572 -f 573/573/573 568/568/568 567/567/567 -f 567/567/567 572/572/572 573/573/573 -f 574/574/574 569/569/569 570/570/570 -f 570/570/570 575/575/575 574/574/574 -f 576/576/576 571/571/571 569/569/569 -f 569/569/569 574/574/574 576/576/576 -f 577/577/577 572/572/572 571/571/571 -f 571/571/571 576/576/576 577/577/577 -f 578/578/578 573/573/573 572/572/572 -f 572/572/572 577/577/577 578/578/578 -f 579/579/579 574/574/574 575/575/575 -f 575/575/575 580/580/580 579/579/579 -f 581/581/581 576/576/576 574/574/574 -f 574/574/574 579/579/579 581/581/581 -f 582/582/582 577/577/577 576/576/576 -f 576/576/576 581/581/581 582/582/582 -f 583/583/583 578/578/578 577/577/577 -f 577/577/577 582/582/582 583/583/583 -f 584/584/584 585/585/585 586/586/586 -f 586/586/586 587/587/587 584/584/584 -f 588/588/588 589/589/589 585/585/585 -f 585/585/585 584/584/584 588/588/588 -f 590/590/590 591/591/591 589/589/589 -f 589/589/589 588/588/588 590/590/590 -f 592/592/592 593/593/593 591/591/591 -f 591/591/591 590/590/590 592/592/592 -f 594/594/594 584/584/584 587/587/587 -f 587/587/587 595/595/595 594/594/594 -f 596/596/596 588/588/588 584/584/584 -f 584/584/584 594/594/594 596/596/596 -f 597/597/597 590/590/590 588/588/588 -f 588/588/588 596/596/596 597/597/597 -f 598/598/598 592/592/592 590/590/590 -f 590/590/590 597/597/597 598/598/598 -f 599/599/599 594/594/594 595/595/595 -f 595/595/595 600/600/600 599/599/599 -f 601/601/601 596/596/596 594/594/594 -f 594/594/594 599/599/599 601/601/601 -f 602/602/602 597/597/597 596/596/596 -f 596/596/596 601/601/601 602/602/602 -f 603/603/603 598/598/598 597/597/597 -f 597/597/597 602/602/602 603/603/603 -f 604/604/604 599/599/599 600/600/600 -f 600/600/600 605/605/605 604/604/604 -f 606/606/606 601/601/601 599/599/599 -f 599/599/599 604/604/604 606/606/606 -f 607/607/607 602/602/602 601/601/601 -f 601/601/601 606/606/606 607/607/607 -f 608/608/608 603/603/603 602/602/602 -f 602/602/602 607/607/607 608/608/608 -f 609/609/609 604/604/604 605/605/605 -f 605/605/605 610/610/610 609/609/609 -f 611/611/611 606/606/606 604/604/604 -f 604/604/604 609/609/609 611/611/611 -f 612/612/612 607/607/607 606/606/606 -f 606/606/606 611/611/611 612/612/612 -f 613/613/613 608/608/608 607/607/607 -f 607/607/607 612/612/612 613/613/613 -f 614/614/614 609/609/609 610/610/610 -f 610/610/610 615/615/615 614/614/614 -f 616/616/616 611/611/611 609/609/609 -f 609/609/609 614/614/614 616/616/616 -f 617/617/617 612/612/612 611/611/611 -f 611/611/611 616/616/616 617/617/617 -f 618/618/618 613/613/613 612/612/612 -f 612/612/612 617/617/617 618/618/618 -f 619/619/619 614/614/614 615/615/615 -f 615/615/615 620/620/620 619/619/619 -f 621/621/621 616/616/616 614/614/614 -f 614/614/614 619/619/619 621/621/621 -f 622/622/622 617/617/617 616/616/616 -f 616/616/616 621/621/621 622/622/622 -f 623/623/623 618/618/618 617/617/617 -f 617/617/617 622/622/622 623/623/623 -f 624/624/624 619/619/619 620/620/620 -f 620/620/620 625/625/625 624/624/624 -f 626/626/626 621/621/621 619/619/619 -f 619/619/619 624/624/624 626/626/626 -f 627/627/627 622/622/622 621/621/621 -f 621/621/621 626/626/626 627/627/627 -f 628/628/628 623/623/623 622/622/622 -f 622/622/622 627/627/627 628/628/628 diff --git a/Assets/OBJ-IO/Examples/Meshes/Teapot_Modified.obj.meta b/Assets/OBJ-IO/Examples/Meshes/Teapot_Modified.obj.meta deleted file mode 100644 index 3f245d21..00000000 --- a/Assets/OBJ-IO/Examples/Meshes/Teapot_Modified.obj.meta +++ /dev/null @@ -1,72 +0,0 @@ -fileFormatVersion: 2 -guid: f84614a174c3b9741ad76cb8d41246be -timeCreated: 1432869715 -licenseType: Pro -ModelImporter: - serializedVersion: 18 - fileIDToRecycleName: - 100000: Teapot001_Instance_0 - 100002: //RootNode - 400000: Teapot001_Instance_0 - 400002: //RootNode - 2300000: Teapot001_Instance_0 - 3300000: Teapot001_Instance_0 - 4300000: Teapot001_Instance_0 - materials: - importMaterials: 1 - materialName: 0 - materialSearch: 1 - animations: - legacyGenerateAnimations: 4 - bakeSimulation: 0 - optimizeGameObjects: 0 - motionNodeName: - animationCompression: 1 - animationRotationError: .5 - animationPositionError: .5 - animationScaleError: .5 - animationWrapMode: 0 - extraExposedTransformPaths: [] - clipAnimations: [] - isReadable: 1 - meshes: - lODScreenPercentages: [] - globalScale: 1 - meshCompression: 0 - addColliders: 0 - importBlendShapes: 1 - swapUVChannels: 0 - generateSecondaryUV: 0 - useFileUnits: 1 - optimizeMeshForGPU: 1 - keepQuads: 0 - weldVertices: 1 - secondaryUVAngleDistortion: 8 - secondaryUVAreaDistortion: 15.000001 - secondaryUVHardAngle: 88 - secondaryUVPackMargin: 4 - useFileScale: 1 - tangentSpace: - normalSmoothAngle: 60 - splitTangentsAcrossUV: 1 - normalImportMode: 0 - tangentImportMode: 1 - importAnimation: 1 - copyAvatar: 0 - humanDescription: - human: [] - skeleton: [] - armTwist: .5 - foreArmTwist: .5 - upperLegTwist: .5 - legTwist: .5 - armStretch: .0500000007 - legStretch: .0500000007 - feetSpacing: 0 - rootMotionBoneName: - lastHumanDescriptionAvatarSource: {instanceID: 0} - animationType: 0 - additionalBone: 0 - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/OBJ-IO/Examples/Scenes.meta b/Assets/OBJ-IO/Examples/Scenes.meta index e85d95fa..b34e3b4b 100644 --- a/Assets/OBJ-IO/Examples/Scenes.meta +++ b/Assets/OBJ-IO/Examples/Scenes.meta @@ -1,9 +1,8 @@ fileFormatVersion: 2 -guid: 141384ae82c22db4b8422ccbe172ef08 +guid: bcdb42897a640452b984acccd4e4fcf9 folderAsset: yes -timeCreated: 1432869564 -licenseType: Pro DefaultImporter: + externalObjects: {} userData: assetBundleName: assetBundleVariant: diff --git a/Assets/OBJ-IO/Examples/Scenes/Example.unity.meta b/Assets/OBJ-IO/Examples/Scenes/Example.unity.meta index 30497ae7..918bc672 100644 --- a/Assets/OBJ-IO/Examples/Scenes/Example.unity.meta +++ b/Assets/OBJ-IO/Examples/Scenes/Example.unity.meta @@ -1,6 +1,7 @@ fileFormatVersion: 2 guid: 8573b7b1c7256de4896b3054d17de1b7 DefaultImporter: + externalObjects: {} userData: assetBundleName: assetBundleVariant: diff --git a/Assets/OBJ-IO/Examples/Scripts.meta b/Assets/OBJ-IO/Examples/Scripts.meta index afe9ef47..2a373e57 100644 --- a/Assets/OBJ-IO/Examples/Scripts.meta +++ b/Assets/OBJ-IO/Examples/Scripts.meta @@ -1,9 +1,8 @@ fileFormatVersion: 2 -guid: 6f612615b304fd249886c72faee156e0 +guid: 65a5eac6a6a1c47d2b88612172d76dcb folderAsset: yes -timeCreated: 1432869564 -licenseType: Pro DefaultImporter: + externalObjects: {} userData: assetBundleName: assetBundleVariant: diff --git a/Assets/OBJ-IO/Examples/Scripts/Example.cs.meta b/Assets/OBJ-IO/Examples/Scripts/Example.cs.meta index 2f53ad02..dcea092c 100644 --- a/Assets/OBJ-IO/Examples/Scripts/Example.cs.meta +++ b/Assets/OBJ-IO/Examples/Scripts/Example.cs.meta @@ -1,6 +1,7 @@ fileFormatVersion: 2 guid: f3ab7cfdf40b84b41a7adc35c545c226 MonoImporter: + externalObjects: {} serializedVersion: 2 defaultReferences: [] executionOrder: 0 diff --git a/Assets/OBJ-IO/Plugins.meta b/Assets/OBJ-IO/Plugins.meta index d180ab8c..ad0163d9 100644 --- a/Assets/OBJ-IO/Plugins.meta +++ b/Assets/OBJ-IO/Plugins.meta @@ -1,9 +1,8 @@ fileFormatVersion: 2 -guid: 0a5ac41a41be22246b94c47885410104 +guid: e3f6c6aa9d81e42b68614479c60db8c5 folderAsset: yes -timeCreated: 1432869564 -licenseType: Pro DefaultImporter: + externalObjects: {} userData: assetBundleName: assetBundleVariant: diff --git a/Assets/OBJ-IO/Plugins/Extension.meta b/Assets/OBJ-IO/Plugins/Extension.meta index a9ce87cc..ea375ff0 100644 --- a/Assets/OBJ-IO/Plugins/Extension.meta +++ b/Assets/OBJ-IO/Plugins/Extension.meta @@ -1,9 +1,8 @@ fileFormatVersion: 2 -guid: 8c1f4314c6ab61442aeeb22e185f3614 +guid: d4806f2b3d679419ea87ae4ade1568e0 folderAsset: yes -timeCreated: 1432869564 -licenseType: Pro DefaultImporter: + externalObjects: {} userData: assetBundleName: assetBundleVariant: diff --git a/Assets/OBJ-IO/Plugins/Extension/GameObjectExtension.cs.meta b/Assets/OBJ-IO/Plugins/Extension/GameObjectExtension.cs.meta index db440fc3..0794cfdd 100644 --- a/Assets/OBJ-IO/Plugins/Extension/GameObjectExtension.cs.meta +++ b/Assets/OBJ-IO/Plugins/Extension/GameObjectExtension.cs.meta @@ -1,6 +1,7 @@ fileFormatVersion: 2 guid: 35b132c59c7910c4b99e560a0f9baf95 MonoImporter: + externalObjects: {} serializedVersion: 2 defaultReferences: [] executionOrder: 0 diff --git a/Assets/OBJ-IO/Plugins/Extension/MeshExtension.cs.meta b/Assets/OBJ-IO/Plugins/Extension/MeshExtension.cs.meta index 49a47a85..eb156356 100644 --- a/Assets/OBJ-IO/Plugins/Extension/MeshExtension.cs.meta +++ b/Assets/OBJ-IO/Plugins/Extension/MeshExtension.cs.meta @@ -1,6 +1,7 @@ fileFormatVersion: 2 guid: a643d266ae55c8845ac48528640b7e8e MonoImporter: + externalObjects: {} serializedVersion: 2 defaultReferences: [] executionOrder: 0 diff --git a/Assets/OBJ-IO/Plugins/Extension/StringExtensions.cs.meta b/Assets/OBJ-IO/Plugins/Extension/StringExtensions.cs.meta index d3720b02..b34282b3 100644 --- a/Assets/OBJ-IO/Plugins/Extension/StringExtensions.cs.meta +++ b/Assets/OBJ-IO/Plugins/Extension/StringExtensions.cs.meta @@ -1,6 +1,7 @@ fileFormatVersion: 2 guid: 5403d11ff2ec0124a9a20522559dfcfa MonoImporter: + externalObjects: {} serializedVersion: 2 defaultReferences: [] executionOrder: 0 diff --git a/Assets/OBJ-IO/Plugins/Extension/Texture2DExtension.cs.meta b/Assets/OBJ-IO/Plugins/Extension/Texture2DExtension.cs.meta index 3e17a536..c7236483 100644 --- a/Assets/OBJ-IO/Plugins/Extension/Texture2DExtension.cs.meta +++ b/Assets/OBJ-IO/Plugins/Extension/Texture2DExtension.cs.meta @@ -1,6 +1,7 @@ fileFormatVersion: 2 guid: 9260066d99f960241b2a222401bcb685 MonoImporter: + externalObjects: {} serializedVersion: 2 defaultReferences: [] executionOrder: 0 diff --git a/Assets/OBJ-IO/Plugins/Extension/TransformExtension.cs.meta b/Assets/OBJ-IO/Plugins/Extension/TransformExtension.cs.meta index 50e2c338..0646733f 100644 --- a/Assets/OBJ-IO/Plugins/Extension/TransformExtension.cs.meta +++ b/Assets/OBJ-IO/Plugins/Extension/TransformExtension.cs.meta @@ -1,6 +1,7 @@ fileFormatVersion: 2 guid: a8e76b9c1894ec743ae076720e775f49 MonoImporter: + externalObjects: {} serializedVersion: 2 defaultReferences: [] executionOrder: 0 diff --git a/Assets/OBJ-IO/Plugins/Extension/UnityExtension.cs.meta b/Assets/OBJ-IO/Plugins/Extension/UnityExtension.cs.meta index 9a9c9d3d..a1780910 100644 --- a/Assets/OBJ-IO/Plugins/Extension/UnityExtension.cs.meta +++ b/Assets/OBJ-IO/Plugins/Extension/UnityExtension.cs.meta @@ -1,6 +1,7 @@ fileFormatVersion: 2 guid: 06a010ef6a1e94840a51827a2a02badc MonoImporter: + externalObjects: {} serializedVersion: 2 defaultReferences: [] executionOrder: 0 diff --git a/Assets/OBJ-IO/Plugins/Extension/VectorExtension.cs.meta b/Assets/OBJ-IO/Plugins/Extension/VectorExtension.cs.meta index 89d8c8e7..dc4d2325 100644 --- a/Assets/OBJ-IO/Plugins/Extension/VectorExtension.cs.meta +++ b/Assets/OBJ-IO/Plugins/Extension/VectorExtension.cs.meta @@ -1,6 +1,7 @@ fileFormatVersion: 2 guid: 18a26dda21abdf5468d5731a6dbd26c4 MonoImporter: + externalObjects: {} serializedVersion: 2 defaultReferences: [] executionOrder: 0 diff --git a/Assets/OBJ-IO/Plugins/Mesh.meta b/Assets/OBJ-IO/Plugins/Mesh.meta index c004e975..f36f7dbf 100644 --- a/Assets/OBJ-IO/Plugins/Mesh.meta +++ b/Assets/OBJ-IO/Plugins/Mesh.meta @@ -1,9 +1,8 @@ fileFormatVersion: 2 -guid: da432757bf963174d97e5319c45db1dc +guid: d13627753faee4ddfb324434752361cf folderAsset: yes -timeCreated: 1432869564 -licenseType: Pro DefaultImporter: + externalObjects: {} userData: assetBundleName: assetBundleVariant: diff --git a/Assets/OBJ-IO/Plugins/Mesh/OBJ.meta b/Assets/OBJ-IO/Plugins/Mesh/OBJ.meta index 872fba10..75cd40de 100644 --- a/Assets/OBJ-IO/Plugins/Mesh/OBJ.meta +++ b/Assets/OBJ-IO/Plugins/Mesh/OBJ.meta @@ -1,9 +1,8 @@ fileFormatVersion: 2 -guid: f74fe5c4c28267845b900549b670af26 +guid: f89480b6a9d594c67b6bab348aec72a8 folderAsset: yes -timeCreated: 1432869564 -licenseType: Pro DefaultImporter: + externalObjects: {} userData: assetBundleName: assetBundleVariant: diff --git a/Assets/OBJ-IO/Plugins/Mesh/OBJ/OBJData.cs b/Assets/OBJ-IO/Plugins/Mesh/OBJ/OBJData.cs new file mode 100644 index 00000000..3e3e5f95 --- /dev/null +++ b/Assets/OBJ-IO/Plugins/Mesh/OBJ/OBJData.cs @@ -0,0 +1,18 @@ + +using System.Collections.Generic; + +using UnityEngine; + +public class OBJData +{ + //------------------------------------------------------------------------------------------------------------ + public List m_Vertices = new List(); + public List m_Normals = new List(); + public List m_UVs = new List(); + public List m_UV2s = new List(); + public List m_Colors = new List(); + + //------------------------------------------------------------------------------------------------------------ + public List m_Materials = new List(); + public List m_Groups = new List(); +} \ No newline at end of file diff --git a/Assets/FileBrowser/internals/GLUtils.cs.meta b/Assets/OBJ-IO/Plugins/Mesh/OBJ/OBJData.cs.meta similarity index 74% rename from Assets/FileBrowser/internals/GLUtils.cs.meta rename to Assets/OBJ-IO/Plugins/Mesh/OBJ/OBJData.cs.meta index e4bfb96f..9b517bfd 100644 --- a/Assets/FileBrowser/internals/GLUtils.cs.meta +++ b/Assets/OBJ-IO/Plugins/Mesh/OBJ/OBJData.cs.meta @@ -1,6 +1,7 @@ fileFormatVersion: 2 -guid: 4825c0d9ac74bc745ae54f0594fbb584 +guid: 5c57f7fdab36a3f4d9d97f4785a884f6 MonoImporter: + externalObjects: {} serializedVersion: 2 defaultReferences: [] executionOrder: 0 diff --git a/Assets/OBJ-IO/Plugins/Mesh/OBJ/OBJFace.cs b/Assets/OBJ-IO/Plugins/Mesh/OBJ/OBJFace.cs new file mode 100644 index 00000000..ee76c3ec --- /dev/null +++ b/Assets/OBJ-IO/Plugins/Mesh/OBJ/OBJFace.cs @@ -0,0 +1,101 @@ + +using System; +using System.IO; +using System.Linq; +using System.Collections.Generic; + +using UnityEngine; + +using UnityExtension; + +public class OBJFace +{ + //------------------------------------------------------------------------------------------------------------ + private readonly List m_Vertices = new List(); + + //------------------------------------------------------------------------------------------------------------ + public void AddVertex(OBJFaceVertex lVertex) + { + m_Vertices.Add(lVertex); + } + + //------------------------------------------------------------------------------------------------------------ + public void ParseVertex(string lVertexString) + { + var fields = lVertexString.Split(new[] { '/' }, StringSplitOptions.None); + + var lIndex = fields[0].ParseInvariantInt(); + var faceVertex = new OBJFaceVertex + { + m_VertexIndex = lIndex - 1 + }; + + if (fields.Length > 1) + { + lIndex = fields[1].Length == 0 ? 0 : fields[1].ParseInvariantInt(); + faceVertex.m_UVIndex = lIndex - 1; + } + + if (fields.Length > 2) + { + lIndex = fields[2].Length == 0 ? 0 : fields[2].ParseInvariantInt(); + faceVertex.m_NormalIndex = lIndex - 1; + } + + if (fields.Length > 3) + { + lIndex = fields[3].Length == 0 ? 0 : fields[3].ParseInvariantInt(); + faceVertex.m_UV2Index = lIndex - 1; + } + + if (fields.Length > 4) + { + lIndex = fields[4].Length == 0 ? 0 : fields[4].ParseInvariantInt(); + faceVertex.m_ColorIndex = lIndex - 1; + } + + AddVertex(faceVertex); + } + + //------------------------------------------------------------------------------------------------------------ + public string ToString(int lIndex) + { + OBJFaceVertex lFaceVertex = m_Vertices[lIndex]; + + string lOutput = (lFaceVertex.m_VertexIndex + 1).ToString(); + + if (lFaceVertex.m_UVIndex > -1) + { + lOutput += string.Format("/{0}", (lFaceVertex.m_UVIndex + 1).ToString()); + } + + if (lFaceVertex.m_NormalIndex > -1) + { + lOutput += string.Format("/{0}", (lFaceVertex.m_NormalIndex + 1).ToString()); + } + + if (lFaceVertex.m_UV2Index > -1) + { + lOutput += string.Format("/{0}", (lFaceVertex.m_UV2Index + 1).ToString()); + } + + if (lFaceVertex.m_ColorIndex > -1) + { + lOutput += string.Format("/{0}", (lFaceVertex.m_ColorIndex + 1).ToString()); + } + + return lOutput; + } + + //------------------------------------------------------------------------------------------------------------ + public OBJFaceVertex this[int i] + { + get { return m_Vertices[i]; } + } + + //------------------------------------------------------------------------------------------------------------ + public int Count + { + get { return m_Vertices.Count; } + } +} diff --git a/Assets/FileBrowser/internals/GUILayoutx.cs.meta b/Assets/OBJ-IO/Plugins/Mesh/OBJ/OBJFace.cs.meta similarity index 74% rename from Assets/FileBrowser/internals/GUILayoutx.cs.meta rename to Assets/OBJ-IO/Plugins/Mesh/OBJ/OBJFace.cs.meta index c7d8c200..98768882 100644 --- a/Assets/FileBrowser/internals/GUILayoutx.cs.meta +++ b/Assets/OBJ-IO/Plugins/Mesh/OBJ/OBJFace.cs.meta @@ -1,6 +1,7 @@ fileFormatVersion: 2 -guid: 8c961478f91c9b84194c12e130492ced +guid: 07402f6cbfe2d0e40ab4d7363cb0ed64 MonoImporter: + externalObjects: {} serializedVersion: 2 defaultReferences: [] executionOrder: 0 diff --git a/Assets/OBJ-IO/Plugins/Mesh/OBJ/OBJFaceVertex.cs b/Assets/OBJ-IO/Plugins/Mesh/OBJ/OBJFaceVertex.cs new file mode 100644 index 00000000..5f0bc285 --- /dev/null +++ b/Assets/OBJ-IO/Plugins/Mesh/OBJ/OBJFaceVertex.cs @@ -0,0 +1,23 @@ +public class OBJFaceVertex +{ + //------------------------------------------------------------------------------------------------------------ + public int m_VertexIndex = -1; + public int m_UVIndex = -1; + public int m_UV2Index = -1; + public int m_NormalIndex = -1; + public int m_ColorIndex = -1; + + public override int GetHashCode() + { + return m_VertexIndex ^ m_UVIndex ^ m_UV2Index ^ m_NormalIndex ^ m_ColorIndex; + } + + public override bool Equals(object obj) + { + OBJFaceVertex faceVertex = (OBJFaceVertex) obj; + return m_VertexIndex == faceVertex.m_VertexIndex + && m_UVIndex == faceVertex.m_UVIndex + && m_UV2Index == faceVertex.m_UV2Index + && m_NormalIndex == faceVertex.m_NormalIndex; + } +} \ No newline at end of file diff --git a/Assets/FileBrowser/internals/SoundViewer.cs.meta b/Assets/OBJ-IO/Plugins/Mesh/OBJ/OBJFaceVertex.cs.meta similarity index 74% rename from Assets/FileBrowser/internals/SoundViewer.cs.meta rename to Assets/OBJ-IO/Plugins/Mesh/OBJ/OBJFaceVertex.cs.meta index 0939e9e9..ffd4ff5d 100644 --- a/Assets/FileBrowser/internals/SoundViewer.cs.meta +++ b/Assets/OBJ-IO/Plugins/Mesh/OBJ/OBJFaceVertex.cs.meta @@ -1,6 +1,7 @@ fileFormatVersion: 2 -guid: 982c467786707e54897799c8eb7460de +guid: 1f5cff977d3365a4f9f33933bb603037 MonoImporter: + externalObjects: {} serializedVersion: 2 defaultReferences: [] executionOrder: 0 diff --git a/Assets/OBJ-IO/Plugins/Mesh/OBJ/OBJGroup.cs b/Assets/OBJ-IO/Plugins/Mesh/OBJ/OBJGroup.cs new file mode 100644 index 00000000..581d4c9d --- /dev/null +++ b/Assets/OBJ-IO/Plugins/Mesh/OBJ/OBJGroup.cs @@ -0,0 +1,27 @@ + +using System.Collections.Generic; + +public class OBJGroup +{ + //------------------------------------------------------------------------------------------------------------ + private readonly List m_Faces = new List(); + + //------------------------------------------------------------------------------------------------------------ + public OBJGroup(string lName) + { + m_Name = lName; + } + + //------------------------------------------------------------------------------------------------------------ + public string m_Name { get; private set; } + public OBJMaterial m_Material { get; set; } + + //------------------------------------------------------------------------------------------------------------ + public IList Faces { get { return m_Faces; } } + + //------------------------------------------------------------------------------------------------------------ + public void AddFace(OBJFace lFace) + { + m_Faces.Add(lFace); + } +} \ No newline at end of file diff --git a/Assets/OBJ-IO/Plugins/Mesh/OBJ/OBJGroup.cs.meta b/Assets/OBJ-IO/Plugins/Mesh/OBJ/OBJGroup.cs.meta new file mode 100644 index 00000000..7d03d415 --- /dev/null +++ b/Assets/OBJ-IO/Plugins/Mesh/OBJ/OBJGroup.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8508b6de42212c84ebaec559aed6c7b6 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/OBJ-IO/Plugins/Mesh/OBJ/OBJLoader.cs b/Assets/OBJ-IO/Plugins/Mesh/OBJ/OBJLoader.cs new file mode 100644 index 00000000..7d2d1dc9 --- /dev/null +++ b/Assets/OBJ-IO/Plugins/Mesh/OBJ/OBJLoader.cs @@ -0,0 +1,219 @@ + +using System; +using System.IO; +using System.Linq; +using System.Collections.Generic; + +using UnityEngine; + +using UnityExtension; + +/* + * Currently only supports Triangluar Meshes + */ + +public class OBJLoader +{ + //------------------------------------------------------------------------------------------------------------ + private static OBJData m_OBJData = null; + + //------------------------------------------------------------------------------------------------------------ + private static OBJMaterial m_CurrentMaterial = null; + private static OBJGroup m_CurrentGroup = null; + + #region PROCESSORS + + //------------------------------------------------------------------------------------------------------------ + private static readonly Dictionary> m_ParseOBJActionDictionary = new Dictionary> + { + { "mtllib", (lEntry) => { /*Load MTL*/ } }, + { "usemtl", (lEntry) => { PushOBJGroupIfNeeded(); m_CurrentGroup.m_Material = m_OBJData.m_Materials.SingleOrDefault((lX) => { return lX.m_Name.EqualsInvariantCultureIgnoreCase(lEntry); }); } }, + { "v", (lEntry) => { m_OBJData.m_Vertices.Add(Utils.ParseVector3String(lEntry)); } }, + { "vn", (lEntry) => { m_OBJData.m_Normals.Add(Utils.ParseVector3String(lEntry)); } }, + { "vt", (lEntry) => { m_OBJData.m_UVs.Add(Utils.ParseVector2String(lEntry)); } }, + { "vt2", (lEntry) => { m_OBJData.m_UV2s.Add(Utils.ParseVector2String(lEntry)); } }, + { "vc", (lEntry) => { m_OBJData.m_Colors.Add(Utils.ParseVector4String(lEntry).ToColor()); } }, + { "f", PushOBJFace }, + { "g", PushOBJGroup }, + }; + + //------------------------------------------------------------------------------------------------------------ + private static readonly Dictionary> m_ParseMTLActionDictionary = new Dictionary> + { + { "newmtl", PushOBJMaterial }, + { "Ka", (lEntry) => { m_CurrentMaterial.m_AmbientColor = Utils.ParseVector3String(lEntry).ToColor(); } }, + { "Kd", (lEntry) => { m_CurrentMaterial.m_DiffuseColor = Utils.ParseVector3String(lEntry).ToColor(); } }, + { "Ks", (lEntry) => { m_CurrentMaterial.m_SpecularColor = Utils.ParseVector3String(lEntry).ToColor(); } }, + { "Ns", (lEntry) => { m_CurrentMaterial.m_SpecularCoefficient = lEntry.ParseInvariantFloat(); } }, + { "d", (lEntry) => { m_CurrentMaterial.m_Transparency = lEntry.ParseInvariantFloat(); } }, + { "Tr", (lEntry) => { m_CurrentMaterial.m_Transparency = lEntry.ParseInvariantFloat(); } }, + { "illum", (lEntry) => { m_CurrentMaterial.m_IlluminationModel = lEntry.ParseInvariantInt(); } }, + { "map_Ka", (lEntry) => { m_CurrentMaterial.m_AmbientTextureMap = lEntry; } }, + { "map_Kd", (lEntry) => { m_CurrentMaterial.m_DiffuseTextureMap = lEntry; } }, + { "map_Ks", (lEntry) => { m_CurrentMaterial.m_SpecularTextureMap = lEntry; } }, + { "map_Ns", (lEntry) => { m_CurrentMaterial.m_SpecularHighlightTextureMap = lEntry; } }, + { "map_d", (lEntry) => { m_CurrentMaterial.m_AlphaTextureMap = lEntry; } }, + { "map_bump", (lEntry) => { m_CurrentMaterial.m_BumpMap = lEntry; } }, + { "bump", (lEntry) => { m_CurrentMaterial.m_BumpMap = lEntry; } }, + { "disp", (lEntry) => { m_CurrentMaterial.m_DisplacementMap = lEntry; } }, + { "decal",(lEntry) => { m_CurrentMaterial.m_StencilDecalMap = lEntry; } }, + }; + + #endregion + + #region PUBLIC_INTERFACE + + //------------------------------------------------------------------------------------------------------------ + public static OBJData LoadOBJ(Stream lStream) + { + m_OBJData = new OBJData(); + + m_CurrentMaterial = null; + m_CurrentGroup = null; + + StreamReader lLineStreamReader = new StreamReader(lStream); + + Action lAction = null; + string lCurrentLine = null; + string[] lFields = null; + string lKeyword = null; + string lData = null; + + while (!lLineStreamReader.EndOfStream) + { + lCurrentLine = lLineStreamReader.ReadLine(); + + if (StringExt.IsNullOrWhiteSpace(lCurrentLine) + || lCurrentLine[0] == '#') + { + continue; + } + + lFields = lCurrentLine.Trim().Split(null, 2); + if (lFields.Length < 2) + { + continue; + } + + lKeyword = lFields[0].Trim(); + lData = lFields[1].Trim(); + + lAction = null; + m_ParseOBJActionDictionary.TryGetValue(lKeyword.ToLowerInvariant(), out lAction); + + if (lAction != null) + { + lAction(lData); + } + } + + var lOBJData = m_OBJData; + m_OBJData = null; + + return lOBJData; + } + + //------------------------------------------------------------------------------------------------------------ + public static void ExportOBJ(OBJData lData, Stream lStream) + { + StreamWriter lLineStreamWriter = new StreamWriter(lStream); + + lLineStreamWriter.WriteLine(string.Format("# File exported by Unity3D version {0}", Application.unityVersion)); + + for (int lCount = 0; lCount < lData.m_Vertices.Count; ++lCount) + { + lLineStreamWriter.WriteLine(string.Format("v {0} {1} {2}", + lData.m_Vertices[lCount].x.ToString("n8"), + lData.m_Vertices[lCount].y.ToString("n8"), + lData.m_Vertices[lCount].z.ToString("n8"))); + } + + for (int lCount = 0; lCount < lData.m_UVs.Count; ++lCount) + { + lLineStreamWriter.WriteLine(string.Format("vt {0} {1}", + lData.m_UVs[lCount].x.ToString("n5"), + lData.m_UVs[lCount].y.ToString("n5"))); + } + + for (int lCount = 0; lCount < lData.m_UV2s.Count; ++lCount) + { + lLineStreamWriter.WriteLine(string.Format("vt2 {0} {1}", + lData.m_UVs[lCount].x.ToString("n5"), + lData.m_UVs[lCount].y.ToString("n5"))); + } + + for (int lCount = 0; lCount < lData.m_Normals.Count; ++lCount) + { + lLineStreamWriter.WriteLine(string.Format("vn {0} {1} {2}", + lData.m_Normals[lCount].x.ToString("n8"), + lData.m_Normals[lCount].y.ToString("n8"), + lData.m_Normals[lCount].z.ToString("n8"))); + } + + for (int lCount = 0; lCount < lData.m_Colors.Count; ++lCount) + { + lLineStreamWriter.WriteLine(string.Format("vc {0} {1} {2} {3}", + lData.m_Colors[lCount].r.ToString("n8"), + lData.m_Colors[lCount].g.ToString("n8"), + lData.m_Colors[lCount].b.ToString("n8"), + lData.m_Colors[lCount].a.ToString("n8"))); + } + + for (int lGroup = 0; lGroup < lData.m_Groups.Count; ++lGroup) + { + lLineStreamWriter.WriteLine(string.Format("g {0}", lData.m_Groups[lGroup].m_Name)); + + for (int lFace = 0; lFace < lData.m_Groups[lGroup].Faces.Count; ++lFace) + { + lLineStreamWriter.WriteLine(string.Format("f {0} {1} {2}", + lData.m_Groups[lGroup].Faces[lFace].ToString(0), + lData.m_Groups[lGroup].Faces[lFace].ToString(1), + lData.m_Groups[lGroup].Faces[lFace].ToString(2))); + } + } + + lLineStreamWriter.Flush(); + } + + #endregion + + //------------------------------------------------------------------------------------------------------------ + private static void PushOBJMaterial(string lMaterialName) + { + m_CurrentMaterial = new OBJMaterial(lMaterialName); + m_OBJData.m_Materials.Add(m_CurrentMaterial); + } + + //------------------------------------------------------------------------------------------------------------ + private static void PushOBJGroup(string lGroupName) + { + m_CurrentGroup = new OBJGroup(lGroupName); + m_OBJData.m_Groups.Add(m_CurrentGroup); + } + + //------------------------------------------------------------------------------------------------------------ + private static void PushOBJGroupIfNeeded() + { + if (m_CurrentGroup == null) + { + PushOBJGroup("default"); + } + } + + //------------------------------------------------------------------------------------------------------------ + private static void PushOBJFace(string lFaceLine) + { + PushOBJGroupIfNeeded(); + + var vertices = lFaceLine.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); + + var face = new OBJFace(); + + foreach (var vertexString in vertices) + { + face.ParseVertex(vertexString); + } + + m_CurrentGroup.AddFace(face); + } +} \ No newline at end of file diff --git a/Assets/OBJ-IO/Plugins/Mesh/OBJ/OBJLoader.cs.meta b/Assets/OBJ-IO/Plugins/Mesh/OBJ/OBJLoader.cs.meta new file mode 100644 index 00000000..99e87241 --- /dev/null +++ b/Assets/OBJ-IO/Plugins/Mesh/OBJ/OBJLoader.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: bda02739f6fbaeb4c8c3da925164b8cf +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/OBJ-IO/Plugins/Mesh/OBJ/OBJMaterial.cs b/Assets/OBJ-IO/Plugins/Mesh/OBJ/OBJMaterial.cs new file mode 100644 index 00000000..b16438e8 --- /dev/null +++ b/Assets/OBJ-IO/Plugins/Mesh/OBJ/OBJMaterial.cs @@ -0,0 +1,42 @@ + +using UnityEngine; + +public class OBJMaterial +{ + //------------------------------------------------------------------------------------------------------------ + public OBJMaterial(string lMaterialName) + { + m_Name = lMaterialName; + } + + //------------------------------------------------------------------------------------------------------------ + public string m_Name; + + //------------------------------------------------------------------------------------------------------------ + public Color m_AmbientColor; + public Color m_DiffuseColor; + public Color m_SpecularColor; + public float m_SpecularCoefficient; + + //------------------------------------------------------------------------------------------------------------ + public float m_Transparency; + + //------------------------------------------------------------------------------------------------------------ + public int m_IlluminationModel; + + //------------------------------------------------------------------------------------------------------------ + public string m_AmbientTextureMap; + public string m_DiffuseTextureMap; + + //------------------------------------------------------------------------------------------------------------ + public string m_SpecularTextureMap; + public string m_SpecularHighlightTextureMap; + + //------------------------------------------------------------------------------------------------------------ + public string m_BumpMap; + public string m_DisplacementMap; + public string m_StencilDecalMap; + + //------------------------------------------------------------------------------------------------------------ + public string m_AlphaTextureMap; +} \ No newline at end of file diff --git a/Assets/OBJ-IO/Plugins/Mesh/OBJ/OBJMaterial.cs.meta b/Assets/OBJ-IO/Plugins/Mesh/OBJ/OBJMaterial.cs.meta new file mode 100644 index 00000000..64e0ef26 --- /dev/null +++ b/Assets/OBJ-IO/Plugins/Mesh/OBJ/OBJMaterial.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ceb2526c78b78c04592f312a4e65ec95 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/OBJ-IO/Plugins/Utils.meta b/Assets/OBJ-IO/Plugins/Utils.meta index f993b503..2e09ad1a 100644 --- a/Assets/OBJ-IO/Plugins/Utils.meta +++ b/Assets/OBJ-IO/Plugins/Utils.meta @@ -1,9 +1,8 @@ fileFormatVersion: 2 -guid: 94cd99f1df5fafa489e641d039f97273 +guid: 645d782c617a141eaa17875286939a36 folderAsset: yes -timeCreated: 1432869564 -licenseType: Pro DefaultImporter: + externalObjects: {} userData: assetBundleName: assetBundleVariant: diff --git a/Assets/OBJ-IO/Plugins/Utils/Int32Converter.cs.meta b/Assets/OBJ-IO/Plugins/Utils/Int32Converter.cs.meta index 2999c354..81b98f51 100644 --- a/Assets/OBJ-IO/Plugins/Utils/Int32Converter.cs.meta +++ b/Assets/OBJ-IO/Plugins/Utils/Int32Converter.cs.meta @@ -1,6 +1,7 @@ fileFormatVersion: 2 guid: 2980235c1e3576a4ab7dca278af19308 MonoImporter: + externalObjects: {} serializedVersion: 2 defaultReferences: [] executionOrder: 0 diff --git a/Assets/OBJ-IO/Readme.txt.meta b/Assets/OBJ-IO/Readme.txt.meta index 6372bc35..6cf7e2df 100644 --- a/Assets/OBJ-IO/Readme.txt.meta +++ b/Assets/OBJ-IO/Readme.txt.meta @@ -1,6 +1,7 @@ fileFormatVersion: 2 guid: e1f277bf041647445ac3bf5b643a46fe TextScriptImporter: + externalObjects: {} userData: assetBundleName: assetBundleVariant: diff --git a/Assets/Plugins/ClipboardHelper.dll.meta b/Assets/Plugins/ClipboardHelper.dll.meta index a6547311..2bf18416 100644 --- a/Assets/Plugins/ClipboardHelper.dll.meta +++ b/Assets/Plugins/ClipboardHelper.dll.meta @@ -1,14 +1,15 @@ fileFormatVersion: 2 guid: d3215659d71d2184bb0d24ec3976c7f2 -timeCreated: 1461458104 -licenseType: Pro PluginImporter: externalObjects: {} serializedVersion: 2 iconMap: {} executionOrder: {} + defineConstraints: [] isPreloaded: 0 isOverridable: 0 + isExplicitlyReferenced: 0 + validateReferences: 1 platformData: - first: '': Any @@ -59,7 +60,7 @@ PluginImporter: second: enabled: 1 settings: - CPU: x86_64 + CPU: AnyCPU - first: Standalone: LinuxUniversal second: diff --git a/Assets/Plugins/Editor.meta b/Assets/Plugins/Editor.meta new file mode 100644 index 00000000..16c6026a --- /dev/null +++ b/Assets/Plugins/Editor.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: b0dde7ce4e3974b2badb6caa1e93bae0 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/Editor/JetBrains.meta b/Assets/Plugins/Editor/JetBrains.meta new file mode 100644 index 00000000..7b606fea --- /dev/null +++ b/Assets/Plugins/Editor/JetBrains.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 54795eca6aef84cd5908ee5239121d32 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/Editor/JetBrains/JetBrains.Rider.Unity.Editor.Plugin.Repacked.dll b/Assets/Plugins/Editor/JetBrains/JetBrains.Rider.Unity.Editor.Plugin.Repacked.dll new file mode 100644 index 00000000..05082ac4 Binary files /dev/null and b/Assets/Plugins/Editor/JetBrains/JetBrains.Rider.Unity.Editor.Plugin.Repacked.dll differ diff --git a/Assets/Plugins/Editor/JetBrains/JetBrains.Rider.Unity.Editor.Plugin.Repacked.dll.meta b/Assets/Plugins/Editor/JetBrains/JetBrains.Rider.Unity.Editor.Plugin.Repacked.dll.meta new file mode 100644 index 00000000..d6f6733b --- /dev/null +++ b/Assets/Plugins/Editor/JetBrains/JetBrains.Rider.Unity.Editor.Plugin.Repacked.dll.meta @@ -0,0 +1,32 @@ +fileFormatVersion: 2 +guid: 0fecaa1aa7cec475bb76150e99a8ee62 +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 0 + isExplicitlyReferenced: 0 + platformData: + - first: + Any: + second: + enabled: 0 + settings: {} + - first: + Editor: Editor + second: + enabled: 1 + settings: + DefaultValueInitialized: true + - first: + Windows Store Apps: WindowsStoreApps + second: + enabled: 0 + settings: + CPU: AnyCPU + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Plugins/FreeImage.dll b/Assets/Plugins/FreeImage.dll deleted file mode 100644 index 0562f4a0..00000000 Binary files a/Assets/Plugins/FreeImage.dll and /dev/null differ diff --git a/Assets/Plugins/FreeImage.dll.meta b/Assets/Plugins/FreeImage.dll.meta deleted file mode 100644 index 74f319db..00000000 --- a/Assets/Plugins/FreeImage.dll.meta +++ /dev/null @@ -1,27 +0,0 @@ -fileFormatVersion: 2 -guid: ebd9e6f743aa7944bb5ef45303809de7 -timeCreated: 1428028810 -licenseType: Pro -PluginImporter: - serializedVersion: 2 - iconMap: {} - executionOrder: {} - isPreloaded: 0 - isOverridable: 0 - platformData: - data: - first: - Any: - second: - enabled: 1 - settings: {} - data: - first: - Editor: Editor - second: - enabled: 0 - settings: - DefaultValueInitialized: true - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Plugins/FreeImageNET.dll b/Assets/Plugins/FreeImageNET.dll deleted file mode 100644 index 9dc67b10..00000000 Binary files a/Assets/Plugins/FreeImageNET.dll and /dev/null differ diff --git a/Assets/Plugins/FreeImageNET.dll.meta b/Assets/Plugins/FreeImageNET.dll.meta deleted file mode 100644 index 6227a91c..00000000 --- a/Assets/Plugins/FreeImageNET.dll.meta +++ /dev/null @@ -1,34 +0,0 @@ -fileFormatVersion: 2 -guid: a345a206b81dd7a44b4622826a684325 -timeCreated: 1427854935 -licenseType: Pro -PluginImporter: - serializedVersion: 2 - iconMap: {} - executionOrder: {} - isPreloaded: 0 - isOverridable: 0 - platformData: - data: - first: - Any: - second: - enabled: 1 - settings: {} - data: - first: - Editor: Editor - second: - enabled: 0 - settings: - DefaultValueInitialized: true - data: - first: - Windows Store Apps: WindowsStoreApps - second: - enabled: 0 - settings: - CPU: AnyCPU - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/PostProcess/OpaquePostProcess.cs b/Assets/PostProcess/OpaquePostProcess.cs index dcfa2468..fb026411 100644 --- a/Assets/PostProcess/OpaquePostProcess.cs +++ b/Assets/PostProcess/OpaquePostProcess.cs @@ -19,10 +19,6 @@ public class OpaquePostProcess : MonoBehaviour { RenderTexture _AccumulatedFramesAlt; Camera thisCamera; - Quaternion lastCamRotation = Quaternion.identity; - Vector3 lastCamPosition = Vector3.zero; - Quaternion savedCameraRotation = Quaternion.identity; - float lastBlendAmount = 1.0f; HaltonSequence positionsequence = new HaltonSequence(); int hspos = 0; diff --git a/Assets/Scripts/AOFromNormalGui.cs b/Assets/Scripts/AOFromNormalGui.cs deleted file mode 100644 index 4e38f682..00000000 --- a/Assets/Scripts/AOFromNormalGui.cs +++ /dev/null @@ -1,339 +0,0 @@ -using UnityEngine; -using System.Collections; -using System.ComponentModel; - -public class AOSettings { - - [DefaultValueAttribute(5.0f)] - public float Spread; - [DefaultValueAttribute("50")] - public string SpreadText; - - [DefaultValueAttribute(0.0f)] - public float FinalBias; - [DefaultValueAttribute("0")] - public string FinalBiasText; - - [DefaultValueAttribute(1.0f)] - public float FinalContrast; - [DefaultValueAttribute("1")] - public string FinalContrastText; - - [DefaultValueAttribute(100.0f)] - public float Depth; - [DefaultValueAttribute("100")] - public string DepthText; - - [DefaultValueAttribute(1.0f)] - public float Blend; - [DefaultValueAttribute("1")] - public string BlendText; - - [DefaultValueAttribute(1.0f)] - public float BlendAmount; - - public AOSettings(){ - - this.Spread = 50.0f; - this.SpreadText = "50"; - - this.Depth = 100.0f; - this.DepthText = "100"; - - this.FinalBias = 0.0f; - this.FinalBiasText = "0"; - - this.FinalContrast = 1.0f; - this.FinalContrastText = "1"; - - this.Blend = 1.0f; - this.BlendText = "1"; - - this.BlendAmount = 1.0f; - } -} - -public class AOFromNormalGui : MonoBehaviour { - - public MainGui MainGuiScript; - - public Texture2D defaultNormal; - public Texture2D defaultHeight; - - Texture2D _AOMap; - RenderTexture _WorkingAOMap; - RenderTexture _BlendedAOMap; - RenderTexture _TempAOMap; - - int imageSizeX = 1024; - int imageSizeY = 1024; - - AOSettings AOS; - - public Material thisMaterial; - Material blitMaterial; - - public GameObject testObject; - bool doStuff = false; - bool newTexture = false; - - Rect windowRect = new Rect (30, 300, 300, 230); - - bool settingsInitialized = false; - - public bool busy = false; - - public void GetValues( ProjectObject projectObject ) { - InitializeSettings (); - projectObject.AOS = AOS; - } - - public void SetValues( ProjectObject projectObject ) { - InitializeSettings (); - if (projectObject.AOS != null) { - AOS = projectObject.AOS; - } else { - settingsInitialized = false; - InitializeSettings (); - } - doStuff = true; - } - - void InitializeSettings() { - - if (settingsInitialized == false) { - - AOS = new AOSettings (); - - if (MainGuiScript._HeightMap != null) { - AOS.Blend = 1.0f; - AOS.BlendText = "1.0"; - } else { - AOS.Blend = 0.0f; - AOS.BlendText = "0.0"; - } - - settingsInitialized = true; - } - - } - - // Use this for initialization - void Start () { - - testObject.GetComponent().sharedMaterial = thisMaterial; - - blitMaterial = new Material (Shader.Find ("Hidden/Blit_Shader")); - - //blitMaterial = new Material (Shader.Find ("Hidden/Blit_Height_From_Normal")); - - InitializeSettings (); - - } - - public void DoStuff() { - doStuff = true; - } - - public void NewTexture() { - newTexture = true; - } - - - // Update is called once per frame - void Update () { - - if (newTexture) { - InitializeTextures(); - newTexture = false; - } - - if (doStuff) { - - StopAllCoroutines(); - - StartCoroutine( ProcessNormalDepth () ); - doStuff = false; - } - - thisMaterial.SetFloat ("_FinalContrast", AOS.FinalContrast); - thisMaterial.SetFloat ("_FinalBias", AOS.FinalBias); - thisMaterial.SetFloat ("_AOBlend", AOS.Blend); - - } - - void DoMyWindow ( int windowID ) { - - int spacingX = 0; - int spacingY = 50; - - int offsetX = 10; - int offsetY = 30; - - if( GuiHelper.Slider( new Rect (offsetX, offsetY, 280, 50), "AO pixel Spread", AOS.Spread, AOS.SpreadText, out AOS.Spread, out AOS.SpreadText, 10.0f, 100.0f ) ) { - doStuff = true; - } - offsetY += 40; - - if( GuiHelper.Slider( new Rect( offsetX, offsetY, 280, 50 ), "Pixel Depth", AOS.Depth, AOS.DepthText, out AOS.Depth, out AOS.DepthText, 0.0f, 256.0f ) ) { - doStuff = true; - } - offsetY += 40; - - GuiHelper.Slider (new Rect (offsetX, offsetY, 280, 50), "Blend Normal AO and Depth AO", AOS.Blend, AOS.BlendText, out AOS.Blend, out AOS.BlendText, 0.0f, 1.0f); - offsetY += 40; - - GuiHelper.Slider( new Rect( offsetX, offsetY, 280, 50 ), "AO Power", AOS.FinalContrast, AOS.FinalContrastText, out AOS.FinalContrast, out AOS.FinalContrastText, 0.1f, 10.0f ); - offsetY += 40; - - GuiHelper.Slider( new Rect( offsetX, offsetY, 280, 50 ), "AO Bias", AOS.FinalBias, AOS.FinalBiasText, out AOS.FinalBias, out AOS.FinalBiasText, -1.0f, 1.0f ); - offsetY += 50; - - if (busy) { GUI.enabled = false; } else { GUI.enabled = true; } - if( GUI.Button (new Rect (offsetX + 150, offsetY, 130, 30), "Set as AO Map" ) ){ - StartCoroutine( ProcessAO () ); - } - GUI.enabled = true; - GUI.DragWindow(); - } - - void OnGUI () { - - windowRect.width = 300; - windowRect.height = 280; - - windowRect = GUI.Window(10, windowRect, DoMyWindow, "Normal + Depth to AO"); - - } - - public void InitializeTextures() { - - testObject.GetComponent().sharedMaterial = thisMaterial; - - CleanupTextures (); - - if (MainGuiScript._NormalMap != null) { - imageSizeX = MainGuiScript._NormalMap.width; - imageSizeY = MainGuiScript._NormalMap.height; - } else { - imageSizeX = MainGuiScript._HeightMap.width; - imageSizeY = MainGuiScript._HeightMap.height; - } - - Debug.Log ( "Initializing Textures of size: " + imageSizeX.ToString() + "x" + imageSizeY.ToString() ); - - _WorkingAOMap = new RenderTexture (imageSizeX, imageSizeY, 0, RenderTextureFormat.RGHalf, RenderTextureReadWrite.Linear); - _WorkingAOMap.wrapMode = TextureWrapMode.Repeat; - _BlendedAOMap = new RenderTexture (imageSizeX, imageSizeY, 0, RenderTextureFormat.RGHalf, RenderTextureReadWrite.Linear); - _BlendedAOMap.wrapMode = TextureWrapMode.Repeat; - - } - - public void Close(){ - CleanupTextures (); - this.gameObject.SetActive (false); - } - - void CleanupTexture( RenderTexture _Texture ) { - - if (_Texture != null) { - _Texture.Release(); - _Texture = null; - } - - } - - void CleanupTextures() { - - Debug.Log ("Cleaning Up Textures"); - - CleanupTexture( _WorkingAOMap ); - CleanupTexture( _BlendedAOMap ); - CleanupTexture( _TempAOMap ); - - } - - public IEnumerator ProcessAO() { - - busy = true; - - Debug.Log ("Processing AO Map"); - - CleanupTexture (_TempAOMap); - _TempAOMap = new RenderTexture (imageSizeX, imageSizeY, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear); - _TempAOMap.wrapMode = TextureWrapMode.Repeat; - - blitMaterial.SetFloat ("_FinalBias", AOS.FinalBias); - blitMaterial.SetFloat ("_FinalContrast", AOS.FinalContrast); - blitMaterial.SetTexture ("_MainTex", _BlendedAOMap); - blitMaterial.SetFloat ("_AOBlend", AOS.Blend); - - Graphics.Blit(_BlendedAOMap, _TempAOMap, blitMaterial, 8); - - if (MainGuiScript._AOMap != null) { - Destroy (MainGuiScript._AOMap); - } - - RenderTexture.active = _TempAOMap; - MainGuiScript._AOMap = new Texture2D( _TempAOMap.width, _TempAOMap.height, TextureFormat.ARGB32, true, true ); - MainGuiScript._AOMap.ReadPixels(new Rect(0, 0, _TempAOMap.width, _TempAOMap.height), 0, 0); - MainGuiScript._AOMap.Apply(); - - yield return new WaitForSeconds(0.1f); - - CleanupTexture ( _TempAOMap ); - - busy = false; - } - - public IEnumerator ProcessNormalDepth () { - - busy = true; - - Debug.Log ("Processing Normal Depth to AO"); - - blitMaterial.SetVector ("_ImageSize", new Vector4 (imageSizeX, imageSizeY, 0, 0)); - blitMaterial.SetFloat ("_Spread", AOS.Spread); - - if (MainGuiScript._NormalMap != null) { - blitMaterial.SetTexture ("_MainTex", MainGuiScript._NormalMap); - } else { - blitMaterial.SetTexture ("_MainTex", defaultNormal); - } - - if (MainGuiScript._HDHeightMap != null) { - blitMaterial.SetTexture ("_HeightTex", MainGuiScript._HDHeightMap); - } else if (MainGuiScript._HeightMap != null) { - blitMaterial.SetTexture ("_HeightTex", MainGuiScript._HeightMap); - } else { - blitMaterial.SetTexture ("_HeightTex", defaultHeight); - } - - blitMaterial.SetTexture ("_BlendTex", _BlendedAOMap); - blitMaterial.SetFloat ("_Depth", AOS.Depth); - thisMaterial.SetTexture ("_MainTex", _BlendedAOMap); - - int yieldCountDown = 5; - - for( int i = 1; i < 100; i++ ) { - - blitMaterial.SetFloat ("_BlendAmount", 1.0f / (float)i ); - blitMaterial.SetFloat ("_Progress", (float)i / 100.0f ); - - Graphics.Blit (MainGuiScript._NormalMap, _WorkingAOMap, blitMaterial, 7); - Graphics.Blit (_WorkingAOMap, _BlendedAOMap); - - - yieldCountDown -= 1; - if( yieldCountDown <= 0 ){ - yieldCountDown = 5; - yield return new WaitForSeconds(0.01f); - } - } - - yield return new WaitForSeconds(0.01f); - - busy = false; - - } -} diff --git a/Assets/Scripts/AlignmentGui.cs b/Assets/Scripts/AlignmentGui.cs index bc5e853d..b7251d49 100644 --- a/Assets/Scripts/AlignmentGui.cs +++ b/Assets/Scripts/AlignmentGui.cs @@ -1,505 +1,526 @@ -using UnityEngine; +#region + using System.Collections; +using JetBrains.Annotations; +using UnityEngine; + +#endregion + +public class AlignmentGui : MonoBehaviour +{ + private static readonly int TargetPoint = Shader.PropertyToID("_TargetPoint"); + private static readonly int MainTex = Shader.PropertyToID("_MainTex"); + private static readonly int CorrectTex = Shader.PropertyToID("_CorrectTex"); + private static readonly int PointScale = Shader.PropertyToID("_PointScale"); + private static readonly int PointTl = Shader.PropertyToID("_PointTL"); + private static readonly int PointTr = Shader.PropertyToID("_PointTR"); + private static readonly int PointBl = Shader.PropertyToID("_PointBL"); + private static readonly int PointBr = Shader.PropertyToID("_PointBR"); + private static readonly int Width = Shader.PropertyToID("_Width"); + private static readonly int Height = Shader.PropertyToID("_Height"); + private static readonly int Lens = Shader.PropertyToID("_Lens"); + private static readonly int PerspectiveX = Shader.PropertyToID("_PerspectiveX"); + private static readonly int PerspectiveY = Shader.PropertyToID("_PerspectiveY"); + private static readonly int Slider = Shader.PropertyToID("_Slider"); + private RenderTexture _alignMap; + + private Material _blitMaterial; + private Camera _camera; + + private bool _doStuff; + + + private int _grabbedPoint; + + private float _lensDistort; + private string _lensDistortText = "0.0"; + + private RenderTexture _lensMap; + + private MainGui _mainGui; + private RenderTexture _perspectiveMap; + + private float _perspectiveX; + private string _perspectiveXText = "0.0"; + + private float _perspectiveY; + private string _perspectiveYText = "0.0"; + private Vector2 _pointBl = new Vector2(0.0f, 0.0f); + private Vector2 _pointBr = new Vector2(1.0f, 0.0f); + + private Vector2 _pointTl = new Vector2(0.0f, 1.0f); + private Vector2 _pointTr = new Vector2(1.0f, 1.0f); + + private float _slider = 0.5f; + private Vector2 _startOffset = Vector2.zero; + + private Texture2D _textureToAlign; + + private Rect _windowRect = new Rect(30, 300, 300, 530); + [UsedImplicitly] public bool NewTexture; + public GameObject TestObject; + + public Material ThisMaterial; + + private void Awake() + { + _camera = Camera.main; + } + + public void Initialize() + { + gameObject.SetActive(true); + _mainGui = MainGui.Instance; + TestObject.GetComponent().sharedMaterial = ThisMaterial; + _blitMaterial = new Material(Shader.Find("Hidden/Blit_Alignment")) {hideFlags = HideFlags.HideAndDontSave}; + + if (_mainGui.DiffuseMapOriginal != null) + _textureToAlign = _mainGui.DiffuseMapOriginal; + else if (_mainGui.HeightMap != null) + _textureToAlign = _mainGui.HeightMap; + else if (_mainGui.MetallicMap != null) + _textureToAlign = _mainGui.MetallicMap; + else if (_mainGui.SmoothnessMap != null) + _textureToAlign = _mainGui.SmoothnessMap; + else if (_mainGui.EdgeMap != null) + _textureToAlign = _mainGui.EdgeMap; + else if (_mainGui.AoMap != null) _textureToAlign = _mainGui.AoMap; + + + _doStuff = true; + } + + + private static void CleanupTexture(RenderTexture texture) + { + if (!texture) return; + texture.Release(); + // ReSharper disable once RedundantAssignment + texture = null; + } + + public void Close() + { + CleanupTexture(_lensMap); + CleanupTexture(_alignMap); + CleanupTexture(_perspectiveMap); + gameObject.SetActive(false); + } + + private void SelectClosestPoint() + { + if (Input.GetMouseButton(0)) return; + if (!_camera) return; + + if (!Physics.Raycast(_camera.ScreenPointToRay(Input.mousePosition), out var hit)) + return; + + var hitTc = hit.textureCoord; + + var dist1 = Vector2.Distance(hitTc, _pointTl); + var dist2 = Vector2.Distance(hitTc, _pointTr); + var dist3 = Vector2.Distance(hitTc, _pointBl); + var dist4 = Vector2.Distance(hitTc, _pointBr); + + var closestDist = dist1; + var closestPoint = _pointTl; + _grabbedPoint = 0; + if (dist2 < closestDist) + { + closestDist = dist2; + closestPoint = _pointTr; + _grabbedPoint = 1; + } + + if (dist3 < closestDist) + { + closestDist = dist3; + closestPoint = _pointBl; + _grabbedPoint = 2; + } + + if (dist4 < closestDist) + { + closestDist = dist4; + closestPoint = _pointBr; + _grabbedPoint = 3; + } + + if (closestDist > 0.1f) + { + closestPoint = new Vector2(-1, -1); + _grabbedPoint = -1; + } + + ThisMaterial.SetVector(TargetPoint, closestPoint); + } + + private void DragPoint() + { + if (!Physics.Raycast(_camera.ScreenPointToRay(Input.mousePosition), out var hit)) + return; + + var hitTc = hit.textureCoord; + + if (Input.GetMouseButtonDown(0)) + { + _startOffset = hitTc; + } + else if (Input.GetMouseButton(0)) + { + Vector2 point; + switch (_grabbedPoint) + { + case 0: + _pointTl += hitTc - _startOffset; + point = _pointTl; + break; + case 1: + _pointTr += hitTc - _startOffset; + point = _pointTr; + break; + case 2: + _pointBl += hitTc - _startOffset; + point = _pointBl; + break; + case 3: + _pointBr += hitTc - _startOffset; + point = _pointBr; + + break; + default: return; + } + + if (point != null) ThisMaterial.SetVector(TargetPoint, point); + + _startOffset = hitTc; + } + + _doStuff = true; + } + + // Update is called once per frame + private void Update() + { + SelectClosestPoint(); + DragPoint(); + + ProcessMap(_textureToAlign); + + var aspect = _textureToAlign.width / (float) _textureToAlign.height; + const float area = 1.0f; + var pointScale = Vector2.one; + pointScale.x = aspect; + var newArea = pointScale.x * pointScale.y; + var areaScale = Mathf.Sqrt(area / newArea); + + pointScale.x *= areaScale; + pointScale.y *= areaScale; + + ThisMaterial.SetTexture(MainTex, _lensMap); + ThisMaterial.SetTexture(CorrectTex, _perspectiveMap); + + ThisMaterial.SetVector(PointScale, pointScale); + + ThisMaterial.SetVector(PointTl, _pointTl); + ThisMaterial.SetVector(PointTr, _pointTr); + ThisMaterial.SetVector(PointBl, _pointBl); + ThisMaterial.SetVector(PointBr, _pointBr); + + _blitMaterial.SetVector(PointTl, _pointTl); + _blitMaterial.SetVector(PointTr, _pointTr); + _blitMaterial.SetVector(PointBl, _pointBl); + _blitMaterial.SetVector(PointBr, _pointBr); + + _blitMaterial.SetFloat(Width, _textureToAlign.width); + _blitMaterial.SetFloat(Height, _textureToAlign.height); + + _blitMaterial.SetFloat(Lens, _lensDistort); + _blitMaterial.SetFloat(PerspectiveX, _perspectiveX); + _blitMaterial.SetFloat(PerspectiveY, _perspectiveY); + + if (_doStuff) + { + _doStuff = false; + } + + ThisMaterial.SetFloat(Slider, _slider); + } + + private void DoMyWindow(int windowId) + { + const int offsetX = 10; + var offsetY = 30; + + GUI.Label(new Rect(offsetX, offsetY, 250, 30), "Alignment Reveal Slider"); + _slider = GUI.HorizontalSlider(new Rect(offsetX, offsetY + 20, 280, 10), _slider, 0.0f, 1.0f); + offsetY += 40; + + GUI.Label(new Rect(offsetX, offsetY, 250, 30), "Preview Map"); + offsetY += 30; + + GUI.enabled = _mainGui.DiffuseMapOriginal != null; + if (GUI.Button(new Rect(offsetX, offsetY, 130, 30), "Original Diffuse Map")) + { + _textureToAlign = _mainGui.DiffuseMapOriginal; + _doStuff = true; + } + + GUI.enabled = _mainGui.DiffuseMap != null; + if (GUI.Button(new Rect(offsetX + 150, offsetY, 130, 30), "Diffuse Map")) + { + _textureToAlign = _mainGui.DiffuseMap; + _doStuff = true; + } + + offsetY += 40; + + + GUI.enabled = _mainGui.HeightMap != null; + if (GUI.Button(new Rect(offsetX, offsetY, 130, 30), "Height Map")) + { + _textureToAlign = _mainGui.HeightMap; + _doStuff = true; + } + + offsetY += 40; + + GUI.enabled = _mainGui.MetallicMap != null; + if (GUI.Button(new Rect(offsetX, offsetY, 130, 30), "Metallic Map")) + { + _textureToAlign = _mainGui.MetallicMap; + _doStuff = true; + } + + GUI.enabled = _mainGui.SmoothnessMap != null; + if (GUI.Button(new Rect(offsetX + 150, offsetY, 130, 30), "Smoothness Map")) + { + _textureToAlign = _mainGui.SmoothnessMap; + _doStuff = true; + } + + offsetY += 40; + + GUI.enabled = _mainGui.EdgeMap != null; + if (GUI.Button(new Rect(offsetX, offsetY, 130, 30), "Edge Map")) + { + _textureToAlign = _mainGui.EdgeMap; + _doStuff = true; + } + + GUI.enabled = _mainGui.AoMap != null; + if (GUI.Button(new Rect(offsetX + 150, offsetY, 130, 30), "AO Map")) + { + _textureToAlign = _mainGui.AoMap; + _doStuff = true; + } + + offsetY += 40; + + GUI.enabled = true; + + + if (GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Lens Distort Correction", _lensDistort, + _lensDistortText, out _lensDistort, out _lensDistortText, -1.0f, 1.0f)) _doStuff = true; + offsetY += 40; + + if (GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Perspective Correction X", _perspectiveX, + _perspectiveXText, out _perspectiveX, out _perspectiveXText, -5.0f, 5.0f)) _doStuff = true; + offsetY += 40; + + if (GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Perspective Correction Y", _perspectiveY, + _perspectiveYText, out _perspectiveY, out _perspectiveYText, -5.0f, 5.0f)) _doStuff = true; + offsetY += 50; + + if (GUI.Button(new Rect(offsetX, offsetY, 130, 30), "Reset Points")) + { + _pointTl = new Vector2(0.0f, 1.0f); + _pointTr = new Vector2(1.0f, 1.0f); + _pointBl = new Vector2(0.0f, 0.0f); + _pointBr = new Vector2(1.0f, 0.0f); + } + + + if (GUI.Button(new Rect(offsetX + 150, offsetY, 130, 30), "Set All Maps")) StartCoroutine(SetMaps()); + + + GUI.DragWindow(); + } + + private void OnGUI() + { + _windowRect.width = 300; + _windowRect.height = 430; + + _windowRect = GUI.Window(21, _windowRect, DoMyWindow, "Texture Alignment Adjuster"); + } + + private void ProcessMap(Texture2D textureTarget) + { + var width = textureTarget.width; + var height = textureTarget.height; + + if (_lensMap == null) + _lensMap = new RenderTexture(width, height, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear); + if (_alignMap == null) + _alignMap = new RenderTexture(width, height, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear); + if (_perspectiveMap == null) + _perspectiveMap = + new RenderTexture(width, height, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear); + + Graphics.Blit(textureTarget, _lensMap, _blitMaterial, 0); + Graphics.Blit(_lensMap, _alignMap, _blitMaterial, 1); + Graphics.Blit(_alignMap, _perspectiveMap, _blitMaterial, 2); + } + + private Texture2D SetMap(Texture2D textureTarget) + { + var width = textureTarget.width; + var height = textureTarget.height; + + CleanupTexture(_lensMap); + CleanupTexture(_alignMap); + CleanupTexture(_perspectiveMap); + + _lensMap = new RenderTexture(width, height, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear); + _alignMap = new RenderTexture(width, height, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear); + _perspectiveMap = + new RenderTexture(width, height, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear); + + Graphics.Blit(textureTarget, _lensMap, _blitMaterial, 0); + Graphics.Blit(_lensMap, _alignMap, _blitMaterial, 1); + Graphics.Blit(_alignMap, _perspectiveMap, _blitMaterial, 2); + + var replaceTexture = _textureToAlign == textureTarget; + + Destroy(textureTarget); + // ReSharper disable once RedundantAssignment + textureTarget = null; + + RenderTexture.active = _perspectiveMap; + textureTarget = new Texture2D(width, height, TextureFormat.ARGB32, false, true); + textureTarget.ReadPixels(new Rect(0, 0, width, height), 0, 0); + textureTarget.Apply(); + + RenderTexture.active = null; + + CleanupTexture(_lensMap); + CleanupTexture(_alignMap); + CleanupTexture(_perspectiveMap); + + if (replaceTexture) _textureToAlign = textureTarget; + + _doStuff = true; + + return textureTarget; + } + + private RenderTexture SetMap(RenderTexture textureTarget) + { + var width = textureTarget.width; + var height = textureTarget.height; + + CleanupTexture(_lensMap); + CleanupTexture(_alignMap); + CleanupTexture(_perspectiveMap); + + _lensMap = new RenderTexture(width, height, 0, RenderTextureFormat.RHalf, RenderTextureReadWrite.Linear); + _alignMap = new RenderTexture(width, height, 0, RenderTextureFormat.RHalf, RenderTextureReadWrite.Linear); + _perspectiveMap = new RenderTexture(width, height, 0, RenderTextureFormat.RHalf, RenderTextureReadWrite.Linear); + + Graphics.Blit(textureTarget, _lensMap, _blitMaterial, 0); + Graphics.Blit(_lensMap, _alignMap, _blitMaterial, 1); + Graphics.Blit(_alignMap, _perspectiveMap, _blitMaterial, 2); + + if (textureTarget != null) + { + textureTarget.Release(); + textureTarget = null; + } + + Graphics.Blit(_perspectiveMap, textureTarget); + + CleanupTexture(_lensMap); + CleanupTexture(_alignMap); + CleanupTexture(_perspectiveMap); + + _doStuff = true; + + return textureTarget; + } + + private IEnumerator SetMaps() + { + if (_mainGui.HeightMap != null) + { + Debug.Log("Setting Height"); + _mainGui.HeightMap = SetMap(_mainGui.HeightMap); + } + + if (_mainGui.HdHeightMap != null) + { + Debug.Log("Setting HD Height"); + _mainGui.HdHeightMap = SetMap(_mainGui.HdHeightMap); + } + + yield return new WaitForSeconds(0.1f); + + if (_mainGui.DiffuseMap != null) + { + Debug.Log("Setting Diffuse"); + _mainGui.DiffuseMap = SetMap(_mainGui.DiffuseMap); + } + + yield return new WaitForSeconds(0.1f); + + if (_mainGui.DiffuseMapOriginal != null) + { + Debug.Log("Setting Diffuse Original"); + _mainGui.DiffuseMapOriginal = SetMap(_mainGui.DiffuseMapOriginal); + } + + yield return new WaitForSeconds(0.1f); + + if (_mainGui.NormalMap != null) + { + Debug.Log("Setting Normal"); + _mainGui.NormalMap = SetMap(_mainGui.NormalMap); + } + + yield return new WaitForSeconds(0.1f); + + if (_mainGui.MetallicMap != null) + { + Debug.Log("Setting Metallic"); + _mainGui.MetallicMap = SetMap(_mainGui.MetallicMap); + } + + yield return new WaitForSeconds(0.1f); -public class AlignmentGui : MonoBehaviour { - - RenderTexture _LensMap; - RenderTexture _AlignMap; - RenderTexture _PerspectiveMap; + if (_mainGui.SmoothnessMap != null) + { + Debug.Log("Setting Smoothness"); + _mainGui.SmoothnessMap = SetMap(_mainGui.SmoothnessMap); + } - Texture2D textureToAlign; + yield return new WaitForSeconds(0.1f); - Material blitMaterial; + if (_mainGui.EdgeMap != null) + { + Debug.Log("Setting Edge"); + _mainGui.EdgeMap = SetMap(_mainGui.EdgeMap); + } - public Material thisMaterial; - public GameObject testObject; - - MainGui MGS; - public bool newTexture = false; - - Rect windowRect = new Rect (30, 300, 300, 530); - - bool doStuff = false; - - Vector2 pointTL = new Vector2(0.0f,1.0f); - Vector2 pointTR = new Vector2(1.0f,1.0f); - Vector2 pointBL = new Vector2(0.0f,0.0f); - Vector2 pointBR = new Vector2(1.0f,0.0f); - - - int GrabbedPoint = 0; - Vector2 StartOffset = Vector2.zero; - - float Slider = 0.5f; - - float LensDistort = 0.0f; - string LensDistortText = "0.0"; + yield return new WaitForSeconds(0.1f); + + if (_mainGui.AoMap != null) + { + Debug.Log("Setting AO"); + _mainGui.AoMap = SetMap(_mainGui.AoMap); + } - float PerspectiveX = 0.0f; - string PerspectiveXText = "0.0"; - - float PerspectiveY = 0.0f; - string PerspectiveYText = "0.0"; - - // Use this for initialization - void Start () { - - } - - public void Initialize() { - this.gameObject.SetActive(true); - MGS = MainGui.instance; - testObject.GetComponent().sharedMaterial = thisMaterial; - blitMaterial = new Material (Shader.Find ("Hidden/Blit_Alignment")); - blitMaterial.hideFlags = HideFlags.HideAndDontSave; - - if (MGS._DiffuseMapOriginal != null) { - textureToAlign = MGS._DiffuseMapOriginal; - }else if (MGS._HeightMap != null) { - textureToAlign = MGS._HeightMap; - }else if (MGS._MetallicMap != null) { - textureToAlign = MGS._MetallicMap; - }else if (MGS._SmoothnessMap != null) { - textureToAlign = MGS._SmoothnessMap; - }else if (MGS._EdgeMap != null) { - textureToAlign = MGS._EdgeMap; - }else if (MGS._AOMap != null) { - textureToAlign = MGS._AOMap; - } - - - doStuff = true; - } - - - void CleanupTexture( RenderTexture _Texture ) { - - if (_Texture != null) { - _Texture.Release(); - _Texture = null; - } - } - - public void Close(){ - CleanupTexture (_LensMap ); - CleanupTexture (_AlignMap ); - CleanupTexture (_PerspectiveMap ); - this.gameObject.SetActive (false); - } - - void SelectClosestPoint() { - - if (!Input.GetMouseButton (0)) { - - RaycastHit hit; - if (!Physics.Raycast (Camera.main.ScreenPointToRay (Input.mousePosition), out hit)) - return; - - Vector2 hitTC = hit.textureCoord; - - float dist1 = Vector2.Distance (hitTC, pointTL); - float dist2 = Vector2.Distance (hitTC, pointTR); - float dist3 = Vector2.Distance (hitTC, pointBL); - float dist4 = Vector2.Distance (hitTC, pointBR); - - float closestDist = dist1; - Vector2 closestPoint = pointTL; - GrabbedPoint = 0; - if (dist2 < closestDist) { - closestDist = dist2; - closestPoint = pointTR; - GrabbedPoint = 1; - } - if (dist3 < closestDist) { - closestDist = dist3; - closestPoint = pointBL; - GrabbedPoint = 2; - } - if (dist4 < closestDist) { - closestDist = dist4; - closestPoint = pointBR; - GrabbedPoint = 3; - } - - if( closestDist > 0.1f ){ - closestPoint = new Vector2(-1,-1); - GrabbedPoint = -1; - } - - thisMaterial.SetVector ("_TargetPoint", closestPoint); - - } - - } - - void DragPoint () { - - RaycastHit hit; - if (!Physics.Raycast (Camera.main.ScreenPointToRay (Input.mousePosition), out hit)) - return; - - Vector2 hitTC = hit.textureCoord; - - if (Input.GetMouseButtonDown (0)) { - StartOffset = hitTC; - } else if(Input.GetMouseButton (0)) { - - switch(GrabbedPoint){ - case 0: - pointTL += hitTC - StartOffset; - thisMaterial.SetVector ("_TargetPoint", pointTL); - break; - case 1: - pointTR += hitTC - StartOffset; - thisMaterial.SetVector ("_TargetPoint", pointTR); - break; - case 2: - pointBL += hitTC - StartOffset; - thisMaterial.SetVector ("_TargetPoint", pointBL); - break; - case 3: - pointBR += hitTC - StartOffset; - thisMaterial.SetVector ("_TargetPoint", pointBR); - break; - } - - StartOffset = hitTC; - } - - doStuff = true; - } - - // Update is called once per frame - void Update () { - - SelectClosestPoint (); - DragPoint (); - - float aspect = (float)textureToAlign.width / (float)textureToAlign.height; - float area = 1.0f; - Vector2 pointScale = Vector2.one; - pointScale.x = aspect; - float newArea = pointScale.x * pointScale.y; - float areaScale = Mathf.Sqrt ( area / newArea ); - - pointScale.x *= areaScale; - pointScale.y *= areaScale; - - thisMaterial.SetTexture ("_MainTex", _LensMap); - thisMaterial.SetTexture ("_CorrectTex", _PerspectiveMap); - - thisMaterial.SetVector ("_PointScale", pointScale); - - thisMaterial.SetVector ("_PointTL", pointTL); - thisMaterial.SetVector ("_PointTR", pointTR); - thisMaterial.SetVector ("_PointBL", pointBL); - thisMaterial.SetVector ("_PointBR", pointBR); - - float realPerspectiveX = PerspectiveX; - if (realPerspectiveX < 0.0f) { - realPerspectiveX = Mathf.Abs( 1.0f / ( realPerspectiveX - 1.0f ) ); - } else { - realPerspectiveX = realPerspectiveX + 1.0f; - } - - float realPerspectiveY = PerspectiveY; - if (realPerspectiveY < 0.0f) { - realPerspectiveY = Mathf.Abs( 1.0f / ( realPerspectiveY - 1.0f ) ); - } else { - realPerspectiveY = realPerspectiveY + 1.0f; - } - - blitMaterial.SetVector ("_PointTL", pointTL); - blitMaterial.SetVector ("_PointTR", pointTR); - blitMaterial.SetVector ("_PointBL", pointBL); - blitMaterial.SetVector ("_PointBR", pointBR); - - blitMaterial.SetFloat ("_Width", textureToAlign.width); - blitMaterial.SetFloat ("_Height", textureToAlign.height); - - blitMaterial.SetFloat ("_Lens", LensDistort); - blitMaterial.SetFloat ("_PerspectiveX", PerspectiveX); - blitMaterial.SetFloat ("_PerspectiveY", PerspectiveY); - - if (doStuff) { - ProcessMap( textureToAlign ); - doStuff = false; - } - - thisMaterial.SetFloat ("_Slider", Slider); - - } - - void DoMyWindow ( int windowID ) { - - int spacingX = 0; - int spacingY = 50; - int spacing2Y = 70; - - int offsetX = 10; - int offsetY = 30; - - GUI.Label (new Rect (offsetX, offsetY, 250, 30), "Alignment Reveal Slider" ); - Slider = GUI.HorizontalSlider( new Rect( offsetX, offsetY + 20, 280, 10 ),Slider,0.0f, 1.0f ); - offsetY += 40; - - GUI.Label (new Rect (offsetX, offsetY, 250, 30), "Preview Map" ); - offsetY += 30; - - if (MGS._DiffuseMapOriginal == null) { GUI.enabled = false; } else { GUI.enabled = true; } - if (GUI.Button (new Rect (offsetX, offsetY, 130, 30), "Original Diffuse Map")) { - textureToAlign = MGS._DiffuseMapOriginal; - doStuff = true; - } - - if (MGS._DiffuseMap == null) { GUI.enabled = false; } else { GUI.enabled = true; } - if (GUI.Button (new Rect (offsetX + 150, offsetY, 130, 30), "Diffuse Map")) { - textureToAlign = MGS._DiffuseMap; - doStuff = true; - } - offsetY += 40; - - - if (MGS._HeightMap == null) { GUI.enabled = false; } else { GUI.enabled = true; } - if (GUI.Button (new Rect (offsetX, offsetY, 130, 30), "Height Map")) { - textureToAlign = MGS._HeightMap; - doStuff = true; - } - offsetY += 40; - - if (MGS._MetallicMap == null) { GUI.enabled = false; } else { GUI.enabled = true; } - if (GUI.Button (new Rect (offsetX, offsetY, 130, 30), "Metallic Map")) { - textureToAlign = MGS._MetallicMap; - doStuff = true; - } - - if (MGS._SmoothnessMap == null) { GUI.enabled = false; } else { GUI.enabled = true; } - if (GUI.Button (new Rect (offsetX + 150, offsetY, 130, 30), "Smoothness Map")) { - textureToAlign = MGS._SmoothnessMap; - doStuff = true; - } - offsetY += 40; - - if (MGS._EdgeMap == null) { GUI.enabled = false; } else { GUI.enabled = true; } - if (GUI.Button (new Rect (offsetX, offsetY, 130, 30), "Edge Map")) { - textureToAlign = MGS._EdgeMap; - doStuff = true; - } - - if (MGS._AOMap == null) { GUI.enabled = false; } else { GUI.enabled = true; } - if (GUI.Button (new Rect (offsetX + 150, offsetY, 130, 30), "AO Map")) { - textureToAlign = MGS._AOMap; - doStuff = true; - } - offsetY += 40; - - GUI.enabled = true; - - - - if (GuiHelper.Slider (new Rect (offsetX, offsetY, 280, 50), "Lens Distort Correction", LensDistort, LensDistortText, out LensDistort, out LensDistortText, -1.0f, 1.0f)) { - doStuff = true; - } - offsetY += 40; - - if (GuiHelper.Slider (new Rect (offsetX, offsetY, 280, 50), "Perspective Correction X", PerspectiveX, PerspectiveXText, out PerspectiveX, out PerspectiveXText, -5.0f, 5.0f)) { - doStuff = true; - } - offsetY += 40; - - if (GuiHelper.Slider (new Rect (offsetX, offsetY, 280, 50), "Perspective Correction Y", PerspectiveY, PerspectiveYText, out PerspectiveY, out PerspectiveYText, -5.0f, 5.0f)) { - doStuff = true; - } - offsetY += 50; - - if( GUI.Button (new Rect (offsetX, offsetY, 130, 30), "Reset Points" ) ){ - pointTL = new Vector2(0.0f,1.0f); - pointTR = new Vector2(1.0f,1.0f); - pointBL = new Vector2(0.0f,0.0f); - pointBR = new Vector2(1.0f,0.0f); - } - - - if( GUI.Button (new Rect (offsetX + 150, offsetY, 130, 30), "Set All Maps" ) ){ - StartCoroutine( SetMaps ( ) ); - } - - - GUI.DragWindow(); - - } - - void OnGUI () { - - windowRect.width = 300; - windowRect.height = 430; - - windowRect = GUI.Window (21, windowRect, DoMyWindow, "Texture Alignment Adjuster"); - } - - void ProcessMap ( Texture2D textureTarget ){ - int width = textureTarget.width; - int height = textureTarget.height; - - if (_LensMap == null) { - _LensMap = new RenderTexture (width, height, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear); - } - if (_AlignMap == null) { - _AlignMap = new RenderTexture (width, height, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear); - } - if (_PerspectiveMap == null) { - _PerspectiveMap = new RenderTexture (width, height, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear); - } - - Graphics.Blit (textureTarget, _LensMap, blitMaterial, 0); - Graphics.Blit (_LensMap, _AlignMap, blitMaterial, 1); - Graphics.Blit (_AlignMap, _PerspectiveMap, blitMaterial, 2); - } - - Texture2D SetMap ( Texture2D textureTarget ) { - - int width = textureTarget.width; - int height = textureTarget.height; - - CleanupTexture (_LensMap ); - CleanupTexture (_AlignMap ); - CleanupTexture (_PerspectiveMap ); - - _LensMap = new RenderTexture (width, height, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear); - _AlignMap = new RenderTexture (width, height, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear); - _PerspectiveMap = new RenderTexture (width, height, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear); - - Graphics.Blit (textureTarget, _LensMap, blitMaterial, 0); - Graphics.Blit (_LensMap, _AlignMap, blitMaterial, 1); - Graphics.Blit (_AlignMap, _PerspectiveMap, blitMaterial, 2); - - bool replaceTexture = false; - if (textureToAlign == textureTarget) { - replaceTexture = true; - } - - Destroy (textureTarget); - textureTarget = null; - - RenderTexture.active = _PerspectiveMap; - textureTarget = new Texture2D (width, height, TextureFormat.ARGB32, false, true); - textureTarget.ReadPixels (new Rect (0, 0, width, height), 0, 0); - textureTarget.Apply (); - - RenderTexture.active = null; - - CleanupTexture (_LensMap ); - CleanupTexture (_AlignMap ); - CleanupTexture (_PerspectiveMap ); - - if (replaceTexture) { - textureToAlign = textureTarget; - } - - doStuff = true; - - return textureTarget; - - } - - RenderTexture SetMap ( RenderTexture textureTarget ) { - - int width = textureTarget.width; - int height = textureTarget.height; - - CleanupTexture (_LensMap ); - CleanupTexture (_AlignMap ); - CleanupTexture (_PerspectiveMap ); - - _LensMap = new RenderTexture (width, height, 0, RenderTextureFormat.RHalf, RenderTextureReadWrite.Linear); - _AlignMap = new RenderTexture (width, height, 0, RenderTextureFormat.RHalf, RenderTextureReadWrite.Linear); - _PerspectiveMap = new RenderTexture (width, height, 0, RenderTextureFormat.RHalf, RenderTextureReadWrite.Linear); - - Graphics.Blit (textureTarget, _LensMap, blitMaterial, 0); - Graphics.Blit (_LensMap, _AlignMap, blitMaterial, 1); - Graphics.Blit (_AlignMap, _PerspectiveMap, blitMaterial, 2); - - if (textureTarget != null) { - textureTarget.Release (); - textureTarget = null; - } - - Graphics.Blit (_PerspectiveMap, textureTarget); - - CleanupTexture (_LensMap ); - CleanupTexture (_AlignMap ); - CleanupTexture (_PerspectiveMap ); - - doStuff = true; - - return textureTarget; - - } - - IEnumerator SetMaps () { - - if (MGS._HeightMap != null) { - Debug.Log ("Setting Height"); - MGS._HeightMap = SetMap( MGS._HeightMap ); - } - - if (MGS._HDHeightMap != null) { - Debug.Log ("Setting HD Height"); - MGS._HDHeightMap = SetMap( MGS._HDHeightMap ); - } - - yield return new WaitForSeconds(0.1f); - - if (MGS._DiffuseMap != null) { - Debug.Log ("Setting Diffuse"); - MGS._DiffuseMap = SetMap( MGS._DiffuseMap ); - } - - yield return new WaitForSeconds(0.1f); - - if (MGS._DiffuseMapOriginal != null) { - Debug.Log ("Setting Diffuse Original"); - MGS._DiffuseMapOriginal = SetMap( MGS._DiffuseMapOriginal ); - } - - yield return new WaitForSeconds(0.1f); - - if (MGS._NormalMap != null) { - Debug.Log ("Setting Normal"); - MGS._NormalMap = SetMap( MGS._NormalMap ); - } - - yield return new WaitForSeconds(0.1f); - - if (MGS._MetallicMap != null) { - Debug.Log ("Setting Metallic"); - MGS._MetallicMap = SetMap( MGS._MetallicMap ); - } - - yield return new WaitForSeconds(0.1f); - - if (MGS._SmoothnessMap != null) { - Debug.Log ("Setting Smoothness"); - MGS._SmoothnessMap = SetMap( MGS._SmoothnessMap ); - } - - yield return new WaitForSeconds(0.1f); - - if (MGS._EdgeMap != null) { - Debug.Log ("Setting Edge"); - MGS._EdgeMap = SetMap( MGS._EdgeMap ); - } - - yield return new WaitForSeconds(0.1f); - - if (MGS._AOMap != null) { - Debug.Log ("Setting AO"); - MGS._AOMap = SetMap( MGS._AOMap ); - } - - yield return new WaitForSeconds(0.1f); - - Resources.UnloadUnusedAssets (); - - } -} + yield return new WaitForSeconds(0.1f); + + Resources.UnloadUnusedAssets(); + } +} \ No newline at end of file diff --git a/Assets/Scripts/AoFromNormalGui.cs b/Assets/Scripts/AoFromNormalGui.cs new file mode 100644 index 00000000..12f7f854 --- /dev/null +++ b/Assets/Scripts/AoFromNormalGui.cs @@ -0,0 +1,301 @@ +#region + +using System.Collections; +using UnityEngine; + +#endregion + +public class AoFromNormalGui : MonoBehaviour +{ + private static readonly int FinalContrast = Shader.PropertyToID("_FinalContrast"); + private static readonly int FinalBias = Shader.PropertyToID("_FinalBias"); + private static readonly int AoBlend = Shader.PropertyToID("_AOBlend"); + private static readonly int MainTex = Shader.PropertyToID("_MainTex"); + private static readonly int ImageSize = Shader.PropertyToID("_ImageSize"); + private static readonly int Spread = Shader.PropertyToID("_Spread"); + private static readonly int HeightTex = Shader.PropertyToID("_HeightTex"); + private static readonly int BlendTex = Shader.PropertyToID("_BlendTex"); + private static readonly int Depth = Shader.PropertyToID("_Depth"); + private static readonly int BlendAmount = Shader.PropertyToID("_BlendAmount"); + private static readonly int Progress = Shader.PropertyToID("_Progress"); + private Texture2D _aoMap; + + private AoSettings _aos; + private RenderTexture _blendedAoMap; + private Material _blitMaterial; + private bool _doStuff; + + private int _imageSizeX = 1024; + private int _imageSizeY = 1024; + private bool _newTexture; + + private bool _settingsInitialized; + private RenderTexture _tempAoMap; + + private Rect _windowRect = new Rect(30, 300, 300, 230); + private RenderTexture _workingAoMap; + + [HideInInspector] public bool Busy; + public Texture2D DefaultHeight; + + public Texture2D DefaultNormal; + + public MainGui MainGuiScript; + + public GameObject TestObject; + + public Material ThisMaterial; + + public void GetValues(ProjectObject projectObject) + { + InitializeSettings(); + projectObject.AoSettings = _aos; + } + + public void SetValues(ProjectObject projectObject) + { + InitializeSettings(); + if (projectObject.AoSettings != null) + { + _aos = projectObject.AoSettings; + } + else + { + _settingsInitialized = false; + InitializeSettings(); + } + + _doStuff = true; + } + + private void InitializeSettings() + { + if (_settingsInitialized) return; + _aos = new AoSettings(); + + if (MainGuiScript.HeightMap != null) + { + _aos.Blend = 1.0f; + _aos.BlendText = "1.0"; + } + else + { + _aos.Blend = 0.0f; + _aos.BlendText = "0.0"; + } + + _settingsInitialized = true; + } + + // Use this for initialization + private void Start() + { + TestObject.GetComponent().sharedMaterial = ThisMaterial; + + _blitMaterial = new Material(Shader.Find("Hidden/Blit_Shader")); + + //blitMaterial = new Material (Shader.Find ("Hidden/Blit_Height_From_Normal")); + + InitializeSettings(); + } + + public void DoStuff() + { + _doStuff = true; + } + + public void NewTexture() + { + _newTexture = true; + } + + + // Update is called once per frame + private void Update() + { + if (_newTexture) + { + InitializeTextures(); + _newTexture = false; + } + + if (_doStuff) + { + StopAllCoroutines(); + + StartCoroutine(ProcessNormalDepth()); + _doStuff = false; + } + + ThisMaterial.SetFloat(FinalContrast, _aos.FinalContrast); + ThisMaterial.SetFloat(FinalBias, _aos.FinalBias); + ThisMaterial.SetFloat(AoBlend, _aos.Blend); + } + + private void DoMyWindow(int windowId) + { + const int offsetX = 10; + var offsetY = 30; + + if (GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "AO pixel Spread", _aos.Spread, _aos.SpreadText, + out _aos.Spread, out _aos.SpreadText, 10.0f, 100.0f)) _doStuff = true; + offsetY += 40; + + if (GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Pixel Depth", _aos.Depth, _aos.DepthText, + out _aos.Depth, out _aos.DepthText, 0.0f, 256.0f)) _doStuff = true; + offsetY += 40; + + GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Blend Normal AO and Depth AO", _aos.Blend, + _aos.BlendText, + out _aos.Blend, out _aos.BlendText, 0.0f, 1.0f); + offsetY += 40; + + GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "AO Power", _aos.FinalContrast, _aos.FinalContrastText, + out _aos.FinalContrast, out _aos.FinalContrastText, 0.1f, 10.0f); + offsetY += 40; + + GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "AO Bias", _aos.FinalBias, _aos.FinalBiasText, + out _aos.FinalBias, out _aos.FinalBiasText, -1.0f, 1.0f); + offsetY += 50; + + GUI.enabled = !Busy; + + if (GUI.Button(new Rect(offsetX + 10, offsetY, 130, 30), "Reset to Defaults")) + { + //_settingsInitialized = false; + SetValues(new ProjectObject()); + //StartCoroutine(ProcessDiffuse()); + } + + if (GUI.Button(new Rect(offsetX + 150, offsetY, 130, 30), "Set as AO Map")) StartCoroutine(ProcessAo()); + GUI.enabled = true; + GUI.DragWindow(); + } + + private void OnGUI() + { + _windowRect.width = 300; + _windowRect.height = 280; + + _windowRect = GUI.Window(10, _windowRect, DoMyWindow, "Normal + Depth to AO"); + } + + public void InitializeTextures() + { + TestObject.GetComponent().sharedMaterial = ThisMaterial; + + CleanupTextures(); + + if (MainGuiScript.NormalMap) + { + _imageSizeX = MainGuiScript.NormalMap.width; + _imageSizeY = MainGuiScript.NormalMap.height; + } + else + { + _imageSizeX = MainGuiScript.HeightMap.width; + _imageSizeY = MainGuiScript.HeightMap.height; + } + + Debug.Log("Initializing Textures of size: " + _imageSizeX + "x" + _imageSizeY); + + _workingAoMap = new RenderTexture(_imageSizeX, _imageSizeY, 0, RenderTextureFormat.RGHalf, + RenderTextureReadWrite.Linear) {wrapMode = TextureWrapMode.Repeat}; + _blendedAoMap = new RenderTexture(_imageSizeX, _imageSizeY, 0, RenderTextureFormat.RGHalf, + RenderTextureReadWrite.Linear) {wrapMode = TextureWrapMode.Repeat}; + } + + public void Close() + { + CleanupTextures(); + gameObject.SetActive(false); + } + + private static void CleanupTexture(RenderTexture texture) + { + if (!texture) return; + texture.Release(); + } + + private void CleanupTextures() + { + CleanupTexture(_workingAoMap); + CleanupTexture(_blendedAoMap); + CleanupTexture(_tempAoMap); + } + + public IEnumerator ProcessAo() + { + Busy = true; + + Debug.Log("Processing AO Map"); + + CleanupTexture(_tempAoMap); + _tempAoMap = new RenderTexture(_imageSizeX, _imageSizeY, 0, RenderTextureFormat.ARGB32, + RenderTextureReadWrite.Linear) {wrapMode = TextureWrapMode.Repeat}; + + _blitMaterial.SetFloat(FinalBias, _aos.FinalBias); + _blitMaterial.SetFloat(FinalContrast, _aos.FinalContrast); + _blitMaterial.SetTexture(MainTex, _blendedAoMap); + _blitMaterial.SetFloat(AoBlend, _aos.Blend); + + Graphics.Blit(_blendedAoMap, _tempAoMap, _blitMaterial, 8); + + if (MainGuiScript.AoMap != null) Destroy(MainGuiScript.AoMap); + + RenderTexture.active = _tempAoMap; + MainGuiScript.AoMap = new Texture2D(_tempAoMap.width, _tempAoMap.height, TextureFormat.ARGB32, true, true); + MainGuiScript.AoMap.ReadPixels(new Rect(0, 0, _tempAoMap.width, _tempAoMap.height), 0, 0); + MainGuiScript.AoMap.Apply(); + + yield return new WaitForSeconds(0.1f); + + CleanupTexture(_tempAoMap); + + Busy = false; + } + + public IEnumerator ProcessNormalDepth() + { + Busy = true; + + Debug.Log("Processing Normal Depth to AO"); + + _blitMaterial.SetVector(ImageSize, new Vector4(_imageSizeX, _imageSizeY, 0, 0)); + _blitMaterial.SetFloat(Spread, _aos.Spread); + + _blitMaterial.SetTexture(MainTex, MainGuiScript.NormalMap != null ? MainGuiScript.NormalMap : DefaultNormal); + + if (MainGuiScript.HdHeightMap != null) + _blitMaterial.SetTexture(HeightTex, MainGuiScript.HdHeightMap); + else if (MainGuiScript.HeightMap != null) + _blitMaterial.SetTexture(HeightTex, MainGuiScript.HeightMap); + else + _blitMaterial.SetTexture(HeightTex, DefaultHeight); + + _blitMaterial.SetTexture(BlendTex, _blendedAoMap); + _blitMaterial.SetFloat(Depth, _aos.Depth); + ThisMaterial.SetTexture(MainTex, _blendedAoMap); + + var yieldCountDown = 5; + + for (var i = 1; i < 100; i++) + { + _blitMaterial.SetFloat(BlendAmount, 1.0f / i); + _blitMaterial.SetFloat(Progress, i / 100.0f); + + Graphics.Blit(MainGuiScript.NormalMap, _workingAoMap, _blitMaterial, 7); + Graphics.Blit(_workingAoMap, _blendedAoMap); + + + yieldCountDown -= 1; + if (yieldCountDown > 0) continue; + yieldCountDown = 5; + yield return new WaitForSeconds(0.01f); + } + + yield return new WaitForSeconds(0.01f); + + Busy = false; + } +} \ No newline at end of file diff --git a/Assets/Scripts/AOFromNormalGui.cs.meta b/Assets/Scripts/AoFromNormalGui.cs.meta similarity index 100% rename from Assets/Scripts/AOFromNormalGui.cs.meta rename to Assets/Scripts/AoFromNormalGui.cs.meta diff --git a/Assets/Scripts/AoSettings.cs b/Assets/Scripts/AoSettings.cs new file mode 100644 index 00000000..642a53f1 --- /dev/null +++ b/Assets/Scripts/AoSettings.cs @@ -0,0 +1,46 @@ +#region + +using System.ComponentModel; + +#endregion + +public class AoSettings +{ + [DefaultValue(1.0f)] public float Blend; + + [DefaultValue("1")] public string BlendText; + + [DefaultValue(100.0f)] public float Depth; + + [DefaultValue("100")] public string DepthText; + + [DefaultValue(0.0f)] public float FinalBias; + + [DefaultValue("0")] public string FinalBiasText; + + [DefaultValue(1.0f)] public float FinalContrast; + + [DefaultValue("1")] public string FinalContrastText; + + [DefaultValue(5.0f)] public float Spread; + + [DefaultValue("50")] public string SpreadText; + + public AoSettings() + { + Spread = 50.0f; + SpreadText = "50"; + + Depth = 100.0f; + DepthText = "100"; + + FinalBias = 0.0f; + FinalBiasText = "0"; + + FinalContrast = 1.0f; + FinalContrastText = "1"; + + Blend = 1.0f; + BlendText = "1"; + } +} \ No newline at end of file diff --git a/Assets/Scripts/AoSettings.cs.meta b/Assets/Scripts/AoSettings.cs.meta new file mode 100644 index 00000000..7a8d9207 --- /dev/null +++ b/Assets/Scripts/AoSettings.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 04241ebfcd2e4458a58c38baa8a20c7d +timeCreated: 1549053956 \ No newline at end of file diff --git a/Assets/Scripts/BashRunner.cs b/Assets/Scripts/BashRunner.cs new file mode 100644 index 00000000..8ba4ba6c --- /dev/null +++ b/Assets/Scripts/BashRunner.cs @@ -0,0 +1,54 @@ +#region + +using System; +using System.Diagnostics; +using System.Text; + +#endregion + +internal static class BashRunner +{ + // ReSharper disable once UnusedMethodReturnValue.Global + public static string Run(string commandLine) + { + var errorBuilder = new StringBuilder(); + var outputBuilder = new StringBuilder(); + var arguments = $"-c \"{commandLine}\""; + using (var process = new Process + { + StartInfo = new ProcessStartInfo + { + FileName = "bash", + Arguments = arguments, + RedirectStandardOutput = true, + RedirectStandardError = true, + UseShellExecute = false, + CreateNoWindow = false + } + }) + { + process.Start(); + process.OutputDataReceived += (sender, args) => { outputBuilder.AppendLine(args.Data); }; + process.BeginOutputReadLine(); + process.ErrorDataReceived += (sender, args) => { errorBuilder.AppendLine(args.Data); }; + process.BeginErrorReadLine(); + if (!process.WaitForExit(500)) + { + var timeoutError = $@"Process timed out. Command line: bash {arguments}. +Output: {outputBuilder} +Error: {errorBuilder}"; + throw new Exception(timeoutError); + } + + if (process.ExitCode == 0) + { + return outputBuilder.ToString(); + } + + var error = $@"Could not execute process. Command line: bash {arguments}. +Output: {outputBuilder} +Error: {errorBuilder}"; + throw new Exception(error); + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/BashRunner.cs.meta b/Assets/Scripts/BashRunner.cs.meta new file mode 100644 index 00000000..a4970b1b --- /dev/null +++ b/Assets/Scripts/BashRunner.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: dba72e141408d04ed81b8e5de49a9698 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/BatchUI.cs b/Assets/Scripts/BatchUI.cs new file mode 100644 index 00000000..d1c906f2 --- /dev/null +++ b/Assets/Scripts/BatchUI.cs @@ -0,0 +1,191 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using System.IO; +using SFB; +using System.Linq; +using System; + +public class BatchUI : MonoBehaviour +{ + public MainGui MainGui; + // public HeightFromDiffuseGui HeightmapCreator; + public bool UseInitalLocation; + bool PathIsSet; + string path = null; + public bool ProcessPropertyMap; + // Start is called before the first frame update + void Start() + { + MainGui = FindObjectOfType(); + } + + // Update is called once per frame + void Update() + { + + } + + /// + /// use inital location toggle + /// + /// what the value is + public void UseInitalLocationToggle(bool value) { UseInitalLocation = value; } + + /// + /// Loads all the textures for batching. + /// + public void BatchLoadTextures() + { + StartCoroutine(BatchProcessTextures()); + } + + /// + /// Processes all the textures and saves them out. + /// + /// IEnum + private IEnumerator BatchProcessTextures() + { + var path = StandaloneFileBrowser.OpenFolderPanel("Texture Files Location", "", false); + //var path = StandaloneFileBrowser.SaveFilePanel("Texture Directory", "", "",""); + var s = Directory.GetFiles(path[0], "*.*").Where(g => g.EndsWith(".jpg") || g.EndsWith(".png")); + foreach (string f in s) + { + //BatchProcessTextures(f); + + byte[] Data = System.IO.File.ReadAllBytes(f); + Texture2D Tex = new Texture2D(2, 2); + if (Tex.LoadImage(Data)) + { + yield return StartCoroutine(BatchTextures(Tex, f)); + + //MainGui.HeightFromDiffuseGuiScript.StartCoroutine(ProcessHeight()); + //return null; + } + } + //return null; + } + + /// + /// Batch runs all the textures to output them to a file location + /// + /// Texture to output + /// Name of texture + /// IEnum + IEnumerator BatchTextures(Texture2D T, string name) + { + MainGui.DiffuseMapOriginal = T; + MainGui.HeightFromDiffuseGuiObject.SetActive(true); + MainGui.HeightFromDiffuseGuiScript.NewTexture(); + MainGui.HeightFromDiffuseGuiScript.DoStuff(); + //yield return MainGui.HeightFromDiffuseGuiScript.StartCoroutine(MainGui.HeightFromDiffuseGuiScript.ProcessDiffuse()); + yield return new WaitForSeconds(.1f); + MainGui.HeightFromDiffuseGuiScript.StartProcessHeight(); + MainGui.CloseWindows(); + MainGui.FixSize(); + MainGui.NormalFromHeightGuiObject.SetActive(true); + MainGui.NormalFromHeightGuiScript.NewTexture(); + MainGui.NormalFromHeightGuiScript.DoStuff(); + //yield return MainGui.NormalFromHeightGuiScript.StartCoroutine(MainGui.NormalFromHeightGuiScript.ProcessHeight()); + yield return new WaitForSeconds(.1f); + MainGui.NormalFromHeightGuiScript.StartProcessNormal(); + yield return new WaitForEndOfFrame(); + MainGui.CloseWindows(); + MainGui.FixSize(); + MainGui.MetallicMap = new Texture2D(MainGui.HeightMap.width, MainGui.HeightMap.height); + Color theColor = new Color(); + for (int x = 0; x < MainGui.MetallicMap.width; x++) + { + for (int y = 0; y < MainGui.MetallicMap.height; y++) + { + theColor.r = 0; + theColor.g = 0; + theColor.b = 0; + theColor.a = 255; + MainGui.MetallicMap.SetPixel(x, y, theColor); + } + } + // MainGui.MetallicGuiObject.SetActive(true); + //MainGui.MetallicGuiScript.NewTexture(); + //MainGui.MetallicGuiScript.DoStuff(); + //yield return new WaitForSeconds(.1f); + //MainGui.MetallicGuiScript.StartCoroutine(MainGui.MetallicGuiScript.ProcessMetallic()); + MainGui.MetallicMap.Apply(); + MainGui.CloseWindows(); + MainGui.FixSize(); + MainGui.SmoothnessGuiObject.SetActive(true); + MainGui.SmoothnessGuiScript.NewTexture(); + MainGui.SmoothnessGuiScript.DoStuff(); + yield return new WaitForSeconds(.1f); + MainGui.SmoothnessGuiScript.StartCoroutine(MainGui.SmoothnessGuiScript.ProcessSmoothness()); + MainGui.CloseWindows(); + MainGui.FixSize(); + MainGui.EdgeFromNormalGuiObject.SetActive(true); + MainGui.EdgeFromNormalGuiScript.NewTexture(); + MainGui.EdgeFromNormalGuiScript.DoStuff(); + yield return new WaitForSeconds(.1f); + MainGui.EdgeFromNormalGuiScript.StartCoroutine(MainGui.EdgeFromNormalGuiScript.ProcessEdge()); + MainGui.CloseWindows(); + MainGui.FixSize(); + MainGui.AoFromNormalGuiObject.SetActive(true); + MainGui.AoFromNormalGuiScript.NewTexture(); + MainGui.AoFromNormalGuiScript.DoStuff(); + yield return new WaitForSeconds(.1f); + MainGui.AoFromNormalGuiScript.StartCoroutine(MainGui.AoFromNormalGuiScript.ProcessAo()); + + yield return new WaitForSeconds(.3f); + + List names = name.Split( new string[] { "/", "\\" }, StringSplitOptions.None).ToList(); + //Debug.Log(names); + foreach(var s in names) + { + Debug.Log(s); + } + string defaultName = names[names.Count - 1]; + Debug.Log(defaultName); + names = defaultName.Split('.').ToList(); + defaultName = names[0]; + string NameWithOutExtension = defaultName; + defaultName = defaultName + ".mtz"; + + if (UseInitalLocation) + { + if (!PathIsSet) + { + path = StandaloneFileBrowser.SaveFilePanel("Save Project", MainGui._lastDirectory, defaultName, "mtz"); + //if (path.IsNullOrEmpty()) return; + PathIsSet = true; + var lastBar = path.LastIndexOf(MainGui._pathChar); + MainGui._lastDirectory = path.Substring(0, lastBar + 1); + + } + else + { + List PathSplit = path.Split(new string[] { "/", "\\" }, StringSplitOptions.None).ToList(); + //PathSplit[PathSplit.Length - 1] + PathSplit.RemoveAt(PathSplit.Count - 1); + //Debug.Log(PathSplit); + path = string.Join("/" , PathSplit.ToArray()); + path = path+ "/" + defaultName; + Debug.Log(defaultName); + //var lastBar = path.LastIndexOf(MainGui._pathChar); + //MainGui._lastDirectory = path.Substring(0, lastBar + 1); + } + } + else + { + path = StandaloneFileBrowser.SaveFilePanel("Save Project", MainGui._lastDirectory, defaultName, "mtz"); + var lastBar = path.LastIndexOf(MainGui._pathChar); + MainGui._lastDirectory = path.Substring(0, lastBar + 1); + } + Debug.Log(path); + MainGui._saveLoadProjectScript.SaveProject(path); + yield return new WaitForSeconds(1f); + if (ProcessPropertyMap) + { + MainGui.ProcessPropertyMap(); + MainGui.SaveTextureFile(MapType.Property, path, NameWithOutExtension); + } + //return null; + } +} diff --git a/Assets/Scripts/BatchUI.cs.meta b/Assets/Scripts/BatchUI.cs.meta new file mode 100644 index 00000000..4ea8a0d7 --- /dev/null +++ b/Assets/Scripts/BatchUI.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 27d90d35f40a67840a7d3f34d9e6c603 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/CameraPanZoom.cs b/Assets/Scripts/CameraPanZoom.cs index de2120d9..684c3cb1 100644 --- a/Assets/Scripts/CameraPanZoom.cs +++ b/Assets/Scripts/CameraPanZoom.cs @@ -1,74 +1,65 @@ -using UnityEngine; -using System.Collections; - -public class CameraPanZoom : MonoBehaviour { - - public FileBrowser fileBrowser; - - Vector3 targetPos; - float targetFov; - - Vector2 mousePos; - Vector2 lastMousePos; - - public bool holdKey = false; - public bool noHoldKey = false; - public KeyCode[] keyToHold; - - int mouseDownCount = 0; - - public int MouseButtonPan = 0; - - // Use this for initialization - void Start () { - - targetPos = this.transform.position; - - } - - // Update is called once per frame - void Update () { - - mousePos = Input.mousePosition; - - Vector2 mouseOffset = mousePos - lastMousePos; - - if (Input.GetMouseButton (MouseButtonPan)) { - mouseDownCount ++; - } else { - mouseDownCount = 0; - } - - bool keyHeld = false; - for (int i = 0; i < keyToHold.Length; i++) { - if (Input.GetKey (keyToHold[i])) { - keyHeld = true; - } - } - - if (noHoldKey && keyHeld == false) { - if (mouseDownCount > 1) { - targetPos -= new Vector3 (1, 0, 0) * mouseOffset.x * 0.025f; - targetPos -= new Vector3 (0, 1, 0) * mouseOffset.y * 0.025f; - } - } - - if (fileBrowser) +#region + +using UnityEngine; + +#endregion + +public class CameraPanZoom : MonoBehaviour +{ + private Vector2 _lastMousePos; + + private Vector2 _mousePos; + private float _targetFov; + + private Vector3 _targetPos; + public KeyCode[] KeyToHold; + + public int MouseButtonPan; + + // Use this for initialization + private void Start() + { + _targetPos = transform.position; + } + + // Update is called once per frame + private void Update() + { + if (!MainGui.Instance) return; + _mousePos = Input.mousePosition; + + var mouseOffset = _mousePos - _lastMousePos; + + var keyHeld = false; + + foreach (var t in KeyToHold) { - if (fileBrowser.Active == false) + if (Input.GetKey(t)) { - targetPos += new Vector3(0, 0, 1) * Input.GetAxis("Mouse ScrollWheel") * 3.0f; + keyHeld = true; } } + + var mouseDown = Input.GetMouseButton(MouseButtonPan); + if ((KeyToHold.Length > 0 && keyHeld || KeyToHold.Length == 0) && mouseDown) + { + MainGui.Instance.SaveHideStateAndHideAndLock(this); + + _targetPos -= new Vector3(1, 0, 0) * mouseOffset.x * 0.025f; + _targetPos -= new Vector3(0, 1, 0) * mouseOffset.y * 0.025f; + } else { - targetPos += new Vector3(0, 0, 1) * Input.GetAxis("Mouse ScrollWheel") * 3.0f; + MainGui.Instance.HideGuiLocker.Unlock(this); } + _targetPos += new Vector3(0, 0, 1) * Input.GetAxis("Mouse ScrollWheel") * 3.0f; + + var trf = transform; + var position = trf.position; + position += (_targetPos - position) * 0.05f; + trf.position = position; - this.transform.position += ( targetPos - this.transform.position ) * 0.05f; - - lastMousePos = mousePos; - - } -} + _lastMousePos = _mousePos; + } +} \ No newline at end of file diff --git a/Assets/Scripts/ClipboardHelper.cs b/Assets/Scripts/ClipboardHelper.cs index dd9b09d2..a15cc064 100644 --- a/Assets/Scripts/ClipboardHelper.cs +++ b/Assets/Scripts/ClipboardHelper.cs @@ -1,36 +1,14 @@ -using UnityEngine; -using System; -using System.Reflection; +#region -public class ClipboardHelper -{ - private static PropertyInfo m_systemCopyBufferProperty = null; +using UnityEngine; - private static PropertyInfo GetSystemCopyBufferProperty() - { - if (m_systemCopyBufferProperty == null) - { - Type T = typeof(GUIUtility); - m_systemCopyBufferProperty = T.GetProperty("systemCopyBuffer", BindingFlags.Static | BindingFlags.NonPublic); - if (m_systemCopyBufferProperty == null) - throw new Exception("Can't access internal member 'GUIUtility.systemCopyBuffer' it may have been removed / renamed"); - } - return m_systemCopyBufferProperty; - } +#endregion - public static string clipBoard - { - get - { - //PropertyInfo P = GetSystemCopyBufferProperty(); - //return (string)P.GetValue(null,null); - return GUIUtility.systemCopyBuffer; - } - set - { - //PropertyInfo P = GetSystemCopyBufferProperty(); - //P.SetValue(null,value,null); - GUIUtility.systemCopyBuffer = value; - } - } +public static class ClipboardHelper +{ + public static string ClipBoard + { + get => GUIUtility.systemCopyBuffer; + set => GUIUtility.systemCopyBuffer = value; + } } \ No newline at end of file diff --git a/Assets/Scripts/CommandListExecutor.cs b/Assets/Scripts/CommandListExecutor.cs index ddd1c578..8c805f74 100644 --- a/Assets/Scripts/CommandListExecutor.cs +++ b/Assets/Scripts/CommandListExecutor.cs @@ -1,384 +1,351 @@ -using UnityEngine; +#region + using System; using System.Collections; using System.Collections.Generic; -using System.Reflection; - -using System.Xml; +using System.IO; +using System.Text; using System.Xml.Serialization; - -public struct CommandSettings { - public bool normalMapMaxStyle; - public bool normalMapMayaStyle; - - public bool postProcessEnabled; - - public PropChannelMap propRed; - public PropChannelMap propGreen; - public PropChannelMap propBlue; -} - -public struct CommandOpen { - public string filePath; - public MapType mapType; -} - -public struct CommandSave { - public string filePath; - public MapType mapType; -} - -public struct CommandAOFromNormal { - public string settings; -} - -public struct CommandEdgeFromNormal { - public string settings; -} - -public struct CommandFlipNormalMapY { - //public bool flipNormalMapY; -} - -public struct CommandFileFormat { - public FileFormat fileFormat; -} - -public enum CommandType { - Settings, - Open, - Save, - HeightFromDiffuse, - NormalFromHeight, - Metallic, - Smoothness, - AOFromNormal, - EdgeFromNormal, - QuickSave, - FlipNormalMapY, - FileFormat, - Wait +using UnityEngine; + +#endregion + +public enum CommandType +{ + Settings, + Open, + Save, + HeightFromDiffuse, + NormalFromHeight, + Metallic, + Smoothness, + AoFromNormal, + EdgeFromNormal, + QuickSave, + FlipNormalMapY, + FileFormat } -public struct Command { - - //public string xmlCommand; - public CommandType commandType; - public string extension; - public string filePath; - public MapType mapType; - public string settings; - - public Settings projectSettings; +public struct Command +{ + //public string xmlCommand; + public CommandType CommandType; + public string Extension; + public string FilePath; + public MapType MapType; + public Settings ProjectSettings; } -public class CommandList { - - public List commands; - +public class CommandList +{ + public List Commands; } -public class CommandListExecutor : MonoBehaviour { - - public GameObject mainGuiObject; - MainGui mainGui; - - public GameObject saveLoadProjectObject; - SaveLoadProject saveLoad; - - public GameObject heightFromDiffuseGuiObject; - HeightFromDiffuseGui heightFromDiffuseGui; - - public GameObject normalFromHeightGuiObject; - NormalFromHeightGui normalFromHeightGui; - - public GameObject metallicGuiObject; - MetallicGui metallicGui; - - public GameObject smoothnessGuiObject; - SmoothnessGui smoothnessGui; - - public GameObject aoFromNormalGuiObject; - AOFromNormalGui aoFromNormalGui; - - public GameObject edgeFromNormalGuiObject; - EdgeFromNormalGui edgeFromNormalGui; - - public GameObject materialGuiObject; - MaterialGui materialGui; - - public SettingsGui settingsGui; - - // Use this for initialization - void Start () { - //string[] arguments = Environment.GetCommandLineArgs(); - mainGui = mainGuiObject.GetComponent (); - saveLoad = saveLoadProjectObject.GetComponent (); - - heightFromDiffuseGui = heightFromDiffuseGuiObject.GetComponent (); - normalFromHeightGui = normalFromHeightGuiObject.GetComponent (); - metallicGui = metallicGuiObject.GetComponent (); - smoothnessGui = smoothnessGuiObject.GetComponent (); - aoFromNormalGui = aoFromNormalGuiObject.GetComponent (); - edgeFromNormalGui = edgeFromNormalGuiObject.GetComponent (); - - materialGui = materialGuiObject.GetComponent (); - - StartCoroutine (StartCommandString()); - - } - - /* - int wait = 20; - void Update(){ - wait -= 1; - if (wait == 0) { - SaveTestString (); - } - } - */ - - IEnumerator StartCommandString(){ - yield return new WaitForSeconds (0.1f); - string commandString = ClipboardHelper.clipBoard; - if( commandString.Contains( "" ) ){ - ProcessCommands ( commandString ); - } - } - - public void SaveTestString() { - - CommandList commandList = new CommandList (); - commandList.commands = new List (); - - Command command = new Command(); - command.commandType = CommandType.Settings; - command.projectSettings = settingsGui.settings; - commandList.commands.Add (command); - - command = new Command(); - command.commandType = CommandType.Open; - command.filePath = "F:\\Project_Files\\TextureTools5\\Dev\\Output\\test_diffuse.bmp"; - command.mapType = MapType.diffuseOriginal; - commandList.commands.Add (command); - - command = new Command(); - command.commandType = CommandType.Open; - command.filePath = "F:\\Project_Files\\TextureTools5\\Dev\\Output\\test_normal.bmp"; - command.mapType = MapType.normal; - commandList.commands.Add (command); - - command = new Command(); - command.commandType = CommandType.FlipNormalMapY; - commandList.commands.Add (command); - - command = new Command(); - command.commandType = CommandType.AOFromNormal; - commandList.commands.Add (command); - - command = new Command(); - command.commandType = CommandType.EdgeFromNormal; - commandList.commands.Add (command); - - command = new Command(); - command.commandType = CommandType.FileFormat; - command.extension = "tga"; - commandList.commands.Add (command); - - command = new Command(); - command.commandType = CommandType.QuickSave; - command.filePath = "F:\\Project_Files\\TextureTools5\\Dev\\Output\\test_property.bmp"; - commandList.commands.Add (command); - - - System.Text.StringBuilder sb = new System.Text.StringBuilder(); - var serializer = new XmlSerializer(typeof(CommandList)); - var stream = new System.IO.StringWriter( sb ); - serializer.Serialize(stream, commandList); - ClipboardHelper.clipBoard = stream.ToString (); - - Debug.Log (stream.ToString ()); - } - - void OnApplicationFocus(bool focusStatus) { - if( focusStatus ){ - string commandString = ClipboardHelper.clipBoard; - if( commandString.Contains( "" ) ){ - ProcessCommands ( commandString ); - } - } - } - - public void ProcessCommands () { - string commandString = ClipboardHelper.clipBoard; - if( commandString.Contains( "" ) ){ - StartCoroutine ( ProcessCommandsCoroutine ( commandString ) ); - } - } - - public void ProcessCommands ( string commandString ) { - StartCoroutine ( ProcessCommandsCoroutine ( commandString ) ); - } - - IEnumerator ProcessCommandsCoroutine( string commandString ) { - - //string commandString = ClipboardHelper.clipBoard; - - var serializer = new XmlSerializer(typeof(CommandList)); - var stream = new System.IO.StringReader (commandString); - CommandList commandList = serializer.Deserialize(stream) as CommandList; - - for (int i = 0; i < commandList.commands.Count; i++) { - Command thisCommand = commandList.commands[i]; - if( thisCommand.commandType == CommandType.Settings ){ - settingsGui.settings = thisCommand.projectSettings; - settingsGui.SetSettings (); - }else if( thisCommand.commandType == CommandType.Open ){ - StartCoroutine ( saveLoad.LoadTexture( thisCommand.mapType, thisCommand.filePath ) ); - while( saveLoad.busy ){ yield return new WaitForSeconds (0.1f); } - }else if( thisCommand.commandType == CommandType.Save ){ - switch( thisCommand.mapType ){ - case MapType.height: - StartCoroutine ( saveLoad.SaveTexture( thisCommand.extension, mainGui._HeightMap, thisCommand.filePath ) ); - break; - case MapType.diffuse: - StartCoroutine ( saveLoad.SaveTexture( thisCommand.extension, mainGui._DiffuseMapOriginal, thisCommand.filePath ) ); - break; - case MapType.metallic: - StartCoroutine ( saveLoad.SaveTexture( thisCommand.extension, mainGui._MetallicMap, thisCommand.filePath ) ); - break; - case MapType.smoothness: - StartCoroutine ( saveLoad.SaveTexture( thisCommand.extension, mainGui._SmoothnessMap, thisCommand.filePath ) ); - break; - case MapType.edge: - StartCoroutine ( saveLoad.SaveTexture( thisCommand.extension, mainGui._EdgeMap, thisCommand.filePath ) ); - break; - case MapType.ao: - StartCoroutine ( saveLoad.SaveTexture( thisCommand.extension, mainGui._AOMap, thisCommand.filePath ) ); - break; - case MapType.property: - mainGui.ProcessPropertyMap(); - StartCoroutine ( saveLoad.SaveTexture( thisCommand.extension, mainGui._PropertyMap, thisCommand.filePath ) ); - break; - default: - break; - } - while( saveLoad.busy ){ yield return new WaitForSeconds (0.1f); } - }else if( thisCommand.commandType == CommandType.FlipNormalMapY ){ - mainGui.FlipNormalMapY(); - }else if( thisCommand.commandType == CommandType.FileFormat ){ - mainGui.SetFormat(thisCommand.extension); - }else if( thisCommand.commandType == CommandType.HeightFromDiffuse ){ - mainGui.CloseWindows(); - heightFromDiffuseGuiObject.SetActive(true); - yield return new WaitForSeconds (0.1f); - heightFromDiffuseGui.InitializeTextures(); - yield return new WaitForSeconds (0.1f); - StartCoroutine( heightFromDiffuseGui.ProcessDiffuse() ); - while( heightFromDiffuseGui.busy ){ yield return new WaitForSeconds (0.1f); } - StartCoroutine( heightFromDiffuseGui.ProcessHeight() ); - while( heightFromDiffuseGui.busy ){ yield return new WaitForSeconds (0.1f); } - heightFromDiffuseGui.Close(); - }else if( thisCommand.commandType == CommandType.NormalFromHeight ){ - mainGui.CloseWindows(); - normalFromHeightGuiObject.SetActive(true); - yield return new WaitForSeconds (0.1f); - normalFromHeightGui.InitializeTextures(); - yield return new WaitForSeconds (0.1f); - StartCoroutine( normalFromHeightGui.ProcessHeight() ); - while( normalFromHeightGui.busy ){ yield return new WaitForSeconds (0.1f); } - StartCoroutine( normalFromHeightGui.ProcessNormal() ); - while( normalFromHeightGui.busy ){ yield return new WaitForSeconds (0.1f); } - normalFromHeightGui.Close(); - }else if( thisCommand.commandType == CommandType.Metallic ){ - mainGui.CloseWindows(); - metallicGuiObject.SetActive(true); - yield return new WaitForSeconds (0.1f); - metallicGui.InitializeTextures(); - yield return new WaitForSeconds (0.1f); - StartCoroutine( metallicGui.ProcessBlur() ); - while( metallicGui.busy ){ yield return new WaitForSeconds (0.1f); } - StartCoroutine( metallicGui.ProcessMetallic() ); - while( metallicGui.busy ){ yield return new WaitForSeconds (0.1f); } - metallicGui.Close(); - }else if( thisCommand.commandType == CommandType.Smoothness ){ - mainGui.CloseWindows(); - smoothnessGuiObject.SetActive(true); - yield return new WaitForSeconds (0.1f); - smoothnessGui.InitializeTextures(); - yield return new WaitForSeconds (0.1f); - StartCoroutine( smoothnessGui.ProcessBlur() ); - while( smoothnessGui.busy ){ yield return new WaitForSeconds (0.1f); } - StartCoroutine( smoothnessGui.ProcessSmoothness() ); - while( smoothnessGui.busy ){ yield return new WaitForSeconds (0.1f); } - smoothnessGui.Close(); - }else if( thisCommand.commandType == CommandType.AOFromNormal ){ - mainGui.CloseWindows(); - aoFromNormalGuiObject.SetActive(true); - yield return new WaitForSeconds (0.1f); - aoFromNormalGui.InitializeTextures(); - yield return new WaitForSeconds (0.1f); - StartCoroutine( aoFromNormalGui.ProcessNormalDepth() ); - while( aoFromNormalGui.busy ){ yield return new WaitForSeconds (0.1f); } - StartCoroutine( aoFromNormalGui.ProcessAO() ); - while( aoFromNormalGui.busy ){ yield return new WaitForSeconds (0.1f); } - aoFromNormalGui.Close(); - }else if( thisCommand.commandType == CommandType.EdgeFromNormal ){ - mainGui.CloseWindows(); - edgeFromNormalGuiObject.SetActive(true); - yield return new WaitForSeconds (0.1f); - edgeFromNormalGui.InitializeTextures(); - yield return new WaitForSeconds (0.1f); - StartCoroutine( edgeFromNormalGui.ProcessNormal() ); - while( edgeFromNormalGui.busy ){ yield return new WaitForSeconds (0.1f); } - StartCoroutine( edgeFromNormalGui.ProcessEdge() ); - while( edgeFromNormalGui.busy ){ yield return new WaitForSeconds (0.1f); } - edgeFromNormalGui.Close(); - }else if( thisCommand.commandType == CommandType.QuickSave ){ - - switch( thisCommand.mapType ){ - case MapType.height: - mainGui.QuicksavePathHeight = thisCommand.filePath; - break; - case MapType.diffuse: - mainGui.QuicksavePathDiffuse = thisCommand.filePath; - break; - case MapType.normal: - mainGui.QuicksavePathNormal = thisCommand.filePath; - break; - case MapType.metallic: - mainGui.QuicksavePathMetallic = thisCommand.filePath; - break; - case MapType.smoothness: - mainGui.QuicksavePathSmoothness = thisCommand.filePath; - break; - case MapType.edge: - mainGui.QuicksavePathEdge = thisCommand.filePath; - break; - case MapType.ao: - mainGui.QuicksavePathAO = thisCommand.filePath; - break; - case MapType.property: - mainGui.QuicksavePathProperty = thisCommand.filePath; - break; - default: - break; - } - } - - yield return new WaitForSeconds (0.1f); - - ClipboardHelper.clipBoard = ""; - - } - - yield return new WaitForSeconds (0.1f); - - mainGui.CloseWindows(); - mainGui.FixSize(); - materialGuiObject.SetActive(true); - materialGui.Initialize(); - } - -} +public class CommandListExecutor : MonoBehaviour +{ + private MainGui _mainGui; + private SaveLoadProject _saveLoad; + + public GameObject SaveLoadProjectObject; + + public SettingsGui SettingsGui; + + // Use this for initialization + private void Start() + { + _mainGui = MainGui.Instance.GetComponent(); + _saveLoad = SaveLoadProjectObject.GetComponent(); + + StartCoroutine(StartCommandString()); + } + + private IEnumerator StartCommandString() + { + yield return new WaitForSeconds(0.1f); + var commandString = ClipboardHelper.ClipBoard; + if (commandString.Contains( + "") + ) ProcessCommands(commandString); + } + + public void SaveTestString() + { + var commandList = new CommandList {Commands = new List()}; + + var command = new Command {CommandType = CommandType.Settings, ProjectSettings = SettingsGui.Settings}; + commandList.Commands.Add(command); + + command = new Command + { + CommandType = CommandType.Open, + FilePath = "F:\\Project_Files\\TextureTools5\\Dev\\Output\\test_diffuse.bmp", + MapType = MapType.DiffuseOriginal + }; + commandList.Commands.Add(command); + + command = new Command + { + CommandType = CommandType.Open, + FilePath = "F:\\Project_Files\\TextureTools5\\Dev\\Output\\test_normal.bmp", + MapType = MapType.Normal + }; + commandList.Commands.Add(command); + + command = new Command {CommandType = CommandType.FlipNormalMapY}; + commandList.Commands.Add(command); + + command = new Command {CommandType = CommandType.AoFromNormal}; + commandList.Commands.Add(command); + + command = new Command {CommandType = CommandType.EdgeFromNormal}; + commandList.Commands.Add(command); + + command = new Command {CommandType = CommandType.FileFormat, Extension = "tga"}; + commandList.Commands.Add(command); + + command = new Command + { + CommandType = CommandType.QuickSave, + FilePath = "F:\\Project_Files\\TextureTools5\\Dev\\Output\\test_property.bmp" + }; + commandList.Commands.Add(command); + + + var sb = new StringBuilder(); + var serializer = new XmlSerializer(typeof(CommandList)); + var stream = new StringWriter(sb); + serializer.Serialize(stream, commandList); + ClipboardHelper.ClipBoard = stream.ToString(); + + Debug.Log(stream.ToString()); + } + + private void OnApplicationFocus(bool focusStatus) + { + if (!focusStatus) return; + var commandString = ClipboardHelper.ClipBoard; + if (commandString.Contains( + "") + ) ProcessCommands(commandString); + } + + public void ProcessCommands() + { + var commandString = ClipboardHelper.ClipBoard; + if (commandString.Contains( + "") + ) StartCoroutine(ProcessCommandsCoroutine(commandString)); + } + + public void ProcessCommands(string commandString) + { + StartCoroutine(ProcessCommandsCoroutine(commandString)); + } + + private IEnumerator ProcessCommandsCoroutine(string commandString) + { + //string commandString = ClipboardHelper.clipBoard; + + var serializer = new XmlSerializer(typeof(CommandList)); + var stream = new StringReader(commandString); + + if (serializer.Deserialize(stream) is CommandList commandList) + foreach (var thisCommand in commandList.Commands) + { + switch (thisCommand.CommandType) + { + case CommandType.Settings: + SettingsGui.Settings = thisCommand.ProjectSettings; + SettingsGui.SetSettings(); + break; + case CommandType.Open: + { + StartCoroutine(_saveLoad.LoadTexture(thisCommand.MapType, thisCommand.FilePath)); + while (_saveLoad.Busy) yield return new WaitForSeconds(0.1f); + break; + } + case CommandType.Save: + { + switch (thisCommand.MapType) + { + case MapType.Height: + _saveLoad.SaveTexture(thisCommand.Extension, _mainGui.HeightMap, + thisCommand.FilePath); + break; + case MapType.Diffuse: + _saveLoad.SaveTexture(thisCommand.Extension, _mainGui.DiffuseMapOriginal, + thisCommand.FilePath); + break; + case MapType.Metallic: + _saveLoad.SaveTexture(thisCommand.Extension, _mainGui.MetallicMap, + thisCommand.FilePath); + break; + case MapType.Smoothness: + _saveLoad.SaveTexture(thisCommand.Extension, _mainGui.SmoothnessMap, + thisCommand.FilePath); + break; + case MapType.Edge: + _saveLoad.SaveTexture(thisCommand.Extension, _mainGui.EdgeMap, + thisCommand.FilePath); + break; + case MapType.Ao: + _saveLoad.SaveTexture(thisCommand.Extension, _mainGui.AoMap, thisCommand.FilePath); + break; + case MapType.Property: + _mainGui.ProcessPropertyMap(); + _saveLoad.SaveTexture(thisCommand.Extension, _mainGui.PropertyMap, + thisCommand.FilePath); + break; + case MapType.DiffuseOriginal: + break; + case MapType.Normal: + break; + default: + throw new ArgumentOutOfRangeException(); + } + + while (_saveLoad.Busy) yield return new WaitForSeconds(0.1f); + break; + } + case CommandType.FlipNormalMapY: + _mainGui.FlipNormalMapY(); + break; + case CommandType.FileFormat: + _mainGui.SetFormat(thisCommand.Extension); + break; + case CommandType.HeightFromDiffuse: + { + _mainGui.CloseWindows(); + _mainGui.HeightFromDiffuseGuiObject.SetActive(true); + yield return new WaitForSeconds(0.1f); + _mainGui.HeightFromDiffuseGuiScript.InitializeTextures(); + yield return new WaitForSeconds(0.1f); + StartCoroutine(_mainGui.HeightFromDiffuseGuiScript.ProcessDiffuse()); + while (_mainGui.HeightFromDiffuseGuiScript.Busy) yield return new WaitForSeconds(0.1f); + StartCoroutine(_mainGui.HeightFromDiffuseGuiScript.ProcessHeight()); + while (_mainGui.HeightFromDiffuseGuiScript.Busy) yield return new WaitForSeconds(0.1f); + _mainGui.HeightFromDiffuseGuiScript.Close(); + break; + } + case CommandType.NormalFromHeight: + { + _mainGui.CloseWindows(); + _mainGui.NormalFromHeightGuiObject.SetActive(true); + yield return new WaitForSeconds(0.1f); + _mainGui.NormalFromHeightGuiScript.InitializeTextures(); + yield return new WaitForSeconds(0.1f); + StartCoroutine(_mainGui.NormalFromHeightGuiScript.ProcessHeight()); + while (_mainGui.NormalFromHeightGuiScript.Busy) yield return new WaitForSeconds(0.1f); + StartCoroutine(_mainGui.NormalFromHeightGuiScript.ProcessNormal()); + while (_mainGui.NormalFromHeightGuiScript.Busy) yield return new WaitForSeconds(0.1f); + _mainGui.NormalFromHeightGuiScript.Close(); + break; + } + case CommandType.Metallic: + { + _mainGui.CloseWindows(); + _mainGui.MetallicGuiObject.SetActive(true); + yield return new WaitForSeconds(0.1f); + _mainGui.MetallicGuiScript.InitializeTextures(); + yield return new WaitForSeconds(0.1f); + StartCoroutine(_mainGui.MetallicGuiScript.ProcessBlur()); + while (_mainGui.MetallicGuiScript.Busy) yield return new WaitForSeconds(0.1f); + StartCoroutine(_mainGui.MetallicGuiScript.ProcessMetallic()); + while (_mainGui.MetallicGuiScript.Busy) yield return new WaitForSeconds(0.1f); + _mainGui.MetallicGuiScript.Close(); + break; + } + case CommandType.Smoothness: + { + _mainGui.CloseWindows(); + _mainGui.SmoothnessGuiObject.SetActive(true); + yield return new WaitForSeconds(0.1f); + _mainGui.SmoothnessGuiScript.InitializeTextures(); + yield return new WaitForSeconds(0.1f); + StartCoroutine(_mainGui.SmoothnessGuiScript.ProcessBlur()); + while (_mainGui.SmoothnessGuiScript.Busy) yield return new WaitForSeconds(0.1f); + StartCoroutine(_mainGui.SmoothnessGuiScript.ProcessSmoothness()); + while (_mainGui.SmoothnessGuiScript.Busy) yield return new WaitForSeconds(0.1f); + _mainGui.SmoothnessGuiScript.Close(); + break; + } + case CommandType.AoFromNormal: + { + _mainGui.CloseWindows(); + _mainGui.AoFromNormalGuiObject.SetActive(true); + yield return new WaitForSeconds(0.1f); + _mainGui.AoFromNormalGuiScript.InitializeTextures(); + yield return new WaitForSeconds(0.1f); + StartCoroutine(_mainGui.AoFromNormalGuiScript.ProcessNormalDepth()); + while (_mainGui.AoFromNormalGuiScript.Busy) yield return new WaitForSeconds(0.1f); + StartCoroutine(_mainGui.AoFromNormalGuiScript.ProcessAo()); + while (_mainGui.AoFromNormalGuiScript.Busy) yield return new WaitForSeconds(0.1f); + _mainGui.AoFromNormalGuiScript.Close(); + break; + } + case CommandType.EdgeFromNormal: + { + _mainGui.CloseWindows(); + _mainGui.EdgeFromNormalGuiObject.SetActive(true); + yield return new WaitForSeconds(0.1f); + _mainGui.EdgeFromNormalGuiScript.InitializeTextures(); + yield return new WaitForSeconds(0.1f); + StartCoroutine(_mainGui.EdgeFromNormalGuiScript.ProcessNormal()); + while (_mainGui.EdgeFromNormalGuiScript.Busy) yield return new WaitForSeconds(0.1f); + StartCoroutine(_mainGui.EdgeFromNormalGuiScript.ProcessEdge()); + while (_mainGui.EdgeFromNormalGuiScript.Busy) yield return new WaitForSeconds(0.1f); + _mainGui.EdgeFromNormalGuiScript.Close(); + break; + } + case CommandType.QuickSave: + switch (thisCommand.MapType) + { + case MapType.Height: + _mainGui.QuicksavePathHeight = thisCommand.FilePath; + break; + case MapType.Diffuse: + _mainGui.QuicksavePathDiffuse = thisCommand.FilePath; + break; + case MapType.Normal: + _mainGui.QuicksavePathNormal = thisCommand.FilePath; + break; + case MapType.Metallic: + _mainGui.QuicksavePathMetallic = thisCommand.FilePath; + break; + case MapType.Smoothness: + _mainGui.QuicksavePathSmoothness = thisCommand.FilePath; + break; + case MapType.Edge: + _mainGui.QuicksavePathEdge = thisCommand.FilePath; + break; + case MapType.Ao: + _mainGui.QuicksavePathAo = thisCommand.FilePath; + break; + case MapType.Property: + _mainGui.QuicksavePathProperty = thisCommand.FilePath; + break; + case MapType.DiffuseOriginal: + break; + default: + throw new ArgumentOutOfRangeException(); + } + + break; + default: + throw new ArgumentOutOfRangeException(); + } + + yield return new WaitForSeconds(0.1f); + + ClipboardHelper.ClipBoard = ""; + } + + yield return new WaitForSeconds(0.1f); + + _mainGui.CloseWindows(); + _mainGui.FixSize(); + _mainGui.MaterialGuiObject.SetActive(true); + _mainGui.MaterialGuiScript.Initialize(); + } +} \ No newline at end of file diff --git a/Assets/Scripts/ControlsGui.cs b/Assets/Scripts/ControlsGui.cs index a2e63b52..f9711ebd 100644 --- a/Assets/Scripts/ControlsGui.cs +++ b/Assets/Scripts/ControlsGui.cs @@ -1,75 +1,55 @@ -using UnityEngine; -using System.Collections; +#region -public class ControlsGui : MonoBehaviour { +using UnityEngine; - Rect windowRect = new Rect (Screen.width - 520, Screen.height - 320, 300, 600); - bool windowOpen = false; - public Settings settings = new Settings(); +#endregion - public static SettingsGui instance; +public class ControlsGui : MonoBehaviour +{ + private bool _windowOpen; - // Use this for initialization - void Start () { - - } - - // Update is called once per frame - void Update () { - - } + private Rect _windowRect = new Rect(Screen.width - 520, Screen.height - 320, 300, 600); - void DoMyWindow ( int windowID ) { + private void DoMyWindow(int windowId) + { + const int offsetX = 10; + var offsetY = 30; - int offsetX = 10; - int offsetY = 30; + GUI.Label(new Rect(offsetX, offsetY, 250, 30), "Rotate Model"); + offsetY += 20; + GUI.Label(new Rect(offsetX, offsetY, 250, 30), "Right Mouse Button"); + offsetY += 30; - GUI.Label (new Rect (offsetX, offsetY, 250, 30), "Rotate Model" ); - offsetY += 20; - GUI.Label (new Rect (offsetX, offsetY, 250, 30), "Right Mouse Button" ); - offsetY += 30; + GUI.Label(new Rect(offsetX, offsetY, 250, 30), "Move Model"); + offsetY += 20; + GUI.Label(new Rect(offsetX, offsetY, 250, 30), "Middle Mouse Button"); + offsetY += 30; - GUI.Label (new Rect (offsetX, offsetY, 250, 30), "Move Model" ); - offsetY += 20; - GUI.Label (new Rect (offsetX, offsetY, 250, 30), "Middle Mouse Button" ); - offsetY += 30; + GUI.Label(new Rect(offsetX, offsetY, 250, 30), "Zoom In/Out"); + offsetY += 20; + GUI.Label(new Rect(offsetX, offsetY, 250, 30), "Mouse Scroll Wheel"); + offsetY += 30; - GUI.Label (new Rect (offsetX, offsetY, 250, 30), "Zoom In/Out" ); - offsetY += 20; - GUI.Label (new Rect (offsetX, offsetY, 250, 30), "Mouse Scroll Wheel" ); - offsetY += 30; + GUI.Label(new Rect(offsetX, offsetY, 250, 30), "Rotate Light"); + offsetY += 20; + GUI.Label(new Rect(offsetX, offsetY, 250, 30), "Middle Mouse Button + L"); + offsetY += 30; - GUI.Label (new Rect (offsetX, offsetY, 250, 30), "Rotate Light" ); - offsetY += 20; - GUI.Label (new Rect (offsetX, offsetY, 250, 30), "Middle Mouse Button + L" ); - offsetY += 30; + GUI.Label(new Rect(offsetX, offsetY, 250, 30), "Rotate Background"); + offsetY += 20; + GUI.Label(new Rect(offsetX, offsetY, 250, 30), "Middle Mouse Button + B"); + offsetY += 30; - GUI.Label (new Rect (offsetX, offsetY, 250, 30), "Rotate Background" ); - offsetY += 20; - GUI.Label (new Rect (offsetX, offsetY, 250, 30), "Middle Mouse Button + B" ); - offsetY += 30; + if (GUI.Button(new Rect(offsetX + 160, offsetY, 120, 30), "Close")) _windowOpen = false; + } + + private void OnGUI() + { + //_windowRect = new Rect(Screen.width - 480, Screen.height - 370, 170, 280); - if (GUI.Button (new Rect (offsetX + 160, offsetY, 120, 30), "Close")) { - windowOpen = false; - } + GUI.Window(22, _windowRect, DoMyWindow, "Controls"); - } - - void OnGUI () { - - windowRect = new Rect (Screen.width - 480, Screen.height - 370, 170, 280); - - if (windowOpen){ - windowRect = GUI.Window (22, windowRect, DoMyWindow, "Controls"); - } - - if (GUI.Button (new Rect(Screen.width - 370, Screen.height - 40, 80, 30), "Controls")) { - if( windowOpen == true){ - windowOpen = false; - }else{ - windowOpen = true; - } - } - - } -} + //if (!GUI.Button(new Rect(Screen.width - 370, Screen.height - 40, 80, 30), "Controls")) return; + //_windowOpen = !_windowOpen; + } +} \ No newline at end of file diff --git a/Assets/Scripts/CopyScale.cs b/Assets/Scripts/CopyScale.cs index 621a6870..ecd0df97 100644 --- a/Assets/Scripts/CopyScale.cs +++ b/Assets/Scripts/CopyScale.cs @@ -1,27 +1,34 @@ -using UnityEngine; -using System.Collections; +#region -public class CopyScale : MonoBehaviour { +using UnityEngine; - public GameObject targetObject; +#endregion - // Use this for initialization - void Start () { - - } - - // Update is called once per frame - void Update () { - Vector3 tempScale = targetObject.transform.localScale; - Material targetMaterial = targetObject.GetComponent ().sharedMaterial; +public class CopyScale : MonoBehaviour +{ + private static readonly int Parallax = Shader.PropertyToID("_Parallax"); + private static readonly int Tiling1 = Shader.PropertyToID("_Tiling"); + private Renderer _renderer; + public GameObject TargetObject; - if ( targetMaterial.HasProperty( "_Parallax" ) ) { - float Height = targetMaterial.GetFloat ("_Parallax"); - Vector4 Tiling = targetMaterial.GetVector ("_Tiling"); + private void Start() + { + _renderer = TargetObject.GetComponent(); + } - tempScale.z += Height * ( 1.0f / Tiling.x ); - } + private void Update() + { + var tempScale = TargetObject.transform.localScale; + var targetMaterial = _renderer.sharedMaterial; - this.transform.localScale = tempScale; - } -} + if (targetMaterial.HasProperty("_Parallax")) + { + var height = targetMaterial.GetFloat(Parallax); + var tiling = targetMaterial.GetVector(Tiling1); + + tempScale.z += height * (1.0f / tiling.x); + } + + transform.localScale = tempScale; + } +} \ No newline at end of file diff --git a/Assets/Scripts/CountLocker.cs b/Assets/Scripts/CountLocker.cs new file mode 100644 index 00000000..b4990df4 --- /dev/null +++ b/Assets/Scripts/CountLocker.cs @@ -0,0 +1,48 @@ +#region + +using System; +using System.Collections.Generic; + +#endregion + +public class CountLocker +{ + private readonly List _lockCallers = new List(); + public bool IsLocked; + + public void Lock(object sender) + { + if (_lockCallers.Contains(sender)) return; + _lockCallers.Add(sender); + + if (IsLocked) return; + IsLocked = true; + OnLock(); + } + + public void Unlock(object sender) + { + if (!_lockCallers.Contains(sender)) return; + _lockCallers.Remove(sender); + + if (_lockCallers.Count != 0) return; + + IsLocked = false; + OnLockEmpty(); + } + + public event EventHandler LockEmpty; + + // ReSharper disable once EventNeverSubscribedTo.Global + public event EventHandler Locked; + + private void OnLockEmpty() + { + LockEmpty?.Invoke(this, EventArgs.Empty); + } + + private void OnLock() + { + Locked?.Invoke(this, EventArgs.Empty); + } +} \ No newline at end of file diff --git a/Assets/Scripts/CountLocker.cs.meta b/Assets/Scripts/CountLocker.cs.meta new file mode 100644 index 00000000..b164c48b --- /dev/null +++ b/Assets/Scripts/CountLocker.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 1d5c5ca165c4456798494bcb6adc2cf1 +timeCreated: 1549040608 \ No newline at end of file diff --git a/Assets/Scripts/CubemapPicker.cs b/Assets/Scripts/CubemapPicker.cs index 9978f286..f26ceba0 100644 --- a/Assets/Scripts/CubemapPicker.cs +++ b/Assets/Scripts/CubemapPicker.cs @@ -1,32 +1,24 @@ -using UnityEngine; -using System.Collections; -using System.Collections.Generic; +#region -public class CubemapPicker : MonoBehaviour { - - public Cubemap[] CubeMaps; - int selectedCubemap = 0; - public KeyCode key; +using UnityEngine; +#endregion - // Use this for initialization - void Start () { - - } - - // Update is called once per frame - void Update () { +public class CubemapPicker : MonoBehaviour +{ + private static readonly int GlobalCubemap = Shader.PropertyToID("_GlobalCubemap"); + private int _selectedCubemap; + public Cubemap[] CubeMaps; + public KeyCode Key; - if (Input.GetKeyDown(key)) + private void Update() + { + if (Input.GetKeyDown(Key)) { - selectedCubemap += 1; - if (selectedCubemap >= CubeMaps.Length) - { - selectedCubemap = 0; - } + _selectedCubemap += 1; + if (_selectedCubemap >= CubeMaps.Length) _selectedCubemap = 0; } - Shader.SetGlobalTexture("_GlobalCubemap", CubeMaps[selectedCubemap]); - + Shader.SetGlobalTexture(GlobalCubemap, CubeMaps[_selectedCubemap]); } -} +} \ No newline at end of file diff --git a/Assets/Scripts/EdgeFromNormalGui.cs b/Assets/Scripts/EdgeFromNormalGui.cs index 0adb853b..d71e15c8 100644 --- a/Assets/Scripts/EdgeFromNormalGui.cs +++ b/Assets/Scripts/EdgeFromNormalGui.cs @@ -1,583 +1,541 @@ -using UnityEngine; +#region + using System.Collections; -using System.ComponentModel; - -public class EdgeSettings { - - [DefaultValueAttribute(1.0)] - public float Blur0Contrast; - [DefaultValueAttribute("1")] - public string Blur0ContrastText; - - [DefaultValueAttribute(1.0f)] - public float Blur0Weight; - [DefaultValueAttribute(0.5f)] - public float Blur1Weight; - [DefaultValueAttribute(0.3f)] - public float Blur2Weight; - [DefaultValueAttribute(0.5f)] - public float Blur3Weight; - [DefaultValueAttribute(0.7f)] - public float Blur4Weight; - [DefaultValueAttribute(0.7f)] - public float Blur5Weight; - [DefaultValueAttribute(0.3f)] - public float Blur6Weight; - - [DefaultValueAttribute(1.0f)] - public float FinalContrast; - [DefaultValueAttribute("1")] - public string FinalContrastText; - - [DefaultValueAttribute(0.0f)] - public float FinalBias; - [DefaultValueAttribute("0")] - public string FinalBiasText; - - [DefaultValueAttribute(1.0f)] - public float EdgeAmount; - [DefaultValueAttribute("1")] - public string EdgeAmountText; - - [DefaultValueAttribute(1.0f)] - public float CreviceAmount; - [DefaultValueAttribute("1")] - public string CreviceAmountText; - - [DefaultValueAttribute(1.0f)] - public float Pinch; - [DefaultValueAttribute("1")] - public string PinchText; - - [DefaultValueAttribute(1.0f)] - public float Pillow; - [DefaultValueAttribute("1")] - public string PillowText; - - public EdgeSettings(){ - - this.Blur0Contrast = 1.0f; - this.Blur0ContrastText = "1"; - - this.Blur0Weight = 1.0f; - this.Blur1Weight = 0.5f; - this.Blur2Weight = 0.3f; - this.Blur3Weight = 0.5f; - this.Blur4Weight = 0.7f; - this.Blur5Weight = 0.7f; - this.Blur6Weight = 0.3f; - - this.FinalContrast = 1.0f; - this.FinalContrastText = "1"; - - this.FinalBias = 0.0f; - this.FinalBiasText = "0"; - - this.EdgeAmount = 1.0f; - this.EdgeAmountText = "1"; - - this.CreviceAmount = 1.0f; - this.CreviceAmountText = "1"; - - this.Pinch = 1.0f; - this.PinchText = "1"; - - this.Pillow = 1.0f; - this.PillowText = "1"; - } - -} - -public class EdgeFromNormalGui : MonoBehaviour { - - public MainGui MainGuiScript; - - Texture2D _EdgeMap; - Texture2D _NormalMap; - RenderTexture _TempBlurMap; - RenderTexture _BlurMap0; - RenderTexture _BlurMap1; - RenderTexture _BlurMap2; - RenderTexture _BlurMap3; - RenderTexture _BlurMap4; - RenderTexture _BlurMap5; - RenderTexture _BlurMap6; - RenderTexture _TempEdgeMap; - - int imageSizeX = 1024; - int imageSizeY = 1024; - - EdgeSettings ES; - - public Material thisMaterial; - Material blitMaterial; - - public GameObject testObject; - bool doStuff = false; - bool newTexture = false; - - Rect windowRect = new Rect (30, 300, 300, 600); - - bool settingsInitialized = false; - - public bool busy = false; - - public void GetValues( ProjectObject projectObject ) { - InitializeSettings (); - projectObject.ES = ES; - } - - public void SetValues( ProjectObject projectObject ) { - InitializeSettings (); - if (projectObject.ES != null) { - ES = projectObject.ES; - } else { - settingsInitialized = false; - InitializeSettings (); - } - doStuff = true; - } - - void InitializeSettings() { - - if (settingsInitialized == false) { - Debug.Log ("Initializing Edge Settings"); - ES = new EdgeSettings (); - settingsInitialized = true; - } - - } - - // Use this for initialization - void Start () { - - testObject.GetComponent().sharedMaterial = thisMaterial; - - blitMaterial = new Material (Shader.Find ("Hidden/Blit_Shader")); - - InitializeSettings (); - - } - - public void DoStuff() { - doStuff = true; - } - - public void NewTexture() { - newTexture = true; - } - - - // Update is called once per frame - void Update () { - - if (newTexture) { - InitializeTextures(); - newTexture = false; - } - - if (doStuff) { - StartCoroutine( ProcessNormal () ); - doStuff = false; - } - - thisMaterial.SetFloat ("_Blur0Weight", ES.Blur0Weight * ES.Blur0Weight * ES.Blur0Weight); - thisMaterial.SetFloat ("_Blur1Weight", ES.Blur1Weight * ES.Blur1Weight * ES.Blur1Weight); - thisMaterial.SetFloat ("_Blur2Weight", ES.Blur2Weight * ES.Blur2Weight * ES.Blur2Weight); - thisMaterial.SetFloat ("_Blur3Weight", ES.Blur3Weight * ES.Blur3Weight * ES.Blur3Weight); - thisMaterial.SetFloat ("_Blur4Weight", ES.Blur4Weight * ES.Blur4Weight * ES.Blur4Weight); - thisMaterial.SetFloat ("_Blur5Weight", ES.Blur5Weight * ES.Blur5Weight * ES.Blur5Weight); - thisMaterial.SetFloat ("_Blur6Weight", ES.Blur6Weight * ES.Blur6Weight * ES.Blur6Weight); - thisMaterial.SetFloat ("_EdgeAmount", ES.EdgeAmount); - thisMaterial.SetFloat ("_CreviceAmount", ES.CreviceAmount); - thisMaterial.SetFloat ("_Pinch", ES.Pinch); - thisMaterial.SetFloat ("_Pillow", ES.Pillow); - thisMaterial.SetFloat ("_FinalContrast", ES.FinalContrast); - thisMaterial.SetFloat ("_FinalBias", ES.FinalBias); - - - } - - void SetDefaultSliderValues() { - - ES.Blur0Contrast = 1.0f; - ES.Blur0ContrastText = "1"; - - ES.EdgeAmount = 1.0f; - ES.EdgeAmountText = "1"; - - ES.CreviceAmount = 1.0f; - ES.CreviceAmountText = "1"; - - ES.Pinch = 1.0f; - ES.PinchText = "1"; - - ES.Pillow = 1.0f; - ES.PillowText = "1"; - - ES.FinalContrast = 2.0f; - ES.FinalContrastText = "2"; - - ES.FinalBias = 0.0f; - ES.FinalBiasText = "0"; - - } - - void SetWeightEQDefault() { - ES.Blur0Weight = 1.0f; - ES.Blur1Weight = 0.5f; - ES.Blur2Weight = 0.3f; - ES.Blur3Weight = 0.5f; - ES.Blur4Weight = 0.7f; - ES.Blur5Weight = 0.7f; - ES.Blur6Weight = 0.3f; - - SetDefaultSliderValues (); - - doStuff = true; - } - - void SetWeightEQDisplace() { - ES.Blur0Weight = 0.1f; - ES.Blur1Weight = 0.15f; - ES.Blur2Weight = 0.25f; - ES.Blur3Weight = 0.45f; - ES.Blur4Weight = 0.75f; - ES.Blur5Weight = 0.95f; - ES.Blur6Weight = 1.0f; - - SetDefaultSliderValues (); - - ES.Blur0Contrast = 3.0f; - ES.Blur0ContrastText = "3"; - - ES.FinalContrast = 5.0f; - ES.FinalContrastText = "5"; - - ES.FinalBias = -0.2f; - ES.FinalBiasText = "-0.2"; - - doStuff = true; - } - - void SetWeightEQSoft() { - ES.Blur0Weight = 0.15f; - ES.Blur1Weight = 0.4f; - ES.Blur2Weight = 0.7f; - ES.Blur3Weight = 0.9f; - ES.Blur4Weight = 1.0f; - ES.Blur5Weight = 0.9f; - ES.Blur6Weight = 0.7f; - - SetDefaultSliderValues (); - - ES.FinalContrast = 4.0f; - ES.FinalContrastText = "4"; - - doStuff = true; - } - - void SetWeightEQTight() { - ES.Blur0Weight = 1.0f; - ES.Blur1Weight = 0.45f; - ES.Blur2Weight = 0.25f; - ES.Blur3Weight = 0.18f; - ES.Blur4Weight = 0.15f; - ES.Blur5Weight = 0.13f; - ES.Blur6Weight = 0.1f; - - SetDefaultSliderValues (); - - ES.Pinch = 1.5f; - ES.PinchText = "1.5"; - - doStuff = true; - } - - void DoMyWindow ( int windowID ) { - - int spacingX = 0; - int spacingY = 50; - - int offsetX = 10; - int offsetY = 30; - - doStuff = GuiHelper.Slider( new Rect( offsetX, offsetY, 280, 50 ), "Pre Contrast", ES.Blur0Contrast, ES.Blur0ContrastText, out ES.Blur0Contrast, out ES.Blur0ContrastText, 0.0f, 5.0f ); - offsetY += 50; - - GUI.Label (new Rect (offsetX, offsetY, 250, 30), "Frequency Equalizer" ); - GUI.Label (new Rect (offsetX + 225, offsetY, 100, 30), "Presets" ); - if ( GUI.Button (new Rect (offsetX + 215, offsetY + 30, 60, 20), "Default") ) { - SetWeightEQDefault (); - } - if ( GUI.Button (new Rect (offsetX + 215, offsetY + 60, 60, 20), "Displace") ) { - SetWeightEQDisplace (); - } - if ( GUI.Button (new Rect (offsetX + 215, offsetY + 90, 60, 20), "Soft") ) { - SetWeightEQSoft (); - } - if ( GUI.Button (new Rect (offsetX + 215, offsetY + 120, 60, 20), "Tight") ) { - SetWeightEQTight (); - } - offsetY += 30; - offsetX += 10; - ES.Blur0Weight = GUI.VerticalSlider( new Rect( offsetX + 180, offsetY, 10, 100 ),ES.Blur0Weight,1.0f, 0.0f ); - ES.Blur1Weight = GUI.VerticalSlider( new Rect( offsetX + 150, offsetY, 10, 100 ),ES.Blur1Weight,1.0f, 0.0f ); - ES.Blur2Weight = GUI.VerticalSlider( new Rect( offsetX + 120, offsetY, 10, 100 ),ES.Blur2Weight,1.0f, 0.0f ); - ES.Blur3Weight = GUI.VerticalSlider( new Rect( offsetX + 90, offsetY, 10, 100 ),ES.Blur3Weight,1.0f, 0.0f ); - ES.Blur4Weight = GUI.VerticalSlider( new Rect( offsetX + 60, offsetY, 10, 100 ),ES.Blur4Weight,1.0f, 0.0f ); - ES.Blur5Weight = GUI.VerticalSlider( new Rect( offsetX + 30, offsetY, 10, 100 ),ES.Blur5Weight,1.0f, 0.0f ); - ES.Blur6Weight = GUI.VerticalSlider( new Rect( offsetX + 0, offsetY, 10, 100 ),ES.Blur6Weight,1.0f, 0.0f ); - offsetX -= 10; - offsetY += 120; - - GuiHelper.Slider( new Rect( offsetX, offsetY, 280, 50 ), "Edge Amount", ES.EdgeAmount, ES.EdgeAmountText, out ES.EdgeAmount, out ES.EdgeAmountText, 0.0f, 1.0f ); - offsetY += 40; - - GuiHelper.Slider( new Rect( offsetX, offsetY, 280, 50 ), "Crevice Amount", ES.CreviceAmount, ES.CreviceAmountText, out ES.CreviceAmount, out ES.CreviceAmountText, 0.0f, 1.0f ); - offsetY += 40; - - GuiHelper.Slider( new Rect( offsetX, offsetY, 280, 50 ), "Pinch", ES.Pinch, ES.PinchText, out ES.Pinch, out ES.PinchText, 0.1f, 10.0f ); - offsetY += 40; - - GuiHelper.Slider( new Rect( offsetX, offsetY, 280, 50 ), "Pillow", ES.Pillow, ES.PillowText, out ES.Pillow, out ES.PillowText, 0.1f, 5.0f ); - offsetY += 40; - - GuiHelper.Slider( new Rect( offsetX, offsetY, 280, 50 ), "Final Contrast", ES.FinalContrast, ES.FinalContrastText, out ES.FinalContrast, out ES.FinalContrastText, 0.1f, 30.0f ); - offsetY += 40; - - GuiHelper.Slider( new Rect( offsetX, offsetY, 280, 50 ), "Final Bias", ES.FinalBias, ES.FinalBiasText, out ES.FinalBias, out ES.FinalBiasText, -1.0f, 1.0f ); - offsetY += 50; - - - if( GUI.Button (new Rect (offsetX + 150, offsetY, 130, 30), "Set as Edge Map" ) ){ - StartCoroutine( ProcessEdge() ); - } - - GUI.DragWindow(); - } - - void OnGUI () { - - windowRect.width = 300; - windowRect.height = 520; - - windowRect = GUI.Window(11, windowRect, DoMyWindow, "Edge from Normal"); - - } - - public void InitializeTextures() { - - testObject.GetComponent().sharedMaterial = thisMaterial; - - CleanupTextures (); - - _NormalMap = MainGuiScript._NormalMap; - - imageSizeX = _NormalMap.width; - imageSizeY = _NormalMap.height; - - Debug.Log ( "Initializing Textures of size: " + imageSizeX.ToString() + "x" + imageSizeY.ToString() ); - - _TempBlurMap = new RenderTexture (imageSizeX, imageSizeY, 0, RenderTextureFormat.RHalf, RenderTextureReadWrite.Linear); - _TempBlurMap.wrapMode = TextureWrapMode.Repeat; - _BlurMap0 = new RenderTexture (imageSizeX, imageSizeY, 0, RenderTextureFormat.RHalf, RenderTextureReadWrite.Linear); - _BlurMap0.wrapMode = TextureWrapMode.Repeat; - _BlurMap1 = new RenderTexture (imageSizeX, imageSizeY, 0, RenderTextureFormat.RHalf, RenderTextureReadWrite.Linear); - _BlurMap1.wrapMode = TextureWrapMode.Repeat; - _BlurMap2 = new RenderTexture (imageSizeX, imageSizeY, 0, RenderTextureFormat.RHalf, RenderTextureReadWrite.Linear); - _BlurMap2.wrapMode = TextureWrapMode.Repeat; - _BlurMap3 = new RenderTexture (imageSizeX, imageSizeY, 0, RenderTextureFormat.RHalf, RenderTextureReadWrite.Linear); - _BlurMap3.wrapMode = TextureWrapMode.Repeat; - _BlurMap4 = new RenderTexture (imageSizeX, imageSizeY, 0, RenderTextureFormat.RHalf, RenderTextureReadWrite.Linear); - _BlurMap4.wrapMode = TextureWrapMode.Repeat; - _BlurMap5 = new RenderTexture (imageSizeX, imageSizeY, 0, RenderTextureFormat.RHalf, RenderTextureReadWrite.Linear); - _BlurMap5.wrapMode = TextureWrapMode.Repeat; - _BlurMap6 = new RenderTexture (imageSizeX, imageSizeY, 0, RenderTextureFormat.RHalf, RenderTextureReadWrite.Linear); - _BlurMap6.wrapMode = TextureWrapMode.Repeat; - - } - - public void Close(){ - CleanupTextures (); - this.gameObject.SetActive (false); - } - - void CleanupTexture( RenderTexture _Texture ) { - - if (_Texture != null) { - _Texture.Release(); - _Texture = null; - } - } - - void CleanupTextures() { - - Debug.Log ("Cleaning Up Textures"); - - CleanupTexture (_TempBlurMap); - CleanupTexture( _BlurMap0 ); - CleanupTexture( _BlurMap1 ); - CleanupTexture( _BlurMap2 ); - CleanupTexture( _BlurMap3 ); - CleanupTexture( _BlurMap4 ); - CleanupTexture( _BlurMap5 ); - CleanupTexture( _BlurMap6 ); - CleanupTexture (_TempEdgeMap); - - } - - public IEnumerator ProcessEdge() { - - busy = true; - - Debug.Log ("Processing Height / Edge"); - - blitMaterial.SetVector ("_ImageSize", new Vector4( imageSizeX, imageSizeY, 0, 0 )); - - blitMaterial.SetFloat ("_Blur0Weight", ES.Blur0Weight * ES.Blur0Weight * ES.Blur0Weight); - blitMaterial.SetFloat ("_Blur1Weight", ES.Blur1Weight * ES.Blur1Weight * ES.Blur1Weight); - blitMaterial.SetFloat ("_Blur2Weight", ES.Blur2Weight * ES.Blur2Weight * ES.Blur2Weight); - blitMaterial.SetFloat ("_Blur3Weight", ES.Blur3Weight * ES.Blur3Weight * ES.Blur3Weight); - blitMaterial.SetFloat ("_Blur4Weight", ES.Blur4Weight * ES.Blur4Weight * ES.Blur4Weight); - blitMaterial.SetFloat ("_Blur5Weight", ES.Blur5Weight * ES.Blur5Weight * ES.Blur5Weight); - blitMaterial.SetFloat ("_Blur6Weight", ES.Blur6Weight * ES.Blur6Weight * ES.Blur6Weight); - blitMaterial.SetFloat ("_EdgeAmount", ES.EdgeAmount); - blitMaterial.SetFloat ("_CreviceAmount", ES.CreviceAmount); - blitMaterial.SetFloat ("_Pinch", ES.Pinch); - blitMaterial.SetFloat ("_Pillow", ES.Pillow); - blitMaterial.SetFloat ("_FinalContrast", ES.FinalContrast); - blitMaterial.SetFloat ("_FinalBias", ES.FinalBias); - - blitMaterial.SetTexture ("_MainTex", _NormalMap); - blitMaterial.SetTexture ("_BlurTex0", _BlurMap0); - blitMaterial.SetTexture ("_BlurTex1", _BlurMap1); - blitMaterial.SetTexture ("_BlurTex2", _BlurMap2); - blitMaterial.SetTexture ("_BlurTex3", _BlurMap3); - blitMaterial.SetTexture ("_BlurTex4", _BlurMap4); - blitMaterial.SetTexture ("_BlurTex5", _BlurMap5); - blitMaterial.SetTexture ("_BlurTex6", _BlurMap6); - - // Save low fidelity for texture 2d - - CleanupTexture (_TempEdgeMap); - _TempEdgeMap = new RenderTexture (imageSizeX, imageSizeY, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear); - _TempEdgeMap.wrapMode = TextureWrapMode.Repeat; - Graphics.Blit(_BlurMap0, _TempEdgeMap, blitMaterial, 6); - - RenderTexture.active = _TempEdgeMap; - - if (MainGuiScript._EdgeMap != null) { - Destroy (MainGuiScript._EdgeMap); - } - - MainGuiScript._EdgeMap = new Texture2D (_TempEdgeMap.width, _TempEdgeMap.height, TextureFormat.ARGB32, true, true); - MainGuiScript._EdgeMap.ReadPixels (new Rect (0, 0, _TempEdgeMap.width, _TempEdgeMap.height), 0, 0); - MainGuiScript._EdgeMap.Apply (); - - yield return new WaitForSeconds(0.1f); - - CleanupTexture (_TempEdgeMap); - - busy = false; - - } - - public IEnumerator ProcessNormal () { - - busy = true; - - Debug.Log ("Processing Normal to Edge"); - - blitMaterial.SetVector ("_ImageSize", new Vector4( imageSizeX, imageSizeY, 0, 0 )); - - // Make normal from height - blitMaterial.SetFloat ("_BlurContrast", ES.Blur0Contrast); - blitMaterial.SetTexture ("_MainTex", _NormalMap); - Graphics.Blit(_NormalMap, _BlurMap0, blitMaterial, 5); - - blitMaterial.SetFloat ("_BlurContrast", 1.0f); - - // Blur the image 1 - blitMaterial.SetTexture ("_MainTex", _BlurMap0); - blitMaterial.SetInt ("_BlurSamples", 4); - blitMaterial.SetFloat ("_BlurSpread", 1.0f); - blitMaterial.SetVector ("_BlurDirection", new Vector4(1,0,0,0) ); - Graphics.Blit(_BlurMap0, _TempBlurMap, blitMaterial, 1); - - blitMaterial.SetTexture ("_MainTex", _TempBlurMap); - blitMaterial.SetVector ("_BlurDirection", new Vector4(0,1,0,0) ); - Graphics.Blit(_TempBlurMap, _BlurMap1, blitMaterial, 1); - - - // Blur the image 2 - blitMaterial.SetTexture ("_MainTex", _BlurMap1); - blitMaterial.SetFloat ("_BlurSpread", 2.0f); - blitMaterial.SetVector ("_BlurDirection", new Vector4(1,0,0,0) ); - Graphics.Blit(_BlurMap1, _TempBlurMap, blitMaterial, 1); - - blitMaterial.SetTexture ("_MainTex", _TempBlurMap); - blitMaterial.SetVector ("_BlurDirection", new Vector4(0,1,0,0) ); - Graphics.Blit(_TempBlurMap, _BlurMap2, blitMaterial, 1); - - - // Blur the image 3 - blitMaterial.SetTexture ("_MainTex", _BlurMap2); - blitMaterial.SetFloat ("_BlurSpread", 4.0f); - blitMaterial.SetVector ("_BlurDirection", new Vector4(1,0,0,0) ); - Graphics.Blit(_BlurMap2, _TempBlurMap, blitMaterial, 1); - - blitMaterial.SetTexture ("_MainTex", _TempBlurMap); - blitMaterial.SetVector ("_BlurDirection", new Vector4(0,1,0,0) ); - Graphics.Blit(_TempBlurMap, _BlurMap3, blitMaterial, 1); - - - // Blur the image 4 - blitMaterial.SetTexture ("_MainTex", _BlurMap3); - blitMaterial.SetFloat ("_BlurSpread", 8.0f); - blitMaterial.SetVector ("_BlurDirection", new Vector4(1,0,0,0) ); - Graphics.Blit(_BlurMap3, _TempBlurMap, blitMaterial, 1); - - blitMaterial.SetTexture ("_MainTex", _TempBlurMap); - blitMaterial.SetVector ("_BlurDirection", new Vector4(0,1,0,0) ); - Graphics.Blit(_TempBlurMap, _BlurMap4, blitMaterial, 1); - - - // Blur the image 5 - blitMaterial.SetTexture ("_MainTex", _BlurMap4); - blitMaterial.SetFloat ("_BlurSpread", 16.0f); - blitMaterial.SetVector ("_BlurDirection", new Vector4(1,0,0,0) ); - Graphics.Blit(_BlurMap4, _TempBlurMap, blitMaterial, 1); - - blitMaterial.SetTexture ("_MainTex", _TempBlurMap); - blitMaterial.SetVector ("_BlurDirection", new Vector4(0,1,0,0) ); - Graphics.Blit(_TempBlurMap, _BlurMap5, blitMaterial, 1); - - - // Blur the image 6 - blitMaterial.SetTexture ("_MainTex", _BlurMap5); - blitMaterial.SetFloat ("_BlurSpread", 32.0f); - blitMaterial.SetVector ("_BlurDirection", new Vector4(1,0,0,0) ); - Graphics.Blit(_BlurMap5, _TempBlurMap, blitMaterial, 1); - - blitMaterial.SetTexture ("_MainTex", _TempBlurMap); - blitMaterial.SetVector ("_BlurDirection", new Vector4(0,1,0,0) ); - Graphics.Blit(_TempBlurMap, _BlurMap6, blitMaterial, 1); - - - thisMaterial.SetTexture ("_MainTex", _BlurMap0); - thisMaterial.SetTexture ("_BlurTex0", _BlurMap0); - thisMaterial.SetTexture ("_BlurTex1", _BlurMap1); - thisMaterial.SetTexture ("_BlurTex2", _BlurMap2); - thisMaterial.SetTexture ("_BlurTex3", _BlurMap3); - thisMaterial.SetTexture ("_BlurTex4", _BlurMap4); - thisMaterial.SetTexture ("_BlurTex5", _BlurMap5); - thisMaterial.SetTexture ("_BlurTex6", _BlurMap6); - - yield return new WaitForSeconds(0.1f); - - busy = false; - - } - -} +using UnityEngine; + +#endregion + +public class EdgeFromNormalGui : MonoBehaviour +{ + private static readonly int Blur0Weight = Shader.PropertyToID("_Blur0Weight"); + private static readonly int Blur1Weight = Shader.PropertyToID("_Blur1Weight"); + private static readonly int Blur2Weight = Shader.PropertyToID("_Blur2Weight"); + private static readonly int Blur3Weight = Shader.PropertyToID("_Blur3Weight"); + private static readonly int Blur4Weight = Shader.PropertyToID("_Blur4Weight"); + private static readonly int Blur5Weight = Shader.PropertyToID("_Blur5Weight"); + private static readonly int Blur6Weight = Shader.PropertyToID("_Blur6Weight"); + private static readonly int EdgeAmount = Shader.PropertyToID("_EdgeAmount"); + private static readonly int CreviceAmount = Shader.PropertyToID("_CreviceAmount"); + private static readonly int Pinch = Shader.PropertyToID("_Pinch"); + private static readonly int Pillow = Shader.PropertyToID("_Pillow"); + private static readonly int FinalContrast = Shader.PropertyToID("_FinalContrast"); + private static readonly int FinalBias = Shader.PropertyToID("_FinalBias"); + private static readonly int ImageSize = Shader.PropertyToID("_ImageSize"); + private static readonly int MainTex = Shader.PropertyToID("_MainTex"); + private static readonly int BlurTex0 = Shader.PropertyToID("_BlurTex0"); + private static readonly int BlurTex1 = Shader.PropertyToID("_BlurTex1"); + private static readonly int BlurTex2 = Shader.PropertyToID("_BlurTex2"); + private static readonly int BlurTex3 = Shader.PropertyToID("_BlurTex3"); + private static readonly int BlurTex4 = Shader.PropertyToID("_BlurTex4"); + private static readonly int BlurTex5 = Shader.PropertyToID("_BlurTex5"); + private static readonly int BlurTex6 = Shader.PropertyToID("_BlurTex6"); + private static readonly int BlurContrast = Shader.PropertyToID("_BlurContrast"); + private static readonly int BlurSamples = Shader.PropertyToID("_BlurSamples"); + private static readonly int BlurSpread = Shader.PropertyToID("_BlurSpread"); + private static readonly int BlurDirection = Shader.PropertyToID("_BlurDirection"); + private Material _blitMaterial; + private RenderTexture _blurMap0; + private RenderTexture _blurMap1; + private RenderTexture _blurMap2; + private RenderTexture _blurMap3; + private RenderTexture _blurMap4; + private RenderTexture _blurMap5; + private RenderTexture _blurMap6; + private bool _doStuff = true; + + private Texture2D _edgeMap; + + private int _imageSizeX = 1024; + private int _imageSizeY = 1024; + private bool _newTexture; + private Texture2D _normalMap; + + private EdgeSettings _settings; + + private bool _settingsInitialized; + private RenderTexture _tempBlurMap; + private RenderTexture _tempEdgeMap; + + private Rect _windowRect = new Rect(30, 300, 300, 600); + + [HideInInspector] public bool Busy; + + public MainGui MainGuiScript; + + public GameObject TestObject; + + public Material ThisMaterial; + + public void GetValues(ProjectObject projectObject) + { + InitializeSettings(); + projectObject.EdgeSettings = _settings; + } + + public void SetValues(ProjectObject projectObject) + { + InitializeSettings(); + if (projectObject.EdgeSettings != null) + { + _settings = projectObject.EdgeSettings; + } + else + { + _settingsInitialized = false; + InitializeSettings(); + } + + _doStuff = true; + } + + private void InitializeSettings() + { + if (_settingsInitialized) return; + Debug.Log("Initializing Edge Settings"); + _settings = new EdgeSettings(); + _settingsInitialized = true; + } + + // Use this for initialization + private void Start() + { + TestObject.GetComponent().sharedMaterial = ThisMaterial; + + _blitMaterial = new Material(Shader.Find("Hidden/Blit_Shader")); + + InitializeSettings(); + } + + public void DoStuff() + { + _doStuff = true; + } + + public void NewTexture() + { + _newTexture = true; + } + + + // Update is called once per frame + private void Update() + { + if (_newTexture) + { + InitializeTextures(); + _newTexture = false; + } + + if (_doStuff) + { + StartCoroutine(ProcessNormal()); + _doStuff = false; + } + + ThisMaterial.SetFloat(Blur0Weight, _settings.Blur0Weight * _settings.Blur0Weight * _settings.Blur0Weight); + ThisMaterial.SetFloat(Blur1Weight, _settings.Blur1Weight * _settings.Blur1Weight * _settings.Blur1Weight); + ThisMaterial.SetFloat(Blur2Weight, _settings.Blur2Weight * _settings.Blur2Weight * _settings.Blur2Weight); + ThisMaterial.SetFloat(Blur3Weight, _settings.Blur3Weight * _settings.Blur3Weight * _settings.Blur3Weight); + ThisMaterial.SetFloat(Blur4Weight, _settings.Blur4Weight * _settings.Blur4Weight * _settings.Blur4Weight); + ThisMaterial.SetFloat(Blur5Weight, _settings.Blur5Weight * _settings.Blur5Weight * _settings.Blur5Weight); + ThisMaterial.SetFloat(Blur6Weight, _settings.Blur6Weight * _settings.Blur6Weight * _settings.Blur6Weight); + ThisMaterial.SetFloat(EdgeAmount, _settings.EdgeAmount); + ThisMaterial.SetFloat(CreviceAmount, _settings.CreviceAmount); + ThisMaterial.SetFloat(Pinch, _settings.Pinch); + ThisMaterial.SetFloat(Pillow, _settings.Pillow); + ThisMaterial.SetFloat(FinalContrast, _settings.FinalContrast); + ThisMaterial.SetFloat(FinalBias, _settings.FinalBias); + } + + private void SetDefaultSliderValues() + { + _settings.Blur0Contrast = 1.0f; + _settings.Blur0ContrastText = "1"; + + _settings.EdgeAmount = 1.0f; + _settings.EdgeAmountText = "1"; + + _settings.CreviceAmount = 1.0f; + _settings.CreviceAmountText = "1"; + + _settings.Pinch = 1.0f; + _settings.PinchText = "1"; + + _settings.Pillow = 1.0f; + _settings.PillowText = "1"; + + _settings.FinalContrast = 2.0f; + _settings.FinalContrastText = "2"; + + _settings.FinalBias = 0.0f; + _settings.FinalBiasText = "0"; + } + + private void SetWeightEqDefault() + { + _settings.Blur0Weight = 1.0f; + _settings.Blur1Weight = 0.5f; + _settings.Blur2Weight = 0.3f; + _settings.Blur3Weight = 0.5f; + _settings.Blur4Weight = 0.7f; + _settings.Blur5Weight = 0.7f; + _settings.Blur6Weight = 0.3f; + + SetDefaultSliderValues(); + + _doStuff = true; + } + + private void SetWeightEqDisplace() + { + _settings.Blur0Weight = 0.1f; + _settings.Blur1Weight = 0.15f; + _settings.Blur2Weight = 0.25f; + _settings.Blur3Weight = 0.45f; + _settings.Blur4Weight = 0.75f; + _settings.Blur5Weight = 0.95f; + _settings.Blur6Weight = 1.0f; + + SetDefaultSliderValues(); + + _settings.Blur0Contrast = 3.0f; + _settings.Blur0ContrastText = "3"; + + _settings.FinalContrast = 5.0f; + _settings.FinalContrastText = "5"; + + _settings.FinalBias = -0.2f; + _settings.FinalBiasText = "-0.2"; + + _doStuff = true; + } + + private void SetWeightEqSoft() + { + _settings.Blur0Weight = 0.15f; + _settings.Blur1Weight = 0.4f; + _settings.Blur2Weight = 0.7f; + _settings.Blur3Weight = 0.9f; + _settings.Blur4Weight = 1.0f; + _settings.Blur5Weight = 0.9f; + _settings.Blur6Weight = 0.7f; + + SetDefaultSliderValues(); + + _settings.FinalContrast = 4.0f; + _settings.FinalContrastText = "4"; + + _doStuff = true; + } + + private void SetWeightEqTight() + { + _settings.Blur0Weight = 1.0f; + _settings.Blur1Weight = 0.45f; + _settings.Blur2Weight = 0.25f; + _settings.Blur3Weight = 0.18f; + _settings.Blur4Weight = 0.15f; + _settings.Blur5Weight = 0.13f; + _settings.Blur6Weight = 0.1f; + + SetDefaultSliderValues(); + + _settings.Pinch = 1.5f; + _settings.PinchText = "1.5"; + + _doStuff = true; + } + + private void DoMyWindow(int windowId) + { + var offsetX = 10; + var offsetY = 30; + + _doStuff = GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Pre Contrast", _settings.Blur0Contrast, + _settings.Blur0ContrastText, out _settings.Blur0Contrast, out _settings.Blur0ContrastText, 0.0f, 5.0f); + offsetY += 50; + + GUI.Label(new Rect(offsetX, offsetY, 250, 30), "Frequency Equalizer"); + GUI.Label(new Rect(offsetX + 225, offsetY, 100, 30), "Presets"); + if (GUI.Button(new Rect(offsetX + 215, offsetY + 30, 60, 20), "Default")) SetWeightEqDefault(); + if (GUI.Button(new Rect(offsetX + 215, offsetY + 60, 60, 20), "Displace")) SetWeightEqDisplace(); + if (GUI.Button(new Rect(offsetX + 215, offsetY + 90, 60, 20), "Soft")) SetWeightEqSoft(); + if (GUI.Button(new Rect(offsetX + 215, offsetY + 120, 60, 20), "Tight")) SetWeightEqTight(); + offsetY += 30; + offsetX += 10; + _settings.Blur0Weight = + GUI.VerticalSlider(new Rect(offsetX + 180, offsetY, 10, 100), _settings.Blur0Weight, 1.0f, 0.0f); + _settings.Blur1Weight = + GUI.VerticalSlider(new Rect(offsetX + 150, offsetY, 10, 100), _settings.Blur1Weight, 1.0f, 0.0f); + _settings.Blur2Weight = + GUI.VerticalSlider(new Rect(offsetX + 120, offsetY, 10, 100), _settings.Blur2Weight, 1.0f, 0.0f); + _settings.Blur3Weight = + GUI.VerticalSlider(new Rect(offsetX + 90, offsetY, 10, 100), _settings.Blur3Weight, 1.0f, 0.0f); + _settings.Blur4Weight = + GUI.VerticalSlider(new Rect(offsetX + 60, offsetY, 10, 100), _settings.Blur4Weight, 1.0f, 0.0f); + _settings.Blur5Weight = + GUI.VerticalSlider(new Rect(offsetX + 30, offsetY, 10, 100), _settings.Blur5Weight, 1.0f, 0.0f); + _settings.Blur6Weight = + GUI.VerticalSlider(new Rect(offsetX + 0, offsetY, 10, 100), _settings.Blur6Weight, 1.0f, 0.0f); + offsetX -= 10; + offsetY += 120; + + GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Edge Amount", _settings.EdgeAmount, + _settings.EdgeAmountText, + out _settings.EdgeAmount, out _settings.EdgeAmountText, 0.0f, 1.0f); + offsetY += 40; + + GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Crevice Amount", _settings.CreviceAmount, + _settings.CreviceAmountText, + out _settings.CreviceAmount, out _settings.CreviceAmountText, 0.0f, 1.0f); + offsetY += 40; + + GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Pinch", _settings.Pinch, _settings.PinchText, + out _settings.Pinch, + out _settings.PinchText, 0.1f, 10.0f); + offsetY += 40; + + GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Pillow", _settings.Pillow, _settings.PillowText, + out _settings.Pillow, + out _settings.PillowText, 0.1f, 5.0f); + offsetY += 40; + + GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Final Contrast", _settings.FinalContrast, + _settings.FinalContrastText, + out _settings.FinalContrast, out _settings.FinalContrastText, 0.1f, 30.0f); + offsetY += 40; + + GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Final Bias", _settings.FinalBias, + _settings.FinalBiasText, + out _settings.FinalBias, out _settings.FinalBiasText, -1.0f, 1.0f); + offsetY += 50; + + if (GUI.Button(new Rect(offsetX + 10, offsetY, 130, 30), "Reset to Defaults")) + { + //_settingsInitialized = false; + SetValues(new ProjectObject()); + //StartCoroutine(ProcessDiffuse()); + } + + if (GUI.Button(new Rect(offsetX + 150, offsetY, 130, 30), "Set as Edge Map")) StartCoroutine(ProcessEdge()); + + GUI.DragWindow(); + } + + private void OnGUI() + { + _windowRect.width = 300; + _windowRect.height = 520; + + _windowRect = GUI.Window(11, _windowRect, DoMyWindow, "Edge from Normal"); + } + + public void InitializeTextures() + { + TestObject.GetComponent().sharedMaterial = ThisMaterial; + + CleanupTextures(); + + _normalMap = MainGuiScript.NormalMap; + + _imageSizeX = _normalMap.width; + _imageSizeY = _normalMap.height; + + Debug.Log("Initializing Textures of size: " + _imageSizeX + "x" + _imageSizeY); + + _tempBlurMap = new RenderTexture(_imageSizeX, _imageSizeY, 0, RenderTextureFormat.RHalf, + RenderTextureReadWrite.Linear) {wrapMode = TextureWrapMode.Repeat}; + _blurMap0 = new RenderTexture(_imageSizeX, _imageSizeY, 0, RenderTextureFormat.RHalf, + RenderTextureReadWrite.Linear) {wrapMode = TextureWrapMode.Repeat}; + _blurMap1 = new RenderTexture(_imageSizeX, _imageSizeY, 0, RenderTextureFormat.RHalf, + RenderTextureReadWrite.Linear) {wrapMode = TextureWrapMode.Repeat}; + _blurMap2 = new RenderTexture(_imageSizeX, _imageSizeY, 0, RenderTextureFormat.RHalf, + RenderTextureReadWrite.Linear) {wrapMode = TextureWrapMode.Repeat}; + _blurMap3 = new RenderTexture(_imageSizeX, _imageSizeY, 0, RenderTextureFormat.RHalf, + RenderTextureReadWrite.Linear) {wrapMode = TextureWrapMode.Repeat}; + _blurMap4 = new RenderTexture(_imageSizeX, _imageSizeY, 0, RenderTextureFormat.RHalf, + RenderTextureReadWrite.Linear) {wrapMode = TextureWrapMode.Repeat}; + _blurMap5 = new RenderTexture(_imageSizeX, _imageSizeY, 0, RenderTextureFormat.RHalf, + RenderTextureReadWrite.Linear) {wrapMode = TextureWrapMode.Repeat}; + _blurMap6 = new RenderTexture(_imageSizeX, _imageSizeY, 0, RenderTextureFormat.RHalf, + RenderTextureReadWrite.Linear) {wrapMode = TextureWrapMode.Repeat}; + StartCoroutine(ProcessNormal()); + } + + public void Close() + { + CleanupTextures(); + gameObject.SetActive(false); + } + + private static void CleanupTexture(RenderTexture texture) + { + if (!texture) return; + texture.Release(); + // ReSharper disable once RedundantAssignment + texture = null; + } + + private void CleanupTextures() + { + CleanupTexture(_tempBlurMap); + CleanupTexture(_blurMap0); + CleanupTexture(_blurMap1); + CleanupTexture(_blurMap2); + CleanupTexture(_blurMap3); + CleanupTexture(_blurMap4); + CleanupTexture(_blurMap5); + CleanupTexture(_blurMap6); + CleanupTexture(_tempEdgeMap); + } + + public IEnumerator ProcessEdge() + { + Busy = true; + + Debug.Log("Processing Height / Edge"); + + _blitMaterial.SetVector(ImageSize, new Vector4(_imageSizeX, _imageSizeY, 0, 0)); + + _blitMaterial.SetFloat(Blur0Weight, _settings.Blur0Weight * _settings.Blur0Weight * _settings.Blur0Weight); + _blitMaterial.SetFloat(Blur1Weight, _settings.Blur1Weight * _settings.Blur1Weight * _settings.Blur1Weight); + _blitMaterial.SetFloat(Blur2Weight, _settings.Blur2Weight * _settings.Blur2Weight * _settings.Blur2Weight); + _blitMaterial.SetFloat(Blur3Weight, _settings.Blur3Weight * _settings.Blur3Weight * _settings.Blur3Weight); + _blitMaterial.SetFloat(Blur4Weight, _settings.Blur4Weight * _settings.Blur4Weight * _settings.Blur4Weight); + _blitMaterial.SetFloat(Blur5Weight, _settings.Blur5Weight * _settings.Blur5Weight * _settings.Blur5Weight); + _blitMaterial.SetFloat(Blur6Weight, _settings.Blur6Weight * _settings.Blur6Weight * _settings.Blur6Weight); + _blitMaterial.SetFloat(EdgeAmount, _settings.EdgeAmount); + _blitMaterial.SetFloat(CreviceAmount, _settings.CreviceAmount); + _blitMaterial.SetFloat(Pinch, _settings.Pinch); + _blitMaterial.SetFloat(Pillow, _settings.Pillow); + _blitMaterial.SetFloat(FinalContrast, _settings.FinalContrast); + _blitMaterial.SetFloat(FinalBias, _settings.FinalBias); + + _blitMaterial.SetTexture(MainTex, _normalMap); + _blitMaterial.SetTexture(BlurTex0, _blurMap0); + _blitMaterial.SetTexture(BlurTex1, _blurMap1); + _blitMaterial.SetTexture(BlurTex2, _blurMap2); + _blitMaterial.SetTexture(BlurTex3, _blurMap3); + _blitMaterial.SetTexture(BlurTex4, _blurMap4); + _blitMaterial.SetTexture(BlurTex5, _blurMap5); + _blitMaterial.SetTexture(BlurTex6, _blurMap6); + + // Save low fidelity for texture 2d + + CleanupTexture(_tempEdgeMap); + _tempEdgeMap = new RenderTexture(_imageSizeX, _imageSizeY, 0, RenderTextureFormat.ARGB32, + RenderTextureReadWrite.Linear) {wrapMode = TextureWrapMode.Repeat}; + Graphics.Blit(_blurMap0, _tempEdgeMap, _blitMaterial, 6); + + RenderTexture.active = _tempEdgeMap; + + if (MainGuiScript.EdgeMap) Destroy(MainGuiScript.EdgeMap); + + MainGuiScript.EdgeMap = + new Texture2D(_tempEdgeMap.width, _tempEdgeMap.height, TextureFormat.ARGB32, true, true); + MainGuiScript.EdgeMap.ReadPixels(new Rect(0, 0, _tempEdgeMap.width, _tempEdgeMap.height), 0, 0); + MainGuiScript.EdgeMap.Apply(); + + yield return new WaitForSeconds(0.1f); + + CleanupTexture(_tempEdgeMap); + + Busy = false; + } + + public IEnumerator ProcessNormal() + { + Busy = true; + + Debug.Log("Processing Normal to Edge"); + + _blitMaterial.SetVector(ImageSize, new Vector4(_imageSizeX, _imageSizeY, 0, 0)); + + // Make normal from height + _blitMaterial.SetFloat(BlurContrast, _settings.Blur0Contrast); + _blitMaterial.SetTexture(MainTex, _normalMap); + Graphics.Blit(_normalMap, _blurMap0, _blitMaterial, 5); + + _blitMaterial.SetFloat(BlurContrast, 1.0f); + + // Blur the image 1 + _blitMaterial.SetTexture(MainTex, _blurMap0); + _blitMaterial.SetInt(BlurSamples, 4); + _blitMaterial.SetFloat(BlurSpread, 1.0f); + _blitMaterial.SetVector(BlurDirection, new Vector4(1, 0, 0, 0)); + Graphics.Blit(_blurMap0, _tempBlurMap, _blitMaterial, 1); + + _blitMaterial.SetTexture(MainTex, _tempBlurMap); + _blitMaterial.SetVector(BlurDirection, new Vector4(0, 1, 0, 0)); + Graphics.Blit(_tempBlurMap, _blurMap1, _blitMaterial, 1); + + + // Blur the image 2 + _blitMaterial.SetTexture(MainTex, _blurMap1); + _blitMaterial.SetFloat(BlurSpread, 2.0f); + _blitMaterial.SetVector(BlurDirection, new Vector4(1, 0, 0, 0)); + Graphics.Blit(_blurMap1, _tempBlurMap, _blitMaterial, 1); + + _blitMaterial.SetTexture(MainTex, _tempBlurMap); + _blitMaterial.SetVector(BlurDirection, new Vector4(0, 1, 0, 0)); + Graphics.Blit(_tempBlurMap, _blurMap2, _blitMaterial, 1); + + + // Blur the image 3 + _blitMaterial.SetTexture(MainTex, _blurMap2); + _blitMaterial.SetFloat(BlurSpread, 4.0f); + _blitMaterial.SetVector(BlurDirection, new Vector4(1, 0, 0, 0)); + Graphics.Blit(_blurMap2, _tempBlurMap, _blitMaterial, 1); + + _blitMaterial.SetTexture(MainTex, _tempBlurMap); + _blitMaterial.SetVector(BlurDirection, new Vector4(0, 1, 0, 0)); + Graphics.Blit(_tempBlurMap, _blurMap3, _blitMaterial, 1); + + + // Blur the image 4 + _blitMaterial.SetTexture(MainTex, _blurMap3); + _blitMaterial.SetFloat(BlurSpread, 8.0f); + _blitMaterial.SetVector(BlurDirection, new Vector4(1, 0, 0, 0)); + Graphics.Blit(_blurMap3, _tempBlurMap, _blitMaterial, 1); + + _blitMaterial.SetTexture(MainTex, _tempBlurMap); + _blitMaterial.SetVector(BlurDirection, new Vector4(0, 1, 0, 0)); + Graphics.Blit(_tempBlurMap, _blurMap4, _blitMaterial, 1); + + + // Blur the image 5 + _blitMaterial.SetTexture(MainTex, _blurMap4); + _blitMaterial.SetFloat(BlurSpread, 16.0f); + _blitMaterial.SetVector(BlurDirection, new Vector4(1, 0, 0, 0)); + Graphics.Blit(_blurMap4, _tempBlurMap, _blitMaterial, 1); + + _blitMaterial.SetTexture(MainTex, _tempBlurMap); + _blitMaterial.SetVector(BlurDirection, new Vector4(0, 1, 0, 0)); + Graphics.Blit(_tempBlurMap, _blurMap5, _blitMaterial, 1); + + + // Blur the image 6 + _blitMaterial.SetTexture(MainTex, _blurMap5); + _blitMaterial.SetFloat(BlurSpread, 32.0f); + _blitMaterial.SetVector(BlurDirection, new Vector4(1, 0, 0, 0)); + Graphics.Blit(_blurMap5, _tempBlurMap, _blitMaterial, 1); + + _blitMaterial.SetTexture(MainTex, _tempBlurMap); + _blitMaterial.SetVector(BlurDirection, new Vector4(0, 1, 0, 0)); + Graphics.Blit(_tempBlurMap, _blurMap6, _blitMaterial, 1); + + + ThisMaterial.SetTexture(MainTex, _blurMap0); + ThisMaterial.SetTexture(BlurTex0, _blurMap0); + ThisMaterial.SetTexture(BlurTex1, _blurMap1); + ThisMaterial.SetTexture(BlurTex2, _blurMap2); + ThisMaterial.SetTexture(BlurTex3, _blurMap3); + ThisMaterial.SetTexture(BlurTex4, _blurMap4); + ThisMaterial.SetTexture(BlurTex5, _blurMap5); + ThisMaterial.SetTexture(BlurTex6, _blurMap6); + + yield return new WaitForSeconds(0.1f); + + Busy = false; + } +} \ No newline at end of file diff --git a/Assets/Scripts/EdgeSettings.cs b/Assets/Scripts/EdgeSettings.cs new file mode 100644 index 00000000..cb142bd0 --- /dev/null +++ b/Assets/Scripts/EdgeSettings.cs @@ -0,0 +1,82 @@ +#region + +using System.ComponentModel; + +#endregion + +public class EdgeSettings +{ + [DefaultValue(1.0)] public float Blur0Contrast; + + [DefaultValue("1")] public string Blur0ContrastText; + + [DefaultValue(1.0f)] public float Blur0Weight; + + [DefaultValue(0.5f)] public float Blur1Weight; + + [DefaultValue(0.3f)] public float Blur2Weight; + + [DefaultValue(0.5f)] public float Blur3Weight; + + [DefaultValue(0.7f)] public float Blur4Weight; + + [DefaultValue(0.7f)] public float Blur5Weight; + + [DefaultValue(0.3f)] public float Blur6Weight; + + [DefaultValue(1.0f)] public float CreviceAmount; + + [DefaultValue("1")] public string CreviceAmountText; + + [DefaultValue(1.0f)] public float EdgeAmount; + + [DefaultValue("1")] public string EdgeAmountText; + + [DefaultValue(0.0f)] public float FinalBias; + + [DefaultValue("0")] public string FinalBiasText; + + [DefaultValue(1.0f)] public float FinalContrast; + + [DefaultValue("1")] public string FinalContrastText; + + [DefaultValue(1.0f)] public float Pillow; + + [DefaultValue("1")] public string PillowText; + + [DefaultValue(1.0f)] public float Pinch; + + [DefaultValue("1")] public string PinchText; + + public EdgeSettings() + { + Blur0Contrast = 1.0f; + Blur0ContrastText = "1"; + + Blur0Weight = 1.0f; + Blur1Weight = 0.5f; + Blur2Weight = 0.3f; + Blur3Weight = 0.5f; + Blur4Weight = 0.7f; + Blur5Weight = 0.7f; + Blur6Weight = 0.3f; + + FinalContrast = 1.0f; + FinalContrastText = "1"; + + FinalBias = 0.0f; + FinalBiasText = "0"; + + EdgeAmount = 1.0f; + EdgeAmountText = "1"; + + CreviceAmount = 1.0f; + CreviceAmountText = "1"; + + Pinch = 1.0f; + PinchText = "1"; + + Pillow = 1.0f; + PillowText = "1"; + } +} \ No newline at end of file diff --git a/Assets/Scripts/EdgeSettings.cs.meta b/Assets/Scripts/EdgeSettings.cs.meta new file mode 100644 index 00000000..fb90cae2 --- /dev/null +++ b/Assets/Scripts/EdgeSettings.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 0b758fd370524127ac83ffe7503b7701 +timeCreated: 1549043288 \ No newline at end of file diff --git a/Assets/Scripts/EditDiffuseGui.cs b/Assets/Scripts/EditDiffuseGui.cs index 90597ee3..675164d7 100644 --- a/Assets/Scripts/EditDiffuseGui.cs +++ b/Assets/Scripts/EditDiffuseGui.cs @@ -1,446 +1,463 @@ -using UnityEngine; +#region + using System.Collections; using System.ComponentModel; -using System; +using UnityEngine; +#endregion -public class EditDiffuseSettings { +public class EditDiffuseSettings +{ + [DefaultValue(50)] public int AvgColorBlurSize; - [DefaultValueAttribute(50)] - public int AvgColorBlurSize; - [DefaultValueAttribute("50")] - public string AvgColorBlurSizeText; + [DefaultValue("50")] public string AvgColorBlurSizeText; - [DefaultValueAttribute(20)] - public int BlurSize; - [DefaultValueAttribute("20")] - public string BlurSizeText; + [DefaultValue(0.0f)] public float BlurContrast; - [DefaultValueAttribute(0.0f)] - public float BlurContrast; - [DefaultValueAttribute("0")] - public string BlurContrastText; + [DefaultValue("0")] public string BlurContrastText; - [DefaultValueAttribute(0.5f)] - public float LightMaskPow; - [DefaultValueAttribute("0.5")] - public string LightMaskPowText; - [DefaultValueAttribute(0f)] - public float LightPow; - [DefaultValueAttribute("0")] - public string LightPowText; + [DefaultValue(20)] public int BlurSize; - [DefaultValueAttribute(0.5f)] - public float DarkMaskPow; - [DefaultValueAttribute("0.5")] - public string DarkMaskPowText; - [DefaultValueAttribute(0.0f)] - public float DarkPow; - [DefaultValueAttribute("0")] - public string DarkPowText; + [DefaultValue("20")] public string BlurSizeText; - [DefaultValueAttribute(0.0f)] - public float HotSpot; - [DefaultValueAttribute("0")] - public string HotSpotText; - [DefaultValueAttribute(0.0f)] - public float DarkSpot; - [DefaultValueAttribute("0")] - public string DarkSpotText; + [DefaultValue(0.5f)] public float ColorLerp; - [DefaultValueAttribute(1.0f)] - public float FinalContrast; - [DefaultValueAttribute("1")] - public string FinalContrastText; + [DefaultValue("0.5")] public string ColorLerpText; - [DefaultValueAttribute(0.0f)] - public float FinalBias; - [DefaultValueAttribute("0")] - public string FinalBiasText; + [DefaultValue(0.5f)] public float DarkMaskPow; - [DefaultValueAttribute(0.5f)] - public float ColorLerp; - [DefaultValueAttribute("0.5")] - public string ColorLerpText; + [DefaultValue("0.5")] public string DarkMaskPowText; - [DefaultValueAttribute(1.0f)] - public float Saturation; - [DefaultValueAttribute("1")] - public string SaturationText; + [DefaultValue(0.0f)] public float DarkPow; + [DefaultValue("0")] public string DarkPowText; - public EditDiffuseSettings(){ - this.AvgColorBlurSize = 50; - this.AvgColorBlurSizeText = "50"; + [DefaultValue(0.0f)] public float DarkSpot; - this.BlurSize = 20; - this.BlurSizeText = "20"; + [DefaultValue("0")] public string DarkSpotText; - this.BlurContrast = 0.0f; - this.BlurContrastText = "0"; + [DefaultValue(0.0f)] public float FinalBias; - this.LightMaskPow = 0.5f; - this.LightMaskPowText = "0"; + [DefaultValue("0")] public string FinalBiasText; - this.LightPow = 0.0f; - this.LightPowText = "0"; + [DefaultValue(1.0f)] public float FinalContrast; - this.DarkMaskPow = 0.5f; - this.DarkMaskPowText = "0.5"; + [DefaultValue("1")] public string FinalContrastText; - this.DarkPow = 0.0f; - this.DarkPowText = "0"; + [DefaultValue(0.0f)] public float HotSpot; - this.HotSpot = 0.0f; - this.HotSpotText = "0"; + [DefaultValue("0")] public string HotSpotText; - this.DarkSpot = 0.0f; - this.DarkSpotText = "0"; + [DefaultValue(0.5f)] public float LightMaskPow; - this.FinalContrast = 1.0f; - this.FinalContrastText = "1"; + [DefaultValue("0.5")] public string LightMaskPowText; - this.FinalBias = 0.0f; - this.FinalBiasText = "0"; + [DefaultValue(0f)] public float LightPow; - this.ColorLerp = 0.5f; - this.ColorLerpText = "0.5"; - - this.Saturation = 1.0f; - this.SaturationText = "1"; - } + [DefaultValue("0")] public string LightPowText; -} + [DefaultValue(1.0f)] public float Saturation; + + [DefaultValue("1")] public string SaturationText; + + + public EditDiffuseSettings() + { + AvgColorBlurSize = 50; + AvgColorBlurSizeText = "50"; + + BlurSize = 20; + BlurSizeText = "20"; + + BlurContrast = 0.0f; + BlurContrastText = "0"; + + LightMaskPow = 0.5f; + LightMaskPowText = "0"; + + LightPow = 0.0f; + LightPowText = "0"; + + DarkMaskPow = 0.5f; + DarkMaskPowText = "0.5"; + + DarkPow = 0.0f; + DarkPowText = "0"; + + HotSpot = 0.0f; + HotSpotText = "0"; -public class EditDiffuseGui : MonoBehaviour { - - public MainGui MainGuiScript; - - Texture2D _DiffuseMap; - Texture2D _DiffuseMapOriginal; - - RenderTexture _TempMap; - RenderTexture _BlurMap; - RenderTexture _AvgTempMap; - RenderTexture _AvgMap; - - public Material thisMaterial; - Material blitMaterial; - - int imageSizeX; - int imageSizeY; - - EditDiffuseSettings EDS; - - public GameObject testObject; - bool doStuff = false; - bool newTexture = false; - - Rect windowRect = new Rect (30, 300, 300, 450); - bool settingsInitialized = false; - - float Slider = 0.5f; - - public void GetValues( ProjectObject projectObject ) { - InitializeSettings (); - projectObject.EDS = EDS; - } - - public void SetValues( ProjectObject projectObject ) { - InitializeSettings (); - if (projectObject.EDS != null) { - EDS = projectObject.EDS; - } else { - settingsInitialized = false; - InitializeSettings (); - } - doStuff = true; - } - - void InitializeSettings() { - - if (settingsInitialized == false) { - Debug.Log ("Initializing Edit Diffuse Settings"); - EDS = new EditDiffuseSettings (); - settingsInitialized = true; - } - - } - - - // Use this for initialization - void Start () { - - testObject.GetComponent().sharedMaterial = thisMaterial; - - blitMaterial = new Material (Shader.Find ("Hidden/Blit_Shader")); - - InitializeSettings (); - - } - - public void DoStuff() { - doStuff = true; - } - - public void NewTexture() { - newTexture = true; - } - - // Update is called once per frame - void Update () { - - if (newTexture) { - InitializeTextures(); - newTexture = false; - } - - if (doStuff) { - StartCoroutine( ProcessBlur () ); - doStuff = false; - } - - - thisMaterial.SetFloat ( "_Slider", Slider); - - thisMaterial.SetFloat ("_BlurContrast", EDS.BlurContrast); - - thisMaterial.SetFloat ("_LightMaskPow", EDS.LightMaskPow ); - thisMaterial.SetFloat ("_LightPow", EDS.LightPow ); - - thisMaterial.SetFloat ("_DarkMaskPow", EDS.DarkMaskPow ); - thisMaterial.SetFloat ("_DarkPow", EDS.DarkPow ); - - thisMaterial.SetFloat ("_HotSpot", EDS.HotSpot ); - thisMaterial.SetFloat ("_DarkSpot", EDS.DarkSpot ); - - thisMaterial.SetFloat ("_FinalContrast", EDS.FinalContrast); - thisMaterial.SetFloat ("_FinalBias", EDS.FinalBias); - - thisMaterial.SetFloat ("_ColorLerp", EDS.ColorLerp); - - thisMaterial.SetFloat ("_Saturation", EDS.Saturation); - - } - - string FloatToString ( float num, int length ) { - - string numString = num.ToString (); - int numStringLength = numString.Length; - int lastIndex = Mathf.FloorToInt( Mathf.Min ( (float)numStringLength , (float)length ) ); - - return numString.Substring (0, lastIndex); - } - - void DoMyWindow ( int windowID ) { - - int spacingX = 0; - int spacingY = 50; - int spacing2Y = 70; - - int offsetX = 10; - int offsetY = 30; - - //GuiHelper.Slider (new Rect (offsetX, offsetY, 280, 50), "Contrast", EDS.DiffuseContrast, EDS.DiffuseContrastText, out EDS.DiffuseContrast, out EDS.DiffuseContrastText, -1.0f, 1.0f ); - //offsetY += 30; - //GuiHelper.Slider (new Rect (offsetX, offsetY, 280, 50), "Bias", EDS.DiffuseBias, EDS.DiffuseBiasText, out EDS.DiffuseBias, out EDS.DiffuseBiasText, -0.5f, 0.5f); - //offsetY += 50; - - GUI.Label (new Rect (offsetX, offsetY, 250, 30), "Diffuse Reveal Slider" ); - Slider = GUI.HorizontalSlider( new Rect( offsetX, offsetY + 20, 280, 10 ),Slider,0.0f, 1.0f ); - offsetY += 50; - - if( GuiHelper.Slider (new Rect (offsetX, offsetY, 280, 50), "Average Color Blur Size", EDS.AvgColorBlurSize, EDS.AvgColorBlurSizeText, out EDS.AvgColorBlurSize, out EDS.AvgColorBlurSizeText, 5, 100) ) { - doStuff = true; - } - offsetY += 50; - - if (GuiHelper.Slider (new Rect (offsetX, offsetY, 280, 50), "Overlay Blur Size", EDS.BlurSize, EDS.BlurSizeText, out EDS.BlurSize, out EDS.BlurSizeText, 5, 100)) { - doStuff = true; - } - offsetY += 30; - GuiHelper.Slider (new Rect (offsetX, offsetY, 280, 50), "Overlay Blur Contrast", EDS.BlurContrast, EDS.BlurContrastText, out EDS.BlurContrast, out EDS.BlurContrastText, -1.0f, 1.0f ); - offsetY += 50; - - GuiHelper.Slider (new Rect (offsetX, offsetY, 280, 50), "Light Mask Power", EDS.LightMaskPow, EDS.LightMaskPowText, out EDS.LightMaskPow, out EDS.LightMaskPowText, 0.0f, 1.0f ); - offsetY += 30; - GuiHelper.Slider (new Rect (offsetX, offsetY, 280, 50), "Remove Light", EDS.LightPow, EDS.LightPowText, out EDS.LightPow, out EDS.LightPowText, 0.0f, 1.0f ); - offsetY += 50; - GuiHelper.Slider (new Rect (offsetX, offsetY, 280, 50), "Shadow Mask Power", EDS.DarkMaskPow, EDS.DarkMaskPowText, out EDS.DarkMaskPow, out EDS.DarkMaskPowText, 0.0f, 1.0f ); - offsetY += 30; - GuiHelper.Slider (new Rect (offsetX, offsetY, 280, 50), "Remove Shadow", EDS.DarkPow, EDS.DarkPowText, out EDS.DarkPow, out EDS.DarkPowText, 0.0f, 1.0f ); - offsetY += 50; - - GuiHelper.Slider (new Rect (offsetX, offsetY, 280, 50), "Hot Spot Removal", EDS.HotSpot, EDS.HotSpotText, out EDS.HotSpot, out EDS.HotSpotText, 0.0f, 1.0f ); - offsetY += 30; - GuiHelper.Slider (new Rect (offsetX, offsetY, 280, 50), "Dark Spot Removal", EDS.DarkSpot, EDS.DarkSpotText, out EDS.DarkSpot, out EDS.DarkSpotText, 0.0f, 1.0f ); - offsetY += 50; - - GuiHelper.Slider (new Rect (offsetX, offsetY, 280, 50), "Final Contrast", EDS.FinalContrast, EDS.FinalContrastText, out EDS.FinalContrast, out EDS.FinalContrastText, -2.0f, 2.0f ); - offsetY += 30; - GuiHelper.Slider (new Rect (offsetX, offsetY, 280, 50), "Final Bias", EDS.FinalBias, EDS.FinalBiasText, out EDS.FinalBias, out EDS.FinalBiasText, -0.5f, 0.5f ); - offsetY += 50; - - GuiHelper.Slider (new Rect (offsetX, offsetY, 280, 50), "Keep Original Color", EDS.ColorLerp, EDS.ColorLerpText, out EDS.ColorLerp, out EDS.ColorLerpText, 0.0f, 1.0f ); - offsetY += 30; - GuiHelper.Slider (new Rect (offsetX, offsetY, 280, 50), "Saturation", EDS.Saturation, EDS.SaturationText, out EDS.Saturation, out EDS.SaturationText, 0.0f, 1.0f ); - offsetY += 50; - - if( GUI.Button (new Rect (offsetX + 150, offsetY, 130, 30), "Set as Diffuse" ) ){ - StartCoroutine( ProcessDiffuse ( MapType.diffuse ) ); - } - - GUI.DragWindow(); - } - - void OnGUI () { - - windowRect.width = 300; - windowRect.height = 650; - - windowRect = GUI.Window(12, windowRect, DoMyWindow, "Edit Diffuse"); - - } - - public void Close(){ - CleanupTextures (); - this.gameObject.SetActive (false); - } - - void CleanupTexture( RenderTexture _Texture ) { - - if (_Texture != null) { - _Texture.Release(); - _Texture = null; - } - - } - - void CleanupTextures() { - - Debug.Log ("Cleaning Up Textures"); - - CleanupTexture( _BlurMap ); - CleanupTexture( _TempMap ); - CleanupTexture (_AvgMap); - CleanupTexture (_AvgTempMap); - } - - void InitializeTextures() { - - testObject.GetComponent().sharedMaterial = thisMaterial; - - CleanupTextures (); - - _DiffuseMapOriginal = MainGuiScript._DiffuseMapOriginal; - - thisMaterial.SetTexture ("_MainTex", _DiffuseMapOriginal); - - imageSizeX = _DiffuseMapOriginal.width; - imageSizeY = _DiffuseMapOriginal.height; - - Debug.Log ( "Initializing Textures of size: " + imageSizeX.ToString() + "x" + imageSizeY.ToString() ); - - _BlurMap = new RenderTexture (imageSizeX, imageSizeY, 0, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear); - _BlurMap.wrapMode = TextureWrapMode.Repeat; - _AvgMap = new RenderTexture (imageSizeX, imageSizeY, 0, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear); - _AvgMap.wrapMode = TextureWrapMode.Repeat; - - } - - IEnumerator ProcessDiffuse( MapType whichTexture ) { - - Debug.Log ("Processing Diffuse"); - - blitMaterial.SetVector ("_ImageSize", new Vector4 (imageSizeX, imageSizeY, 0, 0)); - - blitMaterial.SetTexture ("_MainTex", _DiffuseMapOriginal); - - blitMaterial.SetTexture ("_BlurTex", _BlurMap); - blitMaterial.SetFloat ("_BlurContrast", EDS.BlurContrast); - - blitMaterial.SetTexture ("_AvgTex", _AvgMap); - - blitMaterial.SetFloat ("_LightMaskPow", EDS.LightMaskPow ); - blitMaterial.SetFloat ("_LightPow", EDS.LightPow ); - - blitMaterial.SetFloat ("_DarkMaskPow", EDS.DarkMaskPow ); - blitMaterial.SetFloat ("_DarkPow", EDS.DarkPow ); - - blitMaterial.SetFloat ("_HotSpot", EDS.HotSpot ); - blitMaterial.SetFloat ("_DarkSpot", EDS.DarkSpot ); - - blitMaterial.SetFloat ("_FinalContrast", EDS.FinalContrast); - - blitMaterial.SetFloat ("_FinalBias", EDS.FinalBias); - - blitMaterial.SetFloat ("_ColorLerp", EDS.ColorLerp); - - blitMaterial.SetFloat ("_Saturation", EDS.Saturation); - - CleanupTexture ( _TempMap ); - _TempMap = new RenderTexture (imageSizeX, imageSizeY, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear); - _TempMap.wrapMode = TextureWrapMode.Repeat; - - Graphics.Blit(_DiffuseMapOriginal, _TempMap, blitMaterial, 11); - - RenderTexture.active = _TempMap; - - if (MainGuiScript._DiffuseMap != null) { - Destroy (MainGuiScript._DiffuseMap); - MainGuiScript._DiffuseMap = null; - } - - MainGuiScript._DiffuseMap = new Texture2D (_TempMap.width, _TempMap.height, TextureFormat.ARGB32, true, true ); - MainGuiScript._DiffuseMap.ReadPixels (new Rect (0, 0, _TempMap.width, _TempMap.height), 0, 0); - MainGuiScript._DiffuseMap.Apply (); - - yield return new WaitForSeconds(0.1f); - - CleanupTexture ( _TempMap ); - - } - - IEnumerator ProcessBlur () { - - Debug.Log ("Processing Blur"); - - CleanupTexture ( _TempMap ); - _TempMap = new RenderTexture (imageSizeX, imageSizeY, 0, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear); - _TempMap.wrapMode = TextureWrapMode.Repeat; - - blitMaterial.SetVector ("_ImageSize", new Vector4( imageSizeX, imageSizeY, 0, 0 ) ); - blitMaterial.SetFloat ("_BlurContrast", 1.0f); - blitMaterial.SetFloat ("_BlurSpread", 1.0f); - - // Blur the image 1 - blitMaterial.SetInt ("_BlurSamples", EDS.BlurSize); - blitMaterial.SetVector ("_BlurDirection", new Vector4(1,0,0,0) ); - Graphics.Blit(_DiffuseMapOriginal, _TempMap, blitMaterial, 1); - blitMaterial.SetVector ("_BlurDirection", new Vector4(0,1,0,0) ); - Graphics.Blit(_TempMap, _BlurMap, blitMaterial, 1); - thisMaterial.SetTexture ("_BlurTex", _BlurMap); - - - blitMaterial.SetTexture ("_MainTex", _DiffuseMapOriginal); - blitMaterial.SetInt ("_BlurSamples", EDS.AvgColorBlurSize); - blitMaterial.SetVector ("_BlurDirection", new Vector4(1,0,0,0) ); - Graphics.Blit(_DiffuseMapOriginal, _TempMap, blitMaterial, 1); - blitMaterial.SetVector ("_BlurDirection", new Vector4(0,1,0,0) ); - Graphics.Blit(_TempMap, _AvgMap, blitMaterial, 1); - - blitMaterial.SetFloat ("_BlurSpread", EDS.AvgColorBlurSize / 5); - blitMaterial.SetVector ("_BlurDirection", new Vector4(1,0,0,0) ); - Graphics.Blit(_AvgMap, _TempMap, blitMaterial, 1); - blitMaterial.SetVector ("_BlurDirection", new Vector4(0,1,0,0) ); - Graphics.Blit(_TempMap, _AvgMap, blitMaterial, 1); - - thisMaterial.SetTexture ("_AvgTex", _AvgMap); - - CleanupTexture ( _TempMap ); - CleanupTexture ( _AvgTempMap ); - - yield return new WaitForSeconds(0.01f); - - } + DarkSpot = 0.0f; + DarkSpotText = "0"; + + FinalContrast = 1.0f; + FinalContrastText = "1"; + + FinalBias = 0.0f; + FinalBiasText = "0"; + + ColorLerp = 0.5f; + ColorLerpText = "0.5"; + + Saturation = 1.0f; + SaturationText = "1"; + } } + +public class EditDiffuseGui : MonoBehaviour +{ + private static readonly int Slider = Shader.PropertyToID("_Slider"); + private static readonly int BlurContrast = Shader.PropertyToID("_BlurContrast"); + private static readonly int LightMaskPow = Shader.PropertyToID("_LightMaskPow"); + private static readonly int LightPow = Shader.PropertyToID("_LightPow"); + private static readonly int DarkMaskPow = Shader.PropertyToID("_DarkMaskPow"); + private static readonly int DarkPow = Shader.PropertyToID("_DarkPow"); + private static readonly int HotSpot = Shader.PropertyToID("_HotSpot"); + private static readonly int DarkSpot = Shader.PropertyToID("_DarkSpot"); + private static readonly int FinalContrast = Shader.PropertyToID("_FinalContrast"); + private static readonly int FinalBias = Shader.PropertyToID("_FinalBias"); + private static readonly int ColorLerp = Shader.PropertyToID("_ColorLerp"); + private static readonly int Saturation = Shader.PropertyToID("_Saturation"); + private static readonly int ImageSize = Shader.PropertyToID("_ImageSize"); + private static readonly int MainTex = Shader.PropertyToID("_MainTex"); + private static readonly int BlurTex = Shader.PropertyToID("_BlurTex"); + private static readonly int AvgTex = Shader.PropertyToID("_AvgTex"); + private static readonly int BlurSpread = Shader.PropertyToID("_BlurSpread"); + private static readonly int BlurSamples = Shader.PropertyToID("_BlurSamples"); + private static readonly int BlurDirection = Shader.PropertyToID("_BlurDirection"); + private readonly RenderTexture _avgTempMap; + private RenderTexture _avgMap; + private Material _blitMaterial; + private RenderTexture _blurMap; + + private Texture2D _diffuseMap; + private Texture2D _diffuseMapOriginal; + private bool _doStuff; + + private EditDiffuseSettings _eds; + + private int _imageSizeX; + private int _imageSizeY; + private bool _newTexture; + private bool _settingsInitialized; + + private float _slider = 0.5f; + + private RenderTexture _tempMap; + + private Rect _windowRect = new Rect(30, 300, 300, 450); + + public MainGui MainGuiScript; + + public GameObject TestObject; + + public Material ThisMaterial; + + public EditDiffuseGui(RenderTexture avgTempMap) + { + _avgTempMap = avgTempMap; + } + + public void GetValues(ProjectObject projectObject) + { + InitializeSettings(); + projectObject.EditDiffuseSettings = _eds; + } + + public void SetValues(ProjectObject projectObject) + { + InitializeSettings(); + if (projectObject.EditDiffuseSettings != null) + { + _eds = projectObject.EditDiffuseSettings; + } + else + { + _settingsInitialized = false; + InitializeSettings(); + } + + _doStuff = true; + } + + private void InitializeSettings() + { + if (_settingsInitialized) return; + Debug.Log("Initializing Edit Diffuse Settings"); + _eds = new EditDiffuseSettings(); + _settingsInitialized = true; + } + + + // Use this for initialization + private void Start() + { + TestObject.GetComponent().sharedMaterial = ThisMaterial; + + _blitMaterial = new Material(Shader.Find("Hidden/Blit_Shader")); + + InitializeSettings(); + } + + public void DoStuff() + { + _doStuff = true; + } + + public void NewTexture() + { + _newTexture = true; + } + + // Update is called once per frame + private void Update() + { + if (_newTexture) + { + InitializeTextures(); + _newTexture = false; + } + + if (_doStuff) + { + StartCoroutine(ProcessBlur()); + _doStuff = false; + } + + + ThisMaterial.SetFloat(Slider, _slider); + + ThisMaterial.SetFloat(BlurContrast, _eds.BlurContrast); + + ThisMaterial.SetFloat(LightMaskPow, _eds.LightMaskPow); + ThisMaterial.SetFloat(LightPow, _eds.LightPow); + + ThisMaterial.SetFloat(DarkMaskPow, _eds.DarkMaskPow); + ThisMaterial.SetFloat(DarkPow, _eds.DarkPow); + + ThisMaterial.SetFloat(HotSpot, _eds.HotSpot); + ThisMaterial.SetFloat(DarkSpot, _eds.DarkSpot); + + ThisMaterial.SetFloat(FinalContrast, _eds.FinalContrast); + ThisMaterial.SetFloat(FinalBias, _eds.FinalBias); + + ThisMaterial.SetFloat(ColorLerp, _eds.ColorLerp); + + ThisMaterial.SetFloat(Saturation, _eds.Saturation); + } + + private void DoMyWindow(int windowId) + { + const int offsetX = 10; + var offsetY = 30; + + GUI.Label(new Rect(offsetX, offsetY, 250, 30), "Diffuse Reveal Slider"); + _slider = GUI.HorizontalSlider(new Rect(offsetX, offsetY + 20, 280, 10), _slider, 0.0f, 1.0f); + offsetY += 50; + + if (GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Average Color Blur Size", _eds.AvgColorBlurSize, + _eds.AvgColorBlurSizeText, out _eds.AvgColorBlurSize, out _eds.AvgColorBlurSizeText, 5, 100)) + _doStuff = true; + offsetY += 50; + + if (GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Overlay Blur Size", _eds.BlurSize, _eds.BlurSizeText, + out _eds.BlurSize, out _eds.BlurSizeText, 5, 100)) _doStuff = true; + offsetY += 30; + GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Overlay Blur Contrast", _eds.BlurContrast, + _eds.BlurContrastText, out _eds.BlurContrast, out _eds.BlurContrastText, -1.0f, 1.0f); + offsetY += 50; + + GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Light Mask Power", _eds.LightMaskPow, + _eds.LightMaskPowText, out _eds.LightMaskPow, out _eds.LightMaskPowText, 0.0f, 1.0f); + offsetY += 30; + GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Remove Light", _eds.LightPow, _eds.LightPowText, + out _eds.LightPow, out _eds.LightPowText, 0.0f, 1.0f); + offsetY += 50; + GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Shadow Mask Power", _eds.DarkMaskPow, + _eds.DarkMaskPowText, + out _eds.DarkMaskPow, out _eds.DarkMaskPowText, 0.0f, 1.0f); + offsetY += 30; + GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Remove Shadow", _eds.DarkPow, _eds.DarkPowText, + out _eds.DarkPow, out _eds.DarkPowText, 0.0f, 1.0f); + offsetY += 50; + + GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Hot Spot Removal", _eds.HotSpot, _eds.HotSpotText, + out _eds.HotSpot, out _eds.HotSpotText, 0.0f, 1.0f); + offsetY += 30; + GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Dark Spot Removal", _eds.DarkSpot, _eds.DarkSpotText, + out _eds.DarkSpot, out _eds.DarkSpotText, 0.0f, 1.0f); + offsetY += 50; + + GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Final Contrast", _eds.FinalContrast, + _eds.FinalContrastText, out _eds.FinalContrast, out _eds.FinalContrastText, -2.0f, 2.0f); + offsetY += 30; + GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Final Bias", _eds.FinalBias, _eds.FinalBiasText, + out _eds.FinalBias, out _eds.FinalBiasText, -0.5f, 0.5f); + offsetY += 50; + + GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Keep Original Color", _eds.ColorLerp, _eds.ColorLerpText, + out _eds.ColorLerp, out _eds.ColorLerpText, 0.0f, 1.0f); + offsetY += 30; + GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Saturation", _eds.Saturation, _eds.SaturationText, + out _eds.Saturation, out _eds.SaturationText, 0.0f, 1.0f); + offsetY += 50; + + if (GUI.Button(new Rect(offsetX + 10, offsetY, 130, 30), "Reset to Defaults")) + { + //_settingsInitialized = false; + SetValues(new ProjectObject()); + //StartCoroutine(ProcessDiffuse()); + } + + if (GUI.Button(new Rect(offsetX + 150, offsetY, 130, 30), "Set as Diffuse")) + StartCoroutine(ProcessDiffuse()); + + GUI.DragWindow(); + } + + private void OnGUI() + { + _windowRect.width = 300; + _windowRect.height = 650; + + _windowRect = GUI.Window(12, _windowRect, DoMyWindow, "Edit Diffuse"); + } + + public void Close() + { + CleanupTextures(); + gameObject.SetActive(false); + } + + private static void CleanupTexture(RenderTexture texture) + { + if (!texture) return; + texture.Release(); + // ReSharper disable once RedundantAssignment + texture = null; + } + + private void CleanupTextures() + { + CleanupTexture(_blurMap); + CleanupTexture(_tempMap); + CleanupTexture(_avgMap); + CleanupTexture(_avgTempMap); + } + + private void InitializeTextures() + { + TestObject.GetComponent().sharedMaterial = ThisMaterial; + + CleanupTextures(); + + _diffuseMapOriginal = MainGuiScript.DiffuseMapOriginal; + + ThisMaterial.SetTexture(MainTex, _diffuseMapOriginal); + + _imageSizeX = _diffuseMapOriginal.width; + _imageSizeY = _diffuseMapOriginal.height; + + Debug.Log("Initializing Textures of size: " + _imageSizeX + "x" + _imageSizeY); + + _blurMap = new RenderTexture(_imageSizeX, _imageSizeY, 0, RenderTextureFormat.ARGBHalf, + RenderTextureReadWrite.Linear) {wrapMode = TextureWrapMode.Repeat}; + _avgMap = new RenderTexture(_imageSizeX, _imageSizeY, 0, RenderTextureFormat.ARGBHalf, + RenderTextureReadWrite.Linear) {wrapMode = TextureWrapMode.Repeat}; + } + + private IEnumerator ProcessDiffuse() + { + Debug.Log("Processing Diffuse"); + + _blitMaterial.SetVector(ImageSize, new Vector4(_imageSizeX, _imageSizeY, 0, 0)); + + _blitMaterial.SetTexture(MainTex, _diffuseMapOriginal); + + _blitMaterial.SetTexture(BlurTex, _blurMap); + _blitMaterial.SetFloat(BlurContrast, _eds.BlurContrast); + + _blitMaterial.SetTexture(AvgTex, _avgMap); + + _blitMaterial.SetFloat(LightMaskPow, _eds.LightMaskPow); + _blitMaterial.SetFloat(LightPow, _eds.LightPow); + + _blitMaterial.SetFloat(DarkMaskPow, _eds.DarkMaskPow); + _blitMaterial.SetFloat(DarkPow, _eds.DarkPow); + + _blitMaterial.SetFloat(HotSpot, _eds.HotSpot); + _blitMaterial.SetFloat(DarkSpot, _eds.DarkSpot); + + _blitMaterial.SetFloat(FinalContrast, _eds.FinalContrast); + + _blitMaterial.SetFloat(FinalBias, _eds.FinalBias); + + _blitMaterial.SetFloat(ColorLerp, _eds.ColorLerp); + + _blitMaterial.SetFloat(Saturation, _eds.Saturation); + + CleanupTexture(_tempMap); + _tempMap = new RenderTexture(_imageSizeX, _imageSizeY, 0, RenderTextureFormat.ARGB32, + RenderTextureReadWrite.Linear) {wrapMode = TextureWrapMode.Repeat}; + + Graphics.Blit(_diffuseMapOriginal, _tempMap, _blitMaterial, 11); + + RenderTexture.active = _tempMap; + + if (MainGuiScript.DiffuseMap) + { + Destroy(MainGuiScript.DiffuseMap); + MainGuiScript.DiffuseMap = null; + } + + MainGuiScript.DiffuseMap = new Texture2D(_tempMap.width, _tempMap.height, TextureFormat.ARGB32, true, true); + MainGuiScript.DiffuseMap.ReadPixels(new Rect(0, 0, _tempMap.width, _tempMap.height), 0, 0); + MainGuiScript.DiffuseMap.Apply(); + + yield return new WaitForSeconds(0.1f); + + CleanupTexture(_tempMap); + } + + private IEnumerator ProcessBlur() + { + Debug.Log("Processing Blur"); + + CleanupTexture(_tempMap); + _tempMap = new RenderTexture(_imageSizeX, _imageSizeY, 0, RenderTextureFormat.ARGBHalf, + RenderTextureReadWrite.Linear) {wrapMode = TextureWrapMode.Repeat}; + + _blitMaterial.SetVector(ImageSize, new Vector4(_imageSizeX, _imageSizeY, 0, 0)); + _blitMaterial.SetFloat(BlurContrast, 1.0f); + _blitMaterial.SetFloat(BlurSpread, 1.0f); + + // Blur the image 1 + _blitMaterial.SetInt(BlurSamples, _eds.BlurSize); + _blitMaterial.SetVector(BlurDirection, new Vector4(1, 0, 0, 0)); + Graphics.Blit(_diffuseMapOriginal, _tempMap, _blitMaterial, 1); + _blitMaterial.SetVector(BlurDirection, new Vector4(0, 1, 0, 0)); + Graphics.Blit(_tempMap, _blurMap, _blitMaterial, 1); + ThisMaterial.SetTexture(BlurTex, _blurMap); + + + _blitMaterial.SetTexture(MainTex, _diffuseMapOriginal); + _blitMaterial.SetInt(BlurSamples, _eds.AvgColorBlurSize); + _blitMaterial.SetVector(BlurDirection, new Vector4(1, 0, 0, 0)); + Graphics.Blit(_diffuseMapOriginal, _tempMap, _blitMaterial, 1); + _blitMaterial.SetVector(BlurDirection, new Vector4(0, 1, 0, 0)); + Graphics.Blit(_tempMap, _avgMap, _blitMaterial, 1); + + _blitMaterial.SetFloat(BlurSpread, _eds.AvgColorBlurSize / 5.0f); + _blitMaterial.SetVector(BlurDirection, new Vector4(1, 0, 0, 0)); + Graphics.Blit(_avgMap, _tempMap, _blitMaterial, 1); + _blitMaterial.SetVector(BlurDirection, new Vector4(0, 1, 0, 0)); + Graphics.Blit(_tempMap, _avgMap, _blitMaterial, 1); + + ThisMaterial.SetTexture(AvgTex, _avgMap); + + CleanupTexture(_tempMap); + CleanupTexture(_avgTempMap); + + yield return new WaitForSeconds(0.01f); + } +} \ No newline at end of file diff --git a/Assets/Scripts/Editor/TextureImportTest.cs b/Assets/Scripts/Editor/TextureImportTest.cs index c37b4961..62ca5508 100644 --- a/Assets/Scripts/Editor/TextureImportTest.cs +++ b/Assets/Scripts/Editor/TextureImportTest.cs @@ -1,22 +1,23 @@ -using UnityEngine; -using System.Collections; -using System.IO; -using FreeImageAPI; +#region -public class TextureImportTest : MonoBehaviour { +using UnityEngine; - // Use this for initialization - void Start () { +#endregion - string PathToLoad = "test"; - - FIBITMAP bitmap = FreeImage.LoadEx (PathToLoad); - bool importSuccess = FreeImage.SaveEx (bitmap, Application.dataPath + "/tempImage.png", FREE_IMAGE_FORMAT.FIF_PNG); - - } - - // Update is called once per frame - void Update () { - - } -} +public class TextureImportTest : MonoBehaviour +{ +// // Use this for initialization +// void Start () { +// +// string PathToLoad = "test"; +// +// FIBITMAP bitmap = FreeImage.LoadEx (PathToLoad); +// bool importSuccess = FreeImage.SaveEx (bitmap, Application.dataPath + "/tempImage.png", FREE_IMAGE_FORMAT.FIF_PNG); +// +// } +// +// // Update is called once per frame +// void Update () { +// +// } +} \ No newline at end of file diff --git a/Assets/Scripts/GetColorFromLight.cs b/Assets/Scripts/GetColorFromLight.cs index 3b6e9ad7..5d3b692b 100644 --- a/Assets/Scripts/GetColorFromLight.cs +++ b/Assets/Scripts/GetColorFromLight.cs @@ -1,25 +1,25 @@ -using UnityEngine; -using System.Collections; +#region -public class GetColorFromLight : MonoBehaviour { +using UnityEngine; - Material thisMaterial; - Light thisLight; +#endregion - public GameObject lightObject; +public class GetColorFromLight : MonoBehaviour +{ + private static readonly int Color = Shader.PropertyToID("_Color"); + private Light _thisLight; - // Use this for initialization - void Start () { + private Material _thisMaterial; + public GameObject LightObject; - thisLight = lightObject.GetComponent (); - thisMaterial = this.GetComponent ().material; - - } - - // Update is called once per frame - void Update () { + private void Start() + { + _thisLight = LightObject.GetComponent(); + _thisMaterial = GetComponent().material; + } - thisMaterial.SetColor ("_Color", thisLight.color); - - } -} + private void Update() + { + _thisMaterial.SetColor(Color, _thisLight.color); + } +} \ No newline at end of file diff --git a/Assets/Scripts/HeightFromDiffuseGui.cs b/Assets/Scripts/HeightFromDiffuseGui.cs index cea8c8b4..3115071a 100644 --- a/Assets/Scripts/HeightFromDiffuseGui.cs +++ b/Assets/Scripts/HeightFromDiffuseGui.cs @@ -1,528 +1,428 @@ -using UnityEngine; -using System.Collections; -using System.ComponentModel; - -public class HeightFromDiffuseSettings { - - [DefaultValueAttribute(true)] - public bool useAdjustedDiffuse; - [DefaultValueAttribute(false)] - public bool useOriginalDiffuse; - [DefaultValueAttribute(false)] - public bool useNormal; - - - [DefaultValueAttribute(0.15f)] - public float Blur0Weight; - [DefaultValueAttribute(0.19f)] - public float Blur1Weight; - [DefaultValueAttribute(0.3f)] - public float Blur2Weight; - [DefaultValueAttribute(0.5f)] - public float Blur3Weight; - [DefaultValueAttribute(0.7f)] - public float Blur4Weight; - [DefaultValueAttribute(0.9f)] - public float Blur5Weight; - [DefaultValueAttribute(1.0f)] - public float Blur6Weight; - - [DefaultValueAttribute(1.0f)] - public float Blur0Contrast; - [DefaultValueAttribute(1.0f)] - public float Blur1Contrast; - [DefaultValueAttribute(1.0f)] - public float Blur2Contrast; - [DefaultValueAttribute(1.0f)] - public float Blur3Contrast; - [DefaultValueAttribute(1.0f)] - public float Blur4Contrast; - [DefaultValueAttribute(1.0f)] - public float Blur5Contrast; - [DefaultValueAttribute(1.0f)] - public float Blur6Contrast; - - [DefaultValueAttribute(1.5f)] - public float FinalContrast; - [DefaultValueAttribute("1.5")] - public string FinalContrastText; - - [DefaultValueAttribute(0.0f)] - public float FinalBias; - [DefaultValueAttribute("0")] - public string FinalBiasText; - - [DefaultValueAttribute(0.0f)] - public float FinalGain; - [DefaultValueAttribute("0")] - public string FinalGainText; - - //[DefaultValueAttribute(Color.black)] - public Color SampleColor1; - //[DefaultValueAttribute(Vector2.zero)] - public Vector2 SampleUV1; - [DefaultValueAttribute(false)] - public bool UseSample1; - [DefaultValueAttribute(false)] - public bool IsolateSample1; - [DefaultValueAttribute(1.0f)] - public float HueWeight1; - [DefaultValueAttribute(0.5f)] - public float SatWeight1; - [DefaultValueAttribute(0.2f)] - public float LumWeight1; - [DefaultValueAttribute(0.0f)] - public float MaskLow1; - [DefaultValueAttribute(1.0f)] - public float MaskHigh1; - [DefaultValueAttribute(0.5f)] - public float Sample1Height; - - //[DefaultValueAttribute(Color.black)] - public Color SampleColor2; - //[DefaultValueAttribute(Vector2.zero)] - public Vector2 SampleUV2; - [DefaultValueAttribute(false)] - public bool UseSample2; - [DefaultValueAttribute(false)] - public bool IsolateSample2; - [DefaultValueAttribute(1.0f)] - public float HueWeight2; - [DefaultValueAttribute(0.5f)] - public float SatWeight2; - [DefaultValueAttribute(0.2f)] - public float LumWeight2; - [DefaultValueAttribute(0.0f)] - public float MaskLow2; - [DefaultValueAttribute(1.0f)] - public float MaskHigh2; - [DefaultValueAttribute(0.5f)] - public float Sample2Height; - - [DefaultValueAttribute(0.5f)] - public float SampleBlend; - [DefaultValueAttribute("0.5")] - public string SampleBlendText; - - [DefaultValueAttribute(50.0f)] - public float Spread; - [DefaultValueAttribute("50")] - public string SpreadText; - - [DefaultValueAttribute(1.0f)] - public float SpreadBoost; - [DefaultValueAttribute("1")] - public string SpreadBoostText; - - public HeightFromDiffuseSettings(){ - - this.useAdjustedDiffuse = true; - this.useOriginalDiffuse = false; - this.useNormal = false; - - this.Blur0Weight = 0.15f; - this.Blur1Weight = 0.19f; - this.Blur2Weight = 0.3f; - this.Blur3Weight = 0.5f; - this.Blur4Weight = 0.7f; - this.Blur5Weight = 0.9f; - this.Blur6Weight = 1.0f; - - this.Blur0Contrast = 1.0f; - this.Blur1Contrast = 1.0f; - this.Blur2Contrast = 1.0f; - this.Blur3Contrast = 1.0f; - this.Blur4Contrast = 1.0f; - this.Blur5Contrast = 1.0f; - this.Blur6Contrast = 1.0f; - - this.SampleColor1 = Color.black; - this.SampleUV1 = Vector2.zero; - this.UseSample1 = false; - this.IsolateSample1 = false; - this.HueWeight1 = 1.0f; - this.SatWeight1 = 0.5f; - this.LumWeight1 = 0.2f; - this.MaskLow1 = 0.0f; - this.MaskHigh1 = 1.0f; - this.Sample1Height = 0.5f; - - this.SampleColor2 = Color.black; - this.SampleUV2 = Vector2.zero; - this.UseSample2 = false; - this.IsolateSample2 = false; - this.HueWeight2 = 1.0f; - this.SatWeight2 = 0.5f; - this.LumWeight2 = 0.2f; - this.MaskLow2 = 0.0f; - this.MaskHigh2 = 1.0f; - this.Sample2Height = 0.3f; - - this.FinalContrast = 1.5f; - this.FinalContrastText = "1.5"; - - this.FinalBias = 0.0f; - this.FinalBiasText = "0.0"; - - this.FinalGain = 0.0f; - this.FinalGainText = "0.0"; - - this.SampleBlend = 0.5f; - this.SampleBlendText = "0.5"; - - this.Spread = 50.0f; - this.SpreadText = "50"; - - this.SpreadBoost = 1.0f; - this.SpreadBoostText = "1"; - } -} - -public class HeightFromDiffuseGui : MonoBehaviour { - - public MainGui MainGuiScript; - - RenderTexture _TempBlurMap; - RenderTexture _BlurMap0; - RenderTexture _BlurMap1; - RenderTexture _BlurMap2; - RenderTexture _BlurMap3; - RenderTexture _BlurMap4; - RenderTexture _BlurMap5; - RenderTexture _BlurMap6; - RenderTexture _TempHeightMap; - - RenderTexture _AvgTempMap; - RenderTexture _AvgMap; - - float _BlurScale = 1.0f; - int imageSizeX = 1024; - int imageSizeY = 1024; - - public Material thisMaterial; - Material blitMaterial; - Material blitMaterialSample; - Material blitMaterialNormal; - - HeightFromDiffuseSettings HFDS; - - float LastBlur0Contrast = 1.0f; - - int currentSelection = 0; - bool selectingColor = false; - bool mouseButtonDown = false; - - Texture2D _SampleColorMap1; - Texture2D _SampleColorMap2; - - float Slider = 0.5f; - - bool lastUseDiffuse = false; - bool lastUseOriginalDiffuse = false; - bool lastUseNormal = false; - - public GameObject testObject; - bool doStuff = false; - bool newTexture = false; - - Rect windowRect = new Rect (30, 300, 300, 480); - bool settingsInitialized = false; - - public bool busy = false; - - public void GetValues( ProjectObject projectObject ) { - InitializeSettings (); - projectObject.HFDS = HFDS; - } - - public void SetValues( ProjectObject projectObject ) { - InitializeSettings (); - if (projectObject.HFDS != null) { - HFDS = projectObject.HFDS; - } else { - settingsInitialized = false; - InitializeSettings (); - } - - _SampleColorMap1.SetPixel (1, 1, HFDS.SampleColor1); - _SampleColorMap1.Apply (); +#region - _SampleColorMap2.SetPixel (1, 1, HFDS.SampleColor2); - _SampleColorMap2.Apply (); +using System; +using System.Collections; +using UnityEngine; + +#endregion + +// ReSharper disable SpecifyACultureInStringConversionExplicitly + +public class HeightFromDiffuseGui : MonoBehaviour +{ + private const float BlurScale = 1.0f; + private static readonly int BlurScaleId = Shader.PropertyToID("_BlurScale"); + private static readonly int ImageSize = Shader.PropertyToID("_ImageSize"); + private static readonly int Isolate = Shader.PropertyToID("_Isolate"); + private static readonly int Blur0Weight = Shader.PropertyToID("_Blur0Weight"); + private static readonly int Blur1Weight = Shader.PropertyToID("_Blur1Weight"); + private static readonly int Blur2Weight = Shader.PropertyToID("_Blur2Weight"); + private static readonly int Blur3Weight = Shader.PropertyToID("_Blur3Weight"); + private static readonly int Blur4Weight = Shader.PropertyToID("_Blur4Weight"); + private static readonly int Blur5Weight = Shader.PropertyToID("_Blur5Weight"); + private static readonly int Blur6Weight = Shader.PropertyToID("_Blur6Weight"); + private static readonly int Blur0Contrast = Shader.PropertyToID("_Blur0Contrast"); + private static readonly int Blur1Contrast = Shader.PropertyToID("_Blur1Contrast"); + private static readonly int Blur2Contrast = Shader.PropertyToID("_Blur2Contrast"); + private static readonly int Blur3Contrast = Shader.PropertyToID("_Blur3Contrast"); + private static readonly int Blur4Contrast = Shader.PropertyToID("_Blur4Contrast"); + private static readonly int Blur5Contrast = Shader.PropertyToID("_Blur5Contrast"); + private static readonly int Blur6Contrast = Shader.PropertyToID("_Blur6Contrast"); + private static readonly int FinalGain = Shader.PropertyToID("_FinalGain"); + private static readonly int FinalContrast = Shader.PropertyToID("_FinalContrast"); + private static readonly int FinalBias = Shader.PropertyToID("_FinalBias"); + private static readonly int Slider = Shader.PropertyToID("_Slider"); + private static readonly int BlurTex0 = Shader.PropertyToID("_BlurTex0"); + private static readonly int HeightFromNormal = Shader.PropertyToID("_HeightFromNormal"); + private static readonly int BlurTex1 = Shader.PropertyToID("_BlurTex1"); + private static readonly int BlurTex2 = Shader.PropertyToID("_BlurTex2"); + private static readonly int BlurTex3 = Shader.PropertyToID("_BlurTex3"); + private static readonly int BlurTex4 = Shader.PropertyToID("_BlurTex4"); + private static readonly int BlurTex5 = Shader.PropertyToID("_BlurTex5"); + private static readonly int BlurTex6 = Shader.PropertyToID("_BlurTex6"); + private static readonly int AvgTex = Shader.PropertyToID("_AvgTex"); + private static readonly int Spread = Shader.PropertyToID("_Spread"); + private static readonly int SpreadBoost = Shader.PropertyToID("_SpreadBoost"); + private static readonly int Samples = Shader.PropertyToID("_Samples"); + private static readonly int MainTex = Shader.PropertyToID("_MainTex"); + private static readonly int BlendTex = Shader.PropertyToID("_BlendTex"); + private static readonly int IsNormal = Shader.PropertyToID("_IsNormal"); + private static readonly int BlendAmount = Shader.PropertyToID("_BlendAmount"); + private static readonly int Progress = Shader.PropertyToID("_Progress"); + private static readonly int IsolateSample1 = Shader.PropertyToID("_IsolateSample1"); + private static readonly int UseSample1 = Shader.PropertyToID("_UseSample1"); + private static readonly int SampleColor1 = Shader.PropertyToID("_SampleColor1"); + private static readonly int SampleUv1 = Shader.PropertyToID("_SampleUV1"); + private static readonly int HueWeight1 = Shader.PropertyToID("_HueWeight1"); + private static readonly int SatWeight1 = Shader.PropertyToID("_SatWeight1"); + private static readonly int LumWeight1 = Shader.PropertyToID("_LumWeight1"); + private static readonly int MaskLow1 = Shader.PropertyToID("_MaskLow1"); + private static readonly int MaskHigh1 = Shader.PropertyToID("_MaskHigh1"); + private static readonly int Sample1Height = Shader.PropertyToID("_Sample1Height"); + private static readonly int IsolateSample2 = Shader.PropertyToID("_IsolateSample2"); + private static readonly int UseSample2 = Shader.PropertyToID("_UseSample2"); + private static readonly int SampleColor2 = Shader.PropertyToID("_SampleColor2"); + private static readonly int SampleUv2 = Shader.PropertyToID("_SampleUV2"); + private static readonly int HueWeight2 = Shader.PropertyToID("_HueWeight2"); + private static readonly int SatWeight2 = Shader.PropertyToID("_SatWeight2"); + private static readonly int LumWeight2 = Shader.PropertyToID("_LumWeight2"); + private static readonly int MaskLow2 = Shader.PropertyToID("_MaskLow2"); + private static readonly int MaskHigh2 = Shader.PropertyToID("_MaskHigh2"); + private static readonly int Sample2Height = Shader.PropertyToID("_Sample2Height"); + private static readonly int SampleBlend = Shader.PropertyToID("_SampleBlend"); + private static readonly int BlurContrast = Shader.PropertyToID("_BlurContrast"); + private static readonly int BlurSamples = Shader.PropertyToID("_BlurSamples"); + private static readonly int BlurSpread = Shader.PropertyToID("_BlurSpread"); + private static readonly int BlurDirection = Shader.PropertyToID("_BlurDirection"); + private RenderTexture _avgMap; + + private RenderTexture _avgTempMap; + private Material _blitMaterial; + private Material _blitMaterialNormal; + private Material _blitMaterialSample; + private RenderTexture _blurMap0; + private RenderTexture _blurMap1; + private RenderTexture _blurMap2; + private RenderTexture _blurMap3; + private RenderTexture _blurMap4; + private RenderTexture _blurMap5; + private RenderTexture _blurMap6; + private Camera _camera; + + private int _currentSelection; + private bool _doStuff; + + private HeightFromDiffuseSettings _heightFromDiffuseSettings; + private int _imageSizeX = 1024; + private int _imageSizeY = 1024; + + private float _lastBlur0Contrast = 1.0f; + + private bool _lastUseDiffuse; + private bool _lastUseNormal; + private bool _lastUseOriginalDiffuse; + private bool _mouseButtonDown; + private bool _newTexture; + + private Texture2D _sampleColorMap1; + private Texture2D _sampleColorMap2; + private bool _selectingColor; + private bool _settingsInitialized; + + private float _slider = 0.5f; + + private RenderTexture _tempBlurMap; + private RenderTexture _tempHeightMap; + + private Rect _windowRect = new Rect(30, 300, 300, 480); + + [HideInInspector] public bool Busy; + + public MainGui MainGuiScript; + + public GameObject TestObject; + + public Material ThisMaterial; + + public void GetValues(ProjectObject projectObject) + { + InitializeSettings(); + projectObject.HeightFromDiffuseSettings = _heightFromDiffuseSettings; + } - doStuff = true; - } + public void SetValues(ProjectObject projectObject) + { + InitializeSettings(); + if (projectObject.HeightFromDiffuseSettings != null) + { + _heightFromDiffuseSettings = projectObject.HeightFromDiffuseSettings; + } + else + { + _settingsInitialized = false; + InitializeSettings(); + } - void InitializeSettings() { + _sampleColorMap1.SetPixel(1, 1, _heightFromDiffuseSettings.SampleColor1); + _sampleColorMap1.Apply(); - if (settingsInitialized == false) { - Debug.Log ("Initializing Height From Diffuse Settings"); + _sampleColorMap2.SetPixel(1, 1, _heightFromDiffuseSettings.SampleColor2); + _sampleColorMap2.Apply(); - HFDS = new HeightFromDiffuseSettings (); + _doStuff = true; + } - if (_SampleColorMap1) { - Destroy (_SampleColorMap1); - } - _SampleColorMap1 = new Texture2D (1, 1, TextureFormat.ARGB32, false, true); - _SampleColorMap1.SetPixel (1, 1, HFDS.SampleColor1); - _SampleColorMap1.Apply (); + private void InitializeSettings() + { + if (_settingsInitialized) return; +// Debug.Log("Initializing Height From Diffuse Settings"); - if (_SampleColorMap2) { - Destroy (_SampleColorMap2); - } - _SampleColorMap2 = new Texture2D (1, 1, TextureFormat.ARGB32, false, true); - _SampleColorMap2.SetPixel (1, 1, HFDS.SampleColor2); - _SampleColorMap2.Apply (); + _heightFromDiffuseSettings = new HeightFromDiffuseSettings(); - settingsInitialized = true; - } + if (_sampleColorMap1) Destroy(_sampleColorMap1); + _sampleColorMap1 = new Texture2D(1, 1, TextureFormat.ARGB32, false, true); + _sampleColorMap1.SetPixel(1, 1, _heightFromDiffuseSettings.SampleColor1); + _sampleColorMap1.Apply(); - } + if (_sampleColorMap2) Destroy(_sampleColorMap2); + _sampleColorMap2 = new Texture2D(1, 1, TextureFormat.ARGB32, false, true); + _sampleColorMap2.SetPixel(1, 1, _heightFromDiffuseSettings.SampleColor2); + _sampleColorMap2.Apply(); - // Use this for initialization - void Start () { + _settingsInitialized = true; + } + // Use this for initialization + private void Start() + { + _camera = Camera.main; Resources.UnloadUnusedAssets(); - //MainGuiScript = MainGui.instance; + //MainGuiScript = MainGui.instance; - testObject.GetComponent().sharedMaterial = thisMaterial; - blitMaterial = new Material (Shader.Find ("Hidden/Blit_Shader")); - blitMaterialSample = new Material (Shader.Find ("Hidden/Blit_Sample")); - blitMaterialNormal = new Material(Shader.Find("Hidden/Blit_Height_From_Normal")); + TestObject.GetComponent().sharedMaterial = ThisMaterial; + _blitMaterial = new Material(Shader.Find("Hidden/Blit_Shader")); + _blitMaterialSample = new Material(Shader.Find("Hidden/Blit_Sample")); + _blitMaterialNormal = new Material(Shader.Find("Hidden/Blit_Height_From_Normal")); - InitializeSettings(); + InitializeSettings(); - if (newTexture) + if (_newTexture) { InitializeTextures(); - newTexture = false; + _newTexture = false; } - - FixUseMaps (); - - lastUseDiffuse = HFDS.useAdjustedDiffuse; - lastUseOriginalDiffuse = HFDS.useOriginalDiffuse; - lastUseNormal = HFDS.useNormal; - LastBlur0Contrast = HFDS.Blur0Contrast; - - SetMaterialValues(); - } - - void FixUseMaps(){ - - if (MainGuiScript._DiffuseMapOriginal == null && HFDS.useOriginalDiffuse) { - HFDS.useAdjustedDiffuse = true; - HFDS.useOriginalDiffuse = false; - HFDS.useNormal = false; - } - - if (MainGuiScript._DiffuseMap == null && HFDS.useAdjustedDiffuse) { - HFDS.useAdjustedDiffuse = false; - HFDS.useOriginalDiffuse = true; - HFDS.useNormal = false; - } - - if (MainGuiScript._NormalMap == null && HFDS.useNormal) { - HFDS.useAdjustedDiffuse = true; - HFDS.useOriginalDiffuse = false; - HFDS.useNormal = false; - } - - if (MainGuiScript._DiffuseMapOriginal == null & MainGuiScript._NormalMap == null) - { - HFDS.useAdjustedDiffuse = true; - HFDS.useOriginalDiffuse = false; - HFDS.useNormal = false; - } - - if (MainGuiScript._DiffuseMap == null && MainGuiScript._NormalMap == null) - { - HFDS.useAdjustedDiffuse = false; - HFDS.useOriginalDiffuse = true; - HFDS.useNormal = false; - } - - if (MainGuiScript._DiffuseMap == null && MainGuiScript._DiffuseMapOriginal == null) - { - HFDS.useAdjustedDiffuse = false; - HFDS.useOriginalDiffuse = false; - HFDS.useNormal = true; - } - } - - public void DoStuff() { - doStuff = true; - } - - public void NewTexture() { - newTexture = true; - } - - void SetMaterialValues() { - - thisMaterial.SetFloat ("_BlurScale", _BlurScale); - thisMaterial.SetVector ("_ImageSize", new Vector4( imageSizeX, imageSizeY, 0, 0 )); - - } - - void SetWeightEQDefault() { - HFDS.Blur0Weight = 0.15f; - HFDS.Blur1Weight = 0.19f; - HFDS.Blur2Weight = 0.3f; - HFDS.Blur3Weight = 0.5f; - HFDS.Blur4Weight = 0.7f; - HFDS.Blur5Weight = 0.9f; - HFDS.Blur6Weight = 1.0f; - doStuff = true; - } - - void SetWeightEQDetail() { - HFDS.Blur0Weight = 0.7f; - HFDS.Blur1Weight = 0.4f; - HFDS.Blur2Weight = 0.3f; - HFDS.Blur3Weight = 0.5f; - HFDS.Blur4Weight = 0.8f; - HFDS.Blur5Weight = 0.9f; - HFDS.Blur6Weight = 0.7f; - doStuff = true; - } - - void SetWeightEQDisplace() { - HFDS.Blur0Weight = 0.02f; - HFDS.Blur1Weight = 0.03f; - HFDS.Blur2Weight = 0.1f; - HFDS.Blur3Weight = 0.35f; - HFDS.Blur4Weight = 0.7f; - HFDS.Blur5Weight = 0.9f; - HFDS.Blur6Weight = 1.0f; - doStuff = true; - } - - void SetContrastEQDefault() { - HFDS.Blur0Contrast = 1.0f; - HFDS.Blur1Contrast = 1.0f; - HFDS.Blur2Contrast = 1.0f; - HFDS.Blur3Contrast = 1.0f; - HFDS.Blur4Contrast = 1.0f; - HFDS.Blur5Contrast = 1.0f; - HFDS.Blur6Contrast = 1.0f; - doStuff = true; - } - - void SetContrastEQCrackedMud() { - HFDS.Blur0Contrast = 1.0f; - HFDS.Blur1Contrast = 1.0f; - HFDS.Blur2Contrast = 1.0f; - HFDS.Blur3Contrast = 1.0f; - HFDS.Blur4Contrast = -0.2f; - HFDS.Blur5Contrast = -2.0f; - HFDS.Blur6Contrast = -4.0f; - doStuff = true; - } - - void SetContrastEQFunky() { - HFDS.Blur0Contrast = -3.0f; - HFDS.Blur1Contrast = -1.2f; - HFDS.Blur2Contrast = 0.30f; - HFDS.Blur3Contrast = 1.3f; - HFDS.Blur4Contrast = 2.0f; - HFDS.Blur5Contrast = 2.5f; - HFDS.Blur6Contrast = 2.0f; - doStuff = true; - } - - void SelectColor() { - if ( Input.GetMouseButton(0) ) { - - mouseButtonDown = true; - - RaycastHit hit; - if (!Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit)) - return; - - Renderer rend = hit.transform.GetComponent(); - MeshCollider meshCollider = hit.collider as MeshCollider; - if (rend == null || rend.sharedMaterial == null || rend.sharedMaterial.mainTexture == null || meshCollider == null) - return; - - Vector2 pixelUV = hit.textureCoord; - - Color sampledColor = Color.black; - if( HFDS.useAdjustedDiffuse){ - sampledColor = MainGuiScript._DiffuseMap.GetPixelBilinear(pixelUV.x, pixelUV.y); - }else{ - sampledColor = MainGuiScript._DiffuseMapOriginal.GetPixelBilinear(pixelUV.x, pixelUV.y); - } - - if( currentSelection == 1 ){ - HFDS.SampleUV1 = pixelUV; - HFDS.SampleColor1 = sampledColor; - _SampleColorMap1.SetPixel (1, 1, HFDS.SampleColor1); - _SampleColorMap1.Apply (); - } - - if( currentSelection == 2 ){ - HFDS.SampleUV2 = pixelUV; - HFDS.SampleColor2 = sampledColor; - _SampleColorMap2.SetPixel (1, 1, HFDS.SampleColor2); - _SampleColorMap2.Apply (); - } - - doStuff = true; - - } - - if ( Input.GetMouseButtonUp(0) && mouseButtonDown ) { - - mouseButtonDown = false; - selectingColor = false; - currentSelection = 0; - - } - - } - - // Update is called once per frame - void Update () { - - if (selectingColor) { - SelectColor(); - } - - if (HFDS.useAdjustedDiffuse != lastUseDiffuse) { - lastUseDiffuse = HFDS.useAdjustedDiffuse; - doStuff = true; - } - - if (HFDS.useOriginalDiffuse != lastUseOriginalDiffuse) + + FixUseMaps(); + + _lastUseDiffuse = _heightFromDiffuseSettings.UseAdjustedDiffuse; + _lastUseOriginalDiffuse = _heightFromDiffuseSettings.UseOriginalDiffuse; + _lastUseNormal = _heightFromDiffuseSettings.UseNormal; + _lastBlur0Contrast = _heightFromDiffuseSettings.Blur0Contrast; + + SetMaterialValues(); + } + + private void FixUseMaps() + { + if (MainGuiScript.DiffuseMapOriginal == null && _heightFromDiffuseSettings.UseOriginalDiffuse) { - lastUseOriginalDiffuse = HFDS.useOriginalDiffuse; - doStuff = true; + _heightFromDiffuseSettings.UseAdjustedDiffuse = true; + _heightFromDiffuseSettings.UseOriginalDiffuse = false; + _heightFromDiffuseSettings.UseNormal = false; } - if (HFDS.useNormal != lastUseNormal) + if (MainGuiScript.DiffuseMap == null && _heightFromDiffuseSettings.UseAdjustedDiffuse) { - lastUseNormal = HFDS.useNormal; - doStuff = true; + _heightFromDiffuseSettings.UseAdjustedDiffuse = false; + _heightFromDiffuseSettings.UseOriginalDiffuse = true; + _heightFromDiffuseSettings.UseNormal = false; } - if (HFDS.Blur0Contrast != LastBlur0Contrast) + if (MainGuiScript.NormalMap == null && _heightFromDiffuseSettings.UseNormal) { - LastBlur0Contrast = HFDS.Blur0Contrast; - doStuff = true; - } - - if (newTexture) + _heightFromDiffuseSettings.UseAdjustedDiffuse = true; + _heightFromDiffuseSettings.UseOriginalDiffuse = false; + _heightFromDiffuseSettings.UseNormal = false; + } + + if ((MainGuiScript.DiffuseMapOriginal == null) & (MainGuiScript.NormalMap == null)) { - InitializeTextures(); - newTexture = false; - } + _heightFromDiffuseSettings.UseAdjustedDiffuse = true; + _heightFromDiffuseSettings.UseOriginalDiffuse = false; + _heightFromDiffuseSettings.UseNormal = false; + } - if (doStuff) + if (MainGuiScript.DiffuseMap == null && MainGuiScript.NormalMap == null) { + _heightFromDiffuseSettings.UseAdjustedDiffuse = false; + _heightFromDiffuseSettings.UseOriginalDiffuse = true; + _heightFromDiffuseSettings.UseNormal = false; + } + + if (MainGuiScript.DiffuseMap != null || MainGuiScript.DiffuseMapOriginal != null) return; + _heightFromDiffuseSettings.UseAdjustedDiffuse = false; + _heightFromDiffuseSettings.UseOriginalDiffuse = false; + _heightFromDiffuseSettings.UseNormal = true; + } + + public void DoStuff() + { + _doStuff = true; + } + + public void NewTexture() + { + _newTexture = true; + } - if (HFDS.useNormal) + private void SetMaterialValues() + { + ThisMaterial.SetFloat(BlurScaleId, BlurScale); + ThisMaterial.SetVector(ImageSize, new Vector4(_imageSizeX, _imageSizeY, 0, 0)); + } + + private void SetWeightEqDefault() + { + _heightFromDiffuseSettings.Blur0Weight = 0.15f; + _heightFromDiffuseSettings.Blur1Weight = 0.19f; + _heightFromDiffuseSettings.Blur2Weight = 0.3f; + _heightFromDiffuseSettings.Blur3Weight = 0.5f; + _heightFromDiffuseSettings.Blur4Weight = 0.7f; + _heightFromDiffuseSettings.Blur5Weight = 0.9f; + _heightFromDiffuseSettings.Blur6Weight = 1.0f; + _doStuff = true; + } + + private void SetWeightEqDetail() + { + _heightFromDiffuseSettings.Blur0Weight = 0.7f; + _heightFromDiffuseSettings.Blur1Weight = 0.4f; + _heightFromDiffuseSettings.Blur2Weight = 0.3f; + _heightFromDiffuseSettings.Blur3Weight = 0.5f; + _heightFromDiffuseSettings.Blur4Weight = 0.8f; + _heightFromDiffuseSettings.Blur5Weight = 0.9f; + _heightFromDiffuseSettings.Blur6Weight = 0.7f; + _doStuff = true; + } + + private void SetWeightEqDisplace() + { + _heightFromDiffuseSettings.Blur0Weight = 0.02f; + _heightFromDiffuseSettings.Blur1Weight = 0.03f; + _heightFromDiffuseSettings.Blur2Weight = 0.1f; + _heightFromDiffuseSettings.Blur3Weight = 0.35f; + _heightFromDiffuseSettings.Blur4Weight = 0.7f; + _heightFromDiffuseSettings.Blur5Weight = 0.9f; + _heightFromDiffuseSettings.Blur6Weight = 1.0f; + _doStuff = true; + } + + private void SetContrastEqDefault() + { + _heightFromDiffuseSettings.Blur0Contrast = 1.0f; + _heightFromDiffuseSettings.Blur1Contrast = 1.0f; + _heightFromDiffuseSettings.Blur2Contrast = 1.0f; + _heightFromDiffuseSettings.Blur3Contrast = 1.0f; + _heightFromDiffuseSettings.Blur4Contrast = 1.0f; + _heightFromDiffuseSettings.Blur5Contrast = 1.0f; + _heightFromDiffuseSettings.Blur6Contrast = 1.0f; + _doStuff = true; + } + + private void SetContrastEqCrackedMud() + { + _heightFromDiffuseSettings.Blur0Contrast = 1.0f; + _heightFromDiffuseSettings.Blur1Contrast = 1.0f; + _heightFromDiffuseSettings.Blur2Contrast = 1.0f; + _heightFromDiffuseSettings.Blur3Contrast = 1.0f; + _heightFromDiffuseSettings.Blur4Contrast = -0.2f; + _heightFromDiffuseSettings.Blur5Contrast = -2.0f; + _heightFromDiffuseSettings.Blur6Contrast = -4.0f; + _doStuff = true; + } + + private void SetContrastEqFunky() + { + _heightFromDiffuseSettings.Blur0Contrast = -3.0f; + _heightFromDiffuseSettings.Blur1Contrast = -1.2f; + _heightFromDiffuseSettings.Blur2Contrast = 0.30f; + _heightFromDiffuseSettings.Blur3Contrast = 1.3f; + _heightFromDiffuseSettings.Blur4Contrast = 2.0f; + _heightFromDiffuseSettings.Blur5Contrast = 2.5f; + _heightFromDiffuseSettings.Blur6Contrast = 2.0f; + _doStuff = true; + } + + private void SelectColor() + { + if (Input.GetMouseButton(0)) + { + _mouseButtonDown = true; + if (!_camera) return; + + if (!Physics.Raycast(_camera.ScreenPointToRay(Input.mousePosition), out var hit)) + return; + + var rend = hit.transform.GetComponent(); + var meshCollider = hit.collider as MeshCollider; + if (!rend || !rend.sharedMaterial || !rend.sharedMaterial.mainTexture || + !meshCollider) + return; + + var pixelUv = hit.textureCoord; + + var useAdjusted = _heightFromDiffuseSettings.UseAdjustedDiffuse; + var sampledColor = useAdjusted + ? MainGuiScript.DiffuseMap.GetPixelBilinear(pixelUv.x, pixelUv.y) + : MainGuiScript.DiffuseMapOriginal.GetPixelBilinear(pixelUv.x, pixelUv.y); + + switch (_currentSelection) + { + case 1: + _heightFromDiffuseSettings.SampleUv1 = pixelUv; + _heightFromDiffuseSettings.SampleColor1 = sampledColor; + _sampleColorMap1.SetPixel(1, 1, _heightFromDiffuseSettings.SampleColor1); + _sampleColorMap1.Apply(); + break; + case 2: + _heightFromDiffuseSettings.SampleUv2 = pixelUv; + _heightFromDiffuseSettings.SampleColor2 = sampledColor; + _sampleColorMap2.SetPixel(1, 1, _heightFromDiffuseSettings.SampleColor2); + _sampleColorMap2.Apply(); + break; + default: + throw new InvalidOperationException(); + } + + _doStuff = true; + } + + if (!Input.GetMouseButtonUp(0) || !_mouseButtonDown) return; + + _mouseButtonDown = false; + _selectingColor = false; + _currentSelection = 0; + } + + // Update is called once per frame + private void Update() + { + if (_selectingColor) SelectColor(); + + if (_heightFromDiffuseSettings.UseAdjustedDiffuse != _lastUseDiffuse) + { + _lastUseDiffuse = _heightFromDiffuseSettings.UseAdjustedDiffuse; + _doStuff = true; + } + + if (_heightFromDiffuseSettings.UseOriginalDiffuse != _lastUseOriginalDiffuse) + { + _lastUseOriginalDiffuse = _heightFromDiffuseSettings.UseOriginalDiffuse; + _doStuff = true; + } + + if (_heightFromDiffuseSettings.UseNormal != _lastUseNormal) + { + _lastUseNormal = _heightFromDiffuseSettings.UseNormal; + _doStuff = true; + } + + if (Math.Abs(_heightFromDiffuseSettings.Blur0Contrast - _lastBlur0Contrast) > 0.001f) + { + _lastBlur0Contrast = _heightFromDiffuseSettings.Blur0Contrast; + _doStuff = true; + } + + if (_newTexture) + { + InitializeTextures(); + _newTexture = false; + } + + if (_doStuff) + { + if (_heightFromDiffuseSettings.UseNormal) { StopAllCoroutines(); StartCoroutine(ProcessNormal()); @@ -532,171 +432,174 @@ void Update () { StopAllCoroutines(); StartCoroutine(ProcessDiffuse()); } - - doStuff = false; - } - - if (HFDS.IsolateSample1 || HFDS.IsolateSample2) { - thisMaterial.SetInt ("_Isolate", 1); - } else { - thisMaterial.SetInt ("_Isolate", 0); - } - - thisMaterial.SetFloat ("_Blur0Weight", HFDS.Blur0Weight); - thisMaterial.SetFloat ("_Blur1Weight", HFDS.Blur1Weight); - thisMaterial.SetFloat ("_Blur2Weight", HFDS.Blur2Weight); - thisMaterial.SetFloat ("_Blur3Weight", HFDS.Blur3Weight); - thisMaterial.SetFloat ("_Blur4Weight", HFDS.Blur4Weight); - thisMaterial.SetFloat ("_Blur5Weight", HFDS.Blur5Weight); - thisMaterial.SetFloat ("_Blur6Weight", HFDS.Blur6Weight); - - thisMaterial.SetFloat ("_Blur0Contrast", HFDS.Blur0Contrast); - thisMaterial.SetFloat ("_Blur1Contrast", HFDS.Blur1Contrast); - thisMaterial.SetFloat ("_Blur2Contrast", HFDS.Blur2Contrast); - thisMaterial.SetFloat ("_Blur3Contrast", HFDS.Blur3Contrast); - thisMaterial.SetFloat ("_Blur4Contrast", HFDS.Blur4Contrast); - thisMaterial.SetFloat ("_Blur5Contrast", HFDS.Blur5Contrast); - thisMaterial.SetFloat ("_Blur6Contrast", HFDS.Blur6Contrast); - - float realGain = HFDS.FinalGain; - if (realGain < 0.0f) { - realGain = Mathf.Abs( 1.0f / ( realGain - 1.0f ) ); - } else { - realGain = realGain + 1.0f; - } - - thisMaterial.SetFloat ("_FinalGain", realGain); - thisMaterial.SetFloat ("_FinalContrast", HFDS.FinalContrast); - thisMaterial.SetFloat ("_FinalBias", HFDS.FinalBias); - - thisMaterial.SetFloat ("_Slider", Slider); - - } - - string FloatToString ( float num, int length ) { - - string numString = num.ToString (); - int numStringLength = numString.Length; - int lastIndex = Mathf.FloorToInt( Mathf.Min ( (float)numStringLength , (float)length ) ); - - return numString.Substring (0, lastIndex); - } - - void DoMyWindow ( int windowID ) { - - int offsetX = 10; - int offsetY = 30; - - if (MainGuiScript._DiffuseMap != null) { GUI.enabled = true; } else { GUI.enabled = false; } - HFDS.useAdjustedDiffuse = GUI.Toggle(new Rect(offsetX, offsetY, 80, 30), HFDS.useAdjustedDiffuse, " Diffuse"); - if (HFDS.useAdjustedDiffuse) + + _doStuff = false; + } + + if (_heightFromDiffuseSettings.IsolateSample1 || _heightFromDiffuseSettings.IsolateSample2) + ThisMaterial.SetInt(Isolate, 1); + else + ThisMaterial.SetInt(Isolate, 0); + + ThisMaterial.SetFloat(Blur0Weight, _heightFromDiffuseSettings.Blur0Weight); + ThisMaterial.SetFloat(Blur1Weight, _heightFromDiffuseSettings.Blur1Weight); + ThisMaterial.SetFloat(Blur2Weight, _heightFromDiffuseSettings.Blur2Weight); + ThisMaterial.SetFloat(Blur3Weight, _heightFromDiffuseSettings.Blur3Weight); + ThisMaterial.SetFloat(Blur4Weight, _heightFromDiffuseSettings.Blur4Weight); + ThisMaterial.SetFloat(Blur5Weight, _heightFromDiffuseSettings.Blur5Weight); + ThisMaterial.SetFloat(Blur6Weight, _heightFromDiffuseSettings.Blur6Weight); + + ThisMaterial.SetFloat(Blur0Contrast, _heightFromDiffuseSettings.Blur0Contrast); + ThisMaterial.SetFloat(Blur1Contrast, _heightFromDiffuseSettings.Blur1Contrast); + ThisMaterial.SetFloat(Blur2Contrast, _heightFromDiffuseSettings.Blur2Contrast); + ThisMaterial.SetFloat(Blur3Contrast, _heightFromDiffuseSettings.Blur3Contrast); + ThisMaterial.SetFloat(Blur4Contrast, _heightFromDiffuseSettings.Blur4Contrast); + ThisMaterial.SetFloat(Blur5Contrast, _heightFromDiffuseSettings.Blur5Contrast); + ThisMaterial.SetFloat(Blur6Contrast, _heightFromDiffuseSettings.Blur6Contrast); + + var realGain = _heightFromDiffuseSettings.FinalGain; + if (realGain < 0.0f) + realGain = Mathf.Abs(1.0f / (realGain - 1.0f)); + else + realGain = realGain + 1.0f; + + ThisMaterial.SetFloat(FinalGain, realGain); + ThisMaterial.SetFloat(FinalContrast, _heightFromDiffuseSettings.FinalContrast); + ThisMaterial.SetFloat(FinalBias, _heightFromDiffuseSettings.FinalBias); + + ThisMaterial.SetFloat(Slider, _slider); + } + + private void DoMyWindow(int windowId) + { + var offsetX = 10; + var offsetY = 30; + + GUI.enabled = MainGuiScript.DiffuseMap != null; + _heightFromDiffuseSettings.UseAdjustedDiffuse = GUI.Toggle(new Rect(offsetX, offsetY, 80, 30), + _heightFromDiffuseSettings.UseAdjustedDiffuse, " Diffuse"); + if (_heightFromDiffuseSettings.UseAdjustedDiffuse) { - HFDS.useOriginalDiffuse = false; - HFDS.useNormal = false; + _heightFromDiffuseSettings.UseOriginalDiffuse = false; + _heightFromDiffuseSettings.UseNormal = false; } - else if (!HFDS.useOriginalDiffuse && !HFDS.useNormal) + else if (!_heightFromDiffuseSettings.UseOriginalDiffuse && !_heightFromDiffuseSettings.UseNormal) { - HFDS.useAdjustedDiffuse = true; + _heightFromDiffuseSettings.UseAdjustedDiffuse = true; } - if (MainGuiScript._DiffuseMapOriginal != null) { GUI.enabled = true; } else { GUI.enabled = false; } - HFDS.useOriginalDiffuse = GUI.Toggle (new Rect (offsetX + 80, offsetY, 120, 30), HFDS.useOriginalDiffuse, "Original Diffuse"); - if (HFDS.useOriginalDiffuse) + GUI.enabled = MainGuiScript.DiffuseMapOriginal != null; + _heightFromDiffuseSettings.UseOriginalDiffuse = GUI.Toggle(new Rect(offsetX + 80, offsetY, 120, 30), + _heightFromDiffuseSettings.UseOriginalDiffuse, + "Original Diffuse"); + if (_heightFromDiffuseSettings.UseOriginalDiffuse) { - HFDS.useAdjustedDiffuse = false; - HFDS.useNormal = false; + _heightFromDiffuseSettings.UseAdjustedDiffuse = false; + _heightFromDiffuseSettings.UseNormal = false; } - else if (!HFDS.useAdjustedDiffuse && !HFDS.useNormal) + else if (!_heightFromDiffuseSettings.UseAdjustedDiffuse && !_heightFromDiffuseSettings.UseNormal) { - HFDS.useOriginalDiffuse = true; + _heightFromDiffuseSettings.UseOriginalDiffuse = true; } - if (MainGuiScript._NormalMap) { GUI.enabled = true; } else { GUI.enabled = false; } - HFDS.useNormal = GUI.Toggle(new Rect(offsetX + 210, offsetY, 80, 30), HFDS.useNormal, " Normal"); - if (HFDS.useNormal) + GUI.enabled = MainGuiScript.NormalMap; + _heightFromDiffuseSettings.UseNormal = GUI.Toggle(new Rect(offsetX + 210, offsetY, 80, 30), + _heightFromDiffuseSettings.UseNormal, " Normal"); + if (_heightFromDiffuseSettings.UseNormal) { - HFDS.useAdjustedDiffuse = false; - HFDS.useOriginalDiffuse = false; + _heightFromDiffuseSettings.UseAdjustedDiffuse = false; + _heightFromDiffuseSettings.UseOriginalDiffuse = false; } - else if(!HFDS.useAdjustedDiffuse && !HFDS.useOriginalDiffuse) + else if (!_heightFromDiffuseSettings.UseAdjustedDiffuse && !_heightFromDiffuseSettings.UseOriginalDiffuse) { - HFDS.useNormal = true; + _heightFromDiffuseSettings.UseNormal = true; } + GUI.enabled = true; offsetY += 30; - GUI.Label(new Rect(offsetX, offsetY, 250, 30), "Height Reveal Slider"); - Slider = GUI.HorizontalSlider(new Rect(offsetX, offsetY + 20, 280, 10), Slider, 0.0f, 1.0f); - offsetY += 40; + GUI.Label(new Rect(offsetX, offsetY, 250, 30), "Height Reveal Slider"); + _slider = GUI.HorizontalSlider(new Rect(offsetX, offsetY + 20, 280, 10), _slider, 0.0f, 1.0f); + offsetY += 40; - if (HFDS.useNormal) + if (_heightFromDiffuseSettings.UseNormal) { - - if( GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 10), "Sample Spread", HFDS.Spread, HFDS.SpreadText, out HFDS.Spread, out HFDS.SpreadText, 10.0f, 200.0f) ){ - doStuff = true; - } + if (GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 10), "Sample Spread", + _heightFromDiffuseSettings.Spread, _heightFromDiffuseSettings.SpreadText, + out _heightFromDiffuseSettings.Spread, out _heightFromDiffuseSettings.SpreadText, 10.0f, 200.0f)) + _doStuff = true; offsetY += 40; - if( GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 10), "Sample Spread Boost", HFDS.SpreadBoost, HFDS.SpreadBoostText, out HFDS.SpreadBoost, out HFDS.SpreadBoostText, 1.0f, 5.0f) ){ - doStuff = true; - } - - offsetY += 40; - - } else { + if (GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 10), "Sample Spread Boost", + _heightFromDiffuseSettings.SpreadBoost, + _heightFromDiffuseSettings.SpreadBoostText, out _heightFromDiffuseSettings.SpreadBoost, + out _heightFromDiffuseSettings.SpreadBoostText, 1.0f, 5.0f)) _doStuff = true; + offsetY += 40; + } + else + { GUI.Label(new Rect(offsetX, offsetY, 250, 30), "Frequency Weight Equalizer"); GUI.Label(new Rect(offsetX + 225, offsetY, 100, 30), "Presets"); - if (GUI.Button(new Rect(offsetX + 215, offsetY + 30, 60, 20), "Default")) - { - SetWeightEQDefault(); - } - if (GUI.Button(new Rect(offsetX + 215, offsetY + 60, 60, 20), "Details")) - { - SetWeightEQDetail(); - } - if (GUI.Button(new Rect(offsetX + 215, offsetY + 90, 60, 20), "Displace")) - { - SetWeightEQDisplace(); - } + if (GUI.Button(new Rect(offsetX + 215, offsetY + 30, 60, 20), "Default")) SetWeightEqDefault(); + if (GUI.Button(new Rect(offsetX + 215, offsetY + 60, 60, 20), "Details")) SetWeightEqDetail(); + if (GUI.Button(new Rect(offsetX + 215, offsetY + 90, 60, 20), "Displace")) SetWeightEqDisplace(); offsetY += 30; offsetX += 10; - HFDS.Blur0Weight = GUI.VerticalSlider(new Rect(offsetX + 180, offsetY, 10, 80), HFDS.Blur0Weight, 1.0f, 0.0f); - HFDS.Blur1Weight = GUI.VerticalSlider(new Rect(offsetX + 150, offsetY, 10, 80), HFDS.Blur1Weight, 1.0f, 0.0f); - HFDS.Blur2Weight = GUI.VerticalSlider(new Rect(offsetX + 120, offsetY, 10, 80), HFDS.Blur2Weight, 1.0f, 0.0f); - HFDS.Blur3Weight = GUI.VerticalSlider(new Rect(offsetX + 90, offsetY, 10, 80), HFDS.Blur3Weight, 1.0f, 0.0f); - HFDS.Blur4Weight = GUI.VerticalSlider(new Rect(offsetX + 60, offsetY, 10, 80), HFDS.Blur4Weight, 1.0f, 0.0f); - HFDS.Blur5Weight = GUI.VerticalSlider(new Rect(offsetX + 30, offsetY, 10, 80), HFDS.Blur5Weight, 1.0f, 0.0f); - HFDS.Blur6Weight = GUI.VerticalSlider(new Rect(offsetX + 0, offsetY, 10, 80), HFDS.Blur6Weight, 1.0f, 0.0f); + _heightFromDiffuseSettings.Blur0Weight = + GUI.VerticalSlider(new Rect(offsetX + 180, offsetY, 10, 80), _heightFromDiffuseSettings.Blur0Weight, + 1.0f, 0.0f); + _heightFromDiffuseSettings.Blur1Weight = + GUI.VerticalSlider(new Rect(offsetX + 150, offsetY, 10, 80), _heightFromDiffuseSettings.Blur1Weight, + 1.0f, 0.0f); + _heightFromDiffuseSettings.Blur2Weight = + GUI.VerticalSlider(new Rect(offsetX + 120, offsetY, 10, 80), _heightFromDiffuseSettings.Blur2Weight, + 1.0f, 0.0f); + _heightFromDiffuseSettings.Blur3Weight = + GUI.VerticalSlider(new Rect(offsetX + 90, offsetY, 10, 80), _heightFromDiffuseSettings.Blur3Weight, + 1.0f, 0.0f); + _heightFromDiffuseSettings.Blur4Weight = + GUI.VerticalSlider(new Rect(offsetX + 60, offsetY, 10, 80), _heightFromDiffuseSettings.Blur4Weight, + 1.0f, 0.0f); + _heightFromDiffuseSettings.Blur5Weight = + GUI.VerticalSlider(new Rect(offsetX + 30, offsetY, 10, 80), _heightFromDiffuseSettings.Blur5Weight, + 1.0f, 0.0f); + _heightFromDiffuseSettings.Blur6Weight = GUI.VerticalSlider(new Rect(offsetX + 0, offsetY, 10, 80), + _heightFromDiffuseSettings.Blur6Weight, 1.0f, 0.0f); offsetX -= 10; offsetY += 100; GUI.Label(new Rect(offsetX, offsetY, 250, 30), "Frequency Contrast Equalizer"); GUI.Label(new Rect(offsetX + 225, offsetY, 100, 30), "Presets"); - if (GUI.Button(new Rect(offsetX + 215, offsetY + 30, 60, 20), "Default")) - { - SetContrastEQDefault(); - } - if (GUI.Button(new Rect(offsetX + 215, offsetY + 60, 60, 20), "Cracks")) - { - SetContrastEQCrackedMud(); - } - if (GUI.Button(new Rect(offsetX + 215, offsetY + 90, 60, 20), "Funky")) - { - SetContrastEQFunky(); - } + if (GUI.Button(new Rect(offsetX + 215, offsetY + 30, 60, 20), "Default")) SetContrastEqDefault(); + if (GUI.Button(new Rect(offsetX + 215, offsetY + 60, 60, 20), "Cracks")) SetContrastEqCrackedMud(); + if (GUI.Button(new Rect(offsetX + 215, offsetY + 90, 60, 20), "Funky")) SetContrastEqFunky(); offsetY += 30; offsetX += 10; - HFDS.Blur0Contrast = GUI.VerticalSlider(new Rect(offsetX + 180, offsetY, 10, 80), HFDS.Blur0Contrast, 5.0f, -5.0f); - HFDS.Blur1Contrast = GUI.VerticalSlider(new Rect(offsetX + 150, offsetY, 10, 80), HFDS.Blur1Contrast, 5.0f, -5.0f); - HFDS.Blur2Contrast = GUI.VerticalSlider(new Rect(offsetX + 120, offsetY, 10, 80), HFDS.Blur2Contrast, 5.0f, -5.0f); - HFDS.Blur3Contrast = GUI.VerticalSlider(new Rect(offsetX + 90, offsetY, 10, 80), HFDS.Blur3Contrast, 5.0f, -5.0f); - HFDS.Blur4Contrast = GUI.VerticalSlider(new Rect(offsetX + 60, offsetY, 10, 80), HFDS.Blur4Contrast, 5.0f, -5.0f); - HFDS.Blur5Contrast = GUI.VerticalSlider(new Rect(offsetX + 30, offsetY, 10, 80), HFDS.Blur5Contrast, 5.0f, -5.0f); - HFDS.Blur6Contrast = GUI.VerticalSlider(new Rect(offsetX + 0, offsetY, 10, 80), HFDS.Blur6Contrast, 5.0f, -5.0f); + _heightFromDiffuseSettings.Blur0Contrast = + GUI.VerticalSlider(new Rect(offsetX + 180, offsetY, 10, 80), _heightFromDiffuseSettings.Blur0Contrast, + 5.0f, -5.0f); + _heightFromDiffuseSettings.Blur1Contrast = + GUI.VerticalSlider(new Rect(offsetX + 150, offsetY, 10, 80), _heightFromDiffuseSettings.Blur1Contrast, + 5.0f, -5.0f); + _heightFromDiffuseSettings.Blur2Contrast = + GUI.VerticalSlider(new Rect(offsetX + 120, offsetY, 10, 80), _heightFromDiffuseSettings.Blur2Contrast, + 5.0f, -5.0f); + _heightFromDiffuseSettings.Blur3Contrast = + GUI.VerticalSlider(new Rect(offsetX + 90, offsetY, 10, 80), _heightFromDiffuseSettings.Blur3Contrast, + 5.0f, -5.0f); + _heightFromDiffuseSettings.Blur4Contrast = + GUI.VerticalSlider(new Rect(offsetX + 60, offsetY, 10, 80), _heightFromDiffuseSettings.Blur4Contrast, + 5.0f, -5.0f); + _heightFromDiffuseSettings.Blur5Contrast = + GUI.VerticalSlider(new Rect(offsetX + 30, offsetY, 10, 80), _heightFromDiffuseSettings.Blur5Contrast, + 5.0f, -5.0f); + _heightFromDiffuseSettings.Blur6Contrast = + GUI.VerticalSlider(new Rect(offsetX + 0, offsetY, 10, 80), _heightFromDiffuseSettings.Blur6Contrast, + 5.0f, -5.0f); offsetX -= 10; GUI.Label(new Rect(offsetX + 210, offsetY + 21, 30, 30), "-"); GUI.Label(new Rect(offsetX + 180, offsetY + 21, 30, 30), "-"); @@ -709,516 +612,526 @@ void DoMyWindow ( int windowID ) { offsetY += 100; - - doStuff = GuiHelper.Toggle(new Rect(offsetX, offsetY, 150, 20), HFDS.UseSample1, out HFDS.UseSample1, "Use Color Sample 1", doStuff); - if (HFDS.UseSample1) + _doStuff = GuiHelper.Toggle(new Rect(offsetX, offsetY, 150, 20), _heightFromDiffuseSettings.UseSample1, + out _heightFromDiffuseSettings.UseSample1, + "Use Color Sample 1", _doStuff); + if (_heightFromDiffuseSettings.UseSample1) { - - doStuff = GuiHelper.Toggle(new Rect(offsetX + 180, offsetY, 150, 20), HFDS.IsolateSample1, out HFDS.IsolateSample1, "Isolate Mask", doStuff); - if (HFDS.IsolateSample1) - { - HFDS.IsolateSample2 = false; - } + _doStuff = GuiHelper.Toggle(new Rect(offsetX + 180, offsetY, 150, 20), + _heightFromDiffuseSettings.IsolateSample1, + out _heightFromDiffuseSettings.IsolateSample1, "Isolate Mask", _doStuff); + if (_heightFromDiffuseSettings.IsolateSample1) _heightFromDiffuseSettings.IsolateSample2 = false; offsetY += 30; if (GUI.Button(new Rect(offsetX, offsetY + 5, 80, 20), "Pick Color")) { - selectingColor = true; - currentSelection = 1; + _selectingColor = true; + _currentSelection = 1; } - GUI.DrawTexture(new Rect(offsetX + 10, offsetY + 35, 60, 60), _SampleColorMap1); + GUI.DrawTexture(new Rect(offsetX + 10, offsetY + 35, 60, 60), _sampleColorMap1); GUI.Label(new Rect(offsetX + 90, offsetY, 250, 30), "Hue"); - doStuff = GuiHelper.VerticalSlider(new Rect(offsetX + 95, offsetY + 30, 10, 70), HFDS.HueWeight1, out HFDS.HueWeight1, 1.0f, 0.0f, doStuff); + _doStuff = GuiHelper.VerticalSlider(new Rect(offsetX + 95, offsetY + 30, 10, 70), + _heightFromDiffuseSettings.HueWeight1, + out _heightFromDiffuseSettings.HueWeight1, 1.0f, 0.0f, _doStuff); GUI.Label(new Rect(offsetX + 120, offsetY, 250, 30), "Sat"); - doStuff = GuiHelper.VerticalSlider(new Rect(offsetX + 125, offsetY + 30, 10, 70), HFDS.SatWeight1, out HFDS.SatWeight1, 1.0f, 0.0f, doStuff); + _doStuff = GuiHelper.VerticalSlider(new Rect(offsetX + 125, offsetY + 30, 10, 70), + _heightFromDiffuseSettings.SatWeight1, + out _heightFromDiffuseSettings.SatWeight1, 1.0f, 0.0f, _doStuff); GUI.Label(new Rect(offsetX + 150, offsetY, 250, 30), "Lum"); - doStuff = GuiHelper.VerticalSlider(new Rect(offsetX + 155, offsetY + 30, 10, 70), HFDS.LumWeight1, out HFDS.LumWeight1, 1.0f, 0.0f, doStuff); + _doStuff = GuiHelper.VerticalSlider(new Rect(offsetX + 155, offsetY + 30, 10, 70), + _heightFromDiffuseSettings.LumWeight1, + out _heightFromDiffuseSettings.LumWeight1, 1.0f, 0.0f, _doStuff); GUI.Label(new Rect(offsetX + 180, offsetY, 250, 30), "Low"); - doStuff = GuiHelper.VerticalSlider(new Rect(offsetX + 185, offsetY + 30, 10, 70), HFDS.MaskLow1, out HFDS.MaskLow1, 1.0f, 0.0f, doStuff); + _doStuff = GuiHelper.VerticalSlider(new Rect(offsetX + 185, offsetY + 30, 10, 70), + _heightFromDiffuseSettings.MaskLow1, + out _heightFromDiffuseSettings.MaskLow1, 1.0f, 0.0f, _doStuff); GUI.Label(new Rect(offsetX + 210, offsetY, 250, 30), "High"); - doStuff = GuiHelper.VerticalSlider(new Rect(offsetX + 215, offsetY + 30, 10, 70), HFDS.MaskHigh1, out HFDS.MaskHigh1, 1.0f, 0.0f, doStuff); + _doStuff = GuiHelper.VerticalSlider(new Rect(offsetX + 215, offsetY + 30, 10, 70), + _heightFromDiffuseSettings.MaskHigh1, + out _heightFromDiffuseSettings.MaskHigh1, 1.0f, 0.0f, _doStuff); GUI.Label(new Rect(offsetX + 240, offsetY, 250, 30), "Height"); - doStuff = GuiHelper.VerticalSlider(new Rect(offsetX + 255, offsetY + 30, 10, 70), HFDS.Sample1Height, out HFDS.Sample1Height, 1.0f, 0.0f, doStuff); + _doStuff = GuiHelper.VerticalSlider(new Rect(offsetX + 255, offsetY + 30, 10, 70), + _heightFromDiffuseSettings.Sample1Height, + out _heightFromDiffuseSettings.Sample1Height, 1.0f, 0.0f, _doStuff); offsetY += 110; } else { offsetY += 30; - HFDS.IsolateSample1 = false; + _heightFromDiffuseSettings.IsolateSample1 = false; } - doStuff = GuiHelper.Toggle(new Rect(offsetX, offsetY, 150, 20), HFDS.UseSample2, out HFDS.UseSample2, "Use Color Sample 2", doStuff); - if (HFDS.UseSample2) + _doStuff = GuiHelper.Toggle(new Rect(offsetX, offsetY, 150, 20), _heightFromDiffuseSettings.UseSample2, + out _heightFromDiffuseSettings.UseSample2, + "Use Color Sample 2", _doStuff); + if (_heightFromDiffuseSettings.UseSample2) { - - doStuff = GuiHelper.Toggle(new Rect(offsetX + 180, offsetY, 150, 20), HFDS.IsolateSample2, out HFDS.IsolateSample2, "Isolate Mask", doStuff); - if (HFDS.IsolateSample2) - { - HFDS.IsolateSample1 = false; - } + _doStuff = GuiHelper.Toggle(new Rect(offsetX + 180, offsetY, 150, 20), + _heightFromDiffuseSettings.IsolateSample2, + out _heightFromDiffuseSettings.IsolateSample2, "Isolate Mask", _doStuff); + if (_heightFromDiffuseSettings.IsolateSample2) _heightFromDiffuseSettings.IsolateSample1 = false; offsetY += 30; if (GUI.Button(new Rect(offsetX, offsetY + 5, 80, 20), "Pick Color")) { - selectingColor = true; - currentSelection = 2; + _selectingColor = true; + _currentSelection = 2; } - GUI.DrawTexture(new Rect(offsetX + 10, offsetY + 35, 60, 60), _SampleColorMap2); + GUI.DrawTexture(new Rect(offsetX + 10, offsetY + 35, 60, 60), _sampleColorMap2); GUI.Label(new Rect(offsetX + 90, offsetY, 250, 30), "Hue"); - doStuff = GuiHelper.VerticalSlider(new Rect(offsetX + 95, offsetY + 30, 10, 70), HFDS.HueWeight2, out HFDS.HueWeight2, 1.0f, 0.0f, doStuff); + _doStuff = GuiHelper.VerticalSlider(new Rect(offsetX + 95, offsetY + 30, 10, 70), + _heightFromDiffuseSettings.HueWeight2, + out _heightFromDiffuseSettings.HueWeight2, 1.0f, 0.0f, _doStuff); GUI.Label(new Rect(offsetX + 120, offsetY, 250, 30), "Sat"); - doStuff = GuiHelper.VerticalSlider(new Rect(offsetX + 125, offsetY + 30, 10, 70), HFDS.SatWeight2, out HFDS.SatWeight2, 1.0f, 0.0f, doStuff); + _doStuff = GuiHelper.VerticalSlider(new Rect(offsetX + 125, offsetY + 30, 10, 70), + _heightFromDiffuseSettings.SatWeight2, + out _heightFromDiffuseSettings.SatWeight2, 1.0f, 0.0f, _doStuff); GUI.Label(new Rect(offsetX + 150, offsetY, 250, 30), "Lum"); - doStuff = GuiHelper.VerticalSlider(new Rect(offsetX + 155, offsetY + 30, 10, 70), HFDS.LumWeight2, out HFDS.LumWeight2, 1.0f, 0.0f, doStuff); + _doStuff = GuiHelper.VerticalSlider(new Rect(offsetX + 155, offsetY + 30, 10, 70), + _heightFromDiffuseSettings.LumWeight2, + out _heightFromDiffuseSettings.LumWeight2, 1.0f, 0.0f, _doStuff); GUI.Label(new Rect(offsetX + 180, offsetY, 250, 30), "Low"); - doStuff = GuiHelper.VerticalSlider(new Rect(offsetX + 185, offsetY + 30, 10, 70), HFDS.MaskLow2, out HFDS.MaskLow2, 1.0f, 0.0f, doStuff); + _doStuff = GuiHelper.VerticalSlider(new Rect(offsetX + 185, offsetY + 30, 10, 70), + _heightFromDiffuseSettings.MaskLow2, + out _heightFromDiffuseSettings.MaskLow2, 1.0f, 0.0f, _doStuff); GUI.Label(new Rect(offsetX + 210, offsetY, 250, 30), "High"); - doStuff = GuiHelper.VerticalSlider(new Rect(offsetX + 215, offsetY + 30, 10, 70), HFDS.MaskHigh2, out HFDS.MaskHigh2, 1.0f, 0.0f, doStuff); + _doStuff = GuiHelper.VerticalSlider(new Rect(offsetX + 215, offsetY + 30, 10, 70), + _heightFromDiffuseSettings.MaskHigh2, + out _heightFromDiffuseSettings.MaskHigh2, 1.0f, 0.0f, _doStuff); GUI.Label(new Rect(offsetX + 240, offsetY, 250, 30), "Height"); - doStuff = GuiHelper.VerticalSlider(new Rect(offsetX + 255, offsetY + 30, 10, 70), HFDS.Sample2Height, out HFDS.Sample2Height, 1.0f, 0.0f, doStuff); + _doStuff = GuiHelper.VerticalSlider(new Rect(offsetX + 255, offsetY + 30, 10, 70), + _heightFromDiffuseSettings.Sample2Height, + out _heightFromDiffuseSettings.Sample2Height, 1.0f, 0.0f, _doStuff); offsetY += 110; } else { offsetY += 30; - HFDS.IsolateSample2 = false; + _heightFromDiffuseSettings.IsolateSample2 = false; } - if (HFDS.UseSample1 || HFDS.UseSample2) + if (_heightFromDiffuseSettings.UseSample1 || _heightFromDiffuseSettings.UseSample2) { - - if (GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Sample Blend", HFDS.SampleBlend, HFDS.SampleBlendText, out HFDS.SampleBlend, out HFDS.SampleBlendText, 0.0f, 1.0f)) - { - doStuff = true; - } + if (GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Sample Blend", + _heightFromDiffuseSettings.SampleBlend, + _heightFromDiffuseSettings.SampleBlendText, out _heightFromDiffuseSettings.SampleBlend, + out _heightFromDiffuseSettings.SampleBlendText, 0.0f, 1.0f)) _doStuff = true; offsetY += 40; } } - - GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Final Gain", HFDS.FinalGain, HFDS.FinalGainText, out HFDS.FinalGain, out HFDS.FinalGainText, -0.5f, 0.5f); - offsetY += 40; + GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Final Gain", _heightFromDiffuseSettings.FinalGain, + _heightFromDiffuseSettings.FinalGainText, + out _heightFromDiffuseSettings.FinalGain, out _heightFromDiffuseSettings.FinalGainText, -0.5f, 0.5f); + offsetY += 40; - GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Final Contrast", HFDS.FinalContrast, HFDS.FinalContrastText, out HFDS.FinalContrast, out HFDS.FinalContrastText, -10.0f, 10.0f); + GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Final Contrast", + _heightFromDiffuseSettings.FinalContrast, + _heightFromDiffuseSettings.FinalContrastText, out _heightFromDiffuseSettings.FinalContrast, + out _heightFromDiffuseSettings.FinalContrastText, -10.0f, 10.0f); offsetY += 40; - GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Final Bias", HFDS.FinalBias, HFDS.FinalBiasText, out HFDS.FinalBias, out HFDS.FinalBiasText, -1.0f, 1.0f); + GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Final Bias", _heightFromDiffuseSettings.FinalBias, + _heightFromDiffuseSettings.FinalBiasText, + out _heightFromDiffuseSettings.FinalBias, out _heightFromDiffuseSettings.FinalBiasText, -1.0f, 1.0f); offsetY += 50; - if (busy) { GUI.enabled = false; } else { GUI.enabled = true; } - if( GUI.Button (new Rect (offsetX + 150, offsetY, 130, 30), "Set as Height Map" ) ){ - StartCoroutine( ProcessHeight () ); - } - GUI.enabled = true; - - GUI.DragWindow(); - } - - void OnGUI () { - - windowRect.width = 300; - windowRect.height = 590; + GUI.enabled = !Busy; + if (GUI.Button(new Rect(offsetX + 10, offsetY, 130, 30), "Reset to Defaults")) + { + //_settingsInitialized = false; + SetValues(new ProjectObject()); + _heightFromDiffuseSettings.UseOriginalDiffuse = true; + if (_heightFromDiffuseSettings.UseOriginalDiffuse) + { + _heightFromDiffuseSettings.UseAdjustedDiffuse = false; + _heightFromDiffuseSettings.UseNormal = false; + } + else if (!_heightFromDiffuseSettings.UseAdjustedDiffuse && !_heightFromDiffuseSettings.UseNormal) + { + _heightFromDiffuseSettings.UseOriginalDiffuse = true; + } + //StartCoroutine(ProcessDiffuse()); + } + if (GUI.Button(new Rect(offsetX + 150, offsetY, 130, 30), "Set as Height Map")) StartCoroutine(ProcessHeight()); + GUI.enabled = true; - if (HFDS.UseSample1 && !HFDS.useNormal) { - windowRect.height += 110; - } + GUI.DragWindow(); + } - if (HFDS.UseSample2 && !HFDS.useNormal) { - windowRect.height += 110; - } + private void OnGUI() + { + _windowRect.width = 300; + _windowRect.height = 590; - if ((HFDS.UseSample1 || HFDS.UseSample2) && !HFDS.useNormal) { - windowRect.height += 40; - } + if (_heightFromDiffuseSettings.UseSample1 && !_heightFromDiffuseSettings.UseNormal) _windowRect.height += 110; - windowRect = GUI.Window(13, windowRect, DoMyWindow, "Height From Diffuse"); + if (_heightFromDiffuseSettings.UseSample2 && !_heightFromDiffuseSettings.UseNormal) _windowRect.height += 110; - } + if ((_heightFromDiffuseSettings.UseSample1 || _heightFromDiffuseSettings.UseSample2) && + !_heightFromDiffuseSettings.UseNormal) _windowRect.height += 40; - public void InitializeTextures() { + _windowRect = GUI.Window(13, _windowRect, DoMyWindow, "Height From Diffuse"); + } - testObject.GetComponent().sharedMaterial = thisMaterial; + public void InitializeTextures() + { + TestObject.GetComponent().sharedMaterial = ThisMaterial; - CleanupTextures (); + CleanupTextures(); - FixUseMaps (); + FixUseMaps(); - if ( HFDS.useAdjustedDiffuse ) + if (_heightFromDiffuseSettings.UseAdjustedDiffuse) { - imageSizeX = MainGuiScript._DiffuseMap.width; - imageSizeY = MainGuiScript._DiffuseMap.height; + _imageSizeX = MainGuiScript.DiffuseMap.width; + _imageSizeY = MainGuiScript.DiffuseMap.height; } - else if (HFDS.useOriginalDiffuse) + else if (_heightFromDiffuseSettings.UseOriginalDiffuse) { - imageSizeX = MainGuiScript._DiffuseMapOriginal.width; - imageSizeY = MainGuiScript._DiffuseMapOriginal.height; + _imageSizeX = MainGuiScript.DiffuseMapOriginal.width; + _imageSizeY = MainGuiScript.DiffuseMapOriginal.height; } - else if (HFDS.useNormal) + else if (_heightFromDiffuseSettings.UseNormal) { - imageSizeX = MainGuiScript._NormalMap.width; - imageSizeY = MainGuiScript._NormalMap.height; + _imageSizeX = MainGuiScript.NormalMap.width; + _imageSizeY = MainGuiScript.NormalMap.height; } - Debug.Log ( "Initializing Textures of size: " + imageSizeX.ToString() + "x" + imageSizeY.ToString() ); - - _TempBlurMap = new RenderTexture (imageSizeX, imageSizeY, 0, RenderTextureFormat.RFloat, RenderTextureReadWrite.Linear); - _TempBlurMap.wrapMode = TextureWrapMode.Repeat; - _BlurMap0 = new RenderTexture (imageSizeX, imageSizeY, 0, RenderTextureFormat.RFloat, RenderTextureReadWrite.Linear); - _BlurMap0.wrapMode = TextureWrapMode.Repeat; - _BlurMap1 = new RenderTexture (imageSizeX, imageSizeY, 0, RenderTextureFormat.RFloat, RenderTextureReadWrite.Linear); - _BlurMap1.wrapMode = TextureWrapMode.Repeat; - _BlurMap2 = new RenderTexture (imageSizeX, imageSizeY, 0, RenderTextureFormat.RFloat, RenderTextureReadWrite.Linear); - _BlurMap2.wrapMode = TextureWrapMode.Repeat; - _BlurMap3 = new RenderTexture (imageSizeX, imageSizeY, 0, RenderTextureFormat.RFloat, RenderTextureReadWrite.Linear); - _BlurMap3.wrapMode = TextureWrapMode.Repeat; - _BlurMap4 = new RenderTexture (imageSizeX, imageSizeY, 0, RenderTextureFormat.RFloat, RenderTextureReadWrite.Linear); - _BlurMap4.wrapMode = TextureWrapMode.Repeat; - _BlurMap5 = new RenderTexture (imageSizeX, imageSizeY, 0, RenderTextureFormat.RFloat, RenderTextureReadWrite.Linear); - _BlurMap5.wrapMode = TextureWrapMode.Repeat; - _BlurMap6 = new RenderTexture (imageSizeX, imageSizeY, 0, RenderTextureFormat.RFloat, RenderTextureReadWrite.Linear); - _BlurMap6.wrapMode = TextureWrapMode.Repeat; - - _AvgMap = new RenderTexture (256, 256, 0, RenderTextureFormat.RFloat, RenderTextureReadWrite.Linear); - _AvgMap.wrapMode = TextureWrapMode.Repeat; - - _AvgTempMap = new RenderTexture (256, 256, 0, RenderTextureFormat.RFloat, RenderTextureReadWrite.Linear); - _AvgTempMap.wrapMode = TextureWrapMode.Repeat; - - SetMaterialValues (); - - } - - public void Close(){ - CleanupTextures (); - this.gameObject.SetActive (false); - } - - void CleanupTexture( RenderTexture _Texture ) { - - if (_Texture != null) { - _Texture.Release(); - _Texture = null; - } - - } - - void CleanupTextures() { - - Debug.Log ("Cleaning Up Textures"); - - CleanupTexture( _TempBlurMap ); - CleanupTexture( _BlurMap0 ); - CleanupTexture( _BlurMap1 ); - CleanupTexture( _BlurMap2 ); - CleanupTexture( _BlurMap3 ); - CleanupTexture( _BlurMap4 ); - CleanupTexture( _BlurMap5 ); - CleanupTexture( _BlurMap6 ); - CleanupTexture (_TempHeightMap); - CleanupTexture( _AvgMap ); - CleanupTexture( _AvgTempMap ); +// Debug.Log("Initializing Textures of size: " + _imageSizeX + "x" + _imageSizeY); + + _tempBlurMap = new RenderTexture(_imageSizeX, _imageSizeY, 0, RenderTextureFormat.RFloat, + RenderTextureReadWrite.Linear) {wrapMode = TextureWrapMode.Repeat}; + _blurMap0 = new RenderTexture(_imageSizeX, _imageSizeY, 0, RenderTextureFormat.RFloat, + RenderTextureReadWrite.Linear) {wrapMode = TextureWrapMode.Repeat}; + _blurMap1 = new RenderTexture(_imageSizeX, _imageSizeY, 0, RenderTextureFormat.RFloat, + RenderTextureReadWrite.Linear) {wrapMode = TextureWrapMode.Repeat}; + _blurMap2 = new RenderTexture(_imageSizeX, _imageSizeY, 0, RenderTextureFormat.RFloat, + RenderTextureReadWrite.Linear) {wrapMode = TextureWrapMode.Repeat}; + _blurMap3 = new RenderTexture(_imageSizeX, _imageSizeY, 0, RenderTextureFormat.RFloat, + RenderTextureReadWrite.Linear) {wrapMode = TextureWrapMode.Repeat}; + _blurMap4 = new RenderTexture(_imageSizeX, _imageSizeY, 0, RenderTextureFormat.RFloat, + RenderTextureReadWrite.Linear) {wrapMode = TextureWrapMode.Repeat}; + _blurMap5 = new RenderTexture(_imageSizeX, _imageSizeY, 0, RenderTextureFormat.RFloat, + RenderTextureReadWrite.Linear) {wrapMode = TextureWrapMode.Repeat}; + _blurMap6 = new RenderTexture(_imageSizeX, _imageSizeY, 0, RenderTextureFormat.RFloat, + RenderTextureReadWrite.Linear) {wrapMode = TextureWrapMode.Repeat}; + + _avgMap = new RenderTexture(256, 256, 0, RenderTextureFormat.RFloat, RenderTextureReadWrite.Linear) + { + wrapMode = TextureWrapMode.Repeat + }; - } + _avgTempMap = new RenderTexture(256, 256, 0, RenderTextureFormat.RFloat, RenderTextureReadWrite.Linear) + { + wrapMode = TextureWrapMode.Repeat + }; - public IEnumerator ProcessHeight() { + SetMaterialValues(); + } - busy = true; + public void Close() + { + CleanupTextures(); + gameObject.SetActive(false); + } - Debug.Log ("Processing Height"); + private static void CleanupTexture(RenderTexture texture) + { + if (!texture) return; + texture.Release(); + // ReSharper disable once RedundantAssignment + texture = null; + } - blitMaterial.SetVector ("_ImageSize", new Vector4( imageSizeX, imageSizeY, 0, 0 )); + private void CleanupTextures() + { + CleanupTexture(_tempBlurMap); + CleanupTexture(_blurMap0); + CleanupTexture(_blurMap1); + CleanupTexture(_blurMap2); + CleanupTexture(_blurMap3); + CleanupTexture(_blurMap4); + CleanupTexture(_blurMap5); + CleanupTexture(_blurMap6); + CleanupTexture(_tempHeightMap); + CleanupTexture(_avgMap); + CleanupTexture(_avgTempMap); + } + public void StartProcessHeight() + { + StartCoroutine(ProcessHeight()); + } + public IEnumerator ProcessHeight() + { + Busy = true; + _blitMaterial.SetVector(ImageSize, new Vector4(_imageSizeX, _imageSizeY, 0, 0)); - CleanupTexture(_TempHeightMap); - _TempHeightMap = new RenderTexture(imageSizeX, imageSizeY, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear); - _TempHeightMap.wrapMode = TextureWrapMode.Repeat; + CleanupTexture(_tempHeightMap); + _tempHeightMap = new RenderTexture(_imageSizeX, _imageSizeY, 0, RenderTextureFormat.ARGB32, + RenderTextureReadWrite.Linear) {wrapMode = TextureWrapMode.Repeat}; - blitMaterial.SetFloat("_FinalContrast", HFDS.FinalContrast); - blitMaterial.SetFloat("_FinalBias", HFDS.FinalBias); + _blitMaterial.SetFloat(FinalContrast, _heightFromDiffuseSettings.FinalContrast); + _blitMaterial.SetFloat(FinalBias, _heightFromDiffuseSettings.FinalBias); - float realGain = HFDS.FinalGain; - if (realGain < 0.0f) { - realGain = Mathf.Abs( 1.0f / ( realGain - 1.0f ) ); - } else { - realGain = realGain + 1.0f; - } - blitMaterial.SetFloat("_FinalGain", realGain); + var realGain = _heightFromDiffuseSettings.FinalGain; + if (realGain < 0.0f) + realGain = Mathf.Abs(1.0f / (realGain - 1.0f)); + else + realGain = realGain + 1.0f; + _blitMaterial.SetFloat(FinalGain, realGain); - if (HFDS.useNormal) + if (_heightFromDiffuseSettings.UseNormal) { - - blitMaterial.SetTexture("_BlurTex0", _BlurMap0); - blitMaterial.SetFloat("_HeightFromNormal", 1.0f); + _blitMaterial.SetTexture(BlurTex0, _blurMap0); + _blitMaterial.SetFloat(HeightFromNormal, 1.0f); // Save low fidelity for texture 2d - Graphics.Blit(_BlurMap0, _TempHeightMap, blitMaterial, 2); - + Graphics.Blit(_blurMap0, _tempHeightMap, _blitMaterial, 2); } else { - blitMaterial.SetFloat("_HeightFromNormal", 0.0f); - - blitMaterial.SetFloat("_Blur0Weight", HFDS.Blur0Weight); - blitMaterial.SetFloat("_Blur1Weight", HFDS.Blur1Weight); - blitMaterial.SetFloat("_Blur2Weight", HFDS.Blur2Weight); - blitMaterial.SetFloat("_Blur3Weight", HFDS.Blur3Weight); - blitMaterial.SetFloat("_Blur4Weight", HFDS.Blur4Weight); - blitMaterial.SetFloat("_Blur5Weight", HFDS.Blur5Weight); - blitMaterial.SetFloat("_Blur6Weight", HFDS.Blur6Weight); - - blitMaterial.SetFloat("_Blur0Contrast", HFDS.Blur0Contrast); - blitMaterial.SetFloat("_Blur1Contrast", HFDS.Blur1Contrast); - blitMaterial.SetFloat("_Blur2Contrast", HFDS.Blur2Contrast); - blitMaterial.SetFloat("_Blur3Contrast", HFDS.Blur3Contrast); - blitMaterial.SetFloat("_Blur4Contrast", HFDS.Blur4Contrast); - blitMaterial.SetFloat("_Blur5Contrast", HFDS.Blur5Contrast); - blitMaterial.SetFloat("_Blur6Contrast", HFDS.Blur6Contrast); - - blitMaterial.SetTexture("_BlurTex0", _BlurMap0); - blitMaterial.SetTexture("_BlurTex1", _BlurMap1); - blitMaterial.SetTexture("_BlurTex2", _BlurMap2); - blitMaterial.SetTexture("_BlurTex3", _BlurMap3); - blitMaterial.SetTexture("_BlurTex4", _BlurMap4); - blitMaterial.SetTexture("_BlurTex5", _BlurMap5); - blitMaterial.SetTexture("_BlurTex6", _BlurMap6); - - blitMaterial.SetTexture ("_AvgTex", _AvgMap); + _blitMaterial.SetFloat(HeightFromNormal, 0.0f); + + _blitMaterial.SetFloat(Blur0Weight, _heightFromDiffuseSettings.Blur0Weight); + _blitMaterial.SetFloat(Blur1Weight, _heightFromDiffuseSettings.Blur1Weight); + _blitMaterial.SetFloat(Blur2Weight, _heightFromDiffuseSettings.Blur2Weight); + _blitMaterial.SetFloat(Blur3Weight, _heightFromDiffuseSettings.Blur3Weight); + _blitMaterial.SetFloat(Blur4Weight, _heightFromDiffuseSettings.Blur4Weight); + _blitMaterial.SetFloat(Blur5Weight, _heightFromDiffuseSettings.Blur5Weight); + _blitMaterial.SetFloat(Blur6Weight, _heightFromDiffuseSettings.Blur6Weight); + + _blitMaterial.SetFloat(Blur0Contrast, _heightFromDiffuseSettings.Blur0Contrast); + _blitMaterial.SetFloat(Blur1Contrast, _heightFromDiffuseSettings.Blur1Contrast); + _blitMaterial.SetFloat(Blur2Contrast, _heightFromDiffuseSettings.Blur2Contrast); + _blitMaterial.SetFloat(Blur3Contrast, _heightFromDiffuseSettings.Blur3Contrast); + _blitMaterial.SetFloat(Blur4Contrast, _heightFromDiffuseSettings.Blur4Contrast); + _blitMaterial.SetFloat(Blur5Contrast, _heightFromDiffuseSettings.Blur5Contrast); + _blitMaterial.SetFloat(Blur6Contrast, _heightFromDiffuseSettings.Blur6Contrast); + + _blitMaterial.SetTexture(BlurTex0, _blurMap0); + _blitMaterial.SetTexture(BlurTex1, _blurMap1); + _blitMaterial.SetTexture(BlurTex2, _blurMap2); + _blitMaterial.SetTexture(BlurTex3, _blurMap3); + _blitMaterial.SetTexture(BlurTex4, _blurMap4); + _blitMaterial.SetTexture(BlurTex5, _blurMap5); + _blitMaterial.SetTexture(BlurTex6, _blurMap6); + + _blitMaterial.SetTexture(AvgTex, _avgMap); // Save low fidelity for texture 2d - Graphics.Blit(_BlurMap0, _TempHeightMap, blitMaterial, 2); + Graphics.Blit(_blurMap0, _tempHeightMap, _blitMaterial, 2); } - if (MainGuiScript._HeightMap != null) { - Destroy (MainGuiScript._HeightMap); - } + if (MainGuiScript.HeightMap) Destroy(MainGuiScript.HeightMap); + + RenderTexture.active = _tempHeightMap; + MainGuiScript.HeightMap = + new Texture2D(_tempHeightMap.width, _tempHeightMap.height, TextureFormat.ARGB32, true, true); + MainGuiScript.HeightMap.ReadPixels(new Rect(0, 0, _tempHeightMap.width, _tempHeightMap.height), 0, 0); + MainGuiScript.HeightMap.Apply(); + RenderTexture.active = null; - RenderTexture.active = _TempHeightMap; - MainGuiScript._HeightMap = new Texture2D( _TempHeightMap.width, _TempHeightMap.height, TextureFormat.ARGB32, true, true ); - MainGuiScript._HeightMap.ReadPixels(new Rect(0, 0, _TempHeightMap.width, _TempHeightMap.height), 0, 0); - MainGuiScript._HeightMap.Apply(); - RenderTexture.active = null; + // Save high fidelity for normal making + if (MainGuiScript.HdHeightMap != null) + { + MainGuiScript.HdHeightMap.Release(); + MainGuiScript.HdHeightMap = null; + } - // Save high fidelity for normal making - if (MainGuiScript._HDHeightMap != null) { - MainGuiScript._HDHeightMap.Release (); - MainGuiScript._HDHeightMap = null; - } - MainGuiScript._HDHeightMap = new RenderTexture (_TempHeightMap.width, _TempHeightMap.height, 0, RenderTextureFormat.RHalf, RenderTextureReadWrite.Linear); - MainGuiScript._HDHeightMap.wrapMode = TextureWrapMode.Repeat; - Graphics.Blit(_BlurMap0, MainGuiScript._HDHeightMap, blitMaterial, 2); + MainGuiScript.HdHeightMap = new RenderTexture(_tempHeightMap.width, _tempHeightMap.height, 0, + RenderTextureFormat.RHalf, RenderTextureReadWrite.Linear) {wrapMode = TextureWrapMode.Repeat}; + Graphics.Blit(_blurMap0, MainGuiScript.HdHeightMap, _blitMaterial, 2); - CleanupTexture (_TempHeightMap); + CleanupTexture(_tempHeightMap); - yield return new WaitForSeconds(0.1f); + yield return new WaitForSeconds(0.1f); - busy = false; - } + Busy = false; + } - public IEnumerator ProcessNormal() + private IEnumerator ProcessNormal() { - busy = true; + Busy = true; Debug.Log("Processing Normal"); - blitMaterialNormal.SetVector("_ImageSize", new Vector4(imageSizeX, imageSizeY, 0, 0)); - blitMaterialNormal.SetFloat("_Spread", HFDS.Spread); - blitMaterialNormal.SetFloat("_SpreadBoost", HFDS.SpreadBoost); - blitMaterialNormal.SetFloat("_Samples", (int)HFDS.Spread); - blitMaterialNormal.SetTexture("_MainTex", MainGuiScript._NormalMap); - blitMaterialNormal.SetTexture("_BlendTex", _BlurMap1); + _blitMaterialNormal.SetVector(ImageSize, new Vector4(_imageSizeX, _imageSizeY, 0, 0)); + _blitMaterialNormal.SetFloat(Spread, _heightFromDiffuseSettings.Spread); + _blitMaterialNormal.SetFloat(SpreadBoost, _heightFromDiffuseSettings.SpreadBoost); + _blitMaterialNormal.SetFloat(Samples, (int) _heightFromDiffuseSettings.Spread); + _blitMaterialNormal.SetTexture(MainTex, MainGuiScript.NormalMap); + _blitMaterialNormal.SetTexture(BlendTex, _blurMap1); - thisMaterial.SetFloat("_IsNormal", 1.0f); - thisMaterial.SetTexture("_BlurTex0", _BlurMap0); - thisMaterial.SetTexture("_BlurTex1", _BlurMap1); - thisMaterial.SetTexture("_MainTex", MainGuiScript._NormalMap); + ThisMaterial.SetFloat(IsNormal, 1.0f); + ThisMaterial.SetTexture(BlurTex0, _blurMap0); + ThisMaterial.SetTexture(BlurTex1, _blurMap1); + ThisMaterial.SetTexture(MainTex, MainGuiScript.NormalMap); - int yieldCountDown = 5; + var yieldCountDown = 5; - for (int i = 1; i < 100; i++) + for (var i = 1; i < 100; i++) { + _blitMaterialNormal.SetFloat(BlendAmount, 1.0f / i); + _blitMaterialNormal.SetFloat(Progress, i / 100.0f); - blitMaterialNormal.SetFloat("_BlendAmount", 1.0f / (float)i); - blitMaterialNormal.SetFloat("_Progress", (float)i / 100.0f); + Graphics.Blit(MainGuiScript.NormalMap, _blurMap0, _blitMaterialNormal, 0); + Graphics.Blit(_blurMap0, _blurMap1); - Graphics.Blit(MainGuiScript._NormalMap, _BlurMap0, blitMaterialNormal, 0); - Graphics.Blit(_BlurMap0, _BlurMap1); - - yieldCountDown -= 1; - if( yieldCountDown <= 0 ){ - yieldCountDown = 5; - yield return new WaitForSeconds(0.01f); - } + yieldCountDown -= 1; + if (yieldCountDown > 0) continue; + yieldCountDown = 5; + yield return new WaitForSeconds(0.01f); } - busy = false; - + Busy = false; } - public IEnumerator ProcessDiffuse () + public IEnumerator ProcessDiffuse() { - busy = true; - - Debug.Log ("Processing Diffuse"); - - thisMaterial.SetFloat("_IsNormal", 0.0f); - - if (HFDS.IsolateSample1) { - blitMaterialSample.SetInt ("_IsolateSample1", 1); - } else { - blitMaterialSample.SetInt ("_IsolateSample1", 0); - } - if (HFDS.UseSample1) { - blitMaterialSample.SetInt ("_UseSample1", 1); - } else { - blitMaterialSample.SetInt ("_UseSample1", 0); - } - blitMaterialSample.SetColor ("_SampleColor1", HFDS.SampleColor1); - blitMaterialSample.SetVector ("_SampleUV1", new Vector4 (HFDS.SampleUV1.x, HFDS.SampleUV1.y, 0, 0)); - blitMaterialSample.SetFloat ("_HueWeight1", HFDS.HueWeight1); - blitMaterialSample.SetFloat ("_SatWeight1", HFDS.SatWeight1); - blitMaterialSample.SetFloat ("_LumWeight1", HFDS.LumWeight1); - blitMaterialSample.SetFloat ("_MaskLow1", HFDS.MaskLow1); - blitMaterialSample.SetFloat ("_MaskHigh1", HFDS.MaskHigh1); - blitMaterialSample.SetFloat ("_Sample1Height", HFDS.Sample1Height); - - if (HFDS.IsolateSample2) { - blitMaterialSample.SetInt ("_IsolateSample2", 1); - } else { - blitMaterialSample.SetInt ("_IsolateSample2", 0); - } - if (HFDS.UseSample2) { - blitMaterialSample.SetInt ("_UseSample2", 1); - } else { - blitMaterialSample.SetInt ("_UseSample2", 0); - } - blitMaterialSample.SetColor ("_SampleColor2", HFDS.SampleColor2); - blitMaterialSample.SetVector ("_SampleUV2", new Vector4 (HFDS.SampleUV2.x, HFDS.SampleUV2.y, 0, 0)); - blitMaterialSample.SetFloat ("_HueWeight2", HFDS.HueWeight2); - blitMaterialSample.SetFloat ("_SatWeight2", HFDS.SatWeight2); - blitMaterialSample.SetFloat ("_LumWeight2", HFDS.LumWeight2); - blitMaterialSample.SetFloat ("_MaskLow2", HFDS.MaskLow2); - blitMaterialSample.SetFloat ("_MaskHigh2", HFDS.MaskHigh2); - blitMaterialSample.SetFloat ("_Sample2Height", HFDS.Sample2Height); - - if (HFDS.UseSample1 == false && HFDS.UseSample2 == false) { - blitMaterialSample.SetFloat ("_SampleBlend", 0.0f); - } else { - blitMaterialSample.SetFloat ("_SampleBlend", HFDS.SampleBlend); - } - - blitMaterialSample.SetFloat ("_FinalContrast", HFDS.FinalContrast); - blitMaterialSample.SetFloat ("_FinalBias", HFDS.FinalBias); - - if (HFDS.useOriginalDiffuse) { - Graphics.Blit(MainGuiScript._DiffuseMapOriginal, _BlurMap0, blitMaterialSample, 0); - } else { - Graphics.Blit(MainGuiScript._DiffuseMap, _BlurMap0, blitMaterialSample, 0); - } - - blitMaterial.SetVector ("_ImageSize", new Vector4( imageSizeX, imageSizeY, 0, 0 ) ); - blitMaterial.SetFloat ("_BlurContrast", 1.0f); - - float extraSpread = ( (float)(_BlurMap0.width + _BlurMap0.height) * 0.5f ) / 1024.0f; - float spread = 1.0f; - - // Blur the image 1 - blitMaterial.SetInt ("_BlurSamples", 4); - blitMaterial.SetFloat ("_BlurSpread", spread); - blitMaterial.SetVector ("_BlurDirection", new Vector4(1,0,0,0) ); - Graphics.Blit(_BlurMap0, _TempBlurMap, blitMaterial, 1); - blitMaterial.SetVector ("_BlurDirection", new Vector4(0,1,0,0) ); - Graphics.Blit(_TempBlurMap, _BlurMap1, blitMaterial, 1); - - spread += extraSpread; - - // Blur the image 2 - blitMaterial.SetFloat ("_BlurSpread", spread); - blitMaterial.SetVector ("_BlurDirection", new Vector4(1,0,0,0) ); - Graphics.Blit(_BlurMap1, _TempBlurMap, blitMaterial, 1); - blitMaterial.SetVector ("_BlurDirection", new Vector4(0,1,0,0) ); - Graphics.Blit(_TempBlurMap, _BlurMap2, blitMaterial, 1); - - spread += 2 * extraSpread; - - // Blur the image 3 - blitMaterial.SetFloat ("_BlurSpread", spread); - blitMaterial.SetVector ("_BlurDirection", new Vector4(1,0,0,0) ); - Graphics.Blit(_BlurMap2, _TempBlurMap, blitMaterial, 1); - blitMaterial.SetVector ("_BlurDirection", new Vector4(0,1,0,0) ); - Graphics.Blit(_TempBlurMap, _BlurMap3, blitMaterial, 1); - - spread += 4 * extraSpread; - - // Blur the image 4 - blitMaterial.SetFloat ("_BlurSpread", spread); - blitMaterial.SetVector ("_BlurDirection", new Vector4(1,0,0,0) ); - Graphics.Blit(_BlurMap3, _TempBlurMap, blitMaterial, 1); - blitMaterial.SetVector ("_BlurDirection", new Vector4(0,1,0,0) ); - Graphics.Blit(_TempBlurMap, _BlurMap4, blitMaterial, 1); - - spread += 8 * extraSpread; - - // Blur the image 5 - blitMaterial.SetFloat ("_BlurSpread", spread); - blitMaterial.SetVector ("_BlurDirection", new Vector4(1,0,0,0) ); - Graphics.Blit(_BlurMap4, _TempBlurMap, blitMaterial, 1); - blitMaterial.SetVector ("_BlurDirection", new Vector4(0,1,0,0) ); - Graphics.Blit(_TempBlurMap, _BlurMap5, blitMaterial, 1); - - spread += 16 * extraSpread; - - // Blur the image 6 - blitMaterial.SetFloat ("_BlurSpread", spread); - blitMaterial.SetVector ("_BlurDirection", new Vector4(1,0,0,0) ); - Graphics.Blit(_BlurMap5, _TempBlurMap, blitMaterial, 1); - blitMaterial.SetVector ("_BlurDirection", new Vector4(0,1,0,0) ); - Graphics.Blit(_TempBlurMap, _BlurMap6, blitMaterial, 1); - - - // Average Color - blitMaterial.SetInt ("_BlurSamples", 32); - blitMaterial.SetFloat ("_BlurSpread", 64.0f * extraSpread); - blitMaterial.SetVector ("_BlurDirection", new Vector4(1,0,0,0) ); - Graphics.Blit(_BlurMap6, _AvgTempMap, blitMaterial, 1); - blitMaterial.SetVector ("_BlurDirection", new Vector4(0,1,0,0) ); - Graphics.Blit(_AvgTempMap, _AvgMap, blitMaterial, 1); - - - if ( HFDS.useOriginalDiffuse ) { - thisMaterial.SetTexture("_MainTex", MainGuiScript._DiffuseMapOriginal); - } else { - thisMaterial.SetTexture("_MainTex", MainGuiScript._DiffuseMap); - } - - thisMaterial.SetTexture ("_BlurTex0", _BlurMap0); - thisMaterial.SetTexture ("_BlurTex1", _BlurMap1); - thisMaterial.SetTexture ("_BlurTex2", _BlurMap2); - thisMaterial.SetTexture ("_BlurTex3", _BlurMap3); - thisMaterial.SetTexture ("_BlurTex4", _BlurMap4); - thisMaterial.SetTexture ("_BlurTex5", _BlurMap5); - thisMaterial.SetTexture ("_BlurTex6", _BlurMap6); - thisMaterial.SetTexture ("_AvgTex", _AvgMap); - - yield return new WaitForSeconds(0.01f); - - busy = false; - } -} + Busy = true; + ThisMaterial.SetFloat(IsNormal, 0.0f); + + _blitMaterialSample.SetInt(IsolateSample1, _heightFromDiffuseSettings.IsolateSample1 ? 1 : 0); + _blitMaterialSample.SetInt(UseSample1, _heightFromDiffuseSettings.UseSample1 ? 1 : 0); + _blitMaterialSample.SetColor(SampleColor1, _heightFromDiffuseSettings.SampleColor1); + _blitMaterialSample.SetVector(SampleUv1, + new Vector4(_heightFromDiffuseSettings.SampleUv1.x, _heightFromDiffuseSettings.SampleUv1.y, 0, 0)); + _blitMaterialSample.SetFloat(HueWeight1, _heightFromDiffuseSettings.HueWeight1); + _blitMaterialSample.SetFloat(SatWeight1, _heightFromDiffuseSettings.SatWeight1); + _blitMaterialSample.SetFloat(LumWeight1, _heightFromDiffuseSettings.LumWeight1); + _blitMaterialSample.SetFloat(MaskLow1, _heightFromDiffuseSettings.MaskLow1); + _blitMaterialSample.SetFloat(MaskHigh1, _heightFromDiffuseSettings.MaskHigh1); + _blitMaterialSample.SetFloat(Sample1Height, _heightFromDiffuseSettings.Sample1Height); + + _blitMaterialSample.SetInt(IsolateSample2, _heightFromDiffuseSettings.IsolateSample2 ? 1 : 0); + _blitMaterialSample.SetInt(UseSample2, _heightFromDiffuseSettings.UseSample2 ? 1 : 0); + _blitMaterialSample.SetColor(SampleColor2, _heightFromDiffuseSettings.SampleColor2); + _blitMaterialSample.SetVector(SampleUv2, + new Vector4(_heightFromDiffuseSettings.SampleUv2.x, _heightFromDiffuseSettings.SampleUv2.y, 0, 0)); + _blitMaterialSample.SetFloat(HueWeight2, _heightFromDiffuseSettings.HueWeight2); + _blitMaterialSample.SetFloat(SatWeight2, _heightFromDiffuseSettings.SatWeight2); + _blitMaterialSample.SetFloat(LumWeight2, _heightFromDiffuseSettings.LumWeight2); + _blitMaterialSample.SetFloat(MaskLow2, _heightFromDiffuseSettings.MaskLow2); + _blitMaterialSample.SetFloat(MaskHigh2, _heightFromDiffuseSettings.MaskHigh2); + _blitMaterialSample.SetFloat(Sample2Height, _heightFromDiffuseSettings.Sample2Height); + + if (_heightFromDiffuseSettings.UseSample1 == false && _heightFromDiffuseSettings.UseSample2 == false) + _blitMaterialSample.SetFloat(SampleBlend, 0.0f); + else + _blitMaterialSample.SetFloat(SampleBlend, _heightFromDiffuseSettings.SampleBlend); + + _blitMaterialSample.SetFloat(FinalContrast, _heightFromDiffuseSettings.FinalContrast); + _blitMaterialSample.SetFloat(FinalBias, _heightFromDiffuseSettings.FinalBias); + + Graphics.Blit( + _heightFromDiffuseSettings.UseOriginalDiffuse ? MainGuiScript.DiffuseMapOriginal : MainGuiScript.DiffuseMap, + _blurMap0, _blitMaterialSample, 0); + + _blitMaterial.SetVector(ImageSize, new Vector4(_imageSizeX, _imageSizeY, 0, 0)); + _blitMaterial.SetFloat(BlurContrast, 1.0f); + + var extraSpread = (_blurMap0.width + _blurMap0.height) * 0.5f / 1024.0f; + var spread = 1.0f; + + // Blur the image 1 + _blitMaterial.SetInt(BlurSamples, 4); + _blitMaterial.SetFloat(BlurSpread, spread); + _blitMaterial.SetVector(BlurDirection, new Vector4(1, 0, 0, 0)); + Graphics.Blit(_blurMap0, _tempBlurMap, _blitMaterial, 1); + _blitMaterial.SetVector(BlurDirection, new Vector4(0, 1, 0, 0)); + Graphics.Blit(_tempBlurMap, _blurMap1, _blitMaterial, 1); + + spread += extraSpread; + + // Blur the image 2 + _blitMaterial.SetFloat(BlurSpread, spread); + _blitMaterial.SetVector(BlurDirection, new Vector4(1, 0, 0, 0)); + Graphics.Blit(_blurMap1, _tempBlurMap, _blitMaterial, 1); + _blitMaterial.SetVector(BlurDirection, new Vector4(0, 1, 0, 0)); + Graphics.Blit(_tempBlurMap, _blurMap2, _blitMaterial, 1); + + spread += 2 * extraSpread; + + // Blur the image 3 + _blitMaterial.SetFloat(BlurSpread, spread); + _blitMaterial.SetVector(BlurDirection, new Vector4(1, 0, 0, 0)); + Graphics.Blit(_blurMap2, _tempBlurMap, _blitMaterial, 1); + _blitMaterial.SetVector(BlurDirection, new Vector4(0, 1, 0, 0)); + Graphics.Blit(_tempBlurMap, _blurMap3, _blitMaterial, 1); + + spread += 4 * extraSpread; + + // Blur the image 4 + _blitMaterial.SetFloat(BlurSpread, spread); + _blitMaterial.SetVector(BlurDirection, new Vector4(1, 0, 0, 0)); + Graphics.Blit(_blurMap3, _tempBlurMap, _blitMaterial, 1); + _blitMaterial.SetVector(BlurDirection, new Vector4(0, 1, 0, 0)); + Graphics.Blit(_tempBlurMap, _blurMap4, _blitMaterial, 1); + + spread += 8 * extraSpread; + + // Blur the image 5 + _blitMaterial.SetFloat(BlurSpread, spread); + _blitMaterial.SetVector(BlurDirection, new Vector4(1, 0, 0, 0)); + Graphics.Blit(_blurMap4, _tempBlurMap, _blitMaterial, 1); + _blitMaterial.SetVector(BlurDirection, new Vector4(0, 1, 0, 0)); + Graphics.Blit(_tempBlurMap, _blurMap5, _blitMaterial, 1); + + spread += 16 * extraSpread; + + // Blur the image 6 + _blitMaterial.SetFloat(BlurSpread, spread); + _blitMaterial.SetVector(BlurDirection, new Vector4(1, 0, 0, 0)); + Graphics.Blit(_blurMap5, _tempBlurMap, _blitMaterial, 1); + _blitMaterial.SetVector(BlurDirection, new Vector4(0, 1, 0, 0)); + Graphics.Blit(_tempBlurMap, _blurMap6, _blitMaterial, 1); + + + // Average Color + _blitMaterial.SetInt(BlurSamples, 32); + _blitMaterial.SetFloat(BlurSpread, 64.0f * extraSpread); + _blitMaterial.SetVector(BlurDirection, new Vector4(1, 0, 0, 0)); + Graphics.Blit(_blurMap6, _avgTempMap, _blitMaterial, 1); + _blitMaterial.SetVector(BlurDirection, new Vector4(0, 1, 0, 0)); + Graphics.Blit(_avgTempMap, _avgMap, _blitMaterial, 1); + + + ThisMaterial.SetTexture(MainTex, + _heightFromDiffuseSettings.UseOriginalDiffuse + ? MainGuiScript.DiffuseMapOriginal + : MainGuiScript.DiffuseMap); + + ThisMaterial.SetTexture(BlurTex0, _blurMap0); + ThisMaterial.SetTexture(BlurTex1, _blurMap1); + ThisMaterial.SetTexture(BlurTex2, _blurMap2); + ThisMaterial.SetTexture(BlurTex3, _blurMap3); + ThisMaterial.SetTexture(BlurTex4, _blurMap4); + ThisMaterial.SetTexture(BlurTex5, _blurMap5); + ThisMaterial.SetTexture(BlurTex6, _blurMap6); + ThisMaterial.SetTexture(AvgTex, _avgMap); + + yield return new WaitForSeconds(0.01f); + + Busy = false; + } +} \ No newline at end of file diff --git a/Assets/Scripts/HeightFromDiffuseSettings.cs b/Assets/Scripts/HeightFromDiffuseSettings.cs new file mode 100644 index 00000000..616f884e --- /dev/null +++ b/Assets/Scripts/HeightFromDiffuseSettings.cs @@ -0,0 +1,175 @@ +#region + +using System.ComponentModel; +using UnityEngine; + +#endregion + +public class HeightFromDiffuseSettings +{ + [DefaultValue(1.0f)] public float Blur0Contrast; + + + [DefaultValue(0.15f)] public float Blur0Weight; + + [DefaultValue(1.0f)] public float Blur1Contrast; + + [DefaultValue(0.19f)] public float Blur1Weight; + + [DefaultValue(1.0f)] public float Blur2Contrast; + + [DefaultValue(0.3f)] public float Blur2Weight; + + [DefaultValue(1.0f)] public float Blur3Contrast; + + [DefaultValue(0.5f)] public float Blur3Weight; + + [DefaultValue(1.0f)] public float Blur4Contrast; + + [DefaultValue(0.7f)] public float Blur4Weight; + + [DefaultValue(1.0f)] public float Blur5Contrast; + + [DefaultValue(0.9f)] public float Blur5Weight; + + [DefaultValue(1.0f)] public float Blur6Contrast; + + [DefaultValue(1.0f)] public float Blur6Weight; + + [DefaultValue(0.0f)] public float FinalBias; + + [DefaultValue("0")] public string FinalBiasText; + + [DefaultValue(1.5f)] public float FinalContrast; + + [DefaultValue("1.5")] public string FinalContrastText; + + [DefaultValue(0.0f)] public float FinalGain; + + [DefaultValue("0")] public string FinalGainText; + + [DefaultValue(1.0f)] public float HueWeight1; + + [DefaultValue(1.0f)] public float HueWeight2; + + [DefaultValue(false)] public bool IsolateSample1; + + [DefaultValue(false)] public bool IsolateSample2; + + [DefaultValue(0.2f)] public float LumWeight1; + + [DefaultValue(0.2f)] public float LumWeight2; + + [DefaultValue(1.0f)] public float MaskHigh1; + + [DefaultValue(1.0f)] public float MaskHigh2; + + [DefaultValue(0.0f)] public float MaskLow1; + + [DefaultValue(0.0f)] public float MaskLow2; + + [DefaultValue(0.5f)] public float Sample1Height; + + [DefaultValue(0.5f)] public float Sample2Height; + + [DefaultValue(0.5f)] public float SampleBlend; + + [DefaultValue("0.5")] public string SampleBlendText; + + //[DefaultValueAttribute(Color.black)] + public Color SampleColor1; + + //[DefaultValueAttribute(Color.black)] + public Color SampleColor2; + + //[DefaultValueAttribute(Vector2.zero)] + public Vector2 SampleUv1; + + //[DefaultValueAttribute(Vector2.zero)] + public Vector2 SampleUv2; + + [DefaultValue(0.5f)] public float SatWeight1; + + [DefaultValue(0.5f)] public float SatWeight2; + + [DefaultValue(50.0f)] public float Spread; + + [DefaultValue(1.0f)] public float SpreadBoost; + + [DefaultValue("1")] public string SpreadBoostText; + + [DefaultValue("50")] public string SpreadText; + + [DefaultValue(true)] public bool UseAdjustedDiffuse; + + [DefaultValue(false)] public bool UseNormal; + + [DefaultValue(false)] public bool UseOriginalDiffuse; + + [DefaultValue(false)] public bool UseSample1; + + [DefaultValue(false)] public bool UseSample2; + + public HeightFromDiffuseSettings() + { + UseAdjustedDiffuse = true; + UseOriginalDiffuse = false; + UseNormal = false; + + Blur0Weight = 0.15f; + Blur1Weight = 0.19f; + Blur2Weight = 0.3f; + Blur3Weight = 0.5f; + Blur4Weight = 0.7f; + Blur5Weight = 0.9f; + Blur6Weight = 1.0f; + + Blur0Contrast = 1.0f; + Blur1Contrast = 1.0f; + Blur2Contrast = 1.0f; + Blur3Contrast = 1.0f; + Blur4Contrast = 1.0f; + Blur5Contrast = 1.0f; + Blur6Contrast = 1.0f; + + SampleColor1 = Color.black; + SampleUv1 = Vector2.zero; + UseSample1 = false; + IsolateSample1 = false; + HueWeight1 = 1.0f; + SatWeight1 = 0.5f; + LumWeight1 = 0.2f; + MaskLow1 = 0.0f; + MaskHigh1 = 1.0f; + Sample1Height = 0.5f; + + SampleColor2 = Color.black; + SampleUv2 = Vector2.zero; + UseSample2 = false; + IsolateSample2 = false; + HueWeight2 = 1.0f; + SatWeight2 = 0.5f; + LumWeight2 = 0.2f; + MaskLow2 = 0.0f; + MaskHigh2 = 1.0f; + Sample2Height = 0.3f; + + FinalContrast = 1.5f; + FinalContrastText = "1.5"; + + FinalBias = 0.0f; + FinalBiasText = "0.0"; + + FinalGain = 0.0f; + FinalGainText = "0.0"; + + SampleBlend = 0.5f; + SampleBlendText = "0.5"; + + Spread = 50.0f; + SpreadText = "50"; + + SpreadBoost = 1.0f; + SpreadBoostText = "1"; + } +} \ No newline at end of file diff --git a/Assets/Scripts/HeightFromDiffuseSettings.cs.meta b/Assets/Scripts/HeightFromDiffuseSettings.cs.meta new file mode 100644 index 00000000..54546d7e --- /dev/null +++ b/Assets/Scripts/HeightFromDiffuseSettings.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 5597a94af0aa46e0b8a9e60ae791318f +timeCreated: 1549045031 \ No newline at end of file diff --git a/Assets/Scripts/MainGui.cs b/Assets/Scripts/MainGui.cs index ac130c48..6a1a3532 100644 --- a/Assets/Scripts/MainGui.cs +++ b/Assets/Scripts/MainGui.cs @@ -1,1755 +1,1345 @@ - +#region + using System; -using System.Net; -using System.IO; -using System.Text; -using FreeImageAPI; -using UnityEngine; -using System.Collections; using System.Collections.Generic; -using System.Runtime.InteropServices; -using System.Diagnostics; - -public enum Textures { - height, - diffuse, - diffuseOriginal, - specular, - roughness, - normal, - msao -} - -public enum PropChannelMap { - None, - Height, - Metallic, - Smoothness, - Edge, - Ao, - AoEdge -} - - -public class MainGui : MonoBehaviour { - - public static MainGui instance; - - string message = ""; - float alpha = 1.0f; - char pathChar = '/'; - - //Rect toolsWindowRect = new Rect( 0, 0, 500, 500 ); - //int toolsWindowID = 50; - string toolsWindowTitle = "Texture Tools"; - - MapType mapTypeToLoad; - Texture2D textureToLoad; - Texture2D textureToSave; - string mapType = ""; - - public GameObject HeightFromDiffuseGuiObject; - HeightFromDiffuseGui HeightFromDiffuseGuiScript; - - public GameObject NormalFromHeightGuiObject; - NormalFromHeightGui NormalFromHeightGuiScript; - - public GameObject EdgeFromNormalGuiObject; - EdgeFromNormalGui EdgeFromNormalGuiScript; - - public GameObject AOFromNormalGuiObject; - AOFromNormalGui AOFromNormalGuiScript; - - public GameObject EditDiffuseGuiObject; - EditDiffuseGui EditDiffuseGuiScript; - - public GameObject MetallicGuiObject; - MetallicGui MetallicGuiScript; - - public GameObject SmoothnessGuiObject; - SmoothnessGui SmoothnessGuiScript; - - public GameObject MaterialGuiObject; - MaterialGui MaterialGuiScript; - - public GameObject PostProcessGuiObject; - PostProcessGui PostProcessGuiScript; - - public GameObject TilingTextureMakerGuiObject; - TilingTextureMakerGui TilingTextureMakerGuiScript; - - public AlignmentGui AlignmentGuiScript; - - public GameObject SuggestionGuiObject; - SuggestionGui SuggestionGuiScript; - - public GameObject SaveLoadProjectObject; - SaveLoadProject SaveLoadProjectScript; +using System.Linq; +using SFB; +using UnityEngine; +using UnityEngine.UI; - public GameObject CommandListExecutorObject; - CommandListExecutor CommandListExecutorScript; - public GameObject SettingsGuiObject; - SettingsGui SettingsGuiScript; +#endregion - public Texture2D _TextureBlack; - public Texture2D _TextureWhite; - public Texture2D _TextureGrey; - public Texture2D _TextureNormal; - - public RenderTexture _HDHeightMap; - public Texture2D _HeightMap; - public Texture2D _DiffuseMap; - public Texture2D _DiffuseMapOriginal; - public Texture2D _NormalMap; - public Texture2D _MetallicMap; - public Texture2D _SmoothnessMap; - public Texture2D _EdgeMap; - public Texture2D _AOMap; +public class MainGui : MonoBehaviour +{ + #region "Vars" + private const float GamaCorrection = 2.2f; - public Texture2D _PropertyMap; + public RawImage DiffuseTexture; + public RawImage HeightTexture; + public RawImage SmoothnessTexture; + public RawImage NormalTexture; + public RawImage MetallicTexture; + public RawImage EdgeTexture; + public RawImage AOTexture; - public Material FullMaterialRef; - public Material FullMaterial; - public Material SampleMaterialRef; - public Material SampleMaterial; + public static MainGui Instance; + public GameObject Modle; + public static readonly string[] LoadFormats = + { + "png", "jpg", "jpeg", "tga", "bmp", "exr" + }; + private bool _doOnce; + private static readonly int CorrectionId = Shader.PropertyToID("_GamaCorrection"); + private static readonly int MainTexId = Shader.PropertyToID("_MainTex"); + private static readonly int GlobalCubemapId = Shader.PropertyToID("_GlobalCubemap"); + private static readonly int DisplacementMapId = Shader.PropertyToID("_DisplacementMap"); + private static readonly int DiffuseMapId = Shader.PropertyToID("_DiffuseMap"); + private static readonly int NormalMapId = Shader.PropertyToID("_NormalMap"); + private static readonly int MetallicMapId = Shader.PropertyToID("_MetallicMap"); + private static readonly int SmoothnessMapId = Shader.PropertyToID("_SmoothnessMap"); + private static readonly int AoMapId = Shader.PropertyToID("_AOMap"); + private static readonly int EdgeMapId = Shader.PropertyToID("_EdgeMap"); + private static readonly int TilingId = Shader.PropertyToID("_Tiling"); + + private readonly ExtensionFilter[] _imageLoadFilter = + { + new ExtensionFilter("Image Files", LoadFormats) + }; + + private readonly ExtensionFilter[] _imageSaveFilter = + { + new ExtensionFilter("Image Files", "png", "jpg", "jpeg", "tga", "exr") + }; + + private MapType _activeMapType; + + private bool _busySaving; + + private bool _clearTextures; + public bool _exrSelected { get; set; } + public bool _pngSelected { get; set; } + public bool _tgaSelected { get; set; } + public bool _jpgSelected { get; set; } + + + public string _lastDirectory = ""; + + private List _objectsToUnhide; + public char _pathChar = '/'; + + private bool _propBlueChoose; + private Material _propertyCompMaterial; + + private Shader _propertyCompShader; + private bool _propGreenChoose; + private bool _propRedChoose; + private bool _propAlphaChoose; + public SaveLoadProject _saveLoadProjectScript; + private int _selectedCubemap; + private SettingsGui _settingsGuiScript; + + private Texture2D _textureToLoad; + private Texture2D _textureToSave; + + + private Material _thisMaterial; + private TilingTextureMakerGui _tilingTextureMakerGuiScript; + + public AlignmentGui AlignmentGuiScript; + + public GameObject AoFromNormalGuiObject; + public AoFromNormalGui AoFromNormalGuiScript; + public Texture2D AoMap; + + public Cubemap[] CubeMaps; + public Texture2D DiffuseMap; + public Texture2D DiffuseMapOriginal; + + public GameObject EdgeFromNormalGuiObject; + public EdgeFromNormalGui EdgeFromNormalGuiScript; + public Texture2D EdgeMap; + + public GameObject EditDiffuseGuiObject; + public EditDiffuseGui EditDiffuseGuiScript; + public Material FullMaterial; + + public Material FullMaterialRef; + + public RenderTexture HdHeightMap; + + public GameObject HeightFromDiffuseGuiObject; + public HeightFromDiffuseGui HeightFromDiffuseGuiScript; + public Texture2D HeightMap; + + public GameObject MaterialGuiObject; + public MaterialGui MaterialGuiScript; + + public GameObject MetallicGuiObject; + public MetallicGui MetallicGuiScript; + public Texture2D MetallicMap; + + public GameObject NormalFromHeightGuiObject; + public NormalFromHeightGui NormalFromHeightGuiScript; + public Texture2D NormalMap; + + public GameObject PostProcessGuiObject; + public PropChannelMap PropBlue = PropChannelMap.None; + public Texture2D TextureBlue = null; + public Texture2D PropertyMap; + public PropChannelMap PropGreen = PropChannelMap.None; + public Texture2D TextureGreen = null; + public PropChannelMap PropRed = PropChannelMap.None; + public Texture2D TextureRed = null; + public PropChannelMap PropAlpha = PropChannelMap.None; + public Texture2D TextureAlpha = null; - public GameObject testObject; - public GameObject testObjectCube; - public GameObject testObjectCylinder; - public GameObject testObjectSphere; + public string QuicksavePathAo = ""; + public string QuicksavePathDiffuse = ""; + public string QuicksavePathEdge = ""; + public string QuicksavePathHeight = ""; + public string QuicksavePathMetallic = ""; + public string QuicksavePathNormal = ""; + public string QuicksavePathProperty = ""; + public string QuicksavePathSmoothness = ""; //public Material skyboxMaterial; - public ReflectionProbe reflectionProbe; - public Cubemap[] CubeMaps; - int selectedCubemap = 0; - - Material thisMaterial; - - float _Falloff = 0.1f; - float _OverlapX = 0.2f; - float _OverlapY = 0.2f; - bool _SmoothBlend = false; - float _GamaCorrection = 2.2f; - - bool busySaving = false; - - public FileFormat selectedFormat = FileFormat.tga; - bool bmpSelected = true; - bool jpgSelected = false; - bool pngSelected = true; - bool tgaSelected = false; - bool tiffSelected = false; - - public bool hideGui = false; - Camera thisCamera; - Vector3 CameraTargetPos = Vector3.zero; - Vector3 CameraOffsetPos = Vector3.zero; - - bool clearTextures = false; - - List objectsToUnhide; - - public FileBrowser fileBrowser; - - Shader PropertyCompShader; - Material PropertyCompMaterial; - - public string QuicksavePath = ""; - public string QuicksavePathHeight = ""; - public string QuicksavePathDiffuse = ""; - public string QuicksavePathNormal = ""; - public string QuicksavePathMetallic = ""; - public string QuicksavePathSmoothness = ""; - public string QuicksavePathEdge = ""; - public string QuicksavePathAO = ""; - public string QuicksavePathProperty = ""; - - public PropChannelMap propRed = PropChannelMap.None; - public PropChannelMap propGreen = PropChannelMap.None; - public PropChannelMap propBlue = PropChannelMap.None; - bool propRedChoose = false; - bool propGreenChoose = false; - bool propBlueChoose = false; - - private ClipboardImageHelper.ClipboardImage CIH; - - [DllImport ("FreeImage")] - private static extern FIBITMAP FreeImage_Load( FREE_IMAGE_FORMAT fif, string filename, int flags ); - - [DllImport ("FreeImage")] - private static extern void FreeImage_Unload( FIBITMAP dib ); - - [DllImport ("FreeImage")] - private static extern bool FreeImage_Save( FREE_IMAGE_FORMAT fif, FIBITMAP dib, string filename, FREE_IMAGE_SAVE_FLAGS flags ); - - [DllImport ("FreeImage")] - private static extern int FreeImage_GetHeight( FIBITMAP dib ); - - [DllImport ("FreeImage")] - private static extern int FreeImage_GetWidth( FIBITMAP dib ); - - [DllImport ("FreeImage")] - private static extern bool FreeImage_GetPixelColor( FIBITMAP dib, int x, int y, RGBQUAD value ); - - [DllImport ("FreeImage")] - private static extern FIBITMAP FreeImage_MakeThumbnail( FIBITMAP dib, int max_pixel_size, bool convert ); - - void Start () { - - MainGui.instance = this; - - _HeightMap = null; - _HDHeightMap = null; - _DiffuseMap = null; - _DiffuseMapOriginal = null; - _NormalMap = null; - _MetallicMap = null; - _SmoothnessMap = null; - _EdgeMap = null; - _AOMap = null; - - //fileBrowser = this.GetComponent (); - - PropertyCompShader = Shader.Find ("Hidden/Blit_Property_Comp"); - PropertyCompMaterial = new Material (PropertyCompShader); - - thisCamera = Camera.main; - CameraTargetPos = thisCamera.transform.position; - CameraOffsetPos = CameraTargetPos; - - Shader.SetGlobalFloat ("_GamaCorrection", _GamaCorrection); - - FullMaterial = new Material ( FullMaterialRef.shader ); - FullMaterial.CopyPropertiesFromMaterial (FullMaterialRef); - //FullMaterial = null; - //FullMaterial = tempFullMaterial; - - SampleMaterial = new Material ( SampleMaterialRef.shader ); - SampleMaterial.CopyPropertiesFromMaterial (SampleMaterialRef); - //SampleMaterial = null; - //SampleMaterial = tempSampleMaterial; - - HeightFromDiffuseGuiScript = HeightFromDiffuseGuiObject.GetComponent(); - NormalFromHeightGuiScript = NormalFromHeightGuiObject.GetComponent(); - EdgeFromNormalGuiScript = EdgeFromNormalGuiObject.GetComponent(); - AOFromNormalGuiScript = AOFromNormalGuiObject.GetComponent(); - EditDiffuseGuiScript = EditDiffuseGuiObject.GetComponent(); - MetallicGuiScript = MetallicGuiObject.GetComponent (); - SmoothnessGuiScript = SmoothnessGuiObject.GetComponent(); - MaterialGuiScript = MaterialGuiObject.GetComponent(); - PostProcessGuiScript = PostProcessGuiObject.GetComponent (); - TilingTextureMakerGuiScript = TilingTextureMakerGuiObject.GetComponent(); - SuggestionGuiScript = SuggestionGuiObject.GetComponent(); - SaveLoadProjectScript = SaveLoadProjectObject.GetComponent(); - CommandListExecutorScript = CommandListExecutorObject.GetComponent (); - SettingsGuiScript = SettingsGuiObject.GetComponent (); - - SettingsGuiScript.LoadSettings(); - - //HeightFromNormalGuiScript = HeightFromNormalGuiObject.GetComponent(); - - if (Application.platform == RuntimePlatform.WindowsEditor || Application.platform == RuntimePlatform.WindowsPlayer) { - pathChar = '\\'; - } - - CIH = new ClipboardImageHelper.ClipboardImage (); - - testObject.GetComponent().material = FullMaterial; - SetMaterialValues(); - - reflectionProbe.RenderProbe(); - - } - - public void SetPreviewMaterial( Texture2D textureToPreview ) { - CloseWindows(); - if (textureToPreview != null) { - FixSizeMap (textureToPreview); - SampleMaterial.SetTexture("_MainTex", textureToPreview ); - testObject.GetComponent().material = SampleMaterial; - } - } - - public void SetPreviewMaterial( RenderTexture textureToPreview ) { - CloseWindows(); - if (textureToPreview != null) { - FixSizeMap (textureToPreview); - SampleMaterial.SetTexture("_MainTex", textureToPreview ); - testObject.GetComponent().material = SampleMaterial; - } - } - - public void SetMaterialValues() { - - Shader.SetGlobalTexture ("_GlobalCubemap", CubeMaps[selectedCubemap] ); - - if (_HeightMap != null) { - FullMaterial.SetTexture ("_DisplacementMap", _HeightMap); - } else { - FullMaterial.SetTexture ("_DisplacementMap", _TextureGrey); - } - - if (_DiffuseMap != null) { - FullMaterial.SetTexture ("_DiffuseMap", _DiffuseMap); - } else if (_DiffuseMapOriginal != null) { - FullMaterial.SetTexture ("_DiffuseMap", _DiffuseMapOriginal); - } else { - FullMaterial.SetTexture ("_DiffuseMap", _TextureGrey); - } - - if (_NormalMap != null) { - FullMaterial.SetTexture ("_NormalMap", _NormalMap); - } else { - FullMaterial.SetTexture ("_NormalMap", _TextureNormal); - } - - if (_MetallicMap != null) { - FullMaterial.SetTexture ("_MetallicMap", _MetallicMap); - } else { - FullMaterial.SetTexture ("_MetallicMap", _TextureBlack); - } - - if (_SmoothnessMap != null) { - FullMaterial.SetTexture ("_SmoothnessMap", _SmoothnessMap); - } else { - FullMaterial.SetTexture ("_SmoothnessMap", _TextureBlack); - } - - if (_AOMap != null) { - FullMaterial.SetTexture ("_AOMap", _AOMap); - } else { - FullMaterial.SetTexture ("_AOMap", _TextureWhite); - } - - if (_EdgeMap != null) { - FullMaterial.SetTexture ("_EdgeMap", _EdgeMap); - } else { - FullMaterial.SetTexture ("_EdgeMap", _TextureGrey); - } - - testObject.GetComponent().material = FullMaterial; - - FullMaterial.SetVector ("_Tiling", new Vector4 (1, 1, 0, 0)); - - } - - public void CloseWindows() { - HeightFromDiffuseGuiScript.Close (); - NormalFromHeightGuiScript.Close (); - EdgeFromNormalGuiScript.Close (); - AOFromNormalGuiScript.Close (); - EditDiffuseGuiScript.Close (); - MetallicGuiScript.Close (); - SmoothnessGuiScript.Close (); - TilingTextureMakerGuiScript.Close (); - AlignmentGuiScript.Close (); - MaterialGuiObject.SetActive (false); - PostProcessGuiObject.SetActive (false); - //SettingsGuiObject.SetActive (false); - //SuggestionGuiObject.SetActive (false); - } - - void HideWindows() { - - objectsToUnhide = new List (); - - if (HeightFromDiffuseGuiObject.activeSelf) { - objectsToUnhide.Add( HeightFromDiffuseGuiObject ); - } - - if (NormalFromHeightGuiObject.activeSelf) { - objectsToUnhide.Add( NormalFromHeightGuiObject ); - } - - if (EdgeFromNormalGuiObject.activeSelf) { - objectsToUnhide.Add( EdgeFromNormalGuiObject ); - } - - if (AOFromNormalGuiObject.activeSelf) { - objectsToUnhide.Add( AOFromNormalGuiObject ); - } - - if (EditDiffuseGuiObject.activeSelf) { - objectsToUnhide.Add( EditDiffuseGuiObject ); - } - - if (MetallicGuiObject.activeSelf) { - objectsToUnhide.Add( MetallicGuiObject ); - } - - if (SmoothnessGuiObject.activeSelf) { - objectsToUnhide.Add( SmoothnessGuiObject ); - } - - if (MaterialGuiObject.activeSelf) { - objectsToUnhide.Add( MaterialGuiObject ); - } - - if( PostProcessGuiObject.activeSelf){ - objectsToUnhide.Add( PostProcessGuiObject ); - } - - if (TilingTextureMakerGuiObject.activeSelf) { - objectsToUnhide.Add( TilingTextureMakerGuiObject ); - } - - //if (SettingsGuiObject.activeSelf) { - // objectsToUnhide.Add ( SettingsGuiObject ); - //} - - HeightFromDiffuseGuiObject.SetActive (false); - NormalFromHeightGuiObject.SetActive (false); - EdgeFromNormalGuiObject.SetActive (false); - AOFromNormalGuiObject.SetActive (false); - EditDiffuseGuiObject.SetActive (false); - MetallicGuiObject.SetActive (false); - SmoothnessGuiObject.SetActive (false); - MaterialGuiObject.SetActive (false); - PostProcessGuiObject.SetActive (false); - TilingTextureMakerGuiObject.SetActive (false); - //SettingsGuiObject.SetActive (false); - - } - - void Update() { - - } - - void ShowFullMaterial() { - CloseWindows(); - FixSize(); - MaterialGuiObject.SetActive(true); - MaterialGuiScript.Initialize(); - } - - void Fullscreen() { - if (Screen.fullScreen) { - Screen.fullScreen = false; - } else { - Screen.fullScreen = true; - } - } - - void SetFileMaskImage() { - fileBrowser.fileMasks = "*.png;*.jpg;*.jpeg;*.tga;*.bmp;*.tif"; - } - void SetFileMaskProject() { - fileBrowser.fileMasks = "*.mtz"; - } - - void OnGUI () { - - //==================================================// - // Unhidable Buttons // - //==================================================// - - if (GUI.Button (new Rect(Screen.width - 80, Screen.height - 40, 70, 30), "Quit")) { - Application.Quit(); - } - - GUI.enabled = false; - if (Screen.fullScreen) { - if (GUI.Button (new Rect (Screen.width - 190, Screen.height - 40, 100, 30), "Windowed")) { - Fullscreen(); - } - } else { - if (GUI.Button (new Rect (Screen.width - 190, Screen.height - 40, 100, 30), "Full Screen")) { - Fullscreen(); - } - } - GUI.enabled = true; - - if (GUI.Button (new Rect(Screen.width - 260, 10, 140, 30), "Make Suggestion")) { - SuggestionGuiObject.SetActive(true); - } - - if( hideGui == false ){ - if (GUI.Button (new Rect(Screen.width - 110, 10, 100, 30), "Hide Gui")) { - hideGui = true; - HideWindows(); - //CameraTargetPos = new Vector3(0,0,-10); - } - } else { - if (GUI.Button (new Rect(Screen.width - 110, 10, 100, 30), "Show Gui")) { - hideGui = false; - for( int i = 0; i< objectsToUnhide.Count; i++ ){ - objectsToUnhide[i].SetActive(true); - } - //CameraTargetPos = CameraOffsetPos; - } - return; - } - - //==================================================// - // Main Gui // - //==================================================// - - - int spacingX = 130; - int spacingY = 150; - - int offsetX = 20; - int offsetY = 20; - - - //==============================// - // Height Map // - //==============================// - - GUI.Box( new Rect (offsetX, offsetY, 110, 250), "Height Map" ); - - if ( _HeightMap != null ) { - GUI.DrawTexture (new Rect(offsetX + 5, offsetY + 25, 100, 100), _HeightMap ); - } - - // Paste - if (GUI.Button (new Rect(offsetX + 5, offsetY + 130, 20, 20), "P")) { - mapTypeToLoad = MapType.height; - PasteFile (); - } - - if (_HeightMap == null) { GUI.enabled = false; } else { GUI.enabled = true; } - - // Copy - if (GUI.Button (new Rect(offsetX + 30, offsetY + 130, 20, 20), "C")) { - textureToSave = _HeightMap; - CopyFile (); - } - - GUI.enabled = true; - - // Open - if (GUI.Button (new Rect(offsetX + 60, offsetY + 130, 20, 20), "O")) { - mapTypeToLoad = MapType.height; - SetFileMaskImage(); - fileBrowser.ShowBrowser( "Open Height Map", this.OpenFile); - } - - if (_HeightMap == null) { GUI.enabled = false; } else { GUI.enabled = true; } - - // Save - if (GUI.Button (new Rect(offsetX + 85, offsetY + 130, 20, 20), "S")) { - textureToSave = _HeightMap; - mapType = "_height"; - SetFileMaskImage(); - fileBrowser.ShowBrowser( "Save Height Map", this.SaveFile); - } - - - if (_HeightMap == null || QuicksavePathHeight == "") { GUI.enabled = false; } else { GUI.enabled = true; } - - // Quick Save - if (GUI.Button (new Rect(offsetX + 15, offsetY + 160, 80, 20), "Quick Save")) { - textureToSave = _HeightMap; - mapType = "_height"; - SaveFile(QuicksavePathProperty); - } - - if (_HeightMap == null) { GUI.enabled = false; } else { GUI.enabled = true; } - if (GUI.Button (new Rect(offsetX + 15, offsetY + 190, 80, 20), "Preview")) { - SetPreviewMaterial( _HeightMap ); - //SetPreviewMaterial( _HDHeightMap ); - } - GUI.enabled = true; - - if (_DiffuseMapOriginal == null && _DiffuseMap == null && _NormalMap == null) { GUI.enabled = false; } else { GUI.enabled = true; } - if (GUI.Button (new Rect(offsetX + 5, offsetY + 220, 50, 20), "Create")) { - CloseWindows(); - FixSize(); - HeightFromDiffuseGuiObject.SetActive(true); - HeightFromDiffuseGuiScript.NewTexture(); - HeightFromDiffuseGuiScript.DoStuff(); - } - GUI.enabled = true; - - if (_HeightMap == null ){ GUI.enabled = false; } else { GUI.enabled = true; } - if (GUI.Button (new Rect(offsetX + 60, offsetY + 220, 45, 20), "Clear")) { - ClearTexture(MapType.height); - CloseWindows (); - SetMaterialValues (); - FixSize (); - } - GUI.enabled = true; - - - //==============================// - // Diffuse Map // - //==============================// - - GUI.Box( new Rect (offsetX + spacingX, offsetY, 110, 250), "Diffuse Map" ); - - if (_DiffuseMap != null) { - GUI.DrawTexture (new Rect (offsetX + spacingX + 5, offsetY + 25, 100, 100), _DiffuseMap); - } else if (_DiffuseMapOriginal != null) { - GUI.DrawTexture (new Rect (offsetX + spacingX + 5, offsetY + 25, 100, 100), _DiffuseMapOriginal); - } - - // Paste - if (GUI.Button (new Rect(offsetX + spacingX + 5, offsetY + 130, 20, 20), "P")) { - mapTypeToLoad = MapType.diffuseOriginal; - PasteFile (); - } - - if ( _DiffuseMapOriginal == null && _DiffuseMap == null ) { GUI.enabled = false; } else { GUI.enabled = true; } - - // Copy - if (GUI.Button (new Rect(offsetX + spacingX + 30, offsetY + 130, 20, 20), "C")) { - if( _DiffuseMap != null ){ - textureToSave = _DiffuseMap; - }else{ - textureToSave = _DiffuseMapOriginal; - } - CopyFile (); - } - - GUI.enabled = true; - - // Open - if (GUI.Button (new Rect(offsetX + spacingX + 60, offsetY + 130, 20, 20), "O")) { - mapTypeToLoad = MapType.diffuseOriginal; - SetFileMaskImage(); - fileBrowser.ShowBrowser( "Open Diffuse Map", this.OpenFile ); - } - - if ( _DiffuseMapOriginal == null && _DiffuseMap == null ) { GUI.enabled = false; } else { GUI.enabled = true; } - - // Save - if (GUI.Button (new Rect(offsetX + spacingX + 85, offsetY + 130, 20, 20), "S")) { - if( _DiffuseMap != null ){ - textureToSave = _DiffuseMap; - }else{ - textureToSave = _DiffuseMapOriginal; - } - mapType = "_diffuse"; - SetFileMaskImage(); - fileBrowser.ShowBrowser( "Save Diffuse Map", this.SaveFile ); - } - - if ( ( _DiffuseMapOriginal == null && _DiffuseMap == null ) || QuicksavePathDiffuse == "") { GUI.enabled = false; } else { GUI.enabled = true; } - - // Quick Save - if (GUI.Button (new Rect(offsetX + spacingX + 15, offsetY + 160, 80, 20), "Quick Save")) { - if( _DiffuseMap != null ){ - textureToSave = _DiffuseMap; - }else{ - textureToSave = _DiffuseMapOriginal; - } - mapType = "_diffuse"; - SaveFile(QuicksavePathDiffuse); - } - - if ( _DiffuseMapOriginal == null && _DiffuseMap == null ) { GUI.enabled = false; } else { GUI.enabled = true; } - if (GUI.Button (new Rect(offsetX + spacingX + 15, offsetY + 190, 80, 20), "Preview")) { - if( _DiffuseMap != null ){ - SetPreviewMaterial( _DiffuseMap ); - }else{ - SetPreviewMaterial( _DiffuseMapOriginal ); - } - } - - if ( _DiffuseMapOriginal == null ) { GUI.enabled = false; } else { GUI.enabled = true; } - if (GUI.Button (new Rect(offsetX + spacingX + 5, offsetY + 220, 50, 20), "Edit")) { - CloseWindows(); - FixSize(); - EditDiffuseGuiObject.SetActive(true); - EditDiffuseGuiScript.NewTexture(); - EditDiffuseGuiScript.DoStuff(); - } - - if ( _DiffuseMapOriginal == null && _DiffuseMap == null ) { GUI.enabled = false; } else { GUI.enabled = true; } - if (GUI.Button (new Rect(offsetX + spacingX + 60, offsetY + 220, 45, 20), "Clear")) { - ClearTexture(MapType.diffuse); - CloseWindows (); - SetMaterialValues (); - FixSize (); - } - GUI.enabled = true; - - - //==============================// - // Normal Map // - //==============================// - - GUI.Box( new Rect (offsetX + spacingX * 2, offsetY, 110, 250), "Normal Map" ); - - if ( _NormalMap != null ) { - GUI.DrawTexture (new Rect(offsetX + spacingX * 2 + 5, offsetY + 25, 100, 100), _NormalMap ); - } - - // Paste - if (GUI.Button (new Rect(offsetX + spacingX * 2 + 5, offsetY + 130, 20, 20), "P")) { - mapTypeToLoad = MapType.normal; - PasteFile (); - } - - if (_NormalMap == null) { GUI.enabled = false; } else { GUI.enabled = true; } - - // Copy - if (GUI.Button (new Rect(offsetX + spacingX * 2 + 30, offsetY + 130, 20, 20), "C")) { - textureToSave = _NormalMap; - CopyFile (); - } - - GUI.enabled = true; - - //Open - if (GUI.Button (new Rect(offsetX + spacingX * 2 + 60, offsetY + 130, 20, 20), "O")) { - mapTypeToLoad = MapType.normal; - SetFileMaskImage(); - fileBrowser.ShowBrowser( "Open Normal Map", this.OpenFile ); - } - - if (_NormalMap == null) { GUI.enabled = false; } else { GUI.enabled = true; } - - // Save - if (GUI.Button (new Rect(offsetX + spacingX * 2 + 85, offsetY + 130, 20, 20), "S")) { - textureToSave = _NormalMap; - mapType = "_normal"; - SetFileMaskImage(); - fileBrowser.ShowBrowser( "Save Normal Map", this.SaveFile ); - } - - if (_NormalMap == null || QuicksavePathNormal == "") { GUI.enabled = false; } else { GUI.enabled = true; } - - // Quick Save - if (GUI.Button (new Rect(offsetX + spacingX * 2 + 15, offsetY + 160, 80, 20), "Quick Save")) { - textureToSave = _NormalMap; - mapType = "_normal"; - SaveFile(QuicksavePathNormal); - } - - if (_NormalMap == null) { GUI.enabled = false; } else { GUI.enabled = true; } - if (GUI.Button (new Rect(offsetX + spacingX * 2 + 15, offsetY + 190, 80, 20), "Preview")) { - SetPreviewMaterial( _NormalMap ); - } - - if (_HeightMap == null) { GUI.enabled = false; } else { GUI.enabled = true; } - if (GUI.Button (new Rect (offsetX + spacingX * 2 + 5, offsetY + 220, 50, 20), "Create")) { - CloseWindows (); - FixSize (); - NormalFromHeightGuiObject.SetActive (true); - NormalFromHeightGuiScript.NewTexture (); - NormalFromHeightGuiScript.DoStuff (); - } - - if (_NormalMap == null) { GUI.enabled = false; } else { GUI.enabled = true; } - if (GUI.Button (new Rect(offsetX + spacingX * 2 + 60, offsetY + 220, 45, 20), "Clear")) { - ClearTexture(MapType.normal); - CloseWindows (); - SetMaterialValues (); - FixSize (); - } - GUI.enabled = true; - - - //==============================// - // Metallic Map // - //==============================// - - GUI.Box( new Rect (offsetX + spacingX * 3, offsetY, 110, 250), "Metallic Map" ); - - if ( _MetallicMap != null ) { - GUI.DrawTexture (new Rect(offsetX + spacingX * 3 + 5, offsetY + 25, 100, 100), _MetallicMap ); - } - - // Paste - if (GUI.Button (new Rect(offsetX + spacingX * 3 + 5, offsetY + 130, 20, 20), "P")) { - mapTypeToLoad = MapType.metallic; - PasteFile (); - } - - if (_MetallicMap == null) { GUI.enabled = false; } else { GUI.enabled = true; } - - // Copy - if (GUI.Button (new Rect(offsetX + spacingX * 3 + 30, offsetY + 130, 20, 20), "C")) { - textureToSave = _MetallicMap; - CopyFile (); - } - - GUI.enabled = true; - - //Open - if (GUI.Button (new Rect(offsetX + spacingX * 3 + 60, offsetY + 130, 20, 20), "O")) { - mapTypeToLoad = MapType.metallic; - SetFileMaskImage(); - fileBrowser.ShowBrowser( "Open Metallic Map", this.OpenFile ); - //UniFileBrowser.use.OpenFileWindow (OpenFile); - } - - if (_MetallicMap == null) { GUI.enabled = false; } else { GUI.enabled = true; } - - // Save - if (GUI.Button (new Rect(offsetX + spacingX * 3 + 85, offsetY + 130, 20, 20), "S")) { - textureToSave = _MetallicMap; - mapType = "_metallic"; - SetFileMaskImage(); - fileBrowser.ShowBrowser( "Save Metallic Map", this.SaveFile ); - //UniFileBrowser.use.SaveFileWindow (SaveFile); - } - - if (_MetallicMap == null || QuicksavePathMetallic == "") { GUI.enabled = false; } else { GUI.enabled = true; } - - // Quick Save - if (GUI.Button (new Rect(offsetX + spacingX * 3 + 15, offsetY + 160, 80, 20), "Quick Save")) { - textureToSave = _MetallicMap; - mapType = "_metallic"; - SaveFile(QuicksavePathMetallic); - } - - if (_MetallicMap == null) { GUI.enabled = false; } else { GUI.enabled = true; } - if (GUI.Button (new Rect(offsetX + spacingX * 3 + 15, offsetY + 190, 80, 20), "Preview")) { - SetPreviewMaterial( _MetallicMap ); - } - - if ( _DiffuseMapOriginal == null && _DiffuseMap == null ){ GUI.enabled = false; } else { GUI.enabled = true; } - if (GUI.Button (new Rect (offsetX + spacingX * 3 + 5, offsetY + 220, 50, 20), "Create")) { - CloseWindows(); - FixSize(); - - MetallicGuiObject.SetActive(true); - MetallicGuiScript.NewTexture(); - MetallicGuiScript.DoStuff(); - } - - if (_MetallicMap == null) { GUI.enabled = false; } else { GUI.enabled = true; } - if (GUI.Button (new Rect(offsetX + spacingX * 3 + 60, offsetY + 220, 45, 20), "Clear")) { - ClearTexture(MapType.metallic); - CloseWindows (); - SetMaterialValues (); - FixSize (); - } - GUI.enabled = true; - - - //==============================// - // Smoothness Map // - //==============================// - - GUI.Box( new Rect (offsetX + spacingX * 4, offsetY, 110, 250), "Smoothness Map" ); - - if ( _SmoothnessMap != null ) { - GUI.DrawTexture (new Rect(offsetX + spacingX * 4 + 5, offsetY + 25, 100, 100), _SmoothnessMap ); - } - - // Paste - if (GUI.Button (new Rect(offsetX + spacingX * 4 + 5, offsetY + 130, 20, 20), "P")) { - mapTypeToLoad = MapType.smoothness; - PasteFile (); - } - - if (_SmoothnessMap == null) { GUI.enabled = false; } else { GUI.enabled = true; } - - // Copy - if (GUI.Button (new Rect(offsetX + spacingX * 4 + 30, offsetY + 130, 20, 20), "C")) { - textureToSave = _SmoothnessMap; - CopyFile (); - } - - GUI.enabled = true; - - //Open - if (GUI.Button (new Rect(offsetX + spacingX * 4 + 60, offsetY + 130, 20, 20), "O")) { - mapTypeToLoad = MapType.smoothness; - SetFileMaskImage(); - fileBrowser.ShowBrowser( "Open Smoothness Map", this.OpenFile ); - } - - if (_SmoothnessMap == null) { GUI.enabled = false; } else { GUI.enabled = true; } - - // Save - if (GUI.Button (new Rect(offsetX + spacingX * 4 + 85, offsetY + 130, 20, 20), "S")) { - textureToSave = _SmoothnessMap; - mapType = "_smoothness"; - SetFileMaskImage(); - fileBrowser.ShowBrowser( "Save Smoothness Map", this.SaveFile ); - } - - if (_SmoothnessMap == null || QuicksavePathSmoothness == "") { GUI.enabled = false; } else { GUI.enabled = true; } - - // Quick Save - if (GUI.Button (new Rect(offsetX + spacingX * 4 + 15, offsetY + 160, 80, 20), "Quick Save")) { - textureToSave = _SmoothnessMap; - mapType = "_smoothness"; - SaveFile(QuicksavePathSmoothness); - } - - if (_SmoothnessMap == null) { GUI.enabled = false; } else { GUI.enabled = true; } - if (GUI.Button (new Rect(offsetX + spacingX * 4 + 15, offsetY + 190, 80, 20), "Preview")) { - SetPreviewMaterial( _SmoothnessMap ); - } - - if ( _DiffuseMapOriginal == null && _DiffuseMap == null ){ GUI.enabled = false; } else { GUI.enabled = true; } - if (GUI.Button (new Rect (offsetX + spacingX * 4 + 5, offsetY + 220, 50, 20), "Create")) { - CloseWindows(); - FixSize(); - SmoothnessGuiObject.SetActive(true); - SmoothnessGuiScript.NewTexture(); - SmoothnessGuiScript.DoStuff(); - } - - if (_SmoothnessMap == null) { GUI.enabled = false; } else { GUI.enabled = true; } - if (GUI.Button (new Rect(offsetX + spacingX * 4 + 60, offsetY + 220, 45, 20), "Clear")) { - ClearTexture(MapType.smoothness); - CloseWindows (); - SetMaterialValues (); - FixSize (); - } - GUI.enabled = true; - - - //==============================// - // Edge Map // - //==============================// - - GUI.Box( new Rect (offsetX + spacingX * 5, offsetY, 110, 250), "Edge Map" ); - - if ( _EdgeMap != null ) { - GUI.DrawTexture (new Rect(offsetX + spacingX * 5 + 5, offsetY + 25, 100, 100), _EdgeMap ); - } - - // Paste - if (GUI.Button (new Rect(offsetX + spacingX * 5 + 5, offsetY + 130, 20, 20), "P")) { - mapTypeToLoad = MapType.edge; - PasteFile (); - } - - if (_EdgeMap == null) { GUI.enabled = false; } else { GUI.enabled = true; } - - // Copy - if (GUI.Button (new Rect(offsetX + spacingX * 5 + 30, offsetY + 130, 20, 20), "C")) { - textureToSave = _EdgeMap; - CopyFile (); - } - - GUI.enabled = true; - - //Open - if (GUI.Button (new Rect(offsetX + spacingX * 5 +60, offsetY + 130, 20, 20), "O")) { - mapTypeToLoad = MapType.edge; - SetFileMaskImage(); - fileBrowser.ShowBrowser( "Open Edge Map", this.OpenFile ); - } - - if (_EdgeMap == null) { GUI.enabled = false; } else { GUI.enabled = true; } - - // Save - if (GUI.Button (new Rect(offsetX + spacingX * 5 + 85, offsetY + 130, 20, 20), "S")) { - textureToSave = _EdgeMap; - mapType = "_edge"; - SetFileMaskImage(); - fileBrowser.ShowBrowser( "Save Edge Map", this.SaveFile ); - } - - if (_EdgeMap == null || QuicksavePathEdge == "") { GUI.enabled = false; } else { GUI.enabled = true; } - - // Quick Save - if (GUI.Button (new Rect(offsetX + spacingX * 5 + 15, offsetY + 160, 80, 20), "Quick Save")) { - textureToSave = _EdgeMap; - mapType = "_edge"; - SaveFile(QuicksavePathEdge); - } - - if (_EdgeMap == null) { GUI.enabled = false; } else { GUI.enabled = true; } - if (GUI.Button (new Rect(offsetX + spacingX * 5 + 15, offsetY + 190, 80, 20), "Preview")) { - SetPreviewMaterial( _EdgeMap ); - } - - if ( _NormalMap == null ){ GUI.enabled = false; } else { GUI.enabled = true; } - if (GUI.Button (new Rect(offsetX + spacingX * 5 + 5, offsetY + 220, 50, 20), "Create")) { - CloseWindows(); - FixSize(); - EdgeFromNormalGuiObject.SetActive(true); - EdgeFromNormalGuiScript.NewTexture(); - EdgeFromNormalGuiScript.DoStuff(); - } - - if (_EdgeMap == null) { GUI.enabled = false; } else { GUI.enabled = true; } - if (GUI.Button (new Rect(offsetX + spacingX * 5 + 60, offsetY + 220, 45, 20), "Clear")) { - ClearTexture(MapType.edge); - CloseWindows (); - SetMaterialValues (); - FixSize (); - } - GUI.enabled = true; - - //==============================// - // AO Map // - //==============================// - - GUI.Box( new Rect (offsetX + spacingX * 6, offsetY, 110, 250), "AO Map" ); - - if ( _AOMap != null ) { - GUI.DrawTexture (new Rect(offsetX + spacingX * 6 + 5, offsetY + 25, 100, 100), _AOMap ); - } - - - // Paste - if (GUI.Button (new Rect(offsetX + spacingX * 6 + 5, offsetY + 130, 20, 20), "P")) { - mapTypeToLoad = MapType.ao; - PasteFile (); - } - - if (_AOMap == null) { GUI.enabled = false; } else { GUI.enabled = true; } - - // Copy - if (GUI.Button (new Rect(offsetX + spacingX * 6 + 30, offsetY + 130, 20, 20), "C")) { - textureToSave = _AOMap; - CopyFile (); - } - - GUI.enabled = true; - - //Open - if (GUI.Button (new Rect(offsetX + spacingX * 6 + 60, offsetY + 130, 20, 20), "O")) { - mapTypeToLoad = MapType.ao; - SetFileMaskImage(); - fileBrowser.ShowBrowser( "Open AO Map", this.OpenFile ); - } - - if (_AOMap == null) { GUI.enabled = false; } else { GUI.enabled = true; } - - // Save - if (GUI.Button (new Rect(offsetX + spacingX * 6 + 85, offsetY + 130, 20, 20), "S")) { - textureToSave = _AOMap; - mapType = "_ao"; - SetFileMaskImage(); - fileBrowser.ShowBrowser( "Save AO Map", this.SaveFile ); - } - - if (_AOMap == null || QuicksavePathAO == "") { GUI.enabled = false; } else { GUI.enabled = true; } - - // Quick Save - if (GUI.Button (new Rect(offsetX + spacingX * 6 + 15, offsetY + 160, 80, 20), "Quick Save")) { - textureToSave = _AOMap; - mapType = "_ao"; - SaveFile(QuicksavePathAO); - } - - if (_AOMap == null) { GUI.enabled = false; } else { GUI.enabled = true; } - if (GUI.Button (new Rect(offsetX + spacingX * 6 + 15, offsetY + 190, 80, 20), "Preview")) { - SetPreviewMaterial( _AOMap ); - } - - if ( _NormalMap == null && _HeightMap == null ){ GUI.enabled = false; } else { GUI.enabled = true; } - if (GUI.Button (new Rect(offsetX + spacingX * 6 + 5, offsetY + 220, 50, 20), "Create")) { - CloseWindows(); - FixSize(); - AOFromNormalGuiObject.SetActive(true); - AOFromNormalGuiScript.NewTexture(); - AOFromNormalGuiScript.DoStuff(); - } - - if (_AOMap == null) { GUI.enabled = false; } else { GUI.enabled = true; } - if (GUI.Button (new Rect(offsetX + spacingX * 6 + 60, offsetY + 220, 45, 20), "Clear")) { - ClearTexture(MapType.ao); - CloseWindows (); - SetMaterialValues (); - FixSize (); - } - GUI.enabled = true; - - - //==============================// - // Map Saving Options // - //==============================// - - offsetX = offsetX + spacingX * 7; - - GUI.Box( new Rect (offsetX, offsetY, 230, 250), "Saving Options" ); - - GUI.Label (new Rect (offsetX + 20, offsetY + 20, 100, 25), "File Format"); - - bmpSelected = GUI.Toggle (new Rect (offsetX + 30, offsetY + 40, 80, 20), bmpSelected, "BMP"); - if (bmpSelected) { - SetFormat (FileFormat.bmp); - } - - jpgSelected = GUI.Toggle (new Rect (offsetX + 30, offsetY + 60, 80, 20), jpgSelected, "JPG"); - if (jpgSelected) { - SetFormat (FileFormat.jpg); - } - - pngSelected = GUI.Toggle (new Rect (offsetX + 30, offsetY + 80, 80, 20), pngSelected, "PNG"); - if (pngSelected) { - SetFormat (FileFormat.png); - } - - tgaSelected = GUI.Toggle (new Rect (offsetX + 30, offsetY + 100, 80, 20), tgaSelected, "TGA"); - if (tgaSelected) { - SetFormat (FileFormat.tga); - } - - tiffSelected = GUI.Toggle (new Rect (offsetX + 30, offsetY + 120, 80, 20), tiffSelected, "TIFF"); - if (tiffSelected) { - SetFormat (FileFormat.tiff); - } - - // Flip Normal Map Y - if ( _NormalMap == null ){ GUI.enabled = false; } else { GUI.enabled = true; } - if (GUI.Button (new Rect(offsetX + 10, offsetY + 145, 100, 25), "Flip Normal Y")) { - FlipNormalMapY(); - } - GUI.enabled = true; - - //Save Project - if (GUI.Button (new Rect(offsetX + 10, offsetY + 180, 100, 25), "Save Project")) { - SetFileMaskProject(); - fileBrowser.ShowBrowser( "Save Project", this.SaveProject ); - } - - //Load Project - if (GUI.Button (new Rect(offsetX + 10, offsetY + 215, 100, 25), "Load Project")) { - SetFileMaskProject(); - fileBrowser.ShowBrowser( "Load Project", this.LoadProject ); - } - - //======================================// - // Property Map Settings // - //======================================// - - GUI.Label (new Rect (offsetX + 130, offsetY + 20, 100, 25), "Property Map"); - - if (propRedChoose) { GUI.enabled = false; } else { GUI.enabled = true; } - GUI.Label( new Rect (offsetX + 100, offsetY + 45, 20, 20), "R:" ); - if (GUI.Button ( new Rect (offsetX + 120, offsetY + 45, 100, 25), PCM2String( propRed, "Red None" ) ) ) { - propRedChoose = true; - propGreenChoose = false; - propBlueChoose = false; - } - - if (propGreenChoose) { GUI.enabled = false; } else { GUI.enabled = true; } - GUI.Label( new Rect (offsetX + 100, offsetY + 80, 20, 20), "G:" ); - if (GUI.Button ( new Rect (offsetX + 120, offsetY + 80, 100, 25), PCM2String( propGreen, "Green None" ) ) ) { - propRedChoose = false; - propGreenChoose = true; - propBlueChoose = false; - } - - if (propBlueChoose) { GUI.enabled = false; } else { GUI.enabled = true; } - GUI.Label( new Rect (offsetX + 100, offsetY + 115, 20, 20), "B:" ); - if (GUI.Button ( new Rect (offsetX + 120, offsetY + 115, 100, 25), PCM2String( propBlue, "Blue None" ) ) ) { - propRedChoose = false; - propGreenChoose = false; - propBlueChoose = true; - } - - GUI.enabled = true; - - int propBoxOffsetX = offsetX + 250; - int propBoxOffsetY = 20; - if (propRedChoose || propGreenChoose || propBlueChoose) { - GUI.Box( new Rect (propBoxOffsetX, propBoxOffsetY, 150, 245), "Map for Channel" ); - bool chosen = false; - PropChannelMap chosenPCM = PropChannelMap.None; - - if (GUI.Button (new Rect (propBoxOffsetX + 10, propBoxOffsetY + 30, 130, 25), "None")) { - chosen = true; - chosenPCM = PropChannelMap.None; - } - if (GUI.Button (new Rect (propBoxOffsetX + 10, propBoxOffsetY + 60, 130, 25), "Height")) { - chosen = true; - chosenPCM = PropChannelMap.Height; - } - if (GUI.Button (new Rect (propBoxOffsetX + 10, propBoxOffsetY + 90, 130, 25), "Metallic")) { - chosen = true; - chosenPCM = PropChannelMap.Metallic; - } - if (GUI.Button (new Rect (propBoxOffsetX + 10, propBoxOffsetY + 120, 130, 25), "Smoothness")) { - chosen = true; - chosenPCM = PropChannelMap.Smoothness; - } - if (GUI.Button (new Rect (propBoxOffsetX + 10, propBoxOffsetY + 150, 130, 25), "Edge")) { - chosen = true; - chosenPCM = PropChannelMap.Edge; - } - if (GUI.Button (new Rect (propBoxOffsetX + 10, propBoxOffsetY + 180, 130, 25), "Ambient Occlusion")) { - chosen = true; - chosenPCM = PropChannelMap.Ao; - } - if (GUI.Button (new Rect (propBoxOffsetX + 10, propBoxOffsetY + 210, 130, 25), "AO + Edge")) { - chosen = true; - chosenPCM = PropChannelMap.AoEdge; - } - - if( chosen ){ - if( propRedChoose ){ - propRed = chosenPCM; - } - if( propGreenChoose ){ - propGreen = chosenPCM; - } - if( propBlueChoose ){ - propBlue = chosenPCM; - } - propRedChoose = false; - propGreenChoose = false; - propBlueChoose = false; - } - } - - if (GUI.Button (new Rect(offsetX + 120, offsetY + 150, 100, 40), "Save\r\nProperty Map")) { - ProcessPropertyMap(); - textureToSave = _PropertyMap; - mapType = "_msao"; - SetFileMaskImage(); - fileBrowser.ShowBrowser( "Save Property Map", this.SaveFile ); - } - - if( QuicksavePathProperty == "" ){ GUI.enabled = false; } - if (GUI.Button (new Rect(offsetX + 120, offsetY + 200, 100, 40), "Quick Save\r\nProperty Map")) { - ProcessPropertyMap(); - textureToSave = _PropertyMap; - mapType = "_msao"; - SaveFile(QuicksavePathProperty); - } - GUI.enabled = true; - - - //==========================// - // View Buttons // - //==========================// - - offsetX = 430; - offsetY = 280; - - if (GUI.Button (new Rect(offsetX, offsetY, 100, 40), "Post Process")) { - if( PostProcessGuiObject.activeSelf == true ){ - PostProcessGuiObject.SetActive(false); - }else{ - PostProcessGuiObject.SetActive(true); - } - } - - offsetX += 110; - - if (GUI.Button (new Rect(offsetX, offsetY, 80, 40), "Show Full\r\nMaterial")) { - CloseWindows(); - FixSize(); - MaterialGuiObject.SetActive(true); - MaterialGuiScript.Initialize(); - } - - offsetX += 90; - - if (GUI.Button (new Rect(offsetX, offsetY, 80, 40), "Next\r\nCube Map")) { - selectedCubemap += 1; - if( selectedCubemap >= CubeMaps.Length ){ - selectedCubemap = 0; - } - - //skyboxMaterial.SetTexture ("_Tex", CubeMaps[selectedCubemap] ); - Shader.SetGlobalTexture ("_GlobalCubemap", CubeMaps[selectedCubemap] ); - reflectionProbe.RenderProbe(); - } - - offsetX += 90; - - if (_HeightMap == null) { GUI.enabled = false; } else { GUI.enabled = true; } - if (GUI.Button (new Rect(offsetX, offsetY, 60, 40), "Tile\r\nMaps")) { - CloseWindows(); - FixSize(); - TilingTextureMakerGuiObject.SetActive(true); - TilingTextureMakerGuiScript.Initialize(); - } - GUI.enabled = true; - - offsetX += 70; - - if (_HeightMap == null && _DiffuseMapOriginal == null && _MetallicMap == null && _SmoothnessMap == null && _EdgeMap == null && _AOMap == null) { GUI.enabled = false; } else { GUI.enabled = true; } - if (GUI.Button (new Rect(offsetX, offsetY, 90, 40), "Adjust\r\nAlignment")) { - CloseWindows(); - FixSize(); - //AlignmentGuiScript.gameObject.SetActive(true); - AlignmentGuiScript.Initialize(); - } - GUI.enabled = true; - - offsetX += 100; - - if (GUI.Button (new Rect(offsetX, offsetY, 120, 40), "Clear All\r\nTexture Maps")) { - clearTextures = true; - } - - if (clearTextures) { - - offsetY += 60; - - GUI.Box( new Rect (offsetX, offsetY, 120, 60), "Are You Sure?" ); - - if (GUI.Button (new Rect (offsetX + 10, offsetY + 30, 45, 20), "Yes")) { - clearTextures = false; - ClearAllTextures (); - CloseWindows (); - SetMaterialValues (); - FixSizeSize( 1024.0f, 1024.0f ); - } - - if (GUI.Button (new Rect (offsetX + 65, offsetY + 30, 45, 20), "No")) { - clearTextures = false; - } - } - - GUI.enabled = true; - - } - - string PCM2String ( PropChannelMap pcm, string defaultName ){ - - string returnString = defaultName; - - switch (pcm) { - case PropChannelMap.Height: - returnString = "Height"; - break; - case PropChannelMap.Metallic: - returnString = "Metallic"; - break; - case PropChannelMap.Smoothness: - returnString = "Smoothness"; - break; - case PropChannelMap.Edge: - returnString = "Edge"; - break; - case PropChannelMap.Ao: - returnString = "Ambient Occ"; - break; - case PropChannelMap.AoEdge: - returnString = "AO + Edge"; - break; - } - - return returnString; - - } - - public void FlipNormalMapY(){ - - if( _NormalMap != null ){ - Color pixelColor = Color.black; - //UnityEngine.Debug.Log (_NormalMap.GetPixel (0, 0).b); - for (int i = 0; i < _NormalMap.width; i ++) { - for (int j = 0; j < _NormalMap.height; j ++) { - pixelColor = _NormalMap.GetPixel (i, j); - pixelColor.g = 1.0f - pixelColor.g; - _NormalMap.SetPixel (i, j, pixelColor); - } - } - _NormalMap.Apply (); - } - - /* - bool SPM = false; - if (SampleMaterial.GetTexture ("_MainTex") == _NormalMap) { - SPM = true; - } - - Shader FlipNormalYShader = Shader.Find ("Hidden/Blit_FlipNormalY"); - Material FlipNormalYMaterial = new Material (FlipNormalYShader); - - RenderTexture _TempMap = RenderTexture.GetTemporary (_NormalMap.width, _NormalMap.height, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default); - Graphics.Blit (_NormalMap, _TempMap, FlipNormalYMaterial, 0); - RenderTexture.active = _TempMap; - - if (_NormalMap != null) { - Destroy (_NormalMap); - _NormalMap = null; - } - - _NormalMap = new Texture2D (_TempMap.width, _TempMap.height); - _NormalMap.ReadPixels (new Rect (0, 0, _TempMap.width, _TempMap.height), 0, 0); - _NormalMap.Apply (); - - Destroy (FlipNormalYShader); - Destroy (FlipNormalYMaterial); - - RenderTexture.ReleaseTemporary (_TempMap); - _TempMap = null; - - if (MaterialGuiObject.activeSelf) { - SetMaterialValues (); - FullMaterial.SetTexture ("_Normal", _NormalMap); - MaterialGuiScript.Initialize(); - }else if (SPM) { - SetPreviewMaterial (_NormalMap); - } - */ - - } - - void ClearTexture( Texture2D textureToClear ){ - - if (textureToClear) { - Destroy (textureToClear); - textureToClear = null; - } - - Resources.UnloadUnusedAssets(); - } - - void ClearTexture( MapType mapType ){ - - switch (mapType) { - case MapType.height: - if (_HeightMap) { - Destroy (_HeightMap); - _HeightMap = null; - } - if (_HDHeightMap) { - Destroy (_HDHeightMap); - _HDHeightMap = null; - } - break; - case MapType.diffuse: - if (_DiffuseMap) { - Destroy (_DiffuseMap); - _DiffuseMap = null; - } - if (_DiffuseMapOriginal) { - Destroy (_DiffuseMapOriginal); - _DiffuseMapOriginal = null; - } - break; - case MapType.normal: - if (_NormalMap) { - Destroy (_NormalMap); - _NormalMap = null; - } - break; - case MapType.metallic: - if (_MetallicMap) { - Destroy (_MetallicMap); - _MetallicMap = null; - } - break; - case MapType.smoothness: - if (_SmoothnessMap) { - Destroy (_SmoothnessMap); - _SmoothnessMap = null; - } - break; - case MapType.edge: - if (_EdgeMap) { - Destroy (_EdgeMap); - _EdgeMap = null; - } - break; - case MapType.ao: - if (_AOMap) { - Destroy (_AOMap); - _AOMap = null; - } - break; - } - - Resources.UnloadUnusedAssets(); - } - - public void ClearAllTextures() { - - ClearTexture( MapType.height ); - ClearTexture( MapType.diffuse ); - ClearTexture( MapType.normal ); - ClearTexture( MapType.metallic ); - ClearTexture( MapType.smoothness ); - ClearTexture( MapType.edge ); - ClearTexture( MapType.ao ); - - } - - public void SetFormat ( FileFormat newFormat ) { - - bmpSelected = false; - jpgSelected = false; - pngSelected = false; - tgaSelected = false; - tiffSelected = false; - - switch (newFormat) { - case FileFormat.bmp: - bmpSelected = true; - break; - case FileFormat.jpg: - jpgSelected = true; - break; - case FileFormat.png: - pngSelected = true; - break; - case FileFormat.tga: - tgaSelected = true; - break; - case FileFormat.tiff: - tiffSelected = true; - break; - } - - selectedFormat = newFormat; - } - - public void SetFormat ( string newFormat ) { - - bmpSelected = false; - jpgSelected = false; - pngSelected = false; - tgaSelected = false; - tiffSelected = false; - - switch (newFormat) { - case "bmp": - bmpSelected = true; - selectedFormat = FileFormat.bmp; - break; - case "jpg": - jpgSelected = true; - selectedFormat = FileFormat.jpg; - break; - case "png": - pngSelected = true; - selectedFormat = FileFormat.png; - break; - case "tga": - tgaSelected = true; - selectedFormat = FileFormat.tga; - break; - case "tiff": - tiffSelected = true; - selectedFormat = FileFormat.tiff; - break; - } - - } - - public void SetLoadedTexture( MapType loadedTexture ){ - - //SetMaterialValues (); - - switch( loadedTexture ){ - case MapType.height: - SetPreviewMaterial (_HeightMap); - break; - case MapType.diffuse: - SetPreviewMaterial (_DiffuseMap); - break; - case MapType.diffuseOriginal: - SetPreviewMaterial (_DiffuseMapOriginal); - break; - case MapType.normal: - SetPreviewMaterial (_NormalMap); - break; - case MapType.metallic: - SetPreviewMaterial (_MetallicMap); - break; - case MapType.smoothness: - SetPreviewMaterial (_SmoothnessMap); - break; - case MapType.edge: - SetPreviewMaterial (_EdgeMap); - break; - case MapType.ao: - SetPreviewMaterial (_AOMap); - break; - default: - break; - } - - FixSize (); - } - - string SwitchFormats( FileFormat selectedFormat ) { - - string extension = "bmp"; - switch (selectedFormat) { - case FileFormat.bmp: - extension = "bmp"; - break; - case FileFormat.jpg: - extension = "jpg"; - break; - case FileFormat.png: - extension = "png"; - break; - case FileFormat.tga: - extension = "tga"; - break; - case FileFormat.tiff: - extension = "tiff"; - break; - } - - return extension; - } - - //==================================================// - // Property Map // - //==================================================// - - void SetPropertyTexture ( string texPrefix, Texture2D texture, Texture2D overlayTexture ){ - - if (texture != null) { - PropertyCompMaterial.SetTexture (texPrefix + "Tex", texture); - } else { - PropertyCompMaterial.SetTexture (texPrefix + "Tex", _TextureBlack); - } - - PropertyCompMaterial.SetTexture (texPrefix + "OverlayTex", overlayTexture); - - } - - void SetPropertyMapChannel ( string texPrefix, PropChannelMap pcm ){ - - switch (pcm) { - case PropChannelMap.Height: - SetPropertyTexture (texPrefix, _HeightMap, _TextureGrey); - break; - case PropChannelMap.Metallic: - SetPropertyTexture (texPrefix, _MetallicMap, _TextureGrey); - break; - case PropChannelMap.Smoothness: - SetPropertyTexture (texPrefix, _SmoothnessMap, _TextureGrey); - break; - case PropChannelMap.Edge: - SetPropertyTexture (texPrefix, _EdgeMap, _TextureGrey); - break; - case PropChannelMap.Ao: - SetPropertyTexture (texPrefix, _AOMap, _TextureGrey); - break; - case PropChannelMap.AoEdge: - SetPropertyTexture (texPrefix, _AOMap, _EdgeMap); - break; - case PropChannelMap.None: - SetPropertyTexture (texPrefix, _TextureBlack, _TextureGrey); - break; - } - - } - - public void ProcessPropertyMap () { - - SetPropertyMapChannel ("_Red", propRed); - SetPropertyMapChannel ("_Green", propGreen); - SetPropertyMapChannel ("_Blue", propBlue); - - Vector2 size = GetSize (); - RenderTexture _TempMap = RenderTexture.GetTemporary ((int)size.x, (int)size.y, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default); - Graphics.Blit (_MetallicMap, _TempMap, PropertyCompMaterial, 0); - RenderTexture.active = _TempMap; - - if (_PropertyMap != null) { - Destroy (_PropertyMap); - _PropertyMap = null; - } - - _PropertyMap = new Texture2D (_TempMap.width, _TempMap.height, TextureFormat.RGB24, false); - _PropertyMap.ReadPixels (new Rect (0, 0, _TempMap.width, _TempMap.height), 0, 0); - _PropertyMap.Apply (); - - RenderTexture.ReleaseTemporary (_TempMap); - _TempMap = null; - - } - - //==================================================// - // Project Saving // - //==================================================// - - void SaveProject (string pathToFile) { - SaveLoadProjectScript.SaveProject (pathToFile, selectedFormat); - } - - void LoadProject (string pathToFile) { - SaveLoadProjectScript.LoadProject (pathToFile); - } - - void SaveFile (string pathToFile) { - SaveLoadProjectScript.SaveFile(pathToFile,selectedFormat,textureToSave, "" ); - } - - void CopyFile() { - SaveLoadProjectScript.CopyFile (textureToSave); - } - - void PasteFile() { - ClearTexture (mapTypeToLoad); - SaveLoadProjectScript.PasteFile (mapTypeToLoad); - } - - void OpenFile (string pathToFile) { - if (pathToFile == null) { - return; - } - - // clear the existing texture we are loading - ClearTexture(mapTypeToLoad); - - StartCoroutine ( SaveLoadProjectScript.LoadTexture( mapTypeToLoad, pathToFile ) ); - } - - //==================================================// - // Fix the size of the test model // - //==================================================// - - - public Vector2 GetSize() { - - Texture2D mapToUse = null; - - Vector2 size = new Vector2 (1024, 1024); - - if (_HeightMap != null) { - mapToUse = _HeightMap; - } else if (_DiffuseMap != null) { - mapToUse = _DiffuseMap; - } else if (_DiffuseMapOriginal != null) { - mapToUse = _DiffuseMapOriginal; - } else if (_NormalMap != null) { - mapToUse = _NormalMap; - } else if (_MetallicMap != null) { - mapToUse = _MetallicMap; - } else if (_SmoothnessMap != null) { - mapToUse = _SmoothnessMap; - } else if (_EdgeMap != null) { - mapToUse = _EdgeMap; - } else if (_AOMap != null) { - mapToUse = _AOMap; - } - - if (mapToUse != null) { - size.x = mapToUse.width; - size.y = mapToUse.height; - } - - return size; - } - - public void FixSize() { - - Vector2 size = GetSize (); - FixSizeSize( size.x, size.y ); - - } - - void FixSizeMap( Texture2D mapToUse ) { - FixSizeSize ( (float)mapToUse.width, (float)mapToUse.height ); - } - - void FixSizeMap( RenderTexture mapToUse ) { - FixSizeSize ( (float)mapToUse.width, (float)mapToUse.height ); - } - - void FixSizeSize( float width, float height ) { - - Vector3 testObjectScale = new Vector3(1,1,1); - float area = 1.0f; - - testObjectScale.x = width / height; - - float newArea = testObjectScale.x * testObjectScale.y; - float areaScale = Mathf.Sqrt( area / newArea ); - - testObjectScale.x *= areaScale; - testObjectScale.y *= areaScale; - - testObject.transform.localScale = testObjectScale; - - } + public ReflectionProbe ReflectionProbe; + [HideInInspector] public Material SampleMaterial; + public Material SampleMaterialRef; + public Material SkyboxMaterial; + + public GameObject SaveLoadProjectObject; + public FileFormat SelectedFormat; + + public GameObject SettingsGuiObject; + + public GameObject SmoothnessGuiObject; + public SmoothnessGui SmoothnessGuiScript; + public Texture2D SmoothnessMap; + public GameObject TestObject; + + public Texture2D TextureBlack; + public Texture2D TextureGrey; + public Texture2D TextureNormal; + public Texture2D TextureWhite; + + public GameObject TilingTextureMakerGuiObject; + public BatchUI Batchui; + + //public string XSize = "1024"; + public string XSize { get; set; } + public string YSize { get; set; } + public bool ScaleTexture; + private bool ScaleTextureLocked; + public Toggle[] FileFormatToggles; + + #endregion + + private void Awake() + { + Instance = this; + } + + private void Start() + { + Windowed(); + Batchui = gameObject.AddComponent(); + _lastDirectory = Application.dataPath; + + HeightMap = null; + HdHeightMap = null; + DiffuseMap = null; + DiffuseMapOriginal = null; + NormalMap = null; + MetallicMap = null; + SmoothnessMap = null; + EdgeMap = null; + AoMap = null; + + _propertyCompShader = Shader.Find("Hidden/Blit_Property_Comp"); + _propertyCompMaterial = new Material(_propertyCompShader); + + Shader.SetGlobalFloat(CorrectionId, GamaCorrection); + + FullMaterial = new Material(FullMaterialRef.shader); + FullMaterial.CopyPropertiesFromMaterial(FullMaterialRef); + + SampleMaterial = new Material(SampleMaterialRef.shader); + SampleMaterial.CopyPropertiesFromMaterial(SampleMaterialRef); + + HeightFromDiffuseGuiScript = HeightFromDiffuseGuiObject.GetComponent(); + NormalFromHeightGuiScript = NormalFromHeightGuiObject.GetComponent(); + EdgeFromNormalGuiScript = EdgeFromNormalGuiObject.GetComponent(); + AoFromNormalGuiScript = AoFromNormalGuiObject.GetComponent(); + EditDiffuseGuiScript = EditDiffuseGuiObject.GetComponent(); + MetallicGuiScript = MetallicGuiObject.GetComponent(); + SmoothnessGuiScript = SmoothnessGuiObject.GetComponent(); + MaterialGuiScript = MaterialGuiObject.GetComponent(); + _tilingTextureMakerGuiScript = TilingTextureMakerGuiObject.GetComponent(); + _saveLoadProjectScript = SaveLoadProjectObject.GetComponent(); + _settingsGuiScript = SettingsGuiObject.GetComponent(); + + _settingsGuiScript.LoadSettings(); + + if (Application.platform == RuntimePlatform.WindowsEditor || + Application.platform == RuntimePlatform.WindowsPlayer) + _pathChar = '\\'; + + TestObject.GetComponent().material = FullMaterial; + SetMaterialValues(); + + ReflectionProbe.RenderProbe(); + + HideGuiLocker.LockEmpty += LoadHideState; + } + + private void LateUpdate() + { + if (DiffuseMap != null) + { + DiffuseTexture.texture = DiffuseMap; + DiffuseTexture.color = new Color(1, 1, 1, 1); + } + if (HeightMap != null) + { + HeightTexture.texture = HeightMap; + HeightTexture.color = new Color(1, 1, 1, 1); + } + if (SmoothnessMap != null) + { + SmoothnessTexture.texture = SmoothnessMap; + SmoothnessTexture.color = new Color(1, 1, 1, 1); + } + if (NormalMap != null) + { + NormalTexture.texture = NormalMap; + NormalTexture.color = new Color(1, 1, 1, 1); + } + if (MetallicMap != null) + { + MetallicTexture.texture = MetallicMap; + MetallicTexture.color = new Color(1, 1, 1, 1); + } + if (EdgeMap != null) + { + EdgeTexture.texture = EdgeMap; + EdgeTexture.color = new Color(1, 1, 1, 1); + } + if (AoMap != null) + { + AOTexture.texture = AoMap; + AOTexture.color = new Color(1, 1, 1, 1); + } + } + + public void SaveHideState() + { + if (HideGuiLocker.IsLocked) return; + _lastGuiIsHiddenState = IsGuiHidden; + } + + public void SaveHideStateAndHideAndLock(object sender) + { + SaveHideState(); + IsGuiHidden = true; + HideGuiLocker.Lock(sender); + } + + private void LoadHideState(object sender, EventArgs eventArgs) + { + IsGuiHidden = _lastGuiIsHiddenState; + } + + public void SetPreviewMaterial(Texture2D textureToPreview) + { + CloseWindows(); + if (textureToPreview == null) return; + FixSizeMap(textureToPreview); + SampleMaterial.SetTexture(MainTexId, textureToPreview); + TestObject.GetComponent().material = SampleMaterial; + } + + public void SetPreviewMaterial(RenderTexture textureToPreview) + { + CloseWindows(); + if (textureToPreview == null) return; + FixSizeMap(textureToPreview); + SampleMaterial.SetTexture(MainTexId, textureToPreview); + TestObject.GetComponent().material = SampleMaterial; + } + + public void SetMaterialValues() + { + Shader.SetGlobalTexture(GlobalCubemapId, CubeMaps[_selectedCubemap]); + + FullMaterial.SetTexture(DisplacementMapId, HeightMap != null ? HeightMap : TextureGrey); + + if (DiffuseMap != null) + FullMaterial.SetTexture(DiffuseMapId, DiffuseMap); + else if (DiffuseMapOriginal != null) + FullMaterial.SetTexture(DiffuseMapId, DiffuseMapOriginal); + else + FullMaterial.SetTexture(DiffuseMapId, TextureGrey); + + FullMaterial.SetTexture(NormalMapId, NormalMap != null ? NormalMap : TextureNormal); + + FullMaterial.SetTexture(MetallicMapId, MetallicMap != null ? MetallicMap : TextureBlack); + + FullMaterial.SetTexture(SmoothnessMapId, SmoothnessMap != null ? SmoothnessMap : TextureBlack); + + FullMaterial.SetTexture(AoMapId, AoMap != null ? AoMap : TextureWhite); + + FullMaterial.SetTexture(EdgeMapId, EdgeMap != null ? EdgeMap : TextureGrey); + + TestObject.GetComponent().material = FullMaterial; + + FullMaterial.SetVector(TilingId, new Vector4(1, 1, 0, 0)); + } + + public void SetFileFormat(int selection) + { + switch (selection) + { + + case 0: + SelectedFormat = FileFormat.Png; + break; + case 1: + SelectedFormat = FileFormat.Jpg; + break; + case 2: + SelectedFormat = FileFormat.Exr; + break; + case 3: + SelectedFormat = FileFormat.Tga; + break; + default: + break; + } + } + + public void CloseWindows() + { + HeightFromDiffuseGuiScript.Close(); + NormalFromHeightGuiScript.Close(); + EdgeFromNormalGuiScript.Close(); + AoFromNormalGuiScript.Close(); + EditDiffuseGuiScript.Close(); + MetallicGuiScript.Close(); + SmoothnessGuiScript.Close(); + _tilingTextureMakerGuiScript.Close(); + AlignmentGuiScript.Close(); + MaterialGuiObject.SetActive(false); + PostProcessGuiObject.SetActive(false); + } + + private void HideWindows() + { + _objectsToUnhide = new List(); + + if (HeightFromDiffuseGuiObject.activeSelf) _objectsToUnhide.Add(HeightFromDiffuseGuiObject); + + if (NormalFromHeightGuiObject.activeSelf) _objectsToUnhide.Add(NormalFromHeightGuiObject); + + if (EdgeFromNormalGuiObject.activeSelf) _objectsToUnhide.Add(EdgeFromNormalGuiObject); + + if (AoFromNormalGuiObject.activeSelf) _objectsToUnhide.Add(AoFromNormalGuiObject); + + if (EditDiffuseGuiObject.activeSelf) _objectsToUnhide.Add(EditDiffuseGuiObject); + + if (MetallicGuiObject.activeSelf) _objectsToUnhide.Add(MetallicGuiObject); + + if (SmoothnessGuiObject.activeSelf) _objectsToUnhide.Add(SmoothnessGuiObject); + + if (MaterialGuiObject.activeSelf) _objectsToUnhide.Add(MaterialGuiObject); + + if (PostProcessGuiObject.activeSelf) _objectsToUnhide.Add(PostProcessGuiObject); + + if (TilingTextureMakerGuiObject.activeSelf) _objectsToUnhide.Add(TilingTextureMakerGuiObject); + + HeightFromDiffuseGuiObject.SetActive(false); + NormalFromHeightGuiObject.SetActive(false); + EdgeFromNormalGuiObject.SetActive(false); + AoFromNormalGuiObject.SetActive(false); + EditDiffuseGuiObject.SetActive(false); + MetallicGuiObject.SetActive(false); + SmoothnessGuiObject.SetActive(false); + MaterialGuiObject.SetActive(false); + PostProcessGuiObject.SetActive(false); + TilingTextureMakerGuiObject.SetActive(false); + } + + private static void Fullscreen() + { + Screen.fullScreen = false; + } + + public void Quit() + { + Application.Quit(); + } + public void BatchLoadTextures() + { + Batchui.BatchLoadTextures(); + } + public void Windowed() + { + Fullscreen(); + } + public void UseInitalLocation(bool Bool) + { + Batchui.UseInitalLocation = Bool; + } + public void ProcessPropertyMap(bool Bool) + { + Batchui.ProcessPropertyMap = Bool; + } + + public void ShowPostWindow() + { + PostProcessGuiObject.SetActive(!PostProcessGuiObject.activeSelf); + } + public void TileTextures() + { + CloseWindows(); + FixSize(); + TilingTextureMakerGuiObject.SetActive(true); + _tilingTextureMakerGuiScript.Initialize(); + } + public void NextCubemap() + { + _selectedCubemap += 1; + if (_selectedCubemap >= CubeMaps.Length) _selectedCubemap = 0; + + SkyboxMaterial.SetTexture("_Tex", CubeMaps[_selectedCubemap]); + Shader.SetGlobalTexture(GlobalCubemapId, CubeMaps[_selectedCubemap]); + ReflectionProbe.RenderProbe(); + } + public void AdjustAlignment() + { + CloseWindows(); + FixSize(); + AlignmentGuiScript.Initialize(); + } + public void ClearAllTexturesGUI() + { + _clearTextures = false; + ClearAllTextures(); + CloseWindows(); + SetMaterialValues(); + FixSizeSize(1024.0f, 1024.0f); + } + public void ShowFullMat() + { + CloseWindows(); + FixSize(); + MaterialGuiObject.SetActive(true); + MaterialGuiScript.Initialize(); + } + private void ShowGui() + { + foreach (var objToHide in _objectsToUnhide) + objToHide.SetActive(true); + } + + private void HideGui() + { + HideWindows(); + } + + public void SaveTextureFile(MapType mapType) + { + _textureToSave = HeightMap; + var defaultName = "_" + mapType + ".png"; + var path = StandaloneFileBrowser.SaveFilePanel("Save Height Map", _lastDirectory, defaultName, + _imageSaveFilter); + if (path.IsNullOrEmpty()) return; + + _textureToSave = GetTextureToSave(mapType); + + var lastBar = path.LastIndexOf(_pathChar); + _lastDirectory = path.Substring(0, lastBar + 1); + SaveFile(path); + } + + public void SaveTextureFile(MapType mapType, string path, string name) + { + _textureToSave = HeightMap; + var defaultName = name + "_" + mapType + ".png"; + // var path = StandaloneFileBrowser.SaveFilePanel("Save Height Map", _lastDirectory, defaultName, + // _imageSaveFilter); + List PathSplit = path.Split(new string[] { "/", "\\" }, StringSplitOptions.None).ToList(); + //PathSplit[PathSplit.Length - 1] + PathSplit.RemoveAt(PathSplit.Count - 1); + //Debug.Log(PathSplit); + path = string.Join("/", PathSplit.ToArray()); + path = path + "/" + defaultName; + if (path.IsNullOrEmpty()) return; + + _textureToSave = GetTextureToSave(mapType); + var lastBar = path.LastIndexOf(_pathChar); + _lastDirectory = path.Substring(0, lastBar + 1); + Debug.Log(path); + SaveFile(path); + } + private Texture2D GetTextureToSave(MapType mapType) + { + switch (mapType) + { + case MapType.Height: + return HeightMap; + case MapType.Diffuse: + return DiffuseMap != null ? DiffuseMap : DiffuseMapOriginal; + case MapType.DiffuseOriginal: + return DiffuseMapOriginal; + case MapType.Metallic: + return MetallicMap; + case MapType.Smoothness: + return SmoothnessMap; + case MapType.Normal: + return NormalMap; + case MapType.Edge: + return EdgeMap; + case MapType.Ao: + return AoMap; + case MapType.Property: + return PropertyMap; + default: + throw new ArgumentOutOfRangeException(nameof(mapType), mapType, null); + } + } + + private void OpenTextureFile(MapType mapType) + { + _activeMapType = mapType; + var title = "Open " + mapType + " Map"; + var path = StandaloneFileBrowser.OpenFilePanel(title, _lastDirectory, _imageLoadFilter, false); + if (path[0].IsNullOrEmpty()) return; + var lastBar = path[0].LastIndexOf(_pathChar); + _lastDirectory = path[0].Substring(0, lastBar + 1); + OpenFile(path[0]); + } + + // ReSharper disable once InconsistentNaming + private static string PCM2String(PropChannelMap pcm, string defaultName) + { + var returnString = defaultName; + + switch (pcm) + { + case PropChannelMap.Height: + returnString = "Height"; + break; + case PropChannelMap.Metallic: + returnString = "Metallic"; + break; + case PropChannelMap.Smoothness: + returnString = "Smoothness"; + break; + case PropChannelMap.Edge: + returnString = "Edge"; + break; + case PropChannelMap.Ao: + returnString = "Ambient Occ"; + break; + case PropChannelMap.AoEdge: + returnString = "AO + Edge"; + break; + case PropChannelMap.None: + break; + default: + throw new ArgumentOutOfRangeException(nameof(pcm), pcm, null); + } + + return returnString; + } + + public void FlipNormalMapY() + { + if (NormalMap == null) return; + for (var i = 0; i < NormalMap.width; i++) + for (var j = 0; j < NormalMap.height; j++) + { + var pixelColor = NormalMap.GetPixel(i, j); + pixelColor.g = 1.0f - pixelColor.g; + NormalMap.SetPixel(i, j, pixelColor); + } + + NormalMap.Apply(); + } + + private void ClearTexture(MapType mapType) + { + switch (mapType) + { + case MapType.Height: + if (HeightMap) + { + Destroy(HeightMap); + HeightMap = null; + } + + if (HdHeightMap) + { + Destroy(HdHeightMap); + HdHeightMap = null; + } + + break; + case MapType.Diffuse: + if (DiffuseMap) + { + Destroy(DiffuseMap); + DiffuseMap = null; + } + + if (DiffuseMapOriginal) + { + Destroy(DiffuseMapOriginal); + DiffuseMapOriginal = null; + } + + break; + case MapType.Normal: + if (NormalMap) + { + Destroy(NormalMap); + NormalMap = null; + } + + break; + case MapType.Metallic: + if (MetallicMap) + { + Destroy(MetallicMap); + MetallicMap = null; + } + + break; + case MapType.Smoothness: + if (SmoothnessMap) + { + Destroy(SmoothnessMap); + SmoothnessMap = null; + } + + break; + case MapType.Edge: + if (EdgeMap) + { + Destroy(EdgeMap); + EdgeMap = null; + } + + break; + case MapType.Ao: + if (AoMap) + { + Destroy(AoMap); + AoMap = null; + } + + break; + case MapType.DiffuseOriginal: + if (DiffuseMapOriginal) + { + Destroy(DiffuseMapOriginal); + DiffuseMapOriginal = null; + } + + break; + case MapType.Property: + break; + default: + throw new ArgumentOutOfRangeException(nameof(mapType), mapType, null); + } + + Resources.UnloadUnusedAssets(); + } + + public void ClearAllTextures() + { + ClearTexture(MapType.Height); + ClearTexture(MapType.Diffuse); + ClearTexture(MapType.Normal); + ClearTexture(MapType.Metallic); + ClearTexture(MapType.Smoothness); + ClearTexture(MapType.Edge); + ClearTexture(MapType.Ao); + } + + public void SaveProject() + { + const string defaultName = "baseName.mtz"; + var path = StandaloneFileBrowser.SaveFilePanel("Save Project", _lastDirectory, defaultName, "mtz"); + if (path.IsNullOrEmpty()) return; + + var lastBar = path.LastIndexOf(_pathChar); + _lastDirectory = path.Substring(0, lastBar + 1); + + _saveLoadProjectScript.SaveProject(path); + } + + public void LoadProject() + { + var path = StandaloneFileBrowser.OpenFilePanel("Load Project", _lastDirectory, "mtz", false); + if (path[0].IsNullOrEmpty()) return; + + var lastBar = path[0].LastIndexOf(_pathChar); + _lastDirectory = path[0].Substring(0, lastBar + 1); + + _saveLoadProjectScript.LoadProject(path[0]); + } + + public void SetFormat(FileFormat newFormat) + { + _jpgSelected = false; + _pngSelected = false; + _tgaSelected = false; + _exrSelected = false; + + switch (newFormat) + { + case FileFormat.Jpg: + _jpgSelected = true; + break; + case FileFormat.Png: + _pngSelected = true; + break; + case FileFormat.Tga: + _tgaSelected = true; + break; + case FileFormat.Exr: + _exrSelected = true; + break; + default: + throw new ArgumentOutOfRangeException(nameof(newFormat), newFormat, null); + } + + SelectedFormat = newFormat; + } + + public void SetFormat(string newFormat) + { + _jpgSelected = false; + _pngSelected = false; + _tgaSelected = false; + _exrSelected = false; + + switch (newFormat) + { + case "jpg": + _jpgSelected = true; + SelectedFormat = FileFormat.Jpg; + break; + case "png": + _pngSelected = true; + SelectedFormat = FileFormat.Png; + break; + case "tga": + _tgaSelected = true; + SelectedFormat = FileFormat.Tga; + break; + case "exr": + _exrSelected = true; + SelectedFormat = FileFormat.Exr; + break; + default: + throw new ArgumentOutOfRangeException(nameof(newFormat), newFormat, null); + } + } + + public void SetLoadedTexture(MapType loadedTexture) + { + switch (loadedTexture) + { + case MapType.Height: + SetPreviewMaterial(HeightMap); + break; + case MapType.Diffuse: + SetPreviewMaterial(DiffuseMap); + break; + case MapType.DiffuseOriginal: + SetPreviewMaterial(DiffuseMapOriginal); + break; + case MapType.Normal: + SetPreviewMaterial(NormalMap); + break; + case MapType.Metallic: + SetPreviewMaterial(MetallicMap); + break; + case MapType.Smoothness: + SetPreviewMaterial(SmoothnessMap); + break; + case MapType.Edge: + SetPreviewMaterial(EdgeMap); + break; + case MapType.Ao: + SetPreviewMaterial(AoMap); + break; + case MapType.Property: + break; + default: + throw new ArgumentOutOfRangeException(nameof(loadedTexture), loadedTexture, null); + } + + FixSize(); + } + + //==================================================// + // Property Map // + //==================================================// + + private void SetPropertyTexture(string texPrefix, Texture2D texture, Texture overlayTexture) + { + _propertyCompMaterial.SetTexture(texPrefix + "Tex", texture != null ? texture : TextureBlack); + + _propertyCompMaterial.SetTexture(texPrefix + "OverlayTex", overlayTexture); + } + + private void SetPropertyMapChannel(string texPrefix, PropChannelMap pcm) + { + switch (pcm) + { + case PropChannelMap.Height: + SetPropertyTexture(texPrefix, HeightMap, TextureGrey); + break; + case PropChannelMap.Metallic: + SetPropertyTexture(texPrefix, MetallicMap, TextureGrey); + break; + case PropChannelMap.Smoothness: + SetPropertyTexture(texPrefix, SmoothnessMap, TextureGrey); + break; + case PropChannelMap.Edge: + SetPropertyTexture(texPrefix, EdgeMap, TextureGrey); + break; + case PropChannelMap.Ao: + SetPropertyTexture(texPrefix, AoMap, TextureGrey); + break; + case PropChannelMap.AoEdge: + SetPropertyTexture(texPrefix, AoMap, EdgeMap); + break; + case PropChannelMap.None: + SetPropertyTexture(texPrefix, TextureBlack, TextureGrey); + break; + default: + throw new ArgumentOutOfRangeException(nameof(pcm), pcm, null); + } + } + public void ProcessPropertyMapRevised() + { + var Size = GetSize(); + Texture2D TempMap = null; + if (PropAlpha == PropChannelMap.None) + { + TempMap = new Texture2D(HeightMap.width, HeightMap.height, TextureFormat.RGB24, false); + } + else + { + TempMap = new Texture2D(HeightMap.width, HeightMap.height, TextureFormat.RGBA32, false); + } + + Color theColour = new Color(); + for (int x = 0; x < TempMap.width; x++) + { + for (int y = 0; y < TempMap.height; y++) + { + theColour.r = TextureRed == null ? TextureRed.GetPixel(x, y).grayscale : new Texture2D(TempMap.width,TempMap.height).GetPixel(x,y).grayscale; + theColour.g = TextureGreen == null ? TextureGreen.GetPixel(x, y).grayscale : new Texture2D(TempMap.width, TempMap.height).GetPixel(x, y).grayscale; + theColour.b = TextureBlue == null ? TextureBlue.GetPixel(x, y).grayscale : new Texture2D(TempMap.width, TempMap.height).GetPixel(x, y).grayscale; + if (PropAlpha == PropChannelMap.None) + { + theColour.a = 255; + } + else + { + theColour.a = TextureAlpha == null ? TextureAlpha.GetPixel(x, y).grayscale : new Texture2D(TempMap.width, TempMap.height).GetPixel(x, y).grayscale; + + } + + TempMap.SetPixel(x, y, theColour); + } + } + TempMap.Apply(); + PropertyMap = TempMap; + SaveTextureFile(MapType.Property); + + } + public void ProcessPropertyMap() + { + SetPropertyMapChannel("_Red", PropRed); + SetPropertyMapChannel("_Green", PropGreen); + SetPropertyMapChannel("_Blue", PropBlue); + + var size = GetSize(); + var tempMap = RenderTexture.GetTemporary((int)size.x, (int)size.y, 0, RenderTextureFormat.ARGB32, + RenderTextureReadWrite.Default); + Graphics.Blit(MetallicMap, tempMap, _propertyCompMaterial, 0); + RenderTexture.active = tempMap; + + if (PropertyMap != null) + { + Destroy(PropertyMap); + PropertyMap = null; + } + + PropertyMap = new Texture2D(tempMap.width, tempMap.height, TextureFormat.RGB24, false); + PropertyMap.ReadPixels(new Rect(0, 0, tempMap.width, tempMap.height), 0, 0); + PropertyMap.Apply(); + + RenderTexture.ReleaseTemporary(tempMap); + // ReSharper disable once RedundantAssignment + tempMap = null; + } + + //==================================================// + // Project Saving // + //==================================================// + + private void SaveFile(string pathToFile) + { + _saveLoadProjectScript.SaveFile(pathToFile, _textureToSave); + } + + // ReSharper disable once MemberCanBeMadeStatic.Local + private void CopyFile() + { + _saveLoadProjectScript.CopyFile(_textureToSave); + } + + // ReSharper disable once MemberCanBeMadeStatic.Local + private void PasteFile() + { + ClearTexture(_activeMapType); + _saveLoadProjectScript.PasteFile(_activeMapType); + } + + private void OpenFile(string pathToFile) + { + if (pathToFile == null) return; + + // clear the existing texture we are loading + ClearTexture(_activeMapType); + + StartCoroutine(_saveLoadProjectScript.LoadTexture(_activeMapType, pathToFile)); + } + + //==================================================// + // Fix the size of the test model // + //==================================================// + + + private Vector2 GetSize() + { + Texture2D mapToUse = null; + + var size = new Vector2(1024, 1024); + + if (HeightMap != null) + mapToUse = HeightMap; + else if (DiffuseMap != null) + mapToUse = DiffuseMap; + else if (DiffuseMapOriginal != null) + mapToUse = DiffuseMapOriginal; + else if (NormalMap != null) + mapToUse = NormalMap; + else if (MetallicMap != null) + mapToUse = MetallicMap; + else if (SmoothnessMap != null) + mapToUse = SmoothnessMap; + else if (EdgeMap != null) + mapToUse = EdgeMap; + else if (AoMap != null) mapToUse = AoMap; + + if (mapToUse == null) return size; + size.x = mapToUse.width; + size.y = mapToUse.height; + + return size; + } + + public void FixSize() + { + var size = GetSize(); + FixSizeSize(size.x, size.y); + } + + private void FixSizeMap(Texture mapToUse) + { + FixSizeSize(mapToUse.width, mapToUse.height); + } + + private void FixSizeMap(RenderTexture mapToUse) + { + FixSizeSize(mapToUse.width, mapToUse.height); + } + + private void FixSizeSize(float width, float height) + { + var testObjectScale = new Vector3(1, 1, 1); + const float area = 1.0f; + + testObjectScale.x = width / height; + + var newArea = testObjectScale.x * testObjectScale.y; + var areaScale = Mathf.Sqrt(area / newArea); + + testObjectScale.x *= areaScale; + testObjectScale.y *= areaScale; + + TestObject.transform.localScale = testObjectScale; + } + private float TextureAspectRatio(float Height, float Width) + { + return Width / Height; + } + private float LockTextureValue(float Input, float Height, float Width) + { + return Input * (1 + TextureAspectRatio(Height, Width)); + } + public void MapSelection(int dropDownValue, string PropertyType) + { + PropChannelMap _channels; + switch (dropDownValue) + { + + case (0): + _channels = PropChannelMap.None; + break; + case (1): + _channels = PropChannelMap.Metallic; + break; + case (2): + _channels = PropChannelMap.Smoothness; + break; + case (3): + _channels = PropChannelMap.Height; + break; + case (4): + _channels = PropChannelMap.Ao; + break; + case (5): + _channels = PropChannelMap.Edge; + break; + case (6): + _channels = PropChannelMap.AoEdge; + break; + default: + _channels = PropChannelMap.None; + break; + } + switch (PropertyType) + { + case ("Red"): + PropRed = _channels; + TextureRed = returnTexture(_channels); + break; + case ("Blue"): + PropBlue = _channels; + TextureBlue = returnTexture(_channels); + break; + case ("Green"): + PropGreen = _channels; + TextureGreen = returnTexture(_channels); + break; + case ("Alpha"): + PropAlpha = _channels; + TextureAlpha = returnTexture(_channels); + break; + default: + break; + } + + } + public Texture2D returnTexture(PropChannelMap map) + { + switch (map) + { + case (PropChannelMap.Ao): + return AoMap; + case (PropChannelMap.Metallic): + return MetallicMap; + case (PropChannelMap.Height): + return HeightMap; + case (PropChannelMap.Edge): + return EdgeMap; + case (PropChannelMap.Smoothness): + return SmoothnessMap; + default: + return new Texture2D(1, 1); + } + } + + public void SavePropertyMap() + { + if (PropAlpha == PropChannelMap.None) + { + ProcessPropertyMap(); + } + else + { + ProcessPropertyMapRevised(); + } + // SaveTextureFile(MapType.Property); + } + public void QuickSavePropertyMap() + { + ProcessPropertyMap(); + _textureToSave = PropertyMap; + SaveFile(QuicksavePathProperty); + } + + public void Paste(int mapType) + { + switch (mapType) + { + case 0: + _activeMapType = global::MapType.DiffuseOriginal; + break; + case 1: + _activeMapType = global::MapType.Height; + break; + case 2: + _activeMapType = global::MapType.Normal; + break; + case 4: + _activeMapType = global::MapType.Metallic; + break; + case 3: + _activeMapType = global::MapType.Smoothness; + break; + case 5: + _activeMapType = global::MapType.Edge; + break; + case 6: + _activeMapType = global::MapType.Ao; + break; + + } + PasteFile(); + } + public void Copy(int mapType) + { + switch (mapType) + { + case 0: + _activeMapType = global::MapType.DiffuseOriginal; + break; + } + CopyFile(); + } + public void Open(int mapType) + { + MapType type = SetMapType(mapType); + OpenTextureFile(type); + if (type == MapType.Diffuse) + { + DiffuseMapOriginal = DiffuseMap; + } + } + + public void Save(int mapType) + { + MapType type = SetMapType(mapType); + SaveTextureFile(type); + } + private MapType SetMapType(int mapType) + { + var type = new MapType(); + switch (mapType) + { + case 0: + type = MapType.Diffuse; + break; + case 1: + type = MapType.Height; + break; + case 2: + type = MapType.Normal; + break; + case 3: + type = MapType.Smoothness; + break; + case 4: + type = MapType.Metallic; + break; + case 5: + type = MapType.Edge; + break; + case 6: + type = MapType.Ao; + break; + } + + + return type; + } + public void QuickSave(int mapType) + { + MapType type = SetMapType(mapType); + SaveTextureFile(type); + } + public void Preview(int mapType) + { + SetPreviewMaterial(DiffuseMap != null ? DiffuseMap : DiffuseMapOriginal); + } + + public void Edit(int mapType) + { + CloseWindows(); + FixSize(); + switch (mapType) + { + case 0: + EditDiffuseGuiObject.SetActive(true); + EditDiffuseGuiScript.NewTexture(); + EditDiffuseGuiScript.DoStuff(); + break; + case 1: + HeightFromDiffuseGuiObject.SetActive(true); + HeightFromDiffuseGuiScript.NewTexture(); + HeightFromDiffuseGuiScript.DoStuff(); + break; + case 2: + NormalFromHeightGuiObject.SetActive(true); + NormalFromHeightGuiScript.NewTexture(); + NormalFromHeightGuiScript.DoStuff(); + break; + case 3: + MetallicGuiObject.SetActive(true); + MetallicGuiScript.NewTexture(); + MetallicGuiScript.DoStuff(); + break; + case 4: + SmoothnessGuiObject.SetActive(true); + SmoothnessGuiScript.NewTexture(); + SmoothnessGuiScript.DoStuff(); + break; + case 5: + EdgeFromNormalGuiObject.SetActive(true); + EdgeFromNormalGuiScript.NewTexture(); + EdgeFromNormalGuiScript.DoStuff(); + break; + case 6: + AoFromNormalGuiObject.SetActive(true); + AoFromNormalGuiScript.NewTexture(); + AoFromNormalGuiScript.DoStuff(); + break; + + } + + } + + + public void Clear(int mapType) + { + ClearTexture(SetMapType(mapType)); + CloseWindows(); + SetMaterialValues(); + FixSize(); + } + + public void InvertMap() + { + Texture2D map = SmoothnessMap; + var whitePixels = 0; + var blackPixels = 0; + for (int i = 0; i < map.width; i++) { + + for (int j = 0; j < map.height; j++) + { + Color pixel = map.GetPixel(i, j); + + // if it's a white color then just debug... + pixel.r = 1 - pixel.r ; + pixel.g = 1 - pixel.g ; + pixel.b = 1 - pixel.b ; + map.SetPixel(i, j, pixel); + + } + } + map.Apply(); + SmoothnessMap = map; + SmoothnessTexture.texture = map; + SmoothnessTexture.color = new Color(1, 1, 1, 1); + + } + + + #region Gui Hide Variables + + [HideInInspector] public CountLocker HideGuiLocker = new CountLocker(); + private bool _lastGuiIsHiddenState; + private bool _isGuiHidden; + + public bool IsGuiHidden + { + get => _isGuiHidden; + set + { + if (HideGuiLocker.IsLocked) + { + Debug.Log("Tentando modificar IsGuiHidden quando travado"); + return; + } + + if (value && !_isGuiHidden) + { + HideGui(); + _isGuiHidden = true; + } + else if (!value && _isGuiHidden) + { + ShowGui(); + _isGuiHidden = false; + } + } + } + + + //public void SetPropertyMap() + + #endregion + } \ No newline at end of file diff --git a/Assets/Scripts/MaterialGui.cs b/Assets/Scripts/MaterialGui.cs index d047dad4..d1e0df6c 100644 --- a/Assets/Scripts/MaterialGui.cs +++ b/Assets/Scripts/MaterialGui.cs @@ -1,369 +1,382 @@ -using UnityEngine; -using System.Collections; +#region + using System.ComponentModel; +using UnityEngine; -public class MaterialSettings { - - [DefaultValueAttribute(1.0f)] - public float TexTilingX = 1.0f; - [DefaultValueAttribute(1.0f)] - public float TexTilingY = 1.0f; - [DefaultValueAttribute(0.0f)] - public float TexOffsetX = 0.0f; - [DefaultValueAttribute(0.0f)] - public float TexOffsetY = 0.0f; - - [DefaultValueAttribute("1")] - public string TexTilingXText; - [DefaultValueAttribute("1")] - public string TexTilingYText; - [DefaultValueAttribute("0")] - public string TexOffsetXText; - [DefaultValueAttribute("0")] - public string TexOffsetYText; - - [DefaultValueAttribute(1.0f)] - public float Metallic; - [DefaultValueAttribute(1.0f)] - public float Smoothness; - [DefaultValueAttribute(0.5f)] - public float Parallax; - [DefaultValueAttribute(1.0f)] - public float EdgePower; - [DefaultValueAttribute(1.0f)] - public float AOPower; - - [DefaultValueAttribute("1")] - public string MetallicText; - [DefaultValueAttribute("1")] - public string SmoothnessText; - [DefaultValueAttribute("0.5")] - public string ParallaxText; - [DefaultValueAttribute("1")] - public string EdgePowerText; - [DefaultValueAttribute("1")] - public string AOPowerText; - - [DefaultValueAttribute(1.0f)] - public float LightR; - [DefaultValueAttribute(1.0f)] - public float LightG; - [DefaultValueAttribute(1.0f)] - public float LightB; - [DefaultValueAttribute(1.0f)] - public float LightIntensity; - [DefaultValueAttribute("1")] - public string LightIntensityText; - - public MaterialSettings(){ - - this.TexTilingX = 1.0f; - this.TexTilingY = 1.0f; - this.TexOffsetX = 0.0f; - this.TexOffsetY = 0.0f; - - this.TexTilingXText = "1"; - this.TexTilingYText = "1"; - this.TexOffsetXText = "0"; - this.TexOffsetYText = "0"; - - this.Metallic = 1.0f; - this.Smoothness = 1.0f; - this.Parallax = 0.5f; - this.EdgePower = 1.0f; - this.AOPower = 1.0f; - - this.MetallicText = "1"; - this.SmoothnessText = "1"; - this.ParallaxText = "0.5"; - this.EdgePowerText = "1"; - this.AOPowerText = "1"; - - this.LightR = 1.0f; - this.LightG = 1.0f; - this.LightB = 1.0f; - this.LightIntensity = 1.0f; - this.LightIntensityText = "1"; - - } +#endregion -} +public class MaterialSettings +{ + [DefaultValue(1.0f)] public float AoPower; + + [DefaultValue("1")] public string AoPowerText; -public class MaterialGui : MonoBehaviour { + [DefaultValue(1.0f)] public float EdgePower; - MainGui MainGuiScript; - - Texture2D _HeightMap; - Texture2D _DiffuseMap; - Texture2D _NormalMap; - Texture2D _EdgeMap; - Texture2D _MetallicMap; - Texture2D _SmoothnessMap; - Texture2D _AOMap; + [DefaultValue("1")] public string EdgePowerText; - Texture2D myColorTexture; + [DefaultValue(1.0f)] public float LightB; - Material thisMaterial; + [DefaultValue(1.0f)] public float LightG; - public GameObject LightObject; - public ObjRotator testRotator; + [DefaultValue(1.0f)] public float LightIntensity; - public GameObject testObjectParent; - public GameObject testObject; - public GameObject testObjectCube; - public GameObject testObjectCylinder; - public GameObject testObjectSphere; + [DefaultValue(1.0f)] public float LightR; - bool planeShown = true; - bool cubeShown = false; - bool cylinderShown = false; - bool sphereShown = false; - float dispOffset = 0.5f; + [DefaultValue(1.0f)] public float Metallic; - bool settingsInitialized = false; + [DefaultValue("1")] public string MetallicText; - Rect windowRect = new Rect (30, 300, 300, 530); + [DefaultValue(0.5f)] public float Parallax; - MaterialSettings MatS; + [DefaultValue("0.5")] public string ParallaxText; - void OnDisable () { + [DefaultValue(1.0f)] public float Smoothness; - if ( MainGuiScript.hideGui == false ) { + [DefaultValue("1")] public string SmoothnessText; - if (!testObjectParent.activeSelf) { - testRotator.Reset (); - } + [DefaultValue(0.0f)] public float TexOffsetX; - testObjectParent.SetActive (true); - testObjectCube.SetActive (false); - testObjectCylinder.SetActive (false); - testObjectSphere.SetActive (false); - } + [DefaultValue("0")] public string TexOffsetXText; - } + [DefaultValue(0.0f)] public float TexOffsetY; - // Use this for initialization - void Start () { - InitializeSettings (); - } + [DefaultValue("0")] public string TexOffsetYText; - public void GetValues( ProjectObject projectObject ) { - InitializeSettings (); - projectObject.MatS = MatS; - } + [DefaultValue(1.0f)] public float TexTilingX; - public void SetValues( ProjectObject projectObject ) { - InitializeSettings (); - if (projectObject.MatS != null) { - MatS = projectObject.MatS; - } else { - settingsInitialized = false; - InitializeSettings (); - } - } + [DefaultValue("1")] public string TexTilingXText; - void InitializeSettings() { + [DefaultValue(1.0f)] public float TexTilingY; - if (settingsInitialized == false) { - Debug.Log ("Initializing MaterialSettings"); - MatS = new MaterialSettings (); - myColorTexture = new Texture2D (1, 1, TextureFormat.ARGB32, false); - settingsInitialized = true; - } + [DefaultValue("1")] public string TexTilingYText; - } + public MaterialSettings() + { + TexTilingX = 1.0f; + TexTilingY = 1.0f; + TexOffsetX = 0.0f; + TexOffsetY = 0.0f; - - // Update is called once per frame - void Update () { - - thisMaterial.SetFloat ("_Metallic", MatS.Metallic); - thisMaterial.SetFloat ("_Smoothness", MatS.Smoothness ); - thisMaterial.SetFloat ("_Parallax", MatS.Parallax ); - thisMaterial.SetFloat ("_EdgePower", MatS.EdgePower ); - thisMaterial.SetFloat ("_AOPower", MatS.AOPower ); - - thisMaterial.SetVector ("_Tiling", new Vector4 ( MatS.TexTilingX, MatS.TexTilingY, MatS.TexOffsetX, MatS.TexOffsetY )); - - LightObject.GetComponent ().color = new Color (MatS.LightR, MatS.LightG, MatS.LightB); - LightObject.GetComponent ().intensity = MatS.LightIntensity; - - testObjectParent.SetActive (planeShown); - testObjectCube.SetActive (cubeShown); - testObjectCylinder.SetActive (cylinderShown); - testObjectSphere.SetActive (sphereShown); - thisMaterial.SetFloat ("_DispOffset", dispOffset); - - } - - string FloatToString ( float num, int length ) { - - string numString = num.ToString (); - int numStringLength = numString.Length; - int lastIndex = Mathf.FloorToInt( Mathf.Min ( (float)numStringLength , (float)length ) ); - - return numString.Substring (0, lastIndex); - } - - void chooseLightColor( int posX, int posY ) { - - MatS.LightR = GUI.VerticalSlider( new Rect ( posX + 10, posY + 5, 30, 100 ), MatS.LightR, 1.0f, 0.0f ); - MatS.LightG = GUI.VerticalSlider( new Rect ( posX + 40, posY + 5, 30, 100 ), MatS.LightG, 1.0f, 0.0f); - MatS.LightB = GUI.VerticalSlider( new Rect ( posX + 70, posY + 5, 30, 100 ), MatS.LightB, 1.0f, 0.0f); - MatS.LightIntensity = GUI.VerticalSlider( new Rect ( posX + 120, posY + 5, 30, 100 ), MatS.LightIntensity, 3.0f, 0.0f); - - GUI.Label( new Rect( posX + 10, posY + 110,30,30 ),"R"); - GUI.Label( new Rect( posX + 40, posY + 110,30,30 ),"G"); - GUI.Label( new Rect( posX + 70, posY + 110,30,30 ),"B"); - GUI.Label( new Rect( posX + 100, posY + 110,100,30 ),"Intensity"); - - SetColorTexture (); - - GUI.DrawTexture( new Rect( posX + 170, posY + 5, 100, 100 ), myColorTexture ); - } - - void SetColorTexture(){ - - Color[] colorArray = new Color[1]; - colorArray [0] = new Color (MatS.LightR, MatS.LightG, MatS.LightB, 1.0f); - - myColorTexture.SetPixels (colorArray); - myColorTexture.Apply (); - - } - - void DoMyWindow ( int windowID ) { - - int spacingX = 0; - int spacingY = 50; - int spacing2Y = 70; - - int offsetX = 10; - int offsetY = 30; - - - GuiHelper.Slider (new Rect (offsetX, offsetY, 280, 50), "Metallic Multiplier", MatS.Metallic, MatS.MetallicText, out MatS.Metallic, out MatS.MetallicText, 0.0f, 2.0f ); - offsetY += 40; - - GuiHelper.Slider (new Rect (offsetX, offsetY, 280, 50), "Smoothness Multiplier", MatS.Smoothness, MatS.SmoothnessText, out MatS.Smoothness, out MatS.SmoothnessText, 0.0f, 2.0f ); - offsetY += 40; - - GuiHelper.Slider (new Rect (offsetX, offsetY, 280, 50), "Paralax Displacement", MatS.Parallax, MatS.ParallaxText, out MatS.Parallax, out MatS.ParallaxText, 0.0f, 2.0f ); - offsetY += 40; - - GuiHelper.Slider (new Rect (offsetX, offsetY, 280, 50), "Edge Amount", MatS.EdgePower, MatS.EdgePowerText, out MatS.EdgePower, out MatS.EdgePowerText, 0.0f, 2.0f ); - offsetY += 40; - - GuiHelper.Slider (new Rect (offsetX, offsetY, 280, 50), "Ambient Occlusion Power", MatS.AOPower, MatS.AOPowerText, out MatS.AOPower, out MatS.AOPowerText, 0.0f, 2.0f ); - offsetY += 40; - - GUI.Label (new Rect (offsetX, offsetY, 250, 30), "Light Color" ); - chooseLightColor ( offsetX, offsetY + 20 ); - offsetY += 160; - - GuiHelper.Slider (new Rect (offsetX, offsetY, 280, 50), "Texture Tiling X", MatS.TexTilingX, MatS.TexTilingXText, out MatS.TexTilingX, out MatS.TexTilingXText, 0.1f, 5.0f ); - offsetY += 30; - - GuiHelper.Slider (new Rect (offsetX, offsetY, 280, 50), "Texture Tiling Y", MatS.TexTilingY, MatS.TexTilingYText, out MatS.TexTilingY, out MatS.TexTilingYText, 0.1f, 5.0f ); - offsetY += 50; - - GuiHelper.Slider (new Rect (offsetX, offsetY, 280, 50), "Texture Offset X", MatS.TexOffsetX, MatS.TexOffsetXText, out MatS.TexOffsetX, out MatS.TexOffsetXText, -1.0f, 1.0f ); - offsetY += 30; - - GuiHelper.Slider (new Rect (offsetX, offsetY, 280, 50), "Texture Offset Y", MatS.TexOffsetY, MatS.TexOffsetYText, out MatS.TexOffsetY, out MatS.TexOffsetYText, -1.0f, 1.0f ); - offsetY += 50; - - if (GUI.Button (new Rect (offsetX, offsetY, 60, 30), "Plane")) { - planeShown = true; - cubeShown = false; - cylinderShown = false; - sphereShown = false; - dispOffset = 1.0f; - Shader.DisableKeyword ("TOP_PROJECTION"); - } - - if (GUI.Button (new Rect (offsetX + 70, offsetY, 60, 30), "Cube")) { - planeShown = false; - cubeShown = true; - cylinderShown = false; - sphereShown = false; - dispOffset = 0.25f; - Shader.EnableKeyword ("TOP_PROJECTION"); - } - - if (GUI.Button (new Rect (offsetX + 140, offsetY, 70, 30), "Cylinder")) { - planeShown = false; - cubeShown = false; - cylinderShown = true; - sphereShown = false; - dispOffset = 0.25f; - Shader.EnableKeyword ("TOP_PROJECTION"); - } - - if (GUI.Button (new Rect (offsetX + 220, offsetY, 60, 30), "Sphere")) { - planeShown = false; - cubeShown = false; - cylinderShown = false; - sphereShown = true; - dispOffset = 0.25f; - Shader.EnableKeyword ("TOP_PROJECTION"); - } - - GUI.DragWindow(); - - } - - void OnGUI () { - - windowRect.width = 300; - windowRect.height = 590; - - windowRect = GUI.Window(14, windowRect, DoMyWindow, "Full Material"); - - } - - public void Initialize() { - - InitializeSettings (); - - MainGuiScript = MainGui.instance; - thisMaterial = MainGuiScript.FullMaterial; - - thisMaterial.SetTexture ("_DisplacementMap", MainGuiScript._TextureGrey); - thisMaterial.SetTexture ("_DiffuseMap", MainGuiScript._TextureGrey); - thisMaterial.SetTexture ("_NormalMap", MainGuiScript._TextureNormal); - thisMaterial.SetTexture ("_MetallicMap", MainGuiScript._TextureBlack); - thisMaterial.SetTexture ("_SmoothnessMap", MainGuiScript._TextureGrey); - thisMaterial.SetTexture ("_AOMap", MainGuiScript._TextureWhite); - thisMaterial.SetTexture ("_EdgeMap", MainGuiScript._TextureGrey); - thisMaterial.SetFloat ("_DispOffset", 1.0f ); - - _HeightMap = MainGuiScript._HeightMap; - - if (MainGuiScript._DiffuseMap != null) { - _DiffuseMap = MainGuiScript._DiffuseMap; - } else { - _DiffuseMap = MainGuiScript._DiffuseMapOriginal; - } - _NormalMap = MainGuiScript._NormalMap; - _EdgeMap = MainGuiScript._EdgeMap; - _MetallicMap = MainGuiScript._MetallicMap; - _SmoothnessMap = MainGuiScript._SmoothnessMap; - _AOMap = MainGuiScript._AOMap; - - if (_HeightMap != null) { thisMaterial.SetTexture ("_DisplacementMap", _HeightMap); } - if (_DiffuseMap != null) { thisMaterial.SetTexture ("_DiffuseMap", _DiffuseMap); } - if (_NormalMap != null) { thisMaterial.SetTexture ("_NormalMap", _NormalMap); } - if (_MetallicMap != null) { thisMaterial.SetTexture ("_MetallicMap", _MetallicMap); } - if (_SmoothnessMap != null) { thisMaterial.SetTexture ("_SmoothnessMap", _SmoothnessMap); } - if (_AOMap != null) { thisMaterial.SetTexture ("_AOMap", _AOMap); } - if (_EdgeMap != null) { thisMaterial.SetTexture ("_EdgeMap", _EdgeMap); } - - testObject.GetComponent().material = thisMaterial; - testObjectCube.GetComponent().material = thisMaterial; - testObjectCylinder.GetComponent().material = thisMaterial; - testObjectSphere.GetComponent().material = thisMaterial; - - } + TexTilingXText = "1"; + TexTilingYText = "1"; + TexOffsetXText = "0"; + TexOffsetYText = "0"; + Metallic = 1.0f; + Smoothness = 1.0f; + Parallax = 0.5f; + EdgePower = 1.0f; + AoPower = 1.0f; + + MetallicText = "1"; + SmoothnessText = "1"; + ParallaxText = "0.5"; + EdgePowerText = "1"; + AoPowerText = "1"; + + LightR = 1.0f; + LightG = 1.0f; + LightB = 1.0f; + LightIntensity = 1.0f; + } } + +public class MaterialGui : MonoBehaviour +{ + private static readonly int Metallic = Shader.PropertyToID("_Metallic"); + private static readonly int Smoothness = Shader.PropertyToID("_Smoothness"); + private static readonly int Parallax = Shader.PropertyToID("_Parallax"); + private static readonly int EdgePower = Shader.PropertyToID("_EdgePower"); + private static readonly int AoPower = Shader.PropertyToID("_AOPower"); + private static readonly int Tiling = Shader.PropertyToID("_Tiling"); + private static readonly int DispOffset = Shader.PropertyToID("_DispOffset"); + private static readonly int DisplacementMap = Shader.PropertyToID("_DisplacementMap"); + private static readonly int DiffuseMap = Shader.PropertyToID("_DiffuseMap"); + private static readonly int NormalMap = Shader.PropertyToID("_NormalMap"); + private static readonly int MetallicMap = Shader.PropertyToID("_MetallicMap"); + private static readonly int SmoothnessMap = Shader.PropertyToID("_SmoothnessMap"); + private static readonly int AoMap = Shader.PropertyToID("_AOMap"); + private static readonly int EdgeMap = Shader.PropertyToID("_EdgeMap"); + private Texture2D _aoMap; + private bool _cubeShown; + private bool _cylinderShown; + private Texture2D _diffuseMap; + private float _dispOffset = 0.5f; + private Texture2D _edgeMap; + + private Texture2D _heightMap; + private Light _light; + + private MainGui _mainGuiScript; + + private MaterialSettings _materialSettings; + private Texture2D _metallicMap; + + private Texture2D _myColorTexture; + private Texture2D _normalMap; + + private bool _planeShown = true; + + private bool _settingsInitialized; + private Texture2D _smoothnessMap; + private bool _sphereShown; + + private Material _thisMaterial; + + private Rect _windowRect = new Rect(30, 300, 300, 530); + + public GameObject LightObject; + public GameObject TestObject; + public GameObject TestObjectCube; + public GameObject TestObjectCylinder; + + public GameObject TestObjectParent; + public GameObject TestObjectSphere; + public ObjRotator TestRotator; + + private void OnDisable() + { + if (!_mainGuiScript.IsGuiHidden || TestObjectParent == null) return; + if (!TestObjectParent.activeSelf) TestRotator.Reset(); + + TestObjectParent.SetActive(true); + TestObjectCube.SetActive(false); + TestObjectCylinder.SetActive(false); + TestObjectSphere.SetActive(false); + } + + private void Start() + { + _light = LightObject.GetComponent(); + InitializeSettings(); + } + + public void GetValues(ProjectObject projectObject) + { + InitializeSettings(); + projectObject.MaterialSettings = _materialSettings; + } + + public void SetValues(ProjectObject projectObject) + { + InitializeSettings(); + if (projectObject.MaterialSettings != null) + { + _materialSettings = projectObject.MaterialSettings; + } + else + { + _settingsInitialized = false; + InitializeSettings(); + } + } + + private void InitializeSettings() + { + if (_settingsInitialized) return; + Debug.Log("Initializing MaterialSettings"); + _materialSettings = new MaterialSettings(); + _myColorTexture = new Texture2D(1, 1, TextureFormat.ARGB32, false); + _settingsInitialized = true; + } + + + // Update is called once per frame + private void Update() + { + _thisMaterial.SetFloat(Metallic, _materialSettings.Metallic); + _thisMaterial.SetFloat(Smoothness, _materialSettings.Smoothness); + _thisMaterial.SetFloat(Parallax, _materialSettings.Parallax); + _thisMaterial.SetFloat(EdgePower, _materialSettings.EdgePower); + _thisMaterial.SetFloat(AoPower, _materialSettings.AoPower); + + _thisMaterial.SetVector(Tiling, + new Vector4(_materialSettings.TexTilingX, _materialSettings.TexTilingY, _materialSettings.TexOffsetX, + _materialSettings.TexOffsetY)); + + _light.color = new Color(_materialSettings.LightR, _materialSettings.LightG, _materialSettings.LightB); + _light.intensity = _materialSettings.LightIntensity; + + TestObjectParent.SetActive(_planeShown); + TestObjectCube.SetActive(_cubeShown); + TestObjectCylinder.SetActive(_cylinderShown); + TestObjectSphere.SetActive(_sphereShown); + _thisMaterial.SetFloat(DispOffset, _dispOffset); + } + + private void ChooseLightColor(int posX, int posY) + { + _materialSettings.LightR = + GUI.VerticalSlider(new Rect(posX + 10, posY + 5, 30, 100), _materialSettings.LightR, 1.0f, 0.0f); + _materialSettings.LightG = + GUI.VerticalSlider(new Rect(posX + 40, posY + 5, 30, 100), _materialSettings.LightG, 1.0f, 0.0f); + _materialSettings.LightB = + GUI.VerticalSlider(new Rect(posX + 70, posY + 5, 30, 100), _materialSettings.LightB, 1.0f, 0.0f); + _materialSettings.LightIntensity = + GUI.VerticalSlider(new Rect(posX + 120, posY + 5, 30, 100), _materialSettings.LightIntensity, 3.0f, 0.0f); + + GUI.Label(new Rect(posX + 10, posY + 110, 30, 30), "R"); + GUI.Label(new Rect(posX + 40, posY + 110, 30, 30), "G"); + GUI.Label(new Rect(posX + 70, posY + 110, 30, 30), "B"); + GUI.Label(new Rect(posX + 100, posY + 110, 100, 30), "Intensity"); + + SetColorTexture(); + + GUI.DrawTexture(new Rect(posX + 170, posY + 5, 100, 100), _myColorTexture); + } + + private void SetColorTexture() + { + var colorArray = new Color[1]; + colorArray[0] = new Color(_materialSettings.LightR, _materialSettings.LightG, _materialSettings.LightB, 1.0f); + + _myColorTexture.SetPixels(colorArray); + _myColorTexture.Apply(); + } + + private void DoMyWindow(int windowId) + { + const int offsetX = 10; + var offsetY = 30; + + + GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Metallic Multiplier", _materialSettings.Metallic, + _materialSettings.MetallicText, + out _materialSettings.Metallic, out _materialSettings.MetallicText, 0.0f, 2.0f); + offsetY += 40; + + GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Smoothness Multiplier", _materialSettings.Smoothness, + _materialSettings.SmoothnessText, out _materialSettings.Smoothness, out _materialSettings.SmoothnessText, + 0.0f, 2.0f); + offsetY += 40; + + GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Paralax Displacement", _materialSettings.Parallax, + _materialSettings.ParallaxText, + out _materialSettings.Parallax, out _materialSettings.ParallaxText, 0.0f, 2.0f); + offsetY += 40; + + GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Edge Amount", _materialSettings.EdgePower, + _materialSettings.EdgePowerText, + out _materialSettings.EdgePower, out _materialSettings.EdgePowerText, 0.0f, 2.0f); + offsetY += 40; + + GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Ambient Occlusion Power", _materialSettings.AoPower, + _materialSettings.AoPowerText, + out _materialSettings.AoPower, out _materialSettings.AoPowerText, 0.0f, 2.0f); + offsetY += 40; + + GUI.Label(new Rect(offsetX, offsetY, 250, 30), "Light Color"); + ChooseLightColor(offsetX, offsetY + 20); + offsetY += 160; + + GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Texture Tiling X", _materialSettings.TexTilingX, + _materialSettings.TexTilingXText, + out _materialSettings.TexTilingX, out _materialSettings.TexTilingXText, 0.1f, 5.0f); + offsetY += 30; + + GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Texture Tiling Y", _materialSettings.TexTilingY, + _materialSettings.TexTilingYText, + out _materialSettings.TexTilingY, out _materialSettings.TexTilingYText, 0.1f, 5.0f); + offsetY += 50; + + GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Texture Offset X", _materialSettings.TexOffsetX, + _materialSettings.TexOffsetXText, + out _materialSettings.TexOffsetX, out _materialSettings.TexOffsetXText, -1.0f, 1.0f); + offsetY += 30; + + GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Texture Offset Y", _materialSettings.TexOffsetY, + _materialSettings.TexOffsetYText, + out _materialSettings.TexOffsetY, out _materialSettings.TexOffsetYText, -1.0f, 1.0f); + offsetY += 50; + + if (GUI.Button(new Rect(offsetX, offsetY, 60, 30), "Plane")) + { + _planeShown = true; + _cubeShown = false; + _cylinderShown = false; + _sphereShown = false; + _dispOffset = 1.0f; + Shader.DisableKeyword("TOP_PROJECTION"); + } + + if (GUI.Button(new Rect(offsetX + 70, offsetY, 60, 30), "Cube")) + { + _planeShown = false; + _cubeShown = true; + _cylinderShown = false; + _sphereShown = false; + _dispOffset = 0.25f; + Shader.EnableKeyword("TOP_PROJECTION"); + } + + if (GUI.Button(new Rect(offsetX + 140, offsetY, 70, 30), "Cylinder")) + { + _planeShown = false; + _cubeShown = false; + _cylinderShown = true; + _sphereShown = false; + _dispOffset = 0.25f; + Shader.EnableKeyword("TOP_PROJECTION"); + } + + if (GUI.Button(new Rect(offsetX + 220, offsetY, 60, 30), "Sphere")) + { + _planeShown = false; + _cubeShown = false; + _cylinderShown = false; + _sphereShown = true; + _dispOffset = 0.25f; + Shader.EnableKeyword("TOP_PROJECTION"); + } + + GUI.DragWindow(); + } + + private void OnGUI() + { + _windowRect.width = 300; + _windowRect.height = 590; + + _windowRect = GUI.Window(14, _windowRect, DoMyWindow, "Full Material"); + } + + public void Initialize() + { + InitializeSettings(); + + _mainGuiScript = MainGui.Instance; + _thisMaterial = _mainGuiScript.FullMaterial; + + _thisMaterial.SetTexture(DisplacementMap, _mainGuiScript.TextureGrey); + _thisMaterial.SetTexture(DiffuseMap, _mainGuiScript.TextureGrey); + _thisMaterial.SetTexture(NormalMap, _mainGuiScript.TextureNormal); + _thisMaterial.SetTexture(MetallicMap, _mainGuiScript.TextureBlack); + _thisMaterial.SetTexture(SmoothnessMap, _mainGuiScript.TextureGrey); + _thisMaterial.SetTexture(AoMap, _mainGuiScript.TextureWhite); + _thisMaterial.SetTexture(EdgeMap, _mainGuiScript.TextureGrey); + _thisMaterial.SetFloat(DispOffset, 1.0f); + + _heightMap = _mainGuiScript.HeightMap; + + _diffuseMap = _mainGuiScript.DiffuseMap != null ? _mainGuiScript.DiffuseMap : _mainGuiScript.DiffuseMapOriginal; + _normalMap = _mainGuiScript.NormalMap; + _edgeMap = _mainGuiScript.EdgeMap; + _metallicMap = _mainGuiScript.MetallicMap; + _smoothnessMap = _mainGuiScript.SmoothnessMap; + _aoMap = _mainGuiScript.AoMap; + + if (_heightMap != null) _thisMaterial.SetTexture(DisplacementMap, _heightMap); + if (_diffuseMap != null) _thisMaterial.SetTexture(DiffuseMap, _diffuseMap); + if (_normalMap != null) _thisMaterial.SetTexture(NormalMap, _normalMap); + if (_metallicMap != null) _thisMaterial.SetTexture(MetallicMap, _metallicMap); + if (_smoothnessMap != null) _thisMaterial.SetTexture(SmoothnessMap, _smoothnessMap); + if (_aoMap != null) _thisMaterial.SetTexture(AoMap, _aoMap); + if (_edgeMap != null) _thisMaterial.SetTexture(EdgeMap, _edgeMap); + + TestObject.GetComponent().material = _thisMaterial; + TestObjectCube.GetComponent().material = _thisMaterial; + TestObjectCylinder.GetComponent().material = _thisMaterial; + TestObjectSphere.GetComponent().material = _thisMaterial; + } +} \ No newline at end of file diff --git a/Assets/Scripts/MetallicGui.cs b/Assets/Scripts/MetallicGui.cs index bf807be2..07a73456 100644 --- a/Assets/Scripts/MetallicGui.cs +++ b/Assets/Scripts/MetallicGui.cs @@ -1,530 +1,455 @@ -using UnityEngine; +#region + using System.Collections; -using System.ComponentModel; - -public class MetallicSettings { - - //[DefaultValueAttribute(Color.black)] - public Color MetalColor; - - //[DefaultValueAttribute(Vector2.zero)] - public Vector2 SampleUV; - - [DefaultValueAttribute(1.0f)] - public float HueWeight; - [DefaultValueAttribute(0.5f)] - public float SatWeight; - [DefaultValueAttribute(0.2f)] - public float LumWeight; - - [DefaultValueAttribute(0.0f)] - public float MaskLow; - [DefaultValueAttribute(1.0f)] - public float MaskHigh; - - [DefaultValueAttribute(0)] - public int BlurSize; - [DefaultValueAttribute("0")] - public string BlurSizeText; - - [DefaultValueAttribute(30)] - public int OverlayBlurSize; - [DefaultValueAttribute("30")] - public string OverlayBlurSizeText; - - [DefaultValueAttribute(1.0f)] - public float BlurOverlay; - [DefaultValueAttribute("1")] - public string BlurOverlayText; - - [DefaultValueAttribute(1.0f)] - public float FinalContrast; - [DefaultValueAttribute("1")] - public string FinalContrastText; - - [DefaultValueAttribute(0.0f)] - public float FinalBias; - [DefaultValueAttribute("0")] - public string FinalBiasText; - - [DefaultValueAttribute(false)] - public bool useAdjustedDiffuse; - [DefaultValueAttribute(true)] - public bool useOriginalDiffuse; - - public MetallicSettings(){ - this.MetalColor = Color.black; - - this.SampleUV = Vector2.zero; - - this.HueWeight = 1.0f; - this.SatWeight = 0.5f; - this.LumWeight = 0.2f; - - this.MaskLow = 0.0f; - this.MaskHigh = 1.0f; - - this.BlurSize = 0; - this.BlurSizeText = "0"; - - this.OverlayBlurSize = 30; - this.OverlayBlurSizeText = "30"; - - this.BlurOverlay = 1.0f; - this.BlurOverlayText = "1"; - - this.FinalContrast = 1.0f; - this.FinalContrastText = "1"; - - this.FinalBias = 0.0f; - this.FinalBiasText = "0"; - - this.useAdjustedDiffuse = false; - this.useOriginalDiffuse = true; - - } - -} - -public class MetallicGui : MonoBehaviour { - - public MainGui MainGuiScript; - - Texture2D _DiffuseMap; - Texture2D _DiffuseMapOriginal; - - Texture2D _MetallicMap; - Texture2D _MetalColorMap; - - RenderTexture _TempMap; - RenderTexture _BlurMap; - RenderTexture _OverlayBlurMap; - - public Material thisMaterial; - Material blitMaterial; - Material metallicBlitMaterial; - - int imageSizeX; - int imageSizeY; - - MetallicSettings MS; - - float Slider = 0.5f; - - bool lastUseAdjustedDiffuse = false; - - Rect windowRect = new Rect (30, 300, 300, 530); - - public GameObject testObject; - bool doStuff = false; - bool newTexture = false; - bool selectingColor = false; - bool mouseButtonDown = false; - - bool settingsInitialized = false; - - public bool busy = true; - - public void GetValues( ProjectObject projectObject ) { - InitializeSettings (); - projectObject.MS = MS; - } - - public void SetValues( ProjectObject projectObject ) { - InitializeSettings (); - if (projectObject.MS != null) { - MS = projectObject.MS; - } else { - settingsInitialized = false; - InitializeSettings (); - } - - _MetalColorMap.SetPixel (1, 1, MS.MetalColor); - _MetalColorMap.Apply (); - - doStuff = true; - } - - void InitializeSettings() { - - if (settingsInitialized == false) { - Debug.Log ("Initializing Metallic Settings"); - MS = new MetallicSettings (); - - _MetalColorMap = new Texture2D (1, 1, TextureFormat.ARGB32, false, true); - _MetalColorMap.SetPixel (1, 1, MS.MetalColor); - _MetalColorMap.Apply (); - - settingsInitialized = true; - } - - } - - // Use this for initialization - void Start () { - - testObject.GetComponent().sharedMaterial = thisMaterial; - - blitMaterial = new Material (Shader.Find ("Hidden/Blit_Shader")); - - metallicBlitMaterial = new Material (Shader.Find ("Hidden/Blit_Metallic")); - - InitializeSettings (); - - } - - public void DoStuff() { - doStuff = true; - } - - public void NewTexture() { - newTexture = true; - } - - void SelectColor() { - if ( Input.GetMouseButton(0) ) { - - mouseButtonDown = true; - - RaycastHit hit; - if (!Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit)) - return; - - Renderer rend = hit.transform.GetComponent(); - MeshCollider meshCollider = hit.collider as MeshCollider; - if (rend == null || rend.sharedMaterial == null || rend.sharedMaterial.mainTexture == null || meshCollider == null) - return; - - Vector2 pixelUV = hit.textureCoord; - - MS.SampleUV = pixelUV; - - if( MS.useAdjustedDiffuse ){ - MS.MetalColor = _DiffuseMap.GetPixelBilinear(pixelUV.x, pixelUV.y); - }else{ - MS.MetalColor = _DiffuseMapOriginal.GetPixelBilinear(pixelUV.x, pixelUV.y); - } - - _MetalColorMap.SetPixel (1, 1, MS.MetalColor); - _MetalColorMap.Apply (); - - } - - if ( Input.GetMouseButtonUp(0) && mouseButtonDown ) { - - mouseButtonDown = false; - selectingColor = false; - - } - - } - - // Update is called once per frame - void Update () { - - if (selectingColor) { - SelectColor(); - } - - if (newTexture) { - InitializeTextures(); - newTexture = false; - } - - if (MS.useAdjustedDiffuse != lastUseAdjustedDiffuse) { - lastUseAdjustedDiffuse = MS.useAdjustedDiffuse; - doStuff = true; - } - - if (doStuff) { - StartCoroutine( ProcessBlur () ); - doStuff = false; - } - - //thisMaterial.SetFloat ("_BlurWeight", BlurWeight); - - thisMaterial.SetVector ( "_MetalColor", MS.MetalColor); - thisMaterial.SetVector ( "_SampleUV", new Vector4 (MS.SampleUV.x, MS.SampleUV.y, 0, 0)); - - thisMaterial.SetFloat ( "_HueWeight", MS.HueWeight ); - thisMaterial.SetFloat ( "_SatWeight", MS.SatWeight ); - thisMaterial.SetFloat ( "_LumWeight", MS.LumWeight ); - thisMaterial.SetFloat ( "_MaskLow", MS.MaskLow ); - thisMaterial.SetFloat ( "_MaskHigh", MS.MaskHigh ); - - thisMaterial.SetFloat ( "_Slider", Slider); - thisMaterial.SetFloat ( "_BlurOverlay", MS.BlurOverlay); - thisMaterial.SetFloat ( "_FinalContrast", MS.FinalContrast); - thisMaterial.SetFloat ( "_FinalBias", MS.FinalBias); - - if ( MS.useAdjustedDiffuse ) { - thisMaterial.SetTexture ("_MainTex", _DiffuseMap); - } else { - thisMaterial.SetTexture ("_MainTex", _DiffuseMapOriginal); - } - - } - - string FloatToString ( float num, int length ) { - - string numString = num.ToString (); - int numStringLength = numString.Length; - int lastIndex = Mathf.FloorToInt( Mathf.Min ( (float)numStringLength , (float)length ) ); - - return numString.Substring (0, lastIndex); - } - - void DoMyWindow ( int windowID ) { - - int spacingX = 0; - int spacingY = 50; - int spacing2Y = 70; - - int offsetX = 10; - int offsetY = 30; - - if (_DiffuseMap != null) { GUI.enabled = true; } else { GUI.enabled = false; } - if( GUI.Toggle (new Rect (offsetX, offsetY, 140, 30), MS.useAdjustedDiffuse, " Use Edited Diffuse")) { - MS.useAdjustedDiffuse = true; - MS.useOriginalDiffuse = false; - } - GUI.enabled = true; - if (GUI.Toggle (new Rect (offsetX + 150, offsetY, 140, 30), MS.useOriginalDiffuse, " Use Original Diffuse")) { - MS.useAdjustedDiffuse = false; - MS.useOriginalDiffuse = true; - } - - offsetY += 30; - - GUI.Label (new Rect (offsetX, offsetY, 250, 30), "Metalic Reveal Slider" ); - Slider = GUI.HorizontalSlider( new Rect( offsetX, offsetY + 20, 280, 10 ),Slider,0.0f, 1.0f ); - - offsetY += 40; - - if (GUI.Button (new Rect (offsetX, offsetY + 10, 80, 30), "Pick Color")) { - selectingColor = true; - } - - GUI.DrawTexture( new Rect (offsetX, offsetY + 50, 80, 80), _MetalColorMap ); - - GUI.Label (new Rect (offsetX + 90, offsetY, 250, 30), "Hue"); - MS.HueWeight = GUI.VerticalSlider( new Rect( offsetX + 95, offsetY + 30, 10, 100 ),MS.HueWeight,1.0f, 0.0f ); - - GUI.Label (new Rect (offsetX + 130, offsetY, 250, 30), "Sat" ); - MS.SatWeight = GUI.VerticalSlider( new Rect( offsetX + 135, offsetY + 30, 10, 100 ),MS.SatWeight,1.0f, 0.0f ); - - GUI.Label (new Rect (offsetX + 170, offsetY, 250, 30), "Lum" ); - MS.LumWeight = GUI.VerticalSlider( new Rect( offsetX + 175, offsetY + 30, 10, 100 ),MS.LumWeight,1.0f, 0.0f ); - - GUI.Label (new Rect (offsetX + 220, offsetY, 250, 30), "Low" ); - MS.MaskLow = GUI.VerticalSlider( new Rect( offsetX + 225, offsetY + 30, 10, 100 ),MS.MaskLow,1.0f, 0.0f ); - - GUI.Label (new Rect (offsetX + 250, offsetY, 250, 30), "High" ); - MS.MaskHigh = GUI.VerticalSlider( new Rect( offsetX + 255, offsetY + 30, 10, 100 ),MS.MaskHigh,1.0f, 0.0f ); - - offsetY += 150; - - if (GuiHelper.Slider (new Rect (offsetX, offsetY, 280, 50), "Blur Size", MS.BlurSize, MS.BlurSizeText, out MS.BlurSize, out MS.BlurSizeText, 0, 100)) { - doStuff = true; - } - offsetY += 40; - - if( GuiHelper.Slider (new Rect (offsetX, offsetY, 280, 50), "Overlay Blur Size", MS.OverlayBlurSize, MS.OverlayBlurSizeText, out MS.OverlayBlurSize, out MS.OverlayBlurSizeText, 10, 100 ) ){ - doStuff = true; - } - offsetY += 40; - - GuiHelper.Slider (new Rect (offsetX, offsetY, 280, 50), "High Pass Overlay", MS.BlurOverlay, MS.BlurOverlayText, out MS.BlurOverlay, out MS.BlurOverlayText, -10.0f, 10.0f ); - offsetY += 40; - - GuiHelper.Slider (new Rect (offsetX, offsetY, 280, 50), "Final Contrast", MS.FinalContrast, MS.FinalContrastText, out MS.FinalContrast, out MS.FinalContrastText, -2.0f, 2.0f ); - offsetY += 40; - - GuiHelper.Slider (new Rect (offsetX, offsetY, 280, 50), "Final Bias", MS.FinalBias, MS.FinalBiasText, out MS.FinalBias, out MS.FinalBiasText, -0.5f, 0.5f ); - offsetY += 50; - - if( GUI.Button (new Rect (offsetX + 150, offsetY, 130, 30), "Set as Metallic" ) ){ - StartCoroutine( ProcessMetallic() ); - } - - - GUI.DragWindow(); - - } - - void OnGUI () { - - windowRect.width = 300; - windowRect.height = 500; - - windowRect = GUI.Window(15, windowRect, DoMyWindow, "Metallic From Diffuse"); - - } - - public void Close(){ - CleanupTextures (); - this.gameObject.SetActive (false); - } - - void CleanupTexture( RenderTexture _Texture ) { - - if (_Texture != null) { - _Texture.Release(); - _Texture = null; - } - - } - - void CleanupTextures() { - - Debug.Log ("Cleaning Up Textures"); - - CleanupTexture( _BlurMap ); - CleanupTexture( _OverlayBlurMap ); - CleanupTexture( _TempMap ); - - } - - public void InitializeTextures() { - - testObject.GetComponent().sharedMaterial = thisMaterial; - - CleanupTextures (); - - _DiffuseMap = MainGuiScript._DiffuseMap; - _DiffuseMapOriginal = MainGuiScript._DiffuseMapOriginal; - - if (_DiffuseMap) { - thisMaterial.SetTexture ("_MainTex", _DiffuseMap); - imageSizeX = _DiffuseMap.width; - imageSizeY = _DiffuseMap.height; - } else { - thisMaterial.SetTexture ("_MainTex", _DiffuseMapOriginal); - imageSizeX = _DiffuseMapOriginal.width; - imageSizeY = _DiffuseMapOriginal.height; - - MS.useAdjustedDiffuse = false; - MS.useOriginalDiffuse = true; - } - - Debug.Log ( "Initializing Textures of size: " + imageSizeX.ToString() + "x" + imageSizeY.ToString() ); - - _TempMap = new RenderTexture (imageSizeX, imageSizeY, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear); - _TempMap.wrapMode = TextureWrapMode.Repeat; - _BlurMap = new RenderTexture (imageSizeX, imageSizeY, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear); - _BlurMap.wrapMode = TextureWrapMode.Repeat; - _OverlayBlurMap = new RenderTexture (imageSizeX, imageSizeY, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear); - _OverlayBlurMap.wrapMode = TextureWrapMode.Repeat; - - } - - public IEnumerator ProcessMetallic() { - - busy = true; - - Debug.Log ("Processing Height"); - - metallicBlitMaterial.SetVector ("_ImageSize", new Vector4 (imageSizeX, imageSizeY, 0, 0)); - - metallicBlitMaterial.SetVector ( "_MetalColor", MS.MetalColor); - metallicBlitMaterial.SetVector ( "_SampleUV", new Vector4 (MS.SampleUV.x, MS.SampleUV.y, 0, 0)); - - metallicBlitMaterial.SetFloat ( "_HueWeight", MS.HueWeight ); - metallicBlitMaterial.SetFloat ( "_SatWeight", MS.SatWeight ); - metallicBlitMaterial.SetFloat ( "_LumWeight", MS.LumWeight ); - - metallicBlitMaterial.SetFloat ( "_MaskLow", MS.MaskLow ); - metallicBlitMaterial.SetFloat ( "_MaskHigh", MS.MaskHigh ); - - metallicBlitMaterial.SetFloat ( "_Slider", Slider); - - metallicBlitMaterial.SetFloat ( "_BlurOverlay", MS.BlurOverlay); - - metallicBlitMaterial.SetFloat ( "_FinalContrast", MS.FinalContrast); - - metallicBlitMaterial.SetFloat ( "_FinalBias", MS.FinalBias); - - metallicBlitMaterial.SetTexture ("_BlurTex", _BlurMap); - - metallicBlitMaterial.SetTexture ("_OverlayBlurTex", _OverlayBlurMap); - - CleanupTexture (_TempMap); - _TempMap = new RenderTexture (imageSizeX, imageSizeY, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear); - _TempMap.wrapMode = TextureWrapMode.Repeat; - - if ( MS.useAdjustedDiffuse ) { - Graphics.Blit( _DiffuseMap, _TempMap, metallicBlitMaterial, 0); - } else { - Graphics.Blit( _DiffuseMapOriginal, _TempMap, metallicBlitMaterial, 0); - } - - RenderTexture.active = _TempMap; - - if (MainGuiScript._MetallicMap != null) { - Destroy (MainGuiScript._MetallicMap); - } - - MainGuiScript._MetallicMap = new Texture2D (_TempMap.width, _TempMap.height, TextureFormat.ARGB32, true, true); - MainGuiScript._MetallicMap.ReadPixels (new Rect (0, 0, _TempMap.width, _TempMap.height), 0, 0); - MainGuiScript._MetallicMap.Apply (); - - yield return new WaitForSeconds(0.01f); - - CleanupTexture ( _TempMap ); - - busy = false; - - } - - public IEnumerator ProcessBlur () { - - busy = true; - - Debug.Log ("Processing Blur"); - - blitMaterial.SetVector ("_ImageSize", new Vector4( imageSizeX, imageSizeY, 0, 0 ) ); - blitMaterial.SetFloat ("_BlurContrast", 1.0f); - blitMaterial.SetFloat ("_BlurSpread", 1.0f); - - // Blur the image 1 - blitMaterial.SetInt ("_BlurSamples", MS.BlurSize); - blitMaterial.SetVector ("_BlurDirection", new Vector4(1,0,0,0) ); - if (MS.useAdjustedDiffuse) { - if (MS.BlurSize == 0) { - Graphics.Blit (_DiffuseMap, _TempMap); - } else { - Graphics.Blit (_DiffuseMap, _TempMap, blitMaterial, 1); - } - } else { - if (MS.BlurSize == 0) { - Graphics.Blit (_DiffuseMapOriginal, _TempMap); - } else { - Graphics.Blit (_DiffuseMapOriginal, _TempMap, blitMaterial, 1); - } - } - blitMaterial.SetVector ("_BlurDirection", new Vector4(0,1,0,0) ); - if (MS.BlurSize == 0) { - Graphics.Blit (_TempMap, _BlurMap); - } else { - Graphics.Blit (_TempMap, _BlurMap, blitMaterial, 1); - } - thisMaterial.SetTexture ("_BlurTex", _BlurMap); - - // Blur the image for overlay - blitMaterial.SetInt ("_BlurSamples", MS.OverlayBlurSize); - blitMaterial.SetVector ("_BlurDirection", new Vector4(1,0,0,0) ); - if ( MS.useAdjustedDiffuse ) { - Graphics.Blit( _DiffuseMap, _TempMap, blitMaterial, 1 ); - } else { - Graphics.Blit( _DiffuseMapOriginal, _TempMap, blitMaterial, 1 ); - } - blitMaterial.SetVector ("_BlurDirection", new Vector4(0,1,0,0) ); - Graphics.Blit(_TempMap, _OverlayBlurMap, blitMaterial, 1); - thisMaterial.SetTexture ("_OverlayBlurTex", _OverlayBlurMap); - - yield return new WaitForSeconds(0.01f); - - busy = false; - - } -} +using UnityEngine; + +#endregion + +// ReSharper disable Unity.PreferAddressByIdToGraphicsParams + +public class MetallicGui : MonoBehaviour +{ + private static readonly int MetalColor = Shader.PropertyToID("_MetalColor"); + private static readonly int SampleUv = Shader.PropertyToID("_SampleUV"); + private static readonly int HueWeight = Shader.PropertyToID("_HueWeight"); + private static readonly int SatWeight = Shader.PropertyToID("_SatWeight"); + private static readonly int LumWeight = Shader.PropertyToID("_LumWeight"); + private static readonly int MaskLow = Shader.PropertyToID("_MaskLow"); + private static readonly int MaskHigh = Shader.PropertyToID("_MaskHigh"); + private static readonly int Slider = Shader.PropertyToID("_Slider"); + private static readonly int BlurOverlay = Shader.PropertyToID("_BlurOverlay"); + private static readonly int FinalContrast = Shader.PropertyToID("_FinalContrast"); + private static readonly int FinalBias = Shader.PropertyToID("_FinalBias"); + private static readonly int MainTex = Shader.PropertyToID("_MainTex"); + private Material _blitMaterial; + private RenderTexture _blurMap; + private Camera _camera; + + private Texture2D _diffuseMap; + private Texture2D _diffuseMapOriginal; + private bool _doStuff; + + private int _imageSizeX; + private int _imageSizeY; + + private bool _lastUseAdjustedDiffuse; + private Texture2D _metalColorMap; + private Material _metallicBlitMaterial; + + private Texture2D _metallicMap; + + private MetallicSettings _metallicSettings; + private bool _mouseButtonDown; + private bool _newTexture; + private RenderTexture _overlayBlurMap; + private bool _selectingColor; + + private bool _settingsInitialized; + + private float _slider = 0.5f; + + private RenderTexture _tempMap; + + private Rect _windowRect = new Rect(30, 300, 300, 530); + + [HideInInspector] public bool Busy = true; + + public MainGui MainGuiScript; + + public GameObject TestObject; + + public Material ThisMaterial; + + public void GetValues(ProjectObject projectObject) + { + InitializeSettings(); + projectObject.MetallicSettings = _metallicSettings; + } + + public void SetValues(ProjectObject projectObject) + { + InitializeSettings(); + if (projectObject.MetallicSettings != null) + { + _metallicSettings = projectObject.MetallicSettings; + } + else + { + _settingsInitialized = false; + InitializeSettings(); + } + + _metalColorMap.SetPixel(1, 1, _metallicSettings.MetalColor); + _metalColorMap.Apply(); + + _doStuff = true; + } + + private void InitializeSettings() + { + if (_settingsInitialized) return; + Debug.Log("Initializing Metallic Settings"); + _metallicSettings = new MetallicSettings(); + + _metalColorMap = new Texture2D(1, 1, TextureFormat.ARGB32, false, true); + _metalColorMap.SetPixel(1, 1, _metallicSettings.MetalColor); + _metalColorMap.Apply(); + + _settingsInitialized = true; + } + + // Use this for initialization + private void Start() + { + _camera = Camera.main; + TestObject.GetComponent().sharedMaterial = ThisMaterial; + + _blitMaterial = new Material(Shader.Find("Hidden/Blit_Shader")); + + _metallicBlitMaterial = new Material(Shader.Find("Hidden/Blit_Metallic")); + + InitializeSettings(); + } + + public void DoStuff() + { + _doStuff = true; + } + + public void NewTexture() + { + _newTexture = true; + } + + private void SelectColor() + { + if (Input.GetMouseButton(0)) + { + _mouseButtonDown = true; + + if (!Physics.Raycast(_camera.ScreenPointToRay(Input.mousePosition), out var hit)) + return; + + var rend = hit.transform.GetComponent(); + var meshCollider = hit.collider as MeshCollider; + if (!rend || !rend.sharedMaterial || !rend.sharedMaterial.mainTexture || !meshCollider) + return; + + var pixelUv = hit.textureCoord; + + _metallicSettings.SampleUv = pixelUv; + + _metallicSettings.MetalColor = _metallicSettings.UseAdjustedDiffuse + ? _diffuseMap.GetPixelBilinear(pixelUv.x, pixelUv.y) + : _diffuseMapOriginal.GetPixelBilinear(pixelUv.x, pixelUv.y); + + _metalColorMap.SetPixel(1, 1, _metallicSettings.MetalColor); + _metalColorMap.Apply(); + } + + if (!Input.GetMouseButtonUp(0) || !_mouseButtonDown) return; + + _mouseButtonDown = false; + _selectingColor = false; + } + + // Update is called once per frame + private void Update() + { + if (_selectingColor) SelectColor(); + + if (_newTexture) + { + InitializeTextures(); + _newTexture = false; + } + + if (_metallicSettings.UseAdjustedDiffuse != _lastUseAdjustedDiffuse) + { + _lastUseAdjustedDiffuse = _metallicSettings.UseAdjustedDiffuse; + _doStuff = true; + } + + if (_doStuff) + { + StartCoroutine(ProcessBlur()); + _doStuff = false; + } + + //thisMaterial.SetFloat ("_BlurWeight", BlurWeight); + + ThisMaterial.SetVector(MetalColor, _metallicSettings.MetalColor); + ThisMaterial.SetVector(SampleUv, + new Vector4(_metallicSettings.SampleUv.x, _metallicSettings.SampleUv.y, 0, 0)); + + ThisMaterial.SetFloat(HueWeight, _metallicSettings.HueWeight); + ThisMaterial.SetFloat(SatWeight, _metallicSettings.SatWeight); + ThisMaterial.SetFloat(LumWeight, _metallicSettings.LumWeight); + ThisMaterial.SetFloat(MaskLow, _metallicSettings.MaskLow); + ThisMaterial.SetFloat(MaskHigh, _metallicSettings.MaskHigh); + + ThisMaterial.SetFloat(Slider, _slider); + ThisMaterial.SetFloat(BlurOverlay, _metallicSettings.BlurOverlay); + ThisMaterial.SetFloat(FinalContrast, _metallicSettings.FinalContrast); + ThisMaterial.SetFloat(FinalBias, _metallicSettings.FinalBias); + + ThisMaterial.SetTexture(MainTex, _metallicSettings.UseAdjustedDiffuse ? _diffuseMap : _diffuseMapOriginal); + } + + private void DoMyWindow(int windowId) + { + const int offsetX = 10; + var offsetY = 30; + + GUI.enabled = _diffuseMap != null; + if (GUI.Toggle(new Rect(offsetX, offsetY, 140, 30), _metallicSettings.UseAdjustedDiffuse, + " Use Edited Diffuse")) + { + _metallicSettings.UseAdjustedDiffuse = true; + _metallicSettings.UseOriginalDiffuse = false; + } + + GUI.enabled = true; + if (GUI.Toggle(new Rect(offsetX + 150, offsetY, 140, 30), _metallicSettings.UseOriginalDiffuse, + " Use Original Diffuse")) + { + _metallicSettings.UseAdjustedDiffuse = false; + _metallicSettings.UseOriginalDiffuse = true; + } + + offsetY += 30; + + GUI.Label(new Rect(offsetX, offsetY, 250, 30), "Metallic Reveal Slider"); + _slider = GUI.HorizontalSlider(new Rect(offsetX, offsetY + 20, 280, 10), _slider, 0.0f, 1.0f); + + offsetY += 40; + + if (GUI.Button(new Rect(offsetX, offsetY + 10, 80, 30), "Pick Color")) _selectingColor = true; + + GUI.DrawTexture(new Rect(offsetX, offsetY + 50, 80, 80), _metalColorMap); + + GUI.Label(new Rect(offsetX + 90, offsetY, 250, 30), "Hue"); + _metallicSettings.HueWeight = GUI.VerticalSlider(new Rect(offsetX + 95, offsetY + 30, 10, 100), + _metallicSettings.HueWeight, 1.0f, 0.0f); + + GUI.Label(new Rect(offsetX + 130, offsetY, 250, 30), "Sat"); + _metallicSettings.SatWeight = GUI.VerticalSlider(new Rect(offsetX + 135, offsetY + 30, 10, 100), + _metallicSettings.SatWeight, 1.0f, 0.0f); + + GUI.Label(new Rect(offsetX + 170, offsetY, 250, 30), "Lum"); + _metallicSettings.LumWeight = GUI.VerticalSlider(new Rect(offsetX + 175, offsetY + 30, 10, 100), + _metallicSettings.LumWeight, 1.0f, 0.0f); + + GUI.Label(new Rect(offsetX + 220, offsetY, 250, 30), "Low"); + _metallicSettings.MaskLow = GUI.VerticalSlider(new Rect(offsetX + 225, offsetY + 30, 10, 100), + _metallicSettings.MaskLow, 1.0f, 0.0f); + + GUI.Label(new Rect(offsetX + 250, offsetY, 250, 30), "High"); + _metallicSettings.MaskHigh = GUI.VerticalSlider(new Rect(offsetX + 255, offsetY + 30, 10, 100), + _metallicSettings.MaskHigh, 1.0f, 0.0f); + + offsetY += 150; + + if (GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Blur Size", _metallicSettings.BlurSize, + _metallicSettings.BlurSizeText, + out _metallicSettings.BlurSize, out _metallicSettings.BlurSizeText, 0, 100)) _doStuff = true; + offsetY += 40; + + if (GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Overlay Blur Size", + _metallicSettings.OverlayBlurSize, + _metallicSettings.OverlayBlurSizeText, out _metallicSettings.OverlayBlurSize, + out _metallicSettings.OverlayBlurSizeText, 10, 100)) _doStuff = true; + offsetY += 40; + + GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "High Pass Overlay", _metallicSettings.BlurOverlay, + _metallicSettings.BlurOverlayText, + out _metallicSettings.BlurOverlay, out _metallicSettings.BlurOverlayText, -10.0f, 10.0f); + offsetY += 40; + + GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Final Contrast", _metallicSettings.FinalContrast, + _metallicSettings.FinalContrastText, + out _metallicSettings.FinalContrast, out _metallicSettings.FinalContrastText, -2.0f, 2.0f); + offsetY += 40; + + GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Final Bias", _metallicSettings.FinalBias, + _metallicSettings.FinalBiasText, + out _metallicSettings.FinalBias, out _metallicSettings.FinalBiasText, -0.5f, 0.5f); + offsetY += 50; + if (GUI.Button(new Rect(offsetX + 10, offsetY, 130, 30), "Reset to Defaults")) + { + //_settingsInitialized = false; + SetValues(new ProjectObject()); + //StartCoroutine(ProcessDiffuse()); + } + if (GUI.Button(new Rect(offsetX + 150, offsetY, 130, 30), "Set as Metallic")) StartCoroutine(ProcessMetallic()); + + + GUI.DragWindow(); + } + + private void OnGUI() + { + _windowRect.width = 300; + _windowRect.height = 500; + + _windowRect = GUI.Window(15, _windowRect, DoMyWindow, "Metallic From Diffuse"); + } + + public void Close() + { + CleanupTextures(); + gameObject.SetActive(false); + } + + private static void CleanupTexture(RenderTexture texture) + { + if (!texture) return; + texture.Release(); + // ReSharper disable once RedundantAssignment + texture = null; + } + + private void CleanupTextures() + { + CleanupTexture(_blurMap); + CleanupTexture(_overlayBlurMap); + CleanupTexture(_tempMap); + } + + public void InitializeTextures() + { + TestObject.GetComponent().sharedMaterial = ThisMaterial; + + CleanupTextures(); + + _diffuseMap = MainGuiScript.DiffuseMap; + _diffuseMapOriginal = MainGuiScript.DiffuseMapOriginal; + + if (_diffuseMap) + { + ThisMaterial.SetTexture(MainTex, _diffuseMap); + _imageSizeX = _diffuseMap.width; + _imageSizeY = _diffuseMap.height; + } + else + { + ThisMaterial.SetTexture(MainTex, _diffuseMapOriginal); + _imageSizeX = _diffuseMapOriginal.width; + _imageSizeY = _diffuseMapOriginal.height; + + _metallicSettings.UseAdjustedDiffuse = false; + _metallicSettings.UseOriginalDiffuse = true; + } + + Debug.Log("Initializing Textures of size: " + _imageSizeX + "x" + _imageSizeY); + + _tempMap = new RenderTexture(_imageSizeX, _imageSizeY, 0, RenderTextureFormat.ARGB32, + RenderTextureReadWrite.Linear) {wrapMode = TextureWrapMode.Repeat}; + _blurMap = new RenderTexture(_imageSizeX, _imageSizeY, 0, RenderTextureFormat.ARGB32, + RenderTextureReadWrite.Linear) {wrapMode = TextureWrapMode.Repeat}; + _overlayBlurMap = new RenderTexture(_imageSizeX, _imageSizeY, 0, RenderTextureFormat.ARGB32, + RenderTextureReadWrite.Linear) {wrapMode = TextureWrapMode.Repeat}; + } + + public IEnumerator ProcessMetallic() + { + Busy = true; + + Debug.Log("Processing Height"); + + _metallicBlitMaterial.SetVector("_ImageSize", new Vector4(_imageSizeX, _imageSizeY, 0, 0)); + + _metallicBlitMaterial.SetVector("_MetalColor", _metallicSettings.MetalColor); + _metallicBlitMaterial.SetVector("_SampleUV", + new Vector4(_metallicSettings.SampleUv.x, _metallicSettings.SampleUv.y, 0, 0)); + + _metallicBlitMaterial.SetFloat("_HueWeight", _metallicSettings.HueWeight); + _metallicBlitMaterial.SetFloat("_SatWeight", _metallicSettings.SatWeight); + _metallicBlitMaterial.SetFloat("_LumWeight", _metallicSettings.LumWeight); + + _metallicBlitMaterial.SetFloat("_MaskLow", _metallicSettings.MaskLow); + _metallicBlitMaterial.SetFloat("_MaskHigh", _metallicSettings.MaskHigh); + + _metallicBlitMaterial.SetFloat("_Slider", _slider); + + _metallicBlitMaterial.SetFloat("_BlurOverlay", _metallicSettings.BlurOverlay); + + _metallicBlitMaterial.SetFloat("_FinalContrast", _metallicSettings.FinalContrast); + + _metallicBlitMaterial.SetFloat("_FinalBias", _metallicSettings.FinalBias); + + _metallicBlitMaterial.SetTexture("_BlurTex", _blurMap); + + _metallicBlitMaterial.SetTexture("_OverlayBlurTex", _overlayBlurMap); + + CleanupTexture(_tempMap); + _tempMap = new RenderTexture(_imageSizeX, _imageSizeY, 0, RenderTextureFormat.ARGB32, + RenderTextureReadWrite.Linear) {wrapMode = TextureWrapMode.Repeat}; + + Graphics.Blit(_metallicSettings.UseAdjustedDiffuse ? _diffuseMap : _diffuseMapOriginal, _tempMap, + _metallicBlitMaterial, 0); + + RenderTexture.active = _tempMap; + + if (MainGuiScript.MetallicMap) Destroy(MainGuiScript.MetallicMap); + + MainGuiScript.MetallicMap = new Texture2D(_tempMap.width, _tempMap.height, TextureFormat.ARGB32, true, true); + MainGuiScript.MetallicMap.ReadPixels(new Rect(0, 0, _tempMap.width, _tempMap.height), 0, 0); + MainGuiScript.MetallicMap.Apply(); + + yield return new WaitForSeconds(0.01f); + + CleanupTexture(_tempMap); + + Busy = false; + } + + public IEnumerator ProcessBlur() + { + Busy = true; + + Debug.Log("Processing Blur"); + + _blitMaterial.SetVector("_ImageSize", new Vector4(_imageSizeX, _imageSizeY, 0, 0)); + _blitMaterial.SetFloat("_BlurContrast", 1.0f); + _blitMaterial.SetFloat("_BlurSpread", 1.0f); + + // Blur the image 1 + _blitMaterial.SetInt("_BlurSamples", _metallicSettings.BlurSize); + _blitMaterial.SetVector("_BlurDirection", new Vector4(1, 0, 0, 0)); + if (_metallicSettings.UseAdjustedDiffuse) + { + if (_metallicSettings.BlurSize == 0) + Graphics.Blit(_diffuseMap, _tempMap); + else + Graphics.Blit(_diffuseMap, _tempMap, _blitMaterial, 1); + } + else + { + if (_metallicSettings.BlurSize == 0) + Graphics.Blit(_diffuseMapOriginal, _tempMap); + else + Graphics.Blit(_diffuseMapOriginal, _tempMap, _blitMaterial, 1); + } + + _blitMaterial.SetVector("_BlurDirection", new Vector4(0, 1, 0, 0)); + if (_metallicSettings.BlurSize == 0) + Graphics.Blit(_tempMap, _blurMap); + else + Graphics.Blit(_tempMap, _blurMap, _blitMaterial, 1); + ThisMaterial.SetTexture("_BlurTex", _blurMap); + + // Blur the image for overlay + _blitMaterial.SetInt("_BlurSamples", _metallicSettings.OverlayBlurSize); + _blitMaterial.SetVector("_BlurDirection", new Vector4(1, 0, 0, 0)); + Graphics.Blit(_metallicSettings.UseAdjustedDiffuse ? _diffuseMap : _diffuseMapOriginal, _tempMap, _blitMaterial, + 1); + _blitMaterial.SetVector("_BlurDirection", new Vector4(0, 1, 0, 0)); + Graphics.Blit(_tempMap, _overlayBlurMap, _blitMaterial, 1); + ThisMaterial.SetTexture("_OverlayBlurTex", _overlayBlurMap); + + yield return new WaitForSeconds(0.01f); + + Busy = false; + } +} \ No newline at end of file diff --git a/Assets/Scripts/MetallicSettings.cs b/Assets/Scripts/MetallicSettings.cs new file mode 100644 index 00000000..6b464a0d --- /dev/null +++ b/Assets/Scripts/MetallicSettings.cs @@ -0,0 +1,81 @@ +#region + +using System.ComponentModel; +using UnityEngine; + +#endregion + +public class MetallicSettings +{ + [DefaultValue(1.0f)] public float BlurOverlay; + + [DefaultValue("1")] public string BlurOverlayText; + + [DefaultValue(0)] public int BlurSize; + + [DefaultValue("0")] public string BlurSizeText; + + [DefaultValue(0.0f)] public float FinalBias; + + [DefaultValue("0")] public string FinalBiasText; + + [DefaultValue(1.0f)] public float FinalContrast; + + [DefaultValue("1")] public string FinalContrastText; + + [DefaultValue(1.0f)] public float HueWeight; + + [DefaultValue(0.2f)] public float LumWeight; + + [DefaultValue(1.0f)] public float MaskHigh; + + [DefaultValue(0.0f)] public float MaskLow; + + //[DefaultValueAttribute(Color.black)] + public Color MetalColor; + + [DefaultValue(30)] public int OverlayBlurSize; + + [DefaultValue("30")] public string OverlayBlurSizeText; + + //[DefaultValueAttribute(Vector2.zero)] + public Vector2 SampleUv; + + [DefaultValue(0.5f)] public float SatWeight; + + [DefaultValue(false)] public bool UseAdjustedDiffuse; + + [DefaultValue(true)] public bool UseOriginalDiffuse; + + public MetallicSettings() + { + MetalColor = Color.black; + + SampleUv = Vector2.zero; + + HueWeight = 1.0f; + SatWeight = 0.5f; + LumWeight = 0.2f; + + MaskLow = 0.0f; + MaskHigh = 1.0f; + + BlurSize = 0; + BlurSizeText = "0"; + + OverlayBlurSize = 30; + OverlayBlurSizeText = "30"; + + BlurOverlay = 1.0f; + BlurOverlayText = "1"; + + FinalContrast = 1.0f; + FinalContrastText = "1"; + + FinalBias = 0.0f; + FinalBiasText = "0"; + + UseAdjustedDiffuse = false; + UseOriginalDiffuse = true; + } +} \ No newline at end of file diff --git a/Assets/Scripts/MetallicSettings.cs.meta b/Assets/Scripts/MetallicSettings.cs.meta new file mode 100644 index 00000000..f15f9b4a --- /dev/null +++ b/Assets/Scripts/MetallicSettings.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 2bdb7c40c588407da3094e0f50598bf3 +timeCreated: 1549047402 \ No newline at end of file diff --git a/Assets/Scripts/NormalFromHeightGui.cs b/Assets/Scripts/NormalFromHeightGui.cs index ba218e53..70f6f1e6 100644 --- a/Assets/Scripts/NormalFromHeightGui.cs +++ b/Assets/Scripts/NormalFromHeightGui.cs @@ -1,647 +1,567 @@ -using UnityEngine; -using System.Collections; -using System.ComponentModel; - -public class NormalFromHeightSettings { - - [DefaultValueAttribute(20.0f)] - public float Blur0Contrast; - [DefaultValueAttribute("20")] - public string Blur0ContrastText; - - [DefaultValueAttribute(0.3f)] - public float Blur0Weight; - [DefaultValueAttribute(0.35f)] - public float Blur1Weight; - [DefaultValueAttribute(0.5f)] - public float Blur2Weight; - [DefaultValueAttribute(0.8f)] - public float Blur3Weight; - [DefaultValueAttribute(1.0f)] - public float Blur4Weight; - [DefaultValueAttribute(0.95f)] - public float Blur5Weight; - [DefaultValueAttribute(0.8f)] - public float Blur6Weight; - - [DefaultValueAttribute(5.0f)] - public float FinalContrast; - [DefaultValueAttribute("5")] - public string FinalContrastText; - - [DefaultValueAttribute(0.0f)] - public float Angularity; - [DefaultValueAttribute("0")] - public string AngularityText; +#region - [DefaultValueAttribute(0.5f)] - public float AngularIntensity; - [DefaultValueAttribute("0.5")] - public string AngularIntensityText; - - [DefaultValueAttribute(true)] - public bool UseDiffuse; - - [DefaultValueAttribute(0.0f)] - public float ShapeRecognition; - [DefaultValueAttribute("0")] - public string ShapeRecognitionText; - - [DefaultValueAttribute(0.0f)] - public float LightRotation; - [DefaultValueAttribute("0")] - public string LightRotationText; - - [DefaultValueAttribute(50.0f)] - public int SlopeBlur; - [DefaultValueAttribute("50")] - public string SlopeBlurText; - - [DefaultValueAttribute(0.5f)] - public float ShapeBias; - [DefaultValueAttribute("0.5")] - public string ShapeBiasText; - - public NormalFromHeightSettings() { - - this.Blur0Weight = 0.3f; - this.Blur1Weight = 0.35f; - this.Blur2Weight = 0.5f; - this.Blur3Weight = 0.8f; - this.Blur4Weight = 1.0f; - this.Blur5Weight = 0.95f; - this.Blur6Weight = 0.8f; - - this.Blur0Contrast = 20.0f; - this.Blur0ContrastText = "20"; - - this.FinalContrast = 5.0f; - this.FinalContrastText = "5"; - - this.Angularity = 0.0f; - this.AngularityText = "0"; - - this.AngularIntensity = 0.5f; - this.AngularIntensityText = "0.5"; - - this.UseDiffuse = true; - - this.ShapeRecognition = 0.0f; - this.ShapeRecognitionText = "0"; - - this.LightRotation = 0.0f; - this.LightRotationText = "0"; - - this.SlopeBlur = 50; - this.SlopeBlurText = "50"; - - this.ShapeBias = 0.5f; - this.ShapeBiasText = "0.5"; - } - -} - -public class NormalFromHeightGui : MonoBehaviour { - - MainGui MGS; - - public Light mainLight; - - RenderTexture _TempBlurMap; - public RenderTexture _HeightBlurMap; - RenderTexture _BlurMap0; - RenderTexture _BlurMap1; - RenderTexture _BlurMap2; - RenderTexture _BlurMap3; - RenderTexture _BlurMap4; - RenderTexture _BlurMap5; - RenderTexture _BlurMap6; - RenderTexture _TempNormalMap; - - float Slider = 0.5f; - - float _BlurScale = 1.0f; - int imageSizeX = 1024; - int imageSizeY = 1024; - - NormalFromHeightSettings NFHS; - - public Material thisMaterial; - Material blitMaterial; - - public GameObject testObject; - bool doStuff = false; - bool newTexture = false; - - Rect windowRect = new Rect (30, 300, 300, 450); - bool settingsInitialized = false; - - public bool busy = false; - - public void GetValues( ProjectObject projectObject ) { - InitializeSettings (); - projectObject.NFHS = NFHS; - } - - public void SetValues( ProjectObject projectObject ) { - InitializeSettings (); - if (projectObject.NFHS != null) { - NFHS = projectObject.NFHS; - } else { - settingsInitialized = false; - InitializeSettings (); - } - doStuff = true; - } - - void InitializeSettings() { - - if (settingsInitialized == false) { - Debug.Log ("Initializing Normal From Height Settings"); - NFHS = new NormalFromHeightSettings (); - settingsInitialized = true; - } - - } - - // Use this for initialization - void Start () { - - MGS = MainGui.instance; - - testObject.GetComponent().sharedMaterial = thisMaterial; - - blitMaterial = new Material (Shader.Find ("Hidden/Blit_Shader")); - - InitializeSettings (); - SetMaterialValues(); - - } - - public void DoStuff() { - doStuff = true; - } - - public void NewTexture() { - newTexture = true; - } - - void SetMaterialValues() { - - //thisMaterial.SetFloat ("_BlurScale", _BlurScale); - //thisMaterial.SetVector ("_ImageSize", new Vector4( imageSizeX, imageSizeY, 0, 0 )); - - } - - void SetWeightEQDefault() { - NFHS.Blur0Weight = 0.3f; - NFHS.Blur1Weight = 0.35f; - NFHS.Blur2Weight = 0.5f; - NFHS.Blur3Weight = 0.8f; - NFHS.Blur4Weight = 1.0f; - NFHS.Blur5Weight = 0.95f; - NFHS.Blur6Weight = 0.8f; - doStuff = true; - } - - void SetWeightEQSmooth() { - NFHS.Blur0Weight = 0.1f; - NFHS.Blur1Weight = 0.15f; - NFHS.Blur2Weight = 0.25f; - NFHS.Blur3Weight = 0.6f; - NFHS.Blur4Weight = 0.9f; - NFHS.Blur5Weight = 1.0f; - NFHS.Blur6Weight = 1.0f; - doStuff = true; - } - - void SetWeightEQCrisp() { - NFHS.Blur0Weight = 1.0f; - NFHS.Blur1Weight = 0.9f; - NFHS.Blur2Weight = 0.6f; - NFHS.Blur3Weight = 0.4f; - NFHS.Blur4Weight = 0.25f; - NFHS.Blur5Weight = 0.15f; - NFHS.Blur6Weight = 0.1f; - doStuff = true; - } - - void SetWeightEQMids() { - NFHS.Blur0Weight = 0.15f; - NFHS.Blur1Weight = 0.5f; - NFHS.Blur2Weight = 0.85f; - NFHS.Blur3Weight = 1.0f; - NFHS.Blur4Weight = 0.85f; - NFHS.Blur5Weight = 0.5f; - NFHS.Blur6Weight = 0.15f; - doStuff = true; - } - - // Update is called once per frame - void Update () { - - if (newTexture) { - InitializeTextures(); - newTexture = false; - } - - if (doStuff) { - StartCoroutine( ProcessHeight () ); - doStuff = false; - } - - thisMaterial.SetFloat ("_Blur0Weight", NFHS.Blur0Weight); - thisMaterial.SetFloat ("_Blur1Weight", NFHS.Blur1Weight); - thisMaterial.SetFloat ("_Blur2Weight", NFHS.Blur2Weight); - thisMaterial.SetFloat ("_Blur3Weight", NFHS.Blur3Weight); - thisMaterial.SetFloat ("_Blur4Weight", NFHS.Blur4Weight); - thisMaterial.SetFloat ("_Blur5Weight", NFHS.Blur5Weight); - thisMaterial.SetFloat ("_Blur6Weight", NFHS.Blur6Weight); - - thisMaterial.SetFloat ( "_Slider", Slider); - - thisMaterial.SetFloat ("_Angularity", NFHS.Angularity); - thisMaterial.SetFloat ("_AngularIntensity", NFHS.AngularIntensity); - - //thisMaterial.SetFloat ("_LightRotation", NFHS.LightRotation); - //thisMaterial.SetFloat ("_ShapeRecognition", NFHS.ShapeRecognition); - - thisMaterial.SetFloat ("_FinalContrast", NFHS.FinalContrast); - - thisMaterial.SetVector ("_LightDir", mainLight.transform.forward); - - } - - void DoMyWindow ( int windowID ) { - - int offsetX = 10; - int offsetY = 30; - - //GUI.Label (new Rect (offsetX, offsetY, 250, 30), "Pre Contrast"); - //offsetY += 30; - //Blur0Contrast = GUI.HorizontalSlider( new Rect( offsetX, offsetY, 280, 10 ),Blur0Contrast,5.0f, 50.0f ); - - GUI.Label (new Rect (offsetX, offsetY, 250, 30), "Normal Reveal Slider" ); - Slider = GUI.HorizontalSlider( new Rect( offsetX, offsetY + 20, 280, 10 ),Slider,0.0f, 1.0f ); - - offsetY += 40; - - if( GuiHelper.Slider( new Rect( offsetX, offsetY, 280, 50 ), "Pre Contrast", NFHS.Blur0Contrast, NFHS.Blur0ContrastText, out NFHS.Blur0Contrast, out NFHS.Blur0ContrastText, 0.0f, 50.0f ) ) { - doStuff = true; - } - offsetY += 50; - - GUI.Label (new Rect (offsetX, offsetY, 250, 30), "Frequency Equalizer" ); - GUI.Label (new Rect (offsetX + 225, offsetY, 100, 30), "Presets" ); - if ( GUI.Button (new Rect (offsetX + 215, offsetY + 30, 60, 20), "Default") ) { - SetWeightEQDefault (); - } - if ( GUI.Button (new Rect (offsetX + 215, offsetY + 60, 60, 20), "Smooth") ) { - SetWeightEQSmooth (); - } - if ( GUI.Button (new Rect (offsetX + 215, offsetY + 90, 60, 20), "Crisp") ) { - SetWeightEQCrisp (); - } - if ( GUI.Button (new Rect (offsetX + 215, offsetY + 120, 60, 20), "Mids") ) { - SetWeightEQMids (); - } - offsetY += 30; - offsetX += 10; - NFHS.Blur0Weight = GUI.VerticalSlider( new Rect( offsetX + 180, offsetY, 10, 100 ),NFHS.Blur0Weight,1.0f, 0.0f ); - NFHS.Blur1Weight = GUI.VerticalSlider( new Rect( offsetX + 150, offsetY, 10, 100 ),NFHS.Blur1Weight,1.0f, 0.0f ); - NFHS.Blur2Weight = GUI.VerticalSlider( new Rect( offsetX + 120, offsetY, 10, 100 ),NFHS.Blur2Weight,1.0f, 0.0f ); - NFHS.Blur3Weight = GUI.VerticalSlider( new Rect( offsetX + 90, offsetY, 10, 100 ),NFHS.Blur3Weight,1.0f, 0.0f ); - NFHS.Blur4Weight = GUI.VerticalSlider( new Rect( offsetX + 60, offsetY, 10, 100 ),NFHS.Blur4Weight,1.0f, 0.0f ); - NFHS.Blur5Weight = GUI.VerticalSlider( new Rect( offsetX + 30, offsetY, 10, 100 ),NFHS.Blur5Weight,1.0f, 0.0f ); - NFHS.Blur6Weight = GUI.VerticalSlider( new Rect( offsetX + 0, offsetY, 10, 100 ),NFHS.Blur6Weight,1.0f, 0.0f ); - offsetX -= 10; - offsetY += 120; - - GUI.Label (new Rect (offsetX, offsetY, 250, 30), "Angular Intensity"); - offsetY += 25; - GuiHelper.Slider( new Rect( offsetX, offsetY, 280, 50 ), NFHS.AngularIntensity, NFHS.AngularIntensityText, out NFHS.AngularIntensity, out NFHS.AngularIntensityText, 0.0f, 1.0f ); - offsetY += 25; - GUI.Label (new Rect (offsetX, offsetY, 250, 30), "Angularity Amount"); - offsetY += 25; - GuiHelper.Slider (new Rect (offsetX, offsetY, 280, 50), NFHS.Angularity, NFHS.AngularityText, out NFHS.Angularity, out NFHS.AngularityText, 0.0f, 1.0f); - - offsetY += 30; - - if (MGS._DiffuseMapOriginal) { - GUI.enabled = true; - } else { - GUI.enabled = false; - NFHS.UseDiffuse = false; - } - - bool tempBool = NFHS.UseDiffuse; - NFHS.UseDiffuse = GUI.Toggle (new Rect (offsetX, offsetY, 280, 30), NFHS.UseDiffuse, " Shape from Diffuse (Uncheked from Height)"); - if( tempBool != NFHS.UseDiffuse ){ - doStuff = true; - } - offsetY += 30; - - GUI.enabled = true; - - GUI.Label (new Rect (offsetX, offsetY, 280, 30), " Shape Recognition, Rotation, Spread, Bias"); - offsetY += 30; - if ( GuiHelper.Slider( new Rect( offsetX, offsetY, 280, 50 ), NFHS.ShapeRecognition, NFHS.ShapeRecognitionText, out NFHS.ShapeRecognition, out NFHS.ShapeRecognitionText, 0.0f, 1.0f ) ) { - doStuff = true; - } - offsetY += 25; - if ( GuiHelper.Slider( new Rect( offsetX, offsetY, 280, 50 ), NFHS.LightRotation, NFHS.LightRotationText, out NFHS.LightRotation, out NFHS.LightRotationText, -3.14f, 3.14f ) ) { - doStuff = true; - } - offsetY += 25; - if ( GuiHelper.Slider( new Rect( offsetX, offsetY, 280, 50 ), NFHS.SlopeBlur, NFHS.SlopeBlurText, out NFHS.SlopeBlur, out NFHS.SlopeBlurText, 5, 100 ) ) { - doStuff = true; - } - offsetY += 25; - if ( GuiHelper.Slider( new Rect( offsetX, offsetY, 280, 50 ), NFHS.ShapeBias, NFHS.ShapeBiasText, out NFHS.ShapeBias, out NFHS.ShapeBiasText, 0.0f, 1.0f ) ) { - doStuff = true; - } - offsetY += 30; - - GuiHelper.Slider (new Rect (offsetX, offsetY, 280, 50), "Final Contrast", NFHS.FinalContrast, NFHS.FinalContrastText, out NFHS.FinalContrast, out NFHS.FinalContrastText, 0.0f, 10.0f); - offsetY += 50; - - if( GUI.Button (new Rect (offsetX + 150, offsetY, 130, 30), "Set as Normal Map" ) ){ - StartCoroutine( ProcessNormal () ); - } - - GUI.DragWindow(); - - } - - void OnGUI () { - - windowRect.width = 300; - windowRect.height = 630; - - windowRect = GUI.Window(16, windowRect, DoMyWindow, "Normal From Height"); - - } - - public void InitializeTextures() { - - testObject.GetComponent().sharedMaterial = thisMaterial; - - CleanupTextures (); - - if (!MGS._HDHeightMap) { - thisMaterial.SetTexture ("_HeightTex", MGS._HeightMap); - } else { - thisMaterial.SetTexture ("_HeightTex", MGS._HDHeightMap); - } - - imageSizeX = MGS._HeightMap.width; - imageSizeY = MGS._HeightMap.height; - - Debug.Log ( "Initializing Textures of size: " + imageSizeX.ToString() + "x" + imageSizeY.ToString() ); - - _TempBlurMap = new RenderTexture (imageSizeX, imageSizeY, 0, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear); - _TempBlurMap.wrapMode = TextureWrapMode.Repeat; - _HeightBlurMap = new RenderTexture (imageSizeX, imageSizeY, 0, RenderTextureFormat.RHalf, RenderTextureReadWrite.Linear); - _HeightBlurMap.wrapMode = TextureWrapMode.Repeat; - _BlurMap0 = new RenderTexture (imageSizeX, imageSizeY, 0, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear); - _BlurMap0.wrapMode = TextureWrapMode.Repeat; - _BlurMap1 = new RenderTexture (imageSizeX, imageSizeY, 0, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear); - _BlurMap1.wrapMode = TextureWrapMode.Repeat; - _BlurMap2 = new RenderTexture (imageSizeX, imageSizeY, 0, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear); - _BlurMap2.wrapMode = TextureWrapMode.Repeat; - _BlurMap3 = new RenderTexture (imageSizeX, imageSizeY, 0, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear); - _BlurMap3.wrapMode = TextureWrapMode.Repeat; - _BlurMap4 = new RenderTexture (imageSizeX, imageSizeY, 0, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear); - _BlurMap4.wrapMode = TextureWrapMode.Repeat; - _BlurMap5 = new RenderTexture (imageSizeX, imageSizeY, 0, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear); - _BlurMap5.wrapMode = TextureWrapMode.Repeat; - _BlurMap6 = new RenderTexture (imageSizeX, imageSizeY, 0, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear); - _BlurMap6.wrapMode = TextureWrapMode.Repeat; - - SetMaterialValues (); - - } - - public void Close(){ - CleanupTextures (); - this.gameObject.SetActive (false); - } - - void CleanupTexture( RenderTexture _Texture ) { - - if (_Texture != null) { - _Texture.Release(); - _Texture = null; - } - - } - - void CleanupTextures() { - - Debug.Log ("Cleaning Up Textures"); - - CleanupTexture (_TempBlurMap); - CleanupTexture (_HeightBlurMap); - CleanupTexture( _BlurMap0 ); - CleanupTexture( _BlurMap1 ); - CleanupTexture( _BlurMap2 ); - CleanupTexture( _BlurMap3 ); - CleanupTexture( _BlurMap4 ); - CleanupTexture( _BlurMap5 ); - CleanupTexture( _BlurMap6 ); - CleanupTexture (_TempNormalMap); - - } - - public IEnumerator ProcessNormal() { - - busy = true; - - Debug.Log ("Processing Normal"); - - blitMaterial.SetVector ("_ImageSize", new Vector4( imageSizeX, imageSizeY, 0, 0 )); - - blitMaterial.SetFloat ("_Blur0Weight", NFHS.Blur0Weight); - blitMaterial.SetFloat ("_Blur1Weight", NFHS.Blur1Weight); - blitMaterial.SetFloat ("_Blur2Weight", NFHS.Blur2Weight); - blitMaterial.SetFloat ("_Blur3Weight", NFHS.Blur3Weight); - blitMaterial.SetFloat ("_Blur4Weight", NFHS.Blur4Weight); - blitMaterial.SetFloat ("_Blur5Weight", NFHS.Blur5Weight); - blitMaterial.SetFloat ("_Blur6Weight", NFHS.Blur6Weight); - blitMaterial.SetFloat ("_FinalContrast", NFHS.FinalContrast); - - blitMaterial.SetTexture ("_HeightBlurTex", _HeightBlurMap); - - blitMaterial.SetTexture ("_MainTex", _BlurMap0); - blitMaterial.SetTexture ("_BlurTex0", _BlurMap0); - blitMaterial.SetTexture ("_BlurTex1", _BlurMap1); - blitMaterial.SetTexture ("_BlurTex2", _BlurMap2); - blitMaterial.SetTexture ("_BlurTex3", _BlurMap3); - blitMaterial.SetTexture ("_BlurTex4", _BlurMap4); - blitMaterial.SetTexture ("_BlurTex5", _BlurMap5); - blitMaterial.SetTexture ("_BlurTex6", _BlurMap6); - - blitMaterial.SetFloat ("_Angularity", NFHS.Angularity); - blitMaterial.SetFloat ("_AngularIntensity", NFHS.AngularIntensity); - - - CleanupTexture (_TempNormalMap); - _TempNormalMap = new RenderTexture (imageSizeX, imageSizeY, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear); - _TempNormalMap.wrapMode = TextureWrapMode.Repeat; - Graphics.Blit(_BlurMap0, _TempNormalMap, blitMaterial, 4); - - if (MGS._NormalMap != null) { - Destroy (MGS._NormalMap); - } - - RenderTexture.active = _TempNormalMap; - MGS._NormalMap = new Texture2D( _TempNormalMap.width, _TempNormalMap.height, TextureFormat.ARGB32, true, true ); - MGS._NormalMap.ReadPixels(new Rect(0, 0, _TempNormalMap.width, _TempNormalMap.height), 0, 0); - MGS._NormalMap.Apply(); - - yield return new WaitForSeconds(0.1f); - - CleanupTexture ( _TempNormalMap ); - - busy = false; - - } - - public IEnumerator ProcessHeight () { - - busy = true; - - Debug.Log ("Processing Height"); - - blitMaterial.SetVector ("_ImageSize", new Vector4( imageSizeX, imageSizeY, 0, 0 )); - - // Blur the height map for normal slope - blitMaterial.SetFloat ("_BlurSpread", 1.0f); - blitMaterial.SetInt ("_BlurSamples", NFHS.SlopeBlur); - blitMaterial.SetVector ("_BlurDirection", new Vector4(1,0,0,0) ); - blitMaterial.SetFloat ("_BlurContrast", 1.0f); - - if (MGS._DiffuseMapOriginal && NFHS.UseDiffuse) { - blitMaterial.SetInt ("_Desaturate", 1); - Graphics.Blit (MGS._DiffuseMapOriginal, _TempBlurMap, blitMaterial, 1); - blitMaterial.SetTexture ("_LightTex", MGS._DiffuseMapOriginal); - } else { - if (MGS._HDHeightMap == null) { - blitMaterial.SetInt ("_Desaturate", 0); - Graphics.Blit (MGS._HeightMap, _TempBlurMap, blitMaterial, 1); - blitMaterial.SetTexture ("_LightTex", MGS._HeightMap); - } else { - blitMaterial.SetInt ("_Desaturate", 0); - Graphics.Blit (MGS._HDHeightMap, _TempBlurMap, blitMaterial, 1); - blitMaterial.SetTexture ("_LightTex", MGS._HDHeightMap); - } - } - - blitMaterial.SetInt ("_Desaturate", 0); - - blitMaterial.SetVector ("_BlurDirection", new Vector4(0,1,0,0) ); - Graphics.Blit(_TempBlurMap, _HeightBlurMap, blitMaterial, 1); - - blitMaterial.SetFloat ("_BlurSpread", 3.0f); - blitMaterial.SetVector ("_BlurDirection", new Vector4(1,0,0,0) ); - Graphics.Blit (_HeightBlurMap, _TempBlurMap, blitMaterial, 1); - - blitMaterial.SetVector ("_BlurDirection", new Vector4(0,1,0,0) ); - Graphics.Blit(_TempBlurMap, _HeightBlurMap, blitMaterial, 1); - - blitMaterial.SetTexture ("_LightBlurTex", _HeightBlurMap); - - // Make normal from height - blitMaterial.SetFloat ("_LightRotation", NFHS.LightRotation); - blitMaterial.SetFloat ("_ShapeRecognition", NFHS.ShapeRecognition); - blitMaterial.SetFloat ("_ShapeBias", NFHS.ShapeBias); - blitMaterial.SetTexture ("_DiffuseTex", MGS._DiffuseMapOriginal); - - blitMaterial.SetFloat ("_BlurContrast", NFHS.Blur0Contrast); - - if ( MGS._HDHeightMap == null) { - Graphics.Blit (MGS._HeightMap, _BlurMap0, blitMaterial, 3); - } else { - Graphics.Blit (MGS._HDHeightMap, _BlurMap0, blitMaterial, 3); - } - - float extraSpread = ( (float)(_BlurMap0.width + _BlurMap0.height) * 0.5f ) / 1024.0f; - float spread = 1.0f; - - blitMaterial.SetFloat ("_BlurContrast", 1.0f); - blitMaterial.SetInt ("_Desaturate", 0); - - // Blur the image 1 - blitMaterial.SetInt ("_BlurSamples", 4); - blitMaterial.SetFloat ("_BlurSpread", spread); - blitMaterial.SetVector ("_BlurDirection", new Vector4(1,0,0,0) ); - Graphics.Blit(_BlurMap0, _TempBlurMap, blitMaterial, 1); - blitMaterial.SetVector ("_BlurDirection", new Vector4(0,1,0,0) ); - Graphics.Blit(_TempBlurMap, _BlurMap1, blitMaterial, 1); - - spread += extraSpread; - - // Blur the image 2 - blitMaterial.SetFloat ("_BlurSpread", spread); - blitMaterial.SetVector ("_BlurDirection", new Vector4(1,0,0,0) ); - Graphics.Blit(_BlurMap1, _TempBlurMap, blitMaterial, 1); - blitMaterial.SetVector ("_BlurDirection", new Vector4(0,1,0,0) ); - Graphics.Blit(_TempBlurMap, _BlurMap2, blitMaterial, 1); - - spread += 2 * extraSpread; - - // Blur the image 3 - blitMaterial.SetFloat ("_BlurSpread", spread); - blitMaterial.SetVector ("_BlurDirection", new Vector4(1,0,0,0) ); - Graphics.Blit(_BlurMap2, _TempBlurMap, blitMaterial, 1); - blitMaterial.SetVector ("_BlurDirection", new Vector4(0,1,0,0) ); - Graphics.Blit(_TempBlurMap, _BlurMap3, blitMaterial, 1); - - spread += 4 * extraSpread; - - // Blur the image 4 - blitMaterial.SetFloat ("_BlurSpread", spread); - blitMaterial.SetVector ("_BlurDirection", new Vector4(1,0,0,0) ); - Graphics.Blit(_BlurMap3, _TempBlurMap, blitMaterial, 1); - blitMaterial.SetVector ("_BlurDirection", new Vector4(0,1,0,0) ); - Graphics.Blit(_TempBlurMap, _BlurMap4, blitMaterial, 1); - - spread += 8 * extraSpread; - - // Blur the image 5 - blitMaterial.SetFloat ("_BlurSpread", spread); - blitMaterial.SetVector ("_BlurDirection", new Vector4(1,0,0,0) ); - Graphics.Blit(_BlurMap4, _TempBlurMap, blitMaterial, 1); - blitMaterial.SetVector ("_BlurDirection", new Vector4(0,1,0,0) ); - Graphics.Blit(_TempBlurMap, _BlurMap5, blitMaterial, 1); - - spread += 16 * extraSpread; - - // Blur the image 6 - blitMaterial.SetFloat ("_BlurSpread", spread); - blitMaterial.SetVector ("_BlurDirection", new Vector4(1,0,0,0) ); - Graphics.Blit(_BlurMap5, _TempBlurMap, blitMaterial, 1); - blitMaterial.SetVector ("_BlurDirection", new Vector4(0,1,0,0) ); - Graphics.Blit(_TempBlurMap, _BlurMap6, blitMaterial, 1); - - //if( _HDHeightMap != null) { - // thisMaterial.SetTexture ("_MainTex", _HDHeightMap); - //} else { - // thisMaterial.SetTexture ("_MainTex", MGS._HeightMap); - //} - - - thisMaterial.SetTexture ("_BlurTex0", _BlurMap0); - thisMaterial.SetTexture ("_BlurTex1", _BlurMap1); - thisMaterial.SetTexture ("_BlurTex2", _BlurMap2); - thisMaterial.SetTexture ("_BlurTex3", _BlurMap3); - thisMaterial.SetTexture ("_BlurTex4", _BlurMap4); - thisMaterial.SetTexture ("_BlurTex5", _BlurMap5); - thisMaterial.SetTexture ("_BlurTex6", _BlurMap6); - - yield return new WaitForSeconds(0.01f); - - busy = false; - - } -} +using System.Collections; +using UnityEngine; + +#endregion + +// ReSharper disable Unity.PreferAddressByIdToGraphicsParams + +public class NormalFromHeightGui : MonoBehaviour +{ + private static readonly int Blur0Weight = Shader.PropertyToID("_Blur0Weight"); + private static readonly int Blur1Weight = Shader.PropertyToID("_Blur1Weight"); + private static readonly int Blur2Weight = Shader.PropertyToID("_Blur2Weight"); + private static readonly int Blur3Weight = Shader.PropertyToID("_Blur3Weight"); + private static readonly int Blur4Weight = Shader.PropertyToID("_Blur4Weight"); + private static readonly int Blur5Weight = Shader.PropertyToID("_Blur5Weight"); + private static readonly int Blur6Weight = Shader.PropertyToID("_Blur6Weight"); + private static readonly int Slider = Shader.PropertyToID("_Slider"); + private static readonly int Angularity = Shader.PropertyToID("_Angularity"); + private static readonly int AngularIntensity = Shader.PropertyToID("_AngularIntensity"); + private static readonly int FinalContrast = Shader.PropertyToID("_FinalContrast"); + private static readonly int LightDir = Shader.PropertyToID("_LightDir"); + private static readonly int HeightTex = Shader.PropertyToID("_HeightTex"); + private Material _blitMaterial; + private RenderTexture _blurMap0; + private RenderTexture _blurMap1; + private RenderTexture _blurMap2; + private RenderTexture _blurMap3; + private RenderTexture _blurMap4; + private RenderTexture _blurMap5; + private RenderTexture _blurMap6; + private bool _doStuff; + private int _imageSizeX = 1024; + private int _imageSizeY = 1024; + + private MainGui _mgs; + private bool _newTexture; + + private NormalFromHeightSettings _settings; + private bool _settingsInitialized; + + private float _slider = 0.5f; + + private RenderTexture _tempBlurMap; + private RenderTexture _tempNormalMap; + + private Rect _windowRect = new Rect(30, 300, 300, 450); + + [HideInInspector] public bool Busy; + + [HideInInspector] public RenderTexture HeightBlurMap; + + public Light MainLight; + + public GameObject TestObject; + + public Material ThisMaterial; + + public void GetValues(ProjectObject projectObject) + { + InitializeSettings(); + projectObject.NormalFromHeightSettings = _settings; + } + + public void SetValues(ProjectObject projectObject) + { + InitializeSettings(); + if (projectObject.NormalFromHeightSettings != null) + { + _settings = projectObject.NormalFromHeightSettings; + } + else + { + _settingsInitialized = false; + InitializeSettings(); + } + + _doStuff = true; + } + + private void InitializeSettings() + { + if (_settingsInitialized) return; + Debug.Log("Initializing Normal From Height Settings"); + _settings = new NormalFromHeightSettings(); + _settingsInitialized = true; + } + + // Use this for initialization + private void Start() + { + _mgs = MainGui.Instance; + + TestObject.GetComponent().sharedMaterial = ThisMaterial; + + _blitMaterial = new Material(Shader.Find("Hidden/Blit_Shader")); + + InitializeSettings(); + } + + public void DoStuff() + { + _doStuff = true; + } + + public void NewTexture() + { + _newTexture = true; + } + + private void SetWeightEqDefault() + { + _settings.Blur0Weight = 0.3f; + _settings.Blur1Weight = 0.35f; + _settings.Blur2Weight = 0.5f; + _settings.Blur3Weight = 0.8f; + _settings.Blur4Weight = 1.0f; + _settings.Blur5Weight = 0.95f; + _settings.Blur6Weight = 0.8f; + _doStuff = true; + } + + private void SetWeightEqSmooth() + { + _settings.Blur0Weight = 0.1f; + _settings.Blur1Weight = 0.15f; + _settings.Blur2Weight = 0.25f; + _settings.Blur3Weight = 0.6f; + _settings.Blur4Weight = 0.9f; + _settings.Blur5Weight = 1.0f; + _settings.Blur6Weight = 1.0f; + _doStuff = true; + } + + private void SetWeightEqCrisp() + { + _settings.Blur0Weight = 1.0f; + _settings.Blur1Weight = 0.9f; + _settings.Blur2Weight = 0.6f; + _settings.Blur3Weight = 0.4f; + _settings.Blur4Weight = 0.25f; + _settings.Blur5Weight = 0.15f; + _settings.Blur6Weight = 0.1f; + _doStuff = true; + } + + // ReSharper disable once IdentifierTypo + private void SetWeightEqMids() + { + _settings.Blur0Weight = 0.15f; + _settings.Blur1Weight = 0.5f; + _settings.Blur2Weight = 0.85f; + _settings.Blur3Weight = 1.0f; + _settings.Blur4Weight = 0.85f; + _settings.Blur5Weight = 0.5f; + _settings.Blur6Weight = 0.15f; + _doStuff = true; + } + + private void Update() + { + if (_newTexture) + { + InitializeTextures(); + _newTexture = false; + } + + if (_doStuff) + { + StartCoroutine(ProcessHeight()); + _doStuff = false; + } + + ThisMaterial.SetFloat(Blur0Weight, _settings.Blur0Weight); + ThisMaterial.SetFloat(Blur1Weight, _settings.Blur1Weight); + ThisMaterial.SetFloat(Blur2Weight, _settings.Blur2Weight); + ThisMaterial.SetFloat(Blur3Weight, _settings.Blur3Weight); + ThisMaterial.SetFloat(Blur4Weight, _settings.Blur4Weight); + ThisMaterial.SetFloat(Blur5Weight, _settings.Blur5Weight); + ThisMaterial.SetFloat(Blur6Weight, _settings.Blur6Weight); + + ThisMaterial.SetFloat(Slider, _slider); + + ThisMaterial.SetFloat(Angularity, _settings.Angularity); + ThisMaterial.SetFloat(AngularIntensity, _settings.AngularIntensity); + + ThisMaterial.SetFloat(FinalContrast, _settings.FinalContrast); + + ThisMaterial.SetVector(LightDir, MainLight.transform.forward); + } + + private void DoMyWindow(int windowId) + { + var offsetX = 10; + var offsetY = 30; + + GUI.Label(new Rect(offsetX, offsetY, 250, 30), "Normal Reveal Slider"); + _slider = GUI.HorizontalSlider(new Rect(offsetX, offsetY + 20, 280, 10), _slider, 0.0f, 1.0f); + + offsetY += 40; + + if (GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Pre Contrast", _settings.Blur0Contrast, + _settings.Blur0ContrastText, out _settings.Blur0Contrast, out _settings.Blur0ContrastText, 0.0f, 50.0f)) + _doStuff = true; + offsetY += 50; + + GUI.Label(new Rect(offsetX, offsetY, 250, 30), "Frequency Equalizer"); + GUI.Label(new Rect(offsetX + 225, offsetY, 100, 30), "Presets"); + if (GUI.Button(new Rect(offsetX + 215, offsetY + 30, 60, 20), "Default")) SetWeightEqDefault(); + if (GUI.Button(new Rect(offsetX + 215, offsetY + 60, 60, 20), "Smooth")) SetWeightEqSmooth(); + if (GUI.Button(new Rect(offsetX + 215, offsetY + 90, 60, 20), "Crisp")) SetWeightEqCrisp(); + if (GUI.Button(new Rect(offsetX + 215, offsetY + 120, 60, 20), "Mids")) SetWeightEqMids(); + offsetY += 30; + offsetX += 10; + _settings.Blur0Weight = + GUI.VerticalSlider(new Rect(offsetX + 180, offsetY, 10, 100), _settings.Blur0Weight, 1.0f, 0.0f); + _settings.Blur1Weight = + GUI.VerticalSlider(new Rect(offsetX + 150, offsetY, 10, 100), _settings.Blur1Weight, 1.0f, 0.0f); + _settings.Blur2Weight = + GUI.VerticalSlider(new Rect(offsetX + 120, offsetY, 10, 100), _settings.Blur2Weight, 1.0f, 0.0f); + _settings.Blur3Weight = + GUI.VerticalSlider(new Rect(offsetX + 90, offsetY, 10, 100), _settings.Blur3Weight, 1.0f, 0.0f); + _settings.Blur4Weight = + GUI.VerticalSlider(new Rect(offsetX + 60, offsetY, 10, 100), _settings.Blur4Weight, 1.0f, 0.0f); + _settings.Blur5Weight = + GUI.VerticalSlider(new Rect(offsetX + 30, offsetY, 10, 100), _settings.Blur5Weight, 1.0f, 0.0f); + _settings.Blur6Weight = + GUI.VerticalSlider(new Rect(offsetX + 0, offsetY, 10, 100), _settings.Blur6Weight, 1.0f, 0.0f); + offsetX -= 10; + offsetY += 120; + + GUI.Label(new Rect(offsetX, offsetY, 250, 30), "Angular Intensity"); + offsetY += 25; + GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), _settings.AngularIntensity, + _settings.AngularIntensityText, + out _settings.AngularIntensity, out _settings.AngularIntensityText, 0.0f, 1.0f); + offsetY += 25; + + GUI.Label(new Rect(offsetX, offsetY, 250, 30), "Angularity Amount"); + offsetY += 25; + GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), _settings.Angularity, _settings.AngularityText, + out _settings.Angularity, + out _settings.AngularityText, 0.0f, 1.0f); + + offsetY += 30; + + if (_mgs.DiffuseMapOriginal) + { + GUI.enabled = true; + } + else + { + GUI.enabled = false; + _settings.UseDiffuse = false; + } + + var tempBool = _settings.UseDiffuse; + _settings.UseDiffuse = GUI.Toggle(new Rect(offsetX, offsetY, 280, 30), _settings.UseDiffuse, + " Shape from Diffuse (Unchecked from Height)"); + if (tempBool != _settings.UseDiffuse) _doStuff = true; + offsetY += 30; + + GUI.enabled = true; + + GUI.Label(new Rect(offsetX, offsetY, 280, 30), " Shape Recognition, Rotation, Spread, Bias"); + offsetY += 30; + if (GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), _settings.ShapeRecognition, + _settings.ShapeRecognitionText, + out _settings.ShapeRecognition, out _settings.ShapeRecognitionText, 0.0f, 1.0f)) _doStuff = true; + offsetY += 25; + if (GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), _settings.LightRotation, _settings.LightRotationText, + out _settings.LightRotation, out _settings.LightRotationText, -3.14f, 3.14f)) _doStuff = true; + offsetY += 25; + if (GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), _settings.SlopeBlur, _settings.SlopeBlurText, + out _settings.SlopeBlur, out _settings.SlopeBlurText, 5, 100)) _doStuff = true; + offsetY += 25; + if (GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), _settings.ShapeBias, _settings.ShapeBiasText, + out _settings.ShapeBias, out _settings.ShapeBiasText, 0.0f, 1.0f)) _doStuff = true; + offsetY += 30; + + GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Final Contrast", _settings.FinalContrast, + _settings.FinalContrastText, out _settings.FinalContrast, out _settings.FinalContrastText, 0.0f, 10.0f); + offsetY += 50; + + if (GUI.Button(new Rect(offsetX + 10, offsetY, 130, 30), "Reset to Defaults")) + { + //_settingsInitialized = false; + SetValues(new ProjectObject()); + //StartCoroutine(ProcessDiffuse()); + } + + if (GUI.Button(new Rect(offsetX + 150, offsetY, 130, 30), "Set as Normal Map")) StartCoroutine(ProcessNormal()); + + GUI.DragWindow(); + } + + private void OnGUI() + { + _windowRect.width = 300; + _windowRect.height = 630; + + _windowRect = GUI.Window(16, _windowRect, DoMyWindow, "Normal From Height"); + } + + public void InitializeTextures() + { + TestObject.GetComponent().sharedMaterial = ThisMaterial; + + CleanupTextures(); + + if (!_mgs.HdHeightMap) + ThisMaterial.SetTexture(HeightTex, _mgs.HeightMap); + else + ThisMaterial.SetTexture(HeightTex, _mgs.HdHeightMap); + + _imageSizeX = _mgs.HeightMap.width; + _imageSizeY = _mgs.HeightMap.height; + + Debug.Log("Initializing Textures of size: " + _imageSizeX + "x" + _imageSizeY); + + _tempBlurMap = new RenderTexture(_imageSizeX, _imageSizeY, 0, RenderTextureFormat.ARGBHalf, + RenderTextureReadWrite.Linear) {wrapMode = TextureWrapMode.Repeat}; + HeightBlurMap = new RenderTexture(_imageSizeX, _imageSizeY, 0, RenderTextureFormat.RHalf, + RenderTextureReadWrite.Linear) {wrapMode = TextureWrapMode.Repeat}; + _blurMap0 = new RenderTexture(_imageSizeX, _imageSizeY, 0, RenderTextureFormat.ARGBHalf, + RenderTextureReadWrite.Linear) {wrapMode = TextureWrapMode.Repeat}; + _blurMap1 = new RenderTexture(_imageSizeX, _imageSizeY, 0, RenderTextureFormat.ARGBHalf, + RenderTextureReadWrite.Linear) {wrapMode = TextureWrapMode.Repeat}; + _blurMap2 = new RenderTexture(_imageSizeX, _imageSizeY, 0, RenderTextureFormat.ARGBHalf, + RenderTextureReadWrite.Linear) {wrapMode = TextureWrapMode.Repeat}; + _blurMap3 = new RenderTexture(_imageSizeX, _imageSizeY, 0, RenderTextureFormat.ARGBHalf, + RenderTextureReadWrite.Linear) {wrapMode = TextureWrapMode.Repeat}; + _blurMap4 = new RenderTexture(_imageSizeX, _imageSizeY, 0, RenderTextureFormat.ARGBHalf, + RenderTextureReadWrite.Linear) {wrapMode = TextureWrapMode.Repeat}; + _blurMap5 = new RenderTexture(_imageSizeX, _imageSizeY, 0, RenderTextureFormat.ARGBHalf, + RenderTextureReadWrite.Linear) {wrapMode = TextureWrapMode.Repeat}; + _blurMap6 = new RenderTexture(_imageSizeX, _imageSizeY, 0, RenderTextureFormat.ARGBHalf, + RenderTextureReadWrite.Linear) {wrapMode = TextureWrapMode.Repeat}; + } + + public void Close() + { + CleanupTextures(); + gameObject.SetActive(false); + } + + private static void CleanupTexture(RenderTexture texture) + { + if (!texture) return; + texture.Release(); + // ReSharper disable once RedundantAssignment + texture = null; + } + + private void CleanupTextures() + { + CleanupTexture(_tempBlurMap); + CleanupTexture(HeightBlurMap); + CleanupTexture(_blurMap0); + CleanupTexture(_blurMap1); + CleanupTexture(_blurMap2); + CleanupTexture(_blurMap3); + CleanupTexture(_blurMap4); + CleanupTexture(_blurMap5); + CleanupTexture(_blurMap6); + CleanupTexture(_tempNormalMap); + } + + public void StartProcessNormal() + { + StartCoroutine(ProcessNormal()); + } + + public IEnumerator ProcessNormal() + { + Busy = true; + + Debug.Log("Processing Normal"); + + _blitMaterial.SetVector("_ImageSize", new Vector4(_imageSizeX, _imageSizeY, 0, 0)); + + _blitMaterial.SetFloat("_Blur0Weight", _settings.Blur0Weight); + _blitMaterial.SetFloat("_Blur1Weight", _settings.Blur1Weight); + _blitMaterial.SetFloat("_Blur2Weight", _settings.Blur2Weight); + _blitMaterial.SetFloat("_Blur3Weight", _settings.Blur3Weight); + _blitMaterial.SetFloat("_Blur4Weight", _settings.Blur4Weight); + _blitMaterial.SetFloat("_Blur5Weight", _settings.Blur5Weight); + _blitMaterial.SetFloat("_Blur6Weight", _settings.Blur6Weight); + _blitMaterial.SetFloat("_FinalContrast", _settings.FinalContrast); + + _blitMaterial.SetTexture("_HeightBlurTex", HeightBlurMap); + + _blitMaterial.SetTexture("_MainTex", _blurMap0); + _blitMaterial.SetTexture("_BlurTex0", _blurMap0); + _blitMaterial.SetTexture("_BlurTex1", _blurMap1); + _blitMaterial.SetTexture("_BlurTex2", _blurMap2); + _blitMaterial.SetTexture("_BlurTex3", _blurMap3); + _blitMaterial.SetTexture("_BlurTex4", _blurMap4); + _blitMaterial.SetTexture("_BlurTex5", _blurMap5); + _blitMaterial.SetTexture("_BlurTex6", _blurMap6); + + _blitMaterial.SetFloat("_Angularity", _settings.Angularity); + _blitMaterial.SetFloat("_AngularIntensity", _settings.AngularIntensity); + + + CleanupTexture(_tempNormalMap); + _tempNormalMap = new RenderTexture(_imageSizeX, _imageSizeY, 0, RenderTextureFormat.ARGB32, + RenderTextureReadWrite.Linear) {wrapMode = TextureWrapMode.Repeat}; + Graphics.Blit(_blurMap0, _tempNormalMap, _blitMaterial, 4); + + if (_mgs.NormalMap) Destroy(_mgs.NormalMap); + + RenderTexture.active = _tempNormalMap; + _mgs.NormalMap = new Texture2D(_tempNormalMap.width, _tempNormalMap.height, TextureFormat.ARGB32, true, true); + _mgs.NormalMap.ReadPixels(new Rect(0, 0, _tempNormalMap.width, _tempNormalMap.height), 0, 0); + _mgs.NormalMap.Apply(); + + yield return new WaitForSeconds(0.1f); + + CleanupTexture(_tempNormalMap); + + Busy = false; + } + + public IEnumerator ProcessHeight() + { + Busy = true; + + Debug.Log("Processing Height"); + + _blitMaterial.SetVector("_ImageSize", new Vector4(_imageSizeX, _imageSizeY, 0, 0)); + + // Blur the height map for normal slope + _blitMaterial.SetFloat("_BlurSpread", 1.0f); + _blitMaterial.SetInt("_BlurSamples", _settings.SlopeBlur); + _blitMaterial.SetVector("_BlurDirection", new Vector4(1, 0, 0, 0)); + _blitMaterial.SetFloat("_BlurContrast", 1.0f); + + if (_mgs.DiffuseMapOriginal && _settings.UseDiffuse) + { + _blitMaterial.SetInt("_Desaturate", 1); + Graphics.Blit(_mgs.DiffuseMapOriginal, _tempBlurMap, _blitMaterial, 1); + _blitMaterial.SetTexture("_LightTex", _mgs.DiffuseMapOriginal); + } + else + { + if (_mgs.HdHeightMap == null) + { + _blitMaterial.SetInt("_Desaturate", 0); + Graphics.Blit(_mgs.HeightMap, _tempBlurMap, _blitMaterial, 1); + _blitMaterial.SetTexture("_LightTex", _mgs.HeightMap); + } + else + { + _blitMaterial.SetInt("_Desaturate", 0); + Graphics.Blit(_mgs.HdHeightMap, _tempBlurMap, _blitMaterial, 1); + _blitMaterial.SetTexture("_LightTex", _mgs.HdHeightMap); + } + } + + _blitMaterial.SetInt("_Desaturate", 0); + + _blitMaterial.SetVector("_BlurDirection", new Vector4(0, 1, 0, 0)); + Graphics.Blit(_tempBlurMap, HeightBlurMap, _blitMaterial, 1); + + _blitMaterial.SetFloat("_BlurSpread", 3.0f); + _blitMaterial.SetVector("_BlurDirection", new Vector4(1, 0, 0, 0)); + Graphics.Blit(HeightBlurMap, _tempBlurMap, _blitMaterial, 1); + + _blitMaterial.SetVector("_BlurDirection", new Vector4(0, 1, 0, 0)); + Graphics.Blit(_tempBlurMap, HeightBlurMap, _blitMaterial, 1); + + _blitMaterial.SetTexture("_LightBlurTex", HeightBlurMap); + + // Make normal from height + _blitMaterial.SetFloat("_LightRotation", _settings.LightRotation); + _blitMaterial.SetFloat("_ShapeRecognition", _settings.ShapeRecognition); + _blitMaterial.SetFloat("_ShapeBias", _settings.ShapeBias); + _blitMaterial.SetTexture("_DiffuseTex", _mgs.DiffuseMapOriginal); + + _blitMaterial.SetFloat("_BlurContrast", _settings.Blur0Contrast); + + if (_mgs.HdHeightMap == null) + Graphics.Blit(_mgs.HeightMap, _blurMap0, _blitMaterial, 3); + else + Graphics.Blit(_mgs.HdHeightMap, _blurMap0, _blitMaterial, 3); + + var extraSpread = (_blurMap0.width + _blurMap0.height) * 0.5f / 1024.0f; + var spread = 1.0f; + + _blitMaterial.SetFloat("_BlurContrast", 1.0f); + _blitMaterial.SetInt("_Desaturate", 0); + + // Blur the image 1 + _blitMaterial.SetInt("_BlurSamples", 4); + _blitMaterial.SetFloat("_BlurSpread", spread); + _blitMaterial.SetVector("_BlurDirection", new Vector4(1, 0, 0, 0)); + Graphics.Blit(_blurMap0, _tempBlurMap, _blitMaterial, 1); + _blitMaterial.SetVector("_BlurDirection", new Vector4(0, 1, 0, 0)); + Graphics.Blit(_tempBlurMap, _blurMap1, _blitMaterial, 1); + + spread += extraSpread; + + // Blur the image 2 + _blitMaterial.SetFloat("_BlurSpread", spread); + _blitMaterial.SetVector("_BlurDirection", new Vector4(1, 0, 0, 0)); + Graphics.Blit(_blurMap1, _tempBlurMap, _blitMaterial, 1); + _blitMaterial.SetVector("_BlurDirection", new Vector4(0, 1, 0, 0)); + Graphics.Blit(_tempBlurMap, _blurMap2, _blitMaterial, 1); + + spread += 2 * extraSpread; + + // Blur the image 3 + _blitMaterial.SetFloat("_BlurSpread", spread); + _blitMaterial.SetVector("_BlurDirection", new Vector4(1, 0, 0, 0)); + Graphics.Blit(_blurMap2, _tempBlurMap, _blitMaterial, 1); + _blitMaterial.SetVector("_BlurDirection", new Vector4(0, 1, 0, 0)); + Graphics.Blit(_tempBlurMap, _blurMap3, _blitMaterial, 1); + + spread += 4 * extraSpread; + + // Blur the image 4 + _blitMaterial.SetFloat("_BlurSpread", spread); + _blitMaterial.SetVector("_BlurDirection", new Vector4(1, 0, 0, 0)); + Graphics.Blit(_blurMap3, _tempBlurMap, _blitMaterial, 1); + _blitMaterial.SetVector("_BlurDirection", new Vector4(0, 1, 0, 0)); + Graphics.Blit(_tempBlurMap, _blurMap4, _blitMaterial, 1); + + spread += 8 * extraSpread; + + // Blur the image 5 + _blitMaterial.SetFloat("_BlurSpread", spread); + _blitMaterial.SetVector("_BlurDirection", new Vector4(1, 0, 0, 0)); + Graphics.Blit(_blurMap4, _tempBlurMap, _blitMaterial, 1); + _blitMaterial.SetVector("_BlurDirection", new Vector4(0, 1, 0, 0)); + Graphics.Blit(_tempBlurMap, _blurMap5, _blitMaterial, 1); + + spread += 16 * extraSpread; + + // Blur the image 6 + _blitMaterial.SetFloat("_BlurSpread", spread); + _blitMaterial.SetVector("_BlurDirection", new Vector4(1, 0, 0, 0)); + Graphics.Blit(_blurMap5, _tempBlurMap, _blitMaterial, 1); + _blitMaterial.SetVector("_BlurDirection", new Vector4(0, 1, 0, 0)); + Graphics.Blit(_tempBlurMap, _blurMap6, _blitMaterial, 1); + + //if( _HDHeightMap != null) { + // thisMaterial.SetTexture ("_MainTex", _HDHeightMap); + //} else { + // thisMaterial.SetTexture ("_MainTex", MGS._HeightMap); + //} + + + ThisMaterial.SetTexture("_BlurTex0", _blurMap0); + ThisMaterial.SetTexture("_BlurTex1", _blurMap1); + ThisMaterial.SetTexture("_BlurTex2", _blurMap2); + ThisMaterial.SetTexture("_BlurTex3", _blurMap3); + ThisMaterial.SetTexture("_BlurTex4", _blurMap4); + ThisMaterial.SetTexture("_BlurTex5", _blurMap5); + ThisMaterial.SetTexture("_BlurTex6", _blurMap6); + + yield return new WaitForSeconds(0.01f); + + Busy = false; + } +} \ No newline at end of file diff --git a/Assets/Scripts/NormalFromHeightSettings.cs b/Assets/Scripts/NormalFromHeightSettings.cs new file mode 100644 index 00000000..75067016 --- /dev/null +++ b/Assets/Scripts/NormalFromHeightSettings.cs @@ -0,0 +1,93 @@ +#region + +using System.ComponentModel; + +#endregion + +public class NormalFromHeightSettings +{ + [DefaultValue(0.5f)] public float AngularIntensity; + + [DefaultValue("0.5")] public string AngularIntensityText; + + [DefaultValue(0.0f)] public float Angularity; + + [DefaultValue("0")] public string AngularityText; + + [DefaultValue(20.0f)] public float Blur0Contrast; + + [DefaultValue("20")] public string Blur0ContrastText; + + [DefaultValue(0.3f)] public float Blur0Weight; + + [DefaultValue(0.35f)] public float Blur1Weight; + + [DefaultValue(0.5f)] public float Blur2Weight; + + [DefaultValue(0.8f)] public float Blur3Weight; + + [DefaultValue(1.0f)] public float Blur4Weight; + + [DefaultValue(0.95f)] public float Blur5Weight; + + [DefaultValue(0.8f)] public float Blur6Weight; + + [DefaultValue(5.0f)] public float FinalContrast; + + [DefaultValue("5")] public string FinalContrastText; + + [DefaultValue(0.0f)] public float LightRotation; + + [DefaultValue("0")] public string LightRotationText; + + [DefaultValue(0.5f)] public float ShapeBias; + + [DefaultValue("0.5")] public string ShapeBiasText; + + [DefaultValue(0.0f)] public float ShapeRecognition; + + [DefaultValue("0")] public string ShapeRecognitionText; + + [DefaultValue(50.0f)] public int SlopeBlur; + + [DefaultValue("50")] public string SlopeBlurText; + + [DefaultValue(true)] public bool UseDiffuse; + + public NormalFromHeightSettings() + { + Blur0Weight = 0.3f; + Blur1Weight = 0.35f; + Blur2Weight = 0.5f; + Blur3Weight = 0.8f; + Blur4Weight = 1.0f; + Blur5Weight = 0.95f; + Blur6Weight = 0.8f; + + Blur0Contrast = 20.0f; + Blur0ContrastText = "20"; + + FinalContrast = 5.0f; + FinalContrastText = "5"; + + Angularity = 0.0f; + AngularityText = "0"; + + AngularIntensity = 0.5f; + AngularIntensityText = "0.5"; + + UseDiffuse = true; + + ShapeRecognition = 0.0f; + ShapeRecognitionText = "0"; + + LightRotation = 0.0f; + LightRotationText = "0"; + + SlopeBlur = 50; + SlopeBlurText = "50"; + + ShapeBias = 0.5f; + ShapeBiasText = "0.5"; + } +} \ No newline at end of file diff --git a/Assets/Scripts/NormalFromHeightSettings.cs.meta b/Assets/Scripts/NormalFromHeightSettings.cs.meta new file mode 100644 index 00000000..c77cb380 --- /dev/null +++ b/Assets/Scripts/NormalFromHeightSettings.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 26511bdb812049f2bb1fe9e6db6eb6d9 +timeCreated: 1549048017 \ No newline at end of file diff --git a/Assets/Scripts/ObjRotator.cs b/Assets/Scripts/ObjRotator.cs index d28fce4a..7073d6db 100644 --- a/Assets/Scripts/ObjRotator.cs +++ b/Assets/Scripts/ObjRotator.cs @@ -1,85 +1,92 @@ -using UnityEngine; -using System.Collections; - -public class ObjRotator : MonoBehaviour { - - Vector2 mousePos; - Vector2 lastMousePos; - Vector3 rotation; - Vector3 lerpRotation; - - int mouseDownCount = 0; - - public int MouseButton = 0; - - public bool AllowX = true; - public bool InvertX = false; - - public bool AllowY = true; - public bool InvertY = false; - - public bool holdKey = false; - public bool noHoldKey = false; - public KeyCode keyToHold; - - // Use this for initialization - void Start () { - - mousePos = Input.mousePosition; - lastMousePos = mousePos; - - rotation = this.transform.eulerAngles; - lerpRotation = rotation; - - } - - public void Reset(){ - rotation = new Vector3(0,0,0); - lerpRotation = rotation; - this.transform.eulerAngles = lerpRotation; - } - - // Update is called once per frame - void Update() { - - mousePos = Input.mousePosition; - - Vector2 mouseOffset = mousePos - lastMousePos; - - if (Input.GetMouseButton (MouseButton)) { - mouseDownCount ++; - } else { - mouseDownCount = 0; - } - - // skip the first frame because we could just be regaining focus - - if ( ( holdKey && Input.GetKey (keyToHold) ) || holdKey == false ) { - - if (mouseDownCount > 1) { - if (AllowX) { - if (InvertX) { - rotation -= new Vector3 (0, 1, 0) * mouseOffset.x * 0.3f; - } else { - rotation += new Vector3 (0, 1, 0) * mouseOffset.x * 0.3f; - } - } - if (AllowY) { - if (InvertY) { - rotation -= new Vector3 (1, 0, 0) * mouseOffset.y * 0.3f; - } else { - rotation += new Vector3 (1, 0, 0) * mouseOffset.y * 0.3f; - } - } - rotation.x = Mathf.Clamp (rotation.x, -80, 80); - } - - } - - lerpRotation = lerpRotation * 0.95f + rotation * 0.05f; - this.transform.eulerAngles = lerpRotation; - - lastMousePos = mousePos; - - } -} +#region + +using UnityEngine; + +#endregion + +public class ObjRotator : MonoBehaviour +{ + private Vector2 _lastMousePos; + private Vector3 _lerpRotation; + + private int _mouseDownCount; + + private Vector2 _mousePos; + private Vector3 _rotation; + public bool AllowX = true; + + public bool AllowY = true; + + public bool HoldKey; + public bool InvertX; + public bool InvertY; + public bool AllowHideUI; + + public KeyCode KeyToHold = KeyCode.L; + + public int MouseButton; + + // Use this for initialization + private void Start() + { + _mousePos = Input.mousePosition; + _lastMousePos = _mousePos; + + _rotation = transform.eulerAngles; + _lerpRotation = _rotation; + } + + public void Reset() + { + _rotation = new Vector3(0, 0, 0); + _lerpRotation = _rotation; + transform.eulerAngles = _lerpRotation; + } + + private void FixedUpdate() + { + if (!MainGui.Instance) return; + _mousePos = Input.mousePosition; + + var mouseOffset = _mousePos - _lastMousePos; + + if (Input.GetMouseButton(MouseButton)) + _mouseDownCount++; + else + _mouseDownCount = 0; + + // skip the first frame because we could just be regaining focus + + if ((HoldKey && Input.GetKey(KeyToHold) || HoldKey == false) && _mouseDownCount > 1) + { + if (AllowX) + { + if (InvertX) + _rotation -= new Vector3(0, 1, 0) * mouseOffset.x * 0.3f; + else + _rotation += new Vector3(0, 1, 0) * mouseOffset.x * 0.3f; + } + + if (AllowY) + { + if (InvertY) + _rotation -= new Vector3(1, 0, 0) * mouseOffset.y * 0.3f; + else + _rotation += new Vector3(1, 0, 0) * mouseOffset.y * 0.3f; + } + + _rotation.x = Mathf.Clamp(_rotation.x, -80, 80); + if(AllowHideUI) MainGui.Instance.SaveHideStateAndHideAndLock(this); + } + else + { + MainGui.Instance.HideGuiLocker.Unlock(this); + } + + + _lerpRotation = _lerpRotation * 0.95f + _rotation * 0.05f; + transform.eulerAngles = _lerpRotation; + + _lastMousePos = _mousePos; + } +} \ No newline at end of file diff --git a/Assets/Scripts/PostProcessGui.cs b/Assets/Scripts/PostProcessGui.cs index 89b2ae23..67851901 100644 --- a/Assets/Scripts/PostProcessGui.cs +++ b/Assets/Scripts/PostProcessGui.cs @@ -1,173 +1,177 @@ -using UnityEngine; -using System.Collections; +#region -public class PostProcessGui : MonoBehaviour { +using UnityEngine; - public GameObject MainGuiObject; - public GameObject MainCamera; - - OpaquePostProcess oppScript; - PostProcess ppScript; - - bool EnablePostProcess = true; - - bool UseTAA = true; - - float BloomThreshold = 0.8f; - string BloomThresholdText = "0.8"; - - float BloomAmount = 1.0f; - string BloomAmountText = "1.0"; - - float LensFlareAmount = 0.5f; - string LensFlareAmountText = "0.5"; - - float LensDirtAmount = 1.0f; - string LensDirtAmountText = "1.0"; - - float VignetteAmount = 0.2f; - string VignetteAmountText = "0.2"; - - float DOFMaxBlur = 0.0f; - string DOFMaxBlurText = "0.0"; - - float DOFFocalDepth = 10.0f; - string DOFFocalDepthText = "10.0"; - - float DOFMaxDistance = 50.0f; - string DOFMaxDistanceText = "50.0"; - - bool AutoFocus = true; - - Rect windowRect = new Rect (360, 330, 300, 530); +#endregion - bool initialized = false; - - // Use this for initialization - void Start () { - Initialize (); - } - - void Initialize(){ - if (!initialized) { - oppScript = MainCamera.GetComponent (); - ppScript = MainCamera.GetComponent (); - initialized = true; - } - } - - public void PostProcessOn(){ - Initialize (); - - EnablePostProcess = true; - - oppScript.enabled = true; - - ppScript.enabled = true; - ppScript.bloomThreshold = BloomThreshold; - ppScript.bloomAmount = BloomAmount; - - ppScript.lensFlareAmount = LensFlareAmount; - ppScript.lensDirtAmount = LensDirtAmount; - ppScript.vignetteAmount = VignetteAmount; - - - if (DOFMaxBlur > 12) { - ppScript.DOFMaxBlur = 16; - } else if (DOFMaxBlur > 6) { - ppScript.DOFMaxBlur = 8; - } else if (DOFMaxBlur > 3) { - ppScript.DOFMaxBlur = 4; - } else if (DOFMaxBlur > 1.5) { - ppScript.DOFMaxBlur = 2; - } else if (DOFMaxBlur > 0.5) { - ppScript.DOFMaxBlur = 1; - } else { - ppScript.DOFMaxBlur = 0; - } - ppScript.focalDepth = DOFFocalDepth; - ppScript.DOFMaxDistance = DOFMaxDistance; - - ppScript.AutoFocus = AutoFocus; - } - - public void PostProcessOff(){ - Initialize (); - - EnablePostProcess = false; - - oppScript.enabled = false; - ppScript.enabled = false; - } - - // Update is called once per frame - void Update () { - - if (EnablePostProcess) { - PostProcessOn(); - } else { - PostProcessOff(); - } - - } - - void DoMyWindow ( int windowID ) { - - int spacingX = 0; - int spacingY = 50; - int spacing2Y = 70; - - int offsetX = 10; - int offsetY = 30; - - EnablePostProcess = GUI.Toggle (new Rect (offsetX, offsetY, 280, 30), EnablePostProcess, "Enable Post Process"); - offsetY += 40; - - - GuiHelper.Slider (new Rect (offsetX, offsetY, 280, 50), "Bloom Threshold", BloomThreshold, BloomThresholdText, out BloomThreshold, out BloomThresholdText, 0.0f, 2.0f ); - offsetY += 40; - - GuiHelper.Slider (new Rect (offsetX, offsetY, 280, 50), "Bloom Amount", BloomAmount, BloomAmountText, out BloomAmount, out BloomAmountText, 0.0f, 8.0f ); - offsetY += 60; - - - - GuiHelper.Slider (new Rect (offsetX, offsetY, 280, 50), "Lens Flare Amount", LensFlareAmount, LensFlareAmountText, out LensFlareAmount, out LensFlareAmountText, 0.0f, 4.0f ); - offsetY += 40; - - GuiHelper.Slider (new Rect (offsetX, offsetY, 280, 50), "Lens Dirt Amount", LensDirtAmount, LensDirtAmountText, out LensDirtAmount, out LensDirtAmountText, 0.0f, 2.0f ); - offsetY += 40; - - GuiHelper.Slider (new Rect (offsetX, offsetY, 280, 50), "Vignette Amount", VignetteAmount, VignetteAmountText, out VignetteAmount, out VignetteAmountText, 0.0f, 1.0f ); - offsetY += 60; - - - GuiHelper.Slider (new Rect (offsetX, offsetY, 280, 50), "DOF Max Blur", DOFMaxBlur, DOFMaxBlurText, out DOFMaxBlur, out DOFMaxBlurText, 0.0f, 16.0f ); - offsetY += 40; - - GuiHelper.Slider (new Rect (offsetX, offsetY, 280, 50), "DOF Focal Depth", DOFFocalDepth, DOFFocalDepthText, out DOFFocalDepth, out DOFFocalDepthText, 1.0f, 50.0f ); - offsetY += 40; - - GuiHelper.Slider (new Rect (offsetX, offsetY, 280, 50), "DOF Max Distance", DOFMaxDistance, DOFMaxDistanceText, out DOFMaxDistance, out DOFMaxDistanceText, 5.0f, 200.0f ); - offsetY += 50; - - AutoFocus = GUI.Toggle (new Rect (offsetX, offsetY, 150, 20), AutoFocus, "Use Auto Focus"); - offsetY += 30; - - if (GUI.Button (new Rect (offsetX + 150, offsetY, 130, 30), "Close")) { - this.gameObject.SetActive(false); - } - - GUI.DragWindow(); - - } - - void OnGUI () { - - windowRect.width = 300; - windowRect.height = 510; - - windowRect = GUI.Window(19, windowRect, DoMyWindow, "Post Process"); - - } -} +public class PostProcessGui : MonoBehaviour +{ + private bool _autoFocus = true; + + private float _bloomAmount = 1.0f; + private string _bloomAmountText = "1.0"; + + private float _bloomThreshold = 0.8f; + private string _bloomThresholdText = "0.8"; + + private float _dofFocalDepth = 10.0f; + private string _dofFocalDepthText = "10.0"; + + private float _dofMaxBlur; + private string _dofMaxBlurText = "0.0"; + + private float _dofMaxDistance = 50.0f; + private string _dofMaxDistanceText = "50.0"; + + private bool _enablePostProcess = true; + + private bool _initialized; + + private float _lensDirtAmount = 1.0f; + private string _lensDirtAmountText = "1.0"; + + private float _lensFlareAmount = 0.5f; + private string _lensFlareAmountText = "0.5"; + + private OpaquePostProcess _oppScript; + private PostProcess _ppScript; + + private float _vignetteAmount = 0.2f; + private string _vignetteAmountText = "0.2"; + + private Rect _windowRect = new Rect(360, 330, 300, 530); + public GameObject MainCamera; + + // Use this for initialization + private void Start() + { + Initialize(); + } + + private void Initialize() + { + if (_initialized) return; + _oppScript = MainCamera.GetComponent(); + _ppScript = MainCamera.GetComponent(); + _initialized = true; + } + + public void PostProcessOn() + { + Initialize(); + + _enablePostProcess = true; + + _oppScript.enabled = true; + + _ppScript.enabled = true; + _ppScript.bloomThreshold = _bloomThreshold; + _ppScript.bloomAmount = _bloomAmount; + + _ppScript.lensFlareAmount = _lensFlareAmount; + _ppScript.lensDirtAmount = _lensDirtAmount; + _ppScript.vignetteAmount = _vignetteAmount; + + + if (_dofMaxBlur > 12) + _ppScript.DOFMaxBlur = 16; + else if (_dofMaxBlur > 6) + _ppScript.DOFMaxBlur = 8; + else if (_dofMaxBlur > 3) + _ppScript.DOFMaxBlur = 4; + else if (_dofMaxBlur > 1.5) + _ppScript.DOFMaxBlur = 2; + else if (_dofMaxBlur > 0.5) + _ppScript.DOFMaxBlur = 1; + else + _ppScript.DOFMaxBlur = 0; + _ppScript.focalDepth = _dofFocalDepth; + _ppScript.DOFMaxDistance = _dofMaxDistance; + + _ppScript.AutoFocus = _autoFocus; + } + + public void PostProcessOff() + { + Initialize(); + + _enablePostProcess = false; + + _oppScript.enabled = false; + _ppScript.enabled = false; + } + + private void Update() + { + if (_enablePostProcess) + PostProcessOn(); + else + PostProcessOff(); + } + + private void DoMyWindow(int windowId) + { + const int offsetX = 10; + var offsetY = 30; + + _enablePostProcess = GUI.Toggle(new Rect(offsetX, offsetY, 280, 30), _enablePostProcess, "Enable Post Process"); + offsetY += 40; + + + GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Bloom Threshold", _bloomThreshold, _bloomThresholdText, + out _bloomThreshold, out _bloomThresholdText, 0.0f, 2.0f); + offsetY += 40; + + GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Bloom Amount", _bloomAmount, _bloomAmountText, + out _bloomAmount, out _bloomAmountText, 0.0f, 8.0f); + offsetY += 60; + + + GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Lens Flare Amount", _lensFlareAmount, + _lensFlareAmountText, + out _lensFlareAmount, out _lensFlareAmountText, 0.0f, 4.0f); + offsetY += 40; + + GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Lens Dirt Amount", _lensDirtAmount, _lensDirtAmountText, + out _lensDirtAmount, out _lensDirtAmountText, 0.0f, 2.0f); + offsetY += 40; + + GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Vignette Amount", _vignetteAmount, _vignetteAmountText, + out _vignetteAmount, out _vignetteAmountText, 0.0f, 1.0f); + offsetY += 60; + + + GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "DOF Max Blur", _dofMaxBlur, _dofMaxBlurText, + out _dofMaxBlur, out _dofMaxBlurText, 0.0f, 16.0f); + offsetY += 40; + + GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "DOF Focal Depth", _dofFocalDepth, _dofFocalDepthText, + out _dofFocalDepth, out _dofFocalDepthText, 1.0f, 50.0f); + offsetY += 40; + + GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "DOF Max Distance", _dofMaxDistance, _dofMaxDistanceText, + out _dofMaxDistance, out _dofMaxDistanceText, 5.0f, 200.0f); + offsetY += 50; + + _autoFocus = GUI.Toggle(new Rect(offsetX, offsetY, 150, 20), _autoFocus, "Use Auto Focus"); + offsetY += 30; + + if (GUI.Button(new Rect(offsetX + 150, offsetY, 130, 30), "Close")) gameObject.SetActive(false); + + GUI.DragWindow(); + } + + private void OnGUI() + { + _windowRect.width = 300; + _windowRect.height = 510; + + _windowRect = GUI.Window(19, _windowRect, DoMyWindow, "Post Process"); + } + public void ShowPost() + { + _windowRect.width = 300; + _windowRect.height = 510; + _windowRect = GUI.Window(19, _windowRect, DoMyWindow, "Post Process"); + } +} \ No newline at end of file diff --git a/Assets/Scripts/PropChannelMap.cs b/Assets/Scripts/PropChannelMap.cs new file mode 100644 index 00000000..3a0989fd --- /dev/null +++ b/Assets/Scripts/PropChannelMap.cs @@ -0,0 +1,10 @@ +public enum PropChannelMap +{ + None, + Height, + Metallic, + Smoothness, + Edge, + Ao, + AoEdge +} \ No newline at end of file diff --git a/Assets/Scripts/PropChannelMap.cs.meta b/Assets/Scripts/PropChannelMap.cs.meta new file mode 100644 index 00000000..a7406307 --- /dev/null +++ b/Assets/Scripts/PropChannelMap.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 1a308fa666f8458cb6a15acd4a4ebd94 +timeCreated: 1549040698 \ No newline at end of file diff --git a/Assets/Scripts/Resources/GuiHelper.cs b/Assets/Scripts/Resources/GuiHelper.cs index 0a694232..d1e291d6 100644 --- a/Assets/Scripts/Resources/GuiHelper.cs +++ b/Assets/Scripts/Resources/GuiHelper.cs @@ -1,204 +1,233 @@ -using UnityEngine; -using System.Collections; - -public static class GuiHelper { - - public static string FloatToString ( float num, int length ) { - - string numString = num.ToString (); - int numStringLength = numString.Length; - int lastIndex = Mathf.FloorToInt( Mathf.Min ( (float)numStringLength , (float)length ) ); - - return numString.Substring (0, lastIndex); - } - - // Value is a float - public static bool Slider( Rect rect, string title, float value, string textValue, out float outValue, out string outTextValue, float minValue, float maxValue ){ - - if (textValue == null) { - textValue = value.ToString (); - } - - int offsetX = (int)rect.x; - int offsetY = (int)rect.y; - - GUI.Label (new Rect (rect.x, rect.y, 250, 30), title); - offsetY += 20; - - bool isChanged = false; - - float tempValue = value; - value = GUI.HorizontalSlider( new Rect( offsetX, offsetY, rect.width - 60, 10 ),value, minValue, maxValue ); - if (value != tempValue) { - textValue = FloatToString (value, 6); - isChanged = true; - } - textValue = GUI.TextField (new Rect (offsetX + rect.width - 50, offsetY - 5, 50, 20), textValue); - if (Event.current.type == EventType.KeyDown || Event.current.character == '\n') { - float.TryParse( textValue, out value ); - value = Mathf.Clamp( value, minValue, maxValue ); - textValue = FloatToString (value, 6); - - if( value != tempValue ){ - isChanged = true; - } - } - - outValue = value; - outTextValue = textValue; - - return isChanged; - - } - - // Value is an int - public static bool Slider( Rect rect, string title, int value, string textValue, out int outValue, out string outTextValue, int minValue, int maxValue ){ - - if (textValue == null) { - textValue = value.ToString (); - } - - int offsetX = (int)rect.x; - int offsetY = (int)rect.y; - - GUI.Label (new Rect (rect.x, rect.y, 250, 30), title); - offsetY += 20; - - bool isChanged = false; - - float tempValue = value; - value = (int)GUI.HorizontalSlider( new Rect( offsetX, offsetY, rect.width - 60, 10 ),(float)value, (float)minValue, (float)maxValue ); - if (value != tempValue) { - textValue = FloatToString (value, 6); - isChanged = true; - } - textValue = GUI.TextField (new Rect (offsetX + rect.width - 50, offsetY - 5, 50, 20), textValue); - if (Event.current.type == EventType.KeyDown || Event.current.character == '\n') { - int.TryParse( textValue, out value ); - value = (int)Mathf.Clamp( (float)value, (float)minValue, (float)maxValue ); - textValue = value.ToString(); - - if( value != tempValue ){ - isChanged = true; - } - } - - outValue = value; - outTextValue = textValue; - - return isChanged; - - } - - // No Title, Value is a float - public static bool Slider( Rect rect, float value, string textValue, out float outValue, out string outTextValue, float minValue, float maxValue ){ - - if (textValue == null) { - textValue = value.ToString (); - } - - int offsetX = (int)rect.x; - int offsetY = (int)rect.y; - - bool isChanged = false; - - float tempValue = value; - value = GUI.HorizontalSlider( new Rect( offsetX, offsetY, rect.width - 60, 10 ),value, minValue, maxValue ); - if (value != tempValue) { - textValue = FloatToString (value, 6); - isChanged = true; - } - textValue = GUI.TextField (new Rect (offsetX + rect.width - 50, offsetY - 5, 50, 20), textValue); - if (Event.current.type == EventType.KeyDown || Event.current.character == '\n') { - float.TryParse( textValue, out value ); - value = Mathf.Clamp( value, minValue, maxValue ); - textValue = FloatToString (value, 6); - - if( value != tempValue ){ - isChanged = true; - } - } - - outValue = value; - outTextValue = textValue; - - return isChanged; - - } - - // No Title, Value is an int - public static bool Slider( Rect rect, int value, string textValue, out int outValue, out string outTextValue, int minValue, int maxValue ){ - - if (textValue == null) { - textValue = value.ToString (); - } - - int offsetX = (int)rect.x; - int offsetY = (int)rect.y; - - bool isChanged = false; - - float tempValue = value; - value = (int)GUI.HorizontalSlider( new Rect( offsetX, offsetY, rect.width - 60, 10 ),(float)value, (float)minValue, (float)maxValue ); - if (value != tempValue) { - textValue = FloatToString (value, 6); - isChanged = true; - } - textValue = GUI.TextField (new Rect (offsetX + rect.width - 50, offsetY - 5, 50, 20), textValue); - if (Event.current.type == EventType.KeyDown || Event.current.character == '\n') { - int.TryParse( textValue, out value ); - value = (int)Mathf.Clamp( (float)value, (float)minValue, (float)maxValue ); - textValue = value.ToString(); - - if( value != tempValue ){ - isChanged = true; - } - } - - outValue = value; - outTextValue = textValue; - - return isChanged; - - } - - - // Verticle Slider - - // No Title, Value is a float - public static bool VerticalSlider( Rect rect, float value, out float outValue, float minValue, float maxValue, bool doStuff ){ - - bool isChanged = false; - - float tempValue = value; - value = GUI.VerticalSlider( rect,value, minValue, maxValue ); - if (value != tempValue || doStuff) { - isChanged = true; - } - - outValue = value; - - return isChanged; - - } - - // Toggle - - // No Title, Value is a float - public static bool Toggle( Rect rect, bool value, out bool outValue, string Text, bool doStuff ){ - - bool isChanged = false; - - bool tempValue = value; - value = GUI.Toggle (rect, value, Text); - if ( value != tempValue || doStuff ) { - isChanged = true; - } - - outValue = value; - - return isChanged; - - } - -} +#region + +using System; +using UnityEngine; + +#endregion + +public static class GuiHelper +{ + private static string FloatToString(float num, int length) + { + var numString = num.ToString(); + var numStringLength = numString.Length; + var lastIndex = Mathf.FloorToInt(Mathf.Min(numStringLength, (float) length)); + + return numString.Substring(0, lastIndex); + } + + public static bool Slider(Rect rect, string title, float value, string textValue, out float outValue, + out string outTextValue, float minValue, float maxValue) + { + + if (textValue == null) textValue = value.ToString(); + + var offsetX = (int) rect.x; + var offsetY = (int) rect.y; + + GUI.Label(new Rect(rect.x, rect.y, 250, 30), title); + offsetY += 20; + + var isChanged = false; + + var tempValue = value; + value = GUI.HorizontalSlider(new Rect(offsetX, offsetY, rect.width - 60, 10), value, minValue, maxValue); + if (Math.Abs(value - tempValue) > 0.001f) + { + textValue = FloatToString(value, 6); + isChanged = true; + } + + var handler = Time.time.ToString(); + GUI.SetNextControlName(handler); + textValue = GUI.TextField(new Rect(offsetX + rect.width - 50, offsetY - 5, 50, 20), textValue); + if (Event.current.type == EventType.KeyDown && Event.current.character == '\n' && + GUI.GetNameOfFocusedControl() == handler) + { + if (textValue.Contains(".")) + { + textValue = textValue.Replace(".", ","); + } + + float.TryParse(textValue, out value); + value = Mathf.Clamp(value, minValue, maxValue); + textValue = FloatToString(value, 6); + + if (Math.Abs(value - tempValue) > 0.0001f) isChanged = true; + } + + float floatValue = 0.0f; + float.TryParse(textValue, out floatValue); + if(floatValue != value) + { + value = floatValue; + } + outValue = value; + outTextValue = textValue; + + return isChanged; + } + + // Value is an int + public static bool Slider(Rect rect, string title, int value, string textValue, out int outValue, + out string outTextValue, int minValue, int maxValue) + { + if (textValue == null) textValue = value.ToString(); + + var offsetX = (int) rect.x; + var offsetY = (int) rect.y; + + GUI.Label(new Rect(rect.x, rect.y, 250, 30), title); + offsetY += 20; + + var isChanged = false; + + float tempValue = value; + value = (int) GUI.HorizontalSlider(new Rect(offsetX, offsetY, rect.width - 60, 10), value, minValue, maxValue); + if (Math.Abs(value - tempValue) > 0.0001f) + { + textValue = FloatToString(value, 6); + isChanged = true; + } + + var handler = Time.time.ToString(); + GUI.SetNextControlName(handler); + textValue = GUI.TextField(new Rect(offsetX + rect.width - 50, offsetY - 5, 50, 20), textValue); + if (Event.current.type == EventType.KeyDown && Event.current.character == '\n' && + GUI.GetNameOfFocusedControl() == handler) + { + if (textValue.Contains(".")) + { + textValue = textValue.Replace(".", ","); + } + + float.TryParse(textValue, out var preValue); + value = (int) preValue; + value = Mathf.Clamp(value, minValue, maxValue); + textValue = value.ToString(); + + if (Math.Abs(value - tempValue) > 0.001f) isChanged = true; + } + + outValue = value; + outTextValue = textValue; + + return isChanged; + } + + // No Title, Value is a float + public static bool Slider(Rect rect, float value, string textValue, out float outValue, + out string outTextValue, + float minValue, float maxValue) + { + if (textValue == null) textValue = value.ToString(); + + var offsetX = (int) rect.x; + var offsetY = (int) rect.y; + + var isChanged = false; + + var tempValue = value; + value = GUI.HorizontalSlider(new Rect(offsetX, offsetY, rect.width - 60, 10), value, minValue, maxValue); + if (Math.Abs(value - tempValue) > 0.001f) + { + textValue = FloatToString(value, 6); + isChanged = true; + } + + var handler = Time.time.ToString(); + GUI.SetNextControlName(handler); + textValue = GUI.TextField(new Rect(offsetX + rect.width - 50, offsetY - 5, 50, 20), textValue); + if (Event.current.type == EventType.KeyDown && Event.current.character == '\n' && + GUI.GetNameOfFocusedControl() == handler) + { + if (textValue.Contains(".")) + { + textValue = textValue.Replace(".", ","); + } + + float.TryParse(textValue, out value); + value = Mathf.Clamp(value, minValue, maxValue); + textValue = FloatToString(value, 6); + + if (Math.Abs(value - tempValue) > 0.0001f) isChanged = true; + } + + outValue = value; + outTextValue = textValue; + + return isChanged; + } + + // No Title, Value is an int + public static bool Slider(Rect rect, int value, string textValue, out int outValue, out string outTextValue, + int minValue, int maxValue) + { + if (textValue == null) textValue = value.ToString(); + + var offsetX = (int) rect.x; + var offsetY = (int) rect.y; + + var isChanged = false; + + float tempValue = value; + value = (int) GUI.HorizontalSlider(new Rect(offsetX, offsetY, rect.width - 60, 10), value, minValue, maxValue); + if (Math.Abs(value - tempValue) > 0.0001f) + { + textValue = FloatToString(value, 6); + isChanged = true; + } + + var handler = Time.time.ToString(); + GUI.SetNextControlName(handler); + textValue = GUI.TextField(new Rect(offsetX + rect.width - 50, offsetY - 5, 50, 20), textValue); + if (Event.current.type == EventType.KeyDown && Event.current.character == '\n' && + GUI.GetNameOfFocusedControl() == handler) + { + if (textValue.Contains(".")) + { + textValue = textValue.Replace(".", ","); + } + + float.TryParse(textValue, out var preValue); + value = (int) preValue; + value = (int) Mathf.Clamp(value, minValue, (float) maxValue); + textValue = value.ToString(); + + if (Math.Abs(value - tempValue) > 0.0001f) isChanged = true; + } + + outValue = value; + outTextValue = textValue; + + return isChanged; + } + + + public static bool VerticalSlider(Rect rect, float value, out float outValue, float minValue, float maxValue, + bool doStuff) + { + var isChanged = false; + + var tempValue = value; + value = GUI.VerticalSlider(rect, value, minValue, maxValue); + if (Math.Abs(value - tempValue) > 0.0001f || doStuff) isChanged = true; + + outValue = value; + + return isChanged; + } + + public static bool Toggle(Rect rect, bool value, out bool outValue, string text, bool doStuff) + { + var isChanged = false; + + var tempValue = value; + value = GUI.Toggle(rect, value, text); + if (value != tempValue || doStuff) isChanged = true; + + outValue = value; + + return isChanged; + } +} \ No newline at end of file diff --git a/Assets/Scripts/SampleProbeTex.cs b/Assets/Scripts/SampleProbeTex.cs index 691ed80d..4d371e83 100644 --- a/Assets/Scripts/SampleProbeTex.cs +++ b/Assets/Scripts/SampleProbeTex.cs @@ -1,38 +1,33 @@ -using UnityEngine; -using System.Collections; +#region -[ExecuteInEditMode] -public class SampleProbeTex : MonoBehaviour { +using UnityEngine; + +#endregion - public ReflectionProbe sampleProbe; - public Material skyboxMaterial; +[ExecuteInEditMode] +public class SampleProbeTex : MonoBehaviour +{ + private static readonly int UseProbeTexture = Shader.PropertyToID("_UseProbeTexture"); + private static readonly int Tex = Shader.PropertyToID("_Tex"); + private static readonly int ProbeCubemap = Shader.PropertyToID("_ProbeCubemap"); + public ReflectionProbe SampleProbe; + public Material SkyboxMaterial; - // Use this for initialization - void Start () { - sampleProbe.RenderProbe (); - //StartCoroutine (SwitchCubemaps ()); - } + private void Start() + { + SampleProbe.RenderProbe(); + } - void OnDisable (){ - Shader.SetGlobalFloat ("_UseProbeTexture", 0); - Shader.EnableKeyword ("_USE_BAKED_CUBEMAP_ON"); - Shader.DisableKeyword ("_USE_BAKED_CUBEMAP_OFF"); - } + private void OnDisable() + { + Shader.SetGlobalFloat(UseProbeTexture, 0); + Shader.EnableKeyword("_USE_BAKED_CUBEMAP_ON"); + Shader.DisableKeyword("_USE_BAKED_CUBEMAP_OFF"); + } - IEnumerator SwitchCubemaps(){ - yield return new WaitForSeconds(1); - for( int i = 1; i <= 100; i++ ){ - Shader.SetGlobalFloat ("_UseProbeTexture", (float)i / 100.0f); - yield return new WaitForSeconds(0.01f); - } - Shader.EnableKeyword ("_USE_BAKED_CUBEMAP_OFF"); - Shader.DisableKeyword ("_USE_BAKED_CUBEMAP_ON"); - } - - // Update is called once per frame - void Update () { - - skyboxMaterial.SetTexture ("_Tex", sampleProbe.texture); - Shader.SetGlobalTexture ( "_ProbeCubemap", sampleProbe.texture ); - } -} + private void Update() + { + SkyboxMaterial.SetTexture(Tex, SampleProbe.texture); + Shader.SetGlobalTexture(ProbeCubemap, SampleProbe.texture); + } +} \ No newline at end of file diff --git a/Assets/Scripts/SaveLoadProject.cs b/Assets/Scripts/SaveLoadProject.cs index 7b80dbe6..4e7d5345 100644 --- a/Assets/Scripts/SaveLoadProject.cs +++ b/Assets/Scripts/SaveLoadProject.cs @@ -1,566 +1,495 @@ -using UnityEngine; +#region + +using System; using System.Collections; +using System.Collections.Generic; using System.IO; - -using FreeImageAPI; +using System.Linq; using System.Runtime.InteropServices; - -using System.Xml; using System.Xml.Serialization; - -using System; +using UnityEngine; +using System.Threading; +using System.Threading.Tasks; using System.Diagnostics; - -public enum MapType { - height, - diffuse, - diffuseOriginal, - metallic, - smoothness, - normal, - edge, - ao, - property, - blank +using Debug = UnityEngine.Debug; + +#endregion + +public enum MapType +{ + Height, + Diffuse, + DiffuseOriginal, + Metallic, + Smoothness, + Normal, + Edge, + Ao, + Property } -public enum FileFormat { - bmp, - jpg, - png, - tga, - tiff +public enum FileFormat +{ + Png, + Jpg, + Tga, + Exr } -public class ProjectObject { - - public HeightFromDiffuseSettings HFDS; - public string heightMapPath; +public class ProjectObject +{ + public string AoMapPath; - public EditDiffuseSettings EDS; - public string diffuseMapPath; - public string diffuseMapOriginalPath; + public AoSettings AoSettings; + public string DiffuseMapOriginalPath; + public string DiffuseMapPath; + public string EdgeMapPath; - public NormalFromHeightSettings NFHS; - public string normalMapPath; + public EdgeSettings EdgeSettings; - public MetallicSettings MS; - public string metallicMapPath; + public EditDiffuseSettings EditDiffuseSettings; + public HeightFromDiffuseSettings HeightFromDiffuseSettings; + public string HeightMapPath; - public SmoothnessSettings SS; - public string smoothnessMapPath; + public MaterialSettings MaterialSettings; + public string MetallicMapPath; - public EdgeSettings ES; - public string edgeMapPath; + public MetallicSettings MetallicSettings; - public AOSettings AOS; - public string aoMapPath; + public NormalFromHeightSettings NormalFromHeightSettings; + public string NormalMapPath; + public string SmoothnessMapPath; - public MaterialSettings MatS; - + public SmoothnessSettings SmoothnessSettings; } -public class SaveLoadProject : MonoBehaviour { - - public MainGui mainGui; - public HeightFromDiffuseGui heightFromDiffuseGui; - public EditDiffuseGui editDiffuseGui; - public NormalFromHeightGui normalFromHeightGui; - public MetallicGui metallicGui; - public SmoothnessGui SmoothnessGui; - public EdgeFromNormalGui edgeFromNormalGui; - public AOFromNormalGui aoFromNormalGui; - public MaterialGui materailGui; - - ProjectObject thisProject; - - char pathChar; - - public bool busy = false; - - [DllImport ("FreeImage")] - private static extern FIBITMAP FreeImage_Load( FREE_IMAGE_FORMAT fif, string filename, int flags ); - - [DllImport ("FreeImage")] - private static extern void FreeImage_Unload( FIBITMAP dib ); - - [DllImport ("FreeImage")] - private static extern bool FreeImage_Save( FREE_IMAGE_FORMAT fif, FIBITMAP dib, string filename, FREE_IMAGE_SAVE_FLAGS flags ); - - [DllImport ("FreeImage")] - private static extern int FreeImage_GetHeight( FIBITMAP dib ); - - [DllImport ("FreeImage")] - private static extern int FreeImage_GetWidth( FIBITMAP dib ); - - [DllImport ("FreeImage")] - private static extern bool FreeImage_GetPixelColor( FIBITMAP dib, int x, int y, RGBQUAD value ); - - [DllImport ("FreeImage")] - private static extern FIBITMAP FreeImage_MakeThumbnail( FIBITMAP dib, int max_pixel_size, bool convert ); - - - - // Use this for initialization - void Start () { - - if (Application.platform == RuntimePlatform.WindowsEditor || Application.platform == RuntimePlatform.WindowsPlayer) { - pathChar = '\\'; - } else { - pathChar = '/'; - } - - thisProject = new ProjectObject (); - - } - - // Update is called once per frame - void Update () { - - } - - string SwitchFormats( FileFormat selectedFormat ) { - - string extension = "bmp"; - switch (selectedFormat) { - case FileFormat.bmp: - extension = "bmp"; - break; - case FileFormat.jpg: - extension = "jpg"; - break; - case FileFormat.png: - extension = "png"; - break; - case FileFormat.tga: - extension = "tga"; - break; - case FileFormat.tiff: - extension = "tiff"; - break; - } - - return extension; - } - - public void LoadProject ( string pathToFile ) { - UnityEngine.Debug.Log ("Loading Project: " + pathToFile); - - var serializer = new XmlSerializer(typeof(ProjectObject)); - var stream = new FileStream(pathToFile, FileMode.Open); - thisProject = serializer.Deserialize(stream) as ProjectObject; - stream.Close(); - - heightFromDiffuseGui.SetValues(thisProject); - editDiffuseGui.SetValues(thisProject); - normalFromHeightGui.SetValues (thisProject); - metallicGui.SetValues (thisProject); - SmoothnessGui.SetValues (thisProject); - edgeFromNormalGui.SetValues (thisProject); - aoFromNormalGui.SetValues (thisProject); - materailGui.SetValues (thisProject); - - mainGui.ClearAllTextures (); - - StartCoroutine ( LoadAllTextures( pathToFile ) ); - } - - public void SaveProject ( string pathToFile, FileFormat selectedFormat ) { - UnityEngine.Debug.Log ("Saving Project: " + pathToFile); - - string extension = SwitchFormats(selectedFormat); - - if ( pathToFile.Contains (".") ) { - pathToFile = pathToFile.Substring (0, pathToFile.LastIndexOf (".")); - } - - int fileIndex = pathToFile.LastIndexOf (pathChar); - string projectName = pathToFile.Substring (fileIndex+1, pathToFile.Length-fileIndex-1); - - heightFromDiffuseGui.GetValues(thisProject); - if (mainGui._HeightMap != null) { - thisProject.heightMapPath = projectName + "_height." + extension; - } else { - thisProject.heightMapPath = "null"; - } - - editDiffuseGui.GetValues(thisProject); - if (mainGui._DiffuseMap != null) { - thisProject.diffuseMapPath = projectName + "_diffuse." + extension; - } else { - thisProject.diffuseMapPath = "null"; - } - - if (mainGui._DiffuseMapOriginal != null) { - thisProject.diffuseMapOriginalPath = projectName + "_diffuseOriginal." + extension; - } else { - thisProject.diffuseMapOriginalPath = "null"; - } - - normalFromHeightGui.GetValues(thisProject); - if (mainGui._NormalMap != null) { - thisProject.normalMapPath = projectName + "_normal." + extension; - } else { - thisProject.normalMapPath = "null"; - } - - metallicGui.GetValues(thisProject); - if (mainGui._MetallicMap != null) { - thisProject.metallicMapPath = projectName + "_metallic." + extension; - } else { - thisProject.metallicMapPath = "null"; - } - - SmoothnessGui.GetValues(thisProject); - if (mainGui._SmoothnessMap != null) { - thisProject.smoothnessMapPath = projectName + "_smoothness." + extension; - } else { - thisProject.smoothnessMapPath = "null"; - } - - edgeFromNormalGui.GetValues(thisProject); - if (mainGui._EdgeMap != null) { - thisProject.edgeMapPath = projectName + "_edge." + extension; - } else { - thisProject.edgeMapPath = "null"; - } - - aoFromNormalGui.GetValues(thisProject); - if (mainGui._AOMap != null) { - thisProject.aoMapPath = projectName + "_ao." + extension; - } else { - thisProject.aoMapPath = "null"; - } - - materailGui.GetValues (thisProject); - - var serializer = new XmlSerializer(typeof(ProjectObject)); - var stream = new FileStream(pathToFile + ".mtz", FileMode.Create); - serializer.Serialize(stream, thisProject); - stream.Close(); - - SaveAllFiles (pathToFile, selectedFormat); - } - - public void SaveAllFiles (string pathToFile, FileFormat selectedFormat) { - //int fileIndex = pathToFile.LastIndexOf (pathChar); - //UnityEngine.Debug.Log = "You're saving all files: " + pathToFile.Substring (fileIndex+1, pathToFile.Length-fileIndex-1); - string extension = SwitchFormats(selectedFormat); - if (pathToFile.Contains (".")) { - pathToFile = pathToFile.Substring (0, pathToFile.LastIndexOf (".")); - } - StartCoroutine ( SaveAllTextures( extension, pathToFile ) ); - } - - public void SaveFile ( string pathToFile, FileFormat selectedFormat, Texture2D textureToSave, string mapType ) { - //int fileIndex = pathToFile.LastIndexOf (pathChar); - //UnityEngine.Debug.Log = "You're saving file: " + pathToFile.Substring (fileIndex+1, pathToFile.Length-fileIndex-1); - if (pathToFile.Contains (".")) { - pathToFile = pathToFile.Substring (0, pathToFile.LastIndexOf (".")); - } - string extension = SwitchFormats(selectedFormat); - StartCoroutine ( SaveTexture( extension, textureToSave, pathToFile + mapType ) ); - } - - public void PasteFile( MapType mapTypeToLoad ){ - - string tempImagePath = Application.dataPath + "/temp.png"; - //string tempImagePath = Application.persistentDataPath + "/temp.png"; - UnityEngine.Debug.Log (tempImagePath); - - try{ - Process myProcess = new Process (); - myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; - myProcess.StartInfo.CreateNoWindow = true; - myProcess.StartInfo.UseShellExecute = false; - myProcess.StartInfo.FileName = Application.streamingAssetsPath.Replace ("/", "\\") + "\\c2i.exe"; - myProcess.StartInfo.Arguments = tempImagePath.Replace ("/", "\\"); - myProcess.EnableRaisingEvents = true; - myProcess.Start(); - myProcess.WaitForExit (); - - StartCoroutine ( LoadTexture (mapTypeToLoad, tempImagePath) ); - } catch (Exception e ){ - UnityEngine.Debug.Log (e); - } - - } - - public void CopyFile( Texture2D textureToSave ){ - - SaveFile(Application.dataPath + "/temp.png",FileFormat.png,textureToSave, "" ); - //SaveFile(Application.persistentDataPath + "/temp.png",FileFormat.png,textureToSave, "" ); - - try{ - Process myProcess = new Process (); - myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; - myProcess.StartInfo.CreateNoWindow = true; - myProcess.StartInfo.UseShellExecute = false; - myProcess.StartInfo.FileName = Application.streamingAssetsPath.Replace ("/", "\\") + "\\i2c.exe"; - myProcess.StartInfo.Arguments = Application.dataPath.Replace ("/", "\\") + "\\temp.png"; - myProcess.EnableRaisingEvents = true; - myProcess.Start(); - myProcess.WaitForExit (); - } catch (Exception e ){ - UnityEngine.Debug.Log (e); - } - } - - //==============================================// - // Texture Saving Coroutines // - //==============================================// - - - public IEnumerator SaveAllTextures( string extension, string pathToFile ) { - - StartCoroutine( SaveTexture ( extension, mainGui._HeightMap, pathToFile + "_height" ) ); - while( busy ){ yield return new WaitForSeconds( 0.01f ); } - - StartCoroutine( SaveTexture ( extension, mainGui._DiffuseMap, pathToFile + "_diffuse" ) ); - while( busy ){ yield return new WaitForSeconds( 0.01f ); } - - StartCoroutine( SaveTexture ( extension, mainGui._DiffuseMapOriginal, pathToFile + "_diffuseOriginal" ) ); - while( busy ){ yield return new WaitForSeconds( 0.01f ); } - - StartCoroutine( SaveTexture ( extension, mainGui._NormalMap, pathToFile + "_normal" ) ); - while( busy ){ yield return new WaitForSeconds( 0.01f ); } - - StartCoroutine( SaveTexture ( extension, mainGui._MetallicMap, pathToFile + "_metallic" ) ); - while( busy ){ yield return new WaitForSeconds( 0.01f ); } - - StartCoroutine( SaveTexture ( extension, mainGui._SmoothnessMap, pathToFile + "_smoothness" ) ); - while( busy ){ yield return new WaitForSeconds( 0.01f ); } - - StartCoroutine( SaveTexture ( extension, mainGui._EdgeMap, pathToFile + "_edge" ) ); - while( busy ){ yield return new WaitForSeconds( 0.01f ); } - - StartCoroutine( SaveTexture ( extension, mainGui._AOMap, pathToFile + "_ao" ) ); - while( busy ){ yield return new WaitForSeconds( 0.01f ); } - - yield return new WaitForSeconds( 0.01f ); - } - - - public IEnumerator SaveTexture( string extension, Texture2D textureToSave, string pathToFile ) { - busy = true; - - if (textureToSave != null) { - - FREE_IMAGE_FORMAT imageFormat = FREE_IMAGE_FORMAT.FIF_UNKNOWN; - FREE_IMAGE_SAVE_FLAGS flags = FREE_IMAGE_SAVE_FLAGS.DEFAULT; - - bool useFIF = true; - - switch ( extension.ToLower() ) { - case "bmp": - imageFormat = FREE_IMAGE_FORMAT.FIF_BMP; - break; - case "tga": - imageFormat = FREE_IMAGE_FORMAT.FIF_TARGA; - break; - case "tiff": - imageFormat = FREE_IMAGE_FORMAT.FIF_TIFF; - flags = FREE_IMAGE_SAVE_FLAGS.TIFF_NONE; - break; - case "png": - byte[] pngBytes = textureToSave.EncodeToPNG (); - File.WriteAllBytes (pathToFile + ".png", pngBytes); - useFIF = false; - //imageFormat = FREE_IMAGE_FORMAT.FIF_PNG; - break; - case "jpg": - byte[] jpgBytes = textureToSave.EncodeToJPG (); - File.WriteAllBytes (pathToFile + ".jpg", jpgBytes); - useFIF = false; - //imageFormat = FREE_IMAGE_FORMAT.FIF_JPEG; - //flags = FREE_IMAGE_SAVE_FLAGS.JPEG_QUALITYSUPERB; - break; - default: - imageFormat = FREE_IMAGE_FORMAT.FIF_UNKNOWN; - break; - } - - if( useFIF ){ - byte[] bytes = textureToSave.EncodeToPNG (); - - string tempFilePath = Application.dataPath + pathChar + "temp.png"; - //string tempFilePath = Application.persistentDataPath + pathChar + "temp.png"; - File.WriteAllBytes (tempFilePath, bytes); - - FIBITMAP bitmap = FreeImage_Load (FREE_IMAGE_FORMAT.FIF_PNG, tempFilePath, 0); - bool saveSuccess = FreeImage_Save (imageFormat, bitmap, pathToFile + "." + extension, flags ); - FreeImage_Unload(bitmap); - - //File.Delete (tempFilePath); - } - - Resources.UnloadUnusedAssets(); - - } - yield return new WaitForSeconds (0.01f); - busy = false; - - } - - //==============================================// - // Texture Loading Coroutines // - //==============================================// - - public IEnumerator LoadAllTextures( string pathToFile ) { - pathToFile = pathToFile.Substring (0, pathToFile.LastIndexOf (pathChar)); - pathToFile += pathChar; - - if (thisProject.heightMapPath != "null") { - StartCoroutine (LoadTexture (MapType.height, pathToFile + thisProject.heightMapPath)); - } - while( busy ){ yield return new WaitForSeconds( 0.01f ); } - - if (thisProject.diffuseMapOriginalPath != "null") { - StartCoroutine (LoadTexture (MapType.diffuseOriginal, pathToFile + thisProject.diffuseMapOriginalPath)); - } - while( busy ){ yield return new WaitForSeconds( 0.01f ); } - - if (thisProject.diffuseMapPath != "null") { - StartCoroutine (LoadTexture (MapType.diffuse, pathToFile + thisProject.diffuseMapPath)); - } - while( busy ){ yield return new WaitForSeconds( 0.01f ); } - - if (thisProject.normalMapPath != "null") { - StartCoroutine (LoadTexture (MapType.normal, pathToFile + thisProject.normalMapPath)); - } - while( busy ){ yield return new WaitForSeconds( 0.01f ); } - - if (thisProject.metallicMapPath != "null") { - StartCoroutine (LoadTexture (MapType.metallic, pathToFile + thisProject.metallicMapPath)); - } - while( busy ){ yield return new WaitForSeconds( 0.01f ); } - - if (thisProject.smoothnessMapPath != "null") { - StartCoroutine (LoadTexture (MapType.smoothness, pathToFile + thisProject.smoothnessMapPath)); - } - while( busy ){ yield return new WaitForSeconds( 0.01f ); } - - if (thisProject.edgeMapPath != "null") { - StartCoroutine (LoadTexture (MapType.edge, pathToFile + thisProject.edgeMapPath)); - } - while( busy ){ yield return new WaitForSeconds( 0.01f ); } - - if (thisProject.aoMapPath != "null") { - StartCoroutine (LoadTexture (MapType.ao, pathToFile + thisProject.aoMapPath)); - } - while( busy ){ yield return new WaitForSeconds( 0.01f ); } - - yield return new WaitForSeconds( 0.01f ); - } - - public IEnumerator LoadTexture( MapType textureToLoad, string pathToFile ) { - busy = true; - - int fileIndex = pathToFile.LastIndexOf ('.'); - string extension = pathToFile.Substring (fileIndex+1, pathToFile.Length-fileIndex-1); - - bool loadSuccess = false; - string newPathToFile = Application.dataPath + pathChar + "temp.png"; - //string newPathToFile = Application.persistentDataPath + pathChar + "temp.png"; - try { - // Load The Image - FREE_IMAGE_FORMAT imageFormat = FREE_IMAGE_FORMAT.FIF_UNKNOWN; - - switch ( extension.ToLower() ) { - case "bmp": - imageFormat = FREE_IMAGE_FORMAT.FIF_BMP; - break; - case "tga": - imageFormat = FREE_IMAGE_FORMAT.FIF_TARGA; - break; - case "tif": - imageFormat = FREE_IMAGE_FORMAT.FIF_TIFF; - break; - case "tiff": - imageFormat = FREE_IMAGE_FORMAT.FIF_TIFF; - break; - case "png": - imageFormat = FREE_IMAGE_FORMAT.FIF_PNG; - break; - case "jpg": - imageFormat = FREE_IMAGE_FORMAT.FIF_JPEG; - break; - case "jpeg": - imageFormat = FREE_IMAGE_FORMAT.FIF_JPEG; - break; - default: - imageFormat = FREE_IMAGE_FORMAT.FIF_UNKNOWN; - break; - } - - UnityEngine.Debug.Log ("Loading Image: " + pathToFile ); - - FIBITMAP bitmap = FreeImage_Load (imageFormat, pathToFile, 0); - - loadSuccess = FreeImage_Save (FREE_IMAGE_FORMAT.FIF_PNG, bitmap, newPathToFile, 0); - - FreeImage_Unload(bitmap); - - } - - catch (System.Exception e) { - UnityEngine.Debug.Log( e ); - UnityEngine.Debug.Log( "Could not import with Free Image Importer" ); - } - - if (loadSuccess) { - Texture2D newTexture; - - //var path = System.IO.Path.Combine("file:///"+Application.streamingAssetsPath,"image.png"); - WWW www = new WWW ("file:///" + newPathToFile); - yield return www; - newTexture = www.texture; - newTexture.anisoLevel = 9; - - - switch( textureToLoad ){ - case MapType.height: - mainGui._HeightMap = newTexture; - break; - case MapType.diffuse: - mainGui._DiffuseMap = newTexture; - break; - case MapType.diffuseOriginal: - mainGui._DiffuseMapOriginal = newTexture; - break; - case MapType.normal: - mainGui._NormalMap = newTexture; - break; - case MapType.metallic: - mainGui._MetallicMap = newTexture; - break; - case MapType.smoothness: - mainGui._SmoothnessMap = newTexture; - break; - case MapType.edge: - mainGui._EdgeMap = newTexture; - break; - case MapType.ao: - mainGui._AOMap = newTexture; - break; - default: - break; - } - - //File.Delete(newPathToFile); - - mainGui.SetLoadedTexture (textureToLoad); - - www.Dispose(); - - Resources.UnloadUnusedAssets(); - - } - - yield return new WaitForSeconds (0.01f); - - busy = false; - - } +public class SaveLoadProject : MonoBehaviour +{ + private char _pathChar; + private ProjectObject _thisProject; + + [HideInInspector] public bool Busy; + + // Use this for initialization + private void Start() + { + + if (Application.platform == RuntimePlatform.WindowsEditor || + Application.platform == RuntimePlatform.WindowsPlayer) + _pathChar = '\\'; + else + _pathChar = '/'; + + _thisProject = new ProjectObject(); + } + + public void LoadProject(string pathToFile) + { + Debug.Log("Loading Project: " + pathToFile); + + var serializer = new XmlSerializer(typeof(ProjectObject)); + var stream = new FileStream(pathToFile, FileMode.Open); + _thisProject = serializer.Deserialize(stream) as ProjectObject; + stream.Close(); + MainGui.Instance.HeightFromDiffuseGuiScript.SetValues(_thisProject); + MainGui.Instance.EditDiffuseGuiScript.SetValues(_thisProject); + MainGui.Instance.NormalFromHeightGuiScript.SetValues(_thisProject); + MainGui.Instance.MetallicGuiScript.SetValues(_thisProject); + MainGui.Instance.SmoothnessGuiScript.SetValues(_thisProject); + MainGui.Instance.EdgeFromNormalGuiScript.SetValues(_thisProject); + MainGui.Instance.AoFromNormalGuiScript.SetValues(_thisProject); + MainGui.Instance.MaterialGuiScript.SetValues(_thisProject); + + MainGui.Instance.ClearAllTextures(); + + StartCoroutine(LoadAllTextures(pathToFile)); + } + + public void SaveProject(string pathToFile) + { + if (pathToFile.Contains(".")) + pathToFile = pathToFile.Substring(0, pathToFile.LastIndexOf(".", StringComparison.Ordinal)); + + List extensions = new List(); + Debug.Log("Saving Project: " + pathToFile); + + var extension = MainGui.Instance.SelectedFormat.ToString().ToLower(); + var projectName = pathToFile.Substring(pathToFile.LastIndexOf(_pathChar) + 1); + Debug.Log("Project Name " + projectName); + + Debug.Log("test"); + MainGui.Instance.HeightFromDiffuseGuiScript.GetValues(_thisProject); + if (MainGui.Instance.HeightMap != null) + _thisProject.HeightMapPath = projectName + "_height." + extension; + else + _thisProject.HeightMapPath = "null"; + + MainGui.Instance.EditDiffuseGuiScript.GetValues(_thisProject); + if (MainGui.Instance.DiffuseMap != null) + _thisProject.DiffuseMapPath = projectName + "_diffuse." + extension; + else + _thisProject.DiffuseMapPath = "null"; + + if (MainGui.Instance.DiffuseMapOriginal != null) + _thisProject.DiffuseMapOriginalPath = projectName + "_diffuseOriginal." + extension; + else + _thisProject.DiffuseMapOriginalPath = "null"; + + MainGui.Instance.NormalFromHeightGuiScript.GetValues(_thisProject); + if (MainGui.Instance.NormalMap != null) + _thisProject.NormalMapPath = projectName + "_normal." + extension; + else + _thisProject.NormalMapPath = "null"; + + MainGui.Instance.MetallicGuiScript.GetValues(_thisProject); + if (MainGui.Instance.MetallicMap != null) + _thisProject.MetallicMapPath = projectName + "_metallic." + extension; + else + _thisProject.MetallicMapPath = "null"; + + MainGui.Instance.SmoothnessGuiScript.GetValues(_thisProject); + if (MainGui.Instance.SmoothnessMap != null) + _thisProject.SmoothnessMapPath = projectName + "_smoothness." + extension; + else + _thisProject.SmoothnessMapPath = "null"; + + MainGui.Instance.EdgeFromNormalGuiScript.GetValues(_thisProject); + if (MainGui.Instance.EdgeMap != null) + _thisProject.EdgeMapPath = projectName + "_edge." + extension; + else + _thisProject.EdgeMapPath = "null"; + + MainGui.Instance.AoFromNormalGuiScript.GetValues(_thisProject); + if (MainGui.Instance.AoMap != null) + _thisProject.AoMapPath = projectName + "_ao." + extension; + else + _thisProject.AoMapPath = "null"; + + MainGui.Instance.MaterialGuiScript.GetValues(_thisProject); + + var serializer = new XmlSerializer(typeof(ProjectObject)); + var stream = new FileStream(pathToFile + ".mtz", FileMode.Create); + serializer.Serialize(stream, _thisProject); + stream.Close(); + + SaveAllFiles(pathToFile); + + } + + public void SaveAllFiles(string pathToFile) + { + StartCoroutine(SaveAllTextures(pathToFile)); + } + + public void SaveFile(string pathToFile, Texture2D textureToSave) + { + SaveTexture(textureToSave, pathToFile); + } + + public void PasteFile(MapType mapTypeToLoad) + { + if (!RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + string tempImagePath = Application.dataPath + "/temp.png"; + //string tempImagePath = Application.persistentDataPath + "/temp.png"; + UnityEngine.Debug.Log(tempImagePath); + + try + { + Process myProcess = new Process(); + myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; + myProcess.StartInfo.CreateNoWindow = true; + myProcess.StartInfo.UseShellExecute = false; + myProcess.StartInfo.FileName = Application.streamingAssetsPath.Replace("/", "\\") + "\\c2i.exe"; + myProcess.StartInfo.Arguments = tempImagePath.Replace("/", "\\"); + myProcess.EnableRaisingEvents = true; + myProcess.Start(); + myProcess.WaitForExit(); + + StartCoroutine(LoadTexture(mapTypeToLoad, tempImagePath)); + } + catch (Exception e) + { + UnityEngine.Debug.Log(e); + } + } + else + { + const string filePrefix = "file:///"; + string pathToFile; + + var pathToTextFile = Path.GetTempFileName(); + BashRunner.Run($"xclip -selection clipboard -t TARGETS -o > {pathToTextFile}"); + var bashOut = File.ReadAllText(pathToTextFile); + + Debug.Log($"Out : {bashOut}"); + File.Delete(pathToTextFile); + + if (bashOut.Contains("image/png")) + { + pathToFile = Path.GetTempFileName() + ".png"; + BashRunner.Run($"xclip -selection clipboard -t image/png -o > {pathToFile}"); + } + else + { + BashRunner.Run($"xclip -selection clipboard -o > {pathToTextFile}"); + bashOut = File.ReadAllText(pathToTextFile); + + if (!bashOut.Contains(filePrefix)) return; + var supported = MainGui.LoadFormats.Any(format => bashOut.Contains(format)); + if (!supported) return; + + var firstIndex = bashOut.IndexOf("file:///", StringComparison.Ordinal); + var lastIndex = bashOut.IndexOf("\n", firstIndex, StringComparison.Ordinal); + var length = lastIndex - firstIndex; + pathToFile = bashOut.Substring(firstIndex, length); + pathToFile = pathToFile.Replace("file:///", "/"); + Debug.Log("Path " + pathToFile); + } + File.Delete(pathToTextFile); + + + StartCoroutine(LoadTexture(mapTypeToLoad, pathToFile)); + } + + } + + public void CopyFile(Texture2D textureToSave) + { + + SaveFile(Application.dataPath + "/temp.png", textureToSave); + //SaveFile(Application.persistentDataPath + "/temp.png",FileFormat.png,textureToSave, "" ); + + try + { + Process myProcess = new Process(); + myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; + myProcess.StartInfo.CreateNoWindow = true; + myProcess.StartInfo.UseShellExecute = false; + myProcess.StartInfo.FileName = Application.streamingAssetsPath.Replace("/", "\\") + "\\i2c.exe"; + myProcess.StartInfo.Arguments = Application.dataPath.Replace("/", "\\") + "\\temp.png"; + myProcess.EnableRaisingEvents = true; + myProcess.Start(); + myProcess.WaitForExit(); + } + catch (Exception e) + { + UnityEngine.Debug.Log(e); + } + } + + //==============================================// + // Texture Saving Coroutines // + //==============================================// + + + private IEnumerator SaveAllTextures(string pathToFile) + { + var path = pathToFile.Substring(0, pathToFile.LastIndexOf(_pathChar) + 1); + //yield return StartCoroutine(SaveTexture(MainGui.Instance.HeightMap, path + _thisProject.HeightMapPath)); + + //yield return StartCoroutine(SaveTexture(MainGui.Instance.DiffuseMap, path + _thisProject.DiffuseMapPath)); + + //yield return StartCoroutine(SaveTexture(MainGui.Instance.DiffuseMapOriginal, + // path + _thisProject.DiffuseMapOriginalPath)); + + //yield return StartCoroutine(SaveTexture(MainGui.Instance.NormalMap, path + _thisProject.NormalMapPath)); + + //yield return StartCoroutine(SaveTexture(MainGui.Instance.MetallicMap, path + _thisProject.MetallicMapPath)); + + //yield return StartCoroutine(SaveTexture(MainGui.Instance.SmoothnessMap, path + _thisProject.SmoothnessMapPath)); + + //yield return StartCoroutine(SaveTexture(MainGui.Instance.EdgeMap, path + _thisProject.EdgeMapPath)); + + //yield return StartCoroutine(SaveTexture(MainGui.Instance.AoMap, path + _thisProject.AoMapPath)); + + yield return SaveTexture(MainGui.Instance.HeightMap, path + _thisProject.HeightMapPath); + + yield return SaveTexture(MainGui.Instance.DiffuseMap, path + _thisProject.DiffuseMapPath); + + yield return SaveTexture(MainGui.Instance.DiffuseMapOriginal, + path + _thisProject.DiffuseMapOriginalPath); + + yield return SaveTexture(MainGui.Instance.NormalMap, path + _thisProject.NormalMapPath); -} + yield return SaveTexture(MainGui.Instance.MetallicMap, path + _thisProject.MetallicMapPath); + + yield return SaveTexture(MainGui.Instance.SmoothnessMap, path + _thisProject.SmoothnessMapPath); + + yield return SaveTexture(MainGui.Instance.EdgeMap, path + _thisProject.EdgeMapPath); + + yield return SaveTexture(MainGui.Instance.AoMap, path + _thisProject.AoMapPath); + + MainGui.Instance.Modle.SetActive(true); + } + + public async Task SaveTexture(string extension, Texture2D textureToSave, string pathToFile) + { + await (SaveTexture(textureToSave, pathToFile + "." + extension)); + } + + private async Task SaveTexture(Texture2D textureToSave, string pathToFile) + { + if (!textureToSave || pathToFile.IsNullOrEmpty()) return; + if (MainGui.Instance.ScaleTexture) + { + //TextureScale.BilinearScale(_textureToSave); + textureToSave = TextureScale.Bilinear(textureToSave, int.Parse(MainGui.Instance.XSize), int.Parse(MainGui.Instance.YSize)); + } + + Debug.Log($"Saved {textureToSave} To {pathToFile}"); + if (!pathToFile.Contains(".")) pathToFile = $"{pathToFile}.{MainGui.Instance.SelectedFormat}"; + + var fileIndex = pathToFile.LastIndexOf('.'); + var extension = pathToFile.Substring(fileIndex + 1, pathToFile.Length - fileIndex - 1); + + switch (extension) + { + case "png": + { + var pngBytes = textureToSave.EncodeToPNG(); + File.WriteAllBytes(pathToFile, pngBytes); + break; + } + case "jpg": + { + var jpgBytes = textureToSave.EncodeToJPG(); + File.WriteAllBytes(pathToFile, jpgBytes); + break; + } + case "tga": + { + var tgaBytes = textureToSave.EncodeToTGA(); + File.WriteAllBytes(pathToFile, tgaBytes); + break; + } + case "exr": + { + var exrBytes = textureToSave.EncodeToEXR(); + File.WriteAllBytes(pathToFile, exrBytes); + break; + } + default: + throw new ArgumentOutOfRangeException(nameof(extension), extension, null); + } + + Resources.UnloadUnusedAssets(); + + + //yield return new WaitForSeconds(0.1f); + } + + //==============================================// + // Texture Loading Coroutines // + //==============================================// + + private IEnumerator LoadAllTextures(string pathToFile) + { + pathToFile = pathToFile.Substring(0, pathToFile.LastIndexOf(_pathChar) + 1); + + if (_thisProject.HeightMapPath != "null") + StartCoroutine(LoadTexture(MapType.Height, pathToFile + _thisProject.HeightMapPath)); + + while (Busy) yield return new WaitForSeconds(0.01f); + + if (_thisProject.DiffuseMapOriginalPath != "null") + StartCoroutine(LoadTexture(MapType.DiffuseOriginal, pathToFile + _thisProject.DiffuseMapOriginalPath)); + + while (Busy) yield return new WaitForSeconds(0.01f); + + if (_thisProject.DiffuseMapPath != "null") + StartCoroutine(LoadTexture(MapType.Diffuse, pathToFile + _thisProject.DiffuseMapPath)); + + while (Busy) yield return new WaitForSeconds(0.01f); + + if (_thisProject.NormalMapPath != "null") + StartCoroutine(LoadTexture(MapType.Normal, pathToFile + _thisProject.NormalMapPath)); + + while (Busy) yield return new WaitForSeconds(0.01f); + + if (_thisProject.MetallicMapPath != "null") + StartCoroutine(LoadTexture(MapType.Metallic, pathToFile + _thisProject.MetallicMapPath)); + + while (Busy) yield return new WaitForSeconds(0.01f); + + if (_thisProject.SmoothnessMapPath != "null") + StartCoroutine(LoadTexture(MapType.Smoothness, pathToFile + _thisProject.SmoothnessMapPath)); + + while (Busy) yield return new WaitForSeconds(0.01f); + + if (_thisProject.EdgeMapPath != "null") + StartCoroutine(LoadTexture(MapType.Edge, pathToFile + _thisProject.EdgeMapPath)); + + while (Busy) yield return new WaitForSeconds(0.01f); + + if (_thisProject.AoMapPath != "null") + StartCoroutine(LoadTexture(MapType.Ao, pathToFile + _thisProject.AoMapPath)); + + while (Busy) yield return new WaitForSeconds(0.01f); + + yield return new WaitForSeconds(0.01f); + } + + + + public IEnumerator LoadTexture(MapType textureToLoad, string pathToFile) + { + Busy = true; + + Texture2D newTexture = null; + pathToFile = Uri.UnescapeDataString(pathToFile); + + if (File.Exists(pathToFile)) + { + var fileData = File.ReadAllBytes(pathToFile); + newTexture = new Texture2D(2, 2); + newTexture.LoadImage(fileData); //..this will auto-resize the texture dimensions. + } + + if (!newTexture) yield break; + newTexture.anisoLevel = 9; + + + switch (textureToLoad) + { + case MapType.Height: + MainGui.Instance.HeightMap = newTexture; + break; + case MapType.Diffuse: + MainGui.Instance.DiffuseMap = newTexture; + break; + case MapType.DiffuseOriginal: + MainGui.Instance.DiffuseMap = newTexture; + MainGui.Instance.DiffuseMapOriginal = newTexture; + break; + case MapType.Normal: + MainGui.Instance.NormalMap = newTexture; + break; + case MapType.Metallic: + MainGui.Instance.MetallicMap = newTexture; + break; + case MapType.Smoothness: + MainGui.Instance.SmoothnessMap = newTexture; + break; + case MapType.Edge: + MainGui.Instance.EdgeMap = newTexture; + break; + case MapType.Ao: + MainGui.Instance.AoMap = newTexture; + break; + case MapType.Property: + break; + default: + throw new ArgumentOutOfRangeException(nameof(textureToLoad), textureToLoad, null); + } + + MainGui.Instance.SetLoadedTexture(textureToLoad); + + Resources.UnloadUnusedAssets(); + + + yield return new WaitForSeconds(0.01f); + + Busy = false; + } +} \ No newline at end of file diff --git a/Assets/Scripts/ScreenGuard.cs b/Assets/Scripts/ScreenGuard.cs deleted file mode 100644 index 5bc7c1d1..00000000 --- a/Assets/Scripts/ScreenGuard.cs +++ /dev/null @@ -1,43 +0,0 @@ -using UnityEngine; - -/// -/// Should use temporarily until Unity3d-team fix the bug -/// http://issuetracker.unity3d.com/issues/input-when-resizing-window-input-dot-mouseposition-will-be-clamped-by-the-original-window-size -/// -public class ScreenGuard : MonoBehaviour { - - private int prevWidth; - private int prevHeight; - - private bool isInited = false; - - - private void Start() - { - prevWidth = Screen.width; - prevHeight = Screen.height; - - isInited = true; - } - - private void SetResolution() - { - prevWidth = Screen.width; - prevHeight = Screen.height; - - Screen.SetResolution(Screen.width, Screen.height, Screen.fullScreen); - } - - public void Update() - { - if (!isInited) - { - Start(); - } - - if ((Screen.width != prevWidth) || (Screen.height != prevHeight)) - { - SetResolution(); - } - } -} \ No newline at end of file diff --git a/Assets/Scripts/SettingsGui.cs b/Assets/Scripts/SettingsGui.cs index 77435b14..6c90c3d3 100644 --- a/Assets/Scripts/SettingsGui.cs +++ b/Assets/Scripts/SettingsGui.cs @@ -1,220 +1,263 @@ -using UnityEngine; -using System.Collections; -using System.IO; - -using FreeImageAPI; -using System.Runtime.InteropServices; +#region -using System.Xml; +using System.IO; using System.Xml.Serialization; +using UnityEngine; -public class Settings { +#endregion - public bool normalMapMaxStyle; - public bool normalMapMayaStyle; +public class Settings +{ + public FileFormat FileFormat; + public bool NormalMapMaxStyle; + public bool NormalMapMayaStyle; - public bool postProcessEnabled; - - public PropChannelMap propRed; - public PropChannelMap propGreen; - public PropChannelMap propBlue; - - public FileFormat fileFormat; + public bool PostProcessEnabled; + public PropChannelMap PropBlue; + public PropChannelMap PropGreen; + public PropChannelMap PropRed; } -public class SettingsGui : MonoBehaviour { - - public MainGui mainGui; - public PostProcessGui postProcessGui; - - Rect windowRect = new Rect (Screen.width - 300, Screen.height - 320, 280, 600); - bool windowOpen = false; - public Settings settings = new Settings(); - - public static SettingsGui instance; - - char pathChar; - - // Use this for initialization - void Start () { - - instance = this; - - if (Application.platform == RuntimePlatform.WindowsEditor || Application.platform == RuntimePlatform.WindowsPlayer) { - pathChar = '\\'; - } else { - pathChar = '/'; - } - - LoadSettings (); - - } - - string GetPathToFile(){ - - string pathToFile = Application.dataPath; - //string pathToFile = Application.persistentDataPath; - - if (Application.isEditor) { - pathToFile = pathToFile + "/settings.txt"; - } else { - pathToFile = pathToFile.Substring (0, pathToFile.Length - 16) + "settings.txt"; - } - return pathToFile; - } - - public void LoadSettings(){ - - string pathToFile = GetPathToFile(); - - Debug.Log (pathToFile); - //if (File.Exists (pathToFile)) { - //FileAttributes fileAttributes = File.GetAttributes(pathToFile); - //if ((fileAttributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly) { - //File.SetAttributes (pathToFile, FileAttributes.Normal); - //} - //} - - if (System.IO.File.Exists (pathToFile)) { - var serializer = new XmlSerializer (typeof(Settings)); - var stream = new FileStream (pathToFile, FileMode.Open); - settings = serializer.Deserialize (stream) as Settings; - stream.Close (); - } else { - settings.normalMapMaxStyle = true; - settings.normalMapMayaStyle = false; - settings.postProcessEnabled = true; - settings.propRed = PropChannelMap.None; - settings.propGreen = PropChannelMap.None; - settings.propBlue = PropChannelMap.None; - settings.fileFormat = FileFormat.bmp; - SaveSettings(); - } - - SetSettings (); - - } - - void SaveSettings(){ - - string pathToFile = GetPathToFile(); - - Debug.Log (pathToFile); - - if (File.Exists (pathToFile)) { - //FileAttributes fileAttributes = File.GetAttributes(pathToFile); - //if ((fileAttributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly) { - File.SetAttributes (pathToFile, FileAttributes.Normal); - //} - } - - var serializer = new XmlSerializer (typeof(Settings)); - var stream = new FileStream (pathToFile, FileMode.Create); - serializer.Serialize (stream, settings); - stream.Close (); - } - - void SetNormalMode(){ - int flipNormalY = 0; - if (settings.normalMapMayaStyle) { - flipNormalY = 1; - } - - Shader.SetGlobalInt ("_FlipNormalY", flipNormalY); - } - - public void SetSettings(){ - SetNormalMode (); - - if( settings.postProcessEnabled ){ - postProcessGui.PostProcessOn(); - }else{ - postProcessGui.PostProcessOff(); - } - - mainGui.propRed = settings.propRed; - mainGui.propGreen = settings.propGreen; - mainGui.propBlue = settings.propBlue; - - mainGui.SetFormat( settings.fileFormat ); - } - - // Update is called once per frame - void Update () { - - } - - void DoMyWindow ( int windowID ) { - - int offsetX = 10; - int offsetY = 30; - - GUI.Label (new Rect (offsetX, offsetY, 250, 30), "Normal Map Style" ); - - offsetY += 30; - - settings.normalMapMaxStyle = GUI.Toggle (new Rect (offsetX, offsetY, 100, 30), settings.normalMapMaxStyle, " Max Style"); - if ( settings.normalMapMaxStyle ) { - settings.normalMapMayaStyle = false; - } else { - settings.normalMapMayaStyle = true; - } - - - settings.normalMapMayaStyle = GUI.Toggle (new Rect (offsetX + 100, offsetY, 100, 30), settings.normalMapMayaStyle, " Maya Style"); - if (settings.normalMapMayaStyle) { - settings.normalMapMaxStyle = false; - } else { - settings.normalMapMaxStyle = true; - } - - offsetY += 30; - - settings.postProcessEnabled = GUI.Toggle (new Rect (offsetX, offsetY, 280, 30), settings.postProcessEnabled, " Enable Post Process By Default"); - - offsetY += 30; - - if (GUI.Button (new Rect (offsetX, offsetY, 260, 25), "Set Default Property Map Channels")) { - settings.propRed = mainGui.propRed; - settings.propGreen = mainGui.propGreen; - settings.propBlue = mainGui.propBlue; - } - - offsetY += 30; - - if (GUI.Button (new Rect (offsetX, offsetY, 260, 25), "Set Default File Format")) { - settings.fileFormat = mainGui.selectedFormat; - } - - offsetY += 40; - - if (GUI.Button (new Rect (offsetX + 140, offsetY, 120, 30), "Save and Close")) { - SaveSettings(); - SetNormalMode(); - windowOpen = false; - } - - GUI.DragWindow (); - } - - void OnGUI () { - - windowRect = new Rect (Screen.width - 300, Screen.height - 320, 280, 230); - - if (windowOpen){ - windowRect = GUI.Window (20, windowRect, DoMyWindow, "Setting and Preferences"); - } - - if (GUI.Button (new Rect(Screen.width - 280, Screen.height - 40, 80, 30), "Settings")) { - if( windowOpen == true){ - SaveSettings(); - windowOpen = false; - }else{ - windowOpen = true; - } - } - - } -} +public class SettingsGui : MonoBehaviour +{ + private const string SettingsKey = "Settings"; + public static SettingsGui Instance; + private static readonly int FlipNormalY = Shader.PropertyToID("_FlipNormalY"); + private bool _windowOpen; + + private Rect _windowRect = new Rect(Screen.width - 300, Screen.height - 320, 280, 600); + public PostProcessGui PostProcessGui; + [HideInInspector] public Settings Settings = new Settings(); + public ObjRotator OBJRotator; + public GameObject SettingsMenu; + + private void Start() + { + Instance = this; + + LoadSettings(); + } + + public void LoadSettings() + { + if (PlayerPrefs.HasKey(SettingsKey)) + { + var set = PlayerPrefs.GetString(SettingsKey); + var serializer = new XmlSerializer(typeof(Settings)); + using (TextReader sr = new StringReader(set)) + { + Settings = serializer.Deserialize(sr) as Settings; + } + } + else + { + Settings.NormalMapMaxStyle = true; + Settings.NormalMapMayaStyle = false; + Settings.PostProcessEnabled = true; + Settings.PropRed = PropChannelMap.None; + Settings.PropGreen = PropChannelMap.None; + Settings.PropBlue = PropChannelMap.None; + Settings.FileFormat = FileFormat.Png; + SaveSettings(); + } + + SetSettings(); + } + + public void SaveSettings() + { + var serializer = new XmlSerializer(typeof(Settings)); + using (TextWriter sw = new StringWriter()) + { + serializer.Serialize(sw, Settings); + PlayerPrefs.SetString(SettingsKey, sw.ToString()); + } + } + + public void SetNormalMode() + { + var flipNormalY = 0; + if (Settings.NormalMapMayaStyle) flipNormalY = 1; + + Shader.SetGlobalInt(FlipNormalY, flipNormalY); + } + + public void SetSettings() + { + SetNormalMode(); + + if (Settings.PostProcessEnabled) + PostProcessGui.PostProcessOn(); + else + PostProcessGui.PostProcessOff(); + + var mainGui = MainGui.Instance; + mainGui.PropRed = Settings.PropRed; + mainGui.PropGreen = Settings.PropGreen; + mainGui.PropBlue = Settings.PropBlue; + + mainGui.SetFormat(Settings.FileFormat); + } + + private void DoMyWindow(int windowId) + { + const int offsetX = 10; + + var offsetY = 30; + + OBJRotator.AllowHideUI = GUI.Toggle(new Rect(offsetX, offsetY, 150, 30), OBJRotator.AllowHideUI, "Hide UI On Rotate"); + + offsetY += 20; + + GUI.Label(new Rect(offsetX, offsetY, 250, 30), "Normal Map Style"); + + offsetY += 30; + + Settings.NormalMapMaxStyle = + GUI.Toggle(new Rect(offsetX, offsetY, 100, 30), Settings.NormalMapMaxStyle, " Max Style"); + Settings.NormalMapMayaStyle = !Settings.NormalMapMaxStyle; + + + Settings.NormalMapMayaStyle = GUI.Toggle(new Rect(offsetX + 100, offsetY, 100, 30), Settings.NormalMapMayaStyle, + " Maya Style"); + Settings.NormalMapMaxStyle = !Settings.NormalMapMayaStyle; + + offsetY += 30; + + Settings.PostProcessEnabled = GUI.Toggle(new Rect(offsetX, offsetY, 280, 30), Settings.PostProcessEnabled, + " Enable Post Process By Default"); + + offsetY += 20; + GUI.Label(new Rect(offsetX, offsetY, 250, 30), "Limit Frame Rate"); + + offsetY += 20; + + if (GUI.Button(new Rect(offsetX + 40, offsetY, 30, 30), "30")) + { + Application.targetFrameRate = 30; + QualitySettings.vSyncCount = 0; + PlayerPrefs.SetInt("targetFrameRate", 30); + PlayerPrefs.SetInt("Vsync", 0); + } + if (GUI.Button(new Rect(offsetX + 80, offsetY, 30, 30), "60")) + { + Application.targetFrameRate = 60; + QualitySettings.vSyncCount = 0; + PlayerPrefs.SetInt("targetFrameRate", 60); + PlayerPrefs.SetInt("Vsync", 0); + } + if (GUI.Button(new Rect(offsetX + 120, offsetY, 30, 30), "120")) + { + Application.targetFrameRate = 120; + QualitySettings.vSyncCount = 0; + PlayerPrefs.SetInt("targetFrameRate", 120); + PlayerPrefs.SetInt("Vsync", 0); + } + + if (GUI.Button(new Rect(offsetX + 160, offsetY, 40, 30), "None")) + { + //Application.targetFrameRate = 120; + QualitySettings.vSyncCount = 1; + // PlayerPrefs.SetInt("targetFrameRate", 30); + PlayerPrefs.SetInt("Vsync", 1); + } + + offsetY += 40; + + + if (GUI.Button(new Rect(offsetX, offsetY, 260, 25), "Set Default Property Map Channels")) + { + Settings.PropRed = MainGui.Instance.PropRed; + Settings.PropGreen = MainGui.Instance.PropGreen; + Settings.PropBlue = MainGui.Instance.PropBlue; + } + + offsetY += 30; + + if (GUI.Button(new Rect(offsetX, offsetY, 260, 25), "Set Default File Format")) + Settings.FileFormat = FileFormat.Png; + + offsetY += 40; + + if (GUI.Button(new Rect(offsetX + 140, offsetY, 120, 30), "Save and Close")) + { + SaveSettings(); + SetNormalMode(); + _windowOpen = false; + } + + GUI.DragWindow(); + } + public void SetFrameRate(int FrameRate) + { + Application.targetFrameRate = FrameRate; + QualitySettings.vSyncCount = 0; + PlayerPrefs.SetInt("targetFrameRate", FrameRate); + PlayerPrefs.SetInt("Vsync", 0); + } + public void SetVsyncOn() + { + //Application.targetFrameRate = 120; + QualitySettings.vSyncCount = 1; + // PlayerPrefs.SetInt("targetFrameRate", 30); + PlayerPrefs.SetInt("Vsync", 1); + } + public void SaveDefaultFileFormat() + { + Settings.FileFormat = FileFormat.Png; + } + + public void SaveAndClose() + { + SaveSettings(); + SetNormalMode(); + } + + public void setDefaultPropertyMap() + { + Settings.PropRed = MainGui.Instance.PropRed; + Settings.PropGreen = MainGui.Instance.PropGreen; + Settings.PropBlue = MainGui.Instance.PropBlue; + + } + + public void NormalMapMaxStyle(bool Bool) + { + Settings.NormalMapMaxStyle = Bool; + Settings.NormalMapMayaStyle = !Bool; + } + + public void NormalMapMayaStyle(bool Bool) + { + Settings.NormalMapMayaStyle = Bool; + Settings.NormalMapMaxStyle = !Bool; + } + + public void SetPostProcessing(bool Bool) + { + Settings.PostProcessEnabled = Bool; + } + public void SetHideUI(bool Bool) { + OBJRotator.AllowHideUI = Bool; + } + /* + private void OnGUI() + { + _windowRect = new Rect(Screen.width - 300, Screen.height - 360, 280, 300); + + if (_windowOpen) _windowRect = GUI.Window(20, _windowRect, DoMyWindow, "Setting and Preferences"); + + if (!GUI.Button(new Rect(Screen.width - 280, Screen.height - 40, 80, 30), "Settings")) return; + if (_windowOpen) + { + SaveSettings(); + SettingsMenu.SetActive(false); + } + else + { + SettingsMenu.SetActive(true); + } + }*/ +} \ No newline at end of file diff --git a/Assets/Scripts/SmoothnessGui.cs b/Assets/Scripts/SmoothnessGui.cs index 2ba2d738..ba2c64f8 100644 --- a/Assets/Scripts/SmoothnessGui.cs +++ b/Assets/Scripts/SmoothnessGui.cs @@ -1,820 +1,708 @@ -using UnityEngine; +#region + +using System; using System.Collections; -using System.ComponentModel; - -public class SmoothnessSettings { - - //[DefaultValueAttribute(Color.black)] - public Color SampleColor1; - //[DefaultValueAttribute(Vector2.zero)] - public Vector2 SampleUV1; - - //[DefaultValueAttribute(Color.black)] - public Color SampleColor2; - //[DefaultValueAttribute(Vector2.zero)] - public Vector2 SampleUV2; - - //[DefaultValueAttribute(Color.black)] - public Color SampleColor3; - //[DefaultValueAttribute(Vector2.zero)] - public Vector2 SampleUV3; - - [DefaultValueAttribute(0.7f)] - public float MetalSmoothness; - [DefaultValueAttribute("0.7")] - public string MetalSmoothnessText; - - [DefaultValueAttribute(false)] - public bool UseSample1; - [DefaultValueAttribute(false)] - public bool IsolateSample1; - [DefaultValueAttribute(1.0f)] - public float HueWeight1; - [DefaultValueAttribute(0.5f)] - public float SatWeight1; - [DefaultValueAttribute(0.2f)] - public float LumWeight1; - [DefaultValueAttribute(0.0f)] - public float MaskLow1; - [DefaultValueAttribute(1.0f)] - public float MaskHigh1; - [DefaultValueAttribute(0.5f)] - public float Sample1Smoothness; - - [DefaultValueAttribute(false)] - public bool UseSample2; - [DefaultValueAttribute(false)] - public bool IsolateSample2; - [DefaultValueAttribute(1.0f)] - public float HueWeight2; - [DefaultValueAttribute(0.5f)] - public float SatWeight2; - [DefaultValueAttribute(0.2f)] - public float LumWeight2; - [DefaultValueAttribute(0.0f)] - public float MaskLow2; - [DefaultValueAttribute(1.0f)] - public float MaskHigh2; - [DefaultValueAttribute(0.3f)] - public float Sample2Smoothness; - - [DefaultValueAttribute(false)] - public bool UseSample3; - [DefaultValueAttribute(false)] - public bool IsolateSample3; - [DefaultValueAttribute(1.0f)] - public float HueWeight3; - [DefaultValueAttribute(0.5f)] - public float SatWeight3; - [DefaultValueAttribute(0.2f)] - public float LumWeight3; - [DefaultValueAttribute(0.0f)] - public float MaskLow3; - [DefaultValueAttribute(1.0f)] - public float MaskHigh3; - [DefaultValueAttribute(0.2f)] - public float Sample3Smoothness; - - [DefaultValueAttribute(0.1f)] - public float BaseSmoothness; - [DefaultValueAttribute("0.1")] - public string BaseSmoothnessText; - - [DefaultValueAttribute(0)] - public int BlurSize; - [DefaultValueAttribute("0")] - public string BlurSizeText; - - [DefaultValueAttribute(30)] - public int OverlayBlurSize; - [DefaultValueAttribute("30")] - public string OverlayBlurSizeText; - - [DefaultValueAttribute(3.0f)] - public float BlurOverlay; - [DefaultValueAttribute("3")] - public string BlurOverlayText; - - [DefaultValueAttribute(1.0f)] - public float FinalContrast; - [DefaultValueAttribute("1")] - public string FinalContrastText; - - [DefaultValueAttribute(0.0f)] - public float FinalBias; - [DefaultValueAttribute("0")] - public string FinalBiasText; - - [DefaultValueAttribute(false)] - public bool useAdjustedDiffuse; - [DefaultValueAttribute(true)] - public bool useOriginalDiffuse; - - public SmoothnessSettings(){ - - this.SampleColor1 = Color.black; - this.SampleUV1 = Vector2.zero; - - this.SampleColor2 = Color.black; - this.SampleUV2 = Vector2.zero; - - this.SampleColor3 = Color.black; - this.SampleUV3 = Vector2.zero; - - this.MetalSmoothness = 0.7f; - this.MetalSmoothnessText = "0.7"; - - this.UseSample1 = false; - this.IsolateSample1 = false; - this.HueWeight1 = 1.0f; - this.SatWeight1 = 0.5f; - this.LumWeight1 = 0.2f; - this.MaskLow1 = 0.0f; - this.MaskHigh1 = 1.0f; - this.Sample1Smoothness = 0.5f; - - this.UseSample2 = false; - this.IsolateSample2 = false; - this.HueWeight2 = 1.0f; - this.SatWeight2 = 0.5f; - this.LumWeight2 = 0.2f; - this.MaskLow2 = 0.0f; - this.MaskHigh2 = 1.0f; - this.Sample2Smoothness = 0.3f; - - this.UseSample3 = false; - this.IsolateSample3 = false; - this.HueWeight3 = 1.0f; - this.SatWeight3 = 0.5f; - this.LumWeight3 = 0.2f; - this.MaskLow3 = 0.0f; - this.MaskHigh3 = 1.0f; - this.Sample3Smoothness = 0.2f; - - this.BaseSmoothness = 0.1f; - this.BaseSmoothnessText = "0.1"; - - this.BlurSize = 0; - this.BlurSizeText = "0"; - - this.OverlayBlurSize = 30; - this.OverlayBlurSizeText = "30"; - - this.BlurOverlay = 3.0f; - this.BlurOverlayText = "3"; - - this.FinalContrast = 1.0f; - this.FinalContrastText = "1"; - - this.FinalBias = 0.0f; - this.FinalBiasText = "0"; - - this.useAdjustedDiffuse = false; - this.useOriginalDiffuse = true; - } - -} - -public class SmoothnessGui : MonoBehaviour { - - public MainGui MainGuiScript; - - public Texture2D _DefaultMetallicMap; - - Texture2D _DiffuseMap; - Texture2D _DiffuseMapOriginal; - - Texture2D _MetallicMap; - Texture2D _SmoothnessMap; - - Texture2D _SampleColorMap1; - Texture2D _SampleColorMap2; - Texture2D _SampleColorMap3; - - RenderTexture _TempMap; - RenderTexture _BlurMap; - RenderTexture _OverlayBlurMap; - - public Material thisMaterial; - Material blitMaterial; - Material blitSmoothnessMaterial; - - int imageSizeX; - int imageSizeY; - - int currentSelection = 0; - - SmoothnessSettings SS; - - float Slider = 0.5f; - bool lastUseAdjustedDiffuse = false; - - Rect windowRect = new Rect (30, 300, 300, 530); - - public GameObject testObject; - bool doStuff = false; - bool newTexture = false; - - bool selectingColor = false; - bool mouseButtonDown = false; - - bool settingsInitialized = false; - - public bool busy = false; - - public void GetValues( ProjectObject projectObject ) { - InitializeSettings (); - projectObject.SS = SS; - } - - public void SetValues( ProjectObject projectObject ) { - InitializeSettings (); - if (projectObject.SS != null) { - SS = projectObject.SS; - } else { - settingsInitialized = false; - InitializeSettings (); - } - - _SampleColorMap1.SetPixel (1, 1, SS.SampleColor1); - _SampleColorMap1.Apply (); - - _SampleColorMap2.SetPixel (1, 1, SS.SampleColor2); - _SampleColorMap2.Apply (); - - _SampleColorMap3.SetPixel (1, 1, SS.SampleColor3); - _SampleColorMap3.Apply (); - - doStuff = true; - - } - - void InitializeSettings() { - - if (settingsInitialized == false) { - - SS = new SmoothnessSettings (); - - _SampleColorMap1 = new Texture2D (1, 1, TextureFormat.ARGB32, false, true); - _SampleColorMap1.SetPixel (1, 1, SS.SampleColor1); - _SampleColorMap1.Apply (); - - _SampleColorMap2 = new Texture2D (1, 1, TextureFormat.ARGB32, false, true); - _SampleColorMap2.SetPixel (1, 1, SS.SampleColor2); - _SampleColorMap2.Apply (); - - _SampleColorMap3 = new Texture2D (1, 1, TextureFormat.ARGB32, false, true); - _SampleColorMap3.SetPixel (1, 1, SS.SampleColor3); - _SampleColorMap3.Apply (); - - settingsInitialized = true; - } - - } - - // Use this for initialization - void Start () { - - testObject.GetComponent().sharedMaterial = thisMaterial; - - blitMaterial = new Material (Shader.Find ("Hidden/Blit_Shader")); - blitSmoothnessMaterial = new Material (Shader.Find ("Hidden/Blit_Smoothness")); - - InitializeSettings (); - - } - - public void DoStuff() { - doStuff = true; - } - - public void NewTexture() { - newTexture = true; - } - - // Update is called once per frame - void Update () { - - if (selectingColor) { - SelectColor(); - } - - if (newTexture) { - InitializeTextures(); - newTexture = false; - } - - if (SS.useAdjustedDiffuse != lastUseAdjustedDiffuse) { - lastUseAdjustedDiffuse = SS.useAdjustedDiffuse; - doStuff = true; - } - - if (doStuff) { - StartCoroutine( ProcessBlur () ); - doStuff = false; - } - - //thisMaterial.SetFloat ("_BlurWeight", BlurWeight); - - thisMaterial.SetFloat ( "_MetalSmoothness", SS.MetalSmoothness); - - if (SS.IsolateSample1) { - thisMaterial.SetInt ("_IsolateSample1", 1); - } else { - thisMaterial.SetInt ("_IsolateSample1", 0); - } - if( SS.UseSample1){ - thisMaterial.SetInt ("_UseSample1", 1); - } else { - thisMaterial.SetInt ("_UseSample1", 0); - } - thisMaterial.SetColor ( "_SampleColor1", SS.SampleColor1); - thisMaterial.SetVector ( "_SampleUV1", new Vector4 (SS.SampleUV1.x, SS.SampleUV1.y, 0, 0)); - thisMaterial.SetFloat ( "_HueWeight1", SS.HueWeight1 ); - thisMaterial.SetFloat ( "_SatWeight1", SS.SatWeight1 ); - thisMaterial.SetFloat ( "_LumWeight1", SS.LumWeight1 ); - thisMaterial.SetFloat ( "_MaskLow1", SS.MaskLow1 ); - thisMaterial.SetFloat ( "_MaskHigh1", SS.MaskHigh1 ); - thisMaterial.SetFloat ( "_Sample1Smoothness", SS.Sample1Smoothness); - - if (SS.IsolateSample2) { - thisMaterial.SetInt ("_IsolateSample2", 1); - } else { - thisMaterial.SetInt ("_IsolateSample2", 0); - } - if( SS.UseSample2){ - thisMaterial.SetInt ("_UseSample2", 1); - } else { - thisMaterial.SetInt ("_UseSample2", 0); - } - thisMaterial.SetColor ( "_SampleColor2", SS.SampleColor2); - thisMaterial.SetVector ( "_SampleUV2", new Vector4 (SS.SampleUV2.x, SS.SampleUV2.y, 0, 0)); - thisMaterial.SetFloat ( "_HueWeight2", SS.HueWeight2 ); - thisMaterial.SetFloat ( "_SatWeight2", SS.SatWeight2 ); - thisMaterial.SetFloat ( "_LumWeight2", SS.LumWeight2 ); - thisMaterial.SetFloat ( "_MaskLow2", SS.MaskLow2 ); - thisMaterial.SetFloat ( "_MaskHigh2", SS.MaskHigh2 ); - thisMaterial.SetFloat ( "_Sample2Smoothness", SS.Sample2Smoothness); - - if (SS.IsolateSample3) { - thisMaterial.SetInt ("_IsolateSample3", 1); - } else { - thisMaterial.SetInt ("_IsolateSample3", 0); - } - if( SS.UseSample3){ - thisMaterial.SetInt ("_UseSample3", 1); - } else { - thisMaterial.SetInt ("_UseSample3", 0); - } - thisMaterial.SetColor ( "_SampleColor3", SS.SampleColor3); - thisMaterial.SetVector ( "_SampleUV3", new Vector4 (SS.SampleUV3.x, SS.SampleUV3.y, 0, 0)); - thisMaterial.SetFloat ( "_HueWeight3", SS.HueWeight3 ); - thisMaterial.SetFloat ( "_SatWeight3", SS.SatWeight3 ); - thisMaterial.SetFloat ( "_LumWeight3", SS.LumWeight3 ); - thisMaterial.SetFloat ( "_MaskLow3", SS.MaskLow3 ); - thisMaterial.SetFloat ( "_MaskHigh3", SS.MaskHigh3 ); - thisMaterial.SetFloat ( "_Sample3Smoothness", SS.Sample3Smoothness); - - thisMaterial.SetFloat ( "_BaseSmoothness", SS.BaseSmoothness); - - thisMaterial.SetFloat ( "_Slider", Slider); - thisMaterial.SetFloat ( "_BlurOverlay", SS.BlurOverlay); - thisMaterial.SetFloat ( "_FinalContrast", SS.FinalContrast); - thisMaterial.SetFloat ( "_FinalBias", SS.FinalBias); - - if ( SS.useAdjustedDiffuse ) { - thisMaterial.SetTexture ("_MainTex", _DiffuseMap); - } else { - thisMaterial.SetTexture ("_MainTex", _DiffuseMapOriginal); - } - - } - - void SelectColor() { - if ( Input.GetMouseButton(0) ) { - - mouseButtonDown = true; - - RaycastHit hit; - if (!Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit)) - return; - - Renderer rend = hit.transform.GetComponent(); - MeshCollider meshCollider = hit.collider as MeshCollider; - if (rend == null || rend.sharedMaterial == null || rend.sharedMaterial.mainTexture == null || meshCollider == null) - return; - - Vector2 pixelUV = hit.textureCoord; - - Color sampledColor = Color.black; - if( SS.useAdjustedDiffuse){ - sampledColor = _DiffuseMap.GetPixelBilinear(pixelUV.x, pixelUV.y); - }else{ - sampledColor = _DiffuseMapOriginal.GetPixelBilinear(pixelUV.x, pixelUV.y); - } - - if( currentSelection == 1 ){ - SS.SampleUV1 = pixelUV; - SS.SampleColor1 = sampledColor; - _SampleColorMap1.SetPixel (1, 1, SS.SampleColor1); - _SampleColorMap1.Apply (); - } - - if( currentSelection == 2 ){ - SS.SampleUV2 = pixelUV; - SS.SampleColor2 = sampledColor; - _SampleColorMap2.SetPixel (1, 1, SS.SampleColor2); - _SampleColorMap2.Apply (); - } - - if( currentSelection == 3 ){ - SS.SampleUV3 = pixelUV; - SS.SampleColor3 = sampledColor; - _SampleColorMap3.SetPixel (1, 1, SS.SampleColor3); - _SampleColorMap3.Apply (); - } - - } - - if ( Input.GetMouseButtonUp(0) && mouseButtonDown ) { - - mouseButtonDown = false; - selectingColor = false; - currentSelection = 0; - - } - - } - - void DoMyWindow ( int windowID ) { - - int spacingX = 0; - int spacingY = 50; - int spacing2Y = 70; - - int offsetX = 10; - int offsetY = 30; - - if (_DiffuseMap != null) { GUI.enabled = true; } else { GUI.enabled = false; } - if( GUI.Toggle (new Rect (offsetX, offsetY, 140, 30), SS.useAdjustedDiffuse, " Use Edited Diffuse")) { - SS.useAdjustedDiffuse = true; - SS.useOriginalDiffuse = false; - } - GUI.enabled = true; - if (GUI.Toggle (new Rect (offsetX + 150, offsetY, 140, 30), SS.useOriginalDiffuse, " Use Original Diffuse")) { - SS.useAdjustedDiffuse = false; - SS.useOriginalDiffuse = true; - } - - offsetY += 30; - - GUI.Label (new Rect (offsetX, offsetY, 250, 30), "Smoothness Reveal Slider" ); - Slider = GUI.HorizontalSlider( new Rect( offsetX, offsetY + 20, 280, 10 ),Slider,0.0f, 1.0f ); - offsetY += 40; - - GuiHelper.Slider (new Rect (offsetX, offsetY, 280, 50), "Metal Smoothness", SS.MetalSmoothness, SS.MetalSmoothnessText, out SS.MetalSmoothness, out SS.MetalSmoothnessText, 0.0f, 1.0f ); - offsetY += 40; - - SS.UseSample1 = GUI.Toggle (new Rect (offsetX, offsetY, 150, 20), SS.UseSample1, "Use Color Sample 1"); - if (SS.UseSample1) { - - SS.IsolateSample1 = GUI.Toggle (new Rect (offsetX + 180, offsetY, 150, 20), SS.IsolateSample1, "Isolate Mask"); - if( SS.IsolateSample1 ){ - SS.IsolateSample2 = false; - SS.IsolateSample3 = false; - } - offsetY += 30; - - if ( GUI.Button (new Rect (offsetX, offsetY + 5, 80, 20), "Pick Color") ) { - selectingColor = true; - currentSelection = 1; - } - - GUI.DrawTexture (new Rect (offsetX + 10, offsetY + 35, 60, 60), _SampleColorMap1); - - GUI.Label (new Rect (offsetX + 90, offsetY, 250, 30), "Hue"); - SS.HueWeight1 = GUI.VerticalSlider (new Rect (offsetX + 95, offsetY + 30, 10, 70), SS.HueWeight1, 1.0f, 0.0f); - - GUI.Label (new Rect (offsetX + 120, offsetY, 250, 30), "Sat"); - SS.SatWeight1 = GUI.VerticalSlider (new Rect (offsetX + 125, offsetY + 30, 10, 70), SS.SatWeight1, 1.0f, 0.0f); - - GUI.Label (new Rect (offsetX + 150, offsetY, 250, 30), "Lum"); - SS.LumWeight1 = GUI.VerticalSlider (new Rect (offsetX + 155, offsetY + 30, 10, 70), SS.LumWeight1, 1.0f, 0.0f); - - GUI.Label (new Rect (offsetX + 180, offsetY, 250, 30), "Low"); - SS.MaskLow1 = GUI.VerticalSlider (new Rect (offsetX + 185, offsetY + 30, 10, 70), SS.MaskLow1, 1.0f, 0.0f); - - GUI.Label (new Rect (offsetX + 210, offsetY, 250, 30), "High"); - SS.MaskHigh1 = GUI.VerticalSlider (new Rect (offsetX + 215, offsetY + 30, 10, 70), SS.MaskHigh1, 1.0f, 0.0f); - - GUI.Label (new Rect (offsetX + 240, offsetY, 250, 30), "Smooth"); - SS.Sample1Smoothness = GUI.VerticalSlider (new Rect (offsetX + 255, offsetY + 30, 10, 70), SS.Sample1Smoothness, 1.0f, 0.0f); - - offsetY += 110; - } else { - offsetY += 30; - SS.IsolateSample1 = false; - } - - - SS.UseSample2 = GUI.Toggle (new Rect (offsetX, offsetY, 150, 20), SS.UseSample2, "Use Color Sample 2"); - if (SS.UseSample2) { - - SS.IsolateSample2 = GUI.Toggle (new Rect (offsetX + 180, offsetY, 150, 20), SS.IsolateSample2, "Isolate Mask"); - if( SS.IsolateSample2 ){ - SS.IsolateSample1 = false; - SS.IsolateSample3 = false; - } - offsetY += 30; - - if ( GUI.Button (new Rect (offsetX, offsetY + 5, 80, 20), "Pick Color") ) { - selectingColor = true; - currentSelection = 2; - } - - GUI.DrawTexture (new Rect (offsetX + 10, offsetY + 35, 60, 60), _SampleColorMap2); - - GUI.Label (new Rect (offsetX + 90, offsetY, 250, 30), "Hue"); - SS.HueWeight2 = GUI.VerticalSlider (new Rect (offsetX + 95, offsetY + 30, 10, 70), SS.HueWeight2, 1.0f, 0.0f); - - GUI.Label (new Rect (offsetX + 120, offsetY, 250, 30), "Sat"); - SS.SatWeight2 = GUI.VerticalSlider (new Rect (offsetX + 125, offsetY + 30, 10, 70), SS.SatWeight2, 1.0f, 0.0f); - - GUI.Label (new Rect (offsetX + 150, offsetY, 250, 30), "Lum"); - SS.LumWeight2 = GUI.VerticalSlider (new Rect (offsetX + 155, offsetY + 30, 10, 70), SS.LumWeight2, 1.0f, 0.0f); - - GUI.Label (new Rect (offsetX + 180, offsetY, 250, 30), "Low"); - SS.MaskLow2 = GUI.VerticalSlider (new Rect (offsetX + 185, offsetY + 30, 10, 70), SS.MaskLow2, 1.0f, 0.0f); - - GUI.Label (new Rect (offsetX + 210, offsetY, 250, 30), "High"); - SS.MaskHigh2 = GUI.VerticalSlider (new Rect (offsetX + 215, offsetY + 30, 10, 70), SS.MaskHigh2, 1.0f, 0.0f); - - GUI.Label (new Rect (offsetX + 240, offsetY, 250, 30), "Smooth"); - SS.Sample2Smoothness = GUI.VerticalSlider (new Rect (offsetX + 255, offsetY + 30, 10, 70), SS.Sample2Smoothness, 1.0f, 0.0f); - - offsetY += 110; - } else { - offsetY += 30; - SS.IsolateSample2 = false; - } - - GuiHelper.Slider (new Rect (offsetX, offsetY, 280, 50), "Base Smoothness", SS.BaseSmoothness, SS.BaseSmoothnessText, out SS.BaseSmoothness, out SS.BaseSmoothnessText, 0.0f, 1.0f ); - offsetY += 40; - - if (GuiHelper.Slider (new Rect (offsetX, offsetY, 280, 50), "Sample Blur Size", SS.BlurSize, SS.BlurSizeText, out SS.BlurSize, out SS.BlurSizeText, 0, 100)) { - doStuff = true; - } - offsetY += 40; - - if (GuiHelper.Slider (new Rect (offsetX, offsetY, 280, 50), "High Pass Blur Size", SS.OverlayBlurSize, SS.OverlayBlurSizeText, out SS.OverlayBlurSize, out SS.OverlayBlurSizeText, 10, 100)) { - doStuff = true; - } - offsetY += 40; - - GuiHelper.Slider (new Rect (offsetX, offsetY, 280, 50), "High Pass Overlay", SS.BlurOverlay, SS.BlurOverlayText, out SS.BlurOverlay, out SS.BlurOverlayText, -10.0f, 10.0f ); - offsetY += 40; - - GuiHelper.Slider (new Rect (offsetX, offsetY, 280, 50), "Final Contrast", SS.FinalContrast, SS.FinalContrastText, out SS.FinalContrast, out SS.FinalContrastText, -2.0f, 2.0f ); - offsetY += 40; - - GuiHelper.Slider (new Rect (offsetX, offsetY, 280, 50), "Final Bias", SS.FinalBias, SS.FinalBiasText, out SS.FinalBias, out SS.FinalBiasText, -0.5f, 0.5f ); - offsetY += 50; - - if( GUI.Button (new Rect (offsetX, offsetY, 130, 30), "Set as Smoothness" ) ){ - StartCoroutine( ProcessSmoothness() ); - } - - GUI.DragWindow(); - - } - - void OnGUI () { - - windowRect.width = 300; - windowRect.height = 490; - - if (SS.UseSample1) { - windowRect.height += 110; - } - - if (SS.UseSample2) { - windowRect.height += 110; - } - - windowRect = GUI.Window(17, windowRect, DoMyWindow, "Smoothness From Diffuse"); - - } - - public void Close(){ - CleanupTextures (); - this.gameObject.SetActive (false); - } - - void CleanupTexture( RenderTexture _Texture ) { - - if (_Texture != null) { - _Texture.Release(); - _Texture = null; - } - - } - - void CleanupTextures() { - - Debug.Log ("Cleaning Up Textures"); - - CleanupTexture( _BlurMap ); - CleanupTexture( _OverlayBlurMap ); - CleanupTexture( _TempMap ); - - } - - public void InitializeTextures() { - - testObject.GetComponent().sharedMaterial = thisMaterial; - - CleanupTextures (); - - _DiffuseMap = MainGuiScript._DiffuseMap; - _DiffuseMapOriginal = MainGuiScript._DiffuseMapOriginal; - - _MetallicMap = MainGuiScript._MetallicMap; - if (_MetallicMap != null) { - thisMaterial.SetTexture ("_MetallicTex", _MetallicMap); - } else { - thisMaterial.SetTexture ("_MetallicTex", _DefaultMetallicMap); - } - - if (_DiffuseMap) { - thisMaterial.SetTexture ("_MainTex", _DiffuseMap); - imageSizeX = _DiffuseMap.width; - imageSizeY = _DiffuseMap.height; - } else { - thisMaterial.SetTexture ("_MainTex", _DiffuseMapOriginal); - imageSizeX = _DiffuseMapOriginal.width; - imageSizeY = _DiffuseMapOriginal.height; - - SS.useAdjustedDiffuse = false; - SS.useOriginalDiffuse = true; - } - - Debug.Log ( "Initializing Textures of size: " + imageSizeX.ToString() + "x" + imageSizeY.ToString() ); - - _TempMap = new RenderTexture (imageSizeX, imageSizeY, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear ); - _TempMap.wrapMode = TextureWrapMode.Repeat; - _BlurMap = new RenderTexture (imageSizeX, imageSizeY, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear ); - _BlurMap.wrapMode = TextureWrapMode.Repeat; - _OverlayBlurMap = new RenderTexture (imageSizeX, imageSizeY, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear ); - _OverlayBlurMap.wrapMode = TextureWrapMode.Repeat; - - } - - public IEnumerator ProcessSmoothness() { - - busy = true; - - Debug.Log ("Processing Height"); - - blitSmoothnessMaterial.SetVector ("_ImageSize", new Vector4 (imageSizeX, imageSizeY, 0, 0)); - - if (_MetallicMap != null) { - blitSmoothnessMaterial.SetTexture ("_MetallicTex", _MetallicMap); - } else { - blitSmoothnessMaterial.SetTexture ("_MetallicTex", _DefaultMetallicMap); - } - - - blitSmoothnessMaterial.SetTexture ("_BlurTex", _BlurMap); - - blitSmoothnessMaterial.SetTexture ("_OverlayBlurTex", _OverlayBlurMap); - - blitSmoothnessMaterial.SetFloat ( "_MetalSmoothness", SS.MetalSmoothness); - - if( SS.UseSample1){ - blitSmoothnessMaterial.SetInt ("_UseSample1", 1); - } else { - blitSmoothnessMaterial.SetInt ("_UseSample1", 0); - } - blitSmoothnessMaterial.SetColor ( "_SampleColor1", SS.SampleColor1); - blitSmoothnessMaterial.SetVector ( "_SampleUV1", new Vector4 (SS.SampleUV1.x, SS.SampleUV1.y, 0, 0)); - blitSmoothnessMaterial.SetFloat ( "_HueWeight1", SS.HueWeight1 ); - blitSmoothnessMaterial.SetFloat ( "_SatWeight1", SS.SatWeight1 ); - blitSmoothnessMaterial.SetFloat ( "_LumWeight1", SS.LumWeight1 ); - blitSmoothnessMaterial.SetFloat ( "_MaskLow1", SS.MaskLow1 ); - blitSmoothnessMaterial.SetFloat ( "_MaskHigh1", SS.MaskHigh1 ); - blitSmoothnessMaterial.SetFloat ( "_Sample1Smoothness", SS.Sample1Smoothness); - - if( SS.UseSample2){ - blitSmoothnessMaterial.SetInt ("_UseSample2", 1); - } else { - blitSmoothnessMaterial.SetInt ("_UseSample2", 0); - } - blitSmoothnessMaterial.SetColor ( "_SampleColor2", SS.SampleColor2); - blitSmoothnessMaterial.SetVector ( "_SampleUV2", new Vector4 (SS.SampleUV2.x, SS.SampleUV2.y, 0, 0)); - blitSmoothnessMaterial.SetFloat ( "_HueWeight2", SS.HueWeight2 ); - blitSmoothnessMaterial.SetFloat ( "_SatWeight2", SS.SatWeight2 ); - blitSmoothnessMaterial.SetFloat ( "_LumWeight2", SS.LumWeight2 ); - blitSmoothnessMaterial.SetFloat ( "_MaskLow2", SS.MaskLow2 ); - blitSmoothnessMaterial.SetFloat ( "_MaskHigh2", SS.MaskHigh2 ); - blitSmoothnessMaterial.SetFloat ( "_Sample2Smoothness", SS.Sample2Smoothness); - - if( SS.UseSample3){ - blitSmoothnessMaterial.SetInt ("_UseSample3", 1); - } else { - blitSmoothnessMaterial.SetInt ("_UseSample3", 0); - } - blitSmoothnessMaterial.SetColor ( "_SampleColor3", SS.SampleColor3); - blitSmoothnessMaterial.SetVector ( "_SampleUV3", new Vector4 (SS.SampleUV3.x, SS.SampleUV3.y, 0, 0)); - blitSmoothnessMaterial.SetFloat ( "_HueWeight3", SS.HueWeight3 ); - blitSmoothnessMaterial.SetFloat ( "_SatWeight3", SS.SatWeight3 ); - blitSmoothnessMaterial.SetFloat ( "_LumWeight3", SS.LumWeight3 ); - blitSmoothnessMaterial.SetFloat ( "_MaskLow3", SS.MaskLow3 ); - blitSmoothnessMaterial.SetFloat ( "_MaskHigh3", SS.MaskHigh3 ); - blitSmoothnessMaterial.SetFloat ( "_Sample3Smoothness", SS.Sample3Smoothness); - - blitSmoothnessMaterial.SetFloat ( "_BaseSmoothness", SS.BaseSmoothness); - - blitSmoothnessMaterial.SetFloat ( "_BlurOverlay", SS.BlurOverlay); - blitSmoothnessMaterial.SetFloat ( "_FinalContrast", SS.FinalContrast); - blitSmoothnessMaterial.SetFloat ( "_FinalBias", SS.FinalBias); - - CleanupTexture (_TempMap); - _TempMap = new RenderTexture (imageSizeX, imageSizeY, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear); - _TempMap.wrapMode = TextureWrapMode.Repeat; - - if ( SS.useAdjustedDiffuse ) { - Graphics.Blit( _DiffuseMap, _TempMap, blitSmoothnessMaterial, 0 ); - } else { - Graphics.Blit( _DiffuseMapOriginal, _TempMap, blitSmoothnessMaterial, 0 ); - } - - RenderTexture.active = _TempMap; - - if (MainGuiScript._SmoothnessMap != null) { - Destroy (MainGuiScript._SmoothnessMap); - } - - MainGuiScript._SmoothnessMap = new Texture2D (_TempMap.width, _TempMap.height, TextureFormat.ARGB32, true, true); - MainGuiScript._SmoothnessMap.ReadPixels (new Rect (0, 0, _TempMap.width, _TempMap.height), 0, 0); - MainGuiScript._SmoothnessMap.Apply (); - - yield return new WaitForSeconds(0.01f); - - CleanupTexture ( _TempMap ); - - busy = false; - - } - - public IEnumerator ProcessBlur ( ) { - - busy = true; - - Debug.Log ("Processing Blur"); - - blitMaterial.SetVector ("_ImageSize", new Vector4( imageSizeX, imageSizeY, 0, 0 ) ); - blitMaterial.SetFloat ("_BlurContrast", 1.0f); - blitMaterial.SetFloat ("_BlurSpread", 1.0f); - - // Blur the image for selection - blitMaterial.SetInt ("_BlurSamples", SS.BlurSize); - blitMaterial.SetVector ("_BlurDirection", new Vector4(1,0,0,0) ); - if ( SS.useAdjustedDiffuse ) { - if (SS.BlurSize == 0) { - Graphics.Blit (_DiffuseMap, _TempMap); - } else { - Graphics.Blit (_DiffuseMap, _TempMap, blitMaterial, 1); - } - } else { - if (SS.BlurSize == 0) { - Graphics.Blit (_DiffuseMapOriginal, _TempMap); - } else { - Graphics.Blit (_DiffuseMapOriginal, _TempMap, blitMaterial, 1); - } - } - blitMaterial.SetVector ("_BlurDirection", new Vector4(0,1,0,0) ); - if (SS.BlurSize == 0) { - Graphics.Blit (_TempMap, _BlurMap); - } else { - Graphics.Blit (_TempMap, _BlurMap, blitMaterial, 1); - } - thisMaterial.SetTexture ("_BlurTex", _BlurMap); - - // Blur the image for overlay - blitMaterial.SetInt ("_BlurSamples", SS.OverlayBlurSize); - blitMaterial.SetVector ("_BlurDirection", new Vector4(1,0,0,0) ); - if ( SS.useAdjustedDiffuse ) { - Graphics.Blit( _DiffuseMap, _TempMap, blitMaterial, 1 ); - } else { - Graphics.Blit( _DiffuseMapOriginal, _TempMap, blitMaterial, 1 ); - } - blitMaterial.SetVector ("_BlurDirection", new Vector4(0,1,0,0) ); - Graphics.Blit(_TempMap, _OverlayBlurMap, blitMaterial, 1); - thisMaterial.SetTexture ("_OverlayBlurTex", _OverlayBlurMap); - - yield return new WaitForSeconds(0.01f); - - busy = false; - - } -} +using UnityEngine; + +#endregion + +// ReSharper disable Unity.PreferAddressByIdToGraphicsParams + +public class SmoothnessGui : MonoBehaviour +{ + private static readonly int MetalSmoothness = Shader.PropertyToID("_MetalSmoothness"); + private static readonly int IsolateSample1 = Shader.PropertyToID("_IsolateSample1"); + private static readonly int UseSample1 = Shader.PropertyToID("_UseSample1"); + private static readonly int SampleColor1 = Shader.PropertyToID("_SampleColor1"); + private static readonly int SampleUv1 = Shader.PropertyToID("_SampleUV1"); + private static readonly int HueWeight1 = Shader.PropertyToID("_HueWeight1"); + private static readonly int SatWeight1 = Shader.PropertyToID("_SatWeight1"); + private static readonly int LumWeight1 = Shader.PropertyToID("_LumWeight1"); + private static readonly int MaskLow1 = Shader.PropertyToID("_MaskLow1"); + private static readonly int MaskHigh1 = Shader.PropertyToID("_MaskHigh1"); + private static readonly int Sample1Smoothness = Shader.PropertyToID("_Sample1Smoothness"); + private static readonly int IsolateSample2 = Shader.PropertyToID("_IsolateSample2"); + private static readonly int UseSample2 = Shader.PropertyToID("_UseSample2"); + private static readonly int SampleColor2 = Shader.PropertyToID("_SampleColor2"); + private static readonly int SampleUv2 = Shader.PropertyToID("_SampleUV2"); + private static readonly int HueWeight2 = Shader.PropertyToID("_HueWeight2"); + private static readonly int SatWeight2 = Shader.PropertyToID("_SatWeight2"); + private static readonly int LumWeight2 = Shader.PropertyToID("_LumWeight2"); + private static readonly int MaskLow2 = Shader.PropertyToID("_MaskLow2"); + private static readonly int MaskHigh2 = Shader.PropertyToID("_MaskHigh2"); + private static readonly int Sample2Smoothness = Shader.PropertyToID("_Sample2Smoothness"); + private static readonly int IsolateSample3 = Shader.PropertyToID("_IsolateSample3"); + private static readonly int UseSample3 = Shader.PropertyToID("_UseSample3"); + private static readonly int SampleColor3 = Shader.PropertyToID("_SampleColor3"); + private static readonly int SampleUv3 = Shader.PropertyToID("_SampleUV3"); + private static readonly int HueWeight3 = Shader.PropertyToID("_HueWeight3"); + private static readonly int SatWeight3 = Shader.PropertyToID("_SatWeight3"); + private static readonly int LumWeight3 = Shader.PropertyToID("_LumWeight3"); + private static readonly int MaskLow3 = Shader.PropertyToID("_MaskLow3"); + private static readonly int MaskHigh3 = Shader.PropertyToID("_MaskHigh3"); + private static readonly int Sample3Smoothness = Shader.PropertyToID("_Sample3Smoothness"); + private static readonly int BaseSmoothness = Shader.PropertyToID("_BaseSmoothness"); + private static readonly int Slider = Shader.PropertyToID("_Slider"); + private static readonly int BlurOverlay = Shader.PropertyToID("_BlurOverlay"); + private static readonly int FinalContrast = Shader.PropertyToID("_FinalContrast"); + private static readonly int FinalBias = Shader.PropertyToID("_FinalBias"); + private static readonly int MainTex = Shader.PropertyToID("_MainTex"); + private static readonly int MetallicTex = Shader.PropertyToID("_MetallicTex"); + private static readonly int Invert = Shader.PropertyToID("_Invert"); + private Material _blitMaterial; + private RenderTexture _blurMap; + private Camera _camera; + + private int _currentSelection; + + private Texture2D _diffuseMap; + private Texture2D _diffuseMapOriginal; + private bool _doStuff; + + private int _imageSizeX; + private int _imageSizeY; + private bool _lastUseAdjustedDiffuse; + + private Texture2D _metallicMap; + private bool _mouseButtonDown; + private bool _newTexture; + private RenderTexture _overlayBlurMap; + + private Texture2D _sampleColorMap1; + private Texture2D _sampleColorMap2; + private Texture2D _sampleColorMap3; + + private bool _selectingColor; + private bool _invert; + + private SmoothnessSettings _settings; + + private bool _settingsInitialized; + + private float _slider = 0.5f; + private Texture2D _smoothnessMap; + + private RenderTexture _tempMap; + + private Rect _windowRect = new Rect(30, 300, 300, 530); + + [HideInInspector] public bool Busy; + + public Texture2D DefaultMetallicMap; + + public MainGui MainGuiScript; + + public GameObject TestObject; + + public Material ThisMaterial; + private void Awake() + { + _camera = Camera.main; + + } + + public void GetValues(ProjectObject projectObject) + { + InitializeSettings(); + projectObject.SmoothnessSettings = _settings; + } + + public void SetValues(ProjectObject projectObject) + { + InitializeSettings(); + if (projectObject.SmoothnessSettings != null) + { + _settings = projectObject.SmoothnessSettings; + } + else + { + _settingsInitialized = false; + InitializeSettings(); + } + + _sampleColorMap1.SetPixel(1, 1, _settings.SampleColor1); + _sampleColorMap1.Apply(); + + _sampleColorMap2.SetPixel(1, 1, _settings.SampleColor2); + _sampleColorMap2.Apply(); + + _sampleColorMap3.SetPixel(1, 1, _settings.SampleColor3); + _sampleColorMap3.Apply(); + + _doStuff = true; + } + + private void InitializeSettings() + { + if (_settingsInitialized) return; + _settings = new SmoothnessSettings(); + + _sampleColorMap1 = new Texture2D(1, 1, TextureFormat.ARGB32, false, true); + _sampleColorMap1.SetPixel(1, 1, _settings.SampleColor1); + _sampleColorMap1.Apply(); + + _sampleColorMap2 = new Texture2D(1, 1, TextureFormat.ARGB32, false, true); + _sampleColorMap2.SetPixel(1, 1, _settings.SampleColor2); + _sampleColorMap2.Apply(); + + _sampleColorMap3 = new Texture2D(1, 1, TextureFormat.ARGB32, false, true); + _sampleColorMap3.SetPixel(1, 1, _settings.SampleColor3); + _sampleColorMap3.Apply(); + + _settingsInitialized = true; + } + + // Use this for initialization + private void Start() + { + TestObject.GetComponent().sharedMaterial = ThisMaterial; + + _blitMaterial = new Material(Shader.Find("Hidden/Blit_Shader")); + + InitializeSettings(); + } + + public void DoStuff() + { + _doStuff = true; + } + + public void NewTexture() + { + _newTexture = true; + } + + + // Update is called once per frame + private void Update() + { + if (_selectingColor) SelectColor(); + + if (_newTexture) + { + InitializeTextures(); + _newTexture = false; + } + + if (_settings.UseAdjustedDiffuse != _lastUseAdjustedDiffuse) + { + _lastUseAdjustedDiffuse = _settings.UseAdjustedDiffuse; + _doStuff = true; + } + + if (_doStuff) + { + StartCoroutine(ProcessBlur()); + _doStuff = false; + } + + //thisMaterial.SetFloat ("_BlurWeight", BlurWeight); + + ThisMaterial.SetFloat(MetalSmoothness, _settings.MetalSmoothness); + + ThisMaterial.SetInt(IsolateSample1, _settings.IsolateSample1 ? 1 : 0); + ThisMaterial.SetInt(UseSample1, _settings.UseSample1 ? 1 : 0); + ThisMaterial.SetColor(SampleColor1, _settings.SampleColor1); + ThisMaterial.SetVector(SampleUv1, new Vector4(_settings.SampleUv1.x, _settings.SampleUv1.y, 0, 0)); + ThisMaterial.SetFloat(HueWeight1, _settings.HueWeight1); + ThisMaterial.SetFloat(SatWeight1, _settings.SatWeight1); + ThisMaterial.SetFloat(LumWeight1, _settings.LumWeight1); + ThisMaterial.SetFloat(MaskLow1, _settings.MaskLow1); + ThisMaterial.SetFloat(MaskHigh1, _settings.MaskHigh1); + ThisMaterial.SetFloat(Sample1Smoothness, _settings.Sample1Smoothness); + + ThisMaterial.SetInt(IsolateSample2, _settings.IsolateSample2 ? 1 : 0); + ThisMaterial.SetInt(UseSample2, _settings.UseSample2 ? 1 : 0); + ThisMaterial.SetColor(SampleColor2, _settings.SampleColor2); + ThisMaterial.SetVector(SampleUv2, new Vector4(_settings.SampleUv2.x, _settings.SampleUv2.y, 0, 0)); + ThisMaterial.SetFloat(HueWeight2, _settings.HueWeight2); + ThisMaterial.SetFloat(SatWeight2, _settings.SatWeight2); + ThisMaterial.SetFloat(LumWeight2, _settings.LumWeight2); + ThisMaterial.SetFloat(MaskLow2, _settings.MaskLow2); + ThisMaterial.SetFloat(MaskHigh2, _settings.MaskHigh2); + ThisMaterial.SetFloat(Sample2Smoothness, _settings.Sample2Smoothness); + + ThisMaterial.SetInt(IsolateSample3, _settings.IsolateSample3 ? 1 : 0); + ThisMaterial.SetInt(UseSample3, _settings.UseSample3 ? 1 : 0); + ThisMaterial.SetColor(SampleColor3, _settings.SampleColor3); + ThisMaterial.SetVector(SampleUv3, new Vector4(_settings.SampleUv3.x, _settings.SampleUv3.y, 0, 0)); + ThisMaterial.SetFloat(HueWeight3, _settings.HueWeight3); + ThisMaterial.SetFloat(SatWeight3, _settings.SatWeight3); + ThisMaterial.SetFloat(LumWeight3, _settings.LumWeight3); + ThisMaterial.SetFloat(MaskLow3, _settings.MaskLow3); + ThisMaterial.SetFloat(MaskHigh3, _settings.MaskHigh3); + ThisMaterial.SetFloat(Sample3Smoothness, _settings.Sample3Smoothness); + int invert = 0; + if (_settings.Invert) + { + invert = 1; + } + ThisMaterial.SetInt(Invert, invert); + ThisMaterial.SetFloat(BaseSmoothness, _settings.BaseSmoothness); + + ThisMaterial.SetFloat(Slider, _slider); + ThisMaterial.SetFloat(BlurOverlay, _settings.BlurOverlay); + ThisMaterial.SetFloat(FinalContrast, _settings.FinalContrast); + ThisMaterial.SetFloat(FinalBias, _settings.FinalBias); + + ThisMaterial.SetTexture(MainTex, _settings.UseAdjustedDiffuse ? _diffuseMap : _diffuseMapOriginal); + } + + private void SelectColor() + { + if (Input.GetMouseButton(0)) + { + _mouseButtonDown = true; + + if (!Physics.Raycast(_camera.ScreenPointToRay(Input.mousePosition), out var hit)) + return; + + var rend = hit.transform.GetComponent(); + var meshCollider = hit.collider as MeshCollider; + if (!rend || !rend.sharedMaterial || !rend.sharedMaterial.mainTexture || !meshCollider) + return; + + var pixelUv = hit.textureCoord; + + var sampledColor = _settings.UseAdjustedDiffuse + ? _diffuseMap.GetPixelBilinear(pixelUv.x, pixelUv.y) + : _diffuseMapOriginal.GetPixelBilinear(pixelUv.x, pixelUv.y); + + switch (_currentSelection) + { + case 1: + _settings.SampleUv1 = pixelUv; + _settings.SampleColor1 = sampledColor; + _sampleColorMap1.SetPixel(1, 1, _settings.SampleColor1); + _sampleColorMap1.Apply(); + break; + case 2: + _settings.SampleUv2 = pixelUv; + _settings.SampleColor2 = sampledColor; + _sampleColorMap2.SetPixel(1, 1, _settings.SampleColor2); + _sampleColorMap2.Apply(); + break; + case 3: + _settings.SampleUv3 = pixelUv; + _settings.SampleColor3 = sampledColor; + _sampleColorMap3.SetPixel(1, 1, _settings.SampleColor3); + _sampleColorMap3.Apply(); + break; + default: + throw new InvalidOperationException(); + } + } + + if (!Input.GetMouseButtonUp(0) || !_mouseButtonDown) return; + _mouseButtonDown = false; + _selectingColor = false; + _currentSelection = 0; + } + + private void DoMyWindow(int windowId) + { + const int offsetX = 10; + var offsetY = 30; + + GUI.enabled = _diffuseMap != null; + if (GUI.Toggle(new Rect(offsetX, offsetY, 140, 30), _settings.UseAdjustedDiffuse, " Use Edited Diffuse")) + { + _settings.UseAdjustedDiffuse = true; + _settings.UseOriginalDiffuse = false; + } + + GUI.enabled = true; + if (GUI.Toggle(new Rect(offsetX + 150, offsetY, 140, 30), _settings.UseOriginalDiffuse, + " Use Original Diffuse")) + { + _settings.UseAdjustedDiffuse = false; + _settings.UseOriginalDiffuse = true; + } + + offsetY += 30; + + GUI.Label(new Rect(offsetX, offsetY, 250, 30), "Smoothness Reveal Slider"); + _slider = GUI.HorizontalSlider(new Rect(offsetX, offsetY + 20, 280, 10), _slider, 0.0f, 1.0f); + offsetY += 40; + + GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Metal Smoothness", _settings.MetalSmoothness, + _settings.MetalSmoothnessText, out _settings.MetalSmoothness, out _settings.MetalSmoothnessText, 0.0f, + 1.0f); + offsetY += 40; + + _settings.UseSample1 = + GUI.Toggle(new Rect(offsetX, offsetY, 150, 20), _settings.UseSample1, "Use Color Sample 1"); + if (_settings.UseSample1) + { + _settings.IsolateSample1 = + GUI.Toggle(new Rect(offsetX + 180, offsetY, 150, 20), _settings.IsolateSample1, "Isolate Mask"); + if (_settings.IsolateSample1) + { + _settings.IsolateSample2 = false; + _settings.IsolateSample3 = false; + } + + offsetY += 30; + + if (GUI.Button(new Rect(offsetX, offsetY + 5, 80, 20), "Pick Color")) + { + _selectingColor = true; + _currentSelection = 1; + } + + GUI.DrawTexture(new Rect(offsetX + 10, offsetY + 35, 60, 60), _sampleColorMap1); + + GUI.Label(new Rect(offsetX + 90, offsetY, 250, 30), "Hue"); + _settings.HueWeight1 = GUI.VerticalSlider(new Rect(offsetX + 95, offsetY + 30, 10, 70), + _settings.HueWeight1, 1.0f, 0.0f); + + GUI.Label(new Rect(offsetX + 120, offsetY, 250, 30), "Sat"); + _settings.SatWeight1 = + GUI.VerticalSlider(new Rect(offsetX + 125, offsetY + 30, 10, 70), _settings.SatWeight1, 1.0f, 0.0f); + + GUI.Label(new Rect(offsetX + 150, offsetY, 250, 30), "Lum"); + _settings.LumWeight1 = + GUI.VerticalSlider(new Rect(offsetX + 155, offsetY + 30, 10, 70), _settings.LumWeight1, 1.0f, 0.0f); + + GUI.Label(new Rect(offsetX + 180, offsetY, 250, 30), "Low"); + _settings.MaskLow1 = GUI.VerticalSlider(new Rect(offsetX + 185, offsetY + 30, 10, 70), _settings.MaskLow1, + 1.0f, 0.0f); + + GUI.Label(new Rect(offsetX + 210, offsetY, 250, 30), "High"); + _settings.MaskHigh1 = GUI.VerticalSlider(new Rect(offsetX + 215, offsetY + 30, 10, 70), _settings.MaskHigh1, + 1.0f, 0.0f); + + GUI.Label(new Rect(offsetX + 240, offsetY, 250, 30), "Smooth"); + _settings.Sample1Smoothness = GUI.VerticalSlider(new Rect(offsetX + 255, offsetY + 30, 10, 70), + _settings.Sample1Smoothness, 1.0f, 0.0f); + + offsetY += 110; + } + else + { + offsetY += 30; + _settings.IsolateSample1 = false; + } + + + _settings.UseSample2 = + GUI.Toggle(new Rect(offsetX, offsetY, 150, 20), _settings.UseSample2, "Use Color Sample 2"); + if (_settings.UseSample2) + { + _settings.IsolateSample2 = + GUI.Toggle(new Rect(offsetX + 180, offsetY, 150, 20), _settings.IsolateSample2, "Isolate Mask"); + if (_settings.IsolateSample2) + { + _settings.IsolateSample1 = false; + _settings.IsolateSample3 = false; + } + + offsetY += 30; + + if (GUI.Button(new Rect(offsetX, offsetY + 5, 80, 20), "Pick Color")) + { + _selectingColor = true; + _currentSelection = 2; + } + + GUI.DrawTexture(new Rect(offsetX + 10, offsetY + 35, 60, 60), _sampleColorMap2); + + GUI.Label(new Rect(offsetX + 90, offsetY, 250, 30), "Hue"); + _settings.HueWeight2 = GUI.VerticalSlider(new Rect(offsetX + 95, offsetY + 30, 10, 70), + _settings.HueWeight2, 1.0f, 0.0f); + + GUI.Label(new Rect(offsetX + 120, offsetY, 250, 30), "Sat"); + _settings.SatWeight2 = + GUI.VerticalSlider(new Rect(offsetX + 125, offsetY + 30, 10, 70), _settings.SatWeight2, 1.0f, 0.0f); + + GUI.Label(new Rect(offsetX + 150, offsetY, 250, 30), "Lum"); + _settings.LumWeight2 = + GUI.VerticalSlider(new Rect(offsetX + 155, offsetY + 30, 10, 70), _settings.LumWeight2, 1.0f, 0.0f); + + GUI.Label(new Rect(offsetX + 180, offsetY, 250, 30), "Low"); + _settings.MaskLow2 = GUI.VerticalSlider(new Rect(offsetX + 185, offsetY + 30, 10, 70), _settings.MaskLow2, + 1.0f, 0.0f); + + GUI.Label(new Rect(offsetX + 210, offsetY, 250, 30), "High"); + _settings.MaskHigh2 = GUI.VerticalSlider(new Rect(offsetX + 215, offsetY + 30, 10, 70), _settings.MaskHigh2, + 1.0f, 0.0f); + + GUI.Label(new Rect(offsetX + 240, offsetY, 250, 30), "Smooth"); + _settings.Sample2Smoothness = GUI.VerticalSlider(new Rect(offsetX + 255, offsetY + 30, 10, 70), + _settings.Sample2Smoothness, 1.0f, 0.0f); + + offsetY += 110; + } + else + { + offsetY += 30; + _settings.IsolateSample2 = false; + } + + GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Base Smoothness", _settings.BaseSmoothness, + _settings.BaseSmoothnessText, out _settings.BaseSmoothness, out _settings.BaseSmoothnessText, 0.0f, 1.0f); + offsetY += 40; + + if (GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Sample Blur Size", _settings.BlurSize, + _settings.BlurSizeText, + out _settings.BlurSize, out _settings.BlurSizeText, 0, 100)) _doStuff = true; + offsetY += 40; + + if (GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "High Pass Blur Size", _settings.OverlayBlurSize, + _settings.OverlayBlurSizeText, out _settings.OverlayBlurSize, out _settings.OverlayBlurSizeText, 10, 100)) + _doStuff = true; + offsetY += 40; + + GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "High Pass Overlay", _settings.BlurOverlay, + _settings.BlurOverlayText, + out _settings.BlurOverlay, out _settings.BlurOverlayText, -10.0f, 10.0f); + offsetY += 40; + + GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Final Contrast", _settings.FinalContrast, + _settings.FinalContrastText, + out _settings.FinalContrast, out _settings.FinalContrastText, -2.0f, 2.0f); + offsetY += 40; + + GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Final Bias", _settings.FinalBias, + _settings.FinalBiasText, + out _settings.FinalBias, out _settings.FinalBiasText, -0.5f, 0.5f); + offsetY += 40; + + _settings.Invert = GUI.Toggle(new Rect(offsetX, offsetY, 150, 20), _settings.Invert, "Invert Smoothness"); + + offsetY += 50; + + if (GUI.Button(new Rect(offsetX + 10, offsetY, 130, 30), "Reset to Defaults")) + { + //_settingsInitialized = false; + SetValues(new ProjectObject()); + //StartCoroutine(ProcessDiffuse()); + } + + if (GUI.Button(new Rect(offsetX + 150, offsetY, 130, 30), "Set as Smoothness")) + StartCoroutine(ProcessSmoothness()); + + GUI.DragWindow(); + } + + private void OnGUI() + { + if (!_settingsInitialized) return; + + _windowRect.width = 300; + _windowRect.height = 550; + + if (_settings.UseSample1) _windowRect.height += 110; + + if (_settings.UseSample2) _windowRect.height += 110; + + _windowRect = GUI.Window(17, _windowRect, DoMyWindow, "Smoothness From Diffuse"); + } + + public void Close() + { + CleanupTextures(); + gameObject.SetActive(false); + } + + private static void CleanupTexture(RenderTexture texture) + { + if (!texture) return; + texture.Release(); + // ReSharper disable once RedundantAssignment + texture = null; + } + + private void CleanupTextures() + { + CleanupTexture(_blurMap); + CleanupTexture(_overlayBlurMap); + CleanupTexture(_tempMap); + } + + public void InitializeTextures() + { + InitializeSettings(); + + TestObject.GetComponent().sharedMaterial = ThisMaterial; + + CleanupTextures(); + + _diffuseMap = MainGuiScript.DiffuseMap; + _diffuseMapOriginal = MainGuiScript.DiffuseMapOriginal; + + _metallicMap = MainGuiScript.MetallicMap; + ThisMaterial.SetTexture(MetallicTex, _metallicMap != null ? _metallicMap : DefaultMetallicMap); + + if (_diffuseMap) + { + ThisMaterial.SetTexture(MainTex, _diffuseMap); + _imageSizeX = _diffuseMap.width; + _imageSizeY = _diffuseMap.height; + } + else if (_diffuseMapOriginal) + { + ThisMaterial.SetTexture(MainTex, _diffuseMapOriginal); + _imageSizeX = _diffuseMapOriginal.width; + _imageSizeY = _diffuseMapOriginal.height; + + _settings.UseAdjustedDiffuse = false; + _settings.UseOriginalDiffuse = true; + _settings.UsePastedSmoothness = false; + + } + else + { + _smoothnessMap = MainGuiScript.SmoothnessMap; + ThisMaterial.SetTexture(MainTex, _smoothnessMap); + _imageSizeX = _smoothnessMap.width; + _imageSizeY = _smoothnessMap.height; + _settings.UseAdjustedDiffuse = false; + _settings.UseOriginalDiffuse = false; + _settings.UsePastedSmoothness = true; + } + + Debug.Log("Initializing Textures of size: " + _imageSizeX + "x" + _imageSizeY); + + _tempMap = new RenderTexture(_imageSizeX, _imageSizeY, 0, RenderTextureFormat.ARGB32, + RenderTextureReadWrite.Linear) {wrapMode = TextureWrapMode.Repeat}; + _blurMap = new RenderTexture(_imageSizeX, _imageSizeY, 0, RenderTextureFormat.ARGB32, + RenderTextureReadWrite.Linear) {wrapMode = TextureWrapMode.Repeat}; + _overlayBlurMap = new RenderTexture(_imageSizeX, _imageSizeY, 0, RenderTextureFormat.ARGB32, + RenderTextureReadWrite.Linear) {wrapMode = TextureWrapMode.Repeat}; + } + + public IEnumerator ProcessSmoothness() + { + Busy = true; + + Debug.Log("Processing Height"); + + _blitMaterial.SetVector("_ImageSize", new Vector4(_imageSizeX, _imageSizeY, 0, 0)); + + _blitMaterial.SetTexture("_MetallicTex", _metallicMap != null ? _metallicMap : DefaultMetallicMap); + + + _blitMaterial.SetTexture("_BlurTex", _blurMap); + + _blitMaterial.SetTexture("_OverlayBlurTex", _overlayBlurMap); + + _blitMaterial.SetFloat("_MetalSmoothness", _settings.MetalSmoothness); + + _blitMaterial.SetInt("_UseSample1", _settings.UseSample1 ? 1 : 0); + _blitMaterial.SetColor("_SampleColor1", _settings.SampleColor1); + _blitMaterial.SetVector("_SampleUV1", + new Vector4(_settings.SampleUv1.x, _settings.SampleUv1.y, 0, 0)); + _blitMaterial.SetFloat("_HueWeight1", _settings.HueWeight1); + _blitMaterial.SetFloat("_SatWeight1", _settings.SatWeight1); + _blitMaterial.SetFloat("_LumWeight1", _settings.LumWeight1); + _blitMaterial.SetFloat("_MaskLow1", _settings.MaskLow1); + _blitMaterial.SetFloat("_MaskHigh1", _settings.MaskHigh1); + _blitMaterial.SetFloat("_Sample1Smoothness", _settings.Sample1Smoothness); + + _blitMaterial.SetInt("_UseSample2", _settings.UseSample2 ? 1 : 0); + _blitMaterial.SetColor("_SampleColor2", _settings.SampleColor2); + _blitMaterial.SetVector("_SampleUV2", + new Vector4(_settings.SampleUv2.x, _settings.SampleUv2.y, 0, 0)); + _blitMaterial.SetFloat("_HueWeight2", _settings.HueWeight2); + _blitMaterial.SetFloat("_SatWeight2", _settings.SatWeight2); + _blitMaterial.SetFloat("_LumWeight2", _settings.LumWeight2); + _blitMaterial.SetFloat("_MaskLow2", _settings.MaskLow2); + _blitMaterial.SetFloat("_MaskHigh2", _settings.MaskHigh2); + _blitMaterial.SetFloat("_Sample2Smoothness", _settings.Sample2Smoothness); + + _blitMaterial.SetInt("_UseSample3", _settings.UseSample3 ? 1 : 0); + _blitMaterial.SetColor("_SampleColor3", _settings.SampleColor3); + _blitMaterial.SetVector("_SampleUV3", + new Vector4(_settings.SampleUv3.x, _settings.SampleUv3.y, 0, 0)); + _blitMaterial.SetFloat("_HueWeight3", _settings.HueWeight3); + _blitMaterial.SetFloat("_SatWeight3", _settings.SatWeight3); + _blitMaterial.SetFloat("_LumWeight3", _settings.LumWeight3); + _blitMaterial.SetFloat("_MaskLow3", _settings.MaskLow3); + _blitMaterial.SetFloat("_MaskHigh3", _settings.MaskHigh3); + _blitMaterial.SetFloat("_Sample3Smoothness", _settings.Sample3Smoothness); + int invert = 0; + if (_settings.Invert) + { + invert = 1; + } + _blitMaterial.SetInt("_Invert", invert); + _blitMaterial.SetFloat("_BaseSmoothness", _settings.BaseSmoothness); + + _blitMaterial.SetFloat("_BlurOverlay", _settings.BlurOverlay); + _blitMaterial.SetFloat("_FinalContrast", _settings.FinalContrast); + _blitMaterial.SetFloat("_FinalBias", _settings.FinalBias); + + CleanupTexture(_tempMap); + _tempMap = new RenderTexture(_imageSizeX, _imageSizeY, 0, RenderTextureFormat.ARGB32, + RenderTextureReadWrite.Linear) {wrapMode = TextureWrapMode.Repeat}; + Material m = ThisMaterial; + m.SetFloat("_Slider", 0); + Graphics.Blit(_settings.UseAdjustedDiffuse ? _diffuseMap : _diffuseMapOriginal, _tempMap, + m, 0); + + RenderTexture.active = _tempMap; + + if (MainGuiScript.SmoothnessMap) Destroy(MainGuiScript.SmoothnessMap); + + MainGuiScript.SmoothnessMap = new Texture2D(_tempMap.width, _tempMap.height, TextureFormat.ARGB32, true, true); + MainGuiScript.SmoothnessMap.ReadPixels(new Rect(0, 0, _tempMap.width, _tempMap.height), 0, 0); + MainGuiScript.SmoothnessMap.Apply(); + + yield return new WaitForSeconds(0.01f); + + CleanupTexture(_tempMap); + + Busy = false; + } + + public IEnumerator ProcessBlur() + { + Busy = true; + + Debug.Log("Processing Blur"); + + _blitMaterial.SetVector("_ImageSize", new Vector4(_imageSizeX, _imageSizeY, 0, 0)); + _blitMaterial.SetFloat("_BlurContrast", 1.0f); + _blitMaterial.SetFloat("_BlurSpread", 1.0f); + + // Blur the image for selection + _blitMaterial.SetInt("_BlurSamples", _settings.BlurSize); + _blitMaterial.SetVector("_BlurDirection", new Vector4(1, 0, 0, 0)); + if (_settings.UseAdjustedDiffuse) + { + if (_settings.BlurSize == 0) + Graphics.Blit(_diffuseMap, _tempMap); + else + Graphics.Blit(_diffuseMap, _tempMap, _blitMaterial, 1); + }else if(_settings.UsePastedSmoothness){ + Graphics.Blit(_smoothnessMap, _tempMap); + } + else + { + if (_settings.BlurSize == 0) + Graphics.Blit(_diffuseMapOriginal, _tempMap); + else + Graphics.Blit(_diffuseMapOriginal, _tempMap, _blitMaterial, 1); + } + + _blitMaterial.SetVector("_BlurDirection", new Vector4(0, 1, 0, 0)); + if (_settings.BlurSize == 0) + Graphics.Blit(_tempMap, _blurMap); + else + Graphics.Blit(_tempMap, _blurMap, _blitMaterial, 1); + ThisMaterial.SetTexture("_BlurTex", _blurMap); + + // Blur the image for overlay + _blitMaterial.SetInt("_BlurSamples", _settings.OverlayBlurSize); + _blitMaterial.SetVector("_BlurDirection", new Vector4(1, 0, 0, 0)); + Graphics.Blit(_settings.UseAdjustedDiffuse ? _diffuseMap : _diffuseMapOriginal, _tempMap, _blitMaterial, 1); + _blitMaterial.SetVector("_BlurDirection", new Vector4(0, 1, 0, 0)); + Graphics.Blit(_tempMap, _overlayBlurMap, _blitMaterial, 1); + ThisMaterial.SetTexture("_OverlayBlurTex", _overlayBlurMap); + + yield return new WaitForSeconds(0.01f); + + Busy = false; + } +} \ No newline at end of file diff --git a/Assets/Scripts/SmoothnessSettings.cs b/Assets/Scripts/SmoothnessSettings.cs new file mode 100644 index 00000000..5559950d --- /dev/null +++ b/Assets/Scripts/SmoothnessSettings.cs @@ -0,0 +1,176 @@ +#region + +using System.ComponentModel; +using UnityEngine; + +#endregion + +// ReSharper disable FieldCanBeMadeReadOnly.Global + +public class SmoothnessSettings +{ + [DefaultValue(0.1f)] public float BaseSmoothness; + + [DefaultValue("0.1")] public string BaseSmoothnessText; + + [DefaultValue(3.0f)] public float BlurOverlay; + + [DefaultValue("3")] public string BlurOverlayText; + + [DefaultValue(0)] public int BlurSize; + + [DefaultValue("0")] public string BlurSizeText; + + [DefaultValue(0.0f)] public float FinalBias; + + [DefaultValue("0")] public string FinalBiasText; + + [DefaultValue(1.0f)] public float FinalContrast; + + [DefaultValue("1")] public string FinalContrastText; + + [DefaultValue(1.0f)] public float HueWeight1; + + [DefaultValue(1.0f)] public float HueWeight2; + + [DefaultValue(1.0f)] public float HueWeight3; + + [DefaultValue(false)] public bool IsolateSample1; + + [DefaultValue(false)] public bool IsolateSample2; + + [DefaultValue(false)] public bool IsolateSample3; + + [DefaultValue(0.2f)] public float LumWeight1; + + [DefaultValue(0.2f)] public float LumWeight2; + + [DefaultValue(0.2f)] public float LumWeight3; + + [DefaultValue(1.0f)] public float MaskHigh1; + + [DefaultValue(1.0f)] public float MaskHigh2; + + [DefaultValue(1.0f)] public float MaskHigh3; + + [DefaultValue(0.0f)] public float MaskLow1; + + [DefaultValue(0.0f)] public float MaskLow2; + + [DefaultValue(0.0f)] public float MaskLow3; + + [DefaultValue(0.7f)] public float MetalSmoothness; + + [DefaultValue("0.7")] public string MetalSmoothnessText; + + [DefaultValue(30)] public int OverlayBlurSize; + + [DefaultValue("30")] public string OverlayBlurSizeText; + + [DefaultValue(0.5f)] public float Sample1Smoothness; + + [DefaultValue(0.3f)] public float Sample2Smoothness; + + [DefaultValue(0.2f)] public float Sample3Smoothness; + + [DefaultValue(0)] public bool Invert; + + //[DefaultValueAttribute(Color.black)] + public Color SampleColor1; + + //[DefaultValueAttribute(Color.black)] + public Color SampleColor2; + + //[DefaultValueAttribute(Color.black)] + public Color SampleColor3; + + //[DefaultValueAttribute(Vector2.zero)] + public Vector2 SampleUv1; + + //[DefaultValueAttribute(Vector2.zero)] + public Vector2 SampleUv2; + + //[DefaultValueAttribute(Vector2.zero)] + public Vector2 SampleUv3; + + [DefaultValue(0.5f)] public float SatWeight1; + + [DefaultValue(0.5f)] public float SatWeight2; + + [DefaultValue(0.5f)] public float SatWeight3; + + [DefaultValue(false)] public bool UseAdjustedDiffuse; + + [DefaultValue(true)] public bool UseOriginalDiffuse; + + [DefaultValue(false)] public bool UsePastedSmoothness; + + [DefaultValue(false)] public bool UseSample1; + + [DefaultValue(false)] public bool UseSample2; + + [DefaultValue(false)] public bool UseSample3; + + public SmoothnessSettings() + { + SampleColor1 = Color.black; + SampleUv1 = Vector2.zero; + + SampleColor2 = Color.black; + SampleUv2 = Vector2.zero; + + SampleColor3 = Color.black; + SampleUv3 = Vector2.zero; + + MetalSmoothness = 0.7f; + MetalSmoothnessText = "0.7"; + + UseSample1 = false; + IsolateSample1 = false; + HueWeight1 = 1.0f; + SatWeight1 = 0.5f; + LumWeight1 = 0.2f; + MaskLow1 = 0.0f; + MaskHigh1 = 1.0f; + Sample1Smoothness = 0.5f; + + UseSample2 = false; + IsolateSample2 = false; + HueWeight2 = 1.0f; + SatWeight2 = 0.5f; + LumWeight2 = 0.2f; + MaskLow2 = 0.0f; + MaskHigh2 = 1.0f; + Sample2Smoothness = 0.3f; + + UseSample3 = false; + IsolateSample3 = false; + HueWeight3 = 1.0f; + SatWeight3 = 0.5f; + LumWeight3 = 0.2f; + MaskLow3 = 0.0f; + MaskHigh3 = 1.0f; + Sample3Smoothness = 0.2f; + + BaseSmoothness = 0.1f; + BaseSmoothnessText = "0.1"; + + BlurSize = 0; + BlurSizeText = "0"; + + OverlayBlurSize = 30; + OverlayBlurSizeText = "30"; + + BlurOverlay = 3.0f; + BlurOverlayText = "3"; + + FinalContrast = 1.0f; + FinalContrastText = "1"; + + FinalBias = 0.0f; + FinalBiasText = "0"; + Invert = false; + UseAdjustedDiffuse = false; + UseOriginalDiffuse = true; + } +} \ No newline at end of file diff --git a/Assets/Scripts/SmoothnessSettings.cs.meta b/Assets/Scripts/SmoothnessSettings.cs.meta new file mode 100644 index 00000000..8a87de46 --- /dev/null +++ b/Assets/Scripts/SmoothnessSettings.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 3ba8d34d0d66490aa1b76236ad229ec2 +timeCreated: 1549049713 \ No newline at end of file diff --git a/Assets/Scripts/SpecularGui.cs b/Assets/Scripts/SpecularGui.cs index 7a92c70a..7bbacee4 100644 --- a/Assets/Scripts/SpecularGui.cs +++ b/Assets/Scripts/SpecularGui.cs @@ -1,318 +1,336 @@ -using UnityEngine; +#region + using System.Collections; +using UnityEngine; + +#endregion + +// ReSharper disable Unity.PreferAddressByIdToGraphicsParams + +public class SpecularGui : MonoBehaviour +{ + private static readonly int BlurContrast = Shader.PropertyToID("_BlurContrast"); + private static readonly int LightMaskPow = Shader.PropertyToID("_LightMaskPow"); + private static readonly int LightPow = Shader.PropertyToID("_LightPow"); + private static readonly int DarkMaskPow = Shader.PropertyToID("_DarkMaskPow"); + private static readonly int DarkPow = Shader.PropertyToID("_DarkPow"); + private static readonly int DiffuseContrast = Shader.PropertyToID("_DiffuseContrast"); + private static readonly int DiffuseBias = Shader.PropertyToID("_DiffuseBias"); + private static readonly int FinalContrast = Shader.PropertyToID("_FinalContrast"); + private static readonly int FinalBias = Shader.PropertyToID("_FinalBias"); + private static readonly int ColorLerp = Shader.PropertyToID("_ColorLerp"); + private static readonly int Saturation = Shader.PropertyToID("_Saturation"); + private static readonly int MainTex = Shader.PropertyToID("_MainTex"); + private Material _blitMaterial; + + private float _blurContrast = 1.0f; + private RenderTexture _blurMap; + + private int _blurSize = 20; + + private float _colorLerp = 0.5f; + + private float _darkMaskPow = 1.0f; + private float _darkPow = 1.0f; + private float _diffuseBias; + + private float _diffuseContrast = 1.0f; + private Texture2D _diffuseMap; + private bool _doStuff; + private Texture2D _edgeMap; + private float _finalBias; + + private float _finalContrast = 1.0f; + + private Texture2D _heightMap; + + private int _imageSizeX; + private int _imageSizeY; + + private int _lastBlurSize = 20; + //float BlurWeight = 1.0f; + + private float _lightMaskPow = 1.0f; + private float _lightPow = 1.0f; + private Texture2D _metallicMap; + + private bool _newTexture; + private Texture2D _normalMap; + + private float _saturation; + private Texture2D _smoothnessMap; + + private RenderTexture _tempMap; + + + public GameObject TestObject; + + public Material ThisMaterial; + + // Use this for initialization + private void Start() + { + _lastBlurSize = _blurSize; + TestObject.GetComponent().sharedMaterial = ThisMaterial; + _blitMaterial = new Material(Shader.Find("Hidden/Blit_Shader")); + } + + public void DoStuff() + { + _doStuff = true; + } + + public void NewTexture() + { + _newTexture = true; + } + + // Update is called once per frame + private void Update() + { + if (_blurSize != _lastBlurSize) _doStuff = true; + + _lastBlurSize = _blurSize; + + if (_newTexture) + { + InitializeTextures(); + _newTexture = false; + } + + if (_doStuff) + { + StartCoroutine(ProcessBlur()); + _doStuff = false; + } + + //thisMaterial.SetFloat ("_BlurWeight", BlurWeight); + + ThisMaterial.SetFloat(BlurContrast, _blurContrast); + + ThisMaterial.SetFloat(LightMaskPow, _lightMaskPow); + ThisMaterial.SetFloat(LightPow, _lightPow); + + ThisMaterial.SetFloat(DarkMaskPow, _darkMaskPow); + ThisMaterial.SetFloat(DarkPow, _darkPow); + + ThisMaterial.SetFloat(DiffuseContrast, _diffuseContrast); + ThisMaterial.SetFloat(DiffuseBias, _diffuseBias); + + ThisMaterial.SetFloat(FinalContrast, _finalContrast); + + ThisMaterial.SetFloat(FinalBias, _finalBias); + + ThisMaterial.SetFloat(ColorLerp, _colorLerp); + + ThisMaterial.SetFloat(Saturation, _saturation); + } + + private static string FloatToString(float num, int length) + { + var numString = num.ToString(); + var numStringLength = numString.Length; + var lastIndex = Mathf.FloorToInt(Mathf.Min(numStringLength, (float) length)); + + return numString.Substring(0, lastIndex); + } + + private void OnGUI() + { + //toolsWindowRect = new Rect (20, 20, 300, 700); + + //toolsWindowRect = GUI.Window (toolsWindowID, toolsWindowRect, DrawToolsWindow, toolsWindowTitle); + + const int spacingY = 50; + const int spacing2Y = 70; + + const int offsetX = 30; + var offsetY = 330; + + GUI.Box(new Rect(20, 300, 300, 630), "Metallic"); + + GUI.Label(new Rect(offsetX, offsetY, 250, 30), + "Contrast: " + FloatToString(_diffuseContrast, 4) + " Bias: " + FloatToString(_diffuseBias, 4)); + _diffuseContrast = + GUI.HorizontalSlider(new Rect(offsetX, offsetY + 30, 280, 10), _diffuseContrast, -1.0f, 1.0f); + _diffuseBias = GUI.HorizontalSlider(new Rect(offsetX, offsetY + 50, 280, 10), _diffuseBias, -0.5f, 0.5f); + + offsetY += spacing2Y; + + GUI.Label(new Rect(offsetX, offsetY, 250, 30), + "Blur Size: " + _blurSize + " Contrast: " + FloatToString(_blurContrast, 4)); + _blurSize = Mathf.FloorToInt(GUI.HorizontalSlider(new Rect(offsetX, offsetY + 30, 280, 10), _blurSize, 1.0f, + 100.0f)); + _blurContrast = GUI.HorizontalSlider(new Rect(offsetX, offsetY + 50, 280, 10), _blurContrast, -5.0f, 5.0f); + + offsetY += spacing2Y; + + GUI.Label(new Rect(offsetX, offsetY, 250, 30), + "Light Mask Power: " + FloatToString(_lightMaskPow, 4) + " Intensity: " + FloatToString(_lightPow, 4)); + _lightMaskPow = GUI.HorizontalSlider(new Rect(offsetX, offsetY + 30, 280, 10), _lightMaskPow, 0.1f, 5.0f); + _lightPow = GUI.HorizontalSlider(new Rect(offsetX, offsetY + 50, 280, 10), _lightPow, -1.0f, 1.0f); + + offsetY += spacing2Y; + + GUI.Label(new Rect(offsetX, offsetY, 250, 30), + "Dark Mask Power: " + FloatToString(_darkMaskPow, 4) + " Intensity: " + FloatToString(_darkPow, 4)); + _darkMaskPow = GUI.HorizontalSlider(new Rect(offsetX, offsetY + 30, 280, 10), _darkMaskPow, 0.1f, 5.0f); + _darkPow = GUI.HorizontalSlider(new Rect(offsetX, offsetY + 50, 280, 10), _darkPow, 0.0f, 5.0f); + + offsetY += spacing2Y; + + GUI.Label(new Rect(offsetX, offsetY, 250, 30), "Final Contrast: " + FloatToString(_finalContrast, 4)); + _finalContrast = GUI.HorizontalSlider(new Rect(offsetX, offsetY + 30, 280, 10), _finalContrast, -2.0f, 2.0f); + + offsetY += spacingY; + + GUI.Label(new Rect(offsetX, offsetY, 250, 30), "Final Bias: " + FloatToString(_finalBias, 4)); + _finalBias = GUI.HorizontalSlider(new Rect(offsetX, offsetY + 30, 280, 10), _finalBias, -0.5f, 0.5f); + + offsetY += spacingY; + + GUI.Label(new Rect(offsetX, offsetY, 250, 30), "Keep Original Color: " + FloatToString(_colorLerp, 4)); + _colorLerp = GUI.HorizontalSlider(new Rect(offsetX, offsetY + 30, 280, 10), _colorLerp, 0.0f, 1.0f); + + offsetY += spacingY; + + GUI.Label(new Rect(offsetX, offsetY, 250, 30), "Saturation: " + FloatToString(_saturation, 4)); + _saturation = GUI.HorizontalSlider(new Rect(offsetX, offsetY + 30, 280, 10), _saturation, 0.0f, 1.0f); + + offsetY += spacingY; + + if (GUI.Button(new Rect(offsetX, offsetY, 130, 30), "Set as Metallic")) + StartCoroutine(ProcessRoughSpec(Textures.Specular)); + } + + private static void CleanupTexture(RenderTexture texture) + { + if (!texture) return; + texture.Release(); + // ReSharper disable once RedundantAssignment + texture = null; + } + + private void CleanupTextures() + { + Debug.Log("Cleaning Up Textures"); + + CleanupTexture(_blurMap); + CleanupTexture(_tempMap); + } + + private void InitializeTextures() + { + TestObject.GetComponent().sharedMaterial = ThisMaterial; + + CleanupTextures(); + + _diffuseMap = MainGui.Instance.DiffuseMapOriginal; + + ThisMaterial.SetTexture(MainTex, _diffuseMap); + + _imageSizeX = _diffuseMap.width; + _imageSizeY = _diffuseMap.height; + + Debug.Log("Initializing Textures of size: " + _imageSizeX + "x" + _imageSizeY); + + _tempMap = new RenderTexture(_imageSizeX, _imageSizeY, 0, RenderTextureFormat.ARGBHalf) + { + wrapMode = TextureWrapMode.Repeat + }; + _blurMap = new RenderTexture(_imageSizeX, _imageSizeY, 0, RenderTextureFormat.ARGBHalf) + { + wrapMode = TextureWrapMode.Repeat + }; + } + + private IEnumerator ProcessRoughSpec(Textures whichTexture) + { + Debug.Log("Processing Height"); + + _blitMaterial.SetVector("_ImageSize", new Vector4(_imageSizeX, _imageSizeY, 0, 0)); + + _blitMaterial.SetTexture("_MainTex", _diffuseMap); + + _blitMaterial.SetTexture("_BlurTex", _blurMap); + _blitMaterial.SetFloat("_BlurContrast", _blurContrast); + + _blitMaterial.SetFloat("_LightMaskPow", _lightMaskPow); + _blitMaterial.SetFloat("_LightPow", _lightPow); + + _blitMaterial.SetFloat("_DarkMaskPow", _darkMaskPow); + _blitMaterial.SetFloat("_DarkPow", _darkPow); + + _blitMaterial.SetFloat("_DiffuseContrast", _diffuseContrast); + _blitMaterial.SetFloat("_DiffuseBias", _diffuseBias); + + _blitMaterial.SetFloat("_FinalContrast", _finalContrast); + + _blitMaterial.SetFloat("_FinalBias", _finalBias); + + _blitMaterial.SetFloat("_ColorLerp", _colorLerp); + + _blitMaterial.SetFloat("_Saturation", _saturation); + + CleanupTexture(_tempMap); + _tempMap = new RenderTexture(_imageSizeX, _imageSizeY, 0, RenderTextureFormat.ARGB32) + { + wrapMode = TextureWrapMode.Repeat + }; + + Graphics.Blit(_diffuseMap, _tempMap, _blitMaterial, 10); + + RenderTexture.active = _tempMap; + + switch (whichTexture) + { + case Textures.Roughness: + MainGui.Instance.SmoothnessMap = new Texture2D(_tempMap.width, _tempMap.height); + MainGui.Instance.SmoothnessMap.ReadPixels(new Rect(0, 0, _tempMap.width, _tempMap.height), 0, 0); + MainGui.Instance.SmoothnessMap.Apply(); + break; + case Textures.Specular: + MainGui.Instance.MetallicMap = new Texture2D(_tempMap.width, _tempMap.height); + MainGui.Instance.MetallicMap.ReadPixels(new Rect(0, 0, _tempMap.width, _tempMap.height), 0, 0); + MainGui.Instance.MetallicMap.Apply(); + break; + default: + MainGui.Instance.DiffuseMap = new Texture2D(_tempMap.width, _tempMap.height); + MainGui.Instance.DiffuseMap.ReadPixels(new Rect(0, 0, _tempMap.width, _tempMap.height), 0, 0); + MainGui.Instance.DiffuseMap.Apply(); + break; + } + + yield return new WaitForEndOfFrame(); + + CleanupTexture(_tempMap); + } + + private IEnumerator ProcessBlur() + { + Debug.Log("Processing Blur"); + + _blitMaterial.SetVector("_ImageSize", new Vector4(_imageSizeX, _imageSizeY, 0, 0)); + _blitMaterial.SetFloat("_BlurContrast", 1.0f); + + // Blur the image 1 + _blitMaterial.SetTexture("_MainTex", _diffuseMap); + _blitMaterial.SetInt("_BlurSamples", _blurSize); + _blitMaterial.SetVector("_BlurDirection", new Vector4(1, 0, 0, 0)); + Graphics.Blit(_diffuseMap, _tempMap, _blitMaterial, 1); + + _blitMaterial.SetTexture("_MainTex", _tempMap); + _blitMaterial.SetVector("_BlurDirection", new Vector4(0, 1, 0, 0)); + Graphics.Blit(_tempMap, _blurMap, _blitMaterial, 1); + + ThisMaterial.SetTexture("_BlurTex", _blurMap); + + yield return new WaitForEndOfFrame(); + } -public class SpecularGui : MonoBehaviour { - - enum Textures { - height, - diffuse, - specular, - roughness, - normal - } - - public GameObject MainGuiObject; - MainGui MainGuiScript; - - Textures textureToLoad = Textures.diffuse; - - Texture2D _HeightMap; - Texture2D _DiffuseMap; - Texture2D _NormalMap; - Texture2D _EdgeMap; - Texture2D _MetallicMap; - Texture2D _SmoothnessMap; - - RenderTexture _TempMap; - RenderTexture _BlurMap; - - public Material thisMaterial; - Material blitMaterial; - - int imageSizeX; - int imageSizeY; - - float DiffuseContrast = 1.0f; - float DiffuseBias = 0.0f; - - int BlurSize = 20; - int LastBlurSize = 20; - - float BlurContrast = 1.0f; - //float BlurWeight = 1.0f; - - float LightMaskPow = 1.0f; - float LightPow = 1.0f; - - float DarkMaskPow = 1.0f; - float DarkPow = 1.0f; - - float FinalContrast = 1.0f; - float FinalBias = 0.0f; - - float ColorLerp = 0.5f; - - float Saturation = 0.0f; - - - public GameObject testObject; - bool doStuff = false; - bool newTexture = false; - - // Use this for initialization - void Start () { - - LastBlurSize = BlurSize; - - MainGuiScript = MainGuiObject.GetComponent (); - - //thisMaterial = testObject.renderer.material; - testObject.GetComponent().sharedMaterial = thisMaterial; - - blitMaterial = new Material (Shader.Find ("Hidden/Blit_Shader")); - - } - - public void DoStuff() { - doStuff = true; - } - - public void NewTexture() { - newTexture = true; - } - - // Update is called once per frame - void Update () { - - if (BlurSize != LastBlurSize) { - doStuff = true; - } - - LastBlurSize = BlurSize; - - if (newTexture) { - InitializeTextures(); - newTexture = false; - } - - if (doStuff) { - StartCoroutine( ProcessBlur () ); - doStuff = false; - } - - //thisMaterial.SetFloat ("_BlurWeight", BlurWeight); - - thisMaterial.SetFloat ("_BlurContrast", BlurContrast); - - thisMaterial.SetFloat ("_LightMaskPow", LightMaskPow ); - thisMaterial.SetFloat ("_LightPow", LightPow ); - - thisMaterial.SetFloat ("_DarkMaskPow", DarkMaskPow ); - thisMaterial.SetFloat ("_DarkPow", DarkPow ); - - thisMaterial.SetFloat ("_DiffuseContrast", DiffuseContrast ); - thisMaterial.SetFloat ("_DiffuseBias", DiffuseBias ); - - thisMaterial.SetFloat ("_FinalContrast", FinalContrast); - - thisMaterial.SetFloat ("_FinalBias", FinalBias); - - thisMaterial.SetFloat ("_ColorLerp", ColorLerp); - - thisMaterial.SetFloat ("_Saturation", Saturation); - - } - - string FloatToString ( float num, int length ) { - - string numString = num.ToString (); - int numStringLength = numString.Length; - int lastIndex = Mathf.FloorToInt( Mathf.Min ( (float)numStringLength , (float)length ) ); - - return numString.Substring (0, lastIndex); - } - - void OnGUI () { - - //toolsWindowRect = new Rect (20, 20, 300, 700); - - //toolsWindowRect = GUI.Window (toolsWindowID, toolsWindowRect, DrawToolsWindow, toolsWindowTitle); - - int spacingX = 0; - int spacingY = 50; - int spacing2Y = 70; - - int offsetX = 30; - int offsetY = 330; - - GUI.Box (new Rect (20, 300, 300, 630), "Metallic"); - - GUI.Label (new Rect (offsetX, offsetY, 250, 30), "Contrast: " + FloatToString(DiffuseContrast,4) + " Bias: " + FloatToString(DiffuseBias,4) ); - DiffuseContrast = GUI.HorizontalSlider( new Rect( offsetX, offsetY + 30, 280, 10 ),DiffuseContrast,-1.0f, 1.0f ); - DiffuseBias = GUI.HorizontalSlider( new Rect( offsetX, offsetY + 50, 280, 10 ),DiffuseBias,-0.5f, 0.5f ); - - offsetY += spacing2Y; - - GUI.Label (new Rect (offsetX, offsetY, 250, 30), "Blur Size: " + BlurSize.ToString() + " Contrast: " + FloatToString(BlurContrast,4) ); - BlurSize = Mathf.FloorToInt( GUI.HorizontalSlider( new Rect( offsetX, offsetY + 30, 280, 10 ),BlurSize,1.0f, 100.0f ) ); - BlurContrast = GUI.HorizontalSlider( new Rect( offsetX, offsetY + 50, 280, 10 ),BlurContrast,-5.0f, 5.0f ); - - offsetY += spacing2Y; - - GUI.Label (new Rect (offsetX, offsetY, 250, 30), "Light Mask Power: " + FloatToString(LightMaskPow,4) + " Intensity: " + FloatToString(LightPow,4) ); - LightMaskPow = GUI.HorizontalSlider( new Rect( offsetX, offsetY + 30, 280, 10 ),LightMaskPow,0.1f, 5.0f ); - LightPow = GUI.HorizontalSlider( new Rect( offsetX, offsetY + 50, 280, 10 ),LightPow,-1.0f, 1.0f ); - - offsetY += spacing2Y; - - GUI.Label (new Rect (offsetX, offsetY, 250, 30), "Dark Mask Power: " + FloatToString(DarkMaskPow,4) + " Intensity: " + FloatToString(DarkPow,4) ); - DarkMaskPow = GUI.HorizontalSlider( new Rect( offsetX, offsetY + 30, 280, 10 ),DarkMaskPow,0.1f, 5.0f ); - DarkPow = GUI.HorizontalSlider( new Rect( offsetX, offsetY + 50, 280, 10 ),DarkPow,0.0f, 5.0f ); - - offsetY += spacing2Y; - - GUI.Label (new Rect (offsetX, offsetY, 250, 30), "Final Contrast: " + FloatToString(FinalContrast,4) ); - FinalContrast = GUI.HorizontalSlider( new Rect( offsetX, offsetY + 30, 280, 10 ),FinalContrast,-2.0f, 2.0f ); - - offsetY += spacingY; - - GUI.Label (new Rect (offsetX, offsetY, 250, 30), "Final Bias: " + FloatToString(FinalBias,4) ); - FinalBias = GUI.HorizontalSlider( new Rect( offsetX, offsetY + 30, 280, 10 ),FinalBias,-0.5f, 0.5f ); - - offsetY += spacingY; - - GUI.Label (new Rect (offsetX, offsetY, 250, 30), "Keep Original Color: " + FloatToString(ColorLerp,4) ); - ColorLerp = GUI.HorizontalSlider( new Rect( offsetX, offsetY + 30, 280, 10 ),ColorLerp,0.0f, 1.0f ); - - offsetY += spacingY; - - GUI.Label (new Rect (offsetX, offsetY, 250, 30), "Saturation: " + FloatToString(Saturation,4) ); - Saturation = GUI.HorizontalSlider( new Rect( offsetX, offsetY + 30, 280, 10 ),Saturation,0.0f, 1.0f ); - - offsetY += spacingY; - - if( GUI.Button (new Rect (offsetX, offsetY, 130, 30), "Set as Metallic" ) ){ - StartCoroutine( ProcessRoughSpec ( Textures.specular ) ); - } - - } - - void CleanupTexture( RenderTexture _Texture ) { - - if (_Texture != null) { - _Texture.Release(); - _Texture = null; - } - - } - - void CleanupTextures() { - - Debug.Log ("Cleaning Up Textures"); - - CleanupTexture( _BlurMap ); - CleanupTexture( _TempMap ); - - } - - void InitializeTextures() { - - testObject.GetComponent().sharedMaterial = thisMaterial; - - CleanupTextures (); - - _DiffuseMap = MainGuiScript._DiffuseMapOriginal; - - thisMaterial.SetTexture ("_MainTex", _DiffuseMap); - - imageSizeX = _DiffuseMap.width; - imageSizeY = _DiffuseMap.height; - - Debug.Log ( "Initializing Textures of size: " + imageSizeX.ToString() + "x" + imageSizeY.ToString() ); - - _TempMap = new RenderTexture (imageSizeX, imageSizeY, 0, RenderTextureFormat.ARGBHalf); - _TempMap.wrapMode = TextureWrapMode.Repeat; - _BlurMap = new RenderTexture (imageSizeX, imageSizeY, 0, RenderTextureFormat.ARGBHalf); - _BlurMap.wrapMode = TextureWrapMode.Repeat; - - } - - IEnumerator ProcessRoughSpec( Textures whichTexture ) { - - Debug.Log ("Processing Height"); - - blitMaterial.SetVector ("_ImageSize", new Vector4 (imageSizeX, imageSizeY, 0, 0)); - - blitMaterial.SetTexture ("_MainTex", _DiffuseMap); - - blitMaterial.SetTexture ("_BlurTex", _BlurMap); - blitMaterial.SetFloat ("_BlurContrast", BlurContrast); - - blitMaterial.SetFloat ("_LightMaskPow", LightMaskPow ); - blitMaterial.SetFloat ("_LightPow", LightPow ); - - blitMaterial.SetFloat ("_DarkMaskPow", DarkMaskPow ); - blitMaterial.SetFloat ("_DarkPow", DarkPow ); - - blitMaterial.SetFloat ("_DiffuseContrast", DiffuseContrast ); - blitMaterial.SetFloat ("_DiffuseBias", DiffuseBias ); - - blitMaterial.SetFloat ("_FinalContrast", FinalContrast); - - blitMaterial.SetFloat ("_FinalBias", FinalBias); - - blitMaterial.SetFloat ("_ColorLerp", ColorLerp); - - blitMaterial.SetFloat ("_Saturation", Saturation); - - CleanupTexture (_TempMap); - _TempMap = new RenderTexture (imageSizeX, imageSizeY, 0, RenderTextureFormat.ARGB32); - _TempMap.wrapMode = TextureWrapMode.Repeat; - - Graphics.Blit(_DiffuseMap, _TempMap, blitMaterial, 10); - - RenderTexture.active = _TempMap; - - if (whichTexture == Textures.roughness) { - MainGuiScript._SmoothnessMap = new Texture2D (_TempMap.width, _TempMap.height); - MainGuiScript._SmoothnessMap.ReadPixels (new Rect (0, 0, _TempMap.width, _TempMap.height), 0, 0); - MainGuiScript._SmoothnessMap.Apply (); - } else if (whichTexture == Textures.specular) { - MainGuiScript._MetallicMap = new Texture2D (_TempMap.width, _TempMap.height); - MainGuiScript._MetallicMap.ReadPixels (new Rect (0, 0, _TempMap.width, _TempMap.height), 0, 0); - MainGuiScript._MetallicMap.Apply (); - } else { - MainGuiScript._DiffuseMap = new Texture2D (_TempMap.width, _TempMap.height); - MainGuiScript._DiffuseMap.ReadPixels (new Rect (0, 0, _TempMap.width, _TempMap.height), 0, 0); - MainGuiScript._DiffuseMap.Apply (); - } - - yield return new WaitForEndOfFrame(); - - CleanupTexture ( _TempMap ); - - } - - IEnumerator ProcessBlur () { - - Debug.Log ("Processing Blur"); - - blitMaterial.SetVector ("_ImageSize", new Vector4( imageSizeX, imageSizeY, 0, 0 ) ); - blitMaterial.SetFloat ("_BlurContrast", 1.0f); - - // Blur the image 1 - blitMaterial.SetTexture ("_MainTex", _DiffuseMap); - blitMaterial.SetInt ("_BlurSamples", BlurSize); - blitMaterial.SetVector ("_BlurDirection", new Vector4(1,0,0,0) ); - Graphics.Blit(_DiffuseMap, _TempMap, blitMaterial, 1); - - blitMaterial.SetTexture ("_MainTex", _TempMap); - blitMaterial.SetVector ("_BlurDirection", new Vector4(0,1,0,0) ); - Graphics.Blit(_TempMap, _BlurMap, blitMaterial, 1); - - thisMaterial.SetTexture ("_BlurTex", _BlurMap); - - yield return new WaitForEndOfFrame(); - - } -} + private enum Textures + { + Specular, + Roughness + } +} \ No newline at end of file diff --git a/Assets/Scripts/SuggestionGui.cs b/Assets/Scripts/SuggestionGui.cs index 0df3b5f7..59e78c9c 100644 --- a/Assets/Scripts/SuggestionGui.cs +++ b/Assets/Scripts/SuggestionGui.cs @@ -1,128 +1,129 @@ -using UnityEngine; +#region + +using System; using System.Collections; +using UnityEngine; + +#endregion + +public class SuggestionGui : MonoBehaviour +{ + private const string StringEmail = ""; + + private SuggestionState _suggestionState = SuggestionState.Write; + + private string _suggestionText = ""; + + private Rect _windowRect = new Rect(30, 300, 300, 450); + + private void Start() + { + _windowRect.position = new Vector2(Screen.width - 310, 50); + } + + private IEnumerator SendSuggestion() + { + _suggestionState = SuggestionState.Sending; + + var form = new WWWForm(); + form.AddField("email", StringEmail); + form.AddField("suggestion", _suggestionText); + +#pragma warning disable 618 + var www = new WWW("http://squirrelyjones.com/boundingbox/materialize/processSuggestion.php", form); +#pragma warning restore 618 + yield return www; + var returnText = www.text; + Debug.Log(www.text); + + if (returnText.Contains("success")) + { + _suggestionState = SuggestionState.Sent; + _suggestionText = ""; + } + else + { + _suggestionState = SuggestionState.Failed; + } + + yield return new WaitForSeconds(0.01f); + } + + private void DoMyWindow(int windowId) + { + const int offsetX = 10; + var offsetY = 30; + + switch (_suggestionState) + { + case SuggestionState.Write: + { + GUI.Label(new Rect(offsetX, offsetY, 250, 30), "Got a suggestion? Send it to us!"); + offsetY += 30; + _suggestionText = GUI.TextArea(new Rect(offsetX, offsetY, 280, 170), _suggestionText); + offsetY += 180; + if (GUI.Button(new Rect(offsetX + 150, offsetY, 130, 30), "Send")) StartCoroutine(SendSuggestion()); + if (GUI.Button(new Rect(offsetX, offsetY, 130, 30), "Close")) gameObject.SetActive(false); + break; + } + case SuggestionState.Sending: + { + GUI.Label(new Rect(offsetX, offsetY, 250, 30), "Sending...."); + offsetY += 30; + if (GUI.Button(new Rect(offsetX, offsetY, 130, 30), "Close")) + { + _suggestionState = SuggestionState.Write; + gameObject.SetActive(false); + } + + break; + } + case SuggestionState.Failed: + { + GUI.Label(new Rect(offsetX, offsetY, 250, 30), "Something went wrong!"); + offsetY += 30; + if (GUI.Button(new Rect(offsetX, offsetY, 130, 30), "Close")) + { + _suggestionState = SuggestionState.Write; + gameObject.SetActive(false); + } + + if (GUI.Button(new Rect(offsetX + 150, offsetY, 130, 30), "Try Again")) + _suggestionState = SuggestionState.Write; + break; + } + case SuggestionState.Sent: + { + GUI.Label(new Rect(offsetX, offsetY, 250, 30), "Thanks! I'll get right on that!"); + offsetY += 30; + if (GUI.Button(new Rect(offsetX, offsetY, 130, 30), "Close")) + { + _suggestionState = SuggestionState.Write; + gameObject.SetActive(false); + } + + break; + } + default: + throw new ArgumentOutOfRangeException(); + } + + GUI.DragWindow(); + } + + private void OnGUI() + { + _windowRect.width = 300; + _windowRect.height = _suggestionState == SuggestionState.Write ? 280 : 100; + + _windowRect = GUI.Window(50, _windowRect, DoMyWindow, "Make A Suggestion!"); + } -public class SuggestionGui : MonoBehaviour { - - public GameObject MainGuiObject; - MainGui MainGuiScript; - - public GameObject AuthenticateObject; - AuthenticateGui AuthenticateScript; - - string SuggestionText = ""; - string stringEmail = ""; - - enum SuggestionState { - Write, - Sending, - Failed, - Sent - } - - SuggestionState suggestionState = SuggestionState.Write; - - bool suggestionSent = false; - bool sendingSuggestion = false; - - Rect windowRect = new Rect (30, 300, 300, 450); - - // Use this for initialization - void Start () { - - AuthenticateScript = AuthenticateObject.GetComponent (); - stringEmail = AuthenticateScript.stringEmail; - Debug.Log ("Suggestion Box Email: " + stringEmail); - windowRect.position = new Vector2( Screen.width - 310, 50 ); - - } - - // Update is called once per frame - void Update () { - - } - - IEnumerator SendSuggestion () { - - suggestionState = SuggestionState.Sending; - - // Create a Web Form - WWWForm form = new WWWForm(); - form.AddField("email", stringEmail); - form.AddField("suggestion", SuggestionText); - - //WWW www = new WWW("http://boundingboxsoftware.com/materialize/processSuggestion.php", form); - WWW www = new WWW("http://squirrelyjones.com/boundingbox/materialize/processSuggestion.php", form); - yield return www; - string returnText = www.text; - Debug.Log ( www.text ); - - if (returnText.Contains ("success")) { - suggestionState = SuggestionState.Sent; - SuggestionText = ""; - } else { - suggestionState = SuggestionState.Failed; - } - - yield return new WaitForSeconds(0.01f); - } - - void DoMyWindow ( int windowID ) { - - int offsetX = 10; - int offsetY = 30; - - if (suggestionState == SuggestionState.Write) { - GUI.Label (new Rect (offsetX, offsetY, 250, 30), "Got a suggestion? Send it to us!"); - offsetY += 30; - SuggestionText = GUI.TextArea (new Rect (offsetX, offsetY, 280, 170), SuggestionText); - offsetY += 180; - if (GUI.Button (new Rect (offsetX + 150, offsetY, 130, 30), "Send")) { - StartCoroutine (SendSuggestion ()); - } - if (GUI.Button (new Rect (offsetX, offsetY, 130, 30), "Close")) { - this.gameObject.SetActive (false); - } - } else if (suggestionState == SuggestionState.Sending) { - GUI.Label (new Rect (offsetX, offsetY, 250, 30), "Sending...."); - offsetY += 30; - if (GUI.Button (new Rect (offsetX, offsetY, 130, 30), "Close")) { - suggestionState = SuggestionState.Write; - this.gameObject.SetActive (false); - } - } else if (suggestionState == SuggestionState.Failed) { - GUI.Label (new Rect (offsetX, offsetY, 250, 30), "Something went wrong!"); - offsetY += 30; - if (GUI.Button (new Rect (offsetX, offsetY, 130, 30), "Close")) { - suggestionState = SuggestionState.Write; - this.gameObject.SetActive (false); - } - if (GUI.Button (new Rect (offsetX + 150, offsetY, 130, 30), "Try Again")) { - suggestionState = SuggestionState.Write; - } - } else if (suggestionState == SuggestionState.Sent){ - GUI.Label (new Rect (offsetX, offsetY, 250, 30), "Thanks! I'll get right on that!"); - offsetY += 30; - if (GUI.Button (new Rect (offsetX, offsetY, 130, 30), "Close")) { - suggestionState = SuggestionState.Write; - this.gameObject.SetActive (false); - } - } - - GUI.DragWindow(); - - } - - void OnGUI () { - - windowRect.width = 300; - if (suggestionState == SuggestionState.Write) { - windowRect.height = 280; - } else { - windowRect.height = 100; - } - - windowRect = GUI.Window(50, windowRect, DoMyWindow, "Make A Suggestion!"); - - } - -} + private enum SuggestionState + { + Write, + Sending, + Failed, + Sent + } +} \ No newline at end of file diff --git a/Assets/Scripts/TargaImporter.cs b/Assets/Scripts/TargaImporter.cs deleted file mode 100644 index f526d817..00000000 --- a/Assets/Scripts/TargaImporter.cs +++ /dev/null @@ -1,2249 +0,0 @@ -/** - * This is a modified library from CodeProject: http://www.codeproject.com/Articles/31702/NET-Targa-Image-Reader - * It is modified to remove most .NET dependencies and replaced them with Unity equivilents. This means - * this code should be able to run on all platforms. - * - * No guarantee everything works, but seems to be alright with uncompressed textures. - * It's probably slow, but suits my needs. - * - * Look for "Unity" to see the changes made. - * - * Usage: Texture2D texture = Paloma.TargaImage.LoadTargaImage( "filename.tga" ); - */ - -// ========================================================== -// TargaImage -// -// Design and implementation by -// - David Polomis (paloma_sw@cox.net) -// -// -// This source code, along with any associated files, is licensed under -// The Code Project Open License (CPOL) 1.02 -// A copy of this license can be found in the CPOL.html file -// which was downloaded with this source code -// or at http://www.codeproject.com/info/cpol10.aspx -// -// -// COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, -// WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, -// INCLUDING, WITHOUT LIMITATION, WARRANTIES THAT THE COVERED CODE IS -// FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE OR -// NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE -// OF THE COVERED CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE -// DEFECTIVE IN ANY RESPECT, YOU (NOT THE INITIAL DEVELOPER OR ANY -// OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY SERVICING, -// REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN -// ESSENTIAL PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS -// AUTHORIZED HEREUNDER EXCEPT UNDER THIS DISCLAIMER. -// -// Use at your own risk! -// -// ========================================================== - - -using System; -using System.Collections.Generic; -using System.Collections; -using System.Text; -using System.IO; -using System.Runtime.InteropServices; - -using UnityEngine; - -namespace Paloma -{ - internal static class TargaConstants - { - // constant byte lengths for various fields in the Targa format - internal const int HeaderByteLength = 18; - internal const int FooterByteLength = 26; - internal const int FooterSignatureOffsetFromEnd = 18; - internal const int FooterSignatureByteLength = 16; - internal const int FooterReservedCharByteLength = 1; - internal const int ExtensionAreaAuthorNameByteLength = 41; - internal const int ExtensionAreaAuthorCommentsByteLength = 324; - internal const int ExtensionAreaJobNameByteLength = 41; - internal const int ExtensionAreaSoftwareIDByteLength = 41; - internal const int ExtensionAreaSoftwareVersionLetterByteLength = 1; - internal const int ExtensionAreaColorCorrectionTableValueLength = 256; - internal const string TargaFooterASCIISignature = "TRUEVISION-XFILE"; - } - - - /// - /// The Targa format of the file. - /// - public enum TGAFormat - { - /// - /// Unknown Targa Image format. - /// - UNKNOWN = 0, - - /// - /// Original Targa Image format. - /// - /// Targa Image does not have a Signature of ""TRUEVISION-XFILE"". - ORIGINAL_TGA = 100, - - /// - /// New Targa Image format - /// - /// Targa Image has a TargaFooter with a Signature of ""TRUEVISION-XFILE"". - NEW_TGA = 200 - } - - - /// - /// Indicates the type of color map, if any, included with the image file. - /// - public enum ColorMapType : byte - { - /// - /// No color map was included in the file. - /// - NO_COLOR_MAP = 0, - - /// - /// Color map was included in the file. - /// - COLOR_MAP_INCLUDED = 1 - } - - - /// - /// The type of image read from the file. - /// - public enum ImageType : byte - { - /// - /// No image data was found in file. - /// - NO_IMAGE_DATA = 0, - - /// - /// Image is an uncompressed, indexed color-mapped image. - /// - UNCOMPRESSED_COLOR_MAPPED = 1, - - /// - /// Image is an uncompressed, RGB image. - /// - UNCOMPRESSED_TRUE_COLOR = 2, - - /// - /// Image is an uncompressed, Greyscale image. - /// - UNCOMPRESSED_BLACK_AND_WHITE = 3, - - /// - /// Image is a compressed, indexed color-mapped image. - /// - RUN_LENGTH_ENCODED_COLOR_MAPPED = 9, - - /// - /// Image is a compressed, RGB image. - /// - RUN_LENGTH_ENCODED_TRUE_COLOR = 10, - - /// - /// Image is a compressed, Greyscale image. - /// - RUN_LENGTH_ENCODED_BLACK_AND_WHITE = 11 - } - - - /// - /// The top-to-bottom ordering in which pixel data is transferred from the file to the screen. - /// - public enum VerticalTransferOrder - { - /// - /// Unknown transfer order. - /// - UNKNOWN = -1, - - /// - /// Transfer order of pixels is from the bottom to top. - /// - BOTTOM = 0, - - /// - /// Transfer order of pixels is from the top to bottom. - /// - TOP = 1 - } - - - /// - /// The left-to-right ordering in which pixel data is transferred from the file to the screen. - /// - public enum HorizontalTransferOrder - { - /// - /// Unknown transfer order. - /// - UNKNOWN = -1, - - /// - /// Transfer order of pixels is from the right to left. - /// - RIGHT = 0, - - /// - /// Transfer order of pixels is from the left to right. - /// - LEFT = 1 - } - - - /// - /// Screen destination of first pixel based on the VerticalTransferOrder and HorizontalTransferOrder. - /// - public enum FirstPixelDestination - { - /// - /// Unknown first pixel destination. - /// - UNKNOWN = 0, - - /// - /// First pixel destination is the top-left corner of the image. - /// - TOP_LEFT = 1, - - /// - /// First pixel destination is the top-right corner of the image. - /// - TOP_RIGHT = 2, - - /// - /// First pixel destination is the bottom-left corner of the image. - /// - BOTTOM_LEFT = 3, - - /// - /// First pixel destination is the bottom-right corner of the image. - /// - BOTTOM_RIGHT = 4 - } - - - /// - /// The RLE packet type used in a RLE compressed image. - /// - public enum RLEPacketType - { - /// - /// A raw RLE packet type. - /// - RAW = 0, - - /// - /// A run-length RLE packet type. - /// - RUN_LENGTH = 1 - } - - - /// - /// Reads and loads a Truevision TGA Format image file. - /// - public class TargaImage - - { - private TargaHeader objTargaHeader = null; - private TargaExtensionArea objTargaExtensionArea = null; - private TargaFooter objTargaFooter = null; - private Texture2D bmpTargaImage = null; - private Texture2D bmpImageThumbnail = null; - private TGAFormat eTGAFormat = TGAFormat.UNKNOWN; - private string strFileName = string.Empty; - private int intStride = 0; - private int intPadding = 0; - private System.Collections.Generic.List> rows = new System.Collections.Generic.List>(); - private System.Collections.Generic.List row = new System.Collections.Generic.List(); - - /// - /// Creates a new instance of the TargaImage object. - /// - public TargaImage() - { - this.objTargaFooter = new TargaFooter(); - this.objTargaHeader = new TargaHeader(); - this.objTargaExtensionArea = new TargaExtensionArea(); - this.bmpTargaImage = null; - this.bmpImageThumbnail = null; - } - - - /// - /// Gets a TargaHeader object that holds the Targa Header information of the loaded file. - /// - public TargaHeader Header - { - get { return this.objTargaHeader; } - } - - - /// - /// Gets a TargaExtensionArea object that holds the Targa Extension Area information of the loaded file. - /// - public TargaExtensionArea ExtensionArea - { - get { return this.objTargaExtensionArea; } - } - - - /// - /// Gets a TargaExtensionArea object that holds the Targa Footer information of the loaded file. - /// - public TargaFooter Footer - { - get { return this.objTargaFooter; } - } - - - /// - /// Gets the Targa format of the loaded file. - /// - public TGAFormat Format - { - get { return this.eTGAFormat; } - } - - - /// - /// Gets a Bitmap representation of the loaded file. - /// - public Texture Image - { - get { return this.bmpTargaImage; } - } - - /// - /// Gets the thumbnail of the loaded file if there is one in the file. - /// - public Texture Thumbnail - { - get { return this.bmpImageThumbnail; } - } - - /// - /// Gets the full path and filename of the loaded file. - /// - public string FileName - { - get { return this.strFileName; } - } - - - /// - /// Gets the byte offset between the beginning of one scan line and the next. Used when loading the image into the Image Bitmap. - /// - /// - /// The memory allocated for Microsoft Bitmaps must be aligned on a 32bit boundary. - /// The stride refers to the number of bytes allocated for one scanline of the bitmap. - /// - public int Stride - { - get { return this.intStride; } - } - - - /// - /// Gets the number of bytes used to pad each scan line to meet the Stride value. Used when loading the image into the Image Bitmap. - /// - /// - /// The memory allocated for Microsoft Bitmaps must be aligned on a 32bit boundary. - /// The stride refers to the number of bytes allocated for one scanline of the bitmap. - /// In your loop, you copy the pixels one scanline at a time and take into - /// consideration the amount of padding that occurs due to memory alignment. - /// - public int Padding - { - get { return this.intPadding; } - } - - /// - /// Creates a new instance of the TargaImage object with strFileName as the image loaded. - /// - public TargaImage(string strFileName) : this() - { - // make sure we have a .tga file - if (System.IO.Path.GetExtension(strFileName).ToLower() == ".tga") - { - // make sure the file exists - if (System.IO.File.Exists(strFileName) == true) - { - this.strFileName = strFileName; - MemoryStream filestream = null; - BinaryReader binReader = null; - byte[] filebytes = null; - - // load the file as an array of bytes - filebytes = System.IO.File.ReadAllBytes(this.strFileName); - if (filebytes != null && filebytes.Length > 0) - { - // create a seekable memory stream of the file bytes - using (filestream = new MemoryStream(filebytes)) - { - if (filestream != null && filestream.Length > 0 && filestream.CanSeek == true) - { - // create a BinaryReader used to read the Targa file - using (binReader = new BinaryReader(filestream)) - { - this.LoadTGAFooterInfo(binReader); - this.LoadTGAHeaderInfo(binReader); - this.LoadTGAExtensionArea(binReader); - this.LoadTGAImage(binReader); - } - } - else - throw new Exception(@"Error loading file, could not read file from disk."); - - } - - } - else - throw new Exception(@"Error loading file, could not read file from disk."); - - } - else - throw new Exception(@"Error loading file, could not find file '" + strFileName + "' on disk."); - - } - else - throw new Exception(@"Error loading file, file '" + strFileName + "' must have an extension of '.tga'."); - - - } - - - /// - /// Loads the Targa Footer information from the file. - /// - /// A BinaryReader that points the loaded file byte stream. - private void LoadTGAFooterInfo(BinaryReader binReader) - { - - if (binReader != null && binReader.BaseStream != null && binReader.BaseStream.Length > 0 && binReader.BaseStream.CanSeek == true) - { - - try - { - // set the cursor at the beginning of the signature string. - binReader.BaseStream.Seek((TargaConstants.FooterSignatureOffsetFromEnd * -1), SeekOrigin.End); - - // read the signature bytes and convert to ascii string - string Signature = System.Text.Encoding.ASCII.GetString(binReader.ReadBytes(TargaConstants.FooterSignatureByteLength)).TrimEnd('\0'); - - // do we have a proper signature - if (string.Compare(Signature, TargaConstants.TargaFooterASCIISignature) == 0) - { - // this is a NEW targa file. - // create the footer - this.eTGAFormat = TGAFormat.NEW_TGA; - - // set cursor to beginning of footer info - binReader.BaseStream.Seek((TargaConstants.FooterByteLength * -1), SeekOrigin.End); - - // read the Extension Area Offset value - int ExtOffset = binReader.ReadInt32(); - - // read the Developer Directory Offset value - int DevDirOff = binReader.ReadInt32(); - - // skip the signature we have already read it. - binReader.ReadBytes(TargaConstants.FooterSignatureByteLength); - - // read the reserved character - string ResChar = System.Text.Encoding.ASCII.GetString(binReader.ReadBytes(TargaConstants.FooterReservedCharByteLength)).TrimEnd('\0'); - - // set all values to our TargaFooter class - this.objTargaFooter.SetExtensionAreaOffset(ExtOffset); - this.objTargaFooter.SetDeveloperDirectoryOffset(DevDirOff); - this.objTargaFooter.SetSignature(Signature); - this.objTargaFooter.SetReservedCharacter(ResChar); - } - else - { - // this is not an ORIGINAL targa file. - this.eTGAFormat = TGAFormat.ORIGINAL_TGA; - } - } - catch ( Exception ex ) - { - // clear all - this.ClearAll(); - throw ex; - } - } - else - { - this.ClearAll(); - throw new Exception(@"Error loading file, could not read file from disk."); - } - - - } - - - /// - /// Loads the Targa Header information from the file. - /// - /// A BinaryReader that points the loaded file byte stream. - private void LoadTGAHeaderInfo(BinaryReader binReader) - { - - if (binReader != null && binReader.BaseStream != null && binReader.BaseStream.Length > 0 && binReader.BaseStream.CanSeek == true) - { - try - { - // set the cursor at the beginning of the file. - binReader.BaseStream.Seek(0, SeekOrigin.Begin); - - // read the header properties from the file - this.objTargaHeader.SetImageIDLength(binReader.ReadByte()); - this.objTargaHeader.SetColorMapType((ColorMapType)binReader.ReadByte()); - this.objTargaHeader.SetImageType((ImageType)binReader.ReadByte()); - - this.objTargaHeader.SetColorMapFirstEntryIndex(binReader.ReadInt16()); - this.objTargaHeader.SetColorMapLength(binReader.ReadInt16()); - this.objTargaHeader.SetColorMapEntrySize(binReader.ReadByte()); - - this.objTargaHeader.SetXOrigin(binReader.ReadInt16()); - this.objTargaHeader.SetYOrigin(binReader.ReadInt16()); - this.objTargaHeader.SetWidth(binReader.ReadInt16()); - this.objTargaHeader.SetHeight(binReader.ReadInt16()); - - byte pixeldepth = binReader.ReadByte(); - switch (pixeldepth) - { - case 8: - case 16: - case 24: - case 32: - this.objTargaHeader.SetPixelDepth(pixeldepth); - break; - - default: - this.ClearAll(); - throw new Exception("Targa Image only supports 8, 16, 24, or 32 bit pixel depths."); - } - - - byte ImageDescriptor = binReader.ReadByte(); - this.objTargaHeader.SetAttributeBits((byte)Utilities.GetBits(ImageDescriptor, 0, 4)); - - this.objTargaHeader.SetVerticalTransferOrder((VerticalTransferOrder)Utilities.GetBits(ImageDescriptor, 5, 1)); - this.objTargaHeader.SetHorizontalTransferOrder((HorizontalTransferOrder)Utilities.GetBits(ImageDescriptor, 4, 1)); - - // load ImageID value if any - if (this.objTargaHeader.ImageIDLength > 0) - { - byte[] ImageIDValueBytes = binReader.ReadBytes(this.objTargaHeader.ImageIDLength); - this.objTargaHeader.SetImageIDValue(System.Text.Encoding.ASCII.GetString(ImageIDValueBytes).TrimEnd('\0')); - } - } - catch (Exception ex) - { - this.ClearAll(); - throw ex; - } - - - // load color map if it's included and/or needed - // Only needed for UNCOMPRESSED_COLOR_MAPPED and RUN_LENGTH_ENCODED_COLOR_MAPPED - // image types. If color map is included for other file types we can ignore it. - if (this.objTargaHeader.ColorMapType == ColorMapType.COLOR_MAP_INCLUDED) - { - if (this.objTargaHeader.ImageType == ImageType.UNCOMPRESSED_COLOR_MAPPED || - this.objTargaHeader.ImageType == ImageType.RUN_LENGTH_ENCODED_COLOR_MAPPED) - { - if (this.objTargaHeader.ColorMapLength > 0) - { - try - { - for (int i = 0; i < this.objTargaHeader.ColorMapLength; i++) - { - byte a = 0; - byte r = 0; - byte g = 0; - byte b = 0; - - // load each color map entry based on the ColorMapEntrySize value - switch (this.objTargaHeader.ColorMapEntrySize) - { - case 15: - byte[] color15 = binReader.ReadBytes(2); - // remember that the bytes are stored in reverse oreder - this.objTargaHeader.ColorMap.Add(Utilities.GetColorFrom2Bytes(color15[1], color15[0])); - break; - case 16: - byte[] color16 = binReader.ReadBytes(2); - // remember that the bytes are stored in reverse oreder - this.objTargaHeader.ColorMap.Add(Utilities.GetColorFrom2Bytes(color16[1], color16[0])); - break; - case 24: - b = binReader.ReadByte(); - g = binReader.ReadByte(); - r = binReader.ReadByte(); - this.objTargaHeader.ColorMap.Add(new Color32(r, g, b, 255)); - break; - case 32: - a = binReader.ReadByte(); - b = binReader.ReadByte(); - g = binReader.ReadByte(); - r = binReader.ReadByte(); - this.objTargaHeader.ColorMap.Add(new Color32(r, g, b, a)); - break; - default: - this.ClearAll(); - throw new Exception("TargaImage only supports ColorMap Entry Sizes of 15, 16, 24 or 32 bits."); - - } - - - } - } - catch (Exception ex) - { - this.ClearAll(); - throw ex; - } - - - - } - else - { - this.ClearAll(); - throw new Exception("Image Type requires a Color Map and Color Map Length is zero."); - } - } - - - } - else - { - if (this.objTargaHeader.ImageType == ImageType.UNCOMPRESSED_COLOR_MAPPED || - this.objTargaHeader.ImageType == ImageType.RUN_LENGTH_ENCODED_COLOR_MAPPED) - { - this.ClearAll(); - throw new Exception("Image Type requires a Color Map and there was not a Color Map included in the file."); - } - } - - - } - else - { - this.ClearAll(); - throw new Exception(@"Error loading file, could not read file from disk."); - } - } - - - /// - /// Loads the Targa Extension Area from the file, if it exists. - /// - /// A BinaryReader that points the loaded file byte stream. - private void LoadTGAExtensionArea(BinaryReader binReader) - { - - if (binReader != null && binReader.BaseStream != null && binReader.BaseStream.Length > 0 && binReader.BaseStream.CanSeek == true) - { - // is there an Extension Area in file - if (this.objTargaFooter.ExtensionAreaOffset > 0) - { - try - { - // set the cursor at the beginning of the Extension Area using ExtensionAreaOffset. - binReader.BaseStream.Seek(this.objTargaFooter.ExtensionAreaOffset, SeekOrigin.Begin); - - // load the extension area fields from the file - - this.objTargaExtensionArea.SetExtensionSize((int)(binReader.ReadInt16())); - this.objTargaExtensionArea.SetAuthorName(System.Text.Encoding.ASCII.GetString(binReader.ReadBytes(TargaConstants.ExtensionAreaAuthorNameByteLength)).TrimEnd('\0')); - this.objTargaExtensionArea.SetAuthorComments(System.Text.Encoding.ASCII.GetString(binReader.ReadBytes(TargaConstants.ExtensionAreaAuthorCommentsByteLength)).TrimEnd('\0')); - - - // get the date/time stamp of the file - Int16 iMonth = binReader.ReadInt16(); - Int16 iDay = binReader.ReadInt16(); - Int16 iYear = binReader.ReadInt16(); - Int16 iHour = binReader.ReadInt16(); - Int16 iMinute = binReader.ReadInt16(); - Int16 iSecond = binReader.ReadInt16(); - DateTime dtstamp; - string strStamp = iMonth.ToString() + @"/" + iDay.ToString() + @"/" + iYear.ToString() + @" "; - strStamp += iHour.ToString() + @":" + iMinute.ToString() + @":" + iSecond.ToString(); - if (DateTime.TryParse(strStamp, out dtstamp) == true) - this.objTargaExtensionArea.SetDateTimeStamp(dtstamp); - - - this.objTargaExtensionArea.SetJobName(System.Text.Encoding.ASCII.GetString(binReader.ReadBytes(TargaConstants.ExtensionAreaJobNameByteLength)).TrimEnd('\0')); - - - // get the job time of the file - iHour = binReader.ReadInt16(); - iMinute = binReader.ReadInt16(); - iSecond = binReader.ReadInt16(); - TimeSpan ts = new TimeSpan((int)iHour, (int)iMinute, (int)iSecond); - this.objTargaExtensionArea.SetJobTime(ts); - - - this.objTargaExtensionArea.SetSoftwareID(System.Text.Encoding.ASCII.GetString(binReader.ReadBytes(TargaConstants.ExtensionAreaSoftwareIDByteLength)).TrimEnd('\0')); - - - // get the version number and letter from file - float iVersionNumber = (float)binReader.ReadInt16() / 100.0F; - string strVersionLetter = System.Text.Encoding.ASCII.GetString(binReader.ReadBytes(TargaConstants.ExtensionAreaSoftwareVersionLetterByteLength)).TrimEnd('\0'); - - - this.objTargaExtensionArea.SetSoftwareID(iVersionNumber.ToString(@"F2") + strVersionLetter); - - - // get the color key of the file - byte a = binReader.ReadByte(); - byte r = binReader.ReadByte(); - byte b = binReader.ReadByte(); - byte g = binReader.ReadByte(); - this.objTargaExtensionArea.SetKeyColor(new Color32(r, g, b, a)); - - - this.objTargaExtensionArea.SetPixelAspectRatioNumerator((int)binReader.ReadInt16()); - this.objTargaExtensionArea.SetPixelAspectRatioDenominator((int)binReader.ReadInt16()); - this.objTargaExtensionArea.SetGammaNumerator((int)binReader.ReadInt16()); - this.objTargaExtensionArea.SetGammaDenominator((int)binReader.ReadInt16()); - this.objTargaExtensionArea.SetColorCorrectionOffset(binReader.ReadInt32()); - this.objTargaExtensionArea.SetPostageStampOffset(binReader.ReadInt32()); - this.objTargaExtensionArea.SetScanLineOffset(binReader.ReadInt32()); - this.objTargaExtensionArea.SetAttributesType((int)binReader.ReadByte()); - - - // load Scan Line Table from file if any - if (this.objTargaExtensionArea.ScanLineOffset > 0) - { - binReader.BaseStream.Seek(this.objTargaExtensionArea.ScanLineOffset, SeekOrigin.Begin); - for (int i = 0; i < this.objTargaHeader.Height; i++) - { - this.objTargaExtensionArea.ScanLineTable.Add(binReader.ReadInt32()); - } - } - - - // load Color Correction Table from file if any - if (this.objTargaExtensionArea.ColorCorrectionOffset > 0) - { - binReader.BaseStream.Seek(this.objTargaExtensionArea.ColorCorrectionOffset, SeekOrigin.Begin); - for (int i = 0; i < TargaConstants.ExtensionAreaColorCorrectionTableValueLength; i++) - { - a = Convert.ToByte(binReader.ReadInt16()); - r = Convert.ToByte(binReader.ReadInt16()); - b = Convert.ToByte(binReader.ReadInt16()); - g = Convert.ToByte(binReader.ReadInt16()); - this.objTargaExtensionArea.ColorCorrectionTable.Add(new Color32(r, g, b, a)); - } - } - } - catch (Exception ex) - { - this.ClearAll(); - throw ex; - } - } - } - else - { - this.ClearAll(); - throw new Exception(@"Error loading file, could not read file from disk."); - } - } - - /// - /// Reads the image data bytes from the file. Handles Uncompressed and RLE Compressed image data. - /// Uses FirstPixelDestination to properly align the image. - /// - /// A BinaryReader that points the loaded file byte stream. - /// An array of bytes representing the image data in the proper alignment. - private byte[] LoadImageBytes(BinaryReader binReader) - { - - // read the image data into a byte array - // take into account stride has to be a multiple of 4 - // use padding to make sure multiple of 4 - - byte[] data = null; - if (binReader != null && binReader.BaseStream != null && binReader.BaseStream.Length > 0 && binReader.BaseStream.CanSeek == true) - { - if (this.objTargaHeader.ImageDataOffset > 0) - { - // padding bytes - byte[] padding = new byte[this.intPadding]; - MemoryStream msData = null; - - // seek to the beginning of the image data using the ImageDataOffset value - binReader.BaseStream.Seek(this.objTargaHeader.ImageDataOffset, SeekOrigin.Begin); - - - // get the size in bytes of each row in the image - int intImageRowByteSize = (int)this.objTargaHeader.Width * ((int)this.objTargaHeader.BytesPerPixel); - - // get the size in bytes of the whole image - int intImageByteSize = intImageRowByteSize * (int)this.objTargaHeader.Height; - - // is this a RLE compressed image type - if (this.objTargaHeader.ImageType == ImageType.RUN_LENGTH_ENCODED_BLACK_AND_WHITE || - this.objTargaHeader.ImageType == ImageType.RUN_LENGTH_ENCODED_COLOR_MAPPED || - this.objTargaHeader.ImageType == ImageType.RUN_LENGTH_ENCODED_TRUE_COLOR) - { - - #region COMPRESSED - - // RLE Packet info - byte bRLEPacket = 0; - int intRLEPacketType = -1; - int intRLEPixelCount = 0; - byte[] bRunLengthPixel = null; - - // used to keep track of bytes read - int intImageBytesRead = 0; - int intImageRowBytesRead = 0; - - // keep reading until we have the all image bytes - while (intImageBytesRead < intImageByteSize) - { - // get the RLE packet - bRLEPacket = binReader.ReadByte(); - intRLEPacketType = Utilities.GetBits(bRLEPacket, 7, 1); - intRLEPixelCount = Utilities.GetBits(bRLEPacket, 0, 7) + 1; - - // check the RLE packet type - if ((RLEPacketType)intRLEPacketType == RLEPacketType.RUN_LENGTH) - { - // get the pixel color data - bRunLengthPixel = binReader.ReadBytes((int)this.objTargaHeader.BytesPerPixel); - - // add the number of pixels specified using the read pixel color - for (int i = 0; i < intRLEPixelCount; i++) - { - foreach (byte b in bRunLengthPixel) - row.Add(b); - - // increment the byte counts - intImageRowBytesRead += bRunLengthPixel.Length; - intImageBytesRead += bRunLengthPixel.Length; - - // if we have read a full image row - // add the row to the row list and clear it - // restart row byte count - if (intImageRowBytesRead == intImageRowByteSize) - { - rows.Add(row); - row = new System.Collections.Generic.List( intImageByteSize ); - intImageRowBytesRead = 0; - } - } - - } - - else if ((RLEPacketType)intRLEPacketType == RLEPacketType.RAW) - { - // get the number of bytes to read based on the read pixel count - int intBytesToRead = intRLEPixelCount * (int)this.objTargaHeader.BytesPerPixel; - - // read each byte - for (int i = 0;i < intBytesToRead;i++) - { - row.Add(binReader.ReadByte()); - - // increment the byte counts - intImageBytesRead++; - intImageRowBytesRead++; - - // if we have read a full image row - // add the row to the row list and clear it - // restart row byte count - if (intImageRowBytesRead == intImageRowByteSize) - { - rows.Add(row); - row = new System.Collections.Generic.List( intImageRowByteSize ); - intImageRowBytesRead = 0; - } - - } - - } - } - - #endregion - - } - - else - { - #region NON-COMPRESSED - - // loop through each row in the image - for (int i = 0; i < (int)this.objTargaHeader.Height; i++) - { - // Read in the row - row.AddRange( binReader.ReadBytes(intImageRowByteSize) ); - - // add row to the list of rows - rows.Add(row); - - // create a new row - row = new System.Collections.Generic.List( intImageRowByteSize ); - } - - - #endregion - } - - // flag that states whether or not to reverse the location of all rows. - bool blnRowsReverse = true; - - // flag that states whether or not to reverse the bytes in each row. - bool blnEachRowReverse = false; - - // Unity: We have the reverse behaviour due to in-memory texture alignment - // use FirstPixelDestination to determine the alignment of the - // image data byte - switch (this.objTargaHeader.FirstPixelDestination) - { - case FirstPixelDestination.TOP_LEFT: - blnRowsReverse = true; - blnEachRowReverse = true; - break; - - case FirstPixelDestination.TOP_RIGHT: - blnRowsReverse = true; - blnEachRowReverse = false; - break; - - case FirstPixelDestination.BOTTOM_LEFT: - blnRowsReverse = false; - blnEachRowReverse = true; - break; - - case FirstPixelDestination.BOTTOM_RIGHT: - case FirstPixelDestination.UNKNOWN: - blnRowsReverse = false; - blnEachRowReverse = false; - - break; - } - - // write the bytes from each row into a memory stream and get the - // resulting byte array - using (msData = new MemoryStream()) - { - - // do we reverse the rows in the row list. - if (blnRowsReverse == true) - rows.Reverse(); - - // go through each row - for (int i = 0; i < rows.Count; i++) - { - // do we reverse the bytes in the row - if (blnEachRowReverse == true) - rows[i].Reverse(); - - // get the byte array for the row - byte[] brow = rows[i].ToArray(); - - // write the row bytes and padding bytes to the memory streem - msData.Write(brow, 0, brow.Length); - msData.Write(padding, 0, padding.Length); - } - // get the image byte array - data = msData.ToArray(); - - - - } - - } - else - { - this.ClearAll(); - throw new Exception(@"Error loading file, No image data in file."); - } - } - else - { - this.ClearAll(); - throw new Exception(@"Error loading file, could not read file from disk."); - } - - // return the image byte array - return data; - - } - - /// - /// Reads the image data bytes from the file and loads them into the Image Bitmap object. - /// Also loads the color map, if any, into the Image Bitmap. - /// - /// A BinaryReader that points the loaded file byte stream. - private void LoadTGAImage(BinaryReader binReader) - { - //************** NOTE ******************* - // The memory allocated for Microsoft Bitmaps must be aligned on a 32bit boundary. - // The stride refers to the number of bytes allocated for one scanline of the bitmap. - // In your loop, you copy the pixels one scanline at a time and take into - // consideration the amount of padding that occurs due to memory alignment. - // calculate the stride, in bytes, of the image (32bit aligned width of each image row) - this.intStride = (((int)this.objTargaHeader.Width * (int)this.objTargaHeader.PixelDepth + 31) & ~31) >> 3; // width in bytes - - // calculate the padding, in bytes, of the image - // number of bytes to add to make each row a 32bit aligned row - // padding in bytes - this.intPadding = this.intStride - ((((int)this.objTargaHeader.Width * (int)this.objTargaHeader.PixelDepth) + 7) / 8); - - // get the image data bytes - byte[] bimagedata = this.LoadImageBytes(binReader); - - // get the Pixel format to use with the Bitmap object - TextureFormat pf = this.GetPixelFormat(); - - // create a Bitmap object using the image Width, Height, - // Stride, PixelFormat and the pointer to the pinned byte array. - bmpTargaImage = new UnityEngine.Texture2D((int)this.objTargaHeader.Width, (int)this.objTargaHeader.Height, pf, false); - - // Unity does not properly support BGRA32, so we should manually swap the data - // If this becomes a performance bottle-neck, you can always do the swap in a shader - - if ( pf == TextureFormat.BGRA32 ) - { - for (int i = 0 ; i < bimagedata.Length ; i += 4) - { - // Swap R (byte0) with B (byte2) - byte r = bimagedata[i]; - bimagedata[i] = bimagedata[i+2]; - bimagedata[i+2] = r; - } - } - - bmpTargaImage.LoadRawTextureData( bimagedata ); - bmpTargaImage.Apply(false, true); - - this.LoadThumbnail(binReader, pf); - - // Unity: Ripped out a bunch of palette code - } - - /// - /// Gets the PixelFormat to be used by the Image based on the Targa file's attributes - /// - /// - /// Unity: We probably can't support most of these, so I just changed them to a best guess. - /// - /// - private TextureFormat GetPixelFormat() - { - UnityEngine.TextureFormat targaPixelFormat = TextureFormat.ARGB32; - - // first off what is our Pixel Depth (bits per pixel) - switch (this.objTargaHeader.PixelDepth) - { - case 8: - targaPixelFormat = TextureFormat.Alpha8; - break; - - case 16: - if (this.Format == TGAFormat.NEW_TGA) - { - switch (this.objTargaExtensionArea.AttributesType) - { - case 0: - case 1: - case 2: // no alpha data - targaPixelFormat = TextureFormat.RGB565; - break; - - case 3: // useful alpha data - targaPixelFormat = TextureFormat.RGB565; - break; - } - } - else - { - targaPixelFormat = TextureFormat.RGB565; - } - - break; - - case 24: - targaPixelFormat = TextureFormat.RGB24; - break; - - case 32: - if (this.Format == TGAFormat.NEW_TGA) - { - switch (this.objTargaExtensionArea.AttributesType) - { - - case 1: - case 2: // no alpha data - targaPixelFormat = TextureFormat.BGRA32; - break; - - case 0: - case 3: // useful alpha data - targaPixelFormat = TextureFormat.BGRA32; - break; - - case 4: // premultiplied alpha data - targaPixelFormat = TextureFormat.BGRA32; - break; - - } - } - else - { - targaPixelFormat = TextureFormat.BGRA32; - break; - } - break; - } - - return targaPixelFormat; - } - - - /// - /// Loads the thumbnail of the loaded image file, if any. - /// - /// A BinaryReader that points the loaded file byte stream. - /// A PixelFormat value indicating what pixel format to use when loading the thumbnail. - private void LoadThumbnail(BinaryReader binReader, TextureFormat pfPixelFormat) - { - - // read the Thumbnail image data into a byte array - // take into account stride has to be a multiple of 4 - // use padding to make sure multiple of 4 - - byte[] data = null; - if (binReader != null && binReader.BaseStream != null && binReader.BaseStream.Length > 0 && binReader.BaseStream.CanSeek == true) - { - if (this.ExtensionArea.PostageStampOffset > 0) - { - - // seek to the beginning of the image data using the ImageDataOffset value - binReader.BaseStream.Seek(this.ExtensionArea.PostageStampOffset, SeekOrigin.Begin); - - int iWidth = (int)binReader.ReadByte(); - int iHeight = (int)binReader.ReadByte(); - - int iStride = ((iWidth * (int)this.objTargaHeader.PixelDepth + 31) & ~31) >> 3; // width in bytes - int iPadding = iStride - (((iWidth * (int)this.objTargaHeader.PixelDepth) + 7) / 8); - - System.Collections.Generic.List> objRows = new System.Collections.Generic.List>(); - System.Collections.Generic.List objRow = new System.Collections.Generic.List(); - - - - - byte[] padding = new byte[iPadding]; - MemoryStream msData = null; - bool blnEachRowReverse = false; - bool blnRowsReverse = false; - - - using (msData = new MemoryStream()) - { - // get the size in bytes of each row in the image - int intImageRowByteSize = iWidth * ((int)this.objTargaHeader.PixelDepth / 8); - - // thumbnails are never compressed - for (int i = 0; i < iHeight; i++) - { - objRow.AddRange( binReader.ReadBytes(intImageRowByteSize) ); - objRows.Add(objRow); - objRow = new System.Collections.Generic.List( intImageRowByteSize ); - } - - switch (this.objTargaHeader.FirstPixelDestination) - { - case FirstPixelDestination.TOP_LEFT: - break; - - case FirstPixelDestination.TOP_RIGHT: - blnRowsReverse = false; - blnEachRowReverse = false; - break; - - case FirstPixelDestination.BOTTOM_LEFT: - break; - - case FirstPixelDestination.BOTTOM_RIGHT: - case FirstPixelDestination.UNKNOWN: - blnRowsReverse = true; - blnEachRowReverse = false; - - break; - } - - if (blnRowsReverse == true) - objRows.Reverse(); - - for (int i = 0; i < objRows.Count; i++) - { - if (blnEachRowReverse == true) - objRows[i].Reverse(); - - byte[] brow = objRows[i].ToArray(); - msData.Write(brow, 0, brow.Length); - msData.Write(padding, 0, padding.Length); - } - data = msData.ToArray(); - } - - if (data != null && data.Length > 0) - { - // Unity: use Texture2D - bmpImageThumbnail = new Texture2D( iWidth, iHeight, pfPixelFormat, false); - bmpImageThumbnail.LoadRawTextureData( data ); - } - } - else - { - UnityEngine.Object.Destroy( bmpImageThumbnail ); - bmpImageThumbnail = null; - } - } - else - { - UnityEngine.Object.Destroy( bmpImageThumbnail ); - bmpImageThumbnail = null; - } - - } - - /// - /// Clears out all objects and resources. - /// - private void ClearAll() - { - UnityEngine.Object.Destroy( bmpTargaImage ); - UnityEngine.Object.Destroy( bmpImageThumbnail ); - - this.bmpTargaImage = null; - this.bmpImageThumbnail = null; - - this.objTargaHeader = new TargaHeader(); - this.objTargaExtensionArea = new TargaExtensionArea(); - this.objTargaFooter = new TargaFooter(); - this.eTGAFormat = TGAFormat.UNKNOWN; - this.intStride = 0; - this.intPadding = 0; - this.rows.Clear(); - this.row.Clear(); - this.strFileName = string.Empty; - - } - - /// - /// Loads a Targa image file into a Bitmap object. - /// - /// The Targa image filename - /// A Bitmap object with the Targa image loaded into it. - public static Texture2D LoadTargaImage(string sFileName) - { - TargaImage ti = new TargaImage(sFileName); - return ti.bmpTargaImage; - } - } - - - /// - /// This class holds all of the header properties of a Targa image. - /// This includes the TGA File Header section the ImageID and the Color Map. - /// - public class TargaHeader - { - private byte bImageIDLength = 0; - private ColorMapType eColorMapType = ColorMapType.NO_COLOR_MAP; - private ImageType eImageType = ImageType.NO_IMAGE_DATA; - private short sColorMapFirstEntryIndex = 0; - private short sColorMapLength = 0; - private byte bColorMapEntrySize = 0; - private short sXOrigin = 0; - private short sYOrigin = 0; - private short sWidth = 0; - private short sHeight = 0; - private byte bPixelDepth = 0; - private byte bImageDescriptor = 0; - private VerticalTransferOrder eVerticalTransferOrder = VerticalTransferOrder.UNKNOWN; - private HorizontalTransferOrder eHorizontalTransferOrder = HorizontalTransferOrder.UNKNOWN; - private byte bAttributeBits = 0; - private string strImageIDValue = string.Empty; - private System.Collections.Generic.List cColorMap = new List(); - - /// - /// Gets the number of bytes contained the ImageIDValue property. The maximum - /// number of characters is 255. A value of zero indicates that no ImageIDValue is included with the - /// image. - /// - public byte ImageIDLength - { - get { return this.bImageIDLength; } - } - - /// - /// Sets the ImageIDLength property, available only to objects in the same assembly as TargaHeader. - /// - /// The Image ID Length value read from the file. - internal protected void SetImageIDLength(byte bImageIDLength) - { - this.bImageIDLength = bImageIDLength; - } - - /// - /// Gets the type of color map (if any) included with the image. There are currently 2 - /// defined values for this field: - /// NO_COLOR_MAP - indicates that no color-map data is included with this image. - /// COLOR_MAP_INCLUDED - indicates that a color-map is included with this image. - /// - public ColorMapType ColorMapType - { - get { return this.eColorMapType; } - } - - /// - /// Sets the ColorMapType property, available only to objects in the same assembly as TargaHeader. - /// - /// One of the ColorMapType enumeration values. - internal protected void SetColorMapType(ColorMapType eColorMapType) - { - this.eColorMapType = eColorMapType; - } - - /// - /// Gets one of the ImageType enumeration values indicating the type of Targa image read from the file. - /// - public ImageType ImageType - { - get { return this.eImageType; } - } - - /// - /// Sets the ImageType property, available only to objects in the same assembly as TargaHeader. - /// - /// One of the ImageType enumeration values. - internal protected void SetImageType(ImageType eImageType) - { - this.eImageType = eImageType; - } - - /// - /// Gets the index of the first color map entry. ColorMapFirstEntryIndex refers to the starting entry in loading the color map. - /// - public short ColorMapFirstEntryIndex - { - get { return this.sColorMapFirstEntryIndex; } - } - - /// - /// Sets the ColorMapFirstEntryIndex property, available only to objects in the same assembly as TargaHeader. - /// - /// The First Entry Index value read from the file. - internal protected void SetColorMapFirstEntryIndex(short sColorMapFirstEntryIndex) - { - this.sColorMapFirstEntryIndex = sColorMapFirstEntryIndex; - } - - /// - /// Gets total number of color map entries included. - /// - public short ColorMapLength - { - get { return this.sColorMapLength; } - } - - /// - /// Sets the ColorMapLength property, available only to objects in the same assembly as TargaHeader. - /// - /// The Color Map Length value read from the file. - internal protected void SetColorMapLength(short sColorMapLength) - { - this.sColorMapLength = sColorMapLength; - } - - /// - /// Gets the number of bits per entry in the Color Map. Typically 15, 16, 24 or 32-bit values are used. - /// - public byte ColorMapEntrySize - { - get { return this.bColorMapEntrySize; } - } - - /// - /// Sets the ColorMapEntrySize property, available only to objects in the same assembly as TargaHeader. - /// - /// The Color Map Entry Size value read from the file. - internal protected void SetColorMapEntrySize(byte bColorMapEntrySize) - { - this.bColorMapEntrySize = bColorMapEntrySize; - } - - /// - /// Gets the absolute horizontal coordinate for the lower - /// left corner of the image as it is positioned on a display device having - /// an origin at the lower left of the screen (e.g., the TARGA series). - /// - public short XOrigin - { - get { return this.sXOrigin; } - } - - /// - /// Sets the XOrigin property, available only to objects in the same assembly as TargaHeader. - /// - /// The X Origin value read from the file. - internal protected void SetXOrigin(short sXOrigin) - { - this.sXOrigin = sXOrigin; - } - - /// - /// These bytes specify the absolute vertical coordinate for the lower left - /// corner of the image as it is positioned on a display device having an - /// origin at the lower left of the screen (e.g., the TARGA series). - /// - public short YOrigin - { - get { return this.sYOrigin; } - } - - /// - /// Sets the YOrigin property, available only to objects in the same assembly as TargaHeader. - /// - /// The Y Origin value read from the file. - internal protected void SetYOrigin(short sYOrigin) - { - this.sYOrigin = sYOrigin; - } - - /// - /// Gets the width of the image in pixels. - /// - public short Width - { - get { return this.sWidth; } - } - - /// - /// Sets the Width property, available only to objects in the same assembly as TargaHeader. - /// - /// The Width value read from the file. - internal protected void SetWidth(short sWidth) - { - this.sWidth = sWidth; - } - - /// - /// Gets the height of the image in pixels. - /// - public short Height - { - get { return this.sHeight; } - } - - /// - /// Sets the Height property, available only to objects in the same assembly as TargaHeader. - /// - /// The Height value read from the file. - internal protected void SetHeight(short sHeight) - { - this.sHeight = sHeight; - } - - /// - /// Gets the number of bits per pixel. This number includes - /// the Attribute or Alpha channel bits. Common values are 8, 16, 24 and 32. - /// - public byte PixelDepth - { - get { return this.bPixelDepth; } - } - - /// - /// Sets the PixelDepth property, available only to objects in the same assembly as TargaHeader. - /// - /// The Pixel Depth value read from the file. - internal protected void SetPixelDepth(byte bPixelDepth) - { - this.bPixelDepth = bPixelDepth; - } - - /// - /// Gets or Sets the ImageDescriptor property. The ImageDescriptor is the byte that holds the - /// Image Origin and Attribute Bits values. - /// Available only to objects in the same assembly as TargaHeader. - /// - internal protected byte ImageDescriptor - { - get { return this.bImageDescriptor; } - set { this.bImageDescriptor = value; } - } - - /// - /// Gets one of the FirstPixelDestination enumeration values specifying the screen destination of first pixel based on VerticalTransferOrder and HorizontalTransferOrder - /// - public FirstPixelDestination FirstPixelDestination - { - get - { - - if (this.eVerticalTransferOrder == VerticalTransferOrder.UNKNOWN || this.eHorizontalTransferOrder == HorizontalTransferOrder.UNKNOWN) - return FirstPixelDestination.UNKNOWN; - else if (this.eVerticalTransferOrder == VerticalTransferOrder.BOTTOM && this.eHorizontalTransferOrder == HorizontalTransferOrder.LEFT) - return FirstPixelDestination.BOTTOM_LEFT; - else if (this.eVerticalTransferOrder == VerticalTransferOrder.BOTTOM && this.eHorizontalTransferOrder == HorizontalTransferOrder.RIGHT) - return FirstPixelDestination.BOTTOM_RIGHT; - else if (this.eVerticalTransferOrder == VerticalTransferOrder.TOP && this.eHorizontalTransferOrder == HorizontalTransferOrder.LEFT) - return FirstPixelDestination.TOP_LEFT; - else - return FirstPixelDestination.TOP_RIGHT; - - } - } - - - /// - /// Gets one of the VerticalTransferOrder enumeration values specifying the top-to-bottom ordering in which pixel data is transferred from the file to the screen. - /// - public VerticalTransferOrder VerticalTransferOrder - { - get { return this.eVerticalTransferOrder; } - } - - /// - /// Sets the VerticalTransferOrder property, available only to objects in the same assembly as TargaHeader. - /// - /// One of the VerticalTransferOrder enumeration values. - internal protected void SetVerticalTransferOrder(VerticalTransferOrder eVerticalTransferOrder) - { - this.eVerticalTransferOrder = eVerticalTransferOrder; - } - - /// - /// Gets one of the HorizontalTransferOrder enumeration values specifying the left-to-right ordering in which pixel data is transferred from the file to the screen. - /// - public HorizontalTransferOrder HorizontalTransferOrder - { - get { return this.eHorizontalTransferOrder; } - } - - /// - /// Sets the HorizontalTransferOrder property, available only to objects in the same assembly as TargaHeader. - /// - /// One of the HorizontalTransferOrder enumeration values. - internal protected void SetHorizontalTransferOrder(HorizontalTransferOrder eHorizontalTransferOrder) - { - this.eHorizontalTransferOrder = eHorizontalTransferOrder; - } - - /// - /// Gets the number of attribute bits per pixel. - /// - public byte AttributeBits - { - get { return this.bAttributeBits; } - } - - /// - /// Sets the AttributeBits property, available only to objects in the same assembly as TargaHeader. - /// - /// The Attribute Bits value read from the file. - internal protected void SetAttributeBits(byte bAttributeBits) - { - this.bAttributeBits = bAttributeBits; - } - - /// - /// Gets identifying information about the image. - /// A value of zero in ImageIDLength indicates that no ImageIDValue is included with the image. - /// - public string ImageIDValue - { - get { return this.strImageIDValue; } - } - - /// - /// Sets the ImageIDValue property, available only to objects in the same assembly as TargaHeader. - /// - /// The Image ID value read from the file. - internal protected void SetImageIDValue(string strImageIDValue) - { - this.strImageIDValue = strImageIDValue; - } - - /// - /// Gets the Color Map of the image, if any. The Color Map is represented by a list of Color objects. - /// - public System.Collections.Generic.List ColorMap - { - get { return this.cColorMap; } - } - - /// - /// Gets the offset from the beginning of the file to the Image Data. - /// - public int ImageDataOffset - { - get - { - // calculate the image data offset - - // start off with the number of bytes holding the header info. - int intImageDataOffset = TargaConstants.HeaderByteLength; - - // add the Image ID length (could be variable) - intImageDataOffset += this.bImageIDLength; - - // determine the number of bytes for each Color Map entry - int Bytes = 0; - switch (this.bColorMapEntrySize) - { - case 15: - Bytes = 2; - break; - case 16: - Bytes = 2; - break; - case 24: - Bytes = 3; - break; - case 32: - Bytes = 4; - break; - } - - // add the length of the color map - intImageDataOffset += ((int)this.sColorMapLength * (int)Bytes); - - // return result - return intImageDataOffset; - } - } - - /// - /// Gets the number of bytes per pixel. - /// - public int BytesPerPixel - { - get - { - return (int)this.bPixelDepth / 8; - } - } - } - - - /// - /// Holds Footer infomation read from the image file. - /// - public class TargaFooter - { - private int intExtensionAreaOffset = 0; - private int intDeveloperDirectoryOffset = 0; - private string strSignature = string.Empty; - private string strReservedCharacter = string.Empty; - - /// - /// Gets the offset from the beginning of the file to the start of the Extension Area. - /// If the ExtensionAreaOffset is zero, no Extension Area exists in the file. - /// - public int ExtensionAreaOffset - { - get { return this.intExtensionAreaOffset; } - } - - /// - /// Sets the ExtensionAreaOffset property, available only to objects in the same assembly as TargaFooter. - /// - /// The Extension Area Offset value read from the file. - internal protected void SetExtensionAreaOffset(int intExtensionAreaOffset) - { - this.intExtensionAreaOffset = intExtensionAreaOffset; - } - - /// - /// Gets the offset from the beginning of the file to the start of the Developer Area. - /// If the DeveloperDirectoryOffset is zero, then the Developer Area does not exist - /// - public int DeveloperDirectoryOffset - { - get { return this.intDeveloperDirectoryOffset; } - } - - /// - /// Sets the DeveloperDirectoryOffset property, available only to objects in the same assembly as TargaFooter. - /// - /// The Developer Directory Offset value read from the file. - internal protected void SetDeveloperDirectoryOffset(int intDeveloperDirectoryOffset) - { - this.intDeveloperDirectoryOffset = intDeveloperDirectoryOffset; - } - - /// - /// This string is formatted exactly as "TRUEVISION-XFILE" (no quotes). If the - /// signature is detected, the file is assumed to be a New TGA format and MAY, - /// therefore, contain the Developer Area and/or the Extension Areas. If the - /// signature is not found, then the file is assumed to be an Original TGA format. - /// - public string Signature - { - get { return this.strSignature; } - } - - /// - /// Sets the Signature property, available only to objects in the same assembly as TargaFooter. - /// - /// The Signature value read from the file. - internal protected void SetSignature(string strSignature) - { - this.strSignature = strSignature; - } - - /// - /// A New Targa format reserved character "." (period) - /// - public string ReservedCharacter - { - get { return this.strReservedCharacter; } - } - - /// - /// Sets the ReservedCharacter property, available only to objects in the same assembly as TargaFooter. - /// - /// The ReservedCharacter value read from the file. - internal protected void SetReservedCharacter(string strReservedCharacter) - { - this.strReservedCharacter = strReservedCharacter; - } - - /// - /// Creates a new instance of the TargaFooter class. - /// - public TargaFooter() - {} - - - } - - - /// - /// This class holds all of the Extension Area properties of the Targa image. If an Extension Area exists in the file. - /// - public class TargaExtensionArea - { - int intExtensionSize = 0; - string strAuthorName = string.Empty; - string strAuthorComments = string.Empty; - DateTime dtDateTimeStamp = DateTime.Now; - string strJobName = string.Empty; - TimeSpan dtJobTime = TimeSpan.Zero; - string strSoftwareID = string.Empty; - string strSoftwareVersion = string.Empty; - Color cKeyColor; - int intPixelAspectRatioNumerator = 0; - int intPixelAspectRatioDenominator = 0; - int intGammaNumerator = 0; - int intGammaDenominator = 0; - int intColorCorrectionOffset = 0; - int intPostageStampOffset = 0; - int intScanLineOffset = 0; - int intAttributesType = 0; - private System.Collections.Generic.List intScanLineTable = new List(); - private System.Collections.Generic.List cColorCorrectionTable = new List(); - - /// - /// Gets the number of Bytes in the fixed-length portion of the ExtensionArea. - /// For Version 2.0 of the TGA File Format, this number should be set to 495 - /// - public int ExtensionSize - { - get { return this.intExtensionSize; } - } - - /// - /// Sets the ExtensionSize property, available only to objects in the same assembly as TargaExtensionArea. - /// - /// The Extension Size value read from the file. - internal protected void SetExtensionSize(int intExtensionSize) - { - this.intExtensionSize = intExtensionSize; - } - - /// - /// Gets the name of the person who created the image. - /// - public string AuthorName - { - get { return this.strAuthorName; } - } - - /// - /// Sets the AuthorName property, available only to objects in the same assembly as TargaExtensionArea. - /// - /// The Author Name value read from the file. - internal protected void SetAuthorName(string strAuthorName) - { - this.strAuthorName = strAuthorName; - } - - /// - /// Gets the comments from the author who created the image. - /// - public string AuthorComments - { - get { return this.strAuthorComments; } - } - - /// - /// Sets the AuthorComments property, available only to objects in the same assembly as TargaExtensionArea. - /// - /// The Author Comments value read from the file. - internal protected void SetAuthorComments(string strAuthorComments) - { - this.strAuthorComments = strAuthorComments; - } - - /// - /// Gets the date and time that the image was saved. - /// - public DateTime DateTimeStamp - { - get { return this.dtDateTimeStamp; } - } - - /// - /// Sets the DateTimeStamp property, available only to objects in the same assembly as TargaExtensionArea. - /// - /// The Date Time Stamp value read from the file. - internal protected void SetDateTimeStamp(DateTime dtDateTimeStamp) - { - this.dtDateTimeStamp = dtDateTimeStamp; - } - - /// - /// Gets the name or id tag which refers to the job with which the image was associated. - /// - public string JobName - { - get { return this.strJobName; } - } - - /// - /// Sets the JobName property, available only to objects in the same assembly as TargaExtensionArea. - /// - /// The Job Name value read from the file. - internal protected void SetJobName(string strJobName) - { - this.strJobName = strJobName; - } - - /// - /// Gets the job elapsed time when the image was saved. - /// - public TimeSpan JobTime - { - get { return this.dtJobTime; } - } - - /// - /// Sets the JobTime property, available only to objects in the same assembly as TargaExtensionArea. - /// - /// The Job Time value read from the file. - internal protected void SetJobTime(TimeSpan dtJobTime) - { - this.dtJobTime = dtJobTime; - } - - /// - /// Gets the Software ID. Usually used to determine and record with what program a particular image was created. - /// - public string SoftwareID - { - get { return this.strSoftwareID; } - } - - /// - /// Sets the SoftwareID property, available only to objects in the same assembly as TargaExtensionArea. - /// - /// The Software ID value read from the file. - internal protected void SetSoftwareID(string strSoftwareID) - { - this.strSoftwareID = strSoftwareID; - } - - /// - /// Gets the version of software defined by the SoftwareID. - /// - public string SoftwareVersion - { - get { return this.strSoftwareVersion; } - } - - /// - /// Sets the SoftwareVersion property, available only to objects in the same assembly as TargaExtensionArea. - /// - /// The Software Version value read from the file. - internal protected void SetSoftwareVersion(string strSoftwareVersion) - { - this.strSoftwareVersion = strSoftwareVersion; - } - - /// - /// Gets the key color in effect at the time the image is saved. - /// The Key Color can be thought of as the "background color" or "transparent color". - /// - public Color KeyColor - { - get { return this.cKeyColor; } - } - - /// - /// Sets the KeyColor property, available only to objects in the same assembly as TargaExtensionArea. - /// - /// The Key Color value read from the file. - internal protected void SetKeyColor(Color cKeyColor) - { - this.cKeyColor = cKeyColor; - } - - /// - /// Gets the Pixel Ratio Numerator. - /// - public int PixelAspectRatioNumerator - { - get { return this.intPixelAspectRatioNumerator; } - } - - /// - /// Sets the PixelAspectRatioNumerator property, available only to objects in the same assembly as TargaExtensionArea. - /// - /// The Pixel Aspect Ratio Numerator value read from the file. - internal protected void SetPixelAspectRatioNumerator(int intPixelAspectRatioNumerator) - { - this.intPixelAspectRatioNumerator = intPixelAspectRatioNumerator; - } - - /// - /// Gets the Pixel Ratio Denominator. - /// - public int PixelAspectRatioDenominator - { - get { return this.intPixelAspectRatioDenominator; } - } - - /// - /// Sets the PixelAspectRatioDenominator property, available only to objects in the same assembly as TargaExtensionArea. - /// - /// The Pixel Aspect Ratio Denominator value read from the file. - internal protected void SetPixelAspectRatioDenominator(int intPixelAspectRatioDenominator) - { - this.intPixelAspectRatioDenominator = intPixelAspectRatioDenominator; - } - - /// - /// Gets the Pixel Aspect Ratio. - /// - public float PixelAspectRatio - { - get - { - if (this.intPixelAspectRatioDenominator > 0) - { - return (float)this.intPixelAspectRatioNumerator / (float)this.intPixelAspectRatioDenominator; - } - else - return 0.0F; - } - } - - /// - /// Gets the Gamma Numerator. - /// - public int GammaNumerator - { - get { return this.intGammaNumerator; } - } - - /// - /// Sets the GammaNumerator property, available only to objects in the same assembly as TargaExtensionArea. - /// - /// The Gamma Numerator value read from the file. - internal protected void SetGammaNumerator(int intGammaNumerator) - { - this.intGammaNumerator = intGammaNumerator; - } - - /// - /// Gets the Gamma Denominator. - /// - public int GammaDenominator - { - get { return this.intGammaDenominator; } - } - - /// - /// Sets the GammaDenominator property, available only to objects in the same assembly as TargaExtensionArea. - /// - /// The Gamma Denominator value read from the file. - internal protected void SetGammaDenominator(int intGammaDenominator) - { - this.intGammaDenominator = intGammaDenominator; - } - - /// - /// Gets the Gamma Ratio. - /// - public float GammaRatio - { - get - { - if (this.intGammaDenominator > 0) - { - float ratio = (float)this.intGammaNumerator / (float)this.intGammaDenominator; - return (float)Math.Round(ratio, 1); - } - else - return 1.0F; - } - } - - /// - /// Gets the offset from the beginning of the file to the start of the Color Correction table. - /// - public int ColorCorrectionOffset - { - get { return this.intColorCorrectionOffset; } - } - - /// - /// Sets the ColorCorrectionOffset property, available only to objects in the same assembly as TargaExtensionArea. - /// - /// The Color Correction Offset value read from the file. - internal protected void SetColorCorrectionOffset(int intColorCorrectionOffset) - { - this.intColorCorrectionOffset = intColorCorrectionOffset; - } - - /// - /// Gets the offset from the beginning of the file to the start of the Postage Stamp image data. - /// - public int PostageStampOffset - { - get { return this.intPostageStampOffset; } - } - - /// - /// Sets the PostageStampOffset property, available only to objects in the same assembly as TargaExtensionArea. - /// - /// The Postage Stamp Offset value read from the file. - internal protected void SetPostageStampOffset(int intPostageStampOffset) - { - this.intPostageStampOffset = intPostageStampOffset; - } - - /// - /// Gets the offset from the beginning of the file to the start of the Scan Line table. - /// - public int ScanLineOffset - { - get { return this.intScanLineOffset; } - } - - /// - /// Sets the ScanLineOffset property, available only to objects in the same assembly as TargaExtensionArea. - /// - /// The Scan Line Offset value read from the file. - internal protected void SetScanLineOffset(int intScanLineOffset) - { - this.intScanLineOffset = intScanLineOffset; - } - - /// - /// Gets the type of Alpha channel data contained in the file. - /// 0: No Alpha data included. - /// 1: Undefined data in the Alpha field, can be ignored - /// 2: Undefined data in the Alpha field, but should be retained - /// 3: Useful Alpha channel data is present - /// 4: Pre-multiplied Alpha (see description below) - /// 5-127: RESERVED - /// 128-255: Un-assigned - /// - public int AttributesType - { - get { return this.intAttributesType; } - } - - /// - /// Sets the AttributesType property, available only to objects in the same assembly as TargaExtensionArea. - /// - /// The Attributes Type value read from the file. - internal protected void SetAttributesType(int intAttributesType) - { - this.intAttributesType = intAttributesType; - } - - /// - /// Gets a list of offsets from the beginning of the file that point to the start of the next scan line, - /// in the order that the image was saved - /// - public System.Collections.Generic.List ScanLineTable - { - get { return this.intScanLineTable; } - } - - /// - /// Gets a list of Colors where each Color value is the desired Color correction for that entry. - /// This allows the user to store a correction table for image remapping or LUT driving. - /// - public System.Collections.Generic.List ColorCorrectionTable - { - get { return this.cColorCorrectionTable; } - } - - } - - - /// - /// Utilities functions used by the TargaImage class. - /// - static class Utilities - { - - /// - /// Gets an int value representing the subset of bits from a single Byte. - /// - /// The Byte used to get the subset of bits from. - /// The offset of bits starting from the right. - /// The number of bits to read. - /// - /// An int value representing the subset of bits. - /// - /// - /// Given -> b = 00110101 - /// A call to GetBits(b, 2, 4) - /// GetBits looks at the following bits in the byte -> 00{1101}00 - /// Returns 1101 as an int (13) - /// - internal static int GetBits(byte b, int offset, int count) - { - return (b >> offset) & ((1 << count) - 1); - } - - /// - /// Reads ARGB values from the 16 bits of two given Bytes in a 1555 format. - /// - /// The first Byte. - /// The Second Byte. - /// A Color with a ARGB values read from the two given Bytes - /// - /// Gets the ARGB values from the 16 bits in the two bytes based on the below diagram - /// | BYTE 1 | BYTE 2 | - /// | A RRRRR GG | GGG BBBBB | - /// - internal static Color GetColorFrom2Bytes(byte one, byte two) - { - // get the 5 bits used for the RED value from the first byte - int r1 = Utilities.GetBits(one, 2, 5); - byte r = Convert.ToByte(r1 << 3); - - // get the two high order bits for GREEN from the from the first byte - int bit = Utilities.GetBits(one, 0, 2); - // shift bits to the high order - int g1 = bit << 6; - - // get the 3 low order bits for GREEN from the from the second byte - bit = Utilities.GetBits(two, 5, 3); - // shift the low order bits - int g2 = bit << 3; - // add the shifted values together to get the full GREEN value - byte g = Convert.ToByte(g1 + g2); - - // get the 5 bits used for the BLUE value from the second byte - int b1 = Utilities.GetBits(two, 0, 5); - byte b = Convert.ToByte(b1 << 3); - - // get the 1 bit used for the ALPHA value from the first byte - int a1 = Utilities.GetBits(one, 7, 1); - byte a = Convert.ToByte(a1 * 255); - - // return the resulting Color - return new Color32(r, g, b, a); - } - - /// - /// Gets a 32 character binary string of the specified Int32 value. - /// - /// The value to get a binary string for. - /// A string with the resulting binary for the supplied value. - /// - /// This method was used during debugging and is left here just for fun. - /// - internal static string GetIntBinaryString(Int32 n) - { - char[] b = new char[32]; - int pos = 31; - int i = 0; - - while (i < 32) - { - if ((n & (1 << i)) != 0) - { - b[pos] = '1'; - } - else - { - b[pos] = '0'; - } - pos--; - i++; - } - return new string(b); - } - - /// - /// Gets a 16 character binary string of the specified Int16 value. - /// - /// The value to get a binary string for. - /// A string with the resulting binary for the supplied value. - /// - /// This method was used during debugging and is left here just for fun. - /// - internal static string GetInt16BinaryString(Int16 n) - { - char[] b = new char[16]; - int pos = 15; - int i = 0; - - while (i < 16) - { - if ((n & (1 << i)) != 0) - { - b[pos] = '1'; - } - else - { - b[pos] = '0'; - } - pos--; - i++; - } - return new string(b); - } - - } -} \ No newline at end of file diff --git a/Assets/Scripts/TargaImporter.cs.meta b/Assets/Scripts/TargaImporter.cs.meta deleted file mode 100644 index bd6bb943..00000000 --- a/Assets/Scripts/TargaImporter.cs.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: fb4b16312ac35d841b600fc68a254b0f -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: diff --git a/Assets/Scripts/TextureScale.cs b/Assets/Scripts/TextureScale.cs new file mode 100644 index 00000000..71ef9d88 --- /dev/null +++ b/Assets/Scripts/TextureScale.cs @@ -0,0 +1,161 @@ +// Only works on ARGB32, RGB24 and Alpha8 textures that are marked readable + +using System.Threading; +using UnityEngine; + +public class TextureScale +{ + public class ThreadData + { + public int start; + public int end; + public ThreadData(int s, int e) + { + start = s; + end = e; + } + } + + private static Color[] texColors; + private static Color[] newColors; + private static int w; + private static float ratioX; + private static float ratioY; + private static int w2; + private static int finishCount; + private static Mutex mutex; + + public static void Point(Texture2D tex, int newWidth, int newHeight) + { + ThreadedScale(tex, newWidth, newHeight, false); + } + + public static Texture2D Bilinear(Texture2D tex, int newWidth, int newHeight) + { + Debug.Log("attempting to scale"); + return ThreadedScale(tex, newWidth, newHeight, true); + } + + private static Texture2D ThreadedScale(Texture2D tex, int newWidth, int newHeight, bool useBilinear) + { + texColors = tex.GetPixels(); + newColors = new Color[newWidth * newHeight]; + if (useBilinear) + { + ratioX = 1.0f / ((float)newWidth / (tex.width - 1)); + ratioY = 1.0f / ((float)newHeight / (tex.height - 1)); + } + else + { + ratioX = ((float)tex.width) / newWidth; + ratioY = ((float)tex.height) / newHeight; + } + w = tex.width; + w2 = newWidth; + var cores = Mathf.Min(SystemInfo.processorCount, newHeight); + var slice = newHeight / cores; + + finishCount = 0; + if (mutex == null) + { + mutex = new Mutex(false); + } + if (cores > 1) + { + int i = 0; + ThreadData threadData; + for (i = 0; i < cores - 1; i++) + { + threadData = new ThreadData(slice * i, slice * (i + 1)); + ParameterizedThreadStart ts = useBilinear ? new ParameterizedThreadStart(BilinearScale) : new ParameterizedThreadStart(PointScale); + Thread thread = new Thread(ts); + thread.Start(threadData); + } + threadData = new ThreadData(slice * i, newHeight); + if (useBilinear) + { + BilinearScale(threadData); + } + else + { + PointScale(threadData); + } + while (finishCount < cores) + { + Thread.Sleep(1); + } + } + else + { + ThreadData threadData = new ThreadData(0, newHeight); + if (useBilinear) + { + BilinearScale(threadData); + } + else + { + PointScale(threadData); + } + } + + tex.Resize(newWidth, newHeight); + tex.SetPixels(newColors); + Debug.Log(tex); + tex.Apply(); + + texColors = null; + newColors = null; + return tex; + } + + public static void BilinearScale(System.Object obj) + { + ThreadData threadData = (ThreadData)obj; + for (var y = threadData.start; y < threadData.end; y++) + { + int yFloor = (int)Mathf.Floor(y * ratioY); + var y1 = yFloor * w; + var y2 = (yFloor + 1) * w; + var yw = y * w2; + + for (var x = 0; x < w2; x++) + { + int xFloor = (int)Mathf.Floor(x * ratioX); + var xLerp = x * ratioX - xFloor; + newColors[yw + x] = ColorLerpUnclamped(ColorLerpUnclamped(texColors[y1 + xFloor], texColors[y1 + xFloor + 1], xLerp), + ColorLerpUnclamped(texColors[y2 + xFloor], texColors[y2 + xFloor + 1], xLerp), + y * ratioY - yFloor); + } + } + + mutex.WaitOne(); + finishCount++; + mutex.ReleaseMutex(); + } + + public static void PointScale(System.Object obj) + { + ThreadData threadData = (ThreadData)obj; + for (var y = threadData.start; y < threadData.end; y++) + { + var thisY = (int)(ratioY * y) * w; + var yw = y * w2; + for (var x = 0; x < w2; x++) + { + newColors[yw + x] = texColors[(int)(thisY + ratioX * x)]; + } + } + + mutex.WaitOne(); + finishCount++; + mutex.ReleaseMutex(); + } + + private static Color ColorLerpUnclamped(Color c1, Color c2, float value) + { + return new Color(c1.r + (c2.r - c1.r) * value, + c1.g + (c2.g - c1.g) * value, + c1.b + (c2.b - c1.b) * value, + c1.a + (c2.a - c1.a) * value); + } +} \ No newline at end of file diff --git a/Assets/Scripts/TextureScale.cs.meta b/Assets/Scripts/TextureScale.cs.meta new file mode 100644 index 00000000..e7939bc1 --- /dev/null +++ b/Assets/Scripts/TextureScale.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 352c93c5e55830464bd22e5bde88609d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/TilingTextureMakerGui.cs b/Assets/Scripts/TilingTextureMakerGui.cs index e8487ca8..d09ad698 100644 --- a/Assets/Scripts/TilingTextureMakerGui.cs +++ b/Assets/Scripts/TilingTextureMakerGui.cs @@ -1,814 +1,831 @@ -using UnityEngine; +#region + +using System; using System.Collections; +using UnityEngine; +using Random = UnityEngine.Random; -public class TilingTextureMakerGui : MonoBehaviour { - - MainGui MGS; +#endregion - Material thisMaterial; +// ReSharper disable Unity.PreferAddressByIdToGraphicsParams - public GameObject testObject; - - RenderTexture _HDHeightMapTemp; - RenderTexture _HeightMapTemp; - RenderTexture _DiffuseMapTemp; - RenderTexture _DiffuseMapOriginalTemp; - RenderTexture _MetallicMapTemp; - RenderTexture _SmoothnessMapTemp; - RenderTexture _NormalMapTemp; - RenderTexture _EdgeMapTemp; - RenderTexture _AOMapTemp; +public class TilingTextureMakerGui : MonoBehaviour +{ + private static readonly int Tiling = Shader.PropertyToID("_Tiling"); + private static readonly int MainTex = Shader.PropertyToID("_MainTex"); + private static readonly int HeightTex = Shader.PropertyToID("_HeightTex"); + private static readonly int ObjectScale = Shader.PropertyToID("_ObjectScale"); + private static readonly int FlipY = Shader.PropertyToID("_FlipY"); + private RenderTexture _aoMapTemp; - RenderTexture _TileTemp; - RenderTexture _SplatTemp; - RenderTexture _SplatTempAlt; + private Material _blitMaterial; + private RenderTexture _diffuseMapOriginalTemp; + private RenderTexture _diffuseMapTemp; - float Falloff = 0.1f; - float OverlapX = 0.2f; - float OverlapY = 0.2f; + private bool _doStuff; + private RenderTexture _edgeMapTemp; - float LastFalloff = 0.1f; - float LastOverlapX = 0.2f; - float LastOverlapY = 0.2f; + private float _falloff = 0.1f; - float TexTiling = 1.0f; - float TexOffsetX = 0.0f; - float TexOffsetY = 0.0f; + private string _falloffText = "0.1"; - string FalloffText = "0.1"; - string OverlapXText = "0.2"; - string OverlapYText = "0.2"; - - string TexTilingText = "1.0"; - string TexOffsetXText = "0.0"; - string TexOffsetYText = "0.0"; + private RenderTexture _hdHeightMapTemp; + private RenderTexture _heightMapTemp; - float SplatRotation = 0.0f; - string SplatRotationText = "0.0"; + private float _lastFalloff = 0.1f; - float SplatRotationRandom = 0.25f; - string SplatRotationRandomText = "0.25"; + private int _lastNewTexSelectionX = 2; + private int _lastNewTexSelectionY = 2; + private float _lastOverlapX = 0.2f; + private float _lastOverlapY = 0.2f; + private TileTechnique _lastTileTech = TileTechnique.Overlap; + private RenderTexture _metallicMapTemp; - float SplatScale = 1.0f; - string SplatScaleText = "1.0"; + private int _newTexSelectionX = 2; + private int _newTexSelectionY = 2; - float SplatWobble = 0.2f; - string SplatWobbleText = "0.2"; + private int _newTexSizeX = 1024; + private int _newTexSizeY = 1024; + private RenderTexture _normalMapTemp; - float SplatWobbleRandom = 0.2f; - string SplatWobbleRandomText = "0.2"; + private Vector3 _objectScale = Vector3.one; - float SplatRandomize = 0.0f; - string SplatRandomizeText = "0.0"; + private Vector2[] _offsetKernel; + private float _overlapX = 0.2f; + private string _overlapXText = "0.2"; + private float _overlapY = 0.2f; + private string _overlapYText = "0.2"; + private RenderTexture _smoothnessMapTemp; - GUIContent[] TexSizes; + private Vector4[] _splatKernel; - int NewTexSelectionX = 2; - int NewTexSelectionY = 2; + private float _splatRandomize; + private string _splatRandomizeText = "0.0"; - int LastNewTexSelectionX = 2; - int LastNewTexSelectionY = 2; + private float _splatRotation; - int NewTexSizeX = 1024; - int NewTexSizeY = 1024; + private float _splatRotationRandom = 0.25f; + private string _splatRotationRandomText = "0.25"; + private string _splatRotationText = "0.0"; - Vector2 targetAR; + private float _splatScale = 1.0f; + private string _splatScaleText = "1.0"; + private RenderTexture _splatTemp; + private RenderTexture _splatTempAlt; - Material blitMaterial; + private float _splatWobble = 0.2f; + private string _splatWobbleText = "0.2"; - Rect windowRect = new Rect (30, 300, 300, 530); + private Vector2 _targetAr; - bool doStuff = false; + private bool _techniqueOverlap = true; + private bool _techniqueSplat; + private float _texOffsetX; + private string _texOffsetXText = "0.0"; + private float _texOffsetY; + private string _texOffsetYText = "0.0"; - bool techniqueOverlap = true; - bool techniqueSplat = false; + private GUIContent[] _texSizes; - Vector4[] splatKernel; + private float _texTiling = 1.0f; - Vector2[] offsetKernel; + private string _texTilingText = "1.0"; - Vector3 objectScale = Vector3.one; - - enum TileTechnique { - Overlap, - Splat - } - - TileTechnique tileTech = TileTechnique.Overlap; - TileTechnique lastTileTech = TileTechnique.Overlap; - - - void Start () { - - blitMaterial = new Material (Shader.Find ("Hidden/Blit_Seamless_Texture_Maker")); - - TexSizes = new GUIContent[4]; - TexSizes [0] = new GUIContent( "512" ); - TexSizes [1] = new GUIContent( "1024" ); - TexSizes [2] = new GUIContent( "2048" ); - TexSizes [3] = new GUIContent( "4096" ); - - //offsetKernel = new Vector2[4]; - //offsetKernel [0] = new Vector2 (-0.5f, -0.5f); - //offsetKernel [1] = new Vector2 (-0.5f, 0.5f); - //offsetKernel [2] = new Vector2 (0.5f, -0.5f); - //offsetKernel [3] = new Vector2 (0.5f, 0.5f); - - offsetKernel = new Vector2[9]; - offsetKernel [0] = new Vector2 (-1, -1); - offsetKernel [1] = new Vector2 (-1, 0); - offsetKernel [2] = new Vector2 (-1, 1); - offsetKernel [3] = new Vector2 (0, -1); - offsetKernel [4] = new Vector2 (0, 0); - offsetKernel [5] = new Vector2 (0, 1); - offsetKernel [6] = new Vector2 (1, -1); - offsetKernel [7] = new Vector2 (1, 0); - offsetKernel [8] = new Vector2 (1, 1); - - } - - public void Initialize(){ - MGS = MainGui.instance; - thisMaterial = MGS.FullMaterial; - - testObject.GetComponent().material = thisMaterial; - doStuff = true; - } - - void Update() { - - thisMaterial.SetVector ("_Tiling", new Vector4 ( TexTiling, TexTiling, TexOffsetX, TexOffsetY )); - - if (LastOverlapX != OverlapX) { - LastOverlapX = OverlapX; - doStuff = true; - } - - if (LastOverlapY != OverlapY) { - LastOverlapY = OverlapY; - doStuff = true; - } - - if (LastFalloff != Falloff) { - LastFalloff = Falloff; - doStuff = true; - } - - if (NewTexSelectionX != LastNewTexSelectionX) { - LastNewTexSelectionX = NewTexSelectionX; - doStuff = true; - } - - if (NewTexSelectionY != LastNewTexSelectionY) { - LastNewTexSelectionY = NewTexSelectionY; - doStuff = true; - } - - if (tileTech != lastTileTech) { - lastTileTech = tileTech; - doStuff = true; - } - - if (doStuff) { - doStuff = false; - - switch (NewTexSelectionX) { - case 0: - NewTexSizeX = 512; - break; - case 1: - NewTexSizeX = 1024; - break; - case 2: - NewTexSizeX = 2048; - break; - case 3: - NewTexSizeX = 4096; - break; - default: - NewTexSizeX = 1024; - break; - } - - switch (NewTexSelectionY) { - case 0: - NewTexSizeY = 512; - break; - case 1: - NewTexSizeY = 1024; - break; - case 2: - NewTexSizeY = 2048; - break; - case 3: - NewTexSizeY = 4096; - break; - default: - NewTexSizeY = 1024; - break; - } - - - - float aspect = (float)NewTexSizeX / (float)NewTexSizeY; - - if (Mathf.Approximately(aspect, 8.0f)) { - SKRectWide3 (); - } else if (Mathf.Approximately(aspect, 4.0f)) { - SKRectWide2 (); - } else if (Mathf.Approximately(aspect, 2.0f)) { - SKRectWide (); - } else if (Mathf.Approximately(aspect, 1.0f)) { - SKSquare (); - } else if (Mathf.Approximately(aspect, 0.5f)) { - SKRectTall (); - } else if (Mathf.Approximately(aspect, 0.25f)) { - SKRectTall2 (); - } else if (Mathf.Approximately(aspect, 0.125f)) { - SKRectTall3 (); - } - - - float area = 1.0f; - objectScale = Vector3.one; - objectScale.x = aspect; - float newArea = objectScale.x * objectScale.y; - float areaScale = Mathf.Sqrt ( area / newArea ); - - objectScale.x *= areaScale; - objectScale.y *= areaScale; - - testObject.transform.localScale = objectScale; - - StartCoroutine ( TileTextures ()); - } - } - - void SKSquare(){ - splatKernel = new Vector4[4]; - splatKernel [0] = new Vector4 (0.0f, 0.25f, 0.8f, Random.value); - splatKernel [1] = new Vector4 (0.5f, 0.25f, 0.8f, Random.value); - splatKernel [2] = new Vector4 (0.25f, 0.75f, 0.8f, Random.value); - splatKernel [3] = new Vector4 (0.75f, 0.75f, 0.8f, Random.value); - } - - void SKRectWide(){ - splatKernel = new Vector4[6]; - splatKernel [0] = new Vector4 (0.0f, 0.25f, 0.5f, Random.value); - splatKernel [1] = new Vector4 (0.333f, 0.25f, 0.5f, Random.value); - splatKernel [2] = new Vector4 (0.666f, 0.25f, 0.5f, Random.value); - - splatKernel [3] = new Vector4 (0.166f, 0.75f, 0.5f, Random.value); - splatKernel [4] = new Vector4 (0.5f, 0.75f, 0.5f, Random.value); - splatKernel [5] = new Vector4 (0.833f, 0.75f, 0.5f, Random.value); - } - - void SKRectWide2(){ - splatKernel = new Vector4[4]; - splatKernel [0] = new Vector4 (0.0f, 0.375f, 0.4f, Random.value); - splatKernel [1] = new Vector4 (0.25f, 0.625f, 0.4f, Random.value); - splatKernel [2] = new Vector4 (0.5f, 0.375f, 0.4f, Random.value); - splatKernel [3] = new Vector4 (0.75f, 0.625f, 0.4f, Random.value); - } - - void SKRectWide3(){ - splatKernel = new Vector4[8]; - splatKernel [0] = new Vector4 (0.0f, 0.375f, 0.25f, Random.value); - splatKernel [1] = new Vector4 (0.125f, 0.625f, 0.25f, Random.value); - splatKernel [2] = new Vector4 (0.25f, 0.375f, 0.25f, Random.value); - splatKernel [3] = new Vector4 (0.375f, 0.625f, 0.25f, Random.value); - splatKernel [4] = new Vector4 (0.5f, 0.375f, 0.25f, Random.value); - splatKernel [5] = new Vector4 (0.625f, 0.625f, 0.25f, Random.value); - splatKernel [6] = new Vector4 (0.75f, 0.375f, 0.25f, Random.value); - splatKernel [7] = new Vector4 (0.875f, 0.625f, 0.25f, Random.value); - } - - void SKRectTall(){ - splatKernel = new Vector4[6]; - splatKernel [0] = new Vector4 (0.25f, 0.0f, 0.5f, Random.value); - splatKernel [1] = new Vector4 (0.25f, 0.333f, 0.5f, Random.value); - splatKernel [2] = new Vector4 (0.25f, 0.666f, 0.5f, Random.value); - - splatKernel [3] = new Vector4 (0.75f, 0.166f, 0.5f, Random.value); - splatKernel [4] = new Vector4 (0.75f, 0.5f, 0.5f, Random.value); - splatKernel [5] = new Vector4 (0.75f, 0.833f, 0.5f, Random.value); - } - - void SKRectTall2(){ - splatKernel = new Vector4[4]; - splatKernel [0] = new Vector4 (0.375f, 0.0f, 0.4f, Random.value); - splatKernel [1] = new Vector4 (0.625f, 0.25f, 0.4f, Random.value); - splatKernel [2] = new Vector4 (0.375f, 0.5f, 0.4f, Random.value); - splatKernel [3] = new Vector4 (0.625f, 0.75f, 0.4f, Random.value); - } - - void SKRectTall3(){ - splatKernel = new Vector4[8]; - splatKernel [0] = new Vector4 ( 0.375f, 0.0f, 0.25f, Random.value); - splatKernel [1] = new Vector4 ( 0.625f, 0.125f, 0.25f, Random.value); - splatKernel [2] = new Vector4 ( 0.375f, 0.25f, 0.25f, Random.value); - splatKernel [3] = new Vector4 ( 0.625f, 0.375f, 0.25f, Random.value); - splatKernel [4] = new Vector4 ( 0.375f, 0.5f, 0.25f, Random.value); - splatKernel [5] = new Vector4 ( 0.625f, 0.625f, 0.25f, Random.value); - splatKernel [6] = new Vector4 ( 0.375f, 0.75f, 0.25f, Random.value); - splatKernel [7] = new Vector4 ( 0.625f, 0.875f, 0.25f, Random.value); - } - - void DoMyWindow ( int windowID ) { - - int spacingX = 0; - int spacingY = 50; - int spacing2Y = 70; - - int offsetX = 10; - int offsetY = 30; - - techniqueOverlap = GUI.Toggle(new Rect(offsetX, offsetY, 130, 30), techniqueOverlap, "Technique Overlap"); - if (techniqueOverlap) { - techniqueSplat = false; - tileTech = TileTechnique.Overlap; - } else if ( !techniqueSplat ) { - techniqueOverlap = true; - tileTech = TileTechnique.Overlap; - } - - techniqueSplat = GUI.Toggle (new Rect (offsetX + 150, offsetY, 130, 30), techniqueSplat, "Technique Splat"); - if (techniqueSplat) { - techniqueOverlap = false; - tileTech = TileTechnique.Splat; - } else if (!techniqueOverlap) { - techniqueSplat = true; - tileTech = TileTechnique.Splat; - } - - offsetY += 40; - - GUI.Label (new Rect (offsetX, offsetY, 150, 20), "New Texture Size X" ); - NewTexSelectionX = GUI.SelectionGrid( new Rect (offsetX, offsetY + 30, 120, 50), NewTexSelectionX, TexSizes, 2 ); - - GUI.Label (new Rect (offsetX + 150, offsetY, 150, 20), "New Texture Size Y" ); - NewTexSelectionY = GUI.SelectionGrid( new Rect (offsetX + 150, offsetY + 30, 120, 50), NewTexSelectionY, TexSizes, 2 ); - - offsetY += 100; - - if (GuiHelper.Slider (new Rect (offsetX, offsetY, 280, 50), "Edge Falloff", Falloff, FalloffText, out Falloff, out FalloffText, 0.01f, 1.0f)) { - doStuff = true; - } - offsetY += 40; - - if (techniqueOverlap) { - - if (GuiHelper.Slider (new Rect (offsetX, offsetY, 280, 50), "Overlap X", OverlapX, OverlapXText, out OverlapX, out OverlapXText, 0.00f, 1.0f)) { - doStuff = true; - } - offsetY += 40; - - if (GuiHelper.Slider (new Rect (offsetX, offsetY, 280, 50), "Overlap Y", OverlapY, OverlapYText, out OverlapY, out OverlapYText, 0.00f, 1.0f)) { - doStuff = true; - } - offsetY += 50; - - } - - if (techniqueSplat) { - - if (GuiHelper.Slider (new Rect (offsetX, offsetY, 280, 50), "Splat Rotation", SplatRotation, SplatRotationText, out SplatRotation, out SplatRotationText, 0.0f, 1.0f)) { - doStuff = true; - } - offsetY += 40; - - if (GuiHelper.Slider (new Rect (offsetX, offsetY, 280, 50), "Splat Random Rotation", SplatRotationRandom, SplatRotationRandomText, out SplatRotationRandom, out SplatRotationRandomText, 0.0f, 1.0f)) { - doStuff = true; - } + private Material _thisMaterial; + + private TileTechnique _tileTech = TileTechnique.Overlap; + + private RenderTexture _tileTemp; + + private Rect _windowRect = new Rect(30, 300, 300, 530); + + public GameObject TestObject; + + + private void Start() + { + _blitMaterial = new Material(Shader.Find("Hidden/Blit_Seamless_Texture_Maker")); + + _texSizes = new GUIContent[4]; + _texSizes[0] = new GUIContent("512"); + _texSizes[1] = new GUIContent("1024"); + _texSizes[2] = new GUIContent("2048"); + _texSizes[3] = new GUIContent("4096"); + + _offsetKernel = new Vector2[9]; + _offsetKernel[0] = new Vector2(-1, -1); + _offsetKernel[1] = new Vector2(-1, 0); + _offsetKernel[2] = new Vector2(-1, 1); + _offsetKernel[3] = new Vector2(0, -1); + _offsetKernel[4] = new Vector2(0, 0); + _offsetKernel[5] = new Vector2(0, 1); + _offsetKernel[6] = new Vector2(1, -1); + _offsetKernel[7] = new Vector2(1, 0); + _offsetKernel[8] = new Vector2(1, 1); + } + + public void Initialize() + { + _thisMaterial = MainGui.Instance.FullMaterial; + + TestObject.GetComponent().material = _thisMaterial; + _doStuff = true; + } + + private void Update() + { + _thisMaterial.SetVector(Tiling, new Vector4(_texTiling, _texTiling, _texOffsetX, _texOffsetY)); + + if (Math.Abs(_lastOverlapX - _overlapX) > 0.0001f) + { + _lastOverlapX = _overlapX; + _doStuff = true; + } + + if (Math.Abs(_lastOverlapY - _overlapY) > 0.0001f) + { + _lastOverlapY = _overlapY; + _doStuff = true; + } + + if (Math.Abs(_lastFalloff - _falloff) > 0.0001f) + { + _lastFalloff = _falloff; + _doStuff = true; + } + + if (_newTexSelectionX != _lastNewTexSelectionX) + { + _lastNewTexSelectionX = _newTexSelectionX; + _doStuff = true; + } + + if (_newTexSelectionY != _lastNewTexSelectionY) + { + _lastNewTexSelectionY = _newTexSelectionY; + _doStuff = true; + } + + if (_tileTech != _lastTileTech) + { + _lastTileTech = _tileTech; + _doStuff = true; + } + + if (!_doStuff) return; + _doStuff = false; + + switch (_newTexSelectionX) + { + case 0: + _newTexSizeX = 512; + break; + case 1: + _newTexSizeX = 1024; + break; + case 2: + _newTexSizeX = 2048; + break; + case 3: + _newTexSizeX = 4096; + break; + default: + _newTexSizeX = 1024; + break; + } + + switch (_newTexSelectionY) + { + case 0: + _newTexSizeY = 512; + break; + case 1: + _newTexSizeY = 1024; + break; + case 2: + _newTexSizeY = 2048; + break; + case 3: + _newTexSizeY = 4096; + break; + default: + _newTexSizeY = 1024; + break; + } + + + var aspect = _newTexSizeX / (float) _newTexSizeY; + + if (Mathf.Approximately(aspect, 8.0f)) + SkRectWide3(); + else if (Mathf.Approximately(aspect, 4.0f)) + SkRectWide2(); + else if (Mathf.Approximately(aspect, 2.0f)) + SkRectWide(); + else if (Mathf.Approximately(aspect, 1.0f)) + SkSquare(); + else if (Mathf.Approximately(aspect, 0.5f)) + SkRectTall(); + else if (Mathf.Approximately(aspect, 0.25f)) + SkRectTall2(); + else if (Mathf.Approximately(aspect, 0.125f)) SkRectTall3(); + + + const float area = 1.0f; + _objectScale = Vector3.one; + _objectScale.x = aspect; + var newArea = _objectScale.x * _objectScale.y; + var areaScale = Mathf.Sqrt(area / newArea); + + _objectScale.x *= areaScale; + _objectScale.y *= areaScale; + + TestObject.transform.localScale = _objectScale; + + StartCoroutine(TileTextures()); + } + + private void SkSquare() + { + _splatKernel = new Vector4[4]; + _splatKernel[0] = new Vector4(0.0f, 0.25f, 0.8f, Random.value); + _splatKernel[1] = new Vector4(0.5f, 0.25f, 0.8f, Random.value); + _splatKernel[2] = new Vector4(0.25f, 0.75f, 0.8f, Random.value); + _splatKernel[3] = new Vector4(0.75f, 0.75f, 0.8f, Random.value); + } + + private void SkRectWide() + { + _splatKernel = new Vector4[6]; + _splatKernel[0] = new Vector4(0.0f, 0.25f, 0.5f, Random.value); + _splatKernel[1] = new Vector4(0.333f, 0.25f, 0.5f, Random.value); + _splatKernel[2] = new Vector4(0.666f, 0.25f, 0.5f, Random.value); + + _splatKernel[3] = new Vector4(0.166f, 0.75f, 0.5f, Random.value); + _splatKernel[4] = new Vector4(0.5f, 0.75f, 0.5f, Random.value); + _splatKernel[5] = new Vector4(0.833f, 0.75f, 0.5f, Random.value); + } + + private void SkRectWide2() + { + _splatKernel = new Vector4[4]; + _splatKernel[0] = new Vector4(0.0f, 0.375f, 0.4f, Random.value); + _splatKernel[1] = new Vector4(0.25f, 0.625f, 0.4f, Random.value); + _splatKernel[2] = new Vector4(0.5f, 0.375f, 0.4f, Random.value); + _splatKernel[3] = new Vector4(0.75f, 0.625f, 0.4f, Random.value); + } + + private void SkRectWide3() + { + _splatKernel = new Vector4[8]; + _splatKernel[0] = new Vector4(0.0f, 0.375f, 0.25f, Random.value); + _splatKernel[1] = new Vector4(0.125f, 0.625f, 0.25f, Random.value); + _splatKernel[2] = new Vector4(0.25f, 0.375f, 0.25f, Random.value); + _splatKernel[3] = new Vector4(0.375f, 0.625f, 0.25f, Random.value); + _splatKernel[4] = new Vector4(0.5f, 0.375f, 0.25f, Random.value); + _splatKernel[5] = new Vector4(0.625f, 0.625f, 0.25f, Random.value); + _splatKernel[6] = new Vector4(0.75f, 0.375f, 0.25f, Random.value); + _splatKernel[7] = new Vector4(0.875f, 0.625f, 0.25f, Random.value); + } + + private void SkRectTall() + { + _splatKernel = new Vector4[6]; + _splatKernel[0] = new Vector4(0.25f, 0.0f, 0.5f, Random.value); + _splatKernel[1] = new Vector4(0.25f, 0.333f, 0.5f, Random.value); + _splatKernel[2] = new Vector4(0.25f, 0.666f, 0.5f, Random.value); + + _splatKernel[3] = new Vector4(0.75f, 0.166f, 0.5f, Random.value); + _splatKernel[4] = new Vector4(0.75f, 0.5f, 0.5f, Random.value); + _splatKernel[5] = new Vector4(0.75f, 0.833f, 0.5f, Random.value); + } + + private void SkRectTall2() + { + _splatKernel = new Vector4[4]; + _splatKernel[0] = new Vector4(0.375f, 0.0f, 0.4f, Random.value); + _splatKernel[1] = new Vector4(0.625f, 0.25f, 0.4f, Random.value); + _splatKernel[2] = new Vector4(0.375f, 0.5f, 0.4f, Random.value); + _splatKernel[3] = new Vector4(0.625f, 0.75f, 0.4f, Random.value); + } + + private void SkRectTall3() + { + _splatKernel = new Vector4[8]; + _splatKernel[0] = new Vector4(0.375f, 0.0f, 0.25f, Random.value); + _splatKernel[1] = new Vector4(0.625f, 0.125f, 0.25f, Random.value); + _splatKernel[2] = new Vector4(0.375f, 0.25f, 0.25f, Random.value); + _splatKernel[3] = new Vector4(0.625f, 0.375f, 0.25f, Random.value); + _splatKernel[4] = new Vector4(0.375f, 0.5f, 0.25f, Random.value); + _splatKernel[5] = new Vector4(0.625f, 0.625f, 0.25f, Random.value); + _splatKernel[6] = new Vector4(0.375f, 0.75f, 0.25f, Random.value); + _splatKernel[7] = new Vector4(0.625f, 0.875f, 0.25f, Random.value); + } + + private void DoMyWindow(int windowId) + { + const int offsetX = 10; + var offsetY = 30; + + _techniqueOverlap = GUI.Toggle(new Rect(offsetX, offsetY, 130, 30), _techniqueOverlap, "Technique Overlap"); + if (_techniqueOverlap) + { + _techniqueSplat = false; + _tileTech = TileTechnique.Overlap; + } + else if (!_techniqueSplat) + { + _techniqueOverlap = true; + _tileTech = TileTechnique.Overlap; + } + + _techniqueSplat = GUI.Toggle(new Rect(offsetX + 150, offsetY, 130, 30), _techniqueSplat, "Technique Splat"); + if (_techniqueSplat) + { + _techniqueOverlap = false; + _tileTech = TileTechnique.Splat; + } + else if (!_techniqueOverlap) + { + _techniqueSplat = true; + _tileTech = TileTechnique.Splat; + } + + offsetY += 40; + + GUI.Label(new Rect(offsetX, offsetY, 150, 20), "New Texture Size X"); + _newTexSelectionX = + GUI.SelectionGrid(new Rect(offsetX, offsetY + 30, 120, 50), _newTexSelectionX, _texSizes, 2); + + GUI.Label(new Rect(offsetX + 150, offsetY, 150, 20), "New Texture Size Y"); + _newTexSelectionY = + GUI.SelectionGrid(new Rect(offsetX + 150, offsetY + 30, 120, 50), _newTexSelectionY, _texSizes, 2); + + offsetY += 100; + + if (GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Edge Falloff", _falloff, _falloffText, out _falloff, + out _falloffText, 0.01f, 1.0f)) _doStuff = true; + offsetY += 40; + + if (_techniqueOverlap) + { + if (GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Overlap X", _overlapX, _overlapXText, + out _overlapX, + out _overlapXText, 0.00f, 1.0f)) _doStuff = true; offsetY += 40; - if (GuiHelper.Slider (new Rect (offsetX, offsetY, 280, 50), "Splat Scale", SplatScale, SplatScaleText, out SplatScale, out SplatScaleText, 0.5f, 2.0f)) { - doStuff = true; - } - offsetY += 40; + if (GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Overlap Y", _overlapY, _overlapYText, + out _overlapY, + out _overlapYText, 0.00f, 1.0f)) _doStuff = true; + offsetY += 50; + } - if (GuiHelper.Slider (new Rect (offsetX, offsetY, 280, 50), "Splat Wooble Amount", SplatWobble, SplatWobbleText, out SplatWobble, out SplatWobbleText, 0.0f, 1.0f)) { - doStuff = true; - } + if (_techniqueSplat) + { + if (GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Splat Rotation", _splatRotation, + _splatRotationText, out _splatRotation, out _splatRotationText, 0.0f, 1.0f)) _doStuff = true; offsetY += 40; - if (GuiHelper.Slider (new Rect (offsetX, offsetY, 280, 50), "Splat Randomize", SplatRandomize, SplatRandomizeText, out SplatRandomize, out SplatRandomizeText, 0.0f, 1.0f)) { - doStuff = true; - } + if (GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Splat Random Rotation", _splatRotationRandom, + _splatRotationRandomText, out _splatRotationRandom, out _splatRotationRandomText, 0.0f, 1.0f)) + _doStuff = true; + offsetY += 40; + + if (GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Splat Scale", _splatScale, _splatScaleText, + out _splatScale, out _splatScaleText, 0.5f, 2.0f)) _doStuff = true; + offsetY += 40; + + if (GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Splat Wooble Amount", _splatWobble, + _splatWobbleText, out _splatWobble, out _splatWobbleText, 0.0f, 1.0f)) _doStuff = true; + offsetY += 40; + + if (GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Splat Randomize", _splatRandomize, + _splatRandomizeText, out _splatRandomize, out _splatRandomizeText, 0.0f, 1.0f)) _doStuff = true; offsetY += 50; + } + + GUI.Label(new Rect(offsetX, offsetY, 150, 30), "Tiling Test Variables"); + offsetY += 30; + + GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Texture Tiling", _texTiling, _texTilingText, + out _texTiling, + out _texTilingText, 0.1f, 5.0f); + offsetY += 40; + + GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Texture Offset X", _texOffsetX, _texOffsetXText, + out _texOffsetX, out _texOffsetXText, -1.0f, 1.0f); + offsetY += 40; + + GuiHelper.Slider(new Rect(offsetX, offsetY, 280, 50), "Texture Offset Y", _texOffsetY, _texOffsetYText, + out _texOffsetY, out _texOffsetYText, -1.0f, 1.0f); + offsetY += 40; + + if (GUI.Button(new Rect(offsetX + 150, offsetY, 130, 30), "Set Maps")) StartCoroutine(SetMaps()); + + + GUI.DragWindow(); + } + + private void OnGUI() + { + _windowRect.width = 300; + _windowRect.height = _techniqueSplat ? 610 : 490; + + _windowRect = GUI.Window(18, _windowRect, DoMyWindow, "Tiling Texture Maker"); + } + + // ReSharper disable once RedundantAssignment + private Texture2D SetMap(Texture2D textureTarget, RenderTexture textureToSet) + { + RenderTexture.active = textureToSet; + textureTarget = new Texture2D(_newTexSizeX, _newTexSizeY, TextureFormat.ARGB32, true, true); + textureTarget.ReadPixels(new Rect(0, 0, _newTexSizeX, _newTexSizeY), 0, 0); + textureTarget.Apply(); + return textureTarget; + } + + // ReSharper disable once RedundantAssignment + private RenderTexture SetMapRt(RenderTexture textureTarget, Texture textureToSet) + { + textureTarget = new RenderTexture(_newTexSizeX, _newTexSizeY, 0, RenderTextureFormat.RHalf, + RenderTextureReadWrite.Linear) {wrapMode = TextureWrapMode.Repeat}; + Graphics.Blit(textureToSet, textureTarget); + return textureTarget; + } + + private IEnumerator SetMaps() + { + if (!MainGui.Instance.HeightMap) yield break; + + if (MainGui.Instance.DiffuseMap) + { + Debug.Log("Setting Diffuse"); + Destroy(MainGui.Instance.DiffuseMap); + MainGui.Instance.DiffuseMap = null; + MainGui.Instance.DiffuseMap = SetMap(MainGui.Instance.DiffuseMap, _diffuseMapTemp); + } + + yield return new WaitForSeconds(0.1f); + + if (MainGui.Instance.DiffuseMapOriginal) + { + Debug.Log("Setting Original Diffuse"); + Destroy(MainGui.Instance.DiffuseMapOriginal); + MainGui.Instance.DiffuseMapOriginal = null; + MainGui.Instance.DiffuseMapOriginal = SetMap(MainGui.Instance.DiffuseMapOriginal, _diffuseMapOriginalTemp); + } + + yield return new WaitForSeconds(0.1f); + + if (MainGui.Instance.MetallicMap != null) + { + Debug.Log("Setting Specular"); + Destroy(MainGui.Instance.MetallicMap); + MainGui.Instance.MetallicMap = null; + MainGui.Instance.MetallicMap = SetMap(MainGui.Instance.MetallicMap, _metallicMapTemp); + } - } - - GUI.Label (new Rect (offsetX, offsetY, 150, 30), "Tiling Test Variables" ); - offsetY += 30; - - GuiHelper.Slider (new Rect (offsetX, offsetY, 280, 50), "Texture Tiling", TexTiling, TexTilingText, out TexTiling, out TexTilingText, 0.1f, 5.0f); - offsetY += 40; - - GuiHelper.Slider (new Rect (offsetX, offsetY, 280, 50), "Texture Offset X", TexOffsetX, TexOffsetXText, out TexOffsetX, out TexOffsetXText, -1.0f, 1.0f); - offsetY += 40; - - GuiHelper.Slider (new Rect (offsetX, offsetY, 280, 50), "Texture Offset Y", TexOffsetY, TexOffsetYText, out TexOffsetY, out TexOffsetYText, -1.0f, 1.0f); - offsetY += 40; - - if( GUI.Button (new Rect (offsetX + 150, offsetY, 130, 30), "Set Maps" ) ){ - StartCoroutine( SetMaps ( ) ); - } - - - GUI.DragWindow(); - - } - - void OnGUI () { - - windowRect.width = 300; - if (techniqueSplat) { - windowRect.height = 610; - } else { - windowRect.height = 490; - } - - windowRect = GUI.Window(18, windowRect, DoMyWindow, "Tiling Texture Maker"); - - } - - Texture2D SetMap ( Texture2D textureTarget, RenderTexture textureToSet ) { - RenderTexture.active = textureToSet; - textureTarget = new Texture2D (NewTexSizeX, NewTexSizeY, TextureFormat.ARGB32, true, true); - textureTarget.ReadPixels (new Rect (0, 0, NewTexSizeX, NewTexSizeY), 0, 0); - textureTarget.Apply (); - return textureTarget; - } - - RenderTexture SetMapRT ( RenderTexture textureTarget, RenderTexture textureToSet ) { - textureTarget = new RenderTexture (NewTexSizeX, NewTexSizeY, 0, RenderTextureFormat.RHalf, RenderTextureReadWrite.Linear); - textureTarget.wrapMode = TextureWrapMode.Repeat; - Graphics.Blit (textureToSet, textureTarget); - return textureTarget; - } - - IEnumerator SetMaps () { - - if (MGS._HeightMap == null) { - yield break; - } - - if (MGS._DiffuseMap != null) { - Debug.Log ("Setting Diffuse"); - Destroy (MGS._DiffuseMap); - MGS._DiffuseMap = null; - MGS._DiffuseMap = SetMap( MGS._DiffuseMap, _DiffuseMapTemp ); - } - - yield return new WaitForSeconds(0.1f); - - if (MGS._DiffuseMapOriginal != null) { - Debug.Log ("Setting Original Diffuse"); - Destroy (MGS._DiffuseMapOriginal); - MGS._DiffuseMapOriginal = null; - MGS._DiffuseMapOriginal = SetMap( MGS._DiffuseMapOriginal, _DiffuseMapOriginalTemp ); - } - - yield return new WaitForSeconds(0.1f); - - if (MGS._MetallicMap != null) { - Debug.Log ("Setting Specular"); - Destroy (MGS._MetallicMap); - MGS._MetallicMap = null; - MGS._MetallicMap = SetMap( MGS._MetallicMap, _MetallicMapTemp ); - } - - yield return new WaitForSeconds(0.1f); - - if (MGS._SmoothnessMap != null) { - Debug.Log ("Setting Roughness"); - Destroy (MGS._SmoothnessMap); - MGS._SmoothnessMap = null; - MGS._SmoothnessMap = SetMap( MGS._SmoothnessMap, _SmoothnessMapTemp ); - } - - yield return new WaitForSeconds(0.1f); - - if (MGS._NormalMap != null) { - Debug.Log ("Setting Normal"); - Destroy (MGS._NormalMap); - MGS._NormalMap = null; - MGS._NormalMap = SetMap( MGS._NormalMap, _NormalMapTemp ); - } - - yield return new WaitForSeconds(0.1f); - - if (MGS._EdgeMap != null) { - Debug.Log ("Setting Edge"); - Destroy (MGS._EdgeMap); - MGS._EdgeMap = null; - MGS._EdgeMap = SetMap( MGS._EdgeMap, _EdgeMapTemp ); - } - - yield return new WaitForSeconds(0.1f); - - if (MGS._AOMap != null) { - Debug.Log ("Setting AO"); - Destroy (MGS._AOMap); - MGS._AOMap = null; - MGS._AOMap = SetMap( MGS._AOMap, _AOMapTemp ); - } - - yield return new WaitForSeconds(0.1f); - - if (MGS._HeightMap != null) { - Debug.Log ("Setting Height"); - Destroy (MGS._HeightMap); - MGS._HeightMap = null; - MGS._HeightMap = SetMap (MGS._HeightMap, _HeightMapTemp); - } - - yield return new WaitForSeconds(0.1f); - - - if (MGS._HDHeightMap != null) { - Debug.Log ("Setting Height"); - MGS._HDHeightMap.Release (); - MGS._HDHeightMap = null; - MGS._HDHeightMap = SetMapRT (MGS._HDHeightMap, _HDHeightMapTemp); - } - - yield return new WaitForSeconds(0.1f); - - - Resources.UnloadUnusedAssets (); - - } - - public void Close(){ - CleanupTextures (); - this.gameObject.SetActive (false); - } - - void CleanupTexture( RenderTexture _Texture ) { - if (_Texture != null) { - _Texture.Release(); - _Texture = null; - } - } - - void CleanupTexture( Texture2D _Texture ) { - if (_Texture != null) { - Destroy( _Texture ); - _Texture = null; - } - } - - void CleanupTextures() { - - Debug.Log ("Cleaning Up Textures"); - - CleanupTexture( _HDHeightMapTemp ); - CleanupTexture( _HeightMapTemp ); - CleanupTexture( _DiffuseMapTemp ); - CleanupTexture( _DiffuseMapOriginalTemp ); - CleanupTexture( _MetallicMapTemp ); - CleanupTexture( _SmoothnessMapTemp ); - CleanupTexture( _NormalMapTemp ); - CleanupTexture( _EdgeMapTemp ); - CleanupTexture( _AOMapTemp ); - - CleanupTexture( _TileTemp ); - CleanupTexture( _SplatTemp ); - CleanupTexture( _SplatTempAlt ); - - } - - // need an overload to turn Texture2D into RenderTexture; - RenderTexture TileTexture ( Texture2D textureToTile, RenderTexture textureTarget, string TexName ) { - - CleanupTexture( _TileTemp ); - _TileTemp = new RenderTexture (textureToTile.width, textureToTile.height, 0, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear); - _TileTemp.wrapMode = TextureWrapMode.Repeat; - blitMaterial.SetTexture ("_MainTex", textureToTile); - Graphics.Blit( textureToTile, _TileTemp ); - - return TileTexture (_TileTemp, textureTarget, TexName); - - } - - RenderTexture TileTexture ( RenderTexture textureToTile, RenderTexture textureTarget, string TexName ) { - - switch(tileTech) { - case TileTechnique.Overlap: - return TileTextureOverlap (textureToTile, textureTarget, TexName); - break; - case TileTechnique.Splat: - return TileTextureSplat (textureToTile, textureTarget, TexName); - break; - default: - return TileTextureOverlap (textureToTile, textureTarget, TexName); - break; - } - - } - - RenderTexture TileTextureSplat ( RenderTexture textureToTile, RenderTexture textureTarget, string TexName ) { - - if (textureTarget != null) { - textureTarget.Release (); - textureTarget = null; - } - - //Transform transHelper = new GameObject ().transform; - - CleanupTexture( _SplatTemp ); - CleanupTexture( _SplatTempAlt ); - - if (TexName == "_HDDisplacementMap") { - _SplatTemp = new RenderTexture (NewTexSizeX, NewTexSizeY, 0, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear); - _SplatTemp.wrapMode = TextureWrapMode.Repeat; - _SplatTempAlt = new RenderTexture (NewTexSizeX, NewTexSizeY, 0, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear); - _SplatTempAlt.wrapMode = TextureWrapMode.Repeat; - textureTarget = new RenderTexture( NewTexSizeX, NewTexSizeY, 0, RenderTextureFormat.ARGBHalf, RenderTextureReadWrite.Linear); - textureTarget.wrapMode = TextureWrapMode.Repeat; - } else { - _SplatTemp = new RenderTexture (NewTexSizeX, NewTexSizeY, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear); - _SplatTemp.wrapMode = TextureWrapMode.Repeat; - _SplatTempAlt = new RenderTexture (NewTexSizeX, NewTexSizeY, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear); - _SplatTempAlt.wrapMode = TextureWrapMode.Repeat; - textureTarget = new RenderTexture( NewTexSizeX, NewTexSizeY, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear); - textureTarget.wrapMode = TextureWrapMode.Repeat; - } - textureTarget.wrapMode = TextureWrapMode.Repeat; - - blitMaterial.SetTexture ("_MainTex", textureToTile); - blitMaterial.SetTexture ("_HeightTex", MGS._HeightMap); - blitMaterial.SetVector ("_ObjectScale", objectScale); - - if (SettingsGui.instance.settings.normalMapMayaStyle) { - blitMaterial.SetFloat ("_FlipY", 1.0f); - } else { - blitMaterial.SetFloat ("_FlipY", 0.0f); - } - - // Clear the ping pong buffers - Graphics.Blit (Texture2D.blackTexture, _SplatTemp, blitMaterial, 2); - Graphics.Blit (Texture2D.blackTexture, _SplatTempAlt, blitMaterial, 2); - - float texARWidth = (float)MGS._HeightMap.width / (float)MGS._HeightMap.height; - float texARHeight = (float)MGS._HeightMap.height / (float)MGS._HeightMap.width; - Vector2 texAR = Vector2.one; - if (texARWidth < texARHeight) { - texAR.x = texARWidth; - } else { - texAR.y = texARHeight; - } - - float targetARWidth = (float)NewTexSizeX / (float)NewTexSizeY; - float targetARHeight = (float)NewTexSizeY / (float)NewTexSizeX; - targetAR = Vector2.one; - if (targetARWidth < targetARHeight) { - targetAR.x = targetARWidth; - } else { - targetAR.y = targetARHeight; - } - - blitMaterial.SetFloat("_SplatScale", SplatScale ); - blitMaterial.SetVector("_AspectRatio", texAR ); - blitMaterial.SetVector ("_TargetAspectRatio", targetAR); - - blitMaterial.SetFloat("_SplatRotation", SplatRotation ); - blitMaterial.SetFloat("_SplatRotationRandom", SplatRotationRandom ); - - bool isEven = true; - for (int i = 0; i < splatKernel.Length; i++) { - - blitMaterial.SetVector("_SplatKernel", splatKernel[i] ); - - float offsetX = Mathf.Sin ( ( SplatRandomize + 1.0f + (float)i ) * 128.352f ); - float offsetY = Mathf.Cos ( ( SplatRandomize + 1.0f + (float)i ) * 243.767f ); - blitMaterial.SetVector("_Wobble", new Vector3( offsetX, offsetY, SplatWobble ) ); - - blitMaterial.SetFloat ("_SplatRandomize", Mathf.Sin ( ( SplatRandomize + 1.0f + (float)i ) * 472.361f )); - - if( isEven ){ - blitMaterial.SetTexture ("_TargetTex", _SplatTempAlt); - Graphics.Blit (textureToTile, _SplatTemp, blitMaterial, 1); - isEven = false; - }else{ - blitMaterial.SetTexture ("_TargetTex", _SplatTemp); - Graphics.Blit (textureToTile, _SplatTempAlt, blitMaterial, 1); - isEven = true; - } - } - - //GameObject.Destroy(transHelper.gameObject); - - if (isEven) { - Graphics.Blit (_SplatTempAlt, textureTarget, blitMaterial, 3); - } else { - Graphics.Blit (_SplatTemp, textureTarget, blitMaterial, 3); - } - - thisMaterial.SetTexture ( TexName, textureTarget ); - - CleanupTexture( _SplatTemp ); - CleanupTexture( _SplatTempAlt ); - - return textureTarget; - - } - - - RenderTexture TileTextureOverlap ( RenderTexture textureToTile, RenderTexture textureTarget, string TexName ) { - - if (textureTarget != null) { - textureTarget.Release (); - textureTarget = null; - } - - if (TexName == "_HDDisplacementMap") { - textureTarget = new RenderTexture (NewTexSizeX, NewTexSizeY, 0, RenderTextureFormat.RHalf, RenderTextureReadWrite.Linear); - textureTarget.wrapMode = TextureWrapMode.Repeat; - } else { - textureTarget = new RenderTexture (NewTexSizeX, NewTexSizeY, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear); - textureTarget.wrapMode = TextureWrapMode.Repeat; - } - textureTarget.wrapMode = TextureWrapMode.Repeat; - - blitMaterial.SetTexture ("_MainTex", textureToTile); - - Graphics.Blit( textureToTile, textureTarget, blitMaterial, 0 ); - - thisMaterial.SetTexture ( TexName, textureTarget ); - - return textureTarget; - - } - - IEnumerator TileTextures () { - - Debug.Log ("Processing Tile"); - - blitMaterial.SetFloat ("_Falloff", 1.0f); - blitMaterial.SetFloat ("_Falloff", Falloff); - blitMaterial.SetFloat ("_OverlapX", OverlapX); - blitMaterial.SetFloat ("_OverlapY", OverlapY); - - if (MGS._HeightMap == null) { - yield break; - } else { - blitMaterial.SetTexture ("_HeightTex", MGS._HeightMap); - blitMaterial.SetFloat ( "_IsHeight", 1.0f ); - _HeightMapTemp = TileTexture(MGS._HeightMap, _HeightMapTemp, "_DisplacementMap"); - } + yield return new WaitForSeconds(0.1f); + if (MainGui.Instance.SmoothnessMap != null) + { + Debug.Log("Setting Roughness"); + Destroy(MainGui.Instance.SmoothnessMap); + MainGui.Instance.SmoothnessMap = null; + MainGui.Instance.SmoothnessMap = SetMap(MainGui.Instance.SmoothnessMap, _smoothnessMapTemp); + } + + yield return new WaitForSeconds(0.1f); + + if (MainGui.Instance.NormalMap) + { + Debug.Log("Setting Normal"); + Destroy(MainGui.Instance.NormalMap); + MainGui.Instance.NormalMap = null; + MainGui.Instance.NormalMap = SetMap(MainGui.Instance.NormalMap, _normalMapTemp); + } + + yield return new WaitForSeconds(0.1f); + + if (MainGui.Instance.EdgeMap) + { + Debug.Log("Setting Edge"); + Destroy(MainGui.Instance.EdgeMap); + MainGui.Instance.EdgeMap = null; + MainGui.Instance.EdgeMap = SetMap(MainGui.Instance.EdgeMap, _edgeMapTemp); + } + + yield return new WaitForSeconds(0.1f); + + if (MainGui.Instance.AoMap) + { + Debug.Log("Setting AO"); + Destroy(MainGui.Instance.AoMap); + MainGui.Instance.AoMap = null; + MainGui.Instance.AoMap = SetMap(MainGui.Instance.AoMap, _aoMapTemp); + } + + yield return new WaitForSeconds(0.1f); + + if (MainGui.Instance.HeightMap) + { + Debug.Log("Setting Height"); + Destroy(MainGui.Instance.HeightMap); + MainGui.Instance.HeightMap = null; + MainGui.Instance.HeightMap = SetMap(MainGui.Instance.HeightMap, _heightMapTemp); + } + + yield return new WaitForSeconds(0.1f); + + + if (MainGui.Instance.HdHeightMap) + { + Debug.Log("Setting Height"); + MainGui.Instance.HdHeightMap.Release(); + MainGui.Instance.HdHeightMap = null; + MainGui.Instance.HdHeightMap = SetMapRt(MainGui.Instance.HdHeightMap, _hdHeightMapTemp); + } + + yield return new WaitForSeconds(0.1f); + + + Resources.UnloadUnusedAssets(); + } + + public void Close() + { + CleanupTextures(); + gameObject.SetActive(false); + } + + private static void CleanupTexture(RenderTexture texture) + { + if (!texture) return; + texture.Release(); + // ReSharper disable once RedundantAssignment + texture = null; + } + + private void CleanupTextures() + { + CleanupTexture(_hdHeightMapTemp); + CleanupTexture(_heightMapTemp); + CleanupTexture(_diffuseMapTemp); + CleanupTexture(_diffuseMapOriginalTemp); + CleanupTexture(_metallicMapTemp); + CleanupTexture(_smoothnessMapTemp); + CleanupTexture(_normalMapTemp); + CleanupTexture(_edgeMapTemp); + CleanupTexture(_aoMapTemp); + + CleanupTexture(_tileTemp); + CleanupTexture(_splatTemp); + CleanupTexture(_splatTempAlt); + } + + private RenderTexture TileTexture(Texture textureToTile, RenderTexture textureTarget, string texName) + { + CleanupTexture(_tileTemp); + _tileTemp = new RenderTexture(textureToTile.width, textureToTile.height, 0, RenderTextureFormat.ARGBHalf, + RenderTextureReadWrite.Linear) {wrapMode = TextureWrapMode.Repeat}; + _blitMaterial.SetTexture(MainTex, textureToTile); + Graphics.Blit(textureToTile, _tileTemp); + + return TileTexture(_tileTemp, textureTarget, texName); + } + + private RenderTexture TileTexture(RenderTexture textureToTile, RenderTexture textureTarget, string texName) + { + switch (_tileTech) + { + case TileTechnique.Overlap: + return TileTextureOverlap(textureToTile, textureTarget, texName); + case TileTechnique.Splat: + return TileTextureSplat(textureToTile, textureTarget, texName); + default: + return TileTextureOverlap(textureToTile, textureTarget, texName); + } + } + + private RenderTexture TileTextureSplat(Texture textureToTile, RenderTexture textureTarget, string texName) + { + if (textureTarget) + { + textureTarget.Release(); + // ReSharper disable once RedundantAssignment + textureTarget = null; + } + + //Transform transHelper = new GameObject ().transform; + + CleanupTexture(_splatTemp); + CleanupTexture(_splatTempAlt); + + if (texName == "_HDDisplacementMap") + { + _splatTemp = new RenderTexture(_newTexSizeX, _newTexSizeY, 0, RenderTextureFormat.ARGBHalf, + RenderTextureReadWrite.Linear) {wrapMode = TextureWrapMode.Repeat}; + _splatTempAlt = new RenderTexture(_newTexSizeX, _newTexSizeY, 0, RenderTextureFormat.ARGBHalf, + RenderTextureReadWrite.Linear) {wrapMode = TextureWrapMode.Repeat}; + textureTarget = new RenderTexture(_newTexSizeX, _newTexSizeY, 0, RenderTextureFormat.ARGBHalf, + RenderTextureReadWrite.Linear) {wrapMode = TextureWrapMode.Repeat}; + } + else + { + _splatTemp = new RenderTexture(_newTexSizeX, _newTexSizeY, 0, RenderTextureFormat.ARGB32, + RenderTextureReadWrite.Linear) {wrapMode = TextureWrapMode.Repeat}; + _splatTempAlt = new RenderTexture(_newTexSizeX, _newTexSizeY, 0, RenderTextureFormat.ARGB32, + RenderTextureReadWrite.Linear) {wrapMode = TextureWrapMode.Repeat}; + textureTarget = new RenderTexture(_newTexSizeX, _newTexSizeY, 0, RenderTextureFormat.ARGB32, + RenderTextureReadWrite.Linear) {wrapMode = TextureWrapMode.Repeat}; + } + + textureTarget.wrapMode = TextureWrapMode.Repeat; + + _blitMaterial.SetTexture(MainTex, textureToTile); + _blitMaterial.SetTexture(HeightTex, MainGui.Instance.HeightMap); + _blitMaterial.SetVector(ObjectScale, _objectScale); + + _blitMaterial.SetFloat(FlipY, SettingsGui.Instance.Settings.NormalMapMayaStyle ? 1.0f : 0.0f); + + // Clear the ping pong buffers + Graphics.Blit(Texture2D.blackTexture, _splatTemp, _blitMaterial, 2); + Graphics.Blit(Texture2D.blackTexture, _splatTempAlt, _blitMaterial, 2); + + var texArWidth = MainGui.Instance.HeightMap.width / (float) MainGui.Instance.HeightMap.height; + var texArHeight = MainGui.Instance.HeightMap.height / (float) MainGui.Instance.HeightMap.width; + var texAr = Vector2.one; + if (texArWidth < texArHeight) + texAr.x = texArWidth; + else + texAr.y = texArHeight; + + var targetArWidth = _newTexSizeX / (float) _newTexSizeY; + var targetArHeight = _newTexSizeY / (float) _newTexSizeX; + _targetAr = Vector2.one; + if (targetArWidth < targetArHeight) + _targetAr.x = targetArWidth; + else + _targetAr.y = targetArHeight; + + _blitMaterial.SetFloat("_SplatScale", _splatScale); + _blitMaterial.SetVector("_AspectRatio", texAr); + _blitMaterial.SetVector("_TargetAspectRatio", _targetAr); + + _blitMaterial.SetFloat("_SplatRotation", _splatRotation); + _blitMaterial.SetFloat("_SplatRotationRandom", _splatRotationRandom); + + var isEven = true; + for (var i = 0; i < _splatKernel.Length; i++) + { + _blitMaterial.SetVector("_SplatKernel", _splatKernel[i]); + + var offsetX = Mathf.Sin((_splatRandomize + 1.0f + i) * 128.352f); + var offsetY = Mathf.Cos((_splatRandomize + 1.0f + i) * 243.767f); + _blitMaterial.SetVector("_Wobble", new Vector3(offsetX, offsetY, _splatWobble)); + + _blitMaterial.SetFloat("_SplatRandomize", Mathf.Sin((_splatRandomize + 1.0f + i) * 472.361f)); + + if (isEven) + { + _blitMaterial.SetTexture("_TargetTex", _splatTempAlt); + Graphics.Blit(textureToTile, _splatTemp, _blitMaterial, 1); + isEven = false; + } + else + { + _blitMaterial.SetTexture("_TargetTex", _splatTemp); + Graphics.Blit(textureToTile, _splatTempAlt, _blitMaterial, 1); + isEven = true; + } + } + + //GameObject.Destroy(transHelper.gameObject); - if (MGS._HDHeightMap != null) { - blitMaterial.SetFloat ( "_IsHeight", 1.0f ); - _HDHeightMapTemp = TileTexture(MGS._HDHeightMap, _HDHeightMapTemp, "_HDDisplacementMap"); - } + Graphics.Blit(isEven ? _splatTempAlt : _splatTemp, textureTarget, _blitMaterial, 3); + _thisMaterial.SetTexture(texName, textureTarget); - blitMaterial.SetFloat ( "_IsHeight", 0.0f ); + CleanupTexture(_splatTemp); + CleanupTexture(_splatTempAlt); - if (MGS._DiffuseMapOriginal != null) { - _DiffuseMapOriginalTemp = TileTexture(MGS._DiffuseMapOriginal, _DiffuseMapOriginalTemp, "_DiffuseMapOriginal"); - thisMaterial.SetTexture ("_DiffuseMap", _DiffuseMapOriginalTemp); - } + return textureTarget; + } - if (MGS._DiffuseMap != null) { - _DiffuseMapTemp = TileTexture(MGS._DiffuseMap, _DiffuseMapTemp, "_DiffuseMap"); - thisMaterial.SetTexture ("_DiffuseMap", _DiffuseMapTemp); - } - if (MGS._MetallicMap != null) { - _MetallicMapTemp = TileTexture(MGS._MetallicMap, _MetallicMapTemp, "_MetallicMap"); - thisMaterial.SetTexture ("_MetallicMap", _MetallicMapTemp); - } + private RenderTexture TileTextureOverlap(Texture textureToTile, RenderTexture textureTarget, string texName) + { + if (textureTarget) + { + textureTarget.Release(); + // ReSharper disable once RedundantAssignment + textureTarget = null; + } + + if (texName == "_HDDisplacementMap") + { + textureTarget = new RenderTexture(_newTexSizeX, _newTexSizeY, 0, RenderTextureFormat.RHalf, + RenderTextureReadWrite.Linear) {wrapMode = TextureWrapMode.Repeat}; + } + else + { + textureTarget = new RenderTexture(_newTexSizeX, _newTexSizeY, 0, RenderTextureFormat.ARGB32, + RenderTextureReadWrite.Linear) {wrapMode = TextureWrapMode.Repeat}; + } + + textureTarget.wrapMode = TextureWrapMode.Repeat; + + _blitMaterial.SetTexture("_MainTex", textureToTile); + + Graphics.Blit(textureToTile, textureTarget, _blitMaterial, 0); + + _thisMaterial.SetTexture(texName, textureTarget); + + return textureTarget; + } + + private IEnumerator TileTextures() + { + Debug.Log("Processing Tile"); + + _blitMaterial.SetFloat("_Falloff", 1.0f); + _blitMaterial.SetFloat("_Falloff", _falloff); + _blitMaterial.SetFloat("_OverlapX", _overlapX); + _blitMaterial.SetFloat("_OverlapY", _overlapY); + + if (MainGui.Instance.HeightMap == null) + { + yield break; + } + + _blitMaterial.SetTexture("_HeightTex", MainGui.Instance.HeightMap); + _blitMaterial.SetFloat("_IsHeight", 1.0f); + _heightMapTemp = TileTexture(MainGui.Instance.HeightMap, _heightMapTemp, "_DisplacementMap"); + - if (MGS._SmoothnessMap != null) { - _SmoothnessMapTemp = TileTexture(MGS._SmoothnessMap, _SmoothnessMapTemp, "_SmoothnessMap"); - thisMaterial.SetTexture ("_SmoothnessMap", _SmoothnessMapTemp); - } + if (MainGui.Instance.HdHeightMap != null) + { + _blitMaterial.SetFloat("_IsHeight", 1.0f); + _hdHeightMapTemp = TileTexture(MainGui.Instance.HdHeightMap, _hdHeightMapTemp, "_HDDisplacementMap"); + } + + + _blitMaterial.SetFloat("_IsHeight", 0.0f); + + if (MainGui.Instance.DiffuseMapOriginal != null) + { + _diffuseMapOriginalTemp = + TileTexture(MainGui.Instance.DiffuseMapOriginal, _diffuseMapOriginalTemp, "_DiffuseMapOriginal"); + _thisMaterial.SetTexture("_DiffuseMap", _diffuseMapOriginalTemp); + } - if (MGS._NormalMap != null) { - blitMaterial.SetFloat ( "_IsNormal", 1.0f ); - _NormalMapTemp = TileTexture(MGS._NormalMap, _NormalMapTemp, "_NormalMap"); - thisMaterial.SetTexture ("_NormalMap", _NormalMapTemp); - } + if (MainGui.Instance.DiffuseMap != null) + { + _diffuseMapTemp = TileTexture(MainGui.Instance.DiffuseMap, _diffuseMapTemp, "_DiffuseMap"); + _thisMaterial.SetTexture("_DiffuseMap", _diffuseMapTemp); + } - blitMaterial.SetFloat ( "_IsNormal", 0.0f ); + if (MainGui.Instance.MetallicMap != null) + { + _metallicMapTemp = TileTexture(MainGui.Instance.MetallicMap, _metallicMapTemp, "_MetallicMap"); + _thisMaterial.SetTexture("_MetallicMap", _metallicMapTemp); + } - if (MGS._EdgeMap != null) { - _EdgeMapTemp = TileTexture(MGS._EdgeMap, _EdgeMapTemp, "_EdgeMap"); - thisMaterial.SetTexture ("_EdgeMap", _EdgeMapTemp); - } + if (MainGui.Instance.SmoothnessMap != null) + { + _smoothnessMapTemp = TileTexture(MainGui.Instance.SmoothnessMap, _smoothnessMapTemp, "_SmoothnessMap"); + _thisMaterial.SetTexture("_SmoothnessMap", _smoothnessMapTemp); + } + + if (MainGui.Instance.NormalMap != null) + { + _blitMaterial.SetFloat("_IsNormal", 1.0f); + _normalMapTemp = TileTexture(MainGui.Instance.NormalMap, _normalMapTemp, "_NormalMap"); + _thisMaterial.SetTexture("_NormalMap", _normalMapTemp); + } + + _blitMaterial.SetFloat("_IsNormal", 0.0f); + + if (MainGui.Instance.EdgeMap != null) + { + _edgeMapTemp = TileTexture(MainGui.Instance.EdgeMap, _edgeMapTemp, "_EdgeMap"); + _thisMaterial.SetTexture("_EdgeMap", _edgeMapTemp); + } + + if (MainGui.Instance.AoMap != null) + { + _aoMapTemp = TileTexture(MainGui.Instance.AoMap, _aoMapTemp, "_AOMap"); + _thisMaterial.SetTexture("_AOMap", _aoMapTemp); + } - if (MGS._AOMap != null) { - _AOMapTemp = TileTexture(MGS._AOMap, _AOMapTemp, "_AOMap"); - thisMaterial.SetTexture ("_AOMap", _AOMapTemp); - } + Resources.UnloadUnusedAssets(); - Resources.UnloadUnusedAssets (); + yield return new WaitForSeconds(0.1f); + } - yield return new WaitForSeconds(0.1f); - } + private enum TileTechnique + { + Overlap, + Splat + } } \ No newline at end of file diff --git a/Assets/Scripts/WelcomeGui.cs b/Assets/Scripts/WelcomeGui.cs index 4f51bff9..b2946346 100644 --- a/Assets/Scripts/WelcomeGui.cs +++ b/Assets/Scripts/WelcomeGui.cs @@ -1,116 +1,123 @@ -using UnityEngine; -using System.Collections; - -public class WelcomeGui : MonoBehaviour { - - public bool skipWelcomeScreen; - - public Texture2D logo; - public Texture2D background; - public Cubemap startCubeMap; - - public GameObject MainGuiObject; - public GameObject testObject; - public GameObject SettingsGuiObject; - public GameObject ControlsGuiObject; - public GameObject CommandListExecutorObject; - - - float backgroundFade = 1.0f; - float logoFade = 1.0f; +#region - // Use this for initialization - void Start () { - - Application.runInBackground = true; - - float backgroundFade = 1.0f; - float logoFade = 0.0f; - - if ( skipWelcomeScreen || Application.isEditor ) { - ActivateObjects(); - this.gameObject.SetActive(false); - } else { - StartCoroutine (Intro ()); - } - - Shader.SetGlobalTexture ("_GlobalCubemap", startCubeMap ); - } - - // Update is called once per frame - void Update () { - - } - - void ActivateObjects() { - testObject.SetActive(true); - MainGuiObject.SetActive(true); - SettingsGuiObject.SetActive(true); - ControlsGuiObject.SetActive(true); - CommandListExecutorObject.SetActive(true); - } +using System.Collections; +using UnityEngine; + +#endregion + +public class WelcomeGui : MonoBehaviour +{ + private static readonly int GlobalCubemap = Shader.PropertyToID("_GlobalCubemap"); + + + private float _backgroundFade = 1.0f; + private float _logoFade = 1.0f; + public Texture2D Background; + public GameObject CommandListExecutorObject; + public GameObject ControlsGuiObject; - void OnGUI () { + public Texture2D Logo; - GUI.color = new Color(1,1,1,backgroundFade); + public GameObject MainGuiObject; + public GameObject SettingsGuiObject; - GUI.DrawTexture (new Rect (0, 0, Screen.width, Screen.height), background); + public bool SkipWelcomeScreen; + public Cubemap StartCubeMap; + public GameObject TestObject; - int logoWidth = Mathf.FloorToInt (Screen.width * 0.75f); - int logoHeight = Mathf.FloorToInt (logoWidth * 0.5f); - int logoPosX = Mathf.FloorToInt (Screen.width * 0.5f - logoWidth * 0.5f); - int logoPosY = Mathf.FloorToInt (Screen.height * 0.5f - logoHeight * 0.5f); + private void Start() + { + Application.runInBackground = true; + if (PlayerPrefs.HasKey("targetFrameRate")) + { + Application.targetFrameRate = PlayerPrefs.GetInt("targetFrameRate"); + QualitySettings.vSyncCount = PlayerPrefs.GetInt("Vsync"); + } + if (SkipWelcomeScreen || Application.isEditor) + { + ActivateObjects(); + gameObject.SetActive(false); + } + else + { + StartCoroutine(Intro()); + } - GUI.color = new Color(1,1,1,logoFade); + Shader.SetGlobalTexture(GlobalCubemap, StartCubeMap); + } - GUI.DrawTexture (new Rect (logoPosX, logoPosY, logoWidth, logoHeight), logo); - } - IEnumerator FadeLogo ( float target, float overTime ) { + private void ActivateObjects() + { + TestObject.SetActive(true); + MainGuiObject.SetActive(true); + SettingsGuiObject.SetActive(true); + ControlsGuiObject.SetActive(true); + CommandListExecutorObject.SetActive(true); + } - float timer = overTime; - float original = logoFade; + private void OnGUI() + { + GUI.color = new Color(1, 1, 1, _backgroundFade); - while( timer > 0.0f ){ - timer -= Time.deltaTime; - logoFade = Mathf.Lerp( target, original, timer / overTime ); - yield return new WaitForEndOfFrame(); - } + GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), Background); - logoFade = target; + var logoWidth = Mathf.FloorToInt(Screen.width * 0.75f); + var logoHeight = Mathf.FloorToInt(logoWidth * 0.5f); + var logoPosX = Mathf.FloorToInt(Screen.width * 0.5f - logoWidth * 0.5f); + var logoPosY = Mathf.FloorToInt(Screen.height * 0.5f - logoHeight * 0.5f); - //yield return new WaitForEndOfFrame(); + GUI.color = new Color(1, 1, 1, _logoFade); - } + GUI.DrawTexture(new Rect(logoPosX, logoPosY, logoWidth, logoHeight), Logo); + } - IEnumerator FadeBackground ( float target, float overTime ) { - - float timer = overTime; - float original = backgroundFade; - - while( timer > 0.0f ){ - timer -= Time.deltaTime; - backgroundFade = Mathf.Lerp( target, original, timer / overTime ); - yield return new WaitForEndOfFrame(); - } - - backgroundFade = target; + private IEnumerator FadeLogo(float target, float overTime) + { + var timer = overTime; + var original = _logoFade; - this.gameObject.SetActive (false); - } + while (timer > 0.0f) + { + timer -= Time.deltaTime; + _logoFade = Mathf.Lerp(target, original, timer / overTime); + yield return new WaitForEndOfFrame(); + } - IEnumerator Intro () { + _logoFade = target; - StartCoroutine ( FadeLogo ( 1.0f, 0.5f) ); + //yield return new WaitForEndOfFrame(); + } - yield return new WaitForSeconds(3.0f); + private IEnumerator FadeBackground(float target, float overTime) + { + var timer = overTime; + var original = _backgroundFade; - StartCoroutine ( FadeLogo ( 0.0f, 1.0f) ); + while (timer > 0.0f) + { + timer -= Time.deltaTime; + _backgroundFade = Mathf.Lerp(target, original, timer / overTime); + yield return new WaitForEndOfFrame(); + } - yield return new WaitForSeconds(1.0f); + _backgroundFade = target; - StartCoroutine ( FadeBackground ( 0.0f, 1.0f) ); + gameObject.SetActive(false); + } + + private IEnumerator Intro() + { + StartCoroutine(FadeLogo(1.0f, 0.5f)); + + yield return new WaitForSeconds(3.0f); + + StartCoroutine(FadeLogo(0.0f, 1.0f)); + + yield return new WaitForSeconds(1.0f); - ActivateObjects(); - } -} + StartCoroutine(FadeBackground(0.0f, 1.0f)); + + ActivateObjects(); + } +} \ No newline at end of file diff --git a/Assets/SetPropertyMap.cs b/Assets/SetPropertyMap.cs new file mode 100644 index 00000000..2b69f978 --- /dev/null +++ b/Assets/SetPropertyMap.cs @@ -0,0 +1,50 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UI; + +public class SetPropertyMap : MonoBehaviour +{ + public string DropDownType; + public Dropdown RedMap; + public Dropdown BlueMap; + public Dropdown GreenMap; + public Dropdown AlphaMap; + + + public void SetPropertyMapSelection(int selection) + { + MainGui.Instance.MapSelection(selection, DropDownType); + } + + public void SetPreset(int selection) + { + switch (selection) + { + case 0: + + break; + case 1: + setChannels(1, 0, 4, 2); + break; + case 2: + setChannels(2, 4, 1, 0); + break; + default: + break; + } + } + private void setChannels(int red, int blue, int green, int alpha) + { + + RedMap.value = red; + BlueMap.value = blue; + GreenMap.value = green; + AlphaMap.value = alpha; + //RedMap.SetPropertyMapSelection(red); + //BlueMap.SetPropertyMapSelection(blue); + //GreenMap.SetPropertyMapSelection(green); + //AlphaMap.SetPropertyMapSelection(alpha); + + } +} diff --git a/Assets/SetPropertyMap.cs.meta b/Assets/SetPropertyMap.cs.meta new file mode 100644 index 00000000..f8733441 --- /dev/null +++ b/Assets/SetPropertyMap.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8747724993b9b3841a1bcc33853a384f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Shaders/Alignment_Shader.shader b/Assets/Shaders/Alignment_Shader.shader index 2a9af772..9b89cc98 100644 --- a/Assets/Shaders/Alignment_Shader.shader +++ b/Assets/Shaders/Alignment_Shader.shader @@ -1,6 +1,7 @@ Shader "Custom/Alignment_Shader" { Properties { _MainTex ("Base (RGB)", 2D) = "white" {} + _CorrectTex ("Base (RGB)", 2D) = "white" {} } SubShader { Tags { "RenderType"="Opaque" } diff --git a/Assets/Shaders/Colored Blended.shader b/Assets/Shaders/Colored Blended.shader new file mode 100644 index 00000000..0d03e5dd --- /dev/null +++ b/Assets/Shaders/Colored Blended.shader @@ -0,0 +1,12 @@ +Shader "Lines/Colored Blended" +{ + SubShader + { + Pass + { + Blend SrcAlpha OneMinusSrcAlpha + ZWrite Off Cull Off Fog { Mode Off } + BindChannels { Bind "vertex", vertex Bind "color", color } + } + } +} diff --git a/Assets/Shaders/Colored Blended.shader.meta b/Assets/Shaders/Colored Blended.shader.meta new file mode 100644 index 00000000..b5240a53 --- /dev/null +++ b/Assets/Shaders/Colored Blended.shader.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: c5e7505d0f27de3d5b3444221b1afd33 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Shaders/Diffuse_AO_Mix.shader b/Assets/Shaders/Diffuse_AO_Mix.shader new file mode 100644 index 00000000..4712fe57 --- /dev/null +++ b/Assets/Shaders/Diffuse_AO_Mix.shader @@ -0,0 +1,59 @@ +// Made with Amplify Shader Editor +// Available at the Unity Asset Store - http://u3d.as/y3X +Shader "Diffuse_AO_Mix" +{ + Properties + { + _Diffuse_Map("Diffuse_Map", 2D) = "white" {} + _AO_Map("AO_Map", 2D) = "white" {} + _AOAmount("AO Amount", Float) = 0.5 + [HideInInspector] _texcoord( "", 2D ) = "white" {} + [HideInInspector] __dirty( "", Int ) = 1 + } + + SubShader + { + Tags{ "RenderType" = "Opaque" "Queue" = "Geometry+0" } + Cull Back + CGPROGRAM + #pragma target 3.0 + #pragma surface surf Standard keepalpha addshadow fullforwardshadows + struct Input + { + float2 uv_texcoord; + }; + + uniform sampler2D _Diffuse_Map; + uniform float4 _Diffuse_Map_ST; + uniform sampler2D _AO_Map; + uniform float4 _AO_Map_ST; + uniform float _AOAmount; + + void surf( Input i , inout SurfaceOutputStandard o ) + { + float2 uv_Diffuse_Map = i.uv_texcoord * _Diffuse_Map_ST.xy + _Diffuse_Map_ST.zw; + o.Albedo = tex2D( _Diffuse_Map, uv_Diffuse_Map ).rgb; + float2 uv_AO_Map = i.uv_texcoord * _AO_Map_ST.xy + _AO_Map_ST.zw; + o.Occlusion = pow( tex2D( _AO_Map, uv_AO_Map ).r , _AOAmount ); + o.Alpha = 1; + } + + ENDCG + } + Fallback "Diffuse" + CustomEditor "ASEMaterialInspector" +} +/*ASEBEGIN +Version=16301 +612;638;752;362;1074.069;186.084;1.3;True;False +Node;AmplifyShaderEditor.RangedFloatNode;4;-654.1684,-18.38394;Float;False;Property;_AOAmount;AO Amount;2;0;Create;True;0;0;False;0;0.5;0.5;0;0;0;1;FLOAT;0 +Node;AmplifyShaderEditor.SamplerNode;2;-774.7679,-214.6149;Float;True;Property;_AO_Map;AO_Map;1;0;Create;True;0;0;False;0;390f24b6633f86b42aea57b4a56ce72b;390f24b6633f86b42aea57b4a56ce72b;True;0;False;white;Auto;False;Object;-1;Auto;Texture2D;6;0;SAMPLER2D;;False;1;FLOAT2;0,0;False;2;FLOAT;0;False;3;FLOAT2;0,0;False;4;FLOAT2;0,0;False;5;FLOAT;1;False;5;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4 +Node;AmplifyShaderEditor.PowerNode;5;-374.6689,-173.084;Float;True;2;0;FLOAT;0;False;1;FLOAT;1;False;1;FLOAT;0 +Node;AmplifyShaderEditor.SamplerNode;1;-802.9938,136.1047;Float;True;Property;_Diffuse_Map;Diffuse_Map;0;0;Create;True;0;0;False;0;d7621594f8fd9d64e8aa19e123780f68;d7621594f8fd9d64e8aa19e123780f68;True;0;False;white;Auto;False;Object;-1;Auto;Texture2D;6;0;SAMPLER2D;;False;1;FLOAT2;0,0;False;2;FLOAT;0;False;3;FLOAT2;0,0;False;4;FLOAT2;0,0;False;5;FLOAT;1;False;5;COLOR;0;FLOAT;1;FLOAT;2;FLOAT;3;FLOAT;4 +Node;AmplifyShaderEditor.StandardSurfaceOutputNode;0;31,-176;Float;False;True;2;Float;ASEMaterialInspector;0;0;Standard;Diffuse_AO_Mix;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;False;Back;0;False;-1;0;False;-1;False;0;False;-1;0;False;-1;False;0;Opaque;0.5;True;True;0;False;Opaque;;Geometry;All;True;True;True;True;True;True;True;True;True;True;True;True;True;True;True;True;True;0;False;-1;False;0;False;-1;255;False;-1;255;False;-1;0;False;-1;0;False;-1;0;False;-1;0;False;-1;0;False;-1;0;False;-1;0;False;-1;0;False;-1;False;2;15;10;25;False;0.5;True;0;0;False;-1;0;False;-1;0;0;False;-1;0;False;-1;0;False;-1;0;False;-1;0;False;0;0,0,0,0;VertexOffset;True;False;Cylindrical;False;Relative;0;;-1;-1;-1;-1;0;False;0;0;False;-1;-1;0;False;-1;0;0;0;False;0.1;False;-1;0;False;-1;16;0;FLOAT3;0,0,0;False;1;FLOAT3;0,0,0;False;2;FLOAT3;0,0,0;False;3;FLOAT;0;False;4;FLOAT;0;False;5;FLOAT;0;False;6;FLOAT3;0,0,0;False;7;FLOAT3;0,0,0;False;8;FLOAT;0;False;9;FLOAT;0;False;10;FLOAT;0;False;13;FLOAT3;0,0,0;False;11;FLOAT3;0,0,0;False;12;FLOAT3;0,0,0;False;14;FLOAT4;0,0,0,0;False;15;FLOAT3;0,0,0;False;0 +WireConnection;5;0;2;1 +WireConnection;5;1;4;0 +WireConnection;0;0;1;0 +WireConnection;0;5;5;0 +ASEEND*/ +//CHKSM=CEE2DBF7243C96559B33F52EACBDE644C9897353 \ No newline at end of file diff --git a/Assets/Shaders/Diffuse_AO_Mix.shader.meta b/Assets/Shaders/Diffuse_AO_Mix.shader.meta new file mode 100644 index 00000000..eab87fab --- /dev/null +++ b/Assets/Shaders/Diffuse_AO_Mix.shader.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 4c2efbb4897bee33c93b5c79920096a7 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Shaders/Edit_Diffuse_Preview.shader b/Assets/Shaders/Edit_Diffuse_Preview.shader index b56564f3..f9e28d75 100644 --- a/Assets/Shaders/Edit_Diffuse_Preview.shader +++ b/Assets/Shaders/Edit_Diffuse_Preview.shader @@ -93,11 +93,11 @@ float darkMaskPow = saturate( ( _DarkMaskPow - 0.5 ) * 2.0 ) + 1; darkMaskPow -= 1.0 - ( 1.0 / ( saturate( ( _DarkMaskPow - 0.5 ) * -2.0 ) + 1.0) ); - mainTex = ( mainTex - avgColor); + mainTex = ( mainTex - avgColor);// half mainTexGrey = mainTex.x * 0.3 + mainTex.y * 0.5 + mainTex.z * 0.2; half3 mainTexHighMask = pow( clamp( mainTexGrey * 2.0, 0.001, 0.99 ), lightMaskPow ); half3 mainTexLowMask = pow( clamp( -mainTexGrey * 2.0, 0.001, 0.99 ), darkMaskPow ); - mainTex += 0.5; + mainTex += 0.215; //mainTex = clamp( mainTex, 0.001, 0.99 ); //mainTex = lerp( mainTex, pow( mainTex, _LightPow * 5.0 + 1.0 ), mainTexHighMask ); diff --git a/Assets/Shaders/Smoothness_Preview.shader b/Assets/Shaders/Smoothness_Preview.shader index f6dbd685..bc07417b 100644 --- a/Assets/Shaders/Smoothness_Preview.shader +++ b/Assets/Shaders/Smoothness_Preview.shader @@ -71,6 +71,8 @@ float _GamaCorrection; + int _Invert; + #include "Photoshop.cginc" // vertex-to-fragment interpolation data @@ -124,6 +126,7 @@ sample2Mask *= 1.0 / ( _HueWeight2 + _SatWeight2 + _LumWeight2 ); sample2Mask = smoothstep( _MaskLow2, _MaskHigh2, sample2Mask ); } + float finalSmoothness = _BaseSmoothness; finalSmoothness = lerp( finalSmoothness, _Sample2Smoothness, sample2Mask ); @@ -132,9 +135,13 @@ finalSmoothness *= clamp( overlayGrey * _BlurOverlay + 1.0, 0.0, 10.0 ); - finalSmoothness = saturate( ( finalSmoothness - 0.5 ) * _FinalContrast + 0.5 + _FinalBias ); - - finalSmoothness = saturate( finalSmoothness ); + if (_Invert == 1) { + finalSmoothness = saturate((finalSmoothness - 0.5) * ((_FinalContrast + 0.5) + _FinalBias) *-1); + } + else { + finalSmoothness = saturate((finalSmoothness - 0.5) * _FinalContrast + 0.5 + _FinalBias); + } + finalSmoothness = saturate( finalSmoothness ); if( _IsolateSample1 == 1 ){ finalSmoothness = sample1Mask; @@ -143,10 +150,12 @@ if( _IsolateSample2 == 1 ){ finalSmoothness = sample2Mask; } + float3 finalColor; - float3 finalColor = lerp( mainTex.xyz, finalSmoothness.xxx, smoothstep( _Slider - 0.01, _Slider + 0.01, UV.x ) ); + finalColor = lerp(mainTex.xyz, finalSmoothness.xxx, smoothstep(_Slider - 0.01, _Slider + 0.01, UV.x)); + - return float4( finalColor, 1 ); + return float4( finalColor , 1 ); } ENDCG diff --git a/Assets/StandaloneFileBrowser.meta b/Assets/StandaloneFileBrowser.meta new file mode 100644 index 00000000..fbb92ac9 --- /dev/null +++ b/Assets/StandaloneFileBrowser.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 57e25b4a578dba94c9353f4633b20549 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/StandaloneFileBrowser/IStandaloneFileBrowser.cs b/Assets/StandaloneFileBrowser/IStandaloneFileBrowser.cs new file mode 100644 index 00000000..19c089de --- /dev/null +++ b/Assets/StandaloneFileBrowser/IStandaloneFileBrowser.cs @@ -0,0 +1,13 @@ +using System; + +namespace SFB { + public interface IStandaloneFileBrowser { + string[] OpenFilePanel(string title, string directory, ExtensionFilter[] extensions, bool multiselect); + string[] OpenFolderPanel(string title, string directory, bool multiselect); + string SaveFilePanel(string title, string directory, string defaultName, ExtensionFilter[] extensions); + + void OpenFilePanelAsync(string title, string directory, ExtensionFilter[] extensions, bool multiselect, Action cb); + void OpenFolderPanelAsync(string title, string directory, bool multiselect, Action cb); + void SaveFilePanelAsync(string title, string directory, string defaultName, ExtensionFilter[] extensions, Action cb); + } +} diff --git a/Assets/Scripts/ScreenGuard.cs.meta b/Assets/StandaloneFileBrowser/IStandaloneFileBrowser.cs.meta similarity index 75% rename from Assets/Scripts/ScreenGuard.cs.meta rename to Assets/StandaloneFileBrowser/IStandaloneFileBrowser.cs.meta index 0543180b..297c5e8d 100644 --- a/Assets/Scripts/ScreenGuard.cs.meta +++ b/Assets/StandaloneFileBrowser/IStandaloneFileBrowser.cs.meta @@ -1,6 +1,6 @@ fileFormatVersion: 2 -guid: d676059daaba4f6419a04e5b906edd54 -timeCreated: 1430975799 +guid: 7609f7b6787a54496aa41a3053fcc76a +timeCreated: 1483902788 licenseType: Pro MonoImporter: serializedVersion: 2 diff --git a/Assets/StandaloneFileBrowser/Plugins.meta b/Assets/StandaloneFileBrowser/Plugins.meta new file mode 100644 index 00000000..365e9b2e --- /dev/null +++ b/Assets/StandaloneFileBrowser/Plugins.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: ddc4e7b83981f244ba9a26b88c18cb67 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/StandaloneFileBrowser/Plugins/Linux.meta b/Assets/StandaloneFileBrowser/Plugins/Linux.meta new file mode 100644 index 00000000..12e971a8 --- /dev/null +++ b/Assets/StandaloneFileBrowser/Plugins/Linux.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: 82666e520ab4d4cf08bebbb8059cd6f4 +folderAsset: yes +timeCreated: 1538224809 +licenseType: Free +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/StandaloneFileBrowser/Plugins/Linux/x86_64.meta b/Assets/StandaloneFileBrowser/Plugins/Linux/x86_64.meta new file mode 100644 index 00000000..7f52bdec --- /dev/null +++ b/Assets/StandaloneFileBrowser/Plugins/Linux/x86_64.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: bd198408642944765b9305bd99404136 +folderAsset: yes +timeCreated: 1538230728 +licenseType: Free +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/StandaloneFileBrowser/Plugins/Linux/x86_64/libStandaloneFileBrowser.so b/Assets/StandaloneFileBrowser/Plugins/Linux/x86_64/libStandaloneFileBrowser.so new file mode 100644 index 00000000..344084e5 Binary files /dev/null and b/Assets/StandaloneFileBrowser/Plugins/Linux/x86_64/libStandaloneFileBrowser.so differ diff --git a/Assets/StandaloneFileBrowser/Plugins/Linux/x86_64/libStandaloneFileBrowser.so.meta b/Assets/StandaloneFileBrowser/Plugins/Linux/x86_64/libStandaloneFileBrowser.so.meta new file mode 100644 index 00000000..eebacda3 --- /dev/null +++ b/Assets/StandaloneFileBrowser/Plugins/Linux/x86_64/libStandaloneFileBrowser.so.meta @@ -0,0 +1,127 @@ +fileFormatVersion: 2 +guid: b8c465928f1784a3fac8dc3766f7201c +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 0 + isExplicitlyReferenced: 0 + validateReferences: 1 + platformData: + - first: + '': Any + second: + enabled: 0 + settings: + Exclude Android: 1 + Exclude Editor: 0 + Exclude Linux: 1 + Exclude Linux64: 0 + Exclude LinuxUniversal: 0 + Exclude OSXIntel: 1 + Exclude OSXIntel64: 1 + Exclude OSXUniversal: 1 + Exclude SamsungTV: 1 + Exclude Tizen: 1 + Exclude WebGL: 1 + Exclude Win: 0 + Exclude Win64: 0 + Exclude iOS: 1 + - first: + Android: Android + second: + enabled: 0 + settings: + CPU: ARMv7 + - first: + Any: + second: + enabled: 0 + settings: {} + - first: + Editor: Editor + second: + enabled: 1 + settings: + CPU: x86_64 + DefaultValueInitialized: true + OS: Linux + - first: + Facebook: Win + second: + enabled: 0 + settings: + CPU: AnyCPU + - first: + Facebook: Win64 + second: + enabled: 0 + settings: + CPU: AnyCPU + - first: + Samsung TV: SamsungTV + second: + enabled: 0 + settings: + STV_MODEL: STANDARD_15 + - first: + Standalone: Linux + second: + enabled: 0 + settings: + CPU: None + - first: + Standalone: Linux64 + second: + enabled: 1 + settings: + CPU: AnyCPU + - first: + Standalone: LinuxUniversal + second: + enabled: 1 + settings: + CPU: x86_64 + - first: + Standalone: OSXIntel + second: + enabled: 0 + settings: + CPU: None + - first: + Standalone: OSXIntel64 + second: + enabled: 0 + settings: + CPU: None + - first: + Standalone: OSXUniversal + second: + enabled: 0 + settings: + CPU: None + - first: + Standalone: Win + second: + enabled: 1 + settings: + CPU: AnyCPU + - first: + Standalone: Win64 + second: + enabled: 1 + settings: + CPU: AnyCPU + - first: + iPhone: iOS + second: + enabled: 0 + settings: + CompileFlags: + FrameworkDependencies: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/StandaloneFileBrowser/Plugins/Ookii.Dialogs.dll b/Assets/StandaloneFileBrowser/Plugins/Ookii.Dialogs.dll new file mode 100644 index 00000000..a5164a5f Binary files /dev/null and b/Assets/StandaloneFileBrowser/Plugins/Ookii.Dialogs.dll differ diff --git a/Assets/StandaloneFileBrowser/Plugins/Ookii.Dialogs.dll.meta b/Assets/StandaloneFileBrowser/Plugins/Ookii.Dialogs.dll.meta new file mode 100644 index 00000000..13e560df --- /dev/null +++ b/Assets/StandaloneFileBrowser/Plugins/Ookii.Dialogs.dll.meta @@ -0,0 +1,145 @@ +fileFormatVersion: 2 +guid: e60958662eed5413d86143a0a69b731e +timeCreated: 1491979494 +licenseType: Pro +PluginImporter: + serializedVersion: 2 + iconMap: {} + executionOrder: {} + isPreloaded: 0 + isOverridable: 0 + platformData: + data: + first: + '': Any + second: + enabled: 0 + settings: + Exclude Android: 1 + Exclude Editor: 0 + Exclude Linux: 1 + Exclude Linux64: 1 + Exclude LinuxUniversal: 1 + Exclude OSXIntel: 1 + Exclude OSXIntel64: 1 + Exclude OSXUniversal: 1 + Exclude WebGL: 1 + Exclude Win: 0 + Exclude Win64: 0 + Exclude iOS: 1 + data: + first: + '': Editor + second: + enabled: 0 + settings: + CPU: AnyCPU + OS: AnyOS + data: + first: + Android: Android + second: + enabled: 0 + settings: + CPU: ARMv7 + data: + first: + Any: + second: + enabled: 0 + settings: {} + data: + first: + Editor: Editor + second: + enabled: 1 + settings: + DefaultValueInitialized: true + data: + first: + Facebook: Win + second: + enabled: 0 + settings: + CPU: AnyCPU + data: + first: + Facebook: Win64 + second: + enabled: 0 + settings: + CPU: AnyCPU + data: + first: + Standalone: Linux + second: + enabled: 0 + settings: + CPU: None + data: + first: + Standalone: Linux64 + second: + enabled: 0 + settings: + CPU: None + data: + first: + Standalone: LinuxUniversal + second: + enabled: 0 + settings: + CPU: None + data: + first: + Standalone: OSXIntel + second: + enabled: 0 + settings: + CPU: None + data: + first: + Standalone: OSXIntel64 + second: + enabled: 0 + settings: + CPU: None + data: + first: + Standalone: OSXUniversal + second: + enabled: 0 + settings: + CPU: None + data: + first: + Standalone: Win + second: + enabled: 1 + settings: + CPU: AnyCPU + data: + first: + Standalone: Win64 + second: + enabled: 1 + settings: + CPU: AnyCPU + data: + first: + Windows Store Apps: WindowsStoreApps + second: + enabled: 0 + settings: + CPU: AnyCPU + data: + first: + iPhone: iOS + second: + enabled: 0 + settings: + CompileFlags: + FrameworkDependencies: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/StandaloneFileBrowser/Plugins/StandaloneFileBrowser.bundle.meta b/Assets/StandaloneFileBrowser/Plugins/StandaloneFileBrowser.bundle.meta new file mode 100644 index 00000000..c7bdac63 --- /dev/null +++ b/Assets/StandaloneFileBrowser/Plugins/StandaloneFileBrowser.bundle.meta @@ -0,0 +1,40 @@ +fileFormatVersion: 2 +guid: 110fdfb459db4fc448a2ccd37e200fa4 +folderAsset: yes +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + isPreloaded: 0 + isOverridable: 0 + platformData: + - first: + Any: + second: + enabled: 0 + settings: {} + - first: + Editor: Editor + second: + enabled: 1 + settings: + DefaultValueInitialized: true + - first: + Standalone: OSXIntel + second: + enabled: 1 + settings: {} + - first: + Standalone: OSXIntel64 + second: + enabled: 1 + settings: {} + - first: + Standalone: OSXUniversal + second: + enabled: 1 + settings: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/StandaloneFileBrowser/Plugins/StandaloneFileBrowser.bundle/Contents.meta b/Assets/StandaloneFileBrowser/Plugins/StandaloneFileBrowser.bundle/Contents.meta new file mode 100644 index 00000000..37ed2fc1 --- /dev/null +++ b/Assets/StandaloneFileBrowser/Plugins/StandaloneFileBrowser.bundle/Contents.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 996ea0b0fb9804844ba9595686ee3e7a +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/StandaloneFileBrowser/Plugins/StandaloneFileBrowser.bundle/Contents/Info.plist b/Assets/StandaloneFileBrowser/Plugins/StandaloneFileBrowser.bundle/Contents/Info.plist new file mode 100644 index 00000000..52c479cc --- /dev/null +++ b/Assets/StandaloneFileBrowser/Plugins/StandaloneFileBrowser.bundle/Contents/Info.plist @@ -0,0 +1,46 @@ + + + + + BuildMachineOSBuild + 18A391 + CFBundleDevelopmentRegion + English + CFBundleExecutable + StandaloneFileBrowser + CFBundleIdentifier + com.gkngkc.sfb + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + StandaloneFileBrowser + CFBundlePackageType + BNDL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleSupportedPlatforms + + MacOSX + + CFBundleVersion + 1.0 + CSResourcesFileMapped + + DTCompiler + com.apple.compilers.llvm.clang.1_0 + DTPlatformBuild + 10A255 + DTPlatformVersion + GM + DTSDKBuild + 18A384 + DTSDKName + macosx10.14 + DTXcode + 1000 + DTXcodeBuild + 10A255 + + diff --git a/Assets/StandaloneFileBrowser/Plugins/StandaloneFileBrowser.bundle/Contents/Info.plist.meta b/Assets/StandaloneFileBrowser/Plugins/StandaloneFileBrowser.bundle/Contents/Info.plist.meta new file mode 100644 index 00000000..22c9f907 --- /dev/null +++ b/Assets/StandaloneFileBrowser/Plugins/StandaloneFileBrowser.bundle/Contents/Info.plist.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: ce685769797f44046afa3e567860c94c +timeCreated: 1505756861 +licenseType: Pro +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/StandaloneFileBrowser/Plugins/StandaloneFileBrowser.bundle/Contents/MacOS.meta b/Assets/StandaloneFileBrowser/Plugins/StandaloneFileBrowser.bundle/Contents/MacOS.meta new file mode 100644 index 00000000..bd2d540b --- /dev/null +++ b/Assets/StandaloneFileBrowser/Plugins/StandaloneFileBrowser.bundle/Contents/MacOS.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: a5a66f5db020f344c9327188aec2c060 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/StandaloneFileBrowser/Plugins/StandaloneFileBrowser.bundle/Contents/MacOS/StandaloneFileBrowser b/Assets/StandaloneFileBrowser/Plugins/StandaloneFileBrowser.bundle/Contents/MacOS/StandaloneFileBrowser new file mode 100644 index 00000000..caf2b686 Binary files /dev/null and b/Assets/StandaloneFileBrowser/Plugins/StandaloneFileBrowser.bundle/Contents/MacOS/StandaloneFileBrowser differ diff --git a/Assets/StandaloneFileBrowser/Plugins/StandaloneFileBrowser.bundle/Contents/MacOS/StandaloneFileBrowser.meta b/Assets/StandaloneFileBrowser/Plugins/StandaloneFileBrowser.bundle/Contents/MacOS/StandaloneFileBrowser.meta new file mode 100644 index 00000000..a298a74a --- /dev/null +++ b/Assets/StandaloneFileBrowser/Plugins/StandaloneFileBrowser.bundle/Contents/MacOS/StandaloneFileBrowser.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: ddf122e0e89124ce78aacfeecb3ec554 +timeCreated: 1508179371 +licenseType: Pro +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/StandaloneFileBrowser/Plugins/StandaloneFileBrowser.jslib b/Assets/StandaloneFileBrowser/Plugins/StandaloneFileBrowser.jslib new file mode 100644 index 00000000..1198f38c --- /dev/null +++ b/Assets/StandaloneFileBrowser/Plugins/StandaloneFileBrowser.jslib @@ -0,0 +1,90 @@ +var StandaloneFileBrowserWebGLPlugin = { + // Open file. + // gameObjectNamePtr: Unique GameObject name. Required for calling back unity with SendMessage. + // methodNamePtr: Callback method name on given GameObject. + // filter: Filter files. Example filters: + // Match all image files: "image/*" + // Match all video files: "video/*" + // Match all audio files: "audio/*" + // Custom: ".plist, .xml, .yaml" + // multiselect: Allows multiple file selection + UploadFile: function(gameObjectNamePtr, methodNamePtr, filterPtr, multiselect) { + gameObjectName = Pointer_stringify(gameObjectNamePtr); + methodName = Pointer_stringify(methodNamePtr); + filter = Pointer_stringify(filterPtr); + + // Delete if element exist + var fileInput = document.getElementById(gameObjectName) + if (fileInput) { + document.body.removeChild(fileInput); + } + + fileInput = document.createElement('input'); + fileInput.setAttribute('id', gameObjectName); + fileInput.setAttribute('type', 'file'); + fileInput.setAttribute('style','display:none;'); + fileInput.setAttribute('style','visibility:hidden;'); + if (multiselect) { + fileInput.setAttribute('multiple', ''); + } + if (filter) { + fileInput.setAttribute('accept', filter); + } + fileInput.onclick = function (event) { + // File dialog opened + this.value = null; + }; + fileInput.onchange = function (event) { + // multiselect works + var urls = []; + for (var i = 0; i < event.target.files.length; i++) { + urls.push(URL.createObjectURL(event.target.files[i])); + } + // File selected + SendMessage(gameObjectName, methodName, urls.join()); + + // Remove after file selected + document.body.removeChild(fileInput); + } + document.body.appendChild(fileInput); + + document.onmouseup = function() { + fileInput.click(); + document.onmouseup = null; + } + }, + + // Save file + // DownloadFile method does not open SaveFileDialog like standalone builds, its just allows user to download file + // gameObjectNamePtr: Unique GameObject name. Required for calling back unity with SendMessage. + // methodNamePtr: Callback method name on given GameObject. + // filenamePtr: Filename with extension + // byteArray: byte[] + // byteArraySize: byte[].Length + DownloadFile: function(gameObjectNamePtr, methodNamePtr, filenamePtr, byteArray, byteArraySize) { + gameObjectName = Pointer_stringify(gameObjectNamePtr); + methodName = Pointer_stringify(methodNamePtr); + filename = Pointer_stringify(filenamePtr); + + var bytes = new Uint8Array(byteArraySize); + for (var i = 0; i < byteArraySize; i++) { + bytes[i] = HEAPU8[byteArray + i]; + } + + var downloader = window.document.createElement('a'); + downloader.setAttribute('id', gameObjectName); + downloader.href = window.URL.createObjectURL(new Blob([bytes], { type: 'application/octet-stream' })); + downloader.download = filename; + document.body.appendChild(downloader); + + document.onmouseup = function() { + downloader.click(); + document.body.removeChild(downloader); + document.onmouseup = null; + + SendMessage(gameObjectName, methodName); + } + } +}; + +mergeInto(LibraryManager.library, StandaloneFileBrowserWebGLPlugin); \ No newline at end of file diff --git a/Assets/StandaloneFileBrowser/Plugins/StandaloneFileBrowser.jslib.meta b/Assets/StandaloneFileBrowser/Plugins/StandaloneFileBrowser.jslib.meta new file mode 100644 index 00000000..ac86a87c --- /dev/null +++ b/Assets/StandaloneFileBrowser/Plugins/StandaloneFileBrowser.jslib.meta @@ -0,0 +1,99 @@ +fileFormatVersion: 2 +guid: 265aaf20a6d564e0fb00a9c4a7a9c300 +PluginImporter: + externalObjects: {} + serializedVersion: 2 + iconMap: {} + executionOrder: {} + defineConstraints: [] + isPreloaded: 0 + isOverridable: 0 + isExplicitlyReferenced: 0 + validateReferences: 1 + platformData: + - first: + '': Any + second: + enabled: 0 + settings: + Exclude Editor: 1 + Exclude Linux: 1 + Exclude Linux64: 1 + Exclude LinuxUniversal: 1 + Exclude OSXUniversal: 1 + Exclude Win: 1 + Exclude Win64: 1 + - first: + Any: + second: + enabled: 0 + settings: {} + - first: + Editor: Editor + second: + enabled: 0 + settings: + CPU: AnyCPU + DefaultValueInitialized: true + OS: AnyOS + - first: + Facebook: WebGL + second: + enabled: 1 + settings: {} + - first: + Facebook: Win + second: + enabled: 0 + settings: + CPU: AnyCPU + - first: + Facebook: Win64 + second: + enabled: 0 + settings: + CPU: AnyCPU + - first: + Standalone: Linux + second: + enabled: 0 + settings: + CPU: x86 + - first: + Standalone: Linux64 + second: + enabled: 0 + settings: + CPU: AnyCPU + - first: + Standalone: LinuxUniversal + second: + enabled: 0 + settings: + CPU: None + - first: + Standalone: OSXUniversal + second: + enabled: 0 + settings: + CPU: AnyCPU + - first: + Standalone: Win + second: + enabled: 0 + settings: + CPU: AnyCPU + - first: + Standalone: Win64 + second: + enabled: 0 + settings: + CPU: AnyCPU + - first: + WebGL: WebGL + second: + enabled: 1 + settings: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/StandaloneFileBrowser/Plugins/System.Windows.Forms.dll b/Assets/StandaloneFileBrowser/Plugins/System.Windows.Forms.dll new file mode 100644 index 00000000..f6d84752 Binary files /dev/null and b/Assets/StandaloneFileBrowser/Plugins/System.Windows.Forms.dll differ diff --git a/Assets/StandaloneFileBrowser/Plugins/System.Windows.Forms.dll.meta b/Assets/StandaloneFileBrowser/Plugins/System.Windows.Forms.dll.meta new file mode 100644 index 00000000..f757441d --- /dev/null +++ b/Assets/StandaloneFileBrowser/Plugins/System.Windows.Forms.dll.meta @@ -0,0 +1,145 @@ +fileFormatVersion: 2 +guid: 7d459a96865cc4aaab657012c6dc4833 +timeCreated: 1491979494 +licenseType: Pro +PluginImporter: + serializedVersion: 2 + iconMap: {} + executionOrder: {} + isPreloaded: 0 + isOverridable: 0 + platformData: + data: + first: + '': Any + second: + enabled: 0 + settings: + Exclude Android: 1 + Exclude Editor: 0 + Exclude Linux: 1 + Exclude Linux64: 1 + Exclude LinuxUniversal: 1 + Exclude OSXIntel: 1 + Exclude OSXIntel64: 1 + Exclude OSXUniversal: 1 + Exclude WebGL: 1 + Exclude Win: 0 + Exclude Win64: 0 + Exclude iOS: 1 + data: + first: + '': Editor + second: + enabled: 0 + settings: + CPU: AnyCPU + OS: AnyOS + data: + first: + Android: Android + second: + enabled: 0 + settings: + CPU: ARMv7 + data: + first: + Any: + second: + enabled: 0 + settings: {} + data: + first: + Editor: Editor + second: + enabled: 1 + settings: + DefaultValueInitialized: true + data: + first: + Facebook: Win + second: + enabled: 0 + settings: + CPU: AnyCPU + data: + first: + Facebook: Win64 + second: + enabled: 0 + settings: + CPU: AnyCPU + data: + first: + Standalone: Linux + second: + enabled: 0 + settings: + CPU: None + data: + first: + Standalone: Linux64 + second: + enabled: 0 + settings: + CPU: None + data: + first: + Standalone: LinuxUniversal + second: + enabled: 0 + settings: + CPU: None + data: + first: + Standalone: OSXIntel + second: + enabled: 0 + settings: + CPU: None + data: + first: + Standalone: OSXIntel64 + second: + enabled: 0 + settings: + CPU: None + data: + first: + Standalone: OSXUniversal + second: + enabled: 0 + settings: + CPU: None + data: + first: + Standalone: Win + second: + enabled: 1 + settings: + CPU: AnyCPU + data: + first: + Standalone: Win64 + second: + enabled: 1 + settings: + CPU: AnyCPU + data: + first: + Windows Store Apps: WindowsStoreApps + second: + enabled: 0 + settings: + CPU: AnyCPU + data: + first: + iPhone: iOS + second: + enabled: 0 + settings: + CompileFlags: + FrameworkDependencies: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/StandaloneFileBrowser/Sample.meta b/Assets/StandaloneFileBrowser/Sample.meta new file mode 100644 index 00000000..3c5d69fe --- /dev/null +++ b/Assets/StandaloneFileBrowser/Sample.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 435c74f62ab57b448adeeb37cbc0f96b +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/StandaloneFileBrowser/Sample/BasicSample.cs b/Assets/StandaloneFileBrowser/Sample/BasicSample.cs new file mode 100644 index 00000000..77e427f5 --- /dev/null +++ b/Assets/StandaloneFileBrowser/Sample/BasicSample.cs @@ -0,0 +1,119 @@ +using System.Collections; +using UnityEngine; +using SFB; + +public class BasicSample : MonoBehaviour { + private string _path; + + void OnGUI() { + var guiScale = new Vector3(Screen.width / 800.0f, Screen.height / 600.0f, 1.0f); + GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, guiScale); + + GUILayout.Space(20); + GUILayout.BeginHorizontal(); + GUILayout.Space(20); + GUILayout.BeginVertical(); + + // Open File Samples + + if (GUILayout.Button("Open File")) { + WriteResult(StandaloneFileBrowser.OpenFilePanel("Open File", "", "", false)); + } + GUILayout.Space(5); + if (GUILayout.Button("Open File Async")) { + StandaloneFileBrowser.OpenFilePanelAsync("Open File", "", "", false, (string[] paths) => { WriteResult(paths); }); + } + GUILayout.Space(5); + if (GUILayout.Button("Open File Multiple")) { + WriteResult(StandaloneFileBrowser.OpenFilePanel("Open File", "", "", true)); + } + GUILayout.Space(5); + if (GUILayout.Button("Open File Extension")) { + WriteResult(StandaloneFileBrowser.OpenFilePanel("Open File", "", "txt", true)); + } + GUILayout.Space(5); + if (GUILayout.Button("Open File Directory")) { + WriteResult(StandaloneFileBrowser.OpenFilePanel("Open File", Application.dataPath, "", true)); + } + GUILayout.Space(5); + if (GUILayout.Button("Open File Filter")) { + var extensions = new [] { + new ExtensionFilter("Image Files", "png", "jpg", "jpeg" ), + new ExtensionFilter("Sound Files", "mp3", "wav" ), + new ExtensionFilter("All Files", "*" ), + }; + WriteResult(StandaloneFileBrowser.OpenFilePanel("Open File", "", extensions, true)); + } + + GUILayout.Space(15); + + // Open Folder Samples + + if (GUILayout.Button("Open Folder")) { + var paths = StandaloneFileBrowser.OpenFolderPanel("Select Folder", "", true); + WriteResult(paths); + } + GUILayout.Space(5); + if (GUILayout.Button("Open Folder Async")) { + StandaloneFileBrowser.OpenFolderPanelAsync("Select Folder", "", true, (string[] paths) => { WriteResult(paths); }); + } + GUILayout.Space(5); + if (GUILayout.Button("Open Folder Directory")) { + var paths = StandaloneFileBrowser.OpenFolderPanel("Select Folder", Application.dataPath, true); + WriteResult(paths); + } + + GUILayout.Space(15); + + // Save File Samples + + if (GUILayout.Button("Save File")) { + _path = StandaloneFileBrowser.SaveFilePanel("Save File", "", "", ""); + } + GUILayout.Space(5); + if (GUILayout.Button("Save File Async")) { + StandaloneFileBrowser.SaveFilePanelAsync("Save File", "", "", "", (string path) => { WriteResult(path); }); + } + GUILayout.Space(5); + if (GUILayout.Button("Save File Default Name")) { + _path = StandaloneFileBrowser.SaveFilePanel("Save File", "", "MySaveFile", ""); + } + GUILayout.Space(5); + if (GUILayout.Button("Save File Default Name Ext")) { + _path = StandaloneFileBrowser.SaveFilePanel("Save File", "", "MySaveFile", "dat"); + } + GUILayout.Space(5); + if (GUILayout.Button("Save File Directory")) { + _path = StandaloneFileBrowser.SaveFilePanel("Save File", Application.dataPath, "", ""); + } + GUILayout.Space(5); + if (GUILayout.Button("Save File Filter")) { + // Multiple save extension filters with more than one extension support. + var extensionList = new [] { + new ExtensionFilter("Binary", "bin"), + new ExtensionFilter("Text", "txt"), + }; + _path = StandaloneFileBrowser.SaveFilePanel("Save File", "", "MySaveFile", extensionList); + } + + GUILayout.EndVertical(); + GUILayout.Space(20); + GUILayout.Label(_path); + GUILayout.EndHorizontal(); + } + + public void WriteResult(string[] paths) { + if (paths.Length == 0) { + return; + } + + _path = ""; + foreach (var p in paths) { + _path += p + "\n"; + } + } + + public void WriteResult(string path) { + _path = path; + } +} diff --git a/Assets/StandaloneFileBrowser/Sample/BasicSample.cs.meta b/Assets/StandaloneFileBrowser/Sample/BasicSample.cs.meta new file mode 100644 index 00000000..9319b42e --- /dev/null +++ b/Assets/StandaloneFileBrowser/Sample/BasicSample.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 5148400295519405d82bb0fa65246ea2 +timeCreated: 1483902788 +licenseType: Pro +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/StandaloneFileBrowser/Sample/BasicSampleScene.unity b/Assets/StandaloneFileBrowser/Sample/BasicSampleScene.unity new file mode 100644 index 00000000..75c88fa7 --- /dev/null +++ b/Assets/StandaloneFileBrowser/Sample/BasicSampleScene.unity @@ -0,0 +1,248 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!29 &1 +OcclusionCullingSettings: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_OcclusionBakeSettings: + smallestOccluder: 5 + smallestHole: 0.25 + backfaceThreshold: 100 + m_SceneGUID: 00000000000000000000000000000000 + m_OcclusionCullingData: {fileID: 0} +--- !u!104 &2 +RenderSettings: + m_ObjectHideFlags: 0 + serializedVersion: 9 + m_Fog: 0 + m_FogColor: {r: 0.5, g: 0.5, b: 0.5, a: 1} + m_FogMode: 3 + m_FogDensity: 0.01 + m_LinearFogStart: 0 + m_LinearFogEnd: 300 + m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1} + m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1} + m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1} + m_AmbientIntensity: 1 + m_AmbientMode: 3 + m_SubtractiveShadowColor: {r: 0.42, g: 0.478, b: 0.627, a: 1} + m_SkyboxMaterial: {fileID: 0} + m_HaloStrength: 0.5 + m_FlareStrength: 1 + m_FlareFadeSpeed: 3 + m_HaloTexture: {fileID: 0} + m_SpotCookie: {fileID: 10001, guid: 0000000000000000e000000000000000, type: 0} + m_DefaultReflectionMode: 0 + m_DefaultReflectionResolution: 128 + m_ReflectionBounces: 1 + m_ReflectionIntensity: 1 + m_CustomReflection: {fileID: 0} + m_Sun: {fileID: 0} + m_IndirectSpecularColor: {r: 0, g: 0, b: 0, a: 1} + m_UseRadianceAmbientProbe: 0 +--- !u!157 &3 +LightmapSettings: + m_ObjectHideFlags: 0 + serializedVersion: 11 + m_GIWorkflowMode: 1 + m_GISettings: + serializedVersion: 2 + m_BounceScale: 1 + m_IndirectOutputScale: 1 + m_AlbedoBoost: 1 + m_TemporalCoherenceThreshold: 1 + m_EnvironmentLightingMode: 0 + m_EnableBakedLightmaps: 0 + m_EnableRealtimeLightmaps: 0 + m_LightmapEditorSettings: + serializedVersion: 10 + m_Resolution: 2 + m_BakeResolution: 40 + m_AtlasSize: 1024 + m_AO: 0 + m_AOMaxDistance: 1 + m_CompAOExponent: 1 + m_CompAOExponentDirect: 0 + m_Padding: 2 + m_LightmapParameters: {fileID: 0} + m_LightmapsBakeMode: 1 + m_TextureCompression: 1 + m_FinalGather: 0 + m_FinalGatherFiltering: 1 + m_FinalGatherRayCount: 256 + m_ReflectionCompression: 2 + m_MixedBakeMode: 1 + m_BakeBackend: 0 + m_PVRSampling: 1 + m_PVRDirectSampleCount: 32 + m_PVRSampleCount: 500 + m_PVRBounces: 2 + m_PVRFilterTypeDirect: 0 + m_PVRFilterTypeIndirect: 0 + m_PVRFilterTypeAO: 0 + m_PVRFilteringMode: 0 + m_PVRCulling: 1 + m_PVRFilteringGaussRadiusDirect: 1 + m_PVRFilteringGaussRadiusIndirect: 5 + m_PVRFilteringGaussRadiusAO: 2 + m_PVRFilteringAtrousPositionSigmaDirect: 0.5 + m_PVRFilteringAtrousPositionSigmaIndirect: 2 + m_PVRFilteringAtrousPositionSigmaAO: 1 + m_ShowResolutionOverlay: 1 + m_LightingDataAsset: {fileID: 0} + m_UseShadowmask: 0 +--- !u!196 &4 +NavMeshSettings: + serializedVersion: 2 + m_ObjectHideFlags: 0 + m_BuildSettings: + serializedVersion: 2 + agentTypeID: 0 + agentRadius: 0.5 + agentHeight: 2 + agentSlope: 45 + agentClimb: 0.4 + ledgeDropHeight: 0 + maxJumpAcrossDistance: 0 + minRegionArea: 2 + manualCellSize: 0 + cellSize: 0.16666667 + manualTileSize: 0 + tileSize: 256 + accuratePlacement: 0 + debug: + m_Flags: 0 + m_NavMeshData: {fileID: 0} +--- !u!1 &382763637 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 382763642} + - component: {fileID: 382763641} + - component: {fileID: 382763640} + - component: {fileID: 382763639} + - component: {fileID: 382763638} + m_Layer: 0 + m_Name: Main Camera + m_TagString: MainCamera + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!81 &382763638 +AudioListener: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 382763637} + m_Enabled: 1 +--- !u!124 &382763639 +Behaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 382763637} + m_Enabled: 1 +--- !u!92 &382763640 +Behaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 382763637} + m_Enabled: 1 +--- !u!20 &382763641 +Camera: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 382763637} + m_Enabled: 1 + serializedVersion: 2 + m_ClearFlags: 1 + m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0} + m_projectionMatrixMode: 1 + m_SensorSize: {x: 36, y: 24} + m_LensShift: {x: 0, y: 0} + m_FocalLength: 50 + m_NormalizedViewPortRect: + serializedVersion: 2 + x: 0 + y: 0 + width: 1 + height: 1 + near clip plane: 0.3 + far clip plane: 1000 + field of view: 60 + orthographic: 1 + orthographic size: 5 + m_Depth: -1 + m_CullingMask: + serializedVersion: 2 + m_Bits: 4294967295 + m_RenderingPath: -1 + m_TargetTexture: {fileID: 0} + m_TargetDisplay: 0 + m_TargetEye: 3 + m_HDR: 0 + m_AllowMSAA: 1 + m_AllowDynamicResolution: 0 + m_ForceIntoRT: 0 + m_OcclusionCulling: 1 + m_StereoConvergence: 10 + m_StereoSeparation: 0.022 +--- !u!4 &382763642 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 382763637} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: -10} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &986049433 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 986049435} + - component: {fileID: 986049434} + m_Layer: 0 + m_Name: GameObject + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &986049434 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 986049433} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 5148400295519405d82bb0fa65246ea2, type: 3} + m_Name: + m_EditorClassIdentifier: +--- !u!4 &986049435 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 986049433} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 1 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} diff --git a/Assets/StandaloneFileBrowser/Sample/BasicSampleScene.unity.meta b/Assets/StandaloneFileBrowser/Sample/BasicSampleScene.unity.meta new file mode 100644 index 00000000..e0125355 --- /dev/null +++ b/Assets/StandaloneFileBrowser/Sample/BasicSampleScene.unity.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: d97280fe82b874466870f709c3315d41 +timeCreated: 1483902786 +licenseType: Pro +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/StandaloneFileBrowser/Sample/CanvasSampleOpenFileImage.cs b/Assets/StandaloneFileBrowser/Sample/CanvasSampleOpenFileImage.cs new file mode 100644 index 00000000..4fb1351b --- /dev/null +++ b/Assets/StandaloneFileBrowser/Sample/CanvasSampleOpenFileImage.cs @@ -0,0 +1,53 @@ +using System.Text; +using System.Collections; +using System.Collections.Generic; +using System.Runtime.InteropServices; +using UnityEngine; +using UnityEngine.UI; +using UnityEngine.EventSystems; +using SFB; + +[RequireComponent(typeof(Button))] +public class CanvasSampleOpenFileImage : MonoBehaviour, IPointerDownHandler { + public RawImage output; + +#if UNITY_WEBGL && !UNITY_EDITOR + // + // WebGL + // + [DllImport("__Internal")] + private static extern void UploadFile(string gameObjectName, string methodName, string filter, bool multiple); + + public void OnPointerDown(PointerEventData eventData) { + UploadFile(gameObject.name, "OnFileUpload", ".png, .jpg", false); + } + + // Called from browser + public void OnFileUpload(string url) { + StartCoroutine(OutputRoutine(url)); + } +#else + // + // Standalone platforms & editor + // + public void OnPointerDown(PointerEventData eventData) { } + + void Start() { + var button = GetComponent