Geometric Primitives Layer
Object managing geometric objects, such as spheres, cones, light sources, cameras and so on. The structure of this layer is hierachical. An object in this layer may consits of a number of sub objects. The following code demonstrates this:
#include <real/layer/r3prilay.h>
int R3LibraryInit(R3APP *app) {
if(R3ClassFind(R3CLID_PRIMLAYER)) {
RegisterMySphereClass(app);
}
..
Before registering new geometric classes, make sure the application has a geometric primitive layer class. In other words, don't plugin geometric objects into an application which don't have an object to manage them.
![]() |
Note |
|---|---|
Realsoft 3D creates multiple threads for managing geometric objects. The layer provides a sempahore through which the layer must always be accessed. Use mutually exclusive locking when changing the contents of the layer. Use shared lock when reading the layer. See the examples below. |
To fetch the current project from the layerlist object:
R3OBJ *currentlayer, *prims;
R3GetAttrs(currentlayer,
R3T(R3LAYA_Prims, &prims),
R3TAG_END);
To recursively enumerate all geometric objects in the project:
int print_object(R3OBJ *obj, void *hook_data)
{
char *name;
R3CLID clid;
R3GetAttrs(obj,
R3T(R3RA_Name, &name),
R3T(R3RA_ClassID, &clid),
R3TAG_END);
printf("found object %s (class id=%d)\n", name, clid);
}
R3DoA(prims, R3OLAYM_LOCKSHARED, NULL);
R3Do(prims, R3OLAYM_ENUMOBJECTS,
R3T(R3RA_Hook, print_project_names),
R3T(R3RA_HookData, NULL),
R3T(R3PLAYA_Recursive, TRUE),
R3TAG_END);
R3DoA(prims, R3OLAYM_RELEASE, NULL);
For example, to transform the selected geometric objects, call:
R3PRIMTRANSFORM msg;
R3OBJ *current_layer, *prims;
R3GetAttrs(layer_list, R3T(R3LAYLA_CurrentLayer, ¤t_layer), R3TAG_END);
R3GetAttrs(current_layer, R3T(3LAYA_Prims, &prims), R3TAG_END);
// initialize transformation
memset(&msg, 0, sizeof(msg));
R3MxTranslate(msg.tr, 0.1, 0.2, 0.0);
// apply to the selected objects
R3DoA(prims, R3OLAYM_LOCKEXCLUSIVE, NULL);
R3Do(prims, R3OLAYM_PERFORMONSELECTED,
R3T(R3OLAYA_PMethod, R3PRIMM_TRANSFORM),
R3T(R3OLAYA_PMsg, NULL),
R3T(R3OLAYA_PMsg2, NULL),
R3T(R3OLAYA_PMsg3, &msg),
R3TAG_END);
R3DoA(prims, R3OLAYM_RELEASE, NULL);
r3prilay.h class defines attributes R3PLAYA_CurrentLevel and R3PLAYA_Root, which are needed for managing object hierarchy.
To create a sphere and insert it into the project, call:
sphere = R3New(R3CLID_SPHERE,
R3T(R3SPHA_Radius, &rad),
R3TAG_END);
R3DoA(prims, R3OLAYM_LOCKEXCLUSIVE, NULL);
R3DoA(prims, R3OLAYM_INSERT, sphere);
R3DoA(prims, R3OLAYM_RELEASE, NULL);
To select the sphere, call:
R3DoA(prims, R3OLAYM_LOCKEXCLUSIVE, NULL);
R3DoA(prims, R3OLAYM_SELECTOBJ, sphere);
R3DoA(prims, R3OLAYM_RELEASE, NULL);