// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R3Graphics/R3Scene.cpp
// Function: gaps::R3Scene::ReadFile(char const*, gaps::R3SceneNode*)
int R3Scene::
ReadFile(const char *filename, R3SceneNode *parent_node)
{
  // Parse input filename extension
  const char *extension;
  if (!(extension = strrchr(filename, '.'))) {
    RNFail("Filename %s has no extension (e.g., .txt)\n", filename);
    return 0;
  }

  // Read file of appropriate type
  if (!strncmp(extension, ".scn", 4)) {
    if (!ReadPrincetonFile(filename, parent_node)) return 0;
  }
  else if (!strncmp(extension, ".ssc", 4)) {
    if (!ReadParseFile(filename, parent_node)) return 0;
  }
  else if (!strncmp(extension, ".txt", 4)) {
    if (!ReadSupportHierarchyFile(filename, parent_node)) return 0;
  }
  else if (!strncmp(extension, ".hier", 5)) {
    if (!ReadGrammarHierarchyFile(filename, parent_node)) return 0;
  }
  else if (!strncmp(extension, ".obj", 4)) {
    if (!ReadObjFile(filename, parent_node)) return 0;
  }
  else if (!strncmp(extension, ".ply", 4)) {
    if (!ReadPlyFile(filename, parent_node)) return 0;
  }
  else if (!strncmp(extension, ".off", 4)) {
    if (!ReadMeshFile(filename, parent_node)) return 0;
  }
  else if (!strncmp(extension, ".rct", 4)) {
    if (!ReadRectangleFile(filename, parent_node)) return 0;
  }
  else if (!strncmp(extension, ".obb", 4)) {
    if (!ReadObbFile(filename, parent_node)) return 0;
  }
  else if (!strncmp(extension, ".json", 5)) {
    if (!ReadSUNCGFile(filename, parent_node)) return 0;
  }
  else {
    RNFail("Unable to read file %s (unrecognized extension: %s)\n", filename, extension);
    return 0;
  }

  // Provide default camera
  if (Camera() == R3default_camera) {
    double scene_radius = BBox().DiagonalRadius();
    R3Point scene_center = BBox().Centroid();
    R3Vector towards = R3Vector(0, 0, -1);
    R3Vector up = R3Vector(0, 1, 0);
    R3Point eye = scene_center;
    R3Camera camera(eye, towards, up, 0.25, 0.25, 0.01 * scene_radius, 100 * scene_radius);
    SetCamera(camera);
  }

  // Set filename
  SetFilename(filename);

  // Return success
  return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movq %rdx, %r15
movq %rsi, %rbx
movq %rdi, %r14
movq %rsi, %rdi
movl $0x2e, %esi
callq 0x219b0
testq %rax, %rax
je 0x296c6
movq %rax, %r12
leaq 0xb1021(%rip), %rsi     # 0xda5bb
movl $0x4, %edx
movq %rax, %rdi
callq 0x213d0
testl %eax, %eax
je 0x296de
leaq 0xb100a(%rip), %rsi     # 0xda5c0
movl $0x4, %edx
movq %r12, %rdi
callq 0x213d0
testl %eax, %eax
je 0x296f1
leaq 0xb0ff3(%rip), %rsi     # 0xda5c5
movl $0x4, %edx
movq %r12, %rdi
callq 0x213d0
testl %eax, %eax
je 0x29704
leaq 0xb0fdc(%rip), %rsi     # 0xda5ca
movl $0x5, %edx
movq %r12, %rdi
callq 0x213d0
testl %eax, %eax
je 0x29714
leaq 0xb1c96(%rip), %rsi     # 0xdb2a0
movl $0x4, %edx
movq %r12, %rdi
callq 0x213d0
testl %eax, %eax
je 0x29724
leaq 0xb0faa(%rip), %rsi     # 0xda5d0
movl $0x4, %edx
movq %r12, %rdi
callq 0x213d0
testl %eax, %eax
je 0x2973c
leaq 0xb1900(%rip), %rsi     # 0xdaf42
movl $0x4, %edx
movq %r12, %rdi
callq 0x213d0
testl %eax, %eax
je 0x2974c
leaq 0xb0f77(%rip), %rsi     # 0xda5d5
movl $0x4, %edx
movq %r12, %rdi
callq 0x213d0
testl %eax, %eax
je 0x2975c
leaq 0xb0f60(%rip), %rsi     # 0xda5da
movl $0x4, %edx
movq %r12, %rdi
callq 0x213d0
testl %eax, %eax
je 0x2976c
leaq 0xb0f49(%rip), %rsi     # 0xda5df
movl $0x5, %edx
movq %r12, %rdi
callq 0x213d0
testl %eax, %eax
je 0x2977c
leaq 0xb0f33(%rip), %rdi     # 0xda5e5
xorl %ebp, %ebp
movq %rbx, %rsi
movq %r12, %rdx
xorl %eax, %eax
callq 0x8a0fe
jmp 0x298a0
leaq 0xb0ec3(%rip), %rdi     # 0xda590
xorl %ebp, %ebp
movq %rbx, %rsi
xorl %eax, %eax
callq 0x8a0fe
jmp 0x298a0
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x298b4
jmp 0x2978a
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x2b7d4
jmp 0x2978a
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x2be74
jmp 0x2978a
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x2c418
jmp 0x2978a
testq %r15, %r15
jne 0x2972c
movq (%r14), %r15
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x30c77
jmp 0x2978a
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x2c9f8
jmp 0x2978a
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x2cffa
jmp 0x2978a
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x2d0aa
jmp 0x2978a
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x2d75a
jmp 0x2978a
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x2dcd0
testl %eax, %eax
je 0x2988e
leaq 0x78(%r14), %rdi
leaq 0x1192e3(%rip), %rsi    # 0x142a80
callq 0x400a4
testl %eax, %eax
je 0x2986e
movq (%r14), %rdi
callq 0x3c478
movq %rax, %rdi
callq 0x6d330
mulsd 0xb085e(%rip), %xmm0    # 0xda020
movsd %xmm0, (%rsp)
movq (%r14), %rdi
callq 0x3c478
movq (%rax), %rcx
leaq 0x50(%rsp), %r12
movq %r12, %rdi
movq %rax, %rsi
callq *0x68(%rcx)
leaq 0x38(%rsp), %r15
movsd 0xb0ce3(%rip), %xmm2    # 0xda4d0
xorpd %xmm0, %xmm0
xorps %xmm1, %xmm1
movq %r15, %rdi
callq 0x75e5e
leaq 0x20(%rsp), %r13
movsd 0xb080f(%rip), %xmm1    # 0xda018
xorpd %xmm0, %xmm0
xorps %xmm2, %xmm2
movq %r13, %rdi
callq 0x75e5e
leaq 0x8(%rsp), %rbp
movq %rbp, %rdi
movq %r12, %rsi
callq 0x753da
movsd 0xb07f8(%rip), %xmm2    # 0xda028
movsd (%rsp), %xmm3
mulsd %xmm3, %xmm2
mulsd 0xb080f(%rip), %xmm3    # 0xda050
leaq 0x68(%rsp), %r12
movsd 0xb0c8a(%rip), %xmm0    # 0xda4d8
movq %r12, %rdi
movq %rbp, %rsi
movq %r15, %rdx
movq %r13, %rcx
movaps %xmm0, %xmm1
callq 0x3fa64
leaq 0x70(%r14), %rdi
movq %r12, %rsi
callq 0x3e154
movq 0x148(%r14), %rdi
testq %rdi, %rdi
je 0x2987f
callq 0x21ad0
testq %rbx, %rbx
je 0x29892
movq %rbx, %rdi
callq 0x89f5f
jmp 0x29894
xorl %ebp, %ebp
jmp 0x298a0
xorl %eax, %eax
movq %rax, 0x148(%r14)
movl $0x1, %ebp
movl %ebp, %eax
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq