MCPcopy Create free account
hub / github.com/carbonengine/trinity / GetUvScaleFromAnnotation

Function GetUvScaleFromAnnotation

trinity/Shader/Tr2Effect.cpp:1320–1374  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1318}
1319
1320std::optional<float> GetUvScaleFromAnnotation( const char* paramName, const Tr2EffectParameterAnnotation& annotation, const Tr2ConstantEffectParameterStructureList& constParams )
1321{
1322 if( annotation.type == Tr2EffectParameterAnnotation::FLOAT )
1323 {
1324 return { annotation.floatValue };
1325 }
1326 else if( annotation.type == Tr2EffectParameterAnnotation::STRING )
1327 {
1328 std::string expr( annotation.stringValue );
1329 for( size_t i = 0; i < expr.length(); ++i )
1330 {
1331 auto& c = expr[i];
1332 if( c == '.' )
1333 {
1334 bool isId = false;
1335 for( size_t j = i; j > 0; --j )
1336 {
1337 auto pc = expr[j - 1];
1338 if( isdigit( pc ) )
1339 {
1340 continue;
1341 }
1342 if( isalpha( pc ) )
1343 {
1344 isId = true;
1345 break;
1346 }
1347 break;
1348 }
1349 if( isId )
1350 {
1351 c = '_';
1352 }
1353 }
1354 }
1355
1356 VariableFactoryArguments factoryArgs = { &constParams, false };
1357 CcpParser::Externals externals;
1358 externals.variableFactory = { &GetParserVariable, &factoryArgs };
1359 CcpParser::Program program;
1360 auto parsed = CcpParser::Parse( expr.c_str(), externals, program );
1361 if( !parsed )
1362 {
1363 if( !factoryArgs.hasInvalidVariable )
1364 {
1365 CCP_LOGWARN( "Invalid LodUvScale annotation for effect parameter \"%s\": %s", paramName, ToString( parsed, expr.c_str() ).c_str() );
1366 }
1367 return std::nullopt;
1368 }
1369 void* buffers[] = { (void*)&constParams[0] };
1370 std::unique_ptr<uint8_t[]> tempArena( new uint8_t[program.GetTempArenaSize()] );
1371 return program.Eval( buffers, tempArena.get() );
1372 }
1373 return std::nullopt;
1374}
1375
1376bool ExtractLodingAnnotations( std::array<float, ITriEffectTextureParameter::UV_SET_MAX_COUNT>& densityScale, const char* name, const Tr2EffectAnnotationMap& effectAnnotations, const Tr2ConstantEffectParameterStructureList& constParams )
1377{

Callers 1

ExtractLodingAnnotationsFunction · 0.85

Calls 4

ParseFunction · 0.85
EvalMethod · 0.80
getMethod · 0.80
ToStringFunction · 0.50

Tested by

no test coverage detected