65 const bool conv_polys = (
76 for (
const DispList &dl : *dispbase) {
78 totvert += dl.parts * dl.nr;
79 totedge += dl.parts * (dl.nr - 1);
83 totvert += dl.parts * dl.nr;
84 totedge += dl.parts * dl.nr;
90 totvert += dl.parts * dl.nr;
91 tot = (((dl.flag &
DL_CYCL_U) ? 1 : 0) + (dl.nr - 1)) *
92 (((dl.flag &
DL_CYCL_V) ? 1 : 0) + (dl.parts - 1));
124 mesh->uv_maps_active_set(uv_name);
125 mesh->uv_maps_default_set(uv_name);
132 for (
const DispList &dl : *dispbase) {
133 const bool is_smooth = (dl.rt &
CU_SMOOTH) != 0;
136 const int startvert = dst_vert;
137 a = dl.parts * dl.nr;
138 const float *
data = dl.verts;
145 for (a = 0; a < dl.parts; a++) {
147 for (
b = 1;
b < dl.nr;
b++) {
148 edges[dst_edge][0] = startvert + ofs +
b - 1;
149 edges[dst_edge][1] = startvert + ofs +
b;
157 const int startvert = dst_vert;
158 a = dl.parts * dl.nr;
159 const float *
data = dl.verts;
166 for (a = 0; a < dl.parts; a++) {
168 for (
b = 0;
b < dl.nr;
b++) {
169 edges[dst_edge][0] = startvert + ofs +
b;
170 if (
b == dl.nr - 1) {
171 edges[dst_edge][1] = startvert + ofs;
174 edges[dst_edge][1] = startvert + ofs +
b + 1;
182 const int startvert = dst_vert;
184 const float *
data = dl.verts;
192 const int *
index = dl.index;
194 corner_verts[dst_loop + 0] = startvert +
index[0];
195 corner_verts[dst_loop + 1] = startvert +
index[2];
196 corner_verts[dst_loop + 2] = startvert +
index[1];
197 face_offsets[dst_poly] = dst_loop;
198 material_indices.
span[dst_poly] = dl.col;
200 for (
int i = 0; i < 3; i++) {
201 uv_map[dst_loop + i][0] = (corner_verts[dst_loop + i] - startvert) /
float(dl.nr - 1);
202 uv_map[dst_loop + i][1] = 0.0f;
205 sharp_faces.span[dst_poly] = !is_smooth;
212 const int startvert = dst_vert;
213 a = dl.parts * dl.nr;
214 const float *
data = dl.verts;
221 for (a = 0; a < dl.parts; a++) {
223 if ((dl.flag &
DL_CYCL_V) == 0 && a == dl.parts - 1) {
229 p1 = startvert + dl.nr * a;
236 p2 = startvert + dl.nr * a;
242 if ((dl.flag &
DL_CYCL_V) && a == dl.parts - 1) {
243 p3 -= dl.parts * dl.nr;
244 p4 -= dl.parts * dl.nr;
247 for (;
b < dl.nr;
b++) {
248 corner_verts[dst_loop + 0] = p1;
249 corner_verts[dst_loop + 1] = p3;
250 corner_verts[dst_loop + 2] = p4;
251 corner_verts[dst_loop + 3] = p2;
252 face_offsets[dst_poly] = dst_loop;
253 material_indices.
span[dst_poly] = dl.col;
255 int orco_sizeu = dl.nr - 1;
256 int orco_sizev = dl.parts - 1;
269 for (
int i = 0; i < 4; i++) {
271 int v = corner_verts[dst_loop + i] - startvert;
273 uv_map[dst_loop + i][0] = (
v / dl.nr) /
float(orco_sizev);
274 uv_map[dst_loop + i][1] = (
v % dl.nr) /
float(orco_sizeu);
277 if (
ELEM(i, 1, 2) && uv_map[dst_loop + i][0] == 0.0f) {
278 uv_map[dst_loop + i][0] = 1.0f;
280 if (
ELEM(i, 0, 1) && uv_map[dst_loop + i][1] == 0.0f) {
281 uv_map[dst_loop + i][1] = 1.0f;
285 sharp_faces.span[dst_poly] = !is_smooth;
302 material_indices.
finish();
303 sharp_faces.finish();
325 const ListBaseT<DispList> *dispbase)
327 const Curve *cu = id_cast<const Curve *>(ob->
data);
331 mesh->mat = MEM_dupalloc(cu->
mat);
339 ListBaseT<DispList> disp = {
nullptr,
nullptr};
373 ListBaseT<Nurb> *nurblist,
374 const int edge_users_test)
384 ListBaseT<EdgeLink> edges = {
nullptr,
nullptr};
389 for (
const int edge : corner_edges.
slice(polys[i])) {
396 if (edge_users[i] == edge_users_test) {
398 edl->
edge = &mesh_edges[i];
403 MEM_delete(edge_users);
406 while (edges.first()) {
409 ListBaseT<VertLink> polyline = {
nullptr,
nullptr};
412 int2 &edge_current = *
static_cast<int2 *
>(
const_cast<void *
>((edges.last())->edge));
413 uint startVert = edge_current[0];
414 uint endVert = edge_current[1];
429 const int2 &edge = *
static_cast<int2 *
>(
const_cast<void *
>(edl->
edge));
431 if (edge[0] == endVert) {
438 else if (edge[1] == endVert) {
445 else if (edge[0] == startVert) {
452 else if (edge[1] == startVert) {
465 if (startVert == endVert) {
478 nu = MEM_new<Nurb>(__func__);
480 nu->
pntsu = faces_num;
489 vl = polyline.first();
491 for (i = 0, bp = nu->
bp; i < faces_num;
498 polyline.free_no_destruct();
520 ListBaseT<Nurb> nurblist = {
nullptr,
nullptr};
525 if (nurblist.first()) {
532 ob->
data = id_cast<ID *>(cu);
566 if (src.sharing_info && src.varray.is_span()) {
579 ob->
data = id_cast<ID *>(pointcloud);
595 mesh->verts_num = points->totpoint;
606 if (src.sharing_info && src.varray.is_span()) {
632 const Curve *curve = id_cast<const Curve *>(
object->data);
645 static_cast<const ID *
>(
object->data),
648 Curve *temp_curve = id_cast<Curve *>(temp_object->
data);
665 ID *final_object_data = temp_object->
data;
667 Curve &curve = *
reinterpret_cast<Curve *
>(final_object_data);
675 const bool object_data_stored_in_data_eval = final_object_data ==
679 if (!object_data_stored_in_data_eval) {
690 Curve &curve = *id_cast<Curve *>(
object.
data);
700 if (curve.
bevobj !=
nullptr) {
703 bevel_object.
runtime = &bevel_runtime;
705 bevel_object.
modifiers.clear_no_delete();
707 curve.
bevobj = &bevel_object;
716 taper_object.
runtime = &taper_runtime;
718 taper_object.
modifiers.clear_no_delete();
742 return geometry_set_eval->get_curves();
771 ID *temp_data = temp_object->
data;
775 if (temp_data != temp_object->
data) {
778 Curve *curve =
reinterpret_cast<Curve *
>(temp_data);
804 if (mesh_eval ==
nullptr) {
818 else if (ensure_subdivision) {
832 const bool preserve_origindex,
833 const bool ensure_subdivision)
839 if (depsgraph ==
nullptr) {
845 object_for_eval.
runtime = &runtime;
853 if (preserve_origindex) {
862 if (ensure_subdivision) {
866 if (
result != result_maybe_subdiv) {
869 if (
result->runtime->mesh_eval == result_maybe_subdiv) {
870 result->runtime->mesh_eval =
nullptr;
872 result = result_maybe_subdiv;
885 const bool preserve_all_data_layers,
886 const bool preserve_origindex,
887 const bool use_subdivision)
893 (preserve_all_data_layers || preserve_origindex))
896 depsgraph,
object, preserve_origindex, use_subdivision);
898 const Mesh *mesh_input = id_cast<const Mesh *>(
object->data);
903 mesh_input = editmesh_eval_final;
911 const bool preserve_all_data_layers,
912 const bool preserve_origindex,
913 const bool ensure_subdivision)
915 Mesh *new_mesh =
nullptr;
927 depsgraph,
object, preserve_all_data_layers, preserve_origindex, ensure_subdivision);
933 if (new_mesh ==
nullptr) {
958 if (*id_p ==
nullptr) {
969 if (*id_p ==
nullptr) {
986 Depsgraph *depsgraph,
988 bool preserve_all_data_layers)
993 if (
mesh ==
nullptr) {
997 return mesh_in_bmain;
1021 mesh_in_bmain->
mat =
mesh->mat;
1023 mesh->mat =
nullptr;
1028 mesh_in_bmain->attributes_for_write().remove_anonymous();
1039 return mesh_in_bmain;
1045 if (src_cache.is_cached() && src_cache.data().mask.is_empty()) {
1046 dst.tag_loose_verts_none();
1053 if (src_cache.is_cached() && src_cache.data().mask.is_empty()) {
1054 dst.tag_loose_edges_none();
1060 if (src.no_overlapping_topology()) {
1061 dst.tag_overlapping_none();
1077 const int active_kb_index =
object.shapenr - 1;
1080 CLOG_ERROR(&
LOG,
"Could not find object's active shapekey %d", active_kb_index);
1089 const int actshape_uid)
1097 MEM_SAFE_DELETE_VOID(kb->
data);
1102 if (kb->
uid == actshape_uid) {
1103 mesh.attributes().lookup<
float3>(
"position").varray.materialize(kb_coords);
1112 MEM_SAFE_DELETE_VOID(kb.
data);
1115 CLOG_ERROR(&
LOG,
"Data for shape key '%s' on mesh missing from evaluated mesh ", kb.
name);
1165 if (process_shape_keys) {
1166 if (
Key *key_dst = mesh_dst->
key) {
1172 else if (verts_num_changed) {
1173 CLOG_WARN(&
LOG,
"Shape key data lost when replacing mesh '%s' in Main", mesh_src->
id.
name);
1175 mesh_dst->
key =
nullptr;
1194 const int totvert = mesh_src->
verts_num;
Low-level operations for curves.
display list (or rather multi purpose list) stuff.
General operations, lookup, etc. for materials.
General operations, lookup, etc. for blender objects.
General operations for point clouds.
#define CLOG_ERROR(clg_ref,...)
#define CLOG_WARN(clg_ref,...)
Object is a sort of wrapper for general info.
Read Blender memory allocation and freeing.
#define CD_MASK_ORIGINDEX
constexpr IndexRange()=default
constexpr MutableSpan()=default
constexpr void copy_from(Span< T > values) const
constexpr Span slice(int64_t start, int64_t size) const
constexpr int64_t size() const
constexpr IndexRange index_range() const
constexpr const char * c_str() const
GAttributeReader lookup(const StringRef name) const
bool add(const StringRef name, const AttrDomain domain, const AttrType data_type, const AttributeInit &initializer)
GSpanAttributeWriter lookup_or_add_for_write_span(StringRef name, AttrDomain domain, AttrType data_type, const AttributeInit &initializer=AttributeInitDefaultValue())
GSpanAttributeWriter lookup_or_add_for_write_only_span(StringRef name, AttrDomain domain, AttrType data_type)
IndexRange index_range() const
auto attribute_filter_from_skip_ref(const Span< StringRef > skip)
void copy_attributes(const AttributeAccessor src_attributes, AttrDomain src_domain, AttrDomain dst_domain, const AttributeFilter &attribute_filter, MutableAttributeAccessor dst_attributes)
GeometrySet object_get_evaluated_geometry_set(const Object &object, bool apply_subdiv=true)
void mesh_calc_edges(Mesh &mesh, bool keep_existing_edges, bool select_new_edges)
Mesh * curve_to_wire_mesh(const CurvesGeometry &curve, const bke::AttributeFilter &attribute_filter={})
void mesh_ensure_active_uv_map(Mesh &mesh)
AttrType cpp_type_to_attribute_type(const CPPType &type)
Mesh * mesh_create_eval_final(Depsgraph *depsgraph, const Scene *scene, Object *ob, const CustomData_MeshMasks *dataMask)
internal::ShallowZeroInitializeTag shallow_zero_initialize()
internal::ShallowDataConstRef< T > shallow_copy(const T &other)
void BKE_mesh_to_curve_nurblist(const Mesh *mesh, ListBaseT< Nurb > *nurblist, int edge_users_test)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
static void copy_loose_edge_hint(const Mesh &src, Mesh &dst)
static Mesh * mesh_new_from_mesh(Object *object, const Mesh *mesh, const bool ensure_subdivision)
Mesh * BKE_mesh_new_from_object_to_bmain(Main *bmain, Depsgraph *depsgraph, Object *object, bool preserve_all_data_layers)
void BKE_mesh_copy_parameters(Mesh *me_dst, const Mesh *me_src)
char * STRNCPY(char(&dst)[N], const char *src)
void BKE_object_runtime_reset(Object *object)
int CustomData_number_of_layers(const CustomData *data, eCustomDataType type)
void BKE_mesh_clear_geometry_and_metadata(Mesh *mesh)
MINLINE void copy_v3_v3(float r[3], const float a[3])
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
void BLI_addhead(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
static void copy_overlapping_hint(const Mesh &src, Mesh &dst)
bool CustomData_has_layer(const CustomData *data, eCustomDataType type)
void BKE_object_runtime_free_data(Object *object)
Mesh * BKE_mesh_copy_for_eval(const Mesh &source)
static Mesh * mesh_new_from_mesh_object(Depsgraph *depsgraph, Object *object, const bool preserve_all_data_layers, const bool preserve_origindex, const bool use_subdivision)
void BKE_mesh_nomain_to_mesh(Mesh *mesh_src, Mesh *mesh_dst, Object *ob, bool process_shape_keys=true)
const Mesh * BKE_object_get_editmesh_eval_final(const Object *object)
void BKE_mesh_to_pointcloud(Main *bmain, Depsgraph *depsgraph, Scene *scene, Object *ob)
void BKE_mesh_wrapper_ensure_mdata(Mesh *mesh)
Curve * BKE_curve_add(Main *bmain, const char *name, ObjectType type)
void BKE_object_free_modifiers(Object *ob, int flag)
ATTR_WARN_UNUSED_RESULT const BMVert * v
static int foreach_libblock_make_original_callback(LibraryIDLinkCallbackData *cb_data)
void BKE_id_materials_copy(Main *bmain, ID *id_src, ID *id_dst)
static void copy_loose_vert_hint(const Mesh &src, Mesh &dst)
@ LIB_ID_CREATE_NO_USER_REFCOUNT
@ LIB_ID_COPY_SET_COPIED_ON_WRITE
static Mesh * mesh_new_from_evaluated_curve_type_object(const Object *evaluated_object)
static KeyBlock * keyblock_ensure_from_uid(Key &key, const int uid, const StringRefNull name)
bool DEG_is_original(const T *id)
static void mesh_copy_texture_space_from_curve_type(const Curve *cu, Mesh *mesh)
static Mesh * mesh_nurbs_displist_to_mesh(const Curve *cu, const ListBaseT< DispList > *dispbase)
static void appendPolyLineVert(ListBaseT< VertLink > *lb, uint index)
void * BLI_findlink(const ListBase *listbase, int number) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
static Mesh * mesh_new_from_curve_type_object(const Object *object)
KeyBlock * BKE_keyblock_find_uid(Key *key, int uid)
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
static int find_object_active_key_uid(const Key &key, const Object &object)
void BKE_object_free_derived_caches(Object *ob)
Mesh * BKE_mesh_new_nomain_from_curve(const Object *ob)
void BKE_pointcloud_to_mesh(Main *bmain, Depsgraph *depsgraph, Scene *scene, Object *ob)
BMesh const char void * data
T * DEG_get_evaluated(const Depsgraph *depsgraph, T *id)
PointCloud * BKE_pointcloud_add(Main *bmain, const char *name)
Mesh * BKE_mesh_new_nomain(int verts_num, int edges_num, int faces_num, int corners_num)
void BLI_freelinkN(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Mesh * BKE_mesh_new_nomain_from_curve_displist(const Object *ob, const ListBaseT< DispList > *dispbase)
static const Curves * get_evaluated_curves_from_object(const Object *object)
void BKE_id_free(Main *bmain, void *idv)
static void object_for_curve_to_mesh_free(Object *temp_object)
static int foreach_libblock_make_usercounts_callback(LibraryIDLinkCallbackData *cb_data)
static void curve_to_mesh_eval_ensure(Object &object)
static Object * object_for_curve_to_mesh_create(const Object *object)
void * BKE_id_new_nomain(short type, const char *name)
void id_us_ensure_real(ID *id)
void BKE_mesh_nomain_to_meshkey(Mesh *mesh_src, Mesh *mesh_dst, KeyBlock *kb)
int CustomData_get_layer_index_n(const CustomData *data, eCustomDataType type, int n)
static void move_shapekey_layers_to_keyblocks(const Mesh &mesh, const CustomData &custom_data, Key &key_dst, const int actshape_uid)
T * DEG_get_original(T *id)
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
const CustomData_MeshMasks CD_MASK_MESH
KeyBlock * BKE_keyblock_add(Key *key, const char *name)
ID_Type GS(const char *name)
Mesh * BKE_mesh_new_from_object(Depsgraph *depsgraph, Object *object, bool preserve_all_data_layers, bool preserve_origindex, bool ensure_subdivision)
void BKE_mesh_to_curve(Main *bmain, Depsgraph *depsgraph, Scene *scene, Object *ob)
void BKE_mesh_texspace_calc(Mesh *mesh)
ID * BKE_id_copy_ex(Main *bmain, const ID *id, ID **new_id_p, int flag)
void BKE_displist_make_curveTypes(struct Depsgraph *depsgraph, const struct Scene *scene, struct Object *ob, bool for_render)
LibraryForeachIDCallbackFlag
VecBase< float, 3 > float3
Mesh * BKE_mesh_add(Main *bmain, const char *name)
static Mesh * mesh_new_from_mesh_object_with_layers(Depsgraph *depsgraph, Object *object, const bool preserve_origindex, const bool ensure_subdivision)
bool DEG_is_evaluated(const T *id)
Scene * DEG_get_evaluated_scene(const Depsgraph *graph)
void BKE_curve_texspace_calc(Curve *cu)
Mesh * BKE_mesh_wrapper_ensure_subdivision(Mesh *mesh)
void CustomData_init_from(const CustomData *source, CustomData *dest, eCustomDataMask mask, int totelem)
void BKE_library_foreach_ID_link(Main *bmain, ID *id, FunctionRef< LibraryIDLinkCallback > callback, void *user_data, LibraryForeachIDFlag flag)
static void prependPolyLineVert(ListBaseT< VertLink > *lb, uint index)
void * MEM_new_array_zeroed(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
Mesh * BKE_object_get_evaluated_mesh(const Object *object_eval)
static Mesh * mesh_new_from_mball_object(Object *object)
ListBaseT< DispList > disp
float texspace_location[3]
struct EditFont * editfont
ListBaseT< KeyBlock > block
LibraryForeachIDCallbackFlag cb_flag
struct AttributeStorage attribute_storage
ListBaseT< bDeformGroup > vertex_group_names
bke::MeshRuntime * runtime
char * stencil_uv_map_attribute
int * face_offset_indices
char * default_uv_map_attribute
char * active_uv_map_attribute
char * clone_uv_map_attribute
char * active_color_attribute
char * default_color_attribute
ListBaseT< ModifierData > modifiers
bke::ObjectRuntime * runtime
AttributeInitVArray(GVArray varray)
std::shared_ptr< BMEditMesh > edit_mesh
SharedCache< LooseGeomCache > loose_edges_cache
SharedCache< LooseGeomCache > loose_verts_cache
const ImplicitSharingInfo * face_offsets_sharing_info
MutableVArraySpan< T > span