Skip to content

Commit

Permalink
Add missing docs and improve naming
Browse files Browse the repository at this point in the history
  • Loading branch information
remcoder committed Jan 27, 2025
1 parent 84f1064 commit 954be85
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions src/webgl-preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,14 +441,33 @@ export class WebGLPreview {
this.updateLineClipping(minZ, maxZ);
}


/**
* Updates the clipping planes for all shader materials in the scene.
* This method sets the min and max Z values for the clipping planes in the shader materials.
*
* @param minZ - The minimum Z value for the clipping plane.
* @param maxZ - The maximum Z value for the clipping plane
*/

private updateClippingPlanesForShaderMaterials(minZ: number, maxZ: number) {
this.materials.forEach((material) => {
material.uniforms.clipMinY.value = minZ;
material.uniforms.clipMaxY.value = maxZ;
});
}

private applyClippingPlanes(material: Material, minZ: number, maxZ: number) {
/**
* Applies clipping planes to the specified material based on the minimum and maximum Z values.
*
* This method creates clipping planes for the top and bottom of the specified Z range,
* then applies them to the material's clippingPlanes property.
*
* @param material - Shader material to apply clipping planes to
* @param minZ - The minimum Z value for the clipping plane.
* @param maxZ - The maximum Z value for the clipping plane.
*/
private applyMinMaxClippingPlanes(material: Material, minZ: number, maxZ: number) {
material.clippingPlanes = [new Plane(new Vector3(0, 1, 0), -minZ), new Plane(new Vector3(0, -1, 0), maxZ)];
}

Expand All @@ -464,7 +483,7 @@ export class WebGLPreview {
this.scene.traverse((obj) => {
if (obj instanceof LineSegments2) {
const material = obj.material as LineMaterial;
this.applyClippingPlanes(material, minZ, maxZ);
this.applyMinMaxClippingPlanes(material, minZ, maxZ);
}
});
}
Expand Down Expand Up @@ -806,7 +825,7 @@ export class WebGLPreview {
linewidth: this.lineWidth
});

this.applyClippingPlanes(material, minZ, maxZ);
this.applyMinMaxClippingPlanes(material, minZ, maxZ);

const lineVertices: number[] = [];

Expand Down

0 comments on commit 954be85

Please # to comment.