FileFormat — Aspose.3D FOSS for Java

Example

FileFormat 既充当格式描述符,又充当所有受支持的 3D 文件格式的注册表。每种格式都表示为一个 FileFormat 实例,可通过类属性或静态工厂方法访问。您传递 FileFormat 实例给 Scene.save() 以强制使用特定格式,或使用 FileFormat.detect() 来识别未知文件的格式。.

Example: com.aspose.threed

import com.aspose.threed.FileFormat;

受支持的格式常量

以下列出了在 FOSS 发行版中已积极支持(已注册导入器和/或导出器)的格式常量。.

积极支持(FOSS 发行版)

ExampleExampleExample
FileFormat.WAVEFRONT_OBJ().obj返回一个 的静态方法 ObjFormat 实例
FileFormat.GLTF2().gltf / .glbglTF 2.0 和 GLB;返回一个 的静态方法 GltfFormat 实例。使用 GltfSaveOptions 使用 setContentType(FileContentType.BINARY) 用于 GLB 输出。.
FileFormat.FBX7400ASCII().fbxFBX 7.4 ASCII; 仅导入(不导出)
FileFormat.STL_BINARY.stlSTL 二进制(在类加载时设置)
FileFormat.STLASCII.stlSTL ASCII

Example

FBX 版本 6100-7700(二进制),Maya ASCII/Binary,Discreet 3DS,Universal 3D,GLTF 1.0,GLTF binary,PDF,Blender,DXF,PLY,X(二进制/文本),Draco,RVM,ASE,IFC,Siemens JT,AMF,VRML,HTML5,ZIP,USD/USDA/USDZ,XYZ,PCD,PCD binary。.

静态方法

Example返回类型Example
FileFormat.detect(InputStream stream, String fileName)FileFormat从文件流检测格式;; fileName 用作提示
FileFormat.getFormatByExtension(String ext)FileFormat返回与扩展名字符串匹配的格式,例如 ".obj", ".glb", ".fbx", ".stl"

实例属性

ExampleExampleExampleExample
extensionStringgetExtension()主要文件扩展名(不含前导点)
extensionsList<String>getExtensions()此格式支持的所有扩展名
contentTypeStringgetContentType()MIME 类型字符串
canExportbooleangetCanExport()是否支持导出为此格式
canImportbooleangetCanImport()是否支持从此格式导入
versionStringgetVersion()格式版本字符串

实例方法

Example返回类型Example
createLoadOptions()LoadOptions创建适当的特定格式 LoadOptions 子类
createSaveOptions()SaveOptions创建适当的特定格式 SaveOptions 子类

Example

import com.aspose.threed.Scene;
import com.aspose.threed.FileFormat;
import com.aspose.threed.*;

// Auto-detect and load
Scene scene = Scene.fromFile("model.obj");

// Save with explicit format (force GLB binary)
GltfSaveOptions opts = new GltfSaveOptions();
opts.setContentType(FileContentType.BINARY);
scene.save("output.glb", opts);

// Get format by extension
FileFormat fmt = FileFormat.getFormatByExtension(".fbx");
if (fmt != null) {
    System.out.println(fmt.getCanImport());   // true
    System.out.println(fmt.getCanExport());   // false (FBX export not available)
}

// Create options from a format instance
FileFormat fmtObj = FileFormat.getFormatByExtension(".obj");
LoadOptions loadOpts = fmtObj.createLoadOptions();   // ObjLoadOptions
SaveOptions saveOpts = fmtObj.createSaveOptions();   // ObjSaveOptions

// Detect format from file stream
try (FileInputStream fis = new FileInputStream("unknown_file.bin")) {
    FileFormat detected = FileFormat.detect(fis, "unknown_file.bin");
    if (detected != null) {
        System.out.println(detected.getClass().getSimpleName());
    }
}

另见

 中文