| 2138 | } |
| 2139 | |
| 2140 | template<> void *Resource<TSShape>::create(const Torque::Path &path) |
| 2141 | { |
| 2142 | // Execute the shape script if it exists |
| 2143 | Torque::Path scriptPath(path); |
| 2144 | scriptPath.setExtension(TORQUE_SCRIPT_EXTENSION); |
| 2145 | |
| 2146 | // Don't execute the script if we're already doing so! |
| 2147 | StringTableEntry currentScript = Platform::stripBasePath(CodeBlock::getCurrentCodeBlockFullPath()); |
| 2148 | if (!scriptPath.getFullPath().equal(currentScript)) |
| 2149 | { |
| 2150 | Torque::Path scriptPathDSO(scriptPath); |
| 2151 | scriptPathDSO.setExtension(TORQUE_SCRIPT_EXTENSION ".dso"); |
| 2152 | |
| 2153 | if (Torque::FS::IsFile(scriptPathDSO) || Torque::FS::IsFile(scriptPath)) |
| 2154 | { |
| 2155 | String evalCmd = "exec(\"" + scriptPath + "\");"; |
| 2156 | |
| 2157 | String instantGroup = Con::getVariable("InstantGroup"); |
| 2158 | Con::setIntVariable("InstantGroup", RootGroupId); |
| 2159 | Con::evaluate((const char*)evalCmd.c_str(), false, scriptPath.getFullPath()); |
| 2160 | Con::setVariable("InstantGroup", instantGroup.c_str()); |
| 2161 | } |
| 2162 | } |
| 2163 | |
| 2164 | // Attempt to load the shape |
| 2165 | TSShape * ret = 0; |
| 2166 | bool readSuccess = false; |
| 2167 | const String extension = path.getExtension(); |
| 2168 | |
| 2169 | if ( extension.equal( "dts", String::NoCase ) ) |
| 2170 | { |
| 2171 | FileStream stream; |
| 2172 | stream.open( path.getFullPath(), Torque::FS::File::Read ); |
| 2173 | if ( stream.getStatus() != Stream::Ok ) |
| 2174 | { |
| 2175 | Con::errorf( "Resource<TSShape>::create - Could not open '%s'", path.getFullPath().c_str() ); |
| 2176 | return NULL; |
| 2177 | } |
| 2178 | |
| 2179 | ret = new TSShape; |
| 2180 | readSuccess = ret->read(&stream); |
| 2181 | } |
| 2182 | else if ( extension.equal( "dae", String::NoCase ) || extension.equal( "kmz", String::NoCase ) ) |
| 2183 | { |
| 2184 | #ifdef TORQUE_COLLADA |
| 2185 | // Attempt to load the DAE file |
| 2186 | ret = loadColladaShape(path); |
| 2187 | readSuccess = (ret != NULL); |
| 2188 | #else |
| 2189 | // No COLLADA support => attempt to load the cached DTS file instead |
| 2190 | Torque::Path cachedPath = path; |
| 2191 | cachedPath.setExtension("cached.dts"); |
| 2192 | |
| 2193 | FileStream stream; |
| 2194 | stream.open( cachedPath.getFullPath(), Torque::FS::File::Read ); |
| 2195 | if ( stream.getStatus() != Stream::Ok ) |
| 2196 | { |
| 2197 | Con::errorf( "Resource<TSShape>::create - Could not open '%s'", cachedPath.getFullPath().c_str() ); |
nothing calls this directly
no test coverage detected