WebGLNodes.js 1017 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { WebGLNodeBuilder } from './WebGLNodeBuilder.js';
  2. import { NodeFrame } from 'three/nodes';
  3. import { Material } from 'three';
  4. const builders = new WeakMap();
  5. export const nodeFrame = new NodeFrame();
  6. Material.prototype.onBuild = function ( object, parameters, renderer ) {
  7. if ( object.material.isNodeMaterial === true ) {
  8. builders.set( this, new WebGLNodeBuilder( object, renderer, parameters ).build() );
  9. }
  10. };
  11. Material.prototype.onBeforeRender = function ( renderer, scene, camera, geometry, object ) {
  12. const nodeBuilder = builders.get( this );
  13. if ( nodeBuilder !== undefined ) {
  14. nodeFrame.material = this;
  15. nodeFrame.camera = camera;
  16. nodeFrame.object = object;
  17. nodeFrame.renderer = renderer;
  18. const updateNodes = nodeBuilder.updateNodes;
  19. if ( updateNodes.length > 0 ) {
  20. // force refresh material uniforms
  21. renderer.state.useProgram( null );
  22. //this.uniformsNeedUpdate = true;
  23. for ( const node of updateNodes ) {
  24. nodeFrame.updateNode( node );
  25. }
  26. }
  27. }
  28. };