Reactylon: The React Framework for XR

Perhaps you’ve already exposed this sort of interface/api, but is there a way to create many instances of the same mesh (they share the same geometry, and optionally share the same materials)

Yes, there is a dedicated section about cloning/instancing: Copies, Clones and Instances | Reactylon, the sugar syntax is the instanceFrom prop.

Going off the example you provided, lets say your group of boxes constitutes a single mesh tree. I want to create many instances that all respond to the same hide/show logic at an individual level. That is each group of boxes can be toggled on/off, and each group of boxes can hide/show individual boxes.

Great example to showcase. As the goal is to share the same materials across the boxes, we will use instances instead of clones and, for simplicity, instead of showing or hiding a single box, we will scale its dimensions.

There are two BoxGroup components (representing your single mesh tree), each accepting the following props:

  • name: the name of the box group
  • count: the number of the boxes
  • color: the color of the boxes
  • positionY: the Y position of the box group

When you click on a box, its size toggles between 1 and 2. This change is handled acting on the ref the box so it won’t trigger a re-render.

At the top level, the visibility of the two BoxGroup is managed through HTML buttons, controlled by an external context (primary renderer) and React state. When a BoxGroup is shown, it creates new instances, while it is hidden, it disposes all of them.
Note: the visibility of a BoxGroup doesn’t influence the state of the other one (for instance, try to click on some boxes of one BoxGroup and then toggle the visibility of the other one).

The example is pretty simple, but it demonstrates several key-concepts:

  1. How to sync external updates with the Reactylon rendering context (from primary to secondary renderer)
  2. How to change a property without trigger a re-render (by using ref)
  3. How a React component-based approach simplifies managing a unified entity by encapsulating count, color, and events, making updates and interactions more efficient and scalable.
2 Likes

NICE.

I tweaked your example to render 20k boxes (10k each color), and I don’t notice any lag whatsoever.

This is so awesome! When I get some free time, I’m going to attempt a much more involved large scale demo, and stress test this framework. If feels like you’ve indirectly provided a sort of entity-component system, which is something I’ve always wished babylon.js had a better api for.

1 Like

Hi there! I wanted to share the new features with you:

  • Audio (v1 but as soon as the migration is complete, I’ll move to v2)

    • Ambient sound
    • Spatial sound
    • Spatial sound attached to mesh
  • Physics

    • Havok by default
    • Rigid bodies, motion forces and collision events
    • usePhysics and useHavok hooks

I’ve added the new code sandboxes to the previous message.

And… I’m trying to create more complex examples in the documentation, i hope you like them!

2 Likes

That’s so great! I love it!

1 Like