コード例 #1
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();
            }
        }
コード例 #2
0
        public static void FromStruct(SkeletalAnim anim, SkeletalAnimHelper animJson)
        {
            anim.Name        = animJson.Name;
            anim.Baked       = animJson.Baked;
            anim.Loop        = animJson.Loop;
            anim.FrameCount  = animJson.FrameCount;
            anim.Baked       = animJson.Baked;
            anim.FlagsRotate = animJson.FlagsRotate;
            anim.FlagsScale  = animJson.FlagsScale;
            anim.BoneAnims   = new List <BoneAnim>();
            anim.BindIndices = new ushort[animJson.BoneAnims.Count];
            anim.UserData    = UserDataConvert.Convert(animJson.UserData);

            foreach (var boneAnimJson in animJson.BoneAnims)
            {
                BoneAnim boneAnim = new BoneAnim();
                anim.BoneAnims.Add(boneAnim);

                //Always these indices
                boneAnim.Name               = boneAnimJson.Name;
                boneAnim.BeginRotate        = 3;
                boneAnim.BeginTranslate     = 6;
                boneAnim.BeginBaseTranslate = 7;
                Vector4F rotation = boneAnimJson.BaseData.Rotate;
                if (animJson.UseDegrees && animJson.FlagsRotate == SkeletalAnimFlagsRotate.EulerXYZ)
                {
                    rotation = new Vector4F(
                        rotation.X * CurveAnimHelper.Deg2Rad,
                        rotation.Y * CurveAnimHelper.Deg2Rad,
                        rotation.Z * CurveAnimHelper.Deg2Rad,
                        rotation.W);
                }
                boneAnim.BaseData = new BoneAnimData()
                {
                    Flags     = boneAnimJson.BaseData.Flags,
                    Rotate    = rotation,
                    Translate = boneAnimJson.BaseData.Translate,
                    Scale     = boneAnimJson.BaseData.Scale,
                };

                boneAnim.FlagsTransform |= BoneAnimFlagsTransform.Identity;
                if (boneAnimJson.UseBaseTranslation)
                {
                    boneAnim.FlagsBase |= BoneAnimFlagsBase.Translate;
                }
                if (boneAnimJson.UseBaseRotation)
                {
                    boneAnim.FlagsBase |= BoneAnimFlagsBase.Rotate;
                }
                if (boneAnimJson.UseBaseScale)
                {
                    boneAnim.FlagsBase |= BoneAnimFlagsBase.Scale;
                }
                foreach (var curveJson in boneAnimJson.Curves)
                {
                    var target = (AnimTarget)Enum.Parse(typeof(AnimTarget), curveJson.Target);

                    var curve = CurveAnimHelper.GenerateCurve(curveJson, (uint)target,
                                                              curveJson.Target.Contains("Rotate") && animJson.UseDegrees);
                    boneAnim.Curves.Add(curve);
                    boneAnim.FlagsCurve = SetCurveTarget(target);
                }
                boneAnim.CalculateTransformFlags();
                boneAnim.ApplySegmentScaleCompensate = boneAnimJson.SegmentScaleCompensate;
            }
        }