2011-02-21 08:38:53 +00:00
|
|
|
/*
|
2010-10-05 00:05:14 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
*/
|
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup collada
|
2011-02-21 08:38:53 +00:00
|
|
|
*/
|
|
|
|
|
|
2012-02-17 18:59:41 +00:00
|
|
|
#pragma once
|
2010-10-05 00:05:14 +00:00
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
#include "COLLADAFWIndexList.h"
|
|
|
|
|
#include "COLLADAFWInstanceGeometry.h"
|
|
|
|
|
#include "COLLADAFWMaterialBinding.h"
|
|
|
|
|
#include "COLLADAFWMesh.h"
|
|
|
|
|
#include "COLLADAFWMeshVertexData.h"
|
|
|
|
|
#include "COLLADAFWNode.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "COLLADAFWPolygons.h"
|
2010-10-05 00:05:14 +00:00
|
|
|
#include "COLLADAFWTextureCoordinateBinding.h"
|
|
|
|
|
#include "COLLADAFWTypes.h"
|
|
|
|
|
#include "COLLADAFWUniqueId.h"
|
|
|
|
|
|
2012-08-12 17:13:07 +00:00
|
|
|
#include "ArmatureImporter.h"
|
|
|
|
|
#include "collada_utils.h"
|
|
|
|
|
|
|
|
|
|
#include "BLI_edgehash.h"
|
2020-05-08 18:16:39 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
#include "DNA_material_types.h"
|
|
|
|
|
#include "DNA_mesh_types.h"
|
|
|
|
|
#include "DNA_meshdata_types.h"
|
|
|
|
|
#include "DNA_object_types.h"
|
|
|
|
|
#include "DNA_scene_types.h"
|
2012-05-16 11:21:03 +00:00
|
|
|
|
2019-04-30 13:41:21 +10:00
|
|
|
/* only for ArmatureImporter to "see" MeshImporter::get_object_by_geom_uid */
|
2010-10-05 00:05:14 +00:00
|
|
|
class MeshImporterBase {
|
|
|
|
|
public:
|
|
|
|
|
virtual Object *get_object_by_geom_uid(const COLLADAFW::UniqueId &geom_uid) = 0;
|
2013-01-21 13:45:49 +00:00
|
|
|
virtual Mesh *get_mesh_by_geom_uid(const COLLADAFW::UniqueId &mesh_uid) = 0;
|
2013-02-12 17:52:18 +00:00
|
|
|
virtual std::string *get_geometry_name(const std::string &mesh_name) = 0;
|
2010-10-05 00:05:14 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class UVDataWrapper {
|
|
|
|
|
COLLADAFW::MeshVertexData *mVData;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
public:
|
|
|
|
|
UVDataWrapper(COLLADAFW::MeshVertexData &vdata);
|
|
|
|
|
|
|
|
|
|
#ifdef COLLADA_DEBUG
|
|
|
|
|
void print();
|
|
|
|
|
#endif
|
|
|
|
|
|
2011-07-06 21:37:31 +00:00
|
|
|
void getUV(int uv_index, float *uv);
|
2010-10-05 00:05:14 +00:00
|
|
|
};
|
|
|
|
|
|
2014-05-01 14:52:10 +02:00
|
|
|
class VCOLDataWrapper {
|
|
|
|
|
COLLADAFW::MeshVertexData *mVData;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-05-01 14:52:10 +02:00
|
|
|
public:
|
|
|
|
|
VCOLDataWrapper(COLLADAFW::MeshVertexData &vdata);
|
|
|
|
|
void get_vcol(int v_index, MLoopCol *mloopcol);
|
|
|
|
|
};
|
|
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
class MeshImporter : public MeshImporterBase {
|
|
|
|
|
private:
|
2010-11-03 22:44:39 +00:00
|
|
|
UnitConverter *unitconverter;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-06-14 15:15:51 +02:00
|
|
|
Main *m_bmain;
|
2010-10-05 00:05:14 +00:00
|
|
|
Scene *scene;
|
2018-01-26 13:13:54 +01:00
|
|
|
ViewLayer *view_layer;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
ArmatureImporter *armature_importer;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-30 13:41:21 +10:00
|
|
|
std::map<std::string, std::string> mesh_geom_map; /* needed for correct shape key naming */
|
|
|
|
|
std::map<COLLADAFW::UniqueId, Mesh *> uid_mesh_map; /* geometry unique id-to-mesh map */
|
|
|
|
|
std::map<COLLADAFW::UniqueId, Object *> uid_object_map; /* geom uid-to-object */
|
|
|
|
|
std::vector<Object *> imported_objects; /* list of imported objects */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-04-30 13:41:21 +10:00
|
|
|
/* this structure is used to assign material indices to polygons
|
|
|
|
|
* it holds a portion of Mesh faces and corresponds to a DAE primitive list
|
|
|
|
|
* (<triangles>, <polylist>, etc.) */
|
2010-10-05 00:05:14 +00:00
|
|
|
struct Primitive {
|
2013-03-02 15:58:13 +00:00
|
|
|
MPoly *mpoly;
|
|
|
|
|
unsigned int totpoly;
|
2010-10-05 00:05:14 +00:00
|
|
|
};
|
|
|
|
|
typedef std::map<COLLADAFW::MaterialId, std::vector<Primitive>> MaterialIdPrimitiveArrayMap;
|
2019-04-30 13:41:21 +10:00
|
|
|
/* crazy name! */
|
|
|
|
|
std::map<COLLADAFW::UniqueId, MaterialIdPrimitiveArrayMap> geom_uid_mat_mapping_map;
|
|
|
|
|
/* < materials that have already been mapped to a geometry.
|
|
|
|
|
* A pair/of geom uid and mat uid, one geometry can have several materials */
|
|
|
|
|
std::multimap<COLLADAFW::UniqueId, COLLADAFW::UniqueId> materials_mapped_to_geom;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-15 08:53:22 +11:00
|
|
|
bool set_poly_indices(
|
2020-07-13 11:27:09 +02:00
|
|
|
MPoly *mpoly, MLoop *mloop, int loop_index, const unsigned int *indices, int loop_count);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-15 08:53:22 +11:00
|
|
|
void set_face_uv(MLoopUV *mloopuv,
|
|
|
|
|
UVDataWrapper &uvs,
|
2020-09-04 20:59:13 +02:00
|
|
|
int start_index,
|
2019-03-15 08:53:22 +11:00
|
|
|
COLLADAFW::IndexList &index_list,
|
|
|
|
|
int count);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-15 08:53:22 +11:00
|
|
|
void set_vcol(MLoopCol *mloopcol,
|
|
|
|
|
VCOLDataWrapper &vob,
|
|
|
|
|
int loop_index,
|
|
|
|
|
COLLADAFW::IndexList &index_list,
|
|
|
|
|
int count);
|
2014-05-01 14:52:10 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
#ifdef COLLADA_DEBUG
|
|
|
|
|
void print_index_list(COLLADAFW::IndexList &index_list);
|
|
|
|
|
#endif
|
|
|
|
|
|
2021-12-09 22:25:45 +11:00
|
|
|
/** Checks if mesh has supported primitive types: lines, polylist, triangles, triangle_fans. */
|
2010-10-05 00:05:14 +00:00
|
|
|
bool is_nice_mesh(COLLADAFW::Mesh *mesh);
|
2012-05-16 11:21:03 +00:00
|
|
|
|
|
|
|
|
void read_vertices(COLLADAFW::Mesh *mesh, Mesh *me);
|
|
|
|
|
|
2021-12-09 22:25:45 +11:00
|
|
|
/**
|
|
|
|
|
* Condition 1: The Primitive has normals
|
|
|
|
|
* condition 2: The number of normals equals the number of faces.
|
|
|
|
|
* return true if both conditions apply.
|
|
|
|
|
* return false otherwise.
|
|
|
|
|
*/
|
2012-05-16 11:21:03 +00:00
|
|
|
bool primitive_has_useable_normals(COLLADAFW::MeshPrimitive *mp);
|
2021-12-09 22:25:45 +11:00
|
|
|
/**
|
|
|
|
|
* Assume that only TRIANGLES, TRIANGLE_FANS, POLYLIST and POLYGONS
|
|
|
|
|
* have faces. (to be verified).
|
|
|
|
|
*/
|
2012-05-16 11:21:03 +00:00
|
|
|
bool primitive_has_faces(COLLADAFW::MeshPrimitive *mp);
|
|
|
|
|
|
2021-12-09 22:25:45 +11:00
|
|
|
/**
|
|
|
|
|
* This function is copied from source/blender/editors/mesh/mesh_data.c
|
|
|
|
|
*
|
|
|
|
|
* TODO: (As discussed with sergey-) :
|
2021-12-10 21:28:56 +11:00
|
|
|
* Maybe move this function to `blenderkernel/intern/mesh.c`.
|
2021-12-09 22:25:45 +11:00
|
|
|
* and add definition to BKE_mesh.c.
|
|
|
|
|
*/
|
2012-05-16 11:21:03 +00:00
|
|
|
static void mesh_add_edges(Mesh *mesh, int len);
|
|
|
|
|
|
2013-03-02 15:58:13 +00:00
|
|
|
unsigned int get_loose_edge_count(COLLADAFW::Mesh *mesh);
|
2012-05-16 11:21:03 +00:00
|
|
|
|
|
|
|
|
CustomData create_edge_custom_data(EdgeHash *eh);
|
2010-10-05 00:05:14 +00:00
|
|
|
|
2021-12-09 22:25:45 +11:00
|
|
|
/**
|
|
|
|
|
* Return the number of faces by summing up
|
|
|
|
|
* the face-counts of the parts.
|
|
|
|
|
* hint: This is done because `mesh->getFacesCount()` does
|
|
|
|
|
* count loose edges as extra faces, which is not what we want here.
|
|
|
|
|
*/
|
2011-01-27 19:39:06 +00:00
|
|
|
void allocate_poly_data(COLLADAFW::Mesh *collada_mesh, Mesh *me);
|
2010-10-05 00:05:14 +00:00
|
|
|
|
2019-04-30 13:41:21 +10:00
|
|
|
/* TODO: import uv set names */
|
2021-12-09 22:25:45 +11:00
|
|
|
/**
|
|
|
|
|
* Read all faces from TRIANGLES, TRIANGLE_FANS, POLYLIST, POLYGON
|
|
|
|
|
* Important: This function MUST be called before read_lines()
|
|
|
|
|
* Otherwise we will lose all edges from faces (see read_lines() above)
|
|
|
|
|
*
|
|
|
|
|
* TODO: import uv set names.
|
|
|
|
|
*/
|
2013-03-02 15:58:13 +00:00
|
|
|
void read_polys(COLLADAFW::Mesh *mesh, Mesh *me);
|
2021-12-09 22:25:45 +11:00
|
|
|
/**
|
|
|
|
|
* Read all loose edges.
|
|
|
|
|
* Important: This function assumes that all edges from existing
|
|
|
|
|
* faces have already been generated and added to me->medge
|
|
|
|
|
* So this function MUST be called after read_faces() (see below)
|
|
|
|
|
*/
|
2010-10-05 00:05:14 +00:00
|
|
|
void read_lines(COLLADAFW::Mesh *mesh, Mesh *me);
|
2013-03-02 15:58:13 +00:00
|
|
|
unsigned int get_vertex_count(COLLADAFW::Polygons *mp, int index);
|
2012-08-12 17:13:07 +00:00
|
|
|
|
|
|
|
|
void get_vector(float v[3], COLLADAFW::MeshVertexData &arr, int i, int stride);
|
|
|
|
|
|
2013-03-02 15:58:13 +00:00
|
|
|
bool is_flat_face(unsigned int *nind, COLLADAFW::MeshVertexData &nor, int count);
|
2010-10-05 00:05:14 +00:00
|
|
|
|
2021-12-09 22:25:45 +11:00
|
|
|
/**
|
|
|
|
|
* Returns the list of Users of the given Mesh object.
|
|
|
|
|
* NOTE: This function uses the object user flag to control
|
|
|
|
|
* which objects have already been processed.
|
|
|
|
|
*/
|
2018-06-14 15:55:51 +02:00
|
|
|
std::vector<Object *> get_all_users_of(Mesh *reference_mesh);
|
2010-10-05 00:05:14 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
public:
|
2010-10-05 00:05:14 +00:00
|
|
|
MeshImporter(UnitConverter *unitconv,
|
|
|
|
|
ArmatureImporter *arm,
|
2018-06-14 15:55:51 +02:00
|
|
|
Main *bmain,
|
2019-04-17 06:17:24 +02:00
|
|
|
Scene *sce,
|
2010-10-05 00:05:14 +00:00
|
|
|
ViewLayer *view_layer);
|
2013-01-21 13:45:49 +00:00
|
|
|
|
|
|
|
|
virtual Object *get_object_by_geom_uid(const COLLADAFW::UniqueId &geom_uid);
|
2018-06-08 08:07:48 +02:00
|
|
|
|
2013-01-21 13:45:49 +00:00
|
|
|
virtual Mesh *get_mesh_by_geom_uid(const COLLADAFW::UniqueId &geom_uid);
|
2012-08-12 17:13:07 +00:00
|
|
|
|
2021-12-09 22:25:45 +11:00
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* During import all materials have been assigned to Object.
|
|
|
|
|
* Now we iterate over the imported objects and optimize
|
|
|
|
|
* the assignments as follows:
|
|
|
|
|
*
|
|
|
|
|
* for each imported geometry:
|
|
|
|
|
* if number of users is 1:
|
|
|
|
|
* get the user (object)
|
|
|
|
|
* move the materials from Object to Data
|
|
|
|
|
* else:
|
|
|
|
|
* determine which materials are assigned to the first user
|
|
|
|
|
* check if all other users have the same materials in the same order
|
|
|
|
|
* if the check is positive:
|
|
|
|
|
* Add the materials of the first user to the geometry
|
|
|
|
|
* adjust all other users accordingly.
|
|
|
|
|
*
|
|
|
|
|
*/
|
2017-05-24 23:14:32 +10:00
|
|
|
void optimize_material_assignements();
|
2018-06-08 08:07:48 +02:00
|
|
|
|
2021-12-09 22:25:45 +11:00
|
|
|
/**
|
|
|
|
|
* We do not know in advance which objects will share geometries.
|
|
|
|
|
* And we do not know either if the objects which share geometries
|
|
|
|
|
* come along with different materials. So we first create the objects
|
|
|
|
|
* and assign the materials to Object, then in a later cleanup we decide
|
|
|
|
|
* which materials shall be moved to the created geometries. Also see
|
|
|
|
|
* optimize_material_assignements() above.
|
|
|
|
|
*/
|
2017-05-24 23:14:32 +10:00
|
|
|
void assign_material_to_geom(COLLADAFW::MaterialBinding cmaterial,
|
|
|
|
|
std::map<COLLADAFW::UniqueId, Material *> &uid_material_map,
|
|
|
|
|
Object *ob,
|
|
|
|
|
const COLLADAFW::UniqueId *geom_uid,
|
Remove Blender Internal and legacy viewport from Blender 2.8.
Brecht authored this commit, but he gave me the honours to actually
do it. Here it goes; Blender Internal. Bye bye, you did great!
* Point density, voxel data, ocean, environment map textures were removed,
as these only worked within BI rendering. Note that the ocean modifier
and the Cycles point density shader node continue to work.
* Dynamic paint using material shading was removed, as this only worked
with BI. If we ever wanted to support this again probably it should go
through the baking API.
* GPU shader export through the Python API was removed. This only worked
for the old BI GLSL shaders, which no longer exists. Doing something
similar for Eevee would be significantly more complicated because it
uses a lot of multiplass rendering and logic outside the shader, it's
probably impractical.
* Collada material import / export code is mostly gone, as it only worked
for BI materials. We need to add Cycles / Eevee material support at some
point.
* The mesh noise operator was removed since it only worked with BI
material texture slots. A displacement modifier can be used instead.
* The delete texture paint slot operator was removed since it only worked
for BI material texture slots. Could be added back with node support.
* Not all legacy viewport features are supported in the new viewport, but
their code was removed. If we need to bring anything back we can look at
older git revisions.
* There is some legacy viewport code that I could not remove yet, and some
that I probably missed.
* Shader node execution code was left mostly intact, even though it is not
used anywhere now. We may eventually use this to replace the texture
nodes with Cycles / Eevee shader nodes.
* The Cycles Bake panel now includes settings for baking multires normal
and displacement maps. The underlying code needs to be merged properly,
and we plan to add back support for multires AO baking and add support
to Cycles baking for features like vertex color, displacement, and other
missing baking features.
* This commit removes DNA and the Python API for BI material, lamp, world
and scene settings. This breaks a lot of addons.
* There is more DNA that can be removed or renamed, where Cycles or Eevee
are reusing some old BI properties but the names are not really correct
anymore.
* Texture slots for materials, lamps and world were removed. They remain
for brushes, particles and freestyle linestyles.
* 'BLENDER_RENDER' remains in the COMPAT_ENGINES of UI panels. Cycles and
other renderers use this to find all panels to show, minus a few panels
that they have their own replacement for.
2018-04-19 17:34:44 +02:00
|
|
|
short mat_index);
|
2018-06-08 08:07:48 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
Object *create_mesh_object(COLLADAFW::Node *node,
|
|
|
|
|
COLLADAFW::InstanceGeometry *geom,
|
2013-03-15 10:48:48 +00:00
|
|
|
bool isController,
|
Remove Blender Internal and legacy viewport from Blender 2.8.
Brecht authored this commit, but he gave me the honours to actually
do it. Here it goes; Blender Internal. Bye bye, you did great!
* Point density, voxel data, ocean, environment map textures were removed,
as these only worked within BI rendering. Note that the ocean modifier
and the Cycles point density shader node continue to work.
* Dynamic paint using material shading was removed, as this only worked
with BI. If we ever wanted to support this again probably it should go
through the baking API.
* GPU shader export through the Python API was removed. This only worked
for the old BI GLSL shaders, which no longer exists. Doing something
similar for Eevee would be significantly more complicated because it
uses a lot of multiplass rendering and logic outside the shader, it's
probably impractical.
* Collada material import / export code is mostly gone, as it only worked
for BI materials. We need to add Cycles / Eevee material support at some
point.
* The mesh noise operator was removed since it only worked with BI
material texture slots. A displacement modifier can be used instead.
* The delete texture paint slot operator was removed since it only worked
for BI material texture slots. Could be added back with node support.
* Not all legacy viewport features are supported in the new viewport, but
their code was removed. If we need to bring anything back we can look at
older git revisions.
* There is some legacy viewport code that I could not remove yet, and some
that I probably missed.
* Shader node execution code was left mostly intact, even though it is not
used anywhere now. We may eventually use this to replace the texture
nodes with Cycles / Eevee shader nodes.
* The Cycles Bake panel now includes settings for baking multires normal
and displacement maps. The underlying code needs to be merged properly,
and we plan to add back support for multires AO baking and add support
to Cycles baking for features like vertex color, displacement, and other
missing baking features.
* This commit removes DNA and the Python API for BI material, lamp, world
and scene settings. This breaks a lot of addons.
* There is more DNA that can be removed or renamed, where Cycles or Eevee
are reusing some old BI properties but the names are not really correct
anymore.
* Texture slots for materials, lamps and world were removed. They remain
for brushes, particles and freestyle linestyles.
* 'BLENDER_RENDER' remains in the COMPAT_ENGINES of UI panels. Cycles and
other renderers use this to find all panels to show, minus a few panels
that they have their own replacement for.
2018-04-19 17:34:44 +02:00
|
|
|
std::map<COLLADAFW::UniqueId, Material *> &uid_material_map);
|
2010-10-05 00:05:14 +00:00
|
|
|
|
2021-12-09 22:25:45 +11:00
|
|
|
/** Create a mesh storing a pointer in a map so it can be retrieved later by geometry UID. */
|
2010-10-05 00:05:14 +00:00
|
|
|
bool write_geometry(const COLLADAFW::Geometry *geom);
|
2013-02-13 08:53:05 +00:00
|
|
|
std::string *get_geometry_name(const std::string &mesh_name);
|
2010-10-05 00:05:14 +00:00
|
|
|
};
|