Blender  V2.93
MeshImporter.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
21 #pragma once
22 
23 #include <map>
24 #include <vector>
25 
26 #include "COLLADAFWIndexList.h"
27 #include "COLLADAFWInstanceGeometry.h"
28 #include "COLLADAFWMaterialBinding.h"
29 #include "COLLADAFWMesh.h"
30 #include "COLLADAFWMeshVertexData.h"
31 #include "COLLADAFWNode.h"
32 #include "COLLADAFWPolygons.h"
33 #include "COLLADAFWTextureCoordinateBinding.h"
34 #include "COLLADAFWTypes.h"
35 #include "COLLADAFWUniqueId.h"
36 
37 #include "ArmatureImporter.h"
38 #include "collada_utils.h"
39 
40 #include "BLI_edgehash.h"
41 
42 #include "DNA_material_types.h"
43 #include "DNA_mesh_types.h"
44 #include "DNA_meshdata_types.h"
45 #include "DNA_object_types.h"
46 #include "DNA_scene_types.h"
47 
48 /* only for ArmatureImporter to "see" MeshImporter::get_object_by_geom_uid */
50  public:
51  virtual Object *get_object_by_geom_uid(const COLLADAFW::UniqueId &geom_uid) = 0;
52  virtual Mesh *get_mesh_by_geom_uid(const COLLADAFW::UniqueId &mesh_uid) = 0;
53  virtual std::string *get_geometry_name(const std::string &mesh_name) = 0;
54 };
55 
57  COLLADAFW::MeshVertexData *mVData;
58 
59  public:
60  UVDataWrapper(COLLADAFW::MeshVertexData &vdata);
61 
62 #ifdef COLLADA_DEBUG
63  void print();
64 #endif
65 
66  void getUV(int uv_index, float *uv);
67 };
68 
70  COLLADAFW::MeshVertexData *mVData;
71 
72  public:
73  VCOLDataWrapper(COLLADAFW::MeshVertexData &vdata);
74  void get_vcol(int v_index, MLoopCol *mloopcol);
75 };
76 
78  private:
79  UnitConverter *unitconverter;
80 
81  Main *m_bmain;
82  Scene *scene;
83  ViewLayer *view_layer;
84 
85  ArmatureImporter *armature_importer;
86 
87  std::map<std::string, std::string> mesh_geom_map; /* needed for correct shape key naming */
88  std::map<COLLADAFW::UniqueId, Mesh *> uid_mesh_map; /* geometry unique id-to-mesh map */
89  std::map<COLLADAFW::UniqueId, Object *> uid_object_map; /* geom uid-to-object */
90  std::vector<Object *> imported_objects; /* list of imported objects */
91 
92  /* this structure is used to assign material indices to polygons
93  * it holds a portion of Mesh faces and corresponds to a DAE primitive list
94  * (<triangles>, <polylist>, etc.) */
95  struct Primitive {
96  MPoly *mpoly;
97  unsigned int totpoly;
98  };
99  typedef std::map<COLLADAFW::MaterialId, std::vector<Primitive>> MaterialIdPrimitiveArrayMap;
100  /* crazy name! */
101  std::map<COLLADAFW::UniqueId, MaterialIdPrimitiveArrayMap> geom_uid_mat_mapping_map;
102  /* < materials that have already been mapped to a geometry.
103  * A pair/of geom uid and mat uid, one geometry can have several materials */
104  std::multimap<COLLADAFW::UniqueId, COLLADAFW::UniqueId> materials_mapped_to_geom;
105 
106  bool set_poly_indices(
107  MPoly *mpoly, MLoop *mloop, int loop_index, const unsigned int *indices, int loop_count);
108 
109  void set_face_uv(MLoopUV *mloopuv,
110  UVDataWrapper &uvs,
111  int start_index,
112  COLLADAFW::IndexList &index_list,
113  int count);
114 
115  void set_vcol(MLoopCol *mloopcol,
116  VCOLDataWrapper &vob,
117  int loop_index,
118  COLLADAFW::IndexList &index_list,
119  int count);
120 
121 #ifdef COLLADA_DEBUG
122  void print_index_list(COLLADAFW::IndexList &index_list);
123 #endif
124 
125  bool is_nice_mesh(COLLADAFW::Mesh *mesh);
126 
127  void read_vertices(COLLADAFW::Mesh *mesh, Mesh *me);
128 
129  bool primitive_has_useable_normals(COLLADAFW::MeshPrimitive *mp);
130  bool primitive_has_faces(COLLADAFW::MeshPrimitive *mp);
131 
132  static void mesh_add_edges(Mesh *mesh, int len);
133 
134  unsigned int get_loose_edge_count(COLLADAFW::Mesh *mesh);
135 
136  CustomData create_edge_custom_data(EdgeHash *eh);
137 
138  void allocate_poly_data(COLLADAFW::Mesh *collada_mesh, Mesh *me);
139 
140  /* TODO: import uv set names */
141  void read_polys(COLLADAFW::Mesh *mesh, Mesh *me);
142  void read_lines(COLLADAFW::Mesh *mesh, Mesh *me);
143  unsigned int get_vertex_count(COLLADAFW::Polygons *mp, int index);
144 
145  void get_vector(float v[3], COLLADAFW::MeshVertexData &arr, int i, int stride);
146 
147  bool is_flat_face(unsigned int *nind, COLLADAFW::MeshVertexData &nor, int count);
148 
149  std::vector<Object *> get_all_users_of(Mesh *reference_mesh);
150 
151  public:
152  MeshImporter(UnitConverter *unitconv,
153  ArmatureImporter *arm,
154  Main *bmain,
155  Scene *sce,
156  ViewLayer *view_layer);
157 
158  virtual Object *get_object_by_geom_uid(const COLLADAFW::UniqueId &geom_uid);
159 
160  virtual Mesh *get_mesh_by_geom_uid(const COLLADAFW::UniqueId &geom_uid);
161 
163 
164  void assign_material_to_geom(COLLADAFW::MaterialBinding cmaterial,
165  std::map<COLLADAFW::UniqueId, Material *> &uid_material_map,
166  Object *ob,
167  const COLLADAFW::UniqueId *geom_uid,
168  short mat_index);
169 
170  Object *create_mesh_object(COLLADAFW::Node *node,
171  COLLADAFW::InstanceGeometry *geom,
172  bool isController,
173  std::map<COLLADAFW::UniqueId, Material *> &uid_material_map);
174 
175  /* create a mesh storing a pointer in a map so it can be retrieved later by geometry UID */
176  bool write_geometry(const COLLADAFW::Geometry *geom);
177  std::string *get_geometry_name(const std::string &mesh_name);
178 };
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
Group RGB to Bright Vector Camera Vector Combine Material Light Line Style Layer Add Ambient Diffuse Glossy Refraction Transparent Toon Principled Hair Volume Principled Geometry
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
static ushort indices[]
uint nor
int count
Definition: BKE_main.h:116
uint len