Reader3ds is a class library for importing 3D objects from 3ds files into .Net 3.0 3D objects.

Namespace:  Ab3d
Assembly:  Ab3d.Reader3ds (in Ab3d.Reader3ds)
Version: 4.2.0.0 (4.2.0.0)

Syntax

C#
public class Reader3ds
Visual Basic (Declaration)
Public Class Reader3ds
Visual C++
public ref class Reader3ds

Remarks

Reader3ds can be most simply used with its static Instance property which returns an static instance of the Reader3ds. So you do no need to create your own instance of the class to use its metods. So you can write:

CopyC#
Ab3d.Reader3ds.Instance.ReadFile("sample_scene.3ds", myViewport);

This code uses the Reader3ds..::.ReadFile(String, Viewport3D) that reads the sample_scene.3ds from the application folder and imports all the models, its materials and all the lights and adds them to myViewport. If there are any cameras defined in simple_scene.3ds the first camera is assigned to myViewport. myViewport can be defined in code:

CopyC#
Viewport3D myViewport = new Viewport3D();
dockPanel1.Children.Add(myViewport);
or in XAML:
CopyC#
<Viewport3D Name="myViewport">
</Viewport3D>

After the file has been read you can use all the public properties of the Reader3ds simply by accessing them with the Instance:

CopyC#
GeometryModel3D head = Ab3d.Reader3ds.Instance.NamedObjects["head"] as GeometryModel3D;

The upper code is using NamedObjects to get the 3D objects named as "head" and sets a variable head with its GeometyModel3D.

3ds file can also contain animation data - with Reader3ds it is possible to get the simple animation data from 3ds file. For more see Reader3ds..::.GetFrame(Int32, Viewport3D)

Examples

For advanced use it is recommended to create an instance of Reader3ds - for example:
CopyC#
Ab3d.Reader3ds newReader3ds;
DiffuseMaterial defaultMaterial;

defaultMaterial = new DiffuseMaterial(new SolidColorBrush(Colors.Green));

newReader3ds = new Ab3d.Reader3ds();
newReader3ds.DefaultMaterial = defaultMaterial;
newReader3ds.TexturesPath = "c:\\textures";

newReader3ds.ReadFile("c:\\models\\buttons.3ds", myViewport);

Camera defaultCamera = newReader3ds.Cameras[0]; 
GeometryModel3D head = Ab3d.Reader3ds.Instance.NamedObjects["playButton"] as GeometryModel3D;

The last line in the previous example gets the object that has been named as "playButton". This can be very useful because in 3D modeling application a name can be set for each of the objects. With NamedObjects it is possible to get the Model3DGroup, GeometryModel3D, Light or Camera from the 3ds file. After this you can simply transform the object by using Ab3d..::.Transformer3ds. You can also get all the named objects with its hierarchy - see DumpNamedObjects()()()

Transforming (Translating, Scaling, Rotating) the read objects can be greatly simplified with Ab3d.Transformer3ds class. Reader3ds provides a Transformer property to get the instance of Transformer3ds for the current Reader3ds. Read class description for more info. The following samples demonstartes Transformer3ds usage:

CopyC#
// Read robotarm.3ds into myViewport
Ab3d.Reader3ds.Instance.ReadFile("robotarm.3ds", myViewport);

// Scales all the read objects by 10% (by factor 1.1)
Ab3d.Reader3ds.Instance.Transformer.ScaleObject(1.1, 1.1, 1.1);

// Rotates the 3D object with name "BaseMotor" for 10 degrees around Y axis. 
// The rotation is additive (last parameter is true) - so the rotation does not replace the previous rotation but adds it to the previous rotation - usefull for animation.
Ab3d.Reader3ds.Instance.Transformer.RotateObject("BaseMotor", new Vector3D(0, 1, 0), 10, true);
The following example shows how to use CompositionTarget.Rendering event for creating a frame-base animation with Reader3ds and Animator3ds.
CopyC#
void StartAnimation()
{
    CompositionTarget.Rendering += new EventHandler(CompositionTarget_RenderingHandler);

    Ab3d.Reader3ds.Instance.Animator.AnimationDuration = new TimeSpan(0, 0, 10); // 10 seconds
       Ab3d.Reader3ds.Instance.ReadFile("SampleAnimation.3ds", myViewport);
}

void EndAnimation()
{
    CompositionTarget.Rendering -= new EventHandler(CompositionTarget_RenderingHandler);
       Ab3d.Reader3ds.Instance.Animator.Stop();
}     

void CompositionTarget_Rendering(object sender, EventArgs e)
{
    Ab3d.Reader3ds.Instance.Animator.DoAnimate();
}

Inheritance Hierarchy

System..::.Object
  Ab3d..::.Reader3ds

See Also