Пример #1
0
        /// <summary>
        /// 组合材质球
        /// </summary>
        /// <param name="graphics"></param>
        /// <param name="trisArray"></param>
        /// <param name="address"></param>
        /// <param name="offsets"></param>
        /// <param name="len"></param>
        /// <param name="clip"></param>
        public void CombinationMaterial(HGraphics graphics, int[] trisArray, ArrayInfo[] address, int[] offsets, int len, ref Vector4 clip)
        {
            int id = graphics.MatID;

            if (id == 0)//使用默认材质球
            {
                if (trisArray != null)
                {
                    bool mask = graphics.Mask;
                    for (int i = 0; i < len; i++)
                    {
                        if (CombinationMaterial(graphics.textures[i], graphics.texIds[i], graphics.fillColors[i], ref offsets[i], ref clip, mask))
                        {
                            int s = address[i].Start;
                            int l = address[i].Length;
                            for (int j = 0; j < l; j++)
                            {
                                tmpMesh.Add(trisArray[s]);
                                s++;
                            }
                        }
                        else
                        {
                            if (max > 0)
                            {
                                CompeleteSub();
                            }
                            int s = address[i].Start;
                            int l = address[i].Length;
                            for (int j = 0; j < l; j++)
                            {
                                tmpMesh.Add(trisArray[s]);
                                s++;
                            }
                        }
                        mask = false;
                    }
                }
            }
            else//使用自定义材质球
            {
                if (max > -1)
                {
                    CompeleteSub();
                }
                for (int i = 0; i < len; i++)
                {
                    int s = address[i].Start;
                    int l = address[i].Length;
                    for (int j = 0; j < l; j++)
                    {
                        tmpMesh.Add(trisArray[s]);
                        s++;
                    }
                }
                CombinationMaterial(graphics.Material, id, ref clip);
            }
        }
Пример #2
0
        protected unsafe void LoadHGraphics(FakeStruct fake, HGraphics tar)
        {
            HGraphicsData *src    = (HGraphicsData *)fake.ip;
            var            buffer = fake.buffer;

            asset       = buffer.GetData(src->asset) as string;
            MainTexture = buffer.GetData(src->MainTexture) as string;
            if (MainTexture != null)
            {
                tar.MainTexture = ElementAsset.FindTexture(asset, MainTexture);
            }
            else
            {
                tar.MainTexture = null;
            }
            STexture = buffer.GetData(src->STexture) as string;
            if (STexture != null)
            {
                tar.STexture = ElementAsset.FindTexture(asset, STexture);
            }
            else
            {
                tar.STexture = null;
            }
            TTexture = buffer.GetData(src->TTexture) as string;
            if (TTexture != null)
            {
                tar.TTexture = ElementAsset.FindTexture(asset, TTexture);
            }
            else
            {
                TTexture = null;
            }
            FTexture = buffer.GetData(src->FTexture) as string;
            if (FTexture != null)
            {
                tar.FTexture = ElementAsset.FindTexture(asset, FTexture);
            }
            else
            {
                FTexture = null;
            }
            shader = buffer.GetData(src->shader) as string;
            if (shader != null)
            {
                tar.Material = new Material(Shader.Find(shader));
            }
            else
            {
                tar.Material = null;
            }
            tar.m_color       = src->color;
            tar.uvrect        = src->uvRect;
            tar.Shadow        = src->Shadow;
            tar.shadowOffsset = src->shadowOffsset;
            tar.shadowColor   = src->shadowColor;
        }
