public (MaterialCollectionContent Materials, MeshCollectionContent Meshes) ReadMeshContent(IEnumerable <SharpGLTF.Schema2.Mesh> meshes) { var materialsFactory = new GLTFMaterialsFactory(TagConverter); var meshDecoders = meshes.ToXnaDecoders(materialsFactory, TagConverter); var meshContent = MeshCollectionBuilder.CreateContent(meshDecoders); var matsContent = materialsFactory.CreateContent(); return(matsContent, meshContent); }
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); }