- replaced Object.create_mesh body with 2.4x API's Mesh.createFromObject code to also support curves, surfaces and metaballs.
- replaced Object.dag_update with Object.make_display_list, which copies old API's Object.makeDisplayList
This commit is contained in:
@@ -2019,41 +2019,60 @@ def write(filename, batch_objects = None, \
|
||||
# This is needed so applying modifiers dosnt apply the armature deformation, its also needed
|
||||
# ...so mesh objects return their rest worldspace matrix when bone-parents are exported as weighted meshes.
|
||||
# set every armature to its rest, backup the original values so we done mess up the scene
|
||||
ob_arms_orig_rest = [arm.restPosition for arm in bpy.data.armatures]
|
||||
ob_arms_orig_rest = [arm.rest_position for arm in bpy.data.armatures]
|
||||
# ob_arms_orig_rest = [arm.restPosition for arm in bpy.data.armatures]
|
||||
|
||||
for arm in bpy.data.armatures:
|
||||
arm.restPosition = True
|
||||
arm.rest_position = True
|
||||
# arm.restPosition = True
|
||||
|
||||
if ob_arms_orig_rest:
|
||||
for ob_base in bpy.data.objects:
|
||||
#if ob_base.type == 'Armature':
|
||||
ob_base.makeDisplayList()
|
||||
ob_base.make_display_list()
|
||||
# ob_base.makeDisplayList()
|
||||
|
||||
# This causes the makeDisplayList command to effect the mesh
|
||||
Blender.Set('curframe', Blender.Get('curframe'))
|
||||
sce.set_frame(sce.current_frame)
|
||||
# Blender.Set('curframe', Blender.Get('curframe'))
|
||||
|
||||
|
||||
for ob_base in tmp_objects:
|
||||
for ob, mtx in BPyObject.getDerivedObjects(ob_base):
|
||||
#for ob in [ob_base,]:
|
||||
|
||||
# ignore dupli children
|
||||
if ob_base.parent and ob_base.parent.dupli_type != 'NONE':
|
||||
continue
|
||||
|
||||
obs = [(ob_base, ob_base.matrix)]
|
||||
if ob_base.dupli_type != 'NONE':
|
||||
ob_base.create_dupli_list()
|
||||
obs = [(dob.object, dob.matrix) for dob in ob_base.dupli_list]
|
||||
|
||||
for ob, mtx in obs:
|
||||
# for ob, mtx in BPyObject.getDerivedObjects(ob_base):
|
||||
tmp_ob_type = ob.type
|
||||
if tmp_ob_type == 'Camera':
|
||||
if tmp_ob_type == 'CAMERA':
|
||||
# if tmp_ob_type == 'Camera':
|
||||
if EXP_CAMERA:
|
||||
ob_cameras.append(my_object_generic(ob, mtx))
|
||||
elif tmp_ob_type == 'Lamp':
|
||||
elif tmp_ob_type == 'LAMP':
|
||||
# elif tmp_ob_type == 'Lamp':
|
||||
if EXP_LAMP:
|
||||
ob_lights.append(my_object_generic(ob, mtx))
|
||||
elif tmp_ob_type == 'Armature':
|
||||
elif tmp_ob_type == 'ARMATURE':
|
||||
# elif tmp_ob_type == 'Armature':
|
||||
if EXP_ARMATURE:
|
||||
# TODO - armatures dont work in dupligroups!
|
||||
if ob not in ob_arms: ob_arms.append(ob)
|
||||
# ob_arms.append(ob) # replace later. was "ob_arms.append(sane_obname(ob), ob)"
|
||||
elif tmp_ob_type == 'Empty':
|
||||
elif tmp_ob_type == 'EMPTY':
|
||||
# elif tmp_ob_type == 'Empty':
|
||||
if EXP_EMPTY:
|
||||
ob_null.append(my_object_generic(ob, mtx))
|
||||
elif EXP_MESH:
|
||||
origData = True
|
||||
if tmp_ob_type != 'Mesh':
|
||||
if tmp_ob_type != 'MESH':
|
||||
# if tmp_ob_type != 'Mesh':
|
||||
me = bpy.data.meshes.new()
|
||||
try: me.getFromObject(ob)
|
||||
except: me = None
|
||||
@@ -2171,8 +2190,9 @@ def write(filename, batch_objects = None, \
|
||||
|
||||
if ob_arms_orig_rest:
|
||||
for ob_base in bpy.data.objects:
|
||||
if ob_base.type == 'Armature':
|
||||
ob_base.dag_update()
|
||||
if ob_base.type == 'ARMATURE':
|
||||
# if ob_base.type == 'Armature':
|
||||
ob_base.make_display_list()
|
||||
# ob_base.makeDisplayList()
|
||||
# This causes the makeDisplayList command to effect the mesh
|
||||
sce.set_frame(sce.current_frame)
|
||||
@@ -3322,6 +3342,7 @@ if __name__ == '__main__':
|
||||
# - get rid of BPyObject_getObjectArmature, move it in RNA?
|
||||
# - BATCH_ENABLE and BATCH_GROUP options: line 327
|
||||
# - implement all BPyMesh_* used here with RNA
|
||||
# - getDerivedObjects is not fully replicated with .dupli* funcs
|
||||
|
||||
# TODO
|
||||
|
||||
|
||||
@@ -380,11 +380,6 @@ def write(filename, objects, scene,
|
||||
# Get all meshes
|
||||
for ob_main in objects:
|
||||
|
||||
if ob_main.dupli_type != 'NONE':
|
||||
# XXX
|
||||
print('creating dupli_list on', ob_main.name)
|
||||
ob_main.create_dupli_list()
|
||||
|
||||
# ignore dupli children
|
||||
if ob_main.parent and ob_main.parent.dupli_type != 'NONE':
|
||||
# XXX
|
||||
@@ -393,6 +388,10 @@ def write(filename, objects, scene,
|
||||
|
||||
obs = []
|
||||
if ob_main.dupli_type != 'NONE':
|
||||
# XXX
|
||||
print('creating dupli_list on', ob_main.name)
|
||||
ob_main.create_dupli_list()
|
||||
|
||||
obs = [(dob.object, dob.matrix) for dob in ob_main.dupli_list]
|
||||
|
||||
# XXX debug print
|
||||
|
||||
@@ -40,62 +40,190 @@
|
||||
|
||||
#include "ED_mesh.h"
|
||||
|
||||
/* parameter to rna_Object_create_mesh */
|
||||
typedef enum CreateMeshType {
|
||||
CREATE_MESH_PREVIEW = 0,
|
||||
CREATE_MESH_RENDER = 1
|
||||
} CreateMeshType;
|
||||
|
||||
#ifdef RNA_RUNTIME
|
||||
|
||||
#include "BKE_customdata.h"
|
||||
#include "BKE_DerivedMesh.h"
|
||||
#include "BKE_anim.h"
|
||||
#include "BKE_main.h"
|
||||
#include "BKE_global.h"
|
||||
#include "BKE_context.h"
|
||||
#include "BKE_report.h"
|
||||
#include "BKE_object.h"
|
||||
#include "BKE_mesh.h"
|
||||
#include "BKE_DerivedMesh.h"
|
||||
#include "BKE_customdata.h"
|
||||
#include "BKE_anim.h"
|
||||
#include "BKE_depsgraph.h"
|
||||
#include "BKE_displist.h"
|
||||
#include "BKE_font.h"
|
||||
#include "BKE_mball.h"
|
||||
|
||||
#include "BLI_arithb.h"
|
||||
|
||||
#include "DNA_mesh_types.h"
|
||||
#include "DNA_scene_types.h"
|
||||
#include "DNA_meshdata_types.h"
|
||||
#include "DNA_curve_types.h"
|
||||
|
||||
#include "BLI_arithb.h"
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
/* copied from init_render_mesh (render code) */
|
||||
static Mesh *rna_Object_create_mesh(Object *ob, bContext *C, ReportList *reports, int type)
|
||||
/* copied from Mesh_getFromObject and adapted to RNA interface */
|
||||
/* settings: 0 - preview, 1 - render */
|
||||
static Mesh *rna_Object_create_mesh(Object *ob, bContext *C, ReportList *reports, int apply_modifiers, int settings)
|
||||
{
|
||||
/* 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 */
|
||||
DerivedMesh *dm;
|
||||
Mesh *me;
|
||||
Scene *sce;
|
||||
Mesh *tmpmesh;
|
||||
Curve *tmpcu = NULL;
|
||||
Object *tmpobj = NULL;
|
||||
int render = settings, i;
|
||||
int cage = !apply_modifiers;
|
||||
Scene *sce = CTX_data_scene(C);
|
||||
|
||||
sce= CTX_data_scene(C);
|
||||
/* perform the mesh extraction based on type */
|
||||
switch (ob->type) {
|
||||
case OB_FONT:
|
||||
case OB_CURVE:
|
||||
case OB_SURF:
|
||||
|
||||
/* copies object and modifiers (but not the data) */
|
||||
tmpobj= copy_object(ob);
|
||||
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;
|
||||
}
|
||||
|
||||
/* TODO: other types */
|
||||
if(ob->type != OB_MESH) {
|
||||
BKE_report(reports, RPT_ERROR, "Object should be of type MESH.");
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (type == CREATE_MESH_PREVIEW) {
|
||||
dm= mesh_create_derived_view(sce, ob, mask);
|
||||
}
|
||||
else {
|
||||
dm= mesh_create_derived_render(sce, ob, mask);
|
||||
}
|
||||
/* get updated display list, and convert to a mesh */
|
||||
makeDispListCurveTypes( sce, tmpobj, 0 );
|
||||
nurbs_to_mesh( tmpobj );
|
||||
|
||||
/* nurbs_to_mesh changes the type to a mesh, check it worked */
|
||||
if (tmpobj->type != OB_MESH) {
|
||||
free_libblock_us( &G.main->object, tmpobj );
|
||||
BKE_report(reports, RPT_ERROR, "cant convert curve to mesh. Does the curve have any segments?");
|
||||
return NULL;
|
||||
}
|
||||
tmpmesh = tmpobj->data;
|
||||
free_libblock_us( &G.main->object, tmpobj );
|
||||
break;
|
||||
|
||||
if(!dm) {
|
||||
/* TODO: report */
|
||||
return NULL;
|
||||
}
|
||||
case OB_MBALL:
|
||||
/* metaballs don't have modifiers, so just convert to mesh */
|
||||
ob = find_basis_mball( sce, ob );
|
||||
tmpmesh = add_mesh("Mesh");
|
||||
mball_to_mesh( &ob->disp, tmpmesh );
|
||||
break;
|
||||
|
||||
me= add_mesh("tmp_render_mesh");
|
||||
me->id.us--; /* we don't assign it to anything */
|
||||
DM_to_mesh(dm, me);
|
||||
dm->release(dm);
|
||||
case OB_MESH:
|
||||
/* 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 );
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
BKE_report(reports, RPT_ERROR, "Object does not have geometry data");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return me;
|
||||
/* Copy materials to new mesh */
|
||||
switch (ob->type) {
|
||||
case OB_SURF:
|
||||
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
|
||||
|
||||
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++;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
} /* end copy materials */
|
||||
|
||||
/* we don't assign it to anything */
|
||||
tmpmesh->id.us--;
|
||||
|
||||
/* make sure materials get updated in objects */
|
||||
test_object_materials( ( ID * ) tmpmesh );
|
||||
|
||||
return tmpmesh;
|
||||
}
|
||||
|
||||
/* When no longer needed, duplilist should be freed with Object.free_duplilist */
|
||||
@@ -166,9 +294,18 @@ static void rna_Object_add_vertex_to_group(Object *ob, int vertex_index, bDeform
|
||||
add_vert_to_defgroup(ob, def, vertex_index, weight, assignmode);
|
||||
}
|
||||
|
||||
static void rna_Object_dag_update(Object *ob, bContext *C)
|
||||
/* copied from old API Object.makeDisplayList (Object.c) */
|
||||
static void rna_Object_make_display_list(Object *ob, bContext *C)
|
||||
{
|
||||
DAG_object_flush_update(CTX_data_scene(C), ob, OB_RECALC_DATA);
|
||||
Scene *sce= CTX_data_scene(C);
|
||||
|
||||
if (ob->type == OB_FONT) {
|
||||
Curve *cu = ob->data;
|
||||
freedisplist(&cu->disp);
|
||||
BKE_text_to_curve(sce, ob, CU_LEFT);
|
||||
}
|
||||
|
||||
DAG_object_flush_update(sce, ob, OB_RECALC_DATA);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -215,8 +352,8 @@ void RNA_api_object(StructRNA *srna)
|
||||
PropertyRNA *parm;
|
||||
|
||||
static EnumPropertyItem mesh_type_items[] = {
|
||||
{CREATE_MESH_PREVIEW, "PREVIEW", 0, "Preview", "Apply preview settings."},
|
||||
{CREATE_MESH_RENDER, "RENDER", 0, "Render", "Apply render settings."},
|
||||
{0, "PREVIEW", 0, "Preview", "Apply modifier preview settings."},
|
||||
{1, "RENDER", 0, "Render", "Apply modifier render settings."},
|
||||
{0, NULL, 0, NULL, NULL}
|
||||
};
|
||||
|
||||
@@ -229,9 +366,11 @@ void RNA_api_object(StructRNA *srna)
|
||||
|
||||
/* mesh */
|
||||
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.");
|
||||
RNA_def_function_ui_description(func, "Create a Mesh datablock with modifiers applied.");
|
||||
RNA_def_function_flag(func, FUNC_USE_CONTEXT|FUNC_USE_REPORTS);
|
||||
parm= RNA_def_enum(func, "type", mesh_type_items, 0, "", "Type of mesh settings to apply.");
|
||||
RNA_def_boolean(func, "apply_modifiers", 0, "", "Apply modifiers.");
|
||||
RNA_def_property_flag(parm, PROP_REQUIRED);
|
||||
parm= RNA_def_enum(func, "settings", mesh_type_items, 0, "", "Mesh settings to apply.");
|
||||
RNA_def_property_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);
|
||||
@@ -270,8 +409,8 @@ void RNA_api_object(StructRNA *srna)
|
||||
RNA_def_property_flag(parm, PROP_REQUIRED);
|
||||
|
||||
/* DAG */
|
||||
func= RNA_def_function(srna, "dag_update", "rna_Object_dag_update");
|
||||
RNA_def_function_ui_description(func, "DAG update."); /* XXX describe better */
|
||||
func= RNA_def_function(srna, "make_display_list", "rna_Object_make_display_list");
|
||||
RNA_def_function_ui_description(func, "Update object's display data."); /* XXX describe better */
|
||||
RNA_def_function_flag(func, FUNC_USE_CONTEXT);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user