Ejemplo n.º 1
0
        /// <summary>
        /// Load the raw file at the path given
        /// </summary>
        /// <param name="path">Full path of the raw file</param>
        public void LoadRawFile(string path, GaiaConstants.RawByteOrder byteOrder, ref GaiaConstants.RawBitDepth bitDepth, ref int resolution)
        {
            if (string.IsNullOrEmpty(path))
            {
                Debug.LogError("Must supply a valid path. Raw load Aborted!");
            }

            //Clear out the old
            Reset();

            //Load up the new
            m_featureName = Path.GetFileNameWithoutExtension(path);
            m_scanMap     = new HeightMap();
            m_scanMap.LoadFromRawFile(path, byteOrder, ref bitDepth, ref resolution);
            if (m_scanMap.HasData() == false)
            {
                Debug.LogError("Unable to load raw file. Raw load aborted.");
                return;
            }

            m_scanWidth      = m_scanMap.Width();
            m_scanDepth      = m_scanMap.Depth();
            m_scanHeight     = m_scanWidth / 2;
            m_scanResolution = 0.1f;
            m_scanBounds     = new Bounds(transform.position, new Vector3(m_scanWidth * m_scanResolution, m_scanWidth * m_scanResolution * 0.4f, m_scanDepth * m_scanResolution));
            m_baseLevel      = m_scanMap.GetBaseLevel();

            MeshFilter mf = GetComponent <MeshFilter>();

            if (mf == null)
            {
                mf           = gameObject.AddComponent <MeshFilter>();
                mf.hideFlags = HideFlags.HideInInspector;
            }
            MeshRenderer mr = GetComponent <MeshRenderer>();

            if (mr == null)
            {
                mr           = gameObject.AddComponent <MeshRenderer>();
                mr.hideFlags = HideFlags.HideInInspector;
            }
            mf.mesh = Gaia.Utils.CreateMesh(m_scanMap.Heights(), m_scanBounds.size);
            if (m_previewMaterial != null)
            {
                m_previewMaterial.hideFlags = HideFlags.HideInInspector;
                mr.sharedMaterial           = m_previewMaterial;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Load the raw file at the path given
        /// </summary>
        /// <param name="path">Full path of the raw file</param>
        public void LoadRawFile(string path, GaiaConstants.RawByteOrder byteOrder, ref GaiaConstants.RawBitDepth bitDepth, ref int resolution)
        {
            if (string.IsNullOrEmpty(path))
            {
                Debug.LogError("Must supply a valid path. Raw load Aborted!");
            }

            //Clear out the old
            ResetData();

            //Load up the new
            m_scanMap = new HeightMap();
            m_scanMap.LoadFromRawFile(path, byteOrder, ref bitDepth, ref resolution);
            if (m_scanMap.HasData() == false)
            {
                Debug.LogError("Unable to load raw file. Raw load aborted.");
                return;
            }

            m_scanWidth      = m_scanMap.Width();
            m_scanDepth      = m_scanMap.Depth();
            m_scanHeight     = m_scanWidth / 2;
            m_scanResolution = 0.1f;
            m_scanBounds     = new Bounds(GetPosition(gameObject, null), new Vector3(m_scanWidth * m_scanResolution, m_scanWidth * m_scanResolution, m_scanDepth * m_scanResolution));
            //m_baseLevel = m_scanMap.GetBaseLevel();

            SetOrCreateMeshComponents();
            m_meshFilter.sharedMesh = GaiaUtils.CreateMesh(m_scanMap.Heights(), m_scanBounds.size);
            if (m_previewMaterial != null)
            {
                m_previewMaterial.hideFlags   = HideFlags.HideInInspector;
                m_meshRenderer.sharedMaterial = m_previewMaterial;
            }

            gameObject.transform.position = m_scanBounds.center;
            m_exportFileName = path.Substring(path.LastIndexOf('/'));
            m_boundsSet      = true;
        }
Ejemplo n.º 3
0
        private void GlobalPanel(bool helpEnabled)
        {
            //Text intro
            GUILayout.BeginVertical("Gaia Scanner", m_boxStyle);
            GUILayout.Space(20);
            EditorGUILayout.LabelField("The Gaia Scanner allows you to create new stamps from Windows R16, Windows 16 bit RAW, Mac 16 bit RAW, Terrains, Textures or Meshes. Just drag and drop the file or object onto the area below to scan it.", m_wrapStyle);
            GUILayout.EndVertical();

            DropAreaGUI();

            bool originalGUIState = GUI.enabled;

            if (!m_scanner.m_objectScanned)
            {
                GUI.enabled = false;
            }

            //DrawDefaultInspector();
            GUILayout.BeginVertical("Setup", m_boxStyle);
            GUILayout.Space(20);
            m_editorUtils.Heading("GlobalSettings");
            m_scanner.m_previewMaterial = (Material)m_editorUtils.ObjectField("PreviewMaterial", m_scanner.m_previewMaterial, typeof(Material), false, helpEnabled);
            EditorGUILayout.BeginHorizontal();
            m_scanner.m_exportFolder = m_editorUtils.TextField("ExportPath", m_scanner.m_exportFolder);

            if (m_editorUtils.Button("ExportDirectoryOpen", GUILayout.Width(80)))
            {
                string path = EditorUtility.SaveFolderPanel(m_editorUtils.GetTextValue("ExportDirectoryWindowTitle"), GaiaDirectories.GetUserStampDirectory(), GaiaDirectories.SCANNER_EXPORT_DIRECTORY.Replace("/", ""));
                if (path.Contains(Application.dataPath))
                {
                    m_scanner.m_exportFolder = GaiaDirectories.GetPathStartingAtAssetsFolder(path);
                }
                else
                {
                    EditorUtility.DisplayDialog("Path outside the Assets folder", "The selected path needs to be inside the Assets folder of the project. Please select an appropiate path.", "OK");
                    m_scanner.m_exportFolder = GaiaDirectories.GetScannerExportDirectory();
                }
            }
            EditorGUILayout.EndHorizontal();
            m_editorUtils.InlineHelp("ExportPath", helpEnabled);
            m_scanner.m_exportFileName = m_editorUtils.TextField("ExportFilename", m_scanner.m_exportFileName, helpEnabled);

            float oldBaseLevel = m_scanner.m_baseLevel;

            m_scanner.m_baseLevel = m_editorUtils.Slider("BaseLevel", m_scanner.m_baseLevel, 0f, 1f, helpEnabled);
            if (oldBaseLevel != m_scanner.m_baseLevel)
            {
                SceneView.lastActiveSceneView.Repaint();
            }
            EditorGUILayout.Space(10f);
            m_editorUtils.Heading("ObjectTypeSettings");
            if (m_scanner.m_scannerObjectType == ScannerObjectType.Mesh)
            {
                m_scanner.m_scanResolution = m_editorUtils.Slider("ScanResolution", m_scanner.m_scanResolution, 0.0001f, 1f, helpEnabled);
                if (m_scanner.m_lastScanResolution != m_scanner.m_scanResolution)
                {
                    if (m_editorUtils.Button("RefreshScan"))
                    {
                        m_scanner.LoadGameObject(m_scanner.m_lastScannedMesh);
                    }
                }
            }
            if (m_scanner.m_scannerObjectType == ScannerObjectType.Raw)
            {
                //Drop Options section
                GUILayout.BeginHorizontal();
                {
                    EditorGUILayout.PrefixLabel(BYTE_ORDER_LABEL);
                    EditorGUI.BeginChangeCheck();
                    {
                        m_rawByteOrder = (GaiaConstants.RawByteOrder)GUILayout.Toolbar((int)m_rawByteOrder, new string[] { "IBM PC", "Macintosh" });
                    }
                    if (EditorGUI.EndChangeCheck())
                    {
                        ReloadRawFile();
                    }
                }
                GUILayout.EndHorizontal();
                m_editorUtils.InlineHelp("RawFileByteOrder", helpEnabled);

                EditorGUI.BeginChangeCheck();
                {
                    m_rawBitDepth = (GaiaConstants.RawBitDepth)EditorGUILayout.Popup(BIT_DEPTH_LABEL, (int)m_rawBitDepth, BIT_DEPTHS_LABELS);
                    m_editorUtils.InlineHelp("RawFileBitDepth", helpEnabled);
                }
                if (EditorGUI.EndChangeCheck())
                {
                    ReloadRawFile();
                }
                GUILayout.BeginVertical();
                if (m_showRawInfo)
                {
                    EditorGUILayout.HelpBox("Assumed " + (m_rawBitDepth == GaiaConstants.RawBitDepth.Sixteen ? "16-bit" : "8-bit") + " RAW " + m_assumedRawRes + " x " + m_assumedRawRes, MessageType.Info);
                }
                if (m_showBitDepthWarning)
                {
                    EditorGUILayout.HelpBox(m_editorUtils.GetTextValue("8BitWarning"), MessageType.Warning);
                }
                GUILayout.EndVertical();
            }
            EditorGUILayout.Space(10f);



            m_editorUtils.Heading("ExportSettings");
            //m_scanner.m_textureExportResolution = (GaiaConstants.GaiaProWaterReflectionsQuality) EditorGUILayout.EnumPopup(new GUIContent("Export Resolution", "Sets the export resolution of the texture generated"), m_scanner.m_textureExportResolution);
            m_scanner.m_normalize         = m_editorUtils.Toggle("Normalize", m_scanner.m_normalize, helpEnabled);
            m_scanner.m_exportTextureAlso = m_editorUtils.Toggle("ExportPNG", m_scanner.m_exportTextureAlso, helpEnabled);
            //m_scanner.m_exportBytesData = m_editorUtils.Toggle("ExportBytesData", m_scanner.m_exportBytesData, helpEnabled);

            GUILayout.EndVertical();

            //Terraform section
            GUILayout.BeginVertical("Scanner Controller", m_boxStyle);
            GUILayout.Space(20);
            if (!string.IsNullOrEmpty(m_infoMessage))
            {
                EditorGUILayout.HelpBox(m_infoMessage, MessageType.Info);
            }
            if (m_scanner.m_scanMap == null)
            {
                EditorGUILayout.HelpBox(m_editorUtils.GetTextValue("NoScanDataInfo"), MessageType.Info);
                GUI.enabled = false;
            }
            GUILayout.BeginHorizontal();
            Color normalBGColor = GUI.backgroundColor;

            if (m_settings == null)
            {
                m_settings = GaiaUtils.GetGaiaSettings();
            }

            GUI.backgroundColor = m_settings.GetActionButtonColor();
            if (m_editorUtils.Button("SaveScan"))
            {
                string path = m_scanner.SaveScan();
                AssetDatabase.Refresh();
                path += ".exr";
                Object exportedTexture = AssetDatabase.LoadAssetAtPath(path, typeof(Object));
                if (exportedTexture != null)
                {
                    m_infoMessage = "Scan exported to: " + path;
                    Debug.Log(m_infoMessage);
                    EditorGUIUtility.PingObject(exportedTexture);
                }
            }
            GUI.backgroundColor = normalBGColor;
            GUI.enabled         = true;
            if (m_editorUtils.Button("Clear"))
            {
                m_scanner.Clear();
            }

            GUILayout.EndHorizontal();
            GUILayout.Space(5);
            GUILayout.EndVertical();
            GUILayout.Space(5f);

            m_showRawInfo         = m_assumedRawRes > 0;
            m_showBitDepthWarning = m_rawBitDepth == GaiaConstants.RawBitDepth.Eight;

            GUI.enabled = originalGUIState;
        }