| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <title>SVGLoader - Three.js Docs</title>
- <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
- <script src="../scripts/highlight.min.js"></script>
- <link type="text/css" rel="stylesheet" href="../styles/highlight-three.css">
- <link type="text/css" rel="stylesheet" href="../styles/page.css">
- </head>
- <body>
- <p class="inheritance" translate="no"><a href="Loader.html">Loader</a> → </p>
- <h1 translate="no">SVGLoader</h1>
- <section>
- <header>
- <div class="class-description"><p>A loader for the SVG format.</p>
- <p>Scalable Vector Graphics is an XML-based vector image format for two-dimensional graphics
- with support for interactivity and animation.</p></div>
- <h2>Code Example</h2>
- <div translate="no"><pre><code class="language-js">const loader = new SVGLoader();
- const data = await loader.loadAsync( 'data/svgSample.svg' );
- const paths = data.paths;
- const group = new THREE.Group();
- for ( let i = 0; i < paths.length; i ++ ) {
- const path = paths[ i ];
- const material = new THREE.MeshBasicMaterial( {
- color: path.color,
- side: THREE.DoubleSide,
- depthWrite: false
- } );
- const shapes = SVGLoader.createShapes( path );
- for ( let j = 0; j < shapes.length; j ++ ) {
- const shape = shapes[ j ];
- const geometry = new THREE.ShapeGeometry( shape );
- const mesh = new THREE.Mesh( geometry, material );
- group.add( mesh );
- }
- }
- scene.add( group );
- </code></pre></div>
- </header>
- <article>
- <h2 class="subsection-title">Import</h2>
- <p><span translate="no">SVGLoader</span> is an addon, and must be imported explicitly, see <a href="https://threejs.org/manual/#en/installation" target="_blank">Installation#Addons</a>.</p>
- <pre><code class="language-js">import { SVGLoader } from 'three/addons/loaders/SVGLoader.js';</code></pre>
- <div class="container-overview">
- <h2>Constructor</h2>
- <h3 class="name name-method" id="SVGLoader" translate="no">new <a href="#SVGLoader">SVGLoader</a><span class="signature">( manager : <span class="param-type">LoadingManager</span> )</span> </h3>
- <div class="method">
- <div class="description">
- <p>Constructs a new SVG loader.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name"><code>manager</code></td>
- <td class="description last"><p>The loading manager.</p></td>
- </tr>
- </tbody>
- </table>
- </div>
- </div>
- <h2 class="subsection-title">Properties</h2>
- <div class="member">
- <h3 class="name" id="defaultDPI" translate="no">.<a href="#defaultDPI">defaultDPI</a><span class="type-signature"> : number</span> </h3>
- <div class="description">
- <p>Default dots per inch.<br/>Default is <code>90</code>.</p>
- </div>
- </div>
- <div class="member">
- <h3 class="name" id="defaultUnit" translate="no">.<a href="#defaultUnit">defaultUnit</a><span class="type-signature"> : 'mm' | 'cm' | 'in' | 'pt' | 'pc' | 'px'</span> </h3>
- <div class="description">
- <p>Default unit.<br/>Default is <code>'px'</code>.</p>
- </div>
- </div>
- <h2 class="subsection-title">Methods</h2>
- <h3 class="name name-method" id="load" translate="no">.<a href="#load">load</a><span class="signature">( url : <span class="param-type">string</span>, onLoad : <span class="param-type">function</span>, onProgress : <span class="param-type">onProgressCallback</span>, onError : <span class="param-type">onErrorCallback</span> )</span> </h3>
- <div class="method">
- <div class="description">
- <p>Starts loading from the given URL and passes the loaded SVG asset
- to the <code>onLoad()</code> callback.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name"><code>url</code></td>
- <td class="description last"><p>The path/URL of the file to be loaded. This can also be a data URI.</p></td>
- </tr>
- <tr>
- <td class="name"><code>onLoad</code></td>
- <td class="description last"><p>Executed when the loading process has been finished.</p></td>
- </tr>
- <tr>
- <td class="name"><code>onProgress</code></td>
- <td class="description last"><p>Executed while the loading is in progress.</p></td>
- </tr>
- <tr>
- <td class="name"><code>onError</code></td>
- <td class="description last"><p>Executed when errors occur.</p></td>
- </tr>
- </tbody>
- </table>
- <dl class="details">
- <dt class="tag-overrides"><strong>Overrides:</strong> <a href="Loader.html#load">Loader#load</a></dt>
- </dl>
- </div>
- <h3 class="name name-method" id="parse" translate="no">.<a href="#parse">parse</a><span class="signature">( text : <span class="param-type">string</span> )</span><span class="type-signature"> : Object</span> </h3>
- <div class="method">
- <div class="description">
- <p>Parses the given SVG data and returns the resulting data.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name"><code>text</code></td>
- <td class="description last"><p>The raw SVG data as a string.</p></td>
- </tr>
- </tbody>
- </table>
- <dl class="details">
- <dt class="tag-overrides"><strong>Overrides:</strong> <a href="Loader.html#parse">Loader#parse</a></dt>
- </dl>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> An object holding an array of shape paths and the
- SVG XML document.</dt>
- </dl>
- </div>
- <h2 class="subsection-title">Static Methods</h2>
- <h3 class="name name-method" id=".createShapes" translate="no">.<a href="#.createShapes">createShapes</a><span class="signature">( shapePath : <span class="param-type">ShapePath</span> )</span><span class="type-signature"> : Array.<<a href="Shape.html">Shape</a>></span> </h3>
- <div class="method">
- <div class="description">
- <p>Creates from the given shape path and array of shapes.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name"><code>shapePath</code></td>
- <td class="description last"><p>The shape path.</p></td>
- </tr>
- </tbody>
- </table>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> An array of shapes.</dt>
- </dl>
- </div>
- <h3 class="name name-method" id=".getStrokeStyle" translate="no">.<a href="#.getStrokeStyle">getStrokeStyle</a><span class="signature">( width : <span class="param-type">number</span>, color : <span class="param-type">string</span>, lineJoin : <span class="param-type">'round' | 'bevel' | 'miter' | 'miter-limit'</span>, lineCap : <span class="param-type">'round' | 'square' | 'butt'</span>, miterLimit : <span class="param-type">number</span> )</span><span class="type-signature"> : Object</span> </h3>
- <div class="method">
- <div class="description">
- <p>Returns a stroke style object from the given parameters.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name"><code>width</code></td>
- <td class="description last"><p>The stroke width.<br/>Default is <code>1</code>.</p></td>
- </tr>
- <tr>
- <td class="name"><code>color</code></td>
- <td class="description last"><p>The stroke color, as returned by <a href="Color.html#getStyle">Color#getStyle</a>.<br/>Default is <code>'#000'</code>.</p></td>
- </tr>
- <tr>
- <td class="name"><code>lineJoin</code></td>
- <td class="description last"><p>The line join style.<br/>Default is <code>'miter'</code>.</p></td>
- </tr>
- <tr>
- <td class="name"><code>lineCap</code></td>
- <td class="description last"><p>The line cap style.<br/>Default is <code>'butt'</code>.</p></td>
- </tr>
- <tr>
- <td class="name"><code>miterLimit</code></td>
- <td class="description last"><p>Maximum join length, in multiples of the <code>width</code> parameter (join is truncated if it exceeds that distance).<br/>Default is <code>4</code>.</p></td>
- </tr>
- </tbody>
- </table>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> The style object.</dt>
- </dl>
- </div>
- <h3 class="name name-method" id=".pointsToStroke" translate="no">.<a href="#.pointsToStroke">pointsToStroke</a><span class="signature">( points : <span class="param-type">Array.<Vector2></span>, style : <span class="param-type">Object</span>, arcDivisions : <span class="param-type">number</span>, minDistance : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="BufferGeometry.html">BufferGeometry</a></span> </h3>
- <div class="method">
- <div class="description">
- <p>Creates a stroke from an array of points.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name"><code>points</code></td>
- <td class="description last"><p>The points in 2D space. Minimum 2 points. The path can be open or closed (last point equals to first point).</p></td>
- </tr>
- <tr>
- <td class="name"><code>style</code></td>
- <td class="description last"><p>Object with SVG properties as returned by <code>SVGLoader.getStrokeStyle()</code>, or <code>SVGLoader.parse()</code> in the <code>path.userData.style</code> object.</p></td>
- </tr>
- <tr>
- <td class="name"><code>arcDivisions</code></td>
- <td class="description last"><p>Arc divisions for round joins and endcaps.<br/>Default is <code>12</code>.</p></td>
- </tr>
- <tr>
- <td class="name"><code>minDistance</code></td>
- <td class="description last"><p>Points closer to this distance will be merged.<br/>Default is <code>0.001</code>.</p></td>
- </tr>
- </tbody>
- </table>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> The stroke geometry. UV coordinates are generated ('u' along path. 'v' across it, from left to right).
- Returns <code>null</code> if not geometry was generated.</dt>
- </dl>
- </div>
- <h3 class="name name-method" id=".pointsToStrokeWithBuffers" translate="no">.<a href="#.pointsToStrokeWithBuffers">pointsToStrokeWithBuffers</a><span class="signature">( points : <span class="param-type">Array.<Vector2></span>, style : <span class="param-type">Object</span>, arcDivisions : <span class="param-type">number</span>, minDistance : <span class="param-type">number</span>, vertices : <span class="param-type">Array.<number></span>, normals : <span class="param-type">Array.<number></span>, uvs : <span class="param-type">Array.<number></span>, vertexOffset : <span class="param-type">number</span> )</span><span class="type-signature"> : number</span> </h3>
- <div class="method">
- <div class="description">
- <p>Creates a stroke from an array of points.</p>
- </div>
- <table class="params">
- <tbody>
- <tr>
- <td class="name"><code>points</code></td>
- <td class="description last"><p>The points in 2D space. Minimum 2 points.</p></td>
- </tr>
- <tr>
- <td class="name"><code>style</code></td>
- <td class="description last"><p>Object with SVG properties as returned by <code>SVGLoader.getStrokeStyle()</code>, or <code>SVGLoader.parse()</code> in the <code>path.userData.style</code> object.</p></td>
- </tr>
- <tr>
- <td class="name"><code>arcDivisions</code></td>
- <td class="description last"><p>Arc divisions for round joins and endcaps.<br/>Default is <code>12</code>.</p></td>
- </tr>
- <tr>
- <td class="name"><code>minDistance</code></td>
- <td class="description last"><p>Points closer to this distance will be merged.<br/>Default is <code>0.001</code>.</p></td>
- </tr>
- <tr>
- <td class="name"><code>vertices</code></td>
- <td class="description last"><p>An array holding vertices.</p></td>
- </tr>
- <tr>
- <td class="name"><code>normals</code></td>
- <td class="description last"><p>An array holding normals.</p></td>
- </tr>
- <tr>
- <td class="name"><code>uvs</code></td>
- <td class="description last"><p>An array holding uvs.</p></td>
- </tr>
- <tr>
- <td class="name"><code>vertexOffset</code></td>
- <td class="description last"><p>The vertex offset.<br/>Default is <code>0</code>.</p></td>
- </tr>
- </tbody>
- </table>
- <dl class="details">
- <dt class="tag-returns"><strong>Returns:</strong> The number of vertices.</dt>
- </dl>
- </div>
- <h2 class="subsection-title">Source</h2>
- <p>
- <a href="https://github.com/mrdoob/three.js/blob/master/examples/jsm/loaders/SVGLoader.js" target="_blank" rel="noopener" translate="no">examples/jsm/loaders/SVGLoader.js</a>
- </p>
- </article>
- </section>
- <script src="../scripts/linenumber.js"></script>
- <script src="../scripts/page.js"></script>
- </body>
- </html>
|