// this is the attachment loader which will hook into Futile's AtlasManager for the attachment/element data
    public Attachment NewAttachment(Skin skin, AttachmentType type, String name)
    {
        switch(type){
            case AttachmentType.region:

                FAtlasElement element = Futile.atlasManager.GetElementWithName(name);
                RegionAttachment attachment = new RegionAttachment(name);

                if(element != null){
                    attachment.Texture = element;
                    attachment.SetUVs(element.uvBottomLeft.x, element.uvBottomLeft.y, element.uvTopRight.x, element.uvTopRight.y, false);
                    attachment.RegionOffsetX = 0.0f;
                    attachment.RegionOffsetY = 0.0f;
                    attachment.RegionWidth = element.sourceSize.x;
                    attachment.RegionHeight = element.sourceSize.y;
                    attachment.RegionOriginalWidth = element.sourceSize.x;
                    attachment.RegionOriginalHeight = element.sourceSize.y;

                }else{
                    attachment.Texture = null;
                    attachment.SetUVs(0.0f, 0.0f, 0.0f, 0.0f, false);
                    attachment.RegionOffsetX = 0.0f;
                    attachment.RegionOffsetY = 0.0f;
                    attachment.RegionWidth = 0.0f;
                    attachment.RegionHeight = 0.0f;
                    attachment.RegionOriginalWidth = 0.0f;
                    attachment.RegionOriginalHeight = 0.0f;

                    Debug.Log("Element [" + name + "] not found in Futile.AtlasManager");
                }
                return attachment;
        }
        throw new Exception("Unknown attachment type: " + type);
    }
    public Attachment NewAttachment(Skin skin, AttachmentType type, String name)
    {
        if (type != AttachmentType.region)
            throw new Exception("Unknown attachment type: " + type);

        // Strip folder names.
        int index = name.LastIndexOfAny(new char[] {'/', '\\'});
        if (index != -1)
            name = name.Substring(index + 1);

        tk2dSpriteDefinition def = sprites.GetSpriteDefinition(name);

        if (def == null)
            throw new Exception("Sprite not found in atlas: " + name + " (" + type + ")");
        if (def.complexGeometry)
            throw new NotImplementedException("Complex geometry is not supported: " + name + " (" + type + ")");
        if (def.flipped == tk2dSpriteDefinition.FlipMode.TPackerCW)
            throw new NotImplementedException("Only 2D Toolkit atlases are supported: " + name + " (" + type + ")");

        RegionAttachment attachment = new RegionAttachment(name);

        Vector2 minTexCoords = Vector2.one;
        Vector2 maxTexCoords = Vector2.zero;
        for (int i = 0; i < def.uvs.Length; ++i) {
            Vector2 uv = def.uvs[i];
            minTexCoords = Vector2.Min(minTexCoords, uv);
            maxTexCoords = Vector2.Max(maxTexCoords, uv);
        }
        bool rotated = def.flipped == tk2dSpriteDefinition.FlipMode.Tk2d;
        if (rotated) {
            float temp = minTexCoords.x;
            minTexCoords.x = maxTexCoords.x;
            maxTexCoords.x = temp;
        }
        attachment.SetUVs(
            minTexCoords.x,
            maxTexCoords.y,
            maxTexCoords.x,
            minTexCoords.y,
            rotated
        );

        attachment.RegionOriginalWidth = (int)(def.untrimmedBoundsData[1].x / def.texelSize.x);
        attachment.RegionOriginalHeight = (int)(def.untrimmedBoundsData[1].y / def.texelSize.y);

        attachment.RegionWidth = (int)(def.boundsData[1].x / def.texelSize.x);
        attachment.RegionHeight = (int)(def.boundsData[1].y / def.texelSize.y);

        float x0 = def.untrimmedBoundsData[0].x - def.untrimmedBoundsData[1].x / 2;
        float x1 = def.boundsData[0].x - def.boundsData[1].x / 2;
        attachment.RegionOffsetX = (int)((x1 - x0) / def.texelSize.x);

        float y0 = def.untrimmedBoundsData[0].y - def.untrimmedBoundsData[1].y / 2;
        float y1 = def.boundsData[0].y - def.boundsData[1].y / 2;
        attachment.RegionOffsetY = (int)((y1 - y0) / def.texelSize.y);

        attachment.RendererObject = def.material;

        return attachment;
    }
    public RegionAttachment NewRegionAttachment(Skin skin, String name, String path)
    {
        FAtlasElement element = Futile.atlasManager.GetElementWithName(name);
        RegionAttachment attachment = new RegionAttachment(name);

        if(element != null){
            attachment.RendererObject = element;
            attachment.SetUVs(element.uvBottomLeft.x, element.uvBottomLeft.y, element.uvTopRight.x, element.uvTopRight.y, false);
            attachment.RegionOffsetX = 0.0f;
            attachment.RegionOffsetY = 0.0f;
            attachment.RegionWidth = element.sourceSize.x;
            attachment.RegionHeight = element.sourceSize.y;
            attachment.RegionOriginalWidth = element.sourceSize.x;
            attachment.RegionOriginalHeight = element.sourceSize.y;

        }else{
            attachment.RendererObject = null;
            attachment.SetUVs(0.0f, 0.0f, 0.0f, 0.0f, false);
            attachment.RegionOffsetX = 0.0f;
            attachment.RegionOffsetY = 0.0f;
            attachment.RegionWidth = 0.0f;
            attachment.RegionHeight = 0.0f;
            attachment.RegionOriginalWidth = 0.0f;
            attachment.RegionOriginalHeight = 0.0f;

            Debug.Log("Element [" + name + "] not found in Futile.AtlasManager");
        }
        return attachment;
    }
    public Attachment NewAttachment(Skin skin, AttachmentType type, String name)
    {
        if (type != AttachmentType.region) throw new Exception("Unknown attachment type: " + type);

        // Strip folder names.
        int index = name.LastIndexOfAny(new char[] {'/', '\\'});
        if (index != -1) name = name.Substring(index + 1);

        tk2dSpriteDefinition attachmentParameters = null;
        for (int i = 0; i < sprites.inst.spriteDefinitions.Length; ++i) {
            tk2dSpriteDefinition def = sprites.inst.spriteDefinitions[i];
            if (def.name == name) {
                attachmentParameters = def;
                break;
            }
        }

        if (attachmentParameters == null) throw new Exception("Sprite not found in atlas: " + name + " (" + type + ")");
        if (attachmentParameters.complexGeometry) throw new NotImplementedException("Complex geometry is not supported: " + name + " (" + type + ")");
        if (attachmentParameters.flipped == tk2dSpriteDefinition.FlipMode.TPackerCW) throw new NotImplementedException("Only 2D Toolkit atlases are supported: " + name + " (" + type + ")");

        Vector2 minTexCoords = Vector2.one;
        Vector2 maxTexCoords = Vector2.zero;
        for (int i = 0; i < attachmentParameters.uvs.Length; ++i) {
            Vector2 uv = attachmentParameters.uvs[i];
            minTexCoords = Vector2.Min(minTexCoords, uv);
            maxTexCoords = Vector2.Max(maxTexCoords, uv);
        }

        Texture texture = attachmentParameters.material.mainTexture;
        int width = (int)(Mathf.Abs(maxTexCoords.x - minTexCoords.x) * texture.width);
        int height = (int)(Mathf.Abs(maxTexCoords.y - minTexCoords.y) * texture.height);

        bool rotated = (attachmentParameters.flipped == tk2dSpriteDefinition.FlipMode.Tk2d);

        if (rotated) {
            float temp = minTexCoords.x;
            minTexCoords.x = maxTexCoords.x;
            maxTexCoords.x = temp;
        }

        RegionAttachment attachment = new RegionAttachment(name);

        attachment.SetUVs(
            minTexCoords.x,
            maxTexCoords.y,
            maxTexCoords.x,
            minTexCoords.y,
            rotated
        );

        // TODO - Set attachment.RegionOffsetX/Y. What units does attachmentParameters.untrimmedBoundsData use?!
        attachment.RegionWidth = width;
        attachment.RegionHeight = height;
        attachment.RegionOriginalWidth = width;
        attachment.RegionOriginalHeight = height;

        return attachment;
    }
Ejemplo n.º 5
0
        void spRegionAttachment_updateQuad(ref RegionAttachment self, ref Slot slot, CCV3F_C4B_T2F_Quad quad, bool premultipliedAlpha)
        {
            float[] vertices = new float[8];

            self.ComputeWorldVertices(slot.Skeleton.X, slot.Skeleton.Y, slot.Bone, vertices);

            float r = (slot.Skeleton.R * slot.R * 255);
            float g = (slot.Skeleton.G * slot.G * 255);
            float b = (slot.Skeleton.B * slot.B * 255);

            float normalizedAlpha = slot.Skeleton.A * slot.A;
            if (premultipliedAlpha)
            {

                r *= normalizedAlpha;
                g *= normalizedAlpha;
                b *= normalizedAlpha;
            }

            float a = normalizedAlpha * 255;

            quad.BottomLeft.Colors.R = Convert.ToByte(r);
            quad.BottomLeft.Colors.G = Convert.ToByte(g);
            quad.BottomLeft.Colors.B = Convert.ToByte(b);
            quad.BottomLeft.Colors.A = Convert.ToByte(a);
            quad.TopLeft.Colors.R = Convert.ToByte(r);
            quad.TopLeft.Colors.G = Convert.ToByte(g);
            quad.TopLeft.Colors.B = Convert.ToByte(b);
            quad.TopLeft.Colors.A = Convert.ToByte(a);
            quad.TopRight.Colors.R = Convert.ToByte(r);
            quad.TopRight.Colors.G = Convert.ToByte(g);
            quad.TopRight.Colors.B = Convert.ToByte(b);
            quad.TopRight.Colors.A = Convert.ToByte(a);
            quad.BottomRight.Colors.R = Convert.ToByte(r);
            quad.BottomRight.Colors.G = Convert.ToByte(g);
            quad.BottomRight.Colors.B = Convert.ToByte(b);
            quad.BottomRight.Colors.A = Convert.ToByte(a);

            quad.BottomLeft.Vertices.X = vertices[RegionAttachment.X1];
            quad.BottomLeft.Vertices.Y = vertices[RegionAttachment.Y1];
            quad.TopLeft.Vertices.X = vertices[RegionAttachment.X2];
            quad.TopLeft.Vertices.Y = vertices[RegionAttachment.Y2];
            quad.TopRight.Vertices.X = vertices[RegionAttachment.X3];
            quad.TopRight.Vertices.Y = vertices[RegionAttachment.Y3];
            quad.BottomRight.Vertices.X = vertices[RegionAttachment.X4];
            quad.BottomRight.Vertices.Y = vertices[RegionAttachment.Y4];

            quad.BottomLeft.TexCoords.U = self.UVs[RegionAttachment.X1];
            quad.BottomLeft.TexCoords.V = self.UVs[RegionAttachment.Y1];
            quad.TopLeft.TexCoords.U = self.UVs[RegionAttachment.X2];
            quad.TopLeft.TexCoords.V = self.UVs[RegionAttachment.Y2];
            quad.TopRight.TexCoords.U = self.UVs[RegionAttachment.X3];
            quad.TopRight.TexCoords.V = self.UVs[RegionAttachment.Y3];
            quad.BottomRight.TexCoords.U = self.UVs[RegionAttachment.X4];
            quad.BottomRight.TexCoords.V = self.UVs[RegionAttachment.Y4];
        }
Ejemplo n.º 6
0
    // update the attachment with the current slot data
    public void Update(Slot slot)
    {
        _attachment = slot.Attachment as RegionAttachment;
        _attachment.UpdateVertices(slot.Bone);
        element = _attachment.Texture as FAtlasElement;

        base.color = _slotCustomColor * new Color(slot.R, slot.G, slot.B, slot.A);

        UpdateLocalVertices();
    }
    public Attachment NewAttachment(Skin skin,AttachmentType type,String name)
    {
        if(type != AttachmentType.region) throw new Exception("Unknown attachment type: " + type);

        tk2dSpriteDefinition attachmentParameters = null;
        for(int i = 0; i < sprites.spriteDefinitions.Length; ++i) {
            tk2dSpriteDefinition def = sprites.spriteDefinitions[i];
            if(def.name == name) {
                attachmentParameters = def;
                break;
            }
        }

        if(attachmentParameters == null ) throw new Exception("Sprite not found in atlas: " + name + " (" + type + ")");
        if(attachmentParameters.complexGeometry) throw new NotImplementedException("Complex geometry is not supported: " + name + " (" + type + ")");
        if(attachmentParameters.flipped == tk2dSpriteDefinition.FlipMode.TPackerCW) throw new NotImplementedException("Only 2d toolkit atlases are supported: " + name + " (" + type + ")");
        Texture tex = attachmentParameters.material.mainTexture;

        Vector2 minTexCoords = Vector2.one;
        Vector2 maxTexCoords = Vector2.zero;
        for(int i = 0; i < attachmentParameters.uvs.Length; ++i) {
            Vector2 uv = attachmentParameters.uvs[i];
            minTexCoords = Vector2.Min(minTexCoords,uv);
            maxTexCoords = Vector2.Max(maxTexCoords,uv);
        }

        int width = (int)(Mathf.Abs(maxTexCoords.x - minTexCoords.x) * tex.width);
        int height = (int)(Mathf.Abs(maxTexCoords.y - minTexCoords.y) * tex.height);

        bool rotated = (attachmentParameters.flipped == tk2dSpriteDefinition.FlipMode.Tk2d);

        if(rotated) {
            float temp = minTexCoords.x;
            minTexCoords.x = maxTexCoords.x;
            maxTexCoords.x = temp;
        }

        RegionAttachment attachment = new RegionAttachment(name);

        attachment.SetUVs(
            minTexCoords.x,
            maxTexCoords.y,
            maxTexCoords.x,
            minTexCoords.y,
            rotated
        );

        attachment.RegionWidth = width;
        attachment.RegionHeight = height;
        attachment.RegionOriginalWidth = width;
        attachment.RegionOriginalHeight = height;

        return attachment;
    }
