* Added Main.add_object(type, name)

* Added optional params to Object.create_render_mesh(apply_matrix, custom_matrix)
  apply_matrix is a boolean, True to transform mesh by ob->obmat or custom_matrix if given
* Fix subtle error in Object.create_dupli_list
* Make RNA struct funcs static, hopefully didn't miss any

Ignore export_obj-2.5.py changes for now ;)
This commit is contained in:
Arystanbek Dyussenov 2009-06-20 16:32:52 +00:00
parent a7f914d25a
commit 705fbec768
3 changed files with 95 additions and 15 deletions

@ -347,6 +347,17 @@ EXPORT_POLYGROUPS=False, EXPORT_CURVE_AS_NURBS=True):
face_vert_index = 1
globalNormals = {}
for ob_main in objects:
if ob_main.dupli_type != 'NONE':
ob_main.create_dupli_list()
if ob_main.parent:
pass
if ob_main.dupli_type != 'NONE':
ob_main.free_dupli_list()
# Get all meshes
for ob_main in objects:

@ -32,22 +32,25 @@
#include "RNA_define.h"
#include "RNA_types.h"
#include "DNA_object_types.h"
#ifdef RNA_RUNTIME
#include "BKE_main.h"
#include "BKE_mesh.h"
#include "BKE_library.h"
#include "BKE_object.h"
#include "DNA_mesh_types.h"
Mesh *rna_Main_add_mesh(Main *main, char *name)
static Mesh *rna_Main_add_mesh(Main *main, char *name)
{
Mesh *me= add_mesh(name);
me->id.us--;
return me;
}
void rna_Main_remove_mesh(Main *main, ReportList *reports, Mesh *me)
static void rna_Main_remove_mesh(Main *main, ReportList *reports, Mesh *me)
{
if(me->id.us == 0)
free_libblock(&main->mesh, me);
@ -57,24 +60,55 @@ void rna_Main_remove_mesh(Main *main, ReportList *reports, Mesh *me)
/* XXX python now has invalid pointer? */
}
static Object* rna_Main_add_object(Main *main, int type, char *name)
{
return add_only_object(type, name);
}
#else
void RNA_api_main(StructRNA *srna)
{
FunctionRNA *func;
PropertyRNA *prop;
PropertyRNA *parm;
/* copied from rna_def_object */
static EnumPropertyItem object_type_items[] = {
{OB_EMPTY, "EMPTY", 0, "Empty", ""},
{OB_MESH, "MESH", 0, "Mesh", ""},
{OB_CURVE, "CURVE", 0, "Curve", ""},
{OB_SURF, "SURFACE", 0, "Surface", ""},
{OB_FONT, "TEXT", 0, "Text", ""},
{OB_MBALL, "META", 0, "Meta", ""},
{OB_LAMP, "LAMP", 0, "Lamp", ""},
{OB_CAMERA, "CAMERA", 0, "Camera", ""},
{OB_WAVE, "WAVE", 0, "Wave", ""},
{OB_LATTICE, "LATTICE", 0, "Lattice", ""},
{OB_ARMATURE, "ARMATURE", 0, "Armature", ""},
{0, NULL, 0, NULL, NULL}};
func= RNA_def_function(srna, "add_object", "rna_Main_add_object");
RNA_def_function_ui_description(func, "Add a new object.");
parm= RNA_def_enum(func, "type", object_type_items, 0, "Type", "Type of Object.");
RNA_def_property_flag(parm, PROP_REQUIRED);
parm= RNA_def_string(func, "name", "Object", 0, "", "New name for the datablock.");
RNA_def_property_flag(parm, PROP_REQUIRED);
parm= RNA_def_pointer(func, "object", "Object", "", "New object.");
RNA_def_function_return(func, parm);
func= RNA_def_function(srna, "add_mesh", "rna_Main_add_mesh");
RNA_def_function_ui_description(func, "Add a new mesh.");
prop= RNA_def_string(func, "name", "Mesh", 0, "", "New name for the datablock.");
prop= RNA_def_pointer(func, "mesh", "Mesh", "", "New mesh.");
RNA_def_function_return(func, prop);
parm= RNA_def_string(func, "name", "Mesh", 0, "", "New name for the datablock.");
RNA_def_property_flag(parm, PROP_REQUIRED);
parm= RNA_def_pointer(func, "mesh", "Mesh", "", "New mesh.");
RNA_def_function_return(func, parm);
func= RNA_def_function(srna, "remove_mesh", "rna_Main_remove_mesh");
RNA_def_function_flag(func, FUNC_USE_REPORTS);
RNA_def_function_ui_description(func, "Remove a mesh if it has zero users.");
prop= RNA_def_pointer(func, "mesh", "Mesh", "", "Mesh to remove.");
RNA_def_property_flag(prop, PROP_REQUIRED);
parm= RNA_def_pointer(func, "mesh", "Mesh", "", "Mesh to remove.");
RNA_def_property_flag(parm, PROP_REQUIRED);
}
#endif

