Giter Club home page Giter Club logo

babylonjs / babylon.js Goto Github PK

View Code? Open in Web Editor NEW
22.5K 542.0 3.3K 1.14 GB

Babylon.js is a powerful, beautiful, simple, and open game and rendering engine packed into a friendly JavaScript framework.

Home Page: http://www.babylonjs.com

License: Apache License 2.0

JavaScript 4.42% TypeScript 88.38% HTML 0.43% HLSL 4.06% Roff 1.24% SCSS 1.47% Batchfile 0.01%
webgl webgl2 3d game-development webvr babylon webaudio typescript webxr webgpu game-engine game-engine-3d

babylon.js's Introduction

Babylon.js

Getting started? Play directly with the Babylon.js API using our playground. It also contains a lot of samples to learn how to use it.

npm version Build Status Average time to resolve an issue Percentage of issues still open Build size Twitter Discourse users

Any questions? Here is our official forum.

CDN

โš ๏ธ WARNING: The CDN should not be used in production environments. The purpose of our CDN is to serve Babylon packages to users learning how to use the platform or running small experiments. Once you've built an application and are ready to share it with the world at large, you should serve all packages from your own CDN.

For the preview release, use the following URLs:

A list of additional references can be found here.

npm

BabylonJS and its modules are published on npm with full typing support. To install, use:

npm install babylonjs --save

alternatively, you can now rely on our ES6 packages. Using the ES6 version will allow tree shaking among other bundling benefits.

This will allow you to import BabylonJS entirely using:

import * as BABYLON from 'babylonjs';

or individual classes using:

import { Scene, Engine } from 'babylonjs';

If using TypeScript, don't forget to add 'babylonjs' to 'types' in tsconfig.json:

    ...
    "types": [
        "babylonjs",
        "anotherAwesomeDependency"
    ],
    ...

To add a module, install the respective package. A list of extra packages and their installation instructions can be found on the babylonjs user on npm.

Usage

See Getting Started:

// Get the canvas DOM element
var canvas = document.getElementById('renderCanvas');
// Load the 3D engine
var engine = new BABYLON.Engine(canvas, true, {preserveDrawingBuffer: true, stencil: true});
// CreateScene function that creates and return the scene
var createScene = function(){
    // Create a basic BJS Scene object
    var scene = new BABYLON.Scene(engine);
    // Create a FreeCamera, and set its position to {x: 0, y: 5, z: -10}
    var camera = new BABYLON.FreeCamera('camera1', new BABYLON.Vector3(0, 5, -10), scene);
    // Target the camera to scene origin
    camera.setTarget(BABYLON.Vector3.Zero());
    // Attach the camera to the canvas
    camera.attachControl(canvas, false);
    // Create a basic light, aiming 0, 1, 0 - meaning, to the sky
    var light = new BABYLON.HemisphericLight('light1', new BABYLON.Vector3(0, 1, 0), scene);
    // Create a built-in "sphere" shape using the SphereBuilder
    var sphere = BABYLON.MeshBuilder.CreateSphere('sphere1', {segments: 16, diameter: 2, sideOrientation: BABYLON.Mesh.FRONTSIDE}, scene);
    // Move the sphere upward 1/2 of its height
    sphere.position.y = 1;
    // Create a built-in "ground" shape;
    var ground = BABYLON.MeshBuilder.CreateGround("ground1", { width: 6, height: 6, subdivisions: 2, updatable: false }, scene);
    // Return the created scene
    return scene;
}
// call the createScene function
var scene = createScene();
// run the render loop
engine.runRenderLoop(function(){
    scene.render();
});
// the canvas/window resize event handler
window.addEventListener('resize', function(){
    engine.resize();
});

Contributing

If you want to contribute, please read our contribution guidelines first.

Documentation

Contributing

Please see the Contributing Guidelines.

Useful links

  • Official web site: www.babylonjs.com
  • Online playground to learn by experimentating
  • Online sandbox where you can test your .babylon and glTF scenes with a simple drag'n'drop
  • Online shader creation tool where you can learn how to create GLSL shaders
  • 3DS Max exporter can be used to generate a .babylon file from 3DS Max
  • Maya exporter can be used to generate a .babylon file from Maya
  • Blender exporter can be used to generate a .babylon file from Blender 3d
  • Unity 5 (deprecated) exporter can be used to export your geometries from Unity 5 scene editor(animations are supported)
  • glTF Tools by KhronosGroup

Features

To get a complete list of supported features, please visit our website.

babylon.js's People

Contributors

