Skip to content

Commit

Permalink
Merge pull request #148 from playcanvas/master
Browse files Browse the repository at this point in the history
m
  • Loading branch information
guycalledfrank committed Dec 9, 2015
2 parents 3e160f1 + 56042fb commit 4d16de6
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 5 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.178.2-dev
0.179.0-dev
8 changes: 8 additions & 0 deletions src/audio/audio_channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ pc.extend(pc, function () {
this.manager.on('volumechange', this.onManagerVolumeChange, this);
this.manager.on('suspend', this.onManagerSuspend, this);
this.manager.on('resume', this.onManagerResume, this);

// suspend immediately if manager is suspended
if (this.manager.suspended)
this.onManagerSuspend();
},

/**
Expand Down Expand Up @@ -227,6 +231,10 @@ pc.extend(pc, function () {
this.manager.on('suspend', this.onManagerSuspend, this);
this.manager.on('resume', this.onManagerResume, this);

// suspend immediately if manager is suspended
if (this.manager.suspended)
this.onManagerSuspend();

},

pause: function () {
Expand Down
5 changes: 5 additions & 0 deletions src/audio/audio_channel3d.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ pc.extend(pc, function () {
this.source.connect(this.panner);
this.panner.connect(this.gain);
this.gain.connect(context.destination);

if (!this.loop) {
// mark source as paused when it ends
this.source.onended = this.pause.bind(this);
}
}
});
} else if (pc.AudioManager.hasAudio()) {
Expand Down
12 changes: 12 additions & 0 deletions src/framework/components/audiosource/audiosource_component.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,19 @@ pc.extend(pc, function () {
onSet3d: function (name, oldValue, newValue) {
if (oldValue !== newValue) {
if (this.system.initialized && this.currentSource) {
var paused = false;
var suspended = false;
if (this.channel) {
paused = this.channel.paused;
suspended = this.channel.suspended;
}

this.play(this.currentSource);

if (this.channel) {
this.channel.paused = paused;
this.channel.suspended = suspended;
}
}
}
},
Expand Down
10 changes: 9 additions & 1 deletion src/framework/components/script/script_component.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,16 @@ pc.extend(pc, function () {
var i, len;
var cached = [];

var prefix = this.system._prefix || "";
var regex = /^http(s)?:\/\//i;

for (i = 0, len = urls.length; i < len; i++) {
var type = this.system.app.loader.getFromCache(urls[i]);
var url = urls[i];
if (! regex.test(url)) {
url = pc.path.join(prefix, url);
}

var type = this.system.app.loader.getFromCache(url, 'script');

// if we cannot find the script in the cache then return and load
// all scripts with the resource loader
Expand Down
20 changes: 17 additions & 3 deletions src/scene/scene_mesh.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ pc.extend(pc, function () {
if (!this.mesh.boneAabb) {

this.mesh.boneAabb = [];
this.mesh.boneUsed = [];
var elems = this.mesh.vertexBuffer.format.elements;
var numVerts = this.mesh.vertexBuffer.numVertices;
var vertSize = this.mesh.vertexBuffer.format.size;
Expand All @@ -167,6 +168,7 @@ pc.extend(pc, function () {
var x, y, z;
var boneMin = [];
var boneMax = [];
var boneUsed = this.mesh.boneUsed;

for(i=0; i<numBones; i++) {
boneMin[i] = new pc.Vec3(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
Expand All @@ -192,6 +194,8 @@ pc.extend(pc, function () {
if (bMax.x < x) bMax.x = x;
if (bMax.y < y) bMax.y = y;
if (bMax.z < z) bMax.z = z;

boneUsed[index] = true;
}
}
}
Expand All @@ -211,15 +215,25 @@ pc.extend(pc, function () {
this._boneAabb[i] = new pc.BoundingBox();
}
}

var boneUsed = this.mesh.boneUsed;

// Update per-instance bone AABBs
for(i=0; i<this.mesh.boneAabb.length; i++) {
if (!boneUsed[i]) continue;
this._boneAabb[i].setFromTransformedAabb(this.mesh.boneAabb[i], this.skinInstance.matrices[i]);
}
// Update full instance AABB
this._aabb.center.copy(this._boneAabb[0].center);
this._aabb.halfExtents.copy(this._boneAabb[0].halfExtents);
var first = true;
for(i=0; i<this.mesh.boneAabb.length; i++) {
this._aabb.add(this._boneAabb[i]);
if (!boneUsed[i]) continue;
if (first) {
this._aabb.center.copy(this._boneAabb[i].center);
this._aabb.halfExtents.copy(this._boneAabb[i].halfExtents);
first = false;
} else {
this._aabb.add(this._boneAabb[i]);
}
}
} else {
this._aabb.setFromTransformedAabb(this.mesh.aabb, this.node.worldTransform);
Expand Down

0 comments on commit 4d16de6

Please sign in to comment.