Skip to content

Add native OBJ + MTL + texture loader for custom objects#13

Open
Ishan-Banjara wants to merge 3 commits into
ndahn:masterfrom
Ishan-Banjara:feature/obj-mtl-loader
Open

Add native OBJ + MTL + texture loader for custom objects#13
Ishan-Banjara wants to merge 3 commits into
ndahn:masterfrom
Ishan-Banjara:feature/obj-mtl-loader

Conversation

@Ishan-Banjara
Copy link
Copy Markdown

Summary

Extends the "Custom object..." loader to natively support .obj files with optional .mtl material files and texture images, alongside existing .stl support.

🔗 Live demo: https://ishan-banjara.github.io/Rocksi/

Motivation

The original custom object loader only supports .stl files, which lack material and color information. Many common 3D models (especially from Free3D, Sketchfab, etc.) ship as .obj + .mtl + textures. This PR lets users load those directly with full visual fidelity.

Changes

All changes contained in src/simulator/objects/createObjects.js:

  • Added OBJLoader and MTLLoader imports from three/examples/jsm/loaders/
  • Renamed loadUserSTL()loadUserFile() as a format router
  • File picker now accepts multi-file selection for .obj + .mtl + textures
  • Added loadUserOBJ() with LoadingManager.setURLModifier for blob URL resolution of texture references
  • Added attachOBJToSimObject() which:
    • Preserves MTL colors/textures (doesn't override with block's colour field)
    • Converts materials to MeshPhongMaterial for compatibility with Rocksi's highlight system (prevents a material.emissive crash)
    • Auto-scales model to visible size
    • Centers XY, rests base on floor

The existing STL path is completely unchanged; backward compatible.

How to Test

  1. Drag "Place an object" block into workspace
  2. Select "Custom object..."
  3. Multi-select .obj + .mtl + texture images in the picker
  4. Model appears with full materials

Or try directly at the live demo above.

Notes

  • No new runtime dependencies (OBJLoader/MTLLoader already ship with three)
  • README.md has a small fork-description added; happy to revert that if preferred; the substantive change is entirely in createObjects.js

@ndahn
Copy link
Copy Markdown
Owner

ndahn commented May 13, 2026

Very nice, thank you :D I will try to push an update of the live website in the next few weeks. Sorry for not replying to this sooner!

@ndahn
Copy link
Copy Markdown
Owner

ndahn commented May 13, 2026

I'll need you to cleanup the comments before I can accept this PR. Also the readme should absolutely not be a part of this PR at all. I'm generally not too stoked about purely AI generated PRs that have not even been cross checked.

@Ishan-Banjara
Copy link
Copy Markdown
Author

Really sorry about the sloppy first pass. This is my first PR, leaned on AI too much and didn't review carefully before submitting. Also didn't realize the README change would be the part of the PR, thought it would be only a fork edit. It is all on me. I have reverted the README and removed the AI-style comments and branded console logs. Also, I found the material conversion I added in attachOBJToSimObject was not doing anything. One artifact that remains is the hover-highlight feature is not working with the OBJ models. But no crash, just silently no-ops on hover/click.

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.

2 participants