Skip to content
This repository has been archived by the owner on Feb 13, 2021. It is now read-only.

Commit

Permalink
Moved reactjs added iconic
Browse files Browse the repository at this point in the history
  • Loading branch information
Cubees committed Oct 31, 2017
1 parent 05c96c1 commit ced79cc
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 19 deletions.
40 changes: 36 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,44 @@ Are YAML meta description for files, this is used to make some link between the

Wherever you find these, please don't touch them :)

### Add a new content
Categories classify the content, it is implemented and can be seen in:
### New Content
Categories classify the content.

#### Categories

* Babylon101 - This is an introductory course for Babylon.js that takes users on a step by step journey through many basic features of the Babylon engine. Links on each page takes the reader to extra or related details. This means that although the course can be followed in a linear fashion it is not restricted to being read in this way. The idea is that this heading will stand by itself with no further sub sections.

* How To - Usually this will consist of sub sections that descibe with words, pictures, examples and playgrounds how to contribute, apply or use a feature of the Babylon engine. For consistency use titles that complete a sentence starting How to ....

* Features - These list and describe the features available with the Babylon.js system, that is the engine, extensions and any other resources that provide support for it and its use. Generally descriptions will be brief with lins to more detail. However there will be occasions when descriptions need to wander into `how to` territory to ensure clarity of understanding.

* Extensions - This section provides details on user written code which extend Babylon.js and have to be loaded in addition to Babylon.js. Such code is found in the [extensions](https://github.com/BabylonJS/Extensions) repository.

* Resources - These provide additional areas of support for Babylon.js and include
* Reference - Useful information or summary
* Editor - An editor specificlly designed for Babylon.js
* Manual - Technical details about Babylon.js or a feature that are not strictly necessary in learning how to apply or use a feature but provide extra understanding.
* Exporter - An external 3D application that allows files to be saved in a way that they can be loaded into a Babylon.js project.
* Library - An external application that can be integrated with Babylon.js.

Within descriptions in the resources section there will be details of how to apply and use features of a resource. This is different to the 'How to..' section which is limited to Babylon.js itself.

* Samples - Small project examples or useful functions.


They are implemented and can be seen in:
* [Babylon 101](http://doc.babylonjs.com/babylon101)
* [How To](http://doc.babylonjs.com/How_To)
* [Features](http://doc.babylonjs.com/features)
* [resources](http://doc.babylonjs.com/resources)
* [extensions](http://doc.babylonjs.com/extensions)
* [samples](http://doc.babylonjs.com/samples)

If you want to add your own:

1. Head to the root of How To, features, resources or extensions or How_To
### Adding Content
If you want to add your own content:

1. Head to the root of How To, features, resources, samples or extensions or How_To
2. Create a new folder (or use an existing one)
3. Fill it with your markdown
4. Head to data/statics.json
Expand All @@ -90,6 +118,10 @@ If you want to add your own:
7. Pull request :)






#### statics.json structure

The three root arrays are mandatory, when displayed, object's order is kept.
Expand Down
73 changes: 73 additions & 0 deletions content/resources/Library/BabylonJS_and_Ionic_Angular.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# BabylonJS in an Ionic Angular app.
## A brief example showing how to use BabylonJS in an Ionic 2 application ##

For anyone interested, it is posible to integrate BabylonJS in an Ionic/Cordova app in just a few easy steps. The following is just a narrative of how I did it, since it's been a trial and error thing probably there'll be a better way of doing it, when in doubt I've gone for simplicity rather than optimisation.

## What you need

First, you need node/npm installed. For more on that look [here](https://nodejs.org/en/).

Second, and quite obviously, a working Ionic environment. How to do this is very well documented by the Ionic people so, if you haven't done it before have a look [there](https://ionicframework.com/docs/intro/tutorial/).

## The process

1) Start a new Ionic project, I used the blank template, which provides a basic scaffolding, and removed all unnecessary stuff.

2) Then, install BabylonJS within the project:
```bash
npm install babylonjs@2.5.0 --save
```
>A couple things to remember:
> * Be careful not to write babylon (different package, yes it happened to me!).
> * Specify version, otherwise npm will install the preview branch and things will fall apart at runtime!
3) Go to the last line of babylon.d.ts (in node_modules/babylonjs/dist) and type:

```typescript
export = BABYLON;
```
>These last two steps will create the proper entry in the node_modules folder and will let you do:
> ```typescript
>import BABYLON from 'babylonjs'
>```
>wherever you need to.
4) Depending of what you intend to do in your app, other dependencies might be needed (e.g. cannon.js or hand.js)
You could install them the same way as BabylonJS, but I just downloaded the javascript files, saved them in the www folder and referenced using script tags in `index.html`. However, this has a downside, the www folder is generated after transpiling, so you will need to add those javascript files **manually**.


5) After this I generated an Angular [Provider](https://docs.angularjs.org/guide/providers), this is a singleton class that will wrap our BabylonJS Engine:
```bash
ionic g provider BabylonJS
```
>Besides holding our Engine instance, being in a provider allows for different pages to access the same Engine, e.g. you define different scenes in different pages and use the same Engine provider for all.
6) Another provider (ConfigProvider) is created to handle all necessary configuration variables. In this case it just contains the dice colors and texture for both dice.
> Actually, when you look at it, a Provider is a regular typescript class, nothing really special apart from the **@Injectable** decorator, which tells Angular that this is a special class to be injected during the bootstrap process to make it available to the hierarchy of components that make an app.
7) The very basic configuration interface is an Ionic page showing the available options. Note the header, a basic Ionic component that handles the back button automatically.
All the values are stored in the Config service, that makes them available to any page that declares a dependency to the Config provider.

8) The Home page will contain the BabylonJS canvas. An Ionic page is basically an Angular component with some sugar added, mainly in the form of a few helpful life cycle hooks.
The whole scene is created here, note that we are using the two providers that were previously generated.
The ViewChild decorator is needed in order to have access to the canvas element, think of it as an Angular equivalent of good old 'document.getElementById' method.

