2.5/Posemode:
[blender-staging.git] / source / blender / blenkernel / intern / scene.c
index 156bdae9b005ee11ce86023678cbaafb549162fb..71271e77adfe20ff02f892e2caabf62bae51cb00 100644 (file)
@@ -54,7 +54,7 @@
 #include "DNA_meta_types.h"
 #include "DNA_object_types.h"
 #include "DNA_scene_types.h"
-#include "DNA_scriptlink_types.h"
+#include "DNA_screen_types.h"
 #include "DNA_texture_types.h"
 #include "DNA_userdef_types.h"
 
@@ -77,7 +77,6 @@
 #include "BKE_node.h"
 #include "BKE_object.h"
 #include "BKE_scene.h"
-#include "BKE_sculpt.h"
 #include "BKE_sequence.h"
 #include "BKE_world.h"
 #include "BKE_utildefines.h"
@@ -126,7 +125,112 @@ void free_qtcodecdata(QuicktimeCodecData *qcd)
        }
 }
 
-/* copy_scene moved to src/header_info.c... should be back */
+Scene *copy_scene(Main *bmain, Scene *sce, int type)
+{
+       Scene *scen;
+       ToolSettings *ts;
+       Base *base, *obase;
+       
+       if(type == SCE_COPY_EMPTY) {
+               ListBase lb;
+               scen= add_scene(sce->id.name+2);
+               
+               lb= scen->r.layers;
+               scen->r= sce->r;
+               scen->r.layers= lb;
+       }
+       else {
+               scen= copy_libblock(sce);
+               BLI_duplicatelist(&(scen->base), &(sce->base));
+               
+               clear_id_newpoins();
+               
+               id_us_plus((ID *)scen->world);
+               id_us_plus((ID *)scen->set);
+               id_us_plus((ID *)scen->ima);
+               id_us_plus((ID *)scen->gm.dome.warptext);
+
+               scen->ed= NULL;
+               scen->theDag= NULL;
+               scen->obedit= NULL;
+               scen->toolsettings= MEM_dupallocN(sce->toolsettings);
+
+               ts= scen->toolsettings;
+               if(ts) {
+                       if(ts->vpaint) {
+                               ts->vpaint= MEM_dupallocN(ts->vpaint);
+                               ts->vpaint->paintcursor= NULL;
+                               ts->vpaint->vpaint_prev= NULL;
+                               ts->vpaint->wpaint_prev= NULL;
+                               id_us_plus((ID *)ts->vpaint->brush);
+                       }
+                       if(ts->wpaint) {
+                               ts->wpaint= MEM_dupallocN(ts->wpaint);
+                               ts->wpaint->paintcursor= NULL;
+                               ts->wpaint->vpaint_prev= NULL;
+                               ts->wpaint->wpaint_prev= NULL;
+                               id_us_plus((ID *)ts->wpaint->brush);
+                       }
+                       if(ts->sculpt) {
+                               ts->sculpt= MEM_dupallocN(ts->sculpt);
+                               id_us_plus((ID *)ts->sculpt->brush);
+                       }
+
+                       id_us_plus((ID *)ts->imapaint.brush);
+                       ts->imapaint.paintcursor= NULL;
+
+                       ts->particle.paintcursor= NULL;
+               }
+               
+               BLI_duplicatelist(&(scen->markers), &(sce->markers));
+               BLI_duplicatelist(&(scen->transform_spaces), &(sce->transform_spaces));
+               BLI_duplicatelist(&(scen->r.layers), &(sce->r.layers));
+               BKE_keyingsets_copy(&(scen->keyingsets), &(sce->keyingsets));
+               
+               scen->nodetree= ntreeCopyTree(sce->nodetree, 0);
+               
+               obase= sce->base.first;
+               base= scen->base.first;
+               while(base) {
+                       id_us_plus(&base->object->id);
+                       if(obase==sce->basact) scen->basact= base;
+       
+                       obase= obase->next;
+                       base= base->next;
+               }
+       }
+       
+       /* make a private copy of the avicodecdata */
+       if(sce->r.avicodecdata) {
+               scen->r.avicodecdata = MEM_dupallocN(sce->r.avicodecdata);
+               scen->r.avicodecdata->lpFormat = MEM_dupallocN(scen->r.avicodecdata->lpFormat);
+               scen->r.avicodecdata->lpParms = MEM_dupallocN(scen->r.avicodecdata->lpParms);
+       }
+       
+       /* make a private copy of the qtcodecdata */
+       if(sce->r.qtcodecdata) {
+               scen->r.qtcodecdata = MEM_dupallocN(sce->r.qtcodecdata);
+               scen->r.qtcodecdata->cdParms = MEM_dupallocN(scen->r.qtcodecdata->cdParms);
+       }
+       
+       /* NOTE: part of SCE_COPY_LINK_DATA and SCE_COPY_FULL operations
+        * are done outside of blenkernel with ED_objects_single_users! */
+
+    /*  camera */
+       if(type == SCE_COPY_LINK_DATA || type == SCE_COPY_FULL) {
+           ID_NEW(scen->camera);
+       }
+
+       /* world */
+       if(type == SCE_COPY_FULL) {
+        if(scen->world) {
+            id_us_plus((ID *)scen->world);
+            scen->world= copy_world(scen->world);
+        }
+       }
+
+       return scen;
+}
 
 /* do not free scene itself */
 void free_scene(Scene *sce)
