Camera
Methods: aspose.threed.entities (aspose-3d-foss)
Camera 是一个 Entity 用于定义 3D 场景中视点的。它控制场景如何投影到 2D 图像平面上。相机附加到一个 Node 以在场景中定位和定向它。.
class Camera(Entity):Methods
A3DObject → SceneObject → Entity → Camera
实现说明
在此版本的 aspose-3d-foss 中, Camera 类是一个 声明存根.。仅 projection_type 和 name 实际上被存储并且可以检索。所有其他属性(near_plane, far_plane, field_of_view, aspect_ratio,,等)具有不执行任何操作的 setter;分配的值不会被保留。读取这些属性时,总是返回类的默认值,而不管分配了什么。.
当从 3D 文件(glTF、FBX)导入相机数据时, projection_type 已正确解析。如果格式将其存储为场景图元数据,则其他相机属性可用。.
Methods
Camera(name: str = None, projection_type: str = "PERSPECTIVE")| Methods | Methods | Methods | Methods |
|---|---|---|---|
name | `str | None` | None |
projection_type | str | "PERSPECTIVE" | 初始投影类型。使用 ProjectionType.PERSPECTIVE 或 ProjectionType.ORTHOGRAPHIC. |
Methods
| Methods | Methods | Methods |
|---|---|---|
projection_type | str | 投影模式: "PERSPECTIVE" 或 "ORTHOGRAPHIC". 设置为 ProjectionType 常量. |
near_plane | float | 到近裁剪平面的距离。比此更近的几何体将不会被渲染。默认 0.1. |
far_plane | float | 到远裁剪平面的距离。比此更远的几何体将不会被渲染。默认 1000.0. |
field_of_view | float | 垂直视场角(单位:度,仅限透视相机)。默认 0.0. |
field_of_view_x | float | 水平视场角(单位:度)。默认 0.0. |
field_of_view_y | float | 垂直视场角(以度为单位)(同 field_of_view)。默认 0.0. |
aspect_ratio | float | 输出图像的宽高比。默认 1.0. |
ortho_height | float | 正交视图体积的高度,单位为世界单位(仅限正交相机)。默认 100.0. |
name | str | 相机对象的名称。. |
使用示例
Methods: 在此版本中,仅 projection_type 被功能性地存储。属性赋值用于 near_plane, far_plane, field_of_view,,以及 aspect_ratio 被接受且没有错误,但不会持久化。.
透视相机
from aspose.threed import Scene
from aspose.threed.entities import Camera
from aspose.threed.entities import ProjectionType
scene = Scene()
# projection_type is stored and saved
cam = Camera("MainCamera", ProjectionType.PERSPECTIVE)
node = scene.root_node.create_child_node("camera", cam)
# Position the camera using node transform (this does persist)
node.transform.set_translation(0.0, 5.0, 20.0)
scene.save("scene-with-camera.glb")正交相机
from aspose.threed import Scene, FileFormat
from aspose.threed.entities import Camera, ProjectionType
scene = Scene()
# Only projection_type is retained; other property assignments are no-ops
cam = Camera("OrthoCamera", ProjectionType.ORTHOGRAPHIC)
scene.root_node.create_child_node("ortho_cam", cam)
scene.save("ortho-scene.glb", FileFormat.GLTF)导入后读取相机
from aspose.threed import Scene
from aspose.threed.entities import Camera
scene = Scene()
scene.open("model.glb")
for node in scene.root_node.child_nodes:
if isinstance(node.entity, Camera):
cam = node.entity
# projection_type is reliably populated; other numeric properties
# return default values (0.0 / 1.0) regardless of file content
print(f"Camera '{cam.name}': {cam.projection_type}")