DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
Securing Your Software Supply Chain with JFrog and Azure
Register Today

Trending

  • A Complete Guide to AWS File Handling and How It Is Revolutionizing Cloud Storage
  • How To Use Geo-Partitioning to Comply With Data Regulations and Deliver Low Latency Globally
  • Turbocharge Ab Initio ETL Pipelines: Simple Tweaks for Maximum Performance Boost
  • File Upload Security and Malware Protection

Trending

  • A Complete Guide to AWS File Handling and How It Is Revolutionizing Cloud Storage
  • How To Use Geo-Partitioning to Comply With Data Regulations and Deliver Low Latency Globally
  • Turbocharge Ab Initio ETL Pipelines: Simple Tweaks for Maximum Performance Boost
  • File Upload Security and Malware Protection
  1. DZone
  2. Data Engineering
  3. Data
  4. ReactVR/react-360 Is Great, but Maybe Not Quite There Yet

ReactVR/react-360 Is Great, but Maybe Not Quite There Yet

While it's not perfect yet, it's still pretty dang cool. Read on to learn how to get started making VR apps with this React library!

Swizec Teller user avatar by
Swizec Teller
·
Aug. 07, 18 · Tutorial
Like (2)
Save
Tweet
Share
9.38K Views

Join the DZone community and get the full member experience.

Join For Free

My goal was to build a 3D scatterplot that you can explore. Stand inside your data and look around.

Wouldn't that be cool?

Instead, I got a squished Baymax healthcare companion...

ReactVR, recently renamed to react-360, doesn't have 3D modeling primitives like spheres and boxes. Instead, it asks you to import 3D models and build your scenes with that.

The base example is a 3D viewer of models from Google's Poly library.

And that works great:


You can import a model, display it with a React component, and look around using VR goggles and the Oculus browser. Just gotta make sure there's a URL that shows your VR app.

To Display a 3D Model...

To display a 3D model in VR space, you put it in a react-360 <View> component, add some light, and an <Entity>.

class Baymax extends React.Component {
    render() {
        return (
            <View>
                <AmbientLight intensity={1.0} color="#ffffff" />
                <PointLight
                    intensity={0.4}
                    style={{ transform: [{ translate: [0, 4, -1] }] }}
                />
                <Entity
                    source={{ obj: baymax }}
                    style={{
                        transform: [{ scaleX: 0.05 }, { scaleY: 0.05 }]
                    }}
                />
            </View>
        );
    }
}

Lighting doesn't do much in my <Baymax> example. I'm not sure why. Maybe because the whole model is white?

Where it gets interesting is the scale transformation. In theory, you can scale your models on all 3 axes. In practice, the scaleZ transform is currently not implemented and throws an error. Even though it's in the docs. Oops.

But I guess that's the problem with models you import from the web because you don't know how to make your own. Their scales are out of whack.

The Baymax model, for example, looks great when it's 200 meters away. Yes, units for all vectors in ReactVR and react-360 are in meters. Love it.

Image title

Baymax 200 meteres away head on

To Oosition a react-360 View

Positioning react-360 views happens through something they call roots. You can think of it as an anchor point for your components that you build on top of.

This goes in your client.js and you can have as many roots as you need.

r360.renderToLocation(
    r360.createRoot("Baymax"),
    new Location([0, -30, -200])
);

Location is a 3D vector based off of the user's position. In this case, that's 0 meters to the left or right, 30 meters down, and 200 meters back. Go 200 meters in the other direction, and your user has to turn their head to see your scene.

And that's where react-360 starts to shine. 360 degrees on 3 axes is a lot of space to play around with. Seriously. A ton of space. You can't even imagine until you start to play around.

react-360 Shines at Placing 2D Views in 3D Space

What I believe react-360 is truly optimized for is putting 2D panels in 3D space and giving your users more room to use different controls.

It's kind of a shame that this is the case, but there's a lot you can do with 2D in 3D. Imagine a data dashboard for your infrastructure that uses full 3-axis 360 views to place charts all around you instead of trying to squish everything into a small browser window.

I don't know about you, but I always run out of space when making monitoring dashboards!

Code looks just like React Native by the way. You have <View>s and <Text>s and <Image>s and <VrButton> s. You put them together and voila, an interface.

This builds that panel on the left: 

const TopPosts = props => {
    if (!props.posts) {
        return (
            <View style={styles.wrapper}>
                <Text>Loading...</Text>
            </View>
        );
    }

    return (
        <View style={styles.wrapper}>
            <Text style={styles.postButtonName}>
                Posts: {props.posts.length}
            </Text>
            {props.posts.map((post, i) => (
                <PostButton
                    key={post.id}
                    index={i}
                    name={post.name}
                    author={post.author}
                    preview={post.preview}
                />
            ))}
        </View>
    );
};

Take a list of posts from Google's Poly store, render a <View>, put some <Text> inside to know the count, then iterate through the data and render a <PostButton> for each entry.

The <PostButton> component is a <VrButton> that gives us clickability and callbacks. It contains an image and two text labels. Pretty neat.

You place the panel in 3D space with a root, a surface, and a render to surface.

const leftPanel = new Surface(300, 1200, Surface.SurfaceShape.Flat);
    leftPanel.setAngle(-0.6, 0);
r360.renderToSurface(r360.createRoot("TopPosts"), leftPanel);

The extreme 1,200 height doesn't look so great in a web browser, but works great in VR goggles because you can look up and down.

360 degree really is a lot of room for activities. Really. Wish I knew how to record what I can see inside my goggles.

Fin

There's a lot of potential here. In production mode, react-360 is fast enough to avoid nausea; in dev, not so much. The engineering UX is similar to React Native, and VR is growing like crazy.

You might not realize it, but there's a lot of VR users out there. 171,000,000 according to statista. Similar to the web in 1999.

Now's the time to start playing around.

Watch me build the squished Baymax and preorder React + D3 2018, likely the first React book/course to include VR stuff:

Space (architecture) React (JavaScript library) Build (game engine) React Native Data (computing) IT Data structure Dashboard (Mac OS)

Published at DZone with permission of Swizec Teller, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Trending

  • A Complete Guide to AWS File Handling and How It Is Revolutionizing Cloud Storage
  • How To Use Geo-Partitioning to Comply With Data Regulations and Deliver Low Latency Globally
  • Turbocharge Ab Initio ETL Pipelines: Simple Tweaks for Maximum Performance Boost
  • File Upload Security and Malware Protection

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: