Exemplo n.º 1
0
        private void ReadCurveData(ImportedKeyframedAnimation iAnim, AnimationClipBindingConstant m_ClipBindingConstant, int index, float time, float[] data, int offset, ref int curveIndex)
        {
            var binding = m_ClipBindingConstant.FindBinding(index);

            if (binding.path == 0)
            {
                curveIndex++;
                return;
            }

            var path  = FixBonePath(GetPathFromHash(binding.path));
            var track = iAnim.FindTrack(path);

            switch (binding.attribute)
            {
            case 1:
                track.Translations.Add(new ImportedKeyframe <Vector3>(time, new Vector3
                                                                      (
                                                                          -data[curveIndex++ + offset],
                                                                          data[curveIndex++ + offset],
                                                                          data[curveIndex++ + offset]
                                                                      )));
                break;

            case 2:
                var value = Fbx.QuaternionToEuler(new Quaternion
                                                  (
                                                      data[curveIndex++ + offset],
                                                      -data[curveIndex++ + offset],
                                                      -data[curveIndex++ + offset],
                                                      data[curveIndex++ + offset]
                                                  ));
                track.Rotations.Add(new ImportedKeyframe <Vector3>(time, value));
                break;

            case 3:
                track.Scalings.Add(new ImportedKeyframe <Vector3>(time, new Vector3
                                                                  (
                                                                      data[curveIndex++ + offset],
                                                                      data[curveIndex++ + offset],
                                                                      data[curveIndex++ + offset]
                                                                  )));
                break;

            case 4:
                track.Rotations.Add(new ImportedKeyframe <Vector3>(time, new Vector3
                                                                   (
                                                                       data[curveIndex++ + offset],
                                                                       -data[curveIndex++ + offset],
                                                                       -data[curveIndex++ + offset]
                                                                   )));
                break;

            default:
                //track.Curve.Add(new ImportedKeyframe<float>(time, data[curveIndex++]));
                curveIndex++;
                break;
            }
        }
Exemplo n.º 2
0
        private void ReadCurveData(ImportedKeyframedAnimation iAnim, AnimationClipBindingConstant m_ClipBindingConstant, int index, float time, float[] data, int offset, ref int curveIndex)
        {
            var binding = m_ClipBindingConstant.FindBinding(index);

            if (binding.typeID == ClassIDType.SkinnedMeshRenderer) //BlendShape
            {
                var channelName = GetChannelNameFromHash(binding.attribute);
                if (string.IsNullOrEmpty(channelName))
                {
                    curveIndex++;
                    return;
                }
                int dotPos = channelName.IndexOf('.');
                if (dotPos >= 0)
                {
                    channelName = channelName.Substring(dotPos + 1);
                }

                var bPath = FixBonePath(GetPathFromHash(binding.path));
                if (string.IsNullOrEmpty(bPath))
                {
                    bPath = GetPathByChannelName(channelName);
                }
                var bTrack = iAnim.FindTrack(bPath);
                bTrack.BlendShape             = new ImportedBlendShape();
                bTrack.BlendShape.ChannelName = channelName;
                bTrack.BlendShape.Keyframes.Add(new ImportedKeyframe <float>(time, data[curveIndex++ + offset]));
            }
            else if (binding.typeID == ClassIDType.Transform)
            {
                var path  = FixBonePath(GetPathFromHash(binding.path));
                var track = iAnim.FindTrack(path);

                switch (binding.attribute)
                {
                case 1:
                    track.Translations.Add(new ImportedKeyframe <Vector3>(time, new Vector3
                                                                          (
                                                                              -data[curveIndex++ + offset],
                                                                              data[curveIndex++ + offset],
                                                                              data[curveIndex++ + offset]
                                                                          )));
                    break;

                case 2:
                    var value = Fbx.QuaternionToEuler(new Quaternion
                                                      (
                                                          data[curveIndex++ + offset],
                                                          -data[curveIndex++ + offset],
                                                          -data[curveIndex++ + offset],
                                                          data[curveIndex++ + offset]
                                                      ));
                    track.Rotations.Add(new ImportedKeyframe <Vector3>(time, value));
                    break;

                case 3:
                    track.Scalings.Add(new ImportedKeyframe <Vector3>(time, new Vector3
                                                                      (
                                                                          data[curveIndex++ + offset],
                                                                          data[curveIndex++ + offset],
                                                                          data[curveIndex++ + offset]
                                                                      )));
                    break;

                case 4:
                    track.Rotations.Add(new ImportedKeyframe <Vector3>(time, new Vector3
                                                                       (
                                                                           data[curveIndex++ + offset],
                                                                           -data[curveIndex++ + offset],
                                                                           -data[curveIndex++ + offset]
                                                                       )));
                    break;

                default:
                    curveIndex++;
                    break;
                }
            }
            else
            {
                curveIndex++;
            }
        }
Exemplo n.º 3
0
        private void ReadCurveData(ImportedKeyframedAnimation iAnim, AnimationClipBindingConstant m_ClipBindingConstant, int index, float time, float[] data, int offset, ref int curveIndex)
        {
            var binding = m_ClipBindingConstant.FindBinding(index);

            if (binding.path == 0)
            {
                curveIndex++;
                return;
            }
            var boneName = GetNameFromHashes(binding.path, binding.attribute);
            var track    = iAnim.FindTrack(boneName);

            if (track == null)
            {
                track = new ImportedAnimationKeyframedTrack {
                    Name = boneName
                };
                iAnim.TrackList.Add(track);
            }

            switch (binding.attribute)
            {
            case 1:
                track.Translations.Add(new ImportedKeyframe <Vector3>(time, new Vector3
                                                                      (
                                                                          -data[curveIndex++ + offset],
                                                                          data[curveIndex++ + offset],
                                                                          data[curveIndex++ + offset]
                                                                      )));
                break;

            case 2:
                var value = Fbx.QuaternionToEuler(new Quaternion
                                                  (
                                                      data[curveIndex++ + offset],
                                                      -data[curveIndex++ + offset],
                                                      -data[curveIndex++ + offset],
                                                      data[curveIndex++ + offset]
                                                  ));
                track.Rotations.Add(new ImportedKeyframe <Vector3>(time, value));
                break;

            case 3:
                track.Scalings.Add(new ImportedKeyframe <Vector3>(time, new Vector3
                                                                  (
                                                                      data[curveIndex++ + offset],
                                                                      data[curveIndex++ + offset],
                                                                      data[curveIndex++ + offset]
                                                                  )));
                break;

            case 4:
                track.Rotations.Add(new ImportedKeyframe <Vector3>(time, new Vector3
                                                                   (
                                                                       data[curveIndex++ + offset],
                                                                       -data[curveIndex++ + offset],
                                                                       -data[curveIndex++ + offset]
                                                                   )));
                break;

            default:
                track.Curve.Add(new ImportedKeyframe <float>(time, data[curveIndex++]));
                break;
            }
        }