abow avatar aweirdo avatar barroij avatar bghgary avatar carolhmj avatar cedricguillemet avatar cedricguillemetms avatar craigfeldspar avatar darraghjburke avatar davrous avatar deltakosh avatar devpixelspace avatar dok11 avatar drigax avatar jbousquie avatar julien-moreau avatar kcoley avatar mackeyk24 avatar mergify[bot] avatar msdestiny14 avatar nockawa avatar picklesmcpickle avatar polygonalsun avatar popov72 avatar pryme8 avatar raananw avatar rickfromwork avatar sebavan avatar temechon avatar trevordev avatar

Stargazers

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

babylon.js's Issues

Use git tags to denote versions

Please consider utilizing git annotated tags to denote versions, so that when one talks about a specific version, writes a tutorial for a specific version etc, there is a tree in git (and on gitHub) to check the source for that very tag. Also, it allows to checkout or download a certain version.

Thanks!

re-using Sprites in a SpriteManager

Is re-using Sprites inside of a SpriteManager a planned feature? Or should I create new SpriteManager instances each time I want a Sprite with a set lifetime? Currently SpriteManagers have a set number of Sprites they could possibly hold, and no higher, even if the Sprites aren't animating or doing anything. Only the SpriteManager itself has a dispose() method. Could Sprite instances have a dispose() method as well?

For instance: let's say I want to make a SpriteManager that just shows an explosion sprite -- when an explosion happens, the game loads a new Sprite instance from the SpriteManager, and then plays the explosion animation once. Ideally, after the animation is completed, the Sprite should be disposed from the SpriteManager, freeing up one of its "slots". That way, the SpriteManager doesn't hold 100 Sprite instances total, it can only hold 100 Sprites at a time. If 101 Sprite instances are required, that's too bad. The SpriteManager can only hold 100.

Does that make sense? Is that something that can be implemented? Or is the best practice to create a new SpriteManager even if it's just for one Sprite instance that will be destroyed after being animated? Thanks!

Animation

When I was using ThreeJS, to animate objects in the scene I was writing my codes between scene.Render() and requestAnimationFrame() functions so objects were animating in each ticks. But I saw an example on wiki for animation and he's talking about "registerBeforeRender" function. Can I use my old technique or should I use the registerBeforeRender function? Is this function called just before each render operation or a totaly different thing?

Clarify difference between YawPitchRoll and EulerAngles representation?

In many places, "euler angles" is another name for "yaw pitch roll representation."
However, this code prints a surprising result:

var q1 = BABYLON.Quaternion.RotationYawPitchRoll(1, 0, 0);
var ea = q1.toEulerAngles();
console.log(ea);

Given that none of the factory functions for quaternions/matrices take Euler angles, what is the intended use of this function?

Specular emittance from directional light

Great library, I've enjoyed using it

I noticed that directional lights are implemented as point lights but with w flag used to distinguish between them in the shader code. Shouldn't the specular calculation be bypassed if it's a directional light? It's appearing in my scene in some situations.

Is there a process that you use to combine and build the minified version of babylon.js? I would be nice to make changes to the code and experiment. Do you just cat all the .js files together, and if so what happens to the shader code?

Problem with orthographic camera

Hi !

I wanted to create an orthographic camera (for a 2d view of a 3d scene) with a Camera, but I detected a little issue in Camera.getProjectionMatrix line 61 : I think this._projectionMatrix is missing as last parameter.

Moreover, I cannot have a correct orthographic camera on Y axis looking on (0,0,0). On Z axis, it works great, but the display is weird on axis X or Y. I thought the problem was in the function Matrix.OrthoOffCenterLHToRef, but I can't find it...
Can you help me ?

Skybox and collision detection not working properly

When creating a skybox as in the tutorial, applying gravity and collision detection, if the camera is placed inside the box, it will fall down to the ground and after some frames it will fall through the ground.

maybe adding inverted collision detection option will be a great thing.

and is there a way to set the maximum/minimum visible distance ? thanks

Support Float32Array in Matrix instead of Matrix.

Would be better to support typed Float32Array instead of normal one.
Check for support can be done like gl-matrix:

if(!GLMAT_ARRAY_TYPE) {
var GLMAT_ARRAY_TYPE = (typeof Float32Array !== 'undefined') ? Float32Array : Array;
}
then use new GLMAT_ARRAY_TYPE(16);

Camera movement keys

q,w,d are not well known in games for movement
prefered :
a for left 97
w for up 119
d for right 100
s for back 115

can i modify them manually without the need to edit the engine ?

Moving on local coordinates

As first, thanks for everyone in babylon to build a wonderful library, great works. I've used three.js before and now I'd like to move my projects to babylon.js. I've read all the tutorials and looked all samples in babylon web site but couldn't find any method like "translateZ" or something like that move objects to objects' local coordinates. Isn't there any build in function? How can I do that in babylon.js?

