Exemplo n.º 1
0
        /// <summary>
        /// Save the stamp
        /// </summary>
        /// <returns>Path of saved stamp</returns>
        public string SaveScan()
        {
            if (m_scanMap == null || !m_scanMap.HasData())
            {
                Debug.LogWarning("Cant save scan as none has been loaded");
                return(null);
            }

            #if UNITY_EDITOR
            EditorUtility.DisplayProgressBar("Generating Texture", "Generating texture", 0.25f);
#endif

            //work with a copy for the export - don't want to normalize etc. source data
            HeightMap heightmapCopy = new HeightMap(m_scanMap);

            heightmapCopy.AddClamped(0f, m_baseLevel, 1f);

            if (m_normalize)
            {
                heightmapCopy.Normalise();
            }

            //Save preview
            string fullpath = m_exportFolder + "/" + m_exportFileName;
            GaiaUtils.CompressToMultiChannelFileImage(fullpath, heightmapCopy, heightmapCopy, heightmapCopy, null, TextureFormat.RGBAFloat, GaiaConstants.ImageFileType.Exr, m_baseLevel);

            GaiaUtils.SetDefaultStampImportSettings(fullpath + ".exr");


#if UNITY_EDITOR
            EditorUtility.DisplayProgressBar("Generating Texture", "Compressing texture", 0.5f);
#endif
            GaiaUtils.CompressToSingleChannelFileImage(heightmapCopy.Heights(), m_exportFolder, GaiaConstants.fmtHmTextureFormat, m_exportTextureAlso, false);

            //Save stamp
            if (m_exportBytesData)
            {
#if UNITY_EDITOR
                EditorUtility.DisplayProgressBar("Generating Texture", "Generating bytes data", 0.75f);
#endif
                m_exportFolder += ".bytes";
                float [] metaData = new float[5];
                metaData[0] = m_scanWidth;
                metaData[1] = m_scanDepth;
                metaData[2] = m_scanHeight;
                metaData[3] = m_scanResolution;
                metaData[4] = m_baseLevel;
                byte[] byteData = new byte[metaData.Length * 4];
                Buffer.BlockCopy(metaData, 0, byteData, 0, byteData.Length);
                heightmapCopy.SetMetaData(byteData);
                heightmapCopy.SaveToBinaryFile(m_exportFolder);
            }

#if UNITY_EDITOR
            EditorUtility.ClearProgressBar();
#endif

            return(fullpath);
        }