Пример #3
0
        protected unsafe void SaveHGraphics(FakeStruct fake, HGraphics src)
        {
            HGraphicsData *tar    = (HGraphicsData *)fake.ip;
            var            buffer = fake.buffer;
            var            tex    = src.MainTexture;

            if (tex != null)
            {
                var an = ElementAsset.TxtureFormAsset(tex.name);
                if (an != null)
                {
                    tar->asset = buffer.AddData(an);
                }
                tar->MainTexture = buffer.AddData(tex.name);
            }
            tex = src.STexture;
            if (tex != null)
            {
                var an = ElementAsset.TxtureFormAsset(tex.name);
                if (an != null)
                {
                    tar->asset = buffer.AddData(an);
                }
                tar->STexture = buffer.AddData(tex.name);
            }
            tex = src.TTexture;
            if (tex != null)
            {
                var an = ElementAsset.TxtureFormAsset(tex.name);
                if (an != null)
                {
                    tar->asset = buffer.AddData(an);
                }
                tar->TTexture = buffer.AddData(tex.name);
            }
            tex = src.FTexture;
            if (tex != null)
            {
                var an = ElementAsset.TxtureFormAsset(tex.name);
                if (an != null)
                {
                    tar->asset = buffer.AddData(an);
                }
                tar->FTexture = buffer.AddData(tex.name);
            }
            if (src.m_material != null)
            {
                tar->shader = buffer.AddData(src.m_material.shader.name);
            }
            tar->color         = src.m_color;
            tar->uvRect        = src.uvrect;
            tar->Shadow        = src.Shadow;
            tar->shadowOffsset = src.shadowOffsset;
            tar->shadowColor   = src.shadowColor;
        }
Пример #4
0
        public void CombinationMaterial(HGraphics graphics, int[][] trisArray, int[] offsets, ref Vector4 clip)
        {
            int id = graphics.MatID;

#if UNITY_EDITOR
            var mat = graphics.Material;
            if (mat != null)
            {
                id = mat.GetInstanceID();
            }
#endif
            if (id == 0)//使用默认材质球
            {
                if (trisArray != null)
                {
                    int  c    = trisArray.Length;
                    bool mask = graphics.Mask;
                    for (int i = 0; i < c; i++)
                    {
                        if (CombinationMaterial(graphics.textures[i], graphics.texIds[i], graphics.fillColors[i], ref offsets[i], ref clip, mask))
                        {
                            CombinationMesh(trisArray[i]);
                        }
                        else
                        {
                            if (max > 0)
                            {
                                CompeleteSub();
                            }
                            CombinationMesh(trisArray[i]);
                        }
                        mask = false;
                    }
                }
            }
            else//使用自定义材质球
            {
                if (max > -1)
                {
                    CompeleteSub();
                }
                for (int i = 0; i < trisArray.Length; i++)
                {
                    CombinationMesh(trisArray[i]);
                }
                graphics.Material.SetTexture(tc[0], graphics.textures[0]);
                CombinationMaterial(graphics.Material, id, ref clip);
            }
        }
Пример #5
0
        /// <summary>
        /// 组合材质球
        /// </summary>
        /// <param name="graphics"></param>
        /// <param name="tris"></param>
        /// <param name="len"></param>
        /// <param name="offset"></param>
        /// <param name="clip"></param>
        public void CombinationMaterial(HGraphics graphics, int[] tris, int len, ref int offset, ref Vector4 clip)
        {
            int id = graphics.MatID;

            if (id == 0)//使用默认材质球
            {
                bool mask = graphics.Mask;
                if (CombinationMaterial(graphics.textures[0], graphics.texIds[0], graphics.fillColors[0], ref offset, ref clip, mask))
                {
                    for (int i = 0; i < len; i++)
                    {
                        tmpMesh.Add(tris[i]);
                    }
                }
                else
                {
                    if (max > 0)
                    {
                        CompeleteSub();
                    }
                    for (int i = 0; i < len; i++)
                    {
                        tmpMesh.Add(tris[i]);
                    }
                }
            }
            else//使用自定义材质球
            {
                if (max > -1)
                {
                    CompeleteSub();
                }
                for (int i = 0; i < len; i++)
                {
                    tmpMesh.Add(tris[i]);
                }
                CombinationMaterial(graphics.Material, id, ref clip);
            }
        }
