Пример #1
0
        public static MaterialAnim FromStruct(MaterialAnimHelper matAnim)
        {
            MaterialAnim anim = new MaterialAnim();

            FromStruct(anim, matAnim);
            return(anim);
        }
Пример #2
0
        public static void FromStruct(MaterialAnim anim, MaterialAnimHelper animJson)
        {
            anim.TextureNames = new ResDict <TextureRef>();
            foreach (var tex in animJson.TextureList)
            {
                anim.TextureNames.Add(tex, new TextureRef()
                {
                    Name = tex
                });
            }

            anim.Name                 = animJson.Name;
            anim.Baked                = animJson.Baked;
            anim.Loop                 = animJson.Loop;
            anim.FrameCount           = animJson.FrameCount;
            anim.Baked                = animJson.Baked;
            anim.MaterialAnimDataList = new List <MaterialAnimData>();
            anim.BindIndices          = new ushort[animJson.MaterialAnims.Count];
            for (int i = 0; i < anim.BindIndices.Length; i++)
            {
                anim.BindIndices[i] = 65535;
            }

            anim.UserData = UserDataConvert.Convert(animJson.UserData);

            foreach (var matAnimJson in animJson.MaterialAnims)
            {
                MaterialAnimData matAnim = new MaterialAnimData();
                anim.MaterialAnimDataList.Add(matAnim);
                matAnim.Name                  = matAnimJson.Name;
                matAnim.ParamAnimInfos        = new List <ParamAnimInfo>();
                matAnim.PatternAnimInfos      = new List <PatternAnimInfo>();
                matAnim.ShaderParamCurveIndex = 0;
                List <ushort> texturePatternBase = new List <ushort>();

                foreach (var samplerInfo in matAnimJson.Samplers)
                {
                    var info = new PatternAnimInfo();
                    info.Name       = samplerInfo.Name;
                    info.CurveIndex = -1;

                    if (samplerInfo.Curve != null)
                    {
                        info.CurveIndex = (short)matAnim.Curves.Count;
                    }

                    matAnim.PatternAnimInfos.Add(info);
                    texturePatternBase.Add(samplerInfo.Constant);

                    if (samplerInfo.Curve != null)
                    {
                        matAnim.Curves.Add(CurveAnimHelper.GenerateCurve(samplerInfo.Curve, 0, false));
                    }
                }

                ushort curveIndex    = 0;
                ushort constantIndex = 0;

                foreach (var paramInfo in matAnimJson.Params)
                {
                    var info = new ParamAnimInfo();
                    info.BeginCurve      = curveIndex;
                    info.BeginConstant   = constantIndex;
                    info.ConstantCount   = (ushort)paramInfo.Constants.Count;
                    info.FloatCurveCount = (ushort)paramInfo.Curves.Count();
                    info.IntCurveCount   = 0;
                    info.Name            = paramInfo.Name;
                    matAnim.ParamAnimInfos.Add(info);

                    if (paramInfo.Curves.Count > 0)
                    {
                        matAnim.VisualConstantIndex = 0;
                    }

                    foreach (var curveJson in paramInfo.Curves)
                    {
                        uint target = uint.Parse(curveJson.Target);
                        matAnim.Curves.Add(CurveAnimHelper.GenerateCurve(curveJson, target, false));
                    }
                    foreach (var constJson in paramInfo.Constants)
                    {
                        matAnim.Constants.Add(constJson);
                    }

                    curveIndex    += (ushort)matAnim.Curves.Count;
                    constantIndex += (ushort)matAnim.Constants.Count;
                }
                matAnim.BaseDataList = texturePatternBase.ToArray();
            }
        }