GLTFLightsExtension constructor

GLTFLightsExtension(
  1. dynamic parser
)

Implementation

GLTFLightsExtension(parser) {
  this.parser = parser;

  // Object3D instance caches
  this.cache = {"refs": {}, "uses": {}};

  this._markDefs = () {
    var parser = this.parser;
    var nodeDefs = this.parser.json["nodes"] ?? [];

    for (var nodeIndex = 0, nodeLength = nodeDefs.length;
        nodeIndex < nodeLength;
        nodeIndex++) {
      var nodeDef = nodeDefs[nodeIndex];

      if (nodeDef["extensions"] != null &&
          nodeDef["extensions"][this.name] != null &&
          nodeDef["extensions"][this.name]["light"] != null) {
        parser._addNodeRef(
            this.cache, nodeDef["extensions"][this.name]["light"]);
      }
    }
  };

  this.createNodeAttachment = (nodeIndex) {
    var self = this;
    var parser = this.parser;
    var json = parser.json;
    Map<String, dynamic> nodeDef = json["nodes"][nodeIndex];

    // var lightDef = ( nodeDef.extensions && nodeDef.extensions[ this.name ] ) ?? {};
    var lightDef = {};
    if (nodeDef["extensions"] != null &&
        nodeDef["extensions"][this.name] != null) {
      lightDef = nodeDef["extensions"][this.name];
    }

    var lightIndex = lightDef["light"];

    if (lightIndex == null) return null;

    final _light = this._loadLight(lightIndex);

    return parser._getNodeRef(self.cache, lightIndex, _light);
  };
}