Skip to content

Commit

Permalink
Merge branch 'master' of github.com:playcanvas/engine
Browse files Browse the repository at this point in the history
  • Loading branch information
Maksims Mihejevs committed Nov 20, 2015
2 parents 7db8773 + 578d13d commit 944d426
Show file tree
Hide file tree
Showing 13 changed files with 130 additions and 21 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.176.1-dev
0.177.0-dev
2 changes: 1 addition & 1 deletion src/anim/anim_skeleton.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pc.extend(pc, function () {
// For each animated node...

// keys index offset
var offset = (delta > 0 ? 1 : -1);
var offset = (delta >= 0 ? 1 : -1);

for (i = 0; i < nodes.length; i++) {
node = nodes[i];
Expand Down
5 changes: 4 additions & 1 deletion src/asset/asset_asset.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ pc.extend(pc, function () {
ASSET_MATERIAL: 'material',
ASSET_TEXT: 'text',
ASSET_TEXTURE: 'texture',
ASSET_CUBEMAP: 'cubemap'
ASSET_CUBEMAP: 'cubemap',
ASSET_SHADER: 'shader',
ASSET_CSS: 'css',
ASSET_HTML: 'html'
};
}());
33 changes: 33 additions & 0 deletions src/audio/audio_sound.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,26 @@ pc.extend(pc, function () {

var Sound;

// checks if user is running IE
var ie = function () {
var ua = window.navigator.userAgent;

var msie = ua.indexOf('MSIE ');
if (msie > 0) {
// IE 10 or older => return version number
return parseInt(ua.substring(msie + 5, ua.indexOf('.', msie)), 10);
}

var trident = ua.indexOf('Trident/');
if (trident > 0) {
// IE 11 => return version number
var rv = ua.indexOf('rv:');
return parseInt(ua.substring(rv + 3, ua.indexOf('.', rv)), 10);
}

return false;
};

if (pc.AudioManager.hasAudioContext()) {
Sound = function (manager, url, success, error) {
this.buffer = null;
Expand Down Expand Up @@ -46,14 +66,27 @@ pc.extend(pc, function () {
console.warn(pc.string.format('Audio format for {0} not supported', url));
success(this);
} else {
var isIE = ie();
// audio needs to be added to the DOM for IE
if (isIE)
document.body.appendChild(this.audio);

this.audio.oncanplaythrough = function () {
// remove from DOM no longer necessary
if (isIE)
document.body.removeChild(this.audio);

if (!this.isLoaded) {
this.isLoaded = true;
success(this);
}
}.bind(this);

this.audio.onerror = function () {
// remove from DOM no longer necessary
if (isIE)
document.body.removeChild(this.audio);

// continue loading through error
success(this);
};
Expand Down
2 changes: 1 addition & 1 deletion src/framework/components/animation/animation_component.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pc.extend(pc, function () {
data.currAnim = name;

if (data.model) {
data.blending = blendTime > 0;
data.blending = blendTime > 0 && data.prevAnim;
if (data.blending) {
// Blend from the current time of the current animation to the start of
// the newly specified animation over the specified blend time period.
Expand Down
10 changes: 9 additions & 1 deletion src/framework/components/audiosource/audiosource_component.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@ pc.extend(pc, function () {
},

loadAudioSourceAssets: function (ids) {
var self = this;

var assets = ids.map(function (id) {
return this.system.app.assets.get(id);
}, this);
Expand Down Expand Up @@ -290,6 +292,9 @@ pc.extend(pc, function () {
_done();
}
});

if (! asset.resource)
this.system.app.assets.load(asset);
} else {
// don't wait for assets that aren't in the registry
count--;
Expand All @@ -299,8 +304,11 @@ pc.extend(pc, function () {
// but if they are added insert them into source list
this.system.app.assets.on("add:" + ids[index], function (asset) {
asset.ready(function (asset) {
this.data.sources[asset.name] = asset.resource;
self.data.sources[asset.name] = asset.resource;
});

if (! asset.resource)
self.system.app.assets.load(asset);
});
}
}, this);
Expand Down
5 changes: 3 additions & 2 deletions src/graphics/graphics_device.js
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,7 @@ pc.extend(pc, function () {
gl.generateMipmap(texture._glTarget);
}

if (texture._gpuSize) this._vram.tex -= texture._gpuSize;
texture._gpuSize = gpuTexSize(gl, texture);
this._vram.tex += texture._gpuSize;
},
Expand Down Expand Up @@ -1061,7 +1062,7 @@ pc.extend(pc, function () {
}

// Commit the shader program variables
textureUnit = 0;
var textureUnit = 0;
for (i = 0, len = samplers.length; i < len; i++) {
sampler = samplers[i];
samplerValue = sampler.scopeId.value;
Expand Down Expand Up @@ -1238,7 +1239,7 @@ pc.extend(pc, function () {
* @description Sets the specified render target on the device. If null
* is passed as a parameter, the back buffer becomes the current target
* for all rendering operations.
* @param {pc.RenderTarget} The render target to activate.
* @param {pc.RenderTarget} renderTarget The render target to activate.
* @example
* // Set a render target to receive all rendering output
* device.setRenderTarget(renderTarget);
Expand Down
57 changes: 45 additions & 12 deletions src/graphics/graphics_vertexformat.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,58 @@ pc.extend(pc, function () {

/**
* @name pc.VertexFormat
* @class A vertex format is a descriptor that defines the layout of vertex element data inside
* a pc.VertexBuffer object.
* @description Returns a new pc.VertexFormat object. It is constructed from a description
* that explicitly defines how data is to be laid out inside a vertex buffer (pc.VertexBuffer).
* The description is defined as an array of elements, where each element is an object with the
* following properties:
* semantic: pc.SEMANTIC_.
* components: the number of components used by the element.
* type: (pc.ELEMENTTYPE_).
* normalize: true to remap element values to a range of 0 to 1. Defaults to false.
* @class A vertex format is a descriptor that defines the layout of vertex data inside
* a {@link pc.VertexBuffer}.
* @description Returns a new pc.VertexFormat object.
* @param {pc.GraphicsDevice} graphicsDevice The graphics device used to manage this vertex format.
* @param {Object[]} description An array of vertex element descriptions.
* @param {Object[]} description An array of vertex attribute descriptions.
* @param {Number} description[].semantic The meaning of the vertex element. This is used to link
* the vertex data to a shader input. Can be:
* <ul>
* <li>pc.SEMANTIC_POSITION</li>
* <li>pc.SEMANTIC_NORMAL</li>
* <li>pc.SEMANTIC_TANGENT</li>
* <li>pc.SEMANTIC_BLENDWEIGHT</li>
* <li>pc.SEMANTIC_BLENDINDICES</li>
* <li>pc.SEMANTIC_COLOR</li>
* <li>pc.SEMANTIC_TEXCOORD0</li>
* <li>pc.SEMANTIC_TEXCOORD1</li>
* <li>pc.SEMANTIC_TEXCOORD2</li>
* <li>pc.SEMANTIC_TEXCOORD3</li>
* <li>pc.SEMANTIC_TEXCOORD4</li>
* <li>pc.SEMANTIC_TEXCOORD5</li>
* <li>pc.SEMANTIC_TEXCOORD6</li>
* <li>pc.SEMANTIC_TEXCOORD7</li>
* </ul>
* If vertex data has a meaning other that one of those listed above, use the user-defined
* semantics: pc.SEMANTIC_ATTR0 to pc.SEMANTIC_ATTR15.
* @param {Number} description[].components The number of components of the vertex attribute.
* Can be 1, 2, 3 or 4.
* @param {Number} description[].type The data type of the attribute. Can be:
* <ul>
* <li>pc.ELEMENTTYPE_INT8</li>
* <li>pc.ELEMENTTYPE_UINT8</li>
* <li>pc.ELEMENTTYPE_INT16</li>
* <li>pc.ELEMENTTYPE_UINT16</li>
* <li>pc.ELEMENTTYPE_INT32</li>
* <li>pc.ELEMENTTYPE_UINT32</li>
* <li>pc.ELEMENTTYPE_FLOAT32</li>
* </ul>
* @param {Boolean} description[].normalize If true, vertex attribute data will be mapped from a
* 0 to 255 range down to 0 to 1 when fed to a shader. If false, vertex attribute data is left
* unchanged. If this property is unspecified, false is assumed.
* @example
* // Specify 3-component positions (x, y, z)
* var vertexFormat = new pc.VertexFormat(graphicsDevice, [
* { semantic: pc.SEMANTIC_POSITION, components: 3, type: pc.ELEMENTTYPE_FLOAT32 },
* ]);
* @example
* // Specify 2-component positions (x, y), a texture coordinate (u, v) and a vertex color (r, g, b, a)
* var vertexFormat = new pc.VertexFormat(graphicsDevice, [
* { semantic: pc.SEMANTIC_POSITION, components: 2, type: pc.ELEMENTTYPE_FLOAT32 },
* { semantic: pc.SEMANTIC_TEXCOORD0, components: 2, type: pc.ELEMENTTYPE_FLOAT32 },
* { semantic: pc.SEMANTIC_COLOR, components: 4, type: pc.ELEMENTTYPE_UINT8, normalize: true }
* ]);
*
* @author Will Eastcott
*/
var VertexFormat = function (graphicsDevice, description) {
Expand Down
11 changes: 11 additions & 0 deletions src/input/input_mouse.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,13 @@ pc.extend(pc, function () {
* @param {Function} [error] Function called if the request for mouse lock is unsuccessful.
*/
enablePointerLock: function (success, error) {
if (! document.body.requestPointerLock) {
if (error)
error();

return;
}

var s = function () {
success();
document.removeEventListener('pointerlockchange', s);
Expand Down Expand Up @@ -245,6 +252,10 @@ pc.extend(pc, function () {
* @param {Function} [success] Function called when the mouse lock is disabled
*/
disablePointerLock: function (success) {
if (! document.exitPointerLock) {
return;
}

var s = function () {
success();
document.removeEventListener('pointerlockchange', s);
Expand Down
2 changes: 1 addition & 1 deletion src/resources/parser_jsonmodel.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ pc.extend(pc, function () {
indices = indices.concat(modelData.meshes[j].indices);
}
}
tangents = pc.calculateTangents(vertexData.position.data, vertexData.normal.data, vertexData.texCoord0.data, indices);
var tangents = pc.calculateTangents(vertexData.position.data, vertexData.normal.data, vertexData.texCoord0.data, indices);
vertexData.tangent = { type: "float32", components: 4, data: tangents };
}

Expand Down
1 change: 1 addition & 0 deletions src/scene/scene_forwardrenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,7 @@ pc.extend(pc, function () {

var oldTarget = camera.getRenderTarget();
camera.setRenderTarget(camera._depthTarget);
this.setCamera(camera);

var oldBlending = device.getBlending();
device.setBlending(false);
Expand Down
11 changes: 11 additions & 0 deletions src/scene/scene_material.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ pc.extend(pc, function () {
(this.blendDst === pc.BLENDMODE_SRC_COLOR) &&
(this.blendEquation === pc.BLENDEQUATION_ADD)) {
return pc.BLEND_MULTIPLICATIVE2X;
} else if ((this.blend) &&
(this.blendSrc === pc.BLENDMODE_ONE_MINUS_DST_COLOR) &&
(this.blendDst === pc.BLENDMODE_ONE) &&
(this.blendEquation === pc.BLENDEQUATION_ADD)) {
return pc.BLEND_SCREEN;
} else if ((this.blend) &&
(this.blendSrc === pc.BLENDMODE_DST_COLOR) &&
(this.blendDst === pc.BLENDMODE_ZERO) &&
Expand Down Expand Up @@ -155,6 +160,12 @@ pc.extend(pc, function () {
this.blendDst = pc.BLENDMODE_SRC_COLOR;
this.blendEquation = pc.BLENDEQUATION_ADD;
break;
case pc.BLEND_SCREEN:
this.blend = true;
this.blendSrc = pc.BLENDMODE_ONE_MINUS_DST_COLOR;
this.blendDst = pc.BLENDMODE_ONE;
this.blendEquation = pc.BLENDEQUATION_ADD;
break;
case pc.BLEND_MULTIPLICATIVE:
this.blend = true;
this.blendSrc = pc.BLENDMODE_DST_COLOR;
Expand Down
10 changes: 9 additions & 1 deletion src/scene/scene_scene.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,17 @@
/**
* @enum pc.BLEND
* @name pc.BLEND_MULTIPLICATIVE2X
* @description Same as pc.BLEND_ADDITIVE except the source RGB is multiplied by the source alpha.
* @description Multiplies colors and doubles the result
*/
BLEND_MULTIPLICATIVE2X: 7,

/**
* @enum pc.BLEND
* @name pc.BLEND_SCREEN
* @description Softer version of additive
*/
BLEND_SCREEN: 8,

/**
* @enum pc.FOG
* @name pc.FOG_NONE
Expand Down Expand Up @@ -483,6 +490,7 @@ pc.extend(pc, function () {
};
meshInstance.updateKey();
meshInstance.cull = false;
meshInstance.drawToDepth = false;

var model = new pc.Model();
model.graph = node;
Expand Down

0 comments on commit 944d426

Please sign in to comment.