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 发行版)
| Example | Example | Example |
|---|---|---|
FileFormat.WAVEFRONT_OBJ() | .obj | 返回一个 的静态方法 ObjFormat 实例 |
FileFormat.GLTF2() | .gltf / .glb | glTF 2.0 和 GLB;返回一个 的静态方法 GltfFormat 实例。使用 GltfSaveOptions 使用 setContentType(FileContentType.BINARY) 用于 GLB 输出。. |
FileFormat.FBX7400ASCII() | .fbx | FBX 7.4 ASCII; 仅导入(不导出) |
FileFormat.STL_BINARY | .stl | STL 二进制(在类加载时设置) |
FileFormat.STLASCII | .stl | STL 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" |
实例属性
| Example | Example | Example | Example |
|---|---|---|---|
extension | String | getExtension() | 主要文件扩展名(不含前导点) |
extensions | List<String> | getExtensions() | 此格式支持的所有扩展名 |
contentType | String | getContentType() | MIME 类型字符串 |
canExport | boolean | getCanExport() | 是否支持导出为此格式 |
canImport | boolean | getCanImport() | 是否支持从此格式导入 |
version | String | getVersion() | 格式版本字符串 |
实例方法
| 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());
}
}