Exemplo n.º 1
0
		public Animation (string name, double duration, double rate, AnimationChannel[] channels) {
			_name = name;
			_duration = duration;
			_rate = rate == 0.0 ? 30.0 : rate;
			_channels = channels;
		}
Exemplo n.º 2
0
        unsafe Dictionary <string, Animation> ReadAnimations(BinaryReader reader)
        {
            var anims = new Dictionary <string, Animation>();

            var count = reader.ReadInt32();

            for (var i = 0; i < count; i++)
            {
                var name      = reader.ReadString();
                var duration  = reader.ReadDouble();
                var rate      = reader.ReadDouble();
                var chanCount = reader.ReadInt32();
                var channels  = new AnimationChannel[chanCount];
                for (var j = 0; j < chanCount; j++)
                {
                    var nodeName  = reader.ReadString();
                    var preState  = (AnimationBehavior)reader.ReadInt32();
                    var postState = (AnimationBehavior)reader.ReadInt32();
                    var keyCount  = reader.ReadInt32();
                    var positions = new PositionKey[keyCount];
                    var sz        = keyCount * sizeof(PositionKey);
                    var buf       = new byte[sz];
                    reader.Read(buf, 0, sz);
                    fixed(byte *p = &buf[0])
                    {
                        var src = (PositionKey *)p;

                        fixed(PositionKey *dst = &positions[0])
                        {
                            for (var k = 0; k < keyCount; k++)
                            {
                                *(dst + k) = *(src + k);
                            }
                        }
                    }

                    keyCount = reader.ReadInt32();
                    var rotations = new RotationKey[keyCount];
                    sz = keyCount * sizeof(RotationKey);
                    if (buf.Length < sz)
                    {
                        buf = new byte[sz];
                    }
                    reader.Read(buf, 0, sz);
                    fixed(byte *p = &buf[0])
                    {
                        var src = (RotationKey *)p;

                        fixed(RotationKey *dst = &rotations[0])
                        {
                            for (var k = 0; k < keyCount; k++)
                            {
                                *(dst + k) = *(src + k);
                            }
                        }
                    }

                    keyCount = reader.ReadInt32();
                    var scales = new ScalingKey[keyCount];
                    sz = keyCount * sizeof(ScalingKey);
                    if (buf.Length < sz)
                    {
                        buf = new byte[sz];
                    }
                    reader.Read(buf, 0, sz);
                    fixed(byte *p = &buf[0])
                    {
                        var src = (ScalingKey *)p;

                        fixed(ScalingKey *dst = &scales[0])
                        {
                            for (var k = 0; k < keyCount; k++)
                            {
                                *(dst + k) = *(src + k);
                            }
                        }
                    }

                    channels[j] = new AnimationChannel(nodeName, preState, postState, positions, rotations, scales);
                }
                anims[name] = new Animation(name, duration, rate, channels);
            }

            return(anims);
        }
Exemplo n.º 3
0
		unsafe Dictionary<string, Animation> ReadAnimations(BinaryReader reader) {
			var anims = new Dictionary<string, Animation>();

			var count = reader.ReadInt32();
			for (var i = 0; i < count; i++) {
				var name = reader.ReadString();
				var duration = reader.ReadDouble();
				var rate = reader.ReadDouble();
				var chanCount = reader.ReadInt32();
				var channels = new AnimationChannel[chanCount];
				for (var j = 0; j < chanCount; j++) {
					var nodeName = reader.ReadString();
					var preState = (AnimationBehavior)reader.ReadInt32();
					var postState = (AnimationBehavior)reader.ReadInt32();
					var keyCount = reader.ReadInt32();
					var positions = new PositionKey[keyCount];
					var sz = keyCount * sizeof(PositionKey);
					var buf = new byte[sz];
					reader.Read(buf, 0, sz);
					fixed(byte *p = &buf[0]) {
						var src = (PositionKey*)p;
						fixed(PositionKey* dst = &positions[0]) {
							for (var k = 0; k < keyCount; k++) {
								*(dst + k) = *(src + k);
							}
						}
					}
					keyCount = reader.ReadInt32();
					var rotations = new RotationKey[keyCount];
					sz = keyCount * sizeof(RotationKey);
					if (buf.Length < sz)
						buf = new byte[sz];
					reader.Read(buf, 0, sz);
					fixed(byte *p = &buf[0]) {
						var src = (RotationKey*)p;
						fixed(RotationKey *dst = &rotations[0]) {
							for (var k = 0; k < keyCount; k++) {
								*(dst + k) = *(src + k);
							}
						}
					}
					keyCount = reader.ReadInt32();
					var scales = new ScalingKey[keyCount];
					sz = keyCount * sizeof(ScalingKey);
					if (buf.Length < sz)
						buf = new byte[sz];
					reader.Read(buf, 0, sz);
					fixed(byte *p = &buf[0]) {
						var src = (ScalingKey*)p;
						fixed(ScalingKey *dst = &scales[0]) {
							for (var k = 0; k < keyCount; k++) {
								*(dst + k) = *(src + k);
							}
						}
					}
					channels[j] = new AnimationChannel(nodeName, preState, postState, positions, rotations, scales);
				}
				anims[name] = new Animation(name, duration, rate, channels);
			}

			return anims;
		}