MeshGeometry.fromJson constructor
Implementation
factory MeshGeometry.fromJson(Map<String, Object> json) {
Float32List buffer;
final Object jsonBuffer = json["buffer"];
if (jsonBuffer is List<double>) {
buffer = new Float32List.fromList(jsonBuffer);
} else {
throw new ArgumentError.value(
jsonBuffer, 'json["buffer"]', 'Value type must be List<double>');
}
final Object jsonAttribs = json["attribs"];
Map<String, Object> jsonAttribsMap;
if (jsonAttribs is Map<String, Object>) {
jsonAttribsMap = jsonAttribs;
} else {
throw new ArgumentError.value(jsonBuffer, 'json["attribs"]',
'Value type must be Map<String, Object>');
}
List<VertexAttrib> attribs;
int stride = 0;
for (String key in jsonAttribsMap.keys) {
VertexAttrib attrib;
final Object jsonAttrib = jsonAttribsMap[key];
if (jsonAttrib is Map<String, Object>) {
attrib = attribFromJson(key, jsonAttrib);
attribs.add(attrib);
if (stride == 0) {
stride = attrib.stride;
}
}
}
final MeshGeometry mesh = new MeshGeometry._internal(
buffer.lengthInBytes ~/ stride, stride, attribs, buffer);
final Object jsonIndices = json["indices"];
if (jsonIndices is List<int>) {
mesh.indices = new Uint16List.fromList(jsonIndices);
}
return mesh;
}