Ejemplo n.º 8
0
        void spRegionAttachment_updateQuad(RegionAttachment self, Slot slot, CCV3F_C4B_T2F_Quad quad, bool premultipliedAlpha = false)
        {
            float[] vertices = new float[8];

            self.ComputeWorldVertices(slot.Skeleton.X, slot.Skeleton.Y, slot.Bone, vertices);

            byte r = Convert.ToByte(slot.Skeleton.R * slot.R * 255);
            byte g =Convert.ToByte( slot.Skeleton.G * slot.G * 255);
            byte b = Convert.ToByte(slot.Skeleton.B * slot.B * 255);

            byte normalizedAlpha = Convert.ToByte( slot.Skeleton.A * slot.A);
            if (premultipliedAlpha)
            {
                r *= normalizedAlpha;
                g *= normalizedAlpha;
                b *= normalizedAlpha;
            }

            byte a = Convert.ToByte(normalizedAlpha * 255);
            quad.BottomLeft.Colors.R = r;
            quad.BottomLeft.Colors.G = g;
            quad.BottomLeft.Colors.B = b;
            quad.BottomLeft.Colors.A = a;
            quad.TopLeft.Colors.R = r;
            quad.TopLeft.Colors.G = g;
            quad.TopLeft.Colors.B = b;
            quad.TopLeft.Colors.A = a;
            quad.TopRight.Colors.R = r;
            quad.TopRight.Colors.G = g;
            quad.TopRight.Colors.B = b;
            quad.TopRight.Colors.A = a;
            quad.BottomRight.Colors.R = r;
            quad.BottomRight.Colors.G = g;
            quad.BottomRight.Colors.B = b;
            quad.BottomRight.Colors.A = a;

            quad.BottomLeft.Vertices.X = vertices[VERTEX_X1];
            quad.BottomLeft.Vertices.Y = vertices[VERTEX_Y1];
            quad.TopLeft.Vertices.X = vertices[VERTEX_X2];
            quad.TopLeft.Vertices.Y = vertices[VERTEX_Y2];
            quad.TopRight.Vertices.X = vertices[VERTEX_X3];
            quad.TopRight.Vertices.Y = vertices[VERTEX_Y3];
            quad.BottomRight.Vertices.X = vertices[VERTEX_X4];
            quad.BottomRight.Vertices.Y = vertices[VERTEX_Y4];

            quad.BottomLeft.TexCoords.U = self.UVs[VERTEX_X1];
            quad.BottomLeft.TexCoords.V = self.UVs[VERTEX_Y1];
            quad.TopLeft.TexCoords.U = self.UVs[VERTEX_X2];
            quad.TopLeft.TexCoords.V = self.UVs[VERTEX_Y2];
            quad.TopRight.TexCoords.U = self.UVs[VERTEX_X3];
            quad.TopRight.TexCoords.V = self.UVs[VERTEX_Y3];
            quad.BottomRight.TexCoords.U = self.UVs[VERTEX_X4];
            quad.BottomRight.TexCoords.V = self.UVs[VERTEX_Y4];
        }
Ejemplo n.º 9
0
 public Attachment NewAttachment(AttachmentType type, String name)
 {
     switch (type) {
     case AttachmentType.region:
         AtlasRegion region = atlas.FindRegion(name);
         if (region == null) throw new Exception("Region not found in atlas: " + name + " (" + type + ")");
         RegionAttachment attachment = new RegionAttachment(name);
         attachment.Region = region;
         return attachment;
     }
     throw new Exception("Unknown attachment type: " + type);
 }
Ejemplo n.º 10
0
		private void DrawSlot(Skeleton skeleton, RegionAttachment attachment, Slot slot)
		{
			var region = (AtlasRegion)attachment.RendererObject;
			var thisMaterial = (Material)region.page.rendererObject;
			var thisBlendMode = slot.Data.AdditiveBlending ? BlendMode.Additive : BlendMode.Normal;
			var thisBatch = (Batch2D)renderer.FindOrCreateBatch(thisMaterial, thisBlendMode);
			if (currentBatch != null && currentBatch != thisBatch)
				renderer.FlushDrawBuffer(currentBatch);
			currentBatch = thisBatch;
			attachment.ComputeWorldVertices(skeleton.X, skeleton.Y, slot.Bone, vertices);
			currentColor = new Color(color.RedValue * slot.R, color.GreenValue * slot.G,
				color.BlueValue * slot.B, color.AlphaValue * slot.A);
			AddSlotIndicesAndVertices(attachment.UVs);
		}
		public RegionAttachment NewRegionAttachment (Skin skin, String name, String path) {
			AtlasRegion region = atlas.FindRegion(path);
			if (region == null) throw new Exception("Region not found in atlas: " + path + " (region attachment: " + name + ")");
			RegionAttachment attachment = new RegionAttachment(name);
			attachment.RendererObject = region;
			attachment.SetUVs(region.u, region.v, region.u2, region.v2, region.rotate);
			attachment.regionOffsetX = region.offsetX;
			attachment.regionOffsetY = region.offsetY;
			attachment.regionWidth = region.width;
			attachment.regionHeight = region.height;
			attachment.regionOriginalWidth = region.originalWidth;
			attachment.regionOriginalHeight = region.originalHeight;
			return attachment;
		}
Ejemplo n.º 12
0
		public void Attach () {
			var skeletonRenderer = GetComponent<SkeletonRenderer>();

			if (loader == null)
				//create loader instance, tell it what sprite and shader to use
				loader = new SpriteAttachmentLoader(sprite, Shader.Find("Spine/Skeleton"));

			if (attachment == null)
				attachment = loader.NewRegionAttachment(null, sprite.name, "");

			skeletonRenderer.skeleton.FindSlot(slot).Attachment = attachment;

			if (!keepLoaderInMemory)
				loader = null;
		}
    // update the attachment with the current slot data
    public void Update(Slot slot)
    {
        _attachment = slot.Attachment as RegionAttachment;

        //_attachment.UpdateOffset();
        //_attachment.UpdateVertices(slot.Bone);

        _attachment.ComputeWorldVertices(slot.Bone, vertices);

        element = _attachment.RendererObject as FAtlasElement;
        element = null;

        base.color = _slotCustomColor * new Color(slot.R, slot.G, slot.B, slot.A);

        UpdateLocalVertices();
    }
 public Attachment NewAttachment(Skin skin, AttachmentType type, String name)
 {
     switch (type) {
     case AttachmentType.region:
         AtlasRegion region = atlas.FindRegion(name);
         if (region == null) throw new Exception("Region not found in atlas: " + name + " (" + type + ")");
         RegionAttachment attachment = new RegionAttachment(name);
         attachment.RendererObject = region.page.rendererObject;
         attachment.SetUVs(region.u, region.v, region.u2, region.v2, region.rotate);
         attachment.RegionOffsetX = region.offsetX;
         attachment.RegionOffsetY = region.offsetY;
         attachment.RegionWidth = region.width;
         attachment.RegionHeight = region.height;
         attachment.RegionOriginalWidth = region.originalWidth;
         attachment.RegionOriginalHeight = region.originalHeight;
         return attachment;
     }
     throw new Exception("Unknown attachment type: " + type);
 }
Ejemplo n.º 15
0
        /// <summary>
        /// Creates the region attachment by texture.
        /// </summary>
        /// <returns>The region attachment by texture.</returns>
        /// <param name="slot">Slot.</param>
        /// <param name="texture">Texture.</param>
        private Attachment CreateRegionAttachmentByTexture(Spine.Slot slot, Texture2D texture)
        {
            if (slot == null)
            {
                return(null);
            }

            Spine.RegionAttachment oldAtt = slot.Attachment as Spine.RegionAttachment;
            if (oldAtt == null || texture == null)
            {
                return(null);
            }

            Spine.RegionAttachment att = new Spine.RegionAttachment(oldAtt.Name);
            att.RendererObject = CreateRegion(texture);
            att.Width          = oldAtt.Width;
            att.Height         = oldAtt.Height;
            att.offset         = oldAtt.offset;
            att.Path           = oldAtt.Path;

            att.R = oldAtt.R;
            att.G = oldAtt.G;
            att.B = oldAtt.B;
            att.A = oldAtt.A;

            att.X        = oldAtt.X;
            att.y        = oldAtt.Y;
            att.Rotation = oldAtt.Rotation;
            att.ScaleX   = oldAtt.ScaleX;
            att.ScaleY   = oldAtt.ScaleY;

            att.SetUVs(0f, 1f, 1f, 0f, false);

            Material mat = new Material(Shader.Find("Sprites/Default"));

            mat.mainTexture = texture;
            (att.RendererObject as Spine.AtlasRegion).page.rendererObject = mat;

            slot.Attachment = att;

            return(slot.Attachment);
        }
Ejemplo n.º 16
0
		public void Attach () {
			var skeletonComponent = GetComponent<ISkeletonComponent>();

			var skeletonRenderer = skeletonComponent as SkeletonRenderer;
			if (skeletonRenderer != null)
				this.applyPMA = skeletonRenderer.pmaVertexColors;
			else {
				var skeletonGraphic = skeletonComponent as SkeletonGraphic;
				if (skeletonGraphic != null)
					this.applyPMA = skeletonGraphic.SpineMeshGenerator.PremultiplyVertexColors;
			}

			Shader attachmentShader = applyPMA ? Shader.Find(DefaultPMAShader) : Shader.Find(DefaultStraightAlphaShader);

			loader = loader ?? new SpriteAttachmentLoader(sprite, attachmentShader, applyPMA);

			if (attachment == null)
				attachment = loader.NewRegionAttachment(null, sprite.name, "");

			skeletonComponent.Skeleton.FindSlot(slot).Attachment = attachment;

			if (!keepLoaderInMemory)
				loader = null;
		}
Ejemplo n.º 17
0
        private Attachment ReadAttachment(Stream input, Skin skin, int slotIndex, string attachmentName, bool nonessential)
        {
            float  scale = this.Scale;
            string text  = this.ReadString(input);

            if (text == null)
            {
                text = attachmentName;
            }
            switch (input.ReadByte())
            {
            case 0:
            {
                string text2    = this.ReadString(input);
                float  rotation = this.ReadFloat(input);
                float  num      = this.ReadFloat(input);
                float  num2     = this.ReadFloat(input);
                float  scaleX   = this.ReadFloat(input);
                float  scaleY   = this.ReadFloat(input);
                float  num3     = this.ReadFloat(input);
                float  num4     = this.ReadFloat(input);
                int    num5     = SkeletonBinary.ReadInt(input);
                if (text2 == null)
                {
                    text2 = text;
                }
                RegionAttachment regionAttachment = this.attachmentLoader.NewRegionAttachment(skin, text, text2);
                if (regionAttachment == null)
                {
                    return(null);
                }
                regionAttachment.Path     = text2;
                regionAttachment.x        = num * scale;
                regionAttachment.y        = num2 * scale;
                regionAttachment.scaleX   = scaleX;
                regionAttachment.scaleY   = scaleY;
                regionAttachment.rotation = rotation;
                regionAttachment.width    = num3 * scale;
                regionAttachment.height   = num4 * scale;
                regionAttachment.r        = (float)((num5 & 4278190080u) >> 24) / 255f;
                regionAttachment.g        = (float)((num5 & 16711680) >> 16) / 255f;
                regionAttachment.b        = (float)((num5 & 65280) >> 8) / 255f;
                regionAttachment.a        = (float)(num5 & 255) / 255f;
                regionAttachment.UpdateOffset();
                return(regionAttachment);
            }

            case 1:
            {
                int      num6     = SkeletonBinary.ReadVarint(input, true);
                Vertices vertices = this.ReadVertices(input, num6);
                if (nonessential)
                {
                    SkeletonBinary.ReadInt(input);
                }
                BoundingBoxAttachment boundingBoxAttachment = this.attachmentLoader.NewBoundingBoxAttachment(skin, text);
                if (boundingBoxAttachment == null)
                {
                    return(null);
                }
                boundingBoxAttachment.worldVerticesLength = num6 << 1;
                boundingBoxAttachment.vertices            = vertices.vertices;
                boundingBoxAttachment.bones = vertices.bones;
                return(boundingBoxAttachment);
            }

            case 2:
            {
                string   text3     = this.ReadString(input);
                int      num7      = SkeletonBinary.ReadInt(input);
                int      num8      = SkeletonBinary.ReadVarint(input, true);
                float[]  regionUVs = this.ReadFloatArray(input, num8 << 1, 1f);
                int[]    triangles = this.ReadShortArray(input);
                Vertices vertices2 = this.ReadVertices(input, num8);
                int      num9      = SkeletonBinary.ReadVarint(input, true);
                int[]    edges     = null;
                float    num10     = 0f;
                float    num11     = 0f;
                if (nonessential)
                {
                    edges = this.ReadShortArray(input);
                    num10 = this.ReadFloat(input);
                    num11 = this.ReadFloat(input);
                }
                if (text3 == null)
                {
                    text3 = text;
                }
                MeshAttachment meshAttachment = this.attachmentLoader.NewMeshAttachment(skin, text, text3);
                if (meshAttachment == null)
                {
                    return(null);
                }
                meshAttachment.Path                = text3;
                meshAttachment.r                   = (float)((num7 & 4278190080u) >> 24) / 255f;
                meshAttachment.g                   = (float)((num7 & 16711680) >> 16) / 255f;
                meshAttachment.b                   = (float)((num7 & 65280) >> 8) / 255f;
                meshAttachment.a                   = (float)(num7 & 255) / 255f;
                meshAttachment.bones               = vertices2.bones;
                meshAttachment.vertices            = vertices2.vertices;
                meshAttachment.WorldVerticesLength = num8 << 1;
                meshAttachment.triangles           = triangles;
                meshAttachment.regionUVs           = regionUVs;
                meshAttachment.UpdateUVs();
                meshAttachment.HullLength = num9 << 1;
                if (nonessential)
                {
                    meshAttachment.Edges  = edges;
                    meshAttachment.Width  = num10 * scale;
                    meshAttachment.Height = num11 * scale;
                }
                return(meshAttachment);
            }

            case 3:
            {
                string text4         = this.ReadString(input);
                int    num12         = SkeletonBinary.ReadInt(input);
                string skin2         = this.ReadString(input);
                string parent        = this.ReadString(input);
                bool   inheritDeform = SkeletonBinary.ReadBoolean(input);
                float  num13         = 0f;
                float  num14         = 0f;
                if (nonessential)
                {
                    num13 = this.ReadFloat(input);
                    num14 = this.ReadFloat(input);
                }
                if (text4 == null)
                {
                    text4 = text;
                }
                MeshAttachment meshAttachment2 = this.attachmentLoader.NewMeshAttachment(skin, text, text4);
                if (meshAttachment2 == null)
                {
                    return(null);
                }
                meshAttachment2.Path          = text4;
                meshAttachment2.r             = (float)((num12 & 4278190080u) >> 24) / 255f;
                meshAttachment2.g             = (float)((num12 & 16711680) >> 16) / 255f;
                meshAttachment2.b             = (float)((num12 & 65280) >> 8) / 255f;
                meshAttachment2.a             = (float)(num12 & 255) / 255f;
                meshAttachment2.inheritDeform = inheritDeform;
                if (nonessential)
                {
                    meshAttachment2.Width  = num13 * scale;
                    meshAttachment2.Height = num14 * scale;
                }
                this.linkedMeshes.Add(new SkeletonJson.LinkedMesh(meshAttachment2, skin2, slotIndex, parent));
                return(meshAttachment2);
            }

            case 4:
            {
                bool     closed        = SkeletonBinary.ReadBoolean(input);
                bool     constantSpeed = SkeletonBinary.ReadBoolean(input);
                int      num15         = SkeletonBinary.ReadVarint(input, true);
                Vertices vertices3     = this.ReadVertices(input, num15);
                float[]  array         = new float[num15 / 3];
                int      i             = 0;
                int      num16         = array.Length;
                while (i < num16)
                {
                    array[i] = this.ReadFloat(input) * scale;
                    i++;
                }
                if (nonessential)
                {
                    SkeletonBinary.ReadInt(input);
                }
                PathAttachment pathAttachment = this.attachmentLoader.NewPathAttachment(skin, text);
                if (pathAttachment == null)
                {
                    return(null);
                }
                pathAttachment.closed              = closed;
                pathAttachment.constantSpeed       = constantSpeed;
                pathAttachment.worldVerticesLength = num15 << 1;
                pathAttachment.vertices            = vertices3.vertices;
                pathAttachment.bones   = vertices3.bones;
                pathAttachment.lengths = array;
                return(pathAttachment);
            }

            default:
                return(null);
            }
        }
