ObjWriter class final

Encodes any ModelDocument as Wavefront OBJ, with its .mtl beside it.

Takes a ModelDocument rather than an ObjDocument, for the reason F3dWriter does: the abstraction exists so that one encoder serves every decoder, and a glTF scene exported as OBJ is the case that matters. Nothing here is on a frame path.

The dialect is the one ObjLoader reads, not the union of everything the format allows. Every choice below that had more than one defensible answer was settled by asking what the reader beside this file does with it: the V flip, the sticky usemtl, the absent vt/vn records, the inverted Phong approximation in the .mtl. That is what makes the round trip the centre of the test file rather than a nice extra.

A document with no geometry writes an empty file, and does not refuse. The refusals in this package are for a malformed input — a truncated .f3d, a bad magic — and a model with nothing in it is not malformed, it is empty, which OBJ can say exactly: a header and no records. Read back it gives zero surfaces and the loader's own The file contained no triangles., so the observation survives the round trip in the one place that already reports it. Refusing would force every caller through a result type to guard a case the format represents.

Constructors

ObjWriter(ModelDocument document, {String name = 'model', int decimals = 6, bool flipTexcoordV = true})

Properties

decimals → int
Decimal places for every number written.
final
document → ModelDocument
final
flipTexcoordV → bool
OBJ puts the texture origin at the bottom left and this engine puts it at the top left, so ObjLoader stores 1 - v on the way in and this undoes it on the way out. Both default to true; setting one without the other is how a model comes back with its textures upside down.
final
hashCode → int
The hash code for this object.
no setterinherited
materialLibraryName → String
The filename the mtllib record points at.
no setter
name → String
The base name, without a suffix: it names the .mtl and appears in the header comment. It is not written into any record a reader parses, so a caller that saves under a different filename loses nothing but the mtllib line pointing at the right sibling.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
warnings → List<String>
What write could not carry, since OBJ has no record for it — fmt-12's own row, and its own literal example: a skinned document writes a warning about the skin it could not keep, not a file that looks like a faithful copy and is not.
latefinal

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited
write() → Uint8List
Encodes the .obj. The result is a complete file.
writeMaterialLibrary() → Uint8List?
Encodes the .mtl, or null when the document names no materials.

Operators

operator ==(Object other) → bool
The equality operator.
inherited