Skip to content

SceneFromScratch

Ben Heasly edited this page Oct 17, 2016 · 11 revisions

The SceneFromScratch example constructs a 3D scene from scratch, entirely within Matlab.

This takes advantage of the mexximp tool which RenderToolbox uses under the hood to load 3D scenes into Matlab structs. Instead of loading a scene, this example simply creates a struct of the appropriate format.

Above, Mitsuba rendered the scene.

Description

The created scene contains a sphere with a purple-looking matte reflectance. The sphere floats in front of a large flat panel with a matte reflectance and spatially-varying texture taken from an image of a stone wall.

Three spot lights illuminate the sphere with a daylight spectrum, each spotlight aligned with one of the XYZ coordinate axes. In addition, a spectrally uniform "distant" light source illuminates the sphere and wall, causing the sphere to cast a shadow on the wall.

The camera views the sphere and wall from an oblique angle.

Rendering

Use the script rtbMakeSceneFromScratch.m to produce the image above.

Internals

Much of the work in this example takes place in the function rtbMakeTestScene() which is included with this example.

This function produces a scene struct of the format expected by mexximp. In order to get the format right, rtbMakeTestScene() uses a utility called mexximpConstants(), which returns constant values and correctly formatted struct templates for use with mexximp.

Exporting

In addition to rendering the generated scene, this example exports the same scene to a Collada 3D scene file. This uses the script rtbExportTestScene which is included with this example. In turn, this script uses a mexximp utility called mexximpExport() which accepts a scene struct and passes it to Assimp for exporting to file.

The exported scene is called rtbSceneFromScratch.dae and is included with this example. It should be viewable by many programs that support Collada, including Blender, MeshLab, and OS X Preview.

Clone this wiki locally