import {TypedMatNode} from "./_Base";
import {MaterialPersistedConfig} from "../gl/code/assemblers/materials/PersistedConfig";
import {NodeContext as NodeContext2} from "../../poly/NodeContext";
export class TypedBuilderMatNode extends TypedMatNode {
  constructor() {
    super(...arguments);
    this._children_controller_context = NodeContext2.GL;
    this.persisted_config = new MaterialPersistedConfig(this);
  }
  create_material() {
    let material;
    if (this.persisted_config) {
      material = this.persisted_config.material();
    }
    if (!material) {
      material = this.assemblerController?.assembler.create_material();
    }
    return material;
  }
  get assemblerController() {
    return this._assembler_controller = this._assembler_controller || this._create_assembler_controller();
  }
  createNode(node_class, params_init_value_overrides) {
    return super.createNode(node_class, params_init_value_overrides);
  }
  children() {
    return super.children();
  }
  nodesByType(type) {
    return super.nodesByType(type);
  }
  childrenAllowed() {
    if (this.assemblerController) {
      return super.childrenAllowed();
    }
    this.scene().markAsReadOnly(this);
    return false;
  }
  compile_if_required() {
    if (this.assemblerController?.compile_required()) {
      this._compile();
    }
  }
  _compile() {
    const assemblerController = this.assemblerController;
    if (this.material && assemblerController) {
      assemblerController.assembler.compile_material(this.material);
      assemblerController.post_compile();
    }
  }
}
