Skip to content

Instantly share code, notes, and snippets.

@zhanghai
Created February 19, 2018 10:19
Show Gist options
  • Save zhanghai/415f4ba49b8c858c439f99a8a2e8aa71 to your computer and use it in GitHub Desktop.
Save zhanghai/415f4ba49b8c858c439f99a8a2e8aa71 to your computer and use it in GitHub Desktop.
Patch proj2_meshedit COLLADA parser to support parsing <triangles>
From ab1517d7e99a7dbe83bc1af335a23060e9ed4015 Mon Sep 17 00:00:00 2001
From: Zhang Hai <dreaming.in.code.zh@gmail.com>
Date: Sun, 18 Feb 2018 22:18:45 -0800
Subject: [PATCH] Support parsing COLLADA <triangles>.
---
src/collada.cpp | 38 +++++++++++++++++++++++++-------------
1 file changed, 25 insertions(+), 13 deletions(-)
diff --git a/src/collada.cpp b/src/collada.cpp
index db87115..73451cc 100644
--- a/src/collada.cpp
+++ b/src/collada.cpp
@@ -545,6 +545,11 @@ namespace CGL {
// polylist
XMLElement* e_polylist = e_mesh->FirstChildElement( "polylist" );
+ bool is_triangles = false;
+ if ( !e_polylist ) {
+ e_polylist = e_mesh->FirstChildElement( "triangles" );
+ is_triangles = true;
+ }
if ( e_polylist ) {
// material
@@ -639,22 +644,29 @@ namespace CGL {
// create polygon size array and compute size of index array
vector<size_t> sizes; size_t num_indices = 0;
- XMLElement* e_vcount = e_polylist->FirstChildElement( "vcount" );
- if ( e_vcount ) {
-
- size_t size;
- string s = e_vcount->GetText();
- stringstream ss (s);
+ if ( !is_triangles ) {
+ XMLElement *e_vcount = e_polylist->FirstChildElement("vcount");
+ if ( e_vcount ) {
+
+ size_t size;
+ string s = e_vcount->GetText();
+ stringstream ss(s);
+
+ for (size_t i = 0; i < num_polygons; ++i) {
+ ss >> size;
+ sizes.push_back(size);
+ num_indices += size * stride;
+ }
- for (size_t i = 0; i < num_polygons; ++i) {
- ss >> size;
- sizes.push_back(size);
- num_indices += size * stride;
+ } else {
+ stat("Error: polygon sizes undefined in geometry: " << polymesh.id);
+ exit(-1);
}
-
} else {
- stat("Error: polygon sizes undefined in geometry: " << polymesh.id);
- exit( -1 );
+ for (size_t i = 0; i < num_polygons; ++i) {
+ sizes.push_back(3);
+ num_indices += 3 * stride;
+ }
}
// index array
--
2.16.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment