Browse Source

- Blender coord system to AnKi in blender exporters
- Other minor

Panagiotis Christopoulos Charitos 15 năm trước cách đây
mục cha
commit
4195a8cfb0

+ 14 - 13
blenderscripts/skelanim.py

@@ -13,11 +13,13 @@ class Initializer:
 	def __init__(self):
 		self.obj = None
 		self.saveDir = "" # the name of the saved file
-		self.flipYZ = 0 #convert from bl to right handed coord system
+		self.flipYZ = 0 # convert from bl to right handed coord system. NOT USED
 
 
-# MulMatrix
-def MulMatrix(m, b):
+#=======================================================================================================================
+# multMatrix                                                                                                           =
+#=======================================================================================================================
+def multMatrix(m, b):
 	c = Matrix()
 	c[0][0] = m[0][0]*b[0][0] + m[0][1]*b[1][0] + m[0][2]*b[2][0] + m[0][3]*b[3][0]
 	c[0][1] = m[0][0]*b[0][1] + m[0][1]*b[1][1] + m[0][2]*b[2][1] + m[0][3]*b[3][1]
@@ -38,7 +40,9 @@ def MulMatrix(m, b):
 	return c
 
 
-
+#=======================================================================================================================
+# A few classes                                                                                                        =
+#=======================================================================================================================
 class BonePose:
 	def __init__(self):
 		self.rotation = Quaternion(1.0, 0.0, 0.0, 0.0)
@@ -63,8 +67,6 @@ class SkelAnim:
 def getAnkiScript(obj, flipYZ, action):
 	skeleton = obj.getData(0, 0) 	
 	
-	b_cmnts = 1
-	
 	# init and populate the instances
 	skelAnim = SkelAnim()
 	skelAnim.keyframes = action.getFrameNumbers()
@@ -103,8 +105,8 @@ def getAnkiScript(obj, flipYZ, action):
 			for m in range(0, 3):
 				tra[m][3] = poseBone.loc[m]
 			# bone matris at armature space aka MA
-			MA = Matrix(bone.matrix["ARMATURESPACE"])
-			MAi = Matrix(MA)
+			MA = bone.matrix["ARMATURESPACE"].copy()
+			MAi = MA.copy()
 			MAi.invert()
 			
 			# calc the m4 = MA * tra * rot * MAi
@@ -113,9 +115,9 @@ def getAnkiScript(obj, flipYZ, action):
 			MA.transpose()
 			MAi.transpose()
 			
-			m4 = MulMatrix(rot, MAi)
-			m4 = MulMatrix(tra, m4)
-			m4 = MulMatrix(MA, m4)
+			m4 = multMatrix(rot, MAi)
+			m4 = multMatrix(tra, m4)
+			m4 = multMatrix(MA, m4)
 			
 			m4.transpose()
 			
@@ -193,7 +195,6 @@ def getAnkiScript(obj, flipYZ, action):
 	return ftxt
 
 
-
 #=======================================================================================================================
 # export                                                                                                               =
 #=======================================================================================================================
@@ -214,4 +215,4 @@ def export(init):
 	file.write(getAnkiScript(obj, init.flipYZ, action))
 	
 	print("Skeleton animation exported!! \"" + filename + "\"")	
-	
+	

+ 3 - 3
blenderscripts/skeleton.py

@@ -31,7 +31,7 @@ def multMatrix(m, b):
 
 
 #=======================================================================================================================
-# rotateMatrix                                                                                                         =
+# rotMat                                                                                                               =
 #=======================================================================================================================
 rotMat = Matrix()
 rotMat[0][0] = 1.0
@@ -50,6 +50,7 @@ rotMat[3][0] = 0.0
 rotMat[3][1] = 0.0
 rotMat[3][2] = 0.0
 rotMat[3][3] = 1.0
+rotMat.transpose()
 
 
 #=======================================================================================================================
@@ -130,7 +131,6 @@ def getAnkiSkeletonScript(skeleton, flipYZ):
 		ftxt += "\n"
 		
 		# write the parent
-				
 		if not bone.parent:
 			ftxt += "NULL\n"
 		else:
@@ -164,4 +164,4 @@ def export(skeletonInit):
 	file.write(getAnkiSkeletonScript(skeleton, skeletonInit.flipYZ))
 	
 	print("Skeleton exported!! \"" + filename + "\"")	
-	
+	

+ 8 - 6
src/Resources/Helpers/Image.cpp

@@ -214,9 +214,11 @@ bool Image::loadTga(const char* filename)
 	}
 
 	if(bpp == 32)
