Skip to content
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

Examples: Clean up. #21552

Merged
merged 2 commits into from
Mar 31, 2021
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion examples/jsm/loaders/IFCLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
InterleavedBuffer,
InterleavedBufferAttribute,
BufferAttribute,
} from '../../../../build/three.module.js';
} from '../../../build/three.module.js';
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ops! Can't wait for Import Maps...


var ifcAPI = new IfcAPI();

Expand Down
111 changes: 63 additions & 48 deletions examples/webgl_loader_ifc.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
</head>

<body>
<div id="container"></div>
<div id="info">
<a href="https://threejs.org" target="_blank" rel="noopener">three.js</a>
-
Expand All @@ -26,61 +25,77 @@

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

//Scene
const scene = new THREE.Scene();
scene.background = new THREE.Color( 0x8cc7de );

//Renderer
const container = document.querySelector( '#container' );
const renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setPixelRatio( Math.min( window.devicePixelRatio, 2 ) );
renderer.setAnimationLoop( animation );
container.appendChild( renderer.domElement );

//Camera
const camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 0.1, 1000 );
camera.position.z = - 70;
camera.position.y = 25;
camera.position.x = 90;
camera.lookAt( 0, 0, 0 );
const controls = new OrbitControls( camera, renderer.domElement );

//Initial cube
const geometry = new THREE.BoxGeometry();
const material = new THREE.MeshPhongMaterial( { color: 0xffffff } );
const cube = new THREE.Mesh( geometry, material );
scene.add( cube );

//Lights
const directionalLight1 = new THREE.DirectionalLight( 0xffeeff, 0.8 );
directionalLight1.position.set( 1, 1, 1 );
scene.add( directionalLight1 );
const directionalLight2 = new THREE.DirectionalLight( 0xffffff, 0.8 );
directionalLight2.position.set( - 1, 0.5, - 1 );
scene.add( directionalLight2 );
const ambientLight = new THREE.AmbientLight( 0xffffee, 0.25 );
scene.add( ambientLight );

//Window resize support
window.addEventListener( 'resize', () => {
let scene, camera, renderer;

init();

function init() {

//Scene
scene = new THREE.Scene();
scene.background = new THREE.Color( 0x8cc7de );

//Camera
camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 0.1, 1000 );
camera.position.z = - 70;
camera.position.y = 25;
camera.position.x = 90;

//Initial cube
const geometry = new THREE.BoxGeometry();
const material = new THREE.MeshPhongMaterial( { color: 0xffffff } );
const cube = new THREE.Mesh( geometry, material );
scene.add( cube );

//Lights
const directionalLight1 = new THREE.DirectionalLight( 0xffeeff, 0.8 );
directionalLight1.position.set( 1, 1, 1 );
scene.add( directionalLight1 );

const directionalLight2 = new THREE.DirectionalLight( 0xffffff, 0.8 );
directionalLight2.position.set( - 1, 0.5, - 1 );
scene.add( directionalLight2 );

const ambientLight = new THREE.AmbientLight( 0xffffee, 0.25 );
scene.add( ambientLight );

//Setup IFC Loader
const ifcLoader = new IFCLoader();
ifcLoader.load( 'models/ifc/rac_advanced_sample_project.ifc', function ( model ) {

scene.add( model );
render();

} );

//Renderer
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setPixelRatio( window.devicePixelRatio );
document.body.appendChild( renderer.domElement );

//Controls
const controls = new OrbitControls( camera, renderer.domElement );
controls.addEventListener( 'change', render );

window.addEventListener( 'resize', onWindowResize );

render();

}

function onWindowResize() {

camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );

} );
render();

//Setup IFC Loader
const ifcLoader = new IFCLoader();

//Load IFC file
ifcLoader.load( 'models/ifc/rac_advanced_sample_project.ifc', ( geometry ) => scene.add( geometry ) );
}

//Animation
function animation() {
function render() {

controls.update();
renderer.render( scene, camera );

}
Expand Down