Opened 17 months ago

Last modified 2 weeks ago

#31812 new defect

Bug in polygons3d and IndexFaceSet

Reported by: Yuan Zhou Owned by:
Priority: major Milestone: sage-9.8
Component: graphics Keywords:
Cc: Joshua Campbell, Matthias Köppe, Paul Masson, Samuel Lelièvre Merged in:
Authors: Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Status badges

Description

polygons3d calls sage.plot.plot3d.index_face_set.IndexFaceSetIndexFaceSet, which should show the same graphic as calling polygon3d repeatedly.

sage: points = [(0, 0, 0), (1, 0, 0), (-1, 0, 0), (0, 0, 1), (0, 1, 0), (1, 0, 1), (1, 1, 0), (-1, 0, 1), 
....: (-1, 1, 0)]                                                                                         
sage: faces = [[3, 0, 1, 5], [0, 4, 6, 1], [3, 0, 2, 7], [0, 4, 8, 2]]                                    
sage: polygons3d(faces, points, color='blue')                                
Graphics3d Object

This gives all black faces, instead of blue. It is different than

sage: sum(polygon3d([points[i] for i in face], color='blue') for face in faces)
Graphics3d Object

Change History (10)

comment:1 Changed 17 months ago by Matthias Köppe

works for me (with the default viewer) - it's blue.

comment:2 Changed 17 months ago by Andrew

polygons3d(faces, points, color='blue')

all black faces, but

polygons3d(faces, points, color='blue', viewer='jmol')

all blue

comment:3 in reply to:  2 Changed 17 months ago by Yuan Zhou

Replying to gh-sheerluck:

polygons3d(faces, points, color='blue')

all black faces, but

polygons3d(faces, points, color='blue', viewer='jmol')

all blue

Same behavior here. Blue with viewer='jmol' or 'tachyon' but black with default viewer='threejs'.

Mysteriously, if I call viewer='threejs' after viewer='jmol' was used, then it shows blue.

p = polygons3d(faces, points, color='blue')
p.show()   # default is threejs, black
p.show(viewer='jmol') # blue
p.show(viewer='threejs') # now this mysteriously becomes blue

In any case, this is not a bug in polygons3d or IndexFaceSet then.

comment:4 Changed 17 months ago by Samuel Lelièvre

Cc: Joshua Campbell Paul Masson added

cc-ing three.js experts

comment:5 Changed 17 months ago by Joshua Campbell

I think the reason using viewer='jmol' first fixes it is because the IndexFaceSet.jmol_repr method has a side effect, defined here. Looks like it duplicates vertices so that each face has its own unique set, similar to what you get summing polygon3d, which also shows the correct color.

I'm not sure why the polygons3d version is showing up all black, though. The color is being passed to the template correctly. Interestingly, while rotating the camera around in Edge, it will occasionally flash the correct color blue for a split second. Doesn't happen in Firefox. Also, using threejs_flat_shading=True fixes it, so perhaps something related to lighting/normals?

comment:6 in reply to:  5 Changed 17 months ago by Yuan Zhou

It is related to the orientation of the vertices in a face. In the following example, the first face and the last face in faces_a have opposite orientations, while the two in faces_b have the same. The plot is black using faces_a and is blue using faces_b.

sage: points = [(0, 0, 0), (1, 0, 0), (-1, 0, 0), (0, 0, 1), (0, 1, 0), (1, 0, 1), (1, 1, 0), (-1, 0, 1)]               
sage: faces_a = [[3, 0, 1, 5], [0, 4, 6, 1], [3, 0, 2, 7]]  
sage: faces_b =  [[3, 0, 1, 5], [0, 4, 6, 1], [7, 2, 0, 3]] 
sage: polygons3d(faces_a, points, color='blue') # shows black
sage: polygons3d(faces_b, points, color='blue') # shows blue

Replying to gh-jcamp0x2a:

I think the reason using viewer='jmol' first fixes it is because the IndexFaceSet.jmol_repr method has a side effect, defined here. Looks like it duplicates vertices so that each face has its own unique set, similar to what you get summing polygon3d, which also shows the correct color.

I'm not sure why the polygons3d version is showing up all black, though. The color is being passed to the template correctly. Interestingly, while rotating the camera around in Edge, it will occasionally flash the correct color blue for a split second. Doesn't happen in Firefox. Also, using threejs_flat_shading=True fixes it, so perhaps something related to lighting/normals?

comment:7 Changed 14 months ago by Matthias Köppe

Milestone: sage-9.4sage-9.5

comment:8 Changed 10 months ago by Matthias Köppe

Milestone: sage-9.5sage-9.6

comment:9 Changed 5 months ago by Matthias Köppe

Milestone: sage-9.6sage-9.7

comment:10 Changed 2 weeks ago by Matthias Köppe

Milestone: sage-9.7sage-9.8
Note: See TracTickets for help on using tickets.