Alex Sakhartchouk | 17bd28b | 2011-02-11 17:51:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <iostream> |
| 18 | #include <vector> |
| 19 | |
| 20 | #include "ColladaLoader.h" |
| 21 | #include "ObjLoader.h" |
| 22 | |
| 23 | int main (int argc, char * const argv[]) { |
| 24 | const char *objExt = ".obj"; |
| 25 | const char *daeExt = ".dae"; |
| 26 | |
| 27 | if(argc != 3) { |
| 28 | printf("-----------------------------------------------------------------\n"); |
| 29 | printf("Usage:\n"); |
| 30 | printf("a3dconvert input_file a3d_output_file\n"); |
| 31 | printf("Currently .obj and .dae (collada) input files are accepted\n"); |
| 32 | printf("-----------------------------------------------------------------\n"); |
| 33 | return 1; |
| 34 | } |
| 35 | |
| 36 | bool isSuccessful = false; |
| 37 | |
| 38 | std::string filename = argv[1]; |
| 39 | size_t dotPos = filename.find_last_of('.'); |
| 40 | if (dotPos == std::string::npos) { |
| 41 | printf("Invalid input. Currently .obj and .dae (collada) input files are accepted\n"); |
| 42 | return 1; |
| 43 | } |
| 44 | |
| 45 | std::string ext = filename.substr(dotPos); |
| 46 | if (ext == daeExt) { |
| 47 | ColladaLoader converter; |
| 48 | isSuccessful = converter.init(argv[1]); |
| 49 | if (isSuccessful) { |
| 50 | isSuccessful = converter.convertToA3D(argv[2]); |
| 51 | } |
| 52 | } else if (ext == objExt) { |
| 53 | ObjLoader objConv; |
| 54 | isSuccessful = objConv.init(argv[1]); |
| 55 | if (isSuccessful) { |
| 56 | isSuccessful = objConv.convertToA3D(argv[2]); |
| 57 | } |
| 58 | } else { |
| 59 | printf("Invalid input. Currently .obj and .dae (collada) input files are accepted\n"); |
| 60 | return 1; |
| 61 | } |
| 62 | |
| 63 | if(isSuccessful) { |
| 64 | printf("---All done---\n"); |
| 65 | } else { |
| 66 | printf("---Encountered errors, conversion failed---\n"); |
| 67 | } |
| 68 | |
| 69 | return isSuccessful ? 0 : 1; |
| 70 | } |