8000 GitHub - hlehmann/expo-three: Utilities for using THREE.js on Expo · GitHub
[go: up one dir, main page]

Skip to content
forked from expo/expo-three

About

Utilities for using THREE.js on Expo

Resources

Stars

0 stars

Watchers

0 watching

Forks

 
 

Latest commit

 

History

192 Commits

Folders and files

Repository files navigation

NPM

expo-three

Tools for using three.js to build native 3D experiences 💙

Installation

yarn add three expo-three

Usage

Import the library into your JavaScript file:

import ExpoTHREE from 'expo-three';

Get a global instance of three.js from expo-three:

import { THREE } from 'expo-three';

You can also import AR tools:

// This alias is useful cuz Expo.AR could collide.
import { AR as ThreeAR } from 'expo-three';

ExpoTHREE.AR is not the same as Expo.AR. Think of Expo.AR as a data provider for ExpoTHREE.AR to visualize.

Creating a Renderer

ExpoTHREE.Renderer({ gl: WebGLRenderingContext, width: number, height: number, pixelRatio: number, ...extras })

Given a gl from an Expo.GLView, return a THREE.WebGLRenderer that draws into it.

const renderer = new ExpoTHREE.Renderer(props);
or;
/// A legacy alias for the extended renderer
const renderer = ExpoTHREE.createRenderer(props);
// Now just code some three.js stuff and add it to this! :D

ExpoTHREE.loadAsync()

A function that will asynchronously load files based on their extension.

Notice: Remember to update your app.json to bundle obscure file types!

"packagerOpts": {
  "assetExts": [
    "dae",
    "obj",
    "mtl"
  ]
}

Props

Property Type Description
resource PossibleAsset The asset that will be parsed asynchornously
onProgress (xhr) => void A function that is called with an xhr event
assetProvider () => Promise<Expo.Asset> A function that is called whenever an unknown asset is requested
PossibleAsset Format

export type PossibleAsset = Expo.Asset | number | string | AssetFormat;

type PossibleAsset = number | string | Expo.Asset;
  • number: Static file reference require('./model.*')
  • Expo.Asset: Expo.Asset
  • string: A uri path to an asset

Returns

This returns many different things, based on the input file. For a more predictable return value you should use one of the more specific model loaders.

Example