Removed debug line added when testing for matrix memory leaks that messed up matrix.invert()

updated bvh import which was modified to account for that. as well as other minor changes.
This commit is contained in:
Campbell Barton 2006-08-06 22:47:57 +00:00
parent 4c2ce83986
commit 531cd7c0fc
4 changed files with 45 additions and 11 deletions

@ -2,7 +2,6 @@ import Blender
from Blender import Mathutils, Window, Scene, Draw, Mesh from Blender import Mathutils, Window, Scene, Draw, Mesh
from Blender.Mathutils import CrossVecs, Matrix, Vector, Intersect, LineIntersect from Blender.Mathutils import CrossVecs, Matrix, Vector, Intersect, LineIntersect
# DESCRIPTION: # DESCRIPTION:
# screen_x, screen_y the origin point of the pick ray # screen_x, screen_y the origin point of the pick ray
# it is either the mouse location # it is either the mouse location
@ -44,7 +43,7 @@ def mouseViewRay(screen_x, screen_y, localMatrix=None, useMid = False):
# sorry - i cannot explain here what they all do # sorry - i cannot explain here what they all do
# - if you're not familiar with all those matrices take a look at an introduction to OpenGL... # - if you're not familiar with all those matrices take a look at an introduction to OpenGL...
pm = Window.GetPerspMatrix() # the prespective matrix pm = Window.GetPerspMatrix() # the prespective matrix
pmi = pm.inverted() # the inverted perspective matrix pmi = Matrix(pm); pmi.invert() # the inverted perspective matrix
if (1.0 - epsilon < pmi[3][3] < 1.0 + epsilon): if (1.0 - epsilon < pmi[3][3] < 1.0 + epsilon):
# pmi[3][3] is 1.0 if the 3dwin is in ortho-projection mode (toggled with numpad 5) # pmi[3][3] is 1.0 if the 3dwin is in ortho-projection mode (toggled with numpad 5)
@ -54,7 +53,7 @@ def mouseViewRay(screen_x, screen_y, localMatrix=None, useMid = False):
# ortho mode: is a bit strange - actually there's no definite location of the camera ... # ortho mode: is a bit strange - actually there's no definite location of the camera ...
# but the camera could be displaced anywhere along the viewing direction. # but the camera could be displaced anywhere along the viewing direction.
ortho_d[:] = Window.GetViewVector() ortho_d.x, ortho_d.y, ortho_d.z = Window.GetViewVector()
ortho_d.w = 0 ortho_d.w = 0
# all rays are parallel in ortho mode - so the direction vector is simply the viewing direction # all rays are parallel in ortho mode - so the direction vector is simply the viewing direction
@ -73,7 +72,7 @@ def mouseViewRay(screen_x, screen_y, localMatrix=None, useMid = False):
# is used in sculpt_mesh to initialize backface culling...) # is used in sculpt_mesh to initialize backface culling...)
else: else:
# PERSPECTIVE MODE: here everything is well defined - all rays converge at the camera's location # PERSPECTIVE MODE: here everything is well defined - all rays converge at the camera's location
vmi = Window.GetViewMatrix().inverted() # the inverse viewing matrix vmi = Matrix(Window.GetViewMatrix()); vmi.invert() # the inverse viewing matrix
fp = mouseViewRay.fp fp = mouseViewRay.fp
dx = pm[3][3] * (((screen_x-win_min_x)/win_size_x)-1.0) - pm[3][0] dx = pm[3][3] * (((screen_x-win_min_x)/win_size_x)-1.0) - pm[3][0]
@ -104,9 +103,13 @@ def mouseViewRay(screen_x, screen_y, localMatrix=None, useMid = False):
# Do we want to return a direction in object's localspace? # Do we want to return a direction in object's localspace?
if localMatrix: if localMatrix:
localInvMatrix = localMatrix.inverted() localInvMatrix = Matrix(localMatrix)
localInvMatrix.invert()
p = p*localInvMatrix p = p*localInvMatrix
d = d*localInvMatrix.rotationPart() # normalize_v3 d = d*localInvMatrix # normalize_v3
p.x += localInvMatrix[3][0]
p.y += localInvMatrix[3][1]
p.z += localInvMatrix[3][2]
#else: # Worldspace, do nothing #else: # Worldspace, do nothing
@ -124,6 +127,37 @@ mouseViewRay.fp = Vector(0,0,0)
mouseViewRay.hms = Vector(0,0,0,0) # ortho only 4d mouseViewRay.hms = Vector(0,0,0,0) # ortho only 4d
mouseViewRay.ortho_d = Vector(0,0,0,0) # ortho only 4d mouseViewRay.ortho_d = Vector(0,0,0,0) # ortho only 4d
LMB= Window.MButs['L']
def mouseup():
# Loop until click
mouse_buttons = Window.GetMouseButtons()
while not mouse_buttons & LMB:
Blender.sys.sleep(10)
mouse_buttons = Window.GetMouseButtons()
while mouse_buttons & LMB:
Blender.sys.sleep(10)
mouse_buttons = Window.GetMouseButtons()
if __name__=='__main__':
mouseup()
x,y= Window.GetMouseCoords()
isect, point, dir= mouseViewRay(x,y)
if isect:
scn= Blender.Scene.GetCurrent()
me = Blender.Mesh.New()
ob= Blender.Object.New('Mesh')
ob.link(me)
scn.link(ob)
ob.sel= 1
me.verts.extend([point, dir])
me.verts[0].sel= 1
print isect, point, dir
def spaceRect(): def spaceRect():
''' '''
Returns the space rect Returns the space rect

