Click or drag to resize
Transformer3ds Class
Transformer3ds is a helper class that helps animate and transform (rotate, scale and translate) the objects read with Reader3ds.
Inheritance Hierarchy
SystemObject
  Ab3dTransformer3ds

Namespace: Ab3d
Assembly: Ab3d.Reader3ds (in Ab3d.Reader3ds.dll) Version: 9.0.5590.1040
Syntax
C#
public class Transformer3ds

The Transformer3ds type exposes the following members.

Constructors
  NameDescription
Public methodTransformer3ds
Constructor
Top
Properties
  NameDescription
Public propertyUsedReader3ds
Gets a Reader3ds that is used in this Transformer3ds
Top
Methods
  NameDescription
Public methodApplyTransformation
Applies the newTransformation to the modelToApplyTransformtion. If the model already has the same type of transformation than this transformation is replaced with the new one. If this type of transformation is not already applied to the models than the transformation is added to model's Transform3DGroup
Public methodClearAllTransformations
Clears all transformation in all objects in UsedReader3ds
Public methodClearTransformations(String)
Clears all transformation in objectName (only MatrixTransformations are left because they are needed to represent the hierarchy of read 3ds file)
Public methodClearTransformations(Model3D)
Clears all transformation in objectsGroup (only MatrixTransformations are left because they are needed to represent the hierarchy of read 3ds file)
Public methodStatic memberGetCenterPosition
Returns a center point of a Model3D object
Public methodGetChildren(String)
Get Model3DCollection (Children) for objectName (Model3DGroup or GeometryModel3D) or null if model has no children. GeometryModel3D can have children if for it there was a Model3DGroup created (becasue of a hierarchy). In this case there is a (objectName + Reader3ds.GroupNameSuffix) in NamedObjects dictionary.
Public methodGetChildren(Model3D)
Get Model3DCollection (Children) for Model3DGroup or GeometryModel3D or null if model has no children. GeometryModel3D can have children if for it there was a Model3DGroup created (becasue of a hierarchy). In this case there is a (objectName + Reader3ds.GroupNameSuffix) in NamedObjects dictionary.
Public methodGetObjectCenter
Returns a center point of a Model3D object
Public methodGetObjectName
Gets the name of the object from UsedReader3ds.NamedObjects dictionary
Public methodGetObjectOrItsGroup(String)
If objectName from UsedReader3ds.NamedObjects is Model3DGroup or Light the same model is returned. If objectName is GeometryModel3D and it has children (because of hierarchy there was a Model3DGroup created for it) than return the Model3DGroup. If objectName is GeometryModel3D and has no children return model as GeometryModel3D.
Public methodGetObjectOrItsGroup(Model3D)
If model is Model3DGroup or Light the same model is returned. If model is GeometryModel3D and it has children (because of hierarchy there was a Model3DGroup created for it) than return the Model3DGroup. If model is GeometryModel3D and has no children return model as GeometryModel3D.
Public methodGetObjectRotation(String)
Gets a RotateTransform3D for the object with objectName - if there is a Transform3DGroup the RotateTransform3D is get from it
Public methodGetObjectRotation(Model3D)
Gets a RotateTransform3D for the model - if there is a Transform3DGroup the RotateTransform3D is get from it
Public methodGetObjectScale(String)
Gets a ScaleTransform3D for the object with objectName - if there is a Transform3DGroup the RotateTransform3D is get from it
Public methodGetObjectScale(Model3D)
Gets a ScaleTransform3D for the model - if there is a Transform3DGroup the RotateTransform3D is get from it
Public methodGetObjectSize
Gets the size of one Model3D - length of the diagonal of object's bounds
Public methodGetObjectTranslation(String)
Gets a TranslateTransform3D for the object with objectName - if there is a Transform3DGroup the RotateTransform3D is get from it
Public methodGetObjectTranslation(Model3D)
Gets a TranslateTransform3D for the model - if there is a Transform3DGroup the RotateTransform3D is get from it
Public methodGetParentGroup(String)
Gets the parent Model3DGroup of the NamedObject. If the objectName is already a Model3DGroup than the same object is returned, else the parent group is returned. Used when you get a GeometryModel3D from Reader3ds's NamedObjects and would like to apply a transformation to the GeometryModel3D and all its child objects.
Public methodGetParentGroup(GeometryModel3D)
Gets the parent Model3DGroup of the GeometryModel3D. Used when you get a GeometryModel3D from Reader3ds's NamedObjects and would like to apply a transformation to the GeometryModel3D and all its child objects
Public methodGetParentGroup(Model3DGroup, GeometryModel3D)
Gets the parent Model3DGroup of the GeometryModel3D. Used when you get a GeometryModel3D from Reader3ds's NamedObjects and would like to apply a transformation to the GeometryModel3D and all its child objects
Public methodStatic memberGetSize
Gets the size of one Model3D - length of the diagonal of object's bounds
Public methodHasChildren(String)
Returns true if the objectName (Model3DGroup or GeometryModel3D) has children (at least one - empty collection returns false). GeometryModel3D can have children if for it there was a Model3DGroup created (becasue of a hierarchy). In this case there is a (objectName + Reader3ds.GroupNameSuffix) in NamedObjects dictionary.
Public methodHasChildren(Model3D)
Returns true if the Model3DGroup or GeometryModel3D has children (at least one - empty collection returns false). GeometryModel3D can have children if for it there was a Model3DGroup created (becasue of a hierarchy). In this case there is a (objectName + Reader3ds.GroupNameSuffix) in NamedObjects dictionary.
Public methodRotateObject(AxisAngleRotation3D)
Applies AxisAngleRotation3D to all objects and lights. The rotation is applied around objects center point.
Public methodRotateObject(RotateTransform3D)
Applies RotateTransform3D to all objects and lights. The rotation is applied around objects center point.
Public methodRotateObject(String, AxisAngleRotation3D)
Applies AxisAngleRotation3D to the object with objectName and to all its child objects. The rotation is applied around objects center point.
Public methodRotateObject(String, RotateTransform3D)
Applies RotateTransform3D to the object with objectName and to all its child objects - enables rotating object around custom center point.
Public methodRotateObject(Vector3D, Double)
Applies AxisAngleRotation3D to all objects and lights.
Public methodRotateObject(String, Vector3D, Double)
Applies AxisAngleRotation3D to the object with objectName and to all its child objects
Public methodRotateObject(Vector3D, Double, Boolean)
Applies AxisAngleRotation3D to all objects and lights. The rotation is applied around objects center point.
Public methodRotateObject(String, Vector3D, Double, Boolean)
Applies AxisAngleRotation3D to the object with objectName and to all its child objects. The rotation is applied around objects center point.
Public methodScaleObject(ScaleTransform3D)
Applies scale transformation to all objects and lights.
Public methodScaleObject(String, ScaleTransform3D)
Applies scale transformation to the object with objectName and to all its child objects
Public methodScaleObject(Double, Double, Double)
Applies scale transformation to all objects and lights.
Public methodScaleObject(Double, Double, Double, Boolean)
Applies scale transformation to all objects and lights.
Public methodScaleObject(String, Double, Double, Double)
Applies scale transformation to the object with objectName and to all its child objects
Public methodScaleObject(String, Double, Double, Double, Boolean)
Applies scale transformation to the object with objectName and to all its child objects
Public methodTranslateObject(TranslateTransform3D)
Applies scale transformation to all objects and lights.
Public methodTranslateObject(String, TranslateTransform3D)
Applies scale transformation to the object with objectName and to all its child objects
Public methodTranslateObject(Double, Double, Double)
Applies scale transformation to all objects and lights.
Public methodTranslateObject(Double, Double, Double, Boolean)
Applies scale transformation to all objects and lights.
Public methodTranslateObject(String, Double, Double, Double)
Applies scale transformation to the object with objectName and to all its child objects
Public methodTranslateObject(String, Double, Double, Double, Boolean)
Applies scale transformation to the object with objectName and to all its child objects
Top
Remarks

Objects read with Reader3ds can be hierarchically organized and can already contain a Matrix3DTransform that must not be overridden Because of this additional 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 different 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 instance 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 isAdditive parameter can be used - if true that means that the applied transformation will be added to the currently applied transformation 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.ab4d.com):
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):
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:
robotArmReader3ds.RotateObject("BaseMotor", new Vector3D(0, 1, 0), 10, 10));
There is an even simpler way:
// 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);
See Also