Ejemplo n.º 18
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);
        }
Ejemplo n.º 19
0
        public void Draw(Skeleton skeleton)
        {
            List <Slot> drawOrder = skeleton.DrawOrder;
            float       x = skeleton.X, y = skeleton.Y;
            float       skeletonR = skeleton.R, skeletonG = skeleton.G, skeletonB = skeleton.B, skeletonA = skeleton.A;

            for (int i = 0, n = drawOrder.Count; i < n; i++)
            {
                Slot             slot             = drawOrder[i];
                RegionAttachment regionAttachment = slot.Attachment as RegionAttachment;
                if (regionAttachment != null)
                {
                    BlendState blend = slot.Data.AdditiveBlending ? BlendState.Additive : defaultBlendState;
                    if (device.BlendState != blend)
                    {
                        End();
                        device.BlendState = blend;
                    }

                    SpriteBatchItem item   = batcher.CreateBatchItem();
                    AtlasRegion     region = (AtlasRegion)regionAttachment.RendererObject;
                    item.Texture = (Texture2D)region.page.rendererObject;

                    Color color;
                    float a = skeletonA * slot.A;
                    if (premultipliedAlpha)
                    {
                        color = new Color(skeletonR * slot.R * a, skeletonG * slot.G * a, skeletonB * slot.B * a, a);
                    }
                    else
                    {
                        color = new Color(skeletonR * slot.R, skeletonG * slot.G, skeletonB * slot.B, a);
                    }
                    item.vertexTL.Color = color;
                    item.vertexBL.Color = color;
                    item.vertexBR.Color = color;
                    item.vertexTR.Color = color;

                    float[] vertices = this.vertices;
                    regionAttachment.ComputeWorldVertices(x, y, slot.Bone, vertices);
                    item.vertexTL.Position.X = vertices[RegionAttachment.X1];
                    item.vertexTL.Position.Y = vertices[RegionAttachment.Y1];
                    item.vertexTL.Position.Z = 0;
                    item.vertexBL.Position.X = vertices[RegionAttachment.X2];
                    item.vertexBL.Position.Y = vertices[RegionAttachment.Y2];
                    item.vertexBL.Position.Z = 0;
                    item.vertexBR.Position.X = vertices[RegionAttachment.X3];
                    item.vertexBR.Position.Y = vertices[RegionAttachment.Y3];
                    item.vertexBR.Position.Z = 0;
                    item.vertexTR.Position.X = vertices[RegionAttachment.X4];
                    item.vertexTR.Position.Y = vertices[RegionAttachment.Y4];
                    item.vertexTR.Position.Z = 0;

                    float[] uvs = regionAttachment.UVs;
                    item.vertexTL.TextureCoordinate.X = uvs[RegionAttachment.X1];
                    item.vertexTL.TextureCoordinate.Y = uvs[RegionAttachment.Y1];
                    item.vertexBL.TextureCoordinate.X = uvs[RegionAttachment.X2];
                    item.vertexBL.TextureCoordinate.Y = uvs[RegionAttachment.Y2];
                    item.vertexBR.TextureCoordinate.X = uvs[RegionAttachment.X3];
                    item.vertexBR.TextureCoordinate.Y = uvs[RegionAttachment.Y3];
                    item.vertexTR.TextureCoordinate.X = uvs[RegionAttachment.X4];
                    item.vertexTR.TextureCoordinate.Y = uvs[RegionAttachment.Y4];
                }
            }
        }
Ejemplo n.º 20
0
        //virtual cocos2d::CCTextureAtlas* getTextureAtlas (RegionAttachment regionAttachment);
        #region SpinesCocos2d

        void UpdateRegionAttachmentQuad(RegionAttachment self, Slot slot, ref CCV3F_C4B_T2F_Quad quad, bool premultipliedAlpha = false)
        {

            float[] vertices = new float[8];

            self.ComputeWorldVertices(slot.Skeleton.X, slot.Skeleton.Y, slot.Bone, vertices);

            float r = slot.Skeleton.R * slot.R * 255;
            float g = slot.Skeleton.G * slot.G * 255;
            float b = slot.Skeleton.B * slot.B * 255;

            float normalizedAlpha = slot.Skeleton.A * slot.A;
            if (premultipliedAlpha)
            {
                r *= normalizedAlpha;
                g *= normalizedAlpha;
                b *= normalizedAlpha;
            }

            float a = normalizedAlpha * 255;
            quad.BottomLeft.Colors.R = (byte)r;
            quad.BottomLeft.Colors.G = (byte)g;
            quad.BottomLeft.Colors.B = (byte)b;
            quad.BottomLeft.Colors.A = (byte)a;
            quad.TopLeft.Colors.R = (byte)r;
            quad.TopLeft.Colors.G = (byte)g;
            quad.TopLeft.Colors.B = (byte)b;
            quad.TopLeft.Colors.A = (byte)a;
            quad.TopRight.Colors.R = (byte)r;
            quad.TopRight.Colors.G = (byte)g;
            quad.TopRight.Colors.B = (byte)b;
            quad.TopRight.Colors.A = (byte)a;
            quad.BottomRight.Colors.R = (byte)r;
            quad.BottomRight.Colors.G = (byte)g;
            quad.BottomRight.Colors.B = (byte)b;
            quad.BottomRight.Colors.A = (byte)a;

            quad.BottomLeft.Vertices.X = vertices[RegionAttachment.X1];
            quad.BottomLeft.Vertices.Y = vertices[RegionAttachment.Y1];
            quad.TopLeft.Vertices.X = vertices[RegionAttachment.X2];
            quad.TopLeft.Vertices.Y = vertices[RegionAttachment.Y2];
            quad.TopRight.Vertices.X = vertices[RegionAttachment.X3];
            quad.TopRight.Vertices.Y = vertices[RegionAttachment.Y3];
            quad.BottomRight.Vertices.X = vertices[RegionAttachment.X4];
            quad.BottomRight.Vertices.Y = vertices[RegionAttachment.Y4];

            quad.BottomLeft.TexCoords.U = self.UVs[RegionAttachment.X1];
            quad.BottomLeft.TexCoords.V = self.UVs[RegionAttachment.Y1];
            quad.TopLeft.TexCoords.U = self.UVs[RegionAttachment.X2];
            quad.TopLeft.TexCoords.V = self.UVs[RegionAttachment.Y2];
            quad.TopRight.TexCoords.U = self.UVs[RegionAttachment.X3];
            quad.TopRight.TexCoords.V = self.UVs[RegionAttachment.Y3];
            quad.BottomRight.TexCoords.U = self.UVs[RegionAttachment.X4];
            quad.BottomRight.TexCoords.V = self.UVs[RegionAttachment.Y4];

        }
        public void Draw(Skeleton skeleton)
        {
            float[]     vertices = this.vertices;
            List <Slot> drawOrder = skeleton.DrawOrder;
            float       skeletonR = skeleton.R, skeletonG = skeleton.G, skeletonB = skeleton.B, skeletonA = skeleton.A;

            for (int i = 0, n = drawOrder.Count; i < n; i++)
            {
                Slot       slot       = drawOrder[i];
                Attachment attachment = slot.Attachment;
                if (attachment is RegionAttachment)
                {
                    RegionAttachment regionAttachment = (RegionAttachment)attachment;
                    BlendState       blend            = slot.Data.AdditiveBlending ? BlendState.Additive : defaultBlendState;
                    if (device.BlendState != blend)
                    {
                        End();
                        device.BlendState = blend;
                    }

                    MeshItem item = batcher.NextItem(4, 6);
                    item.triangles = quadTriangles;
                    VertexPositionColorTexture[] itemVertices = item.vertices;

                    AtlasRegion region = (AtlasRegion)regionAttachment.RendererObject;
                    item.texture = (Texture2D)region.page.rendererObject;

                    Color color;
                    float a = skeletonA * slot.A * regionAttachment.A;
                    if (premultipliedAlpha)
                    {
                        color = new Color(
                            skeletonR * slot.R * regionAttachment.R * a,
                            skeletonG * slot.G * regionAttachment.G * a,
                            skeletonB * slot.B * regionAttachment.B * a, a);
                    }
                    else
                    {
                        color = new Color(
                            skeletonR * slot.R * regionAttachment.R,
                            skeletonG * slot.G * regionAttachment.G,
                            skeletonB * slot.B * regionAttachment.B, a);
                    }
                    itemVertices[TL].Color = color;
                    itemVertices[BL].Color = color;
                    itemVertices[BR].Color = color;
                    itemVertices[TR].Color = color;

                    regionAttachment.ComputeWorldVertices(slot.Bone, vertices);
                    itemVertices[TL].Position.X = vertices[RegionAttachment.X1];
                    itemVertices[TL].Position.Y = vertices[RegionAttachment.Y1];
                    itemVertices[TL].Position.Z = 0;
                    itemVertices[BL].Position.X = vertices[RegionAttachment.X2];
                    itemVertices[BL].Position.Y = vertices[RegionAttachment.Y2];
                    itemVertices[BL].Position.Z = 0;
                    itemVertices[BR].Position.X = vertices[RegionAttachment.X3];
                    itemVertices[BR].Position.Y = vertices[RegionAttachment.Y3];
                    itemVertices[BR].Position.Z = 0;
                    itemVertices[TR].Position.X = vertices[RegionAttachment.X4];
                    itemVertices[TR].Position.Y = vertices[RegionAttachment.Y4];
                    itemVertices[TR].Position.Z = 0;

                    float[] uvs = regionAttachment.UVs;
                    itemVertices[TL].TextureCoordinate.X = uvs[RegionAttachment.X1];
                    itemVertices[TL].TextureCoordinate.Y = uvs[RegionAttachment.Y1];
                    itemVertices[BL].TextureCoordinate.X = uvs[RegionAttachment.X2];
                    itemVertices[BL].TextureCoordinate.Y = uvs[RegionAttachment.Y2];
                    itemVertices[BR].TextureCoordinate.X = uvs[RegionAttachment.X3];
                    itemVertices[BR].TextureCoordinate.Y = uvs[RegionAttachment.Y3];
                    itemVertices[TR].TextureCoordinate.X = uvs[RegionAttachment.X4];
                    itemVertices[TR].TextureCoordinate.Y = uvs[RegionAttachment.Y4];
                }
                else if (attachment is MeshAttachment)
                {
                    MeshAttachment mesh        = (MeshAttachment)attachment;
                    int            vertexCount = mesh.Vertices.Length;
                    if (vertices.Length < vertexCount)
                    {
                        vertices = new float[vertexCount];
                    }
                    mesh.ComputeWorldVertices(slot, vertices);

                    int[]    triangles = mesh.Triangles;
                    MeshItem item      = batcher.NextItem(vertexCount, triangles.Length);
                    item.triangles = triangles;

                    AtlasRegion region = (AtlasRegion)mesh.RendererObject;
                    item.texture = (Texture2D)region.page.rendererObject;

                    Color color;
                    float a = skeletonA * slot.A * mesh.A;
                    if (premultipliedAlpha)
                    {
                        color = new Color(
                            skeletonR * slot.R * mesh.R * a,
                            skeletonG * slot.G * mesh.G * a,
                            skeletonB * slot.B * mesh.B * a, a);
                    }
                    else
                    {
                        color = new Color(
                            skeletonR * slot.R * mesh.R,
                            skeletonG * slot.G * mesh.G,
                            skeletonB * slot.B * mesh.B, a);
                    }

                    float[] uvs = mesh.UVs;
                    VertexPositionColorTexture[] itemVertices = item.vertices;
                    for (int ii = 0, v = 0; v < vertexCount; ii++, v += 2)
                    {
                        itemVertices[ii].Color               = color;
                        itemVertices[ii].Position.X          = vertices[v];
                        itemVertices[ii].Position.Y          = vertices[v + 1];
                        itemVertices[ii].Position.Z          = 0;
                        itemVertices[ii].TextureCoordinate.X = uvs[v];
                        itemVertices[ii].TextureCoordinate.Y = uvs[v + 1];
                    }
                }
                else if (attachment is SkinnedMeshAttachment)
                {
                    SkinnedMeshAttachment mesh = (SkinnedMeshAttachment)attachment;
                    int vertexCount            = mesh.UVs.Length;
                    if (vertices.Length < vertexCount)
                    {
                        vertices = new float[vertexCount];
                    }
                    mesh.ComputeWorldVertices(slot, vertices);

                    int[]    triangles = mesh.Triangles;
                    MeshItem item      = batcher.NextItem(vertexCount, triangles.Length);
                    item.triangles = triangles;

                    AtlasRegion region = (AtlasRegion)mesh.RendererObject;
                    item.texture = (Texture2D)region.page.rendererObject;

                    Color color;
                    float a = skeletonA * slot.A * mesh.A;
                    if (premultipliedAlpha)
                    {
                        color = new Color(
                            skeletonR * slot.R * mesh.R * a,
                            skeletonG * slot.G * mesh.G * a,
                            skeletonB * slot.B * mesh.B * a, a);
                    }
                    else
                    {
                        color = new Color(
                            skeletonR * slot.R * mesh.R,
                            skeletonG * slot.G * mesh.G,
                            skeletonB * slot.B * mesh.B, a);
                    }

                    float[] uvs = mesh.UVs;
                    VertexPositionColorTexture[] itemVertices = item.vertices;
                    for (int ii = 0, v = 0; v < vertexCount; ii++, v += 2)
                    {
                        itemVertices[ii].Color               = color;
                        itemVertices[ii].Position.X          = vertices[v];
                        itemVertices[ii].Position.Y          = vertices[v + 1];
                        itemVertices[ii].Position.Z          = 0;
                        itemVertices[ii].TextureCoordinate.X = uvs[v];
                        itemVertices[ii].TextureCoordinate.Y = uvs[v + 1];
                    }
                }
            }
        }
