startObject method

dynamic startObject(
  1. dynamic name,
  2. dynamic fromDeclaration
)

Implementation

startObject(name, fromDeclaration) {
  // print(" startObject name: ${name} fromDeclaration: ${fromDeclaration} ");
  // print(" startObject object: ${this.object} this.object.fromDeclaration: ${this.object?.fromDeclaration} ");
  // If the current object (initial from reset) is not from a g/o declaration in the parsed
  // file. We need to use it for the first parsed g/o to keep things in sync.
  if (this.object != null && this.object!.fromDeclaration == false) {
    this.object!.name = name;
    this.object!.fromDeclaration = (fromDeclaration != false);
    return;
  }

  var previousMaterial =
      this.object != null ? this.object!.currentMaterial() : null;

  if (this.object != null) {
    this.object!._finalize(true);
  }

  this.object = ParseStateObject({
    "name": name ?? '',
    "fromDeclaration": (fromDeclaration != false),
  });

  // Inherit previous objects material.
  // Spec tells us that a declared material must be set to all objects until a new material is declared.
  // If a usemtl declaration is encountered while this new object is being parsed, it will
  // overwrite the inherited material. Exception being that there was already face declarations
  // to the inherited material, then it will be preserved for proper MultiMaterial continuation.

  if (previousMaterial != null && previousMaterial.name != null) {
    var declared = previousMaterial.clone(0);
    declared.inherited = true;
    this.object!.materials.add(declared);
  }

  this.objects.add(this.object);
}