Game Development Community

dev|Pro Game Development Curriculum

How to add Alpha Channel support to ms2dtsExporter

by Ken Finney · 04/18/2002 (10:47 am) · 6 comments

The Milkshape Exporter supports Additive Translucency only - it kicks in when you have the emissive material slider set to less than 75% (default for it is to be all the way to to the right; if you move it left about 1/4 of full range and keep going, you get 75% or less...). That's the total extent of translucency/transparency in the ms2dtsExporter.dll

Now, in MS, the second material button (the botom one)loads a material in as the Alpha Texture, but the exporter doesn't do anything with it.

The following fix enables non-additive/non-subtractive translucency when the exporter simply detects the presence of an Alpha Texture. Remember to keep the emissive slider pushed all the way to the RIGHT, or you will end up with additive translucency, which in most cases, most of us DON'T want.

in the file DTSMilkshapeShape.cpp in the ms2dtsExporter project at around line 185, add the code below shown in bold:
[b]char alphaName[MS_MAX_PATH+1];   //--- KCF: put this anywhere before the code below; 
                                // ---I put it in the traditional location just after entering the MilkshapeShape::MilkshapeShape method code block.[/b]

[i]<skip some code here>[/i]

            // Check transparency value
            if (msMaterial_GetTransparency (msMat) <= 0.75f)
               mat.flags |= Material::Translucent | Material::Additive ;
[b]
            msMaterial_GetAlphaTexture (msMat, alphaName, MS_MAX_PATH); //--- KCF ---             
            if (strlen(alphaName)>0)                    //--- KCF ---    
               mat.flags |= Material::Translucent;     //--- KCF ---       
 [/b]
            materials.push_back(mat) ;

now rebuild, move the dll to your MS directory, run MS, and make sure you have a texture loaded with that second button as the alpha texture.

NOTE: Milkshape will NOT let you import .PNG files if they have an alpha channel in them, so you need *two* copies of your texture, one as PNG and one as JPG, both with IDENTICAL names, but different extensions. You use the JPG version in MS, and use the PNG version in Torque. The exporter exports the name without the extension, and when torque sees the name, it looks for a PNG first by default...


#1
04/18/2002 (1:09 pm)
This is cool stuff Ken I cant wait to try it out! I am confused about one issue though. All I use for my MS textures are .png. I'm sure I'm just misunderstanding the point of using the two types png/jpg. Could you clarify that?
Thanks.

Aaron
#2
04/18/2002 (3:40 pm)
Sure Aaron. As you can see in the forum thread, Milkshape will use PNG files, but -not- ones with an alpha channel in them. So the trick is to make your alpha channel'ed PNG file, and then save another copy with the exact same name but with a different supported extension; I use JPG cuz they are nice & small.

Then in MS, work with the JPG versions. The exporter will export the filename but -not- the extension into the dts file. When you run your TGE based game, Torque will pick up the PNG version, as long as you have it in the same game data directory as the DTS.

So it would help to organize your modeling directory outside your game tree, and keep your JPGs there, and only put the PNG versions of the same files in the fps/data/shapes/whatever directory that you use for your game.

Clear as mud ?
#3
04/18/2002 (6:16 pm)
Perfectly clear :) thanks.
I cant wait to try it out tonight!
#4
04/19/2002 (2:59 pm)
1. I don't have the MilkshapeShape.cc file (I have the .cpp and .h files).
2. I tried this with the .cpp file and got this:
C:\Torque Test\torque\tools\ms2dtsExporter\DTSMilkshapeShape.cpp(172) : error C2065: 'alphaName' : undeclared identifier
#5
04/19/2002 (4:59 pm)
Thx Viper, I forgot include the var declaration. And yes, unlike the Torque Game Engine itself, this tool module is a .cpp file, not .cc - must have been reflex :-)
#6
02/03/2003 (9:17 am)
When I tried this and loaded the jpg into the second slot for Milkshape - I got an error "Error downloading texture". The shape still seemed to export OK - but the color once in Torque was not what I expected (red instead of blue). I'm using Milkshape 1.6.4. Not sure if this still works with that version.