feat(web): wire Blender light contribution factors
This commit is contained in:
@@ -5163,6 +5163,10 @@ json scene_ir_from_blend(const ParsedBlend &blend,
|
||||
{"spotAngle", read_float(*blend.sdna, element, "spotsize").value_or(0.785398f)},
|
||||
{"spotBlend", read_float(*blend.sdna, element, "spotblend").value_or(0.15f)},
|
||||
{"areaShape", read_integer(*blend.sdna, element, "area_shape").value_or(0)},
|
||||
{"diffuseFactor", read_float(*blend.sdna, element, "diff_fac").value_or(1.0f)},
|
||||
{"specularFactor", read_float(*blend.sdna, element, "spec_fac").value_or(1.0f)},
|
||||
{"transmissionFactor", read_float(*blend.sdna, element, "transmission_fac").value_or(1.0f)},
|
||||
{"volumeFactor", read_float(*blend.sdna, element, "volume_fac").value_or(1.0f)},
|
||||
{"areaSize", read_float(*blend.sdna, element, "area_size").value_or(0.25f)},
|
||||
{"areaSizeY", read_float(*blend.sdna, element, "area_sizey").value_or(0.25f)},
|
||||
{"areaSpread", read_float(*blend.sdna, element, "area_spread").value_or(3.14159265f)},
|
||||
|
||||
@@ -5451,6 +5451,38 @@ bool web_engine_blend_main_set_light_area_shape(WebBlendMainState *state,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool web_engine_blend_main_set_light_contribution_factors(WebBlendMainState *state,
|
||||
const char *target_id,
|
||||
const float diffuse_factor,
|
||||
const float specular_factor,
|
||||
const float transmission_factor,
|
||||
const float volume_factor,
|
||||
std::string &error)
|
||||
{
|
||||
if (state == nullptr || state->main == nullptr || target_id == nullptr) {
|
||||
error = "RENDER_PROPERTY_INVALID: light contribution target is missing";
|
||||
return false;
|
||||
}
|
||||
Light *light = find_light(state->main, target_id);
|
||||
if (light == nullptr || !ensure_single_user_data(state->main, &light->id, error)) {
|
||||
if (error.empty()) error = "RENDER_PROPERTY_INVALID: light was not found";
|
||||
return false;
|
||||
}
|
||||
const float values[] = {diffuse_factor, specular_factor, transmission_factor, volume_factor};
|
||||
for (const float value : values) {
|
||||
if (!std::isfinite(value) || value < 0.0f || value > 1.0f) {
|
||||
error = "RENDER_PROPERTY_INVALID: light contribution factor is outside the bounded range";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
light->diff_fac = diffuse_factor;
|
||||
light->spec_fac = specular_factor;
|
||||
light->transmission_fac = transmission_factor;
|
||||
light->volume_fac = volume_factor;
|
||||
light->id.recalc |= ID_RECALC_PARAMETERS;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool web_engine_blend_main_set_render_properties(WebBlendMainState *state,
|
||||
const char *target_id,
|
||||
const char *properties_json,
|
||||
@@ -5647,7 +5679,7 @@ bool web_engine_blend_main_set_render_properties(WebBlendMainState *state,
|
||||
if (strncmp(target_id, "light:", 6) == 0) {
|
||||
Light *light = find_light(state->main, target_id);
|
||||
if (light == nullptr || !ensure_single_user_data(state->main, &light->id, error)) return false;
|
||||
if (!reject_unknown({"type", "areaShape", "color", "energy", "exposure", "temperature", "useTemperature",
|
||||
if (!reject_unknown({"type", "areaShape", "diffuseFactor", "specularFactor", "transmissionFactor", "volumeFactor", "color", "energy", "exposure", "temperature", "useTemperature",
|
||||
"castsShadow", "radius", "spotAngle", "spotBlend", "areaSize",
|
||||
"areaSizeY", "areaSpread", "sunAngle"}))
|
||||
{
|
||||
@@ -5668,6 +5700,22 @@ bool web_engine_blend_main_set_render_properties(WebBlendMainState *state,
|
||||
}
|
||||
if (!web_engine_blend_main_set_light_area_shape(state, target_id, properties["areaShape"].get<int>(), error)) return false;
|
||||
}
|
||||
if (properties.contains("diffuseFactor") || properties.contains("specularFactor") || properties.contains("transmissionFactor") || properties.contains("volumeFactor")) {
|
||||
const auto factor = [&](const char *key, const float current) {
|
||||
if (!properties.contains(key)) return current;
|
||||
if (!properties[key].is_number()) {
|
||||
error = std::string("RENDER_PROPERTY_INVALID: ") + key + " must be numeric";
|
||||
return -1.0f;
|
||||
}
|
||||
return properties[key].get<float>();
|
||||
};
|
||||
const float diffuse = factor("diffuseFactor", light->diff_fac);
|
||||
const float specular = factor("specularFactor", light->spec_fac);
|
||||
const float transmission = factor("transmissionFactor", light->transmission_fac);
|
||||
const float volume = factor("volumeFactor", light->volume_fac);
|
||||
if (diffuse < 0.0f || specular < 0.0f || transmission < 0.0f || volume < 0.0f ||
|
||||
!web_engine_blend_main_set_light_contribution_factors(state, target_id, diffuse, specular, transmission, volume, error)) return false;
|
||||
}
|
||||
if (!read_color("color", &light->r) ||
|
||||
!read_float("energy", 0.0f, 1.0e9f, light->energy) ||
|
||||
!read_float("exposure", -20.0f, 20.0f, light->exposure) ||
|
||||
|
||||
@@ -524,6 +524,13 @@ bool web_engine_blend_main_set_light_area_shape(WebBlendMainState *state,
|
||||
const char *target_id,
|
||||
int area_shape,
|
||||
std::string &error);
|
||||
bool web_engine_blend_main_set_light_contribution_factors(WebBlendMainState *state,
|
||||
const char *target_id,
|
||||
float diffuse_factor,
|
||||
float specular_factor,
|
||||
float transmission_factor,
|
||||
float volume_factor,
|
||||
std::string &error);
|
||||
bool web_engine_blend_main_set_scene_properties(WebBlendMainState *state,
|
||||
const char *target_id,
|
||||
const char *properties_json,
|
||||
|
||||
Reference in New Issue
Block a user