GithubHelp home page GithubHelp logo

hhy5277 / webvr-experiments Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nikgraf/webvr-experiments

0.0 3.0 0.0 2.52 MB

A collection of ReactVR experiments (potentially also A-Frame and WebVR expriments using ReasonML & Elm)

License: MIT License

JavaScript 84.40% HTML 15.60%

webvr-experiments's Introduction

WebVR Experiments

A collection of ReactVR experiments (potentially A-Frame and WebVR using ReasonML & Elm)

Hello World (ReactVR)

This is an experience report/guide to explore ReactVR. Keep in mind I had some basic knowledge in 3D-modeling as well as computer graphics beforehand. Please ping me on Twitter in case you have questions or I take things for granted you have a hard time wrapping your head around. I also highly recommend to read the full ReactVR docs. I did as well :)

reactvr-helloworld

To try out the examples run

# cd into/the/folder
yarn install
npm start
# open http://localhost:8081/vr/

Or check out the hosted live demo of HelloWorld v3.

v1 - Basic Cube Rendering

screen shot cube

With this example I wanted to explore how to create my own geometries and render it within ReactVR. I evaluated a couple of tools and in the end decided to go with Blender. I'm still struggling with the interface a bit, but Blender is open source has all the advanced features I will probably need for the next couple of years.

In Blender I created a cube, removed the light and camera, added a material to color the cube's surfaces and exported the scene to the Wavefront .obj (geometry) and .mtl (material) format. Then learned that Three.js failed to render my simple cube properly as soon as I create a <Mesh source={{ mesh: asset('cube.obj'), mtl: asset('cube.mtl'), lit: true }} /> due to some issues with the material definitions. What worked for me was to remove all the gimmick features from the material and reduce it to Diffuse & Specular lighting. I unchecked all other checkboxes for the material. This is not a Blender only issue, as I encountered similar issues once I gave other tools a try.

cube setup in blender

v2 - Tree (first custom component)

screen shot tree

The goal of this stage was to create a Tree component. I created two geometries (tree-crown, tree-trunk) and placed them in my World component. After some positioning I was able to extract both into a Tree component. This allowed me to create a second one and place it next to the first one.

screen shot 2016-12-28 at 01 33 52

screen shot 2016-12-28 at 01 35 03

Tree component:

export default ({ style }) => (
  <View style={style}>
    <Mesh
      source={{ mesh: asset('tree-trunk.obj'), mtl: asset('tree-trunk.mtl'), lit: true }}
      style={{ transform: [{scale: [0.6, 1, 0.6]}] }}
    />
    <Mesh
      source={{ mesh: asset('tree-crown.obj'), mtl: asset('tree-crown.mtl'), lit: true }}
      style={{ transform: [{translate: [0, 2.5, 0]}] }}
    />
  </View>
);

In addition to that I generated a plane geometry in Blender as floor element. For the sky I generated a blue gradient image and used it in a <Pano /> component.

Initially I planned to place the scenic camera approximately one meter above the ground, but discovered a bug with the <Scene /> component. My fallback was to position the floor as well as the trees -1 (meter) on the z-axis.

v3 - Forest

screen shot forest

Next up I wanted to have a more interesting scene as well as explore how I could generate it. I decided to create a forest. This was pretty much straight forward as I could create a Forest component which uses the Tree component multiple times. By adding some randomizers for positioning, height and scale, I ended up with what I envisioned.

Forest component:

export default ({ style }) => (
  <View style={style}>
    {trees.map((tree) => {
      const scale = randomScale();
      return (
        <Tree
          key={tree.id}
          style={{
            transform: [
              {scale: [scale, scale, scale]},
              {translate: [tree.x, randomHeight(), tree.y]},
            ]
          }}
        />
      );
    })}
  </View>
);

Right now 100 trees are generated and the user is placed at the center of the forest. Trying it with 1000 trees, led to a laggy experience (MacBook 13", Chrome Canary).

What bothered me a bit was that for each Tree a fetch request was fired. I was hoping that ReactVR would cache the geometry and material.

v4 - Animation (coming soon โ€ฆ)

Next up I'm going to look into animations using clouds and birds.

webvr-experiments's People

Contributors

nikgraf avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.