Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- curGeometry.faceVertexUvs[0] = [];
- var curUV = {
- north: model.elements[i].faces.north.uv,
- east: model.elements[i].faces.east.uv,
- south: model.elements[i].faces.south.uv,
- west: model.elements[i].faces.west.uv,
- up: model.elements[i].faces.up.uv,
- down: model.elements[i].faces.down.uv
- }
- // curUV is an object containing an array of UV mapping for each face
- // Fill in any blank UV mapping sides
- for (key in curUV) {
- if (curUV[key] === undefined) {
- curUV[key] = [0, 0, 16, 16];
- }
- }
- curUVvectors = {
- north: null,
- east: null,
- south: null,
- west: null,
- up: null,
- down: null
- };
- // Divide all curUV values by 16 so it is fitted to the 1x1x1 box geometry
- var curUVsides = ['north', 'east', 'south', 'west', 'up', 'down'];
- for (var j = 0; j < curUVsides.length; j++) {
- for (var k = 0; k < curUV[curUVsides[j]].length; k++) {
- curUV[curUVsides[j]][k] = curUV[curUVsides[j]][k] / 16;
- }
- // Turn the 2 points into a 4-pointed square, with these being the corner coordinates:
- // curUV[curUVsides[j]][0 and 2] are x (u) coordinates. curUV[curUVsides[j]][1 and 3] are y (v) coordinates
- var firstCoordinate = {x: curUV[curUVsides[j]][0], y: curUV[curUVsides[j]][1]};
- var secondCoordinate = {x: curUV[curUVsides[j]][2], y: curUV[curUVsides[j]][3]};
- curUVvectors[curUVsides[j]] = [
- new THREE.Vector2(firstCoordinate.x, firstCoordinate.y),
- new THREE.Vector2(firstCoordinate.x, secondCoordinate.y),
- new THREE.Vector2(secondCoordinate.x, secondCoordinate.y),
- new THREE.Vector2(secondCoordinate.x, firstCoordinate.y)
- ]
- }
- // Apply UV mapping
- curGeometry.faceVertexUvs[0][0] = [ curUVvectors.west[0], curUVvectors.west[1], curUVvectors.west[3] ];
- curGeometry.faceVertexUvs[0][1] = [ curUVvectors.west[1], curUVvectors.west[2], curUVvectors.west[3] ];
- curGeometry.faceVertexUvs[0][2] = [ curUVvectors.east[0], curUVvectors.east[1], curUVvectors.east[3] ];
- curGeometry.faceVertexUvs[0][3] = [ curUVvectors.east[1], curUVvectors.east[2], curUVvectors.east[3] ];
- curGeometry.faceVertexUvs[0][4] = [ curUVvectors.up[0], curUVvectors.up[1], curUVvectors.up[3] ];
- curGeometry.faceVertexUvs[0][5] = [ curUVvectors.up[1], curUVvectors.up[2], curUVvectors.up[3] ];
- curGeometry.faceVertexUvs[0][6] = [ curUVvectors.down[0], curUVvectors.down[1], curUVvectors.down[3] ];
- curGeometry.faceVertexUvs[0][7] = [ curUVvectors.down[1], curUVvectors.down[2], curUVvectors.down[3] ];
- curGeometry.faceVertexUvs[0][8] = [ curUVvectors.north[0], curUVvectors.north[1], curUVvectors.north[3] ];
- curGeometry.faceVertexUvs[0][9] = [ curUVvectors.north[1], curUVvectors.north[2], curUVvectors.north[3] ];
- curGeometry.faceVertexUvs[0][10] = [ curUVvectors.south[0], curUVvectors.south[1], curUVvectors.south[3] ];
- curGeometry.faceVertexUvs[0][11] = [ curUVvectors.south[1], curUVvectors.south[2], curUVvectors.south[3] ];
Advertisement
Add Comment
Please, Sign In to add comment