Skip to content

Commit

Permalink
Merge pull request #1 from BabylonJS/master
Browse files Browse the repository at this point in the history
refreshing fork
  • Loading branch information
jahow committed Mar 20, 2015
2 parents fa47717 + 2817094 commit 185c5f7
Show file tree
Hide file tree
Showing 135 changed files with 7,659 additions and 2,593 deletions.
5 changes: 5 additions & 0 deletions Babylon/Animations/babylon.animatable.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions Babylon/Animations/babylon.animatable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
var animation = animations[index];

animation._target = target;
this._animations.push(animation);
}
this._animations.push(animation);
}
}

public getAnimationByTargetProperty(property: string) {
Expand Down Expand Up @@ -87,6 +87,12 @@
running = running || isRunning;
}

if (!running) {
// Remove from active animatables
index = this._scene._activeAnimatables.indexOf(this);
this._scene._activeAnimatables.splice(index, 1);
}

if (!running && this.onAnimationEnd) {
this.onAnimationEnd();
}
Expand Down
10 changes: 8 additions & 2 deletions Babylon/Animations/babylon.animation.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions Babylon/Animations/babylon.animation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,16 @@

this.currentFrame = currentFrame;

for (var key = 0; key < this._keys.length; key++) {
// for each frame, we need the key just before the frame superior
// Try to get a hash to find the right key
var startKey = Math.max(0, Math.min(this._keys.length - 1, Math.floor(this._keys.length * (currentFrame - this._keys[0].frame) / (this._keys[this._keys.length - 1].frame - this._keys[0].frame)) - 1));

if (this._keys[startKey].frame >= currentFrame) {
while (startKey - 1 >= 0 && this._keys[startKey].frame >= currentFrame) {
startKey--;
}
}

for (var key = startKey; key < this._keys.length ; key++) {
if (this._keys[key + 1].frame >= currentFrame) {

var startValue = this._getKeyValue(this._keys[key].value);
Expand Down
2 changes: 1 addition & 1 deletion Babylon/Audio/babylon.audioEngine.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 20 additions & 14 deletions Babylon/Audio/babylon.sound.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 21 additions & 15 deletions Babylon/Audio/babylon.sound.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
public rolloffFactor: number = 1;
public maxDistance: number = 100;
public distanceModel: string = "linear";
public panningModel: string = "HRTF";
private _panningModel: string = "equalpower";
public onended: () => any;
private _playbackRate: number = 1;
private _startTime: number = 0;
Expand Down Expand Up @@ -73,7 +73,6 @@
this.rolloffFactor = options.rolloffFactor || 1;
this.refDistance = options.refDistance || 1;
this.distanceModel = options.distanceModel || "linear";
this.panningModel = options.panningModel || "HRTF";
this._playbackRate = options.playbackRate || 1;
}

Expand All @@ -90,7 +89,7 @@
if (urlOrArrayBuffer) {
// If it's an URL
if (typeof (urlOrArrayBuffer) === "string") {
Tools.LoadFile(urlOrArrayBuffer,(data) => { this._soundLoaded(data); }, null, null, true);
Tools.LoadFile(urlOrArrayBuffer, (data) => { this._soundLoaded(data); }, null, null, true);
}
else {
if (urlOrArrayBuffer instanceof ArrayBuffer) {
Expand All @@ -109,6 +108,9 @@
BABYLON.Tools.Error("Web Audio is not supported by your browser.");
Engine.audioEngine.WarnedWebAudioUnsupported = true;
}
if (this._readyToPlayCallback) {
this._readyToPlayCallback();
}
}
}

Expand Down Expand Up @@ -170,13 +172,15 @@
this.rolloffFactor = options.rolloffFactor || this.rolloffFactor;
this.refDistance = options.refDistance || this.refDistance;
this.distanceModel = options.distanceModel || this.distanceModel;
this.panningModel = options.panningModel || this.panningModel;
this._playbackRate = options.playbackRate || this._playbackRate;
}
}

