30 Map<std::string, std::unique_ptr<MTLMaterial>> &
materials,
35 if (tot_verts_object <= 0) {
40 if (ob_name.empty()) {
43 fixup_invalid_faces();
54 create_vertices(
mesh);
57 create_uv_verts(
mesh);
63 bool verbose_validate =
false;
65 verbose_validate =
true;
75 dst->
flag |= autosmooth;
78 create_vertex_groups(obj);
83 void MeshFromGeometry::fixup_invalid_faces()
101 int vertex_idx = mesh_geometry_.
face_corners_[corner_idx].vert_index;
102 if (used_verts.
contains(vertex_idx)) {
106 used_verts.
add(vertex_idx);
114 Vector<int, 8> face_verts;
115 Vector<int, 8> face_uvs;
116 Vector<int, 8> face_normals;
123 face_verts.append(
corner.vert_index);
124 face_normals.append(
corner.vertex_normal_index);
125 face_uvs.append(
corner.uv_vert_index);
138 for (Span<int> face : new_faces) {
139 if (face.size() < 3) {
143 new_face.vertex_group_index = face_vertex_group;
144 new_face.material_index = face_material;
145 new_face.shaded_smooth = face_shaded_smooth;
147 new_face.corner_count_ = face.size();
148 for (
int idx : face) {
149 BLI_assert(idx >= 0 && idx < face_verts.size());
150 mesh_geometry_.
face_corners_.append({face_verts[idx], face_uvs[idx], face_normals[idx]});
158 void MeshFromGeometry::create_vertices(
Mesh *
mesh)
172 BLI_assert(local_vi >= 0 && local_vi < mesh->totvert);
178 void MeshFromGeometry::create_polys_loops(
Mesh *
mesh,
bool use_vertex_groups)
188 int tot_loop_idx = 0;
190 for (
int poly_idx = 0; poly_idx < tot_face_elems; ++poly_idx) {
191 const PolyElem &curr_face = mesh_geometry_.
face_elements_[poly_idx];
192 if (curr_face.corner_count_ < 3) {
194 std::cerr <<
"Face with less than 3 vertices found, skipping." << std::endl;
199 mpoly.
totloop = curr_face.corner_count_;
201 if (curr_face.shaded_smooth) {
204 mpoly.
mat_nr = curr_face.material_index;
211 for (
int idx = 0; idx < curr_face.corner_count_; ++idx) {
212 const PolyCorner &curr_corner = mesh_geometry_.
face_corners_[curr_face.start_index_ + idx];
221 const int group_index = curr_face.vertex_group_index;
228 void MeshFromGeometry::create_vertex_groups(
Object *obj)
234 for (
const std::string &name : mesh_geometry_.
group_order_) {
239 void MeshFromGeometry::create_edges(
Mesh *
mesh)
244 for (
int i = 0; i < tot_edges; ++i) {
249 BLI_assert(dst_edge.
v1 < total_verts && dst_edge.
v2 < total_verts);
259 void MeshFromGeometry::create_uv_verts(
Mesh *
mesh)
266 int tot_loop_idx = 0;
269 for (
int idx = 0; idx < curr_face.corner_count_; ++idx) {
270 const PolyCorner &curr_corner = mesh_geometry_.
face_corners_[curr_face.start_index_ + idx];
271 const int uv_index = curr_corner.uv_vert_index;
273 if (uv_index >= 0 && uv_index < global_vertices_.
uv_vertices.size()) {
283 const std::string &name,
284 Map<std::string, std::unique_ptr<MTLMaterial>> &
materials,
290 if (found_mat !=
nullptr) {
304 mat->
nodetree = mat_wrap.get_nodetree();
307 created_materials.
add_new(name, mat);
311 void MeshFromGeometry::create_materials(
Main *bmain,
312 Map<std::string, std::unique_ptr<MTLMaterial>> &
materials,
319 bmain, name,
materials, created_materials, relative_paths);
320 if (mat ==
nullptr) {
330 void MeshFromGeometry::create_normals(
Mesh *
mesh)
341 float(*loop_normals)[3] =
static_cast<float(*)[3]
>(
343 int tot_loop_idx = 0;
345 for (
int idx = 0; idx < curr_face.corner_count_; ++idx) {
346 const PolyCorner &curr_corner = mesh_geometry_.
face_corners_[curr_face.start_index_ + idx];
347 int n_index = curr_corner.vertex_normal_index;
352 copy_v3_v3(loop_normals[tot_loop_idx], normal);
361 void MeshFromGeometry::create_colors(
Mesh *
mesh)
371 mesh_geometry_.
vertex_index_max_ < block.start_vertex_index + block.colors.size()) {
typedef float(TangentPoint)[2]
Generic geometry attributes built on CustomData.
struct CustomDataLayer * BKE_id_attribute_new(struct ID *id, const char *name, int type, eAttrDomain domain, struct ReportList *reports)
CustomData interface, see also DNA_customdata_types.h.
const CustomData_MeshMasks CD_MASK_EVERYTHING
void * CustomData_add_layer(struct CustomData *data, int type, eCDAllocType alloctype, void *layer, int totelem)
void id_us_min(struct ID *id)
General operations, lookup, etc. for materials.
void BKE_object_material_assign_single_obdata(struct Main *bmain, struct Object *ob, struct Material *ma, short act)
struct Material * BKE_material_add(struct Main *bmain, const char *name)
void BKE_mesh_nomain_to_mesh(struct Mesh *mesh_src, struct Mesh *mesh_dst, struct Object *ob, const struct CustomData_MeshMasks *mask, bool take_ownership)
void BKE_mesh_calc_edges_loose(struct Mesh *mesh)
bool BKE_mesh_validate(struct Mesh *me, bool do_verbose, bool cddata_check_mask)
struct Mesh * BKE_mesh_new_nomain(int verts_len, int edges_len, int tessface_len, int loops_len, int polys_len)
void BKE_mesh_set_custom_normals(struct Mesh *mesh, float(*r_custom_loopnors)[3])
void BKE_mesh_calc_edges(struct Mesh *mesh, bool keep_existing_edges, bool select_new_edges)
void BKE_ntree_update_main_tree(struct Main *bmain, struct bNodeTree *ntree, struct NodeTreeUpdateExtraParams *params)
General operations, lookup, etc. for blender objects.
void * BKE_object_obdata_add_from_type(struct Main *bmain, int type, const char *name) ATTR_NONNULL(1)
struct Object * BKE_object_add_only_object(struct Main *bmain, int type, const char *name) ATTR_RETURNS_NONNULL
MINLINE void copy_v2_v2(float r[2], const float a[2])
MINLINE void copy_v3_v3(float r[3], const float a[3])
#define UNUSED_VARS_NDEBUG(...)
Value lookup_default(const Key &key, const Value &default_value) const
void add_new(const Key &key, const Value &value)
const Value * lookup_ptr(const Key &key) const
bool contains(const Key &key) const
Object * create_mesh(Main *bmain, Map< std::string, std::unique_ptr< MTLMaterial >> &materials, Map< std::string, Material * > &created_materials, const OBJImportParams &import_params)
smooth(Type::VEC4, "color_mul") .smooth(Type gpFillTexture gpSceneDepthTexture materials[GPENCIL_MATERIAL_BUFFER_LEN]
IconTextureDrawCall normal
ccl_gpu_kernel_postfix ccl_global float int int int int float bool int offset
void *(* MEM_malloc_arrayN)(size_t len, size_t size, const char *str)
void(* MEM_freeN)(void *vmemh)
Vector< Vector< int > > fixup_invalid_polygon(Span< float3 > vertex_coords, Span< int > face_vertex_indices)
static Material * get_or_create_material(Main *bmain, const std::string &name, Map< std::string, std::unique_ptr< MTLMaterial >> &materials, Map< std::string, Material * > &created_materials, bool relative_paths)
void transform_object(Object *object, const OBJImportParams &import_params)
vec_base< float, 4 > float4
struct bNodeTree * nodetree
struct MDeformVert * dvert
bool import_vertex_groups
int get_vertex_count() const
Vector< PolyElem > face_elements_
Vector< std::string > material_order_
Map< int, int > global_to_local_vertices_
Vector< std::string > group_order_
std::string geometry_name_
Vector< PolyCorner > face_corners_
Vector< float3 > vertex_normals
Vector< float3 > vertices
Vector< float2 > uv_vertices
Vector< VertexColorsBlock > vertex_colors