1. 产品
  2.   3D
  3.   Python
  4.   Aspose.3D for Python via .NET

Aspose.3D for Python via .NET

 
 

用于创建、编辑和转换 3D 模型的 Python API

一个实用的 Python 库,用于 3D 文件格式和 3D 场景的创建、编辑、处理以及转换为 FBX、STL、Discreet3DS、Universal3D、Collada 等。

什么是 Aspose.3D for Python via .NET?

Aspose.3D for Python via .NET 是一个全面且稳定的库,使软件开发人员能够在 Python 应用程序中处理 3D 文件和模型,而无需安装 3D 建模和渲染软件。该库帮助软件开发人员创建能够轻松创建、读取、渲染、操作和转换各种文件格式的 3D 模型的应用程序,包括 FBX、3DS、U3D、DAE、glTF、OBJ、STL、DRC、PDF、AMF、PLY 等等。该库使用多种技术,确保即使在大型和复杂的 3D 模型上也能高效快速地执行 3D 操作。

Aspose.3D for Python via .NET 已包含多项重要功能,用于处理 3D 动画,例如创建和操作 3D 动画,包括关键帧动画、骨骼动画和形变动画。这使得创建引人入胜的交互式 3D 应用程序和游戏变得容易。该库还提供了广泛的工具和功能来操作 3D 模型。包括导入和导出 3D 模型、创建和编辑 3D 模型,以及对 3D 模型执行各种操作,如缩放、旋转和位移。

Aspose.3D for Python via .NET 基于 .NET 框架构建,可通过 IronPython(Python 编程语言的 .NET 实现)与 Python 一起使用。凭借对多种 3D 文件格式的支持以及丰富的 3D 模型操作和动画功能,它是需要在应用程序中处理 3D 内容的开发者的极佳选择。

Previous Next

开始使用 Aspose.3D for Python via .NET

通过 .NET 稳定版安装 Aspose.3D for Python 的最简方法是使用 pip。请使用以下命令以顺利完成安装。

通过 pip 安装 Aspose.3D for Python via .NET

pip install aspose-3d 
您也可以直接从 Aspose 产品页面

通过 Python API 生成并加载 3D 场景

Aspose.3D for Python via .NET 已全面支持从头创建新的 3D 场景,并使用 Python 命令将其保存为任何受支持的文件格式。该库还提供了读取现有 3D 场景、对现有 3D 进行修改、将 3D 场景保存为 PDF、从受密码保护的 PDF 打开现有场景、检测文件格式、从 PDF 文件中提取 3D 内容、在加载 3D Obj 文件之前设置加载选项等功能。

如何通过 Python API 创建 3D 场景文档?

import aspose.threed as a3d

# For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET

# The path to the documents directory.

# Create an object of the Scene class

scene = a3d.Scene()

# Save 3D scene document

scene.Save("document.fbx", a3d.FileFormat.FBX7500ASCII)

通过 Python API 渲染 3D 场景

Aspose.3D for Python via .NET 使软件开发人员能够在自己的 Python 应用程序中加载和渲染 3D 场景。该库支持高质量的 3D 场景渲染,包括抗锯齿、景深、运动模糊等。它还支持导入和导出多种 3D 文件格式,包括 FBX、OBJ、STL 和 3DS。这意味着您可以轻松地将现有的 3D 模型导入到场景中,或将 3D 场景导出为兼容的格式。它支持诸如在 3D 几何体上投射和接收阴影、基于硬件的 3D 几何渲染、从相机将 3D 视图渲染为图像格式、渲染 3D 场景的全景视图等功能。以下代码示例展示了软件开发人员如何渲染 3D 场景的全景视图并保存为图像格式。

如何使用 Python 渲染 3D 场景的全景视图并以图像格式保存?

from aspose.pydrawing.imaging import ImageFormat
from aspose.pydrawing import Color
import aspose.threed as a3d

# load the scene

scene = Scene.from_file("vc.glb")

# create a camera for capturing the cube map

cam = a3d.entities.Camera(a3d.entities.ProjectionType.PERSPECTIVE)
cam.near_plane = 0.1
cam.far_plane = 200
cam.rotation_mode = a3d.entities.RotationMode.FIXED_DIRECTION
scene.root_node.create_child_node(cam).transform.set_translation(5, 6, 0);

# create two lights to illuminate the scene

