Skip to content

Commit

Permalink
add clip_triangles() to SkeletonClipping, and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jabuwu committed Feb 15, 2023
1 parent 57e42d1 commit 655f084
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 25 deletions.
18 changes: 5 additions & 13 deletions src/draw/combined.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use crate::{
c::{c_void, spSkeletonClipping_clipTriangles},
BlendMode, Color, Skeleton, SkeletonClipping,
};
use crate::{c::c_void, BlendMode, Color, Skeleton, SkeletonClipping};

use super::{ColorSpace, CullDirection};

Expand Down Expand Up @@ -315,17 +312,12 @@ impl CombinedDrawer {
indices[i as usize] -= vertex_base;
}
unsafe {
spSkeletonClipping_clipTriangles(
clipper.c_ptr(),
&mut vertices[vertex_base as usize] as *mut f32,
vertices.len() as i32 - vertex_base as i32,
&mut indices[index_base as usize],
indices.len() as i32 - index_base as i32,
&mut uvs[vertex_base as usize] as *mut f32,
clipper.clip_triangles(
vertices.as_mut_slice(),
indices.as_mut_slice(),
uvs.as_mut_slice(),
2,
);
}
unsafe {
let clipped_triangles_size =
(*clipper.c_ptr_ref().clippedTriangles).size as usize;
let clipped_vertices_size =
Expand Down
15 changes: 5 additions & 10 deletions src/draw/simple.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
c::{c_void, spMeshAttachment_updateRegion, spSkeletonClipping_clipTriangles},
c::{c_void, spMeshAttachment_updateRegion},
BlendMode, Color, Skeleton, SkeletonClipping,
};

Expand Down Expand Up @@ -206,17 +206,12 @@ impl SimpleDrawer {
if let Some(clipper) = clipper.as_deref_mut() {
if clipper.is_clipping() {
unsafe {
spSkeletonClipping_clipTriangles(
clipper.c_ptr(),
vertices.as_mut_ptr() as *mut f32,
vertices.len() as i32,
indices.as_mut_ptr(),
indices.len() as i32,
uvs.as_mut_ptr() as *mut f32,
clipper.clip_triangles(
vertices.as_mut_slice(),
indices.as_mut_slice(),
uvs.as_mut_slice(),
2,
);
}
unsafe {
let clipped_vertices_size =
(*clipper.c_ptr_ref().clippedVertices).size as usize;
vertices.resize(clipped_vertices_size / 2, [0., 0.]);
Expand Down
29 changes: 27 additions & 2 deletions src/skeleton_clipping.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
use crate::{
c::{
spClippingAttachment, spSkeletonClipping, spSkeletonClipping_clipEnd,
spSkeletonClipping_clipEnd2, spSkeletonClipping_clipStart, spSkeletonClipping_create,
spSkeletonClipping_dispose, spSkeletonClipping_isClipping,
spSkeletonClipping_clipEnd2, spSkeletonClipping_clipStart,
spSkeletonClipping_clipTriangles, spSkeletonClipping_create, spSkeletonClipping_dispose,
spSkeletonClipping_isClipping,
},
c_interface::SyncPtr,
clipping_attachment::ClippingAttachment,
slot::Slot,
};

#[cfg(doc)]
use crate::draw::SimpleDrawer;

/// Active state for [`ClippingAttachment`] during mesh generation.
///
/// For example usage, see the [`SimpleDrawer::draw`] implementation.
#[derive(Debug)]
pub struct SkeletonClipping {
c_skeleton_clipping: SyncPtr<spSkeletonClipping>,
Expand Down Expand Up @@ -55,6 +62,24 @@ impl SkeletonClipping {
unsafe { spSkeletonClipping_isClipping(self.c_ptr_mut()) != 0 }
}

pub unsafe fn clip_triangles(
&self,
vertices: &mut [[f32; 2]],
triangles: &mut [u16],
uvs: &mut [[f32; 2]],
stride: i32,
) {
spSkeletonClipping_clipTriangles(
self.c_ptr(),
vertices.as_mut_ptr() as *mut f32,
vertices.len() as i32,
triangles.as_mut_ptr(),
triangles.len() as i32,
uvs.as_mut_ptr() as *mut f32,
stride,
);
}

c_ptr!(c_skeleton_clipping, spSkeletonClipping);
/*spTriangulator *triangulator;
spFloatArray *clippingPolygon;
Expand Down

0 comments on commit 655f084

Please sign in to comment.