Click or drag to resize
Model3ds Class
Model3ds is a Visual3D class that shows 3D models that are read from 3ds file specified with Source property.
Inheritance Hierarchy

Namespace: Ab3d.Visuals
Assembly: Ab3d.Reader3ds (in Ab3d.Reader3ds.dll) Version: 9.0.5590.1040
Syntax
C#
public class Model3ds : BaseModel3dsVisual3D, IUriContext

The Model3ds type exposes the following members.

Constructors
  NameDescription
Public methodModel3ds
Constructor
Top
Properties
  NameDescription
Public propertyFrameNumber
Gets or sets the frame number that is shown by this Model3ds.
Public propertyIsModel3DCloned
Gets or sets a Boolean that specifies if the Model3D is cloned before it is set as the Model3dsVisual3D's Content. Default value is false.
Public propertyIsReader3dsShared
Gets or sets a Boolean that specifies if the same Source 3ds file is read only once and is shared between all Model3dsVisual3Ds that use the same Source. Default value is true.
Public propertyObjectName
Gets or sets the name of the object from the Source 3ds file that will be shown. If empty (default) all the objects from 3ds will be shown.
Public propertyPosition
Gets or sets the Position of the read 3ds model. The type of position is determined by PositionType property.
Public propertyPositionType
Gets or sets the VisualPositionType value that specifies the type of the Position
Public propertyCode examplePreserveScaleAspectRatio
Gets or sets a Boolean that specifies if the 3D model is scaled so its aspect ratio is preserved (the ratio between width, height and depth of the object).
Public propertyCode exampleSizeX
Gets or sets the size in of the 3D model in X dimension.
Public propertyCode exampleSizeY
Gets or sets the size in of the 3D model in Y dimension.
Public propertyCode exampleSizeZ
Gets or sets the size in of the 3D model in Z dimension.
Public propertySource
Gets or sets the Source of the 3ds file
Public propertyTexturesPath
Gets or sets the path where the textures are located. If null or "" the path of the 3ds file is used. It is also possible to set TexturesPath to url of the textures (http://...) or to the application resources ("pack://application:,,,/XAMLBrowserApplication1;component/models")
Public propertyUsedReader3ds
Gets a Ab3d.Reader3ds instance that is used to read the 3ds file.
Top
Methods
  NameDescription
Public methodReload
Forces a reload of the 3ds file
Top
Events
  NameDescription
Public eventAfterReading3dsFile
AfterReading3dsFile event occurs after the 3ds file has been read.
Public eventCode exampleBeforeReading3dsFile
BeforeReading3dsFile event occurs after the UsedReader3ds has been created and before the actual 3ds file has been read.
Top
Fields
  NameDescription
Public fieldStatic memberFrameNumberProperty
FrameNumberProperty
Public fieldStatic memberIsModel3DClonedProperty
IsModel3DClonedProperty
Public fieldStatic memberIsReader3dsSharedProperty
IsReader3dsSharedProperty
Public fieldStatic memberObjectNameProperty
ObjectNameProperty
Public fieldStatic memberPositionProperty
PositionProperty
Public fieldStatic memberPositionTypeProperty
PositionTypeProperty
Public fieldStatic memberPreserveScaleAspectRatioProperty
PreserveScaleAspectRatioProperty
Public fieldStatic memberSizeXProperty
SizeXProperty
Public fieldStatic memberSizeYProperty
SizeYProperty
Public fieldStatic memberSizeZProperty
SizeZProperty
Public fieldStatic memberSourceProperty
SourceProperty
Public fieldStatic memberTexturesPathProperty
TexturesPathProperty
Top
Remarks

Model3ds can be used in XAML to show 3D models that are read from 3ds file.

The source of the 3ds file is specified with Source property.

The read 3D model is positioned according to the Position and PositionType properties

If the PositionType is set to Center (default), the 3D model will be position so that its center will be at the Position coordinates. If the PositionType is set to BottomCenter, the 3D model will be positioned above the Position coordinates.

The size of the shown object is controlled by the SizeX, SizeY, SizeZ and PreserveScaleAspectRatio properties.

By default all the SizeX, SizeY and SizeZ are set to -1. This means that the original size of the object is used. But if the SizeX is set to let's say 100, the object would be scaled so its SizeX would be 100.

If PreserveScaleAspectRatio is true (default), than the aspect ratio of the 3D model is preserved. This means that the model is stretched to one side mode than to the other - the scale is evenly set to all the axis. This also means that if all SizeX, SizeY and SizeZ are defined, the object will be scaled so it will not exceed and of the specified sizes.

If PreserveScaleAspectRatio is false, than the aspect ration of the 3D model will not be preserved. In this case the SizeX, SizeY and SizeZ will be applied so the object will be exactly the size of the specified sizes.

By default all the 3D models from 3ds file are shown with Model3ds. If only some of the objects need to be shown, it is possible to set the ObjectName property to the name of the 3D model to show. The name should be one of the names from the Reader3ds's NamedObjects dictionary.

To get the names of the read objects, a DumpNamedObjects or GetNamedObjectsText methods can be used on Reader3ds. With Model3ds the used Reader3ds can be accessed with UsedReader3ds property. For example to get the object names and their hierarchy run the following in the Visual Studio Immediate window (execute after the 3ds file has been read):

MyModel3ds.UsedReader3ds.DumpNamedObjects(); // MyModel3ds is an instance of Model3ds

Reader3ds can also play animations from 3ds files. This can be also done with Model3ds with its FrameNumber property. This property can be bound to a DoubleAnimation to animate its value from the first frame to the last frame.

There are also two additional properties.

The IsReader3dsShared property specifies if the used Reader3ds is shared between Model3ds instances. By default its value is True, which means that each source 3ds file is read only once for all Model3ds instances that use the same source. If the value is set to False, the Model3ds creates its own Reader3ds and read the 3ds file with it.

The IsModel3DCloned property specifies if the 3D model that is shown is cloned for each Model3ds instances. By default IsModel3DCloned is set to false. This means that all shared Model3ds instances get the same instance of 3D Model. If you need to change a model without changing all other shared models, set the IsModel3DCloned to true.

The Reader3ds class defines many properties that can be set before the 3ds file is read. For example with Shading it is possible to specify what type of shading will be used for the 3D models. To set those properties it is possible to subscribe to BeforeReading3dsFile event. The event is fired after the UsedReader3ds property is set to Reader3ds instance and before the 3ds file is read. This means that in the event handler it is possible to set the special properties on Reader3ds. When subscribing to BeforeReading3dsFile event and the IsReader3dsShared is true (by default) be careful to subscribe on the first Model3ds because only on the first Model3ds the 3ds is actually read.

Examples

Before using Model3ds the following namespace declaration has to be added to the root xaml element:

xmlns:model3ds="clr-namespace:Ab3d.Visuals;assembly=Ab3d.Reader3ds"

Now the Model3ds can be used in XAML. The following example shown a 3D model from ab3d.3ds file. The model's center is positioned at (-250, 0, 0) and its size is set so its SizeX is 80:

XAML
<model3ds:Model3ds Source="/Resources/ab3d.3ds" 
                   SizeX="80"
                   Position="0 40 0" PositionType="Center"/>

The following code shows the same mode, but this time it is custom sized:

XAML
<model3ds:Model3ds Source="/Resources/ab3d.3ds" 
                   SizeX="50" SizeY="30" SizeZ="40"
                   PreserveScaleAspectRatio="False"
                   Position="0 40 0" PositionType="Center"/>

The following example shows a Teapot01 model from the multiple objects.3ds file:

XAML
<model3ds:Model3ds x:Name="Teapot1"
                   Source="/Resources/multiple objects.3ds" 
                   ObjectName="Teapot01"
                   SizeY="20">
See Also