Best Practices for Managing Scaling of Model Targets

While developing AR experiences with Model Targets, it may be that the real-life object differs in size from the digital model, or that the Model Target is being tested with a differently scaled replica of the object. This guide provides instructions on how to manage scaling and how to identify scaling problems throughout the development process.

It is important that the system knows the actual dimensions of the object that is being tracked (captured in the Model Target’s dataset), whether it is a replica for testing, or the real-world object.

If the Model Target and the real-life object do not have the same dimensions, the tracking can perform poorly or even fail in some instances. Vuforia Engine can handle some degree of discrepancy between model and object. However, receiving  WRONG_SCALE as the StatusInfo of the TargetStatus at runtime or from the log in the Unity Editor is an indication that the size of your Model Target is set incorrectly, and the target is either too small or too large compared to the physical object. For more details on the Model Target’s pose status and status info, see Pose Status and Status Info.

Scale Model Targets

In this guide, you will learn how to correctly maintain the scale of the Model Target before the setup process in the Model Target Generator (MTG), or during authoring in the Unity Editor, or in a native development environment.  

There are two ways of scaling Model Targets:

  1. Scale the model in a CAD modeling software before importing it into the MTG.
  2. Set the scale (physical size) of the Model Target in the Unity editor or at runtime.  

We recommend maintaining an exact 1:1 scale between the object and the 3D model at all times. Therefore, the best practice on scaling 3D models is to size it in the CAD modeling software before importing the 3D model into the MTG. Additionally, the unit information should also be set accordingly to the file format that is used in the CAD modeling software. See more information on supported formats in the Model Target Generator User Guide

Validating the Scale in the Model Target Generator

In the MTG’s Model Units tab, select the right units to define how the input data’s dimensions should be interpreted. Typically, these values are unit-less so they could be inches, centimeters, or meters. Therefore, choosing the dimensions of the Model Target so that the measurements match with the real-life object is an important step during the process of generating the Model Target. The scaling of the 3D model to its correct dimensions should be done before importing it into the MTG.

File Units in the MTG are only there to correct missing/wrong unit information - it is not meant for arbitrary scaling.

  • Choose the Model Units tab and select the correct dimensions the model should be represented in. The general practice for this is:
  • Checking if the dimensions match between the real-life object and the Model Target. If they do not match, then the File Units should be set to the correct dimensions.
    • The available units are: hm (hectometer), am (decameter), m (meter), dm (decimeter), cm (centimeter), mm (millimeter), ft (feet), and in (inches).
  • If the File Units options are unavailable, it is an indication that the model might be corrupt, and it should be reimported.

Intended scale mismatch

However, there may be use cases where the Model Target’s dimensions would explicitly not be set to match the real-life object:

  • When testing your Model Target with a scaled replica of the real-life object (I.e., testing with a to-scale miniature of a car, in form of a toy or a 3D printed version). 
  • When the 3D model’s dimensions are pre-set and are different from the real-life object, or the unit information of the model is unknown.

In the above cases, the correct physical size of the target can be configured in the Unity Editor or at runtime.  

Managing Model Target Scaling in Unity

In most scenarios, the Model Target at this point would not require any editing. However, in the few situations where re-scaling is necessary, this can be achieved by editing the ModelTarget GameObject in the Unity Editor. Make sure to configure to the correct size of the physical object in meters.

  • Select the ModelTarget GameObject and enter the scaling values (length, width, and height) to match the physical dimensions of the object. You will notice that changing one of its dimensions automatically scales the others accordingly.

NOTE: Particles and physics might be affected and cause issues when scaled together with the ModelTarget GameObject.

Testing with a Scaled Replica of the Model Target

If you are developing a Model Target experience for a full-size car model but using a toy model of that car for testing, then you should also adjust the Virtual Scene Scale Factor that is found in Vuforia Configuration.

Consider the following example

The physical car you are developing an AR experience for is 4m in length. All your virtual scene content matches that scale, but you want to test the application on a toy car that is in 1:20 scale with regards to the real car:

  • In the Model Target Behaviour component, change the Physical Length to 20cm (4m divided by 20).
  • In the Vuforia Configuration, set the Virtual Scene Scale Factor to 20.
  • Vuforia Engine will now know the accurate size of the physical object but will report tracking poses in the  reconfigured scale for your scene content. 

Please refer to the Virtual Scene Scale Factor in Unity article for more information.

Managing Model Target Scaling at Runtime

Setting your Model Target to a different size during runtime is only supported when it is uniformly scaled- this applies for all API languages and targets. It is recommended that you store the original values using getSize(), and then apply a new scale size factor to one of its dimensions SetHeight(), SetWidth(), SetLength().

Remember, the Behaviour of the Model Target must be deactivated before changing its size. It can be reactivated once the change has been made.

The following code snippet in C# presents a way to rescale the Model Target at runtime. Create an empty GameObject and attach the script to it. Create a button and place the GameObject in the OnClick() event and select ScaleModelTarget() to fire. Add the ModelTarget GameObject and a scale factor to the SetScaleFactor component.

123456789101112131415161718192021222324252627282930313233343536373839
Copy
using UnityEngine; using Vuforia; public class SetScaleFactor : MonoBehaviour { public ModelTargetBehaviour mModelTargetBehaviour; public float scale; public void ScaleModelTarget() { if (!mModelTargetBehaviour) { Debug.LogError("Cannot set scale, missing model target!"); return; } // First, deactivate the target var mModelTarget = mModelTargetBehaviour; mModelTarget.enabled = false; // Query current Model Target size Vector3 currentSize = mModelTargetBehaviour.GetSize(); Debug.Log("Current Model target size: " + currentSize.ToString("0.000")); // Set the new Model Target size by using a scale factor to either height, length, or width float width = currentSize.x; float newSize = scale * width; mModelTargetBehaviour.SetWidth(newSize); Debug.Log("Changed Model Target size to: " + mModelTargetBehaviour.GetSize().ToString("0.000")); // Re-activate the target mModelTarget.enabled = true; } }

 

Can this page be better?
Share your feedback via our issue tracker