コード例 #1
0
 public SetJoint(ObservableDictionary <JointType, AnimationJoint> list, AnimationJoint j, JointType t)
 {
     _joint     = j;
     _type      = t;
     _jointList = list;
     Execute();
 }
コード例 #2
0
 private IGameAction DeferedAction(AnimationJoint joint, float time, Vector3 to)
 {
     return(GameActionFactory.CreateGameAction(this, () =>
     {
         // This will execute in the moment this animations is executed, and not when created
         return GameActionFactory.CreateGameAction(this,
                                                   new Vector3AnimationGameAction(joint.Owner, joint.Transform.LocalRotation, to, TimeSpan.FromSeconds(time), EaseFunction.CubicInOutEase,
                                                                                  (v) => { joint.Transform.LocalRotation = v; }));
     }));
 }
コード例 #3
0
        private void Load(string file)
        {
            var root = XElement.Load(file);

            foreach (var x in root.Elements())
            {
                JointType kiJoint;
                Enum.TryParse(x.Element("KinectJoint").Value, out kiJoint);
                var meshJoint = x.Element("MeshJoint").Value;

                if (!meshJoint.Equals("Not Set"))
                {
                    if (MeshJoints.ContainsKey(meshJoint))
                        LinkedJoints[kiJoint] = MeshJoints[meshJoint];
                }
                else
                {
                    LinkedJoints[kiJoint] = new AnimationJoint();
                }
            }
        }
コード例 #4
0
        public void ReadFromFile(string filename)
        {
            var file = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), filename);

            //Create new importer
            var importer = new AssimpContext();

            //Check if model is supported
            if (!importer.IsImportFormatSupported(Path.GetExtension(file)))
            {
                throw new ArgumentException("Model format " + Path.GetExtension(file) + " is not supported!  Cannot load {1}", "filename");
            }

            //Configs
            importer.SetConfig(new NormalSmoothingAngleConfig(66.0f));

            var model = importer.ImportFile(file, PostProcessPreset.TargetRealTimeMaximumQuality);

            importer.Dispose();


            MeshData      = new MeshData();
            AnimationData = new AnimationData();
            foreach (var mesh in model.Meshes)
            {
                MeshData.Indices     = mesh.GetIndices().ToList();
                MeshData.IndexCount  = MeshData.Indices.Count;
                MeshData.Name        = mesh.Name;
                MeshData.VertexCount = mesh.VertexCount;

                foreach (var v in mesh.Vertices)
                {
                    MeshData.VertexPositions.Add(new Vector3(v.X, v.Y, v.Z));
                }

                foreach (var v in mesh.Normals)
                {
                    MeshData.VertexNormals.Add(new Vector3(v.X, v.Y, v.Z));
                }

                foreach (var v in mesh.TextureCoordinateChannels[0])
                {
                    MeshData.VertexTextureCoordinates.Add(new Vector2(v.X, v.Y));
                }

                AnimationData.BoneCount = mesh.BoneCount;

                foreach (var b in mesh.Bones)
                {
                    var j = new AnimationJoint();

                    j.Name = b.Name;
                    //j.OffsetMatrix = b.OffsetMatrix;

                    AnimationData.Bones.Add(j);
                }
            }

            return;

            //TO DO STILL BONES ARE DONE IN A DIFFERENT WAY

            AnimationData.HasAnimations = model.HasAnimations;


            foreach (var a in model.Animations)
            {
                //Clip
                var clip = new AnimationClip()
                {
                    Name           = a.Name,
                    Duration       = (float)a.DurationInTicks,
                    TicksPerSecond = (float)a.TicksPerSecond
                };

                //KeyFrames
                foreach (var m in a.NodeAnimationChannels)
                {
                    var key = new AnimationKey();

                    for (var i = 0; i < m.PositionKeyCount; ++i)
                    {
                        var time = m.PositionKeys[i].Time;
                        var pos  = m.PositionKeys[i].Value.ToVector3();
                        var rot  = m.RotationKeys[i].Value;
                        var s    = m.ScalingKeys[i].Value.ToVector3();
                    }



                    //clip.Keys.Add(key);
                }
            }
            // AnimationData.Animations.Add(clip);
            //}
        }
