Skip to content

Commit 51afad9

Browse files
authored
Examples: Clean up. (#21552)
* Examples: Clean up. * IFCLoader: Fix path to core.
1 parent e48fc94 commit 51afad9

File tree

2 files changed

+64
-49
lines changed

2 files changed

+64
-49
lines changed

examples/jsm/loaders/IFCLoader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
InterleavedBuffer,
1515
InterleavedBufferAttribute,
1616
BufferAttribute,
17-
} from '../../../../build/three.module.js';
17+
} from '../../../build/three.module.js';
1818

1919
var ifcAPI = new IfcAPI();
2020

examples/webgl_loader_ifc.html

Lines changed: 63 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
</head>
1212

1313
<body>
14-
<div id="container"></div>
1514
<div id="info">
1615
<a href="https://threejs.org" target="_blank" rel="noopener">three.js</a>
1716
-
@@ -26,61 +25,77 @@
2625

2726
import { IFCLoader } from './jsm/loaders/IFCLoader.js';
2827

29-
//Scene
30-
const scene = new THREE.Scene();
31-
scene.background = new THREE.Color( 0x8cc7de );
32-
33-
//Renderer
34-
const container = document.querySelector( '#container' );
35-
const renderer = new THREE.WebGLRenderer( { antialias: true } );
36-
renderer.setSize( window.innerWidth, window.innerHeight );
37-
renderer.setPixelRatio( Math.min( window.devicePixelRatio, 2 ) );
38-
renderer.setAnimationLoop( animation );
39-
container.appendChild( renderer.domElement );
40-
41-
//Camera
42-
const camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 0.1, 1000 );
43-
camera.position.z = - 70;
44-
camera.position.y = 25;
45-
camera.position.x = 90;
46-
camera.lookAt( 0, 0, 0 );
47-
const controls = new OrbitControls( camera, renderer.domElement );
48-
49-
//Initial cube
50-
const geometry = new THREE.BoxGeometry();
51-
const material = new THREE.MeshPhongMaterial( { color: 0xffffff } );
52-
const cube = new THREE.Mesh( geometry, material );
53-
scene.add( cube );
54-
55-
//Lights
56-
const directionalLight1 = new THREE.DirectionalLight( 0xffeeff, 0.8 );
57-
directionalLight1.position.set( 1, 1, 1 );
58-
scene.add( directionalLight1 );
59-
const directionalLight2 = new THREE.DirectionalLight( 0xffffff, 0.8 );
60-
directionalLight2.position.set( - 1, 0.5, - 1 );
61-
scene.add( directionalLight2 );
62-
const ambientLight = new THREE.AmbientLight( 0xffffee, 0.25 );
63-
scene.add( ambientLight );
64-
65-
//Window resize support
66-
window.addEventListener( 'resize', () => {
28+
let scene, camera, renderer;
29+
30+
init();
31+
32+
function init() {
33+
34+
//Scene
35+
scene = new THREE.Scene();
36+
scene.background = new THREE.Color( 0x8cc7de );
37+
38+
//Camera
39+
camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 0.1, 1000 );
40+
camera.position.z = - 70;
41+
camera.position.y = 25;
42+
camera.position.x = 90;
43+
44+
//Initial cube
45+
const geometry = new THREE.BoxGeometry();
46+
const material = new THREE.MeshPhongMaterial( { color: 0xffffff } );
47+
const cube = new THREE.Mesh( geometry, material );
48+
scene.add( cube );
49+
50+
//Lights
51+
const directionalLight1 = new THREE.DirectionalLight( 0xffeeff, 0.8 );
52+
directionalLight1.position.set( 1, 1, 1 );
53+
scene.add( directionalLight1 );
54+
55+
const directionalLight2 = new THREE.DirectionalLight( 0xffffff, 0.8 );
56+
directionalLight2.position.set( - 1, 0.5, - 1 );
57+
scene.add( directionalLight2 );
58+
59+
const ambientLight = new THREE.AmbientLight( 0xffffee, 0.25 );
60+
scene.add( ambientLight );
61+
62+
//Setup IFC Loader
63+
const ifcLoader = new IFCLoader();
64+
ifcLoader.load( 'models/ifc/rac_advanced_sample_project.ifc', function ( model ) {
65+
66+
scene.add( model );
67+
render();
68+
69+
} );
70+
71+
//Renderer
72+
renderer = new THREE.WebGLRenderer( { antialias: true } );
73+
renderer.setSize( window.innerWidth, window.innerHeight );
74+
renderer.setPixelRatio( window.devicePixelRatio );
75+
document.body.appendChild( renderer.domElement );
76+
77+
//Controls
78+
const controls = new OrbitControls( camera, renderer.domElement );
79+
controls.addEventListener( 'change', render );
80+
81+
window.addEventListener( 'resize', onWindowResize );
82+
83+
render();
84+
85+
}
86+
87+
function onWindowResize() {
6788

6889
camera.aspect = window.innerWidth / window.innerHeight;
6990
camera.updateProjectionMatrix();
7091
renderer.setSize( window.innerWidth, window.innerHeight );
7192

72-
} );
93+
render();
7394

74-
//Setup IFC Loader
75-
const ifcLoader = new IFCLoader();
76-
77-
//Load IFC file
78-
ifcLoader.load( 'models/ifc/rac_advanced_sample_project.ifc', ( geometry ) => scene.add( geometry ) );
95+
}
7996

80-
//Animation
81-
function animation() {
97+
function render() {
8298

83-
controls.update();
8499
renderer.render( scene, camera );
85100

86101
}

0 commit comments

Comments
 (0)