NikLever / CanvasUI

A Three.JS WebXR UI. Enabling easy UI creation for immersive-vr sessions.
canvas-ui-eight.vercel.app
GNU General Public License v3.0
132 stars 22 forks source link

canvasUI refactor #21

Open eviltik opened 2 years ago

eviltik commented 2 years ago

Currently, we are creating Canvas UI widgets by instantiating a Canvas class.

Just thinking to tend to something like datGUIXR.

// only one CanvasUI instance, so we can shared data between widgets (raycaster, xr controllers events ..)
const canvasUI = new CanvasUI();

// then we can add widgets like this
const panelLeft = canvasUI.add(contentPanelLeft, configPanelLeft);
const panelRight = canvasUI.add(contentPanelRight, configPanelRight);

// open the door to new usefull methods ?
panelLeft.hide(); // show() // destroy // move // rotate // setModal // moveForward // moveBackward ..

// globals methods ?
canvasUI.hideAll(); // showAll // destroyAll // enable/visible ..
NikLever commented 2 years ago

A lot of the time there will be a single panel, so let's stick with an option to use a constructor CanvasUI(content, config). That would automatically add a CanvasPanel(content, config) to the panels array.

eviltik commented 2 years ago

Ho yes i see now !

I was working on that on my approach yesterday. Because of keyboard and mouse behavior (same as xr controllers, mouse events are setted twice).

I started a dev-mouse-controller branch based on your dev branch. Let me try.

eviltik commented 2 years ago

A lot of the time there will be a single panel,

Well, not sure about that ;)

That would automatically add a CanvasPanel(content, config) to the panels array. Looks like we need a new class. CanvasPanel.

Not all is clear for me, I'm trying to figure out better. Any additional explanations are welcome.

Just to be sure we are in sync :

NikLever commented 2 years ago

CanvasUI is used to handle controllers and an array of CanvasPanels CanvasPanel is a single Quad mesh with a CanvasTexture

const ui = new CanvasUI(content, config)

would create a singleton CanvasUI with a single CanvasPanel

The same as

const ui = new CanvasUI()
ui.add(content, config)