diff --git a/src/core/shader/generateUniformsSync.js b/src/core/shader/generateUniformsSync.js index 21aed72..b8cdfdc 100644 --- a/src/core/shader/generateUniformsSync.js +++ b/src/core/shader/generateUniformsSync.js @@ -58,11 +58,9 @@ } else if (data.type === 'sampler2D') { - func += `\n - -if (uniforms.${i}.baseTexture) + func += `\nif (uniformValues.${i}.baseTexture) { - var location = renderer.bindTexture(uniformValues.${i}, ${textureCount++}, true); + var location = renderer.bindTexture(uniformValues.${i}.baseTexture, ${textureCount++}, true); if(uniformData.${i}.value !== location) { @@ -72,18 +70,11 @@ } else { - uniformData.${i}.value = textureCount; - renderer.boundTextures[textureCount] = renderer.emptyTextures[textureCount]; - gl.activeTexture(gl.TEXTURE0 + textureCount); + uniformData.${i}.value = ${textureCount}; + renderer.boundTextures[${textureCount}] = renderer.emptyTextures[${textureCount}]; + gl.activeTexture(gl.TEXTURE0 + ${textureCount++}); - uniforms.${i}.value.bind(); -} - var location = renderer.bindTexture(uniformValues.${i}, ${textureCount++}, true); - -if(uniformData.${i}.value !== location) -{ - uniformData.${i}.value = location; - gl.uniform1i(uniformData.${i}.location, location);\n; // eslint-disable-line max-len + uniformValues.${i}.bind(); }`; } else if (data.type === 'mat3') @@ -128,7 +119,7 @@ } // console.log(' --------------- ') - // console.log(func); + console.log(func); return new Function('uniformData', 'uniformValues', 'gl', func); // eslint-disable-line no-new-func } diff --git a/src/core/shader/generateUniformsSync.js b/src/core/shader/generateUniformsSync.js index 21aed72..b8cdfdc 100644 --- a/src/core/shader/generateUniformsSync.js +++ b/src/core/shader/generateUniformsSync.js @@ -58,11 +58,9 @@ } else if (data.type === 'sampler2D') { - func += `\n - -if (uniforms.${i}.baseTexture) + func += `\nif (uniformValues.${i}.baseTexture) { - var location = renderer.bindTexture(uniformValues.${i}, ${textureCount++}, true); + var location = renderer.bindTexture(uniformValues.${i}.baseTexture, ${textureCount++}, true); if(uniformData.${i}.value !== location) { @@ -72,18 +70,11 @@ } else { - uniformData.${i}.value = textureCount; - renderer.boundTextures[textureCount] = renderer.emptyTextures[textureCount]; - gl.activeTexture(gl.TEXTURE0 + textureCount); + uniformData.${i}.value = ${textureCount}; + renderer.boundTextures[${textureCount}] = renderer.emptyTextures[${textureCount}]; + gl.activeTexture(gl.TEXTURE0 + ${textureCount++}); - uniforms.${i}.value.bind(); -} - var location = renderer.bindTexture(uniformValues.${i}, ${textureCount++}, true); - -if(uniformData.${i}.value !== location) -{ - uniformData.${i}.value = location; - gl.uniform1i(uniformData.${i}.location, location);\n; // eslint-disable-line max-len + uniformValues.${i}.bind(); }`; } else if (data.type === 'mat3') @@ -128,7 +119,7 @@ } // console.log(' --------------- ') - // console.log(func); + console.log(func); return new Function('uniformData', 'uniformValues', 'gl', func); // eslint-disable-line no-new-func } diff --git a/src/mesh/Mesh.js b/src/mesh/Mesh.js index 5ddff24..3747883 100644 --- a/src/mesh/Mesh.js +++ b/src/mesh/Mesh.js @@ -1,5 +1,8 @@ import * as core from '../core'; +const tempPoint = new core.Point(); +const tempPolygon = new core.Polygon(); + /** * Base mesh class. * The reason for this class is to empower you to have maximum flexbilty to render any kind of webGL you can think of. @@ -33,7 +36,7 @@ /** * the geometry the mesh will use - * @type {PIXI.mesh.Geometry} + * @type {PIXI.Geometry} */ this.geometry = geometry; @@ -45,7 +48,7 @@ /** * the webGL state the mesh requires to render - * @type {PIXI.Shader} + * @type {PIXI.State} */ this.state = state || new core.State(); @@ -133,13 +136,18 @@ _calculateBounds() { // The position property could be set manually? - if (this.geometry.attributes.aVertexPosition) + if (this.geometry.style.attributes.aVertexPosition) { - const vertices = this.geometry.attributes.aVertexPosition.buffer.data; + const vertices = this.geometry.getAttribute('aVertexPosition').data; // TODO - we can cache local bounds and use them if they are dirty (like graphics) this._bounds.addVertices(this.transform, vertices, 0, vertices.length); } + else + { + return core.Rectangle.EMPTY; + } + } /** @@ -148,7 +156,43 @@ * @param point {PIXI.Point} the point to test * @return {boolean} the result of the test */ + containsPoint(point) + { + if (!this.getBounds().contains(point.x, point.y)) + { + return false; + } + this.worldTransform.applyInverse(point, tempPoint); + + const vertices = this.geometry.getAttribute('aVertexPosition').data; + + const points = tempPolygon.points; + const indices = this.geometry.getIndex().data; + const len = indices.length; + const step = this.drawMode === 4 ? 3 : 1; + + for (let i = 0; i + 2 < len; i += step) + { + const ind0 = indices[i] * 2; + const ind1 = indices[i + 1] * 2; + const ind2 = indices[i + 2] * 2; + + points[0] = vertices[ind0]; + points[1] = vertices[ind0 + 1]; + points[2] = vertices[ind1]; + points[3] = vertices[ind1 + 1]; + points[4] = vertices[ind2]; + points[5] = vertices[ind2 + 1]; + + if (tempPolygon.contains(tempPoint.x, tempPoint.y)) + { + return true; + } + } + + return false; + } } /** * Different drawing buffer modes supported diff --git a/src/core/shader/generateUniformsSync.js b/src/core/shader/generateUniformsSync.js index 21aed72..b8cdfdc 100644 --- a/src/core/shader/generateUniformsSync.js +++ b/src/core/shader/generateUniformsSync.js @@ -58,11 +58,9 @@ } else if (data.type === 'sampler2D') { - func += `\n - -if (uniforms.${i}.baseTexture) + func += `\nif (uniformValues.${i}.baseTexture) { - var location = renderer.bindTexture(uniformValues.${i}, ${textureCount++}, true); + var location = renderer.bindTexture(uniformValues.${i}.baseTexture, ${textureCount++}, true); if(uniformData.${i}.value !== location) { @@ -72,18 +70,11 @@ } else { - uniformData.${i}.value = textureCount; - renderer.boundTextures[textureCount] = renderer.emptyTextures[textureCount]; - gl.activeTexture(gl.TEXTURE0 + textureCount); + uniformData.${i}.value = ${textureCount}; + renderer.boundTextures[${textureCount}] = renderer.emptyTextures[${textureCount}]; + gl.activeTexture(gl.TEXTURE0 + ${textureCount++}); - uniforms.${i}.value.bind(); -} - var location = renderer.bindTexture(uniformValues.${i}, ${textureCount++}, true); - -if(uniformData.${i}.value !== location) -{ - uniformData.${i}.value = location; - gl.uniform1i(uniformData.${i}.location, location);\n; // eslint-disable-line max-len + uniformValues.${i}.bind(); }`; } else if (data.type === 'mat3') @@ -128,7 +119,7 @@ } // console.log(' --------------- ') - // console.log(func); + console.log(func); return new Function('uniformData', 'uniformValues', 'gl', func); // eslint-disable-line no-new-func } diff --git a/src/mesh/Mesh.js b/src/mesh/Mesh.js index 5ddff24..3747883 100644 --- a/src/mesh/Mesh.js +++ b/src/mesh/Mesh.js @@ -1,5 +1,8 @@ import * as core from '../core'; +const tempPoint = new core.Point(); +const tempPolygon = new core.Polygon(); + /** * Base mesh class. * The reason for this class is to empower you to have maximum flexbilty to render any kind of webGL you can think of. @@ -33,7 +36,7 @@ /** * the geometry the mesh will use - * @type {PIXI.mesh.Geometry} + * @type {PIXI.Geometry} */ this.geometry = geometry; @@ -45,7 +48,7 @@ /** * the webGL state the mesh requires to render - * @type {PIXI.Shader} + * @type {PIXI.State} */ this.state = state || new core.State(); @@ -133,13 +136,18 @@ _calculateBounds() { // The position property could be set manually? - if (this.geometry.attributes.aVertexPosition) + if (this.geometry.style.attributes.aVertexPosition) { - const vertices = this.geometry.attributes.aVertexPosition.buffer.data; + const vertices = this.geometry.getAttribute('aVertexPosition').data; // TODO - we can cache local bounds and use them if they are dirty (like graphics) this._bounds.addVertices(this.transform, vertices, 0, vertices.length); } + else + { + return core.Rectangle.EMPTY; + } + } /** @@ -148,7 +156,43 @@ * @param point {PIXI.Point} the point to test * @return {boolean} the result of the test */ + containsPoint(point) + { + if (!this.getBounds().contains(point.x, point.y)) + { + return false; + } + this.worldTransform.applyInverse(point, tempPoint); + + const vertices = this.geometry.getAttribute('aVertexPosition').data; + + const points = tempPolygon.points; + const indices = this.geometry.getIndex().data; + const len = indices.length; + const step = this.drawMode === 4 ? 3 : 1; + + for (let i = 0; i + 2 < len; i += step) + { + const ind0 = indices[i] * 2; + const ind1 = indices[i + 1] * 2; + const ind2 = indices[i + 2] * 2; + + points[0] = vertices[ind0]; + points[1] = vertices[ind0 + 1]; + points[2] = vertices[ind1]; + points[3] = vertices[ind1 + 1]; + points[4] = vertices[ind2]; + points[5] = vertices[ind2 + 1]; + + if (tempPolygon.contains(tempPoint.x, tempPoint.y)) + { + return true; + } + } + + return false; + } } /** * Different drawing buffer modes supported diff --git a/src/mesh/Plane.js b/src/mesh/Plane.js index 975c513..c6fafbb 100644 --- a/src/mesh/Plane.js +++ b/src/mesh/Plane.js @@ -49,7 +49,9 @@ tint: new Float32Array([1, 1, 1]), }; - super(geometry, meshShader, uniforms, 4); + super(geometry, meshShader, uniforms, null, 4); + + uniforms.translationMatrix = this.transform.worldTransform; this.texture = texture;