@@ -141,13 +245,7 @@ void free_scene(Scene *sce)
        /* do not free objects! */
 
        BLI_freelistN(&sce->base);
-       seq_free_editing(sce->ed);
-       if(sce->radio) MEM_freeN(sce->radio);
-       sce->radio= 0;
-       
-#ifndef DISABLE_PYTHON
-       BPY_free_scriptlink(&sce->scriptlink);
-#endif
+       seq_free_editing(sce);
 
        BKE_free_animdata((ID *)sce);
        BKE_keyingsets_free(&sce->keyingsets);
@@ -177,10 +275,8 @@ void free_scene(Scene *sce)
                        MEM_freeN(sce->toolsettings->vpaint);
                if(sce->toolsettings->wpaint)
                        MEM_freeN(sce->toolsettings->wpaint);
-               if(sce->toolsettings->sculpt) {
-                       sculptsession_free(sce->toolsettings->sculpt);
+               if(sce->toolsettings->sculpt)
                        MEM_freeN(sce->toolsettings->sculpt);
-               }
                
                MEM_freeN(sce->toolsettings);
                sce->toolsettings = NULL;       
@@ -205,21 +301,18 @@ Scene *add_scene(char *name)
 
        sce= alloc_libblock(&G.main->scene, ID_SCE, name);
        sce->lay= 1;
-       sce->selectmode= SCE_SELECT_VERTEX;
-       sce->editbutsize= 0.1;
-       sce->autokey_mode= U.autokey_mode;
        
-       sce->r.mode= R_GAMMA;
+       sce->r.mode= R_GAMMA|R_OSA|R_SHADOW|R_SSS|R_ENVMAP|R_RAYTRACE;
        sce->r.cfra= 1;
        sce->r.sfra= 1;
        sce->r.efra= 250;
-       sce->r.xsch= 320;
-       sce->r.ysch= 256;
+       sce->r.xsch= 1920;
+       sce->r.ysch= 1080;
        sce->r.xasp= 1;
        sce->r.yasp= 1;
-       sce->r.xparts= 4;
-       sce->r.yparts= 4;
-       sce->r.size= 100;
+       sce->r.xparts= 8;
+       sce->r.yparts= 8;
+       sce->r.size= 25;
        sce->r.planes= 24;
        sce->r.quality= 90;
        sce->r.framapto= 100;
@@ -228,26 +321,18 @@ Scene *add_scene(char *name)
        sce->r.frs_sec= 25;
        sce->r.frs_sec_base= 1;
        sce->r.ocres = 128;
+       sce->r.color_mgt_flag |= R_COLOR_MANAGEMENT;
        
        sce->r.bake_mode= 1;    /* prevent to include render stuff here */
-       sce->r.bake_filter= 2;
+       sce->r.bake_filter= 8;
        sce->r.bake_osa= 5;
        sce->r.bake_flag= R_BAKE_CLEAR;
        sce->r.bake_normal_space= R_BAKE_SPACE_TANGENT;
-       
-       sce->r.xplay= 640;
-       sce->r.yplay= 480;
-       sce->r.freqplay= 60;
-       sce->r.depth= 32;
+
+       sce->r.scemode= R_DOCOMP|R_DOSEQ|R_EXTENSION;
+       sce->r.stamp= R_STAMP_TIME|R_STAMP_FRAME|R_STAMP_DATE|R_STAMP_SCENE|R_STAMP_CAMERA;
        
        sce->r.threads= 1;
-       
-       sce->r.stereomode = 1;  // no stereo
-       sce->r.domeangle = 180;
-       sce->r.domemode = 1;
-       sce->r.domeres = 4;
-       sce->r.domeresbuf = 1.0f;
-       sce->r.dometilt = 0;
 
        sce->r.simplify_subsurf= 6;
        sce->r.simplify_particles= 1.0f;
@@ -277,6 +362,10 @@ Scene *add_scene(char *name)
        sce->toolsettings->select_thresh= 0.01f;
        sce->toolsettings->jointrilimit = 0.8f;
 
+       sce->toolsettings->selectmode= SCE_SELECT_VERTEX;
+       sce->toolsettings->normalsize= 0.1;
+       sce->toolsettings->autokey_mode= U.autokey_mode;
+
        sce->toolsettings->skgen_resolution = 100;
        sce->toolsettings->skgen_threshold_internal     = 0.01f;
        sce->toolsettings->skgen_threshold_external     = 0.01f;