Lowercase and Unix

For cross platform compliance you should only use lowercase when naming files. I had to rename Screenshots/Heart.jpg and Scenes/heart/Heart.babylon to heart.jpg and heart.babylon before the example would load on my Ubuntu machine.

After renaming the files, everything works perfectly.

Separation between Mesh and transform Node?

In most scene graphs, we can do things like tie lights and cameras to transform nodes, the same way we tie meshes to transform nodes. However, in Babylon, the hierarchical transform math seems to be part of the Mesh class directly, and thus is not usable for camera or light instances. I think it would be useful to separate the "am I a mesh" concern from the "am I in a hierarchy" concern, and then use the latter for each separate kind of thing you want to transform -- cameras, lights, particle systems, bones, meshes, etc.

How do you build the minified version?

I noticed that Vector3 defines an "Up" static. I find this to be a bad idea in scene graphs, because there really is no reason to specify a fixed "Up" -- it's all relative to the camera (and gravity,) both of which should be configurable to fit whatever scene the developer happens to be using.
It's easy to fix the users of Vector3.Up -- cameras can default to Y but have a property for changing; billboarding should use the current camera; and geometry construction can be defined to slice spheres across the Y axis.
But, now that I've edited the .js files and the TypeScript files -- how do I build the version to include?
And how do I know whether I broke anything -- are there any unit tests?
Given that "zip" files are checked in for the tools, rather than the actual working directories, it doesn't feel like the actual development repository is what's here on GitHub?

Is there a mailing list or forum?

First, I think Babylon.js stands up great to my initial investigation. Very good job! It's the first WebGL scene graph I've tried that actually Just Worked (tm.)

When there's something I don't get, and grepping the source doesn't tell me, is there some interactive forum or mailing list where I can have more of a conversation?
The Wiki and blog tutorials are just that -- tutorials. They are not reference documentation.
When I want to know whether there is a way of creating "nulls" or "dummies" in the transform hierarchy, how do I find out about that? (Btw: Is the current answer "no" for that?)

Strange FPS drop

I Have test scene with 1000 sprites and some dummy sphere:

Changing angle of view makes FPS drop:

FPS Low:
fps_low

FPS Normal:
fps_default

next sibling?

I am trying to traverse through a hirearchical set of meshes (such as in a mechanical product) to get the mesh tree. Is there a direct way to identify the mesh that is next to the current mesh at the same level?

If not, I believe it might be a good idea to implement a nextSibling property to identify the immediate mesh after the current one in the same level. We can use this to traverse the hirearchy.

Balu

Object has no method 'createSphere'

Hello,
when I try to start a basic project with just a sphere I get following error:

Uncaught TypeError: Object function (name,vertexDeclaration,scene){this.name=name;this.id=name;this._scene=scene;this._vertexDeclaration=vertexDeclaration;this._vertexStrideSize=0;for(var index=0;index<vertexDeclaration.length;index++){this._vertexStrideSize+=vertexDeclaration[index];}this._vertexStrideSize*=4;this._totalVertices=0;this._worldMatrix=BABYLON.Matrix.Identity();scene.meshes.push(this);this.position=new BABYLON.Vector3(0,0,0);this.rotation=new BABYLON.Vector3(0,0,0);this.scaling=new BABYLON.Vector3(1,1,1);this._vertices=[];this._indices=[];this.subMeshes=[];this.animations=[];this._positions=null;this._cache={position:null,scaling:null,rotation:null};this._childrenFlag=false;} has no method 'createSphere' 

However, this example works in my browser http://www.babylonjs.com/tutorials/simple.html. I replace the main Babylon.js file from that tutorial example with the file of this repo. Conclusion the code works! It seems that exist a bug in this release babylon.1.0.1.js.

My spec:
Linux: linux mint 15 (Ubuntu 13.04)
Chrome: Version 28.0.1500.70

No clone method for Material

I can clone a Mesh and that works great. That allows me to create lots of similar meshes that are all the same. But I can't change a single cloned mesh's material without it changing the material for all cloned meshes.

Is there a better way to achieve this behavior? (Think having a red box mesh imported from Blender, then wanting to replicate it and change it to have different colors or different alpha values).

Otherwise, a clone method for a material would be very useful.

Avoid usage of canvas if already POT texture

BABYLON.Engine.prototype.createTexture always makes usage of _workingCanvas for drawing image in POT format, should be optimized by checking if image loaded from disk is already POT.

so how do you actually use applyTransform() ?

So I'm importing a model from Blender and I'm trying to covert it from Blender's right-handed coordinate system to Babylon.js's left-handed coordinate system. Doing this isn't that difficult, you just need to rotate the imported model around a lot so that its former Z axis is now along the Y axis. However, all subsequent movement of the model will need to be likewise seemingly backwards -- which is why applyTransform() should be so great. My idea is that I could import a model made in Blender, do the transforms on import, and then bake the new transforms into the mesh so that all subsequent re-positioning is using Babylon.js's coordinate system.

However, I can't figure out what applyTransform() needs to work. Looking at the code (line 479 of babylon.mesh.js) seems like it wants one argument: transform, I just can't figure out how I should format that object. Any hints?

Attempting to use empty Mesh causes _boundingInfo undefined error

Running this code (where cylinder and torus are well defined):

this.graphics = new BABYLON.Mesh("root-" + this.name, env.scene); //new BABYLON.Mesh.CreateBox("root-" + this.name, 0.1, env.scene);
this.cylinder.parent = this.graphics;
this.torus.parent = this.graphics;

I get this error on rendering:

TypeError: this._boundingInfo is undefined

From this code:

BABYLON.Mesh.prototype.isInFrustrum = function (frustumPlanes) {
    return this._boundingInfo.isInFrustrum(frustumPlanes);
};

This is when trying to use an empty Mesh as a "null" or "dummy" to slave other objects to. Creating a small box instead of the empty mesh works (but renders the box :-)

Fail to load texture on Chrome

Hello,
I follow the tutos but when it comes to load a texture on Chrome, it doesn't work and even the mesh with this texture isnt displayed.
I've tested on a local server wamp or node.js and on internet but its the same.

But it works on Firefox.

On chrome it only works to load the ball.jpg with the tuto 10.objec collisions

Here is the console on chrome for the 11.picking collision for example :

54
WebGL: INVALID_OPERATION: getUniformLocation: program not linked babylon.js:1
3
WebGL: INVALID_OPERATION: getAttribLocation: program not linked babylon.js:1
WebGL: INVALID_OPERATION: useProgram: program not valid babylon.js:1
WebGL: INVALID_OPERATION: useProgram: program not valid babylon.js:1
WebGL: INVALID_ENUM: activeTexture: texture unit out of range babylon.js:1
196
WebGL: INVALID_OPERATION: useProgram: program not valid babylon.js:1
WebGL: too many errors, no more errors will be reported to the console for this context. babylon.js:1

no errors on firefox... but its slow.

Although three.js can load texture with chrome on my local server.

Faces

First of all - This is a great initiative. It has taken the webGL fear out of a newbie like me. :).

Is there any way for me to loop through the faces of a mesh? Such as while trying to color all sides of a cube differently.
Regards,
Balu

ImportMesh freezes renderLoop

Hi, I've got a problem with using babylon,js, I have to import a lot of meshes one by one, so I use BABYLON.SceneLoader.ImportMesh in a "for" loop, I was expecting to see mesh loading one by one on my scene, but it freezes at the begining of the loop, and at the end of the loop, my scene becomes visible.
I would like to know if there is a way to do this ?

Is there an API document?

Hi,

Is there an API document?
For example i want to learn Mesh object's setVerticesData function and types of its parameters with short examples.

Thanks,

Implement rectangle mesh?

Hi, it'd be great if there was a Mesh.CreateRect() method that works like Mesh.CreateBox() but accepts width, height, depth instead of just "size". I created my own that just does CreateBox and then applies scaling to x, y, and z, but then any child mesh will be scaled the same way. Is this possible, or outside the scope of current plans? Thanks!

Camera controls takes much processing due to float32

when moving camera, rotations (x for example) keeps rolling
ex:
(if i stop moving at 1.1 if keeps increasing/decreasing like 1.111111111 .. 1.1211111111 ... 1.1221111111 till it reaches 1.19999999999)

in the main loop i am sending data (position and rotation) to a websock server and it kept detecting changes, when i checked those changes they were the rotation and position increasing/decreasing till they reach a stop. i will post the example once am home

Exporting from Blender: Y and Z axes are flipped

Hello again. I'm having a weird issue exporting models from Blender into Babylon.js -- it seems that the axes get flipped around. For example, if I make a cone in Blender and point it upwards along the Z axis, it imports into Babylon as pointing along the Y axis. Putting a sphere at (x = 0, y = 0, z = 1) in Blender results in the item importing as (x = 0, y = 1, z = 0) in Babylon.js. Is this something that could be fixed in the exporter? It looks like line 66 of io_export_babylon.py is flipping the Y and Z coordinate -- is that intentional? It seems to also be the case on lines 435 and 436, as well. Any help would be appreciated! Thanks.

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.