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 (object != null && object!.fromDeclaration == false) {
    object!.name = name;
    object!.fromDeclaration = (fromDeclaration != false);
    return;
  }

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

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

  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;
    object!.materials.add(declared);
  }

  objects.add(object);
}