Beispiel #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
            // The path to the documents directory.
            string MyDir = RunExamples.GetDataDir();
            // 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(MyDir + "Non_PBRtoPBRMaterial_Out.gltf", opt);
            // ExEnd:Non_PBRtoPBRMaterial
        }
        /// <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
        }
        public static void glTFSaveOptions()
        {
            // ExStart:glTFSaveOptions
            // The path to the documents directory.
            string MyDir = RunExamples.GetDataDir();
            // 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(MyDir + "glTFSaveOptions_out.gltf", opt);

            // Save a binary glTF file using KHR_binary_glTF extension
            scene.Save(MyDir + "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(MyDir + "Test_out.glb", opts);
            // ExEnd:glTFSaveOptions
        }
Beispiel #5
0
        ///<Summary>
        /// Convert3dToFormat method to convert 3d to other format
        ///</Summary>
        public Response Convert3dToFormat(string fileName, string folderName, string outputType)
        {
            SaveOptions saveOptions     = null;
            bool        foundSaveOption = true;
            bool        createZip       = false;

            switch (outputType)
            {
            case "fbx":
                saveOptions = new FBXSaveOptions(Aspose.ThreeD.FileFormat.FBX7500Binary);
                break;

            case "obj":
                saveOptions = new ObjSaveOptions();
                break;

            case "3ds":
                saveOptions = new Discreet3DSSaveOptions();
                break;

            case "drc":
                saveOptions = new DracoSaveOptions();
                break;

            case "amf":
                saveOptions = new AMFSaveOptions();
                break;

            case "rvm":
                saveOptions = new RvmSaveOptions();
                break;

            case "dae":
                saveOptions = new ColladaSaveOptions();
                break;

            case "gltf":
                saveOptions = new GLTFSaveOptions(FileContentType.ASCII);
                createZip   = true;
                break;

            case "glb":
                saveOptions = new GLTFSaveOptions(FileContentType.Binary);
                break;

            case "pdf":
                saveOptions = new PdfSaveOptions();
                break;

            case "html":
                saveOptions = new HTML5SaveOptions();
                createZip   = true;
                break;

            case "ply":
                saveOptions = new PlySaveOptions();
                break;

            case "stl":
                saveOptions = new STLSaveOptions();
                break;

            case "u3d":
                saveOptions = new U3DSaveOptions();
                break;

            case "att":
                RvmSaveOptions att = new RvmSaveOptions();
                att.ExportAttributes = true;
                saveOptions          = att;
                break;

            default:
                foundSaveOption = false;
                break;
            }

            if (foundSaveOption)
            {
                return(ProcessTask(fileName, folderName, "." + outputType, createZip, false, delegate(string inFilePath, string outPath, string zipOutFolder)
                {
                    Scene scene = new Scene(inFilePath);
                    scene.Save(outPath, saveOptions);
                }));
            }
            else
            {
                return(new Response
                {
                    FileName = null,
                    Status = "Output type not found",
                    StatusCode = 500
                });
            }
        }