Render Custom 3D Objects Using the Model Component in React VR

Nik Graf
InstructorNik Graf
Share this video with your friends

Social Share Links

Send Tweet
Published 7 years ago
Updated 5 years ago

React VR isn't limited to simple 3D primitives. By using the <Model/> Component we can place complex 3D models into our scene.

In this lesson we'll import a custom polygon mesh of an astronaut by loading in a Wavefront .obj file. We'll play with our astronaut and learn about various options that will define the surface area of the model.

[00:00] First, we have to import the model component and add it to our scene. Now we need the model itself. You need to know there are various file formats out there, and how to represent 3D models. React VR supported one out of the box from the beginning, which was OBG. Keep in mind, it only describes the geometry of an object.

[00:21] In our case, I prepared an astronaut model which is in our static assets directory. We add a source property to our model, and it accepts an OBG key which will provide with a file path to the geometry file, and then we add a style attribute. In addition, we move it two meters away from us.

[00:44] Next, we add the property wireframe, and with this change, the model already becomes visible in our scene. Let's take a closer look how to change the appearance of the model surface. Therefore, we remove the wireframe property and apply color, in our case, orange.

[01:00] As you can see, the color applies to the whole model. Let's set the model's property lit to true so it is affected by the current lightning setup. As an alternative to this full covering, we can use a material file that can be referenced.

[01:15] The benefit of a material file is that it contains quite complex definitions of how the surface of the model looks like, for example, various textures or colors that apply to different parts of the surface.

[01:27] Therefore, we add an MTL key to the source object and reference the path of the MTL file in our static assets. Last but not least, another alternative is to provide a texture. In our case, I use the chess world that already ships with the React VR boilerplate. You can get to pretty interesting results, as you can see.

[01:48] Keep in mind, the MTL definition overrides the texture's property, which again overrides the style's color attribute.

egghead
egghead
~ 5 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today