FileFormat — Aspose.3D FOSS for Java

Example

FileFormat fungerar både som en formatbeskrivning och ett register över alla stödda 3D-filformat. Varje format representeras som en FileFormat instans som är tillgänglig som ett klassattribut eller via statiska fabriksmetoder. Du skickar FileFormat instanser till Scene.save() för att tvinga ett specifikt format, eller använd FileFormat.detect() för att identifiera formatet på en okänd fil.

Example: com.aspose.threed

import com.aspose.threed.FileFormat;

Stödda formatkonstanter

Formatkonstanter som aktivt stöds (importörer och/eller exportörer registrerade) i FOSS-utgåvan visas nedan.

Aktivt stödda (FOSS-utgåva)

ExampleExampleExample
FileFormat.WAVEFRONT_OBJ().objStatisk metod som returnerar en ObjFormat instans
FileFormat.GLTF2().gltf / .glbglTF 2.0 och GLB; statisk metod som returnerar en GltfFormat instans. Använd GltfSaveOptions med setContentType(FileContentType.BINARY) för GLB-utdata.
FileFormat.FBX7400ASCII().fbxFBX 7.4 ASCII; endast import (ingen export)
FileFormat.STL_BINARY.stlSTL binär (sätts vid klassladdning)
FileFormat.STLASCII.stlSTL ASCII

Example

FBX-versioner 6100-7700 (binär), Maya ASCII/Binär, Discreet 3DS, Universal 3D, GLTF 1.0, GLTF binär, PDF, Blender, DXF, PLY, X (binär/text), Draco, RVM, ASE, IFC, Siemens JT, AMF, VRML, HTML5, ZIP, USD/USDA/USDZ, XYZ, PCD, PCD binär.

Statiska metoder

ExampleReturtypExample
FileFormat.detect(InputStream stream, String fileName)FileFormatDetekterar formatet från en filström; fileName används som en ledtråd
FileFormat.getFormatByExtension(String ext)FileFormatReturnerar formatet som matchar en filändelse‑sträng såsom ".obj", ".glb", ".fbx", ".stl"

Instansegenskaper

ExampleExampleExampleExample
extensionStringgetExtension()Primär filändelse (utan inledande punkt)
extensionsList<String>getExtensions()Alla filändelser som stöds av detta format
contentTypeStringgetContentType()MIME‑typsträng
canExportbooleangetCanExport()Om export till detta format stöds
canImportbooleangetCanImport()Om import från detta format stöds
versionStringgetVersion()Formatets versionssträng

Instansmetoder

ExampleReturtypExample
createLoadOptions()LoadOptionsSkapar den lämpliga format‑specifika LoadOptions subklass
createSaveOptions()SaveOptionsSkapar den lämpliga format‑specifika SaveOptions subklass

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());
    }
}

Se även

 Svenska