Пример #6
0
        /// <summary>
        /// 组合材质球
        /// </summary>
        /// <param name="graphics"></param>
        /// <param name="t2d"></param>
        /// <param name="tris"></param>
        /// <param name="len"></param>
        /// <param name="offset"></param>
        public void CombinationMaterial(HGraphics graphics, Texture t2d, int[] tris, int len, ref int offset)
        {
            int id = graphics.MatID;

            if (id == 0)//使用默认材质球
            {
                if (CombinationMaterial(t2d, ref offset))
                {
                    for (int i = 0; i < len; i++)
                    {
                        tmpMesh.Add(tris[i]);
                    }
                }
                else
                {
                    if (max > 0)
                    {
                        CompeleteSub();
                    }
                    for (int i = 0; i < len; i++)
                    {
                        tmpMesh.Add(tris[i]);
                    }
                }
            }
            else//使用自定义材质球
            {
                if (max > -1)
                {
                    CompeleteSub();
                }
                for (int i = 0; i < len; i++)
                {
                    tmpMesh.Add(tris[i]);
                }
                CombinationMaterial(graphics.Material, id);
            }
        }
Пример #7
0
        public void CombinationMaterial(HGraphics graphics, int[] tris, ref int offset, ref Vector4 clip)
        {
            int id = graphics.MatID;

#if UNITY_EDITOR
            var mat = graphics.Material;
            if (mat != null)
            {
                id = mat.GetInstanceID();
            }
#endif
            if (id == 0)//使用默认材质球
            {
                bool mask = graphics.Mask;
                if (CombinationMaterial(graphics.textures[0], graphics.texIds[0], graphics.fillColors[0], ref offset, ref clip, mask))
                {
                    CombinationMesh(tris);
                }
                else
                {
                    if (max > 0)
                    {
                        CompeleteSub();
                    }
                    CombinationMesh(tris);
                }
            }
            else//使用自定义材质球
            {
                if (max > -1)
                {
                    CompeleteSub();
                }
                CombinationMesh(tris);
                graphics.Material.SetTexture(tc[0], graphics.textures[0]);
                CombinationMaterial(graphics.Material, id, ref clip);
            }
        }
Пример #8
0
        /// <summary>
        /// 添加阴影
        /// </summary>
        /// <param name="graphics"></param>
        /// <param name="canvas"></param>
        /// <param name="q"></param>
        /// <param name="scale"></param>
        /// <param name="o"></param>
        /// <param name="clip"></param>
        static void AddShadow(HGraphics graphics, HCanvas canvas, ref Quaternion q, ref Vector3 scale, ref Vector3 o, ref Vector4 clip, ref Vector2 center, ref Vector2 half)
        {
            var vs = canvas.vertex;
            var vc = vs.Count;
            int dc = graphics.vertInfo.DataCount;
            var os = graphics.shadowOffsset;

            if (dc > 0)
            {
                float   px  = (0.5f - graphics.Pivot.x) * graphics.SizeDelta.x + os.x;
                float   py  = (0.5f - graphics.Pivot.y) * graphics.SizeDelta.y + os.y;
                Vector2 uv2 = Vector2.zero;
                unsafe
                {
                    HVertex *vert = graphics.vertInfo.Addr;
                    for (int j = 0; j < dc; j++)
                    {
                        var tp = vert[j].position;//局部顶点
                        tp.x += px;
                        tp.y += py;
                        var t = q * tp;
                        t.x  *= scale.x;
                        t.y  *= scale.y;
                        t    += o;
                        t.z   = 0;
                        uv2.x = (t.x - center.x) / half.x * 0.001f + 0.5f;
                        uv2.y = (t.y - center.y) / half.y * 0.001f + 0.5f;
                        vs.Add(t);
                        canvas.colors.Add(graphics.shadowColor);
                        canvas.uv.Add(vert[j].uv);
                        canvas.uv2.Add(uv2);
                        canvas.uv3.Add(vert[j].uv3);
                        canvas.uv4.Add(vert[j].uv4);
                    }
                }
                AddTris(graphics, canvas, vc, dc);
            }
        }