Ejemplo n.º 22
0
        private Attachment ReadAttachment(Stream input, Skin skin, int slotIndex, String attachmentName, bool nonessential)
        {
            float scale = Scale;

            String name = ReadString(input);

            if (name == null)
            {
                name = attachmentName;
            }

            AttachmentType type = (AttachmentType)input.ReadByte();

            switch (type)
            {
            case AttachmentType.region: {
                String path     = ReadString(input);
                float  x        = ReadFloat(input);
                float  y        = ReadFloat(input);
                float  scaleX   = ReadFloat(input);
                float  scaleY   = ReadFloat(input);
                float  rotation = ReadFloat(input);
                float  width    = ReadFloat(input);
                float  height   = ReadFloat(input);
                int    color    = ReadInt(input);

                if (path == null)
                {
                    path = name;
                }
                RegionAttachment region = attachmentLoader.NewRegionAttachment(skin, name, path);
                if (region == null)
                {
                    return(null);
                }
                region.Path     = path;
                region.x        = x * scale;
                region.y        = y * scale;
                region.scaleX   = scaleX;
                region.scaleY   = scaleY;
                region.rotation = rotation;
                region.width    = width * scale;
                region.height   = height * scale;
                region.r        = ((color & 0xff000000) >> 24) / 255f;
                region.g        = ((color & 0x00ff0000) >> 16) / 255f;
                region.b        = ((color & 0x0000ff00) >> 8) / 255f;
                region.a        = ((color & 0x000000ff)) / 255f;
                region.UpdateOffset();
                return(region);
            }

            case AttachmentType.boundingbox: {
                float[] vertices          = ReadFloatArray(input, ReadVarint(input, true) * 2, scale);
                BoundingBoxAttachment box = attachmentLoader.NewBoundingBoxAttachment(skin, name);
                if (box == null)
                {
                    return(null);
                }
                box.vertices = vertices;
                return(box);
            }

            case AttachmentType.mesh: {
                String  path           = ReadString(input);
                int     color          = ReadInt(input);
                int     hullLength     = 0;
                int     verticesLength = ReadVarint(input, true) * 2;
                float[] uvs            = ReadFloatArray(input, verticesLength, 1);
                int[]   triangles      = ReadShortArray(input);
                float[] vertices       = ReadFloatArray(input, verticesLength, scale);
                hullLength = ReadVarint(input, true);
                int[] edges = null;
                float width = 0, height = 0;
                if (nonessential)
                {
                    edges  = ReadShortArray(input);
                    width  = ReadFloat(input);
                    height = ReadFloat(input);
                }

                if (path == null)
                {
                    path = name;
                }
                MeshAttachment mesh = attachmentLoader.NewMeshAttachment(skin, name, path);
                if (mesh == null)
                {
                    return(null);
                }
                mesh.Path      = path;
                mesh.r         = ((color & 0xff000000) >> 24) / 255f;
                mesh.g         = ((color & 0x00ff0000) >> 16) / 255f;
                mesh.b         = ((color & 0x0000ff00) >> 8) / 255f;
                mesh.a         = ((color & 0x000000ff)) / 255f;
                mesh.vertices  = vertices;
                mesh.triangles = triangles;
                mesh.regionUVs = uvs;
                mesh.UpdateUVs();
                mesh.HullLength = hullLength;
                if (nonessential)
                {
                    mesh.Edges  = edges;
                    mesh.Width  = width * scale;
                    mesh.Height = height * scale;
                }
                return(mesh);
            }

            case AttachmentType.linkedmesh: {
                String path = ReadString(input);
                int    color = ReadInt(input);
                String skinName = ReadString(input);
                String parent = ReadString(input);
                bool   inheritFFD = ReadBoolean(input);
                float  width = 0, height = 0;
                if (nonessential)
                {
                    width  = ReadFloat(input);
                    height = ReadFloat(input);
                }

                if (path == null)
                {
                    path = name;
                }
                MeshAttachment mesh = attachmentLoader.NewMeshAttachment(skin, name, path);
                if (mesh == null)
                {
                    return(null);
                }
                mesh.Path       = path;
                mesh.r          = ((color & 0xff000000) >> 24) / 255f;
                mesh.g          = ((color & 0x00ff0000) >> 16) / 255f;
                mesh.b          = ((color & 0x0000ff00) >> 8) / 255f;
                mesh.a          = ((color & 0x000000ff)) / 255f;
                mesh.inheritFFD = inheritFFD;
                if (nonessential)
                {
                    mesh.Width  = width * scale;
                    mesh.Height = height * scale;
                }
                linkedMeshes.Add(new SkeletonJson.LinkedMesh(mesh, skinName, slotIndex, parent));
                return(mesh);
            }

            case AttachmentType.weightedmesh: {
                String  path        = ReadString(input);
                int     color       = ReadInt(input);
                int     vertexCount = ReadVarint(input, true);
                float[] uvs         = ReadFloatArray(input, vertexCount * 2, 1);
                int[]   triangles   = ReadShortArray(input);
                var     weights     = new List <float>(uvs.Length * 3 * 3);
                var     bones       = new List <int>(uvs.Length * 3);
                for (int i = 0; i < vertexCount; i++)
                {
                    int boneCount = (int)ReadFloat(input);
                    bones.Add(boneCount);
                    for (int ii = 0; ii < boneCount; ii++)
                    {
                        bones.Add((int)ReadFloat(input));
                        weights.Add(ReadFloat(input) * scale);
                        weights.Add(ReadFloat(input) * scale);
                        weights.Add(ReadFloat(input));
                    }
                }
                int   hullLength = ReadVarint(input, true);
                int[] edges = null;
                float width = 0, height = 0;
                if (nonessential)
                {
                    edges  = ReadShortArray(input);
                    width  = ReadFloat(input);
                    height = ReadFloat(input);
                }

                if (path == null)
                {
                    path = name;
                }
                WeightedMeshAttachment mesh = attachmentLoader.NewWeightedMeshAttachment(skin, name, path);
                if (mesh == null)
                {
                    return(null);
                }
                mesh.Path      = path;
                mesh.r         = ((color & 0xff000000) >> 24) / 255f;
                mesh.g         = ((color & 0x00ff0000) >> 16) / 255f;
                mesh.b         = ((color & 0x0000ff00) >> 8) / 255f;
                mesh.a         = ((color & 0x000000ff)) / 255f;
                mesh.bones     = bones.ToArray();
                mesh.weights   = weights.ToArray();
                mesh.triangles = triangles;
                mesh.regionUVs = uvs;
                mesh.UpdateUVs();
                mesh.HullLength = hullLength * 2;
                if (nonessential)
                {
                    mesh.Edges  = edges;
                    mesh.Width  = width * scale;
                    mesh.Height = height * scale;
                }
                //
                return(mesh);
            }

            case AttachmentType.weightedlinkedmesh: {
                String path = ReadString(input);
                int    color = ReadInt(input);
                String skinName = ReadString(input);
                String parent = ReadString(input);
                bool   inheritFFD = ReadBoolean(input);
                float  width = 0, height = 0;
                if (nonessential)
                {
                    width  = ReadFloat(input);
                    height = ReadFloat(input);
                }

                if (path == null)
                {
                    path = name;
                }
                WeightedMeshAttachment mesh = attachmentLoader.NewWeightedMeshAttachment(skin, name, path);
                if (mesh == null)
                {
                    return(null);
                }
                mesh.Path       = path;
                mesh.r          = ((color & 0xff000000) >> 24) / 255f;
                mesh.g          = ((color & 0x00ff0000) >> 16) / 255f;
                mesh.b          = ((color & 0x0000ff00) >> 8) / 255f;
                mesh.a          = ((color & 0x000000ff)) / 255f;
                mesh.inheritFFD = inheritFFD;
                if (nonessential)
                {
                    mesh.Width  = width * scale;
                    mesh.Height = height * scale;
                }
                linkedMeshes.Add(new SkeletonJson.LinkedMesh(mesh, skinName, slotIndex, parent));
                return(mesh);
            }
            }
            return(null);
        }
Ejemplo n.º 23
0
        public CCTextureAtlas GetTextureAtlas(RegionAttachment attachment)
        {
            AtlasRegion regionAtlas = (AtlasRegion)attachment.RendererObject;
            var texture2D = (Microsoft.Xna.Framework.Graphics.Texture2D)regionAtlas.page.rendererObject;
            //Console.WriteLine(texture2D.IsDisposed);

            return spine_cocos2dx.CreateAtlasFromTexture2D(texture2D);
        }
Ejemplo n.º 24
0
		public RegionAttachment NewRegionAttachment (Skin skin, string name, string path) {
			RegionAttachment attachment = new RegionAttachment(name);

			Texture2D tex = sprite.texture;
			int instanceId = tex.GetInstanceID();
			AtlasRegion atlasRegion;
			bool cachedMaterialExists = atlasTable.TryGetValue(instanceId, out atlasRegion);

			if (!cachedMaterialExists) {
				// Setup new material.
				var material = new Material(shader);
				if (sprite.packed)
					material.name = "Unity Packed Sprite Material";
				else
					material.name = sprite.name + " Sprite Material";
				material.mainTexture = tex;

				// Create faux-region to play nice with SkeletonRenderer.
				atlasRegion = new AtlasRegion();
				var page = new AtlasPage();
				page.rendererObject = material;
				atlasRegion.page = page;

				// Cache it.
				atlasTable[instanceId] = atlasRegion;
			}

			Rect texRect = sprite.textureRect;

			// Normalize rect to UV space of packed atlas
			texRect.x = Mathf.InverseLerp(0, tex.width, texRect.x);
			texRect.y = Mathf.InverseLerp(0, tex.height, texRect.y);
			texRect.width = Mathf.InverseLerp(0, tex.width, texRect.width);
			texRect.height = Mathf.InverseLerp(0, tex.height, texRect.height);

			Bounds bounds = sprite.bounds;
			Vector2 boundsMin = bounds.min, boundsMax = bounds.max;
			Vector2 size = bounds.size;
			float spriteUnitsPerPixel = 1f / sprite.pixelsPerUnit;

			bool rotated = false;
			if (sprite.packed)
				rotated = sprite.packingRotation == SpritePackingRotation.Any;

			attachment.SetUVs(texRect.xMin, texRect.yMax, texRect.xMax, texRect.yMin, rotated);
			attachment.RendererObject = atlasRegion;
			attachment.SetColor(Color.white);
			attachment.ScaleX = 1;
			attachment.ScaleY = 1;
			attachment.RegionOffsetX = sprite.rect.width * (0.5f - InverseLerp(boundsMin.x, boundsMax.x, 0)) * spriteUnitsPerPixel;
			attachment.RegionOffsetY = sprite.rect.height * (0.5f - InverseLerp(boundsMin.y, boundsMax.y, 0)) * spriteUnitsPerPixel;
			attachment.Width = size.x;
			attachment.Height = size.y;
			attachment.RegionWidth = size.x;
			attachment.RegionHeight = size.y;
			attachment.RegionOriginalWidth = size.x;
			attachment.RegionOriginalHeight = size.y;
			attachment.UpdateOffset();

			return attachment;
		}
