|
@@ -1,4 +1,5 @@
|
|
|
import * as THREE from 'three';
|
|
import * as THREE from 'three';
|
|
|
|
|
+import { PMREMGenerator } from 'three/webgpu';
|
|
|
|
|
|
|
|
import { TransformControls } from 'three/addons/controls/TransformControls.js';
|
|
import { TransformControls } from 'three/addons/controls/TransformControls.js';
|
|
|
|
|
|
|
@@ -291,7 +292,7 @@ function Viewport( editor ) {
|
|
|
signals.editorCleared.add( function () {
|
|
signals.editorCleared.add( function () {
|
|
|
|
|
|
|
|
controls.center.set( 0, 0, 0 );
|
|
controls.center.set( 0, 0, 0 );
|
|
|
- pathtracer.reset();
|
|
|
|
|
|
|
+ if ( pathtracer ) pathtracer.reset();
|
|
|
|
|
|
|
|
initPT();
|
|
initPT();
|
|
|
|
|
|
|
@@ -342,8 +343,18 @@ function Viewport( editor ) {
|
|
|
if ( renderer !== null ) {
|
|
if ( renderer !== null ) {
|
|
|
|
|
|
|
|
renderer.setAnimationLoop( null );
|
|
renderer.setAnimationLoop( null );
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+
|
|
|
|
|
+ pmremGenerator.dispose();
|
|
|
|
|
+
|
|
|
|
|
+ } catch ( e ) {
|
|
|
|
|
+
|
|
|
|
|
+ console.warn( 'PMREMGenerator dispose error:', e );
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
renderer.dispose();
|
|
renderer.dispose();
|
|
|
- pmremGenerator.dispose();
|
|
|
|
|
|
|
|
|
|
container.dom.removeChild( renderer.domElement );
|
|
container.dom.removeChild( renderer.domElement );
|
|
|
|
|
|
|
@@ -377,13 +388,25 @@ function Viewport( editor ) {
|
|
|
renderer.setPixelRatio( window.devicePixelRatio );
|
|
renderer.setPixelRatio( window.devicePixelRatio );
|
|
|
renderer.setSize( container.dom.offsetWidth, container.dom.offsetHeight );
|
|
renderer.setSize( container.dom.offsetWidth, container.dom.offsetHeight );
|
|
|
|
|
|
|
|
- pmremGenerator = new THREE.PMREMGenerator( renderer );
|
|
|
|
|
- pmremGenerator.compileEquirectangularShader();
|
|
|
|
|
|
|
+ if ( renderer.isWebGLRenderer ) {
|
|
|
|
|
+
|
|
|
|
|
+ pmremGenerator = new THREE.PMREMGenerator( renderer );
|
|
|
|
|
+ pmremGenerator.compileEquirectangularShader();
|
|
|
|
|
+
|
|
|
|
|
+ pathtracer = new ViewportPathtracer( renderer );
|
|
|
|
|
|
|
|
- pathtracer = new ViewportPathtracer( renderer );
|
|
|
|
|
|
|
+ } else {
|
|
|
|
|
+
|
|
|
|
|
+ pmremGenerator = new PMREMGenerator( renderer );
|
|
|
|
|
+
|
|
|
|
|
+ pathtracer = null;
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
container.dom.appendChild( renderer.domElement );
|
|
container.dom.appendChild( renderer.domElement );
|
|
|
|
|
|
|
|
|
|
+ signals.sceneEnvironmentChanged.dispatch( editor.environmentType );
|
|
|
|
|
+
|
|
|
render();
|
|
render();
|
|
|
|
|
|
|
|
} );
|
|
} );
|
|
@@ -403,7 +426,7 @@ function Viewport( editor ) {
|
|
|
|
|
|
|
|
signals.cameraChanged.add( function () {
|
|
signals.cameraChanged.add( function () {
|
|
|
|
|
|
|
|
- pathtracer.reset();
|
|
|
|
|
|
|
+ if ( pathtracer ) pathtracer.reset();
|
|
|
|
|
|
|
|
render();
|
|
render();
|
|
|
|
|
|
|
@@ -682,7 +705,7 @@ function Viewport( editor ) {
|
|
|
switch ( viewportShading ) {
|
|
switch ( viewportShading ) {
|
|
|
|
|
|
|
|
case 'realistic':
|
|
case 'realistic':
|
|
|
- pathtracer.init( scene, editor.viewportCamera );
|
|
|
|
|
|
|
+ if ( pathtracer ) pathtracer.init( scene, editor.viewportCamera );
|
|
|
break;
|
|
break;
|
|
|
|
|
|
|
|
case 'solid':
|
|
case 'solid':
|
|
@@ -709,8 +732,10 @@ function Viewport( editor ) {
|
|
|
|
|
|
|
|
updateAspectRatio();
|
|
updateAspectRatio();
|
|
|
|
|
|
|
|
|
|
+ if ( renderer === null ) return;
|
|
|
|
|
+
|
|
|
renderer.setSize( container.dom.offsetWidth, container.dom.offsetHeight );
|
|
renderer.setSize( container.dom.offsetWidth, container.dom.offsetHeight );
|
|
|
- pathtracer.setSize( container.dom.offsetWidth, container.dom.offsetHeight );
|
|
|
|
|
|
|
+ if ( pathtracer ) pathtracer.setSize( container.dom.offsetWidth, container.dom.offsetHeight );
|
|
|
|
|
|
|
|
render();
|
|
render();
|
|
|
|
|
|
|
@@ -831,7 +856,7 @@ function Viewport( editor ) {
|
|
|
|
|
|
|
|
function initPT() {
|
|
function initPT() {
|
|
|
|
|
|
|
|
- if ( editor.viewportShading === 'realistic' ) {
|
|
|
|
|
|
|
+ if ( pathtracer && editor.viewportShading === 'realistic' ) {
|
|
|
|
|
|
|
|
pathtracer.init( scene, editor.viewportCamera );
|
|
pathtracer.init( scene, editor.viewportCamera );
|
|
|
|
|
|
|
@@ -841,7 +866,7 @@ function Viewport( editor ) {
|
|
|
|
|
|
|
|
function updatePTBackground() {
|
|
function updatePTBackground() {
|
|
|
|
|
|
|
|
- if ( editor.viewportShading === 'realistic' ) {
|
|
|
|
|
|
|
+ if ( pathtracer && editor.viewportShading === 'realistic' ) {
|
|
|
|
|
|
|
|
pathtracer.setBackground( scene.background, scene.backgroundBlurriness );
|
|
pathtracer.setBackground( scene.background, scene.backgroundBlurriness );
|
|
|
|
|
|
|
@@ -851,7 +876,7 @@ function Viewport( editor ) {
|
|
|
|
|
|
|
|
function updatePTEnvironment() {
|
|
function updatePTEnvironment() {
|
|
|
|
|
|
|
|
- if ( editor.viewportShading === 'realistic' ) {
|
|
|
|
|
|
|
+ if ( pathtracer && editor.viewportShading === 'realistic' ) {
|
|
|
|
|
|
|
|
pathtracer.setEnvironment( scene.environment );
|
|
pathtracer.setEnvironment( scene.environment );
|
|
|
|
|
|
|
@@ -861,7 +886,7 @@ function Viewport( editor ) {
|
|
|
|
|
|
|
|
function updatePTMaterials() {
|
|
function updatePTMaterials() {
|
|
|
|
|
|
|
|
- if ( editor.viewportShading === 'realistic' ) {
|
|
|
|
|
|
|
+ if ( pathtracer && editor.viewportShading === 'realistic' ) {
|
|
|
|
|
|
|
|
pathtracer.updateMaterials();
|
|
pathtracer.updateMaterials();
|
|
|
|
|
|
|
@@ -871,7 +896,7 @@ function Viewport( editor ) {
|
|
|
|
|
|
|
|
function updatePT() {
|
|
function updatePT() {
|
|
|
|
|
|
|
|
- if ( editor.viewportShading === 'realistic' ) {
|
|
|
|
|
|
|
+ if ( pathtracer && editor.viewportShading === 'realistic' ) {
|
|
|
|
|
|
|
|
pathtracer.update();
|
|
pathtracer.update();
|
|
|
editor.signals.pathTracerUpdated.dispatch( pathtracer.getSamples() );
|
|
editor.signals.pathTracerUpdated.dispatch( pathtracer.getSamples() );
|
|
@@ -887,6 +912,8 @@ function Viewport( editor ) {
|
|
|
|
|
|
|
|
function render() {
|
|
function render() {
|
|
|
|
|
|
|
|
|
|
+ if ( renderer === null ) return;
|
|
|
|
|
+
|
|
|
startTime = performance.now();
|
|
startTime = performance.now();
|
|
|
|
|
|
|
|
renderer.setViewport( 0, 0, container.dom.offsetWidth, container.dom.offsetHeight );
|
|
renderer.setViewport( 0, 0, container.dom.offsetWidth, container.dom.offsetHeight );
|