-		type = T_RGBA;
+		type = CT_RGBA;
+	else if(bpp == 24)
+		type = CT_RGB;
 	else
-		type = T_RGB;
+		FATAL("See file");
 
 	fs.close();
 	return funcsReturn;
@@ -229,7 +231,7 @@ bool Image::loadTga(const char* filename)
 bool Image::loadPng(const char* filename)
 {
 	/*
-	 * Data
+	 * All locals
 	 */
 	const uint PNG_SIG_SIZE = 8;
 	FILE* file = NULL;
@@ -390,13 +392,13 @@ bool Image::loadPng(const char* filename)
 	switch(colorType)
 	{
 		case PNG_COLOR_TYPE_GRAY:
-			type = T_R;
+			type = CT_R;
 			break;
 		case PNG_COLOR_TYPE_RGB:
-			type = T_RGB;
+			type = CT_RGB;
 			break;
 		case PNG_COLOR_TYPE_RGBA:
-			type = T_RGBA;
+			type = CT_RGBA;
 			break;
 	}
 

+ 8 - 5
src/Resources/Helpers/Image.h

@@ -11,16 +11,19 @@
 class Image
 {
 	public:
-		enum Type
+		/**
+		 * The acceptable color types of AnKi
+		 */
+		enum ColorType
 		{
-			T_R,
-			T_RGB,
-			T_RGBA
+			CT_R,
+			CT_RGB,
+			CT_RGBA
 		};
 
 	PROPERTY_R(uint, width, getWidth)
 	PROPERTY_R(uint, height, getHeight)
-	PROPERTY_R(Type, type, getType)
+	PROPERTY_R(ColorType, type, getType)
 	PROPERTY_R(Vec<uchar>, data, getData)
 
 	public:

+ 3 - 2
src/Resources/Skeleton.h

@@ -16,8 +16,9 @@ class Skeleton: public Resource
 		 * Skeleton bone
 		 *
 		 * @note The rotation and translation that transform the bone from bone space to armature space. Meaning that if
-		 * MA = TRS(rotSkelSpace, tslSkelSpace) then head = MA * Vec3(0.0, length, 0.0) and tail = MA * Vec3(0.0, 0.0, 0.0)
-		 * We also keep the inverted ones for fast calculations. rotSkelSpaceInv = MA.Inverted().getRotationPart() and NOT
+		 * MA = TRS(rotSkelSpace, tslSkelSpace) then head = MA * Vec3(0.0, length, 0.0) and tail = MA * Vec3(0.0, 0.0, 0.0).
+		 * We need the MA because the animation rotations and translations are in bone space. We also keep the inverted ones
+		 * for fast calculations. rotSkelSpaceInv = MA.Inverted().getRotationPart() and NOT
 		 * rotSkelSpaceInv = rotSkelSpace.getInverted()
 		 */
 		class Bone

+ 3 - 3
src/Resources/Texture.cpp

@@ -61,19 +61,19 @@ bool Texture::load(const char* filename)
 	GLint type;
 	switch(img.getType())
 	{
-		case Image::T_R:
+		case Image::CT_R:
 			internalFormat = (compressionEnabled) ? GL_COMPRESSED_RED : GL_RED;
 			format = GL_RED;
 			type = GL_UNSIGNED_BYTE;
 			break;
 
-		case Image::T_RGB:
+		case Image::CT_RGB:
 			internalFormat = (compressionEnabled) ? GL_COMPRESSED_RGB : GL_RGB;
 			format = GL_RGB;
 			type = GL_UNSIGNED_BYTE;
 			break;
 
-		case Image::T_RGBA:
+		case Image::CT_RGBA:
 			internalFormat = (compressionEnabled) ? GL_COMPRESSED_RGBA : GL_RGBA;
 			format = GL_RGBA;
 			type = GL_UNSIGNED_BYTE;

+ 2 - 1
src/Util/Common.cpp

@@ -139,7 +139,8 @@ ostream& msgSuffixFatal(ostream& cs)
 bool msgGlError(const char* file, int line, const char* func)
 {
 	GLenum errId = glGetError();
-	if(errId == GL_NO_ERROR) return true;
+	if(errId == GL_NO_ERROR)
+		return true;
 	msgPrefix(MT_ERROR, file, line, func) << "OpenGL Err: " << gluErrorString(errId) << msgSuffix;
 	return false;
 }

+ 2 - 2
src/Util/Common.h

@@ -1,5 +1,5 @@
-#ifndef _COMMON_H_
-#define _COMMON_H_
+#ifndef COMMON_H
+#define COMMON_H
 
 #include <iostream>