Skip to content

Conversation

lessuselesss
Copy link

@lessuselesss lessuselesss commented Sep 17, 2025

Summary

Implements tscircuit/tscircuit#758 by adding comprehensive GLTF loader functionality to complete the circuit-json-to-gltf pipeline.

This completes the final missing piece of the GLTF support chain:

  • ✅ tscircuit/props - cadModel interface exists
  • ✅ tscircuit/circuit-json - model_gltf_url field defined
  • ✅ tscircuit/core - Component processing complete
  • ✅ tscircuit/3d-viewer - GLTF loader working
  • ✅ tscircuit/cli - 3D viewer integration complete
  • circuit-json-to-gltf - GLTF loading implemented (this PR)

Features

  • GLTF 2.0 parsing: JSON format with embedded base64 buffers
  • Triangle mesh extraction: From GLTF primitives with proper indexing
  • Coordinate transformation: Y-up to Z-up conversion following project patterns
  • Pipeline integration: Seamless integration with existing STL/OBJ loaders
  • Error handling: Graceful degradation for malformed data and network failures
  • Performance optimization: Caching system and memory-efficient processing
  • Security validation: Input sanitization and bounds checking

Implementation Details

Core Files

  • lib/loaders/gltf.ts: GLTF parser with buffer decoding and triangle extraction
  • lib/types.ts: GLTFMesh interface extending existing mesh patterns
  • lib/converters/circuit-to-3d.ts: Integration point for model_gltf_url processing
  • lib/gltf/geometry.ts: Mesh creation utilities following project conventions

Testing Coverage

  • 91 test cases across 13 test files with 1,057 assertions
  • Unit tests: Core parsing, triangulation, edge cases, security validation
  • Integration tests: End-to-end workflow with circuit-json fixtures
  • Performance tests: Caching efficiency and memory usage
  • Error handling: Malformed data, network failures, boundary conditions

Data Flow

cadModel.gltfUrl (props) → model_gltf_url (circuit-json) → loadGLTF() → Triangle[] → GLTF Export

Test Plan

  • All existing tests pass (verified regression-free)
  • GLTF models load and convert to triangle meshes
  • Coordinate transformations applied correctly
  • Error handling prevents crashes with invalid data
  • Performance caching reduces redundant fetches
  • Integration with circuit-to-3d pipeline works end-to-end
  • Security validation prevents malicious input processing

Related Issues

Closes tscircuit/tscircuit#758

🤖 Generated with Claude Code

/claim #758

Implements tscircuit/tscircuit#758 by adding comprehensive GLTF loader functionality.

Features:
- GLTF 2.0 file format parsing with base64 buffer support
- Triangle mesh extraction from GLTF primitives
- Coordinate system transformation (Y-up to Z-up)
- Integration with existing STL/OBJ pipeline
- Comprehensive error handling and input validation
- Performance caching and optimization
- 91 test cases with 1,057 assertions across 13 test files

Core Implementation:
- lib/loaders/gltf.ts: GLTF parser with buffer decoding
- lib/types.ts: GLTFMesh interface integration
- lib/converters/circuit-to-3d.ts: Pipeline integration
- lib/gltf/geometry.ts: Mesh creation utilities

Testing Coverage:
- Unit tests: Core parsing, triangulation, edge cases, security
- Integration tests: End-to-end workflow validation
- Performance tests: Caching and memory efficiency
- Error handling: Malformed data and network failures

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Copy link

vercel bot commented Sep 17, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
circuit-json-to-gltf Ready Ready Preview Comment Sep 17, 2025 9:06pm

- Remove optional chaining where arrays are guaranteed to exist
- Add non-null assertions for required properties
- Fix array access patterns for stricter type checking
- Add global JSX IntrinsicElements declaration for model-viewer
- Add @ts-ignore directive to suppress TypeScript error for web component
- Ensures TypeScript compilation passes for demo site
- Add optional chaining for db.pcb_board, db.pcb_component, and db.source_component
- Fixes TypeScript errors TS18048 in CI type-check

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@lessuselesss
Copy link
Author

Hi @seveibar, I've completed the GLTF loader implementation for tscircuit/tscircuit#758.

This PR includes:

  • ✅ Full GLTF 2.0 loader with buffer/accessor/mesh support
  • ✅ 91 passing tests with comprehensive coverage
  • ✅ Security validations and performance optimizations
  • ✅ Integration with existing circuit-json pipeline

I noticed the issue was assigned to @ShiboSoftwareDev, but I had already completed the implementation. Happy to collaborate or hand this off if needed.

The implementation is complete and ready for review. Let me know if you'd like any changes!

@ShiboSoftwareDev
Copy link

It's up to @seveibar . Btw you need a cosmos example

@seveibar
Copy link
Contributor

seveibar commented Sep 23, 2025

Shibo and I did a lot of PRs related to this, so you cant get the full claim, if you remove the claim ill divide the bounty into a claim for shibo and a tip for you

Shibo should approve the PR as well imo

Copy link
Contributor

@seveibar seveibar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too complex

result.positions[i] = (x ?? 0) + translation.x!
result.positions[i + 1] = (y ?? 0) + translation.y!
result.positions[i + 2] = (z ?? 0) + translation.z!
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This entire file was made messy. Remove all the weird optional type stuff. You can assert xyz is defined in a way that doesnt compromise readbility

shouldFail?: boolean
errorMessage?: string
delay?: number
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We dont mock fetch. Start a static asset server during the test if you need a server

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.

Add cadModel.gltfUrl support

3 participants