mirror of
https://github.com/storytold/texturecraft.git
synced 2026-11-26 01:10:48 +01:00
fix(export): render the implicit material's maps for OBJ only
GLB and USD export the material-less mesh as it is and drop those maps, so rendering them only cost time.
This commit is contained in:
1 parent
15a06149d7
commit
41dcf2d4ef
1 file changed
+7
-7
@@ -102,12 +102,12 @@ impl Session {
|
||||
pub fn mesh_obj_with_mtl(&mut self, stem: &str) -> Result<(Vec<u8>, texturecraft_formats::NamedFiles)> {
|
||||
// shortcut: UV-tiled sets get no maps (the OBJ keeps the mesh's UDIM UVs and an MTL map is
|
||||
// one image); their tiles export through Export textures with `$udim` names.
|
||||
let files = self.material_files(texturecraft_formats::usd_export_options(), false)?;
|
||||
let mut mesh = self.source_mesh();
|
||||
// A mesh without materials has one implicit material (and texture set).
|
||||
if mesh.materials.is_empty() {
|
||||
mesh.materials.push("default".into());
|
||||
}
|
||||
let files = self.material_files(texturecraft_formats::usd_export_options(), false, mesh.materials.len())?;
|
||||
Ok(texturecraft_formats::obj_with_mtl(&mesh, &self.doc.project.name, stem, &files))
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ impl Session {
|
||||
/// composite, through the texture export pipeline) embedded. glTF has no UV tiles: a
|
||||
/// UV-tiled set embeds its tile atlas, with the mesh's UVs in atlas space.
|
||||
pub fn mesh_glb_bytes(&mut self) -> Result<Vec<u8>> {
|
||||
let files = self.material_files(texturecraft_formats::glb_export_options(), true)?;
|
||||
let files = self.material_files(texturecraft_formats::glb_export_options(), true, self.mesh.materials.len())?;
|
||||
let textures: Vec<_> = files.into_iter().map(texturecraft_formats::GlbTextures::from_files).collect();
|
||||
texturecraft_formats::glb_bytes(&self.mesh, &self.doc.project.name, &textures).map_err(fe)
|
||||
}
|
||||
@@ -123,15 +123,15 @@ impl Session {
|
||||
/// The working mesh as USD with a UsdPreviewSurface per material (textures like
|
||||
/// [`Session::mesh_glb_bytes`]): usdz packages them, usda / usdc list them to write alongside.
|
||||
pub fn mesh_usd(&mut self, format: texturecraft_formats::UsdFormat) -> Result<texturecraft_formats::UsdExport> {
|
||||
let files = self.material_files(texturecraft_formats::usd_export_options(), true)?;
|
||||
let files = self.material_files(texturecraft_formats::usd_export_options(), true, self.mesh.materials.len())?;
|
||||
texturecraft_formats::usd_bytes(&self.mesh, &self.doc.project.name, &files, format).map_err(fe)
|
||||
}
|
||||
|
||||
/// Each material's texture set rendered with `opts` (as a tile atlas for UV-tiled sets, or
|
||||
/// nothing for them without `tiled`).
|
||||
fn material_files(&mut self, opts: ExportOptions, tiled: bool) -> Result<Vec<Vec<ExportedFile>>> {
|
||||
/// The texture sets of the first `materials` materials rendered with `opts` (as a tile atlas
|
||||
/// for UV-tiled sets, or nothing for them without `tiled`).
|
||||
fn material_files(&mut self, opts: ExportOptions, tiled: bool, materials: usize) -> Result<Vec<Vec<ExportedFile>>> {
|
||||
let opts = ExportOptions { atlas: true, ..opts };
|
||||
(0..self.mesh.materials.len().max(1))
|
||||
(0..materials)
|
||||
.map(|m| match self.doc.project.texture_sets.iter().position(|t| t.material == m) {
|
||||
Some(ts) if tiled || self.doc.project.texture_sets.get(ts).is_some_and(|t| t.tile_grid().is_none()) => self.export_files(&[ts], &opts),
|
||||
_ => Ok(Vec::new()),
|
||||
|
||||
Reference in new issue
Block a user