decodePrimitive method

dynamic decodePrimitive(
  1. dynamic primitive,
  2. dynamic parser
)

Implementation

decodePrimitive(primitive, parser) async {
  var json = this.json;
  var dracoLoader = this.dracoLoader;
  var bufferViewIndex = primitive["extensions"][this.name]["bufferView"];
  var gltfAttributeMap = primitive["extensions"][this.name]["attributes"];
  var threeAttributeMap = {};
  var attributeNormalizedMap = {};
  var attributeTypeMap = {};

  gltfAttributeMap.forEach((attributeName, _value) {
    var threeAttributeName =
        ATTRIBUTES[attributeName] ?? attributeName.toLowerCase();

    threeAttributeMap[threeAttributeName] = gltfAttributeMap[attributeName];
  });

  primitive["attributes"].forEach((attributeName, _value) {
    var threeAttributeName =
        ATTRIBUTES[attributeName] ?? attributeName.toLowerCase();

    if (gltfAttributeMap[attributeName] != null) {
      var accessorDef =
          json["accessors"][primitive["attributes"][attributeName]];
      var componentType = WEBGL_COMPONENT_TYPES[accessorDef["componentType"]];

      attributeTypeMap[threeAttributeName] = componentType;
      attributeNormalizedMap[threeAttributeName] =
          accessorDef["normalized"] == true;
    }
  });

  final bufferView =
      await parser.getDependency('bufferView', bufferViewIndex);

  var completer = Completer<dynamic>();

  dracoLoader.decodeDracoFile(bufferView, (geometry) {
    geometry.attributes.forEach((attributeName, _value) {
      var attribute = geometry.attributes[attributeName];
      var normalized = attributeNormalizedMap[attributeName];

      if (normalized != null) attribute.normalized = normalized;
    });

    completer.complete(geometry);
  }, threeAttributeMap, attributeTypeMap);

  return completer.future;
}