Ejemplo n.º 25
0
        private void addSkeletonAttachment(string slotName, string attachmentName, TextureData textureData)
        {
            RegionAttachment regionAttachment = new RegionAttachment(attachmentName);

            regionAttachment.RendererObject = textureData.Texture;
            regionAttachment.Width = regionAttachment.RegionWidth = regionAttachment.RegionOriginalWidth = textureData.Texture.Width;
            regionAttachment.Height = regionAttachment.RegionHeight = regionAttachment.RegionOriginalHeight = textureData.Texture.Height;
            regionAttachment.RegionOffsetX = textureData.OriginX;
            regionAttachment.RegionOffsetY = textureData.OriginY;
            regionAttachment.Rotation = textureData.Rotation;
            regionAttachment.SetUVs(0, 0, 1, 1, false);
            regionAttachment.UpdateOffset();

            Skeleton.Data.FindSkin("default").AddAttachment(Skeleton.FindSlotIndex(slotName), attachmentName, regionAttachment);
        }
Ejemplo n.º 26
0
        private Attachment ReadAttachment(Dictionary <string, object> map, Skin skin, int slotIndex, string name, SkeletonData skeletonData)
        {
            float scale = Scale;

            name = GetString(map, "name", name);
            string text = GetString(map, "type", "region");

            if (text == "skinnedmesh")
            {
                text = "weightedmesh";
            }
            if (text == "weightedmesh")
            {
                text = "mesh";
            }
            if (text == "weightedlinkedmesh")
            {
                text = "linkedmesh";
            }
            AttachmentType attachmentType = (AttachmentType)Enum.Parse(typeof(AttachmentType), text, ignoreCase: true);
            string         @string        = GetString(map, "path", name);

            switch (attachmentType)
            {
            case AttachmentType.Region:
            {
                RegionAttachment regionAttachment = attachmentLoader.NewRegionAttachment(skin, name, @string);
                if (regionAttachment == null)
                {
                    return(null);
                }
                regionAttachment.Path     = @string;
                regionAttachment.x        = GetFloat(map, "x", 0f) * scale;
                regionAttachment.y        = GetFloat(map, "y", 0f) * scale;
                regionAttachment.scaleX   = GetFloat(map, "scaleX", 1f);
                regionAttachment.scaleY   = GetFloat(map, "scaleY", 1f);
                regionAttachment.rotation = GetFloat(map, "rotation", 0f);
                regionAttachment.width    = GetFloat(map, "width", 32f) * scale;
                regionAttachment.height   = GetFloat(map, "height", 32f) * scale;
                regionAttachment.UpdateOffset();
                if (map.ContainsKey("color"))
                {
                    string hexString2 = (string)map["color"];
                    regionAttachment.r = ToColor(hexString2, 0);
                    regionAttachment.g = ToColor(hexString2, 1);
                    regionAttachment.b = ToColor(hexString2, 2);
                    regionAttachment.a = ToColor(hexString2, 3);
                }
                regionAttachment.UpdateOffset();
                return(regionAttachment);
            }

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

            case AttachmentType.Mesh:
            case AttachmentType.Linkedmesh:
            {
                MeshAttachment meshAttachment = attachmentLoader.NewMeshAttachment(skin, name, @string);
                if (meshAttachment == null)
                {
                    return(null);
                }
                meshAttachment.Path = @string;
                if (map.ContainsKey("color"))
                {
                    string hexString = (string)map["color"];
                    meshAttachment.r = ToColor(hexString, 0);
                    meshAttachment.g = ToColor(hexString, 1);
                    meshAttachment.b = ToColor(hexString, 2);
                    meshAttachment.a = ToColor(hexString, 3);
                }
                meshAttachment.Width  = GetFloat(map, "width", 0f) * scale;
                meshAttachment.Height = GetFloat(map, "height", 0f) * scale;
                string string3 = GetString(map, "parent", null);
                if (string3 != null)
                {
                    meshAttachment.InheritDeform = GetBoolean(map, "deform", defaultValue: true);
                    linkedMeshes.Add(new LinkedMesh(meshAttachment, GetString(map, "skin", null), slotIndex, string3));
                    return(meshAttachment);
                }
                float[] floatArray = GetFloatArray(map, "uvs", 1f);
                ReadVertices(map, meshAttachment, floatArray.Length);
                meshAttachment.triangles = GetIntArray(map, "triangles");
                meshAttachment.regionUVs = floatArray;
                meshAttachment.UpdateUVs();
                if (map.ContainsKey("hull"))
                {
                    meshAttachment.HullLength = GetInt(map, "hull", 0) * 2;
                }
                if (map.ContainsKey("edges"))
                {
                    meshAttachment.Edges = GetIntArray(map, "edges");
                }
                return(meshAttachment);
            }

            case AttachmentType.Path:
            {
                PathAttachment pathAttachment = attachmentLoader.NewPathAttachment(skin, name);
                if (pathAttachment == null)
                {
                    return(null);
                }
                pathAttachment.closed        = GetBoolean(map, "closed", defaultValue: false);
                pathAttachment.constantSpeed = GetBoolean(map, "constantSpeed", defaultValue: true);
                int @int = GetInt(map, "vertexCount", 0);
                ReadVertices(map, pathAttachment, @int << 1);
                pathAttachment.lengths = GetFloatArray(map, "lengths", scale);
                return(pathAttachment);
            }

            case AttachmentType.Point:
            {
                PointAttachment pointAttachment = attachmentLoader.NewPointAttachment(skin, name);
                if (pointAttachment == null)
                {
                    return(null);
                }
                pointAttachment.x        = GetFloat(map, "x", 0f) * scale;
                pointAttachment.y        = GetFloat(map, "y", 0f) * scale;
                pointAttachment.rotation = GetFloat(map, "rotation", 0f);
                return(pointAttachment);
            }

            case AttachmentType.Clipping:
            {
                ClippingAttachment clippingAttachment = attachmentLoader.NewClippingAttachment(skin, name);
                if (clippingAttachment == null)
                {
                    return(null);
                }
                string string2 = GetString(map, "end", null);
                if (string2 != null)
                {
                    SlotData slotData = skeletonData.FindSlot(string2);
                    if (slotData == null)
                    {
                        throw new Exception("Clipping end slot not found: " + string2);
                    }
                    clippingAttachment.EndSlot = slotData;
                }
                ReadVertices(map, clippingAttachment, GetInt(map, "vertexCount", 0) << 1);
                return(clippingAttachment);
            }

            default:
                return(null);
            }
        }
