forked from bartvdbraak/blender
- base_object.layers_from_view(view3d), needed for setting local layers
- module 'add_object_utils', so each script doesnt need its own add object code, dealing with layers, scene, cursor location, editmode etc.
This commit is contained in:
parent
c249d2b95a
commit
f1b9d395e3
57
release/scripts/modules/add_object_utils.py
Normal file
57
release/scripts/modules/add_object_utils.py
Normal file
@ -0,0 +1,57 @@
|
||||
# ##### 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
#
|
||||
# ##### END GPL LICENSE BLOCK #####
|
||||
|
||||
# <pep8 compliant>
|
||||
|
||||
import bpy
|
||||
|
||||
def add_object_data(obdata, context):
|
||||
|
||||
scene = context.scene
|
||||
|
||||
# ugh, could be made nicer
|
||||
for ob in scene.objects:
|
||||
ob.selected = False
|
||||
|
||||
obj_new = bpy.data.objects.new(obdata.name, obdata)
|
||||
|
||||
base = scene.objects.link(obj_new)
|
||||
base.selected = True
|
||||
|
||||
if context.space_data and context.space_data.type == 'VIEW_3D':
|
||||
base.layers_from_view(context.space_data)
|
||||
|
||||
# TODO, local view cursor!
|
||||
obj_new.location = scene.cursor_location
|
||||
|
||||
obj_act = scene.objects.active
|
||||
|
||||
if obj_act and obj_act.mode == 'EDIT' and obj_act.type == obj_new.type:
|
||||
bpy.ops.object.mode_set(mode='OBJECT')
|
||||
|
||||
obj_act.selected = True
|
||||
scene.update() # apply location
|
||||
#scene.objects.active = obj_new
|
||||
|
||||
bpy.ops.object.join() # join into the active.
|
||||
|
||||
bpy.ops.object.mode_set(mode='EDIT')
|
||||
else:
|
||||
scene.objects.active = obj_new
|
||||
if context.user_preferences.edit.enter_edit_mode:
|
||||
bpy.ops.object.mode_set(mode='EDIT')
|
@ -120,36 +120,10 @@ class AddTorus(bpy.types.Operator):
|
||||
mesh.add_geometry(int(len(verts_loc) / 3), 0, int(len(faces) / 4))
|
||||
mesh.verts.foreach_set("co", verts_loc)
|
||||
mesh.faces.foreach_set("verts_raw", faces)
|
||||
|
||||
scene = context.scene
|
||||
|
||||
# ugh
|
||||
for ob in scene.objects:
|
||||
ob.selected = False
|
||||
|
||||
mesh.update()
|
||||
ob_new = bpy.data.objects.new("Torus", mesh)
|
||||
scene.objects.link(ob_new)
|
||||
ob_new.selected = True
|
||||
|
||||
ob_new.location = scene.cursor_location
|
||||
|
||||
obj_act = scene.objects.active
|
||||
|
||||
if obj_act and obj_act.mode == 'EDIT':
|
||||
bpy.ops.object.mode_set(mode='OBJECT')
|
||||
|
||||
obj_act.selected = True
|
||||
scene.update() # apply location
|
||||
#scene.objects.active = ob_new
|
||||
|
||||
bpy.ops.object.join() # join into the active.
|
||||
|
||||
bpy.ops.object.mode_set(mode='EDIT')
|
||||
else:
|
||||
scene.objects.active = ob_new
|
||||
if context.user_preferences.edit.enter_edit_mode:
|
||||
bpy.ops.object.mode_set(mode='EDIT')
|
||||
import add_object_utils
|
||||
add_object_utils.add_object_data(mesh, context)
|
||||
|
||||
return {'FINISHED'}
|
||||
|
||||
|
@ -241,7 +241,6 @@ static int screen_opengl_render_init(bContext *C, wmOperator *op)
|
||||
static void screen_opengl_render_end(bContext *C, OGLRender *oglrender)
|
||||
{
|
||||
Scene *scene= oglrender->scene;
|
||||
int view_context = (oglrender->v3d != NULL);
|
||||
|
||||
if(oglrender->mh) {
|
||||
if(BKE_imtype_is_movie(scene->r.imtype))
|
||||
|
@ -227,6 +227,7 @@ void RNA_api_main(struct StructRNA *srna);
|
||||
void RNA_api_material(StructRNA *srna);
|
||||
void RNA_api_mesh(struct StructRNA *srna);
|
||||
void RNA_api_object(struct StructRNA *srna);
|
||||
void RNA_api_object_base(struct StructRNA *srna);
|
||||
void RNA_api_pose_channel(struct StructRNA *srna);
|
||||
void RNA_api_scene(struct StructRNA *srna);
|
||||
void RNA_api_scene_render(struct StructRNA *srna);
|
||||
|
@ -2050,7 +2050,7 @@ static void rna_def_dupli_object(BlenderRNA *brna)
|
||||
/* TODO: DupliObject has more properties that can be wrapped */
|
||||
}
|
||||
|
||||
static void rna_def_base(BlenderRNA *brna)
|
||||
static void rna_def_object_base(BlenderRNA *brna)
|
||||
{
|
||||
StructRNA *srna;
|
||||
PropertyRNA *prop;
|
||||
@ -2081,13 +2081,15 @@ static void rna_def_base(BlenderRNA *brna)
|
||||
RNA_def_property_boolean_sdna(prop, NULL, "flag", BA_WAS_SEL);
|
||||
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
|
||||
RNA_def_property_ui_text(prop, "User Selected", "Object base user selection state, used to restore user selection after transformations");
|
||||
|
||||
RNA_api_object_base(srna);
|
||||
}
|
||||
|
||||
void RNA_def_object(BlenderRNA *brna)
|
||||
{
|
||||
rna_def_object(brna);
|
||||
rna_def_object_game_settings(brna);
|
||||
rna_def_base(brna);
|
||||
rna_def_object_base(brna);
|
||||
rna_def_vertex_group(brna);
|
||||
rna_def_material_slot(brna);
|
||||
rna_def_dupli_object(brna);
|
||||
|
@ -65,6 +65,7 @@
|
||||
#include "DNA_curve_types.h"
|
||||
#include "DNA_modifier_types.h"
|
||||
#include "DNA_constraint_types.h"
|
||||
#include "DNA_view3d_types.h"
|
||||
|
||||
#include "MEM_guardedalloc.h"
|
||||
|
||||
@ -405,6 +406,13 @@ void rna_Object_ray_cast(Object *ob, ReportList *reports, float ray_start[3], fl
|
||||
*index= -1;
|
||||
}
|
||||
|
||||
/* ObjectBase */
|
||||
|
||||
void rna_ObjectBase_layers_from_view(Base *base, View3D *v3d)
|
||||
{
|
||||
base->lay= base->object->lay= v3d->lay;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
void RNA_api_object(StructRNA *srna)
|
||||
@ -521,5 +529,17 @@ void RNA_api_object(StructRNA *srna)
|
||||
RNA_def_function_return(func, parm);
|
||||
}
|
||||
|
||||
|
||||
void RNA_api_object_base(StructRNA *srna)
|
||||
{
|
||||
FunctionRNA *func;
|
||||
PropertyRNA *parm;
|
||||
|
||||
func= RNA_def_function(srna, "layers_from_view", "rna_ObjectBase_layers_from_view");
|
||||
RNA_def_function_ui_description(func, "Sets the object layers from a 3D View (use when adding an object in local view).");
|
||||
parm= RNA_def_pointer(func, "view", "SpaceView3D", "", "");
|
||||
RNA_def_property_flag(parm, PROP_REQUIRED|PROP_NEVER_NULL);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user