## A few notes on the code

The app itself is a very basic no frills dice roller, but there are a few things worth mentioning:
* We are using Ionic components to provide a basic user interface, with a header and a couple FAB buttons to access the configuration screen and roll the dice. See the methods handling the button events.
* The Home page code makes use of `ionViewDidLoad` and `ionViewWillEnter`, both are Ionic hooks to the page life cycle. The first fires only once, when the view loads, so it is ideal to initialize variables and generate the scene proper.
The second fires every time the view is going to become active, it checks for possible changes in the configuration and modifies the vertex data to point to the correct coordinates if necessary.
* Ionic, by default, caches the views. so anything included in the `ionViewDidLoad` hook will run only once, so the methods createScene() and animate() are called only once. Caching can be disabled, in that case this method will fire every time the view is loaded, and the scene will be generated as new.

## Conclusion

Integrating BabylonJS in an Ionic application was easier than it seemed at first, once you get to know a couple of thing of how Ionic/Angular 2 works. In fact, doing the same in an Ionic 1 app was easy too, but overall everything looks cleaner, more streamlined in the latest version.
However, despite the improvements introduced to Angular, the overhead of having both Ionic and BabylonJS together might make performance a bit sluggish. Maybe it's not the best way of implementing a pure 3d action packed game.
On the other hand, with Ionic you get things, like a very simple way of handling the user interface, navigation and storage out of the box, not to mention that, through Cordova, it's easy to build apps for any mobile platform, so it might be the way to go for less demanding apps.

Finally, this is how the app looks running on an actual Android 6.0 device:

