#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:

Status badges

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 19 months ago by paulmasson

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.

comment:2 Changed 19 months ago by paulmasson

  • Authors set to Paul Masson
  • Status changed from new to 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 19 months ago by paulmasson

  • Branch set to u/paulmasson/29228

comment:4 Changed 19 months ago by gh-jcamp0x2a

  • Commit set to 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?

Last edited 19 months ago by gh-jcamp0x2a (previous) (diff)

comment:5 Changed 19 months ago by git

  • Commit changed from 4056281a815087804bf9edfcd081cbc6b3c3908f to 3a9c485bf28469858ba281c18ec130e08dcae56f

Branch pushed to git repo; I updated commit sha1. New commits:

3a9c485Fix color

comment:6 Changed 19 months ago by paulmasson

  • Branch changed from u/paulmasson/29228 to u/paulmasson/29228-1

comment:7 Changed 19 months ago by paulmasson

  • Commit 3a9c485bf28469858ba281c18ec130e08dcae56f deleted

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 19 months ago by paulmasson

  • Status changed from needs_review to needs_work

comment:9 Changed 19 months ago by git

  • Commit set to 4ae1e779bd7d3bf8c385ea61617eb2423d608476

Branch pushed to git repo; I updated commit sha1. New commits:

4ae1e77Pass color through to texts

comment:10 Changed 19 months ago by paulmasson

  • Branch changed from u/paulmasson/29228-1 to u/paulmasson/29228

comment:11 Changed 19 months ago by paulmasson

  • Status changed from needs_work to needs_review

Joshua, should be set to go now. Please review!

comment:12 Changed 19 months ago by gh-jcamp0x2a

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 19 months ago by paulmasson

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 19 months ago by gh-jcamp0x2a

  • Reviewers set to Joshua Campbell
  • Status changed from needs_review to positive_review

comment:15 Changed 19 months ago by vbraun

  • Branch changed from u/paulmasson/29228 to 4ae1e779bd7d3bf8c385ea61617eb2423d608476
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.