Skip to content

Commit b8d8a86

Browse files
authored
Merge pull request #14119 from Mugen87/dev7
ParametricGeometry: Fix examples
2 parents c63bb30 + 5608b30 commit b8d8a86

File tree

5 files changed

+37
-38
lines changed

5 files changed

+37
-38
lines changed

examples/js/Cloth.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,36 +46,40 @@ var lastTime;
4646

4747
function plane( width, height ) {
4848

49-
return function ( u, v, optionalTarget ) {
50-
51-
var result = optionalTarget || new THREE.Vector3();
49+
return function ( u, v, target ) {
5250

5351
var x = ( u - 0.5 ) * width;
5452
var y = ( v + 0.5 ) * height;
5553
var z = 0;
5654

57-
return result.set( x, y, z );
55+
target.set( x, y, z );
5856

5957
};
6058

6159
}
6260

6361
function Particle( x, y, z, mass ) {
6462

65-
this.position = clothFunction( x, y ); // position
66-
this.previous = clothFunction( x, y ); // previous
67-
this.original = clothFunction( x, y );
63+
this.position = new THREE.Vector3();
64+
this.previous = new THREE.Vector3();
65+
this.original = new THREE.Vector3();
6866
this.a = new THREE.Vector3( 0, 0, 0 ); // acceleration
6967
this.mass = mass;
7068
this.invMass = 1 / mass;
7169
this.tmp = new THREE.Vector3();
7270
this.tmp2 = new THREE.Vector3();
7371

72+
// init
73+
74+
clothFunction( x, y, this.position ); // position
75+
clothFunction( x, y, this.previous ); // previous
76+
clothFunction( x, y, this.original );
77+
7478
}
7579

7680
// Force -> Acceleration
7781

78-
Particle.prototype.addForce = function( force ) {
82+
Particle.prototype.addForce = function ( force ) {
7983

8084
this.a.add(
8185
this.tmp2.copy( force ).multiplyScalar( this.invMass )
@@ -86,7 +90,7 @@ Particle.prototype.addForce = function( force ) {
8690

8791
// Performs Verlet integration
8892

89-
Particle.prototype.integrate = function( timesq ) {
93+
Particle.prototype.integrate = function ( timesq ) {
9094

9195
var newPos = this.tmp.subVectors( this.position, this.previous );
9296
newPos.multiplyScalar( DRAG ).add( this.position );
@@ -280,7 +284,7 @@ function simulate( time ) {
280284

281285
// Ball Constraints
282286

283-
ballPosition.z = - Math.sin( Date.now() / 600 ) * 90 ; //+ 40;
287+
ballPosition.z = - Math.sin( Date.now() / 600 ) * 90; //+ 40;
284288
ballPosition.x = Math.cos( Date.now() / 400 ) * 70;
285289

286290
if ( sphere.visible ) {

examples/js/ParametricGeometries.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ THREE.ParametricGeometries = {
2828

2929
y = - 2 * ( 1 - Math.cos( u ) / 2 ) * Math.sin( v );
3030

31-
return target.set( x, y, z );
31+
target.set( x, y, z );
3232

3333
},
3434

@@ -40,7 +40,7 @@ THREE.ParametricGeometries = {
4040
var y = 0;
4141
var z = v * height;
4242

43-
return target.set( x, y, z );
43+
target.set( x, y, z );
4444

4545
};
4646

@@ -61,7 +61,7 @@ THREE.ParametricGeometries = {
6161
y = Math.sin( v ) * ( a + u * Math.cos( v / 2 ) );
6262
z = u * Math.sin( v / 2 );
6363

64-
return target.set( x, y, z );
64+
target.set( x, y, z );
6565

6666
},
6767

@@ -83,7 +83,7 @@ THREE.ParametricGeometries = {
8383
y = ( major + x ) * Math.sin( u );
8484
x = ( major + x ) * Math.cos( u );
8585

86-
return target.set( x, y, z );
86+
target.set( x, y, z );
8787

8888
}
8989

@@ -146,7 +146,7 @@ THREE.ParametricGeometries.TubeGeometry = function ( path, segments, radius, seg
146146
pos.y += cx * normal.y + cy * binormal.y;
147147
pos.z += cx * normal.z + cy * binormal.z;
148148

149-
return target.copy( pos );
149+
target.copy( pos );
150150

151151
};
152152

@@ -225,7 +225,7 @@ THREE.ParametricGeometries.SphereGeometry = function ( size, u, v ) {
225225
var y = size * Math.sin( u ) * Math.sin( v );
226226
var z = size * Math.cos( u );
227227

228-
return target.set( x, y, z );
228+
target.set( x, y, z );
229229

230230
}
231231

@@ -251,7 +251,7 @@ THREE.ParametricGeometries.PlaneGeometry = function ( width, depth, segmentsWidt
251251
var y = 0;
252252
var z = v * depth;
253253

254-
return target.set( x, y, z );
254+
target.set( x, y, z );
255255

256256
}
257257

examples/js/curves/NURBSSurface.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,12 @@ THREE.NURBSSurface.prototype = {
4242

4343
constructor: THREE.NURBSSurface,
4444

45-
getPoint: function ( t1, t2 ) {
45+
getPoint: function ( t1, t2, target ) {
4646

4747
var u = this.knots1[ 0 ] + t1 * ( this.knots1[ this.knots1.length - 1 ] - this.knots1[ 0 ] ); // linear mapping t1->u
4848
var v = this.knots2[ 0 ] + t2 * ( this.knots2[ this.knots2.length - 1 ] - this.knots2[ 0 ] ); // linear mapping t2->u
4949

50-
return THREE.NURBSUtils.calcSurfacePoint( this.degree1, this.degree2, this.knots1, this.knots2, this.controlPoints, u, v );
50+
THREE.NURBSUtils.calcSurfacePoint( this.degree1, this.degree2, this.knots1, this.knots2, this.controlPoints, u, v, target );
5151

5252
}
5353
};
54-
55-

examples/js/curves/NURBSUtils.js

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ THREE.NURBSUtils = {
1919
p : degree
2020
u : parametric value
2121
U : knot vector
22-
22+
2323
returns the span
2424
*/
2525
findSpan: function( p, u, U ) {
@@ -43,7 +43,7 @@ THREE.NURBSUtils = {
4343
var mid = Math.floor( ( low + high ) / 2 );
4444

4545
while ( u < U[ mid ] || u >= U[ mid + 1 ] ) {
46-
46+
4747
if ( u < U[ mid ] ) {
4848

4949
high = mid;
@@ -61,16 +61,16 @@ THREE.NURBSUtils = {
6161
return mid;
6262

6363
},
64-
65-
64+
65+
6666
/*
6767
Calculate basis functions. See The NURBS Book, page 70, algorithm A2.2
68-
68+
6969
span : span in which u lies
7070
u : parametric point
7171
p : degree
7272
U : knot vector
73-
73+
7474
returns array[p+1] with basis functions values.
7575
*/
7676
calcBasisFunctions: function( span, u, p, U ) {
@@ -81,7 +81,7 @@ THREE.NURBSUtils = {
8181
N[ 0 ] = 1.0;
8282

8383
for ( var j = 1; j <= p; ++ j ) {
84-
84+
8585
left[ j ] = u - U[ span + 1 - j ];
8686
right[ j ] = U[ span + j ] - u;
8787

@@ -108,7 +108,7 @@ THREE.NURBSUtils = {
108108

109109
/*
110110
Calculate B-Spline curve points. See The NURBS Book, page 82, algorithm A3.1.
111-
111+
112112
p : degree of B-Spline
113113
U : knot vector
114114
P : control points (x, y, z, w)
@@ -422,15 +422,15 @@ THREE.NURBSUtils = {
422422

423423
/*
424424
Calculate rational B-Spline surface point. See The NURBS Book, page 134, algorithm A4.3.
425-
425+
426426
p1, p2 : degrees of B-Spline surface
427427
U1, U2 : knot vectors
428428
P : control points (x, y, z, w)
429429
u, v : parametric values
430430
431431
returns point for given (u, v)
432432
*/
433-
calcSurfacePoint: function( p, q, U, V, P, u, v ) {
433+
calcSurfacePoint: function ( p, q, U, V, P, u, v, target ) {
434434

435435
var uspan = this.findSpan( p, u, U );
436436
var vspan = this.findSpan( q, v, V );
@@ -462,11 +462,8 @@ THREE.NURBSUtils = {
462462
}
463463

464464
Sw.divideScalar( Sw.w );
465-
return new THREE.Vector3( Sw.x, Sw.y, Sw.z );
465+
target.set( Sw.x, Sw.y, Sw.z );
466466

467467
}
468468

469469
};
470-
471-
472-

examples/webgl_geometry_nurbs.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868

6969
scene = new THREE.Scene();
7070
scene.background = new THREE.Color( 0xf0f0f0 );
71-
71+
7272
scene.add( new THREE.AmbientLight( 0x808080 ) );
7373

7474
var light = new THREE.DirectionalLight( 0xffffff, 1 );
@@ -159,9 +159,9 @@
159159
map.wrapS = map.wrapT = THREE.RepeatWrapping;
160160
map.anisotropy = 16;
161161

162-
function getSurfacePoint( u, v ) {
162+
function getSurfacePoint( u, v, target ) {
163163

164-
return nurbsSurface.getPoint( u, v );
164+
return nurbsSurface.getPoint( u, v, target );
165165

166166
}
167167

0 commit comments

Comments
 (0)