misc_uv_tests.html 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset=utf-8 />
  5. <title>three.js - uv mapping tests</title>
  6. <style>
  7. article, aside, figure, footer, header, hgroup,
  8. menu, nav, section { display: block; }
  9. </style>
  10. <script src="../build/three.min.js"></script>
  11. <script src="js/UVsUtils.js"></script>
  12. </head>
  13. <body>
  14. <b id="hello">Doing UV wrap tests here!</b>
  15. <i>Please wait while it loads</i>
  16. <script>
  17. /*
  18. * This is to help debug UVs problems in geometry,
  19. * as well as allow a new user to visualize what UVs are about.
  20. */
  21. function test(name, geometry) {
  22. var d = document.createElement('div');
  23. d.innerHTML = '<br><br>' + name + '<br>';
  24. d.appendChild(THREE.UVsDebug(geometry));
  25. document.body.appendChild(d);
  26. }
  27. test('new THREE.PlaneGeometry( 100, 100, 4, 4 )', new THREE.PlaneGeometry( 100, 100, 4, 4 ));
  28. test('new THREE.SphereGeometry( 75, 12, 6 )', new THREE.SphereGeometry( 75, 12, 6 ));
  29. test('new THREE.IcosahedronGeometry( 30, 1 )', new THREE.IcosahedronGeometry( 30, 1 ));
  30. test('new THREE.OctahedronGeometry( 30, 2 )', new THREE.OctahedronGeometry( 30, 2 ));
  31. test('new THREE.CylinderGeometry( 25, 75, 100, 10, 5 )', new THREE.CylinderGeometry( 25, 75, 100, 10, 5 ));
  32. test('new THREE.CubeGeometry( 100, 100, 100, 4, 4, 4 )', new THREE.CubeGeometry( 100, 100, 100, 4, 4, 4 ));
  33. var points = [];
  34. for ( var i = 0; i < 10; i ++ ) {
  35. points.push( new THREE.Vector3( Math.sin( i * 0.2 ) * 15 + 50, 0, ( i - 5 ) * 2 ) );
  36. }
  37. test('new THREE.LatheGeometry( points, 8 )', new THREE.LatheGeometry( points, 8 ));
  38. test('new THREE.TorusGeometry( 50, 20, 8, 8 )', new THREE.TorusGeometry( 50, 20, 8, 8 ));
  39. test('new THREE.TorusKnotGeometry( 50, 10, 12, 6 )', new THREE.TorusKnotGeometry( 50, 10, 12, 6 ));
  40. /*
  41. Not sure how UVs for ExtrudeGeometry are done currently...
  42. */
  43. var pts = [], starPoints = 5, l;
  44. for (i=0; i<starPoints*2;i++) {
  45. if (i%2==1) {
  46. l = 5;
  47. } else {
  48. l = 10;
  49. }
  50. var a = i / starPoints * Math.PI;
  51. pts.push(new THREE.Vector2(Math.cos(a) * l,Math.sin(a) * l ));
  52. }
  53. var starShape = new THREE.Shape(pts);
  54. var extrudeSettings = { amount: 200, bevelEnabled: true, bevelSegments: 2, steps: 10 };
  55. test('new THREE.ExtrudeGeometry(starShape, extrudeSettings);', new THREE.ExtrudeGeometry(starShape, extrudeSettings));
  56. var uvGenerator = new THREE.UVsUtils.CylinderUVGenerator();
  57. testShape = setupShape(8, 3);
  58. holeShape = setupShape(8, 2);
  59. testShape.holes.push(holeShape);
  60. function setupShape(n, r) {
  61. // Make shape
  62. var sh = new THREE.Shape();
  63. for (var i = 0; i < n;i++) {
  64. var method = i ? 'lineTo' : 'moveTo';
  65. var a = (i/n) * Math.PI * 2;
  66. var x = Math.cos(a) * r;
  67. var y = Math.sin(a) * r;
  68. sh[method](x, y);
  69. }
  70. return sh;
  71. }
  72. var exoption = {
  73. bevelEnabled: true,
  74. bevelSize: 1,
  75. amount: 3,
  76. extrudeMaterial: 0,
  77. material: 1,
  78. uvGenerator: uvGenerator
  79. };
  80. var geom = testShape.extrude(exoption);
  81. test('new THREE.ExtrudeGeometry with CylinderUVGenerator;', geom);
  82. </script>
  83. </body>
  84. </html>