public static REPEATDATA Create(Vector3 startPos, Vector3[] maxVS, Vector2 uvOffset, Vector2 atlasSize, Vector2[] atlasUvs) { /* * maxVS[0] maxVS[1] +--------- --+ | | | StartPos & uvOffset | +---------- | | | | | */ if (startPos.x < maxVS[0].x || startPos.y > maxVS[0].y) { throw new SystemException("Unexpected!"); } if (uvOffset.x < 0 || uvOffset.x > atlasSize.x || uvOffset.y < 0 || uvOffset.y > atlasSize.y) { throw new SystemException("Unexpected!"); } REPEATDATA d = new REPEATDATA(); d.vs[0] = startPos; d.vs[1] = startPos + (atlasSize.x - uvOffset.x) * Vector3.right; if (d.vs[1].x > maxVS[1].x) { d.vs[1] = startPos.y * Vector3.up + maxVS[1].x * Vector3.right; } d.vs[2] = startPos - atlasSize.y * Vector3.up; if (d.vs[2].y < maxVS[2].y) { d.vs[2] = startPos.x * Vector3.right + maxVS[2].y * Vector3.up; } d.vs[3] = d.vs[2].y * Vector3.up + d.vs[1].x * Vector3.right; float atlas_width = atlasUvs[1].x - atlasUvs[0].x; float atlas_height = atlasUvs[0].y - atlasUvs[2].y; d.uvs[0] = atlasUvs[0] + new Vector2(uvOffset.x / atlasSize.x * atlas_width, uvOffset.y / atlasSize.y * atlas_height); d.uvs[1] = d.uvs[0].y * Vector2.up + (d.uvs[0].x + ((d.vs[1].x - d.vs[0].x) / atlasSize.x * atlas_width)) * Vector2.right; d.uvs[2] = (d.uvs[0].y - ((d.vs[0].y - d.vs[2].y) / atlasSize.y * atlas_height)) * Vector2.up + d.uvs[0].x * Vector2.right; d.uvs[3] = d.uvs[2].y * Vector2.up + d.uvs[1].x * Vector2.right; return(d); }
public static void DrawAtlas_REPEAT(Vector2[] atlasUvs, Vector2 atlasSize, Vector2 offset, hgMesh.MeshSet meshSet, int boneIndex, Vector3[] vs, int colorIndex) { List <REPEATDATA> list = new List <REPEATDATA>(); Vector3 startPos = vs[0]; Vector2 uvOffset = Vector2.zero; { int ix = (int)offset.x % (int)atlasSize.x; int iy = (int)offset.y % (int)atlasSize.y; float x = ix > 0 ? atlasSize.x - ix : 0; float y = iy > 0 ? atlasSize.y - iy : 0; uvOffset = new Vector2(x, y); } const int loopmax = 1000; for (var i = 0; i <= loopmax; i++) { if (i == loopmax) { throw new SystemException("Unexpected! Too much Loop at DrawAtlas_REPEAT"); } REPEATDATA d = REPEATDATA.Create(startPos, vs, uvOffset, atlasSize, atlasUvs); list.Add(d); if (d.vs[3].x >= vs[3].x) { if (d.vs[3].y <= vs[3].y) { break; } startPos = d.vs[3].y * Vector3.up + vs[0].x * Vector3.right; } else { startPos = d.vs[1]; } } if (meshSet == null) { return; } foreach (var d in list) { int save_vsize = meshSet.vclist.Count; // Vertex meshSet.vlist.AddRange(d.vs); // Vcolor var ncolor = hglHtmlColor.IndexToVColor(colorIndex); ncolor.a = 17f / 64f - 1f / 128f; meshSet.vclist.AddRange(new Color[] { ncolor, ncolor, ncolor, ncolor, }); // Triangle meshSet.trilist.AddRange(new int[] { save_vsize, save_vsize + 1, save_vsize + 3 }); meshSet.trilist.AddRange(new int[] { save_vsize, save_vsize + 3, save_vsize + 2 }); /* uv * 0--1 | | | 2--3 | */ meshSet.uvlist.AddRange(d.uvs); // bone weights if (boneIndex < 0) { throw new SystemException("Unexpected!"); } meshSet.bwlist.Add(new BoneWeight() { boneIndex0 = boneIndex, weight0 = 1 }); // v[0] meshSet.bwlist.Add(new BoneWeight() { boneIndex0 = boneIndex, weight0 = 1 }); // v[1] meshSet.bwlist.Add(new BoneWeight() { boneIndex0 = boneIndex, weight0 = 1 }); // v[2] meshSet.bwlist.Add(new BoneWeight() { boneIndex0 = boneIndex, weight0 = 1 }); // v[3] } }