未验证 提交 987c182a 编写于 作者: M Mr.doob 提交者: GitHub

Merge pull request #16452 from gkjohnson/collada-loader-parse-errors

ColladaLoader: Report xml parse errors
...@@ -3814,6 +3814,32 @@ THREE.ColladaLoader.prototype = { ...@@ -3814,6 +3814,32 @@ THREE.ColladaLoader.prototype = {
} }
// convert the parser error element into text with each child elements text
// separated by new lines.
function parserErrorToText( parserError ) {
var result = '';
var stack = [ parserError ];
while ( stack.length ) {
var node = stack.shift();
if ( node.nodeType === Node.TEXT_NODE ) {
result += node.textContent;
} else {
result += '\n';
stack.push.apply( stack, node.childNodes );
}
}
return result.trim();
}
if ( text.length === 0 ) { if ( text.length === 0 ) {
return { scene: new THREE.Scene() }; return { scene: new THREE.Scene() };
...@@ -3824,6 +3850,28 @@ THREE.ColladaLoader.prototype = { ...@@ -3824,6 +3850,28 @@ THREE.ColladaLoader.prototype = {
var collada = getElementsByTagName( xml, 'COLLADA' )[ 0 ]; var collada = getElementsByTagName( xml, 'COLLADA' )[ 0 ];
var parserError = xml.getElementsByTagName( 'parsererror' )[ 0 ];
if ( parserError !== undefined ) {
// Chrome will return parser error with a div in it
var errorElement = getElementsByTagName( parserError, 'div' )[ 0 ];
var errorText;
if ( errorElement ) {
errorText = errorElement.textContent;
} else {
errorText = parserErrorToText( parserError );
}
console.error( 'ColladaLoader: Failed to parse collada file.\n', errorText );
return null;
}
// metadata // metadata
var version = collada.getAttribute( 'version' ); var version = collada.getAttribute( 'version' );
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册