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
ef71d65d
Commit
ef71d65d
authored
14 years ago
by
Florian Meyer
Browse files
Options
Downloads
Patches
Plain Diff
align_matrix for the rest add mesh scripts
all done now
parent
d61abf20
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
add_mesh_star.py
+21
-16
21 additions, 16 deletions
add_mesh_star.py
add_mesh_twisted_torus.py
+19
-15
19 additions, 15 deletions
add_mesh_twisted_torus.py
add_mesh_wedge.py
+19
-15
19 additions, 15 deletions
add_mesh_wedge.py
with
59 additions
and
46 deletions
add_mesh_star.py
+
21
−
16
View file @
ef71d65d
...
...
@@ -34,7 +34,7 @@ bl_addon_info = {
import
bpy
import
mathutils
from
mathutils
import
Vector
,
Quaternion
from
mathutils
import
Vector
,
Quaternion
,
TranslationMatrix
,
Matrix
from
math
import
pi
from
bpy.props
import
IntProperty
,
FloatProperty
,
BoolProperty
...
...
@@ -59,18 +59,18 @@ 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 U
ser
P
ref
erence.
def
a
pply_object_align
(
context
,
ob
):
obj_align
=
bpy
.
context
.
user_preferences
.
edit
.
object_align
#
calculates the matrix for the new object
#
depending on u
ser
p
ref
def
a
lign_matrix
(
context
):
loc
=
TranslationMatrix
(
context
.
scene
.
cursor_location
)
obj_align
=
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_m
atrix
rot
=
viewMatrix
.
rotation_part
()
ob
.
rotation_euler
=
rot
.
invert
().
to_euler
()
rot
=
context
.
space_data
.
region_3d
.
view_matrix
.
rotation_part
().
invert
().
resize4x4
()
else
:
rot
=
M
atrix
()
align_matrix
=
loc
*
rot
return
align_matrix
# Create a new mesh (object) from verts/edges/faces.
...
...
@@ -79,7 +79,7 @@ def apply_object_align(context, ob):
# 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
,
align_matrix
):
scene
=
context
.
scene
obj_act
=
scene
.
objects
.
active
...
...
@@ -132,9 +132,8 @@ 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_object_align
(
context
,
ob_new
)
# apply viewRotaion
ob_new
.
matrix
=
align_matrix
if
obj_act
and
obj_act
.
mode
==
'
EDIT
'
:
if
not
edit
:
...
...
@@ -315,6 +314,7 @@ class AddStar(bpy.types.Operator):
min
=
0.01
,
max
=
9999.0
,
default
=
0.5
)
align_matrix
=
Matrix
()
def
execute
(
self
,
context
):
props
=
self
.
properties
...
...
@@ -326,7 +326,7 @@ class AddStar(bpy.types.Operator):
props
.
height
)
obj
=
create_mesh_object
(
context
,
verts
,
[],
faces
,
"
Star
"
,
props
.
edit
)
props
.
edit
,
self
.
align_matrix
)
# Store 'recall' properties in the object.
recall_args_list
=
{
...
...
@@ -339,6 +339,11 @@ class AddStar(bpy.types.Operator):
return
{
'
FINISHED
'
}
def
invoke
(
self
,
context
,
event
):
self
.
align_matrix
=
align_matrix
(
context
)
self
.
execute
(
context
)
return
{
'
FINISHED
'
}
# Register the operator
menu_func
=
(
lambda
self
,
context
:
self
.
layout
.
operator
(
AddStar
.
bl_idname
,
...
...
This diff is collapsed.
Click to expand it.
add_mesh_twisted_torus.py
+
19
−
15
View file @
ef71d65d
...
...
@@ -80,18 +80,18 @@ 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 U
ser
P
ref
erence.
def
a
pply_object_align
(
context
,
ob
):
obj_align
=
bpy
.
context
.
user_preferences
.
edit
.
object_align
#
calculates the matrix for the new object
#
depending on u
ser
p
ref
def
a
lign_matrix
(
context
):
loc
=
TranslationMatrix
(
context
.
scene
.
cursor_location
)
obj_align
=
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_m
atrix
rot
=
viewMatrix
.
rotation_part
()
ob
.
rotation_euler
=
rot
.
invert
().
to_euler
()
rot
=
context
.
space_data
.
region_3d
.
view_matrix
.
rotation_part
().
invert
().
resize4x4
()
else
:
rot
=
M
atrix
()
align_matrix
=
loc
*
rot
return
align_matrix
# Create a new mesh (object) from verts/edges/faces.
...
...
@@ -100,7 +100,7 @@ def apply_object_align(context, ob):
# 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
,
align_matrix
):
scene
=
context
.
scene
obj_act
=
scene
.
objects
.
active
...
...
@@ -153,9 +153,8 @@ 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_object_align
(
context
,
ob_new
)
# apply viewRotaion
ob_new
.
matrix
=
align_matrix
if
obj_act
and
obj_act
.
mode
==
'
EDIT
'
:
if
not
edit
:
...
...
@@ -349,6 +348,7 @@ class AddTwistedTorus(bpy.types.Operator):
min
=
0.01
,
max
=
100.0
,
default
=
0.5
)
align_matrix
=
Matrix
()
def
execute
(
self
,
context
):
props
=
self
.
properties
...
...
@@ -367,7 +367,7 @@ class AddTwistedTorus(bpy.types.Operator):
# Actually create the mesh object from this geometry data.
obj
=
create_mesh_object
(
context
,
verts
,
[],
faces
,
"
TwistedTorus
"
,
props
.
edit
)
props
.
edit
,
self
.
align_matrix
)
# Store 'recall' properties in the object.
recall_args_list
=
{
...
...
@@ -384,6 +384,10 @@ class AddTwistedTorus(bpy.types.Operator):
return
{
'
FINISHED
'
}
def
invoke
(
self
,
context
,
event
):
self
.
align_matrix
=
align_matrix
(
context
)
self
.
execute
(
context
)
return
{
'
FINISHED
'
}
# Add to the menu
menu_func
=
(
lambda
self
,
...
...
This diff is collapsed.
Click to expand it.
add_mesh_wedge.py
+
19
−
15
View file @
ef71d65d
...
...
@@ -76,18 +76,18 @@ 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 U
ser
P
ref
erence.
def
a
pply_object_align
(
context
,
ob
):
obj_align
=
bpy
.
context
.
user_preferences
.
edit
.
object_align
#
calculates the matrix for the new object
#
depending on u
ser
p
ref
def
a
lign_matrix
(
context
):
loc
=
TranslationMatrix
(
context
.
scene
.
cursor_location
)
obj_align
=
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_m
atrix
rot
=
viewMatrix
.
rotation_part
()
ob
.
rotation_euler
=
rot
.
invert
().
to_euler
()
rot
=
context
.
space_data
.
region_3d
.
view_matrix
.
rotation_part
().
invert
().
resize4x4
()
else
:
rot
=
M
atrix
()
align_matrix
=
loc
*
rot
return
align_matrix
# Create a new mesh (object) from verts/edges/faces.
...
...
@@ -96,7 +96,7 @@ def apply_object_align(context, ob):
# 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
,
align_matrix
):
scene
=
context
.
scene
obj_act
=
scene
.
objects
.
active
...
...
@@ -149,9 +149,8 @@ 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_object_align
(
context
,
ob_new
)
# apply viewRotaion
ob_new
.
matrix
=
align_matrix
if
obj_act
and
obj_act
.
mode
==
'
EDIT
'
:
if
not
edit
:
...
...
@@ -310,6 +309,7 @@ class AddWedge(bpy.types.Operator):
min
=
0.01
,
max
=
9999.0
,
default
=
2.00
)
align_matrix
=
Matrix
()
def
execute
(
self
,
context
):
props
=
self
.
properties
...
...
@@ -320,7 +320,7 @@ class AddWedge(bpy.types.Operator):
props
.
size_z
)
obj
=
create_mesh_object
(
context
,
verts
,
[],
faces
,
"
Wedge
"
,
props
.
edit
)
props
.
edit
,
self
.
align_matrix
)
# Store 'recall' properties in the object.
recall_args_list
=
{
...
...
@@ -332,6 +332,10 @@ class AddWedge(bpy.types.Operator):
return
{
'
FINISHED
'
}
def
invoke
(
self
,
context
,
event
):
self
.
align_matrix
=
align_matrix
(
context
)
self
.
execute
(
context
)
return
{
'
FINISHED
'
}
# Register the operator
menu_func
=
(
lambda
self
,
context
:
self
.
layout
.
operator
(
AddWedge
.
bl_idname
,
...
...
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