/// <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, EditorStyles.helpBox, _cameraAngle, 6.5f /*TODO : Find distance with fov and boundingsphere, when non uniform size will be supported*/, _samplingIterations, _density), ScaleMode.StretchToFill, true); } }
/// <summary> /// Fills drawer area /// </summary> /// <param name="position">The area of the drawer</param> /// <param name="property">The drawn object</param> /// <param name="label">The "made readable" name of the object (as would be seen in the Insprector)</param> 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; } 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.DrawTexture(drawArea, ((Texture3D)property.objectReferenceValue).RenderTexture3DPreview(drawArea, EditorStyles.helpBox, _cameraAngle, 6.5f /*TODO : Find distance with fov and boundingsphere, when non uniform size will be supported*/, _samplingIterations, _density), ScaleMode.StretchToFill, true); } 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 string[] { "16", "32", "64", "128", "256", "512" }, new int[] { 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, label.text, _notObjectOrTexture3DString, EditorStyles.boldLabel); } } else { EditorGUI.LabelField(position, label.text, "Texture3D field is empty.", EditorStyles.boldLabel); } } else { EditorGUI.LabelField(position, label.text, _notObjectOrTexture3DString, EditorStyles.boldLabel); } }