Пример #9
0
        /// <summary>
        /// 添加阴影
        /// </summary>
        /// <param name="graphics"></param>
        /// <param name="canvas"></param>
        /// <param name="q"></param>
        /// <param name="scale"></param>
        /// <param name="o"></param>
        /// <param name="clip"></param>
        static void AddShadow(HGraphics graphics, HCanvas canvas, ref Quaternion q, ref Vector3 scale, ref Vector3 o, ref Vector4 clip)
        {
            var vs = canvas.vertex;
            var vc = vs.Count;
            int dc = graphics.vertInfo.DataCount;
            var os = graphics.shadowOffsset;

            if (dc > 0)
            {
                float   px  = (0.5f - graphics.Pivot.x) * graphics.SizeDelta.x + os.x;
                float   py  = (0.5f - graphics.Pivot.y) * graphics.SizeDelta.y + os.y;
                Vector2 uv2 = Vector2.zero;
                unsafe
                {
                    HVertex *vert = graphics.vertInfo.Addr;
                    for (int j = 0; j < dc; j++)
                    {
                        var tp = vert[j].position;//局部顶点
                        tp.x += px;
                        tp.y += py;
                        var t = q * tp;
                        t.x  *= scale.x;
                        t.y  *= scale.y;
                        t    += o;
                        t.z   = 0;
                        uv2.x = (t.x + 10000) / 20000;
                        uv2.y = (t.y + 10000) / 20000;
                        vs.Add(t);
                        canvas.colors.Add(graphics.shadowColor);
                        canvas.uv.Add(vert[j].uv);
                        canvas.uv2.Add(uv2);
                        canvas.uv3.Add(vert[j].uv3);
                        canvas.uv4.Add(vert[j].uv4);
                    }
                }
                if (graphics.tris != null)
                {
                    int tid = 0;
                    var src = graphics.tris;
                    int len = src.Length;
                    if (len > 0)
                    {
                        for (int k = 0; k < len; k++)
                        {
                            TriBuffer[k] = src[k] + vc;
                        }
                        canvas.MatCollector.CombinationMaterial(graphics, TriBuffer, len, ref tid, ref clip);
                    }
                    AddUV1(canvas, tid, dc);
                }
                else if (graphics.trisInfo.DataCount > 0 | graphics.trisInfo2.DataCount > 0)
                {
                    int l  = 0;
                    int tc = graphics.trisInfo.DataCount;
                    if (tc > 0)
                    {
                        unsafe
                        {
                            int *ip = graphics.trisInfo.Addr;
                            for (int k = 0; k < tc; k++)
                            {
                                TriBuffer[k] = ip[k] + vc;
                            }
                        }
                        l = 1;
                    }
                    Arrays[0].Length = tc;
                    int tc2 = graphics.trisInfo2.DataCount;
                    if (tc2 > 0)
                    {
                        int ks = tc;
                        unsafe
                        {
                            int *ip = graphics.trisInfo2.Addr;
                            for (int k = 0; k < tc2; k++)
                            {
                                TriBuffer[ks] = ip[k] + vc;
                                ks++;
                            }
                        }
                        Arrays[1].Start  = tc;
                        Arrays[1].Length = tc2;
                        l = 2;
                    }
                    canvas.MatCollector.CombinationMaterial(graphics, TriBuffer, Arrays, IDBuffer, l, ref clip);
                    unsafe
                    {
                        HVertex *hv = graphics.vertInfo.Addr;
                        AddUV1(canvas, IDBuffer, hv, dc, l);
                    }
                }
                else
                {
                    AddUV1(canvas, 0, dc);
                }
            }
        }
