Implements the design from #116067. The socket type is called "Matrix" but it is often referred to as "Transform" when that's what it is semantically. The attribute type is "4x4 Matrix" since that's a lower level choice. Currently matrix sockets are always passed around internally as `float4x4`, but that can be optimized in the future when smaller types would give the same behavior. A new "Matrix" utilities category has the following set of initial nodes" - **Combine Transform** - **Separate Transform** - **Multiply Matrices** - **Transform Direction** - **Transform Vector** - **Invert Matrix** - **Transpose Matrix** The nodes and socket type are behind an experimental flag for now, which will give us time to make sure it's the right set of initial nodes. The viewer node overlay doesn't support matrices-- they aren't supported for rendering in general. They also aren't supported in the modifier interface currently. But they are supported in the spreadsheet, where the value is displayed in a tooltip. Pull Request: https://projects.blender.org/blender/blender/pulls/116166
62 lines
1.8 KiB
C++
62 lines
1.8 KiB
C++
/* SPDX-FileCopyrightText: 2005 Blender Authors
|
|
*
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
|
|
/** \file
|
|
* \ingroup gpu
|
|
*/
|
|
|
|
#include "BLI_array_utils.hh"
|
|
|
|
#include "BKE_attribute_math.hh"
|
|
|
|
#include "GPU_vertex_buffer.h"
|
|
|
|
#include "attribute_convert.hh"
|
|
|
|
namespace blender::draw {
|
|
|
|
GPUVertFormat init_format_for_attribute(const eCustomDataType data_type,
|
|
const StringRefNull vbo_name)
|
|
{
|
|
GPUVertFormat format{};
|
|
bke::attribute_math::convert_to_static_type(data_type, [&](auto dummy) {
|
|
using T = decltype(dummy);
|
|
using Converter = AttributeConverter<T>;
|
|
if constexpr (!std::is_void_v<typename Converter::VBOType>) {
|
|
GPU_vertformat_attr_add(&format,
|
|
vbo_name.c_str(),
|
|
Converter::gpu_component_type,
|
|
Converter::gpu_component_len,
|
|
Converter::gpu_fetch_mode);
|
|
}
|
|
});
|
|
return format;
|
|
}
|
|
|
|
void vertbuf_data_extract_direct(const GSpan attribute, GPUVertBuf &vbo)
|
|
{
|
|
bke::attribute_math::convert_to_static_type(attribute.type(), [&](auto dummy) {
|
|
using T = decltype(dummy);
|
|
using Converter = AttributeConverter<T>;
|
|
using VBOType = typename Converter::VBOType;
|
|
if constexpr (!std::is_void_v<VBOType>) {
|
|
const Span<T> src = attribute.typed<T>();
|
|
MutableSpan<VBOType> data(static_cast<VBOType *>(GPU_vertbuf_get_data(&vbo)),
|
|
attribute.size());
|
|
if constexpr (std::is_same_v<T, VBOType>) {
|
|
array_utils::copy(src, data);
|
|
}
|
|
else {
|
|
threading::parallel_for(src.index_range(), 8192, [&](const IndexRange range) {
|
|
for (const int i : range) {
|
|
data[i] = Converter::convert(src[i]);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
} // namespace blender::draw
|