Skip to content

Commit d98e7d5

Browse files
committed
1.3.2
Former-commit-id: d2f9b61
1 parent b005222 commit d98e7d5

18 files changed

+230
-175
lines changed

Babylon/Cameras/babylon.arcRotateCamera.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
var previousPosition;
5252
var that = this;
5353
var pointerId;
54+
55+
var engine = this._scene.getEngine();
5456

5557
this._onPointerDown = function (evt) {
5658

@@ -96,6 +98,20 @@
9698

9799
evt.preventDefault();
98100
};
101+
102+
this._onMouseMove = function (evt) {
103+
if (!engine.isPointerLock) {
104+
return;
105+
}
106+
107+
var offsetX = evt.movementX || evt.mozMovementX || evt.webkitMovementX || evt.msMovementX || 0;
108+
var offsetY = evt.movementY || evt.mozMovementY || evt.webkitMovementY || evt.msMovementY || 0;
109+
110+
that.inertialAlphaOffset -= offsetX / 1000;
111+
that.inertialBetaOffset -= offsetY / 1000;
112+
113+
evt.preventDefault();
114+
};
99115

100116
this._wheel = function(event) {
101117
var delta = 0;
@@ -165,19 +181,21 @@
165181
canvas.addEventListener(eventPrefix + "up", this._onPointerUp);
166182
canvas.addEventListener(eventPrefix + "out", this._onPointerUp);
167183
canvas.addEventListener(eventPrefix + "move", this._onPointerMove);
184+
canvas.addEventListener("mousemove", this._onMouseMove);
168185
canvas.addEventListener("MSPointerDown", this._onGestureStart);
169-
canvas.addEventListener("MSGestureChange", this._onGesture, true);
170-
window.addEventListener("keydown", this._onKeyDown, true);
171-
window.addEventListener("keyup", this._onKeyUp, true);
186+
canvas.addEventListener("MSGestureChange", this._onGesture);
187+
window.addEventListener("keydown", this._onKeyDown);
188+
window.addEventListener("keyup", this._onKeyUp);
172189
window.addEventListener('mousewheel', this._wheel);
173-
window.addEventListener("blur", this._onLostFocus, true);
190+
window.addEventListener("blur", this._onLostFocus);
174191
};
175192

