Each time you want to invoke Beast to light and render a world or level in your game, you need to use the Beast API to create a scene: a representation of the geometry and light sources that should be taken into account during the rendering.
A scene is essentially a container for:
The scene acts as factory for all these object types; the memory used for these types of objects is managed by the scene they belong to. When you release a scene, all handles to the objects owned by that scene will be invalidated.
Scenes do not have a graph or a hierarchy. You are expected to flatten the transformations you provide for the objects in your scene so that they are all expressed in world space.
Scenes are not persisted in the cache by the Beast Manager. Therefore, they cannot be re-used by other Beast Managers, or re-used once they are destroyed.
You create and set up a scene as follows:
Meshes are not part of a scene themselves; they represent a definition of an object's geometry and properties. Meshes are created by the Beast Manager outside the scene, and are maintained in the cache on their own. Later, you will create instances of your mesh that place the geometry at a specific translation and rotation within your scene. This indirection allows each mesh to be re-used multiple times within each scene (and across multiple scenes at the same time) with a minimal additional memory cost.
For details on meshes, and on how to create and set up mesh handles, see Creating Meshes.
For details on textures, and on how to create and set up texture handles, see Creating Textures.
For details on mesh instances, and on how to create and set up instance handles, see Creating Mesh Instances.
When you create your meshes and instances, you assign materials to them by name. Then, within each scene, you create the actual referenced materials with those names. The properties of each material are set up within each scene. This indirection allows a single mesh to be used across multiple scenes with different material properties in each scene.
For details on materials, and on how to create and set up material handles, see Creating Physical Materials.
For details on light sources, and on how to create and set up light source handles, see Creating Light Sources.
For details on cameras, and on how to create and set up camera handles, see Creating Cameras.
For details on point clouds, and on how to create and set up point cloud handles, see Creating Point Clouds.
The steps above do not have to be done in exactly the order specified. The only requirement is that you must set up all of your instances, materials, light sources, cameras and point clouds after you initialize your scene handle (step 3) and before you close your scene handle (step 10).
For example, the following code fragment illustrates the overall process of setting up a very simple scene:
// 1. Create meshes std::basic_string<TCHAR> sphereMatName(_T("SphereMaterial")); std::basic_string<TCHAR> floorMatName(_T("FloorMaterial")); ILBMeshHandle floorMesh; ILBBeginMesh(bmh, _T("Floor"), &floorMesh); ... // add triangles ILBEndMesh(floorMesh); ILBMeshHandle sphereMesh; ILBBeginMesh(bmh, _T("Sphere"), &sphereMesh); ... // add triangles ILBEndMesh(sphereMesh); // 2. Create a texture used by the floor ILBTextureHandle floorTex; ILBBeginTexture(bm, _T("FloorTexture"), 256, 256, ILB_PF_RGBA_BYTE, &floorTex); ... // add pixel data ILBEndTexture(floorTex); // 3. Create the scene handle ILBSceneHandle scene; ILBBeginPhysicalScene(bmh, _T("SimpleScene"), &scene); // 4. Create instances of the meshes ILBInstanceHandle floorInstance; bex::Matrix4x4 floorTrans = bex::scaleTranslation(bex::Vec3(10.0f, 1.0f, 10.0f), bex::Vec3(0.0f, -5.0f, 0.0f)); ILBCreateInstance(scene, floorMesh, _T("FloorInstance"), &floorTrans, &floorInstance); ILBInstanceHandle sphereInstance; bex::Matrix4x4 sphereTrans = bex::scaleTranslation(bex::Vec3(10.0f, 1.0f, 10.0f), bex::Vec3(0.0f, -5.0f, 0.0f)); ILBCreateInstance(scene, floorMesh, _T("SphereInstance"), &sphereTrans, &sphereInstance); // 5. Set up the materials ILBMaterialHandle floorMat; ILBCreateMaterial(scene, floorMatName.c_str(), &floorMat); ILBShaderHandle diffuseShader; ILBCreateShader(scene, _T("diffuse"), _T("diffuseTexture.osl"), &diffuseShader); ILBSetShader(floorMat, diffuseShader); // 6. Create light sources ILBLightHandle light; ILBCreateDirectionalLight(scene, _T("Sun"), &bex::directionalLightOrientation(bex::Vec3(1.0, -1.0f, -1.0f)), &bex::ColorRGB(1.0f, 1.0f, .8f), &light); ILBSetCastShadows(light, true); ILBSetShadowSamples(light, 32); ILBSetShadowAngle(light, .1f); ILBLightHandle skyLight; ILBCreateSkyLight(scene, _T("SkyLight"), &bex::identity(), &bex::ColorRGB(0.21f, 0.21f, 0.3f), &skyLight); // 7. Create a camera ILBCameraHandle camera; ILBCreatePerspectiveCamera(scene, _T("Camera"), &bex::setCameraMatrix(bex::Vec3(.3f, 3.0f, 20.0f), bex::Vec3(.1f, -0.3f, -1.0f), bex::Vec3(0.0f, 1.0f, 0.0f)), &camera); ILBSetFov(camera, static_cast<float>(M_PI) / 4.0f, 1.0f); // 8. Create a point cloud ILBPointCloudHandle pch; ILBCreatePointCloud(scene, _T("DynamicCloud"), &pch); ... // set up the grid of points in the cloud ILBEndPointCloud(pch); // 9. Create light links ILBAddLightLightLinks(skyLight, ILB_LL_EXCLUDING, sphereInstance, 1); // 10. Finalize the scene ILBEndScene(scene);
You can add objects to a single scene from multiple threads simultaneously. However:
API functions related to the creation and setup of scenes are declared in the beastscene.h file.