@@ -294,6 +383,9 @@ Scene *add_scene(char *name)
 
        sce->toolsettings->proportional_size = 1.0f;
 
+
+       sce->unit.scale_length = 1.0f;
+
        pset= &sce->toolsettings->particle;
        pset->flag= PE_KEEP_LENGTHS|PE_LOCK_FIRST|PE_DEFLECT_EMITTER;
        pset->emitterdist= 0.25f;
@@ -319,6 +411,29 @@ Scene *add_scene(char *name)
        /* note; in header_info.c the scene copy happens..., if you add more to renderdata it has to be checked there */
        scene_add_render_layer(sce);
        
+       /* game data */
+       sce->gm.stereoflag = STEREO_NOSTEREO;
+       sce->gm.stereomode = STEREO_ANAGLYPH;
+       sce->gm.dome.angle = 180;
+       sce->gm.dome.mode = DOME_FISHEYE;
+       sce->gm.dome.res = 4;
+       sce->gm.dome.resbuf = 1.0f;
+       sce->gm.dome.tilt = 0;
+
+       sce->gm.xplay= 800;
+       sce->gm.yplay= 600;
+       sce->gm.freqplay= 60;
+       sce->gm.depth= 32;
+
+       sce->gm.gravity= 9.8f;
+       sce->gm.physicsEngine= WOPHY_BULLET;
+       sce->gm.mode = 32; //XXX ugly harcoding, still not sure we should drop mode. 32 == 1 << 5 == use_occlusion_culling 
+       sce->gm.occlusionRes = 128;
+       sce->gm.ticrate = 60;
+       sce->gm.maxlogicstep = 5;
+       sce->gm.physubstep = 1;
+       sce->gm.maxphystep = 5;
+
        return sce;
 }
 
@@ -378,15 +493,12 @@ void set_scene_bg(Scene *scene)
                base->flag |= flag;
                
                /* not too nice... for recovering objects with lost data */
-               if(ob->pose==NULL) base->flag &= ~OB_POSEMODE;
+               //if(ob->pose==NULL) base->flag &= ~OB_POSEMODE;
                ob->flag= base->flag;
                
                ob->ctime= -1234567.0;  /* force ipo to be calculated later */
        }
        /* no full animation update, this to enable render code to work (render code calls own animation updates) */
-       
-       /* do we need FRAMECHANGED in set_scene? */
-//     if (G.f & G_DOSCRIPTLINKS) BPY_do_all_scripts(SCRIPT_FRAMECHANGED, 0);
 }
 
 /* called from creator.c */
@@ -404,6 +516,30 @@ void set_scene_name(char *name)
        //XXX error("Can't find scene: %s", name);
 }
 
+void unlink_scene(Main *bmain, Scene *sce, Scene *newsce)
+{
+       Scene *sce1;
+       bScreen *sc;
+
+       /* check all sets */
+       for(sce1= bmain->scene.first; sce1; sce1= sce1->id.next)
+               if(sce1->set == sce)
+                       sce1->set= NULL;
+       
+       /* check all sequences */
+       clear_scene_in_allseqs(sce);
+
+       /* check render layer nodes in other scenes */
+       clear_scene_in_nodes(bmain, sce);
+       
+       /* al screens */
+       for(sc= bmain->screen.first; sc; sc= sc->id.next)
+               if(sc->scene == sce)
+                       sc->scene= newsce;
+
+       free_libblock(&bmain->scene, sce);
+}
+
 /* used by metaballs
  * doesnt return the original duplicated object, only dupli's
  */
@@ -645,9 +781,6 @@ void scene_update_for_newframe(Scene *sce, unsigned int lay)
        /* clear animation overrides */
        // XXX TODO...
        
-#ifndef DISABLE_PYTHON
-       if (G.f & G_DOSCRIPTLINKS) BPY_do_all_scripts(SCRIPT_FRAMECHANGED, 0);
-#endif
        /* sets first, we allow per definition current scene to have dependencies on sets */
        for(sce= sce->set; sce; sce= sce->set)
                scene_update(sce, lay);
@@ -671,26 +804,6 @@ void scene_add_render_layer(Scene *sce)
        srl->passflag= SCE_PASS_COMBINED|SCE_PASS_Z;
 }
 
-void sculptsession_free(Sculpt *sculpt)
-{
-       SculptSession *ss= sculpt->session;
-       if(ss) {
-               if(ss->projverts)
-                       MEM_freeN(ss->projverts);
-
-               if(ss->fmap)
-                       MEM_freeN(ss->fmap);
-
-               if(ss->fmap_mem)
-                       MEM_freeN(ss->fmap_mem);
-
-               if(ss->texcache)
-                       MEM_freeN(ss->texcache);
-               MEM_freeN(ss);
-               sculpt->session= NULL;
-       }
-}
-
 /* render simplification */
 
 int get_render_subsurf_level(RenderData *r, int lvl)