This example imports a partial scene containing definitions for the camera, a light, and some geometry (a ground plane and a yellow cube). It then replaces the triangle mesh of the yellow cube by an equivalent on-demand mesh.
#include "example_shared.h"
#include "example_render_target_simple.h"
#include <iostream>
#include <vector>
{
public:
Cube();
mi::Uint32 data_size()
const {
return m_data_size; }
const char* get_userdata_name(
mi::Uint32 )
const {
return 0; }
mi::Uint32 get_motion_vector_count()
const {
return 0; }
mi::Uint32 triangles_size()
const {
return m_triangles_size; }
bool has_unique_material() const { return true; }
const mi::Uint32* get_material_indices()
const {
return 0; }
private:
};
};
};
0, 2, 3, 1, 0, 1, 5, 4, 0, 4, 6, 2, 1, 3, 7, 5, 2, 6, 7, 3, 4, 5, 7, 6 };
mi::Uint32 Cube::m_normal_indices[m_data_size] = {
0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5 };
};
Cube::Cube()
{
for(
mi::Size i = 0; i < m_data_size; ++i) {
m_data_points[i] = m_points[m_point_indices[i]];
m_data_normals[i] = m_normals[m_normal_indices[i]];
}
}
{
};
{
mesh->set_callback( callback.get());
callback = 0;
mesh->set_bbox(
mi::Bbox3( -0.5, -0.5, -0.5, 0.5, 0.5, 0.5));
mesh->set_maximum_displacement( 0);
mesh->create_attribute<
mi::IBoolean>(
"visible",
"Boolean"));
visible->set_value( true);
visible = 0;
check_success( material->set_reference( "yellow_material") == 0);
material = 0;
check_success( transaction->
store( mesh.get(),
"on_demand_mesh") == 0);
mesh = 0;
check_success( instance->attach( "on_demand_mesh") == 0);
instance = 0;
}
{
check_success( rc->add_mdl_path( mdl_path) == 0);
check_success( rc->add_mdl_path( ".") == 0);
}
{
check_success( database.is_valid_interface());
database->get_global_scope());
scope->create_transaction());
check_success( transaction.is_valid_interface());
check_success( import_api.is_valid_interface());
import_api->import_elements( transaction.get(), "file:main.mi"));
check_success( import_result->get_error_number() == 0);
setup_scene( transaction.get());
scene->set_rootgroup( import_result->get_rootgroup());
scene->set_options( import_result->get_options());
scene->set_camera_instance( import_result->get_camera_inst());
transaction->
store( scene.get(),
"the_scene");
scene->create_render_context( transaction.get(), "iray"));
check_success( render_context.is_valid_interface());
scheduler_mode->set_c_str( "batch");
render_context->set_option( "scheduler_mode", scheduler_mode.get());
scene = 0;
new Render_target( image_api.get(), "Color", 512, 384));
check_success( render_context->render( transaction.get(), render_target.get(), 0) >= 0);
check_success( export_api.is_valid_interface());
export_api->export_canvas( "file:example_on_demand_mesh.png", canvas.get());
}
int main( int argc, char* argv[])
{
if( argc != 2) {
std::cerr << "Usage: example_on_demand_mesh <mdl_path>" << std::endl;
keep_console_open();
return EXIT_FAILURE;
}
const char* mdl_path = argv[1];
check_success( neuray.is_valid_interface());
configuration( neuray.get(), mdl_path);
check_start_success( result);
rendering( neuray.get());
check_success( neuray->
shutdown() == 0);
neuray = 0;
check_success( unload());
keep_console_open();
return EXIT_SUCCESS;
}
This interface represents bool.
Definition: inumber.h:122
A reference is an object that acts as a pointer to other database elements.
Definition: iref.h:25
A simple string class.
Definition: istring.h:22
Handle class template for interfaces, automatizing the lifetime control via reference counting.
Definition: handle.h:113
Mixin class template for deriving interface implementations.
Definition: interface_implement.h:41
Axis-aligned N-dimensional bounding box class template of fixed dimension.
Definition: bbox.h:74
Fixed-size math vector class template with generic operations.
Definition: vector.h:286
This interface is used to interact with the distributed database.
Definition: idatabase.h:293
This interface is used to export files.
Definition: iexport_api.h:38
This interface provides various utilities related to canvases and buffers.
Definition: iimage_api.h:49
This interface is used to import files.
Definition: iimport_api.h:100
An instance is a scene element that adds a transformation and attributes to another scene element.
Definition: iinstance.h:117
This is an object representing the Iray library.
Definition: ineuray.h:44
virtual Sint32 shutdown(bool blocking=true)=0
Shuts down the library.
virtual base::IInterface * get_api_component(const base::Uuid &uuid) const =0
Returns an API component from the Iray SDK API.
virtual Sint32 start(bool blocking=true)=0
Starts the operation of the Iray library.
Interface representing an on-demand mesh.
Definition: ion_demand_mesh.h:48
This interface is used to load plugins and to query information about loaded plugins.
Definition: iplugin_configuration.h:24
This interface is used to query and change the rendering configuration.
Definition: irendering_configuration.h:109
The scene is the top-level element describing a subset of DB elements to be rendered.
Definition: iscene.h:44
Interface representing the geometry of on-demand meshes.
Definition: isimple_mesh.h:45
A transaction provides a consistent view on the database.
Definition: itransaction.h:81
virtual base::IInterface * create(const char *type_name, Uint32 argc=0, const base::IInterface *argv[]=0)=0
Creates an object of the type type_name.
virtual base::IInterface * edit(const char *name)=0
Retrieves an element from the database and returns it ready for editing.
virtual Sint32 commit()=0
Commits the transaction.
virtual Sint32 store(base::IInterface *db_element, const char *name, Uint8 privacy=LOCAL_SCOPE)=0
Stores the element db_element in the database under the name name and with the privacy level privacy.
#define MI_BASE_DLL_FILE_EXT
The operating system specific default filename extension for shared libraries (DLLs)
Definition: config.h:340
unsigned int Uint32
32-bit unsigned integer.
Definition: types.h:49
Uint64 Size
Unsigned integral type that is large enough to hold the size of all types.
Definition: types.h:112
float Float32
32-bit float.
Definition: types.h:51
signed int Sint32
32-bit signed integer.
Definition: types.h:46
math::Vector<Uint32, 3> Uint32_3
Vector of three Uint32.
Definition: vector_typedefs.h:69
math::Vector<Float32, 3> Float32_3
Vector of three Float32.
Definition: vector_typedefs.h:90
Generic storage class template for math vector representations storing DIM elements of type T.
Definition: vector.h:135