Ejemplo n.º 27
0
        private Attachment ReadAttachment(Skin skin, int slotIndex, String name, Dictionary <String, Object> map)
        {
            string skinKey = name;

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

            var scale = this.Scale;

            var type = AttachmentType.region;

            if (map.ContainsKey("type"))
            {
                var typeName = (String)map["type"];
                if (typeName == "skinnedmesh")
                {
                    typeName = "weightedmesh";
                }
                type = (AttachmentType)Enum.Parse(typeof(AttachmentType), typeName, 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:
            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  = GetInt(map, "width", 0) * scale;
                mesh.Height = GetInt(map, "height", 0) * scale;

                String parent = GetString(map, "parent", null);
                if (parent == null)
                {
                    mesh.vertices  = GetFloatArray(map, "vertices", scale);
                    mesh.triangles = GetIntArray(map, "triangles");
                    mesh.regionUVs = GetFloatArray(map, "uvs", 1);
                    mesh.UpdateUVs();

                    mesh.HullLength = GetInt(map, "hull", 0) * 2;
                    if (map.ContainsKey("edges"))
                    {
                        mesh.Edges = GetIntArray(map, "edges");
                    }
                }
                else
                {
                    mesh.InheritFFD = GetBoolean(map, "ffd", true);
                    string sourceSkin        = GetString(map, "skin", null);
                    bool   sourceDefaultSkin = sourceSkin == null || sourceSkin == "default";
                    linkedMeshes.Add(new LinkedMesh(mesh, sourceSkin, slotIndex, sourceDefaultSkin ? parent : skinKey));
                }

                return(mesh);
            }

            case AttachmentType.weightedmesh:
            case AttachmentType.weightedlinkedmesh: {
                WeightedMeshAttachment mesh = attachmentLoader.NewWeightedMeshAttachment(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  = GetInt(map, "width", 0) * scale;
                mesh.Height = GetInt(map, "height", 0) * scale;

                String parent = GetString(map, "parent", null);
                if (parent == null)
                {
                    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);
                    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();

                    mesh.HullLength = GetInt(map, "hull", 0) * 2;
                    if (map.ContainsKey("edges"))
                    {
                        mesh.Edges = GetIntArray(map, "edges");
                    }
                }
                else
                {
                    mesh.InheritFFD = GetBoolean(map, "ffd", true);
                    string sourceSkin        = GetString(map, "skin", null);
                    bool   sourceDefaultSkin = sourceSkin == null || sourceSkin == "default";
                    linkedMeshes.Add(new LinkedMesh(mesh, sourceSkin, slotIndex, sourceDefaultSkin ? parent : skinKey));
                }

                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);
        }
Ejemplo n.º 28
0
	static Mesh ExtractRegionAttachment (string name, RegionAttachment attachment, Mesh mesh = null) {
		var bone = GetExtractionBone();

		bone.X = -attachment.X;
		bone.Y = -attachment.Y;
		bone.UpdateWorldTransform();

		Vector2[] uvs = ExtractUV(attachment.UVs);
		float[] floatVerts = new float[8];
		attachment.ComputeWorldVertices(bone, floatVerts);
		Vector3[] verts = ExtractVerts(floatVerts);

		//unrotate verts now that they're centered
		for (int i = 0; i < verts.Length; i++) {
			verts[i] = Quaternion.Euler(0, 0, -attachment.Rotation) * verts[i];
		}

		int[] triangles = new int[6] { 1, 3, 0, 2, 3, 1 };
		Color color = new Color(attachment.R, attachment.G, attachment.B, attachment.A);

		if (mesh == null)
			mesh = new Mesh();

		mesh.triangles = new int[0];

		mesh.vertices = verts;
		mesh.uv = uvs;
		mesh.triangles = triangles;
		mesh.colors = new Color[] { color, color, color, color };
		mesh.RecalculateBounds();
		mesh.RecalculateNormals();
		mesh.name = name;

		return mesh;
	}
Ejemplo n.º 29
0
        private Attachment ReadAttachment(Stream input, SkeletonData skeletonData, Skin skin, int slotIndex, String attachmentName, bool nonessential)
        {
            float scale = Scale;

            String name = ReadString(input);

            if (name == null)
            {
                name = attachmentName;
            }

            AttachmentType type = (AttachmentType)input.ReadByte();

            switch (type)
            {
            case AttachmentType.Region: {
                String path     = ReadString(input);
                float  rotation = ReadFloat(input);
                float  x        = ReadFloat(input);
                float  y        = ReadFloat(input);
                float  scaleX   = ReadFloat(input);
                float  scaleY   = ReadFloat(input);
                float  width    = ReadFloat(input);
                float  height   = ReadFloat(input);
                int    color    = ReadInt(input);

                if (path == null)
                {
                    path = name;
                }
                RegionAttachment region = attachmentLoader.NewRegionAttachment(skin, name, path);
                if (region == null)
                {
                    return(null);
                }
                region.Path     = path;
                region.x        = x * scale;
                region.y        = y * scale;
                region.scaleX   = scaleX;
                region.scaleY   = scaleY;
                region.rotation = rotation;
                region.width    = width * scale;
                region.height   = height * scale;
                region.r        = ((color & 0xff000000) >> 24) / 255f;
                region.g        = ((color & 0x00ff0000) >> 16) / 255f;
                region.b        = ((color & 0x0000ff00) >> 8) / 255f;
                region.a        = ((color & 0x000000ff)) / 255f;
                region.UpdateOffset();
                return(region);
            }

            case AttachmentType.Boundingbox: {
                int      vertexCount = ReadVarint(input, true);
                Vertices vertices    = ReadVertices(input, vertexCount);
                if (nonessential)
                {
                    ReadInt(input);                                       //int color = nonessential ? ReadInt(input) : 0; // Avoid unused local warning.
                }
                BoundingBoxAttachment box = attachmentLoader.NewBoundingBoxAttachment(skin, name);
                if (box == null)
                {
                    return(null);
                }
                box.worldVerticesLength = vertexCount << 1;
                box.vertices            = vertices.vertices;
                box.bones = vertices.bones;
                return(box);
            }

            case AttachmentType.Mesh: {
                String   path = ReadString(input);
                int      color = ReadInt(input);
                int      vertexCount = ReadVarint(input, true);
                float[]  uvs = ReadFloatArray(input, vertexCount << 1, 1);
                int[]    triangles = ReadShortArray(input);
                Vertices vertices = ReadVertices(input, vertexCount);
                int      hullLength = ReadVarint(input, true);
                int[]    edges = null;
                float    width = 0, height = 0;
                if (nonessential)
                {
                    edges  = ReadShortArray(input);
                    width  = ReadFloat(input);
                    height = ReadFloat(input);
                }

                if (path == null)
                {
                    path = name;
                }
                MeshAttachment mesh = attachmentLoader.NewMeshAttachment(skin, name, path);
                if (mesh == null)
                {
                    return(null);
                }
                mesh.Path                = path;
                mesh.r                   = ((color & 0xff000000) >> 24) / 255f;
                mesh.g                   = ((color & 0x00ff0000) >> 16) / 255f;
                mesh.b                   = ((color & 0x0000ff00) >> 8) / 255f;
                mesh.a                   = ((color & 0x000000ff)) / 255f;
                mesh.bones               = vertices.bones;
                mesh.vertices            = vertices.vertices;
                mesh.WorldVerticesLength = vertexCount << 1;
                mesh.triangles           = triangles;
                mesh.regionUVs           = uvs;
                mesh.UpdateUVs();
                mesh.HullLength = hullLength << 1;
                if (nonessential)
                {
                    mesh.Edges  = edges;
                    mesh.Width  = width * scale;
                    mesh.Height = height * scale;
                }
                return(mesh);
            }

            case AttachmentType.Linkedmesh: {
                String path = ReadString(input);
                int    color = ReadInt(input);
                String skinName = ReadString(input);
                String parent = ReadString(input);
                bool   inheritDeform = ReadBoolean(input);
                float  width = 0, height = 0;
                if (nonessential)
                {
                    width  = ReadFloat(input);
                    height = ReadFloat(input);
                }

                if (path == null)
                {
                    path = name;
                }
                MeshAttachment mesh = attachmentLoader.NewMeshAttachment(skin, name, path);
                if (mesh == null)
                {
                    return(null);
                }
                mesh.Path          = path;
                mesh.r             = ((color & 0xff000000) >> 24) / 255f;
                mesh.g             = ((color & 0x00ff0000) >> 16) / 255f;
                mesh.b             = ((color & 0x0000ff00) >> 8) / 255f;
                mesh.a             = ((color & 0x000000ff)) / 255f;
                mesh.inheritDeform = inheritDeform;
                if (nonessential)
                {
                    mesh.Width  = width * scale;
                    mesh.Height = height * scale;
                }
                linkedMeshes.Add(new SkeletonJson.LinkedMesh(mesh, skinName, slotIndex, parent));
                return(mesh);
            }

            case AttachmentType.Path: {
                bool     closed        = ReadBoolean(input);
                bool     constantSpeed = ReadBoolean(input);
                int      vertexCount   = ReadVarint(input, true);
                Vertices vertices      = ReadVertices(input, vertexCount);
                float[]  lengths       = new float[vertexCount / 3];
                for (int i = 0, n = lengths.Length; i < n; i++)
                {
                    lengths[i] = ReadFloat(input) * scale;
                }
                if (nonessential)
                {
                    ReadInt(input);                                       //int color = nonessential ? ReadInt(input) : 0;
                }
                PathAttachment path = attachmentLoader.NewPathAttachment(skin, name);
                if (path == null)
                {
                    return(null);
                }
                path.closed              = closed;
                path.constantSpeed       = constantSpeed;
                path.worldVerticesLength = vertexCount << 1;
                path.vertices            = vertices.vertices;
                path.bones   = vertices.bones;
                path.lengths = lengths;
                return(path);
            }

            case AttachmentType.Point: {
                float rotation = ReadFloat(input);
                float x        = ReadFloat(input);
                float y        = ReadFloat(input);
                if (nonessential)
                {
                    ReadInt(input);                                       //int color = nonessential ? ReadInt(input) : 0;
                }
                PointAttachment point = attachmentLoader.NewPointAttachment(skin, name);
                if (point == null)
                {
                    return(null);
                }
                point.x        = x * scale;
                point.y        = y * scale;
                point.rotation = rotation;
                //if (nonessential) point.color = color;
                return(point);
            }

            case AttachmentType.Clipping: {
                int      endSlotIndex = ReadVarint(input, true);
                int      vertexCount  = ReadVarint(input, true);
                Vertices vertices     = ReadVertices(input, vertexCount);
                if (nonessential)
                {
                    ReadInt(input);
                }

                ClippingAttachment clip = attachmentLoader.NewClippingAttachment(skin, name);
                if (clip == null)
                {
                    return(null);
                }
                clip.EndSlot             = skeletonData.slots.Items[endSlotIndex];
                clip.worldVerticesLength = vertexCount << 1;
                clip.vertices            = vertices.vertices;
                clip.bones = vertices.bones;
                return(clip);
            }
            }
            return(null);
        }
Ejemplo n.º 30
0
        public void Draw(Skeleton skeleton)
        {
            List <Slot> drawOrder = skeleton.DrawOrder;

            for (int i = 0, n = drawOrder.Count; i < n; i++)
            {
                Slot             slot             = drawOrder[i];
                RegionAttachment regionAttachment = slot.Attachment as RegionAttachment;
                if (regionAttachment != null)
                {
                    SpriteBatchItem item = batcher.CreateBatchItem();
                    item.Texture = (Texture2D)regionAttachment.RendererObject;

                    byte r = (byte)(skeleton.R * slot.R * 255);
                    byte g = (byte)(skeleton.G * slot.G * 255);
                    byte b = (byte)(skeleton.B * slot.B * 255);
                    byte a = (byte)(skeleton.A * slot.A * 255);
                    item.vertexTL.Color.R = r;
                    item.vertexTL.Color.G = g;
                    item.vertexTL.Color.B = b;
                    item.vertexTL.Color.A = a;
                    item.vertexBL.Color.R = r;
                    item.vertexBL.Color.G = g;
                    item.vertexBL.Color.B = b;
                    item.vertexBL.Color.A = a;
                    item.vertexBR.Color.R = r;
                    item.vertexBR.Color.G = g;
                    item.vertexBR.Color.B = b;
                    item.vertexBR.Color.A = a;
                    item.vertexTR.Color.R = r;
                    item.vertexTR.Color.G = g;
                    item.vertexTR.Color.B = b;
                    item.vertexTR.Color.A = a;

                    float[] vertices = this.vertices;
                    regionAttachment.ComputeVertices(slot.Bone, vertices);
                    item.vertexTL.Position.X = vertices[RegionAttachment.X1];
                    item.vertexTL.Position.Y = vertices[RegionAttachment.Y1];
                    item.vertexTL.Position.Z = 0;
                    item.vertexBL.Position.X = vertices[RegionAttachment.X2];
                    item.vertexBL.Position.Y = vertices[RegionAttachment.Y2];
                    item.vertexBL.Position.Z = 0;
                    item.vertexBR.Position.X = vertices[RegionAttachment.X3];
                    item.vertexBR.Position.Y = vertices[RegionAttachment.Y3];
                    item.vertexBR.Position.Z = 0;
                    item.vertexTR.Position.X = vertices[RegionAttachment.X4];
                    item.vertexTR.Position.Y = vertices[RegionAttachment.Y4];
                    item.vertexTR.Position.Z = 0;

                    float[] uvs = regionAttachment.UVs;
                    item.vertexTL.TextureCoordinate.X = uvs[RegionAttachment.X1];
                    item.vertexTL.TextureCoordinate.Y = uvs[RegionAttachment.Y1];
                    item.vertexBL.TextureCoordinate.X = uvs[RegionAttachment.X2];
                    item.vertexBL.TextureCoordinate.Y = uvs[RegionAttachment.Y2];
                    item.vertexBR.TextureCoordinate.X = uvs[RegionAttachment.X3];
                    item.vertexBR.TextureCoordinate.Y = uvs[RegionAttachment.Y3];
                    item.vertexTR.TextureCoordinate.X = uvs[RegionAttachment.X4];
                    item.vertexTR.TextureCoordinate.Y = uvs[RegionAttachment.Y4];
                }
            }
        }
Ejemplo n.º 31
0
        private Attachment ReadAttachment(Stream input, Skin skin, String attachmentName, bool nonessential)
        {
            float scale = Scale;

            String name = ReadString(input);

            if (name == null)
            {
                name = attachmentName;
            }
            AttachmentType t = (AttachmentType)input.ReadByte();

            switch (t)
            {
            case AttachmentType.region: {
                String path = ReadString(input);
                if (path == null)
                {
                    path = name;
                }
                RegionAttachment region = attachmentLoader.NewRegionAttachment(skin, name, path);
                //if (region == null) return null;
                if (region == null)
                {
                    region = new RegionAttachment(name);
                }
                region.Path     = path;
                region.x        = ReadFloat(input) * scale;
                region.y        = ReadFloat(input) * scale;
                region.scaleX   = ReadFloat(input);
                region.scaleY   = ReadFloat(input);
                region.rotation = ReadFloat(input);
                region.width    = ReadFloat(input) * scale;
                region.height   = ReadFloat(input) * scale;
                int color = ReadInt(input);
                region.r = ((color & 0xff000000) >> 24) / 255f;
                region.g = ((color & 0x00ff0000) >> 16) / 255f;
                region.b = ((color & 0x0000ff00) >> 8) / 255f;
                region.a = ((color & 0x000000ff)) / 255f;
                region.UpdateOffset();
                return(region);
            }

            case AttachmentType.boundingbox: {
                BoundingBoxAttachment box = attachmentLoader.NewBoundingBoxAttachment(skin, name);
                //if (box == null) return null;
                if (box == null)
                {
                    box = new BoundingBoxAttachment(name);
                }
                box.vertices = ReadFloatArray(input, scale);
                return(box);
            }

            case AttachmentType.mesh: {
                String path = ReadString(input);
                if (path == null)
                {
                    path = name;
                }
                MeshAttachment mesh = attachmentLoader.NewMeshAttachment(skin, name, path);
                //if (mesh == null) return null;
                if (mesh == null)
                {
                    mesh = new MeshAttachment(name);
                }
                mesh.Path      = path;
                mesh.regionUVs = ReadFloatArray(input, 1);
                mesh.triangles = ReadShortArray(input);
                mesh.vertices  = ReadFloatArray(input, scale);
                mesh.UpdateUVs();
                int color = ReadInt(input);
                mesh.r          = ((color & 0xff000000) >> 24) / 255f;
                mesh.g          = ((color & 0x00ff0000) >> 16) / 255f;
                mesh.b          = ((color & 0x0000ff00) >> 8) / 255f;
                mesh.a          = ((color & 0x000000ff)) / 255f;
                mesh.HullLength = ReadInt(input, true) * 2;
                if (nonessential)
                {
                    mesh.Edges  = ReadIntArray(input);
                    mesh.Width  = ReadFloat(input) * scale;
                    mesh.Height = ReadFloat(input) * scale;
                }
                return(mesh);
            }

            case AttachmentType.skinnedmesh: {
                String path = ReadString(input);
                if (path == null)
                {
                    path = name;
                }
                SkinnedMeshAttachment mesh = attachmentLoader.NewSkinnedMeshAttachment(skin, name, path);
                //if (mesh == null) return null;
                if (mesh == null)
                {
                    mesh = new SkinnedMeshAttachment(name);
                }
                //ReadInt(input, true);
                mesh.Path = path;
                float[] uvs       = ReadFloatArray(input, 1);
                int[]   triangles = ReadShortArray(input);

                int vertexCount = ReadInt(input, true);
                var weights     = new List <float>(uvs.Length * 3 * 3);
                var bones       = new List <int>(uvs.Length * 3);
                for (int i = 0; i < vertexCount; i++)
                {
                    int boneCount = (int)ReadFloat(input);
                    bones.Add(boneCount);
                    for (int nn = i + boneCount * 4; i < nn; i += 4)
                    {
                        bones.Add((int)ReadFloat(input));
                        weights.Add(ReadFloat(input) * scale);
                        weights.Add(ReadFloat(input) * scale);
                        weights.Add(ReadFloat(input));
                    }
                }
                mesh.bones     = bones.ToArray();
                mesh.weights   = weights.ToArray();
                mesh.triangles = triangles;
                mesh.regionUVs = uvs;
                mesh.UpdateUVs();
                int color = ReadInt(input);
                mesh.r          = ((color & 0xff000000) >> 24) / 255f;
                mesh.g          = ((color & 0x00ff0000) >> 16) / 255f;
                mesh.b          = ((color & 0x0000ff00) >> 8) / 255f;
                mesh.a          = ((color & 0x000000ff)) / 255f;
                mesh.HullLength = ReadInt(input, true) * 2;
                if (nonessential)
                {
                    mesh.Edges  = ReadIntArray(input);
                    mesh.Width  = ReadFloat(input) * scale;
                    mesh.Height = ReadFloat(input) * scale;
                }
                return(mesh);
            }
            }
            return(null);
        }
Ejemplo n.º 32
0
        public void GetBounds(out float x, out float y, out float width, out float height, ref float[] vertexBuffer)
        {
            float[] worldVertices = vertexBuffer;
            if (worldVertices != null)
            {
                worldVertices = worldVertices;
            }
            else
            {
                worldVertices = new float[8];
            }
            Slot[] items = this.drawOrder.Items;
            float  num   = 2.147484E+09f;
            float  num2  = 2.147484E+09f;
            float  num3  = -2.147484E+09f;
            float  num4  = -2.147484E+09f;
            int    index = 0;
            int    count = this.drawOrder.Count;

            while (index < count)
            {
                Slot             slot = items[index];
                int              worldVerticesLength = 0;
                float[]          numArray2           = null;
                Attachment       attachment          = slot.attachment;
                RegionAttachment attachment2         = attachment as RegionAttachment;
                if (attachment2 != null)
                {
                    worldVerticesLength = 8;
                    numArray2           = worldVertices;
                    if (numArray2.Length < 8)
                    {
                        numArray2 = worldVertices = new float[8];
                    }
                    attachment2.ComputeWorldVertices(slot.bone, worldVertices, 0, 2);
                }
                else
                {
                    MeshAttachment attachment3 = attachment as MeshAttachment;
                    if (attachment3 != null)
                    {
                        MeshAttachment attachment4 = attachment3;
                        worldVerticesLength = attachment4.WorldVerticesLength;
                        numArray2           = worldVertices;
                        if (numArray2.Length < worldVerticesLength)
                        {
                            numArray2 = worldVertices = new float[worldVerticesLength];
                        }
                        attachment4.ComputeWorldVertices(slot, 0, worldVerticesLength, worldVertices, 0, 2);
                    }
                }
                if (numArray2 != null)
                {
                    for (int i = 0; i < worldVerticesLength; i += 2)
                    {
                        float num9  = numArray2[i];
                        float num10 = numArray2[i + 1];
                        num  = Math.Min(num, num9);
                        num2 = Math.Min(num2, num10);
                        num3 = Math.Max(num3, num9);
                        num4 = Math.Max(num4, num10);
                    }
                }
                index++;
            }
            x            = num;
            y            = num2;
            width        = num3 - num;
            height       = num4 - num2;
            vertexBuffer = worldVertices;
        }
Ejemplo n.º 33
0
        public void Draw(Skeleton skeleton)
        {
            List <Slot> drawOrder = skeleton.DrawOrder;

            for (int i = 0, n = drawOrder.Count; i < n; i++)
            {
                Slot       slot       = drawOrder[i];
                Attachment attachment = slot.Attachment;
                if (attachment is RegionAttachment)
                {
                    RegionAttachment regionAttachment = (RegionAttachment)attachment;

                    SpriteBatchItem item = batcher.CreateBatchItem();
                    item.Texture = (Texture2D)regionAttachment.Region.Atlas.Texture;

                    byte r = (byte)(slot.R * 255);
                    byte g = (byte)(slot.G * 255);
                    byte b = (byte)(slot.B * 255);
                    byte a = (byte)(slot.A * 255);
                    item.vertexTL.Color.R = r;
                    item.vertexTL.Color.G = g;
                    item.vertexTL.Color.B = b;
                    item.vertexTL.Color.A = a;
                    item.vertexBL.Color.R = r;
                    item.vertexBL.Color.G = g;
                    item.vertexBL.Color.B = b;
                    item.vertexBL.Color.A = a;
                    item.vertexBR.Color.R = r;
                    item.vertexBR.Color.G = g;
                    item.vertexBR.Color.B = b;
                    item.vertexBR.Color.A = a;
                    item.vertexTR.Color.R = r;
                    item.vertexTR.Color.G = g;
                    item.vertexTR.Color.B = b;
                    item.vertexTR.Color.A = a;

                    regionAttachment.UpdateVertices(slot.Bone);
                    float[] vertices = regionAttachment.Vertices;
                    item.vertexTL.Position.X = vertices[RegionAttachment.X1];
                    item.vertexTL.Position.Y = vertices[RegionAttachment.Y1];
                    item.vertexTL.Position.Z = 0;
                    item.vertexBL.Position.X = vertices[RegionAttachment.X2];
                    item.vertexBL.Position.Y = vertices[RegionAttachment.Y2];
                    item.vertexBL.Position.Z = 0;
                    item.vertexBR.Position.X = vertices[RegionAttachment.X3];
                    item.vertexBR.Position.Y = vertices[RegionAttachment.Y3];
                    item.vertexBR.Position.Z = 0;
                    item.vertexTR.Position.X = vertices[RegionAttachment.X4];
                    item.vertexTR.Position.Y = vertices[RegionAttachment.Y4];
                    item.vertexTR.Position.Z = 0;

                    float[] uvs = regionAttachment.UVs;
                    item.vertexTL.TextureCoordinate.X = uvs[RegionAttachment.X1];
                    item.vertexTL.TextureCoordinate.Y = uvs[RegionAttachment.Y1];
                    item.vertexBL.TextureCoordinate.X = uvs[RegionAttachment.X2];
                    item.vertexBL.TextureCoordinate.Y = uvs[RegionAttachment.Y2];
                    item.vertexBR.TextureCoordinate.X = uvs[RegionAttachment.X3];
                    item.vertexBR.TextureCoordinate.Y = uvs[RegionAttachment.Y3];
                    item.vertexTR.TextureCoordinate.X = uvs[RegionAttachment.X4];
                    item.vertexTR.TextureCoordinate.Y = uvs[RegionAttachment.Y4];
                }
            }
        }
Ejemplo n.º 34
0
        private Attachment ReadAttachment(Stream input, SkeletonData skeletonData, Skin skin, int slotIndex, string attachmentName, bool nonessential)
        {
            float  scale = Scale;
            string text  = ReadString(input);

            if (text == null)
            {
                text = attachmentName;
            }
            switch (input.ReadByte())
            {
            case 0:
            {
                string text2    = ReadString(input);
                float  rotation = ReadFloat(input);
                float  num3     = ReadFloat(input);
                float  num4     = ReadFloat(input);
                float  scaleX   = ReadFloat(input);
                float  scaleY   = ReadFloat(input);
                float  num5     = ReadFloat(input);
                float  num6     = ReadFloat(input);
                int    num7     = ReadInt(input);
                if (text2 == null)
                {
                    text2 = text;
                }
                RegionAttachment regionAttachment = attachmentLoader.NewRegionAttachment(skin, text, text2);
                if (regionAttachment == null)
                {
                    return(null);
                }
                regionAttachment.Path     = text2;
                regionAttachment.x        = num3 * scale;
                regionAttachment.y        = num4 * scale;
                regionAttachment.scaleX   = scaleX;
                regionAttachment.scaleY   = scaleY;
                regionAttachment.rotation = rotation;
                regionAttachment.width    = num5 * scale;
                regionAttachment.height   = num6 * scale;
                regionAttachment.r        = (float)((num7 & 4278190080u) >> 24) / 255f;
                regionAttachment.g        = (float)((num7 & 0xFF0000) >> 16) / 255f;
                regionAttachment.b        = (float)((num7 & 0xFF00) >> 8) / 255f;
                regionAttachment.a        = (float)(num7 & 0xFF) / 255f;
                regionAttachment.UpdateOffset();
                return(regionAttachment);
            }

            case 1:
            {
                int      num20     = ReadVarint(input, optimizePositive: true);
                Vertices vertices4 = ReadVertices(input, num20);
                if (nonessential)
                {
                    ReadInt(input);
                }
                BoundingBoxAttachment boundingBoxAttachment = attachmentLoader.NewBoundingBoxAttachment(skin, text);
                if (boundingBoxAttachment == null)
                {
                    return(null);
                }
                boundingBoxAttachment.worldVerticesLength = num20 << 1;
                boundingBoxAttachment.vertices            = vertices4.vertices;
                boundingBoxAttachment.bones = vertices4.bones;
                return(boundingBoxAttachment);
            }

            case 2:
            {
                string   text3     = ReadString(input);
                int      num8      = ReadInt(input);
                int      num9      = ReadVarint(input, optimizePositive: true);
                float[]  regionUVs = ReadFloatArray(input, num9 << 1, 1f);
                int[]    triangles = ReadShortArray(input);
                Vertices vertices2 = ReadVertices(input, num9);
                int      num10     = ReadVarint(input, optimizePositive: true);
                int[]    edges     = null;
                float    num11     = 0f;
                float    num12     = 0f;
                if (nonessential)
                {
                    edges = ReadShortArray(input);
                    num11 = ReadFloat(input);
                    num12 = ReadFloat(input);
                }
                if (text3 == null)
                {
                    text3 = text;
                }
                MeshAttachment meshAttachment = attachmentLoader.NewMeshAttachment(skin, text, text3);
                if (meshAttachment == null)
                {
                    return(null);
                }
                meshAttachment.Path                = text3;
                meshAttachment.r                   = (float)((num8 & 4278190080u) >> 24) / 255f;
                meshAttachment.g                   = (float)((num8 & 0xFF0000) >> 16) / 255f;
                meshAttachment.b                   = (float)((num8 & 0xFF00) >> 8) / 255f;
                meshAttachment.a                   = (float)(num8 & 0xFF) / 255f;
                meshAttachment.bones               = vertices2.bones;
                meshAttachment.vertices            = vertices2.vertices;
                meshAttachment.WorldVerticesLength = num9 << 1;
                meshAttachment.triangles           = triangles;
                meshAttachment.regionUVs           = regionUVs;
                meshAttachment.UpdateUVs();
                meshAttachment.HullLength = num10 << 1;
                if (nonessential)
                {
                    meshAttachment.Edges  = edges;
                    meshAttachment.Width  = num11 * scale;
                    meshAttachment.Height = num12 * scale;
                }
                return(meshAttachment);
            }

            case 3:
            {
                string text4         = ReadString(input);
                int    num13         = ReadInt(input);
                string skin2         = ReadString(input);
                string parent        = ReadString(input);
                bool   inheritDeform = ReadBoolean(input);
                float  num14         = 0f;
                float  num15         = 0f;
                if (nonessential)
                {
                    num14 = ReadFloat(input);
                    num15 = ReadFloat(input);
                }
                if (text4 == null)
                {
                    text4 = text;
                }
                MeshAttachment meshAttachment2 = attachmentLoader.NewMeshAttachment(skin, text, text4);
                if (meshAttachment2 == null)
                {
                    return(null);
                }
                meshAttachment2.Path          = text4;
                meshAttachment2.r             = (float)((num13 & 4278190080u) >> 24) / 255f;
                meshAttachment2.g             = (float)((num13 & 0xFF0000) >> 16) / 255f;
                meshAttachment2.b             = (float)((num13 & 0xFF00) >> 8) / 255f;
                meshAttachment2.a             = (float)(num13 & 0xFF) / 255f;
                meshAttachment2.inheritDeform = inheritDeform;
                if (nonessential)
                {
                    meshAttachment2.Width  = num14 * scale;
                    meshAttachment2.Height = num15 * scale;
                }
                linkedMeshes.Add(new SkeletonJson.LinkedMesh(meshAttachment2, skin2, slotIndex, parent));
                return(meshAttachment2);
            }

            case 4:
            {
                bool     closed        = ReadBoolean(input);
                bool     constantSpeed = ReadBoolean(input);
                int      num16         = ReadVarint(input, optimizePositive: true);
                Vertices vertices3     = ReadVertices(input, num16);
                float[]  array         = new float[num16 / 3];
                int      i             = 0;
                for (int num17 = array.Length; i < num17; i++)
                {
                    array[i] = ReadFloat(input) * scale;
                }
                if (nonessential)
                {
                    ReadInt(input);
                }
                PathAttachment pathAttachment = attachmentLoader.NewPathAttachment(skin, text);
                if (pathAttachment == null)
                {
                    return(null);
                }
                pathAttachment.closed              = closed;
                pathAttachment.constantSpeed       = constantSpeed;
                pathAttachment.worldVerticesLength = num16 << 1;
                pathAttachment.vertices            = vertices3.vertices;
                pathAttachment.bones   = vertices3.bones;
                pathAttachment.lengths = array;
                return(pathAttachment);
            }

            case 5:
            {
                float rotation2 = ReadFloat(input);
                float num18     = ReadFloat(input);
                float num19     = ReadFloat(input);
                if (nonessential)
                {
                    ReadInt(input);
                }
                PointAttachment pointAttachment = attachmentLoader.NewPointAttachment(skin, text);
                if (pointAttachment == null)
                {
                    return(null);
                }
                pointAttachment.x        = num18 * scale;
                pointAttachment.y        = num19 * scale;
                pointAttachment.rotation = rotation2;
                return(pointAttachment);
            }

            case 6:
            {
                int      num      = ReadVarint(input, optimizePositive: true);
                int      num2     = ReadVarint(input, optimizePositive: true);
                Vertices vertices = ReadVertices(input, num2);
                if (nonessential)
                {
                    ReadInt(input);
                }
                ClippingAttachment clippingAttachment = attachmentLoader.NewClippingAttachment(skin, text);
                if (clippingAttachment == null)
                {
                    return(null);
                }
                clippingAttachment.EndSlot             = skeletonData.slots.Items[num];
                clippingAttachment.worldVerticesLength = num2 << 1;
                clippingAttachment.vertices            = vertices.vertices;
                clippingAttachment.bones = vertices.bones;
                return(clippingAttachment);
            }

            default:
                return(null);
            }
        }
Ejemplo n.º 35
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);
        }
