void f3(int a, int b, int c, Shape shape, bool isBottom, int shapesOffset, WorldUVGenerator uvgen, Option options) { a += shapesOffset; b += shapesOffset; c += shapesOffset; // normal, color, material Face3 face; if (faceIndex >= faces.Count) { face = new Face3(a, b, c); this.faces.Add(face); } else { face = faces[faceIndex]; face.a = a; face.b = b; face.c = c; } faceIndex++; TubeGeometry.FrenetFrames splineTube = options.frames; Vector3 normal; if (splineTube != null) { int stepIndex = isBottom ? 0 : splineTube.tangents.Count - 1; normal = splineTube.tangents[stepIndex] * (isBottom ? -1 : 1); } else { normal = (isBottom ? -1 : 1) * Vector3.forward; } face.vertexNormals = new Vector3[] { normal, normal, normal }; List <Vector2> uvs = isBottom ? uvgen.generateBottomUV(this, shape, a, b, c) : uvgen.generateTopUV(this, shape, a, b, c); face.uvs = uvs.ToArray(); // TODO: faceVertexUvs の変更で問題点ないか確認 // if(faceIndex-1 >= faceVertexUvs.Count){ // this.faceVertexUvs.Add( new List<Vector2>( uvs )); // }else{ // this.faceVertexUvs[faceIndex - 1] = new List<Vector2>( uvs ); // } // //this.faceVertexUvs.Add( new List<Vector2>( new Vector2[]{ Vector2.one, Vector2.one, Vector2.one } )); // Debug }
void f4(int a, int b, int c, int d, Shape shape, List <Vector3> wallContour, int stepIndex, int stepsLength, int contourIndex1, int contourIndex2, int shapesOffset, WorldUVGenerator uvgen, Option options, bool reverse, Quaternion tQ0, Quaternion tQ1) { a += shapesOffset; b += shapesOffset; c += shapesOffset; d += shapesOffset; List <Vector2> uvs = uvgen.generateSideWallUV(this, shape, wallContour, a, b, c, d, stepIndex, stepsLength, contourIndex1, contourIndex2); Face3 face0; if (faceIndex >= faces.Count) { face0 = new Face3(a, b, d); this.faces.Add(face0); } else { face0 = faces[faceIndex]; face0.a = a; face0.b = b; face0.c = d; } face0.uvs = new Vector2[] { uvs[0], uvs[1], uvs[3] }; faceIndex++; Face3 face1; if (faceIndex >= faces.Count) { face1 = new Face3(b, c, d); this.faces.Add(face1); } else { face1 = faces[faceIndex]; face1.a = b; face1.b = c; face1.c = d; } face1.uvs = new Vector2[] { uvs[1], uvs[2], uvs[3] }; faceIndex++; // Vector3 normal0; Vector3 normal1; TubeGeometry.FrenetFrames splineTube = options.frames; if (shape.normals != null) { if (splineTube != null) { Vector3 n0 = shape.normals[contourIndex1]; if (reverse) { n0.y *= -1; } normal0 = tQ0 * n0; normal0.Normalize(); Vector3 n1 = shape.normals[contourIndex1]; if (reverse) { n1.y *= -1; } normal1 = tQ1 * n1; normal1.Normalize(); } else { Vector3 norm = shape.normals[contourIndex1]; if (reverse) { norm.y *= -1; } normal0 = norm; normal1 = norm; } // face0.vertexNormals = new Vector3[]{normal0, normal0, normal1 }; // face1.vertexNormals = new Vector3[]{normal0, normal1, normal1 }; face0.vertexNormals[0] = normal0; face0.vertexNormals[1] = normal0; face0.vertexNormals[2] = normal1; face1.vertexNormals[0] = normal0; face1.vertexNormals[1] = normal1; face1.vertexNormals[2] = normal1; } // // TODO: faceVertexUvs の変更で問題点ないか確認 // List<Vector2> uvs0; // if(faceIndex - 2 >= this.faceVertexUvs.Count){ // uvs0 = new List<Vector2>( new Vector2[]{ uvs[ 0 ], uvs[ 1 ], uvs[ 3 ] } ); // this.faceVertexUvs.Add(uvs0); // }else{ // this.faceVertexUvs[faceIndex - 2] = new List<Vector2>( new Vector2[]{ uvs[ 0 ], uvs[ 1 ], uvs[ 3 ] } ); // } // List<Vector2> uvs1; // if(faceIndex - 1 >= this.faceVertexUvs.Count){ // uvs1 = new List<Vector2>( new Vector2[]{ uvs[ 1 ], uvs[ 2 ], uvs[ 3 ] } ); // this.faceVertexUvs.Add(uvs1); // }else{ // this.faceVertexUvs[faceIndex - 1] = new List<Vector2>( new Vector2[]{ uvs[ 1 ], uvs[ 2 ], uvs[ 3 ] } ); // } // this.faceVertexUvs.Add( new List<Vector2>( new Vector2[]{ Vector2.one, Vector2.one, Vector2.one, Vector2.one } )); // Debug // this.faceVertexUvs.Add( new List<Vector2>( new Vector2[]{ Vector2.one, Vector2.one, Vector2.one, Vector2.one } )); // Debug }
void sidewalls(int vlen, List <Vector3> contour, int layeroffset, int steps, int bevelSegments, int shapesOffset, WorldUVGenerator uvgen, Shape shape, Option options, bool closePath = false, bool reverse = true) { int j, k; TubeGeometry.FrenetFrames splineTube = options.frames; // pre compute Quat int sl = steps + bevelSegments * 2; Quaternion[] normalQuats = new Quaternion[sl + 1]; if (splineTube != null) { for (int i = 0; i < normalQuats.Length; i++) { normalQuats[i] = Quaternion.LookRotation(splineTube.tangents[i], splineTube.normals[i]) * Quaternion.AngleAxis(90, Vector3.forward); } } for (int i = 0; i < contour.Count; i++) { j = i; k = i - 1; if (k < 0) { k = contour.Count - 1; } //console.log('b', i,j, i-1, k,vertices.length); //Debug.Log(">>> k: "+k + " steps: "+steps); int s = 0; //int sl = steps + bevelSegments * 2; for (s = 0; s < sl; s++) { int slen1 = vlen * s; int slen2 = vlen * (s + 1); if (closePath && s == steps - 1) { // close path end slen1 = vlen * (sl - 1); slen2 = 0; } int a = layeroffset + j + slen1; int b = layeroffset + k + slen1; int c = layeroffset + k + slen2; int d = layeroffset + j + slen2; // int stepIndex = s; int stepsLength = sl; Quaternion tQ0; Quaternion tQ1; if (splineTube != null) { tQ0 = normalQuats[stepIndex]; int id = stepIndex + 1; if (id > stepsLength) { id = 0; } tQ1 = normalQuats[id]; } else { tQ0 = Quaternion.identity; tQ1 = Quaternion.identity; } f4(a, b, c, d, shape, contour, s, sl, j, k, shapesOffset, uvgen, options, reverse, tQ0, tQ1); } } }