You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
164 lines
28 KiB
164 lines
28 KiB
<html>
|
|
<head>
|
|
<title>geometry.rs</title>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
|
<style type="text/css">
|
|
.s0 { color: #ed864a;}
|
|
.s1 { color: #ebebeb;}
|
|
.s2 { color: #ffffff;}
|
|
.s3 { color: #ed864a; font-weight: bold;}
|
|
.s4 { color: #33ccff; font-weight: bold;}
|
|
.s5 { color: #499936; font-style: italic;}
|
|
.s6 { color: #54b33e;}
|
|
.s7 { color: #7ec3e6;}
|
|
.ln { color: #999999; font-weight: normal; font-style: normal; }
|
|
</style>
|
|
</head>
|
|
<body bgcolor="#131314">
|
|
<table CELLSPACING=0 CELLPADDING=5 COLS=1 WIDTH="100%" BGCOLOR="#606060" >
|
|
<tr><td><center>
|
|
<font face="Arial, Helvetica" color="#000000">
|
|
geometry.rs</font>
|
|
</center></td></tr></table>
|
|
<pre><a name="l1"><span class="ln">1 </span></a><span class="s0">use </span><span class="s2">bytemuck</span><span class="s1">::{</span><span class="s2">Pod</span><span class="s3">, </span><span class="s2">Zeroable</span><span class="s1">}</span><span class="s3">;</span>
|
|
<a name="l2"><span class="ln">2 </span></a><span class="s0">use </span><span class="s2">nalgebra</span><span class="s1">::</span><span class="s2">Vector4</span><span class="s3">;</span>
|
|
<a name="l3"><span class="ln">3 </span></a><span class="s0">use </span><span class="s2">rapier3d</span><span class="s1">::</span><span class="s2">parry</span><span class="s1">::</span><span class="s2">math</span><span class="s1">::</span><span class="s2">Point</span><span class="s3">;</span>
|
|
<a name="l4"><span class="ln">4 </span></a><span class="s0">use </span><span class="s2">tobj</span><span class="s1">::{</span><span class="s2">LoadError</span><span class="s3">, </span><span class="s2">Model</span><span class="s3">, </span><span class="s2">Material</span><span class="s1">}</span><span class="s3">;</span>
|
|
<a name="l5"><span class="ln">5 </span></a>
|
|
<a name="l6"><span class="ln">6 </span></a>
|
|
<a name="l7"><span class="ln">7 </span></a><span class="s1">#[</span><span class="s2">repr</span><span class="s1">(</span><span class="s2">C</span><span class="s1">)]</span>
|
|
<a name="l8"><span class="ln">8 </span></a><span class="s1">#[</span><span class="s2">derive</span><span class="s1">(</span><span class="s2">Clone</span><span class="s3">, </span><span class="s2">Copy</span><span class="s3">, </span><span class="s2">Debug</span><span class="s1">)]</span>
|
|
<a name="l9"><span class="ln">9 </span></a><span class="s0">pub struct </span><span class="s2">Vertex </span><span class="s1">{</span>
|
|
<a name="l10"><span class="ln">10 </span></a> <span class="s2">pos</span><span class="s1">: [</span><span class="s2">f32</span><span class="s3">; </span><span class="s4">4</span><span class="s1">]</span><span class="s3">,</span>
|
|
<a name="l11"><span class="ln">11 </span></a> <span class="s2">normal</span><span class="s1">: [</span><span class="s2">f32</span><span class="s3">; </span><span class="s4">4</span><span class="s1">]</span><span class="s3">,</span>
|
|
<a name="l12"><span class="ln">12 </span></a> <span class="s2">uv</span><span class="s1">: [</span><span class="s2">f32</span><span class="s3">; </span><span class="s4">2</span><span class="s1">]</span><span class="s3">,</span>
|
|
<a name="l13"><span class="ln">13 </span></a><span class="s1">}</span>
|
|
<a name="l14"><span class="ln">14 </span></a>
|
|
<a name="l15"><span class="ln">15 </span></a><span class="s0">impl </span><span class="s2">Vertex </span><span class="s1">{</span>
|
|
<a name="l16"><span class="ln">16 </span></a> <span class="s0">pub fn </span><span class="s2">position</span><span class="s1">(&</span><span class="s0">self</span><span class="s1">) -> </span><span class="s2">Point</span><span class="s1"><</span><span class="s2">f32</span><span class="s1">> {</span>
|
|
<a name="l17"><span class="ln">17 </span></a> <span class="s2">Point</span><span class="s1">::<</span><span class="s2">f32</span><span class="s1">>::</span><span class="s2">new</span><span class="s1">(</span><span class="s0">self</span><span class="s1">.</span><span class="s2">pos</span><span class="s1">[</span><span class="s4">0</span><span class="s1">]</span><span class="s3">, </span><span class="s0">self</span><span class="s1">.</span><span class="s2">pos</span><span class="s1">[</span><span class="s4">1</span><span class="s1">]</span><span class="s3">, </span><span class="s0">self</span><span class="s1">.</span><span class="s2">pos</span><span class="s1">[</span><span class="s4">2</span><span class="s1">])</span>
|
|
<a name="l18"><span class="ln">18 </span></a> <span class="s1">}</span>
|
|
<a name="l19"><span class="ln">19 </span></a> <span class="s0">pub fn </span><span class="s2">from</span><span class="s1">(</span><span class="s2">pos</span><span class="s1">: [</span><span class="s2">f32</span><span class="s3">; </span><span class="s4">3</span><span class="s1">]</span><span class="s3">, </span><span class="s2">nor</span><span class="s1">: [</span><span class="s2">f32</span><span class="s3">; </span><span class="s4">3</span><span class="s1">]</span><span class="s3">, </span><span class="s2">uv</span><span class="s1">: [</span><span class="s2">f32</span><span class="s3">; </span><span class="s4">2</span><span class="s1">]) -> </span><span class="s2">Vertex </span><span class="s1">{</span>
|
|
<a name="l20"><span class="ln">20 </span></a> <span class="s2">Vertex </span><span class="s1">{</span>
|
|
<a name="l21"><span class="ln">21 </span></a> <span class="s2">pos</span><span class="s1">: [</span><span class="s2">pos</span><span class="s1">[</span><span class="s4">0</span><span class="s1">]</span><span class="s3">, </span><span class="s2">pos</span><span class="s1">[</span><span class="s4">1</span><span class="s1">]</span><span class="s3">, </span><span class="s2">pos</span><span class="s1">[</span><span class="s4">2</span><span class="s1">]</span><span class="s3">, </span><span class="s4">1</span><span class="s1">.</span><span class="s4">0</span><span class="s1">]</span><span class="s3">,</span>
|
|
<a name="l22"><span class="ln">22 </span></a> <span class="s2">normal</span><span class="s1">: [</span><span class="s2">nor</span><span class="s1">[</span><span class="s4">0</span><span class="s1">]</span><span class="s3">, </span><span class="s2">nor</span><span class="s1">[</span><span class="s4">1</span><span class="s1">]</span><span class="s3">, </span><span class="s2">nor</span><span class="s1">[</span><span class="s4">2</span><span class="s1">]</span><span class="s3">, </span><span class="s4">0</span><span class="s1">.</span><span class="s4">0</span><span class="s1">]</span><span class="s3">,</span>
|
|
<a name="l23"><span class="ln">23 </span></a> <span class="s2">uv</span><span class="s1">: [</span><span class="s2">uv</span><span class="s1">[</span><span class="s4">0</span><span class="s1">]</span><span class="s3">, </span><span class="s2">uv</span><span class="s1">[</span><span class="s4">1</span><span class="s1">]]</span><span class="s3">,</span>
|
|
<a name="l24"><span class="ln">24 </span></a> <span class="s1">}</span>
|
|
<a name="l25"><span class="ln">25 </span></a> <span class="s1">}</span>
|
|
<a name="l26"><span class="ln">26 </span></a><span class="s1">}</span>
|
|
<a name="l27"><span class="ln">27 </span></a>
|
|
<a name="l28"><span class="ln">28 </span></a><span class="s0">unsafe impl </span><span class="s2">Pod </span><span class="s0">for </span><span class="s2">Vertex </span><span class="s1">{}</span>
|
|
<a name="l29"><span class="ln">29 </span></a><span class="s0">unsafe impl </span><span class="s2">Zeroable </span><span class="s0">for </span><span class="s2">Vertex </span><span class="s1">{}</span>
|
|
<a name="l30"><span class="ln">30 </span></a>
|
|
<a name="l31"><span class="ln">31 </span></a><span class="s1">#[</span><span class="s2">derive</span><span class="s1">(</span><span class="s2">Clone</span><span class="s3">, </span><span class="s2">Debug</span><span class="s1">)]</span>
|
|
<a name="l32"><span class="ln">32 </span></a><span class="s0">pub struct </span><span class="s2">RawMesh </span><span class="s1">{</span>
|
|
<a name="l33"><span class="ln">33 </span></a> <span class="s0">pub </span><span class="s2">vertices</span><span class="s1">: </span><span class="s2">Vec</span><span class="s1"><</span><span class="s2">Vertex</span><span class="s1">></span><span class="s3">,</span>
|
|
<a name="l34"><span class="ln">34 </span></a> <span class="s0">pub </span><span class="s2">indices</span><span class="s1">: </span><span class="s2">Vec</span><span class="s1"><[</span><span class="s2">u32</span><span class="s3">; </span><span class="s4">3</span><span class="s1">]></span><span class="s3">,</span>
|
|
<a name="l35"><span class="ln">35 </span></a><span class="s1">}</span>
|
|
<a name="l36"><span class="ln">36 </span></a>
|
|
<a name="l37"><span class="ln">37 </span></a>
|
|
<a name="l38"><span class="ln">38 </span></a><span class="s5">/// We use meshes in a few different places. To keep things simple, we return</span>
|
|
<a name="l39"><span class="ln">39 </span></a><span class="s5">/// the most basic, direct-to-memory version. If something fancy needs to be done</span>
|
|
<a name="l40"><span class="ln">40 </span></a><span class="s5">/// with it, the fancy stays there</span>
|
|
<a name="l41"><span class="ln">41 </span></a><span class="s0">pub fn </span><span class="s2">load_obj</span><span class="s1">(</span><span class="s2">obj_path</span><span class="s1">: &</span><span class="s2">str</span><span class="s1">) -> </span><span class="s2">Result</span><span class="s1"><</span><span class="s2">RawMesh</span><span class="s3">, </span><span class="s2">String</span><span class="s1">> {</span>
|
|
<a name="l42"><span class="ln">42 </span></a>
|
|
<a name="l43"><span class="ln">43 </span></a> <span class="s2">log</span><span class="s1">::</span><span class="s2">info</span><span class="s1">!(</span><span class="s6">"Loading object {}"</span><span class="s3">, </span><span class="s2">obj_path</span><span class="s1">)</span><span class="s3">;</span>
|
|
<a name="l44"><span class="ln">44 </span></a>
|
|
<a name="l45"><span class="ln">45 </span></a> <span class="s7">// Is there no better way to translate error messages?</span>
|
|
<a name="l46"><span class="ln">46 </span></a> <span class="s0">let </span><span class="s1">(</span><span class="s2">models</span><span class="s3">, </span><span class="s2">materials</span><span class="s1">) = </span><span class="s0">match </span><span class="s2">tobj</span><span class="s1">::</span><span class="s2">load_obj</span><span class="s1">(</span><span class="s2">obj_path</span><span class="s3">, </span><span class="s0">true</span><span class="s1">) {</span>
|
|
<a name="l47"><span class="ln">47 </span></a> <span class="s2">Ok</span><span class="s1">((</span><span class="s2">a</span><span class="s3">, </span><span class="s2">b</span><span class="s1">)) => {</span><span class="s2">Ok</span><span class="s1">((</span><span class="s2">a</span><span class="s3">, </span><span class="s2">b</span><span class="s1">))}</span>
|
|
<a name="l48"><span class="ln">48 </span></a> <span class="s2">Err</span><span class="s1">(</span><span class="s2">load_error</span><span class="s1">) => {</span><span class="s2">Err</span><span class="s1">(</span><span class="s2">load_error</span><span class="s1">.</span><span class="s2">to_string</span><span class="s1">())}</span>
|
|
<a name="l49"><span class="ln">49 </span></a> <span class="s1">}?</span><span class="s3">;</span>
|
|
<a name="l50"><span class="ln">50 </span></a>
|
|
<a name="l51"><span class="ln">51 </span></a> <span class="s7">// println!("# of models: {}", models.len());</span>
|
|
<a name="l52"><span class="ln">52 </span></a> <span class="s7">// println!("# of materials: {}", materials.len());</span>
|
|
<a name="l53"><span class="ln">53 </span></a> <span class="s7">// println!("{:?}", materials);</span>
|
|
<a name="l54"><span class="ln">54 </span></a>
|
|
<a name="l55"><span class="ln">55 </span></a> <span class="s0">let mut </span><span class="s2">index_data</span><span class="s1">: </span><span class="s2">Vec</span><span class="s1"><[</span><span class="s2">u32</span><span class="s3">; </span><span class="s4">3</span><span class="s1">]> = </span><span class="s2">Vec</span><span class="s1">::</span><span class="s2">new</span><span class="s1">()</span><span class="s3">;</span>
|
|
<a name="l56"><span class="ln">56 </span></a> <span class="s0">let mut </span><span class="s2">vertex_data </span><span class="s1">= </span><span class="s2">Vec</span><span class="s1">::</span><span class="s2">new</span><span class="s1">()</span><span class="s3">;</span>
|
|
<a name="l57"><span class="ln">57 </span></a>
|
|
<a name="l58"><span class="ln">58 </span></a> <span class="s0">for </span><span class="s2">model </span><span class="s0">in </span><span class="s2">models </span><span class="s1">{</span>
|
|
<a name="l59"><span class="ln">59 </span></a> <span class="s0">let </span><span class="s2">mesh </span><span class="s1">= &</span><span class="s2">model</span><span class="s1">.</span><span class="s2">mesh</span><span class="s3">;</span>
|
|
<a name="l60"><span class="ln">60 </span></a>
|
|
<a name="l61"><span class="ln">61 </span></a> <span class="s7">// Cycle through the faces and chunk out the indices</span>
|
|
<a name="l62"><span class="ln">62 </span></a> <span class="s0">let mut </span><span class="s2">next_face </span><span class="s1">= </span><span class="s4">0</span><span class="s3">;</span>
|
|
<a name="l63"><span class="ln">63 </span></a> <span class="s0">for </span><span class="s2">f </span><span class="s0">in </span><span class="s4">0</span><span class="s1">..</span><span class="s2">mesh</span><span class="s1">.</span><span class="s2">num_face_indices</span><span class="s1">.</span><span class="s2">len</span><span class="s1">() {</span>
|
|
<a name="l64"><span class="ln">64 </span></a> <span class="s7">// calculate the next chunk</span>
|
|
<a name="l65"><span class="ln">65 </span></a> <span class="s0">let </span><span class="s2">end </span><span class="s1">= </span><span class="s2">next_face </span><span class="s1">+ </span><span class="s2">mesh</span><span class="s1">.</span><span class="s2">num_face_indices</span><span class="s1">[</span><span class="s2">f</span><span class="s1">] </span><span class="s0">as </span><span class="s2">usize</span><span class="s3">;</span>
|
|
<a name="l66"><span class="ln">66 </span></a> <span class="s0">let </span><span class="s2">face_indices</span><span class="s1">: </span><span class="s2">Vec</span><span class="s1"><</span><span class="s2">_</span><span class="s1">> = </span><span class="s2">mesh</span><span class="s1">.</span><span class="s2">indices</span><span class="s1">[</span><span class="s2">next_face</span><span class="s1">..</span><span class="s2">end</span><span class="s1">].</span><span class="s2">iter</span><span class="s1">().</span><span class="s2">collect</span><span class="s1">()</span><span class="s3">;</span>
|
|
<a name="l67"><span class="ln">67 </span></a>
|
|
<a name="l68"><span class="ln">68 </span></a> <span class="s0">if </span><span class="s2">face_indices</span><span class="s1">.</span><span class="s2">len</span><span class="s1">() != </span><span class="s4">3 </span><span class="s1">{</span>
|
|
<a name="l69"><span class="ln">69 </span></a> <span class="s0">return </span><span class="s2">Err</span><span class="s1">(</span><span class="s6">"we only handle triangulated faces"</span><span class="s1">.</span><span class="s2">to_string</span><span class="s1">())</span><span class="s3">;</span>
|
|
<a name="l70"><span class="ln">70 </span></a> <span class="s1">}</span>
|
|
<a name="l71"><span class="ln">71 </span></a> <span class="s2">index_data</span><span class="s1">.</span><span class="s2">push</span><span class="s1">([*</span><span class="s2">face_indices</span><span class="s1">[</span><span class="s4">0</span><span class="s1">]</span><span class="s3">, </span><span class="s1">*</span><span class="s2">face_indices</span><span class="s1">[</span><span class="s4">1</span><span class="s1">]</span><span class="s3">, </span><span class="s1">*</span><span class="s2">face_indices</span><span class="s1">[</span><span class="s4">2</span><span class="s1">]])</span><span class="s3">;</span>
|
|
<a name="l72"><span class="ln">72 </span></a> <span class="s2">next_face </span><span class="s1">= </span><span class="s2">end</span><span class="s3">;</span>
|
|
<a name="l73"><span class="ln">73 </span></a> <span class="s1">}</span>
|
|
<a name="l74"><span class="ln">74 </span></a>
|
|
<a name="l75"><span class="ln">75 </span></a> <span class="s0">if </span><span class="s2">mesh</span><span class="s1">.</span><span class="s2">positions</span><span class="s1">.</span><span class="s2">len</span><span class="s1">() % </span><span class="s4">3 </span><span class="s1">!= </span><span class="s4">0 </span><span class="s1">{</span>
|
|
<a name="l76"><span class="ln">76 </span></a> <span class="s0">return </span><span class="s2">Err</span><span class="s1">(</span><span class="s2">format</span><span class="s1">!(</span><span class="s6">"position array not % 3 : {}"</span><span class="s3">, </span><span class="s2">mesh</span><span class="s1">.</span><span class="s2">positions</span><span class="s1">.</span><span class="s2">len</span><span class="s1">()))</span>
|
|
<a name="l77"><span class="ln">77 </span></a> <span class="s1">}</span>
|
|
<a name="l78"><span class="ln">78 </span></a> <span class="s0">if </span><span class="s2">mesh</span><span class="s1">.</span><span class="s2">texcoords</span><span class="s1">.</span><span class="s2">len</span><span class="s1">() % </span><span class="s4">2 </span><span class="s1">!= </span><span class="s4">0 </span><span class="s1">{</span>
|
|
<a name="l79"><span class="ln">79 </span></a> <span class="s0">return </span><span class="s2">Err</span><span class="s1">(</span><span class="s2">format</span><span class="s1">!(</span><span class="s6">"position array not % 3 : {}"</span><span class="s3">, </span><span class="s2">mesh</span><span class="s1">.</span><span class="s2">positions</span><span class="s1">.</span><span class="s2">len</span><span class="s1">()))</span>
|
|
<a name="l80"><span class="ln">80 </span></a> <span class="s1">}</span>
|
|
<a name="l81"><span class="ln">81 </span></a> <span class="s0">if </span><span class="s2">mesh</span><span class="s1">.</span><span class="s2">normals</span><span class="s1">.</span><span class="s2">is_empty</span><span class="s1">() {</span>
|
|
<a name="l82"><span class="ln">82 </span></a> <span class="s0">return </span><span class="s2">Err</span><span class="s1">(</span><span class="s2">format</span><span class="s1">!(</span><span class="s6">"It would be best if this had normals"</span><span class="s1">))</span>
|
|
<a name="l83"><span class="ln">83 </span></a> <span class="s1">}</span>
|
|
<a name="l84"><span class="ln">84 </span></a> <span class="s0">if </span><span class="s2">mesh</span><span class="s1">.</span><span class="s2">texcoords</span><span class="s1">.</span><span class="s2">is_empty</span><span class="s1">() {</span>
|
|
<a name="l85"><span class="ln">85 </span></a> <span class="s2">log</span><span class="s1">::</span><span class="s2">info</span><span class="s1">!(</span><span class="s6">"</span><span class="s0">\t</span><span class="s6">Mesh texture coordinates empty"</span><span class="s1">)</span>
|
|
<a name="l86"><span class="ln">86 </span></a> <span class="s1">}</span>
|
|
<a name="l87"><span class="ln">87 </span></a>
|
|
<a name="l88"><span class="ln">88 </span></a> <span class="s0">for </span><span class="s2">v </span><span class="s0">in </span><span class="s4">0</span><span class="s1">..</span><span class="s2">mesh</span><span class="s1">.</span><span class="s2">positions</span><span class="s1">.</span><span class="s2">len</span><span class="s1">() / </span><span class="s4">3 </span><span class="s1">{</span>
|
|
<a name="l89"><span class="ln">89 </span></a> <span class="s0">let </span><span class="s2">texcoords </span><span class="s1">= </span><span class="s0">if </span><span class="s2">mesh</span><span class="s1">.</span><span class="s2">texcoords</span><span class="s1">.</span><span class="s2">len</span><span class="s1">() == </span><span class="s4">0 </span><span class="s1">{</span>
|
|
<a name="l90"><span class="ln">90 </span></a> <span class="s1">[</span><span class="s4">0</span><span class="s1">.</span><span class="s4">0</span><span class="s3">, </span><span class="s4">0</span><span class="s1">.</span><span class="s4">0</span><span class="s1">]</span>
|
|
<a name="l91"><span class="ln">91 </span></a> <span class="s1">} </span><span class="s0">else </span><span class="s1">{</span>
|
|
<a name="l92"><span class="ln">92 </span></a> <span class="s1">[</span><span class="s2">mesh</span><span class="s1">.</span><span class="s2">texcoords</span><span class="s1">[</span><span class="s4">2 </span><span class="s1">* </span><span class="s2">v</span><span class="s1">]</span><span class="s3">, </span><span class="s2">mesh</span><span class="s1">.</span><span class="s2">texcoords</span><span class="s1">[</span><span class="s4">2 </span><span class="s1">* </span><span class="s2">v </span><span class="s1">+ </span><span class="s4">1</span><span class="s1">]]</span>
|
|
<a name="l93"><span class="ln">93 </span></a> <span class="s1">}</span><span class="s3">;</span>
|
|
<a name="l94"><span class="ln">94 </span></a>
|
|
<a name="l95"><span class="ln">95 </span></a> <span class="s2">vertex_data</span><span class="s1">.</span><span class="s2">push</span><span class="s1">(</span><span class="s2">Vertex</span><span class="s1">::</span><span class="s2">from</span><span class="s1">(</span>
|
|
<a name="l96"><span class="ln">96 </span></a> <span class="s1">[</span>
|
|
<a name="l97"><span class="ln">97 </span></a> <span class="s2">mesh</span><span class="s1">.</span><span class="s2">positions</span><span class="s1">[</span><span class="s4">3 </span><span class="s1">* </span><span class="s2">v</span><span class="s1">]</span><span class="s3">,</span>
|
|
<a name="l98"><span class="ln">98 </span></a> <span class="s2">mesh</span><span class="s1">.</span><span class="s2">positions</span><span class="s1">[</span><span class="s4">3 </span><span class="s1">* </span><span class="s2">v </span><span class="s1">+ </span><span class="s4">1</span><span class="s1">]</span><span class="s3">,</span>
|
|
<a name="l99"><span class="ln">99 </span></a> <span class="s2">mesh</span><span class="s1">.</span><span class="s2">positions</span><span class="s1">[</span><span class="s4">3 </span><span class="s1">* </span><span class="s2">v </span><span class="s1">+ </span><span class="s4">2</span><span class="s1">]</span><span class="s3">,</span>
|
|
<a name="l100"><span class="ln">100 </span></a> <span class="s1">]</span><span class="s3">,</span>
|
|
<a name="l101"><span class="ln">101 </span></a> <span class="s1">[</span>
|
|
<a name="l102"><span class="ln">102 </span></a> <span class="s2">mesh</span><span class="s1">.</span><span class="s2">normals</span><span class="s1">[</span><span class="s4">3 </span><span class="s1">* </span><span class="s2">v</span><span class="s1">]</span><span class="s3">,</span>
|
|
<a name="l103"><span class="ln">103 </span></a> <span class="s2">mesh</span><span class="s1">.</span><span class="s2">normals</span><span class="s1">[</span><span class="s4">3 </span><span class="s1">* </span><span class="s2">v </span><span class="s1">+ </span><span class="s4">1</span><span class="s1">]</span><span class="s3">,</span>
|
|
<a name="l104"><span class="ln">104 </span></a> <span class="s2">mesh</span><span class="s1">.</span><span class="s2">normals</span><span class="s1">[</span><span class="s4">3 </span><span class="s1">* </span><span class="s2">v </span><span class="s1">+ </span><span class="s4">2</span><span class="s1">]</span><span class="s3">,</span>
|
|
<a name="l105"><span class="ln">105 </span></a> <span class="s1">]</span><span class="s3">,</span>
|
|
<a name="l106"><span class="ln">106 </span></a> <span class="s2">texcoords</span><span class="s3">,</span>
|
|
<a name="l107"><span class="ln">107 </span></a> <span class="s1">))</span><span class="s3">;</span>
|
|
<a name="l108"><span class="ln">108 </span></a> <span class="s1">}</span>
|
|
<a name="l109"><span class="ln">109 </span></a> <span class="s1">}</span>
|
|
<a name="l110"><span class="ln">110 </span></a> <span class="s2">Ok</span><span class="s1">(</span><span class="s2">RawMesh </span><span class="s1">{</span>
|
|
<a name="l111"><span class="ln">111 </span></a> <span class="s2">vertices</span><span class="s1">: </span><span class="s2">vertex_data</span><span class="s1">.</span><span class="s2">to_vec</span><span class="s1">()</span><span class="s3">,</span>
|
|
<a name="l112"><span class="ln">112 </span></a> <span class="s2">indices</span><span class="s1">: </span><span class="s2">index_data</span><span class="s1">.</span><span class="s2">to_vec</span><span class="s1">()</span><span class="s3">,</span>
|
|
<a name="l113"><span class="ln">113 </span></a> <span class="s1">})</span>
|
|
<a name="l114"><span class="ln">114 </span></a><span class="s1">}</span>
|
|
<a name="l115"><span class="ln">115 </span></a>
|
|
<a name="l116"><span class="ln">116 </span></a><span class="s7">// pub fn create_quad_mesh() -> RawMesh {</span>
|
|
<a name="l117"><span class="ln">117 </span></a><span class="s7">//</span>
|
|
<a name="l118"><span class="ln">118 </span></a><span class="s7">// let mut index_data: Vec<[u32; 3]> = Vec::new();</span>
|
|
<a name="l119"><span class="ln">119 </span></a><span class="s7">// let mut vertex_data = Vec::new();</span>
|
|
<a name="l120"><span class="ln">120 </span></a><span class="s7">//</span>
|
|
<a name="l121"><span class="ln">121 </span></a><span class="s7">// vertex_data.push(Vertex::from(</span>
|
|
<a name="l122"><span class="ln">122 </span></a><span class="s7">// [</span>
|
|
<a name="l123"><span class="ln">123 </span></a><span class="s7">// mesh.positions[3 * v],</span>
|
|
<a name="l124"><span class="ln">124 </span></a><span class="s7">// mesh.positions[3 * v + 1],</span>
|
|
<a name="l125"><span class="ln">125 </span></a><span class="s7">// mesh.positions[3 * v + 2],</span>
|
|
<a name="l126"><span class="ln">126 </span></a><span class="s7">// ],</span>
|
|
<a name="l127"><span class="ln">127 </span></a><span class="s7">// [</span>
|
|
<a name="l128"><span class="ln">128 </span></a><span class="s7">// mesh.normals[3 * v],</span>
|
|
<a name="l129"><span class="ln">129 </span></a><span class="s7">// mesh.normals[3 * v + 1],</span>
|
|
<a name="l130"><span class="ln">130 </span></a><span class="s7">// mesh.normals[3 * v + 2],</span>
|
|
<a name="l131"><span class="ln">131 </span></a><span class="s7">// ],</span>
|
|
<a name="l132"><span class="ln">132 </span></a><span class="s7">// [mesh.texcoords[2 * v], mesh.texcoords[2 * v + 1]],</span>
|
|
<a name="l133"><span class="ln">133 </span></a><span class="s7">// ));</span>
|
|
<a name="l134"><span class="ln">134 </span></a><span class="s7">//</span>
|
|
<a name="l135"><span class="ln">135 </span></a><span class="s7">// RawMesh {</span>
|
|
<a name="l136"><span class="ln">136 </span></a><span class="s7">// vertices: vertex_data.to_vec(),</span>
|
|
<a name="l137"><span class="ln">137 </span></a><span class="s7">// indices: index_data.to_vec(),</span>
|
|
<a name="l138"><span class="ln">138 </span></a><span class="s7">// }</span>
|
|
<a name="l139"><span class="ln">139 </span></a><span class="s7">// }</span>
|
|
<a name="l140"><span class="ln">140 </span></a></pre>
|
|
</body>
|
|
</html> |