JeromeBos

UnrealEd Texture Alignment

Jun 16th, 2014 (edited)
463
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 17.11 KB | None | 0 0
  1. <!--
  2.  
  3. [ UnrealEd - Texture Alignment]
  4.  
  5. --------------------------------------------------------------------------------
  6. :: Release information
  7. --------------------------------------------------------------------------------
  8.  
  9. Release v6 (5 April 2021)
  10. * Fixed incorrect calculations for circular brushes
  11.  
  12. Release v5 (14 January 2015)
  13. * Fixed bug in selecting correct polygon method (special thanks to Roel)
  14.  
  15. Release v4 (1 July 2014):
  16. * Added options for angular brushes
  17. * Added some explanatory pictures
  18. * Added collapsing sections
  19.  
  20. Release v3 (16 June 2014):
  21. * Added options for texture rotation
  22.  
  23. Release v2 (22 July 2010):
  24. * Added additional options for circular brushes
  25.  
  26. Release v1 (23 June 2010):
  27. * Added options for circular brushes
  28.  
  29. --------------------------------------------------------------------------------
  30. :: Additional information
  31. --------------------------------------------------------------------------------
  32.  
  33. Developer / Maintainer:
  34.  Jerome Bos a.k.a. Bloeb
  35.  
  36. Thanks to the BT-community for their ideas, support, bugreports and testing.
  37.  
  38. Thanks to the Unreal Wiki (http://wiki.beyondunreal.com) for information on scripting.
  39.  
  40. --------------------------------------------------------------------------------
  41. :: License
  42. --------------------------------------------------------------------------------
  43.  
  44.  Copyright (c) 2010 - 2015 Jerome Bos
  45.  
  46.  Permission is hereby granted, free of charge, to any person
  47.  obtaining a copy of this software and associated documentation
  48.  files (the "Software"), to deal in the Software without
  49.  restriction, including without limitation the rights to use,
  50.  copy, modify, merge, publish, distribute, sublicense, and/or sell
  51.  copies of the Software, and to permit persons to whom the
  52.  Software is furnished to do so, subject to the following
  53.  conditions:
  54.  
  55.  1. The above copyright notice and this permission notice shall be
  56.     included in all copies or substantial portions of the Software.
  57.  2. Except as contained in this notice, the names of the authors and
  58.     copyright holders, shall not be used in advertising or otherwise
  59.     to promote the sale, use or other dealings in this Software
  60.     without prior written authorization from the copyright holders.
  61.  
  62.  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  63.  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  64.  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  65.  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  66.  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  67.  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  68.  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  69.  OTHER DEALINGS IN THE SOFTWARE.
  70.  
  71. -->
  72.  
  73. <title>UnrealEd - Texture Alignment - Jerome Bos</title>
  74.  
  75. <style type="text/css">
  76. h2, h3
  77. {
  78.     cursor: pointer;
  79. }
  80.  
  81. .section
  82. {
  83.     display: none;
  84. }
  85.  
  86. body
  87. {
  88.     font-family: Calibri, Arial, Sans-serif;
  89. }
  90. </style>
  91.  
  92. <script type="text/javascript">
  93.  
  94. var pi = Math.acos(-1); // 3.14159265;
  95. var trigo_method = 0;
  96. var rotation_angle_measurement = 0;
  97. var connected_brushes_angle_measurement = 0;
  98.  
  99. function display_section(section)
  100. {
  101.     var section_element = document.getElementById(section);
  102.  
  103.     if(section_element.style.display=="block")
  104.         section_element.style.display="none";
  105.     else
  106.         section_element.style.display="block";
  107. }
  108.  
  109. function select_rotation_angle_measurement(index)
  110. {
  111.     rotation_angle_measurement = index;
  112. }
  113.  
  114. function select_connected_brushes_angle_measurement(index)
  115. {
  116.     connected_brushes_angle_measurement = index;
  117. }
  118.  
  119. function angle_func(num, angle_measurement)
  120. {
  121.     if(angle_measurement>0)
  122.         return num * pi / 180;
  123.     else
  124.         return num;
  125. }
  126.  
  127. function select_trigo_method(index)
  128. {
  129.     trigo_method = index;
  130. }
  131.  
  132. function trigo_func(num)
  133. {
  134.     if(trigo_method>0)
  135.         return Math.sin(num);
  136.     else
  137.         return Math.tan(num);
  138. }
  139.  
  140. function calculate_panning()
  141. {
  142.     var sides = document.getElementById('cp_sides').value;
  143.     var radius = document.getElementById('cp_radius').value;
  144.     var scale = document.getElementById('cp_scale').value;
  145.  
  146.     var surface_width = 2*radius*trigo_func(pi/sides)/scale;
  147.  
  148.     document.getElementById('cp_surface_width').value = surface_width;
  149.     document.getElementById('cp_command').value = "POLY TEXPAN U=" + surface_width;
  150.     document.getElementById('cp_command').select();
  151. }
  152.  
  153. function calculate_radius()
  154. {
  155.     var sides = document.getElementById('cr_sides').value;
  156.     var width = document.getElementById('cr_width').value;
  157.     var scale = document.getElementById('cr_scale').value;
  158.  
  159.     var radius = (width/sides)/(2*trigo_func(pi/sides))*scale;
  160.  
  161.     var cr_radius = document.getElementById('cr_radius');
  162.     cr_radius.value = radius;
  163.     cr_radius.select();
  164. }
  165.  
  166. function calculate_scale()
  167. {
  168.     var sides = document.getElementById('cs_sides').value;
  169.     var width = document.getElementById('cs_width').value;
  170.     var radius = document.getElementById('cs_radius').value;
  171.  
  172.     var scale = (2*radius*trigo_func(pi/sides))*sides/width;
  173.  
  174.     var cs_scale = document.getElementById('cs_scale')
  175.     cs_scale.value = scale;
  176.     cs_scale.select();
  177. }
  178.  
  179. function calculate_angle_from_slope()
  180. {
  181.     var adjacent = document.getElementById('angle_slope_adjacent').value;
  182.     var opposite = document.getElementById('angle_slope_opposite').value;
  183.     var angle_radians = document.getElementById('angle_slope_radians');
  184.     var angle_degrees = document.getElementById('angle_slope_degrees');
  185.    
  186.     var angle = Math.atan(opposite/adjacent);
  187.  
  188.     angle_degrees.value = angle * 180 / pi;
  189.     angle_radians.value = angle;
  190.     angle_radians.select();
  191. }
  192.  
  193. function calculate_connected_brushes()
  194. {
  195.     var grid = document.getElementById('connected_brushes_grid').value;
  196.     var side_adjacent = document.getElementById('connected_brushes_side_adjacent').value*grid;
  197.     var side_opposite = document.getElementById('connected_brushes_side_opposite').value*grid;
  198.     var angle = angle_func(document.getElementById('connected_brushes_angle').value,connected_brushes_angle_measurement);
  199.     var width = document.getElementById('connected_brushes_width');
  200.     var hypotenuse = document.getElementById('connected_brushes_hypotenuse');
  201.     var scale_adjacent = document.getElementById('connected_brushes_scale_adjacent');
  202.     var scale_opposite = document.getElementById('connected_brushes_scale_opposite');
  203.  
  204.     var hypotenuse_calc = Math.sqrt(side_adjacent*side_adjacent+side_opposite*side_opposite);
  205.     var width_calc = Math.cos(angle-Math.atan(side_opposite/side_adjacent))*hypotenuse_calc;
  206.  
  207.     hypotenuse.value = hypotenuse_calc;
  208.     scale_adjacent.value = width_calc/side_adjacent;
  209.     scale_opposite.value = width_calc/side_opposite;
  210.     width.value = width_calc;
  211.     width.select();
  212. }
  213.  
  214. function calculate_rotation()
  215. {
  216.     var angle = angle_func(document.getElementById('rot_angle').value,rotation_angle_measurement);
  217.     var command = document.getElementById('rot_command');
  218.    
  219.     var uu = Math.cos(angle);
  220.     var uv = -Math.sin(angle);
  221.     var vu = Math.sin(angle);
  222.     var vv = Math.cos(angle);
  223.    
  224.     command.value = "POLY TEXMULT UU=" + uu + " UV=" + uv + " VU=" + vu + " VV=" + vv;
  225.     command.select();
  226. }
  227.  
  228. </script>
  229.  
  230. <h1>UnrealEd - Texture Alignment</h1>
  231. <h2 id="circular_brushes" onClick="display_section('circular_brushes_section')">1. Circular brushes</h2>
  232. <div id="circular_brushes_section" class="section">
  233. <p>
  234. <svg width="384" height="256" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
  235.     <defs>
  236.         <path id="radius_path" d="M120,128 L120,64" />
  237.         <path id="surface_width_path" d="M160,32 L320,32" />
  238.         <path id="circumscribed_path" d="M64,224 L256,224" />
  239.         <path id="inscribed_path" d="M80,224 L256,224" />
  240.     </defs>
  241.     <rect x="0" y="0" width="384" height="256" stroke="#000" stroke-width="2" fill="#fff" />
  242.     <g id="circumscribed" transform="translate(-32,0)">
  243.         <circle cx="128" cy="128" r="64" fill="none" stroke="#000" stroke-width="1" />
  244.         <polyline points="128,128 128,64" fill="none" stroke="#000" stroke-width="1" stroke-dasharray="5,5" stroke-linecap="round" />
  245.         <polygon points="164.95041722813605,192
  246.                          201.9008344562721,128
  247.                          164.95041722813605,64
  248.                          91.04958277186398,63.999999999999986
  249.                          54.099165543727906,127.99999999999999
  250.                          91.04958277186392,191.99999999999997" fill="none" stroke="#000" stroke-width="2" />
  251.         <polyline points="201.9008344562721,128 164.95041722813605,64" fill="none" stroke="#f00" stroke-width="3" stroke-linecap="round" />
  252.         <g font-family="Calibri, Arial, Sans-serif" font-size="12">
  253.             <text fill="#000"><textPath xlink:href="#radius_path">radius</textPath></text>
  254.             <text fill="#000"><textPath xlink:href="#circumscribed_path">circumscribed polygon</textPath></text>
  255.         </g>
  256.     </g>
  257.     <g id="inscribed" transform="translate(160,0)">
  258.         <circle cx="128" cy="128" r="64" fill="none" stroke="#000" stroke-width="1" />
  259.         <polyline points="128,128 128,64" fill="none" stroke="#000" stroke-width="1" stroke-dasharray="5,5" stroke-linecap="round" />
  260.         <polygon points="128,192
  261.                          183.42562584220406,160
  262.                          183.42562584220408,96.00000000000001
  263.                          128,64
  264.                          72.57437415779594,95.99999999999997
  265.                          72.57437415779593,160" fill="none" stroke="#000" stroke-width="2" />
  266.         <polyline points="183.42562584220408,96.00000000000001 128,64" fill="none" stroke="#f00" stroke-width="3" stroke-linecap="round" />
  267.         <g font-family="Calibri, Arial, Sans-serif" font-size="12">
  268.             <text fill="#000"><textPath xlink:href="#radius_path">radius</textPath></text>
  269.             <text fill="#000"><textPath xlink:href="#inscribed_path">inscribed polygon</textPath></text>
  270.         </g>
  271.     </g>
  272.     <text font-family="Calibri, Arial, Sans-serif" font-size="12" fill="#f00">
  273.         <textPath xlink:href="#surface_width_path">surface width</textPath>
  274.     </text>
  275. </svg>
  276. <p>
  277. method:
  278. <select onChange="select_trigo_method(this.selectedIndex)">
  279. <option selected value="opt_circumscribed">circumscribed polygon</option>
  280. <option value="opt_inscribed">inscribed polygon</option>
  281. </select>
  282.  
  283. <h3 id="calculate_surface_width" onClick="display_section('calculate_surface_width_section')">1.1. Surface width</h3>
  284. <div id="calculate_surface_width_section" class="section">
  285. <p>Aligning circular brushes:
  286. <ol>
  287. <li>Make a circular brush and apply a texture.
  288. <li>Scale the textures.
  289. <li>Select all surfaces that need to be aligned.
  290. <li>Apply the calculated command.
  291. <li>Deselect the most outward surface (either left or right).
  292. <li>Apply the calculated command again.
  293. <li>Repeat this method untill all surfaces are aligned.
  294. </ol>
  295. <p>
  296. sides: <input type="text" id="cp_sides"><br>
  297. radius: <input type="text" id="cp_radius"><br>
  298. scale: <input type="text" id="cp_scale"><br>
  299. <input type="button" value="calc" onClick="calculate_panning()"><br>
  300. surface width: <input type="text" id="cp_surface_width" value=""><br>
  301. command: <input type="text" id="cp_command" value=""><br>
  302. </div>
  303.  
  304. <h3 id="calculate_radius" onClick="display_section('calculate_radius_section')">1.2. Radius</h3>
  305. <div id="calculate_radius_section" class="section">
  306. <p>
  307. sides: <input type="text" id="cr_sides"><br>
  308. scale: <input type="text" id="cr_scale"><br>
  309. texture width: <input type="text" id="cr_width"><br>
  310. <input type="button" value="calc" onClick="calculate_radius()"><br>
  311. radius: <input type="text" id="cr_radius" value=""><br>
  312. </div>
  313.  
  314. <h3 id="calculate_scale" onClick="display_section('calculate_scale_section')">1.3. Scale</h3>
  315. <div id="calculate_scale_section" class="section">
  316. <p>
  317. sides: <input type="text" id="cs_sides"><br>
  318. texture width: <input type="text" id="cs_width"><br>
  319. radius: <input type="text" id="cs_radius"><br>
  320. <input type="button" value="calc" onClick="calculate_scale()"><br>
  321. scale: <input type="text" id="cs_scale" value=""><br>
  322. </div>
  323.  
  324. </div>
  325.  
  326. <h2 id="angular_brushes" onClick="display_section('angular_brushes_section')">2. Angular brushes</h2>
  327. <div id="angular_brushes_section" class="section">
  328.  
  329. <h3 id="angle_from_slope" onClick="display_section('angle_from_slope_section')">2.1. Angle from slope</h3>
  330. <div id="angle_from_slope_section" class="section">
  331. <p>
  332. <svg width="256" height="192" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
  333.     <defs>
  334.         <path id="conv_adjacent_path" d="M128,168 L256,168" />
  335.         <path id="conv_opposite_path" d="M224,64 L224,128" />
  336.         <path id="conv_angle_path" d="M96,128 L256,128" />
  337.     </defs>
  338.     <rect x="0" y="0" width="256" height="192" stroke="#000" stroke-width="2" fill="#fff" />
  339.     <polygon points="32,146 208,146 208,32" fill="none" stroke="#000" stroke-width="2" />
  340.     <path d="M 72 146 A 40 40 0 0 0 65.57256702183963 124.25413272449023" fill="none" stroke="#f00" stroke-width="1" stroke-linecap="round" />
  341.     <polyline points="198,146 198,136 208,136" fill="none" stroke="#00f" stroke-width="1" stroke-linecap="round" />
  342.     <g font-family="Calibri, Arial, Sans-serif" font-size="12">
  343.         <text fill="#000"><textPath xlink:href="#conv_adjacent_path">adjacent</textPath></text>
  344.         <text fill="#000"><textPath xlink:href="#conv_opposite_path">opposite</textPath></text>
  345.         <text fill="#f00"><textPath xlink:href="#conv_angle_path">angle</textPath></text>
  346.     </g>
  347. </svg>
  348. <p>
  349. adjacent: <input type="text" id="angle_slope_adjacent"><br>
  350. opposite: <input type="text" id="angle_slope_opposite"><br>
  351. <input type="button" value="calc" onClick="calculate_angle_from_slope()"><br>
  352. angle: <input type="text" id="angle_slope_radians" value=""> radians<br>
  353. angle: <input type="text" id="angle_slope_degrees" value=""> degrees<br>
  354. </div>
  355.  
  356. <h3 id="connected_brushes" onClick="display_section('connected_brushes_section')">2.2. Width of angular brush</h3>
  357. <div id="connected_brushes_section" class="section">
  358. <p>
  359. <svg width="320" height="320" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
  360.     <defs>
  361.         <path id="adjacent_path" d="M192,208 L256,208" />
  362.         <path id="opposite_path" d="M264,136 L264,256" />
  363.         <path id="hypotenuse_path" d="M184,156 L266,116" />
  364.         <path id="width_path" d="M176,128 L240,64" />
  365.         <path id="angle_path" d="M192,180 L256,180" />
  366.     </defs>
  367.     <rect x="0" y="0" width="320" height="320" stroke="#000" stroke-width="2" fill="#fff" />
  368.     <polyline id="poly_connect_left" points="128,0 256,128 256,320" fill="none" stroke="#000" stroke-width="2" stroke-linecap="round" />
  369.     <polyline id="poly_connect_right" points="0,64 128,192 128,320" fill="none" stroke="#000" stroke-width="2" stroke-linecap="round" />
  370.     <polyline id="poly_connect_middle" points="128,192 256,128" fill="none" stroke="#000" stroke-width="2" stroke-linecap="round" />
  371.     <polyline id="poly_width" points="128,192 224,92" fill="none" stroke="#000" stroke-width="2" stroke-dasharray="5,5" stroke-linecap="round" />
  372.     <polyline id="poly_adjacent" points="128,192 256,192" fill="none" stroke="#000" stroke-width="2" stroke-dasharray="5,5" stroke-linecap="round" />
  373.     <polyline id="poly_angle" points="256,0 256,128" fill="none" stroke="#000" stroke-width="2" stroke-dasharray="5,5" stroke-linecap="round" />
  374.     <polyline id="poly_angle90" points="120,184 128,176 136,184" fill="none" stroke="#00f" stroke-width="1" stroke-linecap="round" />
  375.     <path id="line_angle1" d="M 168 192 A 40 40 0 0 0 156.2842712474619 163.7157287525381" fill="none" stroke="#f00" stroke-width="1" stroke-linecap="round" />
  376.     <path id="line_angle2" d="M 256 88 A 40 40 0 0 0 227.7157287525381 99.7157287525381" fill="none" stroke="#f00" stroke-width="1" stroke-linecap="round" />
  377.     <g font-family="Calibri, Arial, Sans-serif" font-size="12">
  378.         <text fill="#000"><textPath xlink:href="#adjacent_path">adjacent</textPath></text>
  379.         <text fill="#000"><textPath xlink:href="#opposite_path">opposite</textPath></text>
  380.         <text fill="#000"><textPath xlink:href="#hypotenuse_path">hypotenuse</textPath></text>
  381.         <text fill="#000"><textPath xlink:href="#width_path">width</textPath></text>
  382.         <text fill="#f00"><textPath xlink:href="#angle_path">angle</textPath></text>
  383.     </g>
  384. </svg>
  385. <p>
  386. grid: <input type="text" id="connected_brushes_grid" value="16"><br>
  387. adjacent side: <input type="text" id="connected_brushes_side_adjacent"><br>
  388. opposite side: <input type="text" id="connected_brushes_side_opposite"><br>
  389. angle: <input type="text" id="connected_brushes_angle" value="">
  390. <select onChange="select_connected_brushes_angle_measurement(this.selectedIndex)">
  391. <option selected value="connected_brushes_opt_radians">radians</option>
  392. <option value="connected_brushes_opt_degrees">degrees</option>
  393. </select><br>
  394. <input type="button" value="calc" onClick="calculate_connected_brushes()"><br>
  395. hypotenuse: <input type="text" id="connected_brushes_hypotenuse"><br>
  396. width: <input type="text" id="connected_brushes_width"><br>
  397. scale adjacent: <input type="text" id="connected_brushes_scale_adjacent" value=""><br>
  398. scale opposite: <input type="text" id="connected_brushes_scale_opposite" value=""><br>
  399. </div>
  400.  
  401. </div>
  402.  
  403. <h2 id="texture_rotation" onClick="display_section('texture_rotation_section')">3. Texture rotation</h2>
  404. <div id="texture_rotation_section" class="section">
  405. <p>
  406. angle: <input type="text" id="rot_angle" value="">
  407. <select onChange="select_rotation_angle_measurement(this.selectedIndex)">
  408. <option selected value="rot_opt_radians">radians</option>
  409. <option value="rot_opt_degrees">degrees</option>
  410. </select><br>
  411. <input type="button" value="calc" onClick="calculate_rotation()"><br>
  412. command: <input type="text" id="rot_command" value=""><br>
  413. </div>
Add Comment
Please, Sign In to add comment