Files
phy/tobj/fn.load_obj_buf.html
Orion Kindel 0ce894e6b0 doc
2025-03-18 10:30:23 -05:00

56 lines
6.8 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Load the various meshes in an `OBJ` buffer."><title>load_obj_buf in tobj - Rust</title><script>if(window.location.protocol!=="file:")document.head.insertAdjacentHTML("beforeend","SourceSerif4-Regular-6b053e98.ttf.woff2,FiraSans-Regular-0fe48ade.woff2,FiraSans-Medium-e1aa3f0a.woff2,SourceCodePro-Regular-8badfe75.ttf.woff2,SourceCodePro-Semibold-aa29a496.ttf.woff2".split(",").map(f=>`<link rel="preload" as="font" type="font/woff2" crossorigin href="../static.files/${f}">`).join(""))</script><link rel="stylesheet" href="../static.files/normalize-9960930a.css"><link rel="stylesheet" href="../static.files/rustdoc-42caa33d.css"><meta name="rustdoc-vars" data-root-path="../" data-static-root-path="../static.files/" data-current-crate="tobj" data-themes="" data-resource-suffix="" data-rustdoc-version="1.84.0 (9fc6b4312 2025-01-07)" data-channel="1.84.0" data-search-js="search-92e6798f.js" data-settings-js="settings-0f613d39.js" ><script src="../static.files/storage-59e33391.js"></script><script defer src="sidebar-items.js"></script><script defer src="../static.files/main-5f194d8c.js"></script><noscript><link rel="stylesheet" href="../static.files/noscript-893ab5e7.css"></noscript><link rel="alternate icon" type="image/png" href="../static.files/favicon-32x32-6580c154.png"><link rel="icon" type="image/svg+xml" href="../static.files/favicon-044be391.svg"></head><body class="rustdoc fn"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="mobile-topbar"><button class="sidebar-menu-toggle" title="show sidebar"></button></nav><nav class="sidebar"><div class="sidebar-crate"><h2><a href="../tobj/index.html">tobj</a><span class="version">4.0.2</span></h2></div><div class="sidebar-elems"><section id="rustdoc-toc"><h2 class="location"><a href="#">load_<wbr>obj_<wbr>buf</a></h2><h3><a href="#">Sections</a></h3><ul class="block top-toc"><li><a href="#arguments" title="Arguments">Arguments</a></li><li><a href="#example" title="Example">Example</a></li></ul></section><div id="rustdoc-modnav"><h2 class="in-crate"><a href="index.html">In crate tobj</a></h2></div></div></nav><div class="sidebar-resizer"></div><main><div class="width-limiter"><rustdoc-search></rustdoc-search><section id="main-content" class="content"><div class="main-heading"><span class="rustdoc-breadcrumbs"><a href="index.html">tobj</a></span><h1>Function <span class="fn">load_obj_buf</span><button id="copy-path" title="Copy item path to clipboard">Copy item path</button></h1><rustdoc-toolbar></rustdoc-toolbar><span class="sub-heading"><a class="src" href="../src/tobj/lib.rs.html#1638-1845">Source</a> </span></div><pre class="rust item-decl"><code>pub fn load_obj_buf&lt;B, ML&gt;(
reader: <a class="primitive" href="https://doc.rust-lang.org/1.84.0/std/primitive.reference.html">&amp;mut B</a>,
load_options: &amp;<a class="struct" href="struct.LoadOptions.html" title="struct tobj::LoadOptions">LoadOptions</a>,
material_loader: ML,
) -&gt; <a class="type" href="type.LoadResult.html" title="type tobj::LoadResult">LoadResult</a><div class="where">where
B: <a class="trait" href="https://doc.rust-lang.org/1.84.0/std/io/trait.BufRead.html" title="trait std::io::BufRead">BufRead</a>,
ML: <a class="trait" href="https://doc.rust-lang.org/1.84.0/core/ops/function/trait.Fn.html" title="trait core::ops::function::Fn">Fn</a>(&amp;<a class="struct" href="https://doc.rust-lang.org/1.84.0/std/path/struct.Path.html" title="struct std::path::Path">Path</a>) -&gt; <a class="type" href="type.MTLLoadResult.html" title="type tobj::MTLLoadResult">MTLLoadResult</a>,</div></code></pre><details class="toggle top-doc" open><summary class="hideme"><span>Expand description</span></summary><div class="docblock"><p>Load the various meshes in an <code>OBJ</code> buffer.</p>
<p>This could e.g. be a network stream, a text file already in memory etc.</p>
<h2 id="arguments"><a class="doc-anchor" href="#arguments">§</a>Arguments</h2>
<p>You must pass a <code>material_loader</code> function, which will return a material
given a name.</p>
<p>A trivial material loader may just look at the file name and then call
<code>load_mtl_buf</code> with the in-memory MTL file source.</p>
<p>Alternatively it could pass an <code>MTL</code> file in memory to <code>load_mtl_buf</code> to
parse materials from some buffer.</p>
<ul>
<li><code>load_options</code> Governs on-the-fly processing of the mesh during loading.
See <a href="struct.LoadOptions.html" title="struct tobj::LoadOptions"><code>LoadOptions</code></a> for more information.</li>
</ul>
<h2 id="example"><a class="doc-anchor" href="#example">§</a>Example</h2>
<p>The test for <code>load_obj_buf</code> includes the OBJ and MTL files as strings
and uses a <code>Cursor</code> to provide a <code>BufRead</code> interface on the buffer.</p>
<div class="example-wrap"><pre class="rust rust-example-rendered"><code><span class="kw">use </span>std::{env, fs::File, io::BufReader};
<span class="kw">let </span>dir = env::current_dir().unwrap();
<span class="kw">let </span><span class="kw-2">mut </span>cornell_box_obj = dir.clone();
cornell_box_obj.push(<span class="string">"obj/cornell_box.obj"</span>);
<span class="kw">let </span><span class="kw-2">mut </span>cornell_box_file = BufReader::new(File::open(cornell_box_obj.as_path()).unwrap());
<span class="kw">let </span><span class="kw-2">mut </span>cornell_box_mtl1 = dir.clone();
cornell_box_mtl1.push(<span class="string">"obj/cornell_box.mtl"</span>);
<span class="kw">let </span><span class="kw-2">mut </span>cornell_box_mtl2 = dir.clone();
cornell_box_mtl2.push(<span class="string">"obj/cornell_box2.mtl"</span>);
<span class="kw">let </span>m = tobj::load_obj_buf(
<span class="kw-2">&amp;mut </span>cornell_box_file,
<span class="kw-2">&amp;</span>tobj::LoadOptions {
triangulate: <span class="bool-val">true</span>,
single_index: <span class="bool-val">true</span>,
..Default::default()
},
|p| <span class="kw">match </span>p.file_name().unwrap().to_str().unwrap() {
<span class="string">"cornell_box.mtl" </span>=&gt; {
<span class="kw">let </span>f = File::open(cornell_box_mtl1.as_path()).unwrap();
tobj::load_mtl_buf(<span class="kw-2">&amp;mut </span>BufReader::new(f))
}
<span class="string">"cornell_box2.mtl" </span>=&gt; {
<span class="kw">let </span>f = File::open(cornell_box_mtl2.as_path()).unwrap();
tobj::load_mtl_buf(<span class="kw-2">&amp;mut </span>BufReader::new(f))
}
<span class="kw">_ </span>=&gt; <span class="macro">unreachable!</span>(),
},
);</code></pre></div>
</div></details></section></div></main></body></html>