Преглед на файлове

fbx parser creates a Root + some minor changes

Nicolas Cannasse преди 12 години
родител
ревизия
19a65c61de
променени са 4 файла, в които са добавени 59 реда и са изтрити 35 реда
  1. 46 0
      h3d/fbx/Filter.hx
  2. 7 15
      h3d/fbx/Library.hx
  3. 6 2
      h3d/fbx/Parser.hx
  4. 0 18
      h3d/fbx/XBXBuild.hx

+ 46 - 0
h3d/fbx/Filter.hx

@@ -0,0 +1,46 @@
+package h3d.fbx;
+import h3d.fbx.Data;
+
+class Filter {
+	
+	var ignoreList : Array<Array<String>>;
+	
+	public function new() {
+		ignoreList = [];
+	}
+	
+	public function ignore( path : String ) {
+		ignoreList.push(path.split("."));
+	}
+	
+	public function filter( f : FbxNode ) : FbxNode {
+		var f2 = filterRec(f, ignoreList, 0);
+		// TODO : rebuild connections !
+		return f2;
+	}
+	
+	function filterRec( f : FbxNode, match : Array<Array<String>>, index : Int ) {
+		var sub = [];
+		for( m in match )
+			if( m[index] == f.name ) {
+				if( m.length == index + 1 )
+					return null;
+				sub.push(m);
+			}
+		if( sub.length == 0 )
+			return f;
+		var f2 = {
+			name : f.name,
+			props : f.props.copy(),
+			childs : [],
+		};
+		index++;
+		for( c in f.childs ) {
+			var fs = filterRec(c, sub, index);
+			if( fs != null )
+				f2.childs.push(fs);
+		}
+		return f2;
+	}
+
+}

+ 7 - 15
h3d/fbx/Library.hx

@@ -9,7 +9,7 @@ class Library {
 	var invConnect : IntHash<Array<Int>>;
 	
 	public function new() {
-		root = { name : "root", props : [], childs : [] };
+		root = { name : "Root", props : [], childs : [] };
 		reset();
 	}
 	
@@ -20,12 +20,14 @@ class Library {
 	}
 	
 	public function loadTextFile( data : String ) {
-		for( n in Parser.parse(data) )
-			init(n);
+		load(Parser.parse(data));
 	}
 	
-	public function load( x : Iterable<FbxNode> ) {
-		for ( r in x ) init( r );
+	public function load( root : FbxNode ) {
+		reset();
+		this.root = root;
+		for( c in root.childs )
+			init(c);
 	}
 	
 	function init( n : FbxNode ) {
@@ -57,9 +59,7 @@ class Library {
 		case "Objects":
 			for( c in n.childs )
 				ids.set(c.getId(), c);
-			root.childs.push(n);
 		default:
-			root.childs.push(n);
 		}
 	}
 	
@@ -105,12 +105,4 @@ class Library {
 		return root;
 	}
 	
-	public function setRoot(root) {
-		this.root = root;
-		reset();
-		var old = root.childs;
-		root.childs = [];
-		load(old);
-	}
-	
 }

+ 6 - 2
h3d/fbx/Parser.hx

@@ -24,12 +24,16 @@ class Parser {
 	function new() {
 	}
 
-	function parseText( str ) {
+	function parseText( str ) : FbxNode {
 		this.buf = str;
 		this.pos = 0;
 		this.line = 1;
 		token = null;
-		return parseNodes();
+		return {
+			name : "Root",
+			props : [],
+			childs : parseNodes(),
+		};
 	}
 
 	function parseNodes() {

+ 0 - 18
h3d/fbx/XBXBuild.hx

@@ -1,18 +0,0 @@
-package h3d.fbx;
-import Data;
-
-/**
- * ...
- * @author de
- */
-
-//for future fbx leaf cutting
-class XBXBuild
-{
-
-	public function build( b : FbxNode ) : FbxNode
-	{
-		return b;
-	}
-	
-}