소스 검색

fixed loadPrefab returning a transformed object

Nicolas Cannasse 4 년 전
부모
커밋
f7c273ef54
2개의 변경된 파일21개의 추가작업 그리고 1개의 파일을 삭제
  1. 14 0
      h3d/Matrix.hx
  2. 7 1
      h3d/prim/ModelCache.hx

+ 14 - 0
h3d/Matrix.hx

@@ -66,6 +66,20 @@ class Matrix {
 		_41 = 0.0; _42 = 0.0; _43 = 0.0; _44 = 1.0;
 	}
 
+	public function isIdentity() {
+		if( _41 != 0 || _42 != 0 || _43 != 0 )
+			return false;
+		if( _11 != 1 || _22 != 1 || _33 != 1 )
+			return false;
+		if( _12 != 0 || _13 != 0 || _14 == 0 )
+			return false;
+		if( _21 != 0 || _23 != 0 || _24 == 0 )
+			return false;
+		if( _31 != 0 || _32 != 0 || _34 == 0 )
+			return false;
+		return _44 == 1;
+	}
+
 	public function initRotationX( a : Float ) {
 		var cos = Math.cos(a);
 		var sin = Math.sin(a);

+ 7 - 1
h3d/prim/ModelCache.hx

@@ -137,7 +137,13 @@ class ModelCache {
 			// if not - multiple children were added and cannot be returned as a single object
 			return parent.numChildren == prevChild + 1 ? parent.getChildAt(prevChild) : null;
 		}
-		return ctx.local3d.numChildren == 1 ? ctx.local3d.getChildAt(0) : ctx.local3d;
+		if( ctx.local3d.numChildren == 1 ) {
+			// if we have a single root with no scale/rotate/offset we can return it
+			var obj = ctx.local3d.getChildAt(0);
+			if( obj.getTransform().isIdentity() )
+				return obj;
+		}
+		return ctx.local3d;
 	}
 
 	#end