Skip to content

ArModel

Overview

The ArModel is a simplified version of "Mesh", which supports limited number of vertices.

Use the ArModel to draw 3D objects and place them in the 3D environment.

Creating an ArModel

The Maverick SDK supports custom AR Model creation, allowing developers to define vertices, colors, custom bounding spheres and more.

This capability enables precise control over the visual representation and spatial properties of augmented reality models within applications built using the SDK.

It can be created from vertices or simple OBJ file.

Warning

Be cautious not to use too many vertices in your custom AR Model, as this can cause communication timeouts between the glasses and the app and to overload the rendering loop, potentially causing it to hang.

Reduce the model complexity and test thoroughly to ensure smooth performance and stability.

Vertices

In order to create an AR Model you will need to provide a list of ArPrimitive:

  • ArLines
  • ArPoints
  • ArTriangles

Let's examine the creation of a Cube:

/**
* Creates a cube with specified colors for its faces.
*
* @return An [ArModel] representing the cube.
*/
fun makeCube(): ArModel {
    val vertices = floatArrayOf(
        // front
        -1.0f, -1.0f, 1.0f,
        1.0f, -1.0f, 1.0f,
        1.0f, 1.0f, 1.0f,
        -1.0f, 1.0f, 1.0f,
        // back
        -1.0f, -1.0f, -1.0f,
        1.0f, -1.0f, -1.0f,
        1.0f, 1.0f, -1.0f,
        -1.0f, 1.0f, -1.0f
    )
    return ArModel(
        arrayListOf(
            ArTriangles(vertices, intArrayOf(0, 1, 2, 2, 3, 0), EvsColor.Orange.rgba),
            ArTriangles(vertices, intArrayOf(1, 5, 6, 6, 2, 1), EvsColor.Red.rgba),
            ArTriangles(vertices, intArrayOf(7, 6, 5, 5, 4, 7), EvsColor.Green.rgba),
            ArTriangles(vertices, intArrayOf(4, 0, 3, 3, 7, 4), EvsColor.Blue.rgba),
            ArTriangles(vertices, intArrayOf(4, 5, 1, 1, 0, 4), EvsColor.White.rgba),
            ArTriangles(vertices, intArrayOf(3, 2, 6, 6, 7, 3), EvsColor.Cyan.rgba),
        )
    )
}
  • The order of the vertices is crucial, as it determines the triangle's normal vector according to the Right-Hand Coordinate System (counter-clockwise, CCW).
  • We declare all the vertices once and then reuse them (this is done for performance).
  • Each triangle has its own color.

OBJ file support

You can create a simple OBJ file, place it in your app assets folder and create an ArModel right from it.

More information about Wavefront obj files can be found here.

When creating ArModel from obj file, the ArFactory maps the obj file elements to the SDK ArPrimitive objects.

ArFactory.fromObjFile("you_file_name_no_ext")
ArFactory.companion.fromObjFile(objFileNameWithoutExtension: "you_file_name_no_ext")

Stock ArModels

The SDK supplies the ArFactory class to create simple 3D element, as a showcase.

The Factory currently can create cube, star and arrow ArModels.

Placing ArModel

Relative to glasses

Convert the eye position to world position and then translate the model to that position.

In the following example we place the ArModel right in front of the user's eyes:

val arModel = ArFactory.makeCube()
val worldpos = FloatArray(3)
eye2world(xEye = 0f, yEye = 0f, zEye = -1f, q = quat, res = worldpos)
arModel.translate(east = worldpos[0], north = worldpos[1], up = worldpos[2])
let arModel = ArFactory.companion.makeCube()
let worldpos = KotlinFloatArray(size: 3)
eye2world(xEye: 0.0, yEye: 0.0, zEye: -1.0, q: quat, res: worldpos)
arModel.translate(east: worldpos.get(index: 0), north: worldpos.get(index: 1), up: worldpos.get(index: 2))

The function eye2world is implemented here.

For most of the cases you should use the quat for the q parameter.

At world position

Use the translate function (World Coordinate System).

In the following example we place the ArModel to the north:

arModel.translate(east = 0f, north = 1f, up = 0f)
arModel.translate(east: 0.0, north: 1.0, up: 0.0)