@ -108,8 +108,9 @@ def vertexGradientPick(ob, MODE):
else: # Ortho - Same direction, different origin else: # Ortho - Same direction, different origin
cross_grad= CrossVecs(DirectionA, OriginA-OriginB) cross_grad= CrossVecs(DirectionA, OriginA-OriginB)
ORTHO= True ORTHO= True
cross_grad= cross_grad.normalized() * 100 cross_grad.normalize()
cross_grad= cross_grad * 100
lineA= (OriginA, OriginA+(DirectionA*100)) lineA= (OriginA, OriginA+(DirectionA*100))
lineB= (OriginB, OriginB+(DirectionB*100)) lineB= (OriginB, OriginB+(DirectionB*100))

@ -513,7 +513,7 @@ def bvh_node_dict2armature(bvh_nodes, IMPORT_START_FRAME= 1):
if bvh_node.has_loc: if bvh_node.has_loc:
# Set the Location, simple too # Set the Location, simple too
pose_bone.loc= (\ pose_bone.loc= (\
TranslationMatrix(Vector(lx*10, ly*10, lz*10)) *\ TranslationMatrix(Vector(lx, ly, lz)) *\
bone_rest_matrix_inv).translationPart() # WHY * 10? - just how pose works bone_rest_matrix_inv).translationPart() # WHY * 10? - just how pose works
# Get the transform # Get the transform
@ -587,7 +587,7 @@ def bvh_node_dict2armature(bvh_nodes, IMPORT_START_FRAME= 1):
return tuple((bone_rest_matrix * bone_rotation_matrix * bone_rest_matrix_inv).toQuat()) # qw,qx,qy,qz return tuple((bone_rest_matrix * bone_rotation_matrix * bone_rest_matrix_inv).toQuat()) # qw,qx,qy,qz
def pose_loc(anim_data): def pose_loc(anim_data):
return tuple((TranslationMatrix(Vector(anim_data[0]*10, anim_data[1]*10, anim_data[2]*10)) * bone_rest_matrix_inv).translationPart()) return tuple((TranslationMatrix(Vector(anim_data[0], anim_data[1], anim_data[2])) * bone_rest_matrix_inv).translationPart())
last_frame= len(bvh_node.anim_data)+IMPORT_START_FRAME-1 last_frame= len(bvh_node.anim_data)+IMPORT_START_FRAME-1

@ -234,7 +234,6 @@ PyObject *Matrix_Invert(MatrixObject * self)
f = Matrix_Determinant(self); f = Matrix_Determinant(self);
det = (float)PyFloat_AS_DOUBLE(f); /*Increfs, so we need to decref*/ det = (float)PyFloat_AS_DOUBLE(f); /*Increfs, so we need to decref*/
Py_DECREF(f); Py_DECREF(f);
det= 10.0;
if(det != 0) { if(det != 0) {
/*calculate the classical adjoint*/ /*calculate the classical adjoint*/