forked from iaac-macad-s1/lecture2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
62 lines (43 loc) · 1.88 KB
/
Copy pathscript.js
File metadata and controls
62 lines (43 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Import libraries
import * as THREE from 'https://cdn.jsdelivr.net/npm/three@0.124.0/build/three.module.js'
import { OrbitControls } from 'https://cdn.jsdelivr.net/npm/three@0.124.0/examples/jsm/controls/OrbitControls.js'
import { Rhino3dmLoader } from 'https://cdn.jsdelivr.net/npm/three@0.124.0/examples/jsm/loaders/3DMLoader.js'
// declare variables to store scene, camera, and renderer
let scene, camera, renderer
const model = 'Rhino_Logo.3dm'
// call functions
init()
animate()
// function to setup the scene, camera, renderer, and load 3d model
function init () {
// Rhino models are z-up, so set this as the default
THREE.Object3D.DefaultUp = new THREE.Vector3( 0, 0, 1 )
// create a scene and a camera
scene = new THREE.Scene()
scene.background = new THREE.Color(1,1,1)
camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 )
camera.position.y = - 30
// create the renderer and add it to the html
renderer = new THREE.WebGLRenderer( { antialias: true } )
renderer.setSize( window.innerWidth, window.innerHeight )
document.body.appendChild( renderer.domElement )
// add some controls to orbit the camera
const controls = new OrbitControls( camera, renderer.domElement )
// add a directional light
const directionalLight = new THREE.DirectionalLight( 0xffffff )
directionalLight.intensity = 2
scene.add( directionalLight )
// load the model
const loader = new Rhino3dmLoader()
loader.setLibraryPath( 'https://cdn.jsdelivr.net/npm/rhino3dm@0.13.0/' )
loader.load( model, function ( object ) {
// uncomment to hide spinner when model loads
// document.getElementById('loader').remove()
scene.add( object )
} )
}
// function to continuously render the scene
function animate() {
requestAnimationFrame( animate )
renderer.render( scene, camera )
}