![](/img/How_To/ionic-angular/screenshot1.jpg)
![](/img/How_To/ionic-angular/screenshot2.jpg)
![](/img/How_To/ionic-angular/screenshot3.jpg)
2 changes: 2 additions & 0 deletions content/resources/Reference/Documentation_Category_Map.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@
[Increasing Facets, Snippet](/samples/Increasing_Facets)
[Incremental Loading](/How_To/Using_the_Incremental_Loading_System)
[Instances](/How_To/How_to_use_Instances)
[Ionic Angular](/resources/BabylonJS_and_Ionic_Angular)
********
<a name = "L">**L**</a><span style = "float:right">[top](#top)</span>

Expand Down Expand Up @@ -263,6 +264,7 @@
[Radial Cloner](/extensions/RadialCloner)
[Random Effector, Cloner](/extensions/RandomEffector)
[Raycasts](/babylon101/Raycasts)
[Reactjs](/resources/BabylonJS_and_ReactJS)
[Reflection Material](/How_To/Reflect#reflection)
[Reflection Probes](/How_To/How_to_use_Reflection_probes)
[Refraction, Material](/How_To/Reflec#refractiont)
Expand Down
26 changes: 15 additions & 11 deletions data/statics.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,17 +124,6 @@
}
]
},
{
"title": "Reactjs",
"name": "reactjs",
"desc": "How to use Babylon.js with ReactJS",
"files": [
{
"title": "How to use Babylon.js with ReactJS",
"filename": "BabylonJS_and_ReactJS"
}
]
},
{
"title": "Scene",
"name": "scene",
Expand Down Expand Up @@ -759,6 +748,21 @@
}
]
},
{
"title": "Library",
"name": "Library",
"desc": "External Application for Integration with BJS",
"files": [
{
"title": "How to use BabylonJS in an Ionic Angular app",
"filename": "BabylonJS_and_Ionic_Angular"
},
{
"title": "How to use Babylon.js with ReactJS",
"filename": "BabylonJS_and_ReactJS"
}
]
},
{
"title": "Exporter",
"name": "Exporter",
Expand Down
3 changes: 3 additions & 0 deletions log/bjs-doc-error.log
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@
{"level":"error","message":"404 Error - /exporters","timestamp":"2017-10-26T09:20:31.351Z"}
{"level":"error","message":"404 Error - /toturials/","timestamp":"2017-10-26T09:21:23.411Z"}
{"level":"error","message":"404 Error - /tutorials/","timestamp":"2017-10-26T09:21:36.433Z"}
{"level":"error","message":"404 Error - /img/tutorials/ionic-angular/screenshot1.jpg","timestamp":"2017-10-31T12:08:47.646Z"}
{"level":"error","message":"404 Error - /img/tutorials/ionic-angular/screenshot2.jpg","timestamp":"2017-10-31T12:08:49.077Z"}
{"level":"error","message":"404 Error - /img/tutorials/ionic-angular/screenshot3.jpg","timestamp":"2017-10-31T12:08:49.493Z"}
6 changes: 4 additions & 2 deletions public/html/_redirects
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,10 @@
/generals/how_to_start /How_To/how_to_start
/generals/setup_visualStudio /How_To/setup_visualStudio

/features/Solid_Particle_System /how_to/solid_particle_system
/extensions/Physically_Based_Rendering /how_to/physically_based_rendering
/features/Solid_Particle_System /How_To/solid_particle_system
/extensions/Physically_Based_Rendering /How_To/physically_based_rendering

/How_To/BabylonJS_and_ReactJS /resources/BabylonJS_and_ReactJS



4 changes: 2 additions & 2 deletions public/html/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
// and now the rest
categories.forEach(function (cat) {
var numOfFiles = files.filter(function (f) { return f.version === cat }).length;
html += '<div class="basicFilter disabled" data-version="' + cat + '"><span>' + cat + '</span><span>(' + numOfFiles + ')</span></div>';
html += '<div class="basicFilter disabled" data-version="' + cat + '"><span>' + cat.replace(/_/, " ") + '</span><span>(' + numOfFiles + ')</span></div>';
});

html += '</div>';
Expand All @@ -80,7 +80,7 @@
html += '<div class="result" data-version="' + f.version + '">';
html += '<div class="resultTitle">';

html += '<a href="' + f.src + '">' + f.version + ' : ' + f.name + '</a>';
html += '<a href="' + f.src + '">' + f.version.replace(/_/, " ") + ' : ' + f.name + '</a>';

html += '</div>';
html += '</div>';
Expand Down

0 comments on commit ced79cc

Please sign in to comment.