lojjic / aframe-troika-text

An A-Frame component for rendering 3D text using troika-three-text
MIT License
71 stars 12 forks source link

add colorRanges #64

Closed Utopiah closed 1 year ago

lojjic commented 1 year ago

It's a reasonable addition, thanks! Just be aware the API for it will probably change relatively soon.

lojjic commented 1 year ago

Did this change work for you? Aframe doesn't know how to parse the type: 'colorRanges' in the schema.

Utopiah commented 1 year ago

It did work, e.g if I use jxrhighlight() in https://fabien.benetou.fr/pub/home/future_of_text_demo/engine/ (sorry I often switch branches so might not be there when someone else checks, working on a solution for that).

Here is how I use it https://git.benetou.fr/utopiah/text-code-xr-engine/src/branch/syntax-highlighting/index.html#L2319 namely setting el.setAttribute("troika-text", {colorRanges: foundRanges}) on an <a-troika-text> entity. Maybe the problem comes from setting the troika-text on an <a-entity>? It should work still.

PS: I'm using https://fabien.benetou.fr/pub/home/future_of_text_demo/engine/dependencies/aframe-troika-text.min.js which isn't truly a minified version. I believe I mentioned it somewhere else https://github.com/lojjic/aframe-troika-text/issues/63#issuecomment-1415715176 but unfortunately not in this PR, so I didn't rebuild it, only change in src/. I hope I didn't create confusion here.

lojjic commented 1 year ago

Thanks, the problem was only when defining it using markup, it didn't know how to parse the string attribute. I added parsing instructions to the schema (just JSON.parse()) and it works now.

I've published v 0.10.0 with this change, let me know if you have any problems with it.

Utopiah commented 1 year ago

Unfortunately I'm getting

Uncaught SyntaxError: JSON.parse: unexpected character at line 1 column 2 of the JSON data
    Aframe 6
    jxrhighlight https://fabien.benetou.fr/pub/home/future_of_text_demo/engine/:2330
    jxrhighlight https://fabien.benetou.fr/pub/home/future_of_text_demo/engine/:2325
    <anonymous> debugger eval code:1
debugger eval code:45199:742

now so should using e.g el.setAttribute("troika-text", {colorRanges: {0: 0x0099ff, 3: 0xffffff}}) work? Could you please provide a working example? Happy to conform to whatever should be "the way" as I understand it might change soon.

lojjic commented 1 year ago

Ah, I see, after my parsing change it now expects a JSON string. You could JSON-encode it:

el.setAttribute("troika-text", {colorRanges: JSON.stringify({0: 0x0099ff, 3: 0xffffff})})

But I've published 0.10.1 which allows the object.

Utopiah commented 1 year ago

Yeay it works as-is now, thanks!