#include <iostream>
#include <string>
#include "example_shared.h"
const char* description)
{
check_success( 0 == args->add_expression( "description", arg_expr.get()));
annotation_block->add_annotation( annotation.get());
annotation_block->retain();
return annotation_block.get();
}
void create_module(
{
transaction, "::df", context.get()) >= 0);
transaction,
"mdl::new_module",
context.get()));
{
parameters->add_type( "tint", tint_type.get());
drb_args->add_expression( "tint", drb_tint.get());
"mdl::df::diffuse_reflection_bsdf(color,float,string)", drb_args.get()));
surface_args->add_expression( "scattering", drb.get());
"mdl::material_surface(bsdf,material_emission)", surface_args.get()));
body_args->add_expression( "surface", surface.get());
"mdl::material(bool,material_surface,material_surface,color,material_volume,"
"material_geometry,hair_bsdf)", body_args.get()));
"diffuse_material",
body.get(),
nullptr,
parameters.get(),
nullptr,
nullptr,
nullptr,
nullptr,
true,
true,
context.get());
print_messages( context.get());
check_success( result == 0);
check_success( context->get_error_messages_count() == 0);
}
{
defaults->add_expression( "tint", tint_expr.get());
create_annotations( vf.get(), ef.get(), "A diffuse red material"));
"red_material",
"mdl::new_module::diffuse_material(color)",
defaults.get(),
annotations.get(),
nullptr,
true,
true,
context.get());
print_messages( context.get());
check_success( result == 0);
check_success( context->get_error_messages_count() == 0);
}
transaction,
"mdl::new_module",
context.get());
{
parameters->add_type( "across_materials", across_materials_type.get());
rcn_args->add_expression( "across_materials", across_materials_expr.get());
rcn_args.get()));
color_args->add_expression( "rgb", rcn.get());
body_args->add_expression( "tint", color.get());
body.get(), false, context.get()));
print_messages( context.get());
check_success( context->get_error_messages_count() == 0);
for(
mi::Size i = 0, n = uniform->get_length(); i < n; ++i) {
if( element->get_value<bool>()) {
check_success( i == 0);
parameter = tf->create_alias(
} else {
check_success( i != 0);
}
const char* name = parameters->get_name( i);
fixed_parameters->add_type( name, parameter.get());
}
parameters = fixed_parameters;
"uniform_parameter",
body.get(),
nullptr,
parameters.get(),
nullptr,
nullptr,
nullptr,
nullptr,
true,
true,
context.get());
print_messages( context.get());
check_success( result == 0);
check_success( context->get_error_messages_count() == 0);
}
{
enumerators->add_expression( "Add", add_expr.get());
enumerators->add_expression( "Sub", sub_expr.get());
mi::Sint32 result = module_builder->add_enum_type(
"Enum",
enumerators.get(),
nullptr,
nullptr,
true,
context.get());
print_messages( context.get());
check_success( result == 0);
check_success( context->get_error_messages_count() == 0);
fields->add_type( "x", x.get());
fields->add_type( "y", y.get());
result = module_builder->add_struct_type(
"Struct",
fields.get(),
nullptr,
nullptr,
nullptr,
true,
false,
nullptr,
context.get());
print_messages( context.get());
check_success( result == 0);
check_success( context->get_error_messages_count() == 0);
tf->create_enum( "::new_module::Enum"));
tf->create_struct( "::new_module::Struct"));
parameters->add_type( "e", e_type.get());
parameters->add_type( "s", s_type.get());
e_int_args->add_expression( "x", parameter_e.get());
struct_selector_args->add_expression( "s", parameter_s.get());
"mdl::new_module::Struct.x(::new_module::Struct)", struct_selector_args.get()));
"mdl::new_module::Struct.y(::new_module::Struct)", struct_selector_args.get()));
equal_args->add_expression( "x", e_int.get());
equal_args->add_expression( "y", equal_y_expr.get());
add_args->add_expression( "x", s_x.get());
add_args->add_expression( "y", s_y.get());
sub_args->add_expression( "x", s_x.get());
sub_args->add_expression( "y", s_y.get());
body_args->add_expression( "cond", equal.get());
body_args->add_expression( "true_exp", add.get());
body_args->add_expression( "false_exp", sub.get());
result = module_builder->add_function(
"types",
body.get(),
nullptr,
parameters.get(),
nullptr,
nullptr,
nullptr,
nullptr,
true,
false,
context.get());
print_messages( context.get());
check_success( result == 0);
check_success( context->get_error_messages_count() == 0);
}
transaction, "mdl::new_module", module_source.get(), context.get());
print_messages( context.get());
check_success( result == 0);
check_success( context->get_error_messages_count() == 0);
std::cerr << module_source->get_c_str();
}
int MAIN_UTF8( int argc, char* argv[])
{
if( !neuray.is_valid_interface())
exit_failure( "Failed to load the SDK.");
if( !mi::examples::mdl::configure( neuray.get(), {}))
exit_failure( "Failed to initialize the SDK.");
{
if( result != 0)
exit_failure( "Failed to initialize the SDK. Result code: %d", result);
create_module( transaction.get(), mdl_impexp_api.get(), mdl_factory.get());
}
check_success( neuray->shutdown() == 0);
neuray = 0;
neuray = nullptr;
if( !mi::examples::mdl::unload())
exit_failure( "Failed to unload the SDK.");
exit_success();
}
COMMANDLINE_TO_UTF8
This interface represents bool.
Definition: inumber.h:122
A simple string class.
Definition: istring.h:22
Handle class template for interfaces, automatizing the lifetime control via reference counting.
Definition: handle.h:113
An annotation block is an array of annotations.
Definition: iexpression.h:575
This interface is used to interact with the distributed database.
Definition: idatabase.h:289
The interface for creating expressions.
Definition: iexpression.h:650
virtual IExpression_parameter * create_parameter(const IType *type, Size index) const =0
Creates a parameter reference.
virtual IExpression_list * create_expression_list() const =0
Creates a new expression list.
virtual IAnnotation * create_annotation(const char *name, const IExpression_list *arguments) const =0
Creates a new annotation.
virtual IAnnotation_block * create_annotation_block() const =0
Creates a new annotation block.
virtual IExpression_direct_call * create_direct_call(const char *name, IExpression_list *arguments, Sint32 *errors=0) const =0
Creates a direct call.
virtual IExpression_constant * create_constant(IValue *value) const =0
Creates a constant (mutable).
Factory for various MDL interfaces and functions.
Definition: imdl_factory.h:53
virtual IMdl_execution_context * create_execution_context()=0
Creates an execution context.
virtual IMdl_module_builder * create_module_builder(ITransaction *transaction, const char *module_name, Mdl_version min_module_version, Mdl_version max_module_version, IMdl_execution_context *context)=0
Creates a module builder for a given module.
virtual IType_factory * create_type_factory(ITransaction *transaction)=0
Returns an MDL type factory for the given transaction.
virtual IExpression_factory * create_expression_factory(ITransaction *transaction)=0
Returns an MDL expression factory for the given transaction.
virtual IValue_factory * create_value_factory(ITransaction *transaction)=0
Returns an MDL value factory for the given transaction.
API component for MDL related import and export operations.
Definition: imdl_impexp_api.h:43
virtual Sint32 load_module(ITransaction *transaction, const char *argument, IMdl_execution_context *context=0)=0
Loads an MDL module from disk (or a builtin module) into the database.
virtual Sint32 export_module_to_string(ITransaction *transaction, const char *module_name, IString *exported_module, IMdl_execution_context *context=0)=0
Exports an MDL module from the database to string.
A transaction provides a consistent view on the database.
Definition: itransaction.h:82
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 Sint32 commit()=0
Commits the transaction.
@ MK_UNIFORM
A uniform type.
Definition: itype.h:200
@ MK_NONE
No type modifier (mutable, auto-typed).
Definition: itype.h:199
The interface for creating values.
Definition: ivalue.h:660
virtual IValue_string * create_string(const char *value="") const =0
Creates a new value of type string.
virtual IValue_int * create_int(Sint32 value=0) const =0
Creates a new value of type integer.
virtual IValue_color * create_color(Float32 red=0.0f, Float32 green=0.0f, Float32 blue=0.0f) const =0
Creates a new value of type color.
Uint64 Size
Unsigned integral type that is large enough to hold the size of all types.
Definition: types.h:112
signed int Sint32
32-bit signed integer.
Definition: types.h:46
@ MDL_VERSION_1_0
MDL version 1.0.
Definition: iexpression.h:29
@ MDL_VERSION_LATEST
Latest MDL version.
Definition: iexpression.h:40