Skip to content

Commit

Permalink
Merge pull request #2 from playcanvas/master
Browse files Browse the repository at this point in the history
update myself
  • Loading branch information
guycalledfrank committed Oct 16, 2014
2 parents 1159f89 + bc9fa28 commit 3d0a26d
Show file tree
Hide file tree
Showing 13 changed files with 331 additions and 227 deletions.
21 changes: 21 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,27 @@
PlayCanvas Runtime Changes
--------------------------

--------
v0.157.4
--------
* [FIX] pc.math.Quat#slerp now works for opposite quaternions.

--------
v0.157.3
--------
* [FIX] Replace canvas.style.width with canvas.style.clientWidth.

--------
v0.157.2
--------
* [FIX] Mouse tests.

--------
v0.157.0
--------
* [FIX] Fullscreen in Chrome - ignored keyboard input.
* [FIX] Mouse now attach events on window but data is related to target.

--------
v0.156.2
--------
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.157.0-dev
0.158.0-dev
2 changes: 1 addition & 1 deletion examples/particle_system/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
scaleGraph: scaleCurve,
angleGraph: angleCurve,
colorGraph: colorCurve,
textureAsset: result.asset
texture: result.resource
});
});

Expand Down
4 changes: 2 additions & 2 deletions src/framework/components/camera/camera_component.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ pc.extend(pc.fw, function () {
*/
screenToWorld: function (x, y, z, worldCoord) {
var device = this.system.context.graphicsDevice;
var width = parseInt(device.canvas.style.width);
var height = parseInt(device.canvas.style.height);
var width = parseInt(device.canvas.clientWidth);
var height = parseInt(device.canvas.clientHeight);
return this.data.camera.screenToWorld(x, y, z, width, height, worldCoord);
},

Expand Down
97 changes: 81 additions & 16 deletions src/framework/components/particlesystem/particlesystem_component.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
pc.extend(pc.fw, function() {

// if a property name is in this array then when that property changes
// we don't need to rebuild the emitter.
//
// 'rate' and 'lifetime' properties are better reflected after rebuild
// 'stretch' and 'wrapBounds' properties can be changed in realtime but not turned on/off, so let's just rebuild

var NO_REBUILD_PROPERTIES = [
'spawnBounds',
'speedDiv',
'constantSpeedDiv',
'texture',
'normalTexture'
];

var ParticleSystemComponent = function ParticleSystemComponent(system, entity) {
this.on("set", this.onSetParam, this);
};
Expand All @@ -11,17 +26,69 @@ pc.extend(pc.fw, function() {
return;
}

if (this.emitter) {
this.emitter[name] = newValue; // some parameters can apply immediately
var texturePropertyName;

if (name === 'textureAsset') {
texturePropertyName = 'texture';
} else if (name === 'normalTextureAsset') {
texturePropertyName = 'normalTexture';
}

if (texturePropertyName) {
if (newValue) {
var asset = (newValue instanceof pc.asset.Asset ? newValue : this.system.context.assets.getAssetById(newValue));
if (!asset) {
logERROR(pc.string.format('Trying to load particle system before asset {0} is loaded.', newValue));
return;
}

// try to load the cached asset first
var texture;
if (asset.resource) {
texture = asset.resource;
this.data[texturePropertyName] = texture;

if (name === "oneShot") {
this.emitter.resetTime();
if (this.emitter) {
this.emitter[texturePropertyName] = texture;
this.emitter.resetMaterial();
}
} else {
// texture is not in cache so load it dynamically
var options = {
parent: this.entity.getRequest()
};

this.system.context.assets.load(newValue, [], options).then(function (resources) {
texture = resources[0].resource;
this.data[texturePropertyName] = texture;
if (this.emitter) {
this.emitter[texturePropertyName] = texture;
this.emitter.resetMaterial();
}
}.bind(this));
}
} else {
this.emitter.resetMaterial(); // some may require resetting shader constants
// no asset so clear texture property
this.data[texturePropertyName] = null;
if (this.emitter) {
this.emitter[texturePropertyName] = null;
this.emitter.resetMaterial();
}
}

} else {

if (this.emitter) {
this.emitter[name] = newValue;

if (name === "oneShot") {
this.emitter.resetTime();
} else {
this.emitter.resetMaterial(); // some may require resetting shader constants

if ((name !== "spawnBounds") && (name !== "speedDiv") // && (name!="rate") && (name!="lifetime") // these params are better reflected after rebuild
&& (name !== "constantSpeedDiv")) { // && (name!="stretch") && (name!="wrapBounds")) { // stretch and wrapBounds can be changed realtime, but not turned on/off, so let's just rebuild
this.rebuild();
if (NO_REBUILD_PROPERTIES.indexOf(name) < 0) {
this.rebuild();
}
}
}
}
Expand All @@ -48,8 +115,6 @@ pc.extend(pc.fw, function() {
alphaDivGraph: this.data.alphaDivGraph,
texture: this.data.texture,
normalTexture: this.data.normalTexture,
textureAsset: this.data.textureAsset,
normalTextureAsset: this.data.normalTextureAsset,
oneShot: this.data.oneShot,
speedDiv: this.data.speedDiv,
constantSpeedDiv: this.data.constantSpeedDiv,
Expand All @@ -75,11 +140,10 @@ pc.extend(pc.fw, function() {
this.data.model = this.psys;
this.emitter.psys = this.psys;

var comp = this;
this.emitter.onFinished = function() { // called after oneShot emitter is finished. As you can dynamically change oneShot parameter, it should be always initialized
comp.enabled = false; // should call onDisable internally
comp.data.enabled = false;
};
// called after oneShot emitter is finished. As you can dynamically change oneShot parameter, it should be always initialized
this.emitter.onFinished = function() {
this.enabled = false;
}.bind(this);
}


Expand Down Expand Up @@ -107,11 +171,12 @@ pc.extend(pc.fw, function() {
},

rebuild: function() {
var enabled = this.enabled;
this.enabled = false;
this.emitter.rebuild(); // worst case: required to rebuild buffers/shaders
this.emitter.meshInstance.node = this.entity;
this.data.model.meshInstances = [this.emitter.meshInstance];
this.enabled = true;
this.enabled = enabled;
},
});

Expand Down
2 changes: 1 addition & 1 deletion src/framework/framework_application.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ pc.extend(pc.fw, function () {
if (error) {
document.addEventListener('fullscreenerror', e, false);
}
element.requestFullscreen();
element.requestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
},

/**
Expand Down
2 changes: 1 addition & 1 deletion src/input/input_keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ pc.extend(pc.input, function(){
this._keymap = {};
this._lastmap = {};

if(element) {
if (element) {
this.attach(element);
}

Expand Down

0 comments on commit 3d0a26d

Please sign in to comment.