Coder Social home page Coder Social logo

babylonjs / spacepiratesar Goto Github PK

View Code? Open in Web Editor NEW
19.0 7.0 3.0 24.12 MB

Space Pirates Demo with Babylon React-Native and AR.

License: MIT License

JavaScript 4.70% TypeScript 51.99% Starlark 2.10% Java 21.94% Ruby 3.58% Objective-C 15.70%

spacepiratesar's Introduction

Space Pirates AR

SpacePiratesAR

This is a sample demo for Android and iOS: Space Pirates with Babylon React-Native and AR.

Babylon React Native - Getting started with this project

This sample repo is intended to help users getting started using Babylon React Native to create cross-platform applications using BabylonJS. This project can be cloned and used as a starting point or the steps at the end can be used in order to configure a project from scratch.

1. Setup React native development environment

Follow the instructions on React Native's documentation for setting up your development environment. Be sure to select "React Native CLI quickstart" instead of "Expo CLI quickstart" since we currently do not support the usage of Expo.

2. Download

You can download source code archives from GitHub or use git to clone the repository.

> git clone https://github.com/BabylonJS/SpacePiratesAR.git

3. Project setup

From your projects folder restore the npm packages by running:

cd SpacePiratesAR
npm install

(iOS Only)

When building for iOS it will also be required to retrieve the pods for the project. Enter the iOS project folder and retreive pods.

cd ios
pod install
cd ..

(Android Emulator Only)

In order to use Babylon React Native with the Android Emulator it is required that the amulator is configure with GLES3, use the following instructions on how to set it up properly.

4. Try it out

From your projects folder you can now run the following commands to launch your project:

npm run ios
npm run android

If you want to run the application using your own devices please follow the React Native Run on Device documentation.

5. From a blank project to this demo

1. Add Permissions for AR

  • In package.json, add a new dependency :
"react-native-permissions": "^3.0.0"

For camera access on iOS, add a key in Info.plist :

...
<dict>
    <key>NSCameraUsageDescription</key>
    <string></string>
    <key>CFBundleDevelopmentRegion</key>
    ...

and add permission in the pod file:

...
target 'Playground' do
  permissions_path = '../node_modules/react-native-permissions/ios'
  pod 'Permission-Camera', :path => "#{permissions_path}/Camera"
  ...

Add Android camera and AR permission in AndroidManifest.xml :

...
<uses-permission android:name="android.permission.CAMERA"/>
...

and

...
</activity>
      <meta-data android:name="com.google.ar.core" android:value="optional" />
    </application>
...

2. Add Assets to the bundle

At the top of metro.config.js

const defaultAssetExts = require("metro-config/src/defaults/defaults").assetExts

And in exports, for glb and jpg:

resolver: {
    assetExts: [
        ...defaultAssetExts,
        'glb', 'jpg'
    ]
  }

3. Loading .glb

An asset Uri has to be resolved by the bundler. First, add resolveAssetSource import in app.tsx

import resolveAssetSource from 'react-native/Libraries/Image/resolveAssetSource';

Then, to load a glb with Babylon:

const sceneGLBUri = resolveAssetSource(require('./assets/myScene.glb')).uri;
SceneLoader.AppendAsync("", sceneGLBUri, scene).then(() => {
  ...

4. Loading .json

require will find, load and parse the json. Depending on the API used, it might be interesting to convert it back to a string. In this project, JSON are used for loading NME shaders. It can be done this way:

const starsShader = require('./assets/starfieldShader.json');
var starsShaderMaterial = new NodeMaterial("starsShader", scene);
starsShaderMaterial.loadFromSerialization(starsShader, "");
starsShaderMaterial.build();

More information

How to create this project from scratch

Additional Documentation

spacepiratesar's People

Contributors

cedricguillemet avatar cedricguillemetms avatar thomlucc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  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.