feat(web): wire Blender camera focus object
This commit is contained in:
@@ -5689,6 +5689,33 @@ bool web_engine_blend_main_set_world_environment_strength(WebBlendMainState *sta
|
||||
return true;
|
||||
}
|
||||
|
||||
bool web_engine_blend_main_set_camera_focus_object(WebBlendMainState *state,
|
||||
const char *target_id,
|
||||
const char *focus_object_id,
|
||||
std::string &error)
|
||||
{
|
||||
if (state == nullptr || state->main == nullptr || target_id == nullptr || focus_object_id == nullptr) {
|
||||
error = "RENDER_PROPERTY_INVALID: camera focus target is missing";
|
||||
return false;
|
||||
}
|
||||
Camera *camera = find_camera(state->main, target_id);
|
||||
if (camera == nullptr || !ensure_single_user_data(state->main, &camera->id, error)) {
|
||||
if (error.empty()) error = "RENDER_PROPERTY_INVALID: camera was not found";
|
||||
return false;
|
||||
}
|
||||
Object *focus_object = nullptr;
|
||||
if (focus_object_id[0] != '\0') {
|
||||
focus_object = find_object(state->main, focus_object_id);
|
||||
if (focus_object == nullptr) {
|
||||
error = "RENDER_PROPERTY_INVALID: camera focus object was not found";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
camera->dof.focus_object = focus_object;
|
||||
camera->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,
|
||||
@@ -5849,6 +5876,14 @@ bool web_engine_blend_main_set_render_properties(WebBlendMainState *state,
|
||||
if (dof["enabled"].get<bool>()) camera->dof.flag |= CAM_DOF_ENABLED;
|
||||
else camera->dof.flag &= ~CAM_DOF_ENABLED;
|
||||
}
|
||||
if (dof.contains("focusObjectId")) {
|
||||
if (!dof["focusObjectId"].is_null() && !dof["focusObjectId"].is_string()) {
|
||||
error = "RENDER_PROPERTY_INVALID: depthOfField.focusObjectId must be a string or null";
|
||||
return false;
|
||||
}
|
||||
const std::string focus_id = dof["focusObjectId"].is_null() ? std::string() : dof["focusObjectId"].get<std::string>();
|
||||
if (!web_engine_blend_main_set_camera_focus_object(state, target_id, focus_id.c_str(), error)) return false;
|
||||
}
|
||||
const auto dof_float = [&](const char *key, float minimum, float maximum, float &target) {
|
||||
if (!dof.contains(key)) return true;
|
||||
if (!dof[key].is_number()) return false;
|
||||
|
||||
@@ -573,6 +573,10 @@ bool web_engine_blend_main_set_world_environment_strength(WebBlendMainState *sta
|
||||
const char *target_id,
|
||||
float strength,
|
||||
std::string &error);
|
||||
bool web_engine_blend_main_set_camera_focus_object(WebBlendMainState *state,
|
||||
const char *target_id,
|
||||
const char *focus_object_id,
|
||||
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