Guide 1: Initialize and layout a 3D model in a view
Overview
In this guide, we'll show a few common controls that configure the layout of a 3D model in the display-3d-model component. This includes:
Manual controls such as setting the scale of a model and adjusting its X, Y or Z offset.
Automatic configuration controls, such as auto-scaling or auto-centering a model in the viewer.
The ability to load a different 3D model (FBX file).
The view we'll build will look as follows:

Developer notes:
Your app must be on version 4.85.0 or greater of the JourneyApps Runtime. This version introduces the
gridUI component, which we'll use to layout thedisplay-3d-modelUI component and its controls in the view.You should have a zipped .fbx file ready to upload into the app. If you don’t have a 3D model to test with, feel free to download the sample 3D model we're using in this guide here.
The complete data model and view code section at the end of this guide contains the complete view XML and JS files, which may be easier to copy and paste than the individual snippets below.
Load and display the 3D model in your view
First, we'll add a capture-file UI component to our main view, which will allow us to upload the .fbx file containing the 3D model. The capture-file component must be bound to a variable of type attachment.
Next, we'll initialize the display-3d-model UI component.
For this, we'll use a grid, where the display-3d-model component spans the first 3 columns, and the previously added capture-file component is placed in the 4th column.
The main view XML code now looks as follows:
Note that we are including the material-vertex-groups="false" attribute in this basic view. We're simply doing this to expose the model's various colored elements in our examples going forward.
And in the view JS, we'll initialize the 3D model's scale to a default value:
A zipped .fbx file can now be uploaded using the capture-file component. The uploaded 3D model will then display in the display-3d-model component.

Set up manual config controls
Now that a 3D model is displayed, we want to give users to ability to configure the scale and offsets of the model. We'll do this by adding variables to store the values for the offsets (a variable for scale already existed), and add text-input UI components for users to enter or adjust the values:
We need to update our init() function to set initial values for the offsets:
Increasing or decreasing the scale should now increase and decrease the scale of the 3D model respectively. Increasing e.g. the x-offset, should move the 3D model further along the x-axis.
Set up automatic config controls
display-3d-model comes with a number of component methods which allow users to further interact with the 3D model. We'll explore computeScaleFactor to auto-scale the 3D model, as well as computeCenterOffset to auto-center the 3D model in the component.
On the view XML side, we will add two buttons to let users trigger these methods. We also need to add an id attribute to the display-3d-model component, which is needed for the methods to identify the component:
The buttons call two functions respectively: autoScale() and autoCenter().
The autoScale() function, which uses the computeScaleFactor component method, could look as follows:
The autoCenter() function, which utilizes the computeCenterOffset component method, could look as follows:
Complete view code
Below is the complete View XML and JS code used in this guide:
Last updated