public Polygon getPolygon(BoundingBoxAttachment attachment)
        {
            int index = BoundingBoxes.IndexOf(attachment);

            return(index == -1 ? null : Polygons.Items[index]);
        }
Esempio n. 2
0
        private Attachment ReadAttachment(Dictionary <String, Object> map, Skin skin, int slotIndex, String name)
        {
            var scale = this.Scale;

            name = GetString(map, "name", name);

            var typeName = GetString(map, "type", "region");

            if (typeName == "skinnedmesh")
            {
                typeName = "weightedmesh";
            }
            if (typeName == "weightedmesh")
            {
                typeName = "mesh";
            }
            if (typeName == "weightedlinkedmesh")
            {
                typeName = "linkedmesh";
            }
            var type = (AttachmentType)Enum.Parse(typeof(AttachmentType), typeName, true);

            String path = GetString(map, "path", name);

            switch (type)
            {
            case AttachmentType.Region:
                RegionAttachment region = attachmentLoader.NewRegionAttachment(skin, name, path);
                if (region == null)
                {
                    return(null);
                }
                region.Path     = path;
                region.x        = GetFloat(map, "x", 0) * scale;
                region.y        = GetFloat(map, "y", 0) * scale;
                region.scaleX   = GetFloat(map, "scaleX", 1);
                region.scaleY   = GetFloat(map, "scaleY", 1);
                region.rotation = GetFloat(map, "rotation", 0);
                region.width    = GetFloat(map, "width", 32) * scale;
                region.height   = GetFloat(map, "height", 32) * scale;
                region.UpdateOffset();

                if (map.ContainsKey("color"))
                {
                    var color = (String)map["color"];
                    region.r = ToColor(color, 0);
                    region.g = ToColor(color, 1);
                    region.b = ToColor(color, 2);
                    region.a = ToColor(color, 3);
                }

                region.UpdateOffset();
                return(region);

            case AttachmentType.Boundingbox:
                BoundingBoxAttachment box = attachmentLoader.NewBoundingBoxAttachment(skin, name);
                if (box == null)
                {
                    return(null);
                }
                ReadVertices(map, box, GetInt(map, "vertexCount", 0) << 1);
                return(box);

            case AttachmentType.Mesh:
            case AttachmentType.Linkedmesh: {
                MeshAttachment mesh = attachmentLoader.NewMeshAttachment(skin, name, path);
                if (mesh == null)
                {
                    return(null);
                }
                mesh.Path = path;

                if (map.ContainsKey("color"))
                {
                    var color = (String)map["color"];
                    mesh.r = ToColor(color, 0);
                    mesh.g = ToColor(color, 1);
                    mesh.b = ToColor(color, 2);
                    mesh.a = ToColor(color, 3);
                }

                mesh.Width  = GetFloat(map, "width", 0) * scale;
                mesh.Height = GetFloat(map, "height", 0) * scale;

                String parent = GetString(map, "parent", null);
                if (parent != null)
                {
                    mesh.InheritDeform = GetBoolean(map, "deform", true);
                    linkedMeshes.Add(new LinkedMesh(mesh, GetString(map, "skin", null), slotIndex, parent));
                    return(mesh);
                }

                float[] uvs = GetFloatArray(map, "uvs", 1);
                ReadVertices(map, mesh, uvs.Length);
                mesh.triangles = GetIntArray(map, "triangles");
                mesh.regionUVs = uvs;
                mesh.UpdateUVs();

                if (map.ContainsKey("hull"))
                {
                    mesh.HullLength = GetInt(map, "hull", 0) * 2;
                }
                if (map.ContainsKey("edges"))
                {
                    mesh.Edges = GetIntArray(map, "edges");
                }
                return(mesh);
            }

            case AttachmentType.Path: {
                PathAttachment pathAttachment = attachmentLoader.NewPathAttachment(skin, name);
                if (pathAttachment == null)
                {
                    return(null);
                }
                pathAttachment.closed        = GetBoolean(map, "closed", false);
                pathAttachment.constantSpeed = GetBoolean(map, "constantSpeed", true);

                int vertexCount = GetInt(map, "vertexCount", 0);
                ReadVertices(map, pathAttachment, vertexCount << 1);

                // potential BOZO see Java impl
                pathAttachment.lengths = GetFloatArray(map, "lengths", scale);
                return(pathAttachment);
            }
            }
            return(null);
        }