Mesh Creation

Meshes need to be created with rprContextCreateMesh(). There is also an option to use rprContextCreateMeshEx2() if two UV coordinates are needed.

A few items to note regarding meshes.

  • With meshes, we specify them by polygon faces, either triangles or quadrangles. Each face is a list of N indices, with each index referring to a vertex in the list of vertices. Memory can be conserved by not repeating vertices that are part of multiple faces.

  • UV coordinates should be specified for vertices for texturing, etc.

  • Meshes can be subdivided into subdivision surfaces at render time by setting the subdivision setting.

  • Mesh shapes can be changed or transformed after creation, but a new mesh should be created to change mesh vertices.

// Create a cube mesh
rpr_shape cube = nullptr;
{
	CHECK(rprContextCreateMesh(context,
		(rpr_float const*)&cube_data[0], 24, sizeof(vertex),
		(rpr_float const*)((char*)&cube_data[0] + sizeof(rpr_float) * 3), 24, sizeof(vertex),
		(rpr_float const*)((char*)&cube_data[0] + sizeof(rpr_float) * 6), 24, sizeof(vertex),
		(rpr_int const*)indices, sizeof(rpr_int),
		(rpr_int const*)indices, sizeof(rpr_int),
		(rpr_int const*)indices, sizeof(rpr_int),
		num_face_vertices, 12, &cube));

	// Add a cube into the scene
	CHECK(rprSceneAttachShape(scene, cube));

	// Create a translation transform: -2 unit along X axis and 1 unit up Y axis
	RadeonProRender::matrix m = RadeonProRender::translation(RadeonProRender::float3(-2, 1, 0));

	// Set the transform
	CHECK(rprShapeSetTransform(cube, RPR_TRUE, &m.m00));
}

// Create plane mesh
rpr_shape plane = nullptr;
{
	CHECK(rprContextCreateMesh(context,
		(rpr_float const*)&plane_data[0], 4, sizeof(vertex),
		(rpr_float const*)((char*)&plane_data[0] + sizeof(rpr_float) * 3), 4, sizeof(vertex),
		(rpr_float const*)((char*)&plane_data[0] + sizeof(rpr_float) * 6), 4, sizeof(vertex),
		(rpr_int const*)indices, sizeof(rpr_int),
		(rpr_int const*)indices, sizeof(rpr_int),
		(rpr_int const*)indices, sizeof(rpr_int),
		num_face_vertices, 2, &plane));

	// Add a plane to the scene
	CHECK(rprSceneAttachShape(scene, plane));
}

Example of creating simple meshes (cube and plane) can be found in the Basic Scene demo.