Пример #10
0
        /// <summary>
        /// 组合材质球
        /// </summary>
        /// <param name="graphics"></param>
        /// <param name="trisArray"></param>
        /// <param name="address"></param>
        /// <param name="offsets"></param>
        /// <param name="len"></param>
        public void CombinationMaterial(HGraphics graphics, int[] trisArray, ArrayInfo[] address, int[] offsets, int len)
        {
            tmp[0] = graphics.MainTexture;
            tmp[1] = graphics.STexture;
            tmp[2] = graphics.TTexture;
            tmp[3] = graphics.FTexture;
            int id = graphics.MatID;

            if (id == 0)//使用默认材质球
            {
                if (trisArray != null)
                {
                    for (int i = 0; i < len; i++)
                    {
                        int l = address[i].Length;
                        if (l > 0)
                        {
                            if (CombinationMaterial(tmp[i], ref offsets[i]))
                            {
                                int s = address[i].Start;
                                for (int j = 0; j < l; j++)
                                {
                                    tmpMesh.Add(trisArray[s]);
                                    s++;
                                }
                            }
                            else
                            {
                                if (max > 0)
                                {
                                    CompeleteSub();
                                }
                                int s = address[i].Start;
                                for (int j = 0; j < l; j++)
                                {
                                    tmpMesh.Add(trisArray[s]);
                                    s++;
                                }
                            }
                        }
                    }
                }
            }
            else//使用自定义材质球
            {
                if (max > -1)
                {
                    CompeleteSub();
                }
                for (int i = 0; i < len; i++)
                {
                    int s = address[i].Start;
                    int l = address[i].Length;
                    for (int j = 0; j < l; j++)
                    {
                        tmpMesh.Add(trisArray[s]);
                        s++;
                    }
                }
                CombinationMaterial(graphics.Material, id);
            }
        }
Пример #11
0
        static void AddTris(HGraphics graphics, HCanvas canvas, int vc, int dc)
        {
            int max = vc + dc;

            if (graphics.tris != null)
            {
                int tid = 0;
                var src = graphics.tris;
                int len = src.Length;
                if (len > 0)
                {
                    for (int k = 0; k < len; k++)
                    {
                        int index = TriBuffer[k] = src[k] + vc;
                        if (index >= max)
                        {
                            Debug.LogError("数组超标");
                        }
                    }
                    canvas.MatCollector.CombinationMaterial(graphics, graphics.MainTexture, TriBuffer, len, ref tid);
                }
                AddUV1(canvas, tid, ref graphics.vertInfo);
            }
            else if (graphics.trisInfo.DataCount > 0 | graphics.trisInfo1.DataCount > 0 | graphics.trisInfo2.DataCount > 0)
            {
                Arrays[0].Length = 0;
                Arrays[1].Length = 0;
                Arrays[2].Length = 0;
                int l  = 0;
                int tc = graphics.trisInfo.DataCount;
                if (tc > 0)
                {
                    unsafe
                    {
                        int *ip = graphics.trisInfo.Addr;
                        for (int k = 0; k < tc; k++)
                        {
                            TriBuffer[k] = ip[k] + vc;
                        }
                    }
                    l = 1;
                }
                Arrays[0].Length = tc;
                int tc2 = graphics.trisInfo1.DataCount;
                if (tc2 > 0)
                {
                    int ks = tc;
                    unsafe
                    {
                        int *ip = graphics.trisInfo1.Addr;
                        for (int k = 0; k < tc2; k++)
                        {
                            TriBuffer[ks] = ip[k] + vc;
                            ks++;
                        }
                    }
                    Arrays[1].Start  = tc;
                    Arrays[1].Length = tc2;
                    l = 2;
                }
                int tc3 = graphics.trisInfo2.DataCount;
                if (tc3 > 0)
                {
                    int ks = tc + tc2;
                    unsafe
                    {
                        int *ip = graphics.trisInfo2.Addr;
                        for (int k = 0; k < tc3; k++)
                        {
                            TriBuffer[ks] = ip[k] + vc;
                            ks++;
                        }
                    }
                    Arrays[2].Start  = tc + tc2;
                    Arrays[2].Length = tc3;
                    l = 3;
                }
                canvas.MatCollector.CombinationMaterial(graphics, TriBuffer, Arrays, IDBuffer, l);
                unsafe
                {
                    HVertex *hv = graphics.vertInfo.Addr;
                    AddUV1(canvas, IDBuffer, hv, dc, l);
                }
            }
            else
            {
                AddUV1(canvas, 0, ref graphics.vertInfo);
            }
        }
