// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R3Shapes/R3TriangleArray.cpp
// Function: gaps::R3TriangleArray::LoadMesh(gaps::R3Mesh const&)
void R3TriangleArray::
LoadMesh(const R3Mesh& mesh)
{
  // Create vertices
  RNArray<R3TriangleVertex *> triangle_vertices;
  for (int i = 0; i < mesh.NVertices(); i++) {
    R3MeshVertex *mesh_vertex = mesh.Vertex(i);
    const R3Point& position = mesh.VertexPosition(mesh_vertex);
    R3TriangleVertex *triangle_vertex = new R3TriangleVertex(position);
    triangle_vertices.Insert(triangle_vertex);
    vertices.Insert(triangle_vertex);

    // Check if should assign vertex normal
    RNBoolean smooth = TRUE;
    const RNAngle max_smooth_angle = RN_PI/5.0;
    for (int j = 0; j < mesh.VertexValence(mesh_vertex); j++) {
      R3MeshEdge *mesh_edge = mesh.EdgeOnVertex(mesh_vertex, j);
      RNAngle angle = mesh.EdgeInteriorAngle(mesh_edge);
      if (fabs(angle - RN_PI) > max_smooth_angle) { smooth = FALSE; break; }
    }

    // Assign vertex normal
    if (smooth) {
      const R3Vector& normal = mesh.VertexNormal(mesh_vertex);
      triangle_vertex->SetNormal(normal);
    }
    
    // Assign vertex color
    if (!mesh.VertexColor(mesh_vertex).IsBlack()) {
      triangle_vertex->SetColor(mesh.VertexColor(mesh_vertex));
    }

    // Assign vertex texture coordinates
    triangle_vertex->SetTextureCoords(mesh.VertexTextureCoords(mesh_vertex));
  }

  // Create triangles
  for (int i = 0; i < mesh.NFaces(); i++) {
    R3MeshFace *mesh_face = mesh.Face(i);
    int i0 = mesh.VertexID(mesh.VertexOnFace(mesh_face, 0));
    int i1 = mesh.VertexID(mesh.VertexOnFace(mesh_face, 1));
    int i2 = mesh.VertexID(mesh.VertexOnFace(mesh_face, 2));
    R3TriangleVertex *v0 = triangle_vertices.Kth(i0);
    R3TriangleVertex *v1 = triangle_vertices.Kth(i1);
    R3TriangleVertex *v2 = triangle_vertices.Kth(i2);
    R3Triangle *triangle = new R3Triangle(v0, v1, v2);
    triangles.Insert(triangle);
  }

  // Update everything
  Update();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %r14
movq %rdi, (%rsp)
leaq 0x10(%rsp), %rdi
callq 0x6f80c
cmpl $0x0, 0x14(%r14)
jle 0x52d20
movq (%rsp), %rax
leaq 0x8(%rax), %r15
leaq 0x57403(%rip), %rax     # 0xa9fc8
movsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
divsd 0x4f681(%rip), %xmm0    # 0xa2258
movsd %xmm0, 0x20(%rsp)
xorl %ebx, %ebx
movq 0x8(%r14), %rax
movq (%rax,%rbx,8), %rbp
movl $0x68, %edi
callq 0xe440
movq %rax, %r13
leaq 0x18(%rbp), %rsi
movq %rax, %rdi
callq 0x534a0
movl 0x1c(%rsp), %edx
leaq 0x10(%rsp), %rdi
movq %r13, %rsi
callq 0x6f8a2
movq (%rsp), %rax
movl 0x14(%rax), %edx
movq %r15, %rdi
movq %r13, %rsi
callq 0x6f8a2
cmpl $0x0, 0x14(%rbp)
jle 0x52c5e
xorl %r12d, %r12d
movq 0x8(%rbp), %rax
movq (%rax,%r12,8), %rsi
movq %r14, %rdi
callq 0x11f92
subsd 0x8(%rsp), %xmm0
andpd 0x4f626(%rip), %xmm0    # 0xa2270
ucomisd 0x20(%rsp), %xmm0
ja 0x52cbb
incq %r12
movslq 0x14(%rbp), %rax
cmpq %rax, %r12
jl 0x52c2c
testb $0x2, 0x78(%rbp)
jne 0x52c73
movq (%r14), %rax
movq %r14, %rdi
movq %rbp, %rsi
callq *0x2b0(%rax)
leaq 0x30(%rbp), %rsi
leaq 0x18(%r13), %rdi
callq 0x3d752
movsd 0x18(%r13), %xmm0
ucomisd 0x4f55a(%rip), %xmm0    # 0xa21e8
jne 0x52cb6
jp 0x52cb6
movsd 0x20(%r13), %xmm0
ucomisd 0x4f548(%rip), %xmm0    # 0xa21e8
jne 0x52cb6
jp 0x52cb6
movsd 0x28(%r13), %xmm0
ucomisd 0x4f536(%rip), %xmm0    # 0xa21e8
jne 0x52cb6
jnp 0x52cbb
orb $0x1, 0x59(%r13)
movsd 0x58(%rbp), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x52ce6
jp 0x52ce6
movsd 0x60(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jne 0x52ce6
jp 0x52ce6
movsd 0x68(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jne 0x52ce6
jnp 0x52cf8
leaq 0x58(%rbp), %rsi
leaq 0x30(%r13), %rdi
callq 0x6f712
orb $0x4, 0x59(%r13)
addq $0x48, %rbp
movq %r13, %rdi
addq $0x48, %rdi
movq %rbp, %rsi
callq 0x681de
orb $0x2, 0x59(%r13)
incq %rbx
movslq 0x14(%r14), %rax
cmpq %rax, %rbx
jl 0x52bdf
cmpl $0x0, 0x34(%r14)
jle 0x52da6
movq (%rsp), %rax
addq $0x18, %rax
movq %rax, 0x8(%rsp)
xorl %r15d, %r15d
movq 0x28(%r14), %rax
movq (%rax,%r15,8), %rax
movq 0x8(%rax), %rcx
movq 0x10(%rax), %rdx
movslq 0x70(%rcx), %rcx
movslq 0x70(%rdx), %rdx
movq 0x18(%rax), %rax
movslq 0x70(%rax), %rax
movq 0x10(%rsp), %rsi
movq (%rsi,%rcx,8), %r13
movq (%rsi,%rdx,8), %rbp
movq (%rsi,%rax,8), %rbx
movl $0x88, %edi
callq 0xe440
movq %rax, %r12
movq %rax, %rdi
movq %r13, %rsi
movq %rbp, %rdx
movq %rbx, %rcx
callq 0x539b8
movq (%rsp), %rax
movl 0x24(%rax), %edx
movq 0x8(%rsp), %rdi
movq %r12, %rsi
callq 0x6f8a2
incq %r15
movslq 0x34(%r14), %rax
cmpq %rax, %r15
jl 0x52d37
movq (%rsp), %rdi
movq (%rdi), %rax
callq *0x248(%rax)
leaq 0x10(%rsp), %rdi
callq 0x6f876
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x52df5
movq %rax, %rbx
movl $0x68, %esi
movq %r13, %rdi
jmp 0x52de6
movq %rax, %rbx
movl $0x88, %esi
movq %r12, %rdi
callq 0xe450
jmp 0x52df8
jmp 0x52df5
jmp 0x52df5
jmp 0x52df5
jmp 0x52df5
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x6f876
movq %rbx, %rdi
callq 0xe7e0