forked from bartvdbraak/blender
bugfix [#21233] Crash in pyapi, with new object.
pass the obdata as an argument rather then assigning later so as not to allow an invalid state.
This commit is contained in:
parent
835c353aaa
commit
bc3d96678d
@ -322,8 +322,7 @@ class AddGear(bpy.types.Operator):
|
|||||||
|
|
||||||
mesh.update()
|
mesh.update()
|
||||||
|
|
||||||
ob_new = bpy.data.objects.new('Gear','MESH')
|
ob_new = bpy.data.objects.new('Gear', mesh)
|
||||||
ob_new.data = mesh
|
|
||||||
|
|
||||||
tipgroup = ob_new.add_vertex_group('Tips')
|
tipgroup = ob_new.add_vertex_group('Tips')
|
||||||
# for some reason the name does not 'stick' and we have to set it this way:
|
# for some reason the name does not 'stick' and we have to set it this way:
|
||||||
|
@ -447,8 +447,7 @@ def write(filename, objects, scene,
|
|||||||
break
|
break
|
||||||
|
|
||||||
if has_quads:
|
if has_quads:
|
||||||
newob = bpy.data.objects.new('temp_object', 'MESH')
|
newob = bpy.data.objects.new('temp_object', me)
|
||||||
newob.data = me
|
|
||||||
# if we forget to set Object.data - crash
|
# if we forget to set Object.data - crash
|
||||||
scene.objects.link(newob)
|
scene.objects.link(newob)
|
||||||
newob.convert_to_triface(scene)
|
newob.convert_to_triface(scene)
|
||||||
|
@ -295,7 +295,7 @@ def bvh_node_dict2objects(context, bvh_nodes, IMPORT_START_FRAME=1, IMPORT_LOOP=
|
|||||||
objects = []
|
objects = []
|
||||||
|
|
||||||
def add_ob(name):
|
def add_ob(name):
|
||||||
ob = scn.objects.new('Empty')
|
ob = scn.objects.new('Empty', None)
|
||||||
objects.append(ob)
|
objects.append(ob)
|
||||||
return ob
|
return ob
|
||||||
|
|
||||||
@ -352,8 +352,7 @@ def bvh_node_dict2armature(context, bvh_nodes, ROT_MODE='XYZ', IMPORT_START_FRAM
|
|||||||
scn.set_frame(IMPORT_START_FRAME)
|
scn.set_frame(IMPORT_START_FRAME)
|
||||||
|
|
||||||
arm_data = bpy.data.armatures.new("MyBVH")
|
arm_data = bpy.data.armatures.new("MyBVH")
|
||||||
arm_ob = bpy.data.objects.new("MyBVH", 'ARMATURE')
|
arm_ob = bpy.data.objects.new("MyBVH", arm_data)
|
||||||
arm_ob.data = arm_data
|
|
||||||
|
|
||||||
scn.objects.link(arm_ob)
|
scn.objects.link(arm_ob)
|
||||||
|
|
||||||
|
@ -418,8 +418,7 @@ def process_next_chunk(file, previous_chunk, importedObjects, IMAGE_SEARCH):
|
|||||||
uf.tex = True
|
uf.tex = True
|
||||||
|
|
||||||
# bmesh.transform(contextMatrix)
|
# bmesh.transform(contextMatrix)
|
||||||
ob = bpy.data.objects.new(tempName, 'MESH')
|
ob = bpy.data.objects.new(tempName, bmesh)
|
||||||
ob.data = bmesh
|
|
||||||
SCN.objects.link(ob)
|
SCN.objects.link(ob)
|
||||||
# ob = SCN_OBJECTS.new(bmesh, tempName)
|
# ob = SCN_OBJECTS.new(bmesh, tempName)
|
||||||
'''
|
'''
|
||||||
@ -638,8 +637,7 @@ def process_next_chunk(file, previous_chunk, importedObjects, IMAGE_SEARCH):
|
|||||||
x,y,z = struct.unpack('<3f', temp_data)
|
x,y,z = struct.unpack('<3f', temp_data)
|
||||||
new_chunk.bytes_read += STRUCT_SIZE_3FLOAT
|
new_chunk.bytes_read += STRUCT_SIZE_3FLOAT
|
||||||
|
|
||||||
ob = bpy.data.objects.new("Lamp", 'LAMP')
|
ob = bpy.data.objects.new("Lamp", bpy.data.lamps.new("Lamp"))
|
||||||
ob.data = bpy.data.lamps.new("Lamp")
|
|
||||||
SCN.objects.link(ob)
|
SCN.objects.link(ob)
|
||||||
|
|
||||||
contextLamp[1]= ob.data
|
contextLamp[1]= ob.data
|
||||||
|
@ -863,10 +863,8 @@ def create_mesh(scn, new_objects, has_ngons, CREATE_FGONS, CREATE_EDGES, verts_l
|
|||||||
me.update()
|
me.update()
|
||||||
# me.calcNormals()
|
# me.calcNormals()
|
||||||
|
|
||||||
ob= bpy.data.objects.new("Mesh", 'MESH')
|
ob= bpy.data.objects.new("Mesh", me)
|
||||||
ob.data= me
|
|
||||||
scn.objects.link(ob)
|
scn.objects.link(ob)
|
||||||
# ob= scn.objects.new(me)
|
|
||||||
new_objects.append(ob)
|
new_objects.append(ob)
|
||||||
|
|
||||||
# Create the vertex groups. No need to have the flag passed here since we test for the
|
# Create the vertex groups. No need to have the flag passed here since we test for the
|
||||||
|
@ -182,8 +182,7 @@ def generate_rig(context, obj_orig, prefix="ORG-", META_DEF=True):
|
|||||||
try:
|
try:
|
||||||
obj = scene.objects[name]
|
obj = scene.objects[name]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
obj = bpy.data.objects.new(name, type='ARMATURE')
|
obj = bpy.data.objects.new(name, bpy.data.armatures.new(name))
|
||||||
obj.data = bpy.data.armatures.new(name)
|
|
||||||
scene.objects.link(obj)
|
scene.objects.link(obj)
|
||||||
|
|
||||||
obj.data.pose_position = 'POSE'
|
obj.data.pose_position = 'POSE'
|
||||||
@ -487,9 +486,8 @@ def generate_test(context, metarig_type="", GENERATE_FINAL=True):
|
|||||||
scene = context.scene
|
scene = context.scene
|
||||||
|
|
||||||
def create_empty_armature(name):
|
def create_empty_armature(name):
|
||||||
obj_new = bpy.data.objects.new(name, 'ARMATURE')
|
|
||||||
armature = bpy.data.armatures.new(name)
|
armature = bpy.data.armatures.new(name)
|
||||||
obj_new.data = armature
|
obj_new = bpy.data.objects.new(name, armature)
|
||||||
scene.objects.link(obj_new)
|
scene.objects.link(obj_new)
|
||||||
scene.objects.active = obj_new
|
scene.objects.active = obj_new
|
||||||
for obj in scene.objects:
|
for obj in scene.objects:
|
||||||
|
@ -130,8 +130,7 @@ class AddTorus(bpy.types.Operator):
|
|||||||
ob.selected = False
|
ob.selected = False
|
||||||
|
|
||||||
mesh.update()
|
mesh.update()
|
||||||
ob_new = bpy.data.objects.new("Torus", 'MESH')
|
ob_new = bpy.data.objects.new("Torus", mesh)
|
||||||
ob_new.data = mesh
|
|
||||||
scene.objects.link(ob_new)
|
scene.objects.link(ob_new)
|
||||||
ob_new.selected = True
|
ob_new.selected = True
|
||||||
|
|
||||||
|
@ -447,13 +447,11 @@ class MakeDupliFace(bpy.types.Operator):
|
|||||||
# pick an object to use
|
# pick an object to use
|
||||||
obj = objects[0]
|
obj = objects[0]
|
||||||
|
|
||||||
ob_new = bpy.data.objects.new(mesh.name, 'MESH')
|
ob_new = bpy.data.objects.new(mesh.name, mesh)
|
||||||
ob_new.data = mesh
|
|
||||||
base = scene.objects.link(ob_new)
|
base = scene.objects.link(ob_new)
|
||||||
base.layers[:] = obj.layers
|
base.layers[:] = obj.layers
|
||||||
|
|
||||||
ob_inst = bpy.data.objects.new(data.name, obj.type)
|
ob_inst = bpy.data.objects.new(data.name, data)
|
||||||
ob_inst.data = data
|
|
||||||
base = scene.objects.link(ob_inst)
|
base = scene.objects.link(ob_inst)
|
||||||
base.layers[:] = obj.layers
|
base.layers[:] = obj.layers
|
||||||
|
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "RNA_define.h"
|
#include "RNA_define.h"
|
||||||
|
#include "RNA_access.h"
|
||||||
#include "RNA_types.h"
|
#include "RNA_types.h"
|
||||||
#include "RNA_enum_types.h"
|
#include "RNA_enum_types.h"
|
||||||
|
|
||||||
@ -38,6 +39,7 @@
|
|||||||
#ifdef RNA_RUNTIME
|
#ifdef RNA_RUNTIME
|
||||||
|
|
||||||
#include "BKE_main.h"
|
#include "BKE_main.h"
|
||||||
|
#include "BKE_curve.h"
|
||||||
#include "BKE_mesh.h"
|
#include "BKE_mesh.h"
|
||||||
#include "BKE_armature.h"
|
#include "BKE_armature.h"
|
||||||
#include "BKE_library.h"
|
#include "BKE_library.h"
|
||||||
@ -109,12 +111,54 @@ void rna_Main_scenes_remove(Main *bmain, bContext *C, ReportList *reports, struc
|
|||||||
unlink_scene(bmain, scene, newscene);
|
unlink_scene(bmain, scene, newscene);
|
||||||
}
|
}
|
||||||
|
|
||||||
Object *rna_Main_objects_new(Main *bmain, char* name, int type)
|
Object *rna_Main_objects_new(Main *bmain, ReportList *reports, char* name, ID *data)
|
||||||
{
|
{
|
||||||
Object *ob= add_only_object(type, name);
|
Object *ob;
|
||||||
|
int type= OB_EMPTY;
|
||||||
|
if(data) {
|
||||||
|
switch(GS(data->name)) {
|
||||||
|
case ID_ME:
|
||||||
|
type= OB_MESH;
|
||||||
|
break;
|
||||||
|
case ID_CU:
|
||||||
|
type= curve_type((struct Curve *)data);
|
||||||
|
break;
|
||||||
|
case ID_MB:
|
||||||
|
type= OB_MBALL;
|
||||||
|
break;
|
||||||
|
case ID_LA:
|
||||||
|
type= OB_LAMP;
|
||||||
|
break;
|
||||||
|
case ID_CA:
|
||||||
|
type= OB_CAMERA;
|
||||||
|
break;
|
||||||
|
case ID_LT:
|
||||||
|
type= OB_LATTICE;
|
||||||
|
break;
|
||||||
|
case ID_AR:
|
||||||
|
type= OB_ARMATURE;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
const char *idname;
|
||||||
|
if(RNA_enum_id_from_value(id_type_items, GS(data->name), &idname) == 0)
|
||||||
|
idname= "UNKNOWN";
|
||||||
|
|
||||||
|
BKE_reportf(reports, RPT_ERROR, "ID type '%s' is not valid for a object.", idname);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
data->us++;
|
||||||
|
}
|
||||||
|
|
||||||
|
ob= add_only_object(type, name);
|
||||||
ob->id.us--;
|
ob->id.us--;
|
||||||
|
|
||||||
|
ob->data= data;
|
||||||
return ob;
|
return ob;
|
||||||
}
|
}
|
||||||
|
|
||||||
void rna_Main_objects_remove(Main *bmain, ReportList *reports, struct Object *object)
|
void rna_Main_objects_remove(Main *bmain, ReportList *reports, struct Object *object)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
@ -337,10 +381,11 @@ void RNA_def_main_objects(BlenderRNA *brna, PropertyRNA *cprop)
|
|||||||
RNA_def_struct_ui_text(srna, "Main Objects", "Collection of objects");
|
RNA_def_struct_ui_text(srna, "Main Objects", "Collection of objects");
|
||||||
|
|
||||||
func= RNA_def_function(srna, "new", "rna_Main_objects_new");
|
func= RNA_def_function(srna, "new", "rna_Main_objects_new");
|
||||||
|
RNA_def_function_flag(func, FUNC_USE_REPORTS);
|
||||||
RNA_def_function_ui_description(func, "Add a new object to the main database");
|
RNA_def_function_ui_description(func, "Add a new object to the main database");
|
||||||
parm= RNA_def_string(func, "name", "Object", 0, "", "New name for the datablock.");
|
parm= RNA_def_string(func, "name", "Object", 0, "", "New name for the datablock.");
|
||||||
RNA_def_property_flag(parm, PROP_REQUIRED);
|
RNA_def_property_flag(parm, PROP_REQUIRED);
|
||||||
parm= RNA_def_enum(func, "type", object_type_items, 0, "", "Type of Object.");
|
parm= RNA_def_pointer(func, "object_data", "ID", "", "Object data or None for an empty object.");
|
||||||
RNA_def_property_flag(parm, PROP_REQUIRED);
|
RNA_def_property_flag(parm, PROP_REQUIRED);
|
||||||
|
|
||||||
/* return type */
|
/* return type */
|
||||||
|
Loading…
Reference in New Issue
Block a user