Blender V5.3
blender/mesh.cpp
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#include <algorithm>
6#include <optional>
7
9#include "blender/session.h"
10#include "blender/sync.h"
11#include "blender/util.h"
12
13#include "scene/camera.h"
14#include "scene/mesh.h"
15#include "scene/object.h"
16#include "scene/scene.h"
17
18#include "subd/split.h"
19
20#include "util/algorithm.h"
21#include "util/disjoint_set.h"
22
23#include "util/hash.h"
24#include "util/log.h"
25#include "util/math.h"
26
27#include "DNA_modifier_types.h"
28
30#include "BKE_attribute.h"
31#include "BKE_attribute.hh"
32#include "BKE_attribute_math.hh"
33#include "BKE_customdata.hh"
34#include "BKE_mesh.hh"
35
37
39
41
42/* Compute corner normals for motion blur with the velocity attribute, */
44 const blender::Span<blender::float3> positions,
46{
47 const blender::Span<int> corner_verts = b_mesh.corner_verts();
48 blender::Array<blender::float3> motion_corner_normals(corner_verts.size());
49
50 const blender::bke::AttributeAccessor b_attributes = b_mesh.attributes();
51 const blender::bke::GAttributeReader custom_normal = b_attributes.lookup("custom_normal");
52
53 if (custom_normal && custom_normal.varray.type().is<blender::float3>()) {
54 /* Existing custom normals take priority, no motion then. */
55 const blender::Span<blender::float3> corner_normals = b_mesh.corner_normals();
56 std::copy_n(corner_normals.data(), corner_normals.size(), motion_corner_normals.data());
57 }
58 else {
59 const blender::OffsetIndices faces = b_mesh.faces();
60 blender::Array<blender::float3> face_normals(faces.size());
61 blender::bke::mesh::normals_calc_faces(positions, faces, corner_verts, face_normals);
62
63 const blender::VArraySpan sharp_edges = *b_attributes.lookup<bool>(
64 "sharp_edge", blender::bke::AttrDomain::Edge);
65 const blender::VArraySpan sharp_faces = *b_attributes.lookup<bool>(
66 "sharp_face", blender::bke::AttrDomain::Face);
67
69 positions,
70 faces,
71 corner_verts,
72 b_mesh.corner_edges(),
73 b_mesh.vert_to_face_map(),
74 face_normals,
75 sharp_edges,
76 sharp_faces,
78 nullptr,
79 motion_corner_normals);
80 }
81
82 const blender::Span<blender::int3> corner_tris = b_mesh.corner_tris();
83
84 for (const int i : corner_tris.index_range()) {
85 const blender::int3 &tri = corner_tris[i];
86 for (int j = 0; j < 3; j++) {
87 const blender::float3 &normal = motion_corner_normals[tri[j]];
88 N[i * 3 + j] = packed_normal(make_float3(normal[0], normal[1], normal[2]));
89 }
90 }
91}
92
94{
95 const blender::bke::GAttributeReader custom_normal = b_mesh.attributes().lookup("custom_normal");
96 return custom_normal && custom_normal.varray.type().is<blender::float3>() &&
98}
99
101{
102 const blender::Span<blender::float3> vert_normals = b_mesh.vert_normals();
103 for (const int i : vert_normals.index_range()) {
104 N[i] = packed_normal(make_float3(vert_normals[i][0], vert_normals[i][1], vert_normals[i][2]));
105 }
106}
107
109 const blender::Mesh &b_mesh,
111 const float motion_scale)
112{
113 const int numverts = mesh->num_verts();
114
115 /* Override motion steps to fixed number. */
116 mesh->set_motion_steps(3);
117
118 AttributeSet &attributes = mesh->get_subdivision_type() == Mesh::SUBDIVISION_NONE ?
119 mesh->attributes :
120 mesh->subd_attributes;
121
122 /* Find or add attribute */
123 Attribute *attr_P = attributes.find(ATTR_STD_POSITION);
124 attr_P->add_motion(mesh);
125 const packed_float3 *P = mesh->get_position();
126
127 Attribute *attr_cN = attributes.find(ATTR_STD_CORNER_NORMAL);
128 if (attr_cN) {
129 attr_cN->add_motion(mesh);
130 }
131
133 attributes.find(ATTR_STD_VERTEX_NORMAL) :
134 nullptr;
135 if (attr_N) {
136 attr_N->add_motion(mesh);
137 }
138
139 /* Only export previous and next frame, we don't have any in between data. */
140 const float motion_times[2] = {-1.0f, 1.0f};
141 for (int step = 1; step <= 2; step++) {
142 const float relative_time = motion_times[step - 1] * 0.5f * motion_scale;
144
145 for (int i = 0; i < numverts; i++) {
146 mP[i] = float3(P[i]) + make_float3(b_attr[i][0], b_attr[i][1], b_attr[i][2]) * relative_time;
147 }
148
149 if (attr_cN) {
150 const blender::Span<blender::float3> motion_positions(
151 reinterpret_cast<const blender::float3 *>(mP), numverts);
153 b_mesh, motion_positions, attr_cN->data_for_write<packed_normal>(step));
154 }
155 if (attr_N) {
157 }
158 }
159}
160
162{
163 switch (b_domain) {
165 return ATTR_ELEMENT_CORNER;
166 break;
168 return ATTR_ELEMENT_VERTEX;
169 break;
171 return ATTR_ELEMENT_FACE;
172 break;
173 default:
174 assert(false);
175 return ATTR_ELEMENT_NONE;
176 }
177}
178
179static void attr_create_generic(Scene *scene,
180 Mesh *mesh,
181 const blender::Mesh &b_mesh,
182 const bool subdivision,
183 const bool need_motion,
184 const float motion_scale)
185{
188 if (!subdivision) {
189 corner_tris = b_mesh.corner_tris();
190 faces = b_mesh.faces();
191 }
192 const blender::bke::AttributeAccessor b_attributes = b_mesh.attributes();
193 AttributeSet &attributes = (subdivision) ? mesh->subd_attributes : mesh->attributes;
194 static const ustring u_velocity("velocity");
195 const ustring default_color_name{
196 std::string_view(BKE_id_attributes_default_color_name(&b_mesh.id).value_or(""))};
197
198 b_attributes.foreach_attribute([&](const blender::bke::AttributeIter &iter) {
199 const ustring name{std::string_view(iter.name)};
200 const bool is_render_color = name == default_color_name;
201
202 if (need_motion && name == u_velocity) {
203 const blender::VArraySpan b_attribute = *iter.get<blender::float3>(
205 attr_create_motion_from_velocity(mesh, b_mesh, b_attribute, motion_scale);
206 }
207
208 if (!(mesh->need_attribute(scene, name) ||
209 (is_render_color && mesh->need_attribute(scene, ATTR_STD_VERTEX_COLOR))))
210 {
211 return;
212 }
213 if (attributes.find(name)) {
214 return;
215 }
216
217 blender::bke::AttrDomain b_domain = iter.domain;
218 if (b_domain == blender::bke::AttrDomain::Edge) {
219 /* Blender's attribute API handles edge to vertex attribute domain interpolation. */
221 }
222
223 const blender::bke::GAttributeReader b_attr = iter.get(b_domain);
224 if (b_attr.varray.is_empty()) {
225 return;
226 }
227
230 {
231 Attribute *attr = attributes.add(name, TypeRGBA, ATTR_ELEMENT_CORNER_BYTE);
232 if (is_render_color) {
233 attr->std = ATTR_STD_VERTEX_COLOR;
234 }
235
236 uchar4 *data = attr->data_for_write<uchar4>();
238 if (subdivision) {
239 for (const int i : src.index_range()) {
240 data[i] = make_uchar4(src[i][0], src[i][1], src[i][2], src[i][3]);
241 }
242 }
243 else {
244 for (const int i : corner_tris.index_range()) {
245 const blender::int3 &tri = corner_tris[i];
246 data[i * 3 + 0] = make_uchar4(
247 src[tri[0]][0], src[tri[0]][1], src[tri[0]][2], src[tri[0]][3]);
248 data[i * 3 + 1] = make_uchar4(
249 src[tri[1]][0], src[tri[1]][1], src[tri[1]][2], src[tri[1]][3]);
250 data[i * 3 + 2] = make_uchar4(
251 src[tri[2]][0], src[tri[2]][1], src[tri[2]][2], src[tri[2]][3]);
252 }
253 }
254 return;
255 }
256
257 blender::bke::attribute_math::to_static_type(b_attr.varray.type(), [&]<typename BlenderT>() {
258 using Converter = typename ccl::AttributeConverter<BlenderT>;
259 using CyclesT = typename Converter::CyclesT;
260 if constexpr (!std::is_void_v<CyclesT>) {
261 const blender::VArray<BlenderT> src_varray = b_attr.varray.typed<BlenderT>();
262 const blender::CommonVArrayInfo info = b_attr.varray.common_info();
263
264 if (info.type == blender::CommonVArrayInfo::Type::Single) {
265 const auto &single_value = *static_cast<const BlenderT *>(info.data);
266 Attribute *attr = attributes.add(name, Converter::type_desc, ATTR_ELEMENT_MESH);
267 if (is_render_color) {
268 attr->std = ATTR_STD_VERTEX_COLOR;
269 }
270 CyclesT *data = reinterpret_cast<CyclesT *>(attr->data_for_write());
271 *data = Converter::convert(single_value);
272 return;
273 }
274
275 const AttributeElement element = blender_domain_to_attr_element(b_attr.domain);
276 if constexpr (Converter::layout_compatible) {
277 if (Attribute::element_size(mesh, element, attributes.prim) == src_varray.size()) {
278 if (info.type == blender::CommonVArrayInfo::Type::Span && b_attr.sharing_info) {
279 Attribute *attr = attributes.add_shared(name,
280 Converter::type_desc,
281 element,
282 info.data,
283 src_varray.size(),
284 b_attr.sharing_info);
285 if (is_render_color) {
286 attr->std = ATTR_STD_VERTEX_COLOR;
287 }
288 return;
289 }
290 }
291 }
292
293 Attribute *attr = attributes.add(name, Converter::type_desc, element);
294 if (is_render_color) {
295 attr->std = ATTR_STD_VERTEX_COLOR;
296 }
297
298 CyclesT *data = reinterpret_cast<CyclesT *>(attr->data_for_write());
299
300 const blender::VArraySpan src = b_attr.varray.typed<BlenderT>();
301 switch (b_attr.domain) {
302 case blender::bke::AttrDomain::Corner: {
303 if (subdivision) {
304 for (const int i : src.index_range()) {
305 data[i] = Converter::convert(src[i]);
306 }
307 }
308 else {
309 for (const int i : corner_tris.index_range()) {
310 const blender::int3 &tri = corner_tris[i];
311 data[i * 3 + 0] = Converter::convert(src[tri[0]]);
312 data[i * 3 + 1] = Converter::convert(src[tri[1]]);
313 data[i * 3 + 2] = Converter::convert(src[tri[2]]);
314 }
315 }
316 break;
317 }
318 case blender::bke::AttrDomain::Point: {
319 for (const int i : src.index_range()) {
320 data[i] = Converter::convert(src[i]);
321 }
322 break;
323 }
324 case blender::bke::AttrDomain::Face: {
325 if (subdivision) {
326 for (const int i : src.index_range()) {
327 data[i] = Converter::convert(src[i]);
328 }
329 }
330 else {
331 for (const int face : faces.index_range()) {
332 const CyclesT value = Converter::convert(src[face]);
333 const blender::IndexRange face_tris = blender::bke::mesh::face_triangles_range(
334 faces, face);
335 std::fill_n(data + face_tris.start(), face_tris.size(), value);
336 }
337 }
338 break;
339 }
340 default: {
341 assert(false);
342 break;
343 }
344 }
345 }
346 });
347 });
348}
349
350static set<ustring> get_blender_uv_names(const blender::Mesh &b_mesh)
351{
352 set<ustring> uv_names;
353 b_mesh.attributes().foreach_attribute([&](const blender::bke::AttributeIter &iter) {
356 {
358 uv_names.emplace(std::string_view(iter.name));
359 }
360 }
361 });
362 return uv_names;
363}
364
365/* Create uv map attributes. */
366static void attr_create_uv_map(Scene *scene,
367 Mesh *mesh,
368 const blender::Mesh &b_mesh,
369 const set<ustring> &blender_uv_names)
370{
371 const blender::Span<blender::int3> corner_tris = b_mesh.corner_tris();
372 const blender::bke::AttributeAccessor b_attributes = b_mesh.attributes();
373 const ustring render_name(std::string_view(b_mesh.default_uv_map_name()));
374 if (blender_uv_names.empty()) {
375 return;
376 }
377
378 for (const ustring &uv_name : blender_uv_names) {
379 const bool active_render = uv_name == render_name;
380 const AttributeStandard uv_std = (active_render) ? ATTR_STD_UV : ATTR_STD_NONE;
381
382 /* Denotes whether UV map was requested directly. */
383 const bool need_uv = mesh->need_attribute(scene, uv_name) ||
384 (active_render && mesh->need_attribute(scene, uv_std));
385
386 /* UV map */
387 Attribute *uv_attr = nullptr;
388 if (need_uv) {
389 if (active_render) {
390 uv_attr = mesh->attributes.add(uv_std, uv_name);
391 }
392 else {
393 uv_attr = mesh->attributes.add(uv_name, TypeFloat2, ATTR_ELEMENT_CORNER);
394 }
395
396 const blender::VArraySpan b_uv_map = *b_attributes.lookup<blender::float2>(
397 uv_name.c_str(), blender::bke::AttrDomain::Corner);
398 float2 *fdata = uv_attr->data_for_write<float2>();
399 for (const int i : corner_tris.index_range()) {
400 const blender::int3 &tri = corner_tris[i];
401 fdata[i * 3 + 0] = make_float2(b_uv_map[tri[0]][0], b_uv_map[tri[0]][1]);
402 fdata[i * 3 + 1] = make_float2(b_uv_map[tri[1]][0], b_uv_map[tri[1]][1]);
403 fdata[i * 3 + 2] = make_float2(b_uv_map[tri[2]][0], b_uv_map[tri[2]][1]);
404 }
405 }
406 }
407}
408
410 Mesh *mesh,
411 const blender::Mesh &b_mesh,
412 const set<ustring> &blender_uv_names)
413{
414 const blender::OffsetIndices faces = b_mesh.faces();
415 if (faces.is_empty()) {
416 return;
417 }
418
419 if (blender_uv_names.empty()) {
420 return;
421 }
422
423 const blender::bke::AttributeAccessor b_attributes = b_mesh.attributes();
424 const ustring render_name(std::string_view(b_mesh.default_uv_map_name()));
425 for (const ustring &uv_name : blender_uv_names) {
426 const bool active_render = uv_name == render_name;
427 const AttributeStandard uv_std = (active_render) ? ATTR_STD_UV : ATTR_STD_NONE;
428
429 /* Denotes whether UV map was requested directly. */
430 const bool need_uv = mesh->need_attribute(scene, uv_name) ||
431 (active_render && mesh->need_attribute(scene, uv_std));
432 if (!need_uv) {
433 continue;
434 }
435
436 Attribute *uv_attr = nullptr;
437 const blender::bke::AttributeReader b_uv_map = b_attributes.lookup<blender::float2>(
438 uv_name.c_str(), blender::bke::AttrDomain::Corner);
439 const blender::CommonVArrayInfo info = b_uv_map.varray.common_info();
441 if (active_render) {
442 uv_attr = mesh->subd_attributes.add_shared(
443 uv_std, uv_name, info.data, b_uv_map.varray.size(), b_uv_map.sharing_info);
444 }
445 else {
446 uv_attr = mesh->subd_attributes.add_shared(uv_name,
447 TypeFloat2,
449 info.data,
450 b_uv_map.varray.size(),
451 b_uv_map.sharing_info);
452 }
453 }
454 else {
455 if (active_render) {
456 uv_attr = mesh->subd_attributes.add(uv_std, uv_name);
457 }
458 else {
459 uv_attr = mesh->subd_attributes.add(uv_name, TypeFloat2, ATTR_ELEMENT_CORNER);
460 }
461
462 const blender::VArraySpan b_uv_map = *b_attributes.lookup<blender::float2>(
463 uv_name.c_str(), blender::bke::AttrDomain::Corner);
464 float2 *fdata = uv_attr->data_for_write<float2>();
465
466 for (const int i : faces.index_range()) {
467 const blender::IndexRange face = faces[i];
468 for (const int corner : face) {
469 *(fdata++) = make_float2(b_uv_map[corner][0], b_uv_map[corner][1]);
470 }
471 }
472 }
473
474 uv_attr->flags |= ATTR_SUBDIVIDE_SMOOTH_FVAR;
475 }
476}
477
478/* Create vertex pointiness attributes. */
479
480/* Compare vertices by sum of their coordinates. */
482 public:
483 VertexAverageComparator(const packed_float3 *verts, size_t /*num_verts*/) : verts_(verts) {}
484
485 bool operator()(const int &vert_idx_a, const int &vert_idx_b)
486 {
487 const float3 vert_a = verts_[vert_idx_a];
488 const float3 vert_b = verts_[vert_idx_b];
489 if (vert_a == vert_b) {
490 /* Special case for doubles, so we ensure ordering. */
491 return vert_idx_a > vert_idx_b;
492 }
493 const float x1 = vert_a.x + vert_a.y + vert_a.z;
494 const float x2 = vert_b.x + vert_b.y + vert_b.z;
495 return x1 < x2;
496 }
497
498 protected:
500};
501
502static void attr_create_pointiness(Mesh *mesh,
503 const blender::Span<blender::float3> positions,
504 const blender::Span<blender::float3> b_vert_normals,
506 bool subdivision)
507{
508 const int num_verts = positions.size();
509 if (positions.is_empty()) {
510 return;
511 }
512
513 /* STEP 1: Find out duplicated vertices and point duplicates to a single
514 * original vertex.
515 */
516 vector<int> sorted_vert_indices(num_verts);
517 for (int vert_index = 0; vert_index < num_verts; ++vert_index) {
518 sorted_vert_indices[vert_index] = vert_index;
519 }
520 const VertexAverageComparator compare(mesh->get_position(), mesh->num_verts());
521 sort(sorted_vert_indices.begin(), sorted_vert_indices.end(), compare);
522 /* This array stores index of the original vertex for the given vertex
523 * index.
524 */
525 vector<int> vert_orig_index(num_verts);
526 for (int sorted_vert_index = 0; sorted_vert_index < num_verts; ++sorted_vert_index) {
527 const int vert_index = sorted_vert_indices[sorted_vert_index];
528 const float3 &vert_co = mesh->get_position()[vert_index];
529 bool found = false;
530 for (int other_sorted_vert_index = sorted_vert_index + 1; other_sorted_vert_index < num_verts;
531 ++other_sorted_vert_index)
532 {
533 const int other_vert_index = sorted_vert_indices[other_sorted_vert_index];
534 const float3 &other_vert_co = mesh->get_position()[other_vert_index];
535 /* We are too far away now, we wouldn't have duplicate. */
536 if ((other_vert_co.x + other_vert_co.y + other_vert_co.z) -
537 (vert_co.x + vert_co.y + vert_co.z) >
538 3 * FLT_EPSILON)
539 {
540 break;
541 }
542 /* Found duplicate. */
543 if (len_squared(other_vert_co - vert_co) < FLT_EPSILON) {
544 found = true;
545 vert_orig_index[vert_index] = other_vert_index;
546 break;
547 }
548 }
549 if (!found) {
550 vert_orig_index[vert_index] = vert_index;
551 }
552 }
553 /* Make sure we always points to the very first orig vertex. */
554 for (int vert_index = 0; vert_index < num_verts; ++vert_index) {
555 int orig_index = vert_orig_index[vert_index];
556 while (orig_index != vert_orig_index[orig_index]) {
557 orig_index = vert_orig_index[orig_index];
558 }
559 vert_orig_index[vert_index] = orig_index;
560 }
561 sorted_vert_indices.free_memory();
562 /* STEP 2: Calculate vertex normals taking into account their possible
563 * duplicates which gets "welded" together.
564 */
565 vector<float3> vert_normal(num_verts, zero_float3());
566 /* First we accumulate all vertex normals in the original index. */
567 for (int vert_index = 0; vert_index < num_verts; ++vert_index) {
568 const float *b_vert_normal = b_vert_normals[vert_index];
569 const int orig_index = vert_orig_index[vert_index];
570 vert_normal[orig_index] += make_float3(b_vert_normal[0], b_vert_normal[1], b_vert_normal[2]);
571 }
572 /* Then we normalize the accumulated result and flush it to all duplicates
573 * as well.
574 */
575 for (int vert_index = 0; vert_index < num_verts; ++vert_index) {
576 const int orig_index = vert_orig_index[vert_index];
577 vert_normal[vert_index] = normalize(vert_normal[orig_index]);
578 }
579 /* STEP 3: Calculate pointiness using single ring neighborhood. */
580 vector<int> counter(num_verts, 0);
581 vector<float> raw_data(num_verts, 0.0f);
582 vector<float3> edge_accum(num_verts, zero_float3());
583 EdgeMap visited_edges;
584 memset(counter.data(), 0, sizeof(int) * counter.size());
585
586 for (const int i : edges.index_range()) {
587 const blender::int2 b_edge = edges[i];
588 const int v0 = vert_orig_index[b_edge[0]];
589 const int v1 = vert_orig_index[b_edge[1]];
590 if (visited_edges.exists(v0, v1)) {
591 continue;
592 }
593 visited_edges.insert(v0, v1);
594 const float3 co0 = make_float3(positions[v0][0], positions[v0][1], positions[v0][2]);
595 const float3 co1 = make_float3(positions[v1][0], positions[v1][1], positions[v1][2]);
596 const float3 edge = safe_normalize(co1 - co0);
597 edge_accum[v0] += edge;
598 edge_accum[v1] += -edge;
599 ++counter[v0];
600 ++counter[v1];
601 }
602 for (int vert_index = 0; vert_index < num_verts; ++vert_index) {
603 const int orig_index = vert_orig_index[vert_index];
604 if (orig_index != vert_index) {
605 /* Skip duplicates, they'll be overwritten later on. */
606 continue;
607 }
608 if (counter[vert_index] > 0) {
609 const float3 normal = vert_normal[vert_index];
610 const float angle = safe_acosf(dot(normal, edge_accum[vert_index] / counter[vert_index]));
611 raw_data[vert_index] = angle * M_1_PI_F;
612 }
613 else {
614 raw_data[vert_index] = 0.0f;
615 }
616 }
617 /* STEP 3: Blur vertices to approximate 2 ring neighborhood. */
618 AttributeSet &attributes = (subdivision) ? mesh->subd_attributes : mesh->attributes;
619 Attribute *attr = attributes.add(ATTR_STD_POINTINESS);
620 float *data = attr->data_for_write<float>();
621 memcpy(data, raw_data.data(), sizeof(float) * raw_data.size());
622 memset(counter.data(), 0, sizeof(int) * counter.size());
623 visited_edges.clear();
624 for (const int i : edges.index_range()) {
625 const blender::int2 b_edge = edges[i];
626 const int v0 = vert_orig_index[b_edge[0]];
627 const int v1 = vert_orig_index[b_edge[1]];
628 if (visited_edges.exists(v0, v1)) {
629 continue;
630 }
631 visited_edges.insert(v0, v1);
632 data[v0] += raw_data[v1];
633 data[v1] += raw_data[v0];
634 ++counter[v0];
635 ++counter[v1];
636 }
637 for (int vert_index = 0; vert_index < num_verts; ++vert_index) {
638 data[vert_index] /= counter[vert_index] + 1;
639 }
640 /* STEP 4: Copy attribute to the duplicated vertices. */
641 for (int vert_index = 0; vert_index < num_verts; ++vert_index) {
642 const int orig_index = vert_orig_index[vert_index];
643 data[vert_index] = data[orig_index];
644 }
645}
646
647/* The Random Per Island attribute is a random float associated with each
648 * connected component (island) of the mesh. The attribute is computed by
649 * first classifying the vertices into different sets using a Disjoint Set
650 * data structure. Then the index of the root of each vertex (Which is the
651 * representative of the set the vertex belongs to) is hashed and stored.
652 *
653 * We are using a face attribute to avoid interpolation during rendering,
654 * allowing the user to safely hash the output further. Had we used vertex
655 * attribute, the interpolation will introduce very slight variations,
656 * making the output unsafe to hash. */
658 Mesh *mesh,
659 const blender::Mesh &b_mesh,
660 bool subdivision)
661{
662 if (!mesh->need_attribute(scene, ATTR_STD_RANDOM_PER_ISLAND)) {
663 return;
664 }
665
666 if (b_mesh.verts_num == 0) {
667 return;
668 }
669
670 DisjointSet vertices_sets(b_mesh.verts_num);
671
672 const blender::Span<blender::int2> edges = b_mesh.edges();
673 const blender::Span<int> corner_verts = b_mesh.corner_verts();
674
675 for (const int i : edges.index_range()) {
676 vertices_sets.join(edges[i][0], edges[i][1]);
677 }
678
679 AttributeSet &attributes = (subdivision) ? mesh->subd_attributes : mesh->attributes;
681 float *data = attribute->data_for_write<float>();
682
683 if (!subdivision) {
684 const blender::Span<blender::int3> corner_tris = b_mesh.corner_tris();
685 if (!corner_tris.is_empty()) {
686 for (const int i : corner_tris.index_range()) {
687 const int vert = corner_verts[corner_tris[i][0]];
688 data[i] = hash_uint_to_float(vertices_sets.find(vert));
689 }
690 }
691 }
692 else {
693 const blender::OffsetIndices<int> faces = b_mesh.faces();
694 if (!faces.is_empty()) {
695 for (const int i : faces.index_range()) {
696 const int vert = corner_verts[faces[i].start()];
697 data[i] = hash_uint_to_float(vertices_sets.find(vert));
698 }
699 }
700 }
701}
702
703/* Create Mesh */
704
705static void create_mesh(Scene *scene,
706 Mesh *mesh,
707 const blender::Mesh &b_mesh,
708 const array<Node *> &used_shaders,
709 const bool need_motion,
710 const float motion_scale,
711 const bool subdivision = false)
712{
713 const blender::Span<blender::float3> positions = b_mesh.vert_positions();
714 const blender::OffsetIndices faces = b_mesh.faces();
715 const blender::Span<int> corner_verts = b_mesh.corner_verts();
716 const blender::bke::AttributeAccessor b_attributes = b_mesh.attributes();
717 const blender::bke::MeshNormalDomain normals_domain = b_mesh.normals_domain();
718 const int numfaces = (!subdivision) ? b_mesh.corner_tris().size() : faces.size();
719
720 const bool use_corner_normals = normals_domain == blender::bke::MeshNormalDomain::Corner &&
721 (mesh->get_subdivision_type() !=
723
724 /* If no faces, create empty mesh. */
725 if (faces.is_empty()) {
726 return;
727 }
728
729 const blender::VArraySpan material_indices = *b_attributes.lookup<int>(
730 "material_index", blender::bke::AttrDomain::Face);
731 const blender::VArraySpan sharp_faces = *b_attributes.lookup<bool>(
732 "sharp_face", blender::bke::AttrDomain::Face);
733
734 int numtris = 0;
735 if (!subdivision) {
736 numtris = numfaces;
737 }
738 /* allocate memory */
739 if (subdivision) {
740 mesh->resize_subd_faces(numfaces, corner_verts.size());
741 }
742 mesh->resize_mesh(positions.size(), numtris);
743
744 AttributeSet &attributes = (subdivision) ? mesh->subd_attributes : mesh->attributes;
745
746 // TODO: Implicit sharing is currently not used, because Blender float3 buffers don't have
747 // ATTRIBUTE_BUFFER_PADDING. Maybe add padding for Blender attributes?
748 Attribute *attr_P = attributes.add(ATTR_STD_POSITION);
749 attr_P->resize(positions.size());
750 packed_float3 *verts = attr_P->data_for_write<packed_float3>();
751 for (const int i : positions.index_range()) {
752 verts[i] = make_float3(positions[i][0], positions[i][1], positions[i][2]);
753 }
754 mesh->tag_position_modified();
755
756 if (subdivision || !use_corner_normals) {
757 Attribute *attr_N = attributes.add(ATTR_STD_VERTEX_NORMAL);
759 const blender::Span<blender::float3> vert_normals = b_mesh.vert_normals();
760 for (const int i : vert_normals.index_range()) {
761 N[i] = packed_normal(
762 make_float3(vert_normals[i][0], vert_normals[i][1], vert_normals[i][2]));
763 }
764 }
765
766 const set<ustring> blender_uv_names = get_blender_uv_names(b_mesh);
767
768 /* create generated coordinates from undeformed coordinates */
769 const bool need_default_tangent = (subdivision == false) && (blender_uv_names.empty()) &&
770 (mesh->need_attribute(scene, ATTR_STD_UV_TANGENT));
771 if (mesh->need_attribute(scene, ATTR_STD_GENERATED) || need_default_tangent) {
772 const float (*orco)[3] = static_cast<const float (*)[3]>(
773 CustomData_get_layer(&b_mesh.vert_data, blender::CD_ORCO));
774 Attribute *attr = attributes.add(ATTR_STD_GENERATED);
775
776 float3 loc;
777 float3 size;
778 mesh_texture_space(b_mesh, loc, size);
779
780 float texspace_location[3];
781 float texspace_size[3];
782 BKE_mesh_texspace_get(
783 const_cast<blender::Mesh *>(b_mesh.texcomesh ? b_mesh.texcomesh : &b_mesh),
784 texspace_location,
785 texspace_size);
786
787 packed_float3 *generated = attr->data_for_write<packed_float3>();
788
789 for (const int i : positions.index_range()) {
790 blender::float3 value;
791 if (orco) {
792 madd_v3_v3v3v3(value, texspace_location, orco[i], texspace_size);
793 }
794 else {
795 value = positions[i];
796 }
797 generated[i] = make_float3(value[0], value[1], value[2]) * size - loc;
798 }
799 }
800
801 auto clamp_material_index = [&](const int material_index) -> int {
802 return clamp(material_index, 0, used_shaders.size() - 1);
803 };
804
805 /* create faces */
806 if (!subdivision) {
807 int *triangles = mesh->get_triangles().data();
808 bool *smooth = mesh->get_smooth().data();
809 int *shader = mesh->get_shader().data();
810
811 const blender::Span<blender::int3> b_corner_tris = b_mesh.corner_tris();
813 corner_verts,
814 b_corner_tris,
815 blender::MutableSpan<int>(triangles, numtris * 3).cast<blender::int3>());
816
817 if (!material_indices.is_empty()) {
818 for (const int face : faces.index_range()) {
819 const int material_index = clamp_material_index(material_indices[face]);
821 face);
822 std::fill_n(shader + face_tris.start(), face_tris.size(), material_index);
823 }
824 }
825 else {
826 std::fill(shader, shader + numtris, 0);
827 }
828
829 if (!sharp_faces.is_empty()) {
830 for (const int face : faces.index_range()) {
831 const bool face_smooth = !sharp_faces[face];
833 face);
834 std::fill_n(smooth + face_tris.start(), face_tris.size(), face_smooth);
835 }
836 }
837 else {
838 /* All faces are sharp or smooth. */
839 std::fill(smooth, smooth + numtris, normals_domain != blender::bke::MeshNormalDomain::Face);
840 }
841
842 if (use_corner_normals) {
843 const blender::Span<blender::float3> b_corner_normals = b_mesh.corner_normals();
844 Attribute *attr_N = attributes.add(ATTR_STD_CORNER_NORMAL);
846
847 for (const int i : b_corner_tris.index_range()) {
848 const blender::int3 &tri = b_corner_tris[i];
849 for (int j = 0; j < 3; j++) {
850 const int corner = tri[j];
851 const float *normal = b_corner_normals[corner];
852 N[i * 3 + j] = packed_normal(make_float3(normal[0], normal[1], normal[2]));
853 }
854 }
855 }
856
857 mesh->tag_triangles_modified();
858 mesh->tag_shader_modified();
859 mesh->tag_smooth_modified();
860 }
861 else {
862 int *subd_start_corner = mesh->get_subd_start_corner().data();
863 int *subd_num_corners = mesh->get_subd_num_corners().data();
864 int *subd_shader = mesh->get_subd_shader().data();
865 bool *subd_smooth = mesh->get_subd_smooth().data();
866 int *subd_ptex_offset = mesh->get_subd_ptex_offset().data();
867 int *subd_face_corners = mesh->get_subd_face_corners().data();
868
869 if (!sharp_faces.is_empty()) {
870 for (int i = 0; i < numfaces; i++) {
871 subd_smooth[i] = !sharp_faces[i];
872 }
873 }
874 else {
875 /* All faces are sharp or smooth. */
876 std::fill(subd_smooth,
877 subd_smooth + numfaces,
878 normals_domain != blender::bke::MeshNormalDomain::Face);
879 }
880
881 if (!material_indices.is_empty()) {
882 for (int i = 0; i < numfaces; i++) {
883 subd_shader[i] = clamp_material_index(material_indices[i]);
884 }
885 }
886 else {
887 std::fill(subd_shader, subd_shader + numfaces, 0);
888 }
889
890 std::copy(corner_verts.data(), corner_verts.data() + corner_verts.size(), subd_face_corners);
891
892 const blender::OffsetIndices faces = b_mesh.faces();
893 int ptex_offset = 0;
894 for (const int i : faces.index_range()) {
895 const blender::IndexRange face = faces[i];
896
897 subd_start_corner[i] = face.start();
898 subd_num_corners[i] = face.size();
899 subd_ptex_offset[i] = ptex_offset;
900 const int num_ptex = (face.size() == 4) ? 1 : face.size();
901 ptex_offset += num_ptex;
902 }
903
904 mesh->tag_subd_face_corners_modified();
905 mesh->tag_subd_start_corner_modified();
906 mesh->tag_subd_num_corners_modified();
907 mesh->tag_subd_shader_modified();
908 mesh->tag_subd_smooth_modified();
909 mesh->tag_subd_ptex_offset_modified();
910 }
911
912 /* Create all needed attributes.
913 * The calculate functions will check whether they're needed or not.
914 */
915 if (mesh->need_attribute(scene, ATTR_STD_POINTINESS)) {
916 attr_create_pointiness(mesh, positions, b_mesh.vert_normals(), b_mesh.edges(), subdivision);
917 }
918 attr_create_random_per_island(scene, mesh, b_mesh, subdivision);
919 attr_create_generic(scene, mesh, b_mesh, subdivision, need_motion, motion_scale);
920
921 if (subdivision) {
922 attr_create_subd_uv_map(scene, mesh, b_mesh, blender_uv_names);
923 }
924 else {
925 attr_create_uv_map(scene, mesh, b_mesh, blender_uv_names);
926 }
927
928 /* For volume objects, create a matrix to transform from object space to
929 * mesh texture space. this does not work with deformations but that can
930 * probably only be done well with a volume grid mapping of coordinates. */
933 Transform *tfm = attr->data_for_write<Transform>();
934
935 float3 loc;
936 float3 size;
937 mesh_texture_space(b_mesh, loc, size);
938
939 *tfm = transform_translate(-loc) * transform_scale(size);
940 }
941}
942
943static void create_subd_mesh(Scene *scene,
944 Mesh *mesh,
945 BObjectInfo &b_ob_info,
946 const blender::Mesh &b_mesh,
947 const array<Node *> &used_shaders,
948 const bool need_motion,
949 const float motion_scale,
950 const float dicing_rate,
951 const int max_subdivisions)
952{
953 const blender::Object *b_ob = b_ob_info.real_object;
954
955 const auto &subsurf_mod = *b_ob->modifiers.last_as<const blender::SubsurfModifierData>();
956
957 const bool use_creases = (subsurf_mod.flags & blender::eSubsurfModifierFlag_UseCrease) != 0;
958
959 create_mesh(scene, mesh, b_mesh, used_shaders, need_motion, motion_scale, true);
960
961 if (use_creases) {
962 const blender::VArraySpan creases = *b_mesh.attributes().lookup<float>(
963 "crease_edge", blender::bke::AttrDomain::Edge);
964 if (!creases.is_empty()) {
965 size_t num_creases = 0;
966 for (const int i : creases.index_range()) {
967 if (creases[i] != 0.0f) {
968 num_creases++;
969 }
970 }
971
972 mesh->reserve_subd_creases(num_creases);
973
974 const blender::Span<blender::int2> edges = b_mesh.edges();
975 for (const int i : edges.index_range()) {
976 const float crease = creases[i];
977 if (crease != 0.0f) {
978 const blender::int2 &b_edge = edges[i];
979 mesh->add_edge_crease(b_edge[0], b_edge[1], crease);
980 }
981 }
982 }
983
984 const blender::VArraySpan vert_creases = *b_mesh.attributes().lookup<float>(
985 "crease_vert", blender::bke::AttrDomain::Point);
986 if (!vert_creases.is_empty()) {
987 for (const int i : vert_creases.index_range()) {
988 if (vert_creases[i] != 0.0f) {
989 mesh->add_vertex_crease(i, vert_creases[i]);
990 }
991 }
992 }
993 }
994
995 /* Set subd parameters. */
997 switch (subsurf_mod.adaptive_space) {
1000 break;
1003 break;
1004 }
1005 const float subd_dicing_rate = (space == Mesh::SUBDIVISION_ADAPTIVE_SPACE_PIXEL) ?
1006 max(0.1f, subsurf_mod.adaptive_pixel_size * dicing_rate) :
1007 subsurf_mod.adaptive_object_edge_length * dicing_rate;
1008
1009 mesh->set_subd_adaptive_space(space);
1010 mesh->set_subd_dicing_rate(subd_dicing_rate);
1011 mesh->set_subd_max_level(max_subdivisions);
1012 mesh->set_subd_objecttoworld(get_transform(b_ob->object_to_world()));
1013}
1014
1015/* Sync */
1016
1017void BlenderSync::sync_mesh(BObjectInfo &b_ob_info, Mesh *mesh)
1018{
1019 /* make a copy of the shaders as the caller in the main thread still need them for syncing the
1020 * attributes */
1021 array<Node *> used_shaders = mesh->get_used_shaders();
1022
1023 Mesh new_mesh;
1024 new_mesh.set_used_shaders(used_shaders);
1025
1026 if (view_layer.use_surfaces) {
1027 object_subdivision_to_mesh(
1028 *b_ob_info.real_object, new_mesh, preview, use_adaptive_subdivision);
1029 const blender::Mesh *b_mesh = object_to_mesh(b_ob_info);
1030
1031 if (b_mesh) {
1032 /* Motion blur attribute is relative to seconds, we need it relative to frames. */
1033 const bool need_motion = object_need_motion_attribute(b_ob_info, scene);
1034 const float motion_scale = (need_motion) ?
1035 scene->motion_shutter_time() /
1036 (b_scene->r.frs_sec / b_scene->r.frs_sec_base) :
1037 0.0f;
1038
1039 /* Sync mesh itself. */
1040 if (new_mesh.get_subdivision_type() != Mesh::SUBDIVISION_NONE) {
1041 create_subd_mesh(scene,
1042 &new_mesh,
1043 b_ob_info,
1044 *b_mesh,
1045 new_mesh.get_used_shaders(),
1046 need_motion,
1047 motion_scale,
1048 dicing_rate,
1049 max_subdivisions);
1050 }
1051 else {
1052 create_mesh(scene,
1053 &new_mesh,
1054 *b_mesh,
1055 new_mesh.get_used_shaders(),
1056 need_motion,
1057 motion_scale,
1058 false);
1059 }
1060
1061 free_object_to_mesh(b_ob_info, const_cast<blender::Mesh &>(*b_mesh));
1062 }
1063
1064 if (scene->need_motion() == Scene::MOTION_PASS_INTERACTIVE &&
1065 mesh->num_verts() == new_mesh.num_verts())
1066 {
1067 new_mesh.set_motion_steps(2);
1068
1069 Attribute *attr_P = mesh->attributes.find(ATTR_STD_POSITION);
1070 Attribute *new_attr_P = new_mesh.attributes.find(ATTR_STD_POSITION);
1071 if (attr_P->has_motion()) {
1072 /* Carry the previous frame's positions forward as the motion step. */
1073 new_attr_P->take_motion_from(*attr_P);
1074 }
1075 else {
1076 new_attr_P->add_motion(&new_mesh);
1077 new_mesh.copy_center_to_motion_step(0);
1078 }
1079 }
1080 }
1081
1082 /* update original sockets */
1083
1084 mesh->clear_non_sockets();
1085
1086 for (const SocketType &socket : new_mesh.type->inputs) {
1087 /* Those sockets are updated in sync_object, so do not modify them. */
1088 if (socket.name == "use_motion_blur" || socket.name == "used_shaders") {
1089 continue;
1090 }
1091 mesh->set_value(socket, new_mesh, socket);
1092 }
1093
1094 mesh->attributes.update(std::move(new_mesh.attributes));
1095 mesh->subd_attributes.update(std::move(new_mesh.subd_attributes));
1096
1097 mesh->set_num_subd_faces(new_mesh.get_num_subd_faces());
1098
1099 /* tag update */
1100 const bool rebuild = (mesh->triangles_is_modified()) || (mesh->subd_num_corners_is_modified()) ||
1101 (mesh->subd_shader_is_modified()) || (mesh->subd_smooth_is_modified()) ||
1102 (mesh->subd_ptex_offset_is_modified()) ||
1103 (mesh->subd_start_corner_is_modified()) ||
1104 (mesh->subd_face_corners_is_modified());
1105
1106 mesh->tag_update(scene, rebuild);
1107}
1108
1109void BlenderSync::sync_mesh_motion(BObjectInfo &b_ob_info, Mesh *mesh, const int motion_step)
1110{
1111 /* Skip if no vertices were exported. */
1112 const size_t numverts = mesh->num_verts();
1113 const size_t numtris = mesh->num_triangles();
1114 if (numverts == 0) {
1115 return;
1116 }
1117
1118 /* Skip objects without deforming modifiers. this is not totally reliable,
1119 * would need a more extensive check to see which objects are animated. */
1120 const blender::Mesh *b_mesh = nullptr;
1121 if (ccl::BKE_object_is_deform_modified(b_ob_info, *b_scene, preview)) {
1122 /* get derived mesh */
1123 b_mesh = object_to_mesh(b_ob_info);
1124 }
1125
1126 const std::string ob_name = BKE_id_name(b_ob_info.real_object->id);
1127
1128 /* TODO(sergey): Perform preliminary check for number of vertices. */
1129 if (b_mesh) {
1130 const int b_verts_num = b_mesh->verts_num;
1131 const blender::Span<blender::float3> positions = b_mesh->vert_positions();
1132 if (positions.is_empty()) {
1133 free_object_to_mesh(b_ob_info, *const_cast<blender::Mesh *>(b_mesh));
1134 return;
1135 }
1136
1137 AttributeSet &attributes = mesh->get_subdivision_type() == Mesh::SUBDIVISION_NONE ?
1138 mesh->attributes :
1139 mesh->subd_attributes;
1140
1141 /* Export deformed coordinates. */
1142 /* Find attributes. */
1143 Attribute *attr_P = attributes.find(ATTR_STD_POSITION);
1144 Attribute *attr_N = attributes.find(ATTR_STD_VERTEX_NORMAL);
1146 bool new_attribute = false;
1147 /* Set motion steps on attributes if not already done. */
1148 if (!attr_P->has_motion()) {
1149 attr_P->add_motion(mesh);
1150 if (attr_N) {
1151 attr_N->add_motion(mesh);
1152 }
1153 if (attr_cN) {
1154 attr_cN->add_motion(mesh);
1155 }
1156
1157 new_attribute = true;
1158 }
1159 /* Load vertex data from mesh. */
1160 const size_t attr_numverts = attr_P->size;
1161 const int attr_step = motion_step + 1;
1162 packed_float3 *mP = attr_P->data_for_write<packed_float3>(attr_step);
1163 packed_normal *mN = attr_N ? attr_N->data_for_write<packed_normal>(attr_step) : nullptr;
1164 packed_normal *mcN = attr_cN ? attr_cN->data_for_write<packed_normal>(attr_step) : nullptr;
1165
1166 bool topology_changed = b_verts_num != attr_numverts;
1167
1168 /* NOTE: We don't copy more that existing amount of vertices to prevent
1169 * possible memory corruption.
1170 */
1171 for (int i = 0; i < std::min<size_t>(b_verts_num, attr_numverts); i++) {
1172 mP[i] = make_float3(positions[i][0], positions[i][1], positions[i][2]);
1173 }
1174 if (mN) {
1175 const blender::Span<blender::float3> b_vert_normals = b_mesh->vert_normals();
1176 for (int i = 0; i < std::min<size_t>(b_verts_num, attr_numverts); i++) {
1177 mN[i] = packed_normal(
1178 make_float3(b_vert_normals[i][0], b_vert_normals[i][1], b_vert_normals[i][2]));
1179 }
1180 }
1181 if (mcN) {
1182 const blender::Span<blender::float3> b_corner_normals = b_mesh->corner_normals();
1183 const blender::Span<blender::int3> b_corner_tris = b_mesh->corner_tris();
1184 const int mincorners = std::min<int>(b_corner_tris.size(), numtris);
1185
1186 for (int i = 0; i < mincorners; i++) {
1187 const blender::int3 &tri = b_corner_tris[i];
1188 for (int j = 0; j < 3; j++) {
1189 const int corner = tri[j];
1190 const float *normal = b_corner_normals[corner];
1191 mcN[i * 3 + j] = packed_normal(make_float3(normal[0], normal[1], normal[2]));
1192 }
1193 }
1194
1195 topology_changed |= b_corner_tris.size() != numtris;
1196 }
1197 if (new_attribute) {
1198 /* In case of new attribute, we verify if there really was any motion. */
1199 if (topology_changed ||
1200 memcmp(mP, attr_P->data<packed_float3>(), sizeof(packed_float3) * attr_numverts) == 0)
1201 {
1202 /* no motion, remove attributes again */
1203 if (topology_changed) {
1204 LOG_WARNING << "Topology differs, disabling motion blur for object " << ob_name;
1205 }
1206 else {
1207 LOG_TRACE << "No actual deformation motion for object " << ob_name;
1208 }
1209 attr_P->remove_motion();
1210 if (attr_N) {
1211 attr_N->remove_motion();
1212 }
1213 if (attr_cN) {
1214 attr_cN->remove_motion();
1215 }
1216 }
1217 else if (motion_step > 0) {
1218 LOG_TRACE << "Filling deformation motion for object " << ob_name;
1219 /* motion, fill up previous steps that we might have skipped because
1220 * they had no motion, but we need them anyway now */
1221 for (int step = 0; step < motion_step; step++) {
1223 }
1224 }
1225 }
1226 else {
1227 if (topology_changed) {
1228 LOG_WARNING << "Topology differs, discarding motion blur for object " << ob_name
1229 << " at time " << motion_step;
1230 mesh->copy_center_to_motion_step(motion_step);
1231 }
1232 }
1233
1234 free_object_to_mesh(b_ob_info, *const_cast<blender::Mesh *>(b_mesh));
1235 return;
1236 }
1237
1238 /* No deformation on this frame, copy coordinates if other frames did have it. */
1239 mesh->copy_center_to_motion_step(motion_step);
1240}
1241
Generic geometry attributes built on CustomData.
CustomData interface, see also DNA_customdata_types.h.
blender::float3 packed_float3
static void attr_create_subd_uv_map(Scene *scene, Mesh *mesh, const blender::Mesh &b_mesh, const set< ustring > &blender_uv_names)
static void create_mesh(Scene *scene, Mesh *mesh, const blender::Mesh &b_mesh, const array< Node * > &used_shaders, const bool need_motion, const float motion_scale, const bool subdivision=false)
static void attr_create_generic(Scene *scene, Mesh *mesh, const blender::Mesh &b_mesh, const bool subdivision, const bool need_motion, const float motion_scale)
static void attr_create_motion_from_velocity(Mesh *mesh, const blender::Mesh &b_mesh, const blender::Span< blender::float3 > b_attr, const float motion_scale)
static bool attr_need_motion_vertex_normals(const blender::Mesh &b_mesh)
static void create_subd_mesh(Scene *scene, Mesh *mesh, BObjectInfo &b_ob_info, const blender::Mesh &b_mesh, const array< Node * > &used_shaders, const bool need_motion, const float motion_scale, const float dicing_rate, const int max_subdivisions)
static CCL_NAMESPACE_BEGIN void attr_create_motion_corner_normals(const blender::Mesh &b_mesh, const blender::Span< blender::float3 > positions, packed_normal *N)
static set< ustring > get_blender_uv_names(const blender::Mesh &b_mesh)
static void attr_create_random_per_island(Scene *scene, Mesh *mesh, const blender::Mesh &b_mesh, bool subdivision)
static void attr_create_pointiness(Mesh *mesh, const blender::Span< blender::float3 > positions, const blender::Span< blender::float3 > b_vert_normals, const blender::Span< blender::int2 > edges, bool subdivision)
static AttributeElement blender_domain_to_attr_element(const blender::bke::AttrDomain b_domain)
static void attr_create_motion_vertex_normals(const blender::Mesh &b_mesh, packed_normal *N)
static void attr_create_uv_map(Scene *scene, Mesh *mesh, const blender::Mesh &b_mesh, const set< ustring > &blender_uv_names)
btScalar max
void sort(btMatrix3x3 &U, btVector3 &sigma, btMatrix3x3 &V, int t)
Helper function of 3X3 SVD for sorting singular values.
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
Definition btVector3.h:356
void update(AttributeSet &&new_attributes)
Attribute * find(ustring name) const
Attribute * add(ustring name, const TypeDesc type, AttributeElement element)
Attribute * add_shared(ustring name, const TypeDesc type, AttributeElement element, const void *data, int size, ImplicitSharingInfo sharing_info)
size_t find(size_t x)
void join(const size_t x, const size_t y)
void insert(int v0, int v1)
bool exists(int v0, int v1)
void tag_position_modified()
const packed_float3 * get_position() const
void tag_update(Scene *scene, bool rebuild)
AttributeSet attributes
bool need_attribute(const Scene *scene, AttributeStandard std)
size_t get_num_subd_faces() const
Definition scene/mesh.h:221
SubdivisionAdaptiveSpace
Definition scene/mesh.h:134
@ SUBDIVISION_ADAPTIVE_SPACE_OBJECT
Definition scene/mesh.h:136
@ SUBDIVISION_ADAPTIVE_SPACE_PIXEL
Definition scene/mesh.h:135
NODE_DECLARE size_t num_verts() const
void reserve_subd_creases(const size_t num_creases)
AttributeSet subd_attributes
Definition scene/mesh.h:169
void copy_center_to_motion_step(const int motion_step)
void set_num_subd_faces(const size_t num_subd_faces_)
Definition scene/mesh.h:225
void add_vertex_crease(const int v, const float weight)
@ SUBDIVISION_NONE
Definition scene/mesh.h:114
@ SUBDIVISION_CATMULL_CLARK
Definition scene/mesh.h:116
size_t num_triangles() const
Definition scene/mesh.h:73
void clear_non_sockets()
void resize_subd_faces(const int numfaces, const int numcorners)
void resize_mesh(const int numverts, const int numtris)
void add_edge_crease(const int v0, const int v1, const float weight)
Definition scene.h:133
@ MOTION_PASS_INTERACTIVE
Definition scene.h:207
bool operator()(const int &vert_idx_a, const int &vert_idx_b)
const packed_float3 * verts_
VertexAverageComparator(const packed_float3 *verts, size_t)
size_t size() const
const T * data() const
Definition BLI_array.hh:323
bool is() const
constexpr int64_t size() const
constexpr int64_t start() const
constexpr const T * data() const
Definition BLI_span.hh:219
constexpr int64_t size() const
Definition BLI_span.hh:256
constexpr IndexRange index_range() const
Definition BLI_span.hh:405
constexpr bool is_empty() const
Definition BLI_span.hh:264
void foreach_attribute(const FunctionRef< void(const AttributeIter &)> fn) const
GAttributeReader lookup(const StringRef name) const
GAttributeReader get() const
const DataVariant & data() const
constexpr bool is_empty() const
constexpr IndexRange index_range() const
void free_memory()
#define M_1_PI_F
#define CCL_NAMESPACE_END
ccl_device_forceinline float3 make_float3(const float x, const float y, const float z)
ccl_device_forceinline uchar4 make_uchar4(const uchar x, const uchar y, const uchar z, const uchar w)
float hash_uint_to_float(uint kx)
#define assert(assertion)
#define FLT_EPSILON
#define smooth
#define attribute(slot)
VecBase< float, D > normalize(VecOp< float, D >) RET
float dot(VecOp< float, D >, VecOp< float, D >) RET
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
constexpr T clamp(T, U, U) RET
VecT safe_normalize(VecT vector)
@ ATTR_SUBDIVIDE_SMOOTH_FVAR
AttributeElement
@ ATTR_ELEMENT_NONE
@ ATTR_ELEMENT_CORNER_BYTE
@ ATTR_ELEMENT_CORNER
@ ATTR_ELEMENT_VERTEX
@ ATTR_ELEMENT_FACE
AttributeStandard
@ ATTR_STD_GENERATED_TRANSFORM
@ ATTR_STD_UV
@ ATTR_STD_VERTEX_NORMAL
@ ATTR_STD_UV_TANGENT
@ ATTR_STD_NONE
@ ATTR_STD_VERTEX_COLOR
@ ATTR_STD_POSITION
@ ATTR_STD_CORNER_NORMAL
@ ATTR_STD_POINTINESS
@ ATTR_STD_GENERATED
@ ATTR_STD_RANDOM_PER_ISLAND
#define LOG_WARNING
Definition log.h:103
#define LOG_TRACE
Definition log.h:108
ccl_device float safe_acosf(const float a)
Definition math_base.h:590
ccl_device_inline dual1 len_squared(const ccl_private dual< T > &a)
Definition math_dual.h:273
CCL_NAMESPACE_BEGIN ccl_device_inline float3 zero_float3()
Definition math_float3.h:17
ccl_device_inline int4 cast(const float4 a)
Definition math_float4.h:32
#define N
void to_static_type(const CPPType &cpp_type, Fn &&fn)
void normals_calc_corners(Span< float3 > vert_positions, OffsetIndices< int > faces, Span< int > corner_verts, Span< int > corner_edges, GroupedSpan< int > vert_to_face_map, Span< float3 > face_normals, Span< bool > sharp_edges, Span< bool > sharp_faces, Span< short2 > custom_normals, CornerNormalSpaceArray *r_fan_spaces, MutableSpan< float3 > r_corner_normals)
void vert_tris_from_corner_tris(Span< int > corner_verts, Span< int3 > corner_tris, MutableSpan< int3 > vert_tris)
IndexRange face_triangles_range(OffsetIndices< int > faces, int face_i)
Definition BKE_mesh.hh:359
void normals_calc_faces(Span< float3 > vert_positions, OffsetIndices< int > faces, Span< int > corner_verts, MutableSpan< float3 > face_normals)
bool attribute_name_is_anonymous(const StringRef name)
@ SUBSURF_ADAPTIVE_SPACE_PIXEL
@ SUBSURF_ADAPTIVE_SPACE_OBJECT
const char * BKE_id_name(const ID &id)
@ eSubsurfModifierFlag_UseCrease
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
VecBase< int32_t, 3 > int3
VecBase< int16_t, 2 > short2
VecBase< float, 3 > float3
ColorSceneLinearByteEncoded4b< eAlpha::Premultiplied > ColorGeometry4b
#define make_float2
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
blender::Object * real_object
vector< SocketType, std::allocator< SocketType > > inputs
Definition node_type.h:131
const NodeType * type
Definition graph/node.h:179
void set_value(const SocketType &socket, const Node &other, const SocketType &other_socket)
ustring name
Definition node_type.h:84
struct Mesh * texcomesh
CustomData vert_data
ListBaseT< ModifierData > modifiers
const ImplicitSharingInfo * sharing_info
float z
Definition sky_math.h:136
float y
Definition sky_math.h:136
float x
Definition sky_math.h:136
packed_normal()=default
ccl_device_inline Transform transform_scale(const float3 s)
Definition transform.h:313
ccl_device_inline Transform transform_translate(const float3 t)
Definition transform.h:296