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
042076e9
Commit
042076e9
authored
13 years ago
by
Campbell Barton
Browse files
Options
Downloads
Patches
Plain Diff
update for column major matrix's
parent
ecb4e968
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
animation_add_corrective_shape_key.py
+23
-67
23 additions, 67 deletions
animation_add_corrective_shape_key.py
with
23 additions
and
67 deletions
animation_add_corrective_shape_key.py
+
23
−
67
View file @
042076e9
...
@@ -24,10 +24,10 @@ bl_info = {
...
@@ -24,10 +24,10 @@ bl_info = {
"
api
"
:
36157
,
"
api
"
:
36157
,
'
location
'
:
'
Object Data > Shape Keys (Search: corrective)
'
,
'
location
'
:
'
Object Data > Shape Keys (Search: corrective)
'
,
'
description
'
:
'
Creates a corrective shape key for the current pose
'
,
'
description
'
:
'
Creates a corrective shape key for the current pose
'
,
"
wiki_url
"
:
"
http://wiki.blender.org/index.php/Extensions:2.
5
/Py/
"
\
"
wiki_url
"
:
"
http://wiki.blender.org/index.php/Extensions:2.
6
/Py/
"
"
Scripts/Animation/Corrective_Shape_Key
"
,
"
Scripts/Animation/Corrective_Shape_Key
"
,
"
tracker_url
"
:
"
https://projects.blender.org/tracker/index.php?
"
\
"
tracker_url
"
:
"
https://projects.blender.org/tracker/index.php?
"
"
func=detail&aid=22129
"
,
"
func=detail&aid=22129
"
,
'
category
'
:
'
Animation
'
}
'
category
'
:
'
Animation
'
}
"""
"""
...
@@ -51,33 +51,16 @@ Limitations:
...
@@ -51,33 +51,16 @@ Limitations:
import
bpy
import
bpy
import
mathutils
from
mathutils
import
Vector
,
Matrix
iterations
=
20
iterations
=
20
threshold
=
1e-16
threshold
=
1e-16
def
reset_transform
(
ob
):
def
reset_transform
(
ob
):
m
=
mathutils
.
Matrix
()
m
=
Matrix
()
ob
.
matrix_local
=
m
ob
.
matrix_local
=
m
# flips rotation matrix
def
flip_matrix_direction
(
m
):
mat
=
mathutils
.
Matrix
()
mat
[
0
][
0
]
=
m
[
0
][
0
]
mat
[
0
][
1
]
=
m
[
1
][
0
]
mat
[
0
][
2
]
=
m
[
2
][
0
]
mat
[
1
][
0
]
=
m
[
0
][
1
]
mat
[
1
][
1
]
=
m
[
1
][
1
]
mat
[
1
][
2
]
=
m
[
2
][
1
]
mat
[
2
][
0
]
=
m
[
0
][
2
]
mat
[
2
][
1
]
=
m
[
1
][
2
]
mat
[
2
][
2
]
=
m
[
2
][
2
]
return
mat
# this version is for shape_key data
# this version is for shape_key data
def
extractX
(
ob
,
mesh
):
def
extractX
(
ob
,
mesh
):
...
@@ -85,7 +68,7 @@ def extractX(ob, mesh):
...
@@ -85,7 +68,7 @@ def extractX(ob, mesh):
for
i
in
range
(
0
,
len
(
mesh
)):
for
i
in
range
(
0
,
len
(
mesh
)):
v
=
mesh
[
i
]
v
=
mesh
[
i
]
x
+=
[
mathutils
.
Vector
(
v
.
co
)]
x
+=
[
v
.
co
.
copy
(
)]
return
x
return
x
...
@@ -95,7 +78,7 @@ def extractX_2(ob, mesh):
...
@@ -95,7 +78,7 @@ def extractX_2(ob, mesh):
for
i
in
range
(
0
,
len
(
mesh
.
vertices
)):
for
i
in
range
(
0
,
len
(
mesh
.
vertices
)):
v
=
mesh
.
vertices
[
i
]
v
=
mesh
.
vertices
[
i
]
x
+=
[
mathutils
.
Vector
(
v
.
co
)]
x
+=
[
v
.
co
.
copy
(
)]
return
x
return
x
...
@@ -110,7 +93,7 @@ def extractMappedX(ob, mesh):
...
@@ -110,7 +93,7 @@ def extractMappedX(ob, mesh):
# to be at the end of the vertex array
# to be at the end of the vertex array
for
i
in
range
(
len
(
mesh
.
vertices
)
-
totvert
,
len
(
mesh
.
vertices
)):
for
i
in
range
(
len
(
mesh
.
vertices
)
-
totvert
,
len
(
mesh
.
vertices
)):
v
=
mesh
.
vertices
[
i
]
v
=
mesh
.
vertices
[
i
]
x
+=
[
mathutils
.
Vector
(
v
.
co
)]
x
+=
[
v
.
co
.
copy
(
)]
mesh
.
user_clear
()
mesh
.
user_clear
()
bpy
.
data
.
meshes
.
remove
(
mesh
)
bpy
.
data
.
meshes
.
remove
(
mesh
)
...
@@ -177,12 +160,12 @@ def func_add_corrective_pose_shape( source, target):
...
@@ -177,12 +160,12 @@ def func_add_corrective_pose_shape( source, target):
if
epsilon
<
threshold
:
if
epsilon
<
threshold
:
epsilon
=
0.0
epsilon
=
0.0
dx
[
0
]
+=
[
x
[
i
]
+
0.5
*
epsilon
*
mathutils
.
Vector
((
1
,
0
,
0
))]
dx
[
0
]
+=
[
x
[
i
]
+
0.5
*
epsilon
*
Vector
((
1
,
0
,
0
))]
dx
[
1
]
+=
[
x
[
i
]
+
0.5
*
epsilon
*
mathutils
.
Vector
((
-
1
,
0
,
0
))]
dx
[
1
]
+=
[
x
[
i
]
+
0.5
*
epsilon
*
Vector
((
-
1
,
0
,
0
))]
dx
[
2
]
+=
[
x
[
i
]
+
0.5
*
epsilon
*
mathutils
.
Vector
((
0
,
1
,
0
))]
dx
[
2
]
+=
[
x
[
i
]
+
0.5
*
epsilon
*
Vector
((
0
,
1
,
0
))]
dx
[
3
]
+=
[
x
[
i
]
+
0.5
*
epsilon
*
mathutils
.
Vector
((
0
,
-
1
,
0
))]
dx
[
3
]
+=
[
x
[
i
]
+
0.5
*
epsilon
*
Vector
((
0
,
-
1
,
0
))]
dx
[
4
]
+=
[
x
[
i
]
+
0.5
*
epsilon
*
mathutils
.
Vector
((
0
,
0
,
1
))]
dx
[
4
]
+=
[
x
[
i
]
+
0.5
*
epsilon
*
Vector
((
0
,
0
,
1
))]
dx
[
5
]
+=
[
x
[
i
]
+
0.5
*
epsilon
*
mathutils
.
Vector
((
0
,
0
,
-
1
))]
dx
[
5
]
+=
[
x
[
i
]
+
0.5
*
epsilon
*
Vector
((
0
,
0
,
-
1
))]
for
j
in
range
(
0
,
6
):
for
j
in
range
(
0
,
6
):
applyX
(
ob_1
,
mesh_1_key_verts
,
dx
[
j
])
applyX
(
ob_1
,
mesh_1_key_verts
,
dx
[
j
])
...
@@ -196,9 +179,7 @@ def func_add_corrective_pose_shape( source, target):
...
@@ -196,9 +179,7 @@ def func_add_corrective_pose_shape( source, target):
Gx
=
list
((
dx
[
0
][
i
]
-
dx
[
1
][
i
])
/
epsilon
)
Gx
=
list
((
dx
[
0
][
i
]
-
dx
[
1
][
i
])
/
epsilon
)
Gy
=
list
((
dx
[
2
][
i
]
-
dx
[
3
][
i
])
/
epsilon
)
Gy
=
list
((
dx
[
2
][
i
]
-
dx
[
3
][
i
])
/
epsilon
)
Gz
=
list
((
dx
[
4
][
i
]
-
dx
[
5
][
i
])
/
epsilon
)
Gz
=
list
((
dx
[
4
][
i
]
-
dx
[
5
][
i
])
/
epsilon
)
G
=
mathutils
.
Matrix
((
Gx
,
Gy
,
Gz
))
G
=
Matrix
((
Gx
,
Gy
,
Gz
))
G
=
flip_matrix_direction
(
G
)
x
[
i
]
+=
G
*
(
targetx
[
i
]
-
mapx
[
i
])
x
[
i
]
+=
G
*
(
targetx
[
i
]
-
mapx
[
i
])
applyX
(
ob_1
,
mesh_1_key_verts
,
x
)
applyX
(
ob_1
,
mesh_1_key_verts
,
x
)
...
@@ -269,39 +250,12 @@ class object_duplicate_flatten_modifiers(bpy.types.Operator):
...
@@ -269,39 +250,12 @@ class object_duplicate_flatten_modifiers(bpy.types.Operator):
n
.
select
=
True
n
.
select
=
True
return
{
'
FINISHED
'
}
return
{
'
FINISHED
'
}
def
flip_matrix_direction_4x4
(
m
):
mat
=
mathutils
.
Matrix
()
mat
[
0
][
0
]
=
m
[
0
][
0
]
mat
[
0
][
1
]
=
m
[
1
][
0
]
mat
[
0
][
2
]
=
m
[
2
][
0
]
mat
[
0
][
3
]
=
m
[
3
][
0
]
mat
[
1
][
0
]
=
m
[
0
][
1
]
mat
[
1
][
1
]
=
m
[
1
][
1
]
mat
[
1
][
2
]
=
m
[
2
][
1
]
mat
[
1
][
3
]
=
m
[
3
][
1
]
mat
[
2
][
0
]
=
m
[
0
][
2
]
mat
[
2
][
1
]
=
m
[
1
][
2
]
mat
[
2
][
2
]
=
m
[
2
][
2
]
mat
[
2
][
3
]
=
m
[
3
][
2
]
mat
[
3
][
0
]
=
m
[
0
][
3
]
mat
[
3
][
1
]
=
m
[
1
][
3
]
mat
[
3
][
2
]
=
m
[
2
][
3
]
mat
[
3
][
3
]
=
m
[
3
][
3
]
return
mat
def
unposeMesh
(
meshObToUnpose
,
meshObToUnposeWeightSrc
,
armatureOb
):
def
unposeMesh
(
meshObToUnpose
,
meshObToUnposeWeightSrc
,
armatureOb
):
psdMeshData
=
meshObToUnpose
psdMeshData
=
meshObToUnpose
psdMesh
=
psdMeshData
psdMesh
=
psdMeshData
I
=
mathutils
.
Matrix
()
#identity matrix
I
=
Matrix
()
#identity matrix
meshData
=
meshObToUnposeWeightSrc
.
data
meshData
=
meshObToUnposeWeightSrc
.
data
mesh
=
meshData
mesh
=
meshData
...
@@ -345,9 +299,11 @@ def unposeMesh(meshObToUnpose, meshObToUnposeWeightSrc, armatureOb):
...
@@ -345,9 +299,11 @@ def unposeMesh(meshObToUnpose, meshObToUnposeWeightSrc, armatureOb):
weightedAverageDictionary
[
pair
[
0
]]
=
pair
[
1
]
/
totalWeight
weightedAverageDictionary
[
pair
[
0
]]
=
pair
[
1
]
/
totalWeight
else
:
else
:
weightedAverageDictionary
[
pair
[
0
]]
=
0
weightedAverageDictionary
[
pair
[
0
]]
=
0
sigma
=
mathutils
.
Matrix
(
I
-
I
)
#Matrix filled with zeros
# Matrix filled with zeros
sigma
=
Matrix
()
sigma
.
zero
()
list
=
[]
list
=
[]
for
n
in
pbones
:
for
n
in
pbones
:
list
.
append
(
n
)
list
.
append
(
n
)
...
@@ -358,7 +314,7 @@ def unposeMesh(meshObToUnpose, meshObToUnposeWeightSrc, armatureOb):
...
@@ -358,7 +314,7 @@ def unposeMesh(meshObToUnpose, meshObToUnposeWeightSrc, armatureOb):
#~ print("found key %s", pbone.name)
#~ print("found key %s", pbone.name)
vertexWeight
=
weightedAverageDictionary
[
pbone
.
name
]
vertexWeight
=
weightedAverageDictionary
[
pbone
.
name
]
m
=
pbone
.
matrix_channel
.
copy
()
m
=
pbone
.
matrix_channel
.
copy
()
#m
= flip_matrix_direction_4x4(m
)
#m
.transpose(
)
sigma
+=
(
m
-
I
)
*
vertexWeight
sigma
+=
(
m
-
I
)
*
vertexWeight
else
:
else
:
...
...
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