Ejemplo n.º 36
0
        private Attachment ReadAttachment(Skin skin, string name, Dictionary <string, object> map)
        {
            if (map.ContainsKey("name"))
            {
                name = (string)map.get_Item("name");
            }
            AttachmentType attachmentType = AttachmentType.region;

            if (map.ContainsKey("type"))
            {
                attachmentType = (AttachmentType)((int)Enum.Parse(typeof(AttachmentType), (string)map.get_Item("type"), false));
            }
            string path = name;

            if (map.ContainsKey("path"))
            {
                path = (string)map.get_Item("path");
            }
            switch (attachmentType)
            {
            case AttachmentType.region:
            {
                RegionAttachment regionAttachment = this.attachmentLoader.NewRegionAttachment(skin, name, path);
                if (regionAttachment == null)
                {
                    return(null);
                }
                regionAttachment.Path     = path;
                regionAttachment.x        = this.GetFloat(map, "x", 0f) * this.Scale;
                regionAttachment.y        = this.GetFloat(map, "y", 0f) * this.Scale;
                regionAttachment.scaleX   = this.GetFloat(map, "scaleX", 1f);
                regionAttachment.scaleY   = this.GetFloat(map, "scaleY", 1f);
                regionAttachment.rotation = this.GetFloat(map, "rotation", 0f);
                regionAttachment.width    = this.GetFloat(map, "width", 32f) * this.Scale;
                regionAttachment.height   = this.GetFloat(map, "height", 32f) * this.Scale;
                regionAttachment.UpdateOffset();
                if (map.ContainsKey("color"))
                {
                    string hexString = (string)map.get_Item("color");
                    regionAttachment.r = this.ToColor(hexString, 0);
                    regionAttachment.g = this.ToColor(hexString, 1);
                    regionAttachment.b = this.ToColor(hexString, 2);
                    regionAttachment.a = this.ToColor(hexString, 3);
                }
                return(regionAttachment);
            }

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

            case AttachmentType.mesh:
            {
                MeshAttachment meshAttachment = this.attachmentLoader.NewMeshAttachment(skin, name, path);
                if (meshAttachment == null)
                {
                    return(null);
                }
                meshAttachment.Path      = path;
                meshAttachment.vertices  = this.GetFloatArray(map, "vertices", this.Scale);
                meshAttachment.triangles = this.GetIntArray(map, "triangles");
                meshAttachment.regionUVs = this.GetFloatArray(map, "uvs", 1f);
                meshAttachment.UpdateUVs();
                if (map.ContainsKey("color"))
                {
                    string hexString2 = (string)map.get_Item("color");
                    meshAttachment.r = this.ToColor(hexString2, 0);
                    meshAttachment.g = this.ToColor(hexString2, 1);
                    meshAttachment.b = this.ToColor(hexString2, 2);
                    meshAttachment.a = this.ToColor(hexString2, 3);
                }
                meshAttachment.HullLength = this.GetInt(map, "hull", 0) * 2;
                if (map.ContainsKey("edges"))
                {
                    meshAttachment.Edges = this.GetIntArray(map, "edges");
                }
                meshAttachment.Width  = (float)this.GetInt(map, "width", 0) * this.Scale;
                meshAttachment.Height = (float)this.GetInt(map, "height", 0) * this.Scale;
                return(meshAttachment);
            }

            case AttachmentType.skinnedmesh:
            {
                SkinnedMeshAttachment skinnedMeshAttachment = this.attachmentLoader.NewSkinnedMeshAttachment(skin, name, path);
                if (skinnedMeshAttachment == null)
                {
                    return(null);
                }
                skinnedMeshAttachment.Path = path;
                float[]      floatArray  = this.GetFloatArray(map, "uvs", 1f);
                float[]      floatArray2 = this.GetFloatArray(map, "vertices", 1f);
                List <float> list        = new List <float>(floatArray.Length * 3 * 3);
                List <int>   list2       = new List <int>(floatArray.Length * 3);
                float        scale       = this.Scale;
                int          i           = 0;
                int          num         = floatArray2.Length;
                while (i < num)
                {
                    int num2 = (int)floatArray2[i++];
                    list2.Add(num2);
                    int num3 = i + num2 * 4;
                    while (i < num3)
                    {
                        list2.Add((int)floatArray2[i]);
                        list.Add(floatArray2[i + 1] * scale);
                        list.Add(floatArray2[i + 2] * scale);
                        list.Add(floatArray2[i + 3]);
                        i += 4;
                    }
                }
                skinnedMeshAttachment.bones     = list2.ToArray();
                skinnedMeshAttachment.weights   = list.ToArray();
                skinnedMeshAttachment.triangles = this.GetIntArray(map, "triangles");
                skinnedMeshAttachment.regionUVs = floatArray;
                skinnedMeshAttachment.UpdateUVs();
                if (map.ContainsKey("color"))
                {
                    string hexString3 = (string)map.get_Item("color");
                    skinnedMeshAttachment.r = this.ToColor(hexString3, 0);
                    skinnedMeshAttachment.g = this.ToColor(hexString3, 1);
                    skinnedMeshAttachment.b = this.ToColor(hexString3, 2);
                    skinnedMeshAttachment.a = this.ToColor(hexString3, 3);
                }
                skinnedMeshAttachment.HullLength = this.GetInt(map, "hull", 0) * 2;
                if (map.ContainsKey("edges"))
                {
                    skinnedMeshAttachment.Edges = this.GetIntArray(map, "edges");
                }
                skinnedMeshAttachment.Width  = (float)this.GetInt(map, "width", 0) * this.Scale;
                skinnedMeshAttachment.Height = (float)this.GetInt(map, "height", 0) * this.Scale;
                return(skinnedMeshAttachment);
            }

            default:
                return(null);
            }
        }
	public RegionAttachment NewRegionAttachment (Skin skin, String name, String path) {
		ProcessSpriteDefinition(path);
		
		RegionAttachment region = new RegionAttachment(name);
		region.Path = path;
		region.RendererObject = material;
		region.SetUVs(u, v, u2, v2, regionRotated);
		region.RegionOriginalWidth = regionOriginalWidth;
		region.RegionOriginalHeight = regionOriginalHeight;
		region.RegionWidth = regionWidth;
		region.RegionHeight = regionHeight;
		region.RegionOffsetX = regionOffsetX;
		region.RegionOffsetY = regionOffsetY;
		return region;
	}
