(bgeo: &BgeoFile, mut writer: W2)
| 171 | enable_compression: bool, |
| 172 | ) -> Result<(), anyhow::Error> { |
| 173 | fn write_bgeo<W2: io::Write>(bgeo: &BgeoFile, mut writer: W2) -> Result<(), anyhow::Error> { |
| 174 | writer.write_all(&bgeo.header.magic_bytes)?; |
| 175 | writer.write_all(&bgeo.header.version_char.to_be_bytes())?; |
| 176 | writer.write_all(&bgeo.header.version.to_be_bytes())?; |
| 177 | |
| 178 | writer.write_all(&bgeo.header.num_points.to_be_bytes())?; |
| 179 | writer.write_all(&bgeo.header.num_prims.to_be_bytes())?; |
| 180 | writer.write_all(&bgeo.header.num_point_groups.to_be_bytes())?; |
| 181 | writer.write_all(&bgeo.header.num_prim_groups.to_be_bytes())?; |
| 182 | writer.write_all(&bgeo.header.num_point_attrib.to_be_bytes())?; |
| 183 | writer.write_all(&bgeo.header.num_vertex_attrib.to_be_bytes())?; |
| 184 | writer.write_all(&bgeo.header.num_prim_attrib.to_be_bytes())?; |
| 185 | writer.write_all(&bgeo.header.num_attrib.to_be_bytes())?; |
| 186 | |
| 187 | // Write attribute definitions |
| 188 | for attrib in &bgeo.attribute_definitions { |
| 189 | writer.write_all(&(attrib.name.len() as u16).to_be_bytes())?; |
| 190 | writer.write_all(attrib.name.as_bytes())?; |
| 191 | writer.write_all(&(attrib.size as u16).to_be_bytes())?; |
| 192 | writer.write_all(&(attrib.attr_type.to_i32()).to_be_bytes())?; |
| 193 | for &default_val in &attrib.default_values { |
| 194 | writer.write_all(&(default_val.to_be_bytes()))?; |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | let special_attribs = [&bgeo.positions, &bgeo.weights]; |
| 199 | let attrib_iter = || { |
| 200 | special_attribs |
| 201 | .iter() |
| 202 | .copied() |
| 203 | .chain(bgeo.attribute_data.iter().map(|(_, s)| s)) |
| 204 | }; |
| 205 | |
| 206 | let num_points = attrib_iter().map(|s| s.num_points()).max().unwrap(); |
| 207 | for i in 0..num_points { |
| 208 | for attrib in attrib_iter() { |
| 209 | // TODO: Use default values |
| 210 | match attrib { |
| 211 | AttributeStorage::Int(v) => { |
| 212 | writer.write_all(&(v[i].to_be_bytes()))?; |
| 213 | } |
| 214 | AttributeStorage::Float(v) => { |
| 215 | writer.write_all(&(v[i].to_be_bytes()))?; |
| 216 | } |
| 217 | AttributeStorage::Vector(n, v) => { |
| 218 | for j in 0..*n { |
| 219 | writer.write_all(&(v[i * n + j].to_be_bytes()))?; |
| 220 | } |
| 221 | } |
| 222 | } |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | // End bytes |
| 227 | writer.write_all(&0x00_u8.to_be_bytes())?; |
| 228 | writer.write_all(&0xff_u8.to_be_bytes())?; |
| 229 | |
| 230 | Ok(()) |
no test coverage detected