/// <summary> /// Creates a Spine.AtlasRegion from a UnityEngine.Sprite.</summary> public static AtlasRegion ToAtlasRegion(this Sprite s, AtlasPage page) { if (page == null) { throw new System.ArgumentNullException("page", "page cannot be null. AtlasPage determines which texture region belongs and how it should be rendered. You can use material.ToSpineAtlasPage() to get a shareable AtlasPage from a Material, or use the sprite.ToAtlasRegion(material) overload."); } var region = s.ToAtlasRegion(); region.page = page; return(region); }
public void Load(AtlasPage page, String path) { // tsteil - added ToLower() String name = Path.GetFileNameWithoutExtension(path).ToLower(); Material material = null; // tsteil added support for mask mat Material materialMask = null; // tsteil - changed to not use foreach //foreach (Material other in atlasAsset.materials) { var mats = atlasAsset.materials; for (int i = 0, n = mats.Length; i < n; ++i) { var other = mats[i]; if (other.mainTexture == null) { Debug.LogError("Material is missing texture: " + other.name, other); return; } // tsteil - added ToLower() if (other.mainTexture.name.ToLower() == name) { //Debug.LogWarning("found mat: " + other.name + ", " + other.mainTexture.name + ", " + path); material = other; // tsteil - mask mat if (atlasAsset.materialsMask != null && atlasAsset.materialsMask.Length > i) { materialMask = atlasAsset.materialsMask[i]; } break; } } if (material == null) { Debug.LogError("Material with texture name \"" + name + "\" not found for atlas asset: " + atlasAsset.name, atlasAsset); return; } page.rendererObject = material; page.rendererObjectMask = materialMask; // Very old atlas files expected the texture's actual size to be used at runtime. if (page.width == 0 || page.height == 0) { page.width = material.mainTexture.width; page.height = material.mainTexture.height; } }
public void Load(AtlasPage page, String path) { var image = ContentLoader.Load <Image>(Path.GetFileNameWithoutExtension(path)); var shader = ContentLoader.Create <Shader>(new ShaderCreationData(ShaderFlags.Position2DColoredTextured)); var material = new Material(shader, image); page.rendererObject = material; Size size = material.DiffuseMap.PixelSize; page.width = (int)size.Width; page.height = (int)size.Height; }
public static RegionAttachment ToRegionAttachment(this Sprite sprite, AtlasPage page, float rotation = 0f) { if (sprite == null) { throw new ArgumentNullException("sprite"); } if (page == null) { throw new ArgumentNullException("page"); } AtlasRegion region = sprite.ToAtlasRegion(page); float scale = 1f / sprite.pixelsPerUnit; return(region.ToRegionAttachment(sprite.name, scale, rotation)); }
/// <summary> /// Creates a RegionAttachment based on a sprite. This method creates a real, usable AtlasRegion. That AtlasRegion uses the AtlasPage provided./// </summary> public static RegionAttachment ToRegionAttachment(this Sprite sprite, AtlasPage page) { if (sprite == null) { throw new System.ArgumentNullException("sprite"); } if (page == null) { throw new System.ArgumentNullException("page"); } var region = sprite.ToAtlasRegion(page); var unitsPerPixel = 1f / sprite.pixelsPerUnit; return(region.ToRegionAttachment(sprite.name, unitsPerPixel)); }
/// <summary> /// 通过Material创建AtlasPage /// </summary> /// <returns>The atlas page by material.</returns> /// <param name="material">Material.</param> public static AtlasPage GetAtlasPageByMaterial(Material material) { AtlasPage page = new AtlasPage { rendererObject = material, name = material.name }; Texture texture = material.mainTexture; if (texture != null) { page.width = texture.width; page.height = texture.height; } return(page); }
public static AtlasPage ToSpineAtlasPage(this Material m) { AtlasPage page = new AtlasPage { rendererObject = m, name = m.name }; Texture mainTexture = m.mainTexture; if (mainTexture != null) { page.width = mainTexture.width; page.height = mainTexture.height; } return(page); }
protected virtual void Awake() { foreach (var entry in statesAndAnimations) { entry.animation.Initialize(); } BoxCollider = GetComponent <BoxCollider>(); BoxCollider.enabled = false; SkeletonAnimation = GetComponent <SkeletonAnimation>(); _applyPMA = SkeletonAnimation.pmaVertexColors; _shader = _applyPMA ? Shader.Find(DefaultPMAShader) : Shader.Find(DefaultStraightAlphaShader); _material = new Material(_shader); _atlasPage = _material.ToSpineAtlasPage(); }
public static AtlasPage ToSpineAtlasPage(this Material m) { AtlasPage atlasPage = new AtlasPage(); atlasPage.rendererObject = m; atlasPage.name = m.name; AtlasPage atlasPage2 = atlasPage; Texture mainTexture = m.mainTexture; if (mainTexture != null) { atlasPage2.width = mainTexture.width; atlasPage2.height = mainTexture.height; } return(atlasPage2); }
public void Load(AtlasPage page, string path) { String name = Path.GetFileNameWithoutExtension(path); //Shader sar = Resources.Load<Shader>("spine/Shaders/Spine-Skeleton"); //Material[] mats = new Material[atlasAsset.materials.Length]; //int i = 0; //foreach (Material other in atlasAsset.materials) //{ // Material mat = new Material(sar); // mat.mainTexture = other.mainTexture; // mats[i] = mat; // i++; //} //atlasAsset.materials = mats; Material material = null; foreach (Material other in atlasAsset.RuntimeMaterial) { if (other.mainTexture == null) { Debug.LogError("Material is missing texture: " + other.name, other); return; } if (other.mainTexture.name == name) { material = other; break; } } if (material == null) { Debug.LogError("Material with texture name \"" + name + "\" not found for atlas asset: " + atlasAsset.name, atlasAsset); return; } page.rendererObject = material; // Very old atlas files expected the texture's actual size to be used at runtime. if (page.width == 0 || page.height == 0) { page.width = material.mainTexture.width; page.height = material.mainTexture.height; } }
/// <summary> /// Creates a new Spine.AtlasPage from a UnityEngine.Material. If the material has a preassigned texture, the page width and height will be set.</summary> public static AtlasPage ToSpineAtlasPage(this Material m) { var newPage = new AtlasPage { rendererObject = m, name = m.name }; var t = m.mainTexture; if (t != null) { newPage.width = t.width; newPage.height = t.height; } return(newPage); }
/// <summary> /// Loads the specified page. /// </summary> /// <param name="page">The page.</param> /// <param name="path">The path.</param> public void Load(AtlasPage page, string path) { var material = new StandardMaterial() { LightingEnabled = false, DiffusePath = path, VertexColorEnable = true }; material.Initialize(this.assets); var texture = material.Diffuse; page.rendererObject = material; page.width = texture.Width; page.height = texture.Height; }
/// <summary> /// Loads spine texture from the specified WZ path /// </summary> /// <param name="page"></param> /// <param name="path"></param> public void Load(AtlasPage page, string path) { WzObject frameNode = this.ParentNode[path]; if (frameNode == null) { return; } WzCanvasProperty canvasProperty = null; WzImageProperty imageChild = (WzImageProperty)ParentNode[path]; if (imageChild is WzUOLProperty uolProperty) { WzObject uolLink = uolProperty.LinkValue; if (uolLink is WzCanvasProperty uolPropertyLink) { canvasProperty = uolPropertyLink; } else { // other unimplemented prop? } } else if (imageChild is WzCanvasProperty property) { canvasProperty = property; } if (canvasProperty != null && graphicsDevice != null) { WzCanvasProperty linkImgProperty = (WzCanvasProperty)canvasProperty.GetLinkedWzImageProperty(); WzPngProperty pngProperty = linkImgProperty.PngProperty; Texture2D tex = new Texture2D(graphicsDevice, pngProperty.Width, pngProperty.Height, false, linkImgProperty.PngProperty.GetXNASurfaceFormat()); pngProperty.ParsePng(true, tex); page.rendererObject = tex; page.width = pngProperty.Width; page.height = pngProperty.Height; } }
public void Load(AtlasPage page, string path) { // Spine passes a string made with Path.Combine(), which is dumb. We never need to use backslashes. Ever. var filename = path.Replace('\\', '/'); filename = filename.TrimStart('.'); filename = string.Format("{0}{1}", folder, filename); var texture = Library.GetTexture(filename); texture.Smooth = true; page.rendererObject = texture; var size = texture.Size; page.width = (int)size.X; page.height = (int)size.Y; }
/// <summary> /// Creates a new Spine AtlasRegion according to a Unity UV Rect (x-right, y-up, uv-normalized).</summary> static AtlasRegion UVRectToAtlasRegion(Rect uvRect, string name, AtlasPage page, float offsetX, float offsetY, bool rotate, int originalWidth, int originalHeight) { var tr = UVRectToTextureRect(uvRect, page.width, page.height); var rr = tr.SpineUnityFlipRect(page.height); int x = (int)rr.x, y = (int)rr.y; int w, h; if (rotate) { w = (int)rr.height; h = (int)rr.width; } else { w = (int)rr.width; h = (int)rr.height; } return(new AtlasRegion { page = page, name = name, u = uvRect.xMin, u2 = uvRect.xMax, v = uvRect.yMax, v2 = uvRect.yMin, index = -1, width = w, originalWidth = originalWidth, height = h, originalHeight = originalHeight, offsetX = offsetX, offsetY = offsetY, x = x, y = y, rotate = rotate }); }
public void Load(AtlasPage page, string path) { String name = Path.GetFileNameWithoutExtension(path); Material material = null; foreach (Material other in atlasAsset.materials) { if (other.mainTexture == null) { // cwc 换装动态加载图片,初始化时材质的贴图引用为空,正常 // Debug.LogError("Material is missing texture: " + other.name, other); string[] s = other.name.Split('_'); if (s.Length > 1 && string.Compare(s[s.Length - 1], name) == 0) { material = other; break; } } else if (other.mainTexture.name == name) { material = other; break; } } if (material == null) { Debug.LogError( "Material with texture name \"" + name + "\" not found for atlas asset: " + atlasAsset.name, atlasAsset); return; } page.rendererObject = material; // Very old atlas files expected the texture's actual size to be used at runtime. if (page.width == 0 || page.height == 0) { page.width = material.mainTexture.width; page.height = material.mainTexture.height; } }
public void Load(AtlasPage page, String path) { var ccTexture = CCApplication.SharedApplication.TextureCache.AddImage(path); if (texture == null) { using (Stream stream = CCFileUtils.GetFileStream(path)) { texture = Util.LoadTexture(CCDrawManager.GraphicsDevice, stream); } } else { texture = ccTexture.XNATexture; } page.rendererObject = texture; page.width = texture.Width; page.height = texture.Height; }
public static AtlasRegion ToAtlasRegionPMAClone(this Texture2D t, Shader shader, TextureFormat textureFormat = TextureFormat.RGBA32, bool mipmaps = false, Material materialPropertySource = null) { Material material = new Material(shader); if (materialPropertySource != null) { material.CopyPropertiesFromMaterial(materialPropertySource); material.shaderKeywords = materialPropertySource.shaderKeywords; } Texture2D clone = t.GetClone(applyImmediately: false, textureFormat, mipmaps); clone.ApplyPMA(); clone.name = t.name + "-pma-"; material.name = t.name + shader.name; material.mainTexture = clone; AtlasPage page = material.ToSpineAtlasPage(); AtlasRegion atlasRegion = clone.ToAtlasRegion(shader); atlasRegion.page = page; return(atlasRegion); }
protected AtlasRegion CloneAtlasRegionWithMaterial(AtlasRegion originalRegion, List <ReplacementMaterial> replacementMaterials) { var newRegion = originalRegion.Clone(); Material material = null; foreach (var replacement in replacementMaterials) { if (replacement.pageName == originalRegion.page.name) { material = replacement.material; break; } } AtlasPage originalPage = originalRegion.page; var newPage = originalPage.Clone(); newPage.rendererObject = material; newRegion.page = newPage; return(newRegion); }
public void Load(AtlasPage page, string path) { IntPtr tmp = SDL_image.IMG_Load(path); tmp = SDL.SDL_ConvertSurfaceFormat(tmp, SDL.SDL_PIXELFORMAT_ABGR8888, 0); SDL.SDL_Surface surface = Marshal.PtrToStructure <SDL.SDL_Surface>(tmp); var textureIdList = new uint[1]; _gl.GenTextures(1, textureIdList); var textureId = textureIdList[0]; _gl.BindTexture(OpenGL.GL_TEXTURE_2D, textureId); _gl.TexImage2D(OpenGL.GL_TEXTURE_2D, 0, OpenGL.GL_RGBA, surface.w, surface.h, 0, OpenGL.GL_RGBA, OpenGL.GL_UNSIGNED_BYTE, surface.pixels); _gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MAG_FILTER, OpenGL.GL_LINEAR); _gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MIN_FILTER, OpenGL.GL_LINEAR); SDL.SDL_FreeSurface(tmp); page.rendererObject = textureId; }
public static AtlasRegion ToAtlasRegionPMAClone(this Texture2D t, Shader shader, TextureFormat textureFormat = 4, bool mipmaps = false, Material materialPropertySource = null) { Material m = new Material(shader); if (materialPropertySource != null) { m.CopyPropertiesFromMaterial(materialPropertySource); m.shaderKeywords = materialPropertySource.shaderKeywords; } Texture2D texture = t.GetClone(false, textureFormat, mipmaps); texture.ApplyPMA(true); texture.name = t.name + "-pma-"; m.name = t.name + shader.name; m.mainTexture = texture; AtlasPage page = m.ToSpineAtlasPage(); AtlasRegion region = texture.ToAtlasRegion(shader, 0.01f, null); region.page = page; return(region); }
public void Load(AtlasPage page, String path) { String name = Path.GetFileNameWithoutExtension(path); Material material = null; foreach (Material other in atlasAsset.materials) { if (other.mainTexture.name == name) { material = other; break; } } if (material == null) { Debug.LogWarning("Material with texture name \"" + name + "\" not found for atlas asset: " + atlasAsset.name, atlasAsset); return; } page.rendererObject = material; page.width = material.mainTexture.width; page.height = material.mainTexture.height; }
private static AtlasRegion UVRectToAtlasRegion(Rect uvRect, string name, AtlasPage page, float offsetX, float offsetY, bool rotate) { Rect rect = UVRectToTextureRect(uvRect, page.width, page.height); Rect rect2 = rect.SpineUnityFlipRect(page.height); int x = (int)rect2.x; int y = (int)rect2.y; int num; int num2; if (rotate) { num = (int)rect2.height; num2 = (int)rect2.width; } else { num = (int)rect2.width; num2 = (int)rect2.height; } AtlasRegion atlasRegion = new AtlasRegion(); atlasRegion.page = page; atlasRegion.name = name; atlasRegion.u = uvRect.xMin; atlasRegion.u2 = uvRect.xMax; atlasRegion.v = uvRect.yMax; atlasRegion.v2 = uvRect.yMin; atlasRegion.index = -1; atlasRegion.width = num; atlasRegion.originalWidth = num; atlasRegion.height = num2; atlasRegion.originalHeight = num2; atlasRegion.offsetX = offsetX; atlasRegion.offsetY = offsetY; atlasRegion.x = x; atlasRegion.y = y; atlasRegion.rotate = rotate; return(atlasRegion); }
/// <summary> /// 通过Texture2D创建AtlasRegion /// </summary> /// <returns>The atlas region by texture.</returns> /// <param name="texture">Texture.</param> /// <param name="shader">Shader.</param> /// <param name="scale">Scale.</param> /// <param name="material">Material.</param> public static AtlasRegion GetAtlasRegionByTexture(Texture2D texture, Shader shader, float scale, Material material = null) { Material tempMaterial = new Material(shader); if (material != null) { tempMaterial.CopyPropertiesFromMaterial(material); tempMaterial.shaderKeywords = material.shaderKeywords; } tempMaterial.mainTexture = texture; AtlasPage page = GetAtlasPageByMaterial(tempMaterial); float width = texture.width; float height = texture.height; AtlasRegion atlasRegion = new AtlasRegion(); atlasRegion.name = texture.name; atlasRegion.index = -1; atlasRegion.rotate = false; Vector2 boundsMin = Vector2.zero, boundsMax = new Vector2(width, height) * scale; atlasRegion.width = (int)width; atlasRegion.originalWidth = (int)width; atlasRegion.height = (int)height; atlasRegion.originalHeight = (int)height; atlasRegion.offsetX = width * (0.5f - InverseLerp(boundsMin.x, boundsMax.x, 0)); atlasRegion.offsetY = height * (0.5f - InverseLerp(boundsMin.y, boundsMax.y, 0)); // Use the full area of the texture. atlasRegion.u = 0; atlasRegion.v = 1; atlasRegion.u2 = 1; atlasRegion.v2 = 0; atlasRegion.x = 0; atlasRegion.y = 0; atlasRegion.page = page; return(atlasRegion); }
public void Load(AtlasPage page, string path) { var frameNode = this.TopNode.FindNodeByPath(path); if (frameNode == null || frameNode.Value == null) { return; } //处理uol while (frameNode.Value is Wz_Uol) { frameNode = ((Wz_Uol)frameNode.Value).HandleUol(frameNode); } //寻找link var linkNode = frameNode.GetLinkedSourceNode(PluginManager.FindWz); //加载资源 var texture = BaseLoader.Load <Texture2D>(linkNode); page.rendererObject = texture; page.width = texture.Width; page.height = texture.Height; }
private static AtlasRegion UVRectToAtlasRegion(Rect uvRect, string name, AtlasPage page, float offsetX, float offsetY, bool rotate) { int height; int width; Rect rect2 = UVRectToTextureRect(uvRect, page.width, page.height).SpineUnityFlipRect(page.height); int x = (int)rect2.x; int y = (int)rect2.y; if (rotate) { height = (int)rect2.height; width = (int)rect2.width; } else { height = (int)rect2.width; width = (int)rect2.height; } return(new AtlasRegion { page = page, name = name, u = uvRect.xMin, u2 = uvRect.xMax, v = uvRect.yMax, v2 = uvRect.yMin, index = -1, width = height, originalWidth = height, height = width, originalHeight = width, offsetX = offsetX, offsetY = offsetY, x = x, y = y, rotate = rotate }); }
public static AtlasRegion ToAtlasRegion(this Texture2D t, Shader shader, float scale = 0.01f, Material materialPropertySource = null) { Material material = new Material(shader); if (materialPropertySource != null) { material.CopyPropertiesFromMaterial(materialPropertySource); material.shaderKeywords = materialPropertySource.shaderKeywords; } material.mainTexture = t; AtlasPage page = material.ToSpineAtlasPage(); float num = t.width; float num2 = t.height; AtlasRegion atlasRegion = new AtlasRegion(); atlasRegion.name = t.name; atlasRegion.index = -1; atlasRegion.rotate = false; Vector2 zero = Vector2.zero; Vector2 vector = new Vector2(num, num2) * scale; atlasRegion.width = (int)num; atlasRegion.originalWidth = (int)num; atlasRegion.height = (int)num2; atlasRegion.originalHeight = (int)num2; atlasRegion.offsetX = num * (0.5f - InverseLerp(zero.x, vector.x, 0f)); atlasRegion.offsetY = num2 * (0.5f - InverseLerp(zero.y, vector.y, 0f)); atlasRegion.u = 0f; atlasRegion.v = 1f; atlasRegion.u2 = 1f; atlasRegion.v2 = 0f; atlasRegion.x = 0; atlasRegion.y = 0; atlasRegion.page = page; return(atlasRegion); }
public static AtlasRegion ToAtlasRegion(this Texture2D t, Shader shader, float scale = 0.01f, Material materialPropertySource = null) { Material m = new Material(shader); if (materialPropertySource != null) { m.CopyPropertiesFromMaterial(materialPropertySource); m.shaderKeywords = materialPropertySource.shaderKeywords; } m.mainTexture = t; AtlasPage page = m.ToSpineAtlasPage(); float width = t.width; float height = t.height; AtlasRegion region = new AtlasRegion { name = t.name, index = -1, rotate = false }; Vector2 zero = Vector2.zero; Vector2 vector2 = new Vector2(width, height) * scale; region.width = (int)width; region.originalWidth = (int)width; region.height = (int)height; region.originalHeight = (int)height; region.offsetX = width * (0.5f - InverseLerp(zero.x, vector2.x, 0f)); region.offsetY = height * (0.5f - InverseLerp(zero.y, vector2.y, 0f)); region.u = 0f; region.v = 1f; region.u2 = 1f; region.v2 = 0f; region.x = 0; region.y = 0; region.page = page; return(region); }
/// <summary> /// Creates a new Spine.AtlasPage from a UnityEngine.Material. If the material has a preassigned texture, the page width and height will be set.</summary> public static AtlasPage ToSpineAtlasPage (this Material m) { var newPage = new AtlasPage { rendererObject = m, name = m.name }; var t = m.mainTexture; if (t != null) { newPage.width = t.width; newPage.height = t.height; } return newPage; }
/// <summary> /// Creates a RegionAttachment based on a sprite. This method creates a real, usable AtlasRegion. That AtlasRegion uses the AtlasPage provided./// </summary> public static RegionAttachment ToRegionAttachment (this Sprite sprite, AtlasPage page) { if (sprite == null) throw new System.ArgumentNullException("sprite"); if (page == null) throw new System.ArgumentNullException("page"); var region = sprite.ToAtlasRegion(page); var unitsPerPixel = 1f / sprite.pixelsPerUnit; return region.ToRegionAttachment(sprite.name, unitsPerPixel); }
/// <summary> /// Creates a Spine.AtlasRegion from a UnityEngine.Sprite.</summary> public static AtlasRegion ToAtlasRegion (this Sprite s, AtlasPage page) { if (page == null) throw new System.ArgumentNullException("page", "page cannot be null. AtlasPage determines which texture region belongs and how it should be rendered. You can use material.ToSpineAtlasPage() to get a shareable AtlasPage from a Material, or use the sprite.ToAtlasRegion(material) overload."); var region = s.ToAtlasRegion(); region.page = page; return region; }
/// <summary> /// Creates a new Spine AtlasRegion according to a Unity UV Rect (x-right, y-up, uv-normalized).</summary> static AtlasRegion UVRectToAtlasRegion(Rect uvRect, AtlasRegion referenceRegion, AtlasPage page) { var tr = UVRectToTextureRect(uvRect, page.width, page.height); var rr = tr.SpineUnityFlipRect(page.height); int x = (int)rr.x, y = (int)rr.y; int w, h; if (referenceRegion.degrees == 90 || referenceRegion.degrees == 270) { w = (int)rr.height; h = (int)rr.width; } else { w = (int)rr.width; h = (int)rr.height; } int originalW = Mathf.RoundToInt((float)w * ((float)referenceRegion.originalWidth / (float)referenceRegion.width)); int originalH = Mathf.RoundToInt((float)h * ((float)referenceRegion.originalHeight / (float)referenceRegion.height)); int offsetX = Mathf.RoundToInt((float)referenceRegion.offsetX * ((float)w / (float)referenceRegion.width)); int offsetY = Mathf.RoundToInt((float)referenceRegion.offsetY * ((float)h / (float)referenceRegion.height)); if (referenceRegion.degrees == 270) { w = (int)rr.width; h = (int)rr.height; } float u = uvRect.xMin; float u2 = uvRect.xMax; float v = uvRect.yMax; float v2 = uvRect.yMin; return(new AtlasRegion { page = page, name = referenceRegion.name, u = u, u2 = u2, v = v, v2 = v2, index = -1, width = w, originalWidth = originalW, height = h, originalHeight = originalH, offsetX = offsetX, offsetY = offsetY, x = x, y = y, rotate = referenceRegion.rotate, degrees = referenceRegion.degrees }); }
public void Load(AtlasPage page, String path) { page.width = material.mainTexture.width; page.height = material.mainTexture.height; }
/// <summary> /// Creates a new Spine AtlasRegion according to a Unity UV Rect (x-right, y-up, uv-normalized).</summary> static AtlasRegion UVRectToAtlasRegion (Rect uvRect, string name, AtlasPage page, float offsetX, float offsetY, bool rotate) { var tr = UVRectToTextureRect(uvRect, page.width, page.height); var rr = tr.SpineUnityFlipRect(page.height); int w = (int)rr.width, h = (int)rr.height, x = (int)rr.x, y = (int)rr.y; return new AtlasRegion { page = page, name = name, u = uvRect.xMin, u2 = uvRect.xMax, v = uvRect.yMax, v2 = uvRect.yMin, index = -1, width = w, originalWidth = w, height = h, originalHeight = h, offsetX = offsetX, offsetY = offsetY, x = x, y = y, rotate = rotate }; }