2011-02-23 10:52:22 +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-27 20:30:35 +00:00
|
|
|
*/
|
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
#include <algorithm>
|
2020-02-13 17:13:07 -07:00
|
|
|
#include <iostream>
|
2010-10-06 12:04:56 +00:00
|
|
|
|
2011-02-12 06:25:04 +00:00
|
|
|
/* COLLADABU_ASSERT, may be able to remove later */
|
|
|
|
#include "COLLADABUPlatform.h"
|
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
#include "COLLADAFWMeshPrimitive.h"
|
|
|
|
#include "COLLADAFWMeshVertexData.h"
|
|
|
|
#include "COLLADAFWPolygons.h"
|
|
|
|
|
2020-01-26 16:38:18 +01:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
2012-08-12 17:13:07 +00:00
|
|
|
#include "BKE_customdata.h"
|
|
|
|
#include "BKE_displist.h"
|
|
|
|
#include "BKE_global.h"
|
2020-02-10 12:58:59 +01:00
|
|
|
#include "BKE_lib_id.h"
|
2012-08-12 17:13:07 +00:00
|
|
|
#include "BKE_material.h"
|
|
|
|
#include "BKE_mesh.h"
|
|
|
|
#include "BKE_object.h"
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BLI_edgehash.h"
|
2012-08-12 17:13:07 +00:00
|
|
|
#include "BLI_listbase.h"
|
|
|
|
#include "BLI_math.h"
|
|
|
|
#include "BLI_string.h"
|
2010-10-05 00:05:14 +00:00
|
|
|
|
|
|
|
#include "ArmatureImporter.h"
|
|
|
|
#include "MeshImporter.h"
|
|
|
|
#include "collada_utils.h"
|
|
|
|
|
2011-06-20 12:43:10 +00:00
|
|
|
/* get node name, or fall back to original id if not present (name is optional) */
|
2020-09-04 12:04:47 +02:00
|
|
|
template<class T> static std::string bc_get_dae_name(T *node)
|
2010-10-05 00:05:14 +00:00
|
|
|
{
|
2020-07-03 14:59:27 +02:00
|
|
|
return node->getName().empty() ? node->getOriginalId() : node->getName();
|
2010-10-05 00:05:14 +00:00
|
|
|
}
|
|
|
|
|
2017-06-20 15:42:06 +02:00
|
|
|
static const char *bc_primTypeToStr(COLLADAFW::MeshPrimitive::PrimitiveType type)
|
2010-10-05 00:05:14 +00:00
|
|
|
{
|
|
|
|
switch (type) {
|
2012-06-12 22:05:33 +00:00
|
|
|
case COLLADAFW::MeshPrimitive::LINES:
|
|
|
|
return "LINES";
|
|
|
|
case COLLADAFW::MeshPrimitive::LINE_STRIPS:
|
|
|
|
return "LINESTRIPS";
|
|
|
|
case COLLADAFW::MeshPrimitive::POLYGONS:
|
|
|
|
return "POLYGONS";
|
|
|
|
case COLLADAFW::MeshPrimitive::POLYLIST:
|
|
|
|
return "POLYLIST";
|
|
|
|
case COLLADAFW::MeshPrimitive::TRIANGLES:
|
|
|
|
return "TRIANGLES";
|
|
|
|
case COLLADAFW::MeshPrimitive::TRIANGLE_FANS:
|
|
|
|
return "TRIANGLE_FANS";
|
|
|
|
case COLLADAFW::MeshPrimitive::TRIANGLE_STRIPS:
|
2014-08-22 02:46:29 +02:00
|
|
|
return "TRIANGLE_STRIPS";
|
2012-06-12 22:05:33 +00:00
|
|
|
case COLLADAFW::MeshPrimitive::POINTS:
|
|
|
|
return "POINTS";
|
|
|
|
case COLLADAFW::MeshPrimitive::UNDEFINED_PRIMITIVE_TYPE:
|
|
|
|
return "UNDEFINED_PRIMITIVE_TYPE";
|
2010-10-05 00:05:14 +00:00
|
|
|
}
|
|
|
|
return "UNKNOWN";
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *bc_geomTypeToStr(COLLADAFW::Geometry::GeometryType type)
|
|
|
|
{
|
|
|
|
switch (type) {
|
2012-06-12 22:05:33 +00:00
|
|
|
case COLLADAFW::Geometry::GEO_TYPE_MESH:
|
|
|
|
return "MESH";
|
|
|
|
case COLLADAFW::Geometry::GEO_TYPE_SPLINE:
|
|
|
|
return "SPLINE";
|
|
|
|
case COLLADAFW::Geometry::GEO_TYPE_CONVEX_MESH:
|
|
|
|
return "CONVEX_MESH";
|
|
|
|
case COLLADAFW::Geometry::GEO_TYPE_UNKNOWN:
|
|
|
|
default:
|
|
|
|
return "UNKNOWN";
|
2010-10-05 00:05:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
UVDataWrapper::UVDataWrapper(COLLADAFW::MeshVertexData &vdata) : mVData(&vdata)
|
2012-06-12 22:05:33 +00:00
|
|
|
{
|
|
|
|
}
|
2010-10-05 00:05:14 +00:00
|
|
|
|
|
|
|
#ifdef COLLADA_DEBUG
|
|
|
|
void WVDataWrapper::print()
|
|
|
|
{
|
|
|
|
fprintf(stderr, "UVs:\n");
|
2012-04-28 06:31:57 +00:00
|
|
|
switch (mVData->getType()) {
|
2012-06-12 22:05:33 +00:00
|
|
|
case COLLADAFW::MeshVertexData::DATA_TYPE_FLOAT: {
|
|
|
|
COLLADAFW::ArrayPrimitiveType<float> *values = mVData->getFloatValues();
|
2010-10-05 00:05:14 +00:00
|
|
|
if (values->getCount()) {
|
|
|
|
for (int i = 0; i < values->getCount(); i += 2) {
|
2012-06-12 22:05:33 +00:00
|
|
|
fprintf(stderr, "%.1f, %.1f\n", (*values)[i], (*values)[i + 1]);
|
2010-10-05 00:05:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} break;
|
2012-06-12 22:05:33 +00:00
|
|
|
case COLLADAFW::MeshVertexData::DATA_TYPE_DOUBLE: {
|
|
|
|
COLLADAFW::ArrayPrimitiveType<double> *values = mVData->getDoubleValues();
|
2010-10-05 00:05:14 +00:00
|
|
|
if (values->getCount()) {
|
|
|
|
for (int i = 0; i < values->getCount(); i += 2) {
|
2012-06-12 22:05:33 +00:00
|
|
|
fprintf(stderr, "%.1f, %.1f\n", (float)(*values)[i], (float)(*values)[i + 1]);
|
2010-10-05 00:05:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-07-06 21:37:31 +00:00
|
|
|
void UVDataWrapper::getUV(int uv_index, float *uv)
|
2010-10-05 00:05:14 +00:00
|
|
|
{
|
2011-07-06 21:37:31 +00:00
|
|
|
int stride = mVData->getStride(0);
|
2019-05-31 22:51:19 +10:00
|
|
|
if (stride == 0) {
|
2012-06-12 22:05:33 +00:00
|
|
|
stride = 2;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-28 06:31:57 +00:00
|
|
|
switch (mVData->getType()) {
|
2012-06-12 22:05:33 +00:00
|
|
|
case COLLADAFW::MeshVertexData::DATA_TYPE_FLOAT: {
|
|
|
|
COLLADAFW::ArrayPrimitiveType<float> *values = mVData->getFloatValues();
|
2019-05-31 22:51:19 +10:00
|
|
|
if (values->empty()) {
|
2010-10-05 00:05:14 +00:00
|
|
|
return;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2012-06-12 22:05:33 +00:00
|
|
|
uv[0] = (*values)[uv_index * stride];
|
|
|
|
uv[1] = (*values)[uv_index * stride + 1];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
} break;
|
2012-06-12 22:05:33 +00:00
|
|
|
case COLLADAFW::MeshVertexData::DATA_TYPE_DOUBLE: {
|
|
|
|
COLLADAFW::ArrayPrimitiveType<double> *values = mVData->getDoubleValues();
|
2019-05-31 22:51:19 +10:00
|
|
|
if (values->empty()) {
|
2010-10-05 00:05:14 +00:00
|
|
|
return;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2012-06-12 22:05:33 +00:00
|
|
|
uv[0] = (float)(*values)[uv_index * stride];
|
|
|
|
uv[1] = (float)(*values)[uv_index * stride + 1];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
} break;
|
2012-06-12 22:05:33 +00:00
|
|
|
case COLLADAFW::MeshVertexData::DATA_TYPE_UNKNOWN:
|
|
|
|
default:
|
|
|
|
fprintf(stderr, "MeshImporter.getUV(): unknown data type\n");
|
2010-10-05 00:05:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-19 06:25:54 +10:00
|
|
|
VCOLDataWrapper::VCOLDataWrapper(COLLADAFW::MeshVertexData &vdata) : mVData(&vdata)
|
|
|
|
{
|
|
|
|
}
|
2014-05-01 14:52:10 +02:00
|
|
|
|
|
|
|
void VCOLDataWrapper::get_vcol(int v_index, MLoopCol *mloopcol)
|
|
|
|
{
|
|
|
|
int stride = mVData->getStride(0);
|
2019-05-31 22:51:19 +10:00
|
|
|
if (stride == 0) {
|
2014-05-08 04:53:05 +10:00
|
|
|
stride = 3;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-05-01 14:52:10 +02:00
|
|
|
switch (mVData->getType()) {
|
|
|
|
case COLLADAFW::MeshVertexData::DATA_TYPE_FLOAT: {
|
|
|
|
COLLADAFW::ArrayPrimitiveType<float> *values = mVData->getFloatValues();
|
2019-05-31 22:51:19 +10:00
|
|
|
if (values->empty() || values->getCount() <= (v_index * stride + 2)) {
|
2018-09-24 17:27:41 +02:00
|
|
|
return; /* xxx need to create an error instead */
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-07 17:31:28 +02:00
|
|
|
mloopcol->r = unit_float_to_uchar_clamp((*values)[v_index * stride]);
|
|
|
|
mloopcol->g = unit_float_to_uchar_clamp((*values)[v_index * stride + 1]);
|
|
|
|
mloopcol->b = unit_float_to_uchar_clamp((*values)[v_index * stride + 2]);
|
2014-05-01 14:52:10 +02:00
|
|
|
} break;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-05-01 14:52:10 +02:00
|
|
|
case COLLADAFW::MeshVertexData::DATA_TYPE_DOUBLE: {
|
|
|
|
COLLADAFW::ArrayPrimitiveType<double> *values = mVData->getDoubleValues();
|
2019-05-31 22:51:19 +10:00
|
|
|
if (values->empty() || values->getCount() <= (v_index * stride + 2)) {
|
2018-09-24 17:27:41 +02:00
|
|
|
return; /* xxx need to create an error instead */
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-05-07 17:31:28 +02:00
|
|
|
mloopcol->r = unit_float_to_uchar_clamp((*values)[v_index * stride]);
|
|
|
|
mloopcol->g = unit_float_to_uchar_clamp((*values)[v_index * stride + 1]);
|
|
|
|
mloopcol->b = unit_float_to_uchar_clamp((*values)[v_index * stride + 2]);
|
2014-05-01 14:52:10 +02:00
|
|
|
} break;
|
|
|
|
default:
|
|
|
|
fprintf(stderr, "VCOLDataWrapper.getvcol(): unknown data type\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-14 15:55:51 +02:00
|
|
|
MeshImporter::MeshImporter(
|
|
|
|
UnitConverter *unitconv, ArmatureImporter *arm, Main *bmain, Scene *sce, ViewLayer *view_layer)
|
2018-06-08 08:10:35 +02:00
|
|
|
: unitconverter(unitconv),
|
2018-06-14 15:55:51 +02:00
|
|
|
m_bmain(bmain),
|
2018-01-26 13:13:54 +01:00
|
|
|
scene(sce),
|
|
|
|
view_layer(view_layer),
|
2019-04-16 16:40:47 +02:00
|
|
|
armature_importer(arm)
|
|
|
|
{
|
|
|
|
/* pass */
|
2010-10-05 00:05:14 +00:00
|
|
|
}
|
|
|
|
|
2016-06-03 18:22:56 +02:00
|
|
|
bool MeshImporter::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)
|
2010-10-05 00:05:14 +00:00
|
|
|
{
|
2013-03-02 15:58:13 +00:00
|
|
|
mpoly->loopstart = loop_index;
|
|
|
|
mpoly->totloop = loop_count;
|
2016-06-03 18:22:56 +02:00
|
|
|
bool broken_loop = false;
|
2013-03-02 15:58:13 +00:00
|
|
|
for (int index = 0; index < loop_count; index++) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-06-03 18:22:56 +02:00
|
|
|
/* Test if loop defines a hole */
|
|
|
|
if (!broken_loop) {
|
|
|
|
for (int i = 0; i < index; i++) {
|
|
|
|
if (indices[i] == indices[index]) {
|
|
|
|
/* duplicate index -> not good */
|
|
|
|
broken_loop = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-02 15:58:13 +00:00
|
|
|
mloop->v = indices[index];
|
|
|
|
mloop++;
|
|
|
|
}
|
2016-06-03 18:22:56 +02:00
|
|
|
return broken_loop;
|
2010-10-05 00:05:14 +00:00
|
|
|
}
|
|
|
|
|
2020-09-04 20:59:13 +02:00
|
|
|
void MeshImporter::set_vcol(MLoopCol *mloopcol,
|
2014-05-01 14:52:10 +02:00
|
|
|
VCOLDataWrapper &vob,
|
|
|
|
int loop_index,
|
|
|
|
COLLADAFW::IndexList &index_list,
|
|
|
|
int count)
|
|
|
|
{
|
|
|
|
int index;
|
2020-09-04 20:59:13 +02:00
|
|
|
for (index = 0; index < count; index++, mloopcol++) {
|
2015-02-27 21:56:14 +01:00
|
|
|
int v_index = index_list.getIndex(index + loop_index);
|
2020-09-04 20:59:13 +02:00
|
|
|
vob.get_vcol(v_index, mloopcol);
|
2014-05-01 14:52:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-02 15:58:13 +00:00
|
|
|
void MeshImporter::set_face_uv(MLoopUV *mloopuv,
|
|
|
|
UVDataWrapper &uvs,
|
|
|
|
int start_index,
|
|
|
|
COLLADAFW::IndexList &index_list,
|
|
|
|
int count)
|
2010-10-05 00:05:14 +00:00
|
|
|
{
|
|
|
|
/* per face vertex indices, this means for quad we have 4 indices, not 8 */
|
|
|
|
COLLADAFW::UIntValuesArray &indices = index_list.getIndices();
|
|
|
|
|
2013-03-02 15:58:13 +00:00
|
|
|
for (int index = 0; index < count; index++) {
|
|
|
|
int uv_index = indices[index + start_index];
|
|
|
|
uvs.getUV(uv_index, mloopuv[index].uv);
|
2010-10-05 00:05:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef COLLADA_DEBUG
|
|
|
|
void MeshImporter::print_index_list(COLLADAFW::IndexList &index_list)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Index list for \"%s\":\n", index_list.getName().c_str());
|
|
|
|
for (int i = 0; i < index_list.getIndicesCount(); i += 2) {
|
|
|
|
fprintf(stderr, "%u, %u\n", index_list.getIndex(i), index_list.getIndex(i + 1));
|
|
|
|
}
|
|
|
|
fprintf(stderr, "\n");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-04-30 13:41:21 +10:00
|
|
|
/* checks if mesh has supported primitive types: lines, polylist, triangles, triangle_fans */
|
|
|
|
bool MeshImporter::is_nice_mesh(COLLADAFW::Mesh *mesh)
|
2010-10-05 00:05:14 +00:00
|
|
|
{
|
|
|
|
COLLADAFW::MeshPrimitiveArray &prim_arr = mesh->getMeshPrimitives();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-02-08 00:27:35 +00:00
|
|
|
const std::string &name = bc_get_dae_name(mesh);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-02-08 01:02:18 +11:00
|
|
|
for (unsigned int i = 0; i < prim_arr.getCount(); i++) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
COLLADAFW::MeshPrimitive *mp = prim_arr[i];
|
2017-06-20 15:42:06 +02:00
|
|
|
COLLADAFW::MeshPrimitive::PrimitiveType type = mp->getPrimitiveType();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
const char *type_str = bc_primTypeToStr(type);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
/* OpenCollada passes POLYGONS type for <polylist> */
|
|
|
|
if (type == COLLADAFW::MeshPrimitive::POLYLIST || type == COLLADAFW::MeshPrimitive::POLYGONS) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-06-12 22:05:33 +00:00
|
|
|
COLLADAFW::Polygons *mpvc = (COLLADAFW::Polygons *)mp;
|
2010-10-05 00:05:14 +00:00
|
|
|
COLLADAFW::Polygons::VertexCountArray &vca = mpvc->getGroupedVerticesVertexCountArray();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-06-14 13:08:42 +02:00
|
|
|
int hole_count = 0;
|
|
|
|
int nonface_count = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-28 05:03:24 +00:00
|
|
|
for (unsigned int j = 0; j < vca.getCount(); j++) {
|
2010-10-05 00:05:14 +00:00
|
|
|
int count = vca[j];
|
2016-05-12 17:55:41 +02:00
|
|
|
if (abs(count) < 3) {
|
2016-06-14 13:08:42 +02:00
|
|
|
nonface_count++;
|
2010-10-05 00:05:14 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-06-14 13:08:42 +02:00
|
|
|
if (count < 0) {
|
2016-05-12 17:55:41 +02:00
|
|
|
hole_count++;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2016-05-12 17:55:41 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-06-14 13:08:42 +02:00
|
|
|
if (hole_count > 0) {
|
2016-05-12 17:55:41 +02:00
|
|
|
fprintf(stderr,
|
|
|
|
"WARNING: Primitive %s in %s: %d holes not imported (unsupported)\n",
|
|
|
|
type_str,
|
|
|
|
name.c_str(),
|
|
|
|
hole_count);
|
2010-10-05 00:05:14 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-06-14 13:08:42 +02:00
|
|
|
if (nonface_count > 0) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"WARNING: Primitive %s in %s: %d faces with vertex count < 3 (rejected)\n",
|
|
|
|
type_str,
|
|
|
|
name.c_str(),
|
|
|
|
nonface_count);
|
2010-10-05 00:05:14 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
2012-06-27 18:29:47 +00:00
|
|
|
else if (type == COLLADAFW::MeshPrimitive::LINES) {
|
2012-05-16 11:21:03 +00:00
|
|
|
/* TODO: Add Checker for line syntax here */
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-06-12 22:05:33 +00:00
|
|
|
else if (type != COLLADAFW::MeshPrimitive::TRIANGLES &&
|
|
|
|
type != COLLADAFW::MeshPrimitive::TRIANGLE_FANS) {
|
2016-05-12 17:55:41 +02:00
|
|
|
fprintf(stderr, "ERROR: Primitive type %s is not supported.\n", type_str);
|
2010-10-05 00:05:14 +00:00
|
|
|
return false;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MeshImporter::read_vertices(COLLADAFW::Mesh *mesh, Mesh *me)
|
|
|
|
{
|
2011-01-27 19:39:06 +00:00
|
|
|
/* vertices */
|
|
|
|
COLLADAFW::MeshVertexData &pos = mesh->getPositions();
|
2016-11-12 22:20:07 +01:00
|
|
|
if (pos.empty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-01-27 19:39:06 +00:00
|
|
|
int stride = pos.getStride(0);
|
2019-05-31 22:51:19 +10:00
|
|
|
if (stride == 0) {
|
2012-06-12 22:05:33 +00:00
|
|
|
stride = 3;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2016-11-12 22:20:07 +01:00
|
|
|
|
|
|
|
me->totvert = pos.getFloatValues()->getCount() / stride;
|
2020-11-06 17:49:09 +01:00
|
|
|
me->mvert = (MVert *)CustomData_add_layer(&me->vdata, CD_MVERT, CD_CALLOC, nullptr, me->totvert);
|
2010-10-05 00:05:14 +00:00
|
|
|
|
|
|
|
MVert *mvert;
|
|
|
|
int i;
|
|
|
|
|
2010-10-09 21:17:14 +00:00
|
|
|
for (i = 0, mvert = me->mvert; i < me->totvert; i++, mvert++) {
|
2011-01-27 19:39:06 +00:00
|
|
|
get_vector(mvert->co, pos, i, stride);
|
2010-10-09 21:17:14 +00:00
|
|
|
}
|
2010-10-05 00:05:14 +00:00
|
|
|
}
|
|
|
|
|
2012-05-16 11:21:03 +00: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.
|
|
|
|
* ===================================================================== */
|
|
|
|
bool MeshImporter::primitive_has_useable_normals(COLLADAFW::MeshPrimitive *mp)
|
|
|
|
{
|
|
|
|
|
|
|
|
bool has_useable_normals = false;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-05-16 11:21:03 +00:00
|
|
|
int normals_count = mp->getNormalIndices().getCount();
|
|
|
|
if (normals_count > 0) {
|
|
|
|
int index_count = mp->getPositionIndices().getCount();
|
2019-05-31 22:51:19 +10:00
|
|
|
if (index_count == normals_count) {
|
2012-05-16 11:21:03 +00:00
|
|
|
has_useable_normals = true;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
else {
|
2012-05-16 11:21:03 +00:00
|
|
|
fprintf(stderr,
|
2012-06-12 22:05:33 +00:00
|
|
|
"Warning: Number of normals %d is different from the number of vertices %d, "
|
|
|
|
"skipping normals\n",
|
|
|
|
normals_count,
|
|
|
|
index_count);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-16 11:21:03 +00:00
|
|
|
return has_useable_normals;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* =====================================================================
|
|
|
|
* Assume that only TRIANGLES, TRIANGLE_FANS, POLYLIST and POLYGONS
|
|
|
|
* have faces. (to be verified)
|
|
|
|
* ===================================================================== */
|
|
|
|
bool MeshImporter::primitive_has_faces(COLLADAFW::MeshPrimitive *mp)
|
|
|
|
{
|
2014-05-01 14:52:10 +02:00
|
|
|
|
|
|
|
bool has_faces = false;
|
|
|
|
int type = mp->getPrimitiveType();
|
|
|
|
switch (type) {
|
|
|
|
case COLLADAFW::MeshPrimitive::TRIANGLES:
|
|
|
|
case COLLADAFW::MeshPrimitive::TRIANGLE_FANS:
|
|
|
|
case COLLADAFW::MeshPrimitive::POLYLIST:
|
|
|
|
case COLLADAFW::MeshPrimitive::POLYGONS: {
|
|
|
|
has_faces = true;
|
2019-04-17 06:17:24 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
2014-05-01 14:52:10 +02:00
|
|
|
has_faces = false;
|
|
|
|
break;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2014-05-01 14:52:10 +02:00
|
|
|
return has_faces;
|
|
|
|
}
|
|
|
|
|
2015-02-27 21:56:14 +01:00
|
|
|
static std::string extract_vcolname(const COLLADAFW::String &collada_id)
|
2019-04-17 06:17:24 +02:00
|
|
|
{
|
2014-05-01 14:52:10 +02:00
|
|
|
std::string colname = collada_id;
|
|
|
|
int spos = colname.find("-mesh-colors-");
|
|
|
|
if (spos != std::string::npos) {
|
|
|
|
colname = colname.substr(spos + 13);
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2012-08-12 17:13:07 +00:00
|
|
|
return colname;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2014-05-01 14:52:10 +02:00
|
|
|
|
2012-05-16 11:21:03 +00:00
|
|
|
/* =================================================================
|
2012-08-11 22:12:32 +00:00
|
|
|
* Return the number of faces by summing up
|
2020-10-14 14:43:54 +11:00
|
|
|
* the face-counts of the parts.
|
|
|
|
* hint: This is done because `mesh->getFacesCount()` does
|
2012-05-16 11:21:03 +00:00
|
|
|
* count loose edges as extra faces, which is not what we want here.
|
|
|
|
* ================================================================= */
|
2013-03-02 15:58:13 +00:00
|
|
|
void MeshImporter::allocate_poly_data(COLLADAFW::Mesh *collada_mesh, Mesh *me)
|
2012-08-11 22:12:32 +00:00
|
|
|
{
|
2013-03-02 15:58:13 +00:00
|
|
|
COLLADAFW::MeshPrimitiveArray &prim_arr = collada_mesh->getMeshPrimitives();
|
2014-05-01 14:52:10 +02:00
|
|
|
int total_poly_count = 0;
|
|
|
|
int total_loop_count = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-05-16 11:21:03 +00:00
|
|
|
/* collect edge_count and face_count from all parts */
|
2012-10-21 05:46:41 +00:00
|
|
|
for (int i = 0; i < prim_arr.getCount(); i++) {
|
2012-05-16 11:21:03 +00:00
|
|
|
COLLADAFW::MeshPrimitive *mp = prim_arr[i];
|
|
|
|
int type = mp->getPrimitiveType();
|
|
|
|
switch (type) {
|
|
|
|
case COLLADAFW::MeshPrimitive::TRIANGLES:
|
|
|
|
case COLLADAFW::MeshPrimitive::TRIANGLE_FANS:
|
|
|
|
case COLLADAFW::MeshPrimitive::POLYLIST:
|
2013-07-19 10:40:43 +00:00
|
|
|
case COLLADAFW::MeshPrimitive::POLYGONS: {
|
2013-03-02 15:58:13 +00:00
|
|
|
COLLADAFW::Polygons *mpvc = (COLLADAFW::Polygons *)mp;
|
|
|
|
size_t prim_poly_count = mpvc->getFaceCount();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-02 15:58:13 +00:00
|
|
|
size_t prim_loop_count = 0;
|
2018-06-08 08:07:48 +02:00
|
|
|
for (int index = 0; index < prim_poly_count; index++) {
|
2016-05-12 17:55:41 +02:00
|
|
|
int vcount = get_vertex_count(mpvc, index);
|
|
|
|
if (vcount > 0) {
|
|
|
|
prim_loop_count += vcount;
|
|
|
|
total_poly_count++;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* TODO: this is a hole and not another polygon! */
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2016-05-12 17:55:41 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-02 15:58:13 +00:00
|
|
|
total_loop_count += prim_loop_count;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-05-16 11:21:03 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-07-19 10:40:43 +00:00
|
|
|
default:
|
|
|
|
break;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2012-05-16 11:21:03 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-02 15:58:13 +00:00
|
|
|
/* Add the data containers */
|
|
|
|
if (total_poly_count > 0) {
|
|
|
|
me->totpoly = total_poly_count;
|
|
|
|
me->totloop = total_loop_count;
|
2020-11-06 17:49:09 +01:00
|
|
|
me->mpoly = (MPoly *)CustomData_add_layer(
|
|
|
|
&me->pdata, CD_MPOLY, CD_CALLOC, nullptr, me->totpoly);
|
|
|
|
me->mloop = (MLoop *)CustomData_add_layer(
|
|
|
|
&me->ldata, CD_MLOOP, CD_CALLOC, nullptr, me->totloop);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-02 15:58:13 +00:00
|
|
|
unsigned int totuvset = collada_mesh->getUVCoords().getInputInfosArray().getCount();
|
|
|
|
for (int i = 0; i < totuvset; i++) {
|
|
|
|
if (collada_mesh->getUVCoords().getLength(i) == 0) {
|
|
|
|
totuvset = 0;
|
|
|
|
break;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2013-03-02 15:58:13 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-02 15:58:13 +00:00
|
|
|
if (totuvset > 0) {
|
|
|
|
for (int i = 0; i < totuvset; i++) {
|
|
|
|
COLLADAFW::MeshVertexData::InputInfos *info =
|
|
|
|
collada_mesh->getUVCoords().getInputInfosArray()[i];
|
|
|
|
COLLADAFW::String &uvname = info->mName;
|
|
|
|
/* Allocate space for UV_data */
|
|
|
|
CustomData_add_layer_named(
|
2020-11-06 17:49:09 +01:00
|
|
|
&me->ldata, CD_MLOOPUV, CD_DEFAULT, nullptr, me->totloop, uvname.c_str());
|
2013-03-02 15:58:13 +00:00
|
|
|
}
|
|
|
|
/* activate the first uv map */
|
|
|
|
me->mloopuv = (MLoopUV *)CustomData_get_layer_n(&me->ldata, CD_MLOOPUV, 0);
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-05-01 14:52:10 +02:00
|
|
|
int totcolset = collada_mesh->getColors().getInputInfosArray().getCount();
|
|
|
|
if (totcolset > 0) {
|
|
|
|
for (int i = 0; i < totcolset; i++) {
|
|
|
|
COLLADAFW::MeshVertexData::InputInfos *info =
|
|
|
|
collada_mesh->getColors().getInputInfosArray()[i];
|
|
|
|
COLLADAFW::String colname = extract_vcolname(info->mName);
|
|
|
|
CustomData_add_layer_named(
|
2020-11-06 17:49:09 +01:00
|
|
|
&me->ldata, CD_MLOOPCOL, CD_DEFAULT, nullptr, me->totloop, colname.c_str());
|
2014-05-01 14:52:10 +02:00
|
|
|
}
|
|
|
|
me->mloopcol = (MLoopCol *)CustomData_get_layer_n(&me->ldata, CD_MLOOPCOL, 0);
|
|
|
|
}
|
2012-05-16 11:21:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-02 15:58:13 +00:00
|
|
|
unsigned int MeshImporter::get_vertex_count(COLLADAFW::Polygons *mp, int index)
|
|
|
|
{
|
|
|
|
int type = mp->getPrimitiveType();
|
|
|
|
int result;
|
|
|
|
switch (type) {
|
|
|
|
case COLLADAFW::MeshPrimitive::TRIANGLES:
|
2013-07-19 10:40:43 +00:00
|
|
|
case COLLADAFW::MeshPrimitive::TRIANGLE_FANS: {
|
2013-03-02 15:58:13 +00:00
|
|
|
result = 3;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case COLLADAFW::MeshPrimitive::POLYLIST:
|
2013-07-19 10:40:43 +00:00
|
|
|
case COLLADAFW::MeshPrimitive::POLYGONS: {
|
2013-03-02 15:58:13 +00:00
|
|
|
result = mp->getGroupedVerticesVertexCountArray()[index];
|
|
|
|
break;
|
|
|
|
}
|
2013-07-19 10:40:43 +00:00
|
|
|
default: {
|
2013-03-02 15:58:13 +00:00
|
|
|
result = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2012-05-16 11:21:03 +00:00
|
|
|
unsigned int MeshImporter::get_loose_edge_count(COLLADAFW::Mesh *mesh)
|
|
|
|
{
|
|
|
|
COLLADAFW::MeshPrimitiveArray &prim_arr = mesh->getMeshPrimitives();
|
|
|
|
int loose_edge_count = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-05-16 11:21:03 +00:00
|
|
|
/* collect edge_count and face_count from all parts */
|
2012-10-21 05:46:41 +00:00
|
|
|
for (int i = 0; i < prim_arr.getCount(); i++) {
|
2012-05-16 11:21:03 +00:00
|
|
|
COLLADAFW::MeshPrimitive *mp = prim_arr[i];
|
|
|
|
int type = mp->getPrimitiveType();
|
|
|
|
switch (type) {
|
2013-07-19 10:40:43 +00:00
|
|
|
case COLLADAFW::MeshPrimitive::LINES: {
|
2012-05-16 11:21:03 +00:00
|
|
|
size_t prim_totface = mp->getFaceCount();
|
|
|
|
loose_edge_count += prim_totface;
|
|
|
|
break;
|
|
|
|
}
|
2013-07-19 10:40:43 +00:00
|
|
|
default:
|
|
|
|
break;
|
2012-05-16 11:21:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return loose_edge_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* =================================================================
|
2018-09-24 17:27:41 +02:00
|
|
|
* This function is copied from source/blender/editors/mesh/mesh_data.c
|
2020-10-10 18:19:55 +11:00
|
|
|
*
|
2012-05-16 11:21:03 +00:00
|
|
|
* TODO: (As discussed with sergey-) :
|
2018-06-08 08:07:48 +02:00
|
|
|
* Maybe move this function to blenderkernel/intern/mesh.c
|
2012-05-16 11:21:03 +00:00
|
|
|
* and add definition to BKE_mesh.c
|
|
|
|
* ================================================================= */
|
|
|
|
void MeshImporter::mesh_add_edges(Mesh *mesh, int len)
|
|
|
|
{
|
|
|
|
CustomData edata;
|
|
|
|
MEdge *medge;
|
2018-03-11 20:32:47 +01:00
|
|
|
int totedge;
|
2012-05-16 11:21:03 +00:00
|
|
|
|
2019-05-31 22:51:19 +10:00
|
|
|
if (len == 0) {
|
2012-05-16 11:21:03 +00:00
|
|
|
return;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2012-05-16 11:21:03 +00:00
|
|
|
|
|
|
|
totedge = mesh->totedge + len;
|
|
|
|
|
|
|
|
/* update customdata */
|
Refactor CDData masks, to have one mask per mesh elem type.
We already have different storages for cddata of verts, edges etc.,
'simply' do the same for the mask flags we use all around Blender code
to request some data, or limit some operation to some layers, etc.
Reason we need this is that some cddata types (like Normals) are
actually shared between verts/polys/loops, and we don’t want to generate
clnors everytime we request vnors!
As a side note, this also does final fix to T59338, which was the
trigger for this patch (need to request computed loop normals for
another mesh than evaluated one).
Reviewers: brecht, campbellbarton, sergey
Differential Revision: https://developer.blender.org/D4407
2019-03-07 11:13:40 +01:00
|
|
|
CustomData_copy(&mesh->edata, &edata, CD_MASK_MESH.emask, CD_DEFAULT, totedge);
|
2012-05-16 11:21:03 +00:00
|
|
|
CustomData_copy_data(&mesh->edata, &edata, 0, 0, mesh->totedge);
|
|
|
|
|
2019-05-31 22:51:19 +10:00
|
|
|
if (!CustomData_has_layer(&edata, CD_MEDGE)) {
|
2020-11-06 17:49:09 +01:00
|
|
|
CustomData_add_layer(&edata, CD_MEDGE, CD_CALLOC, nullptr, totedge);
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2012-05-16 11:21:03 +00:00
|
|
|
|
|
|
|
CustomData_free(&mesh->edata, mesh->totedge);
|
|
|
|
mesh->edata = edata;
|
2013-03-17 19:55:10 +00:00
|
|
|
BKE_mesh_update_customdata_pointers(mesh, false); /* new edges don't change tessellation */
|
2012-05-16 11:21:03 +00:00
|
|
|
|
|
|
|
/* set default flags */
|
|
|
|
medge = &mesh->medge[mesh->totedge];
|
2019-05-31 22:51:19 +10:00
|
|
|
for (int i = 0; i < len; i++, medge++) {
|
2012-05-16 11:21:03 +00:00
|
|
|
medge->flag = ME_EDGEDRAW | ME_EDGERENDER | SELECT;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2012-05-16 11:21:03 +00:00
|
|
|
|
|
|
|
mesh->totedge = totedge;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* =================================================================
|
|
|
|
* Read all loose edges.
|
2018-06-08 08:07:48 +02:00
|
|
|
* Important: This function assumes that all edges from existing
|
2018-09-24 17:27:41 +02:00
|
|
|
* faces have already been generated and added to me->medge
|
2012-05-16 11:21:03 +00:00
|
|
|
* So this function MUST be called after read_faces() (see below)
|
|
|
|
* ================================================================= */
|
|
|
|
void MeshImporter::read_lines(COLLADAFW::Mesh *mesh, Mesh *me)
|
|
|
|
{
|
|
|
|
unsigned int loose_edge_count = get_loose_edge_count(mesh);
|
2012-06-12 22:05:33 +00:00
|
|
|
if (loose_edge_count > 0) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-05-16 11:21:03 +00:00
|
|
|
unsigned int face_edge_count = me->totedge;
|
2012-09-03 22:04:14 +00:00
|
|
|
/* unsigned int total_edge_count = loose_edge_count + face_edge_count; */ /* UNUSED */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-05-16 11:21:03 +00:00
|
|
|
mesh_add_edges(me, loose_edge_count);
|
|
|
|
MEdge *med = me->medge + face_edge_count;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-05-16 11:21:03 +00:00
|
|
|
COLLADAFW::MeshPrimitiveArray &prim_arr = mesh->getMeshPrimitives();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Partial rewrite of the Collada Module for Blender 2.8
Most important changes are in the Animation exporter and Animation Importer.
There is still some cleaning up to be done. But the Exporter/Importer basically
work within Blender 2.8
Some details:
User Interface:
The interface has been reorganized to look more like the FBX interface.
New options in user interface:
* keep_keyframes:
When sampling the distance between 2 keyframes is defined by
the sampling rate. Furthermore the keyframes defined in the
FCurves are not exported. However when this option is enabled
then also the defined keyframes will be added to the exported fcurves
* keep_smooth_curves:
When sampling we do not use FCurves. So we also have no Curve handles
for smooth exporting. However when this option is enabled, Blender
does its best to recreate the handles for export. This is a very
experimental feature and it is know to break when:
- the exported animated objects have parent inverse matrices
different from the unit matrix
- The exported objects have negative scaling
There may be many other situations when this feature breaks.
This needs to be further tested. It may be removed later or replaced
by something less wonky.
BlenderContext:
is a new class that contains the bridge to Blender. It contains
pointers to the current export/import context plus derived values
of Depsgraph, Scene, Main
Reporting:
I reorganized the output on the Blender Console to become more
informative and more readable
Preservation of Item names:
name attributes are now encoded with XML entities. This makes
sure that i can export/import names exactly defined in the tool.
This affects material names, bone names and object names.
Hierarchy export:
* Object and Bone Hierarchies are now exported correctly
by taking the Blender parent/child hierarchy into account
* Export also not selected intermediate objects
Problem:
When we export an Object Hierarchy, then we must export
all elements of the hierarchy to maintain the transforms. This
is especially important when exporting animated objects, because the
animation curves are exported as relative curves based on the
parent-child hierarchy. If an intermediate animated object is missing
then the exported animation breaks.
Solution:
If the "Selected" Optioon is enabled, then take care
to also export all objects which are not selected and hidden,
but which are parents of selected objects.
Node Based Material Importer (wip):
Added basic support for Materials with diffuse color and
diffuse textures. More properties (opacity, emission) need
changes in the used shader.
Note: Materials are all constructed by using the principled BSDF shader.
Animation Exporter:
* Massive optimization of the Animation Bake tool (Animation Sampler).
Instead of sampling each fcurve separately, i now sample all
exported fcurves simultaneously. So i avoid many (many!)
scene updates during animation export.
* Add support for Continuous Acceleration (Fcurve handles)
This allows us to create smoother FCurves during importing Collada
Animation curves. Possibly this should become an option ionstead of
a fixed import feature.
* Add support for sampling curves (to bake animations)
* The animation sampler now can be used for any animation curve.
Before the sampler only looked at curves which are supported by
Standard Collada 1.4. However the Collada exporter currently
ignores all animation curves which are not covered by the 1.4.1
Collada Standards. There is still some room for improvements
here (work in progres)
Known issues:
* Some exports do currently not work reliably, among those
are the camera animations, material animations and light animations
those animations will be added back next (work in progres)
* Exporting animation curves with keyframes (and tangents)
sometimes results in odd curves (when parent inverse matrix is involved)
This needs to be checked in more depth (probably it can not be solved).
* Export of "all animations in scene" is disabled because the
Collada Importer can not handle this reliably at the
moment (work in progres).
* Support for Animation Clip export
Added one extra level to the exported animations
such that now all scene animations are enclosed:
<Animation name="id_name(ob)_Action">
<Animation>...</Animation>
...
</Animation>
Animation Importer:
* Import of animations for objects with multiple materials
When importing multiple materials for one object,
the imported material animation curves have all been
assigned to the first material in the object.
Error handling (wip):
The Importer was a bit confused as it sometimes ignored fatal
parsing errors and continued to import. I did my best to
unconfuse it, but i believe that this needs to be tested more.
Refactoring:
update : move generation of effect id names into own function
update : adjust importer/exporter for no longer supported HEMI lights
cleanup: Removed no lopnger existing attribute from the exporter presets
cleanup: Removed not needed Context attribute from DocumentExporter
fix : Avoid duplicate deletion of temporary items
cleanup: fixed indentation and white space issues
update : Make BCAnimation class more self contained
cleanup: Renamed classes, updated comments for better reading
cleanup: Moved static class functions to collada_utils
cleanup: Moved typedefs to more intuitive locations
cleanup: indentation and class method declarations
cleanup: Removed no longer needed methods
update : Moved Classes into separate files
cleanup: Added comments
cleanup: take care of name conventions
... : many more small changes, not helpful to list them all
2018-11-23 15:57:45 +01:00
|
|
|
for (int index = 0; index < prim_arr.getCount(); index++) {
|
|
|
|
COLLADAFW::MeshPrimitive *mp = prim_arr[index];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-05-16 11:21:03 +00:00
|
|
|
int type = mp->getPrimitiveType();
|
2012-06-27 18:29:47 +00:00
|
|
|
if (type == COLLADAFW::MeshPrimitive::LINES) {
|
2012-05-16 11:21:03 +00:00
|
|
|
unsigned int edge_count = mp->getFaceCount();
|
|
|
|
unsigned int *indices = mp->getPositionIndices().getData();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-03-11 20:32:47 +01:00
|
|
|
for (int j = 0; j < edge_count; j++, med++) {
|
2012-06-12 22:05:33 +00:00
|
|
|
med->bweight = 0;
|
|
|
|
med->crease = 0;
|
2012-12-06 06:13:43 +00:00
|
|
|
med->flag |= ME_LOOSEEDGE;
|
2018-03-11 20:32:47 +01:00
|
|
|
med->v1 = indices[2 * j];
|
|
|
|
med->v2 = indices[2 * j + 1];
|
2012-05-16 11:21:03 +00:00
|
|
|
}
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2012-05-16 11:21:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* =======================================================================
|
|
|
|
* Read all faces from TRIANGLES, TRIANGLE_FANS, POLYLIST, POLYGON
|
2018-06-08 08:07:48 +02:00
|
|
|
* Important: This function MUST be called before read_lines()
|
2012-05-16 11:21:03 +00:00
|
|
|
* Otherwise we will lose all edges from faces (see read_lines() above)
|
2020-10-10 18:19:55 +11:00
|
|
|
*
|
2010-10-05 00:05:14 +00:00
|
|
|
* TODO: import uv set names
|
2012-05-16 11:21:03 +00:00
|
|
|
* ======================================================================== */
|
2013-03-02 15:58:13 +00:00
|
|
|
void MeshImporter::read_polys(COLLADAFW::Mesh *collada_mesh, Mesh *me)
|
2010-10-05 00:05:14 +00:00
|
|
|
{
|
|
|
|
unsigned int i;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-02 15:58:13 +00:00
|
|
|
allocate_poly_data(collada_mesh, me);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-02 15:58:13 +00:00
|
|
|
UVDataWrapper uvs(collada_mesh->getUVCoords());
|
2014-05-01 14:52:10 +02:00
|
|
|
VCOLDataWrapper vcol(collada_mesh->getColors());
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-02 15:58:13 +00:00
|
|
|
MPoly *mpoly = me->mpoly;
|
|
|
|
MLoop *mloop = me->mloop;
|
|
|
|
int loop_index = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
MaterialIdPrimitiveArrayMap mat_prim_map;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-02 15:58:13 +00:00
|
|
|
COLLADAFW::MeshPrimitiveArray &prim_arr = collada_mesh->getMeshPrimitives();
|
|
|
|
COLLADAFW::MeshVertexData &nor = collada_mesh->getNormals();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
for (i = 0; i < prim_arr.getCount(); i++) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
COLLADAFW::MeshPrimitive *mp = prim_arr[i];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
/* faces */
|
2014-05-01 14:52:10 +02:00
|
|
|
size_t prim_totpoly = mp->getFaceCount();
|
|
|
|
unsigned int *position_indices = mp->getPositionIndices().getData();
|
|
|
|
unsigned int *normal_indices = mp->getNormalIndices().getData();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-05-16 11:21:03 +00:00
|
|
|
bool mp_has_normals = primitive_has_useable_normals(mp);
|
|
|
|
bool mp_has_faces = primitive_has_faces(mp);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-02 15:58:13 +00:00
|
|
|
int collada_meshtype = mp->getPrimitiveType();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-04 13:12:56 +00:00
|
|
|
/* since we cannot set mpoly->mat_nr here, we store a portion of me->mpoly in Primitive */
|
2013-03-02 15:58:13 +00:00
|
|
|
Primitive prim = {mpoly, 0};
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-03-08 13:26:41 +00:00
|
|
|
/* If MeshPrimitive is TRIANGLE_FANS we split it into triangles
|
2020-10-14 14:43:54 +11:00
|
|
|
* The first triangle-fan vertex will be the first vertex in every triangle
|
2013-03-02 15:58:13 +00:00
|
|
|
* XXX The proper function of TRIANGLE_FANS is not tested!!!
|
|
|
|
* XXX In particular the handling of the normal_indices looks very wrong to me */
|
|
|
|
if (collada_meshtype == COLLADAFW::MeshPrimitive::TRIANGLE_FANS) {
|
2020-02-08 01:02:18 +11:00
|
|
|
unsigned int grouped_vertex_count = mp->getGroupedVertexElementsCount();
|
2012-03-28 05:03:24 +00:00
|
|
|
for (unsigned int group_index = 0; group_index < grouped_vertex_count; group_index++) {
|
2013-03-02 15:58:13 +00:00
|
|
|
unsigned int first_vertex = position_indices[0]; /* Store first trifan vertex */
|
|
|
|
unsigned int first_normal = normal_indices[0]; /* Store first trifan vertex normal */
|
2011-03-08 13:26:41 +00:00
|
|
|
unsigned int vertex_count = mp->getGroupedVerticesVertexCount(group_index);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-28 05:03:24 +00:00
|
|
|
for (unsigned int vertex_index = 0; vertex_index < vertex_count - 2; vertex_index++) {
|
2018-09-24 17:27:41 +02:00
|
|
|
/* For each triangle store indices of its 3 vertices */
|
2013-03-02 15:58:13 +00:00
|
|
|
unsigned int triangle_vertex_indices[3] = {
|
|
|
|
first_vertex, position_indices[1], position_indices[2]};
|
|
|
|
set_poly_indices(mpoly, mloop, loop_index, triangle_vertex_indices, 3);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-08-01 13:53:25 +10:00
|
|
|
if (mp_has_normals) { /* vertex normals, same implementation as for the triangles */
|
2011-03-08 13:26:41 +00:00
|
|
|
/* the same for vertces normals */
|
2013-03-02 15:58:13 +00:00
|
|
|
unsigned int vertex_normal_indices[3] = {
|
|
|
|
first_normal, normal_indices[1], normal_indices[2]};
|
2019-05-31 22:51:19 +10:00
|
|
|
if (!is_flat_face(vertex_normal_indices, nor, 3)) {
|
2013-03-02 15:58:13 +00:00
|
|
|
mpoly->flag |= ME_SMOOTH;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2013-03-02 15:58:13 +00:00
|
|
|
normal_indices++;
|
2011-03-08 13:26:41 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-02 15:58:13 +00:00
|
|
|
mpoly++;
|
|
|
|
mloop += 3;
|
|
|
|
loop_index += 3;
|
|
|
|
prim.totpoly++;
|
2012-06-12 22:05:33 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-03-08 13:26:41 +00:00
|
|
|
/* Moving cursor to the next triangle fan. */
|
2019-05-31 22:51:19 +10:00
|
|
|
if (mp_has_normals) {
|
2013-03-02 15:58:13 +00:00
|
|
|
normal_indices += 2;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-02 15:58:13 +00:00
|
|
|
position_indices += 2;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2011-03-08 13:26:41 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-02 15:58:13 +00:00
|
|
|
if (collada_meshtype == COLLADAFW::MeshPrimitive::POLYLIST ||
|
2018-04-16 17:08:27 +02:00
|
|
|
collada_meshtype == COLLADAFW::MeshPrimitive::POLYGONS ||
|
|
|
|
collada_meshtype == COLLADAFW::MeshPrimitive::TRIANGLES) {
|
2013-03-02 15:58:13 +00:00
|
|
|
COLLADAFW::Polygons *mpvc = (COLLADAFW::Polygons *)mp;
|
2013-04-18 21:40:06 +00:00
|
|
|
unsigned int start_index = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-05-01 14:52:10 +02:00
|
|
|
COLLADAFW::IndexListArray &index_list_array_uvcoord = mp->getUVCoordIndicesArray();
|
|
|
|
COLLADAFW::IndexListArray &index_list_array_vcolor = mp->getColorIndicesArray();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-06-03 18:22:56 +02:00
|
|
|
int invalid_loop_holes = 0;
|
2013-03-02 15:58:13 +00:00
|
|
|
for (unsigned int j = 0; j < prim_totpoly; j++) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-02 15:58:13 +00:00
|
|
|
/* Vertices in polygon: */
|
|
|
|
int vcount = get_vertex_count(mpvc, j);
|
2016-05-12 17:55:41 +02:00
|
|
|
if (vcount < 0) {
|
|
|
|
continue; /* TODO: add support for holes */
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-06-03 18:22:56 +02:00
|
|
|
bool broken_loop = set_poly_indices(mpoly, mloop, loop_index, position_indices, vcount);
|
|
|
|
if (broken_loop) {
|
|
|
|
invalid_loop_holes += 1;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-05-01 14:52:10 +02:00
|
|
|
for (unsigned int uvset_index = 0; uvset_index < index_list_array_uvcoord.getCount();
|
|
|
|
uvset_index++) {
|
2013-03-02 15:58:13 +00:00
|
|
|
/* get mtface by face index and uv set index */
|
2014-05-01 14:52:10 +02:00
|
|
|
COLLADAFW::IndexList &index_list = *index_list_array_uvcoord[uvset_index];
|
2014-02-08 13:14:58 +01:00
|
|
|
MLoopUV *mloopuv = (MLoopUV *)CustomData_get_layer_named(
|
|
|
|
&me->ldata, CD_MLOOPUV, index_list.getName().c_str());
|
2020-11-06 17:49:09 +01:00
|
|
|
if (mloopuv == nullptr) {
|
2014-05-01 14:52:10 +02:00
|
|
|
fprintf(stderr,
|
|
|
|
"Collada import: Mesh [%s] : Unknown reference to TEXCOORD [#%s].\n",
|
|
|
|
me->id.name,
|
|
|
|
index_list.getName().c_str());
|
2014-02-08 13:14:58 +01:00
|
|
|
}
|
|
|
|
else {
|
2014-05-01 14:52:10 +02:00
|
|
|
set_face_uv(mloopuv + loop_index,
|
|
|
|
uvs,
|
|
|
|
start_index,
|
|
|
|
*index_list_array_uvcoord[uvset_index],
|
|
|
|
vcount);
|
2014-02-08 13:14:58 +01:00
|
|
|
}
|
2013-03-02 15:58:13 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-02 15:58:13 +00:00
|
|
|
if (mp_has_normals) {
|
2019-05-31 22:51:19 +10:00
|
|
|
if (!is_flat_face(normal_indices, nor, vcount)) {
|
2013-03-02 15:58:13 +00:00
|
|
|
mpoly->flag |= ME_SMOOTH;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2010-10-05 00:05:14 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-02-27 21:56:14 +01:00
|
|
|
if (mp->hasColorIndices()) {
|
|
|
|
int vcolor_count = index_list_array_vcolor.getCount();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-02-27 21:56:14 +01:00
|
|
|
for (unsigned int vcolor_index = 0; vcolor_index < vcolor_count; vcolor_index++) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-02-27 21:56:14 +01:00
|
|
|
COLLADAFW::IndexList &color_index_list = *mp->getColorIndices(vcolor_index);
|
|
|
|
COLLADAFW::String colname = extract_vcolname(color_index_list.getName());
|
|
|
|
MLoopCol *mloopcol = (MLoopCol *)CustomData_get_layer_named(
|
|
|
|
&me->ldata, CD_MLOOPCOL, colname.c_str());
|
2020-11-06 17:49:09 +01:00
|
|
|
if (mloopcol == nullptr) {
|
2015-02-27 21:56:14 +01:00
|
|
|
fprintf(stderr,
|
|
|
|
"Collada import: Mesh [%s] : Unknown reference to VCOLOR [#%s].\n",
|
|
|
|
me->id.name,
|
|
|
|
color_index_list.getName().c_str());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
set_vcol(mloopcol + loop_index, vcol, start_index, color_index_list, vcount);
|
2014-05-01 14:52:10 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-02 15:58:13 +00:00
|
|
|
mpoly++;
|
2014-05-01 14:52:10 +02:00
|
|
|
mloop += vcount;
|
|
|
|
loop_index += vcount;
|
2013-04-18 21:40:06 +00:00
|
|
|
start_index += vcount;
|
2013-03-02 15:58:13 +00:00
|
|
|
prim.totpoly++;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-05-31 22:51:19 +10:00
|
|
|
if (mp_has_normals) {
|
2013-03-02 15:58:13 +00:00
|
|
|
normal_indices += vcount;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-02 15:58:13 +00:00
|
|
|
position_indices += vcount;
|
2010-10-05 00:05:14 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-06-03 18:22:56 +02:00
|
|
|
if (invalid_loop_holes > 0) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"Collada import: Mesh [%s] : contains %d unsupported loops (holes).\n",
|
|
|
|
me->id.name,
|
|
|
|
invalid_loop_holes);
|
2010-10-05 00:05:14 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
2013-03-02 15:58:13 +00:00
|
|
|
else if (collada_meshtype == COLLADAFW::MeshPrimitive::LINES) {
|
2012-05-16 11:21:03 +00:00
|
|
|
continue; /* read the lines later after all the rest is done */
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-05-31 22:51:19 +10:00
|
|
|
if (mp_has_faces) {
|
2012-05-16 11:21:03 +00:00
|
|
|
mat_prim_map[mp->getMaterialId()].push_back(prim);
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2010-10-05 00:05:14 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-02 15:58:13 +00:00
|
|
|
geom_uid_mat_mapping_map[collada_mesh->getUniqueId()] = mat_prim_map;
|
2010-10-05 00:05:14 +00:00
|
|
|
}
|
|
|
|
|
2011-01-27 19:39:06 +00:00
|
|
|
void MeshImporter::get_vector(float v[3], COLLADAFW::MeshVertexData &arr, int i, int stride)
|
2010-10-05 00:05:14 +00:00
|
|
|
{
|
2011-01-27 19:39:06 +00:00
|
|
|
i *= stride;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-04-28 06:31:57 +00:00
|
|
|
switch (arr.getType()) {
|
2012-06-12 22:05:33 +00:00
|
|
|
case COLLADAFW::MeshVertexData::DATA_TYPE_FLOAT: {
|
|
|
|
COLLADAFW::ArrayPrimitiveType<float> *values = arr.getFloatValues();
|
2019-05-31 22:51:19 +10:00
|
|
|
if (values->empty()) {
|
2010-10-05 00:05:14 +00:00
|
|
|
return;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
v[0] = (*values)[i++];
|
|
|
|
v[1] = (*values)[i++];
|
2013-09-21 10:46:58 +00:00
|
|
|
if (stride >= 3) {
|
2013-09-19 21:59:22 +00:00
|
|
|
v[2] = (*values)[i];
|
2013-09-21 10:46:58 +00:00
|
|
|
}
|
|
|
|
else {
|
2013-09-19 21:59:22 +00:00
|
|
|
v[2] = 0.0f;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
} break;
|
2012-06-12 22:05:33 +00:00
|
|
|
case COLLADAFW::MeshVertexData::DATA_TYPE_DOUBLE: {
|
|
|
|
COLLADAFW::ArrayPrimitiveType<double> *values = arr.getDoubleValues();
|
2019-05-31 22:51:19 +10:00
|
|
|
if (values->empty()) {
|
2010-10-05 00:05:14 +00:00
|
|
|
return;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
v[0] = (float)(*values)[i++];
|
|
|
|
v[1] = (float)(*values)[i++];
|
2013-09-21 10:46:58 +00:00
|
|
|
if (stride >= 3) {
|
2013-09-19 21:59:22 +00:00
|
|
|
v[2] = (float)(*values)[i];
|
2013-09-21 10:46:58 +00:00
|
|
|
}
|
|
|
|
else {
|
2013-09-19 21:59:22 +00:00
|
|
|
v[2] = 0.0f;
|
2010-10-05 00:05:14 +00:00
|
|
|
}
|
|
|
|
} break;
|
2012-06-12 22:05:33 +00:00
|
|
|
default:
|
|
|
|
break;
|
2010-10-05 00:05:14 +00:00
|
|
|
}
|
|
|
|
}
|
2013-09-19 21:59:22 +00:00
|
|
|
|
2013-03-02 15:58:13 +00:00
|
|
|
bool MeshImporter::is_flat_face(unsigned int *nind, COLLADAFW::MeshVertexData &nor, int count)
|
2010-10-05 00:05:14 +00:00
|
|
|
{
|
|
|
|
float a[3], b[3];
|
|
|
|
|
2011-01-27 19:39:06 +00:00
|
|
|
get_vector(a, nor, *nind, 3);
|
2010-10-05 00:05:14 +00:00
|
|
|
normalize_v3(a);
|
|
|
|
|
|
|
|
nind++;
|
|
|
|
|
|
|
|
for (int i = 1; i < count; i++, nind++) {
|
2011-01-27 19:39:06 +00:00
|
|
|
get_vector(b, nor, *nind, 3);
|
2010-10-05 00:05:14 +00:00
|
|
|
normalize_v3(b);
|
|
|
|
|
|
|
|
float dp = dot_v3v3(a, b);
|
|
|
|
|
2019-05-31 22:51:19 +10:00
|
|
|
if (dp < 0.99999f || dp > 1.00001f) {
|
2010-10-05 00:05:14 +00:00
|
|
|
return false;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2010-10-05 00:05:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Object *MeshImporter::get_object_by_geom_uid(const COLLADAFW::UniqueId &geom_uid)
|
|
|
|
{
|
2019-05-31 22:51:19 +10:00
|
|
|
if (uid_object_map.find(geom_uid) != uid_object_map.end()) {
|
2010-10-05 00:05:14 +00:00
|
|
|
return uid_object_map[geom_uid];
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2020-11-06 17:49:09 +01:00
|
|
|
return nullptr;
|
2010-10-05 00:05:14 +00:00
|
|
|
}
|
|
|
|
|
2020-09-04 20:59:13 +02:00
|
|
|
Mesh *MeshImporter::get_mesh_by_geom_uid(const COLLADAFW::UniqueId &geom_uid)
|
2013-01-21 13:45:49 +00:00
|
|
|
{
|
2020-09-04 20:59:13 +02:00
|
|
|
if (uid_mesh_map.find(geom_uid) != uid_mesh_map.end()) {
|
|
|
|
return uid_mesh_map[geom_uid];
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2020-11-06 17:49:09 +01:00
|
|
|
return nullptr;
|
2013-01-21 13:45:49 +00:00
|
|
|
}
|
|
|
|
|
2013-02-12 17:52:18 +00:00
|
|
|
std::string *MeshImporter::get_geometry_name(const std::string &mesh_name)
|
|
|
|
{
|
2019-05-31 22:51:19 +10:00
|
|
|
if (this->mesh_geom_map.find(mesh_name) != this->mesh_geom_map.end()) {
|
2013-02-12 17:52:18 +00:00
|
|
|
return &this->mesh_geom_map[mesh_name];
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2020-11-06 17:49:09 +01:00
|
|
|
return nullptr;
|
2013-02-12 17:52:18 +00:00
|
|
|
}
|
|
|
|
|
2012-08-12 17:13:07 +00:00
|
|
|
/**
|
|
|
|
* this function checks if both objects have the same
|
|
|
|
* materials assigned to Object (in the same order)
|
|
|
|
* returns true if condition matches, otherwise false;
|
2019-03-19 15:17:46 +11:00
|
|
|
*/
|
2012-08-12 17:13:07 +00:00
|
|
|
static bool bc_has_same_material_configuration(Object *ob1, Object *ob2)
|
|
|
|
{
|
2019-05-31 22:51:19 +10:00
|
|
|
if (ob1->totcol != ob2->totcol) {
|
2012-08-12 17:13:07 +00:00
|
|
|
return false; /* not same number of materials */
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
|
|
|
if (ob1->totcol == 0) {
|
2012-08-12 17:13:07 +00:00
|
|
|
return false; /* no material at all */
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-10-21 07:58:38 +00:00
|
|
|
for (int index = 0; index < ob1->totcol; index++) {
|
2019-05-31 22:51:19 +10:00
|
|
|
if (ob1->matbits[index] != ob2->matbits[index]) {
|
2012-08-12 17:13:07 +00:00
|
|
|
return false; /* shouldn't happen */
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
|
|
|
if (ob1->matbits[index] == 0) {
|
2012-08-12 17:13:07 +00:00
|
|
|
return false; /* shouldn't happen */
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
|
|
|
if (ob1->mat[index] != ob2->mat[index]) {
|
2012-08-12 17:13:07 +00:00
|
|
|
return false; /* different material assignment */
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2012-08-12 17:13:07 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
2018-09-24 17:27:41 +02:00
|
|
|
* Caution here: This code assumes that all materials are assigned to Object
|
2012-08-12 17:13:07 +00:00
|
|
|
* and no material is assigned to Data.
|
|
|
|
* That is true right after the objects have been imported.
|
|
|
|
*
|
2019-03-19 15:17:46 +11:00
|
|
|
*/
|
2012-08-12 17:13:07 +00:00
|
|
|
static void bc_copy_materials_to_data(Object *ob, Mesh *me)
|
|
|
|
{
|
|
|
|
for (int index = 0; index < ob->totcol; index++) {
|
|
|
|
ob->matbits[index] = 0;
|
|
|
|
me->mat[index] = ob->mat[index];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Remove all references to materials from the object
|
|
|
|
*
|
2019-03-19 15:17:46 +11:00
|
|
|
*/
|
2012-08-12 17:13:07 +00:00
|
|
|
static void bc_remove_materials_from_object(Object *ob, Mesh *me)
|
|
|
|
{
|
|
|
|
for (int index = 0; index < ob->totcol; index++) {
|
|
|
|
ob->matbits[index] = 0;
|
2020-11-06 17:49:09 +01:00
|
|
|
ob->mat[index] = nullptr;
|
2012-08-12 17:13:07 +00: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.
|
2019-03-19 15:17:46 +11:00
|
|
|
*/
|
2012-08-12 17:13:07 +00:00
|
|
|
std::vector<Object *> MeshImporter::get_all_users_of(Mesh *reference_mesh)
|
|
|
|
{
|
|
|
|
std::vector<Object *> mesh_users;
|
2020-12-07 12:21:11 +01:00
|
|
|
for (Object *ob : imported_objects) {
|
2012-08-12 17:13:07 +00:00
|
|
|
if (bc_is_marked(ob)) {
|
|
|
|
bc_remove_mark(ob);
|
|
|
|
Mesh *me = (Mesh *)ob->data;
|
2019-05-31 22:51:19 +10:00
|
|
|
if (me == reference_mesh) {
|
2012-08-12 17:13:07 +00:00
|
|
|
mesh_users.push_back(ob);
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2012-08-12 17:13:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return mesh_users;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* During import all materials have been assigned to Object.
|
|
|
|
* Now we iterate over the imported objects and optimize
|
2013-09-05 19:56:49 +00:00
|
|
|
* the assignments as follows:
|
2012-08-12 17:13:07 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2019-03-19 15:17:46 +11:00
|
|
|
*/
|
2013-01-21 13:45:49 +00:00
|
|
|
void MeshImporter::optimize_material_assignements()
|
2012-08-12 17:13:07 +00:00
|
|
|
{
|
2020-12-07 12:21:11 +01:00
|
|
|
for (Object *ob : imported_objects) {
|
2012-08-12 17:13:07 +00:00
|
|
|
Mesh *me = (Mesh *)ob->data;
|
2020-01-20 13:24:31 +01:00
|
|
|
if (ID_REAL_USERS(&me->id) == 1) {
|
2012-12-29 01:54:58 +00:00
|
|
|
bc_copy_materials_to_data(ob, me);
|
|
|
|
bc_remove_materials_from_object(ob, me);
|
2012-08-12 17:13:07 +00:00
|
|
|
bc_remove_mark(ob);
|
|
|
|
}
|
2020-01-20 13:24:31 +01:00
|
|
|
else if (ID_REAL_USERS(&me->id) > 1) {
|
2012-08-12 17:13:07 +00:00
|
|
|
bool can_move = true;
|
|
|
|
std::vector<Object *> mesh_users = get_all_users_of(me);
|
|
|
|
if (mesh_users.size() > 1) {
|
|
|
|
Object *ref_ob = mesh_users[0];
|
|
|
|
for (int index = 1; index < mesh_users.size(); index++) {
|
|
|
|
if (!bc_has_same_material_configuration(ref_ob, mesh_users[index])) {
|
|
|
|
can_move = false;
|
|
|
|
break;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2012-08-12 17:13:07 +00:00
|
|
|
}
|
|
|
|
if (can_move) {
|
2012-12-29 01:54:58 +00:00
|
|
|
bc_copy_materials_to_data(ref_ob, me);
|
2020-12-07 12:21:11 +01:00
|
|
|
for (Object *object : mesh_users) {
|
2012-12-29 01:54:58 +00:00
|
|
|
bc_remove_materials_from_object(object, me);
|
2012-08-12 17:13:07 +00:00
|
|
|
bc_remove_mark(object);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
2013-01-21 13:45:49 +00:00
|
|
|
* optimize_material_assignements() above.
|
2012-08-12 17:13:07 +00:00
|
|
|
*/
|
2017-05-24 23:14:32 +10:00
|
|
|
void MeshImporter::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)
|
2010-10-05 00:05:14 +00:00
|
|
|
{
|
|
|
|
const COLLADAFW::UniqueId &ma_uid = cmaterial.getReferencedMaterial();
|
2018-06-08 08:07:48 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
/* do we know this material? */
|
|
|
|
if (uid_material_map.find(ma_uid) == uid_material_map.end()) {
|
2018-06-08 08:07:48 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
fprintf(stderr, "Cannot find material by UID.\n");
|
2017-05-24 20:13:45 +02:00
|
|
|
return;
|
2010-10-05 00:05:14 +00:00
|
|
|
}
|
2012-08-12 17:13:07 +00:00
|
|
|
|
2011-03-09 01:13:28 +00:00
|
|
|
/* first time we get geom_uid, ma_uid pair. Save for later check. */
|
|
|
|
materials_mapped_to_geom.insert(
|
|
|
|
std::pair<COLLADAFW::UniqueId, COLLADAFW::UniqueId>(*geom_uid, ma_uid));
|
2018-06-08 08:07:48 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
Material *ma = uid_material_map[ma_uid];
|
2012-08-12 17:13:07 +00:00
|
|
|
|
2018-09-24 17:27:41 +02:00
|
|
|
/* Attention! This temporarily assigns material to object on purpose!
|
2012-08-12 17:13:07 +00:00
|
|
|
* See note above. */
|
|
|
|
ob->actcol = 0;
|
2020-02-05 11:23:58 +01:00
|
|
|
BKE_object_material_assign(m_bmain, ob, ma, mat_index + 1, BKE_MAT_ASSIGN_OBJECT);
|
2018-06-08 08:07:48 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
MaterialIdPrimitiveArrayMap &mat_prim_map = geom_uid_mat_mapping_map[*geom_uid];
|
|
|
|
COLLADAFW::MaterialId mat_id = cmaterial.getMaterialId();
|
2018-06-08 08:07:48 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
/* assign material indices to mesh faces */
|
|
|
|
if (mat_prim_map.find(mat_id) != mat_prim_map.end()) {
|
2018-06-08 08:07:48 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
std::vector<Primitive> &prims = mat_prim_map[mat_id];
|
2018-06-08 08:07:48 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
std::vector<Primitive>::iterator it;
|
2018-06-08 08:07:48 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
for (it = prims.begin(); it != prims.end(); it++) {
|
|
|
|
Primitive &prim = *it;
|
2013-03-02 15:58:13 +00:00
|
|
|
MPoly *mpoly = prim.mpoly;
|
2012-05-03 21:32:49 +00:00
|
|
|
|
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
|
|
|
for (int i = 0; i < prim.totpoly; i++, mpoly++) {
|
2013-03-02 15:58:13 +00:00
|
|
|
mpoly->mat_nr = mat_index;
|
2010-10-05 00:05:14 +00:00
|
|
|
}
|
|
|
|
}
|
2018-06-08 08:07:48 +02:00
|
|
|
}
|
2010-10-05 00:05:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Object *MeshImporter::create_mesh_object(
|
|
|
|
COLLADAFW::Node *node,
|
|
|
|
COLLADAFW::InstanceGeometry *geom,
|
2012-06-12 22:05:33 +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
|
|
|
{
|
|
|
|
const COLLADAFW::UniqueId *geom_uid = &geom->getInstanciatedObjectId();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-09-24 17:27:41 +02:00
|
|
|
/* check if node instantiates controller or geometry */
|
2010-10-05 00:05:14 +00:00
|
|
|
if (isController) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
geom_uid = armature_importer->get_geometry_uid(*geom_uid);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
if (!geom_uid) {
|
|
|
|
fprintf(stderr, "Couldn't find a mesh UID by controller's UID.\n");
|
2020-11-06 17:49:09 +01:00
|
|
|
return nullptr;
|
2010-10-05 00:05:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
if (uid_mesh_map.find(*geom_uid) == uid_mesh_map.end()) {
|
|
|
|
/* this could happen if a mesh was not created
|
|
|
|
* (e.g. if it contains unsupported geometry) */
|
|
|
|
fprintf(stderr, "Couldn't find a mesh by UID.\n");
|
2020-11-06 17:49:09 +01:00
|
|
|
return nullptr;
|
2010-10-05 00:05:14 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2019-05-31 22:51:19 +10:00
|
|
|
if (!uid_mesh_map[*geom_uid]) {
|
2020-11-06 17:49:09 +01:00
|
|
|
return nullptr;
|
2019-05-31 22:51:19 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-05-03 21:32:49 +00:00
|
|
|
/* name Object */
|
2020-07-03 14:59:27 +02:00
|
|
|
const std::string &id = node->getName().empty() ? node->getOriginalId() : node->getName();
|
2020-11-06 17:49:09 +01:00
|
|
|
const char *name = (id.length()) ? id.c_str() : nullptr;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-05-03 21:32:49 +00:00
|
|
|
/* add object */
|
2018-06-14 15:55:51 +02:00
|
|
|
Object *ob = bc_add_object(m_bmain, scene, view_layer, OB_MESH, name);
|
2018-09-24 18:46:51 +02:00
|
|
|
bc_set_mark(ob); /* used later for material assignment optimization */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
/* store object pointer for ArmatureImporter */
|
|
|
|
uid_object_map[*geom_uid] = ob;
|
2012-08-12 17:13:07 +00:00
|
|
|
imported_objects.push_back(ob);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
/* replace ob->data freeing the old one */
|
2012-06-12 22:05:33 +00:00
|
|
|
Mesh *old_mesh = (Mesh *)ob->data;
|
2013-03-02 15:58:13 +00:00
|
|
|
Mesh *new_mesh = uid_mesh_map[*geom_uid];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-06-14 15:15:51 +02:00
|
|
|
BKE_mesh_assign_object(m_bmain, ob, new_mesh);
|
2013-05-28 14:23:07 +00:00
|
|
|
BKE_mesh_calc_normals(new_mesh);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-08-14 23:29:46 +10:00
|
|
|
/* Because BKE_mesh_assign_object would have already decreased it... */
|
|
|
|
id_us_plus(&old_mesh->id);
|
|
|
|
|
2019-01-14 21:08:22 +01:00
|
|
|
BKE_id_free_us(m_bmain, old_mesh);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
COLLADAFW::MaterialBindingArray &mat_array = geom->getMaterialBindings();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
/* loop through geom's materials */
|
2012-06-12 22:05:33 +00:00
|
|
|
for (unsigned int i = 0; i < mat_array.getCount(); i++) {
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-24 07:52:14 +00:00
|
|
|
if (mat_array[i].getReferencedMaterial().isValid()) {
|
2017-05-24 23:14:32 +10:00
|
|
|
assign_material_to_geom(mat_array[i], uid_material_map, ob, geom_uid, i);
|
2012-03-24 06:38:07 +00:00
|
|
|
}
|
|
|
|
else {
|
2011-03-08 20:41:43 +00:00
|
|
|
fprintf(stderr, "invalid referenced material for %s\n", mat_array[i].getName().c_str());
|
|
|
|
}
|
2010-10-05 00:05:14 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-01-10 20:23:40 +01:00
|
|
|
/* clean up the mesh */
|
|
|
|
BKE_mesh_validate((Mesh *)ob->data, false, false);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
return ob;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* create a mesh storing a pointer in a map so it can be retrieved later by geometry UID */
|
2012-06-12 22:05:33 +00:00
|
|
|
bool MeshImporter::write_geometry(const COLLADAFW::Geometry *geom)
|
2010-10-05 00:05:14 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
if (geom->getType() != COLLADAFW::Geometry::GEO_TYPE_MESH) {
|
|
|
|
/* TODO: report warning */
|
|
|
|
fprintf(stderr, "Mesh type %s is not supported\n", bc_geomTypeToStr(geom->getType()));
|
|
|
|
return true;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-06-12 22:05:33 +00:00
|
|
|
COLLADAFW::Mesh *mesh = (COLLADAFW::Mesh *)geom;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
if (!is_nice_mesh(mesh)) {
|
2013-02-08 00:27:35 +00:00
|
|
|
fprintf(stderr, "Ignoring mesh %s\n", bc_get_dae_name(mesh).c_str());
|
2010-10-05 00:05:14 +00:00
|
|
|
return true;
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-07-03 14:59:27 +02:00
|
|
|
const std::string &str_geom_id = mesh->getName().empty() ? mesh->getOriginalId() :
|
|
|
|
mesh->getName();
|
2018-06-14 15:15:51 +02:00
|
|
|
Mesh *me = BKE_mesh_add(m_bmain, (char *)str_geom_id.c_str());
|
2015-11-09 19:47:10 +01:00
|
|
|
id_us_min(&me->id); /* is already 1 here, but will be set later in BKE_mesh_assign_object */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
/* store the Mesh pointer to link it later with an Object
|
2013-03-02 15:58:13 +00:00
|
|
|
* mesh_geom_map needed to map mesh to its geometry name (for shape key naming) */
|
2010-10-05 00:05:14 +00:00
|
|
|
this->uid_mesh_map[mesh->getUniqueId()] = me;
|
2013-02-12 17:52:18 +00:00
|
|
|
this->mesh_geom_map[std::string(me->id.name)] = str_geom_id;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
read_vertices(mesh, me);
|
2013-03-02 15:58:13 +00:00
|
|
|
read_polys(mesh, me);
|
2019-01-10 20:23:40 +01:00
|
|
|
BKE_mesh_calc_edges(me, false, false);
|
2012-05-16 11:21:03 +00:00
|
|
|
/* read_lines() must be called after the face edges have been generated.
|
2018-09-24 17:27:41 +02:00
|
|
|
* Otherwise the loose edges will be silently deleted again. */
|
2012-05-16 11:21:03 +00:00
|
|
|
read_lines(mesh, me);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2010-10-05 00:05:14 +00:00
|
|
|
return true;
|
2010-10-06 12:04:56 +00:00
|
|
|
}
|