Skip to content

Instantly share code, notes, and snippets.

@shama
Created January 30, 2013 23:02
Show Gist options
  • Save shama/4678149 to your computer and use it in GitHub Desktop.
Save shama/4678149 to your computer and use it in GitHub Desktop.
rotate uv 90 degs for front and left
Mesh.prototype.faceVertexUv = function(i) {
var vs = [
this.meshed.vertices[i*4+0],
this.meshed.vertices[i*4+1],
this.meshed.vertices[i*4+2],
this.meshed.vertices[i*4+3]
]
var spans = {
x0: vs[0][0] - vs[1][0],
x1: vs[1][0] - vs[2][0],
y0: vs[0][1] - vs[1][1],
y1: vs[1][1] - vs[2][1],
z0: vs[0][2] - vs[1][2],
z1: vs[1][2] - vs[2][2]
}
var size = {
x: Math.max(Math.abs(spans.x0), Math.abs(spans.x1)),
y: Math.max(Math.abs(spans.y0), Math.abs(spans.y1)),
z: Math.max(Math.abs(spans.z0), Math.abs(spans.z1))
}
if (size.x === 0) {
if (spans.y0 > spans.y1) {
// left
var width = size.y
var height = size.z
}
else {
var width = size.z
var height = size.y
}
}
if (size.y === 0) {
if (spans.x0 > spans.x1) {
var width = size.x
var height = size.z
}
else {
var width = size.z
var height = size.x
}
}
if (size.z === 0) {
if (spans.x0 > spans.x1) {
var width = size.x
var height = size.y
}
else {
// front
var width = size.y
var height = size.x
}
}
if ((size.z === 0 && spans.x0 < spans.x1) || (size.x === 0 && spans.y0 > spans.y1)) {
return [
new THREE.Vector2(width, 0),
new THREE.Vector2(0, 0),
new THREE.Vector2(0, height),
new THREE.Vector2(width, height)
]
} else {
return [
new THREE.Vector2(0, 0),
new THREE.Vector2(0, height),
new THREE.Vector2(width, height),
new THREE.Vector2(width, 0)
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment