Obj |
public class ObjModelVisual3D : BaseVisual3D, IUriContext
The ObjModelVisual3D type exposes the following members.
Name | Description | |
---|---|---|
ObjModelVisual3D | Constructor | |
ObjModelVisual3D(String) | Constructor |
Name | Description | |
---|---|---|
DefaultBackMaterial | Gets or sets the default material that is used for BackMaterial when the back material is not defined in obj file. Default value is null. | |
DefaultMaterial | Gets or sets the default material that is used when the material is not defined in obj file. Default value is a Silver DiffuseMaterial. | |
Position | Gets or sets the Position of the read obj model. The type of position is determined by PositionType property. | |
PositionType | Gets or sets the ObjModelVisual3DVisualPositionType value that specifies the type of the Position | |
PreserveScaleAspectRatio | 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). | |
SizeX | Gets or sets the size in of the 3D model in X dimension. | |
SizeY | Gets or sets the size in of the 3D model in Y dimension. | |
SizeZ | Gets or sets the size in of the 3D model in Z dimension. | |
Source | Gets or sets the Source of the obj file | |
TexturesPath | Gets or sets the path where the textures are located. If null or "" the path of the obj 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") | |
UsedReaderObj | Gets a Ab3d.ReaderObj instance that is used to read the obj file. |
Name | Description | |
---|---|---|
CreateModel |
Creates this Model3D
(Overrides BaseVisual3DCreateModel) | |
Reload | Forces a reload of the obj file | |
SetModel | Sets the Content of the Visual3D | |
SetModelScale | SetModelScale set the modelScale as ScaleTransform3D. It is used to scale the model. The method can be overridden to provide custom scaling. | |
SetModelTranslate | SetModelTranslate sets the modelTranslate as TranslateTransform3D. It is used to position the model. The method can be overridden to provide custom positioning. |
Name | Description | |
---|---|---|
DefaultBackMaterialProperty | DefaultBackMaterialProperty | |
DefaultMaterialProperty | DefaultMaterialProperty | |
modelScale | ScaleTransform3D that is used to scale the model | |
modelTransformGroup | Transform3DGroup that is used to scale and position the model | |
modelTranslate | TranslateTransform3D that is used to position the model | |
PositionProperty | PositionProperty | |
PositionTypeProperty | PositionTypeProperty | |
PreserveScaleAspectRatioProperty | PreserveScaleAspectRatioProperty | |
SizeXProperty | SizeXProperty | |
SizeYProperty | SizeYProperty | |
SizeZProperty | SizeZProperty | |
SourceProperty | SourceProperty | |
TexturesPathProperty | TexturesPathProperty |
Name | Description | |
---|---|---|
DumpHierarchy |
Display details about the hierarchy of Visual3D children to Debug console (for example to Visual Studio's Immediate window).
(Defined by Extensions) | |
ForEachGeometryModel3D |
Performs the specified action on each GeometryModel3D inside the rootModelVisual3D.
(Defined by Extensions) | |
ForEachVisual3D |
Performs the specified action on each ModelVisual3D inside the rootModelVisual3D.
(Defined by Extensions) | |
GetName |
Gets name of the Visual3D that was previously set by SetName extension method.
(Defined by Extensions) | |
SetName |
Sets Name property to Visual3D. Note that if name is not correct for WPF, it can be corrected (name must start with a letter or the underscore character (_), and must contain only letters, digits, or underscores).
In this case the SetName method will set the corrected name to the object and return false (in this case you can call GetName to get the corrected name). True is returned when the original name is set to the object.
(Defined by Extensions) |
ObjModelVisual3D can be used in XAML to show 3D models that are read from obj file.
The source of the obj 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.
Before using ObjModelVisual3D the following namespace declaration has to be added to the root xaml element:
xmlns:visuals="clr-namespace:Ab3d.Visuals;assembly=Ab3d.PowerToys"
Now the ObjModelVisual3D can be used in XAML. The following example shown a 3D model from ab3d.obj file. The model's center is positioned at (-250, 0, 0) and its size is set so its SizeX is 80:
<visuals:ObjModelVisual3D Source="/Resources/ab3d.obj" SizeX="80" Position="0 40 0" PositionType="Center"/>
The following code shows the same mode, but this time it is custom sized:
<visuals:ObjModelVisual3D Source="/Resources/ab3d.obj" SizeX="50" SizeY="30" SizeZ="40" PreserveScaleAspectRatio="False" Position="0 40 0" PositionType="Center"/>
The following code shows how to use ObjModelVisual3D in code behine:
var objModelVisual = new Ab3d.Visuals.ObjModelVisual3D() { Source = new Uri(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources/myModel.obj"), UriKind.Absolute), DefaultMaterial = new DiffuseMaterial(Brushes.Silver), Position = new Point3D(0, 0, 0), PositionType = Visuals.ObjModelVisual3D.VisualPositionType.BottomCenter, SizeX = 100 }; MainViewport3D.Children.Add(objModelVisual);