Skip to content

Commit 2fb6398

Browse files
committed
Fix lines
1 parent 602da29 commit 2fb6398

File tree

4 files changed

+96
-59
lines changed

4 files changed

+96
-59
lines changed

build/whs.js

+26-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/whs.module.js

+26-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/basic/line/script.js

+37-25
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const app = new WHS.App([
1010
controlsModule
1111
]);
1212

13-
controlsModule.controls.autoRotate = true;
13+
// controlsModule.controls.autoRotate = true;
1414

1515
const yPadding = 2;
1616
const xzPadding = 1;
@@ -36,10 +36,12 @@ function drawRectangle(points, color) {
3636
// join the bottom points
3737
for (let i = 0; i < points.length - 1; i++) {
3838
const line = new WHS.Line({
39-
geometry: {
40-
start: new THREE.Vector3(points[i].x, points[i].y, points[i].z),
41-
end: new THREE.Vector3(points[i + 1].x, points[i + 1].y, points[i + 1].z)
42-
},
39+
curve: new THREE.LineCurve3(
40+
new THREE.Vector3(points[i].x, points[i].y, points[i].z),
41+
new THREE.Vector3(points[i + 1].x, points[i + 1].y, points[i + 1].z)
42+
),
43+
44+
points: 2,
4345

4446
material: new THREE.LineBasicMaterial({
4547
color
@@ -52,10 +54,12 @@ function drawRectangle(points, color) {
5254
// top square
5355
for (let i = 0; i < points.length - 1; i++) {
5456
const line = new WHS.Line({
55-
geometry: {
56-
start: new THREE.Vector3(points[i].x, points[i].y + yDist, points[i].z),
57-
end: new THREE.Vector3(points[i + 1].x, points[i + 1].y + yDist, points[i + 1].z)
58-
},
57+
curve: new THREE.LineCurve3(
58+
new THREE.Vector3(points[i].x, points[i].y + yDist, points[i].z),
59+
new THREE.Vector3(points[i + 1].x, points[i + 1].y + yDist, points[i + 1].z)
60+
),
61+
62+
points: 2,
5963

6064
material: new THREE.LineBasicMaterial({
6165
color
@@ -67,17 +71,19 @@ function drawRectangle(points, color) {
6771

6872
// closes the top square
6973
const line2 = new WHS.Line({
70-
geometry: {
71-
start: new THREE.Vector3(
74+
curve: new THREE.LineCurve3(
75+
new THREE.Vector3(
7276
points[points.length - 1].x,
7377
points[points.length - 1].y + yDist,
7478
points[points.length - 1].z),
7579

76-
end: new THREE.Vector3(
80+
new THREE.Vector3(
7781
points[0].x,
7882
points[0].y + yDist,
7983
points[0].z)
80-
},
84+
),
85+
86+
points: 2,
8187

8288
material: new THREE.LineBasicMaterial({
8389
color
@@ -87,10 +93,12 @@ function drawRectangle(points, color) {
8793

8894
// closes the bottom square
8995
const line = new WHS.Line({
90-
geometry: {
91-
start: new THREE.Vector3(points[points.length - 1].x, points[points.length - 1].y, points[points.length - 1].z),
92-
end: new THREE.Vector3(points[0].x, points[0].y, points[0].z)
93-
},
96+
curve: new THREE.LineCurve3(
97+
new THREE.Vector3(points[points.length - 1].x, points[points.length - 1].y, points[points.length - 1].z),
98+
new THREE.Vector3(points[0].x, points[0].y, points[0].z)
99+
),
100+
101+
points: 2,
94102

95103
material: new THREE.LineBasicMaterial({
96104
color
@@ -101,10 +109,12 @@ function drawRectangle(points, color) {
101109
// vertical join
102110
for (let i = 0; i < points.length - 1; i++) {
103111
const line = new WHS.Line({
104-
geometry: {
105-
start: new THREE.Vector3(points[i].x, points[i].y, points[i].z),
106-
end: new THREE.Vector3(points[i].x, points[i + 1].y + yDist, points[i].z)
107-
},
112+
curve: new THREE.LineCurve3(
113+
new THREE.Vector3(points[i].x, points[i].y, points[i].z),
114+
new THREE.Vector3(points[i].x, points[i + 1].y + yDist, points[i].z)
115+
),
116+
117+
points: 2,
108118

109119
material: new THREE.LineBasicMaterial({
110120
color
@@ -115,10 +125,12 @@ function drawRectangle(points, color) {
115125
}
116126
// closes the vertical one
117127
const line3 = new WHS.Line({
118-
geometry: {
119-
start: new THREE.Vector3(points[points.length - 1].x, points[points.length - 1].y, points[points.length - 1].z),
120-
end: new THREE.Vector3(points[3].x, points[3].y + yDist, points[3].z)
121-
},
128+
curve: new THREE.LineCurve3(
129+
new THREE.Vector3(points[points.length - 1].x, points[points.length - 1].y, points[points.length - 1].z),
130+
new THREE.Vector3(points[3].x, points[3].y + yDist, points[3].z)
131+
),
132+
133+
points: 2,
122134

123135
material: new THREE.LineBasicMaterial({
124136
color

src/components/meshes/Line.js

+7-10
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,16 @@ class Line extends MeshComponent {
3434
* @static
3535
* @default <pre>
3636
* {
37-
* geometry: {
38-
* curve: new LineCurve3(new Vector3(0, 0, 0), new Vector3(10, 0, 0)),
39-
* points: 50
40-
* }
37+
* curve: new LineCurve3(new Vector3(0, 0, 0), new Vector3(10, 0, 0)),
38+
* points: 50
4139
* }
4240
* </pre>
4341
*/
4442
static defaults = {
4543
...MeshComponent.defaults,
46-
geometry: {
47-
curve: new LineCurve3(new Vector3(0, 0, 0), new Vector3(10, 0, 0)),
48-
points: 50
49-
}
44+
45+
curve: null,
46+
points: 50
5047
};
5148

5249
/**
@@ -87,7 +84,7 @@ class Line extends MeshComponent {
8784
const geometry = params.buffer ? new BufferGeometry() : new Geometry();
8885

8986
if (params.buffer) {
90-
const pp = params.geometry.curve.getPoints(params.geometry.points);
87+
const pp = params.curve.getPoints(params.points);
9188
const verts = new Float32Array(pp.length * 3);
9289

9390
for (let i = 0, max = pp.length; i < max; i++) {
@@ -99,7 +96,7 @@ class Line extends MeshComponent {
9996
}
10097

10198
geometry.addAttribute('position', new BufferAttribute(verts, 3));
102-
} else geometry.vertices = params.geometry.curve.getPoints(params.geometry.points);
99+
} else geometry.vertices = params.curve.getPoints(params.points);
103100

104101
return geometry;
105102
}

0 commit comments

Comments
 (0)