示例#1
0
        public ModelCollectionContent ConvertToContent(SharpGLTF.Schema2.ModelRoot srcModel)
        {
            // process materials and meshes.

            var materialsBuilder = new GLTFMaterialsFactory(TagConverter);
            var meshesDecoders   = srcModel.LogicalMeshes.ToXnaDecoders(materialsBuilder, TagConverter);
            var meshesContent    = MeshCollectionBuilder.CreateContent(meshesDecoders);
            var materialsContent = materialsBuilder.CreateContent();

            // build the armatures and models

            var armatures = new List <ArmatureContent>();
            var models    = new List <ModelContent>();

            foreach (var scene in srcModel.LogicalScenes)
            {
                var armatureFactory = new GLTFArmatureFactory(scene, TagConverter);

                for (int i = 0; i < srcModel.LogicalAnimations.Count; ++i)
                {
                    var track = srcModel.LogicalAnimations[i];
                    armatureFactory.SetAnimationTrack(i, track.Name, TagConverter?.Invoke(track), track.Duration);
                }

                // TODO: check if we can share armatures
                var armature = armatureFactory.CreateArmature();
                armatures.Add(armature);

                var model = armatureFactory.CreateModelContent(scene, armatures.Count - 1);

                model.Name = scene.Name;
                model.Tag  = TagConverter?.Invoke(scene);

                models.Add(model);
            }

            // coalesce all resources into a container class:

            var content = new ModelCollectionContent(materialsContent, meshesContent, armatures.ToArray(), models.ToArray(), srcModel.DefaultScene.LogicalIndex);

            content = PostProcessor.Postprocess(content);

            return(content);
        }
示例#2
0
        public static ModelCollectionContent ConvertToContent(Assimp.Scene scene)
        {
            // create a mesh decoder for each mesh

            var matsBuilder  = new AssimpMaterialsFactory(scene.Materials);
            var meshDecoders = scene.Meshes.ToXna(matsBuilder);
            var meshContent  = MeshCollectionBuilder.CreateContent(meshDecoders);
            var matsContent  = matsBuilder.CreateContent();

            // build the armatures and models

            var models    = new List <ModelContent>();
            var armatures = new List <ArmatureContent>();

            var armatureFactory = new AssimpArmatureFactory(scene);
            var armature        = armatureFactory.CreateArmature();

            armatures.Add(armature);

            var model = armatureFactory.CreateModelContent(scene, armatures.Count - 1);

            model.Name = "AssimpScene";
            model.Tag  = scene.Metadata;

            // model.ModelBounds =

            models.Add(model);

            // coalesce all resources into a container class:

            var content = new ModelCollectionContent(matsContent, meshContent, armatures.ToArray(), models.ToArray(), 0);

            content = PostProcessor.Postprocess(content);

            return(content);
        }