FMX.ModelViewer Sample

From Appmethod Code Examples
Jump to: navigation, search

This sample demonstrates how to use TModel3D to load 3D models in FireMonkey applications at run time.

Location

You can find the SurfSpotFinderApp sample project at:

Description

This application creates a 3D model viewer that provides basic functionalities: load, rotation, zoom, change of the material that the 3D model uses.

Load a 3D model from a file (*.obj, *.dae, *.ase) and change or view the material that the 3D model uses. For material you can use solid colors, textures or light materials.

You can interact with the loaded 3D model using mouse movements for rotation, the mouse wheel and key arrows for zoom, and the arrows in the upper-left corner for plane change of position.

Some models may not be visible immediately after being loaded due to the scale or Material settings of the respective model. To view the model, just use the track bar to change the scale or click 'Edit Material' and select TColorMaterialSource and appropriate color.

Also, some models may have a high level of detail, so the loading operation may take longer; watch the status bar to see when the model has been loaded.

How to Use the Sample

  1. Navigate to the location given above and open Model3D.dproj.
  2. Press F9 or choose Run > Run.

Files

File Contains

Materials_U

The class for the form that is displayed when the user chooses Edit Material from the editor.

Model3D_U

The class for the main form that represents the editor itself.

Classes

  • TFrameMaterialDesigner is the form from which you can select the properties of the material. It contains a TLayer3D, a TLight, and a TCube on which you can see the selected properties.
  • TModel3DTest is the main form of the application. It contains components such as TViewport3D, TModel3D, TLight, TCamera, TStyleBook, used to create the basic viewer and to display an animated preview of the 3D model at a smaller scale.

Implementation

  • The basic viewer and the animated preview are implemented using TViewport3D to view the 3D object, TModel3D to allow manipulation for the loaded model, TCamera to define the scene perspective, and TLight to imitate the rays of light.
  • A TTrackBar component is used to implement the scale of the object.
  • The load from file, clear, and edit material actions are performed when the buttons with the same name are pressed.
  • Using a TLabel component, the application displays the loading status of the 3D object.
  • A TListBox component contains the material source properties, which are displayed into a TGroupBox.
  • The application uses different TFloatAnimation objects to animate the 3D models.

Uses

See Also

Samples

Personal tools