Milkshape exporter

I wrote a milkshape exporter for Blender 2.34. I wrote it in a day so it is really really alpha. Right now it exports a mesh, vertex groups, joints, and materials. I have been working on the animations but they seem to come out upside down and reverse in Milkshape. If anyone knows why this might be happening. Below is the code i use to get the keyframe information.


def GetAnimation(self, action, joint, frames):
  act = action
  j = joint
  ipo = act.getChannelIpo(j.name)
  for f in frames:
   time = f 
   scene.currentFrame(f)
   scn.makeCurrent()
   x, y, z = getIpoValue(ipo, "LocX"), getIpoValue(ipo, "LocY"), getIpoValue(ipo, "LocZ")  
   loc = [x,y,z]
   print loc
   transKey = MSKeyframe(time, loc)
   ipo_rot = [getIpoValue(ipo, "QuatX"),
              getIpoValue(ipo, "QuatY"), 
              getIpoValue(ipo, "QuatZ"), 
              getIpoValue(ipo, "QuatW"), 
             ]
   quat = Quaternion(ipo_rot)
   eRot = quat
   eRot.toEuler()
   if j.hasParent:  
    eRot[0] = -(eRot[0])
    eRot[1] = -(eRot[1]) 
    eRot[2] = (eRot[2])
   else:
    eRot[0] = -(eRot[0]) 
    eRot[1] = -(eRot[1]) 
    eRot[2] = (eRot[2]) 
   
   rotkey = MSKeyframe(time, eRot)
   j.rotKeyframes.append(rotkey)
   j.transKeyframes.append(transKey)
   j.transKeynum += 1
   j.rotKeynum += 1 
  return j
 
 

well, a milkshape export was something I considered doing

[but I really don’t like milkshape, somehow I can’t exactly arue why]

well anyway, could it be a different coordinate system [right handed in blender vs left handed in directx apps, I think max and maybe milkshape too], or could it be the negative w thing for quaternoins I have seen mentioned several times here?

From what i have read, Milkshape is an openGl app also and uses a right handed cordinate system. Right now the translation keyframes work its just the rotations that come out wrong.

I would like to see this Milkshape exporter because I would want to export from Milkshape to Blitz Basic’s B3D format.

Nice work and I can already envision a few great applications. Is this in distributable form ?

~O

once i fix the animation problem i will post the script for anyone who wants it.

i really need this exporter, keep it up, please!

Im also interested in this exporter. please let me know if you need help with the blitz3d reader.

Are scn and scene supposed to be different variables?

scene.currentFrame(f)
scn.makeCurrent()

LetterRip


   if j.hasParent: 
    eRot[0] = -(eRot[0])
    eRot[1] = -(eRot[1])
    eRot[2] = (eRot[2])
   else:
    eRot[0] = -(eRot[0])
    eRot[1] = -(eRot[1])
    eRot[2] = (eRot[2]) 

those initialize to the exact same thing, are they supposed to be different, otherwise the check is redundant.

LetterRip

also if scene and scn are variables of type Scene, you need to use


scene = Blender.Scene.getCurrent() 
context = scene.getRenderingContext()
context.currentFrame(frameNumber)

scene.currentFrame(frameNumber)

is depricated

LetterRip

I was looking at the Ogre Exporter, and it states


		if not (Blender.Get("version") == 234):
			rot = [ ipo.EvaluateCurveOn(curveId["QuatX"], frame), \
				ipo.EvaluateCurveOn(curveId["QuatY"], frame), \
				ipo.EvaluateCurveOn(curveId["QuatZ"], frame), \
				ipo.EvaluateCurveOn(curveId["QuatW"], frame) ]
		else:
			# Blender 2.34 quaternion naming bug
			rot = [ ipo.EvaluateCurveOn(curveId["QuatY"], frame), \
				ipo.EvaluateCurveOn(curveId["QuatZ"], frame), \
				ipo.EvaluateCurveOn(curveId["QuatW"], frame), \
				ipo.EvaluateCurveOn(curveId["QuatX"], frame) ]

so you might want to try


  ipo_rot = [getIpoValue(ipo, "QuatY"),
              getIpoValue(ipo, "QuatZ"),
              getIpoValue(ipo, "QuatW"),
              getIpoValue(ipo, "QuatX"),
             ] 

and see if that solves the error

Also I just checked the CVS logs. The error was fixed in cvs after the 2.34 release. So 2.35 will not require the work around.

LetterRip

sVenom & anyone else that can help me,

I have a file: Galactus.ms3d, and I’m trying to open it on my Mac OSX 10.3.3 in Blender 2.35, I am using the above script (import_milkshape). But I’m getting an error:

ERROR: Python Script Error, Check Console"

Here’s what’s in the Console window:

Mac OS X Version 10.3.3 (Build 7F44)
2004-11-30 12:26:03 -0800
File “Milkshape_Import_Scri”, line 1

{\rtf1\mac\ansicpg10000\cocoartf102

                                  ^

SyntaxError: invalid token

Now, according to Sandi (aka Dreamsgate) at BlenderMan.org, she says that one of the rules of python has been broken.

She said to get in touch with the author of the Script… that’s you SVENOM, and ask if he thinks it’s a Mac OSX compatibility issue.

Now I can’t swear by the Path to Python, I’m really new to Python, and could use a primer or tutorial on proper installation and testing of Python on the Mac OSX… I have downloaded it, and run the installer. But, like Blender and others… it seems to be installed on my desktop… so should my path in Blender to Python be relative to the app? or should it be absolute? from the drive volume? Anyone else out there have this problem?

I’m really looking forward to solving this problem. Thanks guys!

Weird, because that’s not the first line of the script. I know nothing of Mac but in my sig is a link to Akator’s page on Python in Blender on Mac using Fink.

%<

Could there be a problem with using a .rtf file?

Well yeah, that would be the problem.

RTF are encoded, this would screw the whole script.

Always use pure text formats for scripts (txt for example). The standard py format is pure text, of course.

Martin

Thanks guys…

RTF BAD!
.TXT and .DOC GOOD

Your right… I used a .doc, and the only problem I am getting now is how to define the Path to the .ms3d file. It’s my first time typing a path on the Mac… Is it:

1.) An absolute path from the Root HD to the milkshape file? Like this?:

('Macintosh HD/Users/tranedepriest/MARVEL UNIVERSE/Galactus/GALACTUS.ms3d') 

2.) A relative path from the Blender Application to the milkshape .ms3d file?

3.) A relative path from the Open .bend file to the milkshape file?

I’ll try them all, but frankly I’m not sure if I have the coding right… Up a level is “//” right? I hate coding. :x

I have wroten one milkshap ASCII on maxscript if it interess something.
http://caron.yann.free.fr/3dStation/Export_MSascii.zip
You can help you with that if you want.

is there any news on theprogress of the milkshape exporter script.
I would love to toy around wtih it, rigth now i am exporting using the raw triangles, but that way i am forced to do a lot in milkshape where i like working in blender more.

I actually forgot about this script, so i haven’t been working on it. I really only have one problem with it, and that is the exported animations seen in milkshape. However, the script does export the mesh, materials(colors and textures) and bones correctly