feat(web): wire Blender light shape authoring
This commit is contained in:
@@ -5401,6 +5401,56 @@ bool web_engine_blend_main_set_vertex_weights(WebBlendMainState *state,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool web_engine_blend_main_set_light_type(WebBlendMainState *state,
|
||||
const char *target_id,
|
||||
const char *type_name,
|
||||
std::string &error)
|
||||
{
|
||||
if (state == nullptr || state->main == nullptr || target_id == nullptr || type_name == nullptr) {
|
||||
error = "RENDER_PROPERTY_INVALID: light type 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 std::string type(type_name);
|
||||
if (type == "POINT") light->type = LA_LOCAL;
|
||||
else if (type == "SUN") light->type = LA_SUN;
|
||||
else if (type == "SPOT") light->type = LA_SPOT;
|
||||
else if (type == "AREA") light->type = LA_AREA;
|
||||
else {
|
||||
error = "RENDER_PROPERTY_INVALID: light type is unsupported";
|
||||
return false;
|
||||
}
|
||||
light->id.recalc |= ID_RECALC_PARAMETERS;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool web_engine_blend_main_set_light_area_shape(WebBlendMainState *state,
|
||||
const char *target_id,
|
||||
const int area_shape,
|
||||
std::string &error)
|
||||
{
|
||||
if (state == nullptr || state->main == nullptr || target_id == nullptr) {
|
||||
error = "RENDER_PROPERTY_INVALID: light area shape 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;
|
||||
}
|
||||
if (area_shape != LA_AREA_SQUARE && area_shape != LA_AREA_RECT && area_shape != LA_AREA_DISK && area_shape != LA_AREA_ELLIPSE) {
|
||||
error = "RENDER_PROPERTY_INVALID: light area shape is unsupported";
|
||||
return false;
|
||||
}
|
||||
light->area_shape = eLightAreaShape(area_shape);
|
||||
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,
|
||||
@@ -5597,10 +5647,28 @@ 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({"color", "energy", "exposure", "temperature", "useTemperature",
|
||||
if (!reject_unknown({"type", "areaShape", "color", "energy", "exposure", "temperature", "useTemperature",
|
||||
"castsShadow", "radius", "spotAngle", "spotBlend", "areaSize",
|
||||
"areaSizeY", "areaSpread", "sunAngle"}) ||
|
||||
!read_color("color", &light->r) ||
|
||||
"areaSizeY", "areaSpread", "sunAngle"}))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (properties.contains("type")) {
|
||||
if (!properties["type"].is_string()) {
|
||||
error = "RENDER_PROPERTY_INVALID: type must be a string";
|
||||
return false;
|
||||
}
|
||||
const std::string type = properties["type"].get<std::string>();
|
||||
if (!web_engine_blend_main_set_light_type(state, target_id, type.c_str(), error)) return false;
|
||||
}
|
||||
if (properties.contains("areaShape")) {
|
||||
if (!properties["areaShape"].is_number_integer()) {
|
||||
error = "RENDER_PROPERTY_INVALID: areaShape must be an integer";
|
||||
return false;
|
||||
}
|
||||
if (!web_engine_blend_main_set_light_area_shape(state, target_id, properties["areaShape"].get<int>(), 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) ||
|
||||
!read_float("temperature", 800.0f, 20000.0f, light->temperature) ||
|
||||
|
||||
@@ -516,6 +516,14 @@ bool web_engine_blend_main_set_render_properties(WebBlendMainState *state,
|
||||
const char *target_id,
|
||||
const char *properties_json,
|
||||
std::string &error);
|
||||
bool web_engine_blend_main_set_light_type(WebBlendMainState *state,
|
||||
const char *target_id,
|
||||
const char *type_name,
|
||||
std::string &error);
|
||||
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_scene_properties(WebBlendMainState *state,
|
||||
const char *target_id,
|
||||
const char *properties_json,
|
||||
|
||||
Reference in New Issue
Block a user