コード例 #1
0
        public Polygon getPolygon(BoundingBoxAttachment attachment)
        {
            int index = BoundingBoxes.IndexOf(attachment);

            return(index == -1 ? null : Polygons[index]);
        }
コード例 #2
0
        private Attachment ReadAttachment(Skin skin, String name, Dictionary <String, Object> map)
        {
            if (map.ContainsKey("name"))
            {
                name = (String)map["name"];
            }

            var type = AttachmentType.region;

            if (map.ContainsKey("type"))
            {
                type = (AttachmentType)Enum.Parse(typeof(AttachmentType), (String)map["type"], false);
            }

            String path = name;

            if (map.ContainsKey("path"))
            {
                path = (String)map["path"];
            }

            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);
                }

                return(region);

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

                mesh.Path      = path;
                mesh.vertices  = GetFloatArray(map, "vertices", Scale);
                mesh.triangles = GetIntArray(map, "triangles");
                mesh.regionUVs = GetFloatArray(map, "uvs", 1);
                mesh.UpdateUVs();

                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.HullLength = GetInt(map, "hull", 0) * 2;
                if (map.ContainsKey("edges"))
                {
                    mesh.Edges = GetIntArray(map, "edges");
                }
                mesh.Width  = GetInt(map, "width", 0) * Scale;
                mesh.Height = GetInt(map, "height", 0) * Scale;

                return(mesh);
            }

            case AttachmentType.skinnedmesh: {
                SkinnedMeshAttachment mesh = attachmentLoader.NewSkinnedMeshAttachment(skin, name, path);
                if (mesh == null)
                {
                    return(null);
                }

                mesh.Path = path;
                float[] uvs      = GetFloatArray(map, "uvs", 1);
                float[] vertices = GetFloatArray(map, "vertices", 1);
                var     weights  = new List <float>(uvs.Length * 3 * 3);
                var     bones    = new List <int>(uvs.Length * 3);
                float   scale    = Scale;
                for (int i = 0, n = vertices.Length; i < n;)
                {
                    int boneCount = (int)vertices[i++];
                    bones.Add(boneCount);
                    for (int nn = i + boneCount * 4; i < nn;)
                    {
                        bones.Add((int)vertices[i]);
                        weights.Add(vertices[i + 1] * scale);
                        weights.Add(vertices[i + 2] * scale);
                        weights.Add(vertices[i + 3]);
                        i += 4;
                    }
                }
                mesh.bones     = bones.ToArray();
                mesh.weights   = weights.ToArray();
                mesh.triangles = GetIntArray(map, "triangles");
                mesh.regionUVs = uvs;
                mesh.UpdateUVs();

                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.HullLength = GetInt(map, "hull", 0) * 2;
                if (map.ContainsKey("edges"))
                {
                    mesh.Edges = GetIntArray(map, "edges");
                }
                mesh.Width  = GetInt(map, "width", 0) * Scale;
                mesh.Height = GetInt(map, "height", 0) * Scale;

                return(mesh);
            }

            case AttachmentType.boundingbox:
                BoundingBoxAttachment box = attachmentLoader.NewBoundingBoxAttachment(skin, name);
                if (box == null)
                {
                    return(null);
                }
                box.vertices = GetFloatArray(map, "vertices", Scale);
                return(box);
            }
            return(null);
        }