Skip to content

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

Open
Ishan-Banjara wants to merge 1 commit intondahn:masterfrom
Ishan-Banjara:feature/obj-mtl-loader
Open

Add native OBJ + MTL + texture loader for custom objects#13
Ishan-Banjara wants to merge 1 commit intondahn: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

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