Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SVGLoader: Basic fill color support. #13772

Merged
merged 1 commit into from Apr 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion editor/js/Loader.js
Expand Up @@ -401,7 +401,7 @@ var Loader = function ( editor ) {
var path = paths[ i ];

var material = new THREE.MeshBasicMaterial( {
color: Math.random() * 0xffffff,
color: path.color,
depthWrite: false
} );

Expand Down
23 changes: 23 additions & 0 deletions examples/js/loaders/SVGLoader.js
Expand Up @@ -90,6 +90,8 @@ THREE.SVGLoader.prototype = {
function parsePathNode( node ) {

var path = new THREE.ShapePath();
path.color.setStyle( parseFill( node ) );

var point = new THREE.Vector2();
var control = new THREE.Vector2();

Expand Down Expand Up @@ -331,6 +333,7 @@ THREE.SVGLoader.prototype = {
var h = parseFloat( node.getAttribute( 'height' ) );

var path = new THREE.ShapePath();
path.color.setStyle( parseFill( node ) );
path.moveTo( x, y );
path.lineTo( x + w, y );
path.lineTo( x + w, y + h );
Expand All @@ -357,7 +360,10 @@ THREE.SVGLoader.prototype = {
}

var regex = /(-?[\d\.?]+)[,|\s](-?[\d\.?]+)/g;

var path = new THREE.ShapePath();
path.color.setStyle( parseFill( node ) );

var index = 0;

node.getAttribute( 'points' ).replace(regex, iterator);
Expand Down Expand Up @@ -386,7 +392,10 @@ THREE.SVGLoader.prototype = {
}

var regex = /(-?[\d\.?]+)[,|\s](-?[\d\.?]+)/g;

var path = new THREE.ShapePath();
path.color.setStyle( parseFill( node ) );

var index = 0;

node.getAttribute( 'points' ).replace(regex, iterator);
Expand All @@ -407,6 +416,7 @@ THREE.SVGLoader.prototype = {
subpath.absarc( x, y, r, 0, Math.PI * 2 );

var path = new THREE.ShapePath();
path.color.setStyle( parseFill( node ) );
path.subPaths.push( subpath );

return path;
Expand All @@ -424,6 +434,7 @@ THREE.SVGLoader.prototype = {
subpath.absellipse( x, y, rx, ry, 0, Math.PI * 2 );

var path = new THREE.ShapePath();
path.color.setStyle( parseFill( node ) );
path.subPaths.push( subpath );

return path;
Expand All @@ -446,6 +457,18 @@ THREE.SVGLoader.prototype = {

}

function parseFill( node ) {

if ( node.hasAttribute( 'fill' ) ) {

return node.getAttribute( 'fill' );

}

return '#ffffff';

}

// http://www.w3.org/TR/SVG11/implnote.html#PathElementImplementationNotes

function getReflection( a, b ) {
Expand Down
2 changes: 1 addition & 1 deletion examples/webgl_interactive_draggablecubes.html
Expand Up @@ -36,7 +36,7 @@
container = document.createElement( 'div' );
document.body.appendChild( container );

camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 1, 10000 );
camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 1, 5000 );
camera.position.z = 1000;

controls = new THREE.TrackballControls( camera );
Expand Down
2 changes: 2 additions & 0 deletions src/extras/core/ShapePath.js
Expand Up @@ -11,6 +11,8 @@ function ShapePath() {

this.type = 'ShapePath';

this.color = new THREE.Color();

this.subPaths = [];
this.currentPath = null;

Expand Down