Skip to main content

3D Optimization

This feature in Lens Studio can be found under the Inspector panel while a mesh is selected in the Asset Browser panel.

A mesh in an unpacked 3D asset selected in the Asset Browser, with its triangle and vertex counts, bounds, and the format of each vertex attribute in the Inspector

Overview

In many cases 3D assets created using photogrammetry tools, or marketing assets are used which were created for offline rendering. Both of these approaches provide high poly meshes which require a lot of memory. If you ever find yourself making a Lens with a heavy mesh which results in a Lens size that is too large, or poorly performing on device, adjusting a mesh vertex attributes help optimize your Lens.

When building for SPECS, every vertex a mesh keeps also costs power to render. Use meshes with as few vertices as your Lens needs, and draw repeated meshes with instancing. If you build with CLAD, the /specs-optimize-lens-mesh skill merges meshes that share a material and reduces their geometry for you. See Optimizing Lens Performance.

Many copies of a 3D model placed on a lawn in a Lens

Packed 3D Assets

When you import a 3D assets into Lens Studio, the mesh is compressed based on the Package Default settings.

A mesh in a packed 3D asset selected in the Asset Browser, with Compression override set to Package Default in the Inspector

You can turn off this compression by pressing the Compression Override drop down and selecting None.

Compression override set to None Compression in a mesh's Compression Settings

Unpacking 3D Assets

You can unpack 3D assets to have more compression options.

The context menu of a packed 3D asset in the Asset Browser, with the unpack command selected

Once you unpack a 3D Assets, you can not update the assets based on the source as readily, as you'll be unpacking the 3D assets to Lens Studio native assets. Though, you can reimport or relink.

Vertex Attributes

One way compression is done is by reducing the size of the information contained in each vertex of the 3D mesh.

Vertex attributes can be packed into fewer or even just in one position attribute in a third-party software, later unpack and utilized in Lens Studio. In this case all other attributes can be disabled.

To do this, let's look at the Compression Settings section in the Inspector panel, attributes available here are related to how the mesh was saved in the software used to create the mesh.

A mesh in an unpacked 3D asset selected in the Asset Browser, with its triangle and vertex counts, bounds, and the format of each vertex attribute in the Inspector

Several component types are available.

  • Byte: 8 bits.
  • Short: 16 bits.
  • Unsigned: unsigned integer [0, MAX].
  • Signed: signed integer [-MAX, MAX].
  • Integer normalization: remaps integer byte or short attributes to fixed point values in the range [0.0, 1.0] or [-1.0, 1.0] using the rough math normalizedValue = unnormalizedValue / MAX. Values outside this range are clamped to the min/max.

Format Conversions

Select the drop down next to the attribute to change how its information is stored.

The format menu of a vertex attribute open, listing Signed Byte through Float, Disabled, and Unknown
  • Byte - Signed: Signed 8-bit, two's complement integer with a range of -128 to 127.
  • Byte - Unsigned: Unsigned 8-bit integer with a range of 0 to 255.
  • Byte - SNorm: Signed 8-bit normalized fixed point value with a range of -1.0 to 1.0.
  • Byte - UNorm: Unsigned 8-bit normalized fixed point value with a range of 0.0 to 1.0.
  • Short - Signed: Signed 16-bit, two's complement integer with a range of -32,768 to 32,767.
  • Short - Unsigned: Unsigned 16-bit integer with a range of 0 to 65,535.
  • Short - SNorm: Signed 16-bit normalized fixed point value with a range of -1.0 to 1.0.
  • Short - UNorm: Unsigned 16-bit normalized fixed point value with a range of 0.0 to 1.0.
  • Half Float: 16-bit half precision floating point value, often called “half” or “float16”.
  • Float: 32-bit single precision floating point value.
  • Disable: Disable vertex attribute. This option is not provided for vertex position.

Attribute Setting Recommendations

In most cases, the smaller the attribute data is the better. Below are some examples for different format users can try:

  • Position: Float, Half Float, or try to rearrange your model data so that all positions are within a [-1, 1] range, in that case SNorm can be introduced.
  • Normal: Normalized vectors are on the range [-1, 1], SNorm is recommended.
  • Tangent: If a normal map is not used, tangent can be disabled.
  • Bitangent: If a normal map is not used, bitangent can be disabled.
  • Color: In most cases negative colors are not frequently used, 8-bits Byte - UNorm is recommended, if HDR colors are needed, try Half Float.
  • Texture0: In most cases, texture coordinates can be stored as SNorm or UNorm, however when using Repeated wrap mode with UV, the texture coordinates are out of range [-1, 1], we recommend using Half Float with cases like that.

In other words, you want to use as little data per vertex while still keeping the accuracy of your mesh. In doing so, you will reduce the size of your entire mesh.

Draco

Although decimation/simplification methods could be applied for hi-res meshes, however all automatic methods can’t reduce polycount to actual low poly values while keeping good details. Draco compression comes in handy when working with relatively limited Lens sizes, compression could be 10x smaller compared to the original which allows you putting more meshes into a single Lens.

To enable Draco compression, select Draco under the Compression Type.

The Compression menu of a mesh's Compression Settings open, with Draco and None

Then, toggle the Enable Draco Compression checkbox.

Draco compression on: Enable Draco Compression checked, with Compression Level and the position, texture coordinate, normal, and color bits, and the smaller current size
  • Compression Level: Range of 0 to 10, the higher level, the higher compression ratio and the lower decompression speed.
  • Position, Texcoord, Normal, Color Bits: Range of 1 to 30, the larger bits, the more precise.