コード例 #5
0
        public void ReadFromFile(string filename)
        {
            //Check if file exists
            if (!File.Exists(filename))
            {
                return;
            }

            MeshData      = new MeshData();
            AnimationData = new AnimationData();

            using (var reader = new BinaryReader(File.Open(filename, FileMode.Open)))
            {
                //Read version info
                var verMajor = reader.ReadByte();
                var verMinor = reader.ReadByte();
                //Console.WriteLine("Importing OVM Version {0}.{1}",verMajor,verMinor);

                while (true)
                {
                    //For each block
                    var id = (MeshDataType)reader.ReadByte();
                    if (id == MeshDataType.END)
                    {
                        break;
                    }

                    var length = reader.ReadUInt32();

                    //Console.WriteLine("Length of Id:{0} = {1}", ((MeshDataType)id).ToString(), length);

                    //Do something based on Id
                    switch (id)
                    {
                    case MeshDataType.HEADER:
                    {
                        MeshData.Name        = reader.ReadString();
                        MeshData.VertexCount = (int)reader.ReadUInt32();
                        MeshData.IndexCount  = (int)reader.ReadUInt32();
                    }
                    break;

                    case MeshDataType.POSITIONS:
                        for (var i = 0; i < MeshData.VertexCount; ++i)
                        {
                            var x = reader.ReadSingle();
                            var y = reader.ReadSingle();
                            var z = reader.ReadSingle();
                            MeshData.VertexPositions.Add(new Vector3(x, y, z));
                        }
                        break;

                    case MeshDataType.INDICES:

                        for (var i = 0; i < MeshData.IndexCount; ++i)
                        {
                            var x = (int)reader.ReadInt32();
                            MeshData.Indices.Add(x);
                        }
                        break;

                    case MeshDataType.NORMALS:
                        for (var i = 0; i < MeshData.VertexCount; ++i)
                        {
                            var x = reader.ReadSingle();
                            var y = reader.ReadSingle();
                            var z = reader.ReadSingle();
                            MeshData.VertexNormals.Add(new Vector3(x, y, z));
                        }
                        break;

                    //Not used
                    case MeshDataType.COLORS:
                        for (var i = 0; i < MeshData.VertexCount; ++i)
                        {
                            var x = reader.ReadSingle();
                            var y = reader.ReadSingle();
                            var z = reader.ReadSingle();
                            var w = reader.ReadSingle();
                        }
                        break;

                    case MeshDataType.BLENDINDICES:
                        for (var i = 0; i < MeshData.VertexCount; ++i)
                        {
                            var blendIndex = new Vector4
                            {
                                X = reader.ReadSingle(),
                                Y = reader.ReadSingle(),
                                Z = reader.ReadSingle(),
                                W = reader.ReadSingle()
                            };
                            AnimationData.BlendIndices.Add(blendIndex);
                        }
                        break;

                    case MeshDataType.BLENDWEIGHTS:
                        for (var i = 0; i < MeshData.VertexCount; ++i)
                        {
                            var blendWeight = new Vector4
                            {
                                X = reader.ReadSingle(),
                                Y = reader.ReadSingle(),
                                Z = reader.ReadSingle(),
                                W = reader.ReadSingle()
                            };
                            AnimationData.BlendWeights.Add(blendWeight);
                        }
                        break;

                    case MeshDataType.ANIMATIONCLIPS:


                        // lips in the data
                        var clipcount = reader.ReadInt16();
                        //for every clip
                        for (var i = 0; i < clipcount; ++i)
                        {
                            var clip = new AnimationClip
                            {
                                Name           = reader.ReadString(),
                                Duration       = reader.ReadSingle(),
                                TicksPerSecond = reader.ReadSingle()
                            };

                            //Amount of keys in the clip
                            var keyCount = reader.ReadInt16();

                            for (var j = 0; j < keyCount; j++)
                            {
                                var key = new AnimationKey();
                                key.Tick = reader.ReadSingle();

                                //Transforms in the key
                                var transformCount = reader.ReadInt16();
                                for (var k = 0; k < transformCount; k++)
                                {
                                    var floatArr = new float[16];
                                    for (var l = 0; l < 16; l++)
                                    {
                                        floatArr[l] = reader.ReadSingle();
                                    }

                                    var boneTransforms = new Matrix(floatArr);
                                    key.BoneTransforms.Add(boneTransforms);
                                }

                                //Add key to the clip
                                clip.Keys.Add(key);
                            }

                            //Add clip to the animationList
                            AnimationData.Animations.Add(clip);
                        }


                        break;

                    case MeshDataType.SKELETON:
                        AnimationData.BoneCount = reader.ReadInt16();


                        for (var i = 0; i < AnimationData.BoneCount; ++i)
                        {
                            var bone = new AnimationJoint
                            {
                                Index       = reader.ReadInt16(),
                                Name        = reader.ReadString(),
                                ParentIndex = reader.ReadUInt16()
                            };

                            //Offset
                            var floatArr = new float[16];
                            for (var l = 0; l < 16; l++)
                            {
                                floatArr[l] = reader.ReadSingle();
                            }

                            bone.OffsetMatrix = new Matrix(floatArr);

                            //Local
                            for (var l = 0; l < 16; l++)
                            {
                                floatArr[l] = reader.ReadSingle();
                            }

                            bone.LocalMatrix = new Matrix(floatArr);

                            //Global
                            for (var l = 0; l < 16; l++)
                            {
                                floatArr[l] = reader.ReadSingle();
                            }

                            bone.GlobalMatrix = new Matrix(floatArr);

                            bone.IsValid = true;

                            AnimationData.Bones.Add(bone);

                            AnimationData.HasAnimations = true;
                        }
                        break;

                    default:
                        reader.ReadBytes((int)length);
                        break;
                    }
                }
            }
        }
コード例 #6
0
 private void SetJoint(AnimationJoint joint)
 {
     ReduxManager.InsertInUndoRedo(new SetJoint(LinkedJoints,joint,SelectedType));
     RaisePropertyChanged("SelectedJoint");
 }
コード例 #7
0
 public void Execute()
 {
     _prevValue        = _jointList[_type];
     _jointList[_type] = _joint;
 }