NURBSCurve.tests.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import { NURBSCurve } from '../../../../examples/jsm/curves/NURBSCurve.js';
  2. import { MathUtils, Vector4 } from 'three';
  3. export default QUnit.module( 'Extras', () => {
  4. QUnit.module( 'Curves', () => {
  5. QUnit.module( 'NURBSCurve', ( hooks ) => {
  6. let _nurbsCurve = undefined;
  7. hooks.before( function () {
  8. const nurbsControlPoints = [];
  9. const nurbsKnots = [];
  10. const nurbsDegree = 3;
  11. for ( let i = 0; i <= nurbsDegree; i ++ ) {
  12. nurbsKnots.push( 0 );
  13. }
  14. for ( let i = 0, j = 20; i < j; i ++ ) {
  15. const point = new Vector4( Math.random(), Math.random(), Math.random(), 1 );
  16. nurbsControlPoints.push( point );
  17. const knot = ( i + 1 ) / ( j - nurbsDegree );
  18. nurbsKnots.push( MathUtils.clamp( knot, 0, 1 ) );
  19. }
  20. _nurbsCurve = new NURBSCurve( nurbsDegree, nurbsKnots, nurbsControlPoints );
  21. } );
  22. QUnit.test( 'toJSON', ( assert ) => {
  23. const json = _nurbsCurve.toJSON();
  24. assert.equal( json.degree, _nurbsCurve.degree, 'json.degree ok' );
  25. assert.deepEqual( json.knots, _nurbsCurve.knots, 'json.knots ok' );
  26. assert.deepEqual( json.controlPoints, _nurbsCurve.controlPoints.map( p => p.toArray() ), 'json.controlPoints ok' );
  27. assert.equal( json.startKnot, _nurbsCurve.startKnot, 'json.startKnot ok' );
  28. assert.equal( json.endKnot, _nurbsCurve.endKnot, 'json.endKnot ok' );
  29. } );
  30. QUnit.test( 'fromJSON', ( assert ) => {
  31. const json = _nurbsCurve.toJSON();
  32. const fromJson = new NURBSCurve().fromJSON( json );
  33. assert.equal( fromJson.degree, _nurbsCurve.degree, 'json.degree ok' );
  34. assert.deepEqual( fromJson.knots, _nurbsCurve.knots, 'json.knots ok' );
  35. assert.deepEqual( fromJson.controlPoints, _nurbsCurve.controlPoints, 'json.controlPoints ok' );
  36. assert.equal( fromJson.startKnot, _nurbsCurve.startKnot, 'json.startKnot ok' );
  37. assert.equal( fromJson.endKnot, _nurbsCurve.endKnot, 'json.endKnot ok' );
  38. } );
  39. } );
  40. } );
  41. } );
粤ICP备19079148号