Previous experiment (in 2000) didn't satisfy, it had even some primitive NLA option in groups... so, cleaned up the old code (removed most) and integrated it back in a more useful way. Usage: - CTRL+G gives menu to add group, add to existing group, or remove from groups. - In Object buttons, a new (should become first) Panel was added, showing not only Object "ID button" and Parent, but also the Groups the Object Belongs to. These buttons also allow rename, assigning or removing. - To indicate Objects are grouped, they're drawn in a (not theme yet, so temporal?) green wire color. - Use ALT+SHIFT mouse-select to (de)select an entire group But, the real power of groups is in the following features: -> Particle Force field and Guide control In the "Particle Motion" Panel, you can indicate a Group name, this then limits force fields or guides to members of that Group. (Note that layers still work on top of that... not sure about that). -> Light Groups In the Material "Shaders" Panel, you can indicate a Group name to limit lighting for the Material to lamps in this group. The Lights in a Group do need to be 'visible' for the Scene to be rendered (as usual). -> Group Duplicator In the Object "Anim" Panel, you can set any Object (use Empty!) to duplicate an entire Group. It will make copies of all Objects in that Group. Also works for animated Objects, but it will copy the current positions or deforms. Control over 'local timing' (so we can do Massive anims!) will be added later. (Note; this commit won't render Group duplicators yet, a fix in bf-blender will enable that, next commit will sync) -> Library Appending In the SHIFT-F1 or SHIFT+F4 browsers, you can also find the Groups listed. By appending or linking the Group itself, and use the Group Duplicator, you now can animate and position linked Objects. The nice thing is that the local saved file itself will only store the Group name that was linked, so on a next file read, the Group Objects will be re-read as stored (changed) in the Library file. (Note; current implementation also "gives a base" to linked Group Objects, to show them as Objects in the current Scene. Need that now for testing purposes, but probably will be removed later). -> Outliner Outliner now shows Groups as optio too, nice to organize your data a bit too! In General, Groups have a very good potential... for example, it could become default for MetaBall Objects too (jiri, I can help you later on how this works). All current 'layer relationships' in Blender should be dropped in time, I guess...
468 lines
9.2 KiB
C
468 lines
9.2 KiB
C
/* scene.c
|
|
*
|
|
*
|
|
* $Id$
|
|
*
|
|
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
|
|
*
|
|
* This program is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU General Public License
|
|
* as published by the Free Software Foundation; either version 2
|
|
* of the License, or (at your option) any later version. The Blender
|
|
* Foundation also sells licenses for use in proprietary software under
|
|
* the Blender License. See http://www.blender.org/BL/ for information
|
|
* about this.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
*
|
|
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
* All rights reserved.
|
|
*
|
|
* The Original Code is: all of this file.
|
|
*
|
|
* Contributor(s): none yet.
|
|
*
|
|
* ***** END GPL/BL DUAL LICENSE BLOCK *****
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
#include <config.h>
|
|
#endif
|
|
|
|
#ifndef WIN32
|
|
#include <unistd.h>
|
|
#else
|
|
#include <io.h>
|
|
#endif
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
#include "DNA_armature_types.h"
|
|
#include "DNA_constraint_types.h"
|
|
#include "DNA_curve_types.h"
|
|
#include "DNA_group_types.h"
|
|
#include "DNA_lamp_types.h"
|
|
#include "DNA_material_types.h"
|
|
#include "DNA_meta_types.h"
|
|
#include "DNA_object_types.h"
|
|
#include "DNA_scene_types.h"
|
|
#include "DNA_scriptlink_types.h"
|
|
#include "DNA_userdef_types.h"
|
|
|
|
#include "BKE_action.h"
|
|
#include "BKE_anim.h"
|
|
#include "BKE_armature.h"
|
|
#include "BKE_bad_level_calls.h"
|
|
#include "BKE_constraint.h"
|
|
#include "BKE_depsgraph.h"
|
|
#include "BKE_global.h"
|
|
#include "BKE_ipo.h"
|
|
#include "BKE_key.h"
|
|
#include "BKE_library.h"
|
|
#include "BKE_main.h"
|
|
#include "BKE_object.h"
|
|
#include "BKE_scene.h"
|
|
#include "BKE_world.h"
|
|
#include "BKE_utildefines.h"
|
|
|
|
#include "BPY_extern.h"
|
|
|
|
#include "BLI_blenlib.h"
|
|
|
|
#include "nla.h"
|
|
|
|
#ifdef WIN32
|
|
#else
|
|
#include <sys/time.h>
|
|
#endif
|
|
|
|
void free_avicodecdata(AviCodecData *acd)
|
|
{
|
|
if (acd) {
|
|
if (acd->lpFormat){
|
|
MEM_freeN(acd->lpFormat);
|
|
acd->lpFormat = NULL;
|
|
acd->cbFormat = 0;
|
|
}
|
|
if (acd->lpParms){
|
|
MEM_freeN(acd->lpParms);
|
|
acd->lpParms = NULL;
|
|
acd->cbParms = 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
void free_qtcodecdata(QuicktimeCodecData *qcd)
|
|
{
|
|
if (qcd) {
|
|
if (qcd->cdParms){
|
|
MEM_freeN(qcd->cdParms);
|
|
qcd->cdParms = NULL;
|
|
qcd->cdSize = 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
/* do not free scene itself */
|
|
void free_scene(Scene *sce)
|
|
{
|
|
Base *base;
|
|
|
|
base= sce->base.first;
|
|
while(base) {
|
|
base->object->id.us--;
|
|
base= base->next;
|
|
}
|
|
/* do not free objects! */
|
|
|
|
BLI_freelistN(&sce->base);
|
|
free_editing(sce->ed);
|
|
if(sce->radio) MEM_freeN(sce->radio);
|
|
sce->radio= 0;
|
|
|
|
BPY_free_scriptlink(&sce->scriptlink);
|
|
if (sce->r.avicodecdata) {
|
|
free_avicodecdata(sce->r.avicodecdata);
|
|
MEM_freeN(sce->r.avicodecdata);
|
|
sce->r.avicodecdata = NULL;
|
|
}
|
|
if (sce->r.qtcodecdata) {
|
|
free_qtcodecdata(sce->r.qtcodecdata);
|
|
MEM_freeN(sce->r.qtcodecdata);
|
|
sce->r.qtcodecdata = NULL;
|
|
}
|
|
|
|
BLI_freelistN(&sce->markers);
|
|
|
|
if(sce->toolsettings){
|
|
MEM_freeN(sce->toolsettings);
|
|
sce->toolsettings = NULL;
|
|
}
|
|
|
|
if (sce->theDag) {
|
|
free_forest(sce->theDag);
|
|
MEM_freeN(sce->theDag);
|
|
}
|
|
}
|
|
|
|
Scene *add_scene(char *name)
|
|
{
|
|
Scene *sce;
|
|
|
|
sce= alloc_libblock(&G.main->scene, ID_SCE, name);
|
|
sce->lay= 1;
|
|
sce->selectmode= SCE_SELECT_VERTEX;
|
|
sce->editbutsize= 0.1;
|
|
|
|
sce->r.mode= R_GAMMA;
|
|
sce->r.cfra= 1;
|
|
sce->r.sfra= 1;
|
|
sce->r.efra= 250;
|
|
sce->r.xsch= 320;
|
|
sce->r.ysch= 256;
|
|
sce->r.xasp= 1;
|
|
sce->r.yasp= 1;
|
|
sce->r.xparts= 1;
|
|
sce->r.yparts= 1;
|
|
sce->r.size= 100;
|
|
sce->r.planes= 24;
|
|
sce->r.quality= 90;
|
|
sce->r.framapto= 100;
|
|
sce->r.images= 100;
|
|
sce->r.framelen= 1.0;
|
|
sce->r.frs_sec= 25;
|
|
|
|
sce->r.postgamma= 1.0;
|
|
sce->r.postsat= 1.0;
|
|
sce->r.postmul= 1.0;
|
|
|
|
sce->r.focus= 0.9;
|
|
sce->r.zgamma= 1.0;
|
|
sce->r.zsigma= 4.0;
|
|
sce->r.zblur= 10.0;
|
|
sce->r.zmin= 0.8;
|
|
|
|
sce->r.xplay= 640;
|
|
sce->r.yplay= 480;
|
|
sce->r.freqplay= 60;
|
|
sce->r.depth= 32;
|
|
|
|
sce->r.stereomode = 1; // no stereo
|
|
|
|
sce->toolsettings = MEM_mallocN(sizeof(struct ToolSettings),"Tool Settings Struct");
|
|
sce->toolsettings->cornertype=1;
|
|
sce->toolsettings->degr = 90;
|
|
sce->toolsettings->step = 9;
|
|
sce->toolsettings->turn = 1;
|
|
sce->toolsettings->extr_offs = 1;
|
|
sce->toolsettings->doublimit = 0.001;
|
|
sce->toolsettings->segments = 32;
|
|
sce->toolsettings->rings = 32;
|
|
sce->toolsettings->vertices = 32;
|
|
sce->toolsettings->editbutflag = 1;
|
|
|
|
strcpy(sce->r.backbuf, "//backbuf");
|
|
strcpy(sce->r.pic, U.renderdir);
|
|
strcpy(sce->r.ftype, "//ftype");
|
|
|
|
BLI_init_rctf(&sce->r.safety, 0.1f, 0.9f, 0.1f, 0.9f);
|
|
sce->r.osa= 8;
|
|
|
|
return sce;
|
|
}
|
|
|
|
Base *object_in_scene(Object *ob, Scene *sce)
|
|
{
|
|
Base *base;
|
|
|
|
base= sce->base.first;
|
|
while(base) {
|
|
if(base->object == ob) return base;
|
|
base= base->next;
|
|
}
|
|
return NULL;
|
|
}
|
|
|
|
void set_scene_bg(Scene *sce)
|
|
{
|
|
Base *base;
|
|
Object *ob;
|
|
Group *group;
|
|
GroupObject *go;
|
|
int flag;
|
|
|
|
G.scene= sce;
|
|
|
|
/* deselect objects (for dataselect) */
|
|
ob= G.main->object.first;
|
|
while(ob) {
|
|
ob->flag &= ~(SELECT|OB_FROMGROUP);
|
|
ob= ob->id.next;
|
|
}
|
|
|
|
/* group flags again */
|
|
group= G.main->group.first;
|
|
while(group) {
|
|
go= group->gobject.first;
|
|
while(go) {
|
|
if(go->ob) go->ob->flag |= OB_FROMGROUP;
|
|
go= go->next;
|
|
}
|
|
group= group->id.next;
|
|
}
|
|
|
|
/* sort baselist */
|
|
DAG_scene_sort(sce);
|
|
|
|
/* copy layers and flags from bases to objects */
|
|
base= G.scene->base.first;
|
|
while(base) {
|
|
ob= base->object;
|
|
ob->lay= base->lay;
|
|
|
|
/* group patch... */
|
|
base->flag &= ~(OB_FROMGROUP);
|
|
flag= ob->flag & (OB_FROMGROUP);
|
|
base->flag |= flag;
|
|
|
|
ob->flag= base->flag;
|
|
ob->recalc= OB_RECALC;
|
|
|
|
ob->ctime= -1234567.0; /* force ipo to be calculated later */
|
|
base= base->next;
|
|
}
|
|
// full update
|
|
scene_update_for_newframe(sce, sce->lay);
|
|
|
|
/* do we need FRAMECHANGED in set_scene? */
|
|
// if (G.f & G_DOSCRIPTLINKS) BPY_do_all_scripts(SCRIPT_FRAMECHANGED);
|
|
}
|
|
|
|
void set_scene_name(char *name)
|
|
{
|
|
Scene *sce;
|
|
|
|
for (sce= G.main->scene.first; sce; sce= sce->id.next) {
|
|
if (BLI_streq(name, sce->id.name+2)) {
|
|
set_scene_bg(sce);
|
|
return;
|
|
}
|
|
}
|
|
|
|
error("Can't find scene: %s", name);
|
|
}
|
|
|
|
/* used by metaballs
|
|
* doesnt return the original duplicated object, only dupli's
|
|
*/
|
|
int next_object(int val, Base **base, Object **ob)
|
|
{
|
|
extern ListBase duplilist;
|
|
static Object *dupob;
|
|
static int fase;
|
|
int run_again=1;
|
|
|
|
/* init */
|
|
if(val==0) {
|
|
fase= F_START;
|
|
dupob= 0;
|
|
}
|
|
else {
|
|
|
|
/* run_again is set when a duplilist has been ended */
|
|
while(run_again) {
|
|
run_again= 0;
|
|
|
|
|
|
|
|
/* the first base */
|
|
if(fase==F_START) {
|
|
*base= G.scene->base.first;
|
|
if(*base) {
|
|
*ob= (*base)->object;
|
|
fase= F_SCENE;
|
|
}
|
|
else {
|
|
/* exception: empty scene */
|
|
if(G.scene->set && G.scene->set->base.first) {
|
|
*base= G.scene->set->base.first;
|
|
*ob= (*base)->object;
|
|
fase= F_SET;
|
|
}
|
|
}
|
|
}
|
|
else {
|
|
if(*base && fase!=F_DUPLI) {
|
|
*base= (*base)->next;
|
|
if(*base) *ob= (*base)->object;
|
|
else {
|
|
if(fase==F_SCENE) {
|
|
/* scene is finished, now do the set */
|
|
if(G.scene->set && G.scene->set->base.first) {
|
|
*base= G.scene->set->base.first;
|
|
*ob= (*base)->object;
|
|
fase= F_SET;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if(*base == 0) fase= F_START;
|
|
else {
|
|
if(fase!=F_DUPLI) {
|
|
if( (*base)->object->transflag & OB_DUPLI) {
|
|
|
|
make_duplilist(G.scene, (*base)->object);
|
|
dupob= duplilist.first;
|
|
|
|
}
|
|
}
|
|
/* handle dupli's */
|
|
if(dupob) {
|
|
|
|
*ob= dupob;
|
|
fase= F_DUPLI;
|
|
|
|
dupob= dupob->id.next;
|
|
}
|
|
else if(fase==F_DUPLI) {
|
|
fase= F_SCENE;
|
|
free_duplilist();
|
|
run_again= 1;
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
return fase;
|
|
}
|
|
|
|
Object *scene_find_camera(Scene *sc)
|
|
{
|
|
Base *base;
|
|
|
|
for (base= sc->base.first; base; base= base->next)
|
|
if (base->object->type==OB_CAMERA)
|
|
return base->object;
|
|
|
|
return NULL;
|
|
}
|
|
|
|
|
|
Base *scene_add_base(Scene *sce, Object *ob)
|
|
{
|
|
Base *b= MEM_callocN(sizeof(*b), "scene_add_base");
|
|
BLI_addhead(&sce->base, b);
|
|
|
|
b->object= ob;
|
|
b->flag= ob->flag;
|
|
b->lay= ob->lay;
|
|
|
|
return b;
|
|
}
|
|
|
|
void scene_deselect_all(Scene *sce)
|
|
{
|
|
Base *b;
|
|
|
|
for (b= sce->base.first; b; b= b->next) {
|
|
b->flag&= ~SELECT;
|
|
b->object->flag= b->flag;
|
|
}
|
|
}
|
|
|
|
void scene_select_base(Scene *sce, Base *selbase)
|
|
{
|
|
scene_deselect_all(sce);
|
|
|
|
selbase->flag |= SELECT;
|
|
selbase->object->flag= selbase->flag;
|
|
|
|
sce->basact= selbase;
|
|
}
|
|
|
|
/* applies changes right away */
|
|
void scene_update_for_newframe(Scene *sce, unsigned int lay)
|
|
{
|
|
Base *base;
|
|
Object *ob;
|
|
int setcount=0;
|
|
|
|
/* object ipos are calculated in where_is_object */
|
|
do_all_data_ipos();
|
|
|
|
if (G.f & G_DOSCRIPTLINKS) BPY_do_all_scripts(SCRIPT_FRAMECHANGED);
|
|
|
|
/* for time being; sets otherwise can be cyclic */
|
|
while(sce && setcount<2) {
|
|
if(sce->theDag==NULL)
|
|
DAG_scene_sort(sce);
|
|
|
|
DAG_scene_update_flags(sce, lay); // only stuff that moves
|
|
|
|
for(base= sce->base.first; base; base= base->next) {
|
|
ob= base->object;
|
|
|
|
object_handle_update(ob); // bke_object.h
|
|
|
|
/* only update layer when an ipo */
|
|
if(ob->ipo && has_ipo_code(ob->ipo, OB_LAY) ) {
|
|
base->lay= ob->lay;
|
|
}
|
|
}
|
|
sce= sce->set;
|
|
setcount++;
|
|
}
|
|
}
|