mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-30 02:07:10 +01:00
3D: meshes carry UVs, smooth bevel normals and a part index
Every mesh the 3D effects build now carries texture coordinates for each corner and a part for each triangle (front, back, side, front bevel, back bevel, end cap, cut side). Corners shared by two bands of one bevel take the mean of the bands' normals unless the bevel turns there by 60 degrees or more or a band lies flat toward the front or back, and Inflate's puffed front and back keep the surface's own normals. The vector facets do not change. - Caps, Rotate's plane and Inflate's front and back map the art's bounds; walls and bevels run u along each contour and v from the front cap's edge to the back cap's; Revolve's side runs u around the sweep and v along the profile. - OBJ, glTF and USD write every corner's texture coordinates, not only those of faces with mapped graphics. - Mesh::join checks its index offsets, and joining or exporting a mesh whose lists do not match or that holds a value that is not a number is an error. Docs: docs/three-d.md (3D meshes), docs/mcp.md, docs/effects-parity.md, docs/target-app-parity.md.
This commit is contained in:
1 parent
88f5ece15b
commit
4a6924669e
45 files changed
+1081
-109
No files matched your search
@@ -117,7 +117,7 @@ pub use stylize::{ScribbleSetting, scribble_setting_id, scribble_settings};
|
||||
pub use svg_filter::SVG_FILTER;
|
||||
pub use trap::TRAP;
|
||||
pub use vectorcraft_three_d::PlanarFace;
|
||||
pub use vectorcraft_three_d::{BevelProfile, Mesh};
|
||||
pub use vectorcraft_three_d::{BevelProfile, Mesh, MeshPart};
|
||||
pub use warp::{WARP_NET, WarpNet, WarpStyle, map_version, warp_point, warp_version};
|
||||
|
||||
mod catalog;
|
||||
|
||||
@@ -893,8 +893,11 @@ fn surface_meshes(
|
||||
}
|
||||
let (mesh, on) = vectorcraft_three_d::revolve_mesh_surface(path, rule, b, options)?;
|
||||
let (mut side, mut rest, mut art) = (vectorcraft_three_d::Mesh::default(), vectorcraft_three_d::Mesh::default(), vec![]);
|
||||
for (t, points) in mesh.triangles.iter().zip(&on) {
|
||||
let corner = |i: u32| mesh.positions.get(i as usize).copied().zip(mesh.normals.get(i as usize).copied());
|
||||
for ((t, points), part) in mesh.triangles.iter().zip(&on).zip(&mesh.parts) {
|
||||
let corner = |i: u32| {
|
||||
let i = i as usize;
|
||||
Some((*mesh.positions.get(i)?, *mesh.normals.get(i)?, *mesh.uvs.get(i)?))
|
||||
};
|
||||
let Some(corners) = t.iter().map(|&i| corner(i)).collect::<Option<Vec<_>>>() else { continue };
|
||||
let into = match points {
|
||||
Some(points) => {
|
||||
@@ -904,11 +907,13 @@ fn surface_meshes(
|
||||
None => &mut rest,
|
||||
};
|
||||
let base = into.positions.len() as u32;
|
||||
for (p, n) in corners {
|
||||
for (p, n, uv) in corners {
|
||||
into.positions.push(p);
|
||||
into.normals.push(n);
|
||||
into.uvs.push(uv);
|
||||
}
|
||||
into.triangles.push([base, base + 1, base + 2]);
|
||||
into.parts.push(*part);
|
||||
}
|
||||
let mut out = vec![];
|
||||
if !rest.is_empty() {
|
||||
|
||||
@@ -2893,10 +2893,13 @@ fn split_graphics(id: &str, p: &Value, bounds: Rect, mesh: Mesh, (color, opacity
|
||||
};
|
||||
let Some(on_mesh) = on_mesh else { continue };
|
||||
let (mut taken, mut left, mut art) = (Mesh::default(), Mesh::default(), vec![]);
|
||||
for t in &rest.triangles {
|
||||
let corner = |i: u32| rest.positions.get(i as usize).copied().zip(rest.normals.get(i as usize).copied());
|
||||
for (t, part) in rest.triangles.iter().zip(&rest.parts) {
|
||||
let corner = |i: u32| {
|
||||
let i = i as usize;
|
||||
Some((*rest.positions.get(i)?, *rest.normals.get(i)?, *rest.uvs.get(i)?))
|
||||
};
|
||||
let Some(corners) = t.iter().map(|&i| corner(i)).collect::<Option<Vec<_>>>() else { continue };
|
||||
let points: Option<Vec<Point>> = corners.iter().map(|(m, n)| on_mesh.art_point(*m, *n)).collect();
|
||||
let points: Option<Vec<Point>> = corners.iter().map(|(m, n, _)| on_mesh.art_point(*m, *n)).collect();
|
||||
let into = match points {
|
||||
Some(points) => {
|
||||
art.extend(points);
|
||||
@@ -2905,11 +2908,13 @@ fn split_graphics(id: &str, p: &Value, bounds: Rect, mesh: Mesh, (color, opacity
|
||||
None => &mut left,
|
||||
};
|
||||
let base = into.positions.len() as u32;
|
||||
for (m, n) in corners {
|
||||
for (m, n, uv) in corners {
|
||||
into.positions.push(m);
|
||||
into.normals.push(n);
|
||||
into.uvs.push(uv);
|
||||
}
|
||||
into.triangles.push([base, base + 1, base + 2]);
|
||||
into.parts.push(*part);
|
||||
}
|
||||
rest = left;
|
||||
if !taken.is_empty() {
|
||||
|
||||
@@ -7,7 +7,9 @@
|
||||
//! about the point the object turns about: in points in OBJ and USD (whose layer says how many
|
||||
//! meters a unit is), in meters in glTF, as its specification asks. glTF and USD colors are linear,
|
||||
//! as their specifications ask; MTL colors are the display colors. Materials are two-sided, since
|
||||
//! an open solid or a turned plane is seen from both sides.
|
||||
//! an open solid or a turned plane is seen from both sides. Every corner carries its normal and
|
||||
//! texture coordinates (`vt`, `TEXCOORD_0`, `primvars:st`); a mesh whose lists do not match, or
|
||||
//! that holds a value that is not a number, is refused before anything is written.
|
||||
//!
|
||||
//! The graphics mapped onto a face of a solid ([`textures`]) are a PNG picture of that face: its
|
||||
//! color with the graphics drawn over it, flat and unshaded, which the face's own mesh shows through
|
||||
@@ -140,6 +142,7 @@ pub(crate) fn image_maps(textures: &[Option<Texture>]) -> Vec<bool> {
|
||||
/// OBJ with its MTL after it and the PNG files of `textures` last (an OBJ's opacity maps each after
|
||||
/// its texture). `textures` holds the picture of each part that has one, in the order of `parts`.
|
||||
pub(crate) fn mesh_files(stem: &str, format: &str, parts: &[SolidMesh], textures: &[Option<Texture>]) -> Result<Vec<(String, Vec<u8>)>, String> {
|
||||
check_parts(parts)?;
|
||||
let (images, image) = images(parts.len(), textures);
|
||||
let maps: Vec<bool> = images.iter().map(|(_, map)| map.is_some()).collect();
|
||||
let names = mesh_file_names(stem, format, &maps)?;
|
||||
@@ -180,6 +183,21 @@ impl Scene<'_> {
|
||||
let t = self.textures.get(k)?.as_ref()?;
|
||||
Some((t.uv.as_slice(), (*self.image.get(k)?)?))
|
||||
}
|
||||
|
||||
/// Part `k`'s texture coordinates, one for each corner, 0 to 1 across from the left and down
|
||||
/// from the top: its picture's when it has one, else its mesh's own.
|
||||
fn coords(&self, k: usize) -> Option<&[[f64; 2]]> {
|
||||
let count = self.parts.get(k)?.mesh.positions.len();
|
||||
let own = self.parts.get(k).map(|p| p.mesh.uvs.as_slice());
|
||||
self.texture(k).map(|(uv, _)| uv).into_iter().chain(own).find(|uv| uv.len() == count && count > 0)
|
||||
}
|
||||
}
|
||||
|
||||
/// An error when a part's mesh cannot be written as it is: its lists do not match, or a
|
||||
/// position, normal or texture coordinate is not a number
|
||||
/// ([`vectorcraft_render::effects::Mesh::check`]).
|
||||
fn check_parts(parts: &[SolidMesh]) -> Result<(), String> {
|
||||
parts.iter().try_for_each(|p| p.mesh.check())
|
||||
}
|
||||
|
||||
/// A material: a color, with a picture that replaces its red, green and blue.
|
||||
@@ -230,7 +248,7 @@ fn obj(stem: &str, scene: &Scene) -> (String, String) {
|
||||
}
|
||||
// OBJ's texture coordinates run up from the picture's bottom.
|
||||
for k in 0..parts.len() {
|
||||
for uv in scene.texture(k).map(|(uv, _)| uv).unwrap_or_default() {
|
||||
for uv in scene.coords(k).unwrap_or_default() {
|
||||
let _ = writeln!(o, "vt {} {}", num(uv[0]), num(1.0 - uv[1]));
|
||||
}
|
||||
}
|
||||
@@ -243,9 +261,9 @@ fn obj(stem: &str, scene: &Scene) -> (String, String) {
|
||||
for (k, p) in parts.iter().enumerate() {
|
||||
let _ = writeln!(o, "g Solid_{}", k + 1);
|
||||
let _ = writeln!(o, "usemtl Material_{}", material.get(k).copied().unwrap_or(0) + 1);
|
||||
let textured = scene.texture(k).filter(|(uv, _)| uv.len() == p.mesh.positions.len()).is_some();
|
||||
let coords = scene.coords(k).is_some();
|
||||
for t in &p.mesh.triangles {
|
||||
if textured {
|
||||
if coords {
|
||||
let [a, b, c] = t.map(|i| i as usize);
|
||||
let corner = |i: usize| format!("{}/{}/{}", i + base, i + uv_base, i + base);
|
||||
let _ = writeln!(o, "f {} {} {}", corner(a), corner(b), corner(c));
|
||||
@@ -255,7 +273,7 @@ fn obj(stem: &str, scene: &Scene) -> (String, String) {
|
||||
}
|
||||
}
|
||||
base += p.mesh.positions.len();
|
||||
uv_base += scene.texture(k).map_or(0, |(uv, _)| uv.len());
|
||||
uv_base += scene.coords(k).map_or(0, <[_]>::len);
|
||||
}
|
||||
let mut m = String::new();
|
||||
for (k, mat) in materials.iter().enumerate() {
|
||||
@@ -313,7 +331,7 @@ fn gltf(stem: &str, scene: &Scene) -> String {
|
||||
"material": material.get(k).copied().unwrap_or(0),
|
||||
});
|
||||
// glTF's texture coordinates run down from the picture's top, as the picture's own do.
|
||||
if let Some((uv, _)) = scene.texture(k).filter(|(uv, _)| uv.len() == count) {
|
||||
if let Some(uv) = scene.coords(k) {
|
||||
let bytes = uv.iter().flatten().flat_map(|x| (*x as f32).to_le_bytes()).collect();
|
||||
let coords = view(&mut buffer, bytes, 34962);
|
||||
primitive["attributes"]["TEXCOORD_0"] = json!(accessors.len());
|
||||
@@ -415,7 +433,7 @@ fn usda(stem: &str, scene: &Scene) -> String {
|
||||
);
|
||||
let _ = writeln!(u, " float[] primvars:displayOpacity = [{}] (\n interpolation = \"constant\"\n )", c[3]);
|
||||
// USD's texture coordinates run up from the picture's bottom.
|
||||
if let Some((uv, _)) = scene.texture(k).filter(|(uv, _)| uv.len() == p.mesh.positions.len()) {
|
||||
if let Some(uv) = scene.coords(k) {
|
||||
let st = list(uv.iter().map(|t| format!("({}, {})", num(t[0]), num(1.0 - t[1]))).collect());
|
||||
let _ = writeln!(u, " texCoord2f[] primvars:st = [{st}] (\n interpolation = \"vertex\"\n )");
|
||||
}
|
||||
|
||||
@@ -1,12 +1,18 @@
|
||||
use serde_json::Value;
|
||||
use vectorcraft_render::effects::{Mesh, SolidMesh};
|
||||
use vectorcraft_render::effects::{Mesh, MeshPart, SolidMesh};
|
||||
|
||||
use super::*;
|
||||
|
||||
/// A 10 × 10 square facing the viewer: two triangles, each with corners of its own.
|
||||
fn square(color: [f32; 4]) -> SolidMesh {
|
||||
let [a, b, c, d] = [[-5.0, -5.0, 0.0], [5.0, -5.0, 0.0], [5.0, 5.0, 0.0], [-5.0, 5.0, 0.0]];
|
||||
let mesh = Mesh { positions: vec![a, b, c, a, c, d], normals: vec![[0.0, 0.0, 1.0]; 6], triangles: vec![[0, 1, 2], [3, 4, 5]] };
|
||||
let mesh = Mesh {
|
||||
positions: vec![a, b, c, a, c, d],
|
||||
normals: vec![[0.0, 0.0, 1.0]; 6],
|
||||
uvs: vec![[0.0, 1.0], [1.0, 1.0], [1.0, 0.0], [0.0, 1.0], [1.0, 0.0], [0.0, 0.0]],
|
||||
triangles: vec![[0, 1, 2], [3, 4, 5]],
|
||||
parts: vec![MeshPart::Front; 2],
|
||||
};
|
||||
SolidMesh::plain(mesh, color)
|
||||
}
|
||||
|
||||
@@ -31,8 +37,9 @@ fn obj_numbers_corners_across_solids_and_names_its_materials() {
|
||||
assert!(obj.starts_with("mtllib Box.mtl\no Box\n"));
|
||||
assert_eq!(obj.lines().filter(|l| l.starts_with("v ")).count(), 18);
|
||||
assert_eq!(obj.lines().filter(|l| l.starts_with("vn ")).count(), 18);
|
||||
assert_eq!(obj.lines().filter(|l| l.starts_with("vt ")).count(), 18);
|
||||
// The third solid's last triangle uses corners 13 to 18; red solids share Material_1.
|
||||
assert_eq!(obj.lines().rfind(|l| l.starts_with("f ")), Some("f 16//16 17//17 18//18"));
|
||||
assert_eq!(obj.lines().rfind(|l| l.starts_with("f ")), Some("f 16/16/16 17/17/17 18/18/18"));
|
||||
assert_eq!(obj.lines().filter(|l| l.starts_with("usemtl ")).collect::<Vec<_>>(), ["usemtl Material_1", "usemtl Material_2", "usemtl Material_1"]);
|
||||
let mtl = text(&files, "Box.mtl");
|
||||
assert_eq!(mtl.matches("newmtl").count(), 2);
|
||||
@@ -64,8 +71,12 @@ fn gltf_holds_its_buffer_and_every_accessor_fits_it() {
|
||||
assert_eq!(g["materials"][1]["alphaMode"], "BLEND");
|
||||
assert!(g["materials"][0].get("alphaMode").is_none());
|
||||
assert_eq!(g["materials"][0]["doubleSided"], true);
|
||||
// Without graphics there are no textures.
|
||||
assert!(g.get("images").is_none() && g.get("textures").is_none() && prims[0]["attributes"].get("TEXCOORD_0").is_none());
|
||||
// Without graphics there are no textures, but every corner has its mesh's texture coordinates.
|
||||
assert!(g.get("images").is_none() && g.get("textures").is_none());
|
||||
for p in prims {
|
||||
let uv = &g["accessors"][p["attributes"]["TEXCOORD_0"].as_u64().unwrap() as usize];
|
||||
assert_eq!((uv["type"].as_str(), uv["count"].as_u64()), (Some("VEC2"), Some(6)));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -82,7 +93,28 @@ fn usda_is_y_up_in_points_with_a_material_for_each_color() {
|
||||
// sRGB 0.5 is about 0.214 linear.
|
||||
assert!(u.contains("color3f inputs:diffuseColor = (0.21404"), "{u}");
|
||||
assert_eq!(u.matches('{').count(), u.matches('}').count());
|
||||
assert!(!u.contains("primvars:st") && !u.contains("UsdUVTexture"));
|
||||
// Each mesh carries its own texture coordinates, up from the bottom, with no picture to show.
|
||||
assert_eq!(u.matches("texCoord2f[] primvars:st = [(0, 0), (1, 0), (1, 1), (0, 0), (1, 1), (0, 1)]").count(), 2, "{u}");
|
||||
assert!(!u.contains("UsdUVTexture"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_mesh_whose_lists_do_not_match_or_hold_no_number_is_refused() {
|
||||
let good = square(RED);
|
||||
let mut nan = square(RED);
|
||||
nan.mesh.uvs[2] = [f64::NAN, 0.0];
|
||||
let mut infinite = square(RED);
|
||||
infinite.mesh.normals[0] = [f64::INFINITY, 0.0, 0.0];
|
||||
let mut short = square(RED);
|
||||
short.mesh.uvs.pop();
|
||||
let mut unnamed = square(RED);
|
||||
unnamed.mesh.parts.pop();
|
||||
for bad in [nan, infinite, short, unnamed] {
|
||||
for format in FORMATS_3D {
|
||||
assert!(plain_files("Box", format, &[good.clone(), bad.clone()]).is_err(), "{format} {bad:?}");
|
||||
}
|
||||
}
|
||||
assert!(plain_files("Box", "obj", &[good]).is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -141,7 +173,10 @@ fn prim_names_are_usd_identifiers() {
|
||||
fn textured(png: &[u8]) -> (Vec<SolidMesh>, Vec<Option<Texture>>) {
|
||||
let uv = vec![[0.0, 1.0], [1.0, 1.0], [1.0, 0.0], [0.0, 1.0], [1.0, 0.0], [0.0, 0.0]];
|
||||
let texture = Texture { png: Arc::new(png.to_vec()), opacity: None, uv };
|
||||
(vec![square(RED), square(BLUE)], vec![None, Some(texture)])
|
||||
// The picture's coordinates replace the mesh's own.
|
||||
let mut blue = square(BLUE);
|
||||
blue.mesh.uvs = vec![[0.25, 0.25]; 6];
|
||||
(vec![square(RED), blue], vec![None, Some(texture)])
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -154,16 +189,18 @@ fn each_format_carries_a_textured_part_with_its_coordinates_and_picture() {
|
||||
assert_eq!(files.iter().map(|(n, _)| n.as_str()).collect::<Vec<_>>(), ["My_Box.obj", "My_Box.mtl", "My_Box-texture-1.png"]);
|
||||
assert_eq!(files[2].1, png);
|
||||
let obj = text(&files, "My_Box.obj");
|
||||
assert_eq!(obj.lines().filter(|l| l.starts_with("vt ")).collect::<Vec<_>>(), ["vt 0 0", "vt 1 0", "vt 1 1", "vt 0 0", "vt 1 1", "vt 0 1"]);
|
||||
assert_eq!(obj.lines().rfind(|l| l.starts_with("f ")), Some("f 10/4/10 11/5/11 12/6/12"));
|
||||
assert!(obj.contains("f 1//1 2//2 3//3"), "the plain part keeps no texture coordinates");
|
||||
// The plain part's own coordinates come first, then the textured part's picture's.
|
||||
let square_vt = ["vt 0 0", "vt 1 0", "vt 1 1", "vt 0 0", "vt 1 1", "vt 0 1"];
|
||||
assert_eq!(obj.lines().filter(|l| l.starts_with("vt ")).collect::<Vec<_>>(), [square_vt, square_vt].concat());
|
||||
assert_eq!(obj.lines().rfind(|l| l.starts_with("f ")), Some("f 10/10/10 11/11/11 12/12/12"));
|
||||
assert!(obj.contains("f 1/1/1 2/2/2 3/3/3"), "the plain part keeps its mesh's texture coordinates");
|
||||
let mtl = text(&files, "My_Box.mtl");
|
||||
assert!(mtl.contains("newmtl Material_2\nKd 1 1 1\nd 1\nillum 1\nmap_Kd -clamp on My_Box-texture-1.png\n"), "{mtl}");
|
||||
assert_eq!(mtl.matches("map_Kd").count(), 1);
|
||||
// glTF: TEXCOORD_0 down from the top, and the picture embedded as a data URI.
|
||||
let g: Value = serde_json::from_str(&text(&mesh_files("Box", "gltf", &parts, &pictures).unwrap(), "Box.gltf")).unwrap();
|
||||
let prims = g["meshes"][0]["primitives"].as_array().unwrap();
|
||||
assert!(prims[0]["attributes"].get("TEXCOORD_0").is_none());
|
||||
assert!(prims[0]["attributes"].get("TEXCOORD_0").is_some(), "the plain part keeps its mesh's texture coordinates");
|
||||
let uv = &g["accessors"][prims[1]["attributes"]["TEXCOORD_0"].as_u64().unwrap() as usize];
|
||||
assert_eq!((uv["type"].as_str(), uv["count"].as_u64(), uv["componentType"].as_u64()), (Some("VEC2"), Some(6), Some(5126)));
|
||||
let view = &g["bufferViews"][uv["bufferView"].as_u64().unwrap() as usize];
|
||||
@@ -182,8 +219,7 @@ fn each_format_carries_a_textured_part_with_its_coordinates_and_picture() {
|
||||
let files = mesh_files("Box", "usda", &parts, &pictures).unwrap();
|
||||
assert_eq!(files.iter().map(|(n, _)| n.as_str()).collect::<Vec<_>>(), ["Box.usda", "Box-texture-1.png"]);
|
||||
let u = text(&files, "Box.usda");
|
||||
assert_eq!(u.matches("primvars:st").count(), 1);
|
||||
assert!(u.contains("texCoord2f[] primvars:st = [(0, 0), (1, 0), (1, 1), (0, 0), (1, 1), (0, 1)]"), "{u}");
|
||||
assert_eq!(u.matches("texCoord2f[] primvars:st = [(0, 0), (1, 0), (1, 1), (0, 0), (1, 1), (0, 1)]").count(), 2, "{u}");
|
||||
assert!(u.contains("color3f inputs:diffuseColor.connect = </Box/Materials/Material_2/Texture.outputs:rgb>"), "{u}");
|
||||
assert!(u.contains("asset inputs:file = @Box-texture-1.png@") && u.contains("uniform token info:id = \"UsdUVTexture\""));
|
||||
assert!(u.contains("float2 inputs:st.connect = </Box/Materials/Material_2/Coordinates.outputs:result>"));
|
||||
|
||||
@@ -301,8 +301,9 @@ fn export_3d_paints_mapped_graphics_on_their_caps_in_every_format() {
|
||||
assert!(is_red(pixel(back, at(20.0), 64)) && is_blue(pixel(back, 64, 64)), "{:?}", pixel(back, 64, 64));
|
||||
// The USDA's front cap shows the front picture through st, up from the picture's bottom.
|
||||
let usda = String::from_utf8(out[0].1.clone()).unwrap();
|
||||
assert_eq!(usda.matches("primvars:st").count(), 2);
|
||||
assert_eq!(usda.matches("UsdUVTexture").count(), 2);
|
||||
assert_eq!(usda.matches("def Mesh").count(), 3, "the walls, the front cap and the back cap");
|
||||
assert_eq!(usda.matches("texCoord2f[] primvars:st").count(), 3, "every mesh carries texture coordinates");
|
||||
// glTF holds both pictures, and a cap's coordinates stay inside its picture.
|
||||
let (mut s, _) = mapped("gltf");
|
||||
let out = files(&run(&mut s, "assets.export3D", json!({})));
|
||||
@@ -354,7 +355,7 @@ fn export_3d_paints_graphics_mapped_onto_a_revolves_side_in_every_format() {
|
||||
let middle = (150.0 * scale) as u32;
|
||||
assert!(is_red(pixel(picture, 256, middle)) && is_blue(pixel(picture, 10, 10)), "{:?}", pixel(picture, 256, middle));
|
||||
let usda = String::from_utf8(out[0].1.clone()).unwrap();
|
||||
assert_eq!((usda.matches("def Mesh").count(), usda.matches("primvars:st").count()), (1, 1), "the side is the only face");
|
||||
assert_eq!((usda.matches("def Mesh").count(), usda.matches("UsdUVTexture").count()), (1, 1), "the side is the only face");
|
||||
// Moved 50 pt around the axis, the graphic moves as far across the picture.
|
||||
let (mut s, _) = revolved("usda", json!({}), 50.0);
|
||||
let out = files(&run(&mut s, "assets.export3D", json!({"textureSize": 512})));
|
||||
@@ -381,7 +382,8 @@ fn a_partial_revolve_keeps_its_cut_sides_plain_beside_its_textured_side() {
|
||||
let out = files(&run(&mut s, "assets.export3D", json!({"textureSize": 128})));
|
||||
assert_eq!(out.iter().map(|(n, _)| n.as_str()).collect::<Vec<_>>(), ["Ball.usda", "Ball-texture-1.png"]);
|
||||
let usda = String::from_utf8(out[0].1.clone()).unwrap();
|
||||
assert_eq!((usda.matches("def Mesh").count(), usda.matches("primvars:st").count()), (2, 1), "the cut sides and the side");
|
||||
assert_eq!((usda.matches("def Mesh").count(), usda.matches("UsdUVTexture").count()), (2, 1), "the cut sides and the side");
|
||||
assert_eq!(usda.matches("texCoord2f[] primvars:st").count(), 2, "the plain cut sides keep their own texture coordinates");
|
||||
let d = &s.doc().unwrap().doc;
|
||||
let id = d.asset(asset).unwrap().nodes[0].0;
|
||||
// Without its graphics the surface is one plain mesh, as before.
|
||||
@@ -476,7 +478,11 @@ fn export_3d_keeps_flat_colors_without_graphics_and_refuses_bad_texture_sizes()
|
||||
let out = files(&run(&mut s, "assets.export3D", json!({"textureSize": 128})));
|
||||
assert_eq!(out.iter().map(|(n, _)| n.as_str()).collect::<Vec<_>>(), ["Box.obj", "Box.mtl"]);
|
||||
let obj = String::from_utf8(out[0].1.clone()).unwrap();
|
||||
assert!(!obj.contains("vt ") && obj.lines().filter(|l| l.starts_with("g ")).count() == 1);
|
||||
assert!(!out[1].1.windows(6).any(|w| w == b"map_Kd") && obj.lines().filter(|l| l.starts_with("g ")).count() == 1);
|
||||
// The plain mesh still carries a texture coordinate, 0 to 1, for every corner.
|
||||
let count = |p: &str| obj.lines().filter(|l| l.starts_with(p)).count();
|
||||
assert!(count("vt ") > 0 && count("vt ") == count("v "));
|
||||
assert!(obj.lines().filter_map(|l| l.strip_prefix("vt ")).flat_map(|l| l.split(' ')).all(|v| (0.0..=1.0).contains(&v.parse::<f64>().unwrap())));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
+41
-13
@@ -23,7 +23,9 @@ mod lights;
|
||||
pub use lights::{Light, Lights, MAX_LIGHTS};
|
||||
mod caps;
|
||||
mod mesh;
|
||||
pub use mesh::{Mesh, MeshedSolid, extrude_mesh, extrude_meshed, inflate_meshed, inflate_meshes, plane_mesh, revolve_mesh, revolve_mesh_surface};
|
||||
pub use mesh::{
|
||||
Mesh, MeshPart, MeshedSolid, extrude_mesh, extrude_meshed, inflate_meshed, inflate_meshes, plane_mesh, revolve_mesh, revolve_mesh_surface,
|
||||
};
|
||||
mod shadow;
|
||||
pub use shadow::{
|
||||
MAX_SHADOW_FACES, Shadow, ShadowCaster, ShadowPlane, ShadowPosition, SolidFaces, TOO_COMPLEX_SHADOW, extrude_shadowed, inflate_shadowed,
|
||||
@@ -1071,9 +1073,21 @@ fn keep_profile(
|
||||
turn: f64,
|
||||
caps: &[usize],
|
||||
surface: Option<SurfaceLayout<'_>>,
|
||||
mut keep: impl FnMut(Vec<V3>, V3, Option<[Point; 4]>) -> Result<(), String>,
|
||||
mut keep: impl FnMut(Vec<V3>, V3, Option<[Point; 4]>, MeshPart, solid::Attrs) -> Result<(), String>,
|
||||
) -> Result<(), String> {
|
||||
let (o, steps) = (at.o, at.steps);
|
||||
// For the mesh's texture, the side runs around the sweep (0 to 1 from its start) and along the
|
||||
// profile (0 to 1 from its first point); each end cap spans its disk.
|
||||
let mut profile = Vec::with_capacity(s.points.len());
|
||||
let mut length = 0.0;
|
||||
for (k, p) in s.points.iter().enumerate() {
|
||||
if let Some(q) = k.checked_sub(1).and_then(|k| s.points.get(k)) {
|
||||
length += q.distance(*p);
|
||||
}
|
||||
profile.push(length);
|
||||
}
|
||||
let along = |k: usize| if length > 1e-12 { (profile.get(k).copied().unwrap_or(0.0) / length).clamp(0.0, 1.0) } else { 0.5 };
|
||||
let around = |j: usize| j as f64 / steps.max(1) as f64;
|
||||
for (i, (pair, hole)) in s.points.windows(2).zip(&s.holes).enumerate() {
|
||||
let [a, b] = pair else { continue };
|
||||
let turn = if *hole { -turn } else { turn };
|
||||
@@ -1088,7 +1102,9 @@ fn keep_profile(
|
||||
let (sin, cos) = (at.sweep * (j as f64 + 0.5) / steps as f64).sin_cos();
|
||||
// The corners on the side surface, as the drawn faces place them.
|
||||
let uv = surface.map(|(along, angle)| surface_corners(*a, *b, at.axis, along.get(i).copied().unwrap_or_default(), angle(j)));
|
||||
keep(vec![v0, v1, v2, v3], o.rotate(V3(dy * cos, -dr, dy * sin)), uv)?;
|
||||
let (u0, u1, w0, w1) = (around(j), around(j + 1), along(i), along(i + 1));
|
||||
let texture = solid::Attrs::Corners(vec![vec![([u0, w0], None), ([u0, w1], None), ([u1, w1], None), ([u1, w0], None)]]);
|
||||
keep(vec![v0, v1, v2, v3], o.rotate(V3(dy * cos, -dr, dy * sin)), uv, MeshPart::Side, texture)?;
|
||||
}
|
||||
}
|
||||
for &index in caps {
|
||||
@@ -1099,7 +1115,14 @@ fn keep_profile(
|
||||
} else {
|
||||
cap.insert(0, o.rotate(V3(0.0, end.y - at.center_y, 0.0)));
|
||||
}
|
||||
keep(cap, o.rotate(V3(0.0, outward, 0.0)), None)?;
|
||||
let r = (end.x - at.axis).abs();
|
||||
let plane = solid::PlaneUv {
|
||||
origin: o.rotate(V3(0.0, end.y - at.center_y, 0.0)),
|
||||
x: o.rotate(V3(1.0, 0.0, 0.0)),
|
||||
y: o.rotate(V3(0.0, 0.0, 1.0)),
|
||||
area: Rect::new(-r, -r, r, r),
|
||||
};
|
||||
keep(cap, o.rotate(V3(0.0, outward, 0.0)), None, MeshPart::Cap, solid::Attrs::Planar(plane))?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -1324,8 +1347,8 @@ impl CutRegions {
|
||||
let (draw, mesh, lost) = kept;
|
||||
let result = match mesh.as_deref_mut() {
|
||||
Some(m) => cut_loops(&self.kept, rule, axis).and_then(|loops| {
|
||||
keep_cuts(at, &loops, |contours, normal| {
|
||||
m.push((contours, normal));
|
||||
keep_cuts(at, &loops, |contours, normal, attrs| {
|
||||
m.push(solid::Face3 { contours, normal, part: MeshPart::Cut, attrs });
|
||||
if m.len() > face_limit { Err(TOO_COMPLEX_SURFACE.to_string()) } else { Ok(()) }
|
||||
})
|
||||
}),
|
||||
@@ -1343,14 +1366,19 @@ impl CutRegions {
|
||||
|
||||
/// Keep for a mesh the two cut sides of a partial sweep: the loops `loops` of their regions
|
||||
/// ([`cut_loops`]) turned to each side. Outlines run one way round and holes the other, so the mesh
|
||||
/// leaves the holes open. `keep` keeps one face with its outward normal.
|
||||
fn keep_cuts(at: &Sweeping, loops: &[Vec<Point>], mut keep: impl FnMut(Vec<Vec<V3>>, V3) -> Result<(), String>) -> Result<(), String> {
|
||||
/// leaves the holes open. `keep` keeps one face with its outward normal and where its corners lie
|
||||
/// on its texture: each corner's profile point in the bounds of the loops.
|
||||
fn keep_cuts(at: &Sweeping, loops: &[Vec<Point>], mut keep: impl FnMut(Vec<Vec<V3>>, V3, solid::Attrs) -> Result<(), String>) -> Result<(), String> {
|
||||
if loops.is_empty() {
|
||||
return Ok(());
|
||||
}
|
||||
let area = solid::rings_bounds(loops.iter().map(Vec::as_slice));
|
||||
for (step, normal) in cut_sides(at) {
|
||||
let contours = loops.iter().map(|r| r.iter().map(|p| at.vertex(*p, step)).collect()).collect();
|
||||
keep(contours, at.o.rotate(normal))?;
|
||||
// A profile point goes to view space by one affine map at each step.
|
||||
let origin = at.vertex(Point::ZERO, step);
|
||||
let (x, y) = (at.vertex(Point::new(1.0, 0.0), step).sub(origin), at.vertex(Point::new(0.0, 1.0), step).sub(origin));
|
||||
keep(contours, at.o.rotate(normal), solid::Attrs::Planar(solid::PlaneUv { origin, x, y, area }))?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -1399,8 +1427,8 @@ fn revolve_sweep(
|
||||
}
|
||||
let face_limit = revolve_face_limit(o);
|
||||
// A face kept for a mesh: its normal follows from its corners.
|
||||
let keep = |mesh: &mut Vec<solid::Face3>, face: Vec<V3>, normal: V3| {
|
||||
mesh.push((vec![face], normal));
|
||||
let keep = |mesh: &mut Vec<solid::Face3>, face: Vec<V3>, normal: V3, part: MeshPart, attrs: solid::Attrs| {
|
||||
mesh.push(solid::Face3 { contours: vec![face], normal, part, attrs });
|
||||
if mesh.len() > face_limit { Err(TOO_COMPLEX_SURFACE.to_string()) } else { Ok(()) }
|
||||
};
|
||||
if ![bounds.x0, bounds.y0, bounds.x1, bounds.y1].iter().all(|v| v.is_finite() && v.abs() <= 1e8) {
|
||||
@@ -1584,8 +1612,8 @@ fn revolve_sweep(
|
||||
let caps: Vec<usize> = rings.iter().enumerate().filter_map(|(i, r)| r.as_ref().map(|_| i)).collect();
|
||||
let along = (surface.is_some() && surface_contour == Some(contour)).then(|| along_profile(&kept.points, axis, sp.closed));
|
||||
let layout = along.as_deref().map(|along| (along, &surface_angle as &dyn Fn(usize) -> [f64; 2]));
|
||||
let kept = keep_profile(&at, &kept, turn, &caps, layout, |face, normal, uv| {
|
||||
keep(m, face, normal)?;
|
||||
let kept = keep_profile(&at, &kept, turn, &caps, layout, |face, normal, uv, part, attrs| {
|
||||
keep(m, face, normal, part, attrs)?;
|
||||
if let (Some(uv), Some(s)) = (uv, surface.as_deref_mut()) {
|
||||
s.push((m.len() - 1, uv));
|
||||
}
|
||||
|
||||
+110
-11
@@ -4,28 +4,71 @@
|
||||
//!
|
||||
//! Coordinates are points with y up and z toward the viewer, about the point the solid turns about
|
||||
//! (the centre of the art's bounds; for Revolve, the axis at the profile's middle). Each face keeps
|
||||
//! its own corners and normal, so the mesh is shaded flat. Planar faces with holes (caps and the
|
||||
//! turned plane) are cut into triangles: each hole is joined to its outline by a bridge, then the
|
||||
//! outline is cut by ear clipping.
|
||||
//! its own corners. A corner takes its face's normal, with two exceptions. On a bevel, the corners
|
||||
//! two bands of one bevel share take the mean of the bands' normals, unless the bevel turns there
|
||||
//! by 60° or more or one of the bands lies flat toward the front or back. On Inflate's puffed
|
||||
//! front and back, each corner takes the surface's own normal. Planar faces with holes (caps and
|
||||
//! the turned plane) are cut into triangles: each hole is joined to its outline by a bridge, then
|
||||
//! the outline is cut by ear clipping.
|
||||
//!
|
||||
//! Every corner has texture coordinates from 0 to 1 each way, u to the right and v down, and every
|
||||
//! triangle names the part of the solid it belongs to ([`MeshPart`]):
|
||||
//!
|
||||
//! - Caps, Rotate's plane and Inflate's front and back take each corner's point in the art, before
|
||||
//! any twist or taper, within the art's bounds. The back is not mirrored.
|
||||
//! - Extrude & Bevel's bevels and walls, and Inflate's walls, take u along each contour of the
|
||||
//! outline from its first point (its distance over the contour's length, so its first point is
|
||||
//! at both 0 and 1) and v across the side from the front cap's edge to the back cap's.
|
||||
//! - Revolve's side takes u around the sweep from its start and v along each contour of the
|
||||
//! profile from its first point. Its end caps span the disk they close, and its cut sides take
|
||||
//! each corner's profile point within the bounds of the profile.
|
||||
//!
|
||||
//! An axis with no extent (a contour of no length, art of no width) takes 0.5.
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
use vectorcraft_geom::{FillRule, PathData, Point, Rect};
|
||||
|
||||
use crate::solid::{Face3, Keep, extrude_faces, inflate_faces, plane_faces};
|
||||
use crate::solid::{Attrs, Face3, Keep, extrude_faces, inflate_faces, plane_faces};
|
||||
use crate::{Extrude, Facet, Inflate, Revolve, V3, View};
|
||||
|
||||
/// Most steps the triangulation of one solid may take: a face's ears and bridges each test the
|
||||
/// face's other corners.
|
||||
const MAX_WORK: usize = 400_000_000;
|
||||
|
||||
/// The part of a solid a triangle of its mesh belongs to.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
pub enum MeshPart {
|
||||
/// Extrude & Bevel's front cap, Rotate's plane, and Inflate's front.
|
||||
Front,
|
||||
/// Extrude & Bevel's back cap, and Inflate's back, puffed or flat.
|
||||
Back,
|
||||
/// The walls of Extrude & Bevel and Inflate, and the side Revolve sweeps.
|
||||
Side,
|
||||
/// Extrude & Bevel's bevel between the front cap and the walls.
|
||||
FrontBevel,
|
||||
/// Extrude & Bevel's bevel between the walls and the back cap, with the bevel on both sides.
|
||||
BackBevel,
|
||||
/// A disk or sector closing an end of Revolve's profile.
|
||||
Cap,
|
||||
/// A flat side closing a Revolve sweep of less than 360°.
|
||||
Cut,
|
||||
}
|
||||
|
||||
/// A triangle mesh.
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct Mesh {
|
||||
/// Corner positions in points: x right, y up, z toward the viewer.
|
||||
pub positions: Vec<[f64; 3]>,
|
||||
/// One unit normal for each position: the normal of the face the corner belongs to.
|
||||
/// One unit normal for each position: the normal of the face the corner belongs to, or a
|
||||
/// smoothed one (see the module's description).
|
||||
pub normals: Vec<[f64; 3]>,
|
||||
/// Texture coordinates for each position, each from 0 to 1: u to the right, v down.
|
||||
pub uvs: Vec<[f64; 2]>,
|
||||
/// Corner indices, counterclockwise seen from the side the normals point to.
|
||||
pub triangles: Vec<[u32; 3]>,
|
||||
/// The part of the solid each triangle belongs to.
|
||||
pub parts: Vec<MeshPart>,
|
||||
}
|
||||
|
||||
impl Mesh {
|
||||
@@ -33,6 +76,24 @@ impl Mesh {
|
||||
self.triangles.is_empty()
|
||||
}
|
||||
|
||||
/// Whether the lists match and hold numbers: a normal and texture coordinates for each
|
||||
/// position, a part for each triangle, every corner index naming a position, and every
|
||||
/// position, normal and texture coordinate finite.
|
||||
pub fn is_consistent(&self) -> bool {
|
||||
let n = self.positions.len();
|
||||
let finite = self.positions.iter().chain(&self.normals).flatten().chain(self.uvs.iter().flatten()).all(|v| v.is_finite());
|
||||
self.normals.len() == n
|
||||
&& self.uvs.len() == n
|
||||
&& self.parts.len() == self.triangles.len()
|
||||
&& self.triangles.iter().flatten().all(|&i| usize::try_from(i).is_ok_and(|i| i < n))
|
||||
&& finite
|
||||
}
|
||||
|
||||
/// An error when the mesh cannot be written as it is ([`Mesh::is_consistent`]).
|
||||
pub fn check(&self) -> Result<(), String> {
|
||||
if self.is_consistent() { Ok(()) } else { Err("The 3D object's mesh is incomplete or holds a value that is not a number".into()) }
|
||||
}
|
||||
|
||||
/// The smallest and largest coordinate on each axis; `None` for an empty mesh.
|
||||
pub fn bounds(&self) -> Option<([f64; 3], [f64; 3])> {
|
||||
let first = *self.positions.first()?;
|
||||
@@ -41,16 +102,22 @@ impl Mesh {
|
||||
}))
|
||||
}
|
||||
|
||||
/// The meshes of `parts` as one, in order.
|
||||
pub fn join(parts: impl IntoIterator<Item = Mesh>) -> Mesh {
|
||||
/// The meshes of `parts` as one, in order. An error when a mesh cannot be written as it is
|
||||
/// ([`Mesh::check`]) or the corners would pass what a `u32` index can name.
|
||||
pub fn join(parts: impl IntoIterator<Item = Mesh>) -> Result<Mesh, String> {
|
||||
let mut out = Mesh::default();
|
||||
for m in parts {
|
||||
let base = out.positions.len() as u32;
|
||||
m.check()?;
|
||||
let base = u32::try_from(out.positions.len()).map_err(|_| too_complex())?;
|
||||
// Every index of `m` is below its count of positions, so the shifted indices fit too.
|
||||
base.checked_add(u32::try_from(m.positions.len()).map_err(|_| too_complex())?).ok_or_else(too_complex)?;
|
||||
out.positions.extend(m.positions);
|
||||
out.normals.extend(m.normals);
|
||||
out.uvs.extend(m.uvs);
|
||||
out.triangles.extend(m.triangles.into_iter().map(|t| t.map(|i| i + base)));
|
||||
out.parts.extend(m.parts);
|
||||
}
|
||||
out
|
||||
Ok(out)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,6 +221,11 @@ pub(crate) fn newell(contours: &[Vec<V3>]) -> V3 {
|
||||
n
|
||||
}
|
||||
|
||||
/// The exact position of `v`, as a key ([`Face3::corner`] matches corners exactly).
|
||||
fn key(v: V3) -> [u64; 3] {
|
||||
[v.0.to_bits(), v.1.to_bits(), v.2.to_bits()]
|
||||
}
|
||||
|
||||
/// From the effects' view space (y down) to the mesh's (y up).
|
||||
fn up(v: V3) -> [f64; 3] {
|
||||
[v.0, -v.1, v.2]
|
||||
@@ -176,7 +248,8 @@ fn mesh_on(faces: &[Face3], surface: Option<&[(usize, [Point; 4])]>) -> Result<S
|
||||
let mut on = vec![];
|
||||
let mut work = 0usize;
|
||||
let mut cells = surface.iter().peekable();
|
||||
for (k, (contours, normal)) in faces.iter().enumerate() {
|
||||
for (k, face) in faces.iter().enumerate() {
|
||||
let (contours, normal) = (&face.contours, &face.normal);
|
||||
while cells.next_if(|(i, _)| *i < k).is_some() {}
|
||||
let cell = cells.next_if(|(i, _)| *i == k).map(|(_, uv)| uv);
|
||||
// The surface point of a corner of a triangle: the point of the face's corner it is.
|
||||
@@ -202,6 +275,19 @@ fn mesh_on(faces: &[Face3], surface: Option<&[(usize, [Point; 4])]>) -> Result<S
|
||||
Some([v0, v1, v2, v3]) => vec![[v0, v1, v2], [v0, v2, v3]],
|
||||
None => triangulate(contours, geometric, &mut work)?,
|
||||
};
|
||||
// A face with many listed corners looks each one up by its position.
|
||||
let listed = match &face.attrs {
|
||||
Attrs::Corners(list) if list.iter().map(Vec::len).sum::<usize>() > 16 => {
|
||||
let mut map = HashMap::new();
|
||||
for (c, l) in contours.iter().zip(list) {
|
||||
for (v, data) in c.iter().zip(l) {
|
||||
map.entry(key(*v)).or_insert(*data);
|
||||
}
|
||||
}
|
||||
Some(map)
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
for [a, b, c] in triangles {
|
||||
let (pa, pb, pc) = (up(a), up(b), up(c));
|
||||
let cross = V3(pb[0] - pa[0], pb[1] - pa[1], pb[2] - pa[2]).cross(V3(pc[0] - pa[0], pc[1] - pa[1], pc[2] - pa[2]));
|
||||
@@ -212,9 +298,20 @@ fn mesh_on(faces: &[Face3], surface: Option<&[(usize, [Point; 4])]>) -> Result<S
|
||||
let (pb, pc) = if turned { (pc, pb) } else { (pb, pc) };
|
||||
let (b, c) = if turned { (c, b) } else { (b, c) };
|
||||
let base = u32::try_from(out.positions.len()).map_err(|_| "The 3D object is too complex to export".to_string())?;
|
||||
base.checked_add(2).ok_or_else(too_complex)?;
|
||||
out.positions.extend([pa, pb, pc]);
|
||||
out.normals.extend([[nx, ny, nz]; 3]);
|
||||
for v in [a, b, c] {
|
||||
let (uv, own) = match &listed {
|
||||
Some(map) => map.get(&key(v)).copied().unwrap_or(([0.5, 0.5], None)),
|
||||
None => face.corner(v),
|
||||
};
|
||||
// A corner's own normal, when it has a usable one, else the face's.
|
||||
let own = own.map(V3::unit).filter(|m| m.dot(*m) > 0.5 && [m.0, m.1, m.2].iter().all(|x| x.is_finite()));
|
||||
out.normals.push(own.map_or([nx, ny, nz], up));
|
||||
out.uvs.push(uv);
|
||||
}
|
||||
out.triangles.push([base, base + 1, base + 2]);
|
||||
out.parts.push(face.part);
|
||||
if track {
|
||||
on.push(point(a).zip(point(b)).zip(point(c)).map(|((a, b), c)| [a, b, c]));
|
||||
}
|
||||
@@ -497,3 +594,5 @@ fn clip(ring: &[Corner], out: &mut Vec<[V3; 3]>, work: &mut usize, keep_straight
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
#[cfg(test)]
|
||||
mod tests_attributes;
|
||||
@@ -543,10 +543,32 @@ fn join_numbers_each_parts_corners_after_the_last() {
|
||||
square(&mut b, 0.0, 0.0, 10.0, false);
|
||||
let (p, r) = shape(&b);
|
||||
let one = plane_mesh(&p, FillRule::NonZero, r, front()).unwrap();
|
||||
let both = Mesh::join([one.clone(), one.clone()]);
|
||||
let both = Mesh::join([one.clone(), one.clone()]).unwrap();
|
||||
assert_eq!(both.triangles.len(), 2 * one.triangles.len());
|
||||
assert!(both.triangles.iter().all(|t| t.iter().all(|i| (*i as usize) < both.positions.len())));
|
||||
assert_eq!(both.triangles[one.triangles.len()][0], one.triangles[0][0] + one.positions.len() as u32);
|
||||
assert!(both.is_consistent());
|
||||
assert_eq!(both.uvs.len(), 2 * one.uvs.len());
|
||||
assert_eq!(both.parts.len(), 2 * one.parts.len());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn join_refuses_a_mesh_whose_lists_do_not_match() {
|
||||
let mut b = BezPath::new();
|
||||
square(&mut b, 0.0, 0.0, 10.0, false);
|
||||
let (p, r) = shape(&b);
|
||||
let one = plane_mesh(&p, FillRule::NonZero, r, front()).unwrap();
|
||||
for broken in [
|
||||
Mesh { uvs: vec![], ..one.clone() },
|
||||
Mesh { parts: vec![], ..one.clone() },
|
||||
Mesh { normals: vec![], ..one.clone() },
|
||||
Mesh { uvs: vec![[f64::NAN, 0.0]; one.uvs.len()], ..one.clone() },
|
||||
Mesh { positions: vec![[f64::INFINITY, 0.0, 0.0]; one.positions.len()], ..one.clone() },
|
||||
Mesh { triangles: vec![[0, 1, u32::MAX]], parts: vec![MeshPart::Front], ..one.clone() },
|
||||
] {
|
||||
assert!(!broken.is_consistent());
|
||||
assert!(Mesh::join([one.clone(), broken]).is_err());
|
||||
}
|
||||
}
|
||||
|
||||
/// A mesh's positions and normals as bits, and its triangles.
|
||||
|
||||
@@ -0,0 +1,432 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use vectorcraft_geom::{BezPath, FillRule, PathData, Point, Rect};
|
||||
|
||||
use super::*;
|
||||
use crate::{Bevel, BevelProfile, BevelShape, Edge};
|
||||
|
||||
fn rectangle(x: f64, y: f64, w: f64, h: f64) -> (PathData, Rect) {
|
||||
let mut b = BezPath::new();
|
||||
b.move_to((x, y));
|
||||
b.line_to((x + w, y));
|
||||
b.line_to((x + w, y + h));
|
||||
b.line_to((x, y + h));
|
||||
b.close_path();
|
||||
let p = PathData::from_bezpath(&b);
|
||||
let r = p.bounds().unwrap();
|
||||
(p, r)
|
||||
}
|
||||
|
||||
/// A rectangle with a square hole: the hole's wall is a contour of its own.
|
||||
fn holed() -> (PathData, Rect) {
|
||||
let mut b = BezPath::new();
|
||||
for (x, y, s, clockwise) in [(0.0, 0.0, 100.0, false), (40.0, 40.0, 20.0, true)] {
|
||||
b.move_to((x, y));
|
||||
let corners = if clockwise { [(x, y + s), (x + s, y + s), (x + s, y)] } else { [(x + s, y), (x + s, y + s), (x, y + s)] };
|
||||
for c in corners {
|
||||
b.line_to(c);
|
||||
}
|
||||
b.close_path();
|
||||
}
|
||||
let p = PathData::from_bezpath(&b);
|
||||
let r = p.bounds().unwrap();
|
||||
(p, r)
|
||||
}
|
||||
|
||||
/// A vertical line from y 0 to 100, 20 pt from the left edge of its bounds' axis.
|
||||
fn line_profile() -> (PathData, Rect) {
|
||||
let mut b = BezPath::new();
|
||||
b.move_to((20.0, 0.0));
|
||||
b.line_to((20.0, 100.0));
|
||||
let p = PathData::from_bezpath(&b);
|
||||
let r = p.bounds().unwrap();
|
||||
(p, r)
|
||||
}
|
||||
|
||||
fn front() -> View {
|
||||
View { rotation_x: 0.0, rotation_y: 0.0, rotation_z: 0.0, perspective: 0.0, ..View::default() }
|
||||
}
|
||||
|
||||
fn turned() -> View {
|
||||
View { rotation_x: -25.0, rotation_y: 35.0, rotation_z: 10.0, perspective: 0.0, ..View::default() }
|
||||
}
|
||||
|
||||
fn bevel(shape: BevelShape) -> Bevel {
|
||||
Bevel { shape, width: 6.0, height: 6.0, ..Bevel::default() }
|
||||
}
|
||||
|
||||
fn beveled(b: Bevel) -> Extrude {
|
||||
Extrude { bevel: Some(b), ..Extrude::default() }
|
||||
}
|
||||
|
||||
fn custom() -> BevelShape {
|
||||
BevelShape::Custom(BevelProfile::new(&[(0.0, 0.0), (0.5, 0.2), (0.8, 0.5), (1.0, 1.0)]).unwrap())
|
||||
}
|
||||
|
||||
fn length(v: [f64; 3]) -> f64 {
|
||||
v.iter().map(|x| x * x).sum::<f64>().sqrt()
|
||||
}
|
||||
|
||||
fn geometric(m: &Mesh, t: [u32; 3]) -> [f64; 3] {
|
||||
let [a, b, c] = t.map(|i| m.positions[i as usize]);
|
||||
let (u, v) = ([b[0] - a[0], b[1] - a[1], b[2] - a[2]], [c[0] - a[0], c[1] - a[1], c[2] - a[2]]);
|
||||
let n = [u[1] * v[2] - u[2] * v[1], u[2] * v[0] - u[0] * v[2], u[0] * v[1] - u[1] * v[0]];
|
||||
let l = length(n);
|
||||
n.map(|x| x / l)
|
||||
}
|
||||
|
||||
/// Every list of `m` matches, every texture coordinate is a number from 0 to 1, and every normal
|
||||
/// is a unit vector.
|
||||
fn check(m: &Mesh, what: &str) {
|
||||
assert!(m.is_consistent(), "{what}");
|
||||
assert!(m.uvs.iter().flatten().all(|v| v.is_finite() && (0.0..=1.0).contains(v)), "{what}");
|
||||
assert!(m.normals.iter().all(|n| (length(*n) - 1.0).abs() < 1e-9), "{what}");
|
||||
assert!(m.positions.iter().flatten().all(|v| v.is_finite()), "{what}");
|
||||
}
|
||||
|
||||
fn parts(m: &Mesh) -> Vec<MeshPart> {
|
||||
let mut out: Vec<MeshPart> = vec![];
|
||||
for p in &m.parts {
|
||||
if !out.contains(p) {
|
||||
out.push(*p);
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// The meshes of every effect and many options.
|
||||
fn meshes() -> Vec<(String, Mesh)> {
|
||||
let (square, r) = rectangle(0.0, 0.0, 100.0, 60.0);
|
||||
let (hole, hr) = holed();
|
||||
let mut out = vec![];
|
||||
let shapes = [BevelShape::Classic, BevelShape::Rounded, BevelShape::Cove, BevelShape::Step, BevelShape::Ogee, custom()];
|
||||
for view in [front(), turned(), View { perspective: 60.0, ..turned() }] {
|
||||
for shape in shapes {
|
||||
for b in [
|
||||
bevel(shape),
|
||||
Bevel { inside: true, ..bevel(shape) },
|
||||
Bevel { both_sides: true, ..bevel(shape) },
|
||||
Bevel { repeat: 3, space: 0.2, ..bevel(shape) },
|
||||
] {
|
||||
let o = Extrude { bevel: Some(b), ..Extrude::default() };
|
||||
out.push((format!("{shape:?} {b:?} {view:?}"), extrude_mesh(&square, FillRule::NonZero, r, o, view).unwrap()));
|
||||
}
|
||||
}
|
||||
for o in [
|
||||
Extrude::default(),
|
||||
Extrude { twist: 90.0, taper: 0.5, bevel: Some(bevel(BevelShape::Rounded)), ..Extrude::default() },
|
||||
Extrude { depth: 0.0, ..Extrude::default() },
|
||||
Extrude { cap: false, ..Extrude::default() },
|
||||
] {
|
||||
out.push((format!("{o:?} {view:?}"), extrude_mesh(&hole, FillRule::NonZero, hr, o, view).unwrap()));
|
||||
}
|
||||
out.push((format!("plane {view:?}"), plane_mesh(&hole, FillRule::NonZero, hr, view).unwrap()));
|
||||
let deep = Inflate { depth: 10.0, ..Inflate::default() };
|
||||
for o in [Inflate::default(), Inflate { both_sides: true, twist: 30.0, ..deep }, Inflate { cap: false, ..deep }] {
|
||||
for (k, m) in inflate_meshes(&[(&hole, FillRule::NonZero)], hr, o, view).enumerate() {
|
||||
out.push((format!("inflate {k} {o:?} {view:?}"), m.unwrap()));
|
||||
}
|
||||
}
|
||||
}
|
||||
let (line, lr) = line_profile();
|
||||
for angle in [360.0, 90.0] {
|
||||
let o = Revolve { angle, offset: 10.0, edge: Edge::Left, rotation_x: -20.0, rotation_y: 30.0, ..Revolve::default() };
|
||||
out.push((format!("revolve line {angle}"), revolve_mesh(&line, FillRule::NonZero, lr, o).unwrap()));
|
||||
out.push((format!("revolve holed {angle}"), revolve_mesh(&hole, FillRule::NonZero, hr, o).unwrap()));
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn every_corner_has_texture_coordinates_and_every_triangle_a_part() {
|
||||
for (what, m) in meshes() {
|
||||
assert!(!m.is_empty(), "{what}");
|
||||
check(&m, &what);
|
||||
assert_eq!(m.uvs.len(), m.positions.len(), "{what}");
|
||||
assert_eq!(m.parts.len(), m.triangles.len(), "{what}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn each_triangle_names_the_part_of_the_solid_it_comes_from() {
|
||||
let (p, r) = rectangle(0.0, 0.0, 100.0, 60.0);
|
||||
let both = Extrude { bevel: Some(Bevel { both_sides: true, ..bevel(BevelShape::Rounded) }), ..Extrude::default() };
|
||||
let m = extrude_mesh(&p, FillRule::NonZero, r, both, front()).unwrap();
|
||||
let mut found = parts(&m);
|
||||
found.sort_by_key(|p| *p as u8);
|
||||
assert_eq!(found, [MeshPart::Front, MeshPart::Back, MeshPart::Side, MeshPart::FrontBevel, MeshPart::BackBevel]);
|
||||
// Straight on, the front cap faces the viewer and the back cap away; the walls face sideways.
|
||||
for (t, part) in m.triangles.iter().zip(&m.parts) {
|
||||
let n = geometric(&m, *t);
|
||||
match part {
|
||||
MeshPart::Front => assert!(n[2] > 1.0 - 1e-9),
|
||||
MeshPart::Back => assert!(n[2] < -1.0 + 1e-9),
|
||||
MeshPart::Side => assert!(n[2].abs() < 1e-9),
|
||||
MeshPart::FrontBevel => assert!(n[2] > 0.0),
|
||||
MeshPart::BackBevel => assert!(n[2] < 0.0),
|
||||
other => panic!("{other:?}"),
|
||||
}
|
||||
}
|
||||
assert!(plane_mesh(&p, FillRule::NonZero, r, turned()).unwrap().parts.iter().all(|p| *p == MeshPart::Front));
|
||||
let flat = extrude_mesh(&p, FillRule::NonZero, r, Extrude { depth: 0.0, ..Extrude::default() }, front()).unwrap();
|
||||
assert!(flat.parts.iter().all(|p| *p == MeshPart::Front));
|
||||
let deep = Inflate { depth: 10.0, ..Inflate::default() };
|
||||
let puffed = inflate_meshes(&[(&p, FillRule::NonZero)], r, deep, front()).next().unwrap().unwrap();
|
||||
let mut found = parts(&puffed);
|
||||
found.sort_by_key(|p| *p as u8);
|
||||
assert_eq!(found, [MeshPart::Front, MeshPart::Back, MeshPart::Side]);
|
||||
let (line, lr) = line_profile();
|
||||
let o = Revolve { angle: 90.0, offset: 10.0, ..Revolve::default() };
|
||||
let mut found = parts(&revolve_mesh(&line, FillRule::NonZero, lr, o).unwrap());
|
||||
found.sort_by_key(|p| *p as u8);
|
||||
assert_eq!(found, [MeshPart::Side, MeshPart::Cap, MeshPart::Cut]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn caps_take_their_art_points_and_the_side_runs_around_the_outline_and_front_to_back() {
|
||||
let (p, r) = rectangle(0.0, 0.0, 100.0, 60.0);
|
||||
let m = extrude_mesh(&p, FillRule::NonZero, r, Extrude::default(), front()).unwrap();
|
||||
let depth = Extrude::default().depth;
|
||||
let (mut seams, mut ends) = (HashMap::<[u64; 3], Vec<f64>>::new(), [false; 2]);
|
||||
for (t, part) in m.triangles.iter().zip(&m.parts) {
|
||||
for &i in t {
|
||||
let (q, uv) = (m.positions[i as usize], m.uvs[i as usize]);
|
||||
match part {
|
||||
// The art at (x, y) lies at (x - 50, 30 - y) in the mesh: the back is not mirrored.
|
||||
MeshPart::Front | MeshPart::Back => {
|
||||
assert!((uv[0] - (q[0] + 50.0) / 100.0).abs() < 1e-9 && (uv[1] - (30.0 - q[1]) / 60.0).abs() < 1e-9, "{q:?} {uv:?}");
|
||||
}
|
||||
MeshPart::Side => {
|
||||
seams.entry(q.map(f64::to_bits)).or_default().push(uv[0]);
|
||||
// v runs from the front cap's edge to the back cap's.
|
||||
let v = if q[2] > 0.0 { 0.0 } else { 1.0 };
|
||||
assert!((q[2].abs() - depth / 2.0).abs() < 1e-9 && (uv[1] - v).abs() < 1e-9, "{q:?} {uv:?}");
|
||||
ends[usize::from(q[2] < 0.0)] = true;
|
||||
}
|
||||
other => panic!("{other:?}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
assert_eq!(ends, [true, true]);
|
||||
// The outline's first point carries both ends of the side's u: the seam's corners are kept apart.
|
||||
assert!(seams.values().any(|u| u.contains(&0.0) && u.contains(&1.0)));
|
||||
// Along the 320 pt outline each corner of the rectangle lies 100, 160 and 260 pt from the first.
|
||||
let mut along: Vec<f64> = seams.values().flatten().copied().collect();
|
||||
along.sort_by(f64::total_cmp);
|
||||
along.dedup_by(|a, b| (*a - *b).abs() < 1e-9);
|
||||
assert_eq!(along.len(), 5, "{along:?}");
|
||||
for (u, expected) in along.iter().zip([0.0, 100.0, 160.0, 260.0, 320.0]) {
|
||||
assert!((u - expected / 320.0).abs() < 1e-9, "{along:?}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn revolves_side_runs_around_the_sweep_and_along_the_profile() {
|
||||
let (line, lr) = line_profile();
|
||||
let o = Revolve { offset: 10.0, segments: 16, ..Revolve::default() };
|
||||
let m = revolve_mesh(&line, FillRule::NonZero, lr, o).unwrap();
|
||||
let mut around = HashMap::<[i64; 3], Vec<f64>>::new();
|
||||
for (t, part) in m.triangles.iter().zip(&m.parts) {
|
||||
for &i in t {
|
||||
let (q, uv) = (m.positions[i as usize], m.uvs[i as usize]);
|
||||
if *part == MeshPart::Side {
|
||||
// The sweep's end lands on its start within rounding.
|
||||
around.entry(q.map(|v| (v * 1e6).round() as i64)).or_default().push(uv[0]);
|
||||
// The profile runs from y 0 (the mesh's top, at 50) to y 100 (at -50).
|
||||
assert!((uv[1] - (50.0 - q[1]) / 100.0).abs() < 1e-9, "{q:?} {uv:?}");
|
||||
} else {
|
||||
assert_eq!(*part, MeshPart::Cap);
|
||||
}
|
||||
}
|
||||
}
|
||||
assert!(around.values().any(|u| u.contains(&0.0) && u.contains(&1.0)), "the sweep's seam is kept apart");
|
||||
}
|
||||
|
||||
/// The corners of the bottom edge's front bevel of `m` (an extruded rectangle seen straight on),
|
||||
/// by position, with their normals.
|
||||
fn bottom_bevel(m: &Mesh) -> HashMap<[u64; 3], Vec<[f64; 3]>> {
|
||||
let mut out = HashMap::<[u64; 3], Vec<[f64; 3]>>::new();
|
||||
for (t, part) in m.triangles.iter().zip(&m.parts) {
|
||||
let n = geometric(m, *t);
|
||||
if *part != MeshPart::FrontBevel || n[0].abs() > 1e-9 || n[1] >= 0.0 {
|
||||
continue;
|
||||
}
|
||||
for &i in t {
|
||||
out.entry(m.positions[i as usize].map(f64::to_bits)).or_default().push(m.normals[i as usize]);
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// The angle between `a` and `b` in degrees, from their cross and dot products, so that two equal
|
||||
/// vectors give 0 exactly.
|
||||
fn angle(a: [f64; 3], b: [f64; 3]) -> f64 {
|
||||
let cross = [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];
|
||||
length(cross).atan2(a[0] * b[0] + a[1] * b[1] + a[2] * b[2]).to_degrees()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_rounded_or_custom_bevels_normals_turn_smoothly_across_its_bands() {
|
||||
let (p, r) = rectangle(0.0, 0.0, 200.0, 100.0);
|
||||
for shape in [BevelShape::Rounded, custom(), BevelShape::Ogee] {
|
||||
let o = Extrude { bevel: Some(bevel(shape)), ..Extrude::default() };
|
||||
let m = extrude_mesh(&p, FillRule::NonZero, r, o, front()).unwrap();
|
||||
let corners = bottom_bevel(&m);
|
||||
let mut normals: Vec<[f64; 3]> = vec![];
|
||||
for (at, list) in &corners {
|
||||
// Every band that meets at a corner gives it the same normal.
|
||||
assert!(list.iter().all(|n| angle(*n, list[0]) < 1e-9), "{shape:?} {at:?} {list:?}");
|
||||
assert!(list.iter().all(|n| (length(*n) - 1.0).abs() < 1e-12));
|
||||
if !normals.iter().any(|n| angle(*n, list[0]) < 1e-9) {
|
||||
normals.push(list[0]);
|
||||
}
|
||||
}
|
||||
// The normals turn from the front toward the bottom in steps smaller than the profile's.
|
||||
normals.sort_by(|a, b| b[2].total_cmp(&a[2]));
|
||||
assert!(normals.len() >= 3, "{shape:?} {normals:?}");
|
||||
assert!(normals.windows(2).all(|w| angle(w[0], w[1]) < 45.0), "{shape:?} {normals:?}");
|
||||
// The vector facets keep their flat shading.
|
||||
let facets = crate::extrude(&p, FillRule::NonZero, r, o, front()).unwrap();
|
||||
let built = crate::extrude_meshed(&p, FillRule::NonZero, r, o, front()).unwrap();
|
||||
assert_eq!(facets, built.facets);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_steps_sharp_turns_and_a_classic_bevel_stay_hard_edges() {
|
||||
let (p, r) = rectangle(0.0, 0.0, 200.0, 100.0);
|
||||
let step = extrude_mesh(&p, FillRule::NonZero, r, Extrude { bevel: Some(bevel(BevelShape::Step)), ..Extrude::default() }, front()).unwrap();
|
||||
for (t, part) in step.triangles.iter().zip(&step.parts) {
|
||||
if *part == MeshPart::FrontBevel {
|
||||
let n = geometric(&step, *t);
|
||||
for &i in t {
|
||||
assert!(angle(step.normals[i as usize], n) < 1e-6, "a Step's flat bands keep their own normals");
|
||||
}
|
||||
}
|
||||
}
|
||||
let classic = extrude_mesh(&p, FillRule::NonZero, r, Extrude { bevel: Some(bevel(BevelShape::Classic)), ..Extrude::default() }, front()).unwrap();
|
||||
for t in &classic.triangles {
|
||||
let n = geometric(&classic, *t);
|
||||
for &i in t {
|
||||
assert!(angle(classic.normals[i as usize], n) < 1e-6);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn inflates_puffed_front_takes_the_surfaces_own_normals() {
|
||||
let (p, r) = rectangle(0.0, 0.0, 100.0, 60.0);
|
||||
let m = inflate_meshes(&[(&p, FillRule::NonZero)], r, Inflate::default(), front()).next().unwrap().unwrap();
|
||||
check(&m, "inflate");
|
||||
// Each point of the front has one normal, whichever pieces meet there.
|
||||
let mut at = HashMap::<[u64; 3], Vec<[f64; 3]>>::new();
|
||||
for (t, part) in m.triangles.iter().zip(&m.parts) {
|
||||
if *part == MeshPart::Front {
|
||||
for &i in t {
|
||||
at.entry(m.positions[i as usize].map(f64::to_bits)).or_default().push(m.normals[i as usize]);
|
||||
}
|
||||
}
|
||||
}
|
||||
assert!(at.values().filter(|list| list.len() > 1).count() > 10);
|
||||
for list in at.values() {
|
||||
assert!(list.iter().all(|n| angle(*n, list[0]) < 1e-9), "{list:?}");
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether `p` lies inside the polygon `ring` (even-odd), or within `d` of one of its edges.
|
||||
fn inside_or_near(rings: &[Vec<Point>], p: Point, d: f64) -> bool {
|
||||
let mut odd = false;
|
||||
for ring in rings {
|
||||
for (a, b) in ring.iter().zip(ring.iter().cycle().skip(1)).take(ring.len()) {
|
||||
let (dx, dy) = (b.x - a.x, b.y - a.y);
|
||||
let l2 = dx * dx + dy * dy;
|
||||
let t = if l2 < 1e-18 { 0.0 } else { (((p.x - a.x) * dx + (p.y - a.y) * dy) / l2).clamp(0.0, 1.0) };
|
||||
if p.distance(Point::new(a.x + dx * t, a.y + dy * t)) <= d {
|
||||
return true;
|
||||
}
|
||||
if (a.y > p.y) != (b.y > p.y) && p.x < a.x + (p.y - a.y) / (b.y - a.y) * (b.x - a.x) {
|
||||
odd = !odd;
|
||||
}
|
||||
}
|
||||
}
|
||||
odd
|
||||
}
|
||||
|
||||
/// Every corner of `m` seen from `origin` without perspective lies within `d` of some polygon of
|
||||
/// `drawn`, and every corner of `drawn` within `d` of some triangle of `m`: the mesh's outline
|
||||
/// and the vector facets' differ by no more than `d`.
|
||||
fn outlines_match(m: &Mesh, drawn: &[Vec<Vec<Point>>], origin: Point, d: f64, what: &str) {
|
||||
let page = |q: [f64; 3]| Point::new(origin.x + q[0], origin.y - q[1]);
|
||||
let triangles: Vec<Vec<Point>> = m.triangles.iter().map(|t| t.iter().map(|&i| page(m.positions[i as usize])).collect()).collect();
|
||||
for q in &m.positions {
|
||||
let p = page(*q);
|
||||
assert!(drawn.iter().any(|f| inside_or_near(f, p, d)), "{what}: mesh corner {p:?}");
|
||||
}
|
||||
for p in drawn.iter().flatten().flatten() {
|
||||
assert!(triangles.iter().any(|t| inside_or_near(std::slice::from_ref(t), *p, d)), "{what}: facet corner {p:?}");
|
||||
}
|
||||
}
|
||||
|
||||
/// The largest distance between the outline of a mesh and that of the vector facets of the same
|
||||
/// solid, in points.
|
||||
const OUTLINE_TOLERANCE: f64 = 0.05;
|
||||
|
||||
#[test]
|
||||
fn the_meshs_outline_stays_within_a_twentieth_of_a_point_of_the_vector_facets() {
|
||||
let (p, r) = rectangle(0.0, 0.0, 100.0, 60.0);
|
||||
let (hole, hr) = holed();
|
||||
for shape in [BevelShape::Classic, BevelShape::Rounded, BevelShape::Step, custom()] {
|
||||
for o in [
|
||||
Extrude { bevel: Some(bevel(shape)), ..Extrude::default() },
|
||||
Extrude { bevel: Some(Bevel { inside: true, both_sides: true, ..bevel(shape) }), ..Extrude::default() },
|
||||
] {
|
||||
for (path, bounds) in [(&p, r), (&hole, hr)] {
|
||||
let m = extrude_mesh(path, FillRule::NonZero, bounds, o, turned()).unwrap();
|
||||
let facets = crate::extrude(path, FillRule::NonZero, bounds, o, turned()).unwrap();
|
||||
let drawn: Vec<Vec<Vec<Point>>> = facets.into_iter().map(|f| f.contours).collect();
|
||||
outlines_match(&m, &drawn, bounds.center(), OUTLINE_TOLERANCE, &format!("{shape:?} {o:?}"));
|
||||
}
|
||||
}
|
||||
}
|
||||
let (line, lr) = line_profile();
|
||||
for angle in [360.0, 120.0] {
|
||||
let o = Revolve { angle, offset: 10.0, rotation_x: -20.0, rotation_y: 30.0, ..Revolve::default() };
|
||||
let m = revolve_mesh(&line, FillRule::NonZero, lr, o).unwrap();
|
||||
let drawn: Vec<Vec<Vec<Point>>> = crate::revolve(&line, lr, o).unwrap().into_iter().map(|f| vec![f.points]).collect();
|
||||
let origin = crate::revolve_projection(lr, o.sanitized()).origin;
|
||||
outlines_match(&m, &drawn, origin, OUTLINE_TOLERANCE, &format!("revolve {angle}"));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hostile_input_gives_an_error_or_a_consistent_mesh() {
|
||||
let (p, r) = rectangle(0.0, 0.0, 100.0, 60.0);
|
||||
// A closed outline with no area.
|
||||
let mut b = BezPath::new();
|
||||
b.move_to((0.0, 0.0));
|
||||
b.line_to((50.0, 0.0));
|
||||
b.line_to((100.0, 0.0));
|
||||
b.close_path();
|
||||
let flat = PathData::from_bezpath(&b);
|
||||
let fr = Rect::new(0.0, 0.0, 100.0, 0.0);
|
||||
for m in [
|
||||
extrude_mesh(&flat, FillRule::NonZero, fr, Extrude::default(), turned()),
|
||||
extrude_mesh(&flat, FillRule::NonZero, fr, Extrude { bevel: Some(bevel(BevelShape::Rounded)), ..Extrude::default() }, turned()),
|
||||
plane_mesh(&flat, FillRule::NonZero, fr, turned()),
|
||||
extrude_mesh(&p, FillRule::NonZero, r, Extrude { depth: 0.0, ..Extrude::default() }, turned()),
|
||||
extrude_mesh(&p, FillRule::NonZero, r, Extrude { depth: f64::NAN, twist: f64::NAN, ..Extrude::default() }, turned()),
|
||||
extrude_mesh(&p, FillRule::NonZero, r, beveled(Bevel { width: f64::NAN, height: f64::INFINITY, ..bevel(custom()) }), turned()),
|
||||
extrude_mesh(&p, FillRule::NonZero, r, beveled(Bevel { repeat: usize::MAX, ..bevel(BevelShape::Rounded) }), turned()),
|
||||
revolve_mesh(&p, FillRule::NonZero, r, Revolve { segments: usize::MAX, ..Revolve::default() }),
|
||||
revolve_mesh(&flat, FillRule::NonZero, fr, Revolve::default()),
|
||||
]
|
||||
.into_iter()
|
||||
.flatten()
|
||||
{
|
||||
check(&m, "hostile");
|
||||
}
|
||||
let nan = Rect::new(f64::NAN, 0.0, 100.0, 60.0);
|
||||
assert!(extrude_mesh(&p, FillRule::NonZero, nan, Extrude::default(), turned()).is_err());
|
||||
assert!(plane_mesh(&p, FillRule::NonZero, nan, turned()).is_err());
|
||||
assert!(revolve_mesh(&p, FillRule::NonZero, nan, Revolve::default()).is_err());
|
||||
}
|
||||
@@ -261,7 +261,7 @@ impl ShadowCaster {
|
||||
let p = self.projection?;
|
||||
let light = p.light()?;
|
||||
let s = shadow.sanitized();
|
||||
let corners = || self.within(faces).flat_map(|(contours, _)| contours.iter().flatten());
|
||||
let corners = || self.within(faces).flat_map(|face| face.contours.iter().flatten());
|
||||
let first = *corners().next()?;
|
||||
let (lo, hi) = corners()
|
||||
.fold((first, first), |(lo, hi), v| (V3(lo.0.min(v.0), lo.1.min(v.1), lo.2.min(v.2)), V3(hi.0.max(v.0), hi.1.max(v.1), hi.2.max(v.2))));
|
||||
@@ -299,8 +299,8 @@ impl ShadowCaster {
|
||||
};
|
||||
let to_page = |q: Point| p.project(add(foot, add(scale(u, q.x), scale(w, q.y))));
|
||||
let mut bp = BezPath::new();
|
||||
for (contours, _) in self.within(faces) {
|
||||
let flat: Vec<Vec<Point>> = contours.iter().map(|c| c.iter().map(|v| cast(*v)).collect()).collect();
|
||||
for face in self.within(faces) {
|
||||
let flat: Vec<Vec<Point>> = face.contours.iter().map(|c| c.iter().map(|v| cast(*v)).collect()).collect();
|
||||
let turn: f64 = flat.iter().map(|c| signed_area(c)).sum();
|
||||
// A face edge-on to the light casts nothing.
|
||||
if flat_area(turn, flat.iter().flatten()) {
|
||||
|
||||
@@ -25,9 +25,9 @@ mod side;
|
||||
pub(crate) use build::EXTRUDED;
|
||||
#[cfg(test)]
|
||||
pub(crate) use build::PLANES;
|
||||
pub(crate) use build::{Attrs, Face3, Keep, PlaneUv, extrude_faces, plane_faces, rings_bounds};
|
||||
#[cfg(test)]
|
||||
use build::{Camera, cuts, edge_distance, newell, section};
|
||||
pub(crate) use build::{Face3, Keep, extrude_faces, plane_faces};
|
||||
pub use build::{extrude, extrude_side_size, extrude_surfaces, plane};
|
||||
pub use face_map::{FaceMap, MeshFace, extrude_face_map, extrude_mesh_face, plane_face_map, plane_mesh_face};
|
||||
pub(crate) use inflate::inflate_faces;
|
||||
|
||||
@@ -10,6 +10,7 @@ use super::{
|
||||
Bevel, DepthPlane, Extrude, Facet, FillRule, MAX_FACES, MAX_SOLID_FACES, MapCell, ParamCurve, PathData, PlanarFace, Point, Rect, Revolve,
|
||||
SolidSurface, SurfaceKind, V3, View, eye_distance, perspective_scale,
|
||||
};
|
||||
use crate::mesh::MeshPart;
|
||||
use crate::shadow::Projection;
|
||||
|
||||
/// Turns 3D points into document points and shades faces for one view.
|
||||
@@ -61,9 +62,109 @@ impl Camera {
|
||||
}
|
||||
}
|
||||
|
||||
/// A face of a solid before projection: its contours in view space (holes running the other way)
|
||||
/// and its outward normal.
|
||||
pub(crate) type Face3 = (Vec<Vec<V3>>, V3);
|
||||
/// A face of a solid before projection: its contours in view space (holes running the other way),
|
||||
/// its outward normal, the part of the solid it belongs to, and where its corners lie on the
|
||||
/// part's texture ([`Attrs`]).
|
||||
#[derive(Clone, Debug)]
|
||||
pub(crate) struct Face3 {
|
||||
pub(crate) contours: Vec<Vec<V3>>,
|
||||
pub(crate) normal: V3,
|
||||
pub(crate) part: MeshPart,
|
||||
pub(crate) attrs: Attrs,
|
||||
}
|
||||
|
||||
impl Face3 {
|
||||
/// The texture coordinates of corner `v` of the face, and its own normal when it has one (a
|
||||
/// corner of a smoothed bevel or of a puffed surface). A point that is no corner of the face
|
||||
/// lies at the middle of the texture.
|
||||
pub(crate) fn corner(&self, v: V3) -> ([f64; 2], Option<V3>) {
|
||||
match &self.attrs {
|
||||
Attrs::Planar(plane) => (plane.at(v), None),
|
||||
Attrs::Corners(list) => self
|
||||
.contours
|
||||
.iter()
|
||||
.zip(list)
|
||||
.flat_map(|(c, l)| c.iter().zip(l))
|
||||
.find(|(c, _)| **c == v)
|
||||
.map_or(([0.5, 0.5], None), |(_, (uv, n))| (*uv, *n)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Where the corners of a face lie on its part's texture, from 0 to 1 each way (u to the right, v
|
||||
/// down), and the normals of the corners that have their own.
|
||||
#[derive(Clone, Debug)]
|
||||
pub(crate) enum Attrs {
|
||||
/// Each corner's place on a plane ([`PlaneUv`]); every corner takes the face's normal.
|
||||
Planar(PlaneUv),
|
||||
/// For each corner of each contour, in order, its texture coordinates and its own normal
|
||||
/// (`None` takes the face's).
|
||||
Corners(Vec<Vec<([f64; 2], Option<V3>)>>),
|
||||
}
|
||||
|
||||
/// A plane's texture coordinates: a point `p` on it lies at `origin + x·s + y·t`, and `(s, t)`
|
||||
/// within `area` goes to 0..1 each way. `x` and `y` are square to each other. An axis on which
|
||||
/// `area` has no extent gives 0.5.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub(crate) struct PlaneUv {
|
||||
pub(crate) origin: V3,
|
||||
pub(crate) x: V3,
|
||||
pub(crate) y: V3,
|
||||
pub(crate) area: Rect,
|
||||
}
|
||||
|
||||
impl PlaneUv {
|
||||
pub(crate) fn at(&self, p: V3) -> [f64; 2] {
|
||||
let d = p.sub(self.origin);
|
||||
let along = |axis: V3| d.dot(axis) / axis.dot(axis);
|
||||
[share(along(self.x), self.area.x0, self.area.x1), share(along(self.y), self.area.y0, self.area.y1)]
|
||||
}
|
||||
}
|
||||
|
||||
/// Where `v` lies from `lo` (0) to `hi` (1), within 0..1: 0.5 when the two are equal or `v` is not
|
||||
/// finite.
|
||||
pub(crate) fn share(v: f64, lo: f64, hi: f64) -> f64 {
|
||||
let w = hi - lo;
|
||||
if w > 1e-12 && v.is_finite() { ((v - lo) / w).clamp(0.0, 1.0) } else { 0.5 }
|
||||
}
|
||||
|
||||
/// The bounds of the points of `rings`, or an empty rectangle at the origin when they have none.
|
||||
pub(crate) fn rings_bounds<'a>(rings: impl IntoIterator<Item = &'a [Point]>) -> Rect {
|
||||
let mut points = rings.into_iter().flatten();
|
||||
let Some(first) = points.next() else { return Rect::ZERO };
|
||||
points.fold(Rect::from_points(*first, *first), |b, p| b.union_pt(*p))
|
||||
}
|
||||
|
||||
/// The texture coordinate along each point of `ring` and back to its first point: the distance
|
||||
/// along the ring from its first point over the ring's length, so the first point takes 0 and the
|
||||
/// last entry (the first point again) 1. A ring of no length takes 0.5 throughout.
|
||||
pub(crate) fn along_ring(ring: &[Point]) -> Vec<f64> {
|
||||
let n = ring.len();
|
||||
let mut at = Vec::with_capacity(n + 1);
|
||||
let mut sum = 0.0;
|
||||
for i in 0..=n {
|
||||
at.push(sum);
|
||||
if let (Some(a), Some(b)) = (ring.get(i % n.max(1)), ring.get((i + 1) % n.max(1))) {
|
||||
sum += a.distance(*b);
|
||||
}
|
||||
}
|
||||
let total = at.last().copied().unwrap_or(0.0);
|
||||
at.iter().map(|d| if total > 1e-12 { (d / total).clamp(0.0, 1.0) } else { 0.5 }).collect()
|
||||
}
|
||||
|
||||
/// The texture coordinates and corner normals of the faces of one band ([`Builder::curved_band`]):
|
||||
/// the coordinate along the ring at each of its points and back at its first ([`along_ring`]), the
|
||||
/// coordinate across the band at its two rings, and, for each edge of the rings, the normal of its
|
||||
/// corners on each ring when they are smoothed (`None` takes the face's).
|
||||
pub(super) struct BandMesh<'a> {
|
||||
pub(super) part: MeshPart,
|
||||
pub(super) u: &'a [f64],
|
||||
pub(super) v: [f64; 2],
|
||||
pub(super) normals: Option<RowNormals<'a>>,
|
||||
}
|
||||
|
||||
/// The smoothed normals of the corners of each edge on a band's two rings ([`BandMesh`]).
|
||||
pub(super) type RowNormals<'a> = (&'a [Option<V3>], &'a [Option<V3>]);
|
||||
|
||||
/// What a solid's builder makes: its facets, its faces before projection when a mesh is asked for
|
||||
/// (an error when they pass [`MAX_SOLID_FACES`] while the facets are built too), and the
|
||||
@@ -145,8 +246,22 @@ impl<'a> Builder<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether the builder keeps faces for a mesh.
|
||||
pub(super) fn keeps_mesh(&self) -> bool {
|
||||
self.mesh.is_some()
|
||||
}
|
||||
|
||||
/// Add a face of view-space contours with outward normal `n` (view space), drawn in `order`.
|
||||
pub(super) fn face(&mut self, contours: Vec<Vec<V3>>, n: V3, order: Order) -> Result<(), String> {
|
||||
/// For a mesh it belongs to `part`, and `attrs` gives where its corners lie on the part's
|
||||
/// texture, from its contours.
|
||||
pub(super) fn face(
|
||||
&mut self,
|
||||
contours: Vec<Vec<V3>>,
|
||||
n: V3,
|
||||
order: Order,
|
||||
part: MeshPart,
|
||||
attrs: impl FnOnce(&[Vec<V3>]) -> Attrs,
|
||||
) -> Result<(), String> {
|
||||
let count: usize = contours.iter().map(Vec::len).sum();
|
||||
if count < 3 {
|
||||
return Ok(());
|
||||
@@ -155,7 +270,8 @@ impl<'a> Builder<'a> {
|
||||
self.facet(&contours, count, n, order)?;
|
||||
}
|
||||
let Some(mesh) = &mut self.mesh else { return Ok(()) };
|
||||
mesh.push((contours, n.unit()));
|
||||
let attrs = attrs(&contours);
|
||||
mesh.push(Face3 { contours, normal: n.unit(), part, attrs });
|
||||
if mesh.len() > MAX_SOLID_FACES {
|
||||
if !self.draw {
|
||||
return Err(TOO_COMPLEX_SURFACE.into());
|
||||
@@ -245,15 +361,23 @@ impl<'a> Builder<'a> {
|
||||
}
|
||||
|
||||
/// A planar surface triangle with shared, smooth outward normals. Culling and sorting
|
||||
/// still use its geometry, rather than the normals used only for lighting.
|
||||
pub(super) fn smooth_triangle(&mut self, vertices: [V3; 3], normals: [V3; 3], back: bool) -> Result<(), String> {
|
||||
/// still use its geometry, rather than the normals used only for lighting. For a mesh it
|
||||
/// belongs to `part`, with its corners at `uv` on the part's texture and their normals.
|
||||
pub(super) fn smooth_triangle(
|
||||
&mut self,
|
||||
vertices: [V3; 3],
|
||||
normals: [V3; 3],
|
||||
back: bool,
|
||||
part: MeshPart,
|
||||
uv: [[f64; 2]; 3],
|
||||
) -> Result<(), String> {
|
||||
let contours = vec![vertices.to_vec()];
|
||||
let n = newell(&contours);
|
||||
let n = if back { V3(-n.0, -n.1, -n.2) } else { n };
|
||||
let centre = vertices.iter().fold(V3::default(), |s, v| V3(s.0 + v.0 / 3.0, s.1 + v.1 / 3.0, s.2 + v.2 / 3.0));
|
||||
let flip = !self.closed && self.camera.facing(centre, n.unit()) <= 0.0;
|
||||
let before = self.facets.len();
|
||||
self.face(contours, n, Order::Depth)?;
|
||||
self.face(contours, n, Order::Depth, part, |_| Attrs::Corners(vec![uv.iter().zip(normals).map(|(uv, n)| (*uv, Some(n))).collect()]))?;
|
||||
if self.facets.len() == before || !self.camera.view.shade {
|
||||
return Ok(());
|
||||
}
|
||||
@@ -270,15 +394,17 @@ impl<'a> Builder<'a> {
|
||||
|
||||
/// The band between two partner rings (same length), as one quad per edge, or for a twisted
|
||||
/// wall with `cuts` (see [`cuts`]) as `cuts[i]` quads along edge `i`. `outward` is the
|
||||
/// direction (before rotation) the band faces away from the solid, for orienting normals.
|
||||
pub(super) fn band(&mut self, a: &[V3], b: &[V3], cuts: &[usize], outward: impl Fn(usize) -> V3) -> Result<(), String> {
|
||||
self.curved_band(a, b, cuts, outward, None, None)
|
||||
/// direction (before rotation) the band faces away from the solid, for orienting normals. For a
|
||||
/// mesh the quads take their part, texture coordinates and corner normals from `mesh`.
|
||||
pub(super) fn band(&mut self, a: &[V3], b: &[V3], cuts: &[usize], outward: impl Fn(usize) -> V3, mesh: &BandMesh) -> Result<(), String> {
|
||||
self.curved_band(a, b, cuts, outward, None, None, mesh)
|
||||
}
|
||||
|
||||
/// [`Builder::band`], with `curves` the pieces of curve the rings' edges follow and the
|
||||
/// outlines at `a` and `b`: a quad whose edge is not cut keeps its edges along the profile curved.
|
||||
/// With `side`, each quad carries where its corners lie on the side unrolled flat
|
||||
/// ([`Facet::surface`]).
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub(super) fn curved_band(
|
||||
&mut self,
|
||||
a: &[V3],
|
||||
@@ -287,6 +413,7 @@ impl<'a> Builder<'a> {
|
||||
outward: impl Fn(usize) -> V3,
|
||||
mut curves: Option<WallCurves>,
|
||||
side: Option<SideBand>,
|
||||
mesh: &BandMesh,
|
||||
) -> Result<(), String> {
|
||||
let n = a.len().min(b.len());
|
||||
// At 0 and 1, the corners themselves.
|
||||
@@ -316,7 +443,17 @@ impl<'a> Builder<'a> {
|
||||
normal = V3(-normal.0, -normal.1, -normal.2);
|
||||
}
|
||||
let before = self.facets.len();
|
||||
self.face(vec![quad], normal, order)?;
|
||||
let attrs = |_: &[Vec<V3>]| {
|
||||
let (u0, u1) = (mesh.u.get(i).copied().unwrap_or(0.5), mesh.u.get(i + 1).copied().unwrap_or(0.5));
|
||||
let (ua, ub) = (u0 + (u1 - u0) * s0, u0 + (u1 - u0) * s1);
|
||||
let [va, vb] = mesh.v;
|
||||
// A cut edge's pieces keep their own normals.
|
||||
let normals = mesh.normals.filter(|_| pieces == 1);
|
||||
let na = normals.and_then(|(na, _)| na.get(i).copied().flatten());
|
||||
let nb = normals.and_then(|(_, nb)| nb.get(i).copied().flatten());
|
||||
Attrs::Corners(vec![vec![([ua, va], na), ([ub, va], na), ([ub, vb], nb), ([ua, vb], nb)]])
|
||||
};
|
||||
self.face(vec![quad], normal, order, mesh.part, attrs)?;
|
||||
if self.facets.len() > before
|
||||
&& let Some(f) = self.facets.last_mut()
|
||||
{
|
||||
@@ -648,6 +785,92 @@ fn steps(o: &Extrude) -> Vec<Step> {
|
||||
out
|
||||
}
|
||||
|
||||
/// The face a band between steps `s0` and `s1` borders: +1 between two front bevel steps, -1 when
|
||||
/// it reaches a back bevel step, and 0 for a wall.
|
||||
fn band_face(s0: &Step, s1: &Step) -> f64 {
|
||||
if s1.face < 0.0 {
|
||||
-1.0
|
||||
} else if s0.face > 0.0 && s1.face > 0.0 {
|
||||
1.0
|
||||
} else {
|
||||
0.0
|
||||
}
|
||||
}
|
||||
|
||||
/// The part of the mesh a band bordering `face` ([`band_face`]) belongs to.
|
||||
fn band_part(face: f64) -> MeshPart {
|
||||
if face > 0.0 {
|
||||
MeshPart::FrontBevel
|
||||
} else if face < 0.0 {
|
||||
MeshPart::BackBevel
|
||||
} else {
|
||||
MeshPart::Side
|
||||
}
|
||||
}
|
||||
|
||||
/// The texture coordinate across the side at each step, front to back: the distance from the
|
||||
/// front cap's edge through the bevels and walls (inset and depth together) over the whole
|
||||
/// distance to the back cap's edge. With no distance every step takes 0.5.
|
||||
fn step_coordinates(steps: &[Step], depth: f64) -> Vec<f64> {
|
||||
let mut at = Vec::with_capacity(steps.len());
|
||||
let mut sum = 0.0;
|
||||
for (k, s) in steps.iter().enumerate() {
|
||||
if let Some(p) = k.checked_sub(1).and_then(|k| steps.get(k)) {
|
||||
sum += (s.inset - p.inset).hypot((s.t - p.t) * depth);
|
||||
}
|
||||
at.push(sum);
|
||||
}
|
||||
at.iter().map(|d| if sum > 1e-12 { (d / sum).clamp(0.0, 1.0) } else { 0.5 }).collect()
|
||||
}
|
||||
|
||||
/// The largest angle, in degrees, between two neighboring bands of one bevel whose shared corners
|
||||
/// are smoothed for a mesh. A sharper turn (a Step profile's) stays a hard edge.
|
||||
pub(crate) const BEVEL_CREASE: f64 = 60.0;
|
||||
|
||||
/// For a mesh, the normal of each corner of each edge of `ring` at each step (one list per step,
|
||||
/// one entry per edge) where the bands on either side are smoothed: two bands of the same bevel,
|
||||
/// front or back, that turn by less than [`BEVEL_CREASE`], neither of them lying flat toward the
|
||||
/// front or back (as a cap does). Such a corner takes the mean of the two bands' unit normals;
|
||||
/// every other corner is `None` and takes its face's normal. `placed` holds the ring at each step
|
||||
/// in view space.
|
||||
fn smoothed_rows(camera: &Camera, ring: &[Point], steps: &[Step], placed: &[Vec<V3>]) -> Vec<Vec<Option<V3>>> {
|
||||
let n = ring.len();
|
||||
let front = camera.rotate(V3(0.0, 0.0, 1.0));
|
||||
// Each band's unit outward normal at each edge, as [`Builder::curved_band`] orients it.
|
||||
let bands: Vec<(MeshPart, Vec<V3>)> = placed
|
||||
.windows(2)
|
||||
.zip(steps.windows(2))
|
||||
.map(|(pair, s)| {
|
||||
let face = band_face(&s[0], &s[1]);
|
||||
let normals = (0..n)
|
||||
.map(|i| {
|
||||
let j = (i + 1) % n;
|
||||
let (Some(a), Some(c)) = (pair.first(), pair.get(1)) else { return V3::default() };
|
||||
let quad = [a.get(i), a.get(j), c.get(j), c.get(i)].into_iter().flatten().copied().collect::<Vec<_>>();
|
||||
let normal = newell(std::slice::from_ref(&quad)).unit();
|
||||
if normal.dot(camera.rotate(outward(ring, i, face))) < 0.0 { V3(-normal.0, -normal.1, -normal.2) } else { normal }
|
||||
})
|
||||
.collect();
|
||||
(band_part(face), normals)
|
||||
})
|
||||
.collect();
|
||||
let crease = BEVEL_CREASE.to_radians().cos();
|
||||
let flat = |v: V3| v.dot(front).abs() > 1.0 - 1e-6;
|
||||
(0..steps.len())
|
||||
.map(|k| {
|
||||
let pair = k.checked_sub(1).and_then(|p| bands.get(p)).zip(bands.get(k));
|
||||
let Some(((_, n0), (_, n1))) = pair.filter(|((p0, _), (p1, _))| p0 == p1 && *p0 != MeshPart::Side) else { return vec![None; n] };
|
||||
n0.iter()
|
||||
.zip(n1)
|
||||
.map(|(a, b)| {
|
||||
let whole = a.dot(*a) > 0.5 && b.dot(*b) > 0.5;
|
||||
(whole && !flat(*a) && !flat(*b) && a.dot(*b) > crease).then(|| V3(a.0 + b.0, a.1 + b.1, a.2 + b.2).unit())
|
||||
})
|
||||
.collect()
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Extrude & Bevel: the shape's outline extruded backwards, with optional twist, taper, bevels
|
||||
/// and caps.
|
||||
pub fn extrude(path: &PathData, rule: FillRule, bounds: Rect, options: Extrude, view: View) -> Result<Vec<Facet>, String> {
|
||||
@@ -737,9 +960,14 @@ pub(crate) fn extrude_faces(path: &PathData, rule: FillRule, bounds: Rect, optio
|
||||
Some((k, side::along_ring(rings.get(k)?)?, y))
|
||||
})
|
||||
.flatten();
|
||||
// For a mesh: the texture coordinate across the side at each step, and the parts of the bands.
|
||||
let across = step_coordinates(&steps, o.depth);
|
||||
let part_of = |s0: &Step, s1: &Step| band_part(band_face(s0, s1));
|
||||
for (r, ((ring, traced), pieces)) in rings.iter().zip(&traced).zip(&pieces).enumerate() {
|
||||
let unrolled = unrolled.as_ref().filter(|(k, ..)| *k == r);
|
||||
let placed: Vec<Vec<V3>> = steps.iter().map(|s| ring_at(ring, s)).collect();
|
||||
let u = along_ring(ring);
|
||||
let rows = if b.keeps_mesh() { smoothed_rows(&camera, ring, &steps, &placed) } else { vec![] };
|
||||
for (k, pair) in placed.windows(2).enumerate() {
|
||||
let ([a, c], Some(s0), Some(s1)) = (pair, steps.get(k), steps.get(k + 1)) else { continue };
|
||||
b.cells = layout.as_ref().and_then(|(sides, spans)| {
|
||||
@@ -753,32 +981,34 @@ pub(crate) fn extrude_faces(path: &PathData, rule: FillRule, bounds: Rect, optio
|
||||
let edges = sides.edges.get(r)?.iter().map(|e| e.map(|(section, u0, u1)| (base + section, u0, u1))).collect();
|
||||
Some(BandCells { edges, across: (v0, v1) })
|
||||
});
|
||||
// A band between two front bevel steps borders the front, one reaching a back bevel
|
||||
// step the back; the rest are walls.
|
||||
let face = if s1.face < 0.0 {
|
||||
-1.0
|
||||
} else if s0.face > 0.0 && s1.face > 0.0 {
|
||||
1.0
|
||||
} else {
|
||||
0.0
|
||||
};
|
||||
let face = band_face(s0, s1);
|
||||
// The edges a band shares with a cap follow the cap's curves; the edges between two bands
|
||||
// stay straight, within the sampling tolerance.
|
||||
let (near, far) = (along.get(k).filter(|_| k == 0), along.get(k + 1).filter(|_| k + 2 == steps.len()));
|
||||
let curves = (near.is_some() || far.is_some()).then(|| WallCurves { spans: &traced.spans, near, far, budget: &mut budget });
|
||||
let side = unrolled.and_then(|(_, x, y)| Some(SideBand { x, y: [*y.get(k)?, *y.get(k + 1)?] }));
|
||||
b.curved_band(a, c, pieces, |i| outward(ring, i, face), curves, side)?;
|
||||
let normals = rows.get(k).zip(rows.get(k + 1)).map(|(na, nb)| (na.as_slice(), nb.as_slice()));
|
||||
let v = [across.get(k).copied().unwrap_or(0.5), across.get(k + 1).copied().unwrap_or(0.5)];
|
||||
let mesh = BandMesh { part: part_of(s0, s1), u: &u, v, normals };
|
||||
b.curved_band(a, c, pieces, |i| outward(ring, i, face), curves, side, &mesh)?;
|
||||
}
|
||||
}
|
||||
b.cells = None;
|
||||
if o.cap {
|
||||
// A cap turned toward the viewer covers the walls it overlaps, even those nearer than its
|
||||
// center: twisted walls, and the walls of a fill inside the solid of its stroke.
|
||||
let caps = [(steps.first(), along.first(), 1.0, PlanarFace::Front), (steps.last(), along.last(), -1.0, PlanarFace::Back)];
|
||||
for (s, along, n, end) in caps {
|
||||
let Some(s) = s else { continue };
|
||||
let caps = [
|
||||
(steps.first(), maps.first(), along.first(), 1.0, PlanarFace::Front, MeshPart::Front),
|
||||
(steps.last(), maps.last(), along.last(), -1.0, PlanarFace::Back, MeshPart::Back),
|
||||
];
|
||||
// Each cap's corners take their art points, before any twist or taper, in the art's bounds.
|
||||
let area = rings_bounds(rings.iter().copied());
|
||||
for (s, map, along, n, end, part) in caps {
|
||||
let (Some(s), Some(map)) = (s, map) else { continue };
|
||||
let before = b.len();
|
||||
b.face(rings.iter().map(|r| ring_at(r, s)).collect(), camera.rotate(V3(0.0, 0.0, n)), Order::Last)?;
|
||||
let (x, y, origin) = map.frame();
|
||||
let plane = Attrs::Planar(PlaneUv { origin, x, y, area });
|
||||
b.face(rings.iter().map(|r| ring_at(r, s)).collect(), camera.rotate(V3(0.0, 0.0, n)), Order::Last, part, |_| plane)?;
|
||||
b.end(before, end);
|
||||
if let Some(along) = along {
|
||||
let traced: Vec<&Ring> = traced.iter().collect();
|
||||
@@ -986,9 +1216,12 @@ pub(crate) fn plane_faces(path: &PathData, rule: FillRule, bounds: Rect, view: V
|
||||
// it is drawn last, as a cap is, and planes drawn in one order keep the order they are given in.
|
||||
let up = camera.rotate(V3(0.0, 0.0, 1.0));
|
||||
let n = if camera.facing(V3::default(), up) < 0.0 { V3(-up.0, -up.1, -up.2) } else { up };
|
||||
b.face(contours, n, Order::Last)?;
|
||||
b.end(0, PlanarFace::Front);
|
||||
let m = Placing::new(&camera, bounds.center(), Turn::new(bounds, 0.0, 1.0, 0.0), 0.0);
|
||||
// The plane's corners take their art points in the art's bounds.
|
||||
let (x, y, origin) = m.frame();
|
||||
let plane = Attrs::Planar(PlaneUv { origin, x, y, area: rings_bounds(rings.iter().map(|r| r.points.as_slice())) });
|
||||
b.face(contours, n, Order::Last, MeshPart::Front, |_| plane)?;
|
||||
b.end(0, PlanarFace::Front);
|
||||
let at = |span: &Span, t: f64| camera.project(m.place(span.curve.eval(t)));
|
||||
let map = |p: Point| camera.project(m.place(p));
|
||||
let along = Along { at: &at, map: Some(&map), affine: camera.eye.is_none(), tolerance: CURVE_TOLERANCE };
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
use super::build::{Builder, Built, Camera, Keep, Order, Turn, check_bounds, cuts, fit, newell, outward};
|
||||
use super::build::{
|
||||
Attrs, BandMesh, Builder, Built, Camera, Keep, Order, Placing, PlaneUv, Turn, along_ring, check_bounds, cuts, fit, newell, outward, rings_bounds,
|
||||
share,
|
||||
};
|
||||
use super::membrane::{Edges, MAX_MATERIAL_SEGMENTS, Membrane, cell_triangles, clip, crossings, filled, material};
|
||||
use super::rings::{MAX_SOLID_POINTS, TOO_COMPLEX_SURFACE, curve_pieces, signed_area, solid_rings};
|
||||
use super::{Facet, FillRule, Inflate, MAX_FACES, MAX_SOLID_FACES, PathData, PlanarFace, Point, Rect, V3, Vec2, View};
|
||||
use crate::mesh::MeshPart;
|
||||
|
||||
/// The slices the sides are cut into: more to follow a twist or taper.
|
||||
fn slices(o: &Inflate) -> usize {
|
||||
@@ -278,6 +282,12 @@ fn inflated(p: Puff, bounds: Rect, o: Inflate, view: View, reach: f64, keep: Kee
|
||||
if n.dot(n) > 0.5 { n } else { V3(0.0, 0.0, 1.0) }
|
||||
};
|
||||
let smooth = view.shade && view.has_colored_lights();
|
||||
// For a mesh, a point of the front or back takes its art point in the shape's bounds, and on a
|
||||
// puffed surface its own normal, front or back (turned as the back is).
|
||||
let area = rings_bounds(rings.iter().map(Vec::as_slice));
|
||||
let uv = |q: Point| [share(q.x, area.x0, area.x1), share(q.y, area.y0, area.y1)];
|
||||
let puffed = height > 0.0;
|
||||
let back_normal = |n: V3, turn: &Turn| V3(turn.cos * n.0 - turn.sin * n.1, turn.sin * n.0 + turn.cos * n.1, -n.2);
|
||||
let camera = Camera::new(view, bounds, o.depth + 2.0 * height.max(reach));
|
||||
// A graphic's offsets are from the center of the bounds the solid is built with.
|
||||
let center = bounds.center();
|
||||
@@ -481,9 +491,12 @@ fn inflated(p: Puff, bounds: Rect, o: Inflate, view: View, reach: f64, keep: Kee
|
||||
let before = b.facets.len();
|
||||
let outward = newell(&[front.to_vec()]);
|
||||
if smoothed {
|
||||
b.smooth_triangle(front, points.map(|q| camera.rotate(normal(q))), false)?;
|
||||
b.smooth_triangle(front, points.map(|q| camera.rotate(normal(q))), false, MeshPart::Front, points.map(uv))?;
|
||||
} else {
|
||||
b.face(vec![front.to_vec()], outward, order)?;
|
||||
let attrs = |_: &[Vec<V3>]| {
|
||||
Attrs::Corners(vec![points.iter().map(|q| (uv(*q), puffed.then(|| camera.rotate(normal(*q))))).collect()])
|
||||
};
|
||||
b.face(vec![front.to_vec()], outward, order, MeshPart::Front, attrs)?;
|
||||
}
|
||||
if o.map_surface {
|
||||
mark_surface(&mut b, before, points, center, outward, PlanarFace::Front);
|
||||
@@ -496,15 +509,16 @@ fn inflated(p: Puff, bounds: Rect, o: Inflate, view: View, reach: f64, keep: Kee
|
||||
// normal is reversed.
|
||||
let outward = V3(-n.0, -n.1, -n.2);
|
||||
if smoothed {
|
||||
let normals = points.map(|q| {
|
||||
let n = normal(q);
|
||||
// A uniform taper scales all three coordinates equally;
|
||||
// twist turns the back normal about the shape's z-axis.
|
||||
camera.rotate(V3(back_turn.cos * n.0 - back_turn.sin * n.1, back_turn.sin * n.0 + back_turn.cos * n.1, -n.2))
|
||||
});
|
||||
b.smooth_triangle(back, normals, true)?;
|
||||
// A uniform taper scales all three coordinates equally; twist
|
||||
// turns the back normal about the shape's z-axis.
|
||||
let normals = points.map(|q| camera.rotate(back_normal(normal(q), &back_turn)));
|
||||
b.smooth_triangle(back, normals, true, MeshPart::Back, points.map(uv))?;
|
||||
} else {
|
||||
b.face(vec![back.to_vec()], outward, order)?;
|
||||
let attrs = |_: &[Vec<V3>]| {
|
||||
let corner = |q: &Point| (uv(*q), puffed.then(|| camera.rotate(back_normal(normal(*q), &back_turn))));
|
||||
Attrs::Corners(vec![points.iter().map(corner).collect()])
|
||||
};
|
||||
b.face(vec![back.to_vec()], outward, order, MeshPart::Back, attrs)?;
|
||||
}
|
||||
if o.map_surface {
|
||||
mark_surface(&mut b, before, points, center, outward, PlanarFace::Back);
|
||||
@@ -521,7 +535,11 @@ fn inflated(p: Puff, bounds: Rect, o: Inflate, view: View, reach: f64, keep: Kee
|
||||
pieces.iter().zip(&lifts).map(|(p, h)| p.iter().zip(h).map(|(q, h)| camera.place(*q, half + h)).collect()).collect();
|
||||
let n = newell(&front);
|
||||
let order = if flat { Order::Last } else { Order::Depth };
|
||||
b.face(front, n, order)?;
|
||||
let corners = |side: &dyn Fn(Point) -> Option<V3>| -> Attrs {
|
||||
Attrs::Corners(pieces.iter().map(|p| p.iter().map(|q| (uv(*q), side(*q))).collect()).collect())
|
||||
};
|
||||
let front_normal = |q: Point| puffed.then(|| camera.rotate(normal(q)));
|
||||
b.face(front, n, order, MeshPart::Front, |_| corners(&front_normal))?;
|
||||
if o.both_sides && o.cap {
|
||||
// The back winds the same way round as the front, so its outward normal is
|
||||
// reversed.
|
||||
@@ -531,7 +549,8 @@ fn inflated(p: Puff, bounds: Rect, o: Inflate, view: View, reach: f64, keep: Kee
|
||||
.map(|(p, h)| p.iter().zip(h).map(|(q, h)| camera.place(back_turn.apply(*q), -half - h * back_turn.scale)).collect())
|
||||
.collect();
|
||||
let n = newell(&back);
|
||||
b.face(back, V3(-n.0, -n.1, -n.2), order)?;
|
||||
let back_side = |q: Point| puffed.then(|| camera.rotate(back_normal(normal(q), &back_turn)));
|
||||
b.face(back, V3(-n.0, -n.1, -n.2), order, MeshPart::Back, |_| corners(&back_side))?;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -539,9 +558,11 @@ fn inflated(p: Puff, bounds: Rect, o: Inflate, view: View, reach: f64, keep: Kee
|
||||
}
|
||||
if !o.both_sides && o.cap {
|
||||
let back: Vec<Vec<V3>> = rings.iter().map(|r| r.iter().map(|p| camera.place(back_turn.apply(*p), -half)).collect()).collect();
|
||||
let (x, y, origin) = Placing::new(&camera, bounds.center(), back_turn, -half).frame();
|
||||
let plane = Attrs::Planar(PlaneUv { origin, x, y, area });
|
||||
// The back turned toward the viewer covers the walls it overlaps, even those nearer than
|
||||
// its center: twisted walls, and the walls of a fill inside the solid of its stroke.
|
||||
b.face(back, camera.rotate(V3(0.0, 0.0, -1.0)), Order::Last)?;
|
||||
b.face(back, camera.rotate(V3(0.0, 0.0, -1.0)), Order::Last, MeshPart::Back, |_| plane)?;
|
||||
}
|
||||
if o.depth > 0.0 {
|
||||
// The sides, cut into slices that follow a twist or taper.
|
||||
@@ -558,10 +579,14 @@ fn inflated(p: Puff, bounds: Rect, o: Inflate, view: View, reach: f64, keep: Kee
|
||||
if b.len().saturating_add(edges.saturating_mul(slices)) > MAX_SOLID_FACES {
|
||||
return Err(TOO_COMPLEX_SURFACE.into());
|
||||
}
|
||||
// For a mesh, the sides run across from the front (0) to the back (1).
|
||||
let across = |k: usize| k as f64 / slices.max(1) as f64;
|
||||
let sides = |b: &mut Builder<'_>, pieces: &[Vec<usize>]| -> Result<(), String> {
|
||||
for (ring, pieces) in rings.iter().zip(pieces) {
|
||||
let u = along_ring(ring);
|
||||
for k in 0..slices {
|
||||
b.band(&at(ring, k), &at(ring, k + 1), pieces, |i| outward(ring, i, 0.0))?;
|
||||
let mesh = BandMesh { part: MeshPart::Side, u: &u, v: [across(k), across(k + 1)], normals: None };
|
||||
b.band(&at(ring, k), &at(ring, k + 1), pieces, |i| outward(ring, i, 0.0), &mesh)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
||||
@@ -232,7 +232,7 @@ fn a_face_reaching_past_the_eye_has_no_plane() {
|
||||
for (far, has_plane) in [(eye / 2.0, true), (2.0 * eye, false)] {
|
||||
let mut builder = Builder::new(&camera, false, false, Keep::Facets);
|
||||
let corners = vec![V3(-10.0, -10.0, 0.0), V3(10.0, -10.0, 0.0), V3(0.0, 10.0, far)];
|
||||
builder.face(vec![corners], V3(0.0, -far, 20.0), Order::Depth).unwrap();
|
||||
builder.face(vec![corners], V3(0.0, -far, 20.0), Order::Depth, crate::MeshPart::Front, |_| super::Attrs::Corners(vec![])).unwrap();
|
||||
assert_eq!(builder.facets.len(), 1, "{far}");
|
||||
assert_eq!(builder.facets[0].plane.is_some(), has_plane, "{far}");
|
||||
}
|
||||
|
||||
@@ -276,8 +276,8 @@ fn the_cut_sides_kept_for_a_mesh_have_a_corner_at_every_corner_of_the_side() {
|
||||
// cut side's alone, which faces back against the sweep.
|
||||
let in_plane = |all: bool| {
|
||||
let start = |n: &V3| (n.0.abs() + n.1.abs() + (n.2 + 1.0).abs()) < 1e-9;
|
||||
let kept = faces.iter().filter(|(_, n)| all || start(n));
|
||||
kept.flat_map(|(contours, _)| contours.iter().flatten().copied()).filter(|v| v.2.abs() < 1e-9).collect::<Vec<V3>>()
|
||||
let kept = faces.iter().filter(|f| all || start(&f.normal));
|
||||
kept.flat_map(|f| f.contours.iter().flatten().copied()).filter(|v| v.2.abs() < 1e-9).collect::<Vec<V3>>()
|
||||
};
|
||||
let cut = in_plane(false);
|
||||
assert!(!cut.is_empty());
|
||||
|
||||
@@ -7269,6 +7269,7 @@ liquify-list-end {0}, {1} {0} i {1}
|
||||
@msg a 3D effect on a group's fill or stroke draws nothing un efecte 3D al farciment o al traç d’un grup no dibuixa res
|
||||
@msg a 3D effect on a group's fill or stroke draws nothing to export un efecte 3D al farciment o al traç d’un grup no dibuixa res per exportar
|
||||
@msg The 3D object is too complex to export L’objecte 3D és massa complex per exportar-lo
|
||||
@msg The 3D object's mesh is incomplete or holds a value that is not a number La malla de l’objecte 3D és incompleta o conté un valor que no és un nombre
|
||||
@msg give one <filter> element indica un element <filter>
|
||||
@msg the <filter> element needs an id, the filter's name l’element <filter> necessita un id, el nom del filtre
|
||||
@msg an SVG filter's id is at most {MAX_NAME} characters l’id d’un filtre SVG té com a màxim {MAX_NAME} caràcters
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -6860,6 +6860,7 @@ mark-style Japanese Japonské
|
||||
@msg a 3D effect on a group's fill or stroke draws nothing 3D efekt na výplni nebo tahu skupiny nic nekreslí
|
||||
@msg a 3D effect on a group's fill or stroke draws nothing to export 3D efekt na výplni nebo tahu skupiny nekreslí nic k exportu
|
||||
@msg The 3D object is too complex to export 3D objekt je pro export příliš složitý
|
||||
@msg The 3D object's mesh is incomplete or holds a value that is not a number Síť 3D objektu je neúplná nebo obsahuje hodnotu, která není číslo
|
||||
@msg the <filter> element needs an id, the filter's name prvek <filter> potřebuje id, název filtru
|
||||
@msg an SVG filter's id is at most {MAX_NAME} characters id filtru SVG má nejvýše {MAX_NAME} znaků
|
||||
@msg <{_1}> isn't an element of an SVG filter <{_1}> není prvkem filtru SVG
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -410,6 +410,7 @@ liquify-list-end {0}, {1} {0} og {1}
|
||||
@msg a 3D effect on a group's fill or stroke draws nothing en 3D-effekt på en gruppes udfyldning eller streg tegner intet
|
||||
@msg a 3D effect on a group's fill or stroke draws nothing to export en 3D-effekt på en gruppes udfyldning eller streg tegner intet at eksportere
|
||||
@msg The 3D object is too complex to export 3D-objektet er for komplekst til at blive eksporteret
|
||||
@msg The 3D object's mesh is incomplete or holds a value that is not a number 3D-objektets net er ufuldstændigt eller indeholder en værdi, der ikke er et tal
|
||||
@msg give one <filter> element angiv ét <filter>-element
|
||||
@msg the <filter> element needs an id, the filter's name <filter>-elementet skal have et id, filterets navn
|
||||
@msg an SVG filter's id is at most {MAX_NAME} characters et SVG-filters id er højst {MAX_NAME} tegn
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -6427,6 +6427,7 @@ lighting Light Licht
|
||||
@msg a 3D effect on a group's fill or stroke draws nothing ein 3D-Effekt auf der Fläche oder Kontur einer Gruppe zeichnet nichts
|
||||
@msg a 3D effect on a group's fill or stroke draws nothing to export ein 3D-Effekt auf der Fläche oder Kontur einer Gruppe zeichnet nichts, das exportiert werden kann
|
||||
@msg The 3D object is too complex to export Das 3D-Objekt ist zu komplex für den Export
|
||||
@msg The 3D object's mesh is incomplete or holds a value that is not a number Das Netz des 3D-Objekts ist unvollständig oder enthält einen Wert, der keine Zahl ist
|
||||
@msg the <filter> element needs an id, the filter's name das <filter>-Element braucht eine id, den Namen des Filters
|
||||
@msg an SVG filter's id is at most {MAX_NAME} characters die id eines SVG-Filters hat höchstens {MAX_NAME} Zeichen
|
||||
@msg <{_1}> isn't an element of an SVG filter <{_1}> ist kein Element eines SVG-Filters
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -6242,6 +6242,7 @@ variable-list-end {0}, {1} {0} και {1}
|
||||
@msg a 3D effect on a group's fill or stroke draws nothing ένα εφέ 3D στο γέμισμα ή στην πινελιά μιας ομάδας δεν σχεδιάζει τίποτα
|
||||
@msg a 3D effect on a group's fill or stroke draws nothing to export ένα εφέ 3D στο γέμισμα ή στην πινελιά μιας ομάδας δεν σχεδιάζει τίποτα για εξαγωγή
|
||||
@msg The 3D object is too complex to export Το αντικείμενο 3D είναι πολύ σύνθετο για εξαγωγή
|
||||
@msg The 3D object's mesh is incomplete or holds a value that is not a number Το πλέγμα του αντικειμένου 3D είναι ελλιπές ή περιέχει τιμή που δεν είναι αριθμός
|
||||
@msg give one <filter> element δώστε ένα στοιχείο <filter>
|
||||
@msg the <filter> element needs an id, the filter's name το στοιχείο <filter> χρειάζεται id, το όνομα του φίλτρου
|
||||
@msg an SVG filter's id is at most {MAX_NAME} characters το id ενός φίλτρου SVG έχει το πολύ {MAX_NAME} χαρακτήρες
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -6832,6 +6832,7 @@ mark-style Japanese Japonesas
|
||||
@msg a 3D effect on a group's fill or stroke draws nothing un efecto 3D en el relleno o el trazo de un grupo no dibuja nada
|
||||
@msg a 3D effect on a group's fill or stroke draws nothing to export un efecto 3D en el relleno o el trazo de un grupo no dibuja nada que exportar
|
||||
@msg The 3D object is too complex to export El objeto 3D es demasiado complejo para exportarlo
|
||||
@msg The 3D object's mesh is incomplete or holds a value that is not a number La malla del objeto 3D está incompleta o contiene un valor que no es un número
|
||||
@msg give one <filter> element indique un elemento <filter>
|
||||
@msg the <filter> element needs an id, the filter's name el elemento <filter> necesita un id, el nombre del filtro
|
||||
@msg an SVG filter's id is at most {MAX_NAME} characters el id de un filtro SVG tiene como máximo {MAX_NAME} caracteres
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -6760,6 +6760,7 @@ mark-style Japanese Japanilainen
|
||||
@msg a 3D effect on a group's fill or stroke draws nothing ryhmän täytön tai viivan 3D-tehoste ei piirrä mitään
|
||||
@msg a 3D effect on a group's fill or stroke draws nothing to export ryhmän täytön tai viivan 3D-tehoste ei piirrä mitään vietävää
|
||||
@msg The 3D object is too complex to export 3D-objekti on liian monimutkainen vietäväksi
|
||||
@msg The 3D object's mesh is incomplete or holds a value that is not a number 3D-objektin verkko on puutteellinen tai sisältää arvon, joka ei ole luku
|
||||
@msg give one <filter> element anna yksi <filter>-elementti
|
||||
@msg the <filter> element needs an id, the filter's name <filter>-elementti tarvitsee id:n, suotimen nimen
|
||||
@msg an SVG filter's id is at most {MAX_NAME} characters SVG-suotimen id on enintään {MAX_NAME} merkkiä
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -6443,6 +6443,7 @@ lighting Light Lumière
|
||||
@msg a 3D effect on a group's fill or stroke draws nothing un effet 3D sur le fond ou le contour d’un groupe ne dessine rien
|
||||
@msg a 3D effect on a group's fill or stroke draws nothing to export un effet 3D sur le fond ou le contour d’un groupe ne dessine rien à exporter
|
||||
@msg The 3D object is too complex to export L’objet 3D est trop complexe pour être exporté
|
||||
@msg The 3D object's mesh is incomplete or holds a value that is not a number Le maillage de l’objet 3D est incomplet ou contient une valeur qui n’est pas un nombre
|
||||
@msg the object has no 3D effect (Extrude & Bevel, Revolve, Inflate or Rotate) l’objet n’a aucun effet 3D (Extrusion et biseautage, Révolution, Gonfler ou Rotation)
|
||||
@msg `render` must be an object holding only `mode`, set to shaded or wireframe `render` doit être un objet ne contenant que `mode`, avec la valeur shaded ou wireframe
|
||||
@msg its 3D effect builds no solid son effet 3D ne construit aucun volume
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -9174,6 +9174,7 @@ liquify-list-end {0}, {1} {0} और {1}
|
||||
@msg a 3D effect on a group's fill or stroke draws nothing ग्रुप के फ़िल या स्ट्रोक पर 3D इफ़ेक्ट कुछ नहीं बनाता
|
||||
@msg a 3D effect on a group's fill or stroke draws nothing to export ग्रुप के फ़िल या स्ट्रोक पर 3D इफ़ेक्ट एक्सपोर्ट करने लायक कुछ नहीं बनाता
|
||||
@msg The 3D object is too complex to export 3D ऑब्जेक्ट एक्सपोर्ट करने के लिए बहुत जटिल है
|
||||
@msg The 3D object's mesh is incomplete or holds a value that is not a number 3D ऑब्जेक्ट का मेश अधूरा है या उसमें ऐसा मान है जो संख्या नहीं है
|
||||
@msg give one <filter> element एक <filter> एलिमेंट दें
|
||||
@msg the <filter> element needs an id, the filter's name <filter> एलिमेंट को एक id चाहिए, जो फ़िल्टर का नाम है
|
||||
@msg an SVG filter's id is at most {MAX_NAME} characters SVG फ़िल्टर की id अधिकतम {MAX_NAME} वर्णों की होती है
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -6845,6 +6845,7 @@ variable-list-end {0}, {1} {0} és {1}
|
||||
@msg a 3D effect on a group's fill or stroke draws nothing a csoport kitöltésén vagy körvonalán lévő 3D effektus nem rajzol semmit
|
||||
@msg a 3D effect on a group's fill or stroke draws nothing to export a csoport kitöltésén vagy körvonalán lévő 3D effektus nem rajzol semmi exportálhatót
|
||||
@msg The 3D object is too complex to export A 3D objektum túl összetett az exportáláshoz
|
||||
@msg The 3D object's mesh is incomplete or holds a value that is not a number A 3D objektum hálója hiányos, vagy olyan értéket tartalmaz, amely nem szám
|
||||
@msg the <filter> element needs an id, the filter's name a <filter> elemnek id kell, a szűrő neve
|
||||
@msg an SVG filter's id is at most {MAX_NAME} characters egy SVG-szűrő id-je legfeljebb {MAX_NAME} karakter
|
||||
@msg <{_1}> isn't an element of an SVG filter a(z) <{_1}> nem SVG-szűrő eleme
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -311,6 +311,7 @@
|
||||
@msg a 3D effect on a group's fill or stroke draws nothing efek 3D pada isian atau goresan grup tidak menggambar apa pun
|
||||
@msg a 3D effect on a group's fill or stroke draws nothing to export efek 3D pada isian atau goresan grup tidak menggambar apa pun untuk diekspor
|
||||
@msg The 3D object is too complex to export Objek 3D terlalu rumit untuk diekspor
|
||||
@msg The 3D object's mesh is incomplete or holds a value that is not a number Objek 3D memiliki mesh yang tidak lengkap atau berisi nilai yang bukan angka
|
||||
@msg the object has no 3D effect (Extrude & Bevel, Revolve, Inflate or Rotate) objek tidak memiliki efek 3D (Ekstrusi & bevel, Revolusi, Gelembungkan, atau Putar)
|
||||
@msg `render` must be an object holding only `mode`, set to shaded or wireframe `render` harus berupa objek yang hanya berisi `mode`, bernilai shaded atau wireframe
|
||||
@msg its 3D effect builds no solid efek 3D-nya tidak membangun bentuk padat
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -6474,6 +6474,7 @@ lighting Light Luce
|
||||
@msg a 3D effect on a group's fill or stroke draws nothing un effetto 3D sul riempimento o sulla traccia di un gruppo non disegna nulla
|
||||
@msg a 3D effect on a group's fill or stroke draws nothing to export un effetto 3D sul riempimento o sulla traccia di un gruppo non disegna nulla da esportare
|
||||
@msg The 3D object is too complex to export L'oggetto 3D è troppo complesso per essere esportato
|
||||
@msg The 3D object's mesh is incomplete or holds a value that is not a number La mesh dell'oggetto 3D è incompleta o contiene un valore che non è un numero
|
||||
@msg the <filter> element needs an id, the filter's name l'elemento <filter> richiede un id, il nome del filtro
|
||||
@msg an SVG filter's id is at most {MAX_NAME} characters l'id di un filtro SVG ha al massimo {MAX_NAME} caratteri
|
||||
@msg <{_1}> isn't an element of an SVG filter <{_1}> non è un elemento di un filtro SVG
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -6523,6 +6523,7 @@ lighting Light ライト
|
||||
@msg a 3D effect on a group's fill or stroke draws nothing グループの塗りまたは線にある 3D 効果は何も描画しません
|
||||
@msg a 3D effect on a group's fill or stroke draws nothing to export グループの塗りまたは線にある 3D 効果には書き出せる描画がありません
|
||||
@msg The 3D object is too complex to export 3D オブジェクトが複雑すぎるため書き出せません
|
||||
@msg The 3D object's mesh is incomplete or holds a value that is not a number 3D オブジェクトのメッシュが不完全か、数値でない値を含んでいます
|
||||
@msg the <filter> element needs an id, the filter's name <filter> 要素には id (フィルターの名前) が必要です
|
||||
@msg an SVG filter's id is at most {MAX_NAME} characters SVG フィルターの id は {MAX_NAME} 文字までです
|
||||
@msg <{_1}> isn't an element of an SVG filter <{_1}> は SVG フィルターの要素ではありません
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -8198,6 +8198,7 @@ arrowhead Feather ბუმბული
|
||||
@msg a 3D effect on a group's fill or stroke draws nothing ჯგუფის შევსებაზე ან კონტურზე 3D ეფექტი არაფერს ხატავს
|
||||
@msg a 3D effect on a group's fill or stroke draws nothing to export ჯგუფის შევსებაზე ან კონტურზე 3D ეფექტი ექსპორტისთვის არაფერს ხატავს
|
||||
@msg The 3D object is too complex to export 3D ობიექტი ზედმეტად რთულია ექსპორტისთვის
|
||||
@msg The 3D object's mesh is incomplete or holds a value that is not a number 3D ობიექტის ბადე არასრულია ან შეიცავს მნიშვნელობას, რომელიც რიცხვი არ არის
|
||||
@msg feConvolveMatrix's order feConvolveMatrix-ის order
|
||||
@msg feMorphology's radius feMorphology-ის radius
|
||||
@msg a blur's stdDeviation გაბუნდოვნების stdDeviation
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -6444,6 +6444,7 @@ lighting Light 광원
|
||||
@msg a 3D effect on a group's fill or stroke draws nothing 그룹의 칠이나 획에 있는 3D 효과는 아무것도 그리지 않습니다
|
||||
@msg a 3D effect on a group's fill or stroke draws nothing to export 그룹의 칠이나 획에 있는 3D 효과는 내보낼 것을 그리지 않습니다
|
||||
@msg The 3D object is too complex to export 3D 개체가 너무 복잡하여 내보낼 수 없습니다
|
||||
@msg The 3D object's mesh is incomplete or holds a value that is not a number 3D 개체의 메시가 불완전하거나 숫자가 아닌 값을 포함합니다
|
||||
@msg the <filter> element needs an id, the filter's name <filter> 요소에는 필터 이름인 id가 필요합니다
|
||||
@msg an SVG filter's id is at most {MAX_NAME} characters SVG 필터의 id는 최대 {MAX_NAME}자입니다
|
||||
@msg <{_1}> isn't an element of an SVG filter <{_1}>은(는) SVG 필터의 요소가 아닙니다
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -8608,6 +8608,7 @@ mark-style Japanese Japans
|
||||
@msg a 3D effect on a group's fill or stroke draws nothing een 3D-effect op de vulling of contour van een groep tekent niets
|
||||
@msg a 3D effect on a group's fill or stroke draws nothing to export een 3D-effect op de vulling of contour van een groep tekent niets om te exporteren
|
||||
@msg The 3D object is too complex to export Het 3D-object is te complex om te exporteren
|
||||
@msg The 3D object's mesh is incomplete or holds a value that is not a number Het net van het 3D-object is onvolledig of bevat een waarde die geen getal is
|
||||
@msg the <filter> element needs an id, the filter's name het <filter>-element heeft een id nodig, de naam van het filter
|
||||
@msg an SVG filter's id is at most {MAX_NAME} characters de id van een SVG-filter is hoogstens {MAX_NAME} tekens lang
|
||||
@msg <{_1}> isn't an element of an SVG filter <{_1}> is geen element van een SVG-filter
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -6686,6 +6686,7 @@ mark-style Japanese Japońskie
|
||||
@msg a 3D effect on a group's fill or stroke draws nothing efekt 3D na wypełnieniu lub obrysie grupy niczego nie rysuje
|
||||
@msg a 3D effect on a group's fill or stroke draws nothing to export efekt 3D na wypełnieniu lub obrysie grupy nie rysuje niczego do eksportu
|
||||
@msg The 3D object is too complex to export Obiekt 3D jest zbyt złożony, aby go wyeksportować
|
||||
@msg The 3D object's mesh is incomplete or holds a value that is not a number Siatka obiektu 3D jest niekompletna lub zawiera wartość, która nie jest liczbą
|
||||
@msg the <filter> element needs an id, the filter's name element <filter> wymaga id, czyli nazwy filtra
|
||||
@msg an SVG filter's id is at most {MAX_NAME} characters id filtra SVG ma najwyżej {MAX_NAME} znaków
|
||||
@msg <{_1}> isn't an element of an SVG filter <{_1}> nie jest elementem filtra SVG
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -6808,6 +6808,7 @@ mark-style Japanese Japonesas
|
||||
@msg a 3D effect on a group's fill or stroke draws nothing um efeito 3D no preenchimento ou traçado de um grupo não desenha nada
|
||||
@msg a 3D effect on a group's fill or stroke draws nothing to export um efeito 3D no preenchimento ou traçado de um grupo não desenha nada para exportar
|
||||
@msg The 3D object is too complex to export O objeto 3D é complexo demais para ser exportado
|
||||
@msg The 3D object's mesh is incomplete or holds a value that is not a number A malha do objeto 3D está incompleta ou contém um valor que não é um número
|
||||
@msg the <filter> element needs an id, the filter's name o elemento <filter> precisa de um id, o nome do filtro
|
||||
@msg an SVG filter's id is at most {MAX_NAME} characters o id de um filtro SVG tem no máximo {MAX_NAME} caracteres
|
||||
@msg <{_1}> isn't an element of an SVG filter <{_1}> não é um elemento de filtro SVG
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -6471,6 +6471,7 @@ lighting Light Свет
|
||||
@msg a 3D effect on a group's fill or stroke draws nothing 3D-эффект на заливке или обводке группы ничего не рисует
|
||||
@msg a 3D effect on a group's fill or stroke draws nothing to export 3D-эффект на заливке или обводке группы не рисует ничего для экспорта
|
||||
@msg The 3D object is too complex to export 3D-объект слишком сложен для экспорта
|
||||
@msg The 3D object's mesh is incomplete or holds a value that is not a number Сетка 3D-объекта неполна или содержит значение, которое не является числом
|
||||
@msg the <filter> element needs an id, the filter's name элементу <filter> нужен id, имя фильтра
|
||||
@msg an SVG filter's id is at most {MAX_NAME} characters id фильтра SVG содержит не более {MAX_NAME} символов
|
||||
@msg <{_1}> isn't an element of an SVG filter <{_1}> не является элементом фильтра SVG
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -6337,6 +6337,7 @@ lighting Light Ljus
|
||||
@msg a 3D effect on a group's fill or stroke draws nothing en 3D-effekt på en grupps fyllning eller linje ritar ingenting
|
||||
@msg a 3D effect on a group's fill or stroke draws nothing to export en 3D-effekt på en grupps fyllning eller linje ritar ingenting att exportera
|
||||
@msg The 3D object is too complex to export 3D-objektet är för komplext för att exporteras
|
||||
@msg The 3D object's mesh is incomplete or holds a value that is not a number 3D-objektets nät är ofullständigt eller innehåller ett värde som inte är ett tal
|
||||
@msg give one <filter> element ange ett <filter>-element
|
||||
@msg the <filter> element needs an id, the filter's name <filter>-elementet behöver ett id, filtrets namn
|
||||
@msg an SVG filter's id is at most {MAX_NAME} characters ett SVG-filters id har högst {MAX_NAME} tecken
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -6164,6 +6164,7 @@ lighting Light Işık
|
||||
@msg a 3D effect on a group's fill or stroke draws nothing bir grubun dolgusundaki veya konturundaki 3 boyutlu efekt hiçbir şey çizmez
|
||||
@msg a 3D effect on a group's fill or stroke draws nothing to export bir grubun dolgusundaki veya konturundaki 3 boyutlu efekt dışa aktarılacak hiçbir şey çizmez
|
||||
@msg The 3D object is too complex to export 3 boyutlu nesne dışa aktarmak için çok karmaşık
|
||||
@msg The 3D object's mesh is incomplete or holds a value that is not a number 3 boyutlu nesnenin ağı eksik veya sayı olmayan bir değer içeriyor
|
||||
@msg the <filter> element needs an id, the filter's name <filter> öğesinin, filtrenin adı olan bir id değeri olmalıdır
|
||||
@msg an SVG filter's id is at most {MAX_NAME} characters bir SVG filtresinin id değeri en fazla {MAX_NAME} karakterdir
|
||||
@msg <{_1}> isn't an element of an SVG filter <{_1}> bir SVG filtresi öğesi değildir
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -6454,6 +6454,7 @@ lighting Light Світло
|
||||
@msg a 3D effect on a group's fill or stroke draws nothing 3D-ефект на заливці або обведенні групи нічого не малює
|
||||
@msg a 3D effect on a group's fill or stroke draws nothing to export 3D-ефект на заливці або обведенні групи не малює нічого для експорту
|
||||
@msg The 3D object is too complex to export 3D-об’єкт надто складний для експорту
|
||||
@msg The 3D object's mesh is incomplete or holds a value that is not a number Сітка 3D-об’єкта неповна або містить значення, яке не є числом
|
||||
@msg the <filter> element needs an id, the filter's name елементу <filter> потрібен id, назва фільтра
|
||||
@msg an SVG filter's id is at most {MAX_NAME} characters id фільтра SVG містить не більше {MAX_NAME} символів
|
||||
@msg <{_1}> isn't an element of an SVG filter <{_1}> не є елементом фільтра SVG
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -6205,6 +6205,7 @@ liquify-list-end {0}, {1} {0} và {1}
|
||||
@msg a 3D effect on a group's fill or stroke draws nothing hiệu ứng 3D trên phần tô hoặc nét của nhóm không vẽ gì
|
||||
@msg a 3D effect on a group's fill or stroke draws nothing to export hiệu ứng 3D trên phần tô hoặc nét của nhóm không vẽ gì để xuất
|
||||
@msg The 3D object is too complex to export Đối tượng 3D quá phức tạp để xuất
|
||||
@msg The 3D object's mesh is incomplete or holds a value that is not a number Lưới của đối tượng 3D chưa đầy đủ hoặc chứa giá trị không phải là số
|
||||
@msg give one <filter> element hãy chỉ định một phần tử <filter>
|
||||
@msg the <filter> element needs an id, the filter's name phần tử <filter> cần có id, là tên của bộ lọc
|
||||
@msg an SVG filter's id is at most {MAX_NAME} characters id của bộ lọc SVG có tối đa {MAX_NAME} ký tự
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -6723,6 +6723,7 @@ lighting Light 光源
|
||||
@msg a 3D effect on a group's fill or stroke draws nothing 编组填色或描边上的 3D 效果不绘制任何内容
|
||||
@msg a 3D effect on a group's fill or stroke draws nothing to export 编组填色或描边上的 3D 效果没有可导出的内容
|
||||
@msg The 3D object is too complex to export 3D 对象过于复杂,无法导出
|
||||
@msg The 3D object's mesh is incomplete or holds a value that is not a number 3D 对象的网格不完整,或含有非数字的值
|
||||
@msg the <filter> element needs an id, the filter's name <filter> 元素需要 id,即滤镜的名称
|
||||
@msg an SVG filter's id is at most {MAX_NAME} characters SVG 滤镜的 id 最多 {MAX_NAME} 个字符
|
||||
@msg <{_1}> isn't an element of an SVG filter <{_1}> 不是 SVG 滤镜的元素
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -6572,6 +6572,7 @@ lighting Light 光源
|
||||
@msg a 3D effect on a group's fill or stroke draws nothing 群組填色或筆畫上的 3D 效果不會繪製任何內容
|
||||
@msg a 3D effect on a group's fill or stroke draws nothing to export 群組填色或筆畫上的 3D 效果沒有可匯出的內容
|
||||
@msg The 3D object is too complex to export 3D 物件過於複雜,無法匯出
|
||||
@msg The 3D object's mesh is incomplete or holds a value that is not a number 3D 物件的網格不完整,或含有非數字的值
|
||||
@msg the <filter> element needs an id, the filter's name <filter> 元素需要 id,也就是濾鏡的名稱
|
||||
@msg an SVG filter's id is at most {MAX_NAME} characters SVG 濾鏡的 id 最多 {MAX_NAME} 個字元
|
||||
@msg <{_1}> isn't an element of an SVG filter <{_1}> 不是 SVG 濾鏡的元素
|
||||
|
||||
|
Can't render this file because it is too large.
|
@@ -183,7 +183,7 @@ VectorCraft choices; an original approximation, never compared with another appl
|
||||
| Materials panel, lighting, ray-traced render | Window › 3D and Materials panel with the object types (Plane, Extrude, Revolve, Inflate) and the Object, Rotation and Lighting settings of the applied effect, Render Settings › Wireframe, which draws the live effect as the edges of its faces, and Quick Actions › Expand as Wireframes ([three-d.md](three-d.md#3d-and-materials-panel)); one to ten directional lights with per-light Color (opaque RGB, white by default), Intensity, Rotation, Height, Softness and neutral Ambient Light, Revolve and colored Inflate use smooth vector shading; Extrude & Bevel and Rotate retain planar shading; original Standard, Diffuse, Top Left and Right lighting rigs; shadows behind or below the object from the first light, blurred by its Softness ([three-d.md](three-d.md#shadows)); the Materials tab's Graphics, document symbols mapped onto Extrude & Bevel's caps and onto a plane, moved with an artboard handle, and wrapped around Extrude & Bevel's walls and bevels and around Revolve's side ([three-d.md](three-d.md#graphics)); no base materials, graphics on Inflate, or ray tracing |
|
||||
| 3D (Classic): Extrude & Bevel, Revolve, Rotate | Extrude & Bevel (Classic) initial: live, round seam joins, Extrude Depth, Cap, five original bevel shapes and the custom bevels with Height and Bevel Extent In or Out, Position presets and rotation gizmo, Perspective, Wireframe, No Shading, Diffuse and Plastic surfaces with one to ten lights, Light Intensity, Ambient Light, Highlight Intensity and Size, Blend Steps, Black, Custom, Black Overprint or no Shading Color ([Black Overprint](https://web.archive.org/web/20210601162814/https://helpx.adobe.com/pdf/illustrator_reference.pdf#page=188)), Draw Hidden Faces ([create 3D objects](https://helpx.adobe.com/illustrator/desktop/special-effects-styles/create-3d-graphics/create-3d-objects.html)); Revolve (Classic) initial: live, round seam joins, Angle, Cap, Offset from the left or right edge, Position presets and rotation gizmo, Perspective, the same four surfaces, lights, highlight, Blend Steps and Shading Color, groups and layers revolved about one shared axis (same page); Rotate (Classic) initial: live, round seam joins, every fill and stroke turned as one plane, Position presets and rotation gizmo, Perspective, No Shading and Diffuse surfaces with lights, Ambient Light, Blend Steps and Shading Color ([rotate objects in 3D](https://helpx.adobe.com/illustrator/desktop/special-effects-styles/create-3d-graphics/rotate-objects-in-3d.html)); Preserve Spot Colors in all three, unavailable with a Custom Shading Color ([Preserve Spot Color](https://help.adobe.com/archive/en_US/illustrator/cs5/illustrator_cs5_help.pdf#page=260)); all three: a lighting sphere on the Lighting tab whose lights drag, move to the back or front, and are added at the front center or deleted down to one ([lighting options](https://help.adobe.com/archive/en_US/illustrator/cs5/illustrator_cs5_help.pdf#page=272)); all three: the track cube (face, edge, Shift and ring drags, keyboard steps; [three-d.md](three-d.md#track-cube)); Map Art for Extrude & Bevel (Classic) and Revolve (Classic): one document symbol on each numbered surface, surface navigation with visible and hidden marks and a red outline on the artboard, move, scale and rotate on the surface laid out flat, Scale to Fit, Clear, Clear All, Shade Artwork, Invisible Geometry, kept by Expand Appearance and exports, `threeD.mapArt` ([map artwork to a 3D object](https://web.archive.org/web/20210601162814/https://helpx.adobe.com/pdf/illustrator_reference.pdf#page=189)) |
|
||||
| Turntable (30.0 beta) | none |
|
||||
| Export 3D objects (OBJ, USDA, glTF) | initial: Asset Export's Export 3D Object, and the 3D and Materials panel's Export 3D Object button (which then shows Asset Export with the new assets selected, [three-d.md](three-d.md#3d-and-materials-panel)), collect an object with Extrude & Bevel, Revolve, Inflate or Rotate as a 3D asset, and Export writes its solids as a USDA (the default), USDZ, glTF or OBJ mesh with a material in each solid's paint color (`assets.add3D`, `assets.set3DFormat`, `assets.export3D`); graphics mapped onto a plane or Extrude & Bevel's caps are exported as PNG textures of those faces, flat and unlit; no graphics on Revolve's side, no materials and no shading ([3D export help](https://helpx.adobe.com/illustrator/desktop/special-effects-styles/create-3d-graphics/export-3d-vector-artwork.html)) |
|
||||
| Export 3D objects (OBJ, USDA, glTF) | initial: Asset Export's Export 3D Object, and the 3D and Materials panel's Export 3D Object button (which then shows Asset Export with the new assets selected, [three-d.md](three-d.md#3d-and-materials-panel)), collect an object with Extrude & Bevel, Revolve, Inflate or Rotate as a 3D asset, and Export writes its solids as a USDA (the default), USDZ, glTF or OBJ mesh with a material in each solid's paint color (`assets.add3D`, `assets.set3DFormat`, `assets.export3D`); graphics mapped onto a plane or Extrude & Bevel's caps are exported as PNG textures of those faces, flat and unlit, and the graphics on Revolve's side as a texture of the side unrolled; every corner carries texture coordinates and a normal, smoothed across a curved bevel and over Inflate's puff ([three-d.md](three-d.md#3d-meshes)); no materials and no lighting ([3D export help](https://helpx.adobe.com/illustrator/desktop/special-effects-styles/create-3d-graphics/export-3d-vector-artwork.html)) |
|
||||
|
||||
The `three-d` crate (depends on `geom` and `pathops`, with no UI or GPU dependencies) builds, rotates, projects, shades and depth-sorts the surfaces;
|
||||
the effects crate turns them into art. What's left (materials and shadows, ray-traced rendering,
|
||||
|
||||
+7
-1
@@ -10678,7 +10678,13 @@ fill's, each stroke's, a group's members') is its own mesh, with a two-sided mat
|
||||
(a gradient's stops averaged, a pattern gray); a solid with mapped graphics is split into a textured mesh for each face
|
||||
that carries them and a plain mesh for the rest, as described below. The mesh holds the solid's faces before they are projected onto the
|
||||
page, those turned away from the viewer included, at the object's 3D rotation, y up, about the point the object turns
|
||||
about: in points (USD's layer gives `metersPerUnit`), in meters in glTF. Files that would share a name get `-2`, `-3` and so on.
|
||||
about: in points (USD's layer gives `metersPerUnit`), in meters in glTF. Each corner's normal is its face's, except
|
||||
where two bands of one bevel meet at a turn of less than 60° (neither band lying flat toward the front or back) and on
|
||||
Inflate's puffed front and back: there the normals are smoothed, and an app that reads them shades a rounded bevel or a
|
||||
puff without facets ([three-d.md](three-d.md#3d-meshes)). Every corner also has texture coordinates from 0 to 1
|
||||
(`vt`, `TEXCOORD_0`, `primvars:st`), laid out for each kind of face as three-d.md describes. A mesh whose lists do not
|
||||
match, or that holds a value that is not a number, stops the export with "The 3D object's mesh is incomplete or holds a
|
||||
value that is not a number", and nothing is written. Files that would share a name get `-2`, `-3` and so on.
|
||||
Graphics mapped onto a plane or onto Extrude & Bevel's front or back cap (`threeD.mapGraphic`) are exported as a PNG
|
||||
texture of that face: the face's color with its graphics drawn over it, flat and unlit, on a mesh of the face's own
|
||||
triangles with texture coordinates and a material that shows the texture. A face that is not opaque keeps its opacity
|
||||
|
||||
@@ -1690,6 +1690,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
|
||||
- Extrude & Bevel (both kinds) and Rotate keep the art's curves in the faces they draw, export and expand: caps and the edges of walls and bevels where they meet a cap are cubics with smooth anchors where the art's are, fitted within 0.001 pt in perspective and within the sampling tolerance on a bevel's inset. An edge of a twisted wall that is cut into pieces, a piece of curve that does not fit after 8 halvings, and the curves past 1,048,576 for one solid stay straight (VectorCraft's own values; [three-d.md](three-d.md#what-differs-from-the-public-documentation)). Tests `solid::tests::a_cap_keeps_the_curves_of_the_art`, `a_cap_in_perspective_fits_the_projected_curves`, `a_beveled_cap_and_its_walls_share_their_curves`, `twisted_beveled_tiny_and_degenerate_caps_keep_their_curves`.
|
||||
- Export 3D Object (Asset Export's menu): an object with Extrude & Bevel, Revolve, Inflate or Rotate becomes a 3D asset whose Format is USDA (the default), USDZ, glTF or OBJ, and Export writes each of its solids as a mesh with a material in its paint's color (`assets.add3D`, `assets.set3DFormat`, `assets.export3D`; [export 3D vector artwork](https://helpx.adobe.com/illustrator/desktop/special-effects-styles/create-3d-graphics/export-3d-vector-artwork.html)).
|
||||
- Export 3D Object builds each Extrude & Bevel (both kinds) and Inflate solid once: the same build gives the faces that count toward the object's limit and the faces of its mesh, and the meshes match those of a separate build bit for bit. Tests `mesh::tests::a_meshed_solid_is_built_once`, `an_extruded_solid_and_its_mesh_match_the_two_built_apart`, `inflated_solids_and_their_meshes_match_the_two_built_apart`, `solids::tests_mesh::one_build_exports_the_meshes_built_apart`, `a_stroke_past_the_limits_is_left_out_of_the_export`.
|
||||
- The meshes of Extrude & Bevel, Inflate, Rotate and Revolve carry texture coordinates for every corner, normals smoothed across the bands of a curved bevel (a turn of 60° or more stays a hard edge, VectorCraft's own value) and over Inflate's puff, and a part for each triangle (front, back, side, front bevel, back bevel, end cap, cut side); exported OBJ, glTF and USD files write the new normals and every corner's texture coordinates, refuse a mesh whose lists do not match or hold a value that is not a number, and the vector facets stay the same bit for bit ([three-d.md](three-d.md#3d-meshes)). Tests `mesh::tests_attributes::every_corner_has_texture_coordinates_and_every_triangle_a_part`, `a_rounded_or_custom_bevels_normals_turn_smoothly_across_its_bands`, `a_steps_sharp_turns_and_a_classic_bevel_stay_hard_edges`, `the_meshs_outline_stays_within_a_twentieth_of_a_point_of_the_vector_facets`, `mesh3d::tests::a_mesh_whose_lists_do_not_match_or_hold_no_number_is_refused`.
|
||||
- Export 3D Object writes the graphics mapped onto a plane or onto Extrude & Bevel's front and back caps as a PNG texture of each face, the face's color with its graphics drawn flat and unlit over it, on a mesh of that face with texture coordinates, in all four formats (glTF embeds it, USDZ packs it after the layer, OBJ and USDA write `<name>-texture-1.png` beside them; `assets.export3D` `textureSize`, 128 to 4096 pixels, default 1024, VectorCraft's own values; [the help page](https://helpx.adobe.com/illustrator/desktop/special-effects-styles/create-3d-graphics/map-artwork-on-3d-objects.html)). The graphics wrapped around Revolve's side export the same way, as a texture of the side unrolled as the canvas lays it out, on a mesh of the side's triangles, with its end caps and cut sides plain. Materials and lighting are not exported. Tests `a_caps_mesh_corners_go_back_to_the_art_they_were_made_from`, `a_mesh_carries_its_caps_graphics_flat_in_the_arts_plane`, `each_format_carries_a_textured_part_with_its_coordinates_and_picture`, `export_3d_paints_mapped_graphics_on_their_caps_in_every_format`, `a_revolved_sides_corners_lie_where_the_canvas_places_the_unrolled_side`, `a_revolved_sides_layout_matches_its_drawn_faces_at_every_turn`, `export_3d_paints_graphics_mapped_onto_a_revolves_side_in_every_format`, `a_partial_revolve_keeps_its_cut_sides_plain_beside_its_textured_side`.
|
||||
- The 3D and Materials panel works out whether Export 3D Object is available once for each document revision and reuses it on later frames. The button shows the same state. With 200,000 paths selected, working it out on every frame took a median 61.6 ms of thread CPU time per frame in a release build on Linux (57.1 ms with a path of a compound path with Extrude & Bevel selected last); the first frame after a change still takes about as long, and later frames take about 2 ns (`panels::three_d::tests::export_3d_object_state_kept_for_a_revision_equals_a_fresh_one`, `export_3d_object_state_is_worked_out_once_per_revision`, `export_3d_object_state_timing`).
|
||||
- Checking an Extrude & Bevel (both kinds) or Inflate effect builds each solid the effect draws once, about the bounds the effect draws it about; a shape with no fill still has its profile built on its own. Tests `solids::tests::the_check_builds_each_drawn_solid_once`, `the_check_builds_the_profile_of_a_shape_with_no_fill`.
|
||||
|
||||
@@ -95,6 +95,37 @@ pages describe it.
|
||||
rotation and light rings on the artboard are part of the options dialog only. The panel's Lighting tab has the
|
||||
lighting widget instead ([Lighting widget](#lighting-widget)).
|
||||
|
||||
## 3D meshes
|
||||
|
||||
The meshes that Export 3D Object writes come from the `three-d` crate's `Mesh`, built from the same faces the effect
|
||||
draws. The vector facets on the canvas and in SVG and PDF do not change with what follows. Besides positions,
|
||||
normals and triangles, a mesh carries:
|
||||
|
||||
- **Normals.** A corner takes its face's normal. Where two bands of one bevel meet, the shared corners take the mean of
|
||||
the two bands' normals, unless the bevel turns there by 60° or more (a Step profile's turns) or one of the bands lies
|
||||
flat toward the front or back; caps, walls and the edges between a bevel and a cap or wall stay hard. On Inflate's
|
||||
puffed front and back each corner takes the surface's own normal. The bevel settings shape its profile into a
|
||||
rounded curve or an ornamental one ([the help page](https://helpx.adobe.com/illustrator/desktop/special-effects-styles/create-3d-graphics/3d-materials-panel-options.html));
|
||||
the smoothing rule and the 60° crease are VectorCraft's own.
|
||||
- **Texture coordinates** for every corner, each from 0 to 1, u to the right and v down, as glTF 2.0 places
|
||||
`TEXCOORD_0` (<https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html>). Caps, Rotate's plane and Inflate's
|
||||
front and back take each corner's art point, before any twist or taper, in the art's bounds; the back is not
|
||||
mirrored. Extrude & Bevel's bevels and walls and Inflate's walls take u along each contour of the outline from its
|
||||
first point, as the distance over the contour's length, so the seam at the first point has corners at both 0 and 1,
|
||||
and v across the side from the front cap's edge to the back cap's. Revolve's side takes u around the sweep from its
|
||||
start and v along each contour of the profile; its end caps span the disk they close, and its cut sides take each
|
||||
corner's profile point in the profile's bounds. An axis with no extent takes 0.5. These layouts are VectorCraft's
|
||||
own.
|
||||
- **A part for each triangle**: `Front` (a front cap, Rotate's plane, Inflate's front), `Back`, `Side` (walls and
|
||||
Revolve's swept side), `FrontBevel`, `BackBevel`, `Cap` (Revolve's end caps) and `Cut` (the flat sides of a Revolve
|
||||
of less than 360°).
|
||||
|
||||
The exported files write the normals and the texture coordinates of every corner: OBJ's `vt` (up from the bottom),
|
||||
glTF's `TEXCOORD_0` and USD's `primvars:st` (up from the bottom). A face with mapped graphics writes the coordinates
|
||||
of its texture instead, laid out as the graphics are ([Graphics](#graphics)). The files do not write the parts. A
|
||||
mesh whose lists do not match, or that holds a value that is not a number, stops the export with an error before any
|
||||
file is written.
|
||||
|
||||
## Extrude & Bevel
|
||||
|
||||
The art is the front face; its outline is extruded backwards by **Depth** (0–2,000 pt), so seen straight on the
|
||||
|
||||
Reference in new issue
Block a user