decodePrimitive method

dynamic decodePrimitive(
  1. Map<String, dynamic> primitive,
  2. GLTFParser parser
)

Implementation

decodePrimitive(Map<String,dynamic> primitive, GLTFParser parser) async {
  final json = this.json;
  final dracoLoader = this.dracoLoader;
  final bufferViewIndex = primitive["extensions"][name]["bufferView"];
  final gltfAttributeMap = primitive["extensions"][name]["attributes"];
  final threeAttributeMap = {};
  final attributeNormalizedMap = {};
  final attributeTypeMap = {};

  gltfAttributeMap.forEach((attributeName, value) {
    final threeAttributeName = webglAttributes[attributeName] ?? attributeName.toLowerCase();
    threeAttributeMap[threeAttributeName] = gltfAttributeMap[attributeName];
  });

  primitive["attributes"].forEach((attributeName, value) {
    final threeAttributeName = webglAttributes[attributeName] ?? attributeName.toLowerCase();

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

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

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

  final completer = Completer<dynamic>();

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

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

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

  return completer.future;
}