Skip to content

Replace precompile with onBeforeCompile injection for Three.js materials - #10

Open
AndrewRayCode wants to merge 1 commit into
mainfrom
spork
Open

Replace precompile with onBeforeCompile injection for Three.js materials#10
AndrewRayCode wants to merge 1 commit into
mainfrom
spork

Conversation

@AndrewRayCode

Copy link
Copy Markdown
Contributor

Summary

Replaces the old renderer.compile() + RawShaderMaterial approach with onBeforeCompile on real Three.js materials (MeshPhysicalMaterial, MeshPhongMaterial, MeshToonMaterial).

  • threngine: New createMaterial() using onBeforeCompile with an InjectionMap system that targets specific #include <chunk> replacements. Strips Three.js built-in attribute/varying declarations from user code to avoid redefinitions. Forces USE_UV when user code references vUv so Three.js's UV pipeline populates it correctly.
  • graph.ts: New ThreeNodeInfo/ThreeNodeFiller types on CompileGraphResult. Engine nodes are skipped in compileNode (no void main generated). Output node sections are filtered from compileSource for Three engine graphs so fragmentResult/vertexResult contain only user-authored functions.
  • context.ts: Early return for Three engine nodes — no AST needed since they no longer generate shader code.
  • threeExport.ts: New self-contained JS export generator for both pure ShaderMaterial graphs and MeshPhysical/Phong/ToonMaterial graphs with baked chunk replacements.

Test plan

  • Load /editor/create/three — checkerboard renders on sphere with no WebGL errors
  • Verify fragment fillers (map, normalMap, etc.) inject correctly via InjectionMap
  • Verify vertex position filler replaces begin_vertex chunk
  • Confirm threeExport.ts generates valid JS for both shader types

🤖 Generated with Claude Code

…js engine nodes

Switch from renderer.compile() + RawShaderMaterial to onBeforeCompile on real
MeshPhysical/Phong/ToonMaterial. User GLSL functions are injected into Three.js
shader templates via targeted chunk replacements. Adds ThreeNodeInfo/ThreeNodeFiller
types, new threeExport.ts for self-contained JS export, and strips Three.js built-in
attribute/varying declarations from user code to avoid redefinitions.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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