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

ShapeGeometry: Adding lineTo manually closing a shape, this line gets ignore #9450

Closed
5 of 12 tasks
ghost opened this issue Aug 2, 2016 · 14 comments
Closed
5 of 12 tasks

Comments

@ghost
Copy link

ghost commented Aug 2, 2016

Description of the problem

If I draw a rectangle (rectangle used for the simplied example, but holds true for any 2D geometry I tried. I always ignores the last segment) with

    svgShape = new THREE.Shape();
    svgShape.moveTo(0.97780502,-1.9777799999999388);
    svgShape.lineTo(0.97780502,-1.9777799999999388);
    svgShape.lineTo(198.02219502,-1.9777799999999388);
    svgShape.lineTo(198.02219502,-99.02216799999997);
    svgShape.lineTo(0.9778050200000052,-99.02216799999997);
    svgShape.lineTo(0.97780502,-1.9777799999999388);  // looking at the rendered result, this line gets ignored? 
    var svgMaterial = new THREE.MeshBasicMaterial( { color: 0x0000ff } )
    svgGeom = new THREE.ShapeGeometry( svgShape );
    var object = new THREE.Line( svgGeom, svgMaterial ) ;
    scene.add(object);

The result has a missing side:

rect

Three.js version

Tested and happens with every version I tried

  • 80dev
  • r79
  • r76
Browser

I only tested Chrome, but quite sure the others have same issue

  • All of them
  • Chrome
  • Firefox
  • Internet Explorer
OS
  • All of them
  • Windows
  • Linux
  • Android
  • IOS
Hardware Requirements (graphics card, VR Device, ...)
Replicated issue in JSFidde:

Replicated here: https://jsfiddle.net/peter6960/e7tbg5fp/7/

@ghost
Copy link
Author

ghost commented Aug 2, 2016

@ghost
Copy link
Author

ghost commented Aug 2, 2016

Additional note:

Using shape.autoclose DOES close the shape, but I do not think I need to rely on that, since our geometry is dynamically drawn, and some shapes will need to be closed, some wont, its easier to handle drawing the closing segment manually in the upstream code (just follow the SVG path). My parser already generates the closing line: and the code does the last lineTo. Why is it dropped?

@mrdoob
Copy link
Owner

mrdoob commented Aug 2, 2016

/ping @zz85

@ghost
Copy link
Author

ghost commented Aug 2, 2016

svgShape.moveTo(1,-2);
svgShape.lineTo(0.97780502,-1.9777799999999388);
svgShape.lineTo(198.02219502,-1.9777799999999388);
svgShape.lineTo(198.02219502,-99.02216799999997);
svgShape.lineTo(0.9778050200000052,-99.02216799999997);
svgShape.lineTo(0.97780502,-1.9777799999999388); 

It works just fine.

@ghost
Copy link
Author

ghost commented Aug 2, 2016

Replicated here: https://jsfiddle.net/peter6960/e7tbg5fp/7/

svgShape.moveTo(0.97780502,-1.9777799999999388);
svgShape.lineTo(0.97780502,-1.9777799999999388); 

That "LINE" does not make any sense.

@ghost
Copy link
Author

ghost commented Aug 2, 2016

The 'move to' exists because some svgs we import has multiple entities, so
we move to to match the position of that entity in relation to the rest of
the objects.

Agreed on the first line to, that can be removed. But removing it doesnt
add the missing last segment.

(commented out, reran fiddle, still not adding last segment
still ignores last segment

@ghost
Copy link
Author

ghost commented Aug 2, 2016

Ok, rereading your first comment, removing the Move to, seems to address the issue and the segment shows up.

@ghost
Copy link
Author

ghost commented Aug 2, 2016

Now, I still dont understand WHY it fails with the move to.
Removing the move to is not an option (See result of import in my app, without the move to:

without move

I do admit its 99.999% sure I am doing something wrong, I guess my question is - should I not be using move to (if not, how do I get a "not drawing a line" move to the start of the first path I want to draw?
or, is it the format in which I create the geometry?

I can use another method - the moveto/lineto came from the threejs examples

@ghost
Copy link
Author

ghost commented Aug 2, 2016

Now, I still dont understand WHY it fails with the move to.

It doesn't fail.
Please read again (carefully) my first posted message.
The first line must be a VALID one!

@WestLangley
Copy link
Collaborator

@openhardwarecoza You are not using three.js correctly.

Copy the coding patterns in http://threejs.org/examples/webgl_geometry_shapes.html.

ShapeGeometry is a geometry appropriate for triangular meshes -- not lines.

// mesh
var svgMaterial = new THREE.MeshBasicMaterial( { color: 0x0000ff } );
svgGeom = new THREE.ShapeGeometry( svgShape );
var object = new THREE.Mesh( svgGeom, svgMaterial ) ;

// line
svgShape.autoClose = true;
var points = svgShape.createPointsGeometry();
var object = new THREE.Line( points, new THREE.LineBasicMaterial( { color: 0x0000ff } ) );

http://jsfiddle.net/e7tbg5fp/8/

@ghost
Copy link
Author

ghost commented Aug 2, 2016

Aha, thanks Westlangley! More explained reply - much appreciated! (Adding a little theory helps a lot more in teaching) . I have been battling the ShapeGeometry thing for a few days now!

So, taking your advice, triggered my thinking that of course, I only need lines! So.... Much better:

https://jsfiddle.net/peter6960/e7tbg5fp/10/

var svgGeom = new THREE.Geometry();
svgGeom.vertices.push( new THREE.Vector3( 0.97780502,-1.9777799999999388, 0 ) );
svgGeom.vertices.push( new THREE.Vector3( 198.02219502,-1.9777799999999388, 0 ) );
svgGeom.vertices.push( new THREE.Vector3( 198.02219502,-99.02216799999997, 0 ) );
svgGeom.vertices.push( new THREE.Vector3( 0.9778050200000052,-99.02216799999997, 0 ) );
svgGeom.vertices.push( new THREE.Vector3( 0.97780502,-1.9777799999999388, 0 ) );
var svgMaterial = new THREE.MeshBasicMaterial( { color: 0x0000ff } )
var object = new THREE.Line( svgGeom, svgMaterial ) ;
scene.add(object);

Works perfectly now!

@ghost ghost closed this as completed Aug 2, 2016
@WestLangley
Copy link
Collaborator

@openhardwarecoza Please use LineBasicMaterial for lines.

@ghost
Copy link
Author

ghost commented Aug 2, 2016

Yeah, sorry, normally I would SO, but this looked like a bug based on what i thought lineto was supposed to do. (; I did ask MrDoob first in issue on my project (; Wont Happen Again

@WestLangley
Copy link
Collaborator

@openhardwarecoza I saw that. No problem. : - )

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants