Replies: 2 comments 4 replies
-
Thanks for opening the discussion @JakobHock . Personally, I'd like to be able to allow users to swap renderers eventually, but there are a number of changes that would need to happen in order to allow that. We're a really small team working on the core and at the moment and other issues are taking priority. But that could change if there is feedback from the community indicating a strong desire to swap renderers. Feel free to open a feature request on Tres or discuss on the Discord. (For Tres, Github discussions are sometimes overlooked. Those other avenues might give a better idea of how much community interest there is.) |
Beta Was this translation helpful? Give feedback.
-
Hello, I have also encountered this problem and I am very excited to see your solution here. However, I am not sure how the |
Beta Was this translation helpful? Give feedback.
-
Motivation
TresJS is currently missing a clean way to integrate the CSS2DRenderer into the scene. The standard way to use the CSS2DRenderer currently would to do something like the following:
The
CustomCSS2DRenderer
would provide the renderer to the tree and the user would have to inject in into every place they would want to create a label as. Additional there is no nice way to handle the UI part as HTML elements are not allowed in aTresCanvas
. This is an unmaintainable way of handling the 2D part of a 3D scene.Proposal
To address these difficulties, i propose tres could provide a
TresCSS2DRenderer
component that would handle the rendering of the 2D part of the scene. With the registration of said component the user would be able to use a newTresLabel
component inside meshes to create 2D labels in the scene.TresLabel
is a wrapper around theCSS2DObject
class from Threejs and supports props to control the underlying object. TheTresLabel
provides aslot
for the user to define the content of the label with standard HTML and CSS. TheMesh
to which theTresLabel
is assigned to would be provided in the template as aslotprop
to enable the user to access it's information in the label. The proposed API would look like the following:Changes
For this proposal to be implemented the following changes would have to be made:
TresCSS2DRenderer
component to the core package.CSS2DRenderer
on creation of the scene if aTresCSS2DRenderer
is present in the tree.TresLabel
component if aTresCSS2DRenderer
is present in the tree.Mesh
of aTresMesh
as aslotprop
in theTresLabel
component.Benefits
TresLabel
component in everyTresMesh
without having to inject the renderer into the tree.Conclusion
Support for 2D elements in a 3D scene is a necessary feature for TresJS to be a complete 3D framework. The proposed API would provide a clean and maintainable way to integrate 2D elements into the scene. The user would be able to use standard HTML and CSS to style the labels and would not have to fiddle around with rendering labels in a javascript native way.
As this is my first proposal/contribution to TresJS i would be happy to hear your feedback on the proposal and be able to discuss it with you.
Beta Was this translation helpful? Give feedback.
All reactions