|
|
@@ -5,98 +5,13 @@ import {
|
|
|
|
|
|
import { ParametricGeometry } from './ParametricGeometry.js';
|
|
|
|
|
|
-/**
|
|
|
- * Experimenting of primitive geometry creation using Surface Parametric equations
|
|
|
- */
|
|
|
-
|
|
|
-const ParametricGeometries = {
|
|
|
-
|
|
|
- klein: function ( v, u, target ) {
|
|
|
-
|
|
|
- u *= Math.PI;
|
|
|
- v *= 2 * Math.PI;
|
|
|
-
|
|
|
- u = u * 2;
|
|
|
- let x, z;
|
|
|
- if ( u < Math.PI ) {
|
|
|
-
|
|
|
- x = 3 * Math.cos( u ) * ( 1 + Math.sin( u ) ) + ( 2 * ( 1 - Math.cos( u ) / 2 ) ) * Math.cos( u ) * Math.cos( v );
|
|
|
- z = - 8 * Math.sin( u ) - 2 * ( 1 - Math.cos( u ) / 2 ) * Math.sin( u ) * Math.cos( v );
|
|
|
-
|
|
|
- } else {
|
|
|
-
|
|
|
- x = 3 * Math.cos( u ) * ( 1 + Math.sin( u ) ) + ( 2 * ( 1 - Math.cos( u ) / 2 ) ) * Math.cos( v + Math.PI );
|
|
|
- z = - 8 * Math.sin( u );
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- const y = - 2 * ( 1 - Math.cos( u ) / 2 ) * Math.sin( v );
|
|
|
-
|
|
|
- target.set( x, y, z );
|
|
|
-
|
|
|
- },
|
|
|
-
|
|
|
- plane: function ( width, height ) {
|
|
|
-
|
|
|
- return function ( u, v, target ) {
|
|
|
-
|
|
|
- const x = u * width;
|
|
|
- const y = 0;
|
|
|
- const z = v * height;
|
|
|
-
|
|
|
- target.set( x, y, z );
|
|
|
-
|
|
|
- };
|
|
|
-
|
|
|
- },
|
|
|
-
|
|
|
- mobius: function ( u, t, target ) {
|
|
|
-
|
|
|
- // flat mobius strip
|
|
|
- // http://www.wolframalpha.com/input/?i=M%C3%B6bius+strip+parametric+equations&lk=1&a=ClashPrefs_*Surface.MoebiusStrip.SurfaceProperty.ParametricEquations-
|
|
|
- u = u - 0.5;
|
|
|
- const v = 2 * Math.PI * t;
|
|
|
-
|
|
|
- const a = 2;
|
|
|
-
|
|
|
- const x = Math.cos( v ) * ( a + u * Math.cos( v / 2 ) );
|
|
|
- const y = Math.sin( v ) * ( a + u * Math.cos( v / 2 ) );
|
|
|
- const z = u * Math.sin( v / 2 );
|
|
|
-
|
|
|
- target.set( x, y, z );
|
|
|
-
|
|
|
- },
|
|
|
-
|
|
|
- mobius3d: function ( u, t, target ) {
|
|
|
-
|
|
|
- // volumetric mobius strip
|
|
|
-
|
|
|
- u *= Math.PI;
|
|
|
- t *= 2 * Math.PI;
|
|
|
-
|
|
|
- u = u * 2;
|
|
|
- const phi = u / 2;
|
|
|
- const major = 2.25, a = 0.125, b = 0.65;
|
|
|
-
|
|
|
- let x = a * Math.cos( t ) * Math.cos( phi ) - b * Math.sin( t ) * Math.sin( phi );
|
|
|
- const z = a * Math.cos( t ) * Math.sin( phi ) + b * Math.sin( t ) * Math.cos( phi );
|
|
|
- const y = ( major + x ) * Math.sin( u );
|
|
|
- x = ( major + x ) * Math.cos( u );
|
|
|
-
|
|
|
- target.set( x, y, z );
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-};
|
|
|
-
|
|
|
|
|
|
/*********************************************
|
|
|
*
|
|
|
* Parametric Replacement for TubeGeometry
|
|
|
*
|
|
|
*********************************************/
|
|
|
-
|
|
|
-ParametricGeometries.TubeGeometry = class TubeGeometry extends ParametricGeometry {
|
|
|
+class ParametricTubeGeometry extends ParametricGeometry {
|
|
|
|
|
|
constructor( path, segments = 64, radius = 1, segmentsRadius = 8, closed = false ) {
|
|
|
|
|
|
@@ -147,7 +62,7 @@ ParametricGeometries.TubeGeometry = class TubeGeometry extends ParametricGeometr
|
|
|
|
|
|
}
|
|
|
|
|
|
-};
|
|
|
+}
|
|
|
|
|
|
|
|
|
/*********************************************
|
|
|
@@ -155,7 +70,7 @@ ParametricGeometries.TubeGeometry = class TubeGeometry extends ParametricGeometr
|
|
|
* Parametric Replacement for TorusKnotGeometry
|
|
|
*
|
|
|
*********************************************/
|
|
|
-ParametricGeometries.TorusKnotGeometry = class TorusKnotGeometry extends ParametricGeometries.TubeGeometry {
|
|
|
+class ParametricTorusKnotGeometry extends ParametricTubeGeometry {
|
|
|
|
|
|
constructor( radius = 200, tube = 40, segmentsT = 64, segmentsR = 8, p = 2, q = 3 ) {
|
|
|
|
|
|
@@ -194,14 +109,14 @@ ParametricGeometries.TorusKnotGeometry = class TorusKnotGeometry extends Paramet
|
|
|
|
|
|
}
|
|
|
|
|
|
-};
|
|
|
+}
|
|
|
|
|
|
/*********************************************
|
|
|
*
|
|
|
* Parametric Replacement for SphereGeometry
|
|
|
*
|
|
|
*********************************************/
|
|
|
-ParametricGeometries.SphereGeometry = class SphereGeometry extends ParametricGeometry {
|
|
|
+class ParametricSphereGeometry extends ParametricGeometry {
|
|
|
|
|
|
constructor( size, u, v ) {
|
|
|
|
|
|
@@ -222,7 +137,7 @@ ParametricGeometries.SphereGeometry = class SphereGeometry extends ParametricGeo
|
|
|
|
|
|
}
|
|
|
|
|
|
-};
|
|
|
+}
|
|
|
|
|
|
|
|
|
/*********************************************
|
|
|
@@ -230,8 +145,7 @@ ParametricGeometries.SphereGeometry = class SphereGeometry extends ParametricGeo
|
|
|
* Parametric Replacement for PlaneGeometry
|
|
|
*
|
|
|
*********************************************/
|
|
|
-
|
|
|
-ParametricGeometries.PlaneGeometry = class PlaneGeometry extends ParametricGeometry {
|
|
|
+class ParametricPlaneGeometry extends ParametricGeometry {
|
|
|
|
|
|
constructor( width, depth, segmentsWidth, segmentsDepth ) {
|
|
|
|
|
|
@@ -249,6 +163,93 @@ ParametricGeometries.PlaneGeometry = class PlaneGeometry extends ParametricGeome
|
|
|
|
|
|
}
|
|
|
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * Experimenting of primitive geometry creation using Surface Parametric equations
|
|
|
+ */
|
|
|
+
|
|
|
+const ParametricGeometries = {
|
|
|
+
|
|
|
+ klein: function ( v, u, target ) {
|
|
|
+
|
|
|
+ u *= Math.PI;
|
|
|
+ v *= 2 * Math.PI;
|
|
|
+
|
|
|
+ u = u * 2;
|
|
|
+ let x, z;
|
|
|
+ if ( u < Math.PI ) {
|
|
|
+
|
|
|
+ x = 3 * Math.cos( u ) * ( 1 + Math.sin( u ) ) + ( 2 * ( 1 - Math.cos( u ) / 2 ) ) * Math.cos( u ) * Math.cos( v );
|
|
|
+ z = - 8 * Math.sin( u ) - 2 * ( 1 - Math.cos( u ) / 2 ) * Math.sin( u ) * Math.cos( v );
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ x = 3 * Math.cos( u ) * ( 1 + Math.sin( u ) ) + ( 2 * ( 1 - Math.cos( u ) / 2 ) ) * Math.cos( v + Math.PI );
|
|
|
+ z = - 8 * Math.sin( u );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ const y = - 2 * ( 1 - Math.cos( u ) / 2 ) * Math.sin( v );
|
|
|
+
|
|
|
+ target.set( x, y, z );
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ plane: function ( width, height ) {
|
|
|
+
|
|
|
+ return function ( u, v, target ) {
|
|
|
+
|
|
|
+ const x = u * width;
|
|
|
+ const y = 0;
|
|
|
+ const z = v * height;
|
|
|
+
|
|
|
+ target.set( x, y, z );
|
|
|
+
|
|
|
+ };
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ mobius: function ( u, t, target ) {
|
|
|
+
|
|
|
+ // flat mobius strip
|
|
|
+ // http://www.wolframalpha.com/input/?i=M%C3%B6bius+strip+parametric+equations&lk=1&a=ClashPrefs_*Surface.MoebiusStrip.SurfaceProperty.ParametricEquations-
|
|
|
+ u = u - 0.5;
|
|
|
+ const v = 2 * Math.PI * t;
|
|
|
+
|
|
|
+ const a = 2;
|
|
|
+
|
|
|
+ const x = Math.cos( v ) * ( a + u * Math.cos( v / 2 ) );
|
|
|
+ const y = Math.sin( v ) * ( a + u * Math.cos( v / 2 ) );
|
|
|
+ const z = u * Math.sin( v / 2 );
|
|
|
+
|
|
|
+ target.set( x, y, z );
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ mobius3d: function ( u, t, target ) {
|
|
|
+
|
|
|
+ // volumetric mobius strip
|
|
|
+
|
|
|
+ u *= Math.PI;
|
|
|
+ t *= 2 * Math.PI;
|
|
|
+
|
|
|
+ u = u * 2;
|
|
|
+ const phi = u / 2;
|
|
|
+ const major = 2.25, a = 0.125, b = 0.65;
|
|
|
+
|
|
|
+ let x = a * Math.cos( t ) * Math.cos( phi ) - b * Math.sin( t ) * Math.sin( phi );
|
|
|
+ const z = a * Math.cos( t ) * Math.sin( phi ) + b * Math.sin( t ) * Math.cos( phi );
|
|
|
+ const y = ( major + x ) * Math.sin( u );
|
|
|
+ x = ( major + x ) * Math.cos( u );
|
|
|
+
|
|
|
+ target.set( x, y, z );
|
|
|
+
|
|
|
+ },
|
|
|
+ PlaneGeometry: ParametricPlaneGeometry,
|
|
|
+ TorusKnotGeometry: ParametricTorusKnotGeometry,
|
|
|
+ TubeGeometry: ParametricTubeGeometry,
|
|
|
+ SphereGeometry: ParametricSphereGeometry
|
|
|
};
|
|
|
|
|
|
export { ParametricGeometries };
|