Browse Source

added geometry color merge + fix merge when PInts

Nicolas Cannasse 11 years ago
parent
commit
175ed6719f
2 changed files with 17 additions and 1 deletions
  1. 3 0
      hxd/fmt/fbx/Data.hx
  2. 14 1
      hxd/fmt/fbx/Geometry.hx

+ 3 - 0
hxd/fmt/fbx/Data.hx

@@ -74,6 +74,9 @@ class FbxTools {
 			var fl = new Array<Float>();
 			for( x in i )
 				fl.push(x);
+			n.props[0] = PFloats(fl); // keep data synchronized
+			// this is necessary for merging geometries since we are pushing directly into the
+			// float buffer
 			return fl;
 		default:
 			throw n.name + " has " + n.props + " props";

+ 14 - 1
hxd/fmt/fbx/Geometry.hx

@@ -86,7 +86,7 @@ class Geometry {
 		for( n in g.getNormals() )
 			normals.push(n);
 
-		// merget uvs
+		// merge uvs
 		var uv = getUVs();
 		var uv2 = g.getUVs();
 		if( uv.length != uv2.length )
@@ -101,6 +101,19 @@ class Geometry {
 				uv.index.push(i + count);
 		}
 
+		// merge colors
+		var colors = getColors();
+		var colors2 = g.getColors();
+		if( (colors != null) != (colors2 != null) )
+			throw "Different Color layer in merged objects";
+		if( colors != null ) {
+			var count = colors.values.length >> 2;
+			for( v in colors2.values )
+				colors.values.push(v);
+			for( i in colors2.index )
+				colors.index.push(i + count);
+		}
+
 		// merge materials
 		var m2 = g.getMaterials();
 		if( m2 == null ) {