mrdoob / three.js

JavaScript 3D Library.
https://threejs.org/
MIT License
101.71k stars 35.3k forks source link

VRMLLoader: Support Text Nodes #13002

Closed DoomTay closed 4 years ago

DoomTay commented 6 years ago
Description of the problem

Here is one such example of a text node with a "size" field containing only one number.

Three.js version
Browser
OS
Mugen87 commented 6 years ago

Yes, this feature is not supported. Maybe we should rename the issue to "VRMLLoader: Support Text Nodes" or something like that. Besides, the semantic of size is different when it's used inside fontStyle.

DoomTay commented 6 years ago

It seems that VRMLLoader fails to support a few things besides V1. I couldn't get it working with this or this, which is gzipped, or this NIST-developed one

It's a shame, because I was hoping to use this as the backbone for a Firefox addon that allows for VRML navigation, saving me the work of having to research and write my own thing

bartmcleod commented 6 years ago

VrmParser does not yet support Text, but I'm happy to address the issue following #13402.

bartmcleod commented 6 years ago

@DoomTay would you mind to file an issue at the VrmlParser project? https://github.com/bartmcleod/VrmlParser I am looking into it. The first hurdle with Ver21.wrl seems to be that Switch is not yet supported or even parsed correctly.[Edit]Switch is supported. Must be something else.

[edit] Interesting, there were two issues with the file and my parser:

  1. An issue with my parser: node names were more strictly limited than specified by the VRML 97 specification. It would not parse "(" and ")" in a node name. That was easy to fix.
  2. There is a strange tab character in your Ver21.wrl file, that is not matched by the \t meta character. If I replace these tabs by a few spaces, I can parse the file and work on the text node.
bartmcleod commented 6 years ago

@DoomTay your example files seem to be full blown games with a lot of interaction, some of which might be supported by the current implementation of VrmlParser. Some of it is not, such as the Script node and route arrays. To be able to fully render these examples using VrmlParser is an interesting and ambituous goal. The challenge we could be facing here extends well beyond supporting the Text node.

Mugen87 commented 4 years ago

I had a go on implementing TextNode in VRMLLoader today. Unfortunately, without success^^. This part of the VRML spec is really hard to map on today's Web APIs. You have to draw the text on a canvas element and then use it as a texture for a plane geometry. However, the sizing of the canvas as well as the correct application of VRML font style definitions when drawing the text is very complex.

TBH, the amount of code which is necessary to implement full support (or at least a decent one) seems to outweigh the benefits of text nodes.

bartmcleod commented 4 years ago

@Mugen87 The text node has already (limited) support in the vrmlparser project. The VRMLLoader in Three is just an example of how VRML could be used in Three, but actual development effort in this field should go to the vrmlparser project, as this offers better separation of nodes. This makes it easier to add support one node at a time and to improve upon nodes when new ideas come up. It is also fully aware of the VRML node tree, which should make it possible to treat text in more advanced ways. We would however need someone with deep knowledge of fonts to be able to make a viable modern implementation.

Mugen87 commented 4 years ago

It is also fully aware of the VRML node tree, which should make it possible to treat text in more advanced ways.

VRMLLoader was rewritten last year. This works now in the loader, too.

Anyway, I'm fine with advising users to use your vrmlparser project if they need to work with TextNode for some reasons.

bartmcleod commented 4 years ago

VRMLLoader was rewritten last year. This works now in the loader, too.

I wasn't aware of this. I have been very busy doing other stuff. It is kinda sad that apparently the two projects diverged in such way that rewrites in one do not benefit the other.

Mugen87 commented 4 years ago

I think we have discussed this before but VRMLLoader should behave like other three.js loaders and just parse geometries and materials. It's not its task to parse the whole application that a VRML asset might represent (including script logic, sensors etc.).

Against this backdrop, it's totally okay when different projects have different focus areas.

bartmcleod commented 4 years ago

We did discuss it before and the projects do have different focus areas. However, I think they could share more than they do now. I have separated out the treatment of animation logic and sensors following that discussion, but I do not know in how far this contributed to the development of the loader VRMLLoader a year ago, if at all. That would mean duplicated effort I'm affraid.

Mugen87 commented 4 years ago

Closing, see https://github.com/mrdoob/three.js/issues/13002#issuecomment-624063402.