Jump to content

canvas 2d Track Node and vrDeviceOrientation Camera problem/issue/question


jinxsterz
 Share

Recommended Posts

Hi Jinxsterz!  Interesting issue.

Let's ping @Nockawa, the author of Canvas2D, and show him your issue.

http://babylonjs-playground.com/#1N9RJY#57

(switch vr cams in line 34/35, as wanted, everyone)

VR cams and ScreenSpaceCanvas2D's (with Group2D trackNode/trackedNode) do not work so well.  I'm not sure if it CAN be "fixed".  Maybe Nockawa will have some words about it.

http://babylonjs-playground.com/#1N9RJY#56

There is a "work-around" that is really not good, but it works.  (mouse control-drag to move-around Arc Cam target)

Let's tour the #56 playground:

Line 4 - the createLabel() function, and below that... it has a helper function called createText().  CreateLabel() is called from line 126.  It is called once for EACH cube.

Line 5 - Notice we use a worldSpaceCanvas2D and NOT a screenSpaceCanvas2D.  Each worldSpaceCanvas2D (let's call it wsc2d)... has a "trackedNode" built-in, automatically.  It is called a worldSpaceCanvasNode.   You MIGHT be able to set its .showBoundingBox = true... to better see it (if you wish).  Now we will use it.

Line 15 - set the worldSpaceCanvasNode (let's call it WSCN) .position... 20 units UP.  This places the labels ABOVE the cube/mesh.
Line 16 - set WSCN billboardMode to all-axes.  This causes the label to always face the camera... or try-to.
Line 17 - set WSCN parent to be mesh, which ==  a cube.

Lines 22-31 - create a Rectangle2d.  In this case, it is ONLY used to make the white border around each label.

Lines 33-54 - set many many variables... preparing to make the actual text and its background, border, color gradients, etc.  (Text2d)

Lines 57-73 - CALL the createText(many parameters) function.  It is located at line 80.

Lines 80-98 - A very-powerful createText() function.  It does many things. It sets text border with color gradients, sets text background with color gradients, sets fonts, positions text within rect2's white border, etc.  Remember... that most of the adjustments for the Text2D part of the label... are done in lines 33-54. 

These WSC2D labels work okay, eh?  I don't have any VR devices to test-with... but I think it will work "better" than SSC2D labels.

Let's look at another playground:

http://babylonjs-playground.com/#1N9RJY#58

Here, I have switched back-to VR Free Cam in lines 105/106. (It WAS set to VR ARC cam in #56 demo).  Also, I disabled billboard mode on the WSCN (the invisible trackedNode that WorldSpaceCanvas2D automatically uses)... in line 16. 

Things look different, now.  Camera is a FREE instead of ARC, so IT acts differently.  And labels no longer automatically try to face the camera, so they act differently, too.

Possibly, with line 16 activated (billboardMode ON)... you will quickly get cross-eyed or wall-eyed... when using VR cameras.  You might get motion sickness.  :o  Be careful  :)

Canvas2d system is still being developed, though it is already quite powerful.  We MIGHT see future improvements for using ScreenSpaceCanvas2D with VR cameras... but perhaps not.  For now, using worldSpaceCanvas2D (instead of screenSpaceCanvas2D) might be the only solution. 

In general, notice that ScreenSpaceCanvas2D method uses ONE ScreenSpaceCanvas2D... and many Group2d children, each with trackNode.

Conversely, WorldSpaceCanvas2D method uses MANY WorldSpaceCanvas2D (each has a worldSpaceCanvasNode - an invisible mesh that can be parented to other mesh), and uses no Group2D

WSC2D still CAN use Group2D, but there was no need, for our demo.  We need no Group2D trackNode.  We use the WorldSpaceCanvas2D.worldSpaceCanvasNode instead.  We simply parented the WSCN to any mesh we wish (in line 17).

I hope this helps.  Sorry for the inconvenience.  Perhaps Nockawa will have comments about the future of ScreenSpaceCanvas2D... when used with VR cameras.  Be well.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...