From 4ce780c4d7c293f76971c5b46a355007c83c9982 Mon Sep 17 00:00:00 2001 From: Mugen87 Date: Tue, 17 Oct 2017 11:33:02 +0200 Subject: [PATCH] Curves: Added type property --- docs/api/extras/curves/CatmullRomCurve3.html | 2 +- examples/webgl_geometry_extrude_shapes.html | 2 +- examples/webgl_geometry_extrude_splines.html | 2 +- examples/webgl_geometry_spline_editor.html | 6 +++--- src/extras/core/Curve.js | 2 ++ src/extras/core/CurvePath.js | 3 ++- src/extras/core/Font.js | 2 ++ src/extras/core/Path.js | 3 +++ src/extras/core/Shape.js | 2 ++ src/extras/core/ShapePath.js | 2 ++ src/extras/curves/ArcCurve.js | 2 ++ src/extras/curves/CatmullRomCurve3.js | 9 ++++++--- src/extras/curves/CubicBezierCurve.js | 2 ++ src/extras/curves/CubicBezierCurve3.js | 2 ++ src/extras/curves/EllipseCurve.js | 2 ++ src/extras/curves/LineCurve.js | 2 ++ src/extras/curves/LineCurve3.js | 2 ++ src/extras/curves/QuadraticBezierCurve.js | 2 ++ src/extras/curves/QuadraticBezierCurve3.js | 2 ++ src/extras/curves/SplineCurve.js | 2 ++ 20 files changed, 43 insertions(+), 10 deletions(-) diff --git a/docs/api/extras/curves/CatmullRomCurve3.html b/docs/api/extras/curves/CatmullRomCurve3.html index 4e6c36ff4b..7256588a99 100644 --- a/docs/api/extras/curves/CatmullRomCurve3.html +++ b/docs/api/extras/curves/CatmullRomCurve3.html @@ -63,7 +63,7 @@ var curveObject = new THREE.Line( geometry, material );

[property:Boolean closed]

The curve will loop back onto itself when this is true. False by default
-

[property:String type]

+

[property:String cureType]

Possible values are `centripetal` (default), `chordal` and `catmullrom`.

[property:float tension]

diff --git a/examples/webgl_geometry_extrude_shapes.html b/examples/webgl_geometry_extrude_shapes.html index 4f2677b607..82868a81d4 100644 --- a/examples/webgl_geometry_extrude_shapes.html +++ b/examples/webgl_geometry_extrude_shapes.html @@ -74,7 +74,7 @@ new THREE.Vector3( 60, -100, -60 ) ] ); - closedSpline.type = 'catmullrom'; + closedSpline.curveType = 'catmullrom'; closedSpline.closed = true; var extrudeSettings = { diff --git a/examples/webgl_geometry_extrude_splines.html b/examples/webgl_geometry_extrude_splines.html index 2e778f4f1c..7a723ecda6 100644 --- a/examples/webgl_geometry_extrude_splines.html +++ b/examples/webgl_geometry_extrude_splines.html @@ -72,7 +72,7 @@ new THREE.Vector3( 0, -40, 40 ) ] ); - sampleClosedSpline.type = 'catmullrom'; + sampleClosedSpline.curveType = 'catmullrom'; sampleClosedSpline.closed = true; // Keep a dictionary of Curve instances diff --git a/examples/webgl_geometry_spline_editor.html b/examples/webgl_geometry_spline_editor.html index fcf6379d64..f29d8352dc 100644 --- a/examples/webgl_geometry_spline_editor.html +++ b/examples/webgl_geometry_spline_editor.html @@ -258,7 +258,7 @@ } var curve = new THREE.CatmullRomCurve3( positions ); - curve.type = 'catmullrom'; + curve.curveType = 'catmullrom'; curve.mesh = new THREE.Line( geometry.clone(), new THREE.LineBasicMaterial( { color: 0xff0000, opacity: 0.35, @@ -268,7 +268,7 @@ splines.uniform = curve; curve = new THREE.CatmullRomCurve3( positions ); - curve.type = 'centripetal'; + curve.curveType = 'centripetal'; curve.mesh = new THREE.Line( geometry.clone(), new THREE.LineBasicMaterial( { color: 0x00ff00, opacity: 0.35, @@ -278,7 +278,7 @@ splines.centripetal = curve; curve = new THREE.CatmullRomCurve3( positions ); - curve.type = 'chordal'; + curve.curveType = 'chordal'; curve.mesh = new THREE.Line( geometry.clone(), new THREE.LineBasicMaterial( { color: 0x0000ff, opacity: 0.35, diff --git a/src/extras/core/Curve.js b/src/extras/core/Curve.js index c981dbf4a0..5ee6ab627d 100644 --- a/src/extras/core/Curve.js +++ b/src/extras/core/Curve.js @@ -39,6 +39,8 @@ import { Matrix4 } from '../../math/Matrix4.js'; function Curve() { + this.type = 'Curve'; + this.arcLengthDivisions = 200; } diff --git a/src/extras/core/CurvePath.js b/src/extras/core/CurvePath.js index ac250f8c47..2552c5d2be 100644 --- a/src/extras/core/CurvePath.js +++ b/src/extras/core/CurvePath.js @@ -17,8 +17,9 @@ function CurvePath() { Curve.call( this ); - this.curves = []; + this.type = 'CurvePath'; + this.curves = []; this.autoClose = false; // Automatically closes the path } diff --git a/src/extras/core/Font.js b/src/extras/core/Font.js index 88c1b4fe95..a71346267c 100644 --- a/src/extras/core/Font.js +++ b/src/extras/core/Font.js @@ -9,6 +9,8 @@ import { ShapePath } from './ShapePath.js'; function Font( data ) { + this.type = 'Font'; + this.data = data; } diff --git a/src/extras/core/Path.js b/src/extras/core/Path.js index b3d98d3408..af330b4b6a 100644 --- a/src/extras/core/Path.js +++ b/src/extras/core/Path.js @@ -11,6 +11,9 @@ import { CurvePath } from './CurvePath.js'; function Path( points ) { CurvePath.call( this ); + + this.type = 'Path'; + this.currentPoint = new Vector2(); if ( points ) { diff --git a/src/extras/core/Shape.js b/src/extras/core/Shape.js index b178fe4be2..21d789f83d 100644 --- a/src/extras/core/Shape.js +++ b/src/extras/core/Shape.js @@ -16,6 +16,8 @@ function Shape() { Path.apply( this, arguments ); + this.type = 'Shape'; + this.holes = []; } diff --git a/src/extras/core/ShapePath.js b/src/extras/core/ShapePath.js index beb97e66b1..a5f02f24c9 100644 --- a/src/extras/core/ShapePath.js +++ b/src/extras/core/ShapePath.js @@ -9,6 +9,8 @@ import { ShapeUtils } from '../ShapeUtils.js'; function ShapePath() { + this.type = 'ShapePath'; + this.subPaths = []; this.currentPath = null; diff --git a/src/extras/curves/ArcCurve.js b/src/extras/curves/ArcCurve.js index 23cefcd159..54b8848c4c 100644 --- a/src/extras/curves/ArcCurve.js +++ b/src/extras/curves/ArcCurve.js @@ -5,6 +5,8 @@ function ArcCurve( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) { EllipseCurve.call( this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise ); + this.type = 'ArcCurve'; + } ArcCurve.prototype = Object.create( EllipseCurve.prototype ); diff --git a/src/extras/curves/CatmullRomCurve3.js b/src/extras/curves/CatmullRomCurve3.js index 1a502e939d..3f35457d54 100644 --- a/src/extras/curves/CatmullRomCurve3.js +++ b/src/extras/curves/CatmullRomCurve3.js @@ -87,10 +87,13 @@ function CatmullRomCurve3( points ) { Curve.call( this ); + this.type = 'CatmullRomCurve3'; + if ( points.length < 2 ) console.warn( 'THREE.CatmullRomCurve3: Points array needs at least two entries.' ); this.points = points || []; this.closed = false; + this.curveType = 'centripetal'; } @@ -150,10 +153,10 @@ CatmullRomCurve3.prototype.getPoint = function ( t, optionalTarget ) { } - if ( this.type === undefined || this.type === 'centripetal' || this.type === 'chordal' ) { + if ( this.curveType === 'centripetal' || this.curveType === 'chordal' ) { // init Centripetal / Chordal Catmull-Rom - var pow = this.type === 'chordal' ? 0.5 : 0.25; + var pow = this.curveType === 'chordal' ? 0.5 : 0.25; var dt0 = Math.pow( p0.distanceToSquared( p1 ), pow ); var dt1 = Math.pow( p1.distanceToSquared( p2 ), pow ); var dt2 = Math.pow( p2.distanceToSquared( p3 ), pow ); @@ -167,7 +170,7 @@ CatmullRomCurve3.prototype.getPoint = function ( t, optionalTarget ) { py.initNonuniformCatmullRom( p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2 ); pz.initNonuniformCatmullRom( p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2 ); - } else if ( this.type === 'catmullrom' ) { + } else if ( this.curveType === 'catmullrom' ) { var tension = this.tension !== undefined ? this.tension : 0.5; px.initCatmullRom( p0.x, p1.x, p2.x, p3.x, tension ); diff --git a/src/extras/curves/CubicBezierCurve.js b/src/extras/curves/CubicBezierCurve.js index fc6e9b8466..fb883fb49c 100644 --- a/src/extras/curves/CubicBezierCurve.js +++ b/src/extras/curves/CubicBezierCurve.js @@ -7,6 +7,8 @@ function CubicBezierCurve( v0, v1, v2, v3 ) { Curve.call( this ); + this.type = 'CubicBezierCurve'; + this.v0 = v0; this.v1 = v1; this.v2 = v2; diff --git a/src/extras/curves/CubicBezierCurve3.js b/src/extras/curves/CubicBezierCurve3.js index c7150f45b7..c951f8fdc0 100644 --- a/src/extras/curves/CubicBezierCurve3.js +++ b/src/extras/curves/CubicBezierCurve3.js @@ -7,6 +7,8 @@ function CubicBezierCurve3( v0, v1, v2, v3 ) { Curve.call( this ); + this.type = 'CubicBezierCurve3'; + this.v0 = v0; this.v1 = v1; this.v2 = v2; diff --git a/src/extras/curves/EllipseCurve.js b/src/extras/curves/EllipseCurve.js index 40ce5ca1dc..95cdebb8e6 100644 --- a/src/extras/curves/EllipseCurve.js +++ b/src/extras/curves/EllipseCurve.js @@ -6,6 +6,8 @@ function EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockw Curve.call( this ); + this.type = 'EllipseCurve'; + this.aX = aX; this.aY = aY; diff --git a/src/extras/curves/LineCurve.js b/src/extras/curves/LineCurve.js index 1e620d3c87..6ff67926bc 100644 --- a/src/extras/curves/LineCurve.js +++ b/src/extras/curves/LineCurve.js @@ -6,6 +6,8 @@ function LineCurve( v1, v2 ) { Curve.call( this ); + this.type = 'LineCurve'; + this.v1 = v1; this.v2 = v2; diff --git a/src/extras/curves/LineCurve3.js b/src/extras/curves/LineCurve3.js index 3ebe4b1654..896aefc548 100644 --- a/src/extras/curves/LineCurve3.js +++ b/src/extras/curves/LineCurve3.js @@ -6,6 +6,8 @@ function LineCurve3( v1, v2 ) { Curve.call( this ); + this.type = 'LineCurve3'; + this.v1 = v1; this.v2 = v2; diff --git a/src/extras/curves/QuadraticBezierCurve.js b/src/extras/curves/QuadraticBezierCurve.js index e9fb626d4d..378b6d9f6c 100644 --- a/src/extras/curves/QuadraticBezierCurve.js +++ b/src/extras/curves/QuadraticBezierCurve.js @@ -7,6 +7,8 @@ function QuadraticBezierCurve( v0, v1, v2 ) { Curve.call( this ); + this.type = 'QuadraticBezierCurve'; + this.v0 = v0; this.v1 = v1; this.v2 = v2; diff --git a/src/extras/curves/QuadraticBezierCurve3.js b/src/extras/curves/QuadraticBezierCurve3.js index 38e2442098..e3815e9ab8 100644 --- a/src/extras/curves/QuadraticBezierCurve3.js +++ b/src/extras/curves/QuadraticBezierCurve3.js @@ -7,6 +7,8 @@ function QuadraticBezierCurve3( v0, v1, v2 ) { Curve.call( this ); + this.type = 'QuadraticBezierCurve3'; + this.v0 = v0; this.v1 = v1; this.v2 = v2; diff --git a/src/extras/curves/SplineCurve.js b/src/extras/curves/SplineCurve.js index 21088ef27b..e27aabae8f 100644 --- a/src/extras/curves/SplineCurve.js +++ b/src/extras/curves/SplineCurve.js @@ -7,6 +7,8 @@ function SplineCurve( points /* array of Vector2 */ ) { Curve.call( this ); + this.type = 'SplineCurve'; + this.points = ( points === undefined ) ? [] : points; } -- GitLab