// File: 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:
subq $0x128, %rsp            # imm = 0x128
movq %rdi, 0x118(%rsp)
movq %rsi, 0x110(%rsp)
movq %rdx, 0x108(%rsp)
movq 0x118(%rsp), %rax
movq %rax, (%rsp)
movq 0x110(%rsp), %rdi
movl $0x2e, %esi
callq 0x22b10
movq %rax, 0x100(%rsp)
cmpq $0x0, %rax
jne 0x2e931
movq 0x110(%rsp), %rsi
leaq 0x15fcee(%rip), %rdi    # 0x18e608
movb $0x0, %al
callq 0xf3b00
movl $0x0, 0x124(%rsp)
jmp 0x2edae
movq 0x100(%rsp), %rdi
leaq 0x15fcf3(%rip), %rsi    # 0x18e633
movl $0x4, %edx
callq 0x22450
cmpl $0x0, %eax
jne 0x2e982
movq (%rsp), %rdi
movq 0x110(%rsp), %rsi
movq 0x108(%rsp), %rdx
callq 0x2edc0
cmpl $0x0, %eax
jne 0x2e97d
movl $0x0, 0x124(%rsp)
jmp 0x2edae
jmp 0x2ec95
movq 0x100(%rsp), %rdi
leaq 0x15fca7(%rip), %rsi    # 0x18e638
movl $0x4, %edx
callq 0x22450
cmpl $0x0, %eax
jne 0x2e9d3
movq (%rsp), %rdi
movq 0x110(%rsp), %rsi
movq 0x108(%rsp), %rdx
callq 0x32740
cmpl $0x0, %eax
jne 0x2e9ce
movl $0x0, 0x124(%rsp)
jmp 0x2edae
jmp 0x2ec93
movq 0x100(%rsp), %rdi
leaq 0x15fc5b(%rip), %rsi    # 0x18e63d
movl $0x4, %edx
callq 0x22450
cmpl $0x0, %eax
jne 0x2ea24
movq (%rsp), %rdi
movq 0x110(%rsp), %rsi
movq 0x108(%rsp), %rdx
callq 0x332f0
cmpl $0x0, %eax
jne 0x2ea1f
movl $0x0, 0x124(%rsp)
jmp 0x2edae
jmp 0x2ec91
movq 0x100(%rsp), %rdi
leaq 0x15fc0f(%rip), %rsi    # 0x18e642
movl $0x5, %edx
callq 0x22450
cmpl $0x0, %eax
jne 0x2ea75
movq (%rsp), %rdi
movq 0x110(%rsp), %rsi
movq 0x108(%rsp), %rdx
callq 0x33c80
cmpl $0x0, %eax
jne 0x2ea70
movl $0x0, 0x124(%rsp)
jmp 0x2edae
jmp 0x2ec8f
movq 0x100(%rsp), %rdi
leaq 0x1608cd(%rip), %rsi    # 0x18f351
movl $0x4, %edx
callq 0x22450
cmpl $0x0, %eax
jne 0x2eac6
movq (%rsp), %rdi
movq 0x110(%rsp), %rsi
movq 0x108(%rsp), %rdx
callq 0x34710
cmpl $0x0, %eax
jne 0x2eac1
movl $0x0, 0x124(%rsp)
jmp 0x2edae
jmp 0x2ec8d
movq 0x100(%rsp), %rdi
leaq 0x15fb73(%rip), %rsi    # 0x18e648
movl $0x4, %edx
callq 0x22450
cmpl $0x0, %eax
jne 0x2eb17
movq (%rsp), %rdi
movq 0x110(%rsp), %rsi
movq 0x108(%rsp), %rdx
callq 0x34760
cmpl $0x0, %eax
jne 0x2eb12
movl $0x0, 0x124(%rsp)
jmp 0x2edae
jmp 0x2ec8b
movq 0x100(%rsp), %rdi
leaq 0x1604c9(%rip), %rsi    # 0x18efef
movl $0x4, %edx
callq 0x22450
cmpl $0x0, %eax
jne 0x2eb68
movq (%rsp), %rdi
movq 0x110(%rsp), %rsi
movq 0x108(%rsp), %rdx
callq 0x35610
cmpl $0x0, %eax
jne 0x2eb63
movl $0x0, 0x124(%rsp)
jmp 0x2edae
jmp 0x2ec89
movq 0x100(%rsp), %rdi
leaq 0x15fad6(%rip), %rsi    # 0x18e64d
movl $0x4, %edx
callq 0x22450
cmpl $0x0, %eax
jne 0x2ebb9
movq (%rsp), %rdi
movq 0x110(%rsp), %rsi
movq 0x108(%rsp), %rdx
callq 0x35750
cmpl $0x0, %eax
jne 0x2ebb4
movl $0x0, 0x124(%rsp)
jmp 0x2edae
jmp 0x2ec87
movq 0x100(%rsp), %rdi
leaq 0x15fa8a(%rip), %rsi    # 0x18e652
movl $0x4, %edx
callq 0x22450
cmpl $0x0, %eax
jne 0x2ec07
movq (%rsp), %rdi
movq 0x110(%rsp), %rsi
movq 0x108(%rsp), %rdx
callq 0x362b0
cmpl $0x0, %eax
jne 0x2ec05
movl $0x0, 0x124(%rsp)
jmp 0x2edae
jmp 0x2ec85
movq 0x100(%rsp), %rdi
leaq 0x15fa41(%rip), %rsi    # 0x18e657
movl $0x5, %edx
callq 0x22450
cmpl $0x0, %eax
jne 0x2ec55
movq (%rsp), %rdi
movq 0x110(%rsp), %rsi
movq 0x108(%rsp), %rdx
callq 0x36b80
cmpl $0x0, %eax
jne 0x2ec53
movl $0x0, 0x124(%rsp)
jmp 0x2edae
jmp 0x2ec83
movq 0x110(%rsp), %rsi
movq 0x100(%rsp), %rdx
leaq 0x15f9f1(%rip), %rdi    # 0x18e65d
movb $0x0, %al
callq 0xf3b00
movl $0x0, 0x124(%rsp)
jmp 0x2edae
jmp 0x2ec85
jmp 0x2ec87
jmp 0x2ec89
jmp 0x2ec8b
jmp 0x2ec8d
jmp 0x2ec8f
jmp 0x2ec91
jmp 0x2ec93
jmp 0x2ec95
movq (%rsp), %rdi
callq 0x2b8e0
movq %rax, %rdi
leaq 0x1cd118(%rip), %rsi    # 0x1fbdc0
callq 0x5e2f0
cmpl $0x0, %eax
je 0x2ed92
movq (%rsp), %rdi
callq 0x2b590
movq %rax, %rdi
callq 0x2b5b0
movq (%rsp), %rdi
movsd %xmm0, 0xf8(%rsp)
callq 0x2b590
movq %rax, %rsi
movq (%rsi), %rax
leaq 0xe0(%rsp), %rdi
callq *0x68(%rax)
leaq 0xc8(%rsp), %rdi
xorps %xmm1, %xmm1
movsd 0x15f8b3(%rip), %xmm2   # 0x18e5b0
movaps %xmm1, %xmm0
callq 0xcd9d0
leaq 0xb0(%rsp), %rdi
xorps %xmm2, %xmm2
movsd 0x15f2f8(%rip), %xmm1   # 0x18e010
movaps %xmm2, %xmm0
callq 0xcd9d0
leaq 0x98(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
callq 0xcc8b0
movsd 0x15f2fb(%rip), %xmm2   # 0x18e038
mulsd 0xf8(%rsp), %xmm2
movsd 0x15f2e2(%rip), %xmm3   # 0x18e030
mulsd 0xf8(%rsp), %xmm3
leaq 0x8(%rsp), %rdi
leaq 0x98(%rsp), %rsi
leaq 0xc8(%rsp), %rdx
leaq 0xb0(%rsp), %rcx
movsd 0x15f82c(%rip), %xmm1   # 0x18e5a8
movaps %xmm1, %xmm0
callq 0x5d920
movq (%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x2d170
movq (%rsp), %rdi
movq 0x110(%rsp), %rsi
callq 0x48830
movl $0x1, 0x124(%rsp)
movl 0x124(%rsp), %eax
addq $0x128, %rsp            # imm = 0x128
retq
nopl (%rax)