-
-
Notifications
You must be signed in to change notification settings - Fork 35.7k
/
Copy paththreejs-cameras.js
84 lines (65 loc) · 1.87 KB
/
threejs-cameras.js
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import * as THREE from 'three';
import { threejsLessonUtils } from './threejs-lesson-utils.js';
{
function addShape( color, geometry ) {
const material = new THREE.MeshPhongMaterial( { color } );
return new THREE.Mesh( geometry, material );
}
threejsLessonUtils.addDiagrams( {
shapeCube: {
create() {
const width = 8;
const height = 8;
const depth = 8;
return addShape( 'hsl(150,100%,40%)', new THREE.BoxGeometry( width, height, depth ) );
},
},
shapeCone: {
create() {
const radius = 6;
const height = 8;
const segments = 24;
return addShape( 'hsl(160,100%,40%)', new THREE.ConeGeometry( radius, height, segments ) );
},
},
shapeCylinder: {
create() {
const radiusTop = 4;
const radiusBottom = 4;
const height = 8;
const radialSegments = 24;
return addShape( 'hsl(170,100%,40%)', new THREE.CylinderGeometry( radiusTop, radiusBottom, height, radialSegments ) );
},
},
shapeSphere: {
create() {
const radius = 5;
const widthSegments = 24;
const heightSegments = 16;
return addShape( 'hsl(180,100%,40%)', new THREE.SphereGeometry( radius, widthSegments, heightSegments ) );
},
},
shapeFrustum: {
create() {
const width = 8;
const height = 8;
const depth = 8;
const geometry = new THREE.BoxGeometry( width, height, depth );
const perspMat = new THREE.Matrix4();
perspMat.makePerspective( - 3, 3, - 3, 3, 4, 12 );
const inMat = new THREE.Matrix4();
inMat.makeTranslation( 0, 0, 8 );
const mat = new THREE.Matrix4();
mat.multiply( perspMat );
mat.multiply( inMat );
geometry.applyMatrix4( mat );
geometry.computeBoundingBox();
geometry.center();
geometry.scale( 3, 3, 3 );
geometry.rotateY( Math.PI );
geometry.computeVertexNormals();
return addShape( 'hsl(190,100%,40%)', geometry );
},
},
} );
}