Mesh.tests.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /* global QUnit */
  2. import { Object3D } from '../../../../src/core/Object3D.js';
  3. import { Mesh } from '../../../../src/objects/Mesh.js';
  4. import { Raycaster } from '../../../../src/core/Raycaster.js';
  5. import { PlaneGeometry } from '../../../../src/geometries/PlaneGeometry.js';
  6. import { BoxGeometry } from '../../../../src/geometries/BoxGeometry.js';
  7. import { MeshBasicMaterial } from '../../../../src/materials/MeshBasicMaterial.js';
  8. import { Vector2 } from '../../../../src/math/Vector2.js';
  9. import { Vector3 } from '../../../../src/math/Vector3.js';
  10. import { DoubleSide } from '../../../../src/constants.js';
  11. export default QUnit.module( 'Objects', () => {
  12. QUnit.module( 'Mesh', () => {
  13. // INHERITANCE
  14. QUnit.test( 'Extending', ( assert ) => {
  15. const mesh = new Mesh();
  16. assert.strictEqual(
  17. mesh instanceof Object3D, true,
  18. 'Mesh extends from Object3D'
  19. );
  20. } );
  21. // INSTANCING
  22. QUnit.todo( 'Instancing', ( assert ) => {
  23. assert.ok( false, 'everything\'s gonna be alright' );
  24. } );
  25. // PROPERTIES
  26. QUnit.test( 'type', ( assert ) => {
  27. const object = new Mesh();
  28. assert.ok(
  29. object.type === 'Mesh',
  30. 'Mesh.type should be Mesh'
  31. );
  32. } );
  33. QUnit.todo( 'geometry', ( assert ) => {
  34. assert.ok( false, 'everything\'s gonna be alright' );
  35. } );
  36. QUnit.todo( 'material', ( assert ) => {
  37. assert.ok( false, 'everything\'s gonna be alright' );
  38. } );
  39. // PUBLIC
  40. QUnit.test( 'isMesh', ( assert ) => {
  41. const object = new Mesh();
  42. assert.ok(
  43. object.isMesh,
  44. 'Mesh.isMesh should be true'
  45. );
  46. } );
  47. QUnit.todo( 'copy', ( assert ) => {
  48. assert.ok( false, 'everything\'s gonna be alright' );
  49. } );
  50. QUnit.todo( 'updateMorphTargets', ( assert ) => {
  51. assert.ok( false, 'everything\'s gonna be alright' );
  52. } );
  53. QUnit.todo( 'getVertexPosition', ( assert ) => {
  54. assert.ok( false, 'everything\'s gonna be alright' );
  55. } );
  56. QUnit.todo( 'raycast', ( assert ) => {
  57. const geometry = new PlaneGeometry();
  58. const material = new MeshBasicMaterial();
  59. const mesh = new Mesh( geometry, material );
  60. const raycaster = new Raycaster();
  61. raycaster.ray.origin.set( 0.25, 0.25, 1 );
  62. raycaster.ray.direction.set( 0, 0, - 1 );
  63. const intersections = [];
  64. mesh.raycast( raycaster, intersections );
  65. const intersection = intersections[ 0 ];
  66. assert.equal( intersection.object, mesh, 'intersction object' );
  67. assert.equal( intersection.distance, 1, 'intersction distance' );
  68. assert.equal( intersection.faceIndex, 1, 'intersction face index' );
  69. assert.deepEqual( intersection.face, { a: 0, b: 2, c: 1 }, 'intersction vertex indices' );
  70. assert.deepEqual( intersection.point, new Vector3( 0.25, 0.25, 0 ), 'intersction point' );
  71. assert.deepEqual( intersection.uv, new Vector2( 0.75, 0.75 ), 'intersction uv' );
  72. } );
  73. QUnit.test( 'raycast/range', ( assert ) => {
  74. const geometry = new BoxGeometry( 1, 1, 1 );
  75. const material = new MeshBasicMaterial( { side: DoubleSide } );
  76. const mesh = new Mesh( geometry, material );
  77. const raycaster = new Raycaster();
  78. const intersections = [];
  79. raycaster.ray.origin.set( 0, 0, 0 );
  80. raycaster.ray.direction.set( 1, 0, 0 );
  81. raycaster.near = 100;
  82. raycaster.far = 200;
  83. mesh.matrixWorld.identity();
  84. mesh.position.setX( 150 );
  85. mesh.updateMatrixWorld( true );
  86. intersections.length = 0;
  87. mesh.raycast( raycaster, intersections );
  88. assert.ok( intersections.length > 0, 'bounding sphere between near and far' );
  89. mesh.matrixWorld.identity();
  90. mesh.position.setX( raycaster.near );
  91. mesh.updateMatrixWorld( true );
  92. intersections.length = 0;
  93. mesh.raycast( raycaster, intersections );
  94. assert.ok( intersections.length > 0, 'bounding sphere across near' );
  95. mesh.matrixWorld.identity();
  96. mesh.position.setX( raycaster.far );
  97. mesh.updateMatrixWorld( true );
  98. intersections.length = 0;
  99. mesh.raycast( raycaster, intersections );
  100. assert.ok( intersections.length > 0, 'bounding sphere across far' );
  101. mesh.matrixWorld.identity();
  102. mesh.position.setX( 150 );
  103. mesh.scale.setY( 9999 );
  104. mesh.updateMatrixWorld( true );
  105. intersections.length = 0;
  106. mesh.raycast( raycaster, intersections );
  107. assert.ok( intersections.length > 0, 'bounding sphere across near and far' );
  108. mesh.matrixWorld.identity();
  109. mesh.position.setX( - 9999 );
  110. mesh.updateMatrixWorld( true );
  111. intersections.length = 0;
  112. mesh.raycast( raycaster, intersections );
  113. assert.ok( intersections.length === 0, 'bounding sphere behind near' );
  114. mesh.matrixWorld.identity();
  115. mesh.position.setX( 9999 );
  116. mesh.updateMatrixWorld( true );
  117. intersections.length = 0;
  118. mesh.raycast( raycaster, intersections );
  119. assert.ok( intersections.length === 0, 'bounding sphere beyond far' );
  120. } );
  121. } );
  122. } );
粤ICP备19079148号