poppygl 0.0.15 → 0.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -156,6 +156,7 @@ declare class SoftwareRenderer {
156
156
  */
157
157
  declare function drawInfiniteGrid(software_renderer: SoftwareRenderer, params: {
158
158
  camera: Camera;
159
+ grid_y?: number;
159
160
  cell_size?: number;
160
161
  section_size?: number;
161
162
  fade_distance?: number;
package/dist/index.js CHANGED
@@ -630,6 +630,7 @@ function computeGridFadeAlpha(params) {
630
630
  );
631
631
  }
632
632
  function drawInfiniteGrid(software_renderer, params) {
633
+ const grid_y = params.grid_y ?? 0;
633
634
  const cell_size = params.cell_size ?? 1;
634
635
  const section_size = params.section_size ?? 10;
635
636
  const fade_distance = params.fade_distance ?? 100;
@@ -667,13 +668,21 @@ function drawInfiniteGrid(software_renderer, params) {
667
668
  const ray_dir_y = far_point[1] - near_point[1];
668
669
  const ray_dir_z = far_point[2] - near_point[2];
669
670
  if (Math.abs(ray_dir_y) < 1e-6) continue;
670
- const t = -near_point[1] / ray_dir_y;
671
+ const t = (grid_y - near_point[1]) / ray_dir_y;
671
672
  if (t < 0 || t > 1) continue;
672
673
  const world_x = near_point[0] + t * ray_dir_x;
673
674
  const world_z = near_point[2] + t * ray_dir_z;
675
+ const world_pt = vec43.fromValues(world_x, grid_y, world_z, 1);
676
+ const clip_pt = vec43.create();
677
+ vec43.transformMat4(clip_pt, world_pt, vp);
678
+ const ndc_z = clip_pt[2] / clip_pt[3];
679
+ const depth_01 = ndc_z * 0.5 + 0.5;
680
+ const di = y * software_renderer.width + x;
681
+ if (depth_01 >= software_renderer.depth[di]) continue;
674
682
  const dx = world_x - cam_pos_x;
683
+ const dy = grid_y - cam_pos_y;
675
684
  const dz = world_z - cam_pos_z;
676
- const dist = Math.sqrt(dx * dx + dz * dz);
685
+ const dist = Math.sqrt(dx * dx + dy * dy + dz * dz);
677
686
  const alpha = computeGridFadeAlpha({
678
687
  dist,
679
688
  fade_distance,
@@ -824,9 +833,15 @@ function renderDrawCalls(drawCalls, optionsInput = {}, imageFactory = createUint
824
833
  }
825
834
  }
826
835
  };
836
+ renderGroup(opaqueDraws);
837
+ renderGroup(maskDraws);
827
838
  if (infiniteGridOptions) {
839
+ const aabb = computeWorldAABB(drawCalls);
840
+ const modelCenterY = (aabb.min[1] + aabb.max[1]) / 2;
841
+ const gridY = infiniteGridOptions.offset?.y ?? modelCenterY;
828
842
  drawInfiniteGrid(renderer, {
829
843
  camera,
844
+ grid_y: gridY,
830
845
  cell_size: infiniteGridOptions.cellSize,
831
846
  section_size: infiniteGridOptions.sectionSize,
832
847
  fade_distance: infiniteGridOptions.fadeDistance,
@@ -836,8 +851,6 @@ function renderDrawCalls(drawCalls, optionsInput = {}, imageFactory = createUint
836
851
  gamma_out: options.gamma
837
852
  });
838
853
  }
839
- renderGroup(opaqueDraws);
840
- renderGroup(maskDraws);
841
854
  renderGroup(blendDraws);
842
855
  return { bitmap: renderer.bitmap, camera, options };
843
856
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "poppygl",
3
3
  "main": "dist/index.js",
4
- "version": "0.0.15",
4
+ "version": "0.0.16",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/tscircuit/poppygl.git"