FileFormat — Aspose.3D FOSS for Java
Methods
FileFormat đóng vai trò vừa là bộ mô tả định dạng vừa là danh bạ của tất cả các định dạng tệp 3D được hỗ trợ. Mỗi định dạng được biểu diễn dưới dạng một FileFormat đối tượng có thể truy cập như một thuộc tính lớp hoặc thông qua các phương thức nhà máy tĩnh. Bạn truyền FileFormat các đối tượng tới Scene.save() để ép buộc một định dạng cụ thể, hoặc sử dụng FileFormat.detect() để xác định định dạng của tệp không xác định.
Methods: com.aspose.threed
import com.aspose.threed.FileFormat;Các Hằng Định Dạng Được Hỗ Trợ
Các hằng định dạng được hỗ trợ tích cực (các trình nhập và/hoặc xuất đã đăng ký) trong bản phát hành FOSS được hiển thị bên dưới.
Được Hỗ Trợ Tích Cực (bản phát hành FOSS)
| Methods | Methods | Methods |
|---|---|---|
FileFormat.WAVEFRONTOBJ | .obj | Trường public static final (đối tượng ObjFormat) |
FileFormat.GLTF2 | .gltf / .glb | glTF 2.0 và GLB; trường public static final (đối tượng GltfFormat). Sử dụng GltfSaveOptions với setContentType(FileContentType.BINARY) để xuất GLB. |
FileFormat.FBX7400ASCII | .fbx | FBX 7.4 ASCII; chỉ nhập (không xuất) |
FileFormat.STL_BINARY | .stl | STL nhị phân (được thiết lập khi lớp được tải) |
FileFormat.STLASCII | .stl | STL ASCII |
Methods
FBX phiên bản 6100-7700 (binary), Maya ASCII/Binary, Discreet 3DS, Universal 3D, GLTF 1.0, GLTF binary, PDF, Blender, DXF, PLY, X (binary/text), Draco, RVM, ASE, IFC, Siemens JT, AMF, VRML, HTML5, ZIP, USD/USDA/USDZ, XYZ, PCD, PCD binary.
Phương Thức Tĩnh
| Methods | Kiểu trả về | Methods |
|---|---|---|
FileFormat.detect(InputStream stream, String fileName) | FileFormat | Phát hiện định dạng từ luồng tệp; fileName được sử dụng làm gợi ý |
FileFormat.getFormatByExtension(String ext) | FileFormat | Trả về định dạng khớp với chuỗi phần mở rộng như ".obj", ".glb", ".fbx", ".stl" |
Thuộc Tính Thể Hiện
| Methods | Methods | Methods | Methods |
|---|---|---|---|
extension | String | getExtension() | Phần mở rộng tệp chính (không có dấu chấm đầu) |
extensions | List<String> | getExtensions() | Tất cả các phần mở rộng được hỗ trợ bởi định dạng này |
contentType | String | getContentType() | Chuỗi MIME type |
canExport | boolean | getCanExport() | Có hỗ trợ xuất sang định dạng này hay không |
canImport | boolean | getCanImport() | Có hỗ trợ nhập từ định dạng này hay không |
version | String | getVersion() | Chuỗi phiên bản định dạng |
Phương Thức Thể Hiện
| Methods | Kiểu trả về | Methods |
|---|---|---|
createLoadOptions() | LoadOptions | Tạo ra định dạng cụ thể phù hợp LoadOptions lớp con |
createSaveOptions() | SaveOptions | Tạo ra định dạng cụ thể phù hợp SaveOptions lớp con |
Methods
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());
}
}