Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Geometries: Move to ES6 classes. #17425

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
178 changes: 91 additions & 87 deletions examples/jsm/geometries/ParametricGeometries.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import {
Curve,
Geometry,
ParametricGeometry,
Vector3
} from "../../../build/three.module.js";
Expand Down Expand Up @@ -103,162 +102,167 @@ var ParametricGeometries = {
*
*********************************************/

ParametricGeometries.TubeGeometry = function ( path, segments, radius, segmentsRadius, closed ) {
class ParametricTubeGeometry extends ParametricGeometry {

this.path = path;
this.segments = segments || 64;
this.radius = radius || 1;
this.segmentsRadius = segmentsRadius || 8;
this.closed = closed || false;
constructor( path, segments, radius, segmentsRadius, closed ) {

var scope = this, numpoints = this.segments + 1;
var frames = path.computeFrenetFrames( segments, closed ),
tangents = frames.tangents,
normals = frames.normals,
binormals = frames.binormals;

var frames = path.computeFrenetFrames( segments, closed ),
tangents = frames.tangents,
normals = frames.normals,
binormals = frames.binormals;
var position = new Vector3();

// proxy internals
var ParametricTube = function ( u, v, target ) {

this.tangents = tangents;
this.normals = normals;
this.binormals = binormals;
v *= 2 * Math.PI;

var position = new Vector3();
var i = u * segments;
i = Math.floor( i );

var ParametricTube = function ( u, v, target ) {
path.getPointAt( u, position );

v *= 2 * Math.PI;
var normal = normals[ i ];
var binormal = binormals[ i ];

var i = u * ( numpoints - 1 );
i = Math.floor( i );
var cx = radius * Math.cos( v ); // TODO: Hack: Negating it so it faces outside.
var cy = radius * Math.sin( v );

path.getPointAt( u, position );
position.x += cx * normal.x + cy * binormal.x;
position.y += cx * normal.y + cy * binormal.y;
position.z += cx * normal.z + cy * binormal.z;

var normal = normals[ i ];
var binormal = binormals[ i ];
target.copy( position );

var cx = - scope.radius * Math.cos( v ); // TODO: Hack: Negating it so it faces outside.
var cy = scope.radius * Math.sin( v );
};

position.x += cx * normal.x + cy * binormal.x;
position.y += cx * normal.y + cy * binormal.y;
position.z += cx * normal.z + cy * binormal.z;
super( ParametricTube, segments, segmentsRadius );

target.copy( position );
this.path = path;
this.segments = segments || 64;
this.radius = radius || 1;
this.segmentsRadius = segmentsRadius || 8;
this.closed = closed || false;

};
// proxy internals

ParametricGeometry.call( this, ParametricTube, segments, segmentsRadius );
this.tangents = tangents;
this.normals = normals;
this.binormals = binormals;

};
}

ParametricGeometries.TubeGeometry.prototype = Object.create( Geometry.prototype );
ParametricGeometries.TubeGeometry.prototype.constructor = ParametricGeometries.TubeGeometry;
}

ParametricGeometries.TubeGeometry = ParametricTubeGeometry;


/*********************************************
*
* Parametric Replacement for TorusKnotGeometry
*
*********************************************/
ParametricGeometries.TorusKnotGeometry = function ( radius, tube, segmentsT, segmentsR, p, q ) {

this.radius = radius || 200;
this.tube = tube || 40;
this.segmentsT = segmentsT || 64;
this.segmentsR = segmentsR || 8;
this.p = p || 2;
this.q = q || 3;
class ParametricTorusKnotGeometry extends ParametricTubeGeometry {

function TorusKnotCurve() {
constructor( radius, tube, segmentsT, segmentsR, p, q ) {

Curve.call( this );
class TorusKnotCurve extends Curve {

}
getPoint( t, optionalTarget ) {

TorusKnotCurve.prototype = Object.create( Curve.prototype );
TorusKnotCurve.prototype.constructor = TorusKnotCurve;
var point = optionalTarget || new Vector3();

TorusKnotCurve.prototype.getPoint = function ( t, optionalTarget ) {
t *= Math.PI * 2;

var point = optionalTarget || new Vector3();
var r = 0.5;

t *= Math.PI * 2;
var x = ( 1 + r * Math.cos( q * t ) ) * Math.cos( p * t );
var y = ( 1 + r * Math.cos( q * t ) ) * Math.sin( p * t );
var z = r * Math.sin( q * t );

var r = 0.5;
return point.set( x, y, z ).multiplyScalar( radius );

var x = ( 1 + r * Math.cos( q * t ) ) * Math.cos( p * t );
var y = ( 1 + r * Math.cos( q * t ) ) * Math.sin( p * t );
var z = r * Math.sin( q * t );
}

return point.set( x, y, z ).multiplyScalar( radius );
}

};
var segments = segmentsT;
var radiusSegments = segmentsR;
var extrudePath = new TorusKnotCurve();

var segments = segmentsT;
var radiusSegments = segmentsR;
var extrudePath = new TorusKnotCurve();
super( extrudePath, segments, tube, radiusSegments, true, false );

ParametricGeometries.TubeGeometry.call( this, extrudePath, segments, tube, radiusSegments, true, false );
this.radius = radius || 200;
this.tube = tube || 40;
this.segmentsT = segmentsT || 64;
this.segmentsR = segmentsR || 8;
this.p = p || 2;
this.q = q || 3;

};
}

ParametricGeometries.TorusKnotGeometry.prototype = Object.create( Geometry.prototype );
ParametricGeometries.TorusKnotGeometry.prototype.constructor = ParametricGeometries.TorusKnotGeometry;
}

ParametricGeometries.TorusKnotGeometry = ParametricTorusKnotGeometry;

/*********************************************
*
* Parametric Replacement for SphereGeometry
*
*********************************************/
ParametricGeometries.SphereGeometry = function ( size, u, v ) {

function sphere( u, v, target ) {
class ParametricSphereGeometry extends ParametricGeometry {

u *= Math.PI;
v *= 2 * Math.PI;
constructor( size, u, v ) {

var x = size * Math.sin( u ) * Math.cos( v );
var y = size * Math.sin( u ) * Math.sin( v );
var z = size * Math.cos( u );
function sphere( u, v, target ) {

target.set( x, y, z );
u *= Math.PI;
v *= 2 * Math.PI;

}
var x = size * Math.sin( u ) * Math.cos( v );
var y = size * Math.sin( u ) * Math.sin( v );
var z = size * Math.cos( u );

ParametricGeometry.call( this, sphere, u, v );
target.set( x, y, z );

};
}

super( sphere, u, v );

}

ParametricGeometries.SphereGeometry.prototype = Object.create( Geometry.prototype );
ParametricGeometries.SphereGeometry.prototype.constructor = ParametricGeometries.SphereGeometry;
}

ParametricGeometries.SphereGeometry = ParametricSphereGeometry;

/*********************************************
*
* Parametric Replacement for PlaneGeometry
*
*********************************************/

ParametricGeometries.PlaneGeometry = function ( width, depth, segmentsWidth, segmentsDepth ) {
class ParametricPlaneGeometry extends ParametricGeometry {

function plane( u, v, target ) {
constructor( width, depth, segmentsWidth, segmentsDepth ) {

var x = u * width;
var y = 0;
var z = v * depth;
function plane( u, v, target ) {

target.set( x, y, z );
var x = u * width;
var y = 0;
var z = v * depth;

}
target.set( x, y, z );

ParametricGeometry.call( this, plane, segmentsWidth, segmentsDepth );
}

};
super( plane, segmentsWidth, segmentsDepth );

}

}

ParametricGeometries.PlaneGeometry.prototype = Object.create( Geometry.prototype );
ParametricGeometries.PlaneGeometry.prototype.constructor = ParametricGeometries.PlaneGeometry;
ParametricGeometries.PlaneGeometry = ParametricPlaneGeometry;

export { ParametricGeometries };
Loading