[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [11193] branches/soc-2007-mosani/source/ blender/render/render_api: I just realized that I' m going about coding this wrong.
Aaron Moore
two.a.ron at gmail.com
Sun Jul 8 09:48:47 CEST 2007
Revision: 11193
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=11193
Author: mosani
Date: 2007-07-08 09:48:47 +0200 (Sun, 08 Jul 2007)
Log Message:
-----------
I just realized that I'm going about coding this wrong.
I went strait from designing an interface to attempting
to code that interface.
I need to design an implementation separately from trying
to code it. This commit is the last before I start again
with a solid implementation design first.
Aaron
Modified Paths:
--------------
branches/soc-2007-mosani/source/blender/render/render_api/include/RND_types.h
branches/soc-2007-mosani/source/blender/render/render_api/include/RenderAPI.h
branches/soc-2007-mosani/source/blender/render/render_api/include/RenderAPI_helpers.h
branches/soc-2007-mosani/source/blender/render/render_api/source/RND_helpers.c
branches/soc-2007-mosani/source/blender/render/render_api/source/test.c
Modified: branches/soc-2007-mosani/source/blender/render/render_api/include/RND_types.h
===================================================================
--- branches/soc-2007-mosani/source/blender/render/render_api/include/RND_types.h 2007-07-07 22:18:55 UTC (rev 11192)
+++ branches/soc-2007-mosani/source/blender/render/render_api/include/RND_types.h 2007-07-08 07:48:47 UTC (rev 11193)
@@ -41,11 +41,14 @@
typedef struct RenderAPIScene{
Scene *source; /* the scene to be rendered */
- ListBase objects; /* an index of RenderAPIObjectHodlers */
+ ListBase objects; /* an index of RenderAPIObjectHodlers for whole scene */
+ ListBase originals; /* a list of RenderAPIObjectHodlers, which objects
+ that have multiple instances refer to */
short instance_info; /* true if objects contains instance info */
}RenderAPIScene;
typedef struct RenderAPIObject{
+ struct RenderAPIObject *next, *prev;
ListBase holders; /* a list of RenderAPIObjectHolders for the
selected object set */
struct RenderAPIObjectHolder *current_object; /* is listed within the
@@ -57,18 +60,25 @@
this is used to hold meta data for a single
object so that the list structure RNDObject
may flatten this hierarchy into a list.
+
+ Note: I have members which may look like
+ simple copies from the object structure,
+ one may wonder why I don't just include a
+ pointer to that. These members often differ
+ from their Object structure equivalents, due
+ to collapsing of duplication and parenting
+ transformations, and other things.
*/
typedef struct RenderAPIObjectHolder{
- struct RenderAPIObjectHolder *next;
+ struct RenderAPIObjectHolder *next, *prev;
+ Object *source; /* the Object struct within the blender database */
- int type; /* choose one of the following pointers, based on
+ char *name;
+ int type; /* determines what the identity of data is, based on
RND_DATATYPE value. */
- Lamp *lamp; /* the lamp within blender's database */
- DerivedMesh *mesh; /* the mesh within blender's database */
- /* ...more datatypes */
- struct RenderAPIObjectHolder *original; /* the original object of which this is
- an instance */
+ struct RenderAPIObjectHolder *original; /* the original object of which
+ this is an instance */
float transformation[4][4]; /* the resultant transformation matrix
after groups, parenting, duplicators */
Modified: branches/soc-2007-mosani/source/blender/render/render_api/include/RenderAPI.h
===================================================================
--- branches/soc-2007-mosani/source/blender/render/render_api/include/RenderAPI.h 2007-07-07 22:18:55 UTC (rev 11192)
+++ branches/soc-2007-mosani/source/blender/render/render_api/include/RenderAPI.h 2007-07-08 07:48:47 UTC (rev 11193)
@@ -47,6 +47,8 @@
/* functions */
#include "BLI_blenlib.h"
#include "MEM_guardedalloc.h"
+#include "BKE_scene.h"
+#include "BLI_arithb.h" /* math */
/* structures */
#include "BKE_global.h"
Modified: branches/soc-2007-mosani/source/blender/render/render_api/include/RenderAPI_helpers.h
===================================================================
--- branches/soc-2007-mosani/source/blender/render/render_api/include/RenderAPI_helpers.h 2007-07-07 22:18:55 UTC (rev 11192)
+++ branches/soc-2007-mosani/source/blender/render/render_api/include/RenderAPI_helpers.h 2007-07-08 07:48:47 UTC (rev 11193)
@@ -32,26 +32,38 @@
#ifndef RENDER_API_HELPERS_H
#define RENDER_API_HELPERS_H
-/*
- * Null pointers, etc.
+/* Null pointers, etc.
*/
RNDScene RenderAPI_empty_scene();
-/*
- * Frees all render API memory for this job
+/* Nulls list.first and list.last, this may already exist,
+ * but I couldn't find it.
*/
+void RenderAPI_empty_list( ListBase *list );
+
+/* Initializes all data which can be a derived from object, without interacting
+ * with other objects.
+ */
+RenderAPIObjectHolder *RenderAPI_initialize_object_holder( Object *object );
+
+/* Frees all render API memory for this job
+ */
void RenderAPI_free( RNDScene scene );
-/*
- * Create an index of all renderable objects in this scene. Collapse
+/* Create an index of all renderable objects in this scene. Collapse
* parenting, and duplicators. If RND_INSTANCE is specified in type, include
* instance information.
*/
void RenderAPI_create_object_index( RNDScene scene, unsigned int type );
-/*
- * Returns true if object is rendered for scene
+/* Returns true if object is rendered for scene
*/
-int RenderAPI_is_rendered( RNDScene scene, Base *base );
+int RenderAPI_is_rendered( RNDScene scene, Base *base );
+
+/* Creates instancing information for objects. Store orignal objects in
+ * scene->originals, and link instances from objects to them. Only searches
+ * for instances within objects.
+ */
+void RenderAPI_calculate_instances( RNDScene scene, ListBase objects );
#endif
Modified: branches/soc-2007-mosani/source/blender/render/render_api/source/RND_helpers.c
===================================================================
--- branches/soc-2007-mosani/source/blender/render/render_api/source/RND_helpers.c 2007-07-07 22:18:55 UTC (rev 11192)
+++ branches/soc-2007-mosani/source/blender/render/render_api/source/RND_helpers.c 2007-07-08 07:48:47 UTC (rev 11193)
@@ -35,49 +35,169 @@
RNDScene RenderAPI_empty_scene(){
RNDScene scene = MEM_mallocN( sizeof(RenderAPIScene), "renderAPI scene" );
scene->source = G.scene;
- scene->objects.first = scene->objects.last = NULL;
+ RenderAPI_empty_list( &scene->objects );
+ RenderAPI_empty_list( &scene->originals );
+ //scene->objects.first = scene->objects.last = NULL;
scene->instance_info = 0;
return scene;
}
+void RenderAPI_empty_list( ListBase *list ){
+ list->first = list->last = NULL;
+}
+
+RenderAPIObjectHolder *RenderAPI_initialize_object_holder( Object *object )
+{
+ RenderAPIObjectHolder *holder;
+ /* create a blank object, fill with preliminary data */
+ holder = MEM_mallocN( sizeof(RenderAPIObjectHolder),
+ "renderAPI object holder" );
+ holder->source = object;
+ holder->original = NULL;
+ holder->name = object->id.name;
+ Mat4CpyMat4( holder->transformation, object->obmat );
+ return holder;
+}
+
void RenderAPI_free( RNDScene scene ){
+ BLI_freelistN( &scene->objects );
+ BLI_freelistN( &scene->originals );
MEM_freeN( scene );
}
void RenderAPI_create_object_index( RNDScene scene, unsigned int type ){
+ RenderAPIObjectHolder *object;
+ ListBase group_duplicators; /* a list of group duplicator
+ RenderAPIObjectHolders */
+ ListBase lights, meshes, nurbs, curves, metaballs; /* for pooling objects
+ by type. */
+ Base *current_base;
+
+ /* Initialize variables */
+ RenderAPI_empty_list( &group_duplicators );
+ RenderAPI_empty_list( &lights );
+ RenderAPI_empty_list( &meshes );
+ RenderAPI_empty_list( &nurbs );
+ RenderAPI_empty_list( &curves );
+ RenderAPI_empty_list( &metaballs );
+
+ /* Loop through source scene, filter out non-rendered, gather pools of
+ all rendered types, gather pool of dupli-groups duplicators. */
+ current_base = scene->source->base.first;
+ for( ; current_base; current_base = current_base->next )
+ {
+ if( RenderAPI_is_rendered( scene, current_base ) )
+ {
+ /* index group duplicators
+ (group duplicatees are the only duplicatees which don't contain
+ enough information to produce the duplicates themselves, this is
+ why they are singled out for indexing) */
+ if( current_base->object->dup_group != NULL ){
+ object = RenderAPI_initialize_object_holder(
+ current_base->object );
+ BLI_addtail( &group_duplicators, object );
+ }
+
+ /* pool with objects of the same type */
+ switch(current_base->object->type){
+
+ case OB_LAMP:
+ object = RenderAPI_initialize_object_holder( current_base->object );
+ BLI_addtail( &lights, object );
+ break;
+
+ case OB_MESH:
+ object = RenderAPI_initialize_object_holder( current_base->object );
+ BLI_addtail( &meshes, object );
+ break;
+
+ case OB_SURF:
+ object = RenderAPI_initialize_object_holder( current_base->object );
+ BLI_addtail( &nurbs, object );
+ break;
+
+ case OB_CURVE:
+ case OB_FONT:
+ object = RenderAPI_initialize_object_holder( current_base->object );
+ BLI_addtail( &curves, object );
+ break;
+
+ case OB_MBALL:
+ object = RenderAPI_initialize_object_holder( current_base->object );
+ BLI_addtail( &metaballs, object );
+ break;
+
+ default: break;
+ }
+ }
+ }
- Base *current_base = scene->source->base.first;
+ /* if specified, calculate instance information */
+ if( type & RND_INSTANCE ){
+ RenderAPI_calculate_instances( scene, lights );
+ RenderAPI_calculate_instances( scene, meshes );
+ RenderAPI_calculate_instances( scene, nurbs );
+ RenderAPI_calculate_instances( scene, curves );
+ RenderAPI_calculate_instances( scene, metaballs );
+ }
- for( ; current_base; current_base = current_base->next ){
- if( RenderAPI_is_rendered( scene, current_base ) )
- fprintf(stderr,"rendered: %s\n",current_base->object->id.name);
- else
- fprintf(stderr,"ignored: %s\n",current_base->object->id.name);
- }
+ /* combine all types into a single index, and store in scene->objects */
+ addlisttolist( &scene->objects, &lights );
+ addlisttolist( &scene->objects, &meshes );
+ addlisttolist( &scene->objects, &nurbs );
+ addlisttolist( &scene->objects, &curves );
+ addlisttolist( &scene->objects, &metaballs );
+
+ BLI_freelistN( &group_duplicators );
}
+/* Returns true if the object is rendered in the scene
+ */
int RenderAPI_is_rendered( RNDScene scene, Base *base )
{
- /* dupligroup duplicators should be marked here, because they
- can't be accessed if they are filtered out */
-
- /* object type is not renderable */
- if( !(base->object->type == OB_LAMP ||
- base->object->type == OB_MESH ||
- base->object->type == OB_SURF ||
- base->object->type == OB_CURVE ||
- base->object->type == OB_FONT ||
- base->object->type == OB_MBALL) )
+ /* object was restricted from rendering in the outliner */
+ if( base->object->restrictflag & OB_RESTRICT_RENDER )
return 0;
/* object is not on a rendered layer */
if( !(scene->source->lay & base->lay) )
return 0;
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list