readAttachment method
Implementation
Attachment? readAttachment(Map<String, dynamic> map, Skin skin, int slotIndex,
String name, SkeletonData skeletonData) {
final double scale = this.scale;
name = _getString(map, 'name', name);
final String type = _getString(map, 'type', 'region');
switch (type) {
case 'region':
{
final String path = _getString(map, 'path', name);
final RegionAttachment region =
attachmentLoader.newRegionAttachment(skin, name, path)
..path = path
..x = _getDouble(map, 'x', 0.0) * scale
..y = _getDouble(map, 'y', 0.0) * scale
..scaleX = _getDouble(map, 'scaleX', 1.0)
..scaleY = _getDouble(map, 'scaleY', 1.0)
..rotation = _getDouble(map, 'rotation', 0.0)
..width = _getDouble(map, 'width') * scale
..height = _getDouble(map, 'height') * scale;
final String color = _getString(map, 'color');
if (color.isNotEmpty) region.color.setFromString(color);
region.updateOffset();
return region;
}
case 'boundingbox':
{
final BoundingBoxAttachment box =
attachmentLoader.newBoundingBoxAttachment(skin, name);
readVertices(map, box, _getInt(map, 'vertexCount') << 1);
final String color = _getString(map, 'color');
if (color.isNotEmpty) box.color.setFromString(color);
return box;
}
case 'mesh':
case 'linkedmesh':
{
final String path = _getString(map, 'path', name);
final MeshAttachment mesh =
attachmentLoader.newMeshAttachment(skin, name, path)..path = path;
final String color = _getString(map, 'color');
if (color.isNotEmpty) mesh.color.setFromString(color);
final String parent = _getString(map, 'parent');
if (parent.isNotEmpty) {
mesh.inheritDeform = _getBool(map, 'deform', true);
linkedMeshes.add(
LinkedMesh(mesh, _getString(map, 'skin'), slotIndex, parent));
return mesh;
}
final Float32List uvs = _getFloat32List(map, 'uvs')!;
readVertices(map, mesh, uvs.length);
mesh
..triangles = _getInt16List(map, 'triangles')
..regionUVs = uvs
..updateUVs()
..hullLength = _getInt(map, 'hull', 0) * 2;
return mesh;
}
case 'path':
{
final PathAttachment path =
attachmentLoader.newPathAttachment(skin, name)
..closed = _getBool(map, 'closed', false)
..constantSpeed = _getBool(map, 'constantSpeed', true);
final int vertexCount = _getInt(map, 'vertexCount');
readVertices(map, path, vertexCount << 1);
path.lengths = _getFloat32List(map, 'lengths')!
.map((double length) => length * scale) as Float32List;
final String color = _getString(map, 'color');
if (color.isNotEmpty) path.color.setFromString(color);
return path;
}
case 'point':
{
final PointAttachment point =
attachmentLoader.newPointAttachment(skin, name)
..x = _getDouble(map, 'x', 0.0) * scale
..y = _getDouble(map, 'y', 0.0) * scale
..rotation = _getDouble(map, 'rotation', 0.0);
final String color = _getString(map, 'color');
if (color.isNotEmpty) point.color.setFromString(color);
return point;
}
case 'clipping':
{
final ClippingAttachment clip =
attachmentLoader.newClippingAttachment(skin, name);
final String end = _getString(map, 'end');
if (end.isNotEmpty) {
final SlotData? slot = skeletonData.findSlot(end);
if (slot == null) {
throw StateError('Clipping end slot not found: $end');
}
clip.endSlot = slot;
}
final int vertexCount = _getInt(map, 'vertexCount');
readVertices(map, clip, vertexCount << 1);
final String color = _getString(map, 'color');
if (color.isNotEmpty) clip.color.setFromString(color);
return clip;
}
}
return null;
}