Exemplo n.º 1
0
        public ModelTemplate(ModelCollectionContent collection, int index)
        {
            var srcModel = collection._Models[index];

            _Armature  = collection._SharedArmatures[srcModel.ArmatureLogicalIndex];
            _Drawables = srcModel.DrawableReferences;

            _ModelBounds = srcModel.ModelBounds;
        }
Exemplo n.º 2
0
        public static DeviceModelCollection CreateFrom(ModelCollectionContent content, Func <MaterialCollectionContent, MeshCollectionContent, MeshCollection> meshesConverter)
        {
            var meshes = meshesConverter(content._SharedMaterials, content._SharedMeshes);

            var models = content._Models
                         .Select((item, idx) => new ModelTemplate(content, idx))
                         .ToArray();

            return(new DeviceModelCollection(meshes, content._SharedArmatures, models, content._DefaultModelIndex));
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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);
        }