Beispiel #1
0
        private Bone GetBone(GFrame frame, List <Tuple <Bone, GFrame> > bones, Bone parentBone = null)
        {
            Bone bone = new Bone()
            {
                Parent = parentBone,
                Name   = frame.Name,
                TransformationMatrix = frame.TransformationMatrix,
            };

            bones.Add(new Tuple <Bone, GFrame>(bone, frame));

            if (frame.FirstChild != null)
            {
                List <Bone> childrens = new List <Bone>();
                GFrame      current   = (GFrame)frame.FirstChild;
                while (current != null)
                {
                    Bone childBone = GetBone(current, bones, bone);
                    childrens.Add(childBone);
                    current = (GFrame)current.Sibling;
                }
                bone.Childrens = childrens.ToArray();
            }

            return(bone);
        }
Beispiel #2
0
        public SceneImportResult LoadSkelletalMesh(string xFile)
        {
            this.xFile = xFile;
            var allocator = new MeshAllocator();
            AnimationController aController;
            FileStream          file = new FileStream(xFile, FileMode.Open, FileAccess.Read);
            GFrame frameRoot         = (GFrame)Frame.LoadHierarchyFromX(Engine.Graphics, file, MeshFlags.Managed, allocator, null, out aController);

            var vd = VertexDescriptor.Get <SkinVertex>();
            List <Tuple <Bone, GFrame> > bones = new List <Tuple <Bone, GFrame> >();

            Bone root = GetBone(frameRoot, bones);
            QuadTreeSceneNode sceneNode = new QuadTreeSceneNode(Path.GetFileNameWithoutExtension(xFile), 10);

            foreach (var item in bones)
            {
                if (item.Item2.MeshContainer != null)
                {
                    var mesh = GetMesh((GMeshContainer)item.Item2.MeshContainer, root, vd);
                    sceneNode.Add(new SkelletalMeshNode(item.Item2.Name, mesh));
                }
            }

            sceneNode.UpdateLayout(true);

            try
            {
                file.Close();
                if (aController != null)
                {
                    aController.Dispose();
                }
                allocator.DestroyFrame(frameRoot);
                root.Dispose();
            }
            catch (Exception)
            {
            }

            //AnimationCollection animations = new AnimationCollection();
            //animations.Load(xFile, model.RootBone);

            return(new SceneImportResult {
                VisualSceneRoot = sceneNode, BoneRoots = new List <Bone> {
                    root
                }
            });
        }