Home > Code > C# > How to Render an Image of 3D Model from the Camera inside .NET Application

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

by sher azam   on Jul 13, 2016   Category: C#   |  Views: 517    |  Points: 25   |  Gold 


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.

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)



Overview: Aspose.3D for .NET

Aspose.3D for .NET is a feature-rich component and class library for .NET that empowers Mono and .NET application including ASP.NET, Windows Forms and Web Services to connect with prevalent 3D document formats automatically without the 3D modeling and rendering software being installed on the server. It supports FBX (ASCII, Binary) and STL (ASCII, Binary) file formats and developers can easily create, read, convert, modify and control the substance of these 3D document formats using Aspose.3D API.

More about Aspose.3D for .NET

- Homepage of Aspose.3D for .NET: http://www.aspose.com/.net/3d-component.aspx

- Download Aspose.3D for .NET: http://www.aspose.com/downloads/3d/net



Post Code  |  Code Snippet Home

User Responses


No response found, be the first to review this code snippet.

Submit feedback about this code snippet

Please sign in to post feedback

Latest Posts