startObject method

void startObject(
  1. String? name,
  2. bool? fromDeclaration
)

Implementation

void startObject(String? name, bool? 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;
  }

  final previousMaterial = object?.currentMaterial();

  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 material is declared.
  // If a usemtl declaration is encountered while this 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) {
    final declared = previousMaterial.clone(0);
    declared.inherited = true;
    object!.materials.add(declared);
  }

  objects.add(object);
}