Renderer.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968
  1. import Animation from './Animation.js';
  2. import RenderObjects from './RenderObjects.js';
  3. import Attributes from './Attributes.js';
  4. import Geometries from './Geometries.js';
  5. import Info from './Info.js';
  6. import Pipelines from './Pipelines.js';
  7. import Bindings from './Bindings.js';
  8. import RenderLists from './RenderLists.js';
  9. import RenderContexts from './RenderContexts.js';
  10. import Textures from './Textures.js';
  11. import Background from './Background.js';
  12. import Nodes from './nodes/Nodes.js';
  13. import { Scene, Frustum, Matrix4, Vector2, Vector3, Vector4, Color, DoubleSide, BackSide, FrontSide, SRGBColorSpace, NoToneMapping } from 'three';
  14. const _scene = new Scene();
  15. const _drawingBufferSize = new Vector2();
  16. const _screen = new Vector4();
  17. const _frustum = new Frustum();
  18. const _projScreenMatrix = new Matrix4();
  19. const _vector3 = new Vector3();
  20. class Renderer {
  21. constructor( backend ) {
  22. this.isRenderer = true;
  23. // public
  24. this.domElement = backend.getDomElement();
  25. this.backend = backend;
  26. this.autoClear = true;
  27. this.autoClearColor = true;
  28. this.autoClearDepth = true;
  29. this.autoClearStencil = true;
  30. this.outputColorSpace = SRGBColorSpace;
  31. this.toneMapping = NoToneMapping;
  32. this.toneMappingExposure = 1.0;
  33. this.sortObjects = true;
  34. this.depth = true;
  35. this.stencil = true;
  36. this.info = new Info();
  37. // internals
  38. this._pixelRatio = 1;
  39. this._width = this.domElement.width;
  40. this._height = this.domElement.height;
  41. this._viewport = new Vector4( 0, 0, this._width, this._height );
  42. this._scissor = new Vector4( 0, 0, this._width, this._height );
  43. this._scissorTest = false;
  44. this._properties = null;
  45. this._attributes = null;
  46. this._geometries = null;
  47. this._nodes = null;
  48. this._animation = null;
  49. this._bindings = null;
  50. this._objects = null;
  51. this._pipelines = null;
  52. this._renderLists = null;
  53. this._renderContexts = null;
  54. this._textures = null;
  55. this._background = null;
  56. this._currentRenderContext = null;
  57. this._lastRenderContext = null;
  58. this._opaqueSort = null;
  59. this._transparentSort = null;
  60. this._clearAlpha = 1;
  61. this._clearColor = new Color( 0x000000 );
  62. this._clearDepth = 1;
  63. this._clearStencil = 0;
  64. this._renderTarget = null;
  65. this._activeCubeFace = 0;
  66. this._activeMipmapLevel = 0;
  67. this._renderObjectFunction = null;
  68. this._currentRenderObjectFunction = null;
  69. this._initialized = false;
  70. this._initPromise = null;
  71. // backwards compatibility
  72. this.shadowMap = {
  73. enabled: false,
  74. type: null
  75. };
  76. this.xr = {
  77. enabled: false
  78. };
  79. }
  80. async init() {
  81. if ( this._initialized ) {
  82. throw new Error( 'Renderer: Backend has already been initialized.' );
  83. }
  84. if ( this._initPromise !== null ) {
  85. return this._initPromise;
  86. }
  87. this._initPromise = new Promise( async ( resolve, reject ) => {
  88. const backend = this.backend;
  89. try {
  90. await backend.init( this );
  91. } catch ( error ) {
  92. reject( error );
  93. return;
  94. }
  95. this._nodes = new Nodes( this, backend );
  96. this._animation = new Animation( this._nodes, this.info );
  97. this._attributes = new Attributes( backend );
  98. this._background = new Background( this, this._nodes );
  99. this._geometries = new Geometries( this._attributes, this.info );
  100. this._textures = new Textures( backend, this.info );
  101. this._pipelines = new Pipelines( backend, this._nodes );
  102. this._bindings = new Bindings( backend, this._nodes, this._textures, this._attributes, this._pipelines, this.info );
  103. this._objects = new RenderObjects( this, this._nodes, this._geometries, this._pipelines, this._bindings, this.info );
  104. this._renderLists = new RenderLists();
  105. this._renderContexts = new RenderContexts();
  106. //
  107. this._initialized = true;
  108. resolve();
  109. } );
  110. return this._initPromise;
  111. }
  112. get coordinateSystem() {
  113. return this.backend.coordinateSystem;
  114. }
  115. async compile( /*scene, camera*/ ) {
  116. console.warn( 'THREE.Renderer: .compile() is not implemented yet.' );
  117. }
  118. async render( scene, camera ) {
  119. if ( this._initialized === false ) await this.init();
  120. // preserve render tree
  121. const nodeFrame = this._nodes.nodeFrame;
  122. const previousRenderId = nodeFrame.renderId;
  123. const previousRenderContext = this._currentRenderContext;
  124. const previousRenderObjectFunction = this._currentRenderObjectFunction;
  125. //
  126. const sceneRef = ( scene.isScene === true ) ? scene : _scene;
  127. const renderTarget = this._renderTarget;
  128. const renderContext = this._renderContexts.get( scene, camera, renderTarget );
  129. const activeCubeFace = this._activeCubeFace;
  130. const activeMipmapLevel = this._activeMipmapLevel;
  131. this._currentRenderContext = renderContext;
  132. this._currentRenderObjectFunction = this._renderObjectFunction || this.renderObject;
  133. //
  134. this.info.calls ++;
  135. this.info.render.calls ++;
  136. nodeFrame.renderId = this.info.calls;
  137. //
  138. const coordinateSystem = this.coordinateSystem;
  139. if ( camera.coordinateSystem !== coordinateSystem ) {
  140. camera.coordinateSystem = coordinateSystem;
  141. camera.updateProjectionMatrix();
  142. }
  143. //
  144. if ( scene.matrixWorldAutoUpdate === true ) scene.updateMatrixWorld();
  145. if ( camera.parent === null && camera.matrixWorldAutoUpdate === true ) camera.updateMatrixWorld();
  146. if ( this.info.autoReset === true ) this.info.reset();
  147. //
  148. let viewport = this._viewport;
  149. let scissor = this._scissor;
  150. let pixelRatio = this._pixelRatio;
  151. if ( renderTarget !== null ) {
  152. viewport = renderTarget.viewport;
  153. scissor = renderTarget.scissor;
  154. pixelRatio = 1;
  155. }
  156. this.getDrawingBufferSize( _drawingBufferSize );
  157. _screen.set( 0, 0, _drawingBufferSize.width, _drawingBufferSize.height );
  158. const minDepth = ( viewport.minDepth === undefined ) ? 0 : viewport.minDepth;
  159. const maxDepth = ( viewport.maxDepth === undefined ) ? 1 : viewport.maxDepth;
  160. renderContext.viewportValue.copy( viewport ).multiplyScalar( pixelRatio ).floor();
  161. renderContext.viewportValue.width >>= activeMipmapLevel;
  162. renderContext.viewportValue.height >>= activeMipmapLevel;
  163. renderContext.viewportValue.minDepth = minDepth;
  164. renderContext.viewportValue.maxDepth = maxDepth;
  165. renderContext.viewport = renderContext.viewportValue.equals( _screen ) === false;
  166. renderContext.scissorValue.copy( scissor ).multiplyScalar( pixelRatio ).floor();
  167. renderContext.scissor = this._scissorTest && renderContext.scissorValue.equals( _screen ) === false;
  168. renderContext.scissorValue.width >>= activeMipmapLevel;
  169. renderContext.scissorValue.height >>= activeMipmapLevel;
  170. renderContext.depth = this.depth;
  171. renderContext.stencil = this.stencil;
  172. //
  173. sceneRef.onBeforeRender( this, scene, camera, renderTarget );
  174. //
  175. _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  176. _frustum.setFromProjectionMatrix( _projScreenMatrix, coordinateSystem );
  177. const renderList = this._renderLists.get( scene, camera );
  178. renderList.begin();
  179. this._projectObject( scene, camera, 0, renderList );
  180. renderList.finish();
  181. if ( this.sortObjects === true ) {
  182. renderList.sort( this._opaqueSort, this._transparentSort );
  183. }
  184. //
  185. if ( renderTarget !== null ) {
  186. this._textures.updateRenderTarget( renderTarget, activeMipmapLevel );
  187. const renderTargetData = this._textures.get( renderTarget );
  188. renderContext.textures = renderTargetData.textures;
  189. renderContext.depthTexture = renderTargetData.depthTexture;
  190. renderContext.width = renderTargetData.width;
  191. renderContext.height = renderTargetData.height;
  192. } else {
  193. renderContext.textures = null;
  194. renderContext.depthTexture = null;
  195. renderContext.width = this.domElement.width;
  196. renderContext.height = this.domElement.height;
  197. }
  198. renderContext.width >>= activeMipmapLevel;
  199. renderContext.height >>= activeMipmapLevel;
  200. renderContext.activeCubeFace = activeCubeFace;
  201. renderContext.activeMipmapLevel = activeMipmapLevel;
  202. renderContext.occlusionQueryCount = renderList.occlusionQueryCount;
  203. //
  204. this._nodes.updateScene( sceneRef );
  205. //
  206. this._background.update( sceneRef, renderList, renderContext );
  207. //
  208. this.backend.beginRender( renderContext );
  209. // process render lists
  210. const opaqueObjects = renderList.opaque;
  211. const transparentObjects = renderList.transparent;
  212. const lightsNode = renderList.lightsNode;
  213. if ( opaqueObjects.length > 0 ) this._renderObjects( opaqueObjects, camera, sceneRef, lightsNode );
  214. if ( transparentObjects.length > 0 ) this._renderObjects( transparentObjects, camera, sceneRef, lightsNode );
  215. // finish render pass
  216. this.backend.finishRender( renderContext );
  217. // restore render tree
  218. nodeFrame.renderId = previousRenderId;
  219. this._currentRenderContext = previousRenderContext;
  220. this._currentRenderObjectFunction = previousRenderObjectFunction;
  221. this._lastRenderContext = renderContext;
  222. //
  223. sceneRef.onAfterRender( this, scene, camera, renderTarget );
  224. }
  225. getActiveCubeFace() {
  226. return this._activeCubeFace;
  227. }
  228. getActiveMipmapLevel() {
  229. return this._activeMipmapLevel;
  230. }
  231. async setAnimationLoop( callback ) {
  232. if ( this._initialized === false ) await this.init();
  233. this._animation.setAnimationLoop( callback );
  234. }
  235. getArrayBuffer( attribute ) { // @deprecated, r155
  236. console.warn( 'THREE.Renderer: getArrayBuffer() is deprecated. Use getArrayBufferAsync() instead.' );
  237. return this.getArrayBufferAsync( attribute );
  238. }
  239. async getArrayBufferAsync( attribute ) {
  240. return await this.backend.getArrayBufferAsync( attribute );
  241. }
  242. getContext() {
  243. return this._context;
  244. }
  245. getPixelRatio() {
  246. return this._pixelRatio;
  247. }
  248. getDrawingBufferSize( target ) {
  249. return target.set( this._width * this._pixelRatio, this._height * this._pixelRatio ).floor();
  250. }
  251. getSize( target ) {
  252. return target.set( this._width, this._height );
  253. }
  254. setPixelRatio( value = 1 ) {
  255. this._pixelRatio = value;
  256. this.setSize( this._width, this._height, false );
  257. }
  258. setDrawingBufferSize( width, height, pixelRatio ) {
  259. this._width = width;
  260. this._height = height;
  261. this._pixelRatio = pixelRatio;
  262. this.domElement.width = Math.floor( width * pixelRatio );
  263. this.domElement.height = Math.floor( height * pixelRatio );
  264. this.setViewport( 0, 0, width, height );
  265. if ( this._initialized ) this.backend.updateSize();
  266. }
  267. setSize( width, height, updateStyle = true ) {
  268. this._width = width;
  269. this._height = height;
  270. this.domElement.width = Math.floor( width * this._pixelRatio );
  271. this.domElement.height = Math.floor( height * this._pixelRatio );
  272. if ( updateStyle === true ) {
  273. this.domElement.style.width = width + 'px';
  274. this.domElement.style.height = height + 'px';
  275. }
  276. this.setViewport( 0, 0, width, height );
  277. if ( this._initialized ) this.backend.updateSize();
  278. }
  279. setOpaqueSort( method ) {
  280. this._opaqueSort = method;
  281. }
  282. setTransparentSort( method ) {
  283. this._transparentSort = method;
  284. }
  285. getScissor( target ) {
  286. const scissor = this._scissor;
  287. target.x = scissor.x;
  288. target.y = scissor.y;
  289. target.width = scissor.width;
  290. target.height = scissor.height;
  291. return target;
  292. }
  293. setScissor( x, y, width, height ) {
  294. const scissor = this._scissor;
  295. if ( x.isVector4 ) {
  296. scissor.copy( x );
  297. } else {
  298. scissor.set( x, y, width, height );
  299. }
  300. }
  301. getScissorTest() {
  302. return this._scissorTest;
  303. }
  304. setScissorTest( boolean ) {
  305. this._scissorTest = boolean;
  306. }
  307. getViewport( target ) {
  308. return target.copy( this._viewport );
  309. }
  310. setViewport( x, y, width, height, minDepth = 0, maxDepth = 1 ) {
  311. const viewport = this._viewport;
  312. if ( x.isVector4 ) {
  313. viewport.copy( x );
  314. } else {
  315. viewport.set( x, y, width, height );
  316. }
  317. viewport.minDepth = minDepth;
  318. viewport.maxDepth = maxDepth;
  319. }
  320. getClearColor( target ) {
  321. return target.copy( this._clearColor );
  322. }
  323. setClearColor( color, alpha = 1 ) {
  324. this._clearColor.set( color );
  325. this._clearAlpha = alpha;
  326. }
  327. getClearAlpha() {
  328. return this._clearAlpha;
  329. }
  330. setClearAlpha( alpha ) {
  331. this._clearAlpha = alpha;
  332. }
  333. getClearDepth() {
  334. return this._clearDepth;
  335. }
  336. setClearDepth( depth ) {
  337. this._clearDepth = depth;
  338. }
  339. getClearStencil() {
  340. return this._clearStencil;
  341. }
  342. setClearStencil( stencil ) {
  343. this._clearStencil = stencil;
  344. }
  345. isOccluded( object ) {
  346. const renderContext = this._currentRenderContext || this._lastRenderContext;
  347. return renderContext && this.backend.isOccluded( renderContext, object );
  348. }
  349. clear( color = true, depth = true, stencil = true ) {
  350. const renderContext = this._currentRenderContext || this._lastRenderContext;
  351. if ( renderContext ) this.backend.clear( renderContext, color, depth, stencil );
  352. }
  353. clearColor() {
  354. this.clear( true, false, false );
  355. }
  356. clearDepth() {
  357. this.clear( false, true, false );
  358. }
  359. clearStencil() {
  360. this.clear( false, false, true );
  361. }
  362. dispose() {
  363. this.info.dispose();
  364. this._animation.dispose();
  365. this._objects.dispose();
  366. this._properties.dispose();
  367. this._pipelines.dispose();
  368. this._nodes.dispose();
  369. this._bindings.dispose();
  370. this._renderLists.dispose();
  371. this._renderContexts.dispose();
  372. this._textures.dispose();
  373. this.setRenderTarget( null );
  374. this.setAnimationLoop( null );
  375. }
  376. setRenderTarget( renderTarget, activeCubeFace = 0, activeMipmapLevel = 0 ) {
  377. this._renderTarget = renderTarget;
  378. this._activeCubeFace = activeCubeFace;
  379. this._activeMipmapLevel = activeMipmapLevel;
  380. }
  381. getRenderTarget() {
  382. return this._renderTarget;
  383. }
  384. setRenderObjectFunction( renderObjectFunction ) {
  385. this._renderObjectFunction = renderObjectFunction;
  386. }
  387. getRenderObjectFunction() {
  388. return this._renderObjectFunction;
  389. }
  390. async compute( computeNodes ) {
  391. if ( this._initialized === false ) await this.init();
  392. const nodeFrame = this._nodes.nodeFrame;
  393. const previousRenderId = nodeFrame.renderId;
  394. //
  395. this.info.calls ++;
  396. this.info.compute.calls ++;
  397. nodeFrame.renderId = this.info.calls;
  398. //
  399. const backend = this.backend;
  400. const pipelines = this._pipelines;
  401. const bindings = this._bindings;
  402. const nodes = this._nodes;
  403. const computeList = Array.isArray( computeNodes ) ? computeNodes : [ computeNodes ];
  404. if ( computeList[ 0 ] === undefined || computeList[ 0 ].isComputeNode !== true ) {
  405. throw new Error( 'THREE.Renderer: .compute() expects a ComputeNode.' );
  406. }
  407. backend.beginCompute( computeNodes );
  408. for ( const computeNode of computeList ) {
  409. // onInit
  410. if ( pipelines.has( computeNode ) === false ) {
  411. const dispose = () => {
  412. computeNode.removeEventListener( 'dispose', dispose );
  413. pipelines.delete( computeNode );
  414. bindings.delete( computeNode );
  415. nodes.delete( computeNode );
  416. };
  417. computeNode.addEventListener( 'dispose', dispose );
  418. //
  419. computeNode.onInit( { renderer: this } );
  420. }
  421. nodes.updateForCompute( computeNode );
  422. bindings.updateForCompute( computeNode );
  423. const computeBindings = bindings.getForCompute( computeNode );
  424. const computePipeline = pipelines.getForCompute( computeNode, computeBindings );
  425. backend.compute( computeNodes, computeNode, computeBindings, computePipeline );
  426. }
  427. backend.finishCompute( computeNodes );
  428. //
  429. nodeFrame.renderId = previousRenderId;
  430. }
  431. hasFeature( name ) {
  432. return this.backend.hasFeature( name );
  433. }
  434. copyFramebufferToTexture( framebufferTexture ) {
  435. const renderContext = this._currentRenderContext || this._lastRenderContext;
  436. this._textures.updateTexture( framebufferTexture );
  437. this.backend.copyFramebufferToTexture( framebufferTexture, renderContext );
  438. }
  439. readRenderTargetPixelsAsync( renderTarget, x, y, width, height ) {
  440. return this.backend.copyTextureToBuffer( renderTarget.texture, x, y, width, height );
  441. }
  442. _projectObject( object, camera, groupOrder, renderList ) {
  443. if ( object.visible === false ) return;
  444. const visible = object.layers.test( camera.layers );
  445. if ( visible ) {
  446. if ( object.isGroup ) {
  447. groupOrder = object.renderOrder;
  448. } else if ( object.isLOD ) {
  449. if ( object.autoUpdate === true ) object.update( camera );
  450. } else if ( object.isLight ) {
  451. renderList.pushLight( object );
  452. } else if ( object.isSprite ) {
  453. if ( ! object.frustumCulled || _frustum.intersectsSprite( object ) ) {
  454. if ( this.sortObjects === true ) {
  455. _vector3.setFromMatrixPosition( object.matrixWorld ).applyMatrix4( _projScreenMatrix );
  456. }
  457. const geometry = object.geometry;
  458. const material = object.material;
  459. if ( material.visible ) {
  460. renderList.push( object, geometry, material, groupOrder, _vector3.z, null );
  461. }
  462. }
  463. } else if ( object.isLineLoop ) {
  464. console.error( 'THREE.Renderer: Objects of type THREE.LineLoop are not supported. Please use THREE.Line or THREE.LineSegments.' );
  465. } else if ( object.isMesh || object.isLine || object.isPoints ) {
  466. if ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) {
  467. const geometry = object.geometry;
  468. const material = object.material;
  469. if ( this.sortObjects === true ) {
  470. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  471. _vector3
  472. .copy( geometry.boundingSphere.center )
  473. .applyMatrix4( object.matrixWorld )
  474. .applyMatrix4( _projScreenMatrix );
  475. }
  476. if ( Array.isArray( material ) ) {
  477. const groups = geometry.groups;
  478. for ( let i = 0, l = groups.length; i < l; i ++ ) {
  479. const group = groups[ i ];
  480. const groupMaterial = material[ group.materialIndex ];
  481. if ( groupMaterial && groupMaterial.visible ) {
  482. renderList.push( object, geometry, groupMaterial, groupOrder, _vector3.z, group );
  483. }
  484. }
  485. } else if ( material.visible ) {
  486. renderList.push( object, geometry, material, groupOrder, _vector3.z, null );
  487. }
  488. }
  489. }
  490. }
  491. const children = object.children;
  492. for ( let i = 0, l = children.length; i < l; i ++ ) {
  493. this._projectObject( children[ i ], camera, groupOrder, renderList );
  494. }
  495. }
  496. _renderObjects( renderList, camera, scene, lightsNode ) {
  497. // process renderable objects
  498. for ( let i = 0, il = renderList.length; i < il; i ++ ) {
  499. const renderItem = renderList[ i ];
  500. // @TODO: Add support for multiple materials per object. This will require to extract
  501. // the material from the renderItem object and pass it with its group data to renderObject().
  502. const { object, geometry, material, group } = renderItem;
  503. if ( camera.isArrayCamera ) {
  504. const cameras = camera.cameras;
  505. for ( let j = 0, jl = cameras.length; j < jl; j ++ ) {
  506. const camera2 = cameras[ j ];
  507. if ( object.layers.test( camera2.layers ) ) {
  508. const vp = camera2.viewport;
  509. const minDepth = ( vp.minDepth === undefined ) ? 0 : vp.minDepth;
  510. const maxDepth = ( vp.maxDepth === undefined ) ? 1 : vp.maxDepth;
  511. const viewportValue = this._currentRenderContext.viewportValue;
  512. viewportValue.copy( vp ).multiplyScalar( this._pixelRatio ).floor();
  513. viewportValue.minDepth = minDepth;
  514. viewportValue.maxDepth = maxDepth;
  515. this.backend.updateViewport( this._currentRenderContext );
  516. this._currentRenderObjectFunction( object, scene, camera2, geometry, material, group, lightsNode );
  517. }
  518. }
  519. } else {
  520. this._currentRenderObjectFunction( object, scene, camera, geometry, material, group, lightsNode );
  521. }
  522. }
  523. }
  524. renderObject( object, scene, camera, geometry, material, group, lightsNode ) {
  525. material = scene.overrideMaterial !== null ? scene.overrideMaterial : material;
  526. //
  527. object.onBeforeRender( this, scene, camera, geometry, material, group );
  528. material.onBeforeRender( this, scene, camera, geometry, material, group );
  529. //
  530. if ( material.transparent === true && material.side === DoubleSide && material.forceSinglePass === false ) {
  531. material.side = BackSide;
  532. this._renderObjectDirect( object, material, scene, camera, lightsNode, 'backSide' ); // create backSide pass id
  533. material.side = FrontSide;
  534. this._renderObjectDirect( object, material, scene, camera, lightsNode ); // use default pass id
  535. material.side = DoubleSide;
  536. } else {
  537. this._renderObjectDirect( object, material, scene, camera, lightsNode );
  538. }
  539. //
  540. object.onAfterRender( this, scene, camera, geometry, material, group );
  541. }
  542. _renderObjectDirect( object, material, scene, camera, lightsNode, passId ) {
  543. const renderObject = this._objects.get( object, material, scene, camera, lightsNode, this._currentRenderContext, passId );
  544. //
  545. this._nodes.updateBefore( renderObject );
  546. //
  547. object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
  548. object.normalMatrix.getNormalMatrix( object.modelViewMatrix );
  549. //
  550. this._nodes.updateForRender( renderObject );
  551. this._geometries.updateForRender( renderObject );
  552. this._bindings.updateForRender( renderObject );
  553. this._pipelines.updateForRender( renderObject );
  554. //
  555. this.backend.draw( renderObject, this.info );
  556. }
  557. }
  558. export default Renderer;