AB4D Forum

Full Version: get rendered image
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, how can I get a rendered image from loaded 3d model (obj, stl, or ply)?
It's possible to do this in background, or in a command line program?
Thanks
You can do that, though you would probably get better results when human can check the 3d model and set the camera correctly.

To do that you first need to read the 3D models. To read obj files you can use ReaderObj class from Ab3d.PowerToys. To read stl and ply files you can try to use Assimp importer (third party importer that can be used with WPF wrapper that comes with Ab3d.PowerToys).

After you will have the models read, you will need to set up the camera. When you do that automatically it is usually best to use the bounding box of the read model (Bounds property on Model3D) multiply the diagonal value on the bounding box by some number (for example 3) and define a camera that is positioned a calculated distance from the center of the bounding box. You can use TargetPositionCamera from Ab3d.PowerToys for that.

With Ab3d.PowerToys you can also use the SceneCamera that simpifies the job because it automatically measures the size of the scene - here you set the Distance as percentage of the diagonal length - for example 3 means 3 times the diagonal length.

By both cameras you also need to set the Heading and Attitude at which the camera looks at the center of the scene.

If the camera is not shown on the UI, then you also need to manually call Refresh method to update the camera.

After that you can call the RenderToBitmap method on SceneCamera or TargetPositionCamera (or any other camera from Ab3d.PowerToys library) and this will produce a rendered bitmap that can be saved to disk.

The method also takes various parameters that can be used to define the size of image, used supersampling (to produce antialiased images) and define the DPI value.