@ -32,6 +32,8 @@
#include "RNA_define.h"
#include "RNA_types.h"
#include "DNA_object_types.h"
#ifdef RNA_RUNTIME
#include "BKE_customdata.h"
@ -41,17 +43,19 @@
#include "DNA_mesh_types.h"
#include "DNA_scene_types.h"
#include "DNA_object_types.h"
#include "DNA_meshdata_types.h"
#define OBJECT_API_PROP_DUPLILIST "dupli_list"
/* copied from init_render_mesh (render code) */
Mesh *rna_Object_create_render_mesh(Object *ob, bContext *C, ReportList *reports)
static Mesh *rna_Object_create_render_mesh(Object *ob, bContext *C, ReportList *reports, int apply_matrix, float *matrix)
{
CustomDataMask mask = CD_MASK_BAREMESH|CD_MASK_MTFACE|CD_MASK_MCOL;
DerivedMesh *dm;
Mesh *me;
Scene *sce;
int a;
MVert *mvert;
sce= CTX_data_scene(C);
@ -73,11 +77,25 @@ Mesh *rna_Object_create_render_mesh(Object *ob, bContext *C, ReportList *reports
DM_to_mesh(dm, me);
dm->release(dm);
if (apply_matrix) {
float *mat = ob->obmat;
if (matrix) {
/* apply custom matrix */
mat = matrix;
}
/* is this really that simple? :) */
for(a= 0, mvert= me->mvert; a < me->totvert; a++, mvert++) {
Mat4MulVecfl(ob->obmat, mvert->co);
}
}
return me;
}
/* When no longer needed, duplilist should be freed with Object.free_duplilist */
void rna_Object_create_duplilist(Object *ob, bContext *C, ReportList *reports)
static void rna_Object_create_duplilist(Object *ob, bContext *C, ReportList *reports)
{
PointerRNA obptr;
PointerRNA dobptr;
@ -96,7 +114,7 @@ void rna_Object_create_duplilist(Object *ob, bContext *C, ReportList *reports)
if (!(prop= RNA_struct_find_property(&obptr, OBJECT_API_PROP_DUPLILIST))) {
// hint: all Objects will now have this property defined
prop= RNA_def_collection_runtime(obptr.type, OBJECT_API_PROP_DUPLILIST, "DupliObject", "Dupli list", "List of object's duplis");
prop= RNA_def_collection_runtime(obptr.type, OBJECT_API_PROP_DUPLILIST, &RNA_DupliObject, "Dupli list", "List of object's duplis");
}
RNA_property_collection_clear(&obptr, prop);
@ -109,11 +127,9 @@ void rna_Object_create_duplilist(Object *ob, bContext *C, ReportList *reports)
}
/* ob->duplilist should now be freed with Object.free_duplilist */
return *((CollectionPropertyRNA*)prop);
}
void rna_Object_free_duplilist(Object *ob, ReportList *reports)
static void rna_Object_free_duplilist(Object *ob, ReportList *reports)
{
PointerRNA obptr;
PropertyRNA *prop;
@ -138,9 +154,28 @@ void RNA_api_object(StructRNA *srna)
FunctionRNA *func;
PropertyRNA *parm;
/* copied from rna_def_object */
static EnumPropertyItem object_type_items[] = {
{OB_EMPTY, "EMPTY", 0, "Empty", ""},
{OB_MESH, "MESH", 0, "Mesh", ""},
{OB_CURVE, "CURVE", 0, "Curve", ""},
{OB_SURF, "SURFACE", 0, "Surface", ""},
{OB_FONT, "TEXT", 0, "Text", ""},
{OB_MBALL, "META", 0, "Meta", ""},
{OB_LAMP, "LAMP", 0, "Lamp", ""},
{OB_CAMERA, "CAMERA", 0, "Camera", ""},
{OB_WAVE, "WAVE", 0, "Wave", ""},
{OB_LATTICE, "LATTICE", 0, "Lattice", ""},
{OB_ARMATURE, "ARMATURE", 0, "Armature", ""},
{0, NULL, 0, NULL, NULL}};
func= RNA_def_function(srna, "create_render_mesh", "rna_Object_create_render_mesh");
RNA_def_function_ui_description(func, "Create a Mesh datablock with all modifiers applied.");
RNA_def_function_flag(func, FUNC_USE_CONTEXT|FUNC_USE_REPORTS);
parm= RNA_def_boolean(func, "apply_matrix", 0, "", "True if object matrix or custom matrix should be applied to geometry.");
RNA_def_property_clear_flag(parm, PROP_REQUIRED);
parm= RNA_def_float_matrix(func, "custom_matrix", 16, NULL, 0.0f, 0.0f, "", "Optional custom matrix to apply.", 0.0f, 0.0f);
RNA_def_property_clear_flag(parm, PROP_REQUIRED);
parm= RNA_def_pointer(func, "mesh", "Mesh", "", "Mesh created from object, remove it if it is only used for export.");
RNA_def_function_return(func, parm);