diff --git a/src/mesh/Mesh.js b/src/mesh/Mesh.js index 8b277d8..718d6e0 100644 --- a/src/mesh/Mesh.js +++ b/src/mesh/Mesh.js @@ -187,8 +187,8 @@ Mesh.prototype._renderCanvasDrawTriangle = function (context, vertices, uvs, index0, index1, index2) { var textureSource = this.texture.baseTexture.source; - var textureWidth = this.texture.width; - var textureHeight = this.texture.height; + var textureWidth = this.texture.baseTexture.width; + var textureHeight = this.texture.baseTexture.height; var x0 = vertices[index0], x1 = vertices[index1], x2 = vertices[index2]; var y0 = vertices[index0 + 1], y1 = vertices[index1 + 1], y2 = vertices[index2 + 1]; diff --git a/src/mesh/Mesh.js b/src/mesh/Mesh.js index 8b277d8..718d6e0 100644 --- a/src/mesh/Mesh.js +++ b/src/mesh/Mesh.js @@ -187,8 +187,8 @@ Mesh.prototype._renderCanvasDrawTriangle = function (context, vertices, uvs, index0, index1, index2) { var textureSource = this.texture.baseTexture.source; - var textureWidth = this.texture.width; - var textureHeight = this.texture.height; + var textureWidth = this.texture.baseTexture.width; + var textureHeight = this.texture.baseTexture.height; var x0 = vertices[index0], x1 = vertices[index1], x2 = vertices[index2]; var y0 = vertices[index0 + 1], y1 = vertices[index1 + 1], y2 = vertices[index2 + 1]; diff --git a/src/mesh/Rope.js b/src/mesh/Rope.js index f3224de..630ed5f 100644 --- a/src/mesh/Rope.js +++ b/src/mesh/Rope.js @@ -1,4 +1,5 @@ var Mesh = require('./Mesh'); +var core = require('../core'); /** * The rope allows you to draw a texture across several points and them manipulate these points @@ -73,12 +74,14 @@ var indices = this.indices; var colors = this.colors; - // this.count -= 0.2; + var textureUvs = this._getTextureUvs(); + var offset = new core.math.Point(textureUvs.x0, textureUvs.y0); + var factor = new core.math.Point(textureUvs.x2 - textureUvs.x0, textureUvs.y2 - textureUvs.y0); - uvs[0] = 0; - uvs[1] = 0; - uvs[2] = 0; - uvs[3] = 1; + uvs[0] = 0 + offset.x; + uvs[1] = 0 + offset.y; + uvs[2] = 0 + offset.x; + uvs[3] = 1 * factor.y + offset.y; colors[0] = 1; colors[1] = 1; @@ -96,22 +99,11 @@ // time to do some smart drawing! amount = i / (total-1); - if (i%2) - { - uvs[index] = amount; - uvs[index+1] = 0; + uvs[index] = amount * factor.x + offset.x; + uvs[index+1] = 0 + offset.y; - uvs[index+2] = amount; - uvs[index+3] = 1; - } - else - { - uvs[index] = amount; - uvs[index+1] = 0; - - uvs[index+2] = amount; - uvs[index+3] = 1; - } + uvs[index+2] = amount * factor.x + offset.x; + uvs[index+3] = 1 * factor.y + offset.y; index = i * 2; colors[index] = 1; @@ -124,6 +116,34 @@ }; /* + * Returns texture UVs + * + * @private + */ + +Rope.prototype._getTextureUvs = function() +{ + if(!this._textureUvs) + { + this._textureUvs = new core.TextureUvs(); + this._textureUvs.set(this.texture.crop, this.texture.baseTexture, this.texture.rotate); + } + return this._textureUvs; +}; + +/* + * Clear texture UVs when new texture is set + * + * @private + */ + +Rope.prototype.onTextureUpdate = function () +{ + this._textureUvs = null; + Mesh.prototype.onTextureUpdate.call(this); +}; + +/* * Updates the object transform for rendering * * @private