2011-02-23 10:52:22 +00:00
|
|
|
/*
|
2009-06-18 19:48:55 +00:00
|
|
|
* ***** 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,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2009-06-18 19:48:55 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2009 Blender Foundation.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Contributor(s): Blender Foundation
|
|
|
|
*
|
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
|
|
|
*/
|
|
|
|
|
2011-02-27 20:20:01 +00:00
|
|
|
/** \file blender/makesrna/intern/rna_object_api.c
|
|
|
|
* \ingroup RNA
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2009-06-18 19:48:55 +00:00
|
|
|
#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"
|
|
|
|
|
2009-06-20 16:32:52 +00:00
|
|
|
#include "DNA_object_types.h"
|
2011-03-16 08:53:35 +00:00
|
|
|
#include "DNA_modifier_types.h"
|
2009-06-20 16:32:52 +00:00
|
|
|
|
2010-08-27 02:33:35 +00:00
|
|
|
// #include "BLO_sys_types.h" /* needed for intptr_t used in ED_mesh.h */
|
2009-07-01 18:23:11 +00:00
|
|
|
|
2010-08-27 02:33:35 +00:00
|
|
|
// #include "ED_mesh.h"
|
2009-07-01 18:23:11 +00:00
|
|
|
|
2011-07-19 15:21:21 +00:00
|
|
|
|
2009-06-18 19:48:55 +00:00
|
|
|
#ifdef RNA_RUNTIME
|
2011-08-04 13:22:38 +00:00
|
|
|
#include "BLI_math.h"
|
2009-06-18 19:48:55 +00:00
|
|
|
|
2009-07-16 13:19:43 +00:00
|
|
|
#include "BKE_main.h"
|
|
|
|
#include "BKE_global.h"
|
|
|
|
#include "BKE_context.h"
|
|
|
|
#include "BKE_report.h"
|
|
|
|
#include "BKE_object.h"
|
|
|
|
#include "BKE_mesh.h"
|
2009-06-18 19:48:55 +00:00
|
|
|
#include "BKE_DerivedMesh.h"
|
2010-01-02 15:31:02 +00:00
|
|
|
#include "BKE_bvhutils.h"
|
2009-07-28 01:06:56 +00:00
|
|
|
|
2009-06-18 19:48:55 +00:00
|
|
|
#include "BKE_customdata.h"
|
2009-06-19 10:40:18 +00:00
|
|
|
#include "BKE_anim.h"
|
2009-06-24 19:23:34 +00:00
|
|
|
#include "BKE_depsgraph.h"
|
2009-09-16 10:09:57 +00:00
|
|
|
#include "BKE_displist.h"
|
2009-07-16 13:19:43 +00:00
|
|
|
#include "BKE_font.h"
|
2009-09-16 15:55:00 +00:00
|
|
|
#include "BKE_mball.h"
|
2010-11-12 15:05:57 +00:00
|
|
|
#include "BKE_modifier.h"
|
2009-07-16 13:19:43 +00:00
|
|
|
|
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-07-16 13:19:43 +00:00
|
|
|
#include "DNA_curve_types.h"
|
2009-08-08 11:33:34 +00:00
|
|
|
#include "DNA_modifier_types.h"
|
2009-11-11 19:58:30 +00:00
|
|
|
#include "DNA_constraint_types.h"
|
2010-05-23 12:14:07 +00:00
|
|
|
#include "DNA_view3d_types.h"
|
2009-06-18 19:48:55 +00:00
|
|
|
|
2009-07-16 13:19:43 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
2009-06-18 19:48:55 +00:00
|
|
|
|
2009-07-16 13:19:43 +00:00
|
|
|
/* copied from Mesh_getFromObject and adapted to RNA interface */
|
|
|
|
/* settings: 0 - preview, 1 - render */
|
2011-08-16 18:59:45 +00:00
|
|
|
Mesh *rna_Object_to_mesh(Object *ob, ReportList *reports, Scene *sce, int apply_modifiers, int settings)
|
2009-06-18 19:48:55 +00:00
|
|
|
{
|
2009-07-16 13:19:43 +00:00
|
|
|
Mesh *tmpmesh;
|
|
|
|
Curve *tmpcu = NULL;
|
2009-09-16 10:09:57 +00:00
|
|
|
Object *tmpobj = NULL;
|
2011-03-16 08:53:35 +00:00
|
|
|
int render = settings == eModifierMode_Render, i;
|
2009-07-16 13:19:43 +00:00
|
|
|
int cage = !apply_modifiers;
|
|
|
|
|
|
|
|
/* perform the mesh extraction based on type */
|
2011-04-21 15:53:30 +00:00
|
|
|
switch (ob->type) {
|
|
|
|
case OB_FONT:
|
|
|
|
case OB_CURVE:
|
|
|
|
case OB_SURF:
|
2009-09-16 10:09:57 +00:00
|
|
|
|
|
|
|
/* copies object and modifiers (but not the data) */
|
2009-07-16 13:19:43 +00:00
|
|
|
tmpobj= copy_object(ob);
|
2009-09-16 10:09:57 +00:00
|
|
|
tmpcu = (Curve *)tmpobj->data;
|
|
|
|
tmpcu->id.us--;
|
|
|
|
|
|
|
|
/* if getting the original caged mesh, delete object modifiers */
|
|
|
|
if( cage )
|
|
|
|
object_free_modifiers(tmpobj);
|
|
|
|
|
|
|
|
/* copies the data */
|
|
|
|
tmpobj->data = copy_curve( (Curve *) ob->data );
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
/* copy_curve() sets disp.first null, so currently not need */
|
|
|
|
{
|
|
|
|
Curve *cu;
|
|
|
|
cu = (Curve *)tmpobj->data;
|
|
|
|
if( cu->disp.first )
|
|
|
|
MEM_freeN( cu->disp.first );
|
|
|
|
cu->disp.first = NULL;
|
|
|
|
}
|
2009-06-18 19:48:55 +00:00
|
|
|
|
2009-09-16 10:09:57 +00:00
|
|
|
#endif
|
2009-06-18 19:48:55 +00:00
|
|
|
|
2009-09-16 10:09:57 +00:00
|
|
|
/* get updated display list, and convert to a mesh */
|
2009-07-16 13:19:43 +00:00
|
|
|
makeDispListCurveTypes( sce, tmpobj, 0 );
|
2009-09-16 10:09:57 +00:00
|
|
|
nurbs_to_mesh( tmpobj );
|
2009-07-16 13:19:43 +00:00
|
|
|
|
|
|
|
/* nurbs_to_mesh changes the type to a mesh, check it worked */
|
2009-09-16 10:09:57 +00:00
|
|
|
if (tmpobj->type != OB_MESH) {
|
2010-04-06 01:28:39 +00:00
|
|
|
free_libblock_us( &(G.main->object), tmpobj );
|
2009-07-16 13:19:43 +00:00
|
|
|
BKE_report(reports, RPT_ERROR, "cant convert curve to mesh. Does the curve have any segments?");
|
|
|
|
return NULL;
|
2009-09-16 10:09:57 +00:00
|
|
|
}
|
2009-07-16 13:19:43 +00:00
|
|
|
tmpmesh = tmpobj->data;
|
|
|
|
free_libblock_us( &G.main->object, tmpobj );
|
|
|
|
break;
|
|
|
|
|
2011-11-14 16:18:44 +00:00
|
|
|
case OB_MBALL: {
|
2009-09-16 10:09:57 +00:00
|
|
|
/* metaballs don't have modifiers, so just convert to mesh */
|
2011-12-05 15:57:57 +00:00
|
|
|
Object *basis_ob = find_basis_mball(sce, ob);
|
2009-09-22 17:50:29 +00:00
|
|
|
/* todo, re-generatre for render-res */
|
|
|
|
/* metaball_polygonize(scene, ob) */
|
|
|
|
|
2011-11-14 16:18:44 +00:00
|
|
|
if(ob != basis_ob)
|
|
|
|
return NULL; /* only do basis metaball */
|
|
|
|
|
2009-07-16 13:19:43 +00:00
|
|
|
tmpmesh = add_mesh("Mesh");
|
2011-12-05 15:57:57 +00:00
|
|
|
|
|
|
|
if(render) {
|
|
|
|
ListBase disp = {NULL, NULL};
|
|
|
|
makeDispListMBall_forRender(sce, ob, &disp);
|
|
|
|
mball_to_mesh(&disp, tmpmesh);
|
|
|
|
freedisplist(&disp);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
mball_to_mesh(&ob->disp, tmpmesh);
|
2011-04-21 15:53:30 +00:00
|
|
|
break;
|
2009-07-16 13:19:43 +00:00
|
|
|
|
2011-11-14 16:18:44 +00:00
|
|
|
}
|
2011-04-21 15:53:30 +00:00
|
|
|
case OB_MESH:
|
2009-07-16 13:19:43 +00:00
|
|
|
/* copies object and modifiers (but not the data) */
|
|
|
|
if (cage) {
|
|
|
|
/* copies the data */
|
|
|
|
tmpmesh = copy_mesh( ob->data );
|
|
|
|
/* if not getting the original caged mesh, get final derived mesh */
|
|
|
|
} else {
|
|
|
|
/* Make a dummy mesh, saves copying */
|
|
|
|
DerivedMesh *dm;
|
|
|
|
/* 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 */
|
|
|
|
|
|
|
|
/* Write the display mesh into the dummy mesh */
|
|
|
|
if (render)
|
|
|
|
dm = mesh_create_derived_render( sce, ob, mask );
|
|
|
|
else
|
|
|
|
dm = mesh_create_derived_view( sce, ob, mask );
|
|
|
|
|
|
|
|
tmpmesh = add_mesh( "Mesh" );
|
|
|
|
DM_to_mesh( dm, tmpmesh );
|
|
|
|
dm->release( dm );
|
|
|
|
}
|
|
|
|
|
2009-09-16 10:09:57 +00:00
|
|
|
break;
|
2011-04-21 15:53:30 +00:00
|
|
|
default:
|
2009-07-16 13:19:43 +00:00
|
|
|
BKE_report(reports, RPT_ERROR, "Object does not have geometry data");
|
2011-04-21 15:53:30 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2009-09-16 10:09:57 +00:00
|
|
|
|
2009-07-16 13:19:43 +00:00
|
|
|
/* Copy materials to new mesh */
|
|
|
|
switch (ob->type) {
|
|
|
|
case OB_SURF:
|
2011-01-12 17:57:00 +00:00
|
|
|
case OB_FONT:
|
|
|
|
case OB_CURVE:
|
2009-07-16 13:19:43 +00:00
|
|
|
tmpmesh->totcol = tmpcu->totcol;
|
|
|
|
|
|
|
|
/* free old material list (if it exists) and adjust user counts */
|
|
|
|
if( tmpcu->mat ) {
|
|
|
|
for( i = tmpcu->totcol; i-- > 0; ) {
|
|
|
|
/* are we an object material or data based? */
|
|
|
|
if (ob->colbits & 1<<i)
|
|
|
|
tmpmesh->mat[i] = ob->mat[i];
|
|
|
|
else
|
|
|
|
tmpmesh->mat[i] = tmpcu->mat[i];
|
|
|
|
|
|
|
|
if (tmpmesh->mat[i])
|
|
|
|
tmpmesh->mat[i]->id.us++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
/* Crashes when assigning the new material, not sure why */
|
|
|
|
case OB_MBALL:
|
|
|
|
tmpmb = (MetaBall *)ob->data;
|
|
|
|
tmpmesh->totcol = tmpmb->totcol;
|
|
|
|
|
|
|
|
/* free old material list (if it exists) and adjust user counts */
|
|
|
|
if( tmpmb->mat ) {
|
|
|
|
for( i = tmpmb->totcol; i-- > 0; ) {
|
|
|
|
tmpmesh->mat[i] = tmpmb->mat[i]; /* CRASH HERE ??? */
|
|
|
|
if (tmpmesh->mat[i]) {
|
|
|
|
tmpmb->mat[i]->id.us++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
2009-09-16 10:09:57 +00:00
|
|
|
|
2009-07-16 13:19:43 +00:00
|
|
|
case OB_MESH:
|
|
|
|
if (!cage) {
|
|
|
|
Mesh *origmesh= ob->data;
|
|
|
|
tmpmesh->flag= origmesh->flag;
|
|
|
|
tmpmesh->mat = MEM_dupallocN(origmesh->mat);
|
|
|
|
tmpmesh->totcol = origmesh->totcol;
|
|
|
|
tmpmesh->smoothresh= origmesh->smoothresh;
|
|
|
|
if( origmesh->mat ) {
|
|
|
|
for( i = origmesh->totcol; i-- > 0; ) {
|
|
|
|
/* are we an object material or data based? */
|
|
|
|
if (ob->colbits & 1<<i)
|
|
|
|
tmpmesh->mat[i] = ob->mat[i];
|
|
|
|
else
|
|
|
|
tmpmesh->mat[i] = origmesh->mat[i];
|
|
|
|
if (tmpmesh->mat[i])
|
|
|
|
tmpmesh->mat[i]->id.us++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-09-16 10:09:57 +00:00
|
|
|
break;
|
2009-07-16 13:19:43 +00:00
|
|
|
} /* end copy materials */
|
2009-06-18 19:48:55 +00:00
|
|
|
|
2009-07-16 13:19:43 +00:00
|
|
|
/* we don't assign it to anything */
|
|
|
|
tmpmesh->id.us--;
|
|
|
|
|
|
|
|
/* make sure materials get updated in objects */
|
|
|
|
test_object_materials( ( ID * ) tmpmesh );
|
2009-06-18 19:48:55 +00:00
|
|
|
|
2009-07-16 13:19:43 +00:00
|
|
|
return tmpmesh;
|
2009-06-24 19:23:34 +00:00
|
|
|
}
|
2009-06-20 16:32:52 +00:00
|
|
|
|
2011-02-12 21:54:50 +00:00
|
|
|
/* mostly a copy from convertblender.c */
|
|
|
|
static void dupli_render_particle_set(Scene *scene, Object *ob, int level, int enable)
|
|
|
|
{
|
|
|
|
/* ugly function, but we need to set particle systems to their render
|
|
|
|
* settings before calling object_duplilist, to get render level duplis */
|
|
|
|
Group *group;
|
|
|
|
GroupObject *go;
|
|
|
|
ParticleSystem *psys;
|
|
|
|
DerivedMesh *dm;
|
|
|
|
float mat[4][4];
|
|
|
|
|
|
|
|
unit_m4(mat);
|
|
|
|
|
|
|
|
if(level >= MAX_DUPLI_RECUR)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(ob->transflag & OB_DUPLIPARTS) {
|
|
|
|
for(psys=ob->particlesystem.first; psys; psys=psys->next) {
|
|
|
|
if(ELEM(psys->part->ren_as, PART_DRAW_OB, PART_DRAW_GR)) {
|
|
|
|
if(enable)
|
|
|
|
psys_render_set(ob, psys, mat, mat, 1, 1, 0.f);
|
|
|
|
else
|
|
|
|
psys_render_restore(ob, psys);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(level == 0 && enable) {
|
|
|
|
/* this is to make sure we get render level duplis in groups:
|
|
|
|
* the derivedmesh must be created before init_render_mesh,
|
|
|
|
* since object_duplilist does dupliparticles before that */
|
|
|
|
dm = mesh_create_derived_render(scene, ob, CD_MASK_BAREMESH|CD_MASK_MTFACE|CD_MASK_MCOL);
|
|
|
|
dm->release(dm);
|
|
|
|
|
|
|
|
for(psys=ob->particlesystem.first; psys; psys=psys->next)
|
|
|
|
psys_get_modifier(ob, psys)->flag &= ~eParticleSystemFlag_psys_updated;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(ob->dup_group==NULL) return;
|
|
|
|
group= ob->dup_group;
|
|
|
|
|
|
|
|
for(go= group->gobject.first; go; go= go->next)
|
|
|
|
dupli_render_particle_set(scene, go->ob, level+1, enable);
|
|
|
|
}
|
2009-06-19 10:40:18 +00:00
|
|
|
/* When no longer needed, duplilist should be freed with Object.free_duplilist */
|
2011-08-16 18:59:45 +00:00
|
|
|
void rna_Object_create_duplilist(Object *ob, ReportList *reports, Scene *sce)
|
2009-06-19 10:40:18 +00:00
|
|
|
{
|
|
|
|
if (!(ob->transflag & OB_DUPLI)) {
|
2011-09-19 13:23:58 +00:00
|
|
|
BKE_report(reports, RPT_ERROR, "Object does not have duplis");
|
2009-06-19 10:40:18 +00:00
|
|
|
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) {
|
2011-09-19 13:23:58 +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
|
|
|
}
|
2011-02-12 21:54:50 +00:00
|
|
|
if(G.rendering)
|
|
|
|
dupli_render_particle_set(sce, ob, 0, 1);
|
2010-04-06 01:28:39 +00:00
|
|
|
ob->duplilist= object_duplilist(sce, ob);
|
2011-02-12 21:54:50 +00:00
|
|
|
if(G.rendering)
|
|
|
|
dupli_render_particle_set(sce, ob, 0, 0);
|
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
|
|
|
}
|
|
|
|
|
2011-08-16 18:59:45 +00:00
|
|
|
void rna_Object_free_duplilist(Object *ob)
|
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-09-16 10:09:57 +00:00
|
|
|
}
|
2009-06-19 10:40:18 +00:00
|
|
|
}
|
|
|
|
|
2010-12-08 11:42:11 +00:00
|
|
|
static PointerRNA rna_Object_shape_key_add(Object *ob, bContext *C, ReportList *reports, const char *name, int from_mix)
|
2009-12-28 18:03:04 +00:00
|
|
|
{
|
|
|
|
Scene *scene= CTX_data_scene(C);
|
|
|
|
KeyBlock *kb= NULL;
|
|
|
|
|
|
|
|
if((kb=object_insert_shape_key(scene, ob, name, from_mix))) {
|
2010-01-06 12:19:46 +00:00
|
|
|
PointerRNA keyptr;
|
|
|
|
|
|
|
|
RNA_pointer_create((ID *)ob->data, &RNA_ShapeKey, kb, &keyptr);
|
2009-12-28 18:03:04 +00:00
|
|
|
WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob);
|
2010-01-06 12:19:46 +00:00
|
|
|
|
|
|
|
return keyptr;
|
2009-12-28 18:03:04 +00:00
|
|
|
}
|
|
|
|
else {
|
2011-09-19 13:23:58 +00:00
|
|
|
BKE_reportf(reports, RPT_ERROR, "Object \"%s\"does not support shapes", ob->id.name+2);
|
2010-01-06 12:19:46 +00:00
|
|
|
return PointerRNA_NULL;
|
2009-12-28 18:03:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-06 01:28:39 +00:00
|
|
|
int rna_Object_is_visible(Object *ob, Scene *sce)
|
2009-08-12 16:37:05 +00:00
|
|
|
{
|
2011-02-18 22:42:03 +00:00
|
|
|
return !(ob->restrictflag & OB_RESTRICT_VIEW) && (ob->lay & sce->lay);
|
2009-08-12 16:37:05 +00:00
|
|
|
}
|
|
|
|
|
2009-07-01 18:23:11 +00:00
|
|
|
/*
|
|
|
|
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) {
|
2011-09-19 13:23:58 +00:00
|
|
|
BKE_report(reports, RPT_ERROR, "Object should be of MESH type");
|
2009-07-01 18:23:11 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Mesh *me = (Mesh*)ob->data;
|
2011-12-14 21:08:08 +00:00
|
|
|
int group_index = BLI_findlink(&ob->defbase, group);
|
2009-07-01 18:23:11 +00:00
|
|
|
if (group_index == -1) {
|
2011-09-19 13:23:58 +00:00
|
|
|
BKE_report(reports, RPT_ERROR, "No deform groups assigned to mesh");
|
2009-07-01 18:23:11 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (assignmode != WEIGHT_REPLACE && assignmode != WEIGHT_ADD && assignmode != WEIGHT_SUBTRACT) {
|
2011-09-19 13:23:58 +00:00
|
|
|
BKE_report(reports, RPT_ERROR, "Bad assignment mode" );
|
2009-07-01 18:23:11 +00:00
|
|
|
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) {
|
2011-09-19 13:23:58 +00:00
|
|
|
BKE_report(reports, RPT_ERROR, "Bad vertex index in list");
|
2009-07-01 18:23:11 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
add_vert_defnr(ob, group_index, i, weight, assignmode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
2009-06-24 19:23:34 +00:00
|
|
|
|
2010-01-02 15:31:02 +00:00
|
|
|
void rna_Object_ray_cast(Object *ob, ReportList *reports, float ray_start[3], float ray_end[3], float r_location[3], float r_normal[3], int *index)
|
|
|
|
{
|
2011-03-03 17:58:06 +00:00
|
|
|
BVHTreeFromMesh treeData= {NULL};
|
2010-01-02 15:31:02 +00:00
|
|
|
|
|
|
|
if(ob->derivedFinal==NULL) {
|
2011-09-19 13:23:58 +00:00
|
|
|
BKE_reportf(reports, RPT_ERROR, "object \"%s\" has no mesh data to be used for ray casting", ob->id.name+2);
|
2010-01-02 15:31:02 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* no need to managing allocation or freeing of the BVH data. this is generated and freed as needed */
|
|
|
|
bvhtree_from_mesh_faces(&treeData, ob->derivedFinal, 0.0f, 4, 6);
|
|
|
|
|
|
|
|
if(treeData.tree==NULL) {
|
2011-09-19 13:23:58 +00:00
|
|
|
BKE_reportf(reports, RPT_ERROR, "object \"%s\" could not create internal data for ray casting", ob->id.name+2);
|
2010-01-02 15:31:02 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
BVHTreeRayHit hit;
|
|
|
|
float ray_nor[3], dist;
|
|
|
|
sub_v3_v3v3(ray_nor, ray_end, ray_start);
|
|
|
|
|
|
|
|
dist= hit.dist = normalize_v3(ray_nor);
|
|
|
|
hit.index = -1;
|
|
|
|
|
|
|
|
if(BLI_bvhtree_ray_cast(treeData.tree, ray_start, ray_nor, 0.0f, &hit, treeData.raycast_callback, &treeData) != -1) {
|
|
|
|
if(hit.dist<=dist) {
|
|
|
|
copy_v3_v3(r_location, hit.co);
|
|
|
|
copy_v3_v3(r_normal, hit.no);
|
|
|
|
*index= hit.index;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
zero_v3(r_location);
|
|
|
|
zero_v3(r_normal);
|
|
|
|
*index= -1;
|
|
|
|
}
|
|
|
|
|
2011-07-19 15:21:21 +00:00
|
|
|
void rna_Object_closest_point_on_mesh(Object *ob, ReportList *reports, float point_co[3], float max_dist, float n_location[3], float n_normal[3], int *index)
|
2011-07-17 12:40:18 +00:00
|
|
|
{
|
|
|
|
BVHTreeFromMesh treeData= {NULL};
|
|
|
|
|
|
|
|
if(ob->derivedFinal==NULL) {
|
2011-09-19 13:23:58 +00:00
|
|
|
BKE_reportf(reports, RPT_ERROR, "object \"%s\" has no mesh data to be used for finding nearest point", ob->id.name+2);
|
2011-07-17 12:40:18 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* no need to managing allocation or freeing of the BVH data. this is generated and freed as needed */
|
|
|
|
bvhtree_from_mesh_faces(&treeData, ob->derivedFinal, 0.0f, 4, 6);
|
|
|
|
|
|
|
|
if(treeData.tree==NULL) {
|
|
|
|
BKE_reportf(reports, RPT_ERROR, "object \"%s\" could not create internal data for finding nearest point", ob->id.name+2);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
BVHTreeNearest nearest;
|
|
|
|
|
|
|
|
nearest.index = -1;
|
2011-07-19 15:21:21 +00:00
|
|
|
nearest.dist = max_dist * max_dist;
|
2011-07-17 12:40:18 +00:00
|
|
|
|
|
|
|
if(BLI_bvhtree_find_nearest(treeData.tree, point_co, &nearest, treeData.nearest_callback, &treeData) != -1) {
|
|
|
|
copy_v3_v3(n_location, nearest.co);
|
|
|
|
copy_v3_v3(n_normal, nearest.no);
|
|
|
|
*index= nearest.index;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
zero_v3(n_location);
|
|
|
|
zero_v3(n_normal);
|
|
|
|
*index= -1;
|
|
|
|
}
|
|
|
|
|
2010-05-23 12:14:07 +00:00
|
|
|
/* ObjectBase */
|
|
|
|
|
|
|
|
void rna_ObjectBase_layers_from_view(Base *base, View3D *v3d)
|
|
|
|
{
|
|
|
|
base->lay= base->object->lay= v3d->lay;
|
|
|
|
}
|
|
|
|
|
2011-08-16 18:59:45 +00:00
|
|
|
int rna_Object_is_modified(Object *ob, Scene *scene, int settings)
|
2011-03-16 08:53:35 +00:00
|
|
|
{
|
|
|
|
return object_is_modified(scene, ob) & settings;
|
|
|
|
}
|
|
|
|
|
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[] = {
|
2011-03-16 08:53:35 +00:00
|
|
|
{eModifierMode_Realtime, "PREVIEW", 0, "Preview", "Apply modifier preview settings"},
|
|
|
|
{eModifierMode_Render, "RENDER", 0, "Render", "Apply modifier render settings"},
|
2009-06-28 13:29:03 +00:00
|
|
|
{0, NULL, 0, NULL, NULL}
|
|
|
|
};
|
2009-06-24 19:23:34 +00:00
|
|
|
|
2009-07-13 11:04:18 +00:00
|
|
|
/* mesh */
|
2011-03-14 01:37:18 +00:00
|
|
|
func= RNA_def_function(srna, "to_mesh", "rna_Object_to_mesh");
|
2011-09-19 13:23:58 +00:00
|
|
|
RNA_def_function_ui_description(func, "Create a Mesh datablock with modifiers applied");
|
2010-04-06 01:28:39 +00:00
|
|
|
RNA_def_function_flag(func, FUNC_USE_REPORTS);
|
2011-09-19 13:23:58 +00:00
|
|
|
parm= RNA_def_pointer(func, "scene", "Scene", "", "Scene within which to evaluate modifiers");
|
2010-04-06 01:28:39 +00:00
|
|
|
RNA_def_property_flag(parm, PROP_REQUIRED|PROP_NEVER_NULL);
|
2011-09-19 13:23:58 +00:00
|
|
|
parm= RNA_def_boolean(func, "apply_modifiers", 0, "", "Apply modifiers");
|
2009-07-16 13:19:43 +00:00
|
|
|
RNA_def_property_flag(parm, PROP_REQUIRED);
|
2011-09-19 13:23:58 +00:00
|
|
|
parm= RNA_def_enum(func, "settings", mesh_type_items, 0, "", "Modifier settings to apply");
|
2009-06-28 13:29:03 +00:00
|
|
|
RNA_def_property_flag(parm, PROP_REQUIRED);
|
2011-09-19 13:23:58 +00:00
|
|
|
parm= RNA_def_pointer(func, "mesh", "Mesh", "", "Mesh created from object, remove it if it is only used for export");
|
2009-06-19 10:40:18 +00:00
|
|
|
RNA_def_function_return(func, parm);
|
2009-06-28 13:29:03 +00:00
|
|
|
|
2009-07-13 11:04:18 +00:00
|
|
|
/* duplis */
|
2011-03-14 01:37:18 +00:00
|
|
|
func= RNA_def_function(srna, "dupli_list_create", "rna_Object_create_duplilist");
|
2011-09-19 13:23:58 +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 to restore the "
|
|
|
|
"objects real matrix and layers");
|
|
|
|
parm= RNA_def_pointer(func, "scene", "Scene", "", "Scene within which to evaluate duplis");
|
2010-04-06 01:28:39 +00:00
|
|
|
RNA_def_property_flag(parm, PROP_REQUIRED|PROP_NEVER_NULL);
|
|
|
|
RNA_def_function_flag(func, FUNC_USE_REPORTS);
|
2009-06-19 10:40:18 +00:00
|
|
|
|
2011-03-14 01:37:18 +00:00
|
|
|
func= RNA_def_function(srna, "dupli_list_clear", "rna_Object_free_duplilist");
|
2011-09-19 13:23:58 +00:00
|
|
|
RNA_def_function_ui_description(func, "Free the list of dupli objects");
|
2009-06-24 19:23:34 +00:00
|
|
|
|
2009-08-08 11:33:34 +00:00
|
|
|
/* Armature */
|
2010-11-12 15:05:57 +00:00
|
|
|
func= RNA_def_function(srna, "find_armature", "modifiers_isDeformedByArmature");
|
2011-09-19 13:23:58 +00:00
|
|
|
RNA_def_function_ui_description(func, "Find armature influencing this object as a parent or via a modifier");
|
|
|
|
parm= RNA_def_pointer(func, "ob_arm", "Object", "", "Armature object influencing this object or NULL");
|
2009-08-08 11:33:34 +00:00
|
|
|
RNA_def_function_return(func, parm);
|
|
|
|
|
2009-12-28 18:03:04 +00:00
|
|
|
/* Shape key */
|
2010-12-08 11:42:11 +00:00
|
|
|
func= RNA_def_function(srna, "shape_key_add", "rna_Object_shape_key_add");
|
2011-09-19 13:23:58 +00:00
|
|
|
RNA_def_function_ui_description(func, "Add shape key to an object");
|
2009-12-28 18:03:04 +00:00
|
|
|
RNA_def_function_flag(func, FUNC_USE_CONTEXT|FUNC_USE_REPORTS);
|
2011-09-19 13:23:58 +00:00
|
|
|
RNA_def_string(func, "name", "Key", 0, "", "Unique name for the new keylock"); /* optional */
|
|
|
|
RNA_def_boolean(func, "from_mix", 1, "", "Create new shape from existing mix of shapes");
|
|
|
|
parm= RNA_def_pointer(func, "key", "ShapeKey", "", "New shape keyblock");
|
2010-01-06 12:19:46 +00:00
|
|
|
RNA_def_property_flag(parm, PROP_RNAPTR);
|
2009-12-28 18:03:04 +00:00
|
|
|
RNA_def_function_return(func, parm);
|
|
|
|
|
2010-01-02 15:31:02 +00:00
|
|
|
/* Ray Cast */
|
|
|
|
func= RNA_def_function(srna, "ray_cast", "rna_Object_ray_cast");
|
2011-09-19 13:23:58 +00:00
|
|
|
RNA_def_function_ui_description(func, "Cast a ray onto in object space");
|
2010-01-02 15:31:02 +00:00
|
|
|
RNA_def_function_flag(func, FUNC_USE_REPORTS);
|
|
|
|
|
|
|
|
/* ray start and end */
|
|
|
|
parm= RNA_def_float_vector(func, "start", 3, NULL, -FLT_MAX, FLT_MAX, "", "", -1e4, 1e4);
|
|
|
|
RNA_def_property_flag(parm, PROP_REQUIRED);
|
|
|
|
parm= RNA_def_float_vector(func, "end", 3, NULL, -FLT_MAX, FLT_MAX, "", "", -1e4, 1e4);
|
|
|
|
RNA_def_property_flag(parm, PROP_REQUIRED);
|
|
|
|
|
|
|
|
/* return location and normal */
|
|
|
|
parm= RNA_def_float_vector(func, "location", 3, NULL, -FLT_MAX, FLT_MAX, "Location", "The hit location of this ray cast", -1e4, 1e4);
|
|
|
|
RNA_def_property_flag(parm, PROP_THICK_WRAP);
|
2010-01-24 10:51:59 +00:00
|
|
|
RNA_def_function_output(func, parm);
|
2010-01-02 15:31:02 +00:00
|
|
|
parm= RNA_def_float_vector(func, "normal", 3, NULL, -FLT_MAX, FLT_MAX, "Normal", "The face normal at the ray cast hit location", -1e4, 1e4);
|
|
|
|
RNA_def_property_flag(parm, PROP_THICK_WRAP);
|
2010-01-24 10:51:59 +00:00
|
|
|
RNA_def_function_output(func, parm);
|
2010-01-02 15:31:02 +00:00
|
|
|
|
2011-09-19 13:23:58 +00:00
|
|
|
parm= RNA_def_int(func, "index", 0, 0, 0, "", "The face index, -1 when no intersection is found", 0, 0);
|
2010-01-24 10:51:59 +00:00
|
|
|
RNA_def_function_output(func, parm);
|
2010-01-02 15:31:02 +00:00
|
|
|
|
2011-07-17 12:40:18 +00:00
|
|
|
/* Nearest Point */
|
|
|
|
func= RNA_def_function(srna, "closest_point_on_mesh", "rna_Object_closest_point_on_mesh");
|
2011-09-19 13:23:58 +00:00
|
|
|
RNA_def_function_ui_description(func, "Find the nearest point on the object");
|
2011-07-17 12:40:18 +00:00
|
|
|
RNA_def_function_flag(func, FUNC_USE_REPORTS);
|
|
|
|
|
2011-07-19 15:21:21 +00:00
|
|
|
/* location of point for test and max distance */
|
2011-07-17 12:40:18 +00:00
|
|
|
parm= RNA_def_float_vector(func, "point", 3, NULL, -FLT_MAX, FLT_MAX, "", "", -1e4, 1e4);
|
|
|
|
RNA_def_property_flag(parm, PROP_REQUIRED);
|
2011-08-04 13:22:38 +00:00
|
|
|
/* default is sqrt(FLT_MAX) */
|
|
|
|
RNA_def_float(func, "max_dist", 1.844674352395373e+19, 0.0, FLT_MAX, "", "", 0.0, FLT_MAX);
|
2011-07-17 12:40:18 +00:00
|
|
|
|
|
|
|
/* return location and normal */
|
|
|
|
parm= RNA_def_float_vector(func, "location", 3, NULL, -FLT_MAX, FLT_MAX, "Location", "The location on the object closest to the point", -1e4, 1e4);
|
|
|
|
RNA_def_property_flag(parm, PROP_THICK_WRAP);
|
|
|
|
RNA_def_function_output(func, parm);
|
|
|
|
parm= RNA_def_float_vector(func, "normal", 3, NULL, -FLT_MAX, FLT_MAX, "Normal", "The face normal at the closest point", -1e4, 1e4);
|
|
|
|
RNA_def_property_flag(parm, PROP_THICK_WRAP);
|
|
|
|
RNA_def_function_output(func, parm);
|
|
|
|
|
2011-09-19 13:23:58 +00:00
|
|
|
parm= RNA_def_int(func, "index", 0, 0, 0, "", "The face index, -1 when no closest point is found", 0, 0);
|
2011-07-17 12:40:18 +00:00
|
|
|
RNA_def_function_output(func, parm);
|
|
|
|
|
2009-08-12 16:37:05 +00:00
|
|
|
/* View */
|
|
|
|
func= RNA_def_function(srna, "is_visible", "rna_Object_is_visible");
|
2011-09-19 13:23:58 +00:00
|
|
|
RNA_def_function_ui_description(func, "Determine if object is visible in a given scene");
|
2010-04-06 01:28:39 +00:00
|
|
|
parm= RNA_def_pointer(func, "scene", "Scene", "", "");
|
|
|
|
RNA_def_property_flag(parm, PROP_REQUIRED|PROP_NEVER_NULL);
|
2011-09-19 13:23:58 +00:00
|
|
|
parm= RNA_def_boolean(func, "result", 0, "", "Object visibility");
|
2011-03-16 08:53:35 +00:00
|
|
|
RNA_def_function_return(func, parm);
|
|
|
|
|
|
|
|
/* utility function for checking if the object is modified */
|
|
|
|
func= RNA_def_function(srna, "is_modified", "rna_Object_is_modified");
|
2011-09-19 13:23:58 +00:00
|
|
|
RNA_def_function_ui_description(func, "Determine if this object is modified from the base mesh data");
|
2011-03-16 08:53:35 +00:00
|
|
|
parm= RNA_def_pointer(func, "scene", "Scene", "", "");
|
|
|
|
RNA_def_property_flag(parm, PROP_REQUIRED|PROP_NEVER_NULL);
|
2011-09-19 13:23:58 +00:00
|
|
|
parm= RNA_def_enum(func, "settings", mesh_type_items, 0, "", "Modifier settings to apply");
|
2011-03-16 08:53:35 +00:00
|
|
|
RNA_def_property_flag(parm, PROP_REQUIRED);
|
2011-09-19 13:23:58 +00:00
|
|
|
parm= RNA_def_boolean(func, "result", 0, "", "Object visibility");
|
2009-08-12 16:37:05 +00:00
|
|
|
RNA_def_function_return(func, parm);
|
2009-06-18 19:48:55 +00:00
|
|
|
}
|
|
|
|
|
2010-05-23 12:14:07 +00:00
|
|
|
|
|
|
|
void RNA_api_object_base(StructRNA *srna)
|
|
|
|
{
|
|
|
|
FunctionRNA *func;
|
|
|
|
PropertyRNA *parm;
|
|
|
|
|
|
|
|
func= RNA_def_function(srna, "layers_from_view", "rna_ObjectBase_layers_from_view");
|
2011-09-19 13:23:58 +00:00
|
|
|
RNA_def_function_ui_description(func, "Sets the object layers from a 3D View (use when adding an object in local view)");
|
2010-05-23 12:14:07 +00:00
|
|
|
parm= RNA_def_pointer(func, "view", "SpaceView3D", "", "");
|
|
|
|
RNA_def_property_flag(parm, PROP_REQUIRED|PROP_NEVER_NULL);
|
|
|
|
}
|
|
|
|
|
2009-06-18 19:48:55 +00:00
|
|
|
#endif
|
|
|
|
|