Friday, May 30, 2008

Involuntary language change in FlashDevelop

This is more of a reminder for myself, but can be useful if you're a non-english developer who uses FlashDevelop :)

Due to some networking updates, I had to update my FlexSdk3 to the nightly build.
After installing however, the compiler errormessages I got in FlashDevelop suddenly where partially Dutch instead of English.

It was quite a horrible combination and so I needed to change it back to English badly, but unfortunately could find no documentation about it.

After asking on Adobe forums the answer was provided:

Change the jvm.config file and alter the line java.args line to this:


java.args=-Xmx384m -Dsun.io.useCanonCaches=false -Duser.language=en -Duser.country=US

Thursday, May 22, 2008

3 x 3 ledcube simulator

A friend of mine is making a 3x3 ledcube (see video) and asked me to write a little routine to do a snake in a 3x3x3 matrix.

I came up with a quick 'n dirty random snake routine, which is kinda like the routine I used for my 3d cube demo

To see what it looks like, I've also thrown together a little 3x3 led emulator :)
3x3 ledcube snake

And you can check out the source if you want (nothing fancy) here

Friday, May 2, 2008

Render to Texture, or Texture baking in 3dStudio max for Papervision3d

Here's a small tutorial on how to Bake a texture in 3d studio Max (2009) for use with papervision3d.

Show the result

First off, let me state that I am not particularly skilled in 3dMax, I'm more of a lightwave person myself, but since Lightwave cannot produce content I can use in Papervision, 3dMax it is :)

This tutorial shows you how to do Texture baking very basically. It doesn't go into Mental Ray or Vray. It's just to show you how its done, so you can use it as a starting point for more detailed experimentation :)

I'll sum up the steps I do to make objects, light them and render them to texture. I've tried to use Mental ray and Vray too, but today for some reason 3dMax only wishes to spit out completely white texture maps, while it displays them correctly in the render preview window.

We'll be exporting our scene as a .3ds file, because I've tried using Collada export (using http://www.feelingsoftware.com/ 's Collada exported. But as soon as I started baking textures, my scenes won't render correctly.


Step 1 - make your model

I've created 3 boxes and an omni light. In this Tutorial I haven't given them a material, this will be automatically done when we're baking the texture. You can do this manually as well if you wish.

Step 2 - Set the filetype to PNG
You can skip this step if your 3dMax already renders to PNG, or if you like using .TGA's and arent using Papervision3d :)

In my setup, 3dMax automatically renders all files as Targa (.tga), but I want to use PNG's which Papervision can read so we need to change this.

I use the following method.
1 - select only 1 object in the scene.
2 - open the "Render to Texture" dialog (press 0)
3 - under "Output" Delete any entries if present.
4 - ADD a "Diffuse map"
5 - click on the dots-button to the right of "File name and Type"
6 - Select a filename, and select PNG as a filetype.
7 - After the file dialog is closed, you'll see that the file extension is .png now.
8 - Delete the output entry again, 3dMax will now save .png's as default when you create new Output maps.

In my case, 3dMax only goes back to saving .tga's after the program has quit/crashed and has been restarted. So If you clear your scene, and render to texture again, the output should still be .png and you can skil this step.

If there's a setting somewhere where you can change this in 3dMax, please let me know :)

Step 3 - Render to Texture dialog

Select all your objects on stage and press the 0 key, or use the menu "Rendering - Render to Texture" to bring up the "Render to texture" Dialog.
Here you can select where your textures will be saved.
Because you selected all your objects, they should all appear in the "Objects to bake" tab. If the list is empty, you apparantly havent selected any objects.


Make sure "Use Automatic unwrap" is selected. You can also use manually created UV-mappings if you wish (Make sure to set it to the correct channel if you do), but this example has no UVmapping yet, so we'll leave this to Automatic.


Step 4 - Selecting which type of map
Make sure "All selected" is checked, because we want to make a map for every object in the scene.
Click on the ADD button, and select "Diffuse map"

Since we'll be exporting to .3ds, you need to know that 3dMax automatically renames texture filenames to a 8.3 filename type. So that means 8 characters for the filename, 3 for the extention.
This is a problem, because our baked textures arent limited to that specification and will happily render out to filenames that won't fit in this scheme.
Result : Your 3ds file will want to open box01Dif.png while your texture was rendered to box01DiffuseMap.png.

To fix this we do the following :
1 - Make sure your object names are smaller than 8 characters.
2 - In the "Selected Element Common Settings"-tab, clear the "DiffuseMap" from the 'Name' inputbox.



So your window should look like this:


Select the map size you want, we'll use 256x256 in this tutorial.

Step 5 - preparing the render
Select "Output into Source" and "Keep Source Materials"

This will replace the material of your objects when you bake the textures. We need this because we'll be exporting this scene, with the baked materials for Papervision.

Also select "Lighting" and "Shadows" in the "Selected Elements Unique setting" tab.
This will enable the texture to be rendered with, you guessed it, shadows and lighting :)




Step 6 - Render the texture
This is the easiest step.
Click on "Render" and wait for 3dMax to finish.


Step 7 - Export to a .3ds file.

All done in 3dMax, if you take a look at your Materials editor, you can see that the materials now contain texturemaps with lighting and shadows.
If you dont see your materials, select an object in your scene and click on the eyedropper button to get the material from the object.




Finished.
You can now load your .3ds file into your Papervision flash, make sure it knows where to find the texture images, and it should work.

I've included a small example, made with FlashDevelop.
Click here to download it


I've found an error/missing feature in the 3dsParser in papervision. Apparantly a "LOAD_COMPLETE" event was missing from the 3dsParser, so I've added that.

To do this, edit org.papervision3d.objects.parsers.Max3DS.as


and change the OnFileLoadComplete function to :

private function onFileLoadComplete(event:Event=null):void
{
var loader:URLLoader = event.target as URLLoader;

parse(ByteArray(loader.data));
// added by whizzkid
var fileEvent:FileLoadEvent = new FileLoadEvent( FileLoadEvent.LOAD_COMPLETE, filename );
this.dispatchEvent( fileEvent );

}


And if you're not using FlashDevelop, manually add the following import as well:


import org.papervision3d.events.FileLoadEvent;



I've included this file in my example.



This is my first tutorial ever, so please let me know what you think about it, and if you find an error or have any suggestions, leave a message :)

Regards,
Martijn