diff --git a/src/loaders/SVGLoader.js b/src/loaders/SVGLoader.js index 7f1e1bac..b8879e62 100644 --- a/src/loaders/SVGLoader.js +++ b/src/loaders/SVGLoader.js @@ -13,6 +13,8 @@ import { Vector3, } from 'three' +const COLOR_SPACE_SVG = 'srgb' + class SVGLoader extends Loader { constructor(manager) { super(manager) @@ -59,12 +61,13 @@ class SVGLoader extends Loader { const transform = getNodeTransform(node) - let traverseChildNodes = true + let isDefsNode = false let path = null switch (node.nodeName) { case 'svg': + style = parseStyle(node, style) break case 'style': @@ -111,16 +114,14 @@ class SVGLoader extends Loader { break case 'defs': - traverseChildNodes = false - break - - case 'mask': - traverseChildNodes = false + isDefsNode = true break case 'use': style = parseStyle(node, style) - const usedNodeId = node.href.baseVal.substring(1) + + const href = node.getAttributeNS('http://www.w3.org/1999/xlink', 'href') || '' + const usedNodeId = href.substring(1) const usedNode = node.viewportElement.getElementById(usedNodeId) if (usedNode) { parseNode(usedNode, style) @@ -136,7 +137,7 @@ class SVGLoader extends Loader { if (path) { if (style.fill !== undefined && style.fill !== 'none') { - path.color.setStyle(style.fill) + path.color.setStyle(style.fill, COLOR_SPACE_SVG) } transformPath(path, currentTransform) @@ -146,12 +147,19 @@ class SVGLoader extends Loader { path.userData = { node: node, style: style } } - if (traverseChildNodes) { - const nodes = node.childNodes + const childNodes = node.childNodes - for (let i = 0; i < nodes.length; i++) { - parseNode(nodes[i], style) + for (let i = 0; i < childNodes.length; i++) { + const node = childNodes[i] + + if (isDefsNode && node.nodeName !== 'style' && node.nodeName !== 'defs') { + // Ignore everything in defs except CSS style definitions + // and nested defs, because it is OK by the standard to have + //