GeometryUtils.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. var GeometryUtils = {
  2. merge: function ( geometry1, object2 /* mesh | geometry */ ) {
  3. var isMesh = object2 instanceof THREE.Mesh,
  4. vertexPosition = geometry1.vertices.length,
  5. facePosition = geometry1.faces.length,
  6. uvPosition = geometry1.uvs.length,
  7. geometry2 = isMesh ? object2.geometry : object2,
  8. vertices1 = geometry1.vertices,
  9. vertices2 = geometry2.vertices,
  10. faces1 = geometry1.faces,
  11. faces2 = geometry2.faces,
  12. uvs1 = geometry1.uvs,
  13. uvs2 = geometry2.uvs;
  14. isMesh && object2.updateMatrix();
  15. for ( var i = 0, il = vertices2.length; i < il; i ++ ) {
  16. var vertex = vertices2[ i ];
  17. var vertexCopy = new THREE.Vertex( vertex.position.clone() );
  18. isMesh && object2.matrix.multiplyVector3( vertexCopy.position );
  19. vertices1.push( vertexCopy );
  20. }
  21. for ( i = 0, il = faces2.length; i < il; i ++ ) {
  22. var face = faces2[ i ], faceCopy, normal,
  23. faceVertexNormals = face.vertexNormals;
  24. if ( face instanceof THREE.Face3 ) {
  25. faceCopy = new THREE.Face3( face.a + vertexPosition, face.b + vertexPosition, face.c + vertexPosition );
  26. } else if ( face instanceof THREE.Face4 ) {
  27. faceCopy = new THREE.Face4( face.a + vertexPosition, face.b + vertexPosition, face.c + vertexPosition, face.d + vertexPosition );
  28. }
  29. faceCopy.centroid.copy( face.centroid );
  30. faceCopy.normal.copy( face.normal );
  31. for ( var j = 0, jl = faceVertexNormals.length; j < jl; j ++ ) {
  32. normal = faceVertexNormals[ j ];
  33. faceCopy.vertexNormals.push( normal.clone() );
  34. }
  35. faceCopy.materials = face.materials.slice();
  36. faces1.push( faceCopy );
  37. }
  38. for ( i = 0, il = uvs2.length; i < il; i ++ ) {
  39. var uv = uvs2[ i ], uvCopy = [];
  40. for ( var j = 0, jl = uv.length; j < jl; j ++ ) {
  41. uvCopy.push( new THREE.UV( uv[ j ].u, uv[ j ].v ) );
  42. }
  43. uvs1.push( uvCopy );
  44. }
  45. }
  46. };
粤ICP备19079148号