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)

MethodsMethodsMethods
FileFormat.WAVEFRONTOBJ.objTrường public static final (đối tượng ObjFormat)
FileFormat.GLTF2.gltf / .glbglTF 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.fbxFBX 7.4 ASCII; chỉ nhập (không xuất)
FileFormat.STL_BINARY.stlSTL nhị phân (được thiết lập khi lớp được tải)
FileFormat.STLASCII.stlSTL 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

MethodsKiểu trả vềMethods
FileFormat.detect(InputStream stream, String fileName)FileFormatPhát hiện định dạng từ luồng tệp; fileName được sử dụng làm gợi ý
FileFormat.getFormatByExtension(String ext)FileFormatTrả 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

MethodsMethodsMethodsMethods
extensionStringgetExtension()Phần mở rộng tệp chính (không có dấu chấm đầu)
extensionsList<String>getExtensions()Tất cả các phần mở rộng được hỗ trợ bởi định dạng này
contentTypeStringgetContentType()Chuỗi MIME type
canExportbooleangetCanExport()Có hỗ trợ xuất sang định dạng này hay không
canImportbooleangetCanImport()Có hỗ trợ nhập từ định dạng này hay không
versionStringgetVersion()Chuỗi phiên bản định dạng

Phương Thức Thể Hiện

MethodsKiểu trả vềMethods
createLoadOptions()LoadOptionsTạo ra định dạng cụ thể phù hợp LoadOptions lớp con
createSaveOptions()SaveOptionsTạ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());
    }
}

Xem thêm

 Tiếng Việt