decodePrimitive method
dynamic
decodePrimitive(
- dynamic primitive,
- dynamic parser
Implementation
decodePrimitive(primitive, parser) async {
var json = this.json;
var dracoLoader = this.dracoLoader;
var bufferViewIndex = primitive["extensions"][name]["bufferView"];
var gltfAttributeMap = primitive["extensions"][name]["attributes"];
var threeAttributeMap = {};
var attributeNormalizedMap = {};
var attributeTypeMap = {};
gltfAttributeMap.forEach((attributeName, value) {
var threeAttributeName = webGlAttributes[attributeName] ?? attributeName.toLowerCase();
threeAttributeMap[threeAttributeName] = gltfAttributeMap[attributeName];
});
primitive["attributes"].forEach((attributeName, value) {
var threeAttributeName = webGlAttributes[attributeName] ?? attributeName.toLowerCase();
if (gltfAttributeMap[attributeName] != null) {
var accessorDef = json["accessors"][primitive["attributes"][attributeName]];
var componentType = webGlComponentTypes[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;
}