Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
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.º 3
0
        public static IMeshPrimitiveDecoder <int> Create(SharpGLTF.Runtime.IMeshPrimitiveDecoder <SharpGLTF.Schema2.Material> primitive, GLTFMaterialsFactory materials)
        {
            var material = materials.UseMaterial(primitive.Material);

            return(new _MeshPrimitiveDecoder(primitive, material));
        }
Exemplo n.º 4
0
 public _MeshDecoder(SharpGLTF.Runtime.IMeshDecoder <SharpGLTF.Schema2.Material> mesh, GLTFMaterialsFactory materials, object tag)
 {
     _Source     = mesh;
     _Primitives = mesh.Primitives.Select(item => _MeshPrimitiveDecoder.Create(item, materials)).ToArray();
     _Tag        = tag;
 }