Esempio n. 1
0
        /// <summary>
        /// Draws the preview area
        /// </summary>
        /// <param name="rect">The area of the preview window</param>
        /// <param name="backgroundStyle">The default GUIStyle used for preview windows</param>
        public override void OnPreviewGUI(Rect rect, GUIStyle backgroundStyle)
        {
            _cameraAngle = PreviewRenderUtilityHelpers.DragToAngles(_cameraAngle, rect);

            if (Event.current.type == EventType.Repaint)
            {
                GUI.DrawTexture(rect, ((Texture3D)serializedObject.targetObject).RenderTexture3DPreview(rect, _cameraAngle, 6.5f /*TODO : Find distance with fov and boundingsphere, when non uniform size will be supported*/, _samplingIterations, _density), ScaleMode.StretchToFill, true);
            }
        }
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (CheckIfObjectType(property))
            {
                if (ShowField)
                {
                    Rect rect = position;
                    rect.height = EditorGUIUtility.singleLineHeight;
                    EditorGUI.ObjectField(rect, property, typeof(Texture3D));
                    position.y += EditorGUIUtility.singleLineHeight;
                }

                if (!CheckIfNull(property))
                {
                    if (CheckIfTexture3D(property))
                    {
                        if (Event.current.type == EventType.Layout)
                        {
                            return;
                        }

                        position.y += EditorGUIUtility.singleLineHeight;

                        int  size     = ComputePreviewSize((int)position.x * 2);
                        Rect drawArea = position;
                        drawArea.width  = size;
                        drawArea.height = drawArea.width;
                        drawArea.x     += position.width * 0.5f - drawArea.width * 0.5f;

                        _cameraAngle = PreviewRenderUtilityHelpers.DragToAngles(_cameraAngle, drawArea);
                        if (Event.current.type == EventType.Repaint)
                        {
                            GUI.Box(drawArea, ((Texture3D)property.objectReferenceValue).RenderTexture3DPreview(drawArea, _cameraAngle, 6.5f /*TODO : Find distance with fov and boundingsphere, when non uniform size will be supported*/, _samplingIterations, _density));
                        }

                        Rect rect = drawArea;
                        rect.y     += drawArea.height;
                        rect.height = EditorGUIUtility.singleLineHeight;
                        rect.width  = 100; // TODO : not use magic numbers
                        if (GUI.Button(rect, "Reset Camera", EditorStyles.miniButton))
                        {
                            ResetPreviewCameraAngle();
                        }
                        rect.x    += rect.width;
                        rect.width = 60; // TODO : not use magic numbers
                        EditorGUI.LabelField(rect, "Quality :");
                        rect.x += rect.width;
                        _samplingIterations = EditorGUI.IntPopup(rect, _samplingIterations, new[]
                        {
                            "16",
                            "32",
                            "64",
                            "128",
                            "256",
                            "512"
                        }, new[]
                        {
                            16,
                            32,
                            64,
                            128,
                            256,
                            512
                        });
                        rect.x    += rect.width;
                        rect.width = 60; // TODO : not use magic numbers
                        EditorGUI.LabelField(rect, "Density :");
                        rect.x    += rect.width;
                        rect.width = drawArea.width - 280; // TODO : not use magic numbers
                        _density   = EditorGUI.Slider(rect, _density, 0, 5);
                    }
                    else
                    {
                        EditorGUI.LabelField(position, Texture3DPreviewDrawer._notObjectOrTexture3DString, EditorStyles.boldLabel);
                    }
                }
                else
                {
                    EditorGUI.LabelField(position, "Texture3D field is empty.", EditorStyles.centeredGreyMiniLabel);
                }
            }
            else
            {
                EditorGUI.LabelField(position, Texture3DPreviewDrawer._notObjectOrTexture3DString, EditorStyles.boldLabel);
            }
        }