Exemplo n.º 1
0
        public static void GlTFSaveOptions()
        {
            // ExStart:glTFSaveOptions
            // Initialize Scene object
            Scene scene = new Scene();

            // Create a child node
            scene.RootNode.CreateChildNode("sphere", new Sphere());
            // Set glTF saving options. The code example embeds all assets into the target file usually a glTF file comes with some dependencies, a bin file for model's vertex/indices, two .glsl files for vertex/fragment shaders
            // Use opt.EmbedAssets to tells the Aspose.3D API to export scene and embed the dependencies inside the target file.
            GltfSaveOptions opt = new GltfSaveOptions(FileContentType.ASCII);

            opt.EmbedAssets = true;
            // Use KHR_materials_common extension to define the material, thus no GLSL files are generated.
            opt.UseCommonMaterials = true;
            // Customize the name of the buffer file which defines model
            opt.BufferFile = "mybuf.bin";
            // Save GlTF file
            scene.Save(RunExamples.GetOutputFilePath("glTFSaveOptions_out.gltf"), opt);

            // Save a binary glTF file using KHR_binary_glTF extension
            scene.Save(RunExamples.GetOutputFilePath("glTFSaveOptions_out.glb"), FileFormat.GLTF_Binary);

            // Developers may use saving options to create a binary glTF file using KHR_binary_glTF extension
            GltfSaveOptions opts = new GltfSaveOptions(FileContentType.Binary);

            scene.Save(RunExamples.GetOutputFilePath("Test_out.glb"), opts);
            // ExEnd:glTFSaveOptions
        }
        public static void Run()
        {
            // ExStart:Non_PBRtoPBRMaterial
            // initialize a new 3D scene
            var s   = new Scene();
            var box = new Box();

            s.RootNode.CreateChildNode("box1", box).Material = new PhongMaterial()
            {
                DiffuseColor = new Vector3(1, 0, 1)
            };
            GltfSaveOptions opt = new GltfSaveOptions(FileFormat.GLTF2);

            //Custom material converter to convert PhongMaterial to PbrMaterial
            opt.MaterialConverter = delegate(Material material)
            {
                PhongMaterial m = (PhongMaterial)material;
                return(new PbrMaterial()
                {
                    Albedo = new Vector3(m.DiffuseColor.x, m.DiffuseColor.y, m.DiffuseColor.z)
                });
            };
            // save in GLTF 2.0 format
            s.Save(RunExamples.GetOutputFilePath("Non_PBRtoPBRMaterial_Out.gltf"), opt);
            // ExEnd:Non_PBRtoPBRMaterial
        }
Exemplo n.º 3
0
        /// <summary>
        /// The JSON content of GLTF file is indented for human reading, default value is false
        /// This method is supported by version 19.8 or greater.
        /// </summary>
        public static void PrettyPrintInGltfSaveOption()
        {
            // ExStart:PrettyPrintInGltfSaveOption
            // Initialize 3D scene
            Scene scene = new Scene(new Sphere());
            // Initialize GLTFSaveOptions
            GltfSaveOptions opt = new GltfSaveOptions(FileFormat.GLTF2);

            // The JSON content of GLTF file is indented for human reading, default value is false
            opt.PrettyPrint = true;
            // Save 3D Scene
            scene.Save(RunExamples.GetDataDir() + "prettyPrintInGltfSaveOption.gltf", opt);
            // ExEnd:PrettyPrintInGltfSaveOption
        }