Ejemplo n.º 38
0
        public void Draw(Skeleton skeleton)
        {
            var   drawOrder = skeleton.DrawOrder;
            var   drawOrderItems = skeleton.DrawOrder.Items;
            float skeletonR = skeleton.R, skeletonG = skeleton.G, skeletonB = skeleton.B, skeletonA = skeleton.A;
            Color color = new Color();

            if (VertexEffect != null)
            {
                VertexEffect.Begin(skeleton);
            }

            for (int i = 0, n = drawOrder.Count; i < n; i++)
            {
                Slot       slot       = drawOrderItems[i];
                Attachment attachment = slot.Attachment;

                float     attachmentColorR, attachmentColorG, attachmentColorB, attachmentColorA;
                Texture2D texture       = null;
                int       verticesCount = 0;
                float[]   vertices      = this.vertices;
                int       indicesCount  = 0;
                int[]     indices       = null;
                float[]   uvs           = null;

                if (attachment is RegionAttachment)
                {
                    RegionAttachment regionAttachment = (RegionAttachment)attachment;
                    attachmentColorR = regionAttachment.R; attachmentColorG = regionAttachment.G; attachmentColorB = regionAttachment.B; attachmentColorA = regionAttachment.A;
                    AtlasRegion region = (AtlasRegion)regionAttachment.RendererObject;
                    texture       = (Texture2D)region.page.rendererObject;
                    verticesCount = 4;
                    regionAttachment.ComputeWorldVertices(slot.Bone, vertices, 0, 2);
                    indicesCount = 6;
                    indices      = quadTriangles;
                    uvs          = regionAttachment.UVs;
                }
                else if (attachment is MeshAttachment)
                {
                    MeshAttachment mesh = (MeshAttachment)attachment;
                    attachmentColorR = mesh.R; attachmentColorG = mesh.G; attachmentColorB = mesh.B; attachmentColorA = mesh.A;
                    AtlasRegion region = (AtlasRegion)mesh.RendererObject;
                    texture = (Texture2D)region.page.rendererObject;
                    int vertexCount = mesh.WorldVerticesLength;
                    if (vertices.Length < vertexCount)
                    {
                        vertices = new float[vertexCount];
                    }
                    verticesCount = vertexCount >> 1;
                    mesh.ComputeWorldVertices(slot, vertices);
                    indicesCount = mesh.Triangles.Length;
                    indices      = mesh.Triangles;
                    uvs          = mesh.UVs;
                }
                else if (attachment is ClippingAttachment)
                {
                    ClippingAttachment clip = (ClippingAttachment)attachment;
                    clipper.ClipStart(slot, clip);
                    continue;
                }
                else
                {
                    continue;
                }

                // set blend state
                BlendState blend = slot.Data.BlendMode == BlendMode.Additive ? BlendState.Additive : defaultBlendState;
                if (device.BlendState != blend)
                {
                    //End();
                    //device.BlendState = blend;
                }

                // calculate color
                float a = skeletonA * slot.A * attachmentColorA;
                if (premultipliedAlpha)
                {
                    color = new Color(
                        skeletonR * slot.R * attachmentColorR * a,
                        skeletonG * slot.G * attachmentColorG * a,
                        skeletonB * slot.B * attachmentColorB * a, a);
                }
                else
                {
                    color = new Color(
                        skeletonR * slot.R * attachmentColorR,
                        skeletonG * slot.G * attachmentColorG,
                        skeletonB * slot.B * attachmentColorB, a);
                }

                Color darkColor = new Color();
                if (slot.HasSecondColor)
                {
                    if (premultipliedAlpha)
                    {
                        darkColor = new Color(slot.R2 * a, slot.G2 * a, slot.B2 * a);
                    }
                    else
                    {
                        darkColor = new Color(slot.R2 * a, slot.G2 * a, slot.B2 * a);
                    }
                }
                darkColor.A = premultipliedAlpha ? (byte)255 : (byte)0;

                // clip
                if (clipper.IsClipping)
                {
                    clipper.ClipTriangles(vertices, verticesCount << 1, indices, indicesCount, uvs);
                    vertices      = clipper.ClippedVertices.Items;
                    verticesCount = clipper.ClippedVertices.Count >> 1;
                    indices       = clipper.ClippedTriangles.Items;
                    indicesCount  = clipper.ClippedTriangles.Count;
                    uvs           = clipper.ClippedUVs.Items;
                }

                if (verticesCount == 0 || indicesCount == 0)
                {
                    continue;
                }

                // submit to batch
                MeshItem item = batcher.NextItem(verticesCount, indicesCount);
                item.texture = texture;
                for (int ii = 0, nn = indicesCount; ii < nn; ii++)
                {
                    item.triangles[ii] = indices[ii];
                }
                VertexPositionColorTextureColor[] itemVertices = item.vertices;
                for (int ii = 0, v = 0, nn = verticesCount << 1; v < nn; ii++, v += 2)
                {
                    itemVertices[ii].Color               = color;
                    itemVertices[ii].Color2              = darkColor;
                    itemVertices[ii].Position.X          = vertices[v];
                    itemVertices[ii].Position.Y          = vertices[v + 1];
                    itemVertices[ii].Position.Z          = 0;
                    itemVertices[ii].TextureCoordinate.X = uvs[v];
                    itemVertices[ii].TextureCoordinate.Y = uvs[v + 1];
                    if (VertexEffect != null)
                    {
                        VertexEffect.Transform(ref itemVertices[ii]);
                    }
                }

                clipper.ClipEnd(slot);
            }
            clipper.ClipEnd();
            if (VertexEffect != null)
            {
                VertexEffect.End();
            }
        }
Ejemplo n.º 39
0
    public RegionAttachment NewRegionAttachment(Skin skin, string name, string path)
    {
        RegionAttachment attachment = new RegionAttachment(name);

        Texture2D tex = sprite.texture;
        int instanceId = tex.GetInstanceID();
        AtlasRegion atlasRegion;

        //check cache first
        if (atlasTable.ContainsKey(instanceId)) {
            atlasRegion = atlasTable[instanceId];
        } else {
            //Setup new material
            Material mat = new Material(shader);
            if (sprite.packed)
                mat.name = "Unity Packed Sprite Material";
            else
                mat.name = sprite.name + " Sprite Material";
            mat.mainTexture = tex;

            //create faux-region to play nice with SkeletonRenderer
            atlasRegion = new AtlasRegion();
            AtlasPage page = new AtlasPage();
            page.rendererObject = mat;
            atlasRegion.page = page;

            //cache it
            atlasTable[instanceId] = atlasRegion;
        }

        Rect texRect = sprite.textureRect;

        //normalize rect to UV space of packed atlas
        texRect.x = Mathf.InverseLerp(0, tex.width, texRect.x);
        texRect.y = Mathf.InverseLerp(0, tex.height, texRect.y);
        texRect.width = Mathf.InverseLerp(0, tex.width, texRect.width);
        texRect.height = Mathf.InverseLerp(0, tex.height, texRect.height);

        Bounds bounds = sprite.bounds;
        Vector3 size = bounds.size;

        //TODO: make sure this rotation thing actually works
        bool rotated = false;
        if (sprite.packed)
            rotated = sprite.packingRotation == SpritePackingRotation.Any;

        //do some math and assign UVs and sizes
        attachment.SetUVs(texRect.xMin, texRect.yMax, texRect.xMax, texRect.yMin, rotated);
        attachment.RendererObject = atlasRegion;
        attachment.SetColor(Color.white);
        attachment.ScaleX = 1;
        attachment.ScaleY = 1;
        attachment.RegionOffsetX = sprite.rect.width * (0.5f - Mathf.InverseLerp(bounds.min.x, bounds.max.x, 0)) / sprite.pixelsPerUnit;
        attachment.RegionOffsetY = sprite.rect.height * (0.5f - Mathf.InverseLerp(bounds.min.y, bounds.max.y, 0)) / sprite.pixelsPerUnit;
        attachment.Width = size.x;
        attachment.Height = size.y;
        attachment.RegionWidth = size.x;
        attachment.RegionHeight = size.y;
        attachment.RegionOriginalWidth = size.x;
        attachment.RegionOriginalHeight = size.y;
        attachment.UpdateOffset();

        return attachment;
    }
Ejemplo n.º 40
0
        public void GetBounds(out float x, out float y, out float width, out float height, ref float[] vertexBuffer)
        {
            float[] array = vertexBuffer;
            array = (array ?? new float[8]);
            Slot[] items = drawOrder.Items;
            float  num   = 2.14748365E+09f;
            float  num2  = 2.14748365E+09f;
            float  num3  = -2.14748365E+09f;
            float  num4  = -2.14748365E+09f;
            int    i     = 0;

            for (int count = drawOrder.Count; i < count; i++)
            {
                Slot             slot             = items[i];
                int              num5             = 0;
                float[]          array2           = null;
                Attachment       attachment       = slot.attachment;
                RegionAttachment regionAttachment = attachment as RegionAttachment;
                if (regionAttachment != null)
                {
                    num5   = 8;
                    array2 = array;
                    if (array2.Length < 8)
                    {
                        array2 = (array = new float[8]);
                    }
                    regionAttachment.ComputeWorldVertices(slot.bone, array, 0);
                }
                else
                {
                    MeshAttachment meshAttachment = attachment as MeshAttachment;
                    if (meshAttachment != null)
                    {
                        MeshAttachment meshAttachment2 = meshAttachment;
                        num5   = meshAttachment2.WorldVerticesLength;
                        array2 = array;
                        if (array2.Length < num5)
                        {
                            array2 = (array = new float[num5]);
                        }
                        meshAttachment2.ComputeWorldVertices(slot, 0, num5, array, 0);
                    }
                }
                if (array2 != null)
                {
                    for (int j = 0; j < num5; j += 2)
                    {
                        float val  = array2[j];
                        float val2 = array2[j + 1];
                        num  = Math.Min(num, val);
                        num2 = Math.Min(num2, val2);
                        num3 = Math.Max(num3, val);
                        num4 = Math.Max(num4, val2);
                    }
                }
            }
            x            = num;
            y            = num2;
            width        = num3 - num;
            height       = num4 - num2;
            vertexBuffer = array;
        }