addPrimitiveAttributes top-level property

Function addPrimitiveAttributes
getter/setter pair

@param {BufferGeometry} geometry @param {GLTF.Primitive} primitiveDef @param {GLTFParser} parser @return {Promise

Implementation

Function addPrimitiveAttributes =
    (geometry, Map<String, dynamic> primitiveDef, GLTFParser parser) async {
  var attributes = primitiveDef["attributes"];

  List pending = [];

  Function assignAttributeAccessor = (accessorIndex, attributeName) async {
    final accessor = await parser.getDependency('accessor', accessorIndex);
    return geometry.setAttribute(attributeName, accessor);
  };

  List<String> attKeys = geometry.attributes.keys.toList();

  for (var gltfAttributeName in attributes.keys) {
    var value = attributes[gltfAttributeName];

    var threeAttributeName =
        ATTRIBUTES[gltfAttributeName] ?? gltfAttributeName.toLowerCase();

    // Skip attributes already provided by e.g. Draco extension.
    if (attKeys.indexOf(threeAttributeName) >= 0) {
      // skip
    } else {
      await assignAttributeAccessor(
          attributes[gltfAttributeName], threeAttributeName);
      pending.add(geometry);
    }
  }

  if (primitiveDef["indices"] != null && geometry.index == null) {
    var accessor =
        await parser.getDependency('accessor', primitiveDef["indices"]);
    geometry.setIndex(accessor);
  }

  assignExtrasToUserData(geometry, primitiveDef);

  computeBounds(geometry, primitiveDef, parser);

  return primitiveDef["targets"] != null
      ? await addMorphTargets(geometry, primitiveDef["targets"], parser)
      : geometry;
};