void GetVoxelThumbnails(VoxelDefinition vd) { Texture2D top, side, bottom; top = side = bottom = null; if (vd.overrideMaterial && vd.texturesByMaterial) { Material mat = vd.overrideMaterialNonGeo; Texture2D tex = (Texture2D)mat.mainTexture; if (tex != null) { #if UNITY_EDITOR string path = UnityEditor.AssetDatabase.GetAssetPath(tex); if (!string.IsNullOrEmpty(path)) { UnityEditor.TextureImporter timp = UnityEditor.AssetImporter.GetAtPath(path) as UnityEditor.TextureImporter; if (timp != null && !timp.isReadable) { timp.isReadable = true; timp.SaveAndReimport(); } } #endif top = side = bottom = Instantiate <Texture2D> (tex); } } else { if (vd.renderType == RenderType.Custom && vd.textureSample != null) { top = side = bottom = vd.textureSample; } else { top = vd.textureTop; side = vd.textureSide; bottom = vd.textureBottom; } } if (top != null) { vd.textureThumbnailTop = Instantiate(top) as Texture2D; vd.textureThumbnailTop.hideFlags = HideFlags.DontSave; TextureTools.Scale(vd.textureThumbnailTop, 64, 64, FilterMode.Point); } if (side != null) { vd.textureThumbnailSide = Instantiate(side) as Texture2D; vd.textureThumbnailSide.hideFlags = HideFlags.DontSave; TextureTools.Scale(vd.textureThumbnailSide, 64, 64, FilterMode.Point); } if (bottom != null) { vd.textureThumbnailBottom = Instantiate(bottom) as Texture2D; vd.textureThumbnailBottom.hideFlags = HideFlags.DontSave; TextureTools.Scale(vd.textureThumbnailBottom, 64, 64, FilterMode.Point); } }
/// <summary> /// Private default texture resolver. Copies the given texture into the asset database. /// </summary> private static Texture2D DefaultTextureResolver(pxr.SdfAssetPath textureAssetPath, bool isNormalMap, SceneImportOptions options) { #if UNITY_EDITOR if (!File.Exists(textureAssetPath.GetResolvedPath())) { return(null); } string sourcePath = textureAssetPath.GetResolvedPath(); string destPath = Path.Combine(options.projectAssetPath, Path.GetFileName(sourcePath)); string assetPath = options.projectAssetPath + Path.GetFileName(sourcePath); string fullPath = destPath; if (fullPath.StartsWith("Assets/")) { fullPath = fullPath.Substring("Assets/".Length); } if (!File.Exists(destPath)) { UnityEditor.FileUtil.CopyFileOrDirectory(sourcePath, destPath); UnityEditor.AssetDatabase.ImportAsset(assetPath); UnityEditor.TextureImporter texImporter = (UnityEditor.TextureImporter)UnityEditor.AssetImporter.GetAtPath(assetPath); if (texImporter == null) { Debug.LogError("Failed to load asset: " + assetPath); return(null); } else { texImporter.isReadable = true; if (isNormalMap) { texImporter.convertToNormalmap = true; texImporter.textureType = UnityEditor.TextureImporterType.NormalMap; } UnityEditor.EditorUtility.SetDirty(texImporter); texImporter.SaveAndReimport(); } } return((Texture2D)UnityEditor.AssetDatabase.LoadAssetAtPath(assetPath, typeof(Texture2D))); #else return(null); #endif }
public override bool SetTextureOnMaterial(string fieldName, ImageData id, PlaytimePainter pntr) { // if (id == null) // return; Texture tex = id.CurrentTexture(); if (pntr.terrain != null) { if (fieldName.Contains(PainterDataAndConfig.terrainLight)) { FindMergingTerrain(pntr); if ((mergingTerrain != null) && (id != null)) { mergingTerrain.lightTexture = id.texture2D; } #if UNITY_EDITOR if (tex is Texture2D) { UnityEditor.TextureImporter timp = ((Texture2D)tex).GetTextureImporter(); if (timp != null) { bool needReimport = timp.WasClamped(); needReimport |= timp.HadNoMipmaps(); if (needReimport) { timp.SaveAndReimport(); } } } #endif Shader.SetGlobalTexture(PainterDataAndConfig.terrainLight, tex); return(true); } } return(false); }
public override bool SetTextureOnMaterial(string fieldName, ImageData id, PlaytimePainter painter) { Texture tex = id.CurrentTexture(); if (painter.terrain != null) { if (fieldName.Contains(PainterDataAndConfig.terrainTexture)) { int no = fieldName[0].CharToInt(); painter.terrain.SetSplashPrototypeTexture(id.texture2D, no); if (tex.GetType() != typeof(Texture2D)) { //else Debug.Log("Can only use Texture2D for Splat Prototypes. If using regular terrain may not see changes."); } else { #if UNITY_EDITOR UnityEditor.TextureImporter timp = ((Texture2D)tex).GetTextureImporter(); if (timp != null) { bool needReimport = timp.WasClamped(); needReimport |= timp.HadNoMipmaps(); if (needReimport) { timp.SaveAndReimport(); } } #endif } return(true); } } return(false); }