安装

安装 Aspose.3D FOSS for Python

Aspose.3D FOSS for Python 以纯 Python 包的形式在 PyPI 上发布。无需编译本地扩展、安装系统库,也不需要 Microsoft Office 或其他第三方运行时。.


先决条件

要求细节
Python 版本3.7, 3.8, 3.9, 3.10, 3.11, or 3.12
包管理器pip(随 CPython 捆绑)
操作系统Windows、macOS、Linux(任何运行 CPython 的平台)
编译器 / 构建工具不需要
系统软件包不需要

1. Install via pip (Recommended)

安装 Aspose.3D FOSS 最简单的方法是直接从 PyPI 获取::

pip install aspose-3d-foss

pip 将下载并安装该包,并记录在你的环境中。无需后期配置。.

要安装固定版本以实现可复现的构建::

pip install aspose-3d-foss==26.1.0

2. Set Up a Virtual Environment (Recommended for Projects)

使用虚拟环境可以使库与其他 Python 项目隔离,避免版本冲突。.

创建并激活虚拟环境::

##Create the environment
python -m venv .venv

##Activate on Linux / macOS
source .venv/bin/activate

##Activate on Windows (Command Prompt)
.venv\Scripts\activate.bat

##Activate on Windows (PowerShell)
.venv\Scripts\Activate.ps1

在已激活的环境中安装库::

pip install aspose-3d-foss

记录依赖以实现可复现性::

pip freeze > requirements.txt

在另一台机器上重新创建环境::

python -m venv .venv
source .venv/bin/activate   # or the Windows equivalent
pip install -r requirements.txt

3. Verify the Installation

安装后,验证库是否能够正确导入::

from aspose.threed import Scene

scene = Scene()
print("Aspose.3D FOSS installed successfully")
print(f"Root node name: {scene.root_node.name}")

预期输出::

Aspose.3D FOSS installed successfully
Root node name:

注:: 根节点没有默认名称 — scene.root_node.name 返回空字符串。.

您也可以使用 pip 检查已安装的版本::

pip show aspose-3d-foss

这将打印版本、作者和许可证(MIT)。.


快速入门:加载场景并检查它

以下脚本加载一个 3D 文件,打印每个网格节点的信息,并将场景重新导出为 GLB 格式::

from aspose.threed import Scene
from aspose.threed.formats import ObjLoadOptions

##Load an OBJ file with material support
options = ObjLoadOptions()
options.enable_materials = True
options.flip_coordinate_system = False

scene = Scene()
scene.open("model.obj", options)

##Print the scene hierarchy
print(f"Top-level nodes: {len(scene.root_node.child_nodes)}")

for node in scene.root_node.child_nodes:
    if node.entity is None:
        continue
    mesh = node.entity
    print(f"  Node: {node.name}")
    print(f"    Vertices: {len(mesh.control_points)}")
    print(f"    Polygons: {len(mesh.polygons)}")
    if node.material:
        print(f"    Material: {type(node.material).__name__}")

##Re-export to GLB (binary glTF)
scene.save("output.glb")
print("Saved output.glb")

如果您还没有 OBJ 文件,库也可以从头创建场景::

from aspose.threed import Scene

##Create an empty scene and save it as glTF
scene = Scene()
scene.save("empty.gltf")
print("Created empty.gltf")

平台说明

Windows、macOS、Linux:: 该库在所有平台上完全相同。没有平台特定的代码路径或二进制扩展。.

Docker / 无服务器: 由于没有系统软件包依赖,该库可以在精简的 Docker 镜像中运行(例如 python:3.12-slim)而无需安装任何额外的 apt 或 yum 软件包。.

CI/CD: 添加 pip install aspose-3d-foss 到你的 CI 流水线的依赖步骤中。无需额外设置。.

Conda: 如果你的项目使用 Conda,请在 Conda 环境中从 PyPI 安装该库::

conda create -n my-env python=3.12
conda activate my-env
pip install aspose-3d-foss

其他资源

 中文