Object API changes so these functions now require a scene as first argument:

create_mesh, create_dupli_list, make_display_list and is_visible.

This is done in order to make these context independent as the RNA API should
be as much as possible, and to fix #21297 and #21719, where there was an
assumption from these functions that there is a scene in the context, which
does not work for external render engines exporting in a separate thread.

Also avoided using context in a number of other functions, ideally only UI/WM
type functions should use context.

I've updated the scripts in trunk, but the addons and external ones in
development will need updates too.
This commit is contained in:
2010-04-06 01:28:39 +00:00
parent b1e556890d
commit 9498121463
14 changed files with 56 additions and 59 deletions

View File

@@ -267,7 +267,7 @@ def write_pov(filename, scene=None, info_callback=None):
file.write('}\n')
def exportMeshs(sel):
def exportMeshs(scene, sel):
ob_num = 0
@@ -280,7 +280,7 @@ def write_pov(filename, scene=None, info_callback=None):
me = ob.data
me_materials = me.materials
me = ob.create_mesh(True, 'RENDER')
me = ob.create_mesh(scene, True, 'RENDER')
if not me:
continue
@@ -593,7 +593,7 @@ def write_pov(filename, scene=None, info_callback=None):
sel = scene.objects
exportLamps([l for l in sel if l.type == 'LAMP'])
exportMeta([l for l in sel if l.type == 'META'])
exportMeshs(sel)
exportMeshs(scene, sel)
exportWorld(scene.world)
exportGlobalSettings(scene)

View File

@@ -74,12 +74,12 @@ import bpy
# also used by X3D exporter
# return a tuple (free, object list), free is True if memory should be freed later with free_derived_objects()
def create_derived_objects(ob):
def create_derived_objects(scene, ob):
if ob.parent and ob.parent.dupli_type != 'NONE':
return False, None
if ob.dupli_type != 'NONE':
ob.create_dupli_list()
ob.create_dupli_list(scene)
return True, [(dob.object, dob.matrix) for dob in ob.dupli_list]
else:
return False, [(ob, ob.matrix)]
@@ -968,11 +968,12 @@ def save_3ds(filename, context):
# each material is added once):
materialDict = {}
mesh_objects = []
for ob in [ob for ob in context.scene.objects if ob.is_visible()]:
scene = context.scene
for ob in [ob for ob in scene.objects if ob.is_visible(scene)]:
# for ob in sce.objects.context:
# get derived objects
free, derived = create_derived_objects(ob)
free, derived = create_derived_objects(scene, ob)
if derived == None: continue
@@ -982,7 +983,7 @@ def save_3ds(filename, context):
if ob.type not in ('MESH', 'CURVE', 'SURFACE', 'TEXT', 'META'):
continue
data = ob_derived.create_mesh(True, 'PREVIEW')
data = ob_derived.create_mesh(scene, True, 'PREVIEW')
# data = getMeshFromObject(ob_derived, None, True, False, sce)
if data:
data.transform(mat)

View File

