Skip to content

Enhance ArrayUtils.reconstruct with Flat Output Support#23

Merged
afshawnlotfi merged 1 commit intomainfrom
feature/ts-multi-dim-arr
Apr 9, 2026
Merged

Enhance ArrayUtils.reconstruct with Flat Output Support#23
afshawnlotfi merged 1 commit intomainfrom
feature/ts-multi-dim-arr

Conversation

@afshawnlotfi
Copy link
Copy Markdown
Member

Overview

This PR enhances the ArrayUtils.reconstruct method in both Python and TypeScript to support returning flat 1-D arrays, providing more flexibility for different use cases like GPU buffer consumption.

Key Changes

Core Feature: flat Parameter

  • Added flat: bool = False parameter to ArrayUtils.reconstruct() in both Python and TypeScript
  • When flat=True: Returns a single flat TypedArray / ndarray (useful for GPU vertex buffers)
  • When flat=False (default): 2-D+ arrays are split into per-column TypedArray[] in TypeScript, or reshaped to original dimensions in Python

TypeScript (typescript/src/array.ts)

  • Refactored reconstruct() to reduce code duplication across encoding branches
  • Return type changed to TypedArray | TypedArray[]
  • 2-D arrays with shape [N, stride] now return an array of stride column arrays by default

Python (python/meshly/array.py)

  • Added flat parameter with docstring explaining behavior
  • Simplified decode logic by removing inline comments and consolidating reshape step

Mesh Decoding

  • Mesh.decode() explicitly passes flat=true to always return flat arrays (mesh data is consumed as interleaved GPU buffers)
  • PackableWorkerClient.decodeArray() also uses flat=true

Test Updates

  • Added test case for 2-D array column splitting behavior
  • Updated Python integration tests to expect TypedArray[] for 2-D fields like inertia_tensor and collision_points

Documentation

  • Updated both Python and TypeScript READMEs with usage examples
  • Added clarifying note that Mesh.decode always returns flat arrays
  • Updated API reference to reflect new return types and flat parameter

…arrays; update README and tests for clarity on usage and expected behavior
@afshawnlotfi afshawnlotfi merged commit 4e1ee2c into main Apr 9, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant