Browse Source

Merge pull request #691 from jbousquie/master

added faceUV option in CreateBox
David Catuhe 10 years ago
parent
commit
60315fde1b
1 changed files with 12 additions and 5 deletions
  1. 12 5
      src/Mesh/babylon.mesh.vertexData.ts

+ 12 - 5
src/Mesh/babylon.mesh.vertexData.ts

@@ -574,7 +574,7 @@
             return vertexData;
         }
 
-        public static CreateBox(options: { width?: number, height?: number, depth?: number, sideOrientation?: number }): VertexData;
+        public static CreateBox(options: { width?: number, height?: number, depth?: number, faceUV?: Vector4[], sideOrientation?: number }): VertexData;
         public static CreateBox(size: number, sideOrientation?: number): VertexData;
         public static CreateBox(options: any, sideOrientation: number = Mesh.DEFAULTSIDE): VertexData {
             var normalsSource = [
@@ -594,6 +594,7 @@
             var width = 1;
             var height = 1;
             var depth = 1;
+            var faceUV: Vector4[] = options.faceUV || new Array<Vector4>(6);
 
             if (options.width !== undefined) {
                 width = options.width || 1;
@@ -605,6 +606,12 @@
                 depth = options || 1;
             }
 
+            for (var f = 0; f < 6; f++) {
+                if (faceUV[f] === undefined) {
+                    faceUV[f] = new Vector4(0, 0, 1, 1);
+                }
+            }
+
             sideOrientation = sideOrientation || options.sideOrientation || Mesh.DEFAULTSIDE;
 
             var scaleVector = new Vector3(width / 2, height / 2, depth / 2);
@@ -631,22 +638,22 @@
                 var vertex = normal.subtract(side1).subtract(side2).multiply(scaleVector);
                 positions.push(vertex.x, vertex.y, vertex.z);
                 normals.push(normal.x, normal.y, normal.z);
-                uvs.push(1.0, 1.0);
+                uvs.push(faceUV[index].z, faceUV[index].w);
 
                 vertex = normal.subtract(side1).add(side2).multiply(scaleVector);
                 positions.push(vertex.x, vertex.y, vertex.z);
                 normals.push(normal.x, normal.y, normal.z);
-                uvs.push(0.0, 1.0);
+                uvs.push(faceUV[index].x, faceUV[index].w);
 
                 vertex = normal.add(side1).add(side2).multiply(scaleVector);
                 positions.push(vertex.x, vertex.y, vertex.z);
                 normals.push(normal.x, normal.y, normal.z);
-                uvs.push(0.0, 0.0);
+                uvs.push(faceUV[index].x, faceUV[index].y);
 
                 vertex = normal.add(side1).subtract(side2).multiply(scaleVector);
                 positions.push(vertex.x, vertex.y, vertex.z);
                 normals.push(normal.x, normal.y, normal.z);
-                uvs.push(1.0, 0.0);
+                uvs.push(faceUV[index].z, faceUV[index].y);
             }
 
             // sides