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 creates via the API a red tetrahedron as a triangle mesh and constructs a blue subdivision surface from the tetrahedron.
#include "example_shared.h"
#include "example_render_target_simple.h"
#include <iostream>
#include <map>
#include <vector>
{
check_success( mesh);
normals->append_vector3( tetra_normals[i]);
check_success( normals->is_valid_attribute());
check_success( mesh_connectivity->attach_attribute_vector( normals.get()) == 0);
check_success( !normals->is_valid_attribute());
return mesh;
}
struct Edge {
Edge() : v1( 0), v2( 0) {}
bool operator<(
const Edge& e)
const {
return v1 < e.v1 || ( v1 == e.v1 && v2 < e.v2); }
};
{
std::vector< mi::Float32_3 > smoothed_point(
std::vector< mi::Uint32> valence( n, 0);
std::map< Edge, mi::Uint32> split_vertex;
++ valence[ triangle[0]];
++ valence[ triangle[1]];
++ valence[ triangle[2]];
mesh->
point( triangle[0], p);
smoothed_point[ triangle[1]] += p;
mesh->
point( triangle[1], p);
smoothed_point[ triangle[2]] += p;
mesh->
point( triangle[2], p);
smoothed_point[ triangle[0]] += p;
Edge edge( v1, v2);
std::map< Edge, mi::Uint32>::iterator split_vertex_pos = split_vertex.find( edge);
if ( split_vertex_pos == split_vertex.end()) {
split_vertex[ edge] = new_index[j];
} else {
new_index[j] = split_vertex_pos->second;
mesh->
point( new_index[j], q);
mesh->
set_point( new_index[j], q + new_point);
}
}
}
w = 5.0/8.0 - w * w;
(1 - w) * p + w * smoothed_point[i] /
static_cast<mi::Float32>( valence[i]));
}
check_success( normals.is_valid_interface());
normals->reserve( n + e);
mesh->
point( triangle[0], p0);
mesh->
point( triangle[1], p1);
mesh->
point( triangle[2], p2);
normals->set_vector3( triangle[0],
normals->set_vector3( triangle[1],
normals->set_vector3( triangle[2],
}
normals->set_vector3( i, v);
}
mesh_connectivity->attach_attribute_vector( normals.get());
}
{
transaction->
store( mesh_red.get(),
"mesh_red");
instance->attach( "mesh_red");
matrix.translate( -0.1, -0.5, 0.2);
instance->set_matrix( matrix);
instance->create_attribute<
mi::IBoolean>(
"visible",
"Boolean"));
visible->set_value( true);
material->set_reference( "red_material");
transaction->
store( instance.get(),
"instance_red");
group->attach( "instance_red");
transaction->
copy(
"mesh_red",
"mesh_blue");
loop_subdivision( mesh_blue.get());
loop_subdivision( mesh_blue.get());
loop_subdivision( mesh_blue.get());
loop_subdivision( mesh_blue.get());
instance->
attach(
"mesh_blue");
matrix.translate( 0.4, -1.5, -1.6);
matrix.rotate( 0.0, 1.25 *
MI_PI_2, 0.0);
mi::Float64_4_4 matrix_scale( 0.25, 0, 0, 0, 0, 0.25, 0, 0, 0, 0, 0.25, 0, 0, 0, 0, 1);
matrix *= matrix_scale;
instance->set_matrix( matrix);
visible = instance->create_attribute<
mi::IBoolean>(
"visible",
"Boolean");
material = instance->create_attribute<
mi::IRef>(
"material",
"Ref");
transaction->
store( instance.get(),
"instance_blue");
group->
attach(
"instance_blue");
}
{
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(), import_result->get_rootgroup());
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_triangle_mesh.png", canvas.get());
}
int main( int argc, char* argv[])
{
if( argc != 2) {
std::cerr << "Usage: example_triangle_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
virtual void set_value(bool val)=0
Sets the value of the object via a parameter of type bool.
A reference is an object that acts as a pointer to other database elements.
Definition: iref.h:25
virtual Sint32 set_reference(const base::IInterface *db_element)=0
Sets the reference to db_element.
A simple string class.
Definition: istring.h:22
Handle class template for interfaces, automatizing the lifetime control via reference counting.
Definition: handle.h:113
NxM-dimensional matrix class template of fixed dimensions.
Definition: matrix.h:367
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
A group is a container for other scene elements.
Definition: igroup.h:39
virtual Sint32 attach(const char *scene_element)=0
Attaches a scene element to the group.
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
virtual Sint32 attach(const char *scene_element)=0
Attaches a scene element to the instance.
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.
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
A transaction provides a consistent view on the database.
Definition: itransaction.h:81
virtual Sint32 copy(const char *source, const char *target, Uint8 privacy=LOCAL_SCOPE)=0
Creates a copy of a database element.
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.
Interface representing a triangle mesh.
Definition: itriangle_mesh.h:122
virtual Uint32 triangles_size() const =0
Returns the number of triangles.
virtual Sint32 attach_mesh_connectivity(ITriangle_connectivity *connectivity)=0
Attaches the mesh connectivity to the mesh.
virtual Uint32 points_size() const =0
Returns the number of points in the mesh.
virtual Uint32 append_point(const Float32_3_struct &p)=0
Adds a point p to the end of all points and returns the index of the new point.
virtual Triangle_handle_struct append_triangle(const Triangle_point_indices_struct &triangle)=0
Adds a triangle to the mesh.
virtual Triangle_point_indices_struct triangle_point_indices(Triangle_handle_struct hnd) const =0
Returns the triple of indices describing the vertices of the triangle of index i.
virtual ITriangle_connectivity * edit_mesh_connectivity()=0
Detaches and returns the mesh connectivity.
virtual Sint32 set_triangle(Triangle_handle_struct hnd, const Triangle_point_indices_struct &triangle)=0
Modifies a triangle of the mesh.
virtual void reserve_triangles(Uint32 n)=0
Reserves space for at least n triangles.
virtual void reserve_points(Uint32 n)=0
Reserves space for at least n points.
virtual Sint32 point(Uint32 index, Float32_3_struct &p) const =0
Returns the coordinates of the point of index index in the output parameter p.
virtual Sint32 set_point(Uint32 index, const Float32_3_struct &p)=0
Sets the point of index index to the new point p.
Handle class for type-safety.
Definition: identifier.h:66
A triangle defined by three point indices, starting at index 0.
Definition: itriangle_connectivity.h:33
#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
#define MI_PI_2
Value of Pi / 2.
Definition: types.h:194
double Float64
64-bit float.
Definition: types.h:52
float Float32
32-bit float.
Definition: types.h:51
#define MI_PI
Value of Pi.
Definition: types.h:192
signed int Sint32
32-bit signed integer.
Definition: types.h:46
Color cos(const Color &c)
Returns a color with the elementwise cosine of the color c.
Definition: color.h:561
T cross(const Vector_struct<T, 2> &lhs, const Vector_struct<T, 2> &rhs)
Returns the two-times-two determinant result for the two vectors lhs and rhs.
Definition: vector.h:1705
bool normalize()
Normalizes this vector to unit length.
Definition: vector.h:646
math::Vector<Float32, 3> Float32_3
Vector of three Float32.
Definition: vector_typedefs.h:90
math::Matrix<Float64, 4, 4> Float64_4_4
4 x 4 matrix of Float64.
Definition: matrix_typedefs.h:330
@ ATTR_NORMAL
Surface normals of type mi::Float32_3 per point or per vertex.
Definition: iattribute_vector.h:65
bool operator<(const Tag &lhs, const Tag &rhs)
Returns true if lhs is less than rhs.
Definition: iserializer.h:104