Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
blender-addons
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
blender
blender-addons
Commits
dee864a8
Commit
dee864a8
authored
14 years ago
by
Florian Meyer
Browse files
Options
Downloads
Patches
Plain Diff
-fixed view_align problem
doesn't snap back anymore when changing properties
parent
3db602cf
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
add_mesh_gears.py
+30
-20
30 additions, 20 deletions
add_mesh_gears.py
with
30 additions
and
20 deletions
add_mesh_gears.py
+
30
−
20
View file @
dee864a8
...
...
@@ -88,27 +88,13 @@ def store_recall_properties(ob, op, op_args):
ob
[
'
recall
'
]
=
recall_properties
# Apply view rotation to objects if "Align To" for
# new objects was set to "VIEW" in the User Preference.
def
apply_object_align
(
context
,
ob
):
obj_align
=
bpy
.
context
.
user_preferences
.
edit
.
object_align
if
(
context
.
space_data
.
type
==
'
VIEW_3D
'
and
obj_align
==
'
VIEW
'
):
view3d
=
context
.
space_data
region
=
view3d
.
region_3d
viewMatrix
=
region
.
view_matrix
rot
=
viewMatrix
.
rotation_part
()
ob
.
rotation_euler
=
rot
.
invert
().
to_euler
()
# Create a new mesh (object) from verts/edges/faces.
# verts/edges/faces ... List of vertices/edges/faces for the
# new mesh (as used in from_pydata).
# name ... Name of the new mesh (& object).
# edit ... Replace existing mesh data.
# Note: Using "edit" will destroy/delete existing mesh data.
def
create_mesh_object
(
context
,
verts
,
edges
,
faces
,
name
,
edit
):
def
create_mesh_object
(
context
,
verts
,
edges
,
faces
,
name
,
edit
,
newMatrix
):
scene
=
context
.
scene
obj_act
=
scene
.
objects
.
active
...
...
@@ -161,9 +147,9 @@ def create_mesh_object(context, verts, edges, faces, name, edit):
ob_new
.
selected
=
True
# Place the object at the 3D cursor location.
ob_new
.
location
=
scene
.
cursor_location
# apply viewRotaion
ob_new
.
matrix
=
newMatrix
apply_object_align
(
context
,
ob_new
)
if
obj_act
and
obj_act
.
mode
==
'
EDIT
'
:
if
not
edit
:
...
...
@@ -766,6 +752,7 @@ class AddGear(bpy.types.Operator):
min
=
0.0
,
max
=
100.0
,
default
=
0.0
)
newMatrix
=
'
fromInvoke
'
def
execute
(
self
,
context
):
props
=
self
.
properties
...
...
@@ -783,7 +770,7 @@ class AddGear(bpy.types.Operator):
crown
=
props
.
crown
)
# Actually create the mesh object from this geometry data.
obj
=
create_mesh_object
(
context
,
verts
,
[],
faces
,
"
Gear
"
,
props
.
edit
)
obj
=
create_mesh_object
(
context
,
verts
,
[],
faces
,
"
Gear
"
,
props
.
edit
,
self
.
newMatrix
)
# Store 'recall' properties in the object.
recall_args_list
=
{
...
...
@@ -811,6 +798,17 @@ class AddGear(bpy.types.Operator):
return
{
'
FINISHED
'
}
def
invoke
(
self
,
context
,
event
):
loc
=
mathutils
.
TranslationMatrix
(
context
.
scene
.
cursor_location
)
obj_align
=
context
.
user_preferences
.
edit
.
object_align
if
(
context
.
space_data
.
type
==
'
VIEW_3D
'
and
obj_align
==
'
VIEW
'
):
rot
=
context
.
space_data
.
region_3d
.
view_matrix
.
rotation_part
().
invert
().
resize4x4
()
else
:
rot
=
mathutils
.
RotationMatrix
()
self
.
newMatrix
=
loc
*
rot
self
.
execute
(
context
)
return
{
'
FINISHED
'
}
class
AddWormGear
(
bpy
.
types
.
Operator
):
'''
Add a worm gear mesh.
'''
...
...
@@ -868,6 +866,7 @@ class AddWormGear(bpy.types.Operator):
min
=
0.0
,
max
=
100.0
,
default
=
0.0
)
newMatrix
=
'
fromInvoke
'
def
execute
(
self
,
context
):
props
=
self
.
properties
...
...
@@ -885,7 +884,7 @@ class AddWormGear(bpy.types.Operator):
# Actually create the mesh object from this geometry data.
obj
=
create_mesh_object
(
context
,
verts
,
[],
faces
,
"
Worm Gear
"
,
props
.
edit
)
props
.
edit
,
self
.
newMatrix
)
# Store 'recall' properties in the object.
recall_args_list
=
{
...
...
@@ -912,6 +911,17 @@ class AddWormGear(bpy.types.Operator):
return
{
'
FINISHED
'
}
def
invoke
(
self
,
context
,
event
):
loc
=
mathutils
.
TranslationMatrix
(
context
.
scene
.
cursor_location
)
obj_align
=
context
.
user_preferences
.
edit
.
object_align
if
(
context
.
space_data
.
type
==
'
VIEW_3D
'
and
obj_align
==
'
VIEW
'
):
rot
=
context
.
space_data
.
region_3d
.
view_matrix
.
rotation_part
().
invert
().
resize4x4
()
else
:
rot
=
mathutils
.
RotationMatrix
()
self
.
newMatrix
=
loc
*
rot
self
.
execute
(
context
)
return
{
'
FINISHED
'
}
class
INFO_MT_mesh_gears_add
(
bpy
.
types
.
Menu
):
# Define the "Gears" menu
...
...
@@ -950,4 +960,4 @@ def unregister():
bpy
.
types
.
INFO_MT_mesh_add
.
remove
(
menu_func
)
if
__name__
==
"
__main__
"
:
register
()
register
()
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment