Rss

Loading Audio

Supported Formats

For iOS and Android, only WAV and OGG formats are supported.

For PC (Windows, Linux, MacOSX), with the FFMpeg extensions, all audio formats supported by FFMpeg can be loaded.

Loading

Use the following to load an audio file:

Audio mymusic = Audio.Load("myaudiofile.ogg");

This loads in the audio file as a single contiguous stream.

To load a file in pieces, specify an additional parameter, the chunk size:

Audio mymusic = Audio.Load("myaudiofile.ogg",64000);

This will load the audio into the audio playback buffers in chunks of up to 64000 in size. This is useful for longer files, files downloaded from the internet, or ogg files where the decoding takes a relatively long time.

Audio is always loaded in a background thread.

To load audio from the internet, do:

Audio mymusic = Audio.Load("http://www.mywebsite.com/myaudiofile.ogg",64000);

To load audio from an embedded resource, do:

Audio mymusic = Audio.Load("embed://myaudiofile.ogg",64000);

Playback

To initiate playback, do:

mymusic.Play();

This will initiate the playback in a dedicated audio playback background thread, and will play once.

For more advanced functions, don’t just call the Play() method directly. the method returns a specific audio stream class for managing the sound:

AudioStream musicplayback = mymusic.Play();

This represents a specific playback of the file, and the stream class then allows manipulation of the various audio properties:

musicplayback.Pitch = 0.25f;
musicplayback.Gain = 0.5f;    // Volume (0..1)
musicplayback.Looping=true;
musicstream.State = AudioState.Paused;

Loading Geometry

Geometry asteroid = Geometry.Load("Models/Stone_Pack1_Stone_1/Stone_Pack1_Stone_1.obj");

This code loads the Geometry in, in the same thread. Textures will be loaded from the same folder.
To load the geometry dynamically, use:

Geometry asteroid = Geometry.DynamicLoad("Models/Stone_Pack1_Stone_1/Stone_Pack1_Stone_1.obj");

This creates the Geometry class for reference, but then schedules the geometry for background loading, and loads the geometry in a background thread. If the underlying OS does not support background loading (MacOSX or iOS for example)
the geometry is loaded immediately. You may use any of the above variations, embed:// or http:// for dynamic loading as well.

Geometry Textures

Textures are loaded from the same folder by default. To specify a different folder, use the second parameter in the Geometry.Load (or Geometry.DynamicLoad function) to specify an alternate folder to search for textures.

Geometry Scaling

Geometry is loaded as-is in terms of scale. To specify a different scale, use the third and fourth parameters in Geometry.Load to specify the type of scale, and the scalar values:

gmeteor = Geometry.Load(Asset.LocalAssetFolder + "Models/Stone_Pack1_Stone_1/Stone_Pack1_Stone_1.obj", Asset.TexturePath + "Models/",
								ScaleType.Multiplier, new Vector(0.25, 0.25, 0.25));

Geometry Transformations

More advanced than scaling by itself, a Geometry transformation applies a transformation matrix to all coordinates (normals are renormalized):

Matrix rotate = Matrix.Rotation(new Angles(0, -Maths.NINETY, 0), Winding.XYZ);
Matrix scale = Matrix.Scale(new Vector(0.00015f, 0.00015f, 0.00015f));

Matrix transformation = scale * rotate;

Geometry Battleship = Geometry.Load(“space_battleship_5_upgraded.3DS”,””,transformation);

This is a one-time transformation during loading, and is particularly useful with third-party models to reorient and rescale the models for the needs of a scene.

Instancing

Once loaded, call Geometry.Instance to create an instance of the Geometry:

Geometry asteroid1 = Geometry.Instance(asteroid, true);

The second parameter, KeepMaterials will reuse the existing materials from the original class if set to True, so only the Geometry is instanced. If False, copies of the same materials will be created and referenced for the instance, so both the materials and the geometry will be instanced.

 Format-Specific Notes

The file format to import is determined by the filename extension (not case sensitive).

OBJ

.mtl files will be used to load materials (if available). If the .mtl file is not available, texture files that match the material name will be loaded if found (with .ibc, then .jpg, then .png extension).

3DS

Textures will attempt to load using the default file extension and type. If the texture is not found, the model importer will look for the equivalent .ibc file in the same location.

 

Loading Assets

Each asset type, Textures, Geometry etc.. has it’s own static functions for loading assets, each with custom properties, but they all have the one property in common, AssetName.

AssetName is essentially, the filename of the asset to load, but the file can be embedded, a local file or a URL.

Below is an example of how to specify the different ways, using a Texture asset.

To load a texture from a local file:

Texture lensflare = Texture.Load(Mipmapping.Nearest, false,
                              "planets/sunflare.ibc");

To load a texture from a URL:

Texture lensflare = Texture.Load(Mipmapping.Nearest, false,
         "http://www.mywebsite.com.sg/planets/sunflare.ibc");

NOTE: The web server will need to be configured to allow downloading of the requisite file extensions, in this case, .ibc.

To load the texture from an embedded resource:

Texture lensflare = Texture.Load(Mipmapping.Nearest, false,
                                    "embed://sunflare.ibc");

NOTE: The web server will need to be configured to allow downloading of the requisite file extensions, in this case, .ibc.

Loading Textures

Creation

Texture lensflare = Texture.Load(Mipmapping.Nearest, false,
                                   "Planets/sunflare.ibc");

This code loads the texture in, in the same thread, with Nearest mipmapping, and not repeating (the “false” value).
To load the texture dynamically, use:

Texture lensflare = Texture.DynamicLoad(Mipmapping.Nearest, false,
                                  "Planets/sunflare.ibc", true);

This creates the Texture class for reference, but then schedules the texture for background loading, and loads the texture in a background thread. If the underlying OS does not support background loading (MacOSX or iOS for example)
the texture is loaded immediately. You may use any of the above variations, embed:// or http:// for dynamic loading as well.

Disposal

To dispose of the texture, either add it to the Scene that it is valid for, and the Texture will be disposed automatically on scene exit, or call the texture.Dispose() method. All currently loaded Textures are automatically disposed on applicaiton exit, but you may wish to dispose of them earlier to save memory.