-
Notifications
You must be signed in to change notification settings - Fork 0
/
primary.js
61 lines (51 loc) · 1.64 KB
/
primary.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
import * as THREE from 'three';
import HullComponent from './hull_component.js';
export default class Primary extends HullComponent{
constructor({ material }) {
super();
this.material = material;
this.group = new THREE.Group();
this.group.rotateX( Math.PI / 2.0);
this.geometry = {};
this.mesh = {}
this.dimensions = {};
return this;
}
update({
thickness,
radius,
widthRatio
}) {
this.clear();
var points = [];
const saucerPointCount = 20;
for ( var i = 0; i <= saucerPointCount; i ++ ) {
points.push(
new THREE.Vector2(
Math.sin( i / saucerPointCount * Math.PI ) * radius,
i / saucerPointCount * thickness
)
);
}
const foreExclusionAngle = 0.0;
this.geometry = new THREE.LatheGeometry(points, 64, Math.PI + foreExclusionAngle, 2.0 * ( Math.PI - foreExclusionAngle) );
this.geometry.scale(widthRatio, 1.0, 1.0);
this.computeBoundingBox(this.geometry);
this.mesh = new THREE.Mesh( this.geometry, this.material.clone() );
this.group.add( this.mesh );
}
computeBoundingBox(measuredGeom) {
measuredGeom.computeBoundingBox();
this.dimensions.x = measuredGeom.boundingBox.max.x - measuredGeom.boundingBox.min.x;
this.dimensions.y = measuredGeom.boundingBox.max.y - measuredGeom.boundingBox.min.y;
this.dimensions.z = measuredGeom.boundingBox.max.z - measuredGeom.boundingBox.min.z;
}
clear(){
if (this.geometry['dispose']) {
this.geometry.dispose();
for (var i = this.group.children.length - 1; i >= 0; i--) {
this.group.remove(this.group.children[i]);
}
}
}
}