private _createSpatialParameters() {
if (Engine.audioEngine.canUseWebAudio) {
if (this._scene.headphone) {
this._panningModel = "HRTF";
}
this._soundPanner = Engine.audioEngine.audioContext.createPanner();

if (this.useCustomAttenuation) {
Expand All @@ -185,31 +189,33 @@
this._soundPanner.maxDistance = Number.MAX_VALUE;
this._soundPanner.refDistance = 1;
this._soundPanner.rolloffFactor = 1;
this._soundPanner.panningModel = "HRTF";
this._soundPanner.panningModel = this._panningModel;
}
else {
this._soundPanner.distanceModel = this.distanceModel;
this._soundPanner.maxDistance = this.maxDistance;
this._soundPanner.refDistance = this.refDistance;
this._soundPanner.rolloffFactor = this.rolloffFactor;
this._soundPanner.panningModel = this.panningModel;
this._soundPanner.panningModel = this._panningModel;
}
this._soundPanner.connect(this._ouputAudioNode);
this._inputAudioNode = this._soundPanner;
}
}

public switchPanningModelToHRTF() {
this._switchPanningModel("HRTF");
this._panningModel = "HRTF";
this._switchPanningModel();
}

public switchPanningModelToEqualPower() {
this._switchPanningModel("equalpower");
this._panningModel = "equalpower";
this._switchPanningModel();
}

private _switchPanningModel(newModel: string) {
private _switchPanningModel() {
if (Engine.audioEngine.canUseWebAudio && this.spatialSound) {
this._soundPanner.panningModel = newModel;
this._soundPanner.panningModel = this._panningModel;
}
}

Expand Down Expand Up @@ -245,15 +251,15 @@
public setPosition(newPosition: Vector3) {
this._position = newPosition;

if (this.isPlaying && this.spatialSound) {
if (Engine.audioEngine.canUseWebAudio && this.spatialSound) {
this._soundPanner.setPosition(this._position.x, this._position.y, this._position.z);
}
}

public setLocalDirectionToMesh(newLocalDirection: Vector3) {
this._localDirection = newLocalDirection;

if (this._connectedMesh && this.isPlaying) {
if (Engine.audioEngine.canUseWebAudio && this._connectedMesh && this.isPlaying) {
this._updateDirection();
}
}
Expand All @@ -266,7 +272,7 @@
}

public updateDistanceFromListener() {
if (this._connectedMesh && this.useCustomAttenuation) {
if (Engine.audioEngine.canUseWebAudio && this._connectedMesh && this.useCustomAttenuation) {
var distance = this._connectedMesh.getDistanceToCamera(this._scene.activeCamera);
this._soundGain.gain.value = this._customAttenuationFunction(this._volume, distance, this.maxDistance, this.refDistance, this.rolloffFactor);
}
Expand Down Expand Up @@ -345,7 +351,7 @@
}

public setVolume(newVolume: number, time?: number) {
if (Engine.audioEngine.canUseWebAudio) {
if (Engine.audioEngine.canUseWebAudio && !this.spatialSound) {
if (time) {
this._soundGain.gain.linearRampToValueAtTime(this._volume, Engine.audioEngine.audioContext.currentTime);
this._soundGain.gain.linearRampToValueAtTime(newVolume, time);
Expand Down Expand Up @@ -385,7 +391,7 @@

private _onRegisterAfterWorldMatrixUpdate(connectedMesh: AbstractMesh) {
this.setPosition(connectedMesh.getBoundingInfo().boundingSphere.centerWorld);
if (this._isDirectional && this.isPlaying) {
if (Engine.audioEngine.canUseWebAudio && this._isDirectional && this.isPlaying) {
this._updateDirection();
}
}
Expand Down
Loading

0 comments on commit 185c5f7

Please sign in to comment.