--- translator.py.old	2009-09-03 18:27:16.000000000 +0900
+++ translator.py	2010-06-19 11:47:48.000000000 +0900
@@ -51,6 +51,13 @@
 #	where to fix their model.
 # - The patch from 2008.08.31, implementing the patch from Dmitri was incomplete.
 #	The joints were renamed (replace('.','_')), but not the vertex group names!
+# 2009.01.25 by kumaryu:
+# - exporter fixes.
+# - fixes export IDREF_array elements replace `.' by `_'
+# - now bone animations are in bonespace.
+# - fixes accessor references source.
+# - all animation interpolations to LINEAR. (BEZIER needs TANGENT)
+# - transparency to alpha instead of one minus alpha.
 # 2008.09.20 by migius:
 # - bugfix meshes with more than 16 materials: material index bigger than 15 replaced with 15.
 # 2008.08.31 by migius:
@@ -1139,9 +1146,17 @@
 					bindMatrix = Matrix(bArmature.bones[vertexGroupName].matrix["ARMATURESPACE"]).resize4x4().transpose()
 					bindMatrix = Matrix(bArmatureObject.getMatrix('localspace')).transpose() * bindMatrix
 				else:
-					headPos = bArmature.bones[vertexGroupName].head["ARMATURESPACE"]
-					bindMatrix = Matrix([1,0,0,headPos.x], [0,1,0,headPos.y], [0,0,1,headPos.z],[0,0,0,1])
-					bindMatrix = Matrix(bArmatureObject.getMatrix('localspace')).transpose() * bindMatrix
+					bone = bArmature.bones[vertexGroupName]
+					bindMatrix = Matrix().resize4x4().identity()
+					while (bone!=None):
+						headPos = bone.head['ARMATURESPACE']
+						if bone.hasParent():
+							invParentMatrix = Matrix(bone.parent.matrix['ARMATURESPACE']).invert()
+							bindMatrix *= Matrix(bone.matrix['BONESPACE']).resize4x4() * TranslationMatrix(headPos*invParentMatrix)
+						else:
+							bindMatrix *= Matrix(bone.matrix['BONESPACE']).resize4x4() * TranslationMatrix(headPos)
+						bone = bone.parent
+					bindMatrix = (bindMatrix * bArmatureObject.getMatrix('localspace')).transpose()
 
 				invBindMatrix = Matrix(bindMatrix).invert()
 				poseSourceArray.data.extend(MatrixToList(invBindMatrix))
@@ -1353,33 +1368,6 @@
 
 			for key in quats:
 				euler = quats[key].toEuler()
-
-				if joint is not None:
-					if dmitri:
-						bindMatrix = Matrix(joint.matrix["ARMATURESPACE"]).resize4x4().transpose()
-					else:
-						headPos = joint.head["ARMATURESPACE"]
-						bindMatrix = Matrix([1,0,0,headPos.x], [0,1,0,headPos.y], [0,0,1,headPos.z],[0,0,0,1])
-					armMatrix = Matrix(bindMatrix)
-					if not joint.hasParent():
-						armMatrix = Matrix(bArmatureObject.getMatrix('localspace')).transpose().invert()
-						armMatrix *= bindMatrix
-
-					if 1: #migius
-						swap = euler.y
-						euler.y = - euler.z
-						euler.z = swap
-
-					else:
-						poseMatrix = Matrix(bParentMatrix).invert() * armMatrix
-						poseMatrix.transpose()
-
-						poseEuler = poseMatrix.toEuler()
-						euler.x += poseEuler.x
-						euler.y += poseEuler.y
-						euler.z += poseEuler.z
-					#if debprn: print 'deb: getEuler: ', joint.name , poseEuler, euler
-
 				eulers[key] = euler
 
 			# this nodes list of euler angles:
@@ -1421,40 +1409,6 @@
 						timeVal = float(curve[float(frameNumber)])
 						##print cName, frameNumber, timeVal
 						anit[cName[-1]] = timeVal
-
-						if not joint is None:
-							if dmitri:
-								bindMatrix = Matrix(joint.matrix["ARMATURESPACE"]).resize4x4().transpose()
-							else:
-								headPos = joint.head["ARMATURESPACE"]
-								bindMatrix = Matrix([1,0,0,headPos.x], [0,1,0,headPos.y], [0,0,1,headPos.z],[0,0,0,1])
-							armMatrix = bindMatrix
-							if ( not joint.hasParent() ):
-								armMatrix = Matrix(bArmatureObject.getMatrix('localspace')).transpose()
-								armMatrix *= bindMatrix
-
-							poseMatrix = Matrix(bParentMatrix).invert() * armMatrix
-
-							if cName.startswith("Loc"):
-								poseMatrix.transpose()
-								jointPosition = poseMatrix.translationPart()
-
-								if cName[-1] == 'X':
-									anit['X'] += jointPosition.x
-								if cName[-1] == 'Y':
-									anit['Y'] += jointPosition.y
-								if cName[-1] == 'Z':
-									anit['Z'] += jointPosition.z
-							if cName.startswith("Scale"):
-								poseMatrix.transpose()
-								jointPosition = poseMatrix.scalePart()
-								if cName[-1] == 'X':
-									anit['X'] *= jointPosition.x
-								if cName[-1] == 'Y':
-									anit['Y'] *= jointPosition.y
-								if cName[-1] == 'Z':
-									anit['Z'] *= jointPosition.z
-
 						if cName.startswith("Rot"):
 							anit[cName[-1]] = anit[cName[-1]]*10 # Multiply the angle times 10 (Blender uses angle/10)
 				else:
