예제 #1
0
        public Animation GetAnimation(int frames, int bones, Span <byte> allData)
        {
            var header = JmadDataContainer.Create(allData);

            // Most animation data starts with a flat section, ignoring until I figure out why
            if (header.Type == JmadDataType.Flat)
            {
                allData = allData.Slice(header.TotalLength());
                header  = JmadDataContainer.Create(allData);
            }

            var frameData = new AnimationNodeTransform[frames, bones];

            for (int f = 0; f < frames; f++)
            {
                for (int b = 0; b < bones; b++)
                {
                    frameData[f, b] = new AnimationNodeTransform
                    {
                        Orientation = header.ReadOrientation(allData, f, b),
                        Translation = header.ReadTranslation(allData, f, b)
                    };
                }
            }

            return(new Animation()
            {
                Frames = frameData
            });
        }
예제 #2
0
        public static JmadDataContainer Create(Span <byte> data)
        {
            var jmad = new JmadDataContainer(data);

            switch (jmad.Type)
            {
            case JmadDataType.Flat:
                jmad.SetComponentOffsets(32, data.ReadInt32At(12), data.ReadInt32At(16));
                break;

            case JmadDataType.Normal:
                jmad.SetComponentOffsets(32, data.ReadInt32At(12), data.ReadInt32At(16));
                jmad.SetComponentSizes(data.ReadInt32At(20), data.ReadInt32At(24), data.ReadInt32At(28));
                break;

            case JmadDataType.Four:
                jmad.SetVariableComponentSizeBlocks(48, data.ReadInt32At(12), data.ReadInt32At(16));
                jmad.SetFrameMappingOffsets(data.ReadInt32At(20), data.ReadInt32At(24), data.ReadInt32At(28));
                jmad.SetComponentOffsets(data.ReadInt32At(32), data.ReadInt32At(36), data.ReadInt32At(40));
                break;

            case JmadDataType.Five:
                jmad.SetVariableComponentSizeBlocks(48, data.ReadInt32At(12), data.ReadInt32At(16));
                jmad.SetFrameMappingOffsets(data.ReadInt32At(20), data.ReadInt32At(24), data.ReadInt32At(28), usesShorts: true);
                jmad.SetComponentOffsets(data.ReadInt32At(32), data.ReadInt32At(36), data.ReadInt32At(40));
                break;

            case JmadDataType.Six:
                jmad.SetVariableComponentSizeBlocks(48, data.ReadInt32At(12), data.ReadInt32At(16), reversedBlocks: true);
                jmad.SetFrameMappingOffsets(data.ReadInt32At(20), data.ReadInt32At(24), data.ReadInt32At(28));
                jmad.SetComponentOffsets(data.ReadInt32At(32), data.ReadInt32At(36), data.ReadInt32At(40));
                break;

            case JmadDataType.Seven:
                jmad.SetVariableComponentSizeBlocks(48, data.ReadInt32At(12), data.ReadInt32At(16), reversedBlocks: true);
                jmad.SetFrameMappingOffsets(data.ReadInt32At(20), data.ReadInt32At(24), data.ReadInt32At(28), usesShorts: true);
                jmad.SetComponentOffsets(data.ReadInt32At(32), data.ReadInt32At(36), data.ReadInt32At(40));
                break;

            case JmadDataType.UncompressedNormal:
                jmad.SetComponentOffsets(32, data.ReadInt32At(12), data.ReadInt32At(16));
                jmad.SetComponentSizes(data.ReadInt32At(20), data.ReadInt32At(24), data.ReadInt32At(28));
                break;

            default:
                Debug.Fail("Unsupported data type");
                break;
            }

            return(jmad);
        }