FileFormat — Aspose.3D FOSS for Python API Reference

Example

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

Example: aspose.threed

from aspose.threed import FileFormat

受支持的格式常量

在 FOSS 发行版中,已积极支持(已注册导入器和/或导出器)的格式常量如下所示。源代码中列为 None 的常量是尚未实现的格式的保留名称。.

已实际支持(FOSS 发行版)

ExampleExampleExample
FileFormat.WAVEFRONT_OBJ().obj返回一个 ObjFormat 实例
FileFormat.GLTF2().gltf / .glbglTF 2.0;返回一个 GltfFormat 实例
FileFormat.FBX7400ASCII().fbxFBX 7.4 ASCII;静态方法
FileFormat.MICROSOFT_3MF.3mf3MF (set at module load)
FileFormat.COLLADA.daeExample
FileFormat.STL_BINARY.stlSTL 二进制(在模块加载时设置)
FileFormat.STLASCII.stlSTL ASCII

Example

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

静态方法

Example返回类型Example
FileFormat.detect(stream, file_name)`FileFormatNone`
FileFormat.get_format_by_extension(ext)`FileFormatNone`

实例属性

ExampleExampleExample
extensionstr主要文件扩展名(不含前导点)
extensionslist[str]此格式支持的所有扩展名
content_typestrMIME 类型字符串
can_exportbool是否支持导出为此格式
can_importbool是否支持从此格式导入
versionstr格式版本字符串

实例方法

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

Example

from aspose.threed import Scene, FileFormat

# Auto-detect and load
scene = Scene.from_file("model.obj")

# Save with explicit format (force GLB binary)
from aspose.threed.formats import GltfSaveOptions
opts = GltfSaveOptions()
opts.binary_mode = True
scene.save("output.glb", opts)

# Get format by extension
fmt = FileFormat.get_format_by_extension(".fbx")
if fmt:
    print(fmt.can_import)   # True
    print(fmt.can_export)   # True

# Create options from a format instance
fmt_obj = FileFormat.get_format_by_extension(".obj")
load_opts = fmt_obj.create_load_options()   # ObjLoadOptions
save_opts = fmt_obj.create_save_options()   # ObjSaveOptions

# Detect format from file stream
with open("unknown_file.bin", "rb") as f:
    detected = FileFormat.detect(f, "unknown_file.bin")
    if detected:
        print(type(detected).__name__)

另见

 中文