I am creating a 3D model from multiple images using the photogrammetry session. Now, when the session generates an OBJ file and I measure the distance between two points, the distance is displayed sporadically in different units. Sometimes it's meters, then centimeters, or another unit altogether. How can I tell the photogrammetry session to always create the model in millimeters?
Thanks for asking. This is an interesting question to investigate.
PhotogrammetrySession doesn't have a setting for units, but when your photos carry depth data, the model it writes is at real-world size in meters. Capturing photographs for RealityKit Object Capture says "If your source images contain depth data, RealityKit uses it to calculate the real-world size of the scanned object." I tested this with a box about 130 by 80 by 50 mm. I photographed it with RealityKit's guided capture on an iPhone 18 Pro Max running iOS 27.2.1, and reconstructed it on a Mac running macOS 27.2.1. The OBJ file's coordinates came out about 0.135 by 0.086 by 0.055, the box's size in meters. The USDA file that the session writes beside it declares metersPerUnit = 1.
Without depth data, the scale isn't tied to the object. The same article adds that without depth data, "you may have to scale the object when placing it into your AR scene." After I removed the depth data from my photos, the model had the same shape at about four times the size.
An OBJ file stores plain numbers with no unit, so the app you measure in decides how to label a distance. Multiplying the coordinates by 1000 after the session writes the file gives you millimeters. This function writes a scaled copy and leaves the rest of the file unchanged:
import Foundation
// Writes a copy of an OBJ file with every vertex position multiplied by `factor`.
// Texture coordinates, normals, faces, and material references stay as they are.
func scaleOBJ(at source: URL, to destination: URL, by factor: Double) throws {
let lines = try String(contentsOf: source, encoding: .utf8).components(separatedBy: "\n")
let scaled = lines.map { line -> String in
guard line.hasPrefix("v ") else { return line }
let fields = line.split(separator: " ")
let xyz = fields.dropFirst().prefix(3).compactMap { Double($0) }
guard xyz.count == 3 else { return line }
let rest = fields.dropFirst(4).map(String.init)
return (["v"] + xyz.map { String($0 * factor) } + rest).joined(separator: " ")
}
try scaled.joined(separator: "\n").write(to: destination, atomically: true, encoding: .utf8)
}
The copy refers to its material file by name, so it finds that file when both are in the same folder. On my .full model, which has about 61,000 triangles in a 7 MB file, the function took less than a tenth of a second. It reads the whole file into memory, and the process peaked at 47 MB. PhotogrammetrySession.Request.Detail lists .full at fewer than 250,000 triangles and .raw at fewer than 30 million. For a .raw model, a version that reads one line at a time uses much less memory.
The init(bounds:transform:) initializer of PhotogrammetrySession.Request.Geometry also takes a transform, which the documentation describes as a way to "scale, rotate, or move the object." In my tests, a uniform scale of 1000 had no effect. The OBJ file, a USDZ file, and the returned ModelEntity all kept the box's size in meters. That doesn't match the documentation, so please file a bug report in Feedback Assistant. Include a set of photos and your request code. If you post the Feedback number here I'll check the status next time I do a sweep of forums posts where I've suggested bug reports.