@@ -2038,7 +2038,7 @@ 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.make_display_list()
ob_base.make_display_list(scene)
# ob_base.makeDisplayList()
# This causes the makeDisplayList command to effect the mesh
@@ -2054,7 +2054,7 @@ def write(filename, batch_objects = None, \
obs = [(ob_base, ob_base.matrix)]
if ob_base.dupli_type != 'NONE':
ob_base.create_dupli_list()
ob_base.create_dupli_list(scene)
obs = [(dob.object, dob.matrix) for dob in ob_base.dupli_list]
for ob, mtx in obs:
@@ -2083,7 +2083,7 @@ def write(filename, batch_objects = None, \
if tmp_ob_type != 'MESH':
# if tmp_ob_type != 'Mesh':
# me = bpy.data.meshes.new()
try: me = ob.create_mesh(True, 'PREVIEW')
try: me = ob.create_mesh(scene, True, 'PREVIEW')
# try: me.getFromObject(ob)
except: me = None
if me:
@@ -2094,7 +2094,7 @@ def write(filename, batch_objects = None, \
# Mesh Type!
if EXP_MESH_APPLY_MOD:
# me = bpy.data.meshes.new()
me = ob.create_mesh(True, 'PREVIEW')
me = ob.create_mesh(scene, True, 'PREVIEW')
# me.getFromObject(ob)
# so we keep the vert groups
@@ -2214,7 +2214,7 @@ def write(filename, batch_objects = None, \
for ob_base in bpy.data.objects:
if ob_base.type == 'ARMATURE':
# if ob_base.type == 'Armature':
ob_base.make_display_list()
ob_base.make_display_list(scene)
# ob_base.makeDisplayList()
# This causes the makeDisplayList command to effect the mesh
scene.set_frame(scene.frame_current)

View File

@@ -84,7 +84,7 @@ def write(filename, sce, ob, PREF_STARTFRAME, PREF_ENDFRAME, PREF_FPS):
orig_frame = sce.frame_current
sce.set_frame(PREF_STARTFRAME)
me = ob.create_mesh(True, 'PREVIEW')
me = ob.create_mesh(sce, True, 'PREVIEW')
#Flip y and z
mat_flip = Mathutils.Matrix(\
@@ -123,7 +123,7 @@ def write(filename, sce, ob, PREF_STARTFRAME, PREF_ENDFRAME, PREF_FPS):
"""
sce.set_frame(frame)
me = ob.create_mesh(True, 'PREVIEW')
me = ob.create_mesh(sce, True, 'PREVIEW')
check_vertcount(me, numverts)
me.transform(mat_flip * ob.matrix)

View File

@@ -396,7 +396,7 @@ def write(filename, objects, scene,
if ob_main.dupli_type != 'NONE':
# XXX
print('creating dupli_list on', ob_main.name)
ob_main.create_dupli_list()
ob_main.create_dupli_list(scene)
obs = [(dob.object, dob.matrix) for dob in ob_main.dupli_list]
@@ -421,7 +421,7 @@ def write(filename, objects, scene,
if ob.type != 'MESH':
continue
me = ob.create_mesh(EXPORT_APPLY_MODIFIERS, 'PREVIEW')
me = ob.create_mesh(scene, EXPORT_APPLY_MODIFIERS, 'PREVIEW')
if EXPORT_ROTX90:
me.transform(mat_xrot90 * ob_mat)

View File

@@ -103,7 +103,7 @@ def write(filename, scene, ob, \
#mesh = BPyMesh.getMeshFromObject(ob, None, EXPORT_APPLY_MODIFIERS, False, scn) # XXX
if EXPORT_APPLY_MODIFIERS:
mesh = ob.create_mesh(True, 'PREVIEW')
mesh = ob.create_mesh(scene, True, 'PREVIEW')
else:
mesh = ob.data

View File

@@ -852,10 +852,10 @@ class x3d_class:
# --------------------------
for ob_main in [o for o in scene.objects if o.is_visible()]:
for ob_main in [o for o in scene.objects if o.is_visible(scene)]:
# for ob_main in scene.objects.context:
free, derived = create_derived_objects(ob_main)
free, derived = create_derived_objects(scene, ob_main)
if derived == None: continue
@@ -871,7 +871,7 @@ class x3d_class:
# elif objType in ("Mesh", "Curve", "Surf", "Text") :
if EXPORT_APPLY_MODIFIERS or objType != 'MESH':
# if EXPORT_APPLY_MODIFIERS or objType != 'Mesh':
me = ob.create_mesh(EXPORT_APPLY_MODIFIERS, 'PREVIEW')
me = ob.create_mesh(scene, EXPORT_APPLY_MODIFIERS, 'PREVIEW')
# me= BPyMesh.getMeshFromObject(ob, containerMesh, EXPORT_APPLY_MODIFIERS, False, scene)
else:
me = ob.data

View File

@@ -364,7 +364,7 @@ static void rna_Nurb_update_knot_v(Main *bmain, Scene *scene, PointerRNA *ptr)
rna_Curve_update_data(bmain, scene, ptr);
}
static void rna_Curve_spline_points_add(ID *id, Nurb *nu, bContext *C, ReportList *reports, int number)
static void rna_Curve_spline_points_add(ID *id, Nurb *nu, ReportList *reports, int number)
{
if(nu->type == CU_BEZIER) {
BKE_report(reports, RPT_ERROR, "Bezier spline can't have points added");
@@ -378,11 +378,11 @@ static void rna_Curve_spline_points_add(ID *id, Nurb *nu, bContext *C, ReportLis
/* update */
makeknots(nu, 1);
rna_Curve_update_data_id(CTX_data_main(C), CTX_data_scene(C), id);
rna_Curve_update_data_id(NULL, NULL, id);
}
}
static void rna_Curve_spline_bezpoints_add(ID *id, Nurb *nu, bContext *C, ReportList *reports, int number)
static void rna_Curve_spline_bezpoints_add(ID *id, Nurb *nu, ReportList *reports, int number)
{
if(nu->type != CU_BEZIER) {
BKE_report(reports, RPT_ERROR, "Only bezier splines can be added");
@@ -395,7 +395,7 @@ static void rna_Curve_spline_bezpoints_add(ID *id, Nurb *nu, bContext *C, Report
/* update */
makeknots(nu, 1);
rna_Curve_update_data_id(CTX_data_main(C), CTX_data_scene(C), id);
rna_Curve_update_data_id(NULL, NULL, id);
}
}
@@ -903,7 +903,7 @@ static void rna_def_curve_spline_points(BlenderRNA *brna, PropertyRNA *cprop)
func= RNA_def_function(srna, "add", "rna_Curve_spline_points_add");
RNA_def_function_ui_description(func, "Add a number of points to this spline.");
RNA_def_function_flag(func, FUNC_USE_CONTEXT|FUNC_USE_SELF_ID|FUNC_USE_REPORTS);
RNA_def_function_flag(func, FUNC_USE_SELF_ID|FUNC_USE_REPORTS);
parm= RNA_def_int(func, "number", 1, INT_MIN, INT_MAX, "Number", "Number of points to add to the spline", 0, INT_MAX);
/*
@@ -930,7 +930,7 @@ static void rna_def_curve_spline_bezpoints(BlenderRNA *brna, PropertyRNA *cprop)
func= RNA_def_function(srna, "add", "rna_Curve_spline_bezpoints_add");
RNA_def_function_ui_description(func, "Add a number of points to this spline.");
RNA_def_function_flag(func, FUNC_USE_CONTEXT|FUNC_USE_SELF_ID|FUNC_USE_REPORTS);
RNA_def_function_flag(func, FUNC_USE_SELF_ID|FUNC_USE_REPORTS);
parm= RNA_def_int(func, "number", 1, INT_MIN, INT_MAX, "Number", "Number of points to add to the spline", 0, INT_MAX);
/*

View File

@@ -396,12 +396,12 @@ static void rna_FCurve_active_modifier_set(PointerRNA *ptr, PointerRNA value)
set_active_fmodifier(&fcu->modifiers, (FModifier *)value.data);
}
static FModifier *rna_FCurve_modifiers_new(FCurve *fcu, bContext *C, int type)
static FModifier *rna_FCurve_modifiers_new(FCurve *fcu, int type)
{
return add_fmodifier(&fcu->modifiers, type);
}
static int rna_FCurve_modifiers_remove(FCurve *fcu, bContext *C, int index)
static int rna_FCurve_modifiers_remove(FCurve *fcu, int index)
{
return remove_fmodifier_index(&fcu->modifiers, index);
}
@@ -1252,7 +1252,6 @@ static void rna_def_fcurve_modifiers(BlenderRNA *brna, PropertyRNA *cprop)
/* Constraint collection */
func= RNA_def_function(srna, "new", "rna_FCurve_modifiers_new");
RNA_def_function_flag(func, FUNC_USE_CONTEXT);
RNA_def_function_ui_description(func, "Add a constraint to this object");
/* return type */
parm= RNA_def_pointer(func, "fmodifier", "FModifier", "", "New fmodifier.");
@@ -1262,7 +1261,6 @@ static void rna_def_fcurve_modifiers(BlenderRNA *brna, PropertyRNA *cprop)
RNA_def_property_flag(parm, PROP_REQUIRED);
func= RNA_def_function(srna, "remove", "rna_FCurve_modifiers_remove");
RNA_def_function_flag(func, FUNC_USE_CONTEXT);
RNA_def_function_ui_description(func, "Remove a modifier from this fcurve.");
/* return type */
parm= RNA_def_boolean(func, "success", 0, "Success", "Removed the constraint successfully.");

View File

@@ -951,13 +951,13 @@ static void rna_Object_active_constraint_set(PointerRNA *ptr, PointerRNA value)
constraints_set_active(&ob->constraints, (bConstraint *)value.data);
}
static bConstraint *rna_Object_constraint_new(Object *object, bContext *C, int type)
static bConstraint *rna_Object_constraint_new(Object *object, int type)
{
WM_main_add_notifier(NC_OBJECT|ND_CONSTRAINT|NA_ADDED, object);
return add_ob_constraint(object, NULL, type);
}
static int rna_Object_constraint_remove(Object *object, bContext *C, int index)
static int rna_Object_constraint_remove(Object *object, int index)
{
int ok = remove_constraint_index(&object->constraints, index);
if(ok) {
@@ -1275,7 +1275,6 @@ static void rna_def_object_constraints(BlenderRNA *brna, PropertyRNA *cprop)
/* Constraint collection */
func= RNA_def_function(srna, "new", "rna_Object_constraint_new");
RNA_def_function_flag(func, FUNC_USE_CONTEXT);
RNA_def_function_ui_description(func, "Add a new constraint to this object");
/* return type */
parm= RNA_def_pointer(func, "constraint", "Constraint", "", "New constraint.");
@@ -1285,7 +1284,6 @@ static void rna_def_object_constraints(BlenderRNA *brna, PropertyRNA *cprop)
RNA_def_property_flag(parm, PROP_REQUIRED);
func= RNA_def_function(srna, "remove", "rna_Object_constraint_remove");
RNA_def_function_flag(func, FUNC_USE_CONTEXT);
RNA_def_function_ui_description(func, "Remove a constraint from this object.");
/* return type */
parm= RNA_def_boolean(func, "success", 0, "Success", "Removed the constraint successfully.");

View File

@@ -70,14 +70,13 @@
/* 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)
static Mesh *rna_Object_create_mesh(Object *ob, ReportList *reports, Scene *sce, int apply_modifiers, int settings)
{
Mesh *tmpmesh;
Curve *tmpcu = NULL;
Object *tmpobj = NULL;
int render = settings, i;
int cage = !apply_modifiers;
Scene *sce = CTX_data_scene(C);
/* perform the mesh extraction based on type */
switch (ob->type) {
@@ -115,7 +114,7 @@ static Mesh *rna_Object_create_mesh(Object *ob, bContext *C, ReportList *reports
/* nurbs_to_mesh changes the type to a mesh, check it worked */
if (tmpobj->type != OB_MESH) {
free_libblock_us( &(CTX_data_main(C)->object), tmpobj );
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;
}
@@ -233,7 +232,7 @@ static Mesh *rna_Object_create_mesh(Object *ob, bContext *C, ReportList *reports
}
/* When no longer needed, duplilist should be freed with Object.free_duplilist */
static void rna_Object_create_duplilist(Object *ob, bContext *C, ReportList *reports)
static void rna_Object_create_duplilist(Object *ob, ReportList *reports, Scene *sce)
{
if (!(ob->transflag & OB_DUPLI)) {
BKE_report(reports, RPT_ERROR, "Object does not have duplis.");
@@ -248,7 +247,7 @@ static void rna_Object_create_duplilist(Object *ob, bContext *C, ReportList *rep
ob->duplilist= NULL;
}
ob->duplilist= object_duplilist(CTX_data_scene(C), ob);
ob->duplilist= object_duplilist(sce, ob);
/* ob->duplilist should now be freed with Object.free_duplilist */
}
@@ -273,10 +272,8 @@ static void rna_Object_add_vertex_to_group(Object *ob, int vertex_index, bDeform
}
/* copied from old API Object.makeDisplayList (Object.c) */
static void rna_Object_make_display_list(Object *ob, bContext *C)
static void rna_Object_make_display_list(Object *ob, Scene *sce)
{
Scene *sce= CTX_data_scene(C);
if (ob->type == OB_FONT) {
Curve *cu = ob->data;
freedisplist(&cu->disp);
@@ -328,9 +325,9 @@ static PointerRNA rna_Object_add_shape_key(Object *ob, bContext *C, ReportList *
}
}
int rna_Object_is_visible(Object *ob, bContext *C)
int rna_Object_is_visible(Object *ob, Scene *sce)
{
return !(ob->restrictflag & OB_RESTRICT_VIEW) && ob->lay & CTX_data_scene(C)->lay;
return !(ob->restrictflag & OB_RESTRICT_VIEW) && ob->lay & sce->lay;
}
/*
@@ -431,7 +428,9 @@ 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 modifiers applied.");
RNA_def_function_flag(func, FUNC_USE_CONTEXT|FUNC_USE_REPORTS);
RNA_def_function_flag(func, FUNC_USE_REPORTS);
parm= RNA_def_pointer(func, "scene", "Scene", "", "Scene within which to evaluate modifiers.");
RNA_def_property_flag(parm, PROP_REQUIRED|PROP_NEVER_NULL);
parm= 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, "", "Modifier settings to apply.");
@@ -442,7 +441,9 @@ void RNA_api_object(StructRNA *srna)
/* duplis */
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, needs to be freed manually with free_dupli_list.");
RNA_def_function_flag(func, FUNC_USE_CONTEXT|FUNC_USE_REPORTS);
parm= RNA_def_pointer(func, "scene", "Scene", "", "Scene within which to evaluate duplis.");
RNA_def_property_flag(parm, PROP_REQUIRED|PROP_NEVER_NULL);
RNA_def_function_flag(func, 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.");
@@ -508,12 +509,14 @@ void RNA_api_object(StructRNA *srna)
/* DAG */
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);
parm= RNA_def_pointer(func, "scene", "Scene", "", "");
RNA_def_property_flag(parm, PROP_REQUIRED|PROP_NEVER_NULL);
/* View */
func= RNA_def_function(srna, "is_visible", "rna_Object_is_visible");
RNA_def_function_ui_description(func, "Determine if object is visible in active scene.");
RNA_def_function_flag(func, FUNC_USE_CONTEXT);
RNA_def_function_ui_description(func, "Determine if object is visible in a given scene.");
parm= RNA_def_pointer(func, "scene", "Scene", "", "");
RNA_def_property_flag(parm, PROP_REQUIRED|PROP_NEVER_NULL);
parm= RNA_def_boolean(func, "is_visible", 0, "", "Object visibility.");
RNA_def_function_return(func, parm);
}

View File

@@ -431,7 +431,7 @@ static void rna_PoseChannel_active_constraint_set(PointerRNA *ptr, PointerRNA va
constraints_set_active(&pchan->constraints, (bConstraint *)value.data);
}
static bConstraint *rna_PoseChannel_constraints_new(bPoseChannel *pchan, bContext *C, int type)
static bConstraint *rna_PoseChannel_constraints_new(bPoseChannel *pchan, int type)
{
//WM_main_add_notifier(NC_OBJECT|ND_CONSTRAINT|NA_ADDED, object);
// TODO, pass object also
@@ -439,7 +439,7 @@ static bConstraint *rna_PoseChannel_constraints_new(bPoseChannel *pchan, bContex
return add_pose_constraint(NULL, pchan, NULL, type);
}
static int rna_PoseChannel_constraints_remove(bPoseChannel *pchan, bContext *C, int index)
static int rna_PoseChannel_constraints_remove(bPoseChannel *pchan, int index)
{
// TODO
//ED_object_constraint_set_active(object, NULL);
@@ -639,7 +639,6 @@ static void rna_def_pose_channel_constraints(BlenderRNA *brna, PropertyRNA *cpro
/* Constraint collection */
func= RNA_def_function(srna, "new", "rna_PoseChannel_constraints_new");
RNA_def_function_flag(func, FUNC_USE_CONTEXT);
RNA_def_function_ui_description(func, "Add a constraint to this object");
/* return type */
parm= RNA_def_pointer(func, "constraint", "Constraint", "", "New constraint.");
@@ -649,7 +648,6 @@ static void rna_def_pose_channel_constraints(BlenderRNA *brna, PropertyRNA *cpro
RNA_def_property_flag(parm, PROP_REQUIRED);
func= RNA_def_function(srna, "remove", "rna_PoseChannel_constraints_remove");
RNA_def_function_flag(func, FUNC_USE_CONTEXT);
RNA_def_function_ui_description(func, "Remove a constraint from this object.");
/* return type */
parm= RNA_def_boolean(func, "success", 0, "Success", "Removed the constraint successfully.");

View File

@@ -204,7 +204,7 @@ static Base *rna_Scene_object_link(Scene *scene, ReportList *reports, Object *ob
return base;
}
static void rna_Scene_object_unlink(Scene *scene, bContext *C, ReportList *reports, Object *ob)
static void rna_Scene_object_unlink(Scene *scene, ReportList *reports, Object *ob)
{
Base *base= object_in_scene(ob, scene);
if (!base) {
@@ -223,7 +223,7 @@ static void rna_Scene_object_unlink(Scene *scene, bContext *C, ReportList *repor
DAG_scene_sort(scene);
DAG_ids_flush_update(0);
WM_event_add_notifier(C, NC_SCENE|ND_OB_ACTIVE, scene);
WM_main_add_notifier(NC_SCENE|ND_OB_ACTIVE, scene);
}
static void rna_Scene_skgen_etch_template_set(PointerRNA *ptr, PointerRNA value)
@@ -2650,7 +2650,7 @@ static void rna_def_scene_objects(BlenderRNA *brna, PropertyRNA *cprop)
func= RNA_def_function(srna, "unlink", "rna_Scene_object_unlink");
RNA_def_function_ui_description(func, "Unlink object from scene.");
RNA_def_function_flag(func, FUNC_USE_CONTEXT|FUNC_USE_REPORTS);
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);

View File

@@ -46,7 +46,7 @@
static void rna_Scene_set_frame(Scene *scene, bContext *C, int frame)
static void rna_Scene_set_frame(Scene *scene, int frame)
{
scene->r.cfra= frame;
CLAMP(scene->r.cfra, MINAFRAME, MAXFRAME);
@@ -98,7 +98,6 @@ void RNA_api_scene(StructRNA *srna)
PropertyRNA *parm;
func= RNA_def_function(srna, "set_frame", "rna_Scene_set_frame");
RNA_def_function_flag(func, FUNC_USE_CONTEXT);
RNA_def_function_ui_description(func, "Set scene frame updating all objects immediately.");
parm= RNA_def_int(func, "frame", 0, MINAFRAME, MAXFRAME, "", "Frame number to set.", MINAFRAME, MAXFRAME);
RNA_def_property_flag(parm, PROP_REQUIRED);