Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorArystanbek Dyussenov <arystan.d@gmail.com>2009-06-24 23:23:34 +0400
committerArystanbek Dyussenov <arystan.d@gmail.com>2009-06-24 23:23:34 +0400
commit3f2fef55c2bbeb1f837b48c76263e3e035d56792 (patch)
tree49b7dd1f984f2e816ff22e6d3f09a74680f83746 /source
parentd2a5bbdc2c04973f5a9e65003f70cbe336b87ad0 (diff)
- added API functions:
* Main.remove_object * Scene.add_object * Scene.remove_object * Object.convert_to_triface * Object.create_preview_mesh - a small tweak in set_mesh (blenkernel/inter/mesh.c) to make it work on objects having data == NULL
Diffstat (limited to 'source')
-rw-r--r--source/blender/blenkernel/intern/mesh.c3
-rw-r--r--source/blender/makesrna/intern/makesrna.c2
-rw-r--r--source/blender/makesrna/intern/rna_main_api.c33
-rw-r--r--source/blender/makesrna/intern/rna_mesh_api.c3
-rw-r--r--source/blender/makesrna/intern/rna_object_api.c91
-rw-r--r--source/blender/makesrna/intern/rna_scene.c2
-rw-r--r--source/blender/makesrna/intern/rna_scene_api.c91
7 files changed, 191 insertions, 34 deletions
diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c
index 3facf975992..9fc8d0ed609 100644
--- a/source/blender/blenkernel/intern/mesh.c
+++ b/source/blender/blenkernel/intern/mesh.c
@@ -542,7 +542,8 @@ void set_mesh(Object *ob, Mesh *me)
if(ob->type==OB_MESH) {
old= ob->data;
- old->id.us--;
+ if (old) /* to make set_mesh work on objects created with add_only_object, i.e. having ob->data == NULL */
+ old->id.us--;
ob->data= me;
id_us_plus((ID *)me);
}
diff --git a/source/blender/makesrna/intern/makesrna.c b/source/blender/makesrna/intern/makesrna.c
index e7ca3fc5932..f7bf176a325 100644
--- a/source/blender/makesrna/intern/makesrna.c
+++ b/source/blender/makesrna/intern/makesrna.c
@@ -1853,7 +1853,7 @@ RNAProcessItem PROCESS_ITEMS[]= {
{"rna_particle.c", NULL, RNA_def_particle},
{"rna_pose.c", NULL, RNA_def_pose},
{"rna_property.c", NULL, RNA_def_gameproperty},
- {"rna_scene.c", NULL, RNA_def_scene},
+ {"rna_scene.c", "rna_scene_api.c", RNA_def_scene},
{"rna_screen.c", NULL, RNA_def_screen},
{"rna_scriptlink.c", NULL, RNA_def_scriptlink},
{"rna_sensor.c", NULL, RNA_def_sensor},
diff --git a/source/blender/makesrna/intern/rna_main_api.c b/source/blender/makesrna/intern/rna_main_api.c
index 2c78884a027..08a3b7cee25 100644
--- a/source/blender/makesrna/intern/rna_main_api.c
+++ b/source/blender/makesrna/intern/rna_main_api.c
@@ -62,7 +62,29 @@ static void rna_Main_remove_mesh(Main *main, ReportList *reports, Mesh *me)
static Object* rna_Main_add_object(Main *main, int type, char *name)
{
- return add_only_object(type, name);
+ Object *ob= add_only_object(type, name);
+ ob->id.us--;
+ return ob;
+}
+
+/*
+ WARNING: the following example shows when this function should not be called
+
+ ob = bpy.data.add_object()
+ scene.add_object(ob)
+
+ # ob is freed here
+ scene.remove_object(ob)
+
+ # don't do this since ob is already freed!
+ bpy.data.remove_object(ob)
+*/
+static void rna_Main_remove_object(Main *main, ReportList *reports, Object *ob)
+{
+ if(ob->id.us == 0)
+ free_libblock(&main->object, ob);
+ else
+ BKE_report(reports, RPT_ERROR, "Object must have zero users to be removed.");
}
#else
@@ -89,13 +111,19 @@ void RNA_api_main(StructRNA *srna)
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.");
+ parm= RNA_def_enum(func, "type", object_type_items, 0, "", "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, "remove_object", "rna_Main_remove_object");
+ RNA_def_function_flag(func, FUNC_USE_REPORTS);
+ RNA_def_function_ui_description(func, "Remove an object if it has zero users.");
+ parm= RNA_def_pointer(func, "object", "Object", "", "Object to remove.");
+ RNA_def_property_flag(parm, PROP_REQUIRED);
+
func= RNA_def_function(srna, "add_mesh", "rna_Main_add_mesh");
RNA_def_function_ui_description(func, "Add a new mesh.");
parm= RNA_def_string(func, "name", "Mesh", 0, "", "New name for the datablock.");
@@ -108,7 +136,6 @@ void RNA_api_main(StructRNA *srna)
RNA_def_function_ui_description(func, "Remove a mesh if it has zero users.");
parm= RNA_def_pointer(func, "mesh", "Mesh", "", "Mesh to remove.");
RNA_def_property_flag(parm, PROP_REQUIRED);
-
}
#endif
diff --git a/source/blender/makesrna/intern/rna_mesh_api.c b/source/blender/makesrna/intern/rna_mesh_api.c
index 0aa4faeddd8..984e6a5d30f 100644
--- a/source/blender/makesrna/intern/rna_mesh_api.c
+++ b/source/blender/makesrna/intern/rna_mesh_api.c
@@ -36,6 +36,7 @@
#include "BKE_customdata.h"
#include "BKE_DerivedMesh.h"
+#include "BLI_arithb.h"
#include "DNA_mesh_types.h"
#include "DNA_scene_types.h"
@@ -60,7 +61,7 @@ void rna_Mesh_transform(Mesh *me, float *mat)
int i;
MVert *mvert= me->mvert;
- for(i= 0; i < mesh->totvert; i++, mvert++) {
+ for(i= 0; i < me->totvert; i++, mvert++) {
Mat4MulVecfl(mat, mvert->co);
}
}
diff --git a/source/blender/makesrna/intern/rna_object_api.c b/source/blender/makesrna/intern/rna_object_api.c
index 69d3f48761c..5af12b696c4 100644
--- a/source/blender/makesrna/intern/rna_object_api.c
+++ b/source/blender/makesrna/intern/rna_object_api.c
@@ -28,6 +28,8 @@
#include <stdlib.h>
#include <stdio.h>
+#include <string.h>
+#include <time.h>
#include "RNA_define.h"
#include "RNA_types.h"
@@ -40,6 +42,7 @@
#include "BKE_DerivedMesh.h"
#include "BKE_anim.h"
#include "BKE_report.h"
+#include "BKE_depsgraph.h"
#include "DNA_mesh_types.h"
#include "DNA_scene_types.h"
@@ -47,15 +50,17 @@
#include "BLI_arithb.h"
+#include "BLO_sys_types.h" /* needed for intptr_t used in ED_mesh.h */
+
+#include "ED_mesh.h"
+
/* copied from init_render_mesh (render code) */
-static Mesh *rna_Object_create_render_mesh(Object *ob, bContext *C, ReportList *reports, int apply_matrix, float *matrix)
+static Mesh *create_mesh(Object *ob, bContext *C, ReportList *reports, int render_mesh)
{
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);
@@ -65,7 +70,7 @@ static Mesh *rna_Object_create_render_mesh(Object *ob, bContext *C, ReportList *
return NULL;
}
- dm= mesh_create_derived_render(sce, ob, mask);
+ dm= render_mesh ? mesh_create_derived_render(sce, ob, mask) : mesh_create_derived_view(sce, ob, mask);
if(!dm) {
/* TODO: report */
@@ -77,21 +82,17 @@ static Mesh *rna_Object_create_render_mesh(Object *ob, bContext *C, ReportList *
DM_to_mesh(dm, me);
dm->release(dm);
- if (apply_matrix) {
- float *mat = (float*)ob->obmat;
-
- if (matrix) {
- /* apply custom matrix */
- mat = matrix;
- }
+ return me;
+}
- /* is this really that simple? :) */
- for(a= 0, mvert= me->mvert; a < me->totvert; a++, mvert++) {
- Mat4MulVecfl(ob->obmat, mvert->co);
- }
- }
+static Mesh *rna_Object_create_render_mesh(Object *ob, bContext *C, ReportList *reports)
+{
+ return create_mesh(ob, C, reports, 1);
+}
- return me;
+static Mesh *rna_Object_create_preview_mesh(Object *ob, bContext *C, ReportList *reports)
+{
+ return create_mesh(ob, C, reports, 0);
}
/* When no longer needed, duplilist should be freed with Object.free_duplilist */
@@ -102,9 +103,9 @@ static void rna_Object_create_duplilist(Object *ob, bContext *C, ReportList *rep
return;
}
- /* free duplilist if a user forget to */
+ /* free duplilist if a user forgets to */
if (ob->duplilist) {
- BKE_report(reports, RPT_WARNING, "%s.dupli_list has not been freed.", RNA_struct_identifier(&RNA_Object));
+ BKE_reportf(reports, RPT_WARNING, "%s.dupli_list has not been freed.", RNA_struct_identifier(&RNA_Object));
free_object_duplilist(ob->duplilist);
ob->duplilist= NULL;
@@ -117,15 +118,41 @@ static void rna_Object_create_duplilist(Object *ob, bContext *C, ReportList *rep
static void rna_Object_free_duplilist(Object *ob, ReportList *reports)
{
- PointerRNA obptr;
- PropertyRNA *prop;
-
if (ob->duplilist) {
free_object_duplilist(ob->duplilist);
ob->duplilist= NULL;
}
}
+static void rna_Object_convert_to_triface(Object *ob, bContext *C, ReportList *reports, Scene *sce)
+{
+ Mesh *me;
+ int ob_editing = CTX_data_edit_object(C) == ob;
+
+ if (ob->type != OB_MESH) {
+ BKE_report(reports, RPT_ERROR, "Object should be of type MESH.");
+ return;
+ }
+
+ me= (Mesh*)ob->data;
+
+ if (!ob_editing)
+ make_editMesh(sce, ob);
+
+ /* select all */
+ EM_set_flag_all(me->edit_mesh, SELECT);
+
+ convert_to_triface(me->edit_mesh, 0);
+
+ load_editMesh(sce, ob);
+
+ if (!ob_editing)
+ free_editMesh(me->edit_mesh);
+
+ DAG_object_flush_update(sce, ob, OB_RECALC_DATA);
+}
+
+
#else
void RNA_api_object(StructRNA *srna)
@@ -149,22 +176,30 @@ void RNA_api_object(StructRNA *srna)
{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_ui_description(func, "Create a Mesh datablock with all modifiers applied for rendering.");
+ RNA_def_function_flag(func, FUNC_USE_CONTEXT|FUNC_USE_REPORTS);
+ 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);
+
+ func= RNA_def_function(srna, "create_preview_mesh", "rna_Object_create_preview_mesh");
+ RNA_def_function_ui_description(func, "Create a Mesh datablock with all modifiers applied for preview.");
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);
func= RNA_def_function(srna, "create_dupli_list", "rna_Object_create_duplilist");
- RNA_def_function_ui_description(func, "Create a list of dupli objects for this object. When no longer needed, it should be freed with free_dupli_list.");
+ RNA_def_function_ui_description(func, "Create a list of dupli objects for this object, needs to be freed manually with free_dupli_list.");
RNA_def_function_flag(func, FUNC_USE_CONTEXT|FUNC_USE_REPORTS);
func= RNA_def_function(srna, "free_dupli_list", "rna_Object_free_duplilist");
RNA_def_function_ui_description(func, "Free the list of dupli objects.");
RNA_def_function_flag(func, FUNC_USE_REPORTS);
+
+ func= RNA_def_function(srna, "convert_to_triface", "rna_Object_convert_to_triface");
+ RNA_def_function_ui_description(func, "Convert all mesh faces to triangles.");
+ RNA_def_function_flag(func, FUNC_USE_CONTEXT|FUNC_USE_REPORTS);
+ parm= RNA_def_pointer(func, "scene", "Scene", "", "Scene where the object is.");
+ RNA_def_property_flag(parm, PROP_REQUIRED);
}
#endif
diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c
index 47c9025149a..1017703c56b 100644
--- a/source/blender/makesrna/intern/rna_scene.c
+++ b/source/blender/makesrna/intern/rna_scene.c
@@ -1018,6 +1018,8 @@ void RNA_def_scene(BlenderRNA *brna)
rna_def_tool_settings(brna);
rna_def_scene_render_data(brna);
+
+ RNA_api_scene(srna);
}
#endif
diff --git a/source/blender/makesrna/intern/rna_scene_api.c b/source/blender/makesrna/intern/rna_scene_api.c
new file mode 100644
index 00000000000..a38622b48ae
--- /dev/null
+++ b/source/blender/makesrna/intern/rna_scene_api.c
@@ -0,0 +1,91 @@
+/**
+ * $Id: rna_object_api.c 21115 2009-06-23 19:17:59Z kazanbas $
+ *
+ * ***** BEGIN GPL 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.
+ *
+ * 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) 2009 Blender Foundation.
+ * All rights reserved.
+ *
+ *
+ * Contributor(s): Blender Foundation
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "RNA_define.h"
+#include "RNA_types.h"
+
+#include "DNA_object_types.h"
+
+#ifdef RNA_RUNTIME
+
+#include "BKE_scene.h"
+#include "ED_object.h"
+
+static void rna_Scene_add_object(Scene *sce, ReportList *reports, Object *ob)
+{
+ Base *base= object_in_scene(ob, sce);
+ if (base) {
+ BKE_report(reports, RPT_ERROR, "Object is already in this scene.");
+ return;
+ }
+ base= scene_add_base(sce, ob);
+ ob->id.us++;
+
+ /* this is similar to what object_add_type and add_object do */
+ ob->lay= base->lay= sce->lay;
+ ob->recalc |= OB_RECALC;
+
+ DAG_scene_sort(sce);
+}
+
+static void rna_Scene_remove_object(Scene *sce, ReportList *reports, Object *ob)
+{
+ Base *base= object_in_scene(ob, sce);
+ if (!base) {
+ BKE_report(reports, RPT_ERROR, "Object is not in this scene.");
+ return;
+ }
+ /* as long as ED_base_object_free_and_unlink calls free_libblock_us, we don't have to decrement ob->id.us */
+ ED_base_object_free_and_unlink(sce, base);
+}
+
+#else
+
+void RNA_api_scene(StructRNA *srna)
+{
+ FunctionRNA *func;
+ PropertyRNA *parm;
+
+ func= RNA_def_function(srna, "add_object", "rna_Scene_add_object");
+ RNA_def_function_ui_description(func, "Add object to scene.");
+ RNA_def_function_flag(func, FUNC_USE_REPORTS);
+ parm= RNA_def_pointer(func, "object", "Object", "", "Object to add to scene.");
+ RNA_def_property_flag(parm, PROP_REQUIRED);
+
+ func= RNA_def_function(srna, "remove_object", "rna_Scene_remove_object");
+ RNA_def_function_ui_description(func, "Remove object from scene.");
+ RNA_def_function_flag(func, FUNC_USE_REPORTS);
+ parm= RNA_def_pointer(func, "object", "Object", "", "Object to remove from scene.");
+ RNA_def_property_flag(parm, PROP_REQUIRED);
+}
+
+#endif
+