diff options
author | Daniel Genrich <daniel.genrich@gmx.net> | 2014-10-23 17:12:28 +0400 |
---|---|---|
committer | Daniel Genrich <daniel.genrich@gmx.net> | 2014-10-23 17:12:28 +0400 |
commit | 9ff1ebed52e0f858a395eeea4caf89304e068b2d (patch) | |
tree | b05d0f4b229de61b088a128ad412dd7bba347928 /source/blender/blenkernel/intern/scene.c | |
parent | a2ed11c6eeab5fab8cb81e32e1c68fdafdd5dbbc (diff) | |
parent | eaaeae469968c5c78a5d7e6d202f1af00b382a79 (diff) |
Merge remote-tracking branch 'origin/master' into soc-2014-fluid
Conflicts:
.gitignore
intern/cycles/CMakeLists.txt
source/blender/blenkernel/intern/smoke.c
source/blender/python/intern/bpy_interface.c
source/creator/CMakeLists.txt
Diffstat (limited to 'source/blender/blenkernel/intern/scene.c')
-rw-r--r-- | source/blender/blenkernel/intern/scene.c | 162 |
1 files changed, 137 insertions, 25 deletions
diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c index 0e95cf1d418..5bfd6e8a120 100644 --- a/source/blender/blenkernel/intern/scene.c +++ b/source/blender/blenkernel/intern/scene.c @@ -39,6 +39,7 @@ #include "DNA_anim_types.h" #include "DNA_group_types.h" #include "DNA_linestyle_types.h" +#include "DNA_mesh_types.h" #include "DNA_node_types.h" #include "DNA_object_types.h" #include "DNA_rigidbody_types.h" @@ -46,6 +47,8 @@ #include "DNA_screen_types.h" #include "DNA_sequence_types.h" #include "DNA_space_types.h" +#include "DNA_view3d_types.h" +#include "DNA_windowmanager_types.h" #include "BLI_math.h" #include "BLI_blenlib.h" @@ -62,6 +65,7 @@ #include "BKE_action.h" #include "BKE_colortools.h" #include "BKE_depsgraph.h" +#include "BKE_editmesh.h" #include "BKE_fcurve.h" #include "BKE_freestyle.h" #include "BKE_global.h" @@ -78,6 +82,7 @@ #include "BKE_scene.h" #include "BKE_sequencer.h" #include "BKE_sound.h" +#include "BKE_unit.h" #include "BKE_world.h" #include "RE_engine.h" @@ -86,8 +91,7 @@ #include "IMB_colormanagement.h" -//XXX #include "BIF_previewrender.h" -//XXX #include "BIF_editseq.h" +#include "bmesh.h" #ifdef WIN32 #else @@ -253,6 +257,7 @@ Scene *BKE_scene_copy(Scene *sce, int type) BKE_paint_copy(&ts->imapaint.paint, &ts->imapaint.paint); ts->imapaint.paintcursor = NULL; + id_us_plus((ID *)ts->imapaint.stencil); ts->particle.paintcursor = NULL; } @@ -510,7 +515,12 @@ Scene *BKE_scene_add(Main *bmain, const char *name) sce->r.border.ymin = 0.0f; sce->r.border.xmax = 1.0f; sce->r.border.ymax = 1.0f; + + sce->r.preview_start_resolution = 64; + sce->r.line_thickness_mode = R_LINE_THICKNESS_ABSOLUTE; + sce->r.unit_line_thickness = 1.0f; + sce->toolsettings = MEM_callocN(sizeof(struct ToolSettings), "Tool Settings Struct"); sce->toolsettings->doublimit = 0.001; sce->toolsettings->uvcalc_margin = 0.001f; @@ -553,6 +563,8 @@ Scene *BKE_scene_add(Main *bmain, const char *name) sce->toolsettings->proportional_size = 1.0f; sce->toolsettings->imapaint.paint.flags |= PAINT_SHOW_BRUSH; + sce->toolsettings->imapaint.normal_angle = 80; + sce->toolsettings->imapaint.seam_bleed = 2; sce->physics_settings.gravity[0] = 0.0f; sce->physics_settings.gravity[1] = 0.0f; @@ -719,14 +731,14 @@ void BKE_scene_set_background(Main *bmain, Scene *scene) /* called from creator.c */ Scene *BKE_scene_set_name(Main *bmain, const char *name) { - Scene *sce = (Scene *)BKE_libblock_find_name(ID_SCE, name); + Scene *sce = (Scene *)BKE_libblock_find_name_ex(bmain, ID_SCE, name); if (sce) { BKE_scene_set_background(bmain, sce); - printf("Scene switch: '%s' in file: '%s'\n", name, G.main->name); + printf("Scene switch: '%s' in file: '%s'\n", name, bmain->name); return sce; } - printf("Can't find scene: '%s' in file: '%s'\n", name, G.main->name); + printf("Can't find scene: '%s' in file: '%s'\n", name, bmain->name); return NULL; } @@ -804,9 +816,7 @@ void BKE_scene_unlink(Main *bmain, Scene *sce, Scene *newsce) BKE_libblock_free(bmain, sce); } -/* used by metaballs - * doesn't return the original duplicated object, only dupli's - */ +/* Used by metaballs, return *all* objects (including duplis) existing in the scene (including scene's sets) */ int BKE_scene_base_iter_next(EvaluationContext *eval_ctx, SceneBaseIter *iter, Scene **scene, int val, Base **base, Object **ob) { @@ -817,11 +827,12 @@ int BKE_scene_base_iter_next(EvaluationContext *eval_ctx, SceneBaseIter *iter, iter->phase = F_START; iter->dupob = NULL; iter->duplilist = NULL; + iter->dupli_refob = NULL; } else { /* run_again is set when a duplilist has been ended */ while (run_again) { - run_again = 0; + run_again = false; /* the first base */ if (iter->phase == F_START) { @@ -879,34 +890,46 @@ int BKE_scene_base_iter_next(EvaluationContext *eval_ctx, SceneBaseIter *iter, iter->dupob = iter->duplilist->first; - if (!iter->dupob) + if (!iter->dupob) { free_object_duplilist(iter->duplilist); + iter->duplilist = NULL; + } + iter->dupli_refob = NULL; } } } /* handle dupli's */ if (iter->dupob) { - - copy_m4_m4(iter->omat, iter->dupob->ob->obmat); - copy_m4_m4(iter->dupob->ob->obmat, iter->dupob->mat); - (*base)->flag |= OB_FROMDUPLI; *ob = iter->dupob->ob; iter->phase = F_DUPLI; - + + if (iter->dupli_refob != *ob) { + if (iter->dupli_refob) { + /* Restore previous object's real matrix. */ + copy_m4_m4(iter->dupli_refob->obmat, iter->omat); + } + /* Backup new object's real matrix. */ + iter->dupli_refob = *ob; + copy_m4_m4(iter->omat, iter->dupli_refob->obmat); + } + copy_m4_m4((*ob)->obmat, iter->dupob->mat); + iter->dupob = iter->dupob->next; } else if (iter->phase == F_DUPLI) { iter->phase = F_SCENE; (*base)->flag &= ~OB_FROMDUPLI; - for (iter->dupob = iter->duplilist->first; iter->dupob; iter->dupob = iter->dupob->next) { - copy_m4_m4(iter->dupob->ob->obmat, iter->omat); + if (iter->dupli_refob) { + /* Restore last object's real matrix. */ + copy_m4_m4(iter->dupli_refob->obmat, iter->omat); + iter->dupli_refob = NULL; } free_object_duplilist(iter->duplilist); iter->duplilist = NULL; - run_again = 1; + run_again = true; } } } @@ -1118,11 +1141,6 @@ void BKE_scene_frame_set(struct Scene *scene, double cfra) double intpart; scene->r.subframe = modf(cfra, &intpart); scene->r.cfra = (int)intpart; - - if (cfra < 0.0) { - scene->r.cfra -= 1; - scene->r.subframe = 1.0f + scene->r.subframe; - } } /* drivers support/hacks @@ -1462,7 +1480,7 @@ static void scene_update_objects(EvaluationContext *eval_ctx, Main *bmain, Scene bool need_singlethread_pass; /* Early check for whether we need to invoke all the task-based - * tihngs (spawn new ppol, traverse dependency graph and so on). + * things (spawn new ppol, traverse dependency graph and so on). * * Basically if there's no ID datablocks tagged for update which * corresponds to object->recalc flags (which are checked in @@ -1541,6 +1559,53 @@ static void scene_update_tagged_recursive(EvaluationContext *eval_ctx, Main *bma } +static bool check_rendered_viewport_visible(Main *bmain) +{ + wmWindowManager *wm = bmain->wm.first; + wmWindow *window; + for (window = wm->windows.first; window != NULL; window = window->next) { + bScreen *screen = window->screen; + ScrArea *area; + for (area = screen->areabase.first; area != NULL; area = area->next) { + View3D *v3d = area->spacedata.first; + if (area->spacetype != SPACE_VIEW3D) { + continue; + } + if (v3d->drawtype == OB_RENDER) { + return true; + } + } + } + return false; +} + +static void prepare_mesh_for_viewport_render(Main *bmain, Scene *scene) +{ + /* This is needed to prepare mesh to be used by the render + * engine from the viewport rendering. We do loading here + * so all the objects which shares the same mesh datablock + * are nicely tagged for update and updated. + * + * This makes it so viewport render engine doesn't need to + * call loading of the edit data for the mesh objects. + */ + + Object *obedit = scene->obedit; + if (obedit) { + Mesh *mesh = obedit->data; + /* TODO(sergey): Check object recalc flags as well? */ + if ((obedit->type == OB_MESH) && + (mesh->id.flag & (LIB_ID_RECALC | LIB_ID_RECALC_DATA))) + { + if (check_rendered_viewport_visible(bmain)) { + BMesh *bm = mesh->edit_btmesh->bm; + BM_mesh_bm_to_me(bm, mesh, false); + DAG_id_tag_update(&mesh->id, 0); + } + } + } +} + void BKE_scene_update_tagged(EvaluationContext *eval_ctx, Main *bmain, Scene *scene) { Scene *sce_iter; @@ -1552,6 +1617,9 @@ void BKE_scene_update_tagged(EvaluationContext *eval_ctx, Main *bmain, Scene *sc for (sce_iter = scene; sce_iter; sce_iter = sce_iter->set) DAG_scene_relations_update(bmain, sce_iter); + /* flush editing data if needed */ + prepare_mesh_for_viewport_render(bmain, scene); + /* flush recalc flags to dependencies */ DAG_ids_flush_tagged(bmain); @@ -1599,7 +1667,20 @@ void BKE_scene_update_tagged(EvaluationContext *eval_ctx, Main *bmain, Scene *sc BKE_animsys_evaluate_animdata(scene, &material->id, adt, ctime, 0); } } - + + /* Also do the same for node trees. */ + if (DAG_id_type_tagged(bmain, ID_NT)) { + float ctime = BKE_scene_frame_get(scene); + + FOREACH_NODETREE(bmain, ntree, id) + { + AnimData *adt = BKE_animdata_from_id(&ntree->id); + if (adt && (adt->recalc & ADT_RECALC_ANIM)) + BKE_animsys_evaluate_animdata(scene, &ntree->id, adt, ctime, 0); + } + FOREACH_NODETREE_END + } + /* notify editors and python about recalc */ BLI_callback_exec(bmain, &scene->id, BLI_CB_EVT_SCENE_UPDATE_POST); DAG_ids_check_recalc(bmain, scene, false); @@ -1819,6 +1900,12 @@ bool BKE_scene_use_new_shading_nodes(Scene *scene) return (type && type->flag & RE_USE_SHADING_NODES); } +bool BKE_scene_uses_blender_internal(struct Scene *scene) +{ + return strcmp("BLENDER_RENDER", scene->r.engine) == 0; +} + + void BKE_scene_base_flag_to_objects(struct Scene *scene) { Base *base = scene->base.first; @@ -1890,3 +1977,28 @@ int BKE_scene_num_threads(const Scene *scene) { return BKE_render_num_threads(&scene->r); } + +/* Apply the needed correction factor to value, based on unit_type (only length-related are affected currently) + * and unit->scale_length. + */ +double BKE_scene_unit_scale(const UnitSettings *unit, const int unit_type, double value) +{ + if (unit->system == USER_UNIT_NONE) { + /* Never apply scale_length when not using a unit setting! */ + return value; + } + + switch (unit_type) { + case B_UNIT_LENGTH: + return value * (double)unit->scale_length; + case B_UNIT_AREA: + return value * pow(unit->scale_length, 2); + case B_UNIT_VOLUME: + return value * pow(unit->scale_length, 3); + case B_UNIT_MASS: + return value * pow(unit->scale_length, 3); + case B_UNIT_CAMERA: /* *Do not* use scene's unit scale for camera focal lens! See T42026. */ + default: + return value; + } +} |