Transformer3ds is a helper class that helps animate and transform (rotate, scale and translate) the objects read with Reader3ds.

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

Syntax

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

Remarks

Objects read with Ab3d..::.Reader3ds can be hierarhicly organized and can already contain a Matrix3DTransform that must not be overrided. Because of this aditional transformations of the objects can be a little bit tricky. Also when adding a transformation (rotation, scale or translate) it is possible that the object already contains a differenct transformation so a new Transform3DGroup must be added to the object.

The methods in Transformer3ds can greatly simplify transforming the objects read with Reader3ds. Firstly we need to create an instance of Transformer3ds and put a Reader3ds instace as a parameter to the constructor. Main methods in the class are: RotateObject(Vector3D, Double), ScaleObject(Double, Double, Double), TranslateObject(Double, Double, Double).

Each of those methods can takes an objectName as a first parameter - the name from the Reader3ds's NamedObjects. The transformation will happen this object. If this parameter is omitted, than all the objects read with specified Reader3ds are transformed.

Than there are parameters to define the transformation - for example Vector3D objectRotationAxis and double objectRotationAngle

Also bool isAdditive parameter can be used - if true that means that the applied transformation will be added to the currently applied transormation and will not replace the current one. For example if we specify 5.0 for objectRotationAngle and set true for isAdditive than the rotation angle will be increased for 5 degrees.

Examples

The following example reads a 3ds file and applies some transformation on its objects (sample is get from RobotArm sample available on http://www.wpf-graphics.com):
CopyC#
Ab3d.Reader3ds robotArmReader3ds = new Ab3d.Reader3ds();
robotArmReader3ds.ReadFile("robotarm.3DS", Viewport1);

Ab3d.Transformer3ds robotArmTransformer = new Ab3d.Transformer3ds(robotArmReader3ds);

robotArmTransformer.RotateObject("BaseMotor", new AxisAngleRotation3D(new Vector3D(0, 1, 0), 10));
robotArmTransformer.RotateObject("Joint2", new AxisAngleRotation3D(new Vector3D(0, 0, 1), 45));
robotArmTransformer.TranslateObject("Hand3", -10, 0, 0);
The following example rotates all the objects read with robotArmReader3ds (RotateObject is called without ObjectName parameter):
CopyC#
robotArmTransformer.Transformer.RotateObject(new AxisAngleRotation3D(new Vector3D(0, 0, 1), 45));
Note that the Transformer3ds can be also used with Reader3ds's Transformer property, for example:
CopyC#
robotArmReader3ds.RotateObject("BaseMotor", new Vector3D(0, 1, 0), 10, 10));
There is an even simpler way:
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 AxisAngleRotation3D(new Vector3D(0, 1, 0), 10), true);

Inheritance Hierarchy

System..::.Object
  Ab3d..::.Transformer3ds

See Also