// File: /workspace/github_cpp_makefile_star2_O1/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 0x29794
movq %rax, %r12
leaq 0xb2f43(%rip), %rsi     # 0xdc5ab
movl $0x4, %edx
movq %rax, %rdi
callq 0x213d0
testl %eax, %eax
je 0x297ac
leaq 0xb2f2c(%rip), %rsi     # 0xdc5b0
movl $0x4, %edx
movq %r12, %rdi
callq 0x213d0
testl %eax, %eax
je 0x297bf
leaq 0xb2f15(%rip), %rsi     # 0xdc5b5
movl $0x4, %edx
movq %r12, %rdi
callq 0x213d0
testl %eax, %eax
je 0x297d2
leaq 0xb2efe(%rip), %rsi     # 0xdc5ba
movl $0x5, %edx
movq %r12, %rdi
callq 0x213d0
testl %eax, %eax
je 0x297e2
leaq 0xb3bb8(%rip), %rsi     # 0xdd290
movl $0x4, %edx
movq %r12, %rdi
callq 0x213d0
testl %eax, %eax
je 0x297f2
leaq 0xb2ecc(%rip), %rsi     # 0xdc5c0
movl $0x4, %edx
movq %r12, %rdi
callq 0x213d0
testl %eax, %eax
je 0x2980a
leaq 0xb3822(%rip), %rsi     # 0xdcf32
movl $0x4, %edx
movq %r12, %rdi
callq 0x213d0
testl %eax, %eax
je 0x2981a
leaq 0xb2e99(%rip), %rsi     # 0xdc5c5
movl $0x4, %edx
movq %r12, %rdi
callq 0x213d0
testl %eax, %eax
je 0x2982a
leaq 0xb2e82(%rip), %rsi     # 0xdc5ca
movl $0x4, %edx
movq %r12, %rdi
callq 0x213d0
testl %eax, %eax
je 0x2983a
leaq 0xb2e6b(%rip), %rsi     # 0xdc5cf
movl $0x5, %edx
movq %r12, %rdi
callq 0x213d0
testl %eax, %eax
je 0x2984a
leaq 0xb2e55(%rip), %rdi     # 0xdc5d5
xorl %ebp, %ebp
movq %rbx, %rsi
movq %r12, %rdx
xorl %eax, %eax
callq 0x8b53a
jmp 0x2996e
leaq 0xb2de5(%rip), %rdi     # 0xdc580
xorl %ebp, %ebp
movq %rbx, %rsi
xorl %eax, %eax
callq 0x8b53a
jmp 0x2996e
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x29982
jmp 0x29858
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x2b8ba
jmp 0x29858
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x2bfa2
jmp 0x29858
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x2c59a
jmp 0x29858
testq %r15, %r15
jne 0x297fa
movq (%r14), %r15
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x30f33
jmp 0x29858
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x2cba0
jmp 0x29858
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x2d1b6
jmp 0x29858
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x2d266
jmp 0x29858
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x2d922
jmp 0x29858
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x2deb8
testl %eax, %eax
je 0x2995c
leaq 0x78(%r14), %rdi
leaq 0x11b215(%rip), %rsi    # 0x144a80
callq 0x40520
testl %eax, %eax
je 0x2993c
movq (%r14), %rdi
callq 0x3c988
movq %rax, %rdi
callq 0x6e16c
mulsd 0xb2790(%rip), %xmm0    # 0xdc020
movsd %xmm0, (%rsp)
movq (%r14), %rdi
callq 0x3c988
movq (%rax), %rcx
leaq 0x50(%rsp), %r12
movq %r12, %rdi
movq %rax, %rsi
callq *0x68(%rcx)
leaq 0x38(%rsp), %r15
movsd 0xb2c15(%rip), %xmm2    # 0xdc4d0
xorpd %xmm0, %xmm0
xorps %xmm1, %xmm1
movq %r15, %rdi
callq 0x76d52
leaq 0x20(%rsp), %r13
movsd 0xb2741(%rip), %xmm1    # 0xdc018
xorpd %xmm0, %xmm0
xorps %xmm2, %xmm2
movq %r13, %rdi
callq 0x76d52
leaq 0x8(%rsp), %rbp
movq %rbp, %rdi
movq %r12, %rsi
callq 0x762ca
movsd 0xb272a(%rip), %xmm2    # 0xdc028
movsd (%rsp), %xmm3
mulsd %xmm3, %xmm2
mulsd 0xb2741(%rip), %xmm3    # 0xdc050
leaq 0x68(%rsp), %r12
movsd 0xb2bbc(%rip), %xmm0    # 0xdc4d8
movq %r12, %rdi
movq %rbp, %rsi
movq %r15, %rdx
movq %r13, %rcx
movaps %xmm0, %xmm1
callq 0x3fee0
leaq 0x70(%r14), %rdi
movq %r12, %rsi
callq 0x3e614
movq 0x148(%r14), %rdi
testq %rdi, %rdi
je 0x2994d
callq 0x21ae0
testq %rbx, %rbx
je 0x29960
movq %rbx, %rdi
callq 0x8b397
jmp 0x29962
xorl %ebp, %ebp
jmp 0x2996e
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