| 2098 | } |
| 2099 | |
| 2100 | template<> void *Resource<TSShape>::create(const Torque::Path &path) |
| 2101 | { |
| 2102 | // Execute the shape script if it exists |
| 2103 | Torque::Path scriptPath(path); |
| 2104 | scriptPath.setExtension("cs"); |
| 2105 | |
| 2106 | // Don't execute the script if we're already doing so! |
| 2107 | StringTableEntry currentScript = Platform::stripBasePath(CodeBlock::getCurrentCodeBlockFullPath()); |
| 2108 | if (!scriptPath.getFullPath().equal(currentScript)) |
| 2109 | { |
| 2110 | Torque::Path scriptPathDSO(scriptPath); |
| 2111 | scriptPathDSO.setExtension("cs.dso"); |
| 2112 | |
| 2113 | if (Torque::FS::IsFile(scriptPathDSO) || Torque::FS::IsFile(scriptPath)) |
| 2114 | { |
| 2115 | String evalCmd = "exec(\"" + scriptPath + "\");"; |
| 2116 | |
| 2117 | String instantGroup = Con::getVariable("InstantGroup"); |
| 2118 | Con::setIntVariable("InstantGroup", RootGroupId); |
| 2119 | Con::evaluate((const char*)evalCmd.c_str(), false, scriptPath.getFullPath()); |
| 2120 | Con::setVariable("InstantGroup", instantGroup.c_str()); |
| 2121 | } |
| 2122 | } |
| 2123 | |
| 2124 | // Attempt to load the shape |
| 2125 | TSShape * ret = 0; |
| 2126 | bool readSuccess = false; |
| 2127 | const String extension = path.getExtension(); |
| 2128 | |
| 2129 | if ( extension.equal( "dts", String::NoCase ) ) |
| 2130 | { |
| 2131 | FileStream stream; |
| 2132 | stream.open( path.getFullPath(), Torque::FS::File::Read ); |
| 2133 | if ( stream.getStatus() != Stream::Ok ) |
| 2134 | { |
| 2135 | Con::errorf( "Resource<TSShape>::create - Could not open '%s'", path.getFullPath().c_str() ); |
| 2136 | return NULL; |
| 2137 | } |
| 2138 | |
| 2139 | ret = new TSShape; |
| 2140 | readSuccess = ret->read(&stream); |
| 2141 | } |
| 2142 | else if ( extension.equal( "dae", String::NoCase ) || extension.equal( "kmz", String::NoCase ) ) |
| 2143 | { |
| 2144 | #ifdef TORQUE_COLLADA |
| 2145 | // Attempt to load the DAE file |
| 2146 | ret = loadColladaShape(path); |
| 2147 | readSuccess = (ret != NULL); |
| 2148 | #else |
| 2149 | // No COLLADA support => attempt to load the cached DTS file instead |
| 2150 | Torque::Path cachedPath = path; |
| 2151 | cachedPath.setExtension("cached.dts"); |
| 2152 | |
| 2153 | FileStream stream; |
| 2154 | stream.open( cachedPath.getFullPath(), Torque::FS::File::Read ); |
| 2155 | if ( stream.getStatus() != Stream::Ok ) |
| 2156 | { |
| 2157 | Con::errorf( "Resource<TSShape>::create - Could not open '%s'", cachedPath.getFullPath().c_str() ); |
nothing calls this directly
no test coverage detected