Refactor: move uvproject code from blenlib to blenkernel

I'm moving this for two (related) reasons:
* It depends a lot on the specifics of `Camera` and `Object` data-blocks.
* It links `Object::object_to_world()` which is not an inline function and thus
  easily leads to linker errors. It mostly seems like luck that this is not
  breaking our build due to early dead code elimination when linking binaries
  which use the blenlib static library such as `msgfmt`.

I found this while working on a compilation tool which would not be as lucky and
has a linker error because of the dependence on `Object::object_to_world`.

Pull Request: https://projects.blender.org/blender/blender/pulls/136547
This commit is contained in:
Jacques Lucke
2025-03-26 20:51:57 +01:00
parent 3dc78529f2
commit 202db40afb
6 changed files with 29 additions and 28 deletions

View File

@@ -4,7 +4,7 @@
#pragma once
/** \file
* \ingroup bli
* \ingroup bke
*/
struct Object;
@@ -16,7 +16,7 @@ struct ProjCameraInfo;
* \param rotmat: can be `obedit->object_to_world().ptr()` when uv project is used.
* \param winx, winy: can be from `scene->r.xsch / ysch`.
*/
struct ProjCameraInfo *BLI_uvproject_camera_info(const struct Object *ob,
struct ProjCameraInfo *BKE_uvproject_camera_info(const struct Object *ob,
const float rotmat[4][4],
float winx,
float winy);
@@ -24,13 +24,13 @@ struct ProjCameraInfo *BLI_uvproject_camera_info(const struct Object *ob,
/**
* Apply UV from #ProjCameraInfo (camera).
*/
void BLI_uvproject_from_camera(float target[2], float source[3], struct ProjCameraInfo *uci);
void BKE_uvproject_from_camera(float target[2], float source[3], struct ProjCameraInfo *uci);
/**
* Apply uv from perspective matrix.
* \param persmat: Can be `rv3d->persmat`.
*/
void BLI_uvproject_from_view(float target[2],
void BKE_uvproject_from_view(float target[2],
float source[3],
float persmat[4][4],
float rotmat[4][4],
@@ -40,13 +40,13 @@ void BLI_uvproject_from_view(float target[2],
/**
* Apply orthographic UVs.
*/
void BLI_uvproject_from_view_ortho(float target[2], float source[3], const float rotmat[4][4]);
void BKE_uvproject_from_view_ortho(float target[2], float source[3], const float rotmat[4][4]);
/**
* So we can adjust scale with keeping the struct private.
*/
void BLI_uvproject_camera_info_scale(ProjCameraInfo *uci, float scale_x, float scale_y);
void BKE_uvproject_camera_info_scale(ProjCameraInfo *uci, float scale_x, float scale_y);
/*
* Free info. */
void BLI_uvproject_camera_info_free(ProjCameraInfo *uci);
void BKE_uvproject_camera_info_free(ProjCameraInfo *uci);

View File

@@ -302,6 +302,7 @@ set(SRC
intern/type_conversions.cc
intern/undo_system.cc
intern/unit.cc
intern/uvproject.cc
intern/vfont.cc
intern/vfont_curve.cc
intern/vfontdata_freetype.cc
@@ -513,6 +514,7 @@ set(SRC
BKE_type_conversions.hh
BKE_undo_system.hh
BKE_unit.hh
BKE_uvproject.h
BKE_vfont.hh
BKE_vfontdata.hh
BKE_viewer_path.hh

View File

@@ -3,7 +3,7 @@
* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup bli
* \ingroup bke
*/
#include <cmath>
@@ -16,7 +16,8 @@
#include "BLI_math_matrix.h"
#include "BLI_math_rotation.h"
#include "BLI_math_vector.h"
#include "BLI_uvproject.h"
#include "BKE_uvproject.h"
struct ProjCameraInfo {
float camangle;
@@ -28,7 +29,7 @@ struct ProjCameraInfo {
bool do_persp, do_pano, do_rotmat;
};
void BLI_uvproject_from_camera(float target[2], float source[3], ProjCameraInfo *uci)
void BKE_uvproject_from_camera(float target[2], float source[3], ProjCameraInfo *uci)
{
float pv4[4];
@@ -80,7 +81,7 @@ void BLI_uvproject_from_camera(float target[2], float source[3], ProjCameraInfo
target[1] += uci->shifty;
}
void BLI_uvproject_from_view(float target[2],
void BKE_uvproject_from_view(float target[2],
float source[3],
float persmat[4][4],
float rotmat[4][4],
@@ -121,7 +122,7 @@ void BLI_uvproject_from_view(float target[2],
target[1] = (y + target[1]) / winy;
}
ProjCameraInfo *BLI_uvproject_camera_info(const Object *ob,
ProjCameraInfo *BKE_uvproject_camera_info(const Object *ob,
const float rotmat[4][4],
float winx,
float winy)
@@ -173,12 +174,12 @@ ProjCameraInfo *BLI_uvproject_camera_info(const Object *ob,
return nullptr;
}
void BLI_uvproject_camera_info_free(ProjCameraInfo *uci)
void BKE_uvproject_camera_info_free(ProjCameraInfo *uci)
{
MEM_freeN(uci);
}
void BLI_uvproject_from_view_ortho(float target[2], float source[3], const float rotmat[4][4])
void BKE_uvproject_from_view_ortho(float target[2], float source[3], const float rotmat[4][4])
{
float pv[3];
@@ -189,7 +190,7 @@ void BLI_uvproject_from_view_ortho(float target[2], float source[3], const float
target[1] = pv[2];
}
void BLI_uvproject_camera_info_scale(ProjCameraInfo *uci, float scale_x, float scale_y)
void BKE_uvproject_camera_info_scale(ProjCameraInfo *uci, float scale_x, float scale_y)
{
uci->xasp *= scale_x;
uci->yasp *= scale_y;

View File

@@ -159,7 +159,6 @@ set(SRC
intern/timecode.cc
intern/timeit.cc
intern/uuid.cc
intern/uvproject.cc
intern/vector.cc
intern/virtual_array.cc
intern/voxel.cc
@@ -398,7 +397,6 @@ set(SRC
BLI_utildefines_variadic.h
BLI_utility_mixins.hh
BLI_uuid.h
BLI_uvproject.h
BLI_vector.hh
BLI_vector_list.hh
BLI_vector_set.hh

View File

@@ -31,7 +31,6 @@
#include "BLI_string.h"
#include "BLI_time.h"
#include "BLI_utildefines.h"
#include "BLI_uvproject.h"
#include "BLI_vector.hh"
#include "BLT_translation.hh"
@@ -50,6 +49,7 @@
#include "BKE_subdiv.hh"
#include "BKE_subdiv_mesh.hh"
#include "BKE_subdiv_modifier.hh"
#include "BKE_uvproject.h"
#include "DEG_depsgraph.hh"
@@ -3483,14 +3483,14 @@ static wmOperatorStatus uv_from_view_exec(bContext *C, wmOperator *op)
BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
float *luv = BM_ELEM_CD_GET_FLOAT_P(l, cd_loop_uv_offset);
BLI_uvproject_from_view_ortho(luv, l->v->co, rotmat);
BKE_uvproject_from_view_ortho(luv, l->v->co, rotmat);
}
changed = true;
}
}
else if (camera) {
const bool camera_bounds = RNA_boolean_get(op->ptr, "camera_bounds");
ProjCameraInfo *uci = BLI_uvproject_camera_info(
ProjCameraInfo *uci = BKE_uvproject_camera_info(
v3d->camera,
obedit->object_to_world().ptr(),
camera_bounds ? (scene->r.xsch * scene->r.xasp) : 1.0f,
@@ -3504,12 +3504,12 @@ static wmOperatorStatus uv_from_view_exec(bContext *C, wmOperator *op)
BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
float *luv = BM_ELEM_CD_GET_FLOAT_P(l, cd_loop_uv_offset);
BLI_uvproject_from_camera(luv, l->v->co, uci);
BKE_uvproject_from_camera(luv, l->v->co, uci);
}
changed = true;
}
BLI_uvproject_camera_info_free(uci);
BKE_uvproject_camera_info_free(uci);
}
}
else {
@@ -3522,7 +3522,7 @@ static wmOperatorStatus uv_from_view_exec(bContext *C, wmOperator *op)
BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
float *luv = BM_ELEM_CD_GET_FLOAT_P(l, cd_loop_uv_offset);
BLI_uvproject_from_view(
BKE_uvproject_from_view(
luv, l->v->co, rv3d->persmat, rotmat, region->winx, region->winy);
}
changed = true;

View File

@@ -12,7 +12,6 @@
#include "BLI_math_matrix.h"
#include "BLI_math_vector.h"
#include "BLI_uvproject.h"
#include "BLT_translation.hh"
@@ -27,6 +26,7 @@
#include "BKE_customdata.hh"
#include "BKE_lib_query.hh"
#include "BKE_mesh.hh"
#include "BKE_uvproject.h"
#include "UI_interface.hh"
#include "UI_resources.hh"
@@ -148,8 +148,8 @@ static Mesh *uvprojectModifier_do(UVProjectModifierData *umd,
if (projectors[i].ob->type == OB_CAMERA) {
const Camera *cam = (const Camera *)projectors[i].ob->data;
if (cam->type == CAM_PANO) {
projectors[i].uci = BLI_uvproject_camera_info(projectors[i].ob, nullptr, aspx, aspy);
BLI_uvproject_camera_info_scale(
projectors[i].uci = BKE_uvproject_camera_info(projectors[i].ob, nullptr, aspx, aspy);
BKE_uvproject_camera_info_scale(
static_cast<ProjCameraInfo *>(projectors[i].uci), scax, scay);
free_uci = true;
}
@@ -215,7 +215,7 @@ static Mesh *uvprojectModifier_do(UVProjectModifierData *umd,
if (projectors[0].uci) {
for (const int corner : face) {
const int vert = corner_verts[corner];
BLI_uvproject_from_camera(
BKE_uvproject_from_camera(
mloop_uv[corner], coords[vert], static_cast<ProjCameraInfo *>(projectors[0].uci));
}
}
@@ -254,7 +254,7 @@ static Mesh *uvprojectModifier_do(UVProjectModifierData *umd,
if (best_projector->uci) {
for (const int corner : face) {
const int vert = corner_verts[corner];
BLI_uvproject_from_camera(
BKE_uvproject_from_camera(
mloop_uv[corner], coords[vert], static_cast<ProjCameraInfo *>(best_projector->uci));
}
}