-
Notifications
You must be signed in to change notification settings - Fork 0
/
MySimpleNurbsBuilder.js
123 lines (56 loc) · 2.13 KB
/
MySimpleNurbsBuilder.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import * as THREE from 'three';
import { MyAxis } from './MyAxis.js';
import { NURBSSurface } from 'three/addons/curves/NURBSSurface.js';
import { ParametricGeometry } from 'three/addons/geometries/ParametricGeometry.js';
/**
* This class contains the contents of out application
*/
class MySimpleNurbsBuilder {
/**
constructs the object
@param {MyApp} app The application object
*/
constructor(app) {
this.app = app
}
build(controlPoints, degree1, degree2, samples1, samples2, material) {
const knots1 = []
const knots2 = []
// build knots1 = [ 0, 0, 0, 1, 1, 1 ];
for (var i = 0; i <= degree1; i++) {
knots1.push(0)
}
for (var i = 0; i <= degree1; i++) {
knots1.push(1)
}
// build knots2 = [ 0, 0, 0, 0, 1, 1, 1, 1 ];
for (var i = 0; i <= degree2; i++) {
knots2.push(0)
}
for (var i = 0; i <= degree2; i++) {
knots2.push(1)
}
let stackedPoints = []
console.log("Control Points: ", controlPoints)
for (var i = 0; i < controlPoints.length; i++) {
let row = controlPoints[i]
let newRow = []
for (var j = 0; j < row.length; j++) {
let item = row[j]
newRow.push(new THREE.Vector4(item[0],
item[1], item[2], item[3]));
}
stackedPoints[i] = newRow;
}
console.log("Stacked: ", stackedPoints)
const nurbsSurface = new NURBSSurface( degree1, degree2,
knots1, knots2, stackedPoints );
const geometry = new ParametricGeometry( getSurfacePoint,
samples1, samples2 );
return geometry;
function getSurfacePoint( u, v, target ) {
return nurbsSurface.getPoint( u, v, target );
}
}
}
export { MySimpleNurbsBuilder };