// File: 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:
subq $0x1f8, %rsp            # imm = 0x1F8
movq %rdi, 0x1f0(%rsp)
movq %rsi, 0x1e8(%rsp)
movq 0x1f0(%rsp), %rdi
movq %rdi, 0xe8(%rsp)
movq (%rdi), %rax
callq *0x10(%rax)
movq 0xe8(%rsp), %rdi
movq 0x1e8(%rsp), %rsi
addq $0xf8, %rsi
addq $0xf8, %rdi
callq 0x37500
movq 0x1e8(%rsp), %rdi
callq 0x135e0
cltq
movq %rax, 0xf8(%rsp)
movl $0x98, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
addq $0x8, %rdi
setb %al
orb %al, %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
movq %rdi, 0xf0(%rsp)
callq 0xf030
movq %rax, %rcx
movq 0xf8(%rsp), %rax
movq %rcx, 0x100(%rsp)
movq %rax, (%rcx)
addq $0x8, %rcx
movq %rcx, 0x108(%rsp)
cmpq $0x0, %rax
je 0x217b8
movq 0x108(%rsp), %rax
movq 0xf8(%rsp), %rcx
imulq $0x98, %rcx, %rdx
movq %rax, %rcx
addq %rdx, %rcx
movq %rcx, 0xd8(%rsp)
movq %rax, 0xe0(%rsp)
movq 0xe0(%rsp), %rdi
movq %rdi, 0xd0(%rsp)
callq 0x36460
jmp 0x21795
movq 0xd8(%rsp), %rcx
movq 0xd0(%rsp), %rax
addq $0x98, %rax
cmpq %rcx, %rax
movq %rax, 0xe0(%rsp)
jne 0x2177e
movq 0xe8(%rsp), %rax
movq 0x108(%rsp), %rcx
movq %rcx, 0x38(%rax)
movl $0x0, 0x1d8(%rsp)
movl 0x1d8(%rsp), %eax
movl %eax, 0xcc(%rsp)
movq 0x1e8(%rsp), %rdi
callq 0x135e0
movl %eax, %ecx
movl 0xcc(%rsp), %eax
cmpl %ecx, %eax
jge 0x219ae
movq 0x1e8(%rsp), %rdi
movl 0x1d8(%rsp), %esi
callq 0x13630
movq %rax, 0x1d0(%rsp)
movq 0x1e8(%rsp), %rdi
movq 0x1d0(%rsp), %rsi
callq 0x13660
movq %rax, 0x1c8(%rsp)
movq 0x1e8(%rsp), %rdi
movq 0x1d0(%rsp), %rsi
callq 0x36860
movq %rax, 0x1c0(%rsp)
movq 0x1e8(%rsp), %rdi
movq 0x1d0(%rsp), %rsi
callq 0x368d0
movq %rax, 0x1b8(%rsp)
movq 0x1e8(%rsp), %rdi
movq 0x1d0(%rsp), %rsi
callq 0x368f0
movq 0xe8(%rsp), %rdi
movq %rax, 0x1b0(%rsp)
movq 0x1c8(%rsp), %rsi
movq 0x1c0(%rsp), %rdx
movq 0x1b8(%rsp), %rcx
movq 0x1b0(%rsp), %r8
movq 0x38(%rdi), %r9
movslq 0x1d8(%rsp), %rax
imulq $0x98, %rax, %rax
addq %rax, %r9
movq (%rdi), %rax
callq *0x38(%rax)
movq 0xe8(%rsp), %rdi
movq %rax, 0x1a8(%rsp)
movq 0x1a8(%rsp), %rsi
callq 0x36910
cmpl 0x1d8(%rsp), %eax
je 0x21996
leaq 0x111978(%rip), %rdi    # 0x133280
movb $0x0, %al
callq 0xd4e20
jmp 0x21996
movq 0x108(%rsp), %rcx
movq %rax, %rsi
movq 0xd0(%rsp), %rax
movq %rsi, 0x1e0(%rsp)
movl %edx, 0x1dc(%rsp)
cmpq %rax, %rcx
movq %rax, 0xc0(%rsp)
je 0x2197c
movq 0xc0(%rsp), %rdi
addq $-0x98, %rdi
movq %rdi, 0xb8(%rsp)
callq 0x36560
movq 0x108(%rsp), %rcx
movq 0xb8(%rsp), %rax
cmpq %rcx, %rax
movq %rax, 0xc0(%rsp)
jne 0x21943
movq 0xf0(%rsp), %rsi
movq 0x100(%rsp), %rdi
callq 0xf990
jmp 0x2204a
jmp 0x21998
movl 0x1d8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1d8(%rsp)
jmp 0x217d7
movq 0x1e8(%rsp), %rdi
callq 0x135c0
cltq
movq %rax, 0xa0(%rsp)
movl $0x58, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
addq $0x8, %rdi
setb %al
orb %al, %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
movq %rdi, 0x98(%rsp)
callq 0xf030
movq %rax, %rcx
movq 0xa0(%rsp), %rax
movq %rcx, 0xa8(%rsp)
movq %rax, (%rcx)
addq $0x8, %rcx
movq %rcx, 0xb0(%rsp)
cmpq $0x0, %rax
je 0x21a81
movq 0xb0(%rsp), %rax
movq 0xa0(%rsp), %rcx
imulq $0x58, %rcx, %rdx
movq %rax, %rcx
addq %rdx, %rcx
movq %rcx, 0x88(%rsp)
movq %rax, 0x90(%rsp)
movq 0x90(%rsp), %rdi
movq %rdi, 0x80(%rsp)
callq 0x365c0
jmp 0x21a60
movq 0x88(%rsp), %rcx
movq 0x80(%rsp), %rax
addq $0x58, %rax
cmpq %rcx, %rax
movq %rax, 0x90(%rsp)
jne 0x21a49
movq 0xe8(%rsp), %rax
movq 0xb0(%rsp), %rcx
movq %rcx, 0x40(%rax)
movl $0x0, 0x1a4(%rsp)
movl 0x1a4(%rsp), %eax
movl %eax, 0x7c(%rsp)
movq 0x1e8(%rsp), %rdi
callq 0x135c0
movl %eax, %ecx
movl 0x7c(%rsp), %eax
cmpl %ecx, %eax
jge 0x21c86
movq 0x1e8(%rsp), %rdi
movl 0x1a4(%rsp), %esi
callq 0x36930
movq %rax, 0x198(%rsp)
movq 0x1e8(%rsp), %rdi
movq 0x198(%rsp), %rsi
xorl %edx, %edx
callq 0x36960
movq %rax, 0x190(%rsp)
movq 0x1e8(%rsp), %rdi
movq 0x198(%rsp), %rsi
movl $0x1, %edx
callq 0x36960
movq %rax, 0x188(%rsp)
movq 0x1e8(%rsp), %rdi
movq 0x190(%rsp), %rsi
callq 0x36910
movl %eax, 0x184(%rsp)
movq 0x1e8(%rsp), %rdi
movq 0x188(%rsp), %rsi
callq 0x36910
movq 0xe8(%rsp), %rdi
movl %eax, 0x180(%rsp)
movl 0x184(%rsp), %esi
callq 0x13630
movq 0xe8(%rsp), %rdi
movq %rax, 0x178(%rsp)
movl 0x180(%rsp), %esi
callq 0x13630
movq 0xe8(%rsp), %rdi
movq %rax, 0x170(%rsp)
movq 0x178(%rsp), %rsi
movq 0x170(%rsp), %rdx
movq 0x40(%rdi), %rcx
movslq 0x1a4(%rsp), %rax
imulq $0x58, %rax, %rax
addq %rax, %rcx
movq (%rdi), %rax
callq *0x40(%rax)
movq 0xe8(%rsp), %rdi
movq %rax, 0x168(%rsp)
movq 0x168(%rsp), %rsi
callq 0x36980
cmpl 0x1a4(%rsp), %eax
je 0x21c6e
leaq 0x1116a1(%rip), %rdi    # 0x133296
movb $0x0, %al
callq 0xd4e20
jmp 0x21c6e
movq 0xb0(%rsp), %rcx
movq %rax, %rsi
movq 0x80(%rsp), %rax
movq %rsi, 0x1e0(%rsp)
movl %edx, 0x1dc(%rsp)
cmpq %rax, %rcx
movq %rax, 0x70(%rsp)
je 0x21c54
movq 0x70(%rsp), %rdi
addq $-0x58, %rdi
movq %rdi, 0x68(%rsp)
callq 0x36640
movq 0xb0(%rsp), %rcx
movq 0x68(%rsp), %rax
cmpq %rcx, %rax
movq %rax, 0x70(%rsp)
jne 0x21c2a
movq 0x98(%rsp), %rsi
movq 0xa8(%rsp), %rdi
callq 0xf990
jmp 0x2204a
jmp 0x21c70
movl 0x1a4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1a4(%rsp)
jmp 0x21aa0
movq 0x1e8(%rsp), %rdi
callq 0x135a0
cltq
movq %rax, 0x50(%rsp)
movl $0xc8, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
addq $0x8, %rdi
setb %al
orb %al, %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
movq %rdi, 0x48(%rsp)
callq 0xf030
movq %rax, %rcx
movq 0x50(%rsp), %rax
movq %rcx, 0x58(%rsp)
movq %rax, (%rcx)
addq $0x8, %rcx
movq %rcx, 0x60(%rsp)
cmpq $0x0, %rax
je 0x21d34
movq 0x60(%rsp), %rax
movq 0x50(%rsp), %rcx
imulq $0xc8, %rcx, %rdx
movq %rax, %rcx
addq %rdx, %rcx
movq %rcx, 0x38(%rsp)
movq %rax, 0x40(%rsp)
movq 0x40(%rsp), %rdi
movq %rdi, 0x30(%rsp)
callq 0x36680
jmp 0x21d1a
movq 0x38(%rsp), %rcx
movq 0x30(%rsp), %rax
addq $0xc8, %rax
cmpq %rcx, %rax
movq %rax, 0x40(%rsp)
jne 0x21d09
movq 0xe8(%rsp), %rax
movq 0x60(%rsp), %rcx
movq %rcx, 0x48(%rax)
movl $0x0, 0x164(%rsp)
movl 0x164(%rsp), %eax
movl %eax, 0x2c(%rsp)
movq 0x1e8(%rsp), %rdi
callq 0x135a0
movl %eax, %ecx
movl 0x2c(%rsp), %eax
cmpl %ecx, %eax
jge 0x22029
movq 0x1e8(%rsp), %rdi
movl 0x164(%rsp), %esi
callq 0x136d0
movq %rax, 0x158(%rsp)
movq 0x1e8(%rsp), %rdi
movq 0x158(%rsp), %rsi
xorl %edx, %edx
callq 0x13700
movq %rax, 0x150(%rsp)
movq 0x1e8(%rsp), %rdi
movq 0x158(%rsp), %rsi
movl $0x1, %edx
callq 0x13700
movq %rax, 0x148(%rsp)
movq 0x1e8(%rsp), %rdi
movq 0x158(%rsp), %rsi
movl $0x2, %edx
callq 0x13700
movq %rax, 0x140(%rsp)
movq 0x1e8(%rsp), %rdi
movq 0x150(%rsp), %rsi
callq 0x36910
movl %eax, 0x13c(%rsp)
movq 0x1e8(%rsp), %rdi
movq 0x148(%rsp), %rsi
callq 0x36910
movl %eax, 0x138(%rsp)
movq 0x1e8(%rsp), %rdi
movq 0x140(%rsp), %rsi
callq 0x36910
movq 0xe8(%rsp), %rdi
movl %eax, 0x134(%rsp)
movl 0x13c(%rsp), %esi
callq 0x13630
movq 0xe8(%rsp), %rdi
movq %rax, 0x128(%rsp)
movl 0x138(%rsp), %esi
callq 0x13630
movq 0xe8(%rsp), %rdi
movq %rax, 0x120(%rsp)
movl 0x134(%rsp), %esi
callq 0x13630
movq 0xe8(%rsp), %rdi
movq %rax, 0x118(%rsp)
movq 0x128(%rsp), %rsi
movq 0x120(%rsp), %rdx
movq 0x118(%rsp), %rcx
movq 0x48(%rdi), %r8
movslq 0x164(%rsp), %rax
imulq $0xc8, %rax, %rax
addq %rax, %r8
movq (%rdi), %rax
callq *0x48(%rax)
movq 0xe8(%rsp), %rdi
movq %rax, 0x110(%rsp)
movq 0x110(%rsp), %rsi
callq 0x369a0
cmpl 0x164(%rsp), %eax
je 0x21f73
leaq 0x1113a4(%rip), %rdi    # 0x1332aa
movb $0x0, %al
callq 0xd4e20
jmp 0x21f73
movq 0x60(%rsp), %rcx
movq %rax, %rsi
movq 0x30(%rsp), %rax
movq %rsi, 0x1e0(%rsp)
movl %edx, 0x1dc(%rsp)
cmpq %rax, %rcx
movq %rax, 0x20(%rsp)
je 0x21f5f
movq 0x20(%rsp), %rdi
addq $-0xc8, %rdi
movq %rdi, 0x18(%rsp)
callq 0x367a0
movq 0x60(%rsp), %rcx
movq 0x18(%rsp), %rax
cmpq %rcx, %rax
movq %rax, 0x20(%rsp)
jne 0x21f35
movq 0x48(%rsp), %rsi
movq 0x58(%rsp), %rdi
callq 0xf990
jmp 0x2204a
movq 0x110(%rsp), %rax
movq %rax, (%rsp)
movq 0x1e8(%rsp), %rdi
movq 0x158(%rsp), %rsi
callq 0x369e0
movq (%rsp), %rsi
movq 0xe8(%rsp), %rdi
movl %eax, %edx
callq 0x369c0
movq 0x110(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x1e8(%rsp), %rdi
movq 0x158(%rsp), %rsi
callq 0x36a20
movq 0x8(%rsp), %rsi
movq 0xe8(%rsp), %rdi
movl %eax, %edx
callq 0x36a00
movq 0x110(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x1e8(%rsp), %rdi
movq 0x158(%rsp), %rsi
callq 0x36a60
movq 0xe8(%rsp), %rdi
movq 0x10(%rsp), %rsi
movl %eax, %edx
callq 0x36a40
movl 0x164(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x164(%rsp)
jmp 0x21d50
movq 0xe8(%rsp), %rdi
movq (%rdi), %rax
callq *0x290(%rax)
movq 0xe8(%rsp), %rax
addq $0x1f8, %rsp            # imm = 0x1F8
retq
movq 0x1e0(%rsp), %rdi
callq 0xf890
nopw (%rax,%rax)