176193
BABYLON.ArcRotateCamera.prototype.detachControl = function (canvas) {
177194
canvas.removeEventListener(eventPrefix + "down", this._onPointerDown);
178195
canvas.removeEventListener(eventPrefix + "up", this._onPointerUp);
179196
canvas.removeEventListener(eventPrefix + "out", this._onPointerUp);
180197
canvas.removeEventListener(eventPrefix + "move", this._onPointerMove);
198+
canvas.removeEventListener("mousemove", this._onMouseMove);
181199
canvas.removeEventListener("MSPointerDown", this._onGestureStart);
182200
canvas.removeEventListener("MSGestureChange", this._onGesture);
183201
window.removeEventListener("keydown", this._onKeyDown);

Babylon/Cameras/babylon.freeCamera.js

Lines changed: 77 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
this.ellipsoid = new BABYLON.Vector3(0.5, 1, 0.5);
1515

1616
this._keys = [];
17-
this.keysUp = [38, 87];
17+
this.keysUp = [38];
1818
this.keysDown = [40];
19-
this.keysLeft = [37, 81];
20-
this.keysRight = [39, 68];
19+
this.keysLeft = [37];
20+
this.keysRight = [39];
2121

2222
if (!scene.activeCamera) {
2323
scene.activeCamera = this;
@@ -88,91 +88,93 @@
8888
var that = this;
8989
var engine = this._scene.getEngine();
9090

91-
this._onMouseDown = function (evt) {
92-
previousPosition = {
93-
x: evt.clientX,
94-
y: evt.clientY
91+
if (this._onMouseDown === undefined) {
92+
this._onMouseDown = function (evt) {
93+
previousPosition = {
94+
x: evt.clientX,
95+
y: evt.clientY
96+
};
97+
98+
evt.preventDefault();
9599
};
96100

97-
evt.preventDefault();
98-
};
101+
this._onMouseUp = function (evt) {
102+
previousPosition = null;
103+
evt.preventDefault();
104+
};
99105

100-
this._onMouseUp = function (evt) {
101-
previousPosition = null;
102-
evt.preventDefault();
103-
};
106+
this._onMouseOut = function (evt) {
107+
previousPosition = null;
108+
that._keys = [];
109+
evt.preventDefault();
110+
};
104111

105-
this._onMouseOut = function (evt) {
106-
previousPosition = null;
107-
that._keys = [];
108-
evt.preventDefault();
109-
};
112+
this._onMouseMove = function (evt) {
113+
if (!previousPosition && !engine.isPointerLock) {
114+
return;
115+
}
110116

111-
this._onMouseMove = function (evt) {
112-
if (!previousPosition && !engine.isPointerLock) {
113-
return;
114-
}
117+
var offsetX;
118+
var offsetY;
115119

116-
var offsetX;
117-
var offsetY;
120+
if (!engine.isPointerLock) {
121+
offsetX = evt.clientX - previousPosition.x;
122+
offsetY = evt.clientY - previousPosition.y;
123+
} else {
124+
offsetX = evt.movementX || evt.mozMovementX || evt.webkitMovementX || evt.msMovementX || 0;
125+
offsetY = evt.movementY || evt.mozMovementY || evt.webkitMovementY || evt.msMovementY || 0;
126+
}
118127

119-
if (!engine.isPointerLock) {
120-
offsetX = evt.clientX - previousPosition.x;
121-
offsetY = evt.clientY - previousPosition.y;
122-
} else {
123-
offsetX = evt.movementX || evt.mozMovementX || evt.webkitMovementX || evt.msMovementX || 0;
124-
offsetY = evt.movementY || evt.mozMovementY || evt.webkitMovementY || evt.msMovementY || 0;
125-
}
128+
that.cameraRotation.y += offsetX / 2000.0;
129+
that.cameraRotation.x += offsetY / 2000.0;
126130

127-
that.cameraRotation.y += offsetX / 2000.0;
128-
that.cameraRotation.x += offsetY / 2000.0;
131+
previousPosition = {
132+
x: evt.clientX,
133+
y: evt.clientY
134+
};
135+
evt.preventDefault();
136+
};
129137

130-
previousPosition = {
131-
x: evt.clientX,
132-
y: evt.clientY
138+
this._onKeyDown = function (evt) {
139+
if (that.keysUp.indexOf(evt.keyCode) !== -1 ||
140+
that.keysDown.indexOf(evt.keyCode) !== -1 ||
141+
that.keysLeft.indexOf(evt.keyCode) !== -1 ||
142+
that.keysRight.indexOf(evt.keyCode) !== -1) {
143+
var index = that._keys.indexOf(evt.keyCode);
144+
145+
if (index === -1) {
146+
that._keys.push(evt.keyCode);
147+
}
148+
evt.preventDefault();
149+
}
133150
};
134-
evt.preventDefault();
135-
};
136-
137-
this._onKeyDown = function (evt) {
138-
if (that.keysUp.indexOf(evt.keyCode) !== -1 ||
139-
that.keysDown.indexOf(evt.keyCode) !== -1 ||
140-
that.keysLeft.indexOf(evt.keyCode) !== -1 ||
141-
that.keysRight.indexOf(evt.keyCode) !== -1) {
142-
var index = that._keys.indexOf(evt.keyCode);
143-
144-
if (index === -1) {
145-
that._keys.push(evt.keyCode);
151+
152+
this._onKeyUp = function (evt) {
153+
if (that.keysUp.indexOf(evt.keyCode) !== -1 ||
154+
that.keysDown.indexOf(evt.keyCode) !== -1 ||
155+
that.keysLeft.indexOf(evt.keyCode) !== -1 ||
156+
that.keysRight.indexOf(evt.keyCode) !== -1) {
157+
var index = that._keys.indexOf(evt.keyCode);
158+
159+
if (index >= 0) {
160+
that._keys.splice(index, 1);
161+
}
162+
evt.preventDefault();
146163
}
147-
evt.preventDefault();
148-
}
149-
};
164+
};
150165

151-
this._onKeyUp = function (evt) {
152-
if (that.keysUp.indexOf(evt.keyCode) !== -1 ||
153-
that.keysDown.indexOf(evt.keyCode) !== -1 ||
154-
that.keysLeft.indexOf(evt.keyCode) !== -1 ||
155-
that.keysRight.indexOf(evt.keyCode) !== -1) {
156-
var index = that._keys.indexOf(evt.keyCode);
166+
this._onLostFocus = function () {
167+
that._keys = [];
168+
};
169+
}
157170

158-
if (index >= 0) {
159-
that._keys.splice(index, 1);
160-
}
161-
evt.preventDefault();
162-
}
163-
};
164-
165-
this._onLostFocus = function () {
166-
that._keys = [];
167-
};
168-
169-
canvas.addEventListener("mousedown", this._onMouseDown, true);
170-
canvas.addEventListener("mouseup", this._onMouseUp, true);
171-
canvas.addEventListener("mouseout", this._onMouseOut, true);
172-
canvas.addEventListener("mousemove", this._onMouseMove, true);
173-
window.addEventListener("keydown", this._onKeyDown, true);
174-
window.addEventListener("keyup", this._onKeyUp, true);
175-
window.addEventListener("blur", this._onLostFocus, true);
171+
canvas.addEventListener("mousedown", this._onMouseDown, false);
172+
canvas.addEventListener("mouseup", this._onMouseUp, false);
173+
canvas.addEventListener("mouseout", this._onMouseOut, false);
174+
canvas.addEventListener("mousemove", this._onMouseMove, false);
175+
window.addEventListener("keydown", this._onKeyDown, false);
176+
window.addEventListener("keyup", this._onKeyUp, false);
177+
window.addEventListener("blur", this._onLostFocus, false);
176178
};
177179

178180
BABYLON.FreeCamera.prototype.detachControl = function (canvas) {

Babylon/Cameras/babylon.touchCamera.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,11 @@
9797
that._offsetY = null;
9898
};
9999

100-
canvas.addEventListener("pointerdown", this._onPointerDown, true);
101-
canvas.addEventListener("pointerup", this._onPointerUp, true);
102-
canvas.addEventListener("pointerout", this._onPointerUp, true);
103-
canvas.addEventListener("pointermove", this._onPointerMove, true);
104-
window.addEventListener("blur", this._onLostFocus, true);
100+
canvas.addEventListener("pointerdown", this._onPointerDown);
101+
canvas.addEventListener("pointerup", this._onPointerUp);
102+
canvas.addEventListener("pointerout", this._onPointerUp);
103+
canvas.addEventListener("pointermove", this._onPointerMove);
104+
window.addEventListener("blur", this._onLostFocus);
105105
};
106106

107107
BABYLON.TouchCamera.prototype.detachControl = function (canvas) {
Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,31 @@
11
var BABYLON = BABYLON || {};
22

3-
(function () {
4-
BABYLON.Octree = function () {
3+
(function() {
4+
BABYLON.Octree = function(maxBlockCapacity) {
55
this.blocks = [];
6+
this._maxBlockCapacity = maxBlockCapacity || 64;
67
this._selection = new BABYLON.Tools.SmartArray(256);
78
};
8-
9+
910
// Methods
10-
BABYLON.Octree.prototype.update = function (worldMin, worldMax, meshes) {
11-
this.blocks = [];
11+
BABYLON.Octree.prototype.update = function(worldMin, worldMax, meshes) {
12+
BABYLON.Octree._CreateBlocks(worldMin, worldMax, meshes, this._maxBlockCapacity, this);
13+
};
14+
15+
BABYLON.Octree.prototype.select = function(frustumPlanes) {
16+
this._selection.reset();
17+
18+
for (var index = 0; index < this.blocks.length; index++) {
19+
var block = this.blocks[index];
20+
block.select(frustumPlanes, this._selection);
21+
}
22+
23+
return this._selection;
24+
};
25+
26+
// Statics
27+
BABYLON.Octree._CreateBlocks = function (worldMin, worldMax, meshes, maxBlockCapacity, target) {
28+
target.blocks = [];
1229
var blockSize = new BABYLON.Vector3((worldMax.x - worldMin.x) / 2, (worldMax.y - worldMin.y) / 2, (worldMax.z - worldMin.z) / 2);
1330

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

21-
var block = new BABYLON.OctreeBlock(x, y, z, localMin, localMax);
38+
var block = new BABYLON.OctreeBlock(localMin, localMax, maxBlockCapacity);
2239
block.addEntries(meshes);
23-
this.blocks.push(block);
40+
target.blocks.push(block);
2441
}
2542
}
2643
}
2744
};
28-
29-
BABYLON.Octree.prototype.select = function (frustumPlanes) {
30-
this._selection.reset();
31-
32-
for (var index = 0; index < this.blocks.length; index++) {
33-
var block = this.blocks[index];
34-
if (block.intersects(frustumPlanes)) {
35-
this._selection.push(block);
36-
}
37-
}
38-
39-
return this._selection;
40-
};
4145
})();

Babylon/Culling/Octrees/babylon.octreeBlock.js

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
var BABYLON = BABYLON || {};
22

33
(function () {
4-
BABYLON.OctreeBlock = function (x, y, z, minPoint, maxPoint) {
4+
BABYLON.OctreeBlock = function (minPoint, maxPoint, capacity) {
55
this.subMeshes = [];
66
this.meshes = [];
7-
this.x = x;
8-
this.y = y;
9-
this.z = z;
7+
this._capacity = capacity;
108

119
this._minPoint = minPoint;
1210
this._maxPoint = maxPoint;
@@ -53,13 +51,22 @@
5351
}
5452
}
5553
}
54+
55+
if (this.subMeshes.length > this._capacity) {
56+
BABYLON.Octree._CreateBlocks(this._minPoint, this._maxPoint, this.meshes, this._capacity, this);
57+
}
5658
};
5759

58-
BABYLON.OctreeBlock.prototype.intersects = function(frustumPlanes) {
60+
BABYLON.OctreeBlock.prototype.select = function (frustumPlanes, selection) {
61+
if (this.blocks) {
62+
for (var index = 0; index < this.blocks.length; index++) {
63+
var block = this.blocks[index];
64+
block.select(frustumPlanes, selection);
65+
}
66+
return;
67+
}
5968
if (BABYLON.BoundingBox.IsInFrustrum(this._boundingVectors, frustumPlanes)) {
60-
return true;
69+
selection.push(this);
6170
}
62-
63-
return false;
6471
};
6572
})();

Babylon/Materials/babylon.effect.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,15 @@
109109
this._engine.setTexture(this._samplers.indexOf(channel), texture);
110110
};
111111

112-
BABYLON.Effect.prototype._cacheMatrix = function (uniformName, matrix) {
113-
if (!this._valueCache[uniformName]) {
114-
this._valueCache[uniformName] = new BABYLON.Matrix();
115-
}
112+
//BABYLON.Effect.prototype._cacheMatrix = function (uniformName, matrix) {
113+
// if (!this._valueCache[uniformName]) {
114+
// this._valueCache[uniformName] = new BABYLON.Matrix();
115+
// }
116116

117-
for (var index = 0; index < 16; index++) {
118-
this._valueCache[uniformName].m[index] = matrix.m[index];
119-
}
120-
};
117+
// for (var index = 0; index < 16; index++) {
118+
// this._valueCache[uniformName].m[index] = matrix.m[index];
119+
// }
120+
//};
121121

122122
BABYLON.Effect.prototype._cacheFloat2 = function (uniformName, x, y) {
123123
if (!this._valueCache[uniformName]) {
@@ -164,10 +164,10 @@
164164
};
165165

166166
BABYLON.Effect.prototype.setMatrix = function (uniformName, matrix) {
167-
if (this._valueCache[uniformName] && this._valueCache[uniformName].equals(matrix))
168-
return;
167+
//if (this._valueCache[uniformName] && this._valueCache[uniformName].equals(matrix))
168+
// return;
169169

170-
this._cacheMatrix(uniformName, matrix);
170+
//this._cacheMatrix(uniformName, matrix);
171171
this._engine.setMatrix(this.getUniform(uniformName), matrix);
172172
};
173173

0 commit comments

Comments
 (0)