Skip to content

Commit

Permalink
Fix to parsing some Collada with extra vertex semantics referenced on…
Browse files Browse the repository at this point in the history
…ly in the vertices section.
  • Loading branch information
SaracenOne committed May 8, 2021
1 parent fbbc568 commit 10a1810
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 30 deletions.
5 changes: 5 additions & 0 deletions editor/collada/collada.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,7 @@ void Collada::_parse_mesh_geometry(XMLParser &parser, String p_id, String p_name

MeshData::Vertices vert;
String id = parser.get_attribute_value("id");
int last_ref = 0;

while (parser.read() == OK) {

Expand All @@ -1043,6 +1044,10 @@ void Collada::_parse_mesh_geometry(XMLParser &parser, String p_id, String p_name
String semantic = parser.get_attribute_value("semantic");
String source = _uri_to_id(parser.get_attribute_value("source"));

if (semantic == "TEXCOORD") {
semantic = "TEXCOORD" + itos(last_ref++);
}

vert.sources[semantic] = source;

COLLADA_PRINT(section + " input semantic: " + semantic + " source: " + source);
Expand Down
114 changes: 84 additions & 30 deletions editor/import/editor_import_collada.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -537,67 +537,121 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref<ArrayMesh> &p_me
const Collada::MeshData::Source *normal_src = NULL;
int normal_ofs = 0;

if (p.sources.has("NORMAL")) {
{
String normal_source_id = "";

if (p.sources.has("NORMAL")) {
normal_source_id = p.sources["NORMAL"].source;
normal_ofs = p.sources["NORMAL"].offset;
} else if (meshdata.vertices[vertex_src_id].sources.has("NORMAL")) {
normal_source_id = meshdata.vertices[vertex_src_id].sources["NORMAL"];
normal_ofs = vertex_ofs;
}

String normal_source_id = p.sources["NORMAL"].source;
normal_ofs = p.sources["NORMAL"].offset;
ERR_FAIL_COND_V(!meshdata.sources.has(normal_source_id), ERR_INVALID_DATA);
normal_src = &meshdata.sources[normal_source_id];
if (normal_source_id != "") {
ERR_FAIL_COND_V(!meshdata.sources.has(normal_source_id), ERR_INVALID_DATA);
normal_src = &meshdata.sources[normal_source_id];
}
}

const Collada::MeshData::Source *binormal_src = NULL;
int binormal_ofs = 0;

if (p.sources.has("TEXBINORMAL")) {
{
String binormal_source_id = "";

if (p.sources.has("TEXBINORMAL")) {
binormal_source_id = p.sources["TEXBINORMAL"].source;
binormal_ofs = p.sources["TEXBINORMAL"].offset;
} else if (meshdata.vertices[vertex_src_id].sources.has("TEXBINORMAL")) {
binormal_source_id = meshdata.vertices[vertex_src_id].sources["TEXBINORMAL"];
binormal_ofs = vertex_ofs;
}

String binormal_source_id = p.sources["TEXBINORMAL"].source;
binormal_ofs = p.sources["TEXBINORMAL"].offset;
ERR_FAIL_COND_V(!meshdata.sources.has(binormal_source_id), ERR_INVALID_DATA);
binormal_src = &meshdata.sources[binormal_source_id];
if (binormal_source_id != "") {
ERR_FAIL_COND_V(!meshdata.sources.has(binormal_source_id), ERR_INVALID_DATA);
binormal_src = &meshdata.sources[binormal_source_id];
}
}

const Collada::MeshData::Source *tangent_src = NULL;
int tangent_ofs = 0;

if (p.sources.has("TEXTANGENT")) {
{
String tangent_source_id = "";

if (p.sources.has("TEXTANGENT")) {
tangent_source_id = p.sources["TEXTANGENT"].source;
tangent_ofs = p.sources["TEXTANGENT"].offset;
} else if (meshdata.vertices[vertex_src_id].sources.has("TEXTANGENT")) {
tangent_source_id = meshdata.vertices[vertex_src_id].sources["TEXTANGENT"];
tangent_ofs = vertex_ofs;
}

String tangent_source_id = p.sources["TEXTANGENT"].source;
tangent_ofs = p.sources["TEXTANGENT"].offset;
ERR_FAIL_COND_V(!meshdata.sources.has(tangent_source_id), ERR_INVALID_DATA);
tangent_src = &meshdata.sources[tangent_source_id];
if (tangent_source_id != "") {
ERR_FAIL_COND_V(!meshdata.sources.has(tangent_source_id), ERR_INVALID_DATA);
tangent_src = &meshdata.sources[tangent_source_id];
}
}

const Collada::MeshData::Source *uv_src = NULL;
int uv_ofs = 0;

if (p.sources.has("TEXCOORD0")) {
{
String uv_source_id = "";

if (p.sources.has("TEXCOORD0")) {
uv_source_id = p.sources["TEXCOORD0"].source;
uv_ofs = p.sources["TEXCOORD0"].offset;
} else if (meshdata.vertices[vertex_src_id].sources.has("TEXCOORD0")) {
uv_source_id = meshdata.vertices[vertex_src_id].sources["TEXCOORD0"];
uv_ofs = vertex_ofs;
}

String uv_source_id = p.sources["TEXCOORD0"].source;
uv_ofs = p.sources["TEXCOORD0"].offset;
ERR_FAIL_COND_V(!meshdata.sources.has(uv_source_id), ERR_INVALID_DATA);
uv_src = &meshdata.sources[uv_source_id];
if (uv_source_id != "") {
ERR_FAIL_COND_V(!meshdata.sources.has(uv_source_id), ERR_INVALID_DATA);
uv_src = &meshdata.sources[uv_source_id];
}
}

const Collada::MeshData::Source *uv2_src = NULL;
int uv2_ofs = 0;

if (p.sources.has("TEXCOORD1")) {
{
String uv2_source_id = "";

if (p.sources.has("TEXCOORD1")) {
uv2_source_id = p.sources["TEXCOORD1"].source;
uv2_ofs = p.sources["TEXCOORD1"].offset;
} else if (meshdata.vertices[vertex_src_id].sources.has("TEXCOORD1")) {
uv2_source_id = meshdata.vertices[vertex_src_id].sources["TEXCOORD1"];
uv2_ofs = vertex_ofs;
}

String uv2_source_id = p.sources["TEXCOORD1"].source;
uv2_ofs = p.sources["TEXCOORD1"].offset;
ERR_FAIL_COND_V(!meshdata.sources.has(uv2_source_id), ERR_INVALID_DATA);
uv2_src = &meshdata.sources[uv2_source_id];
if (uv2_source_id != "") {
ERR_FAIL_COND_V(!meshdata.sources.has(uv2_source_id), ERR_INVALID_DATA);
uv2_src = &meshdata.sources[uv2_source_id];
}
}

const Collada::MeshData::Source *color_src = NULL;
int color_ofs = 0;

if (p.sources.has("COLOR")) {
{
String color_source_id = "";

if (p.sources.has("COLOR")) {
color_source_id = p.sources["COLOR"].source;
color_ofs = p.sources["COLOR"].offset;
} else if (meshdata.vertices[vertex_src_id].sources.has("COLOR")) {
color_source_id = meshdata.vertices[vertex_src_id].sources["COLOR"];
color_ofs = vertex_ofs;
}

String color_source_id = p.sources["COLOR"].source;
color_ofs = p.sources["COLOR"].offset;
ERR_FAIL_COND_V(!meshdata.sources.has(color_source_id), ERR_INVALID_DATA);
color_src = &meshdata.sources[color_source_id];
if (color_source_id != "") {
ERR_FAIL_COND_V(!meshdata.sources.has(color_source_id), ERR_INVALID_DATA);
color_src = &meshdata.sources[color_source_id];
}
}

//find largest source..
Expand Down

0 comments on commit 10a1810

Please sign in to comment.