by
8,582 17
0
5
185k
0
Top 1% !
Pearl of Wisdom
Easy-to-find
Specified
OpenSource
Popularity: 9304th place
Languagevhdl
LicenseMIT_X11

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

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.
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/1343504/How-to-Render-an-Image-of-3D-Model-from-?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
// Enter here the actual content of the snippet. // 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)
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus