从 SoA 数据添加精灵(与现有 API 兼容) Add sprites from SoA data (compatible with existing API). # Parameters - `transforms`: [x, y, rotation, scaleX, scaleY, originX, originY] per sprite - `texture_ids`: 纹理 ID | Texture IDs - `uvs`: [u0, v0, u1, v1] per sprite - `colors`: 打包的 RGBA 颜色 | Packed RGBA colors - `material_ids`: 材质 ID | Material IDs - `texture_sizes`: 纹理尺寸映射函数 | Texture size lookup function
(
&mut self,
transforms: &[f32],
texture_ids: &[u32],
uvs: &[f32],
colors: &[u32],
material_ids: &[u32],
texture_sizes: F,
)
| 232 | /// - `material_ids`: 材质 ID | Material IDs |
| 233 | /// - `texture_sizes`: 纹理尺寸映射函数 | Texture size lookup function |
| 234 | pub fn add_sprites_soa<F>( |
| 235 | &mut self, |
| 236 | transforms: &[f32], |
| 237 | texture_ids: &[u32], |
| 238 | uvs: &[f32], |
| 239 | colors: &[u32], |
| 240 | material_ids: &[u32], |
| 241 | texture_sizes: F, |
| 242 | ) -> usize |
| 243 | where |
| 244 | F: Fn(u32) -> (f32, f32), |
| 245 | { |
| 246 | let count = texture_ids.len(); |
| 247 | let mut added = 0; |
| 248 | |
| 249 | for i in 0..count { |
| 250 | let t_offset = i * 7; |
| 251 | let uv_offset = i * 4; |
| 252 | |
| 253 | if t_offset + 6 >= transforms.len() || uv_offset + 3 >= uvs.len() { |
| 254 | break; |
| 255 | } |
| 256 | |
| 257 | let x = transforms[t_offset]; |
| 258 | let y = transforms[t_offset + 1]; |
| 259 | let rotation = transforms[t_offset + 2]; |
| 260 | let scale_x = transforms[t_offset + 3]; |
| 261 | let scale_y = transforms[t_offset + 4]; |
| 262 | let origin_x = transforms[t_offset + 5]; |
| 263 | let origin_y = transforms[t_offset + 6]; |
| 264 | |
| 265 | let texture_id = texture_ids[i]; |
| 266 | let (tex_width, tex_height) = texture_sizes(texture_id); |
| 267 | |
| 268 | let width = tex_width * scale_x; |
| 269 | let height = tex_height * scale_y; |
| 270 | |
| 271 | let u0 = uvs[uv_offset]; |
| 272 | let v0 = uvs[uv_offset + 1]; |
| 273 | let u1 = uvs[uv_offset + 2]; |
| 274 | let v1 = uvs[uv_offset + 3]; |
| 275 | |
| 276 | let color = colors[i]; |
| 277 | let material_id = material_ids[i]; |
| 278 | |
| 279 | if self.add_sprite( |
| 280 | x, y, width, height, rotation, origin_x, origin_y, |
| 281 | u0, v0, u1, v1, color, texture_id, material_id, |
| 282 | ) { |
| 283 | added += 1; |
| 284 | } else { |
| 285 | break; |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | added |
| 290 | } |
| 291 |
nothing calls this directly
no test coverage detected