Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 39 additions & 10 deletions editor/js/Loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -704,25 +704,54 @@ function Loader( editor ) {
group.scale.multiplyScalar( 0.1 );
group.scale.y *= - 1;

let renderOrder = 0;

for ( let i = 0; i < paths.length; i ++ ) {

const path = paths[ i ];

const material = new THREE.MeshBasicMaterial( {
color: path.color,
depthWrite: false
} );
// fill

const fillMaterial = SVGLoader.createFillMaterial( path );

if ( fillMaterial ) {

const shapes = SVGLoader.createShapes( path );

const shapes = SVGLoader.createShapes( path );
for ( let j = 0; j < shapes.length; j ++ ) {

for ( let j = 0; j < shapes.length; j ++ ) {
const shape = shapes[ j ];

const shape = shapes[ j ];
const geometry = new THREE.ShapeGeometry( shape );
const mesh = new THREE.Mesh( geometry, fillMaterial );
mesh.renderOrder = renderOrder ++;

group.add( mesh );

}

}

const geometry = new THREE.ShapeGeometry( shape );
const mesh = new THREE.Mesh( geometry, material );
// stroke

group.add( mesh );
const strokeMaterial = SVGLoader.createStrokeMaterial( path );

if ( strokeMaterial ) {

for ( const subPath of path.subPaths ) {

const geometry = SVGLoader.pointsToStroke( subPath.getPoints(), path.userData.style );

if ( geometry ) {

const mesh = new THREE.Mesh( geometry, strokeMaterial );
mesh.renderOrder = renderOrder ++;

group.add( mesh );

}

}

}

Expand Down
42 changes: 42 additions & 0 deletions examples/jsm/loaders/SVGLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -2663,6 +2663,22 @@ class SVGLoader extends Loader {
outerPoint.copy( tempV2_5 ).add( currentPoint );
innerPoint.add( currentPoint );

// in-loop fold detection to mitigate #25326
if ( innerSideModified ) {

// when the second triangle's signed area would flip, snap innerPoint to the previous inner-side vertex

const refPt = joinIsOnLeftSide ? lastPointR : lastPointL;
const foldCross = ( outerPoint.x - refPt.x ) * ( innerPoint.y - refPt.y )
- ( outerPoint.y - refPt.y ) * ( innerPoint.x - refPt.x );
if ( ( joinIsOnLeftSide && foldCross < 0 ) || ( ! joinIsOnLeftSide && foldCross > 0 ) ) {

innerPoint.copy( refPt );

}

}

isMiter = false;

if ( innerSideModified ) {
Expand Down Expand Up @@ -2941,6 +2957,32 @@ class SVGLoader extends Loader {

}

// Second fix for #25326: Scan for reamining flipped (CW) triangles and collapse them to
// degenerated ones. This is safe and leaves no "holes" in the stroke because the flipped
// triangle's area is covered by neighbouring (CCW) triangles.

if ( vertices ) {

const tri = [ new Vector2(), new Vector2(), new Vector2() ];
const startFloat = vertexOffset * 3;

for ( let t = startFloat; t < currentCoordinate; t += 9 ) {

tri[ 0 ].set( vertices[ t ], vertices[ t + 1 ] );
tri[ 1 ].set( vertices[ t + 3 ], vertices[ t + 4 ] );
tri[ 2 ].set( vertices[ t + 6 ], vertices[ t + 7 ] );

if ( ShapeUtils.area( tri ) < 0 ) {

vertices[ t + 3 ] = tri[ 0 ].x;
vertices[ t + 4 ] = tri[ 0 ].y;

}

}

}

return numVertices;

// -- End of algorithm
Expand Down
4 changes: 4 additions & 0 deletions examples/models/svg/tests/wideStroke.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/screenshots/webgl_loader_ldraw.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions examples/webgl_loader_svg.html
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
'emptyPath': 'models/svg/emptyPath.svg',
'emoji': 'models/svg/emoji.svg',
'blueprint': 'models/svg/blueprint.svg',
'wideStroke': 'models/svg/tests/wideStroke.svg',

} ).name( 'SVG File' ).onChange( update );

Expand Down
2 changes: 1 addition & 1 deletion src/renderers/WebGLRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ class WebGLRenderer {

if ( _outputBufferType !== UnsignedByteType ) {

output = new WebGLOutput( _outputBufferType, canvas.width, canvas.height, depth, stencil );
output = new WebGLOutput( _outputBufferType, canvas.width, canvas.height, antialias, depth, stencil );

}

Expand Down
3 changes: 2 additions & 1 deletion src/renderers/webgl/WebGLOutput.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ const toneMappingMap = {
[ CustomToneMapping ]: 'CUSTOM_TONE_MAPPING'
};

function WebGLOutput( type, width, height, depth, stencil ) {
function WebGLOutput( type, width, height, antialias, depth, stencil ) {

// render targets for scene and post-processing
const targetA = new WebGLRenderTarget( width, height, {
type: type,
depthBuffer: depth,
stencilBuffer: stencil,
samples: antialias ? 4 : 0,
depthTexture: depth ? new DepthTexture( width, height ) : undefined
} );

Expand Down
Loading