article

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

Email
Submitted on: 7/13/2016 7:39:30 AM
By: Sherazam  
Level: Intermediate
User Rating: Unrated
Compatibility: C#, VB.NET
Views: 6576
 
     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.

 
				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.
 


Other 44 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this article (in the Intermediate category)?
(The article with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular article, please click here instead.)
 

To post feedback, first please login.