Skip to content

Reproduce a bug example, (Model disappeared when same 3 models pathtraced) #671

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 39 additions & 10 deletions example/primitives.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Scene, SphereGeometry, MeshStandardMaterial, Mesh, BoxGeometry, PerspectiveCamera, ACESFilmicToneMapping, WebGLRenderer } from 'three';
import { Scene, SphereGeometry, MeshStandardMaterial, Mesh, PerspectiveCamera, ACESFilmicToneMapping, WebGLRenderer } from 'three';
import { WebGLPathTracer, GradientEquirectTexture } from '..';
import { getScaledSettings } from './utils/getScaledSettings.js';
import GUI from 'three/examples/jsm/libs/lil-gui.module.min.js';

// init scene, renderer, camera, controls, etc
const scene = new Scene();
Expand All @@ -14,30 +15,26 @@ const ball1 = new Mesh(
} )
);
const ball2 = new Mesh(
sphereGeom,
sphereGeom.clone(),
new MeshStandardMaterial( {
color: '#ff9800',
roughness: 0.1,
metalness: 1,
} )
);
const ball3 = new Mesh(
sphereGeom,
sphereGeom.clone(),
new MeshStandardMaterial( {
color: '#2196f3',
roughness: 0.2,
metalness: 1,
} )
);
const ground = new Mesh(
new BoxGeometry( 3.5, 0.1, 1.5 ),
new MeshStandardMaterial(),
);

ball1.position.x = - 1;
ball3.position.x = 1;
ground.position.y = - 0.54;
scene.add( ball1, ball2, ball3, ground );

scene.add( ball1 );

// set the environment map
const texture = new GradientEquirectTexture();
Expand All @@ -61,6 +58,30 @@ pathTracer.renderScale = settings.renderScale;
pathTracer.tiles.setScalar( settings.tiles );
pathTracer.setScene( scene, camera );

const gui = new GUI();
const params = {
'enable': false,
'addedModel': false
};

gui.add( params, 'enable' ).name( 'Enable' );

gui.add( params, 'addedModel' ).name( 'Add model' ).onChange( () => {

if ( params.addedModel ) {

scene.add( ball2, ball3 );
pathTracer.setScene( scene, camera );

} else {

scene.remove( ball2, ball3 );
pathTracer.setScene( scene, camera );

}

} );

onResize();

animate();
Expand All @@ -73,7 +94,15 @@ function animate() {
requestAnimationFrame( animate );

// update the camera and render one sample
pathTracer.renderSample();
if ( params.enable ) {

pathTracer.renderSample();

} else {

renderer.render( scene, camera );

}

}

Expand Down
Loading