Face3.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /**
  2. * @author simonThiele / https://github.com/simonThiele
  3. */
  4. module( "Face3" );
  5. test( "copy", function() {
  6. var instance = new THREE.Face3(0, 1, 2, new THREE.Vector3(0, 1, 0), new THREE.Color(0.25, 0.5, 0.75), 2);
  7. var copiedInstance = instance.copy(instance);
  8. checkCopy(copiedInstance);
  9. checkVertexAndColors(copiedInstance);
  10. });
  11. test( "copy", function() {
  12. var instance = new THREE.Face3(0, 1, 2,
  13. [new THREE.Vector3(0, 1, 0), new THREE.Vector3(1, 0, 1)],
  14. [new THREE.Color(0.25, 0.5, 0.75), new THREE.Color(1, 0, 0.4)],
  15. 2);
  16. var copiedInstance = instance.copy(instance);
  17. checkCopy(copiedInstance);
  18. checkVertexAndColorArrays(copiedInstance);
  19. });
  20. test( "clone", function() {
  21. var instance = new THREE.Face3(0, 1, 2, new THREE.Vector3(0, 1, 0), new THREE.Color(0.25, 0.5, 0.75), 2);
  22. var copiedInstance = instance.clone();
  23. checkCopy(copiedInstance);
  24. checkVertexAndColors(copiedInstance);
  25. });
  26. function checkCopy(copiedInstance) {
  27. ok( copiedInstance instanceof THREE.Face3, "copy created the correct type" );
  28. ok(
  29. copiedInstance.a === 0 &&
  30. copiedInstance.b === 1 &&
  31. copiedInstance.c === 2 &&
  32. copiedInstance.materialIndex === 2
  33. ,"properties where copied" );
  34. }
  35. function checkVertexAndColors(copiedInstance) {
  36. ok(
  37. copiedInstance.normal.x === 0 && copiedInstance.normal.y === 1 && copiedInstance.normal.z === 0 &&
  38. copiedInstance.color.r === 0.25 && copiedInstance.color.g === 0.5 && copiedInstance.color.b === 0.75
  39. ,"properties where copied" );
  40. }
  41. function checkVertexAndColorArrays(copiedInstance) {
  42. ok(
  43. copiedInstance.vertexNormals[0].x === 0 && copiedInstance.vertexNormals[0].y === 1 && copiedInstance.vertexNormals[0].z === 0 &&
  44. copiedInstance.vertexNormals[1].x === 1 && copiedInstance.vertexNormals[1].y === 0 && copiedInstance.vertexNormals[1].z === 1 &&
  45. copiedInstance.vertexColors[0].r === 0.25 && copiedInstance.vertexColors[0].g === 0.5 && copiedInstance.vertexColors[0].b === 0.75 &&
  46. copiedInstance.vertexColors[1].r === 1 && copiedInstance.vertexColors[1].g === 0 && copiedInstance.vertexColors[1].b === 0.4
  47. ,"properties where copied" );
  48. }