Blender V4.5
MeshImporter.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#pragma once
10
11#include <map>
12#include <vector>
13
14#include "COLLADAFWIndexList.h"
15#include "COLLADAFWInstanceGeometry.h"
16#include "COLLADAFWMaterialBinding.h"
17#include "COLLADAFWMesh.h"
18#include "COLLADAFWMeshVertexData.h"
19#include "COLLADAFWNode.h"
20#include "COLLADAFWPolygons.h"
21#include "COLLADAFWTypes.h"
22#include "COLLADAFWUniqueId.h"
23
24#include "collada_utils.h"
25
27
28#include "DNA_material_types.h"
29#include "DNA_mesh_types.h"
30#include "DNA_object_types.h"
31#include "DNA_scene_types.h"
32
34struct MLoopCol;
35
36/* only for ArmatureImporter to "see" MeshImporter::get_object_by_geom_uid */
38 public:
39 virtual Object *get_object_by_geom_uid(const COLLADAFW::UniqueId &geom_uid) = 0;
40 virtual Mesh *get_mesh_by_geom_uid(const COLLADAFW::UniqueId &mesh_uid) = 0;
41 virtual std::string *get_geometry_name(const std::string &mesh_name) = 0;
42};
43
45 COLLADAFW::MeshVertexData *mVData;
46
47 public:
48 UVDataWrapper(COLLADAFW::MeshVertexData &vdata);
49
50#ifdef COLLADA_DEBUG
51 void print();
52#endif
53
54 void getUV(int uv_index, float *uv);
55};
56
58 COLLADAFW::MeshVertexData *mVData;
59
60 public:
61 VCOLDataWrapper(COLLADAFW::MeshVertexData &vdata);
62 void get_vcol(int v_index, MLoopCol *mloopcol);
63};
64
66 private:
67 UnitConverter *unitconverter;
68 bool use_custom_normals;
69
70 Main *m_bmain;
71 Scene *scene;
72 ViewLayer *view_layer;
73
74 ArmatureImporter *armature_importer;
75
76 std::map<std::string, std::string> mesh_geom_map; /* needed for correct shape key naming */
77 std::map<COLLADAFW::UniqueId, Mesh *> uid_mesh_map; /* geometry unique id-to-mesh map */
78 std::map<COLLADAFW::UniqueId, Object *> uid_object_map; /* geom UID-to-object */
79 std::vector<Object *> imported_objects; /* list of imported objects */
80
81 /* this structure is used to assign material indices to faces
82 * it holds a portion of Mesh faces and corresponds to a DAE primitive list
83 * (`<triangles>`, `<polylist>`, etc.) */
84 struct Primitive {
85 int face_index;
86 int *material_indices;
87 uint faces_num;
88 };
89 using MaterialIdPrimitiveArrayMap = std::map<COLLADAFW::MaterialId, std::vector<Primitive>>;
90 /* crazy name! */
91 std::map<COLLADAFW::UniqueId, MaterialIdPrimitiveArrayMap> geom_uid_mat_mapping_map;
92 /* < materials that have already been mapped to a geometry.
93 * A pair/of geom UID and mat UID, one geometry can have several materials. */
94 std::multimap<COLLADAFW::UniqueId, COLLADAFW::UniqueId> materials_mapped_to_geom;
95
96 bool set_poly_indices(int *face_verts, int loop_index, const uint *indices, int loop_count);
97
98 void set_face_uv(blender::float2 *mloopuv,
99 UVDataWrapper &uvs,
100 int start_index,
101 COLLADAFW::IndexList &index_list,
102 int count);
103
104 void set_vcol(MLoopCol *mloopcol,
105 VCOLDataWrapper &vob,
106 int loop_index,
107 COLLADAFW::IndexList &index_list,
108 int count);
109
110#ifdef COLLADA_DEBUG
111 void print_index_list(COLLADAFW::IndexList &index_list);
112#endif
113
118 bool is_nice_mesh(COLLADAFW::Mesh *mesh);
119
120 void read_vertices(COLLADAFW::Mesh *mesh, Mesh *blender_mesh);
121
128 bool primitive_has_useable_normals(COLLADAFW::MeshPrimitive *mp);
133 bool primitive_has_faces(COLLADAFW::MeshPrimitive *mp);
134
142 static void mesh_add_edges(Mesh *mesh, int len);
143
144 uint get_loose_edge_count(COLLADAFW::Mesh *mesh);
145
152 void allocate_poly_data(COLLADAFW::Mesh *collada_mesh, Mesh *mesh);
153
154 /* TODO: import uv set names */
162 void read_polys(COLLADAFW::Mesh *mesh,
163 Mesh *blender_mesh,
171 void read_lines(COLLADAFW::Mesh *mesh, Mesh *blender_mesh);
172 uint get_vertex_count(COLLADAFW::Polygons *mp, int index);
173
174 void get_vector(float v[3], COLLADAFW::MeshVertexData &arr, int i, int stride);
175
176 bool is_flat_face(uint *nind, COLLADAFW::MeshVertexData &nor, int count);
177
183 std::vector<Object *> get_all_users_of(Mesh *reference_mesh);
184
185 public:
186 MeshImporter(UnitConverter *unitconv,
187 bool use_custom_normals,
188 ArmatureImporter *arm,
189 Main *bmain,
190 Scene *sce,
191 ViewLayer *view_layer);
192
193 Object *get_object_by_geom_uid(const COLLADAFW::UniqueId &geom_uid) override;
194
195 Mesh *get_mesh_by_geom_uid(const COLLADAFW::UniqueId &geom_uid) override;
196
215
224 void assign_material_to_geom(COLLADAFW::MaterialBinding cmaterial,
225 std::map<COLLADAFW::UniqueId, Material *> &uid_material_map,
226 Object *ob,
227 const COLLADAFW::UniqueId *geom_uid,
228 short mat_index);
229
230 Object *create_mesh_object(COLLADAFW::Node *node,
231 COLLADAFW::InstanceGeometry *geom,
232 bool isController,
233 std::map<COLLADAFW::UniqueId, Material *> &uid_material_map);
234
236 bool write_geometry(const COLLADAFW::Geometry *geom);
237 std::string *get_geometry_name(const std::string &mesh_name) override;
238};
unsigned int uint
Object is a sort of wrapper for general info.
ATTR_WARN_UNUSED_RESULT const BMVert * v
virtual Object * get_object_by_geom_uid(const COLLADAFW::UniqueId &geom_uid)=0
virtual std::string * get_geometry_name(const std::string &mesh_name)=0
virtual Mesh * get_mesh_by_geom_uid(const COLLADAFW::UniqueId &mesh_uid)=0
Mesh * get_mesh_by_geom_uid(const COLLADAFW::UniqueId &geom_uid) override
void optimize_material_assignements()
bool write_geometry(const COLLADAFW::Geometry *geom)
void assign_material_to_geom(COLLADAFW::MaterialBinding cmaterial, std::map< COLLADAFW::UniqueId, Material * > &uid_material_map, Object *ob, const COLLADAFW::UniqueId *geom_uid, short mat_index)
MeshImporter(UnitConverter *unitconv, bool use_custom_normals, ArmatureImporter *arm, Main *bmain, Scene *sce, ViewLayer *view_layer)
Object * create_mesh_object(COLLADAFW::Node *node, COLLADAFW::InstanceGeometry *geom, bool isController, std::map< COLLADAFW::UniqueId, Material * > &uid_material_map)
std::string * get_geometry_name(const std::string &mesh_name) override
Object * get_object_by_geom_uid(const COLLADAFW::UniqueId &geom_uid) override
UVDataWrapper(COLLADAFW::MeshVertexData &vdata)
void getUV(int uv_index, float *uv)
void get_vcol(int v_index, MLoopCol *mloopcol)
VCOLDataWrapper(COLLADAFW::MeshVertexData &vdata)
static ushort indices[]
uint nor
int count
VecBase< float, 2 > float2
i
Definition text_draw.cc:230
uint len