Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/modifiers/intern/MOD_subsurf.c')
-rw-r--r--source/blender/modifiers/intern/MOD_subsurf.c151
1 files changed, 151 insertions, 0 deletions
diff --git a/source/blender/modifiers/intern/MOD_subsurf.c b/source/blender/modifiers/intern/MOD_subsurf.c
index e054e3478ea..2b2f6893a2e 100644
--- a/source/blender/modifiers/intern/MOD_subsurf.c
+++ b/source/blender/modifiers/intern/MOD_subsurf.c
@@ -22,26 +22,40 @@
*/
#include <stddef.h>
+#include <string.h>
#include "MEM_guardedalloc.h"
#include "BLI_utildefines.h"
+#include "BLT_translation.h"
+
#include "DNA_mesh_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
+#include "DNA_screen_types.h"
+#include "BKE_context.h"
#include "BKE_scene.h"
+#include "BKE_screen.h"
#include "BKE_subdiv.h"
#include "BKE_subdiv_ccg.h"
#include "BKE_subdiv_deform.h"
#include "BKE_subdiv_mesh.h"
#include "BKE_subsurf.h"
+#include "UI_interface.h"
+#include "UI_resources.h"
+
+#include "RE_engine.h"
+
+#include "RNA_access.h"
+
#include "DEG_depsgraph.h"
#include "DEG_depsgraph_query.h"
#include "MOD_modifiertypes.h"
+#include "MOD_ui_common.h"
#include "intern/CCGSubSurf.h"
@@ -275,6 +289,142 @@ static void deformMatrices(ModifierData *md,
}
}
+#ifdef WITH_CYCLES
+static bool get_show_adaptive_options(const bContext *C, Panel *panel)
+{
+ /* Don't show adaptive options if cycles isn't the active engine. */
+ const struct RenderEngineType *engine_type = CTX_data_engine_type(C);
+ if (!STREQ(engine_type->idname, "CYCLES")) {
+ return false;
+ }
+
+ /* Only show adaptive options if this is the last modifier. */
+ PointerRNA md_ptr;
+ modifier_panel_get_property_pointers(C, panel, NULL, &md_ptr);
+ ModifierData *md = md_ptr.data;
+ if (md->next != NULL) {
+ return false;
+ }
+
+ /* Don't show adaptive options if the cycles experimental feature set is disabled. */
+ Scene *scene = CTX_data_scene(C);
+ PointerRNA scene_ptr;
+ RNA_id_pointer_create(&scene->id, &scene_ptr);
+ if (BKE_scene_uses_cycles(scene)) {
+ PointerRNA cycles_ptr = RNA_pointer_get(&scene_ptr, "cycles");
+ if (RNA_enum_get(&cycles_ptr, "feature_set") != 1) { /* EXPERIMENTAL */
+ return false;
+ }
+ }
+
+ return true;
+}
+#endif
+
+static void panel_draw(const bContext *C, Panel *panel)
+{
+ uiLayout *layout = panel->layout;
+
+ PointerRNA ptr;
+ PointerRNA ob_ptr;
+ modifier_panel_get_property_pointers(C, panel, &ob_ptr, &ptr);
+
+ /* Only test for adaptive subdivision if built with cycles. */
+ bool show_adaptive_options = false;
+ bool ob_use_adaptive_subdivision = false;
+ PointerRNA cycles_ptr = {NULL};
+ PointerRNA ob_cycles_ptr = {NULL};
+#ifdef WITH_CYCLES
+ PointerRNA scene_ptr;
+ Scene *scene = CTX_data_scene(C);
+ RNA_id_pointer_create(&scene->id, &scene_ptr);
+ if (BKE_scene_uses_cycles(scene)) {
+ cycles_ptr = RNA_pointer_get(&scene_ptr, "cycles");
+ ob_cycles_ptr = RNA_pointer_get(&ob_ptr, "cycles");
+ if (!RNA_pointer_is_null(&ob_cycles_ptr)) {
+ ob_use_adaptive_subdivision = RNA_boolean_get(&ob_cycles_ptr, "use_adaptive_subdivision");
+ show_adaptive_options = get_show_adaptive_options(C, panel);
+ }
+ }
+#endif
+
+ uiLayoutSetPropSep(layout, true);
+
+ uiItemR(layout, &ptr, "subdivision_type", 0, IFACE_("Type"), ICON_NONE);
+
+ if (show_adaptive_options) {
+ uiItemR(layout,
+ &ob_cycles_ptr,
+ "use_adaptive_subdivision",
+ 0,
+ IFACE_("Adaptive Subdivision"),
+ ICON_NONE);
+ }
+ if (ob_use_adaptive_subdivision && show_adaptive_options) {
+ uiItemR(layout, &ob_cycles_ptr, "dicing_rate", 0, NULL, ICON_NONE);
+ float render = MAX2(RNA_float_get(&cycles_ptr, "dicing_rate") *
+ RNA_float_get(&ob_cycles_ptr, "dicing_rate"),
+ 0.1f);
+ float preview = MAX2(RNA_float_get(&cycles_ptr, "preview_dicing_rate") *
+ RNA_float_get(&ob_cycles_ptr, "dicing_rate"),
+ 0.1f);
+ char output[64];
+ snprintf(output, 64, "Final Scale: Render %.2f px, Viewport %.2f px", render, preview);
+ uiItemL(layout, output, ICON_NONE);
+
+ uiItemS(layout);
+
+ uiItemR(layout, &ptr, "levels", 0, IFACE_("Levels Viewport"), ICON_NONE);
+ }
+ else {
+ uiLayout *col = uiLayoutColumn(layout, true);
+ uiItemR(col, &ptr, "levels", 0, IFACE_("Levels Viewport"), ICON_NONE);
+ uiItemR(col, &ptr, "render_levels", 0, IFACE_("Render"), ICON_NONE);
+ }
+
+ uiItemR(layout, &ptr, "show_only_control_edges", 0, NULL, ICON_NONE);
+
+ modifier_panel_end(layout, &ptr);
+}
+
+static void advanced_panel_draw(const bContext *C, Panel *panel)
+{
+ uiLayout *layout = panel->layout;
+
+ PointerRNA ptr;
+ PointerRNA ob_ptr;
+ modifier_panel_get_property_pointers(C, panel, &ob_ptr, &ptr);
+
+ bool ob_use_adaptive_subdivision = false;
+ bool show_adaptive_options = false;
+#ifdef WITH_CYCLES
+ Scene *scene = CTX_data_scene(C);
+ if (BKE_scene_uses_cycles(scene)) {
+ PointerRNA ob_cycles_ptr = RNA_pointer_get(&ob_ptr, "cycles");
+ if (!RNA_pointer_is_null(&ob_cycles_ptr)) {
+ ob_use_adaptive_subdivision = RNA_boolean_get(&ob_cycles_ptr, "use_adaptive_subdivision");
+ show_adaptive_options = get_show_adaptive_options(C, panel);
+ }
+ }
+#endif
+
+ uiLayoutSetPropSep(layout, true);
+
+ uiLayoutSetActive(layout, !(show_adaptive_options && ob_use_adaptive_subdivision));
+ uiItemR(layout, &ptr, "quality", 0, NULL, ICON_NONE);
+ uiItemR(layout, &ptr, "uv_smooth", 0, NULL, ICON_NONE);
+ uiItemR(layout, &ptr, "use_creases", 0, NULL, ICON_NONE);
+
+ modifier_panel_end(layout, &ptr);
+}
+
+static void panelRegister(ARegionType *region_type)
+{
+ PanelType *panel_type = modifier_panel_register(region_type, eModifierType_Subsurf, panel_draw);
+ modifier_subpanel_register(
+ region_type, "advanced", "Advanced", NULL, advanced_panel_draw, panel_type);
+}
+
ModifierTypeInfo modifierType_Subsurf = {
/* name */ "Subdivision",
/* structName */ "SubsurfModifierData",
@@ -306,4 +456,5 @@ ModifierTypeInfo modifierType_Subsurf = {
/* foreachIDLink */ NULL,
/* foreachTexLink */ NULL,
/* freeRuntimeData */ freeRuntimeData,
+ /* panelRegister */ panelRegister,
};