41 enabled_ = !res.is_selection() &&
state.show_attribute_viewer_text();
53 const Object &
object = *ob_ref.object;
54 const DupliObject *dupli_object = ob_ref.dupli_object;
55 const bool is_preview = dupli_object !=
nullptr &&
62 const float4x4 &object_to_world =
object.object_to_world();
67 add_instance_attributes_to_text_cache(
74 switch (
object.type) {
77 add_attributes_to_text_cache(dt, mesh.
attributes(), object_to_world);
82 add_attributes_to_text_cache(dt, pointcloud.
attributes(), object_to_world);
89 add_attributes_to_text_cache(dt, curves.
attributes(), object_to_world);
96 add_attributes_to_text_cache(dt, curves.
attributes(), object_to_world);
107 if (!attribute_accessor.
contains(
".viewer")) {
115 add_values_to_text_cache(dt, attribute.
varray, positions, object_to_world);
118 void add_instance_attributes_to_text_cache(
DRWTextStore *dt,
128 add_values_to_text_cache(dt, attribute, {
float3(0, 0, 0)}, object_to_world);
131 static void add_text_to_cache(DRWTextStore *dt,
133 const StringRef text,
148 static void add_lines_to_cache(DRWTextStore *dt,
150 const Span<StringRef> lines,
154 const StringRef line = lines[
i];
168 void add_values_to_text_cache(DRWTextStore *dt,
169 const GVArray &values,
170 const Span<float3> positions,
177 using T = decltype(dummy);
178 const VArray<T> &values_typed = values.typed<T>();
179 for (const int i : values.index_range()) {
180 const float3 position = math::transform_point(object_to_world, positions[i]);
181 const T &value = values_typed[i];
183 if constexpr (std::is_same_v<T, bool>) {
185 const size_t numstr_len = SNPRINTF_RLEN(numstr,
"%s", value ?
"True" :
"False");
186 add_text_to_cache(dt, position, StringRef(numstr, numstr_len), col);
188 else if constexpr (std::is_same_v<T, int8_t>) {
190 const size_t numstr_len = SNPRINTF_RLEN(numstr,
"%d", int(value));
191 add_text_to_cache(dt, position, StringRef(numstr, numstr_len), col);
193 else if constexpr (std::is_same_v<T, int>) {
195 const size_t numstr_len = SNPRINTF_RLEN(numstr,
"%d", value);
196 add_text_to_cache(dt, position, StringRef(numstr, numstr_len), col);
198 else if constexpr (std::is_same_v<T, int2>) {
200 const size_t numstr_len = SNPRINTF_RLEN(numstr,
"(%d, %d)", value.x, value.y);
201 add_text_to_cache(dt, position, StringRef(numstr, numstr_len), col);
203 else if constexpr (std::is_same_v<T, float>) {
205 const size_t numstr_len = SNPRINTF_RLEN(numstr,
"%g", value);
206 add_text_to_cache(dt, position, StringRef(numstr, numstr_len), col);
208 else if constexpr (std::is_same_v<T, float2>) {
210 const size_t numstr_len = SNPRINTF_RLEN(numstr,
"(%g, %g)", value.x, value.y);
211 add_text_to_cache(dt, position, StringRef(numstr, numstr_len), col);
213 else if constexpr (std::is_same_v<T, float3>) {
215 const size_t numstr_len = SNPRINTF_RLEN(
216 numstr,
"(%g, %g, %g)", value.x, value.y, value.z);
217 add_text_to_cache(dt, position, StringRef(numstr, numstr_len), col);
219 else if constexpr (std::is_same_v<T, ColorGeometry4b>) {
220 const ColorGeometry4f color = value.decode();
222 const size_t numstr_len = SNPRINTF_RLEN(
223 numstr,
"(%.3f, %.3f, %.3f, %.3f)", color.r, color.g, color.b, color.a);
224 add_text_to_cache(dt, position, StringRef(numstr, numstr_len), col);
226 else if constexpr (std::is_same_v<T, ColorGeometry4f>) {
228 const size_t numstr_len = SNPRINTF_RLEN(
229 numstr,
"(%.3f, %.3f, %.3f, %.3f)", value.r, value.g, value.b, value.a);
230 add_text_to_cache(dt, position, StringRef(numstr, numstr_len), col);
232 else if constexpr (std::is_same_v<T, math::Quaternion>) {
234 const size_t numstr_len = SNPRINTF_RLEN(
235 numstr,
"(%.3f, %.3f, %.3f, %.3f)", value.w, value.x, value.y, value.z);
236 add_text_to_cache(dt, position, StringRef(numstr, numstr_len), col);
238 else if constexpr (std::is_same_v<T, float4x4>) {
240 math::EulerXYZ rotation;
242 math::to_loc_rot_scale_safe<true>(value, location, rotation, scale);
244 char location_str[64];
245 const size_t location_str_len = SNPRINTF_RLEN(
246 location_str,
"Location: %.3f, %.3f, %.3f", location.x, location.y, location.z);
247 char rotation_str[64];
248 const size_t rotation_str_len = SNPRINTF_RLEN(rotation_str,
249 "Rotation: %.3f°, %.3f°, %.3f°",
250 rotation.x().degree(),
251 rotation.y().degree(),
252 rotation.z().degree());
254 const size_t scale_str_len = SNPRINTF_RLEN(
255 scale_str,
"Scale: %.3f, %.3f, %.3f", scale.x, scale.y, scale.z);
256 add_lines_to_cache(dt,
258 {StringRef(location_str, location_str_len),
259 StringRef(rotation_str, rotation_str_len),
260 StringRef(scale_str, scale_str_len)},
264 BLI_assert_unreachable();
void DRW_text_cache_add(DRWTextStore *dt, const float co[3], const char *str, const int str_len, short xoffs, short yoffs, short flag, const uchar col[4], const bool shadow, const bool align_center)