// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/pkgs/R3Shapes/R3Mesh.cpp
// Function: gaps::R3Mesh::operator=(gaps::R3Mesh const&)
R3Mesh& R3Mesh::
operator=(const R3Mesh& mesh)
{
  // Delete everything
  Empty();
  
  // Copy bbox
  bbox = mesh.bbox;

  // Copy vertices 
  vertex_block = new R3MeshVertex [ mesh.NVertices() ];
  for (int i = 0; i < mesh.NVertices(); i++) {
    R3MeshVertex *vertex = mesh.Vertex(i);
    const R3Point& position = mesh.VertexPosition(vertex);
    const R3Vector& normal = mesh.VertexNormal(vertex);
    const RNRgb& color = mesh.VertexColor(vertex);
    const R2Point& texcoords = mesh.VertexTextureCoords(vertex);
    R3MeshVertex *copy_vertex = this->CreateVertex(position, normal, color, texcoords, &vertex_block[i] );
    if (this->VertexID(copy_vertex) != i) RNAbort("Mismatching vertex id"); 
  }

  // Copy edges
  edge_block = new R3MeshEdge [ mesh.NEdges() ];
  for (int i = 0; i < mesh.NEdges(); i++) {
    R3MeshEdge *edge = mesh.Edge(i);
    R3MeshVertex *v0 = mesh.VertexOnEdge(edge, 0);
    R3MeshVertex *v1 = mesh.VertexOnEdge(edge, 1);
    int i0 = mesh.VertexID(v0);
    int i1 = mesh.VertexID(v1);
    R3MeshVertex *copy_v0 = this->Vertex(i0);
    R3MeshVertex *copy_v1 = this->Vertex(i1);
    R3MeshEdge *copy_edge = this->CreateEdge(copy_v0, copy_v1, &edge_block[i] );
    if (this->EdgeID(copy_edge) != i) RNAbort("Mismatching edge id"); 
  }

  // Copy faces
  face_block = new R3MeshFace [ mesh.NFaces() ];
  for (int i = 0; i < mesh.NFaces(); i++) {
    R3MeshFace *face = mesh.Face(i);
    R3MeshVertex *v0 = mesh.VertexOnFace(face, 0);
    R3MeshVertex *v1 = mesh.VertexOnFace(face, 1);
    R3MeshVertex *v2 = mesh.VertexOnFace(face, 2);
    int i0 = mesh.VertexID(v0);
    int i1 = mesh.VertexID(v1);
    int i2 = mesh.VertexID(v2);
    R3MeshVertex *copy_v0 = this->Vertex(i0);
    R3MeshVertex *copy_v1 = this->Vertex(i1);
    R3MeshVertex *copy_v2 = this->Vertex(i2);
    R3MeshFace *copy_face = this->CreateFace(copy_v0, copy_v1, copy_v2, &face_block[i]);
    if (this->FaceID(copy_face) != i) RNAbort("Mismatching face id"); 
    this->SetFaceMaterial(copy_face, mesh.FaceMaterial(face));
    this->SetFaceSegment(copy_face, mesh.FaceSegment(face));
    this->SetFaceCategory(copy_face, mesh.FaceCategory(face));
  }

  // Invalidate GL buffer objects
  InvalidateGLBufferObjects();

  // Return this
  return *this;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movq (%rdi), %rax
callq *0x10(%rax)
movl $0xf8, %edi
leaq (%r14,%rdi), %rsi
addq %rbx, %rdi
callq 0x2141e
movslq 0x14(%r14), %r13
movl $0x98, %ecx
movq %r13, %rax
mulq %rcx
movq %rax, %r15
seto %al
addq $0x8, %r15
pushq $-0x1
popq %rcx
cmovbq %rcx, %r15
testb %al, %al
cmovneq %rcx, %r15
movq %r15, %rdi
callq 0xe030
leaq 0x8(%rax), %rcx
movq %rcx, 0x10(%rsp)
movq %rax, 0x8(%rsp)
movq %r13, (%rax)
testq %r13, %r13
je 0x17008
imulq $-0x98, %r13, %r12
xorl %ebp, %ebp
movq 0x10(%rsp), %r13
movq %r13, %rdi
callq 0x2108c
addq $-0x98, %rbp
addq $0x98, %r13
cmpq %rbp, %r12
jne 0x16fed
movq 0x10(%rsp), %rax
movq %rax, 0x38(%rbx)
xorl %ebp, %ebp
xorl %r15d, %r15d
movslq 0x14(%r14), %rax
cmpq %rax, %r15
jge 0x1707c
movq 0x8(%r14), %rax
movq (%rax,%r15,8), %r12
leaq 0x18(%r12), %r13
movq %r14, %rdi
movq %r12, %rsi
callq 0x21234
leaq 0x58(%r12), %rcx
addq $0x48, %r12
movq 0x38(%rbx), %r9
addq %rbp, %r9
movq (%rbx), %r10
movq %rbx, %rdi
movq %r13, %rsi
movq %rax, %rdx
movq %r12, %r8
callq *0x38(%r10)
movl 0x70(%rax), %eax
cmpq %rax, %r15
je 0x17070
leaq 0x7c22b(%rip), %rdi     # 0x93294
xorl %eax, %eax
callq 0x680f0
incq %r15
addq $0x98, %rbp
jmp 0x17016
movslq 0x24(%r14), %r15
pushq $0x58
popq %rcx
movq %r15, %rax
mulq %rcx
seto %cl
addq $0x8, %rax
pushq $-0x1
popq %rdx
cmovbq %rdx, %rax
testb %cl, %cl
cmovneq %rdx, %rax
movq %rax, %rdi
callq 0xe030
leaq 0x8(%rax), %rcx
movq %r15, (%rax)
testq %r15, %r15
je 0x170f3
imulq $0x58, %r15, %rax
xorl %edx, %edx
leaq 0xbf672(%rip), %rsi     # 0xd6730
xorps %xmm0, %xmm0
movq %rsi, (%rcx,%rdx)
andq $0x0, 0x28(%rcx,%rdx)
orl $-0x1, 0x30(%rcx,%rdx)
andq $0x0, 0x50(%rcx,%rdx)
movups %xmm0, 0x8(%rcx,%rdx)
movups %xmm0, 0x18(%rcx,%rdx)
andl $0x0, 0x48(%rcx,%rdx)
movups %xmm0, 0x38(%rcx,%rdx)
addq $0x58, %rdx
cmpq %rdx, %rax
jne 0x170c1
movq %rcx, 0x40(%rbx)
leaq 0x7c1ac(%rip), %r12     # 0x932aa
xorl %r13d, %r13d
xorl %ebp, %ebp
movslq %r15d, %rax
cmpq %rax, %rbp
jge 0x1715f
movq 0x18(%r14), %rax
movq (%rax,%rbp,8), %rax
movq 0x8(%rax), %rcx
movq 0x10(%rax), %rax
movslq 0x70(%rcx), %rcx
movslq 0x70(%rax), %rax
movq (%rbx), %r8
movq 0x8(%rbx), %rdx
movq (%rdx,%rcx,8), %rsi
movq (%rdx,%rax,8), %rdx
movq 0x40(%rbx), %rcx
addq %r13, %rcx
movq %rbx, %rdi
callq *0x40(%r8)
movl 0x30(%rax), %eax
cmpq %rax, %rbp
je 0x17152
movq %r12, %rdi
xorl %eax, %eax
callq 0x680f0
incq %rbp
movl 0x24(%r14), %r15d
addq $0x58, %r13
jmp 0x17103
movslq 0x34(%r14), %r13
movl $0xc8, %ecx
movq %r13, %rax
mulq %rcx
movq %rax, %r15
seto %al
addq $0x8, %r15
pushq $-0x1
popq %rcx
cmovbq %rcx, %r15
testb %al, %al
cmovneq %rcx, %r15
movq %r15, %rdi
callq 0xe030
leaq 0x8(%rax), %rcx
movq %rcx, 0x10(%rsp)
movq %rax, 0x8(%rsp)
movq %r13, (%rax)
testq %r13, %r13
je 0x171cc
imulq $-0xc8, %r13, %r12
xorl %ebp, %ebp
movq 0x10(%rsp), %r13
movq %r13, %rdi
callq 0x21186
addq $-0xc8, %rbp
addq $0xc8, %r13
cmpq %rbp, %r12
jne 0x171b1
movq 0x10(%rsp), %rax
movq %rax, 0x48(%rbx)
xorl %r13d, %r13d
xorl %ebp, %ebp
movslq 0x34(%r14), %rax
cmpq %rax, %rbp
jge 0x17271
movq 0x28(%r14), %rax
movq (%rax,%rbp,8), %r15
movq 0x8(%r15), %rax
movq 0x10(%r15), %rcx
movq 0x18(%r15), %rdx
movslq 0x70(%rax), %rax
movslq 0x70(%rcx), %rcx
movslq 0x70(%rdx), %rdi
movq (%rbx), %r9
movq 0x8(%rbx), %r8
movq (%r8,%rax,8), %rsi
movq (%r8,%rcx,8), %rdx
movq (%r8,%rdi,8), %rcx
movq 0x48(%rbx), %r8
addq %r13, %r8
movq %rbx, %rdi
callq *0x48(%r9)
movq %rax, %r12
movl 0xa4(%rax), %eax
cmpq %rax, %rbp
je 0x17244
leaq 0x7c081(%rip), %rdi     # 0x932be
xorl %eax, %eax
callq 0x680f0
movq 0x98(%r15), %rax
movq %rax, 0x98(%r12)
movl 0xa0(%r15), %eax
movl %eax, 0xa0(%r12)
incq %rbp
addq $0xc8, %r13
jmp 0x171da
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x290(%rax)
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
testq %rbp, %rbp
je 0x172e3
negq %rbp
movq 0x8(%rsp), %r14
addq $-0xc0, %r14
leaq (%r14,%rbp), %rdi
callq 0x21208
addq $-0xc8, %rbp
jne 0x172a6
jmp 0x172e3
movq %rax, %rbx
testq %rbp, %rbp
je 0x172e3
negq %rbp
movq 0x8(%rsp), %r14
addq $-0x90, %r14
leaq (%r14,%rbp), %rdi
callq 0x21124
addq $-0x98, %rbp
jne 0x172d1
movq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0xe8f0
movq %rbx, %rdi
callq 0xe810