scene.root_node.create_child_node(a3d.entities.Light("", a3d.entities.LightType.POINT).transform.set_translation(-10, 7, -10)
light = a3d.entities.Light()
light.color = Color.cadet_blue
scene.root_node.create_child_node(light).transform.set_translation(49, 0, 49)

# create a renderer

# Create a cube map render target with depth texture, depth is required when rendering a scene.

rt = renderer.render_factory.create_cube_render_texture(a3d.render.RenderParameters(False), 512, 512)

# create a 2D texture render target with no depth texture used for image processing
final = renderer.render_factory.CreateRenderTexture(a3d.render.RenderParameters(False, 32, 0, 0), 1024 * 3 , 1024)

# a viewport is required on the render target

rt.create_viewport(cam, a3d.utilities.RelativeRectangle.from_scale(0, 0, 1, 1))
renderer.render(rt)

# execute the equirectangular projection post-processing with the previous rendered cube map as input

equirectangular = renderer.get_post_processing("equirectangular")

# Specify the cube map rendered from the scene as this post processing's input

equirectangular.input = rt.targets[0]

# Execute the post processing effect and save the result to render target final

renderer.execute(equirectangular, final)

# save the texture into disk

final.targets[0].save("panorama.png", ImageFormat.PNG)

在 3D 文档中使用动画

Aspose.3D for Python via .NET 允许软件开发人员使用 Python 库在 3D 文档中创建和处理动画。该库包含了众多动画处理功能,例如渲染动画场景、在 3D 文件中设置目标摄像机、创建骨骼动画、处理形变目标以及混合多个动画。下面的示例演示了如何使用 Python 命令创建一个简单的动画。

如何使用 Python API 创建简单动画?

import clr
clr.AddReference("Aspose.3D")
from Aspose.ThreeD import *

# create a new scene
scene = Scene()

# create a new camera
camera = Camera()
camera.Name = "Camera"
scene.RootNode.CreateChildNode(camera)

# create a new mesh
mesh = Mesh()
mesh.Name = "Mesh"
vertices = Vector3[]
vertices.append(Vector3(0, 0, 0))
vertices.append(Vector3(0, 1, 0))
vertices.append(Vector3(1, 1, 0))
vertices.append(Vector3(1, 0, 0))
mesh.Vertices = vertices
mesh.Triangles = [0, 1, 2, 0, 2, 3]

# create a new node for the mesh
meshNode = Node()
meshNode.Name = "MeshNode"
meshNode.Translation = Vector3(0, 0, 0)
meshNode.CreateChildNode(mesh)

# add the mesh node to the scene
scene.RootNode.CreateChildNode(meshNode)

# create a new animation track for the mesh node
track = AnimationTrack(meshNode, AnimationTargetType.Translation)

# create a new keyframe at time 0
keyframe1 = Keyframe()
keyframe1.Time = 0
keyframe1.Value = Vector3(0, 0, 0)
track.Keyframes.Add(keyframe1)

# create a new keyframe at time 1
keyframe2 = Keyframe()
keyframe2.Time = 1
keyframe2.Value = Vector3(0, 0, 5)
track.Keyframes.Add(keyframe2)

# create a new animation clip
clip = AnimationClip("Clip")
clip.Duration = 1
clip.Tracks.Add(track)

# add the animation clip to the scene
scene.Animations.Add(clip)

# save the scene to a file
scene.Save("animation.fbx", FileFormat.FBX7400ASCII)

使用 Python API 处理多边形

Aspose.3D for Python via .NET 使软件开发人员能够在 Python 应用程序中向其 3D 模型添加和管理多边形网格。该库支持多种与多边形网格管理相关的功能,例如从文件加载多边形网格、创建多边形网格、将 3D 模型中的所有多边形转换为三角形、将多边形网格导出到文件等。下面的示例展示了用户如何通过创建 Mesh 对象并向其添加顶点和面来创建多边形网格。

如何使用 Python API 创建多边形网格?

# Create a mesh
mesh = Mesh()

# Add vertices
mesh.Vertices.Add(Vector3(0, 0, 0))
mesh.Vertices.Add(Vector3(0, 0, 1))
mesh.Vertices.Add(Vector3(0, 1, 0))
mesh.Vertices.Add(Vector3(1, 0, 0))

# Add faces
mesh.Faces.AddPolygonFace(0, 1, 2)
mesh.Faces.AddPolygonFace(0, 1, 3)
mesh.Faces.AddPolygonFace(0, 2, 3)
mesh.Faces.AddPolygonFace(1, 2, 3)

# Export the polygon mesh to a file

# Create a scene and add the mesh to it
scene = Scene()
scene.RootNode.CreateChildNode(mesh)

# Save the scene to a file
scene.Save("mesh.obj", FileFormat.WavefrontOBJ)

 中国人