Blender V4.3
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
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 "COLLADAFWTextureCoordinateBinding.h"
22#include "COLLADAFWTypes.h"
23#include "COLLADAFWUniqueId.h"
24
25#include "ArmatureImporter.h"
26#include "collada_utils.h"
27
29
30#include "DNA_material_types.h"
31#include "DNA_mesh_types.h"
32#include "DNA_object_types.h"
33#include "DNA_scene_types.h"
34
35struct MLoopCol;
36
37/* only for ArmatureImporter to "see" MeshImporter::get_object_by_geom_uid */
39 public:
40 virtual Object *get_object_by_geom_uid(const COLLADAFW::UniqueId &geom_uid) = 0;
41 virtual Mesh *get_mesh_by_geom_uid(const COLLADAFW::UniqueId &mesh_uid) = 0;
42 virtual std::string *get_geometry_name(const std::string &mesh_name) = 0;
43};
44
46 COLLADAFW::MeshVertexData *mVData;
47
48 public:
49 UVDataWrapper(COLLADAFW::MeshVertexData &vdata);
50
51#ifdef COLLADA_DEBUG
52 void print();
53#endif
54
55 void getUV(int uv_index, float *uv);
56};
57
59 COLLADAFW::MeshVertexData *mVData;
60
61 public:
62 VCOLDataWrapper(COLLADAFW::MeshVertexData &vdata);
63 void get_vcol(int v_index, MLoopCol *mloopcol);
64};
65
67 private:
68 UnitConverter *unitconverter;
69 bool use_custom_normals;
70
71 Main *m_bmain;
72 Scene *scene;
73 ViewLayer *view_layer;
74
75 ArmatureImporter *armature_importer;
76
77 std::map<std::string, std::string> mesh_geom_map; /* needed for correct shape key naming */
78 std::map<COLLADAFW::UniqueId, Mesh *> uid_mesh_map; /* geometry unique id-to-mesh map */
79 std::map<COLLADAFW::UniqueId, Object *> uid_object_map; /* geom UID-to-object */
80 std::vector<Object *> imported_objects; /* list of imported objects */
81
82 /* this structure is used to assign material indices to faces
83 * it holds a portion of Mesh faces and corresponds to a DAE primitive list
84 * (`<triangles>`, `<polylist>`, etc.) */
85 struct Primitive {
86 int face_index;
87 int *material_indices;
88 uint faces_num;
89 };
90 typedef std::map<COLLADAFW::MaterialId, std::vector<Primitive>> MaterialIdPrimitiveArrayMap;
91 /* crazy name! */
92 std::map<COLLADAFW::UniqueId, MaterialIdPrimitiveArrayMap> geom_uid_mat_mapping_map;
93 /* < materials that have already been mapped to a geometry.
94 * A pair/of geom UID and mat UID, one geometry can have several materials. */
95 std::multimap<COLLADAFW::UniqueId, COLLADAFW::UniqueId> materials_mapped_to_geom;
96
97 bool set_poly_indices(int *face_verts, int loop_index, const uint *indices, int loop_count);
98
99 void set_face_uv(blender::float2 *mloopuv,
100 UVDataWrapper &uvs,
101 int start_index,
102 COLLADAFW::IndexList &index_list,
103 int count);
104
105 void set_vcol(MLoopCol *mloopcol,
106 VCOLDataWrapper &vob,
107 int loop_index,
108 COLLADAFW::IndexList &index_list,
109 int count);
110
111#ifdef COLLADA_DEBUG
112 void print_index_list(COLLADAFW::IndexList &index_list);
113#endif
114
119 bool is_nice_mesh(COLLADAFW::Mesh *mesh);
120
121 void read_vertices(COLLADAFW::Mesh *mesh, Mesh *blender_mesh);
122
129 bool primitive_has_useable_normals(COLLADAFW::MeshPrimitive *mp);
134 bool primitive_has_faces(COLLADAFW::MeshPrimitive *mp);
135
143 static void mesh_add_edges(Mesh *mesh, int len);
144
145 uint get_loose_edge_count(COLLADAFW::Mesh *mesh);
146
153 void allocate_poly_data(COLLADAFW::Mesh *collada_mesh, Mesh *mesh);
154
155 /* TODO: import uv set names */
163 void read_polys(COLLADAFW::Mesh *mesh,
164 Mesh *blender_mesh,
172 void read_lines(COLLADAFW::Mesh *mesh, Mesh *blender_mesh);
173 uint get_vertex_count(COLLADAFW::Polygons *mp, int index);
174
175 void get_vector(float v[3], COLLADAFW::MeshVertexData &arr, int i, int stride);
176
177 bool is_flat_face(uint *nind, COLLADAFW::MeshVertexData &nor, int count);
178
184 std::vector<Object *> get_all_users_of(Mesh *reference_mesh);
185
186 public:
187 MeshImporter(UnitConverter *unitconv,
188 bool use_custom_normals,
189 ArmatureImporter *arm,
190 Main *bmain,
191 Scene *sce,
192 ViewLayer *view_layer);
193
194 virtual Object *get_object_by_geom_uid(const COLLADAFW::UniqueId &geom_uid);
195
196 virtual Mesh *get_mesh_by_geom_uid(const COLLADAFW::UniqueId &geom_uid);
197
216
225 void assign_material_to_geom(COLLADAFW::MaterialBinding cmaterial,
226 std::map<COLLADAFW::UniqueId, Material *> &uid_material_map,
227 Object *ob,
228 const COLLADAFW::UniqueId *geom_uid,
229 short mat_index);
230
231 Object *create_mesh_object(COLLADAFW::Node *node,
232 COLLADAFW::InstanceGeometry *geom,
233 bool isController,
234 std::map<COLLADAFW::UniqueId, Material *> &uid_material_map);
235
237 bool write_geometry(const COLLADAFW::Geometry *geom);
238 std::string *get_geometry_name(const std::string &mesh_name);
239};
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
virtual Mesh * get_mesh_by_geom_uid(const COLLADAFW::UniqueId &geom_uid)
virtual Object * get_object_by_geom_uid(const COLLADAFW::UniqueId &geom_uid)
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)
UVDataWrapper(COLLADAFW::MeshVertexData &vdata)
void getUV(int uv_index, float *uv)
void get_vcol(int v_index, MLoopCol *mloopcol)
VCOLDataWrapper(COLLADAFW::MeshVertexData &vdata)
int len
int count
Frequency::GEOMETRY nor[]