@@ -2487,8 +2487,7 @@ bool set_bsdf_param(
2487
2487
void set_spectral_param (
2488
2488
Axf_impexp_state* impexp_state,
2489
2489
mi::neuraylib::IExpression_list* default_parameters,
2490
- mi::neuraylib::IType_factory* type_factory,
2491
- mi::neuraylib::IValue_factory* val_factory,
2490
+ mi::neuraylib::IMdl_factory* mdl_factory,
2492
2491
mi::neuraylib::IExpression_factory* expr_factory,
2493
2492
const mi::neuraylib::IFunction_definition* material,
2494
2493
const char * material_name,
@@ -2508,54 +2507,32 @@ void set_spectral_param(
2508
2507
return ;
2509
2508
}
2510
2509
2511
- assert (wavelengths.size () == values.size ());
2512
- const size_t num_wavelengths = wavelengths.size ();
2513
-
2514
2510
//
2515
2511
// create a spectral color constructor call
2516
2512
//
2517
2513
2518
- mi::base::Handle <const mi::neuraylib::IFunction_definition> function_definition (
2519
- transaction->access <mi::neuraylib::IFunction_definition>(
2520
- " mdl::color(float[N],float[N])" ));
2521
- mi::base::Handle <mi::neuraylib::IExpression_list> arguments (
2522
- expr_factory->create_expression_list ());
2523
- mi::base::Handle <const mi::neuraylib::IType> elem_type (type_factory->create_float ());
2524
- mi::base::Handle <const mi::neuraylib::IType_array> array_type (
2525
- type_factory->create_immediate_sized_array (elem_type.get (), num_wavelengths));
2526
-
2527
- // attach wavelengths and values arrays
2528
- for (unsigned int i = 0 ; i < 2 ; ++i)
2529
- {
2530
- const char *array_name = function_definition->get_parameter_name (i);
2531
-
2532
- const float *f = (i == 0 ) ? wavelengths.data () : values.data ();
2533
-
2534
- // create and fill the array
2535
- mi::base::Handle <mi::neuraylib::IValue_array> ar (
2536
- val_factory->create_array (array_type.get ()));
2537
- for (mi::Size j = 0 ; j < num_wavelengths; ++j)
2538
- {
2539
- mi::base::Handle <mi::neuraylib::IValue> val (
2540
- val_factory->create_float (f[j]));
2541
- ar->set_value (j, val.get ());
2542
- }
2543
-
2544
- mi::base::Handle <mi::neuraylib::IExpression> array_expr (
2545
- expr_factory->create_constant (ar.get ()));
2546
- arguments->add_expression (array_name, array_expr.get ());
2547
- }
2548
-
2549
- mi::Sint32 res;
2550
- mi::base::Handle <mi::neuraylib::IFunction_call> function_call (
2551
- function_definition->create_function_call (arguments.get (), &res));
2552
- const string color_constructor_name =
2553
- get_axf_spectrum_prefix () +
2554
- impexp_state->get_module_prefix () + string (" _" ) +
2555
- material_name + string (" _" ) + param_name;
2556
- transaction->store (function_call.get (), color_constructor_name.c_str ());
2557
-
2558
-
2514
+ assert (wavelengths.size () == values.size ());
2515
+
2516
+ mi::neuraylib::Definition_wrapper dw (transaction, " mdl::color(float[N],float[N])" , mdl_factory);
2517
+ assert (dw.is_valid ());
2518
+
2519
+ mi::Sint32 result = 0 ;
2520
+ mi::base::Handle <mi::neuraylib::IFunction_call> fc (dw.create_instance (nullptr , &result));
2521
+ assert (result == 0 );
2522
+
2523
+ string color_constructor_name
2524
+ = get_axf_spectrum_prefix ()
2525
+ + impexp_state->get_module_prefix () + string (" _" )
2526
+ + material_name + string (" _" )
2527
+ + param_name;
2528
+ transaction->store (fc.get (), color_constructor_name.c_str ());
2529
+
2530
+ mi::neuraylib::Argument_editor ae (transaction, color_constructor_name.c_str (), mdl_factory, true );
2531
+ result = ae.set_value (" wavelengths" , wavelengths.data (), wavelengths.size ());
2532
+ assert (result == 0 );
2533
+ result = ae.set_value (" amplitudes" , values.data (), values.size ());
2534
+ assert (result == 0 );
2535
+
2559
2536
//
2560
2537
// attach call to parameter
2561
2538
//
@@ -2774,13 +2751,13 @@ void Axf_reader::create_variant(
2774
2751
param_name = " sigma_s" ;
2775
2752
set_spectral_param (
2776
2753
impexp_state,
2777
- default_parameters.get (), type_factory .get (), val_factory. get (),
2754
+ default_parameters.get (), mdl_factory .get (),
2778
2755
expr_factory.get (), m_volumetric_material.get (), material_name.c_str (),
2779
2756
m_transaction, param_name, m_wavelengths, m_sigma_s);
2780
2757
param_name = " sigma_a" ;
2781
2758
set_spectral_param (
2782
2759
impexp_state,
2783
- default_parameters.get (), type_factory. get (), val_factory .get (),
2760
+ default_parameters.get (), mdl_factory .get (),
2784
2761
expr_factory.get (), m_volumetric_material.get (), material_name.c_str (),
2785
2762
m_transaction, param_name, m_wavelengths, m_sigma_a);
2786
2763
}
0 commit comments