Kloputils v2.0

(klopes) #1

Hi all, here’s the Kloputils v2.0 Do you remember my alligning tool? Well, it’s turned into a toolkit to create and modify objects using features not included in Blender. Sorry, only in Spanish, but… well, read the text in the file.

I won’t may recieve neither emails or messages, I’ve not internet: westerday I was playing and a guy who (I supose, never nobody tell me about) is my chief, or something.

I hope it to be useful
Download from here:

(Caronte) #2

Thanks mate!

(eeshlo) #3

I see you used my old mat2euler function, unfortunately that one is not quite correct, it will fail in some cases. Here is the final code I use now in the Lightflow script, you only need to pass the matrix and it will return euler angles, as well as size & translation vectors:

# normalize vector inplace, return length
def vnormlen(v):
	vlen = sqrt(v[0]*v[0] + v[1]*v[1] + v[2]*v[2])
	if vlen!=0.0:
		d = 1.0/vlen
		v[0]*=d;  v[1]*=d;  v[2]*=d
	return vlen

# vector dotproduct
def vdot(v1, v2):
	# dot product
	return v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2]

# vector crossproduct
def crossp(v1, v2):
	r = [0.0, 0.0, 0.0]
	r[0] = v1[1]*v2[2] - v1[2]*v2[1]
	r[1] = v1[2]*v2[0] - v1[0]*v2[2]
	r[2] = v1[0]*v2[1] - v1[1]*v2[0]
	return r

# get matrix3x3 determinant 
def determinant3x3(mtx):
	return vdot(mtx[0], crossp(mtx[1], mtx[2]))

# extract euler rotation, scale & position from a single matrix, necessary for parent/child transformations
# does NOT work with non-uniform scaling on parent objects...
def infoFromMtx(mat):
	mtx = [list(mat[0][:3]), list(mat[1][:3]), list(mat[2][:3])]
	scale = [0.0, 0.0, 0.0]
	scale[0] = vnormlen(mtx[0])
	scale[1] = vnormlen(mtx[1])
	scale[2] = vnormlen(mtx[2])
	# scaling negative?
	if determinant3x3(mtx)<0.0:
		for i in range(3):
			scale[i] *= -1.0
			mtx[i][0] *= -1.0
			mtx[i][1] *= -1.0
			mtx[i][2] *= -1.0
	angle_y = -asin(max(min(mtx[0][2], 1.0), -1.0))
	C = cos(angle_y)
	if C!=0.0: C = 1.0/C
	angle_x = atan2(mtx[1][2] * C, mtx[2][2] * C)
	angle_z = atan2(mtx[0][1] * C, mtx[0][0] * C)
	return (angle_x, angle_y, angle_z), tuple(scale), tuple(mat[3][:3])

(klopes) #4

Thanks, now i’ve fixed another bug in the linear system solver :slight_smile:
I’m implementing your new code, thank you again.