Пример #12
0
        static void AddShadow(HGraphics graphics, HCanvas canvas, ref Quaternion q, ref Vector3 scale, ref Vector3 o, ref Vector4 clip)
        {
            var vs   = canvas.vertex;
            var vc   = vs.Count;
            var vert = graphics.vertices;
            var os   = graphics.shadowOffsset;

            if (vert != null)
            {
                float   px  = (0.5f - graphics.Pivot.x) * graphics.SizeDelta.x + os.x;
                float   py  = (0.5f - graphics.Pivot.y) * graphics.SizeDelta.y + os.y;
                Vector2 uv2 = Vector2.zero;
                for (int j = 0; j < vert.Length; j++)
                {
                    var tp = vert[j].position;//局部顶点
                    tp.x += px;
                    tp.y += py;
                    var t = q * tp;
                    t.x  *= scale.x;
                    t.y  *= scale.y;
                    t    += o;
                    t.z   = 0;
                    uv2.x = (t.x + 10000) / 20000;
                    uv2.y = (t.y + 10000) / 20000;
                    vs.Add(t);
                    canvas.colors.Add(graphics.shadowColor);
                    canvas.uv.Add(vert[j].uv);
                    canvas.uv2.Add(uv2);
                    canvas.uv3.Add(vert[j].uv3);
                    canvas.uv4.Add(vert[j].uv4);
                }
                if (graphics.tris != null)
                {
                    int tid = 0;
                    var src = graphics.tris;
                    if (src.Length > 0)
                    {
                        int[] tmp = new int[src.Length];
                        for (int k = 0; k < tmp.Length; k++)
                        {
                            tmp[k] = src[k] + vc;
                        }
                        canvas.MatCollector.CombinationMaterial(graphics, tmp, ref tid, ref clip);
                    }
                    AddUV1(canvas, tid, vert.Length);
                }
                else if (graphics.subTris != null)
                {
                    var subs = graphics.subTris;
                    int l    = subs.Length;
                    if (l > 0)
                    {
                        int[]   ids = new int[l];
                        int[][] buf = new int[l][];
                        for (int i = 0; i < l; i++)
                        {
                            var   src = subs[i];
                            int[] tmp = new int[src.Length];
                            for (int k = 0; k < tmp.Length; k++)
                            {
                                tmp[k] = src[k] + vc;
                            }
                            buf[i] = tmp;
                        }
                        canvas.MatCollector.CombinationMaterial(graphics, buf, ids, ref clip);
                        AddUV1(canvas, ids, vert);
                    }
                    else
                    {
                        AddUV1(canvas, 0, vert.Length);
                    }
                }
                else
                {
                    AddUV1(canvas, 0, vert.Length);
                }
            }
        }
Пример #13
0
        protected void LoadHGraphics(FakeStruct fake, HGraphics tar)
        {
            HGraphicsData tmp = new HGraphicsData();

            unsafe
            {
                HGraphicsData *src = &tmp;
                GraphicsHelper.LoadData((byte *)src, fake.ip);
                var buffer = fake.buffer;
                asset       = buffer.GetData(src->asset) as string;
                MainTexture = buffer.GetData(src->MainTexture) as string;
                if (MainTexture != null)
                {
                    tar.MainTexture = ElementAsset.FindTexture(asset, MainTexture);
                }
                else
                {
                    tar.MainTexture = null;
                }
                STexture = buffer.GetData(src->STexture) as string;
                if (STexture != null)
                {
                    tar.STexture = ElementAsset.FindTexture(asset, STexture);
                }
                else
                {
                    tar.STexture = null;
                }
                TTexture = buffer.GetData(src->TTexture) as string;
                if (TTexture != null)
                {
                    tar.TTexture = ElementAsset.FindTexture(asset, TTexture);
                }
                else
                {
                    TTexture = null;
                }
                FTexture = buffer.GetData(src->FTexture) as string;
                if (FTexture != null)
                {
                    tar.FTexture = ElementAsset.FindTexture(asset, FTexture);
                }
                else
                {
                    FTexture = null;
                }
                shader = buffer.GetData(src->shader) as string;
                if (shader != null)
                {
                    tar.Material = new Material(Shader.Find(shader));
                }
                else
                {
                    tar.Material = null;
                }
            }
            tar.m_color       = tmp.color;
            tar.uvrect        = tmp.uvRect;
            tar.Shadow        = tmp.Shadow;
            tar.shadowOffsset = tmp.shadowOffsset;
            tar.shadowColor   = tmp.shadowColor;
            tar.tris          = null;
        }