void SetProperties(VCMaterial mat) { if (m_SelectedMatter != null) { m_BumpStrengthUI.sliderValue = mat.m_BumpStrength; m_SpecStrengthUI.sliderValue = mat.m_SpecularStrength * 0.5f; m_SpecPowerUI.sliderValue = (mat.m_SpecularPower - 1) / 254f; m_SpecColorUI.color = mat.m_SpecularColor; m_EmsvColorUI.color = mat.m_EmissiveColor; m_TileUI.sliderValue = (mat.m_Tile - 0.25f) / 3.75f; if (m_DiffuseTex != null) { Texture2D.Destroy(m_DiffuseTex); } m_DiffuseTex = Texture2D.Instantiate(mat.m_DiffuseTex as Texture2D) as Texture2D; if (m_BumpTex != null) { Texture2D.Destroy(m_BumpTex); } m_BumpTex = Texture2D.Instantiate(mat.m_BumpTex as Texture2D) as Texture2D; m_DiffuseMat.mainTexture = m_DiffuseTex; m_BumpMat.mainTexture = m_BumpTex; m_TempMaterial.m_DiffuseData = new byte [mat.m_DiffuseData.Length]; m_TempMaterial.m_BumpData = new byte [mat.m_BumpData.Length]; System.Array.Copy(mat.m_DiffuseData, m_TempMaterial.m_DiffuseData, mat.m_DiffuseData.Length); System.Array.Copy(mat.m_BumpData, m_TempMaterial.m_BumpData, mat.m_BumpData.Length); m_TempMaterial.CalcGUID(); } }
void OnDestroy() { if (m_DiffuseMat != null) { Material.Destroy(m_DiffuseMat); m_DiffuseMat = null; } if (m_BumpMat != null) { Material.Destroy(m_BumpMat); m_BumpMat = null; } if (m_DiffuseTex != null) { Texture2D.Destroy(m_DiffuseTex); m_DiffuseTex = null; } if (m_BumpTex != null) { Texture2D.Destroy(m_BumpTex); m_BumpTex = null; } if (m_TempMaterial != null) { m_TempMaterial.Destroy(); m_TempMaterial = null; } }
private void ResetMaterial() { if (m_TempMaterial != null) { m_TempMaterial.Destroy(); m_TempMaterial = null; } m_TempMaterial = new VCMaterial(); }
public void MaterialListFocusOnSelected() { m_TempSelected = VCEditor.SelectedMaterial; if (m_MatterPopupList.selection != "All".ToLocalizationString() && VCEditor.SelectedMaterial != null) { m_MatterPopupList.selection = VCUtils.Capital(VCConfig.s_Matters[VCEditor.SelectedMaterial.m_MatterId].Name, true); } Invoke("MaterialListFocusOnSelectedInvoke", 0.2f); }
public override void Redo() { VCMaterial old_mat = VCEditor.s_Scene.m_IsoData.m_Materials[m_Index]; VCMaterial new_mat = VCEAssetMgr.GetMaterial(m_NewMat); ulong old_guid = (old_mat == null) ? (0) : (old_mat.m_Guid); ulong new_guid = (new_mat == null) ? (0) : (new_mat.m_Guid); if (old_guid != new_guid) { VCEditor.s_Scene.m_IsoData.m_Materials[m_Index] = new_mat; VCEditor.s_Scene.GenerateIsoMat(); } }
public void Reset(VCMaterial target) { ResetMaterial(); InitMatterList(); if (m_DiffuseMat == null) { m_DiffuseMat = Material.Instantiate(m_UITextureSrcMat) as Material; m_DiffuseMapUI.material = m_DiffuseMat; } if (m_BumpMat == null) { m_BumpMat = Material.Instantiate(m_UITextureSrcMat) as Material; m_BumpMapUI.material = m_BumpMat; } m_Target = target; m_TitleUI.text = m_Target == null ? "NEW MATERIAL".ToLocalizationString() : "EDIT MATERIAL".ToLocalizationString(); m_OKUI.text = m_Target == null ? "Create".ToLocalizationString() : "Apply".ToLocalizationString(); if (m_Target != null) { m_UIDUI.text = target.GUIDString; m_NameUI.text = target.m_Name; m_MatterUI.selection = VCUtils.Capital(VCConfig.s_Matters[target.m_MatterId].Name, true); m_CustomizeUI.isChecked = !target.m_UseDefault; QuerySelectedMatter(); if (!m_CustomizeUI.isChecked) { SetDefaultProperties(); } else { SetProperties(target); } } else { m_UIDUI.text = "0000000000000000"; m_CustomizeUI.isChecked = false; if (VCEditor.Instance.m_UI.m_MatterPopupList.selection != "All".ToLocalizationString()) { m_MatterUI.selection = VCEditor.Instance.m_UI.m_MatterPopupList.selection; } else { m_MatterUI.selection = m_MatterUI.items[0]; } m_NameUI.text = "New Material".ToLocalizationString(); QuerySelectedMatter(); SetDefaultProperties(); } Update(); }
public static bool AddMaterialFromTemp(ulong guid) { if (s_TempMaterials.ContainsKey(guid)) { VCMaterial vcmat = s_TempMaterials[guid]; s_TempMaterials.Remove(guid); s_Materials.Add(guid, vcmat); return(CreateMaterialDataFile(vcmat)); } else { return(false); } }
public int QueryMaterialIndex(VCMaterial vcmat) { if (vcmat == null) { return(-1); } // Find the same material for (int i = 0; i < MAT_ARR_CNT; ++i) { if (m_Materials[i] != null && vcmat.m_Guid == m_Materials[i].m_Guid) { return(i); } } return(-1); }
public void GenerateIsoMat() { if (VCMatGenerator.Instance != null) { VCMaterial[] _matlist = null; if (m_IsoData != null && m_IsoData.m_Materials != null) { _matlist = m_IsoData.m_Materials; } else { _matlist = new VCMaterial [VCIsoData.MAT_ARR_CNT]; } VCMatGenerator.Instance.GenMeshMaterial(_matlist, true); } }
// Create material data file public static bool CreateMaterialDataFile(VCMaterial vcmat) { try { byte[] buffer = vcmat.Export(); ulong guid = CRC64.Compute(buffer); string sguid = guid.ToString("X").PadLeft(16, '0'); FileStream fs = new FileStream(VCConfig.s_MaterialPath + sguid + VCConfig.s_MaterialFileExt, FileMode.Create, FileAccess.ReadWrite); fs.Write(buffer, 0, buffer.Length); fs.Close(); return(true); } catch (Exception) { return(false); } }
// Generate an icon for a VCMaterial public void GenMaterialIcon(VCMaterial vcmat) { m_IconGenGroup.SetActive(true); if (vcmat.m_Icon == null) { vcmat.m_Icon = new RenderTexture(64, 64, 24, RenderTextureFormat.ARGB32); } m_IconCubeRenderer.material.mainTexture = vcmat.m_DiffuseTex; m_IconCubeRenderer.material.SetTexture("_BumpMap", vcmat.m_BumpTex); m_IconGenCamera.targetTexture = vcmat.m_Icon; Color oldambient = RenderSettings.ambientLight; RenderSettings.ambientLight = Color.black; m_IconGenCamera.Render(); RenderSettings.ambientLight = oldambient; m_IconGenGroup.SetActive(false); }
void CreateAsNew() { VCMaterial newmat = new VCMaterial(); newmat.Import(m_TempMaterial.Export()); VCEAssetMgr.s_Materials.Add(newmat.m_Guid, newmat); if (!VCEAssetMgr.CreateMaterialDataFile(newmat)) { VCEMsgBox.Show(VCEMsgBoxType.MATERIAL_NOT_SAVED); } VCEditor.SelectedMaterial = newmat; VCEditor.Instance.m_UI.m_MaterialList.RefreshMaterialListThenFocusOnSelected(); VCEditor.SelectedMaterial = newmat; Reset(newmat); VCEStatusBar.ShowText("New Material".ToLocalizationString() + " [" + newmat.m_Name + "]", 6f, true); }
// Query a voxel type for a specified VCMaterial public int QueryVoxelType(VCMaterial vcmat) { if (vcmat == null) { return(-1); } // Find the same material for (int i = 0; i < MAT_ARR_CNT; ++i) { if (m_Materials[i] != null && vcmat.m_Guid == m_Materials[i].m_Guid) { return(i); } } // Find a null position for (int i = 0; i < MAT_ARR_CNT; ++i) { if (m_Materials[i] == null) { return(i); } } // Full, find not used int[] used_count = new int [MAT_ARR_CNT]; for (int i = 0; i < MAT_ARR_CNT; ++i) { used_count[i] = 0; } foreach (KeyValuePair <int, VCVoxel> kvp in m_Voxels) { used_count[(int)(kvp.Value.Type)]++; } for (int i = 0; i < MAT_ARR_CNT; ++i) { if (used_count[i] == 0) { return(i); } } // Unfortunately, no material avaliable return(-1); }
public void ListFocusOn(VCMaterial focus_item) { if (focus_item != null) { Vector3 pos = m_Panel.transform.localPosition; foreach (GameObject itemgo in m_AssetItems) { VCEUIMaterialItem item = itemgo.GetComponent <VCEUIMaterialItem>(); if (item.m_Material == focus_item) { pos.y = m_OriginY - itemgo.transform.localPosition.y - 8; } } m_Panel.transform.localPosition = pos; } else { RepositionList(); } }
// Read file and add material work private static void LoadMaterialFromList(string[] files) { foreach (string s in files) { VCMaterial vcmat = new VCMaterial(); try { FileStream fs = new FileStream(s, FileMode.Open, FileAccess.ReadWrite); byte[] buffer = new byte [(int)(fs.Length)]; fs.Read(buffer, 0, (int)(fs.Length)); fs.Close(); vcmat.Import(buffer); // Check file valid string guid_from_filename = new FileInfo(s).Name.ToUpper(); string filename_should_be = (vcmat.GUIDString + VCConfig.s_MaterialFileExt).ToUpper(); if (guid_from_filename != filename_should_be) { throw new Exception("The name and GUID doesn't match!"); } } catch (Exception e) { vcmat.Destroy(); Debug.LogError("Load material [" + s + "] failed ! \r\n" + e.ToString()); continue; } if (s_Materials.ContainsKey(vcmat.m_Guid)) { s_Materials[vcmat.m_Guid].Destroy(); s_Materials[vcmat.m_Guid] = vcmat; } else { s_Materials.Add(vcmat.m_Guid, vcmat); } } }
// Send some default materials if user's material count is 0 private static void SendDefaultMaterials() { foreach (KeyValuePair <int, VCMatterInfo> kvp in VCConfig.s_Matters) { VCMatterInfo matter = kvp.Value; VCMaterial vcmat = new VCMaterial(); vcmat.m_Name = "Default".ToLocalizationString() + " " + matter.Name; vcmat.m_MatterId = matter.ItemIndex; vcmat.m_UseDefault = true; try { byte[] buffer = vcmat.Export(); ulong guid = CRC64.Compute(buffer); string sguid = guid.ToString("X").PadLeft(16, '0'); FileStream fs = new FileStream(VCConfig.s_MaterialPath + sguid + VCConfig.s_MaterialFileExt, FileMode.Create, FileAccess.ReadWrite); fs.Write(buffer, 0, buffer.Length); fs.Close(); vcmat.Import(buffer); } catch (Exception e) { vcmat.Destroy(); Debug.LogError("Save material [" + vcmat.m_Name + "] failed ! \r\n" + e.ToString()); continue; } if (s_Materials.ContainsKey(vcmat.m_Guid)) { s_Materials[vcmat.m_Guid].Destroy(); s_Materials[vcmat.m_Guid] = vcmat; } else { s_Materials.Add(vcmat.m_Guid, vcmat); } } }
public void OnDelClick() { s_CurrentDelMat = m_Material; VCEMsgBox.Show(VCEMsgBoxType.MATERIAL_DEL_QUERY); }
public bool Import(byte[] buffer, VCIsoOption options) { if (buffer == null) { return(false); } Reset(options); int min_iso_size = 48; if (buffer.Length < min_iso_size) { return(false); } try { using (MemoryStream ms_iso = new MemoryStream(buffer)) { BinaryReader r = new BinaryReader(ms_iso); // Header string check_str = r.ReadString(); // r, string if (check_str != "VCISO") { r.Close(); return(false); } int l = 0; m_HeadInfo.Version = r.ReadInt32(); // r, int m_HeadInfo.Category = (EVCCategory)(r.ReadInt32()); // r, int string author = ""; if (m_HeadInfo.Version >= 0x02020000) { author = r.ReadString(); } m_HeadInfo.Name = r.ReadString(); // r, string m_HeadInfo.Desc = r.ReadString(); // r, string string remarks = ""; if (m_HeadInfo.Version >= 0x02020000) { remarks = r.ReadString(); } m_HeadInfo.xSize = r.ReadInt32(); // r, int m_HeadInfo.ySize = r.ReadInt32(); // r, int m_HeadInfo.zSize = r.ReadInt32(); // r, int l = r.ReadInt32(); // r, int m_HeadInfo.IconTex = r.ReadBytes(l); // r, byte[] m_HeadInfo.EnsureIconTexValid(); m_HeadInfo.Author = ""; m_HeadInfo.Remarks = ""; if (m_HeadInfo.Version >= 0x02020000) { for (int c = 0; c < author.Length; ++c) { m_HeadInfo.Author += (char)(author[c] ^ (char)(0xAC)); } for (int c = 0; c < remarks.Length; ++c) { m_HeadInfo.Remarks += (char)(remarks[c] ^ (char)(0xAC)); } } switch (m_HeadInfo.Version) { case 0x02000000: case 0x02010000: case 0x02020000: case 0x02020001: case 0x02030001: { // Counts int mat_cnt = r.ReadInt32(); // r, int int dcl_cnt = 0; if (m_HeadInfo.Version >= 0x02010000) { dcl_cnt = r.ReadInt32(); // r, int } int com_cnt = r.ReadInt32(); // r, int int vxl_cnt = r.ReadInt32(); // r, int int clr_cnt = r.ReadInt32(); // r, int // Materials for (int i = 0; i < mat_cnt; ++i) { ulong guid = r.ReadUInt64(); // r, ulong; if (guid != 0) { l = r.ReadInt32(); // r, int byte[] mat_buffer = r.ReadBytes(l); // r, byte[] // Option // If for editor, find mats in VCEAssetMgr for the iso, or create mats in VCEAssetMgr. if (m_Options.ForEditor) { if (VCEAssetMgr.s_Materials.ContainsKey(guid)) { m_Materials[i] = VCEAssetMgr.s_Materials[guid]; } else { VCMaterial vcmat = new VCMaterial(); vcmat.Import(mat_buffer); //VCEAssetMgr.s_TempMaterials.Add(guid, vcmat); VCEAssetMgr.s_TempMaterials[guid] = vcmat; //log:lz-2016.05.17 直接Add会报错,key可能已存在 m_Materials[i] = vcmat; } } // If not for editor, these materials are belong to the iso. else { m_Materials[i] = new VCMaterial(); m_Materials[i].Import(mat_buffer); } } } // Decals for (int i = 0; i < dcl_cnt; ++i) { ulong guid = r.ReadUInt64(); // r, ulong; if (guid != 0) { l = r.ReadInt32(); // r, int byte[] dcl_buffer = r.ReadBytes(l); // r, byte[] // Option // If for editor, find decals in VCEAssetMgr for the iso, or create decals in VCEAssetMgr. if (m_Options.ForEditor) { if (VCEAssetMgr.s_Decals.ContainsKey(guid)) { m_DecalAssets[i] = VCEAssetMgr.s_Decals[guid]; } else { VCDecalAsset vcdcl = new VCDecalAsset(); vcdcl.Import(dcl_buffer); //VCEAssetMgr.s_TempDecals.Add(guid, vcdcl); //log:lz-2016.05.17 直接Add会报错,key可能已存在 VCEAssetMgr.s_TempDecals[guid] = vcdcl; m_DecalAssets[i] = vcdcl; } } // If not for editor, these decals are belong to the iso. else { m_DecalAssets[i] = new VCDecalAsset(); m_DecalAssets[i].Import(dcl_buffer); } } } // Read compressed data // using (MemoryStream ms_zip = new MemoryStream()) { l = r.ReadInt32(); // r, int ms_zip.Write(r.ReadBytes(l), 0, l); // r, byte[] zip, byte[] // Decompress data // using (MemoryStream ms_unzip = new MemoryStream()) { ms_zip.Seek((long)(0), SeekOrigin.Begin); IonicZlib.Decompress(ms_zip, ms_unzip); ms_unzip.Seek((long)(0), SeekOrigin.Begin); BinaryReader r_unzip = new BinaryReader(ms_unzip); // Components for (int i = 0; i < com_cnt; ++i) { l = r_unzip.ReadInt32(); // unzip, int if (l > 0) { byte[] com_buffer = r_unzip.ReadBytes(l); // unzip, byte[] EVCComponent com_type = (EVCComponent)(r_unzip.ReadInt32()); // unzip, int VCComponentData cdata = VCComponentData.Create(com_type, com_buffer); if (cdata != null) { cdata.m_CurrIso = this; m_Components.Add(cdata); } } } if (m_HeadInfo.Version >= 0x02020001) { ulong sig = r_unzip.ReadUInt64(); if (m_HeadInfo.HeadSignature != sig) { Debug.LogError("Check sig failed"); return(false); } } // Voxels for (int i = 0; i < vxl_cnt; ++i) { int key = r_unzip.ReadInt32(); // unzip, int ushort val = r_unzip.ReadUInt16(); // unzip, ushort m_Voxels[key] = (VCVoxel)(val); } // Colors for (int i = 0; i < clr_cnt; ++i) { int key = r_unzip.ReadInt32(); // unzip, int Color32 val; val.r = r_unzip.ReadByte(); // unzip, byte val.g = r_unzip.ReadByte(); // unzip, byte val.b = r_unzip.ReadByte(); // unzip, byte val.a = r_unzip.ReadByte(); // unzip, byte m_Colors.Add(key, val); } r_unzip.Close(); } } break; } default: return(false); } r.Close(); return(true); } } catch (Exception e) { Debug.LogError("Importing ISO Failed :" + e.ToString()); return(false); } }
private void MaterialListFocusOnSelectedInvoke() { VCEditor.SelectedMaterial = m_TempSelected; m_TempSelected = null; ListFocusOn(VCEditor.SelectedMaterial); }
public void ShowWindow(VCMaterial target) { m_Window.SetActive(true); Reset(target); Update(); }
// Update is called once per frame void Update() { if (!VCEditor.DocumentOpen()) { return; } if (VCEditor.Instance.m_UI.m_MaterialTab.isChecked) { if (VCEditor.SelectedMaterial != null) { if (m_lastMat != VCEditor.SelectedMaterial) { m_UIGroup.SetActive(true); m_MaterialIconTexture.mainTexture = VCEditor.SelectedMaterial.m_DiffuseTex; m_MaterialIcon.material = m_MaterialIconTexture; m_IconMask.GetComponent <UITweener>().Reset(); m_IconMask.GetComponent <UITweener>().Play(true); m_GlowIcon.Reset(); m_GlowIcon.Play(true); m_MaterialIcon.gameObject.SetActive(true); m_ComponentIcon.gameObject.SetActive(false); m_ColorIcon.gameObject.SetActive(false); m_ItemNameLabel.text = VCEditor.SelectedMaterial.m_Name; m_IconMask.SetActive(true); } } else { m_UIGroup.SetActive(false); } m_lastMat = VCEditor.SelectedMaterial; m_lastDecal = null; m_lastPart = null; m_lastColor = Color.clear; } else if (VCEditor.Instance.m_UI.m_DecalTab.isChecked) { if (VCEditor.SelectedDecal != null) { if (m_lastDecal != VCEditor.SelectedDecal) { m_UIGroup.SetActive(true); m_MaterialIconTexture.mainTexture = VCEditor.SelectedDecal.m_Tex; m_MaterialIcon.material = m_MaterialIconTexture; m_IconMask.GetComponent <UITweener>().Reset(); m_IconMask.GetComponent <UITweener>().Play(true); m_GlowIcon.Reset(); m_GlowIcon.Play(true); m_MaterialIcon.gameObject.SetActive(true); m_ComponentIcon.gameObject.SetActive(false); m_ColorIcon.gameObject.SetActive(false); m_ItemNameLabel.text = "1 " + "decal".ToLocalizationString() + " [999999](UID = " + VCEditor.SelectedDecal.GUIDString + ")[-]"; m_IconMask.SetActive(true); } } else { m_UIGroup.SetActive(false); } m_lastDecal = VCEditor.SelectedDecal; m_lastMat = null; m_lastPart = null; m_lastColor = Color.clear; } else if (VCEditor.Instance.m_UI.m_PartTab.isChecked) { if (VCEditor.SelectedPart != null) { if (m_lastPart != VCEditor.SelectedPart) { m_ComponentIcon.spriteName = VCEditor.SelectedPart.m_IconPath.Split(',')[0]; m_IconMask.GetComponent <UITweener>().Reset(); m_IconMask.GetComponent <UITweener>().Play(true); m_GlowIcon.Reset(); m_GlowIcon.Play(true); m_ComponentIcon.gameObject.SetActive(true); m_UIGroup.SetActive(true); m_MaterialIcon.gameObject.SetActive(false); m_ColorIcon.gameObject.SetActive(false); m_ItemNameLabel.text = VCEditor.SelectedPart.m_Name; m_IconMask.SetActive(true); } } else { m_UIGroup.SetActive(false); } m_lastMat = null; m_lastDecal = null; m_lastPart = VCEditor.SelectedPart; m_lastColor = Color.clear; } else if (VCEditor.Instance.m_UI.m_PaintTab.isChecked) { Color color = VCEditor.SelectedColor; color.a = 1; m_ColorIcon.color = color; if (m_lastColor != color) { m_IconMask.GetComponent <UITweener>().Reset(); m_IconMask.GetComponent <UITweener>().Play(true); m_GlowIcon.Reset(); m_GlowIcon.Play(true); } m_ColorIcon.gameObject.SetActive(true); m_UIGroup.SetActive(true); m_MaterialIcon.gameObject.SetActive(false); m_ComponentIcon.gameObject.SetActive(false); m_ItemNameLabel.text = "RGB ( " + (color.r * 100).ToString("0") + "%, " + (color.g * 100).ToString("0") + "%, " + (color.b * 100).ToString("0") + "% )"; m_IconMask.SetActive(true); m_lastMat = null; m_lastDecal = null; m_lastPart = null; m_lastColor = color; } else { m_UIGroup.SetActive(false); m_lastMat = null; m_lastDecal = null; m_lastPart = null; m_lastColor = Color.clear; } }
// Generate a mesh material for VOXEL CREATIONs public ulong GenMeshMaterial(VCMaterial[] mat_list, bool bForEditor = false) { // Prepare textures RenderTexture diff_rtex = null; RenderTexture bump_rtex = null; Texture2D prop_tex = null; Vector4 Setting1 = new Vector4(1.0F / ((float)VCIsoData.MAT_COL_CNT), 1.0F / ((float)VCIsoData.MAT_ROW_CNT), 1.0F, VCMaterial.TEX_RESOLUTION); // Get mat_list's hash code ulong _guid = VCMaterial.CalcMatGroupHash(mat_list); // For editor, VCEditor.s_Scene if (bForEditor) { if (!VCEditor.DocumentOpen()) { return(0); } diff_rtex = VCEditor.s_Scene.m_TempIsoMat.m_DiffTex; bump_rtex = VCEditor.s_Scene.m_TempIsoMat.m_BumpTex; prop_tex = VCEditor.s_Scene.m_TempIsoMat.m_PropertyTex; Material final_mat = VCEditor.s_Scene.m_TempIsoMat.m_EditorMat; final_mat.SetTexture("_DiffuseTex", diff_rtex); final_mat.SetTexture("_BumpTex", bump_rtex); final_mat.SetTexture("_PropertyTex", prop_tex); final_mat.SetVector("_Settings1", Setting1); } // Not for editor, VCMatManagr else { if (VCMatManager.Instance == null) { return(0); } // Has material group in VCMatManager (hash exist) if (VCMatManager.Instance.m_mapMaterials.ContainsKey(_guid)) { // Fetch textures diff_rtex = VCMatManager.Instance.m_mapDiffuseTexs[_guid]; bump_rtex = VCMatManager.Instance.m_mapBumpTexs[_guid]; prop_tex = VCMatManager.Instance.m_mapPropertyTexs[_guid]; } // A new material group (hash not exist) else { // Create new textures diff_rtex = new RenderTexture(VCIsoData.MAT_COL_CNT * VCMaterial.TEX_RESOLUTION, VCIsoData.MAT_ROW_CNT * VCMaterial.TEX_RESOLUTION, 0, RenderTextureFormat.ARGB32); bump_rtex = new RenderTexture(VCIsoData.MAT_COL_CNT * VCMaterial.TEX_RESOLUTION, VCIsoData.MAT_ROW_CNT * VCMaterial.TEX_RESOLUTION, 0, RenderTextureFormat.ARGB32); prop_tex = new Texture2D(VCIsoData.MAT_ARR_CNT, 4, TextureFormat.ARGB32, false, false); diff_rtex.anisoLevel = 4; diff_rtex.filterMode = FilterMode.Trilinear; diff_rtex.useMipMap = true; diff_rtex.wrapMode = TextureWrapMode.Repeat; bump_rtex.anisoLevel = 4; bump_rtex.filterMode = FilterMode.Trilinear; bump_rtex.useMipMap = true; bump_rtex.wrapMode = TextureWrapMode.Repeat; prop_tex.anisoLevel = 0; prop_tex.filterMode = FilterMode.Point; // Set u3d material params Material final_mat = Material.Instantiate(m_TemplateMeshMat) as Material; final_mat.name = "VCMat #" + _guid.ToString("X").PadLeft(16, '0'); final_mat.SetTexture("_DiffuseTex", diff_rtex); final_mat.SetTexture("_BumpTex", bump_rtex); final_mat.SetTexture("_PropertyTex", prop_tex); final_mat.SetVector("_Settings1", Setting1); // Add to VCMatManager VCMatManager.Instance.m_mapMaterials.Add(_guid, final_mat); VCMatManager.Instance.m_mapDiffuseTexs.Add(_guid, diff_rtex); VCMatManager.Instance.m_mapBumpTexs.Add(_guid, bump_rtex); VCMatManager.Instance.m_mapPropertyTexs.Add(_guid, prop_tex); VCMatManager.Instance.m_mapMatRefCounters.Add(_guid, 0); } } // // Render Material's Texture // m_TexturePlanesGroup.gameObject.SetActive(true); // Gen diffuse for (int i = 0; i < mat_list.Length && i < VCIsoData.MAT_ARR_CNT; ++i) { // Set diffuses on each piece of plane. if (mat_list[i] != null) { m_PlaneRenderers[i].material.SetTexture("_MainTex", mat_list[i].m_DiffuseTex); } else { m_PlaneRenderers[i].material.SetTexture("_MainTex", Resources.Load(VCMaterial.s_BlankDiffuseRes) as Texture2D); } } m_TextureCam.targetTexture = diff_rtex; m_TextureCam.Render(); // render diffuse // Gen bump for (int i = 0; i < mat_list.Length && i < VCIsoData.MAT_ARR_CNT; ++i) { // Set normal maps on each piece of plane. if (mat_list[i] != null) { m_PlaneRenderers[i].material.SetTexture("_MainTex", mat_list[i].m_BumpTex); } else { m_PlaneRenderers[i].material.SetTexture("_MainTex", Resources.Load(VCMaterial.s_BlankBumpRes) as Texture2D); } } m_TextureCam.targetTexture = bump_rtex; m_TextureCam.Render(); // render bump // Gen properties for (int i = 0; i < mat_list.Length && i < VCIsoData.MAT_ARR_CNT; ++i) { // Property texture has several property track in y direction // each track have n pixels (n = VCIsoData.MAT_ARR_CNT) in x direction, // each pixel represents the property or the combination of several properties for one material. if (mat_list[i] != null) { prop_tex.SetPixel(i, 0, mat_list[i].m_SpecularColor); prop_tex.SetPixel(i, 1, mat_list[i].m_EmissiveColor); prop_tex.SetPixel(i, 2, new Color(mat_list[i].m_BumpStrength, mat_list[i].m_SpecularStrength / 2, mat_list[i].m_SpecularPower / 255, 1)); prop_tex.SetPixel(i, 3, new Color(mat_list[i].m_Tile / 17, 0, 0, 1)); } else { prop_tex.SetPixel(i, 0, Color.black); prop_tex.SetPixel(i, 1, Color.black); prop_tex.SetPixel(i, 2, new Color(0, 0, 5 / 255, 1)); prop_tex.SetPixel(i, 3, new Color(1 / 17, 0, 0, 1)); } } prop_tex.Apply(); m_TextureCam.targetTexture = null; m_TexturePlanesGroup.gameObject.SetActive(false); return(_guid); }