Blender  V3.3
MeshImporter.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 #pragma once
8 
9 #include <map>
10 #include <vector>
11 
12 #include "COLLADAFWIndexList.h"
13 #include "COLLADAFWInstanceGeometry.h"
14 #include "COLLADAFWMaterialBinding.h"
15 #include "COLLADAFWMesh.h"
16 #include "COLLADAFWMeshVertexData.h"
17 #include "COLLADAFWNode.h"
18 #include "COLLADAFWPolygons.h"
19 #include "COLLADAFWTextureCoordinateBinding.h"
20 #include "COLLADAFWTypes.h"
21 #include "COLLADAFWUniqueId.h"
22 
23 #include "ArmatureImporter.h"
24 #include "collada_utils.h"
25 
26 #include "BLI_edgehash.h"
27 
28 #include "DNA_material_types.h"
29 #include "DNA_mesh_types.h"
30 #include "DNA_meshdata_types.h"
31 #include "DNA_object_types.h"
32 #include "DNA_scene_types.h"
33 
34 /* only for ArmatureImporter to "see" MeshImporter::get_object_by_geom_uid */
36  public:
37  virtual Object *get_object_by_geom_uid(const COLLADAFW::UniqueId &geom_uid) = 0;
38  virtual Mesh *get_mesh_by_geom_uid(const COLLADAFW::UniqueId &mesh_uid) = 0;
39  virtual std::string *get_geometry_name(const std::string &mesh_name) = 0;
40 };
41 
43  COLLADAFW::MeshVertexData *mVData;
44 
45  public:
46  UVDataWrapper(COLLADAFW::MeshVertexData &vdata);
47 
48 #ifdef COLLADA_DEBUG
49  void print();
50 #endif
51 
52  void getUV(int uv_index, float *uv);
53 };
54 
56  COLLADAFW::MeshVertexData *mVData;
57 
58  public:
59  VCOLDataWrapper(COLLADAFW::MeshVertexData &vdata);
60  void get_vcol(int v_index, MLoopCol *mloopcol);
61 };
62 
64  private:
65  UnitConverter *unitconverter;
66 
67  Main *m_bmain;
68  Scene *scene;
69  ViewLayer *view_layer;
70 
71  ArmatureImporter *armature_importer;
72 
73  std::map<std::string, std::string> mesh_geom_map; /* needed for correct shape key naming */
74  std::map<COLLADAFW::UniqueId, Mesh *> uid_mesh_map; /* geometry unique id-to-mesh map */
75  std::map<COLLADAFW::UniqueId, Object *> uid_object_map; /* geom UID-to-object */
76  std::vector<Object *> imported_objects; /* list of imported objects */
77 
78  /* this structure is used to assign material indices to polygons
79  * it holds a portion of Mesh faces and corresponds to a DAE primitive list
80  * (<triangles>, <polylist>, etc.) */
81  struct Primitive {
82  MPoly *mpoly;
83  unsigned int totpoly;
84  };
85  typedef std::map<COLLADAFW::MaterialId, std::vector<Primitive>> MaterialIdPrimitiveArrayMap;
86  /* crazy name! */
87  std::map<COLLADAFW::UniqueId, MaterialIdPrimitiveArrayMap> geom_uid_mat_mapping_map;
88  /* < materials that have already been mapped to a geometry.
89  * A pair/of geom UID and mat UID, one geometry can have several materials. */
90  std::multimap<COLLADAFW::UniqueId, COLLADAFW::UniqueId> materials_mapped_to_geom;
91 
92  bool set_poly_indices(
93  MPoly *mpoly, MLoop *mloop, int loop_index, const unsigned int *indices, int loop_count);
94 
95  void set_face_uv(MLoopUV *mloopuv,
96  UVDataWrapper &uvs,
97  int start_index,
98  COLLADAFW::IndexList &index_list,
99  int count);
100 
101  void set_vcol(MLoopCol *mloopcol,
102  VCOLDataWrapper &vob,
103  int loop_index,
104  COLLADAFW::IndexList &index_list,
105  int count);
106 
107 #ifdef COLLADA_DEBUG
108  void print_index_list(COLLADAFW::IndexList &index_list);
109 #endif
110 
112  bool is_nice_mesh(COLLADAFW::Mesh *mesh);
113 
114  void read_vertices(COLLADAFW::Mesh *mesh, Mesh *me);
115 
122  bool primitive_has_useable_normals(COLLADAFW::MeshPrimitive *mp);
127  bool primitive_has_faces(COLLADAFW::MeshPrimitive *mp);
128 
136  static void mesh_add_edges(Mesh *mesh, int len);
137 
138  unsigned int get_loose_edge_count(COLLADAFW::Mesh *mesh);
139 
140  CustomData create_edge_custom_data(EdgeHash *eh);
141 
148  void allocate_poly_data(COLLADAFW::Mesh *collada_mesh, Mesh *me);
149 
150  /* TODO: import uv set names */
158  void read_polys(COLLADAFW::Mesh *mesh, Mesh *me);
165  void read_lines(COLLADAFW::Mesh *mesh, Mesh *me);
166  unsigned int get_vertex_count(COLLADAFW::Polygons *mp, int index);
167 
168  void get_vector(float v[3], COLLADAFW::MeshVertexData &arr, int i, int stride);
169 
170  bool is_flat_face(unsigned int *nind, COLLADAFW::MeshVertexData &nor, int count);
171 
177  std::vector<Object *> get_all_users_of(Mesh *reference_mesh);
178 
179  public:
180  MeshImporter(UnitConverter *unitconv,
181  ArmatureImporter *arm,
182  Main *bmain,
183  Scene *sce,
184  ViewLayer *view_layer);
185 
186  virtual Object *get_object_by_geom_uid(const COLLADAFW::UniqueId &geom_uid);
187 
188  virtual Mesh *get_mesh_by_geom_uid(const COLLADAFW::UniqueId &geom_uid);
189 
209 
218  void assign_material_to_geom(COLLADAFW::MaterialBinding cmaterial,
219  std::map<COLLADAFW::UniqueId, Material *> &uid_material_map,
220  Object *ob,
221  const COLLADAFW::UniqueId *geom_uid,
222  short mat_index);
223 
224  Object *create_mesh_object(COLLADAFW::Node *node,
225  COLLADAFW::InstanceGeometry *geom,
226  bool isController,
227  std::map<COLLADAFW::UniqueId, Material *> &uid_material_map);
228 
230  bool write_geometry(const COLLADAFW::Geometry *geom);
231  std::string *get_geometry_name(const std::string &mesh_name);
232 };
struct Mesh Mesh
Object is a sort of wrapper for general info.
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei stride
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)
Object * create_mesh_object(COLLADAFW::Node *node, COLLADAFW::InstanceGeometry *geom, bool isController, std::map< COLLADAFW::UniqueId, Material * > &uid_material_map)
MeshImporter(UnitConverter *unitconv, ArmatureImporter *arm, Main *bmain, Scene *sce, ViewLayer *view_layer)
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)
OperationNode * node
int len
Definition: draw_manager.c:108
uint nor
int count
ccl_gpu_kernel_postfix int ccl_global int * indices
Definition: BKE_main.h:121