@@ -1532,7 +1486,7 @@
 				elif interpolation == 'Linear':
 					cInterpolation = 'LINEAR'
 				else:
-					cInterpolation = 'BEZIER'
+					cInterpolation = 'LINEAR'
 
 				if name == collada.DaeSyntax.TRANSLATE or name == collada.DaeSyntax.SCALE:
 					if value['X'] is None:
@@ -2518,7 +2472,12 @@
 			bindMatrix = Matrix(bBone.matrix["ARMATURESPACE"]).resize4x4().transpose()
 		else:
 			headPos = bBone.head["ARMATURESPACE"]
-			bindMatrix = Matrix([1,0,0,headPos.x], [0,1,0,headPos.y], [0,0,1,headPos.z],[0,0,0,1])
+			if bBone.hasParent():
+				invParentMatrix = Matrix(bBone.parent.matrix['ARMATURESPACE']).invert()
+				headPos = headPos * invParentMatrix
+			else:
+				tailPos = Vector(0.0, 0.0, 0.0)
+			bindMatrix = (Matrix(bBone.matrix["BONESPACE"]).resize4x4() * TranslationMatrix(headPos)).transpose()
 		armMatrix = bindMatrix
 
 		if ( not bBone.hasParent() ):
@@ -2542,35 +2501,18 @@
 		except:
 			pass
 
-		mat = Matrix(parentMatrix).invert() * armMatrix
-		boneMatrix = Matrix(bindMatrix)
-		mat.transpose()
-		#PrintTransforms(mat, "ARMATURESPACE: " + bBone.name)
-
+		boneMatrix = Matrix(armMatrix)
 		if bakeMatrices :
-			mat = Matrix(mat).transpose()
+			mat = Matrix(boneMatrix)
 			daeNode.transforms.append([collada.DaeSyntax.MATRIX, mat])
 		else:
-			translation = mat.translationPart()
-
-			daeNode.transforms.append([collada.DaeSyntax.TRANSLATE, translation])
-
-			euler = mat.toEuler()
-##			print euler
-			rotxVec = [1,0,0,euler.x]
-			rotyVec = [0,1,0,euler.y]
-			rotzVec = [0,0,1,euler.z]
-
-##			print rotxVec[3], rotyVec[3], rotzVec[3]
-
-			daeNode.transforms.append([collada.DaeSyntax.ROTATE, rotzVec])
-			daeNode.transforms.append([collada.DaeSyntax.ROTATE, rotyVec])
-			daeNode.transforms.append([collada.DaeSyntax.ROTATE, rotxVec])
-
-			scale = mat.scalePart()
-			daeNode.transforms.append([collada.DaeSyntax.SCALE, scale])
-
-
+			mat = Matrix(boneMatrix)
+			daeNode.transforms.append([collada.DaeSyntax.MATRIX, mat])
+			daeNode.transforms.append([collada.DaeSyntax.TRANSLATE, Vector(0, 0, 0)])
+			daeNode.transforms.append([collada.DaeSyntax.ROTATE, [0,0,1,0]])
+			daeNode.transforms.append([collada.DaeSyntax.ROTATE, [0,1,0,0]])
+			daeNode.transforms.append([collada.DaeSyntax.ROTATE, [1,0,0,0]])
+			daeNode.transforms.append([collada.DaeSyntax.SCALE,  Vector(1, 1, 1)])
 		if not bBone.children is None:
 			for childBone in bBone.children:
 				daeNode.nodes.append(self.BoneToDae(childBone, bPose, boneMatrix, bArmatureObject, boneMatrix))
@@ -3383,7 +3325,7 @@
 			shader = collada.DaeFxShadeLambert()
 
 		shader.AddValue(collada.DaeFxSyntax.DIFFUSE,bMaterial.getRGBCol()+[1])
-		shader.AddValue(collada.DaeFxSyntax.TRANSPARENCY, 1 - bMaterial.alpha)
+		shader.AddValue(collada.DaeFxSyntax.TRANSPARENCY, bMaterial.alpha)
 		shader.AddValue(collada.DaeFxSyntax.TRANSPARENT, [1,1,1,1])
 		mainColor = bMaterial.getRGBCol()
 		white = [1.0,1.0,1.0]
