2009-06-18 19:48:55 +00:00
|
|
|
/**
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* ***** 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>
|
2009-06-24 19:23:34 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <time.h>
|
2009-06-18 19:48:55 +00:00
|
|
|
|
|
|
|
#include "RNA_define.h"
|
|
|
|
#include "RNA_types.h"
|
|
|
|
|
2009-06-20 16:32:52 +00:00
|
|
|
#include "DNA_object_types.h"
|
|
|
|
|
2009-07-01 18:23:11 +00:00
|
|
|
#include "BLO_sys_types.h" /* needed for intptr_t used in ED_mesh.h */
|
|
|
|
|
|
|
|
#include "ED_mesh.h"
|
|
|
|
|
2009-06-28 13:29:03 +00:00
|
|
|
/* parameter to rna_Object_create_mesh */
|
|
|
|
typedef enum CreateMeshType {
|
|
|
|
CREATE_MESH_PREVIEW = 0,
|
|
|
|
CREATE_MESH_RENDER = 1
|
|
|
|
} CreateMeshType;
|
|
|
|
|
2009-06-18 19:48:55 +00:00
|
|
|
#ifdef RNA_RUNTIME
|
|
|
|
|
|
|
|
#include "BKE_customdata.h"
|
|
|
|
#include "BKE_DerivedMesh.h"
|
2009-06-19 10:40:18 +00:00
|
|
|
#include "BKE_anim.h"
|
|
|
|
#include "BKE_report.h"
|
2009-06-24 19:23:34 +00:00
|
|
|
#include "BKE_depsgraph.h"
|
2009-06-18 19:48:55 +00:00
|
|
|
|
|
|
|
#include "DNA_mesh_types.h"
|
|
|
|
#include "DNA_scene_types.h"
|
2009-06-20 16:32:52 +00:00
|
|
|
#include "DNA_meshdata_types.h"
|
2009-06-18 19:48:55 +00:00
|
|
|
|
2009-06-23 17:52:58 +00:00
|
|
|
#include "BLI_arithb.h"
|
2009-06-19 12:46:51 +00:00
|
|
|
|
2009-06-18 19:48:55 +00:00
|
|
|
/* copied from init_render_mesh (render code) */
|
2009-06-28 13:29:03 +00:00
|
|
|
static Mesh *rna_Object_create_mesh(Object *ob, bContext *C, ReportList *reports, int type)
|
2009-06-18 19:48:55 +00:00
|
|
|
{
|
2009-06-26 12:33:07 +00:00
|
|
|
/* CustomDataMask mask = CD_MASK_BAREMESH|CD_MASK_MTFACE|CD_MASK_MCOL; */
|
|
|
|
CustomDataMask mask = CD_MASK_MESH; /* this seems more suitable, exporter,
|
|
|
|
for example, needs CD_MASK_MDEFORMVERT */
|
2009-06-18 19:48:55 +00:00
|
|
|
DerivedMesh *dm;
|
|
|
|
Mesh *me;
|
2009-06-20 05:52:19 +00:00
|
|
|
Scene *sce;
|
|
|
|
|
|
|
|
sce= CTX_data_scene(C);
|
2009-06-18 19:48:55 +00:00
|
|
|
|
|
|
|
/* TODO: other types */
|
2009-06-20 05:52:19 +00:00
|
|
|
if(ob->type != OB_MESH) {
|
|
|
|
BKE_report(reports, RPT_ERROR, "Object should be of type MESH.");
|
2009-06-18 19:48:55 +00:00
|
|
|
return NULL;
|
2009-06-20 05:52:19 +00:00
|
|
|
}
|
2009-06-28 13:29:03 +00:00
|
|
|
|
|
|
|
if (type == CREATE_MESH_PREVIEW) {
|
|
|
|
dm= mesh_create_derived_view(sce, ob, mask);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
dm= mesh_create_derived_render(sce, ob, mask);
|
|
|
|
}
|
2009-06-18 19:48:55 +00:00
|
|
|
|
2009-06-20 05:52:19 +00:00
|
|
|
if(!dm) {
|
|
|
|
/* TODO: report */
|
2009-06-18 19:48:55 +00:00
|
|
|
return NULL;
|
2009-06-20 05:52:19 +00:00
|
|
|
}
|
2009-06-18 19:48:55 +00:00
|
|
|
|
|
|
|
me= add_mesh("tmp_render_mesh");
|
|
|
|
me->id.us--; /* we don't assign it to anything */
|
|
|
|
DM_to_mesh(dm, me);
|
|
|
|
dm->release(dm);
|
|
|
|
|
2009-06-24 19:23:34 +00:00
|
|
|
return me;
|
|
|
|
}
|
2009-06-20 16:32:52 +00:00
|
|
|
|
2009-06-19 10:40:18 +00:00
|
|
|
/* When no longer needed, duplilist should be freed with Object.free_duplilist */
|
2009-06-20 16:32:52 +00:00
|
|
|
static void rna_Object_create_duplilist(Object *ob, bContext *C, ReportList *reports)
|
2009-06-19 10:40:18 +00:00
|
|
|
{
|
|
|
|
if (!(ob->transflag & OB_DUPLI)) {
|
|
|
|
BKE_report(reports, RPT_ERROR, "Object does not have duplis.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-06-24 19:23:34 +00:00
|
|
|
/* free duplilist if a user forgets to */
|
2009-06-23 17:52:58 +00:00
|
|
|
if (ob->duplilist) {
|
2009-07-01 18:23:11 +00:00
|
|
|
BKE_reportf(reports, RPT_WARNING, "Object.dupli_list has not been freed.");
|
2009-06-19 10:40:18 +00:00
|
|
|
|
2009-06-23 17:52:58 +00:00
|
|
|
free_object_duplilist(ob->duplilist);
|
|
|
|
ob->duplilist= NULL;
|
2009-06-19 10:40:18 +00:00
|
|
|
}
|
|
|
|
|
2009-06-23 17:52:58 +00:00
|
|
|
ob->duplilist= object_duplilist(CTX_data_scene(C), ob);
|
2009-06-19 10:40:18 +00:00
|
|
|
|
2009-06-19 12:46:51 +00:00
|
|
|
/* ob->duplilist should now be freed with Object.free_duplilist */
|
2009-06-19 10:40:18 +00:00
|
|
|
}
|
|
|
|
|
2009-06-20 16:32:52 +00:00
|
|
|
static void rna_Object_free_duplilist(Object *ob, ReportList *reports)
|
2009-06-19 10:40:18 +00:00
|
|
|
{
|
2009-06-20 20:08:11 +00:00
|
|
|
if (ob->duplilist) {
|
|
|
|
free_object_duplilist(ob->duplilist);
|
|
|
|
ob->duplilist= NULL;
|
|
|
|
}
|
2009-06-19 10:40:18 +00:00
|
|
|
}
|
|
|
|
|
2009-06-24 19:23:34 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2009-07-01 18:23:11 +00:00
|
|
|
static int rna_Object_add_vertex_group(Object *ob, char *group_name)
|
|
|
|
{
|
|
|
|
bDeformGroup *defgroup= add_defgroup_name(ob, group_name);
|
|
|
|
return BLI_findindex(&ob->defbase, defgroup);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
static void rna_Mesh_assign_verts_to_group(Object *ob, bDeformGroup *group, int *indices, int totindex, float weight, int assignmode)
|
|
|
|
{
|
|
|
|
if (ob->type != OB_MESH) {
|
|
|
|
BKE_report(reports, RPT_ERROR, "Object should be of MESH type.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Mesh *me = (Mesh*)ob->data;
|
|
|
|
int group_index = get_defgroup_num(ob, group);
|
|
|
|
if (group_index == -1) {
|
|
|
|
BKE_report(reports, RPT_ERROR, "No deform groups assigned to mesh.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (assignmode != WEIGHT_REPLACE && assignmode != WEIGHT_ADD && assignmode != WEIGHT_SUBTRACT) {
|
|
|
|
BKE_report(reports, RPT_ERROR, "Bad assignment mode." );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// makes a set of dVerts corresponding to the mVerts
|
|
|
|
if (!me->dvert)
|
|
|
|
create_dverts(&me->id);
|
|
|
|
|
|
|
|
// loop list adding verts to group
|
|
|
|
for (i= 0; i < totindex; i++) {
|
|
|
|
if(i < 0 || i >= me->totvert) {
|
|
|
|
BKE_report(reports, RPT_ERROR, "Bad vertex index in list.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
add_vert_defnr(ob, group_index, i, weight, assignmode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
2009-06-24 19:23:34 +00:00
|
|
|
|
2009-06-18 19:48:55 +00:00
|
|
|
#else
|
|
|
|
|
|
|
|
void RNA_api_object(StructRNA *srna)
|
|
|
|
{
|
|
|
|
FunctionRNA *func;
|
2009-06-19 10:40:18 +00:00
|
|
|
PropertyRNA *parm;
|
2009-06-18 19:48:55 +00:00
|
|
|
|
2009-06-28 13:29:03 +00:00
|
|
|
static EnumPropertyItem mesh_type_items[] = {
|
|
|
|
{CREATE_MESH_PREVIEW, "PREVIEW", 0, "Preview", "Apply preview settings."},
|
|
|
|
{CREATE_MESH_RENDER, "RENDER", 0, "Render", "Apply render settings."},
|
|
|
|
{0, NULL, 0, NULL, NULL}
|
|
|
|
};
|
2009-06-24 19:23:34 +00:00
|
|
|
|
2009-06-28 13:29:03 +00:00
|
|
|
func= RNA_def_function(srna, "create_mesh", "rna_Object_create_mesh");
|
|
|
|
RNA_def_function_ui_description(func, "Create a Mesh datablock with all modifiers applied.");
|
2009-06-20 05:52:19 +00:00
|
|
|
RNA_def_function_flag(func, FUNC_USE_CONTEXT|FUNC_USE_REPORTS);
|
2009-06-28 13:29:03 +00:00
|
|
|
parm= RNA_def_enum(func, "type", mesh_type_items, 0, "", "Type of mesh settings to apply.");
|
|
|
|
RNA_def_property_flag(parm, PROP_REQUIRED);
|
2009-06-19 10:40:18 +00:00
|
|
|
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);
|
2009-06-28 13:29:03 +00:00
|
|
|
|
2009-06-19 10:40:18 +00:00
|
|
|
func= RNA_def_function(srna, "create_dupli_list", "rna_Object_create_duplilist");
|
2009-06-24 19:23:34 +00:00
|
|
|
RNA_def_function_ui_description(func, "Create a list of dupli objects for this object, needs to be freed manually with free_dupli_list.");
|
2009-06-19 10:40:18 +00:00
|
|
|
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);
|
2009-06-24 19:23:34 +00:00
|
|
|
|
|
|
|
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);
|
2009-06-25 18:04:32 +00:00
|
|
|
parm= RNA_def_pointer(func, "scene", "Scene", "", "Scene where the object belongs.");
|
2009-06-24 19:23:34 +00:00
|
|
|
RNA_def_property_flag(parm, PROP_REQUIRED);
|
2009-07-01 18:23:11 +00:00
|
|
|
|
|
|
|
func= RNA_def_function(srna, "add_vertex_group", "rna_Object_add_vertex_group");
|
|
|
|
RNA_def_function_ui_description(func, "Add vertex group to object.");
|
|
|
|
parm= RNA_def_string(func, "name", "Group", 0, "", "Vertex group name.");
|
|
|
|
parm= RNA_def_int(func, "group_index", 0, 0, 0, "", "Index of the created vertex group.", 0, 0);
|
|
|
|
RNA_def_function_return(func, parm);
|
2009-06-18 19:48:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|