Skip to content

Commit

Permalink
1.3.2
Browse files Browse the repository at this point in the history
Former-commit-id: d2f9b61
  • Loading branch information
deltakosh committed Aug 21, 2013
1 parent b005222 commit d98e7d5
Show file tree
Hide file tree
Showing 18 changed files with 230 additions and 175 deletions.
26 changes: 22 additions & 4 deletions Babylon/Cameras/babylon.arcRotateCamera.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
var previousPosition;
var that = this;
var pointerId;

var engine = this._scene.getEngine();

this._onPointerDown = function (evt) {

Expand Down Expand Up @@ -96,6 +98,20 @@

evt.preventDefault();
};

this._onMouseMove = function (evt) {
if (!engine.isPointerLock) {
return;
}

var offsetX = evt.movementX || evt.mozMovementX || evt.webkitMovementX || evt.msMovementX || 0;
var offsetY = evt.movementY || evt.mozMovementY || evt.webkitMovementY || evt.msMovementY || 0;

that.inertialAlphaOffset -= offsetX / 1000;
that.inertialBetaOffset -= offsetY / 1000;

evt.preventDefault();
};

this._wheel = function(event) {
var delta = 0;
Expand Down Expand Up @@ -165,19 +181,21 @@
canvas.addEventListener(eventPrefix + "up", this._onPointerUp);
canvas.addEventListener(eventPrefix + "out", this._onPointerUp);
canvas.addEventListener(eventPrefix + "move", this._onPointerMove);
canvas.addEventListener("mousemove", this._onMouseMove);
canvas.addEventListener("MSPointerDown", this._onGestureStart);
canvas.addEventListener("MSGestureChange", this._onGesture, true);
window.addEventListener("keydown", this._onKeyDown, true);
window.addEventListener("keyup", this._onKeyUp, true);
canvas.addEventListener("MSGestureChange", this._onGesture);
window.addEventListener("keydown", this._onKeyDown);
window.addEventListener("keyup", this._onKeyUp);
window.addEventListener('mousewheel', this._wheel);
window.addEventListener("blur", this._onLostFocus, true);
window.addEventListener("blur", this._onLostFocus);
};

BABYLON.ArcRotateCamera.prototype.detachControl = function (canvas) {
canvas.removeEventListener(eventPrefix + "down", this._onPointerDown);
canvas.removeEventListener(eventPrefix + "up", this._onPointerUp);
canvas.removeEventListener(eventPrefix + "out", this._onPointerUp);
canvas.removeEventListener(eventPrefix + "move", this._onPointerMove);
canvas.removeEventListener("mousemove", this._onMouseMove);
canvas.removeEventListener("MSPointerDown", this._onGestureStart);
canvas.removeEventListener("MSGestureChange", this._onGesture);
window.removeEventListener("keydown", this._onKeyDown);
Expand Down
152 changes: 77 additions & 75 deletions Babylon/Cameras/babylon.freeCamera.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
this.ellipsoid = new BABYLON.Vector3(0.5, 1, 0.5);

this._keys = [];
this.keysUp = [38, 87];
this.keysUp = [38];
this.keysDown = [40];
this.keysLeft = [37, 81];
this.keysRight = [39, 68];
this.keysLeft = [37];
this.keysRight = [39];

if (!scene.activeCamera) {
scene.activeCamera = this;
Expand Down Expand Up @@ -88,91 +88,93 @@
var that = this;
var engine = this._scene.getEngine();

this._onMouseDown = function (evt) {
previousPosition = {
x: evt.clientX,
y: evt.clientY
if (this._onMouseDown === undefined) {
this._onMouseDown = function (evt) {
previousPosition = {
x: evt.clientX,
y: evt.clientY
};

evt.preventDefault();
};

evt.preventDefault();
};
this._onMouseUp = function (evt) {
previousPosition = null;
evt.preventDefault();
};

this._onMouseUp = function (evt) {
previousPosition = null;
evt.preventDefault();
};
this._onMouseOut = function (evt) {
previousPosition = null;
that._keys = [];
evt.preventDefault();
};

this._onMouseOut = function (evt) {
previousPosition = null;
that._keys = [];
evt.preventDefault();
};
this._onMouseMove = function (evt) {
if (!previousPosition && !engine.isPointerLock) {
return;
}

this._onMouseMove = function (evt) {
if (!previousPosition && !engine.isPointerLock) {
return;
}
var offsetX;
var offsetY;

var offsetX;
var offsetY;
if (!engine.isPointerLock) {
offsetX = evt.clientX - previousPosition.x;
offsetY = evt.clientY - previousPosition.y;
} else {
offsetX = evt.movementX || evt.mozMovementX || evt.webkitMovementX || evt.msMovementX || 0;
offsetY = evt.movementY || evt.mozMovementY || evt.webkitMovementY || evt.msMovementY || 0;
}

if (!engine.isPointerLock) {
offsetX = evt.clientX - previousPosition.x;
offsetY = evt.clientY - previousPosition.y;
} else {
offsetX = evt.movementX || evt.mozMovementX || evt.webkitMovementX || evt.msMovementX || 0;
offsetY = evt.movementY || evt.mozMovementY || evt.webkitMovementY || evt.msMovementY || 0;
}
that.cameraRotation.y += offsetX / 2000.0;
that.cameraRotation.x += offsetY / 2000.0;

that.cameraRotation.y += offsetX / 2000.0;
that.cameraRotation.x += offsetY / 2000.0;
previousPosition = {
x: evt.clientX,
y: evt.clientY
};
evt.preventDefault();
};

previousPosition = {
x: evt.clientX,
y: evt.clientY
this._onKeyDown = function (evt) {
if (that.keysUp.indexOf(evt.keyCode) !== -1 ||
that.keysDown.indexOf(evt.keyCode) !== -1 ||
that.keysLeft.indexOf(evt.keyCode) !== -1 ||
that.keysRight.indexOf(evt.keyCode) !== -1) {
var index = that._keys.indexOf(evt.keyCode);

if (index === -1) {
that._keys.push(evt.keyCode);
}
evt.preventDefault();
}
};
evt.preventDefault();
};

this._onKeyDown = function (evt) {
if (that.keysUp.indexOf(evt.keyCode) !== -1 ||
that.keysDown.indexOf(evt.keyCode) !== -1 ||
that.keysLeft.indexOf(evt.keyCode) !== -1 ||
that.keysRight.indexOf(evt.keyCode) !== -1) {
var index = that._keys.indexOf(evt.keyCode);

if (index === -1) {
that._keys.push(evt.keyCode);

this._onKeyUp = function (evt) {
if (that.keysUp.indexOf(evt.keyCode) !== -1 ||
that.keysDown.indexOf(evt.keyCode) !== -1 ||
that.keysLeft.indexOf(evt.keyCode) !== -1 ||
that.keysRight.indexOf(evt.keyCode) !== -1) {
var index = that._keys.indexOf(evt.keyCode);

if (index >= 0) {
that._keys.splice(index, 1);
}
evt.preventDefault();
}
evt.preventDefault();
}
};
};

this._onKeyUp = function (evt) {
if (that.keysUp.indexOf(evt.keyCode) !== -1 ||
that.keysDown.indexOf(evt.keyCode) !== -1 ||
that.keysLeft.indexOf(evt.keyCode) !== -1 ||
that.keysRight.indexOf(evt.keyCode) !== -1) {
var index = that._keys.indexOf(evt.keyCode);
this._onLostFocus = function () {
that._keys = [];
};
}

if (index >= 0) {
that._keys.splice(index, 1);
}
evt.preventDefault();
}
};

this._onLostFocus = function () {
that._keys = [];
};

canvas.addEventListener("mousedown", this._onMouseDown, true);
canvas.addEventListener("mouseup", this._onMouseUp, true);
canvas.addEventListener("mouseout", this._onMouseOut, true);
canvas.addEventListener("mousemove", this._onMouseMove, true);
window.addEventListener("keydown", this._onKeyDown, true);
window.addEventListener("keyup", this._onKeyUp, true);
window.addEventListener("blur", this._onLostFocus, true);
canvas.addEventListener("mousedown", this._onMouseDown, false);
canvas.addEventListener("mouseup", this._onMouseUp, false);
canvas.addEventListener("mouseout", this._onMouseOut, false);
canvas.addEventListener("mousemove", this._onMouseMove, false);
window.addEventListener("keydown", this._onKeyDown, false);
window.addEventListener("keyup", this._onKeyUp, false);
window.addEventListener("blur", this._onLostFocus, false);
};

BABYLON.FreeCamera.prototype.detachControl = function (canvas) {
Expand Down
10 changes: 5 additions & 5 deletions Babylon/Cameras/babylon.touchCamera.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@
that._offsetY = null;
};

canvas.addEventListener("pointerdown", this._onPointerDown, true);
canvas.addEventListener("pointerup", this._onPointerUp, true);
canvas.addEventListener("pointerout", this._onPointerUp, true);
canvas.addEventListener("pointermove", this._onPointerMove, true);
window.addEventListener("blur", this._onLostFocus, true);
canvas.addEventListener("pointerdown", this._onPointerDown);
canvas.addEventListener("pointerup", this._onPointerUp);
canvas.addEventListener("pointerout", this._onPointerUp);
canvas.addEventListener("pointermove", this._onPointerMove);
window.addEventListener("blur", this._onLostFocus);
};

BABYLON.TouchCamera.prototype.detachControl = function (canvas) {
Expand Down
44 changes: 24 additions & 20 deletions Babylon/Culling/Octrees/babylon.octree.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
var BABYLON = BABYLON || {};

(function () {
BABYLON.Octree = function () {
(function() {
BABYLON.Octree = function(maxBlockCapacity) {
this.blocks = [];
this._maxBlockCapacity = maxBlockCapacity || 64;
this._selection = new BABYLON.Tools.SmartArray(256);
};

// Methods
BABYLON.Octree.prototype.update = function (worldMin, worldMax, meshes) {
this.blocks = [];
BABYLON.Octree.prototype.update = function(worldMin, worldMax, meshes) {
BABYLON.Octree._CreateBlocks(worldMin, worldMax, meshes, this._maxBlockCapacity, this);
};

BABYLON.Octree.prototype.select = function(frustumPlanes) {
this._selection.reset();

for (var index = 0; index < this.blocks.length; index++) {
var block = this.blocks[index];
block.select(frustumPlanes, this._selection);
}

return this._selection;
};

// Statics
BABYLON.Octree._CreateBlocks = function (worldMin, worldMax, meshes, maxBlockCapacity, target) {
target.blocks = [];
var blockSize = new BABYLON.Vector3((worldMax.x - worldMin.x) / 2, (worldMax.y - worldMin.y) / 2, (worldMax.z - worldMin.z) / 2);

// Segmenting space
Expand All @@ -18,24 +35,11 @@
var localMin = worldMin.add(blockSize.multiplyByFloats(x, y, z));
var localMax = worldMin.add(blockSize.multiplyByFloats(x + 1, y + 1, z + 1));

var block = new BABYLON.OctreeBlock(x, y, z, localMin, localMax);
var block = new BABYLON.OctreeBlock(localMin, localMax, maxBlockCapacity);
block.addEntries(meshes);
this.blocks.push(block);
target.blocks.push(block);
}
}
}
};

BABYLON.Octree.prototype.select = function (frustumPlanes) {
this._selection.reset();

for (var index = 0; index < this.blocks.length; index++) {
var block = this.blocks[index];
if (block.intersects(frustumPlanes)) {
this._selection.push(block);
}
}

return this._selection;
};
})();
23 changes: 15 additions & 8 deletions Babylon/Culling/Octrees/babylon.octreeBlock.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
var BABYLON = BABYLON || {};

(function () {
BABYLON.OctreeBlock = function (x, y, z, minPoint, maxPoint) {
BABYLON.OctreeBlock = function (minPoint, maxPoint, capacity) {
this.subMeshes = [];
this.meshes = [];
this.x = x;
this.y = y;
this.z = z;
this._capacity = capacity;

this._minPoint = minPoint;
this._maxPoint = maxPoint;
Expand Down Expand Up @@ -53,13 +51,22 @@
}
}
}

if (this.subMeshes.length > this._capacity) {
BABYLON.Octree._CreateBlocks(this._minPoint, this._maxPoint, this.meshes, this._capacity, this);
}
};

BABYLON.OctreeBlock.prototype.intersects = function(frustumPlanes) {
BABYLON.OctreeBlock.prototype.select = function (frustumPlanes, selection) {
if (this.blocks) {
for (var index = 0; index < this.blocks.length; index++) {
var block = this.blocks[index];
block.select(frustumPlanes, selection);
}
return;
}
if (BABYLON.BoundingBox.IsInFrustrum(this._boundingVectors, frustumPlanes)) {
return true;
selection.push(this);
}

return false;
};
})();
22 changes: 11 additions & 11 deletions Babylon/Materials/babylon.effect.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,15 @@
this._engine.setTexture(this._samplers.indexOf(channel), texture);
};

BABYLON.Effect.prototype._cacheMatrix = function (uniformName, matrix) {
if (!this._valueCache[uniformName]) {
this._valueCache[uniformName] = new BABYLON.Matrix();
}
//BABYLON.Effect.prototype._cacheMatrix = function (uniformName, matrix) {
// if (!this._valueCache[uniformName]) {
// this._valueCache[uniformName] = new BABYLON.Matrix();
// }

for (var index = 0; index < 16; index++) {
this._valueCache[uniformName].m[index] = matrix.m[index];
}
};
// for (var index = 0; index < 16; index++) {
// this._valueCache[uniformName].m[index] = matrix.m[index];
// }
//};

BABYLON.Effect.prototype._cacheFloat2 = function (uniformName, x, y) {
if (!this._valueCache[uniformName]) {
Expand Down Expand Up @@ -164,10 +164,10 @@
};

BABYLON.Effect.prototype.setMatrix = function (uniformName, matrix) {
if (this._valueCache[uniformName] && this._valueCache[uniformName].equals(matrix))
return;
//if (this._valueCache[uniformName] && this._valueCache[uniformName].equals(matrix))
// return;

this._cacheMatrix(uniformName, matrix);
//this._cacheMatrix(uniformName, matrix);
this._engine.setMatrix(this.getUniform(uniformName), matrix);
};

Expand Down
Loading

0 comments on commit d98e7d5

Please sign in to comment.