Render 3D View in Image format from Camera
Contents
[
Hide
]
Using Aspose.3D for Python via .NET, developers can render an image to view a realistic image of 3D model, with or without the enhanced background, textures, shadows and also adjust the image size.
Take a Picture of 3D Model from the Camera
The render method exposed by the Scene class can be used to take a picture from the active camera. Developers may also use the several different ways to navigate and position the camera in the scene. In this code example, we create a camera at position (10,10,10) in an existing 3D scene and look at the origin point for rendering.
The render options take the background color as a Vector3 with RGB components in the 0..1 range, the output size as a Vector2, and the image format as a string like "png":
from aspose.threed import ImageRenderOptions, Scene
from aspose.threed.entities import Camera
from aspose.threed.utilities import Vector2, Vector3
# Load scene from file
scene = Scene.from_file("camera.usdz")
# Create a camera at (10,10,10) and look at the origin point for rendering,
# It must be attached to the scene before render
camera = Camera()
scene.root_node.create_child_node("camera", camera)
camera.parent_node.transform.translation = Vector3(10.0, 10.0, 10.0)
camera.look_at = Vector3(0.0, 0.0, 0.0)
# Specify the image render option
opt = ImageRenderOptions()
# Set the background color, RGB components in the 0..1 range
opt.background_color = Vector3(0.941, 0.973, 1.0)
# Tells renderer where the it can find textures
opt.asset_directories.append("textures")
# Turn on shadow
opt.enable_shadows = True
# Render the scene in given camera's perspective into specified png file with size 1024x1024
scene.render(camera, "Render3DModelImageFromCamera.png", Vector2(1024.0, 1024.0), "png", opt)You can also render into an in-memory TextureData instead of a file, which lets you post-process or embed the rendered image without touching the disk:
from aspose.threed.render import PixelFormat, TextureData
# Render into a TextureData with the R8G8B8A8 pixel format
bitmap = TextureData(1024, 1024, PixelFormat.R8G8B8A8)
scene.render(camera, bitmap, opt)
Rendering uses the Vulkan graphics API, a functioning Vulkan driver must be available on the machine where the rendering runs.