Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

factored out UV calculation into faceVertexUv()

  • Loading branch information...
commit e51b920abf92053da27f365fb1dc123a3f7e094a 1 parent 26bdb3f
@substack substack authored
Showing with 42 additions and 39 deletions.
  1. +42 −39 index.js
View
81 index.js
@@ -25,45 +25,7 @@ function Mesh(data, scaleFactor, mesher) {
}
for (var i = 0; i < result.faces.length; ++i) {
- var vs = [
- result.vertices[i*4+0],
- result.vertices[i*4+1],
- result.vertices[i*4+2],
- result.vertices[i*4+3]
- ]
- var size = {
- x: Math.max(
- Math.abs(vs[0][0] - vs[1][0]),
- Math.abs(vs[1][0] - vs[2][0])
- ),
- y: Math.max(
- Math.abs(vs[0][1] - vs[1][1]),
- Math.abs(vs[1][1] - vs[2][1])
- ),
- z: Math.max(
- Math.abs(vs[0][2] - vs[1][2]),
- Math.abs(vs[1][2] - vs[2][2])
- )
- }
- if (size.x === 0) {
- var width = size.z
- var height = size.y
- }
- if (size.y === 0) {
- var width = size.x
- var height = size.z
- }
- if (size.z === 0) {
- var width = size.x
- var height = size.y
- }
-
- geometry.faceVertexUvs[0].push([
- new THREE.Vector2(0, 0),
- new THREE.Vector2(0, height),
- new THREE.Vector2(width, height),
- new THREE.Vector2(width, 0)
- ])
+ geometry.faceVertexUvs[0].push(this.faceVertexUv(i))
var q = result.faces[i]
if (q.length === 5) {
@@ -120,4 +82,45 @@ Mesh.prototype.setPosition = function(x, y, z) {
if (this.wireMesh) this.wireMesh.position = new THREE.Vector3(x, y, z)
if (this.surfaceMesh) this.surfaceMesh.position = new THREE.Vector3(x, y, z)
}
+
+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 size = {
+ x: Math.max(
+ Math.abs(vs[0][0] - vs[1][0]),
+ Math.abs(vs[1][0] - vs[2][0])
+ ),
+ y: Math.max(
+ Math.abs(vs[0][1] - vs[1][1]),
+ Math.abs(vs[1][1] - vs[2][1])
+ ),
+ z: Math.max(
+ Math.abs(vs[0][2] - vs[1][2]),
+ Math.abs(vs[1][2] - vs[2][2])
+ )
+ }
+ if (size.x === 0) {
+ var width = size.z
+ var height = size.y
+ }
+ if (size.y === 0) {
+ var width = size.x
+ var height = size.z
+ }
+ if (size.z === 0) {
+ var width = size.x
+ var height = size.y
+ }
+ return [
+ new THREE.Vector2(0, 0),
+ new THREE.Vector2(0, height),
+ new THREE.Vector2(width, height),
+ new THREE.Vector2(width, 0)
+ ]
+}
;
Please sign in to comment.
Something went wrong with that request. Please try again.