Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lab 009 - Title Card & Vue 3 Composables #13

Closed
vrhermit opened this issue Jan 31, 2022 · 0 comments
Closed

Lab 009 - Title Card & Vue 3 Composables #13

vrhermit opened this issue Jan 31, 2022 · 0 comments

Comments

@vrhermit
Copy link
Owner

vrhermit commented Jan 31, 2022

Playing with Vue 3 composables and Babylon JS. I think this could be a valuable way to create modular, reusable, and reactive objects.

New composable called Title Card (in a folder called “composables”. Title Card exports a function which creates the title card and returns two reactive refs as an object. Internal watch functions will update the Babylon JS GUI anytime the ref values change.

const createTitleCard = (scene) => {

  // The data that we will display in the VR console
  let title = ref("TITLE PLACEHOLDER");
  let subtitle = ref("SUBTITLE PLACEHOLDER");

 
  // Babylon JS GUI code here, removed for brevity 


  // Watch the title and subtitle for changes
  // and update the text in the GUI
  watch(title, (newValue) => {
    const texture = scene.getTextureByName("title-card-texture");
    texture.getControlByName("title-text").text = newValue;
  });

  watch(subtitle, (newValue) => {
    const texture = scene.getTextureByName("title-card-texture");
    texture.getControlByName("subtitle-text").text = newValue;
  });

  return { title, subtitle };
};

export default createTitleCard;

The scene uses this function and destructures the result.

  const { title, subtitle } = createTitleCard(scene);
  ...
  title.value = "Lab 009";
  subtitle.value = "Title Card & Vue 3 Composables";
@vrhermit vrhermit mentioned this issue Feb 1, 2022
17 tasks
@vrhermit vrhermit closed this as completed Feb 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

No branches or pull requests

1 participant