Skip to content

Commit

Permalink
v1.7.0
Browse files Browse the repository at this point in the history
Former-commit-id: ca50f04
  • Loading branch information
deltakosh committed Nov 29, 2013
1 parent 93f1854 commit 73ee3e3
Show file tree
Hide file tree
Showing 94 changed files with 1,333 additions and 369 deletions.
4 changes: 3 additions & 1 deletion Babylon/Animations/babylon.animatable.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
var BABYLON = BABYLON || {};
"use strict";

var BABYLON = BABYLON || {};

(function () {
BABYLON._Animatable = function (target, from, to, loop, speedRatio, onAnimationEnd) {
Expand Down
4 changes: 3 additions & 1 deletion Babylon/Animations/babylon.animation.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
var BABYLON = BABYLON || {};
"use strict";

var BABYLON = BABYLON || {};

(function () {
BABYLON.Animation = function (name, targetProperty, framePerSecond, dataType, loopMode) {
Expand Down
4 changes: 3 additions & 1 deletion Babylon/Bones/babylon.bone.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
var BABYLON = BABYLON || {};
"use strict";

var BABYLON = BABYLON || {};

(function () {
BABYLON.Bone = function (name, skeleton, parentBone, matrix) {
Expand Down
4 changes: 3 additions & 1 deletion Babylon/Bones/babylon.skeleton.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
var BABYLON = BABYLON || {};
"use strict";

var BABYLON = BABYLON || {};

(function () {
BABYLON.Skeleton = function (name, id, scene) {
Expand Down
4 changes: 3 additions & 1 deletion Babylon/Cameras/babylon.arcRotateCamera.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
var BABYLON = BABYLON || {};
"use strict";

var BABYLON = BABYLON || {};

(function () {
var eventPrefix = BABYLON.Tools.GetPointerPrefix();
Expand Down
13 changes: 6 additions & 7 deletions Babylon/Cameras/babylon.camera.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
var BABYLON = BABYLON || {};
"use strict";

var BABYLON = BABYLON || {};

(function () {
BABYLON.Camera = function (name, position, scene) {
Expand All @@ -17,13 +19,15 @@
}

this._computedViewMatrix = BABYLON.Matrix.Identity();
this._currentRenderId = -1;

// Animations
this.animations = [];

// Postprocesses
this.postProcesses = [];

// Viewport
this.viewport = new BABYLON.Viewport(0, 0, 1.0, 1.0);
};

BABYLON.Camera.prototype = Object.create(BABYLON.Node.prototype);
Expand Down Expand Up @@ -76,12 +80,7 @@
};

BABYLON.Camera.prototype.getViewMatrix = function () {
if (this._currentRenderId == this._scene.getRenderId()) {
return this._computedViewMatrix;
}

this._computedViewMatrix = this._getViewMatrix();
this._currentRenderId = this._scene.getRenderId();

if (this.parent && this.parent.getWorldMatrix) {
if (!this._worldMatrix) {
Expand Down
4 changes: 3 additions & 1 deletion Babylon/Cameras/babylon.deviceOrientationCamera.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
var BABYLON = BABYLON || {};
"use strict";

var BABYLON = BABYLON || {};

(function () {
BABYLON.DeviceOrientationCamera = function (name, position, scene) {
Expand Down
4 changes: 3 additions & 1 deletion Babylon/Cameras/babylon.freeCamera.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
var BABYLON = BABYLON || {};
"use strict";

var BABYLON = BABYLON || {};

(function () {
BABYLON.FreeCamera = function (name, position, scene) {
Expand Down
4 changes: 3 additions & 1 deletion Babylon/Cameras/babylon.touchCamera.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
var BABYLON = BABYLON || {};
"use strict";

var BABYLON = BABYLON || {};

(function () {
BABYLON.TouchCamera = function (name, position, scene) {
Expand Down
12 changes: 12 additions & 0 deletions Babylon/Collisions/babylon.pickingInfo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
var BABYLON = BABYLON || {};

(function () {
BABYLON.PickingInfo = function () {
};

// Properties
BABYLON.PickingInfo.prototype.hit = false;
BABYLON.PickingInfo.prototype.distance = 0;
BABYLON.PickingInfo.prototype.pickedPoint = null;
BABYLON.PickingInfo.prototype.pickedMesh = null;
})();
30 changes: 30 additions & 0 deletions Babylon/LensFlare/babylon.lensFlare.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
var BABYLON = BABYLON || {};

(function () {
BABYLON.LensFlare = function (size, position, color, imgUrl, system) {
this.color = color || new BABYLON.Color3(1, 1, 1);
this.position = position;
this.size = size;
this.texture = imgUrl ? new BABYLON.Texture(imgUrl, system.getScene(), true) : null;
this._system = system;

system.lensFlares.push(this);
};

// Properties
BABYLON.LensFlare.prototype.position = 0;
BABYLON.LensFlare.prototype.size = 1.0;
BABYLON.LensFlare.prototype.texture = null;

// Methods
BABYLON.LensFlare.prototype.dispose = function() {
if (this.texture) {
this.texture.dispose();
}

// Remove from scene
var index = this._system.lensFlares.indexOf(this);
this._system.lensFlares.splice(index, 1);
};

})();
212 changes: 212 additions & 0 deletions Babylon/LensFlare/babylon.lensFlareSystem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
var BABYLON = BABYLON || {};

(function () {
BABYLON.LensFlareSystem = function (name, emitter, scene) {
this.lensFlares = [];
this._scene = scene;
this._emitter = emitter;
this.name = name;

scene.lensFlareSystems.push(this);

this.meshesSelectionPredicate = function(m) {
return m.material && m.isVisible && m.isEnabled() && m.checkCollisions;
};

// VBO
var vertices = [];
vertices.push(1, 1);
vertices.push(-1, 1);
vertices.push(-1, -1);
vertices.push(1, -1);
this._vertexDeclaration = [2];
this._vertexStrideSize = 2 * 4;
this._vertexBuffer = scene.getEngine().createVertexBuffer(vertices);

// Indices
var indices = [];
indices.push(0);
indices.push(1);
indices.push(2);

indices.push(0);
indices.push(2);
indices.push(3);

this._indexBuffer = scene.getEngine().createIndexBuffer(indices);

// Effects
this._effect = this._scene.getEngine().createEffect("lensFlare",
["position"],
["color", "viewportMatrix"],
["textureSampler"], "");
};

// Members
BABYLON.LensFlareSystem.prototype.borderLimit = 300;

// Properties
BABYLON.LensFlareSystem.prototype.getScene = function() {
return this._scene;
};

BABYLON.LensFlareSystem.prototype.getEmitterPosition = function() {
return this._emitter.getAbsolutePosition ? this._emitter.getAbsolutePosition() : this._emitter.position;
};

// Methods
BABYLON.LensFlareSystem.prototype.computeEffectivePosition = function (globalViewport) {
var position = this.getEmitterPosition();

position = BABYLON.Vector3.Project(position, BABYLON.Matrix.Identity(), this._scene.getTransformMatrix(), globalViewport);

this._positionX = position.x;
this._positionY = position.y;

position = BABYLON.Vector3.TransformCoordinates(this.getEmitterPosition(), this._scene.getViewMatrix());

if (position.z > 0) {
if ((this._positionX > globalViewport.x) && (this._positionX < globalViewport.x + globalViewport.width)) {
if ((this._positionY > globalViewport.y) && (this._positionY < globalViewport.y + globalViewport.height))
return true;
}
}

return false;
};

BABYLON.LensFlareSystem.prototype._isVisible = function () {
var emitterPosition = this.getEmitterPosition();
var direction = emitterPosition.subtract(this._scene.activeCamera.position);
var distance = direction.length();
direction.normalize();

var ray = new BABYLON.Ray(this._scene.activeCamera.position, direction);
var pickInfo = this._scene.pickWithRay(ray, this.meshesSelectionPredicate, true);

return !pickInfo.hit || pickInfo.distance > distance;
};

BABYLON.LensFlareSystem.prototype.render = function () {
if (!this._effect.isReady())
return false;

var engine = this._scene.getEngine();
var viewport = this._scene.activeCamera.viewport;
var globalViewport = viewport.toGlobal(engine);

// Position
if (!this.computeEffectivePosition(globalViewport)) {
return false;
}

// Visibility
if (!this._isVisible()) {
return false;
}

// Intensity
var awayX;
var awayY;

if (this._positionX < this.borderLimit + globalViewport.x) {
awayX = this.borderLimit + globalViewport.x - this._positionX;
} else if (this._positionX > globalViewport.x + globalViewport.width - this.borderLimit) {
awayX = this._positionX - globalViewport.x - globalViewport.width + this.borderLimit;
} else {
awayX = 0;
}

if (this._positionY < this.borderLimit + globalViewport.y) {
awayY = this.borderLimit + globalViewport.y - this._positionY;
} else if (this._positionY > globalViewport.y + globalViewport.height - this.borderLimit) {
awayY = this._positionY - globalViewport.y - globalViewport.height + this.borderLimit;
} else {
awayY = 0;
}

var away = (awayX > awayY) ? awayX : awayY;
if (away > this.borderLimit) {
away = this.borderLimit;
}

var intensity = 1.0 - (away / this.borderLimit);
if (intensity < 0) {
return false;
}

if (intensity > 1.0) {
intensity = 1.0;
}

// Position
var centerX = globalViewport.x + globalViewport.width / 2;
var centerY = globalViewport.y + globalViewport.height / 2;
var distX = centerX - this._positionX;
var distY = centerY - this._positionY;

// Effects
engine.enableEffect(this._effect);
engine.setState(false);
engine.setDepthBuffer(false);
engine.setAlphaMode(BABYLON.Engine.ALPHA_ADD);

// VBOs
engine.bindBuffers(this._vertexBuffer, this._indexBuffer, this._vertexDeclaration, this._vertexStrideSize, this._effect);

// Flares
for (var index = 0; index < this.lensFlares.length; index++) {
var flare = this.lensFlares[index];

var x = centerX - (distX * flare.position);
var y = centerY - (distY * flare.position);

var cw = flare.size;
var ch = flare.size * engine.getAspectRatio();
var cx = 2 * (x / globalViewport.width) - 1.0;
var cy = 1.0 - 2 * (y / globalViewport.height);

var viewportMatrix = BABYLON.Matrix.FromValues(
cw / 2, 0, 0, 0,
0, ch / 2, 0, 0,
0, 0, 1, 0,
cx, cy, 0, 1);

this._effect.setMatrix("viewportMatrix", viewportMatrix);

// Texture
this._effect.setTexture("textureSampler", flare.texture);

// Color
this._effect.setFloat4("color", flare.color.r * intensity, flare.color.g * intensity, flare.color.b * intensity, 1.0);

// Draw order
engine.draw(true, 0, 6);
}

engine.setDepthBuffer(true);
engine.setAlphaMode(BABYLON.Engine.ALPHA_DISABLE);
return true;
};

BABYLON.LensFlareSystem.prototype.dispose = function () {
if (this._vertexBuffer) {
this._scene.getEngine()._releaseBuffer(this._vertexBuffer);
this._vertexBuffer = null;
}

if (this._indexBuffer) {
this._scene.getEngine()._releaseBuffer(this._indexBuffer);
this._indexBuffer = null;
}

while (this.lensFlares.length) {
this.lensFlares[0].dispose();
}

// Remove from scene
var index = this._scene.lensFlareSystems.indexOf(this);
this._scene.lensFlareSystems.splice(index, 1);
};

})();
3 changes: 3 additions & 0 deletions Babylon/Lights/babylon.light.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

// Animations
this.animations = [];

// Exclusions
this.excludedMeshes = [];
};

BABYLON.Light.prototype = Object.create(BABYLON.Node.prototype);
Expand Down
8 changes: 8 additions & 0 deletions Babylon/Materials/babylon.standardMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@
continue;
}

if (mesh && light.excludedMeshes.indexOf(mesh) !== -1) {
continue;
}

defines.push("#define LIGHT" + lightIndex);

if (lightIndex > 0) {
Expand Down Expand Up @@ -347,6 +351,10 @@
if (!light.isEnabled()) {
continue;
}

if (mesh && light.excludedMeshes.indexOf(mesh) !== -1) {
continue;
}

if (light instanceof BABYLON.PointLight) {
// Point Light
Expand Down
Loading

0 comments on commit 73ee3e3

Please sign in to comment.