Skip to content

Commit

Permalink
Set tileCoord from passed vUv coordinate (topmost only)
Browse files Browse the repository at this point in the history
Gets close to proper material texturing, but not quite. Some block
faces render as expected but others have the wrong texture. Still,
closest I've gotten so far yet with greedy meshing + atlas uv + vjs..
  • Loading branch information
deathcap committed Jan 12, 2014
1 parent bf7a410 commit 4430410
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,17 @@ function Texture(game, opts) {
' vec2 tileOffset;',

// because ERROR: 0:45: '[]' : Index expression must be constant (and also, WebGL OpenGL ES 2.0 doesn't support switch/case)
' if (faceIndex == 0) tileOffset = tileOffsets[0];',
'/* if (faceIndex == 0) tileOffset = tileOffsets[0];',
' else if (faceIndex == 1) tileOffset = tileOffsets[1];',
' else if (faceIndex == 2) tileOffset = tileOffsets[2];',
' else if (faceIndex == 3) tileOffset = tileOffsets[3];',
' else if (faceIndex == 4) tileOffset = tileOffsets[4];',
' else if (faceIndex == 5) tileOffset = tileOffsets[5];',
' else if (faceIndex == 6) tileOffset = tileOffsets[6];',
' else tileOffset = tileOffsets[3];',
' else tileOffset = tileOffsets[3]; */',

' tileOffset.s = vUv.s;',
' tileOffset.t = 1.0 - vUv.t;',

' vec2 texCoord = tileOffset + tileSizeUV * fract(tileUV);',
'',
Expand Down Expand Up @@ -411,7 +414,8 @@ Texture.prototype.paint = function(mesh, materials) {
//mesh.surfaceMesh.material.materials[0].uniforms.tileOffsets.value[faceIndex] = new self.game.THREE.Vector2(atlasuv[0][0], atlasuv[0][1]);

for (var j = 0; j < mesh.geometry.faceVertexUvs[0][i].length; j++) {
mesh.geometry.faceVertexUvs[0][i][j].set(atlasuv[j][0], 1 - atlasuv[j][1]);
//mesh.geometry.faceVertexUvs[0][i][j].set(atlasuv[j][0], 1 - atlasuv[j][1]);
mesh.geometry.faceVertexUvs[0][i][j].set(topUV[0], topUV[1]); // set all to top (fixed tileSizeUV)
}
});

Expand Down

0 comments on commit 4430410

Please sign in to comment.