Example #1
0
 public void Test_LoadObj()
 {
     Assert.True(System.IO.File.Exists(objFile), "obj file does not exist!");
     using (var parser = new ObjParser(objFile))
     {
         var model = parser.GetModel();
         Assert.True(model.Vertices.Count > 0);
     }
 }
Example #2
0
        /// <summary>
        /// run converter
        /// </summary>
        public void Run()
        {
            if (_model == null)
            {
                _model = new GltfModel();
                //TODO:
                if (_objModel == null)
                {
                    using (_objParser)
                    {
                        _objModel = _objParser.GetModel();
                    }
                }
                _model.Scenes.Add(new Scene());
                var u32IndicesEnabled = RequiresUint32Indices(_objModel);
                var meshes            = _objModel.Geometries;
                var meshesLength      = meshes.Count;
                for (var i = 0; i < meshesLength; i++)
                {
                    var mesh      = meshes[i];
                    var meshIndex = AddMesh(_objModel, mesh, u32IndicesEnabled);
                    AddNode(mesh.Id, meshIndex, null);
                }

                if (_model.Images.Count > 0)
                {
                    _model.Samplers.Add(new Sampler
                    {
                        MagFilter = MagFilter.Linear,
                        MinFilter = MinFilter.NearestMipmapLinear,
                        WrapS     = WrappingMode.Repeat,
                        WrapT     = WrappingMode.Repeat
                    });
                }

                var allBuffers = AddBuffers(_options.Name);
                _model.Buffers.Add(new Gltf.Buffer
                {
                    Name       = _options.Name,
                    ByteLength = allBuffers.Count
                });
                var boundary = 4;
                FillImageBuffers(allBuffers, boundary);


                if (!_options.Binary)
                {
                    _model.Buffers[0].Uri = "data:application/octet-stream;base64," + Convert.ToBase64String(allBuffers.ToArray());
                }
                else
                {
                    _glb = GltfToGlb(allBuffers);
                }
                _model.Clean();
            }
        }
Example #3
0
 public void Test_Split()
 {
     Assert.True(System.IO.File.Exists(objFile), "obj file does not exist!");
     using (var parser = new ObjParser(objFile))
     {
         var model  = parser.GetModel();
         var models = model.Split(2);
         Assert.True(models.Count > 0);
     }
 }