Return to Snippet

Revision: 70801
at July 13, 2016 18:52 by sherazam


Initial Code
// this code example creates a camera in a 3D scene, sets its target and render an image.

// [C# Code Sample]

// For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET
// The path to the documents directory.
string MyDir = RunExamples.GetDataDir();

// Load scene from file
Scene scene = new Scene(MyDir + "camera.3ds");
// 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 = new Camera();
scene.RootNode.CreateChildNode("camera", camera);
camera.ParentNode.Transform.Translation = new Vector3(10, 10, 10);
camera.LookAt = Vector3.Origin;

// Specify the image render option
ImageRenderOptions opt = new ImageRenderOptions();
// Set the background color
opt.BackgroundColor = Color.AliceBlue;
// Tells renderer where the it can find textures
opt.AssetDirectories.Add(MyDir + "textures");
// Turn on shadow
opt.EnableShadows = true;
// Render the scene in given camera's perspective into specified png file with size 1024x1024
scene.Render(camera, MyDir + "Render3DModelImageFromCamera_out_.png", new Size(1024, 1024), ImageFormat.Png, opt);

//[VB.NET Code Sample]

' For complete examples and data files, please go to https://github.com/aspose-3d/Aspose.3D-for-.NET
' The path to the documents directory.
Dim MyDir As String = RunExamples.GetDataDir()

' Load scene from file
Dim scene As New Scene(MyDir & Convert.ToString("camera.3ds"))
' Create a camera at (10,10,10) and look at the origin point for rendering,
' it must be attached to the scene before render
Dim camera As New Camera()
scene.RootNode.CreateChildNode("camera", camera)
camera.ParentNode.Transform.Translation = New Vector3(10, 10, 10)
camera.LookAt = Vector3.Origin

' Specify the image render option
Dim opt As New ImageRenderOptions()
' Set the background color
opt.BackgroundColor = Color.AliceBlue
' Tells renderer where the it can find textures
opt.AssetDirectories.Add(MyDir & Convert.ToString("textures"))
' Turn on shadow
opt.EnableShadows = True
' Render the scene in given camera's perspective into specified png file with size 1024x1024
scene.Render(camera, MyDir & Convert.ToString("Render3DModelImageFromCamera_out_.png"), New Size(1024, 1024), ImageFormat.Png, opt)

Initial URL
http://www.aspose.com/.net/3d-component.aspx

Initial Description
This Technical tip explains how .NET developers can render an image of 3D model from the camera inside their .NET applications. Using Aspose.3D for .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. 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.

Initial Title
How to Render an Image of 3D Model from the Camera inside .NET Application

Initial Tags
image, Net

Initial Language
C#