Opened 3 years ago
Closed 3 years ago
#29228 closed defect (fixed)
Unable to change text color in Three.js viewer
Reported by: | gh-jcamp0x2a | Owned by: | |
---|---|---|---|
Priority: | minor | Milestone: | sage-9.1 |
Component: | graphics | Keywords: | threejs text color |
Cc: | Merged in: | ||
Authors: | Paul Masson | Reviewers: | Joshua Campbell |
Report Upstream: | N/A | Work issues: | |
Branch: | 4ae1e77 (Commits, GitHub, GitLab) | Commit: | 4ae1e779bd7d3bf8c385ea61617eb2423d608476 |
Dependencies: | Stopgaps: |
Description
The documentation for text3d
suggests that the color of text can be adjusted:
https://doc.sagemath.org/html/en/reference/plot3d/sage/plot/plot3d/shapes2.html#sage.plot.plot3d.shapes2.text3d
But running the example provided results in only black text:
text3d("Sage is...",(2,12,1), color=(1,0,0)) + text3d("quite powerful!!",(4,10,0), color=(0,0,1))
Inspecting the threejs_template.html
, in the addLabel
function, the fill color is hard-coded:
context.fillStyle = 'black';
Encountered in 9.1.beta3 as well as 8.9.
Change History (15)
comment:1 Changed 3 years ago by
comment:2 Changed 3 years ago by
Authors: | → Paul Masson |
---|---|
Status: | new → needs_review |
This commit passes text colors through to the template. Font size isn't being tracked by textures right now, and the entire graphics/keywords system is irritating and needs work, so passing font size should be left for another ticket.
The example above now shows the proper colors. One of the texts is clipped because the underlying Three.js sprite is limited in size. That can be addressed on another ticket as well, after some planned cleanup of sprite processing in the template.
comment:3 Changed 3 years ago by
Branch: | → u/paulmasson/29228 |
---|
comment:4 Changed 3 years ago by
Commit: | → 4056281a815087804bf9edfcd081cbc6b3c3908f |
---|
Hi Paul. I was testing out this branch and noticed that the colors weren't displaying in Chrome or Firefox. Looks like the #
was missing at the beginning of the color string. Prepending it in base.pyx
fixed it:
color = '#' + p.all[0].texture.hex_rgb()
I suppose it could also be prepended in the template right before it's used, depending on where you'd prefer to handle it.
Edit: somehow I seem to have changed the commit, though I don't understand how I was able to do that. Maybe because I was browsing the diff while writing this comment?
comment:5 Changed 3 years ago by
Commit: | 4056281a815087804bf9edfcd081cbc6b3c3908f → 3a9c485bf28469858ba281c18ec130e08dcae56f |
---|
Branch pushed to git repo; I updated commit sha1. New commits:
3a9c485 | Fix color
|
comment:6 Changed 3 years ago by
Branch: | u/paulmasson/29228 → u/paulmasson/29228-1 |
---|
comment:7 Changed 3 years ago by
Commit: | 3a9c485bf28469858ba281c18ec130e08dcae56f |
---|
Joshua, the merge issue isn't your doing. The template moved from src/ext
to src/sage/ext_data
on #21785. Need to redo things...
comment:8 Changed 3 years ago by
Status: | needs_review → needs_work |
---|
comment:9 Changed 3 years ago by
Commit: | → 4ae1e779bd7d3bf8c385ea61617eb2423d608476 |
---|
Branch pushed to git repo; I updated commit sha1. New commits:
4ae1e77 | Pass color through to texts
|
comment:10 Changed 3 years ago by
Branch: | u/paulmasson/29228-1 → u/paulmasson/29228 |
---|
comment:11 Changed 3 years ago by
Status: | needs_work → needs_review |
---|
Joshua, should be set to go now. Please review!
comment:12 Changed 3 years ago by
I've tested it again and the issue has been resolved. The correct text colors appear in the output. I made sure to update my start script to copy things from/to the new directories. I'll need to go into my animation branch and update things as well.
Thanks Paul!
comment:13 Changed 3 years ago by
Joshua, if you are satisfied with this ticket then enter your full name as a reviewer and set it to positive review.
comment:14 Changed 3 years ago by
Reviewers: | → Joshua Campbell |
---|---|
Status: | needs_review → positive_review |
comment:15 Changed 3 years ago by
Branch: | u/paulmasson/29228 → 4ae1e779bd7d3bf8c385ea61617eb2423d608476 |
---|---|
Resolution: | → fixed |
Status: | positive_review → closed |
The only options currently passed in are text and location:
https://github.com/sagemath/sage/blob/develop/src/sage/plot/plot3d/base.pyx#L422
Color can be added here and then processed in the
addLabel
function. Could include font size as well as an additional option.