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>
# include "RNA_define.h"
# include "RNA_types.h"
2009-06-20 16:32:52 +00:00
# include "DNA_object_types.h"
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-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-20 16:32:52 +00:00
static Mesh * rna_Object_create_render_mesh ( Object * ob , bContext * C , ReportList * reports , int apply_matrix , float * matrix )
2009-06-18 19:48:55 +00:00
{
CustomDataMask mask = CD_MASK_BAREMESH | CD_MASK_MTFACE | CD_MASK_MCOL ;
DerivedMesh * dm ;
Mesh * me ;
2009-06-20 05:52:19 +00:00
Scene * sce ;
2009-06-20 16:32:52 +00:00
int a ;
MVert * mvert ;
2009-06-20 05:52:19 +00:00
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-18 19:48:55 +00:00
2009-06-20 05:52:19 +00:00
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-20 16:32:52 +00:00
if ( apply_matrix ) {
2009-06-23 17:52:58 +00:00
float * mat = ( float * ) ob - > obmat ;
2009-06-20 16:32:52 +00:00
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 ) ;
}
}
2009-06-18 19:48:55 +00:00
return me ;
}
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-23 17:52:58 +00:00
/* free duplilist if a user forget to */
if ( ob - > duplilist ) {
BKE_report ( reports , RPT_WARNING , " %s.dupli_list has not been freed. " , RNA_struct_identifier ( & RNA_Object ) ) ;
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
{
PointerRNA obptr ;
PropertyRNA * prop ;
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-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-20 16:32:52 +00:00
/* 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 } } ;
2009-06-18 19:48:55 +00:00
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. " ) ;
2009-06-20 05:52:19 +00:00
RNA_def_function_flag ( func , FUNC_USE_CONTEXT | FUNC_USE_REPORTS ) ;
2009-06-20 16:32:52 +00:00
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 ) ;
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-20 05:52:19 +00:00
2009-06-19 10:40:18 +00:00
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_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-18 19:48:55 +00:00
}
# endif