byte parseCommandMoveplane( char *message, byte length, byte *position, command_t *command, bytecode_t *bytecode) { byte axis; byte offset; byte destination; rgb_t rgb; byte errorCode = 0; bytecode->executer = command->executer; skipWhitespace(message, length, position); errorCode = parseAxis(message, length, position, & axis); skipWhitespace(message, length, position); errorCode = parseOffset(message, length, position, & offset); skipWhitespace(message, length, position); errorCode = parseOffset(message, length, position, & destination); skipWhitespace(message, length, position); errorCode = parseRGB(message, length, position, & rgb); if (errorCode == 0) cubeMoveplane(axis, offset, destination, rgb); return(errorCode); };
byte parseCommandSphere( char *message, byte length, byte *position, command_t *command, bytecode_t *bytecode) { byte positionX1; byte positionY1; byte positionZ1; byte size; byte errorCode = 0; bytecode->executer = command->executer; skipWhitespace(message, length, position); errorCode = parsePosition(message, length, position, & positionX1, & positionY1, & positionZ1); skipWhitespace(message, length, position); errorCode = parseOffset(message, length, position, & size); skipWhitespace(message, length, position); errorCode = parseRGB(message, length, position, & bytecode->u.lit.colorFrom); skipWhitespace(message, length, position); errorCode = parseRGB(message, length, position, & bytecode->u.lit.colorTo); if (errorCode) { errorCode = 0; bytecode->u.lit.colorTo = BLACK; } if (errorCode == 0) cubeSphere( positionX1, positionY1, positionZ1, size, bytecode->u.lit.colorFrom, bytecode->u.lit.colorTo); return(errorCode); };
byte parseCommandBox( char *message, byte length, byte *position, command_t *command, bytecode_t *bytecode) { byte positionX1; byte positionY1; byte positionZ1; byte positionX2; byte positionY2; byte positionZ2; byte style = 0; byte errorCode = 0; bytecode->executer = command->executer; skipWhitespace(message, length, position); errorCode = parsePosition(message, length, position, & positionX1, & positionY1, & positionZ1); skipWhitespace(message, length, position); errorCode = parsePosition(message, length, position, & positionX2, & positionY2, & positionZ2); skipWhitespace(message, length, position); errorCode = parseRGB(message, length, position, & bytecode->u.lit.colorFrom); skipWhitespace(message, length, position); errorCode = parseOffset(message, length, position, & style); if (errorCode) { errorCode = 0; style = 0; } skipWhitespace(message, length, position); errorCode = parseRGB(message, length, position, & bytecode->u.lit.colorTo); if (errorCode) { errorCode = 0; bytecode->u.lit.colorTo = BLACK; } if (errorCode == 0) cubeBox( positionX1, positionY1, positionZ1, positionX2, positionY2, positionZ2, bytecode->u.lit.colorFrom, style, bytecode->u.lit.colorTo); return(errorCode); };
byte parseCommandSetplane( char *message, byte length, byte *position, command_t *command, bytecode_t *bytecode) { byte axis; byte offset; byte errorCode = 0; bytecode->executer = command->executer; skipWhitespace(message, length, position); errorCode = parseAxis(message, length, position, & axis); skipWhitespace(message, length, position); errorCode = parseOffset(message, length, position, & offset); skipWhitespace(message, length, position); errorCode = parseRGB(message, length, position, & bytecode->u.lit.colorFrom); if (errorCode == 0) cubeSetplane(axis, offset, bytecode->u.lit.colorFrom); return(errorCode); };
string token = ""; if (parentJointName == "") { //--- 'ROOT' _bvhStream >> token; } Joint joint; //--- Joint name _bvhStream >> token; joint.setName(token); //--- '{' _bvhStream >> token; CvPoint3D64f offset = parseOffset(); joint.setOffset(offset); //--- 'Channels' _bvhStream >> token; //--- 'Number of Channels' _bvhStream >> token; int channels = atoi(token.c_str()); joint.setNumberChannels(channels); //--- Channels' names for (int i = 0; i < channels; i++) { _bvhStream >> token; // cout << token << endl; }
void main( int argc, char **argv ) { FILE *fp; int ch; format fmt = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; char fmtset = 0; argv = ExpandEnv( &argc, argv ); for( ;; ) { ch = GetOpt( &argc, argv, "bcdDhoOsSxX", usageMsg ); if( ch == -1 ) { break; } if( strchr( "bcdDhoOsSxX", ch ) != NULL ) { fmtset = 1; switch( ch ) { // switch to set format type case 'h': fmt.b_hex = 1; break; case 'b': fmt.b_oct = 1; break; case 'c': fmt.b_asc = 1; break; case 'd': fmt.w_dec = 1; break; case 'D': fmt.dw_dec = 1; break; case 'o': fmt.w_oct = 1; break; case 'O': fmt.dw_oct = 1; break; case 's': fmt.w_sgn = 1; break; case 'S': fmt.dw_sgn = 1; break; case 'x': fmt.w_hex = 1; break; case 'X': fmt.dw_hex = 1; break; } } } if( !fmtset ) { fmt.w_oct = 1; // set default (octal words) } argv++; if( *argv == NULL || **argv == '+' ) { if( *argv != NULL ) { parseOffset( *argv, &fmt ); // get specified offset if( fmt.offset < 0 ) { Die( "od: invalid offset\n" ); // error } } setmode( STDIN_FILENO, O_BINARY ); // switch stdin to binary mode dumpFile( stdin, &fmt ); } else { if( argc == 3 ) { parseOffset( *(argv + 1), &fmt ); // get specified offset if( fmt.offset < 0 ) { Die( "od: invalid offset\n" ); // error } } if( (fp = fopen( *argv, "rb" )) == NULL ) { Die( "od: cannot open input file \"%s\"\n", *argv ); } dumpFile( fp, &fmt ); fclose( fp ); } }
Sprite* Sprite::create(Properties* properties) { // Check if the Properties is valid and has a valid namespace. if (!properties || strcmp(properties->getNamespace(), "sprite") != 0) { GP_ERROR("Properties object must be non-null and have namespace equal to 'sprite'."); return NULL; } // Get image path. const char* imagePath = properties->getString("path"); if (imagePath == NULL || strlen(imagePath) == 0) { GP_ERROR("Sprite is missing required image file path."); return NULL; } // Don't support loading custom effects Effect* effect = NULL; // Get width and height float width = -1.0f; float height = -1.0f; float widthPercentage = 0.0f; float heightPercentage = 0.0f; if (properties->exists("width")) { if (properties->getType("width") == Properties::NUMBER) { // Number only (200) width = properties->getFloat("width"); } else { // Number and something else (200%) widthPercentage = properties->getFloat("width") / 100.0f; } } if (properties->exists("height")) { if (properties->getType("height") == Properties::NUMBER) { height = properties->getFloat("height"); } else { heightPercentage = properties->getFloat("height") / 100.0f; } } Sprite* sprite; if (properties->exists("source")) { // Get source frame Rectangle source; properties->getVector4("source", (Vector4*)&source); // Get frame count int frameCount = properties->getInt("frameCount"); if (frameCount < 0) { GP_WARN("Sprites require at least one frame. Defaulting to frame count 1."); } if (frameCount < 1) { frameCount = 1; } // Load sprite sprite = Sprite::create(imagePath, width, height, source, frameCount, effect); } else { // Load sprite sprite = Sprite::create(imagePath, width, height, effect); } // Edit scaling of sprites if needed if (widthPercentage != 0.0f || heightPercentage != 0.0f) { if (widthPercentage != 0.0f) { sprite->_width *= widthPercentage; sprite->_frames[0].width *= widthPercentage; } if (heightPercentage != 0.0f) { sprite->_height *= heightPercentage; sprite->_frames[0].height *= heightPercentage; } } // Get anchor Vector4 vect; if (properties->getVector2("anchor", (Vector2*)&vect)) { sprite->setAnchor(*((Vector2*)&vect)); } // Get color if (properties->exists("color")) { switch (properties->getType("color")) { case Properties::VECTOR3: vect.w = 1.0f; properties->getVector3("color", (Vector3*)&vect); break; case Properties::VECTOR4: properties->getVector4("color", &vect); break; case Properties::STRING: default: properties->getColor("color", &vect); break; } sprite->setColor(vect); } // Get opacity if (properties->exists("opacity")) { sprite->setOpacity(properties->getFloat("opacity")); } // Get blend mode BlendMode mode; if (parseBlendMode(properties->getString("blendMode"), &mode)) { sprite->setBlendMode(mode); } // Get flip flags FlipFlags flags; if (parseFlipFlags(properties->getString("flip"), &flags)) { sprite->setFlip(flags); } // Get sprite offset Offset offset; if (parseOffset(properties->getString("offset"), &offset)) { sprite->setOffset(offset); } return sprite; }
SendingMessage::SendingMessage(scenario *msg_scenario, const char *src, bool skip_sanity, int dialog_number, bool use_txn) : ack(false),cancel(false), response(false) { // should we parse out the _n portion of call here or later? Here would be faster and more // in keepin with the existing style, I suppose... const char *osrc = src; char * literal; int literalLen; char * dest; char * key; char current_line[MAX_HEADER_LEN]; const char * line_mark = NULL; int num_cr = get_cr_number(src); this->msg_scenario = msg_scenario; this->dialog_number = dialog_number; dest = literal = (char *)malloc(strlen(src) + num_cr + 1); literalLen = 0; current_line[0] = '\0'; *dest = 0; while(*src) { /* If start of new line, copy through next \n into current_line */ if (current_line[0] == '\0') { line_mark = strchr(src, '\n'); if (line_mark) { int header_len = line_mark - src; if (header_len > MAX_HEADER_LEN-1) header_len = MAX_HEADER_LEN-1; memcpy(current_line, src, header_len); current_line[header_len] = '\0'; } } /* This hex encoding could be done in XML parsing, allowing us to skip * these conditionals and branches. */ if ((*src == '\\') && (*(src+1) == 'x')) { /* Allows any hex coded char like '\x5B' ([) */ src += 2; if (isxdigit(*src)) { int val = get_decimal_from_hex(*src); src++; if (isxdigit(*src)) { val = (val << 4) + get_decimal_from_hex(*src); } *dest++ = val & 0xff; } src++; } else if (*src == '\n') { *dest++ = '\r'; *dest++ = *src++; current_line[0] = '\0'; } else if (*src != '[') { *dest++ = *src++; } else { /* We have found a keyword, store the literal that we have been generating. */ literalLen = dest - literal; if (literalLen) { *dest = '\0'; literal = (char *)realloc(literal, literalLen + 1); if (!literal) { REPORT_ERROR("Out of memory!"); } MessageComponent *newcomp = (MessageComponent *)calloc(1, sizeof(MessageComponent)); if (!newcomp) { REPORT_ERROR("Out of memory!"); } newcomp->type = E_Message_Literal; newcomp->literal = literal; newcomp->literalLen = literalLen; // length without the terminator newcomp->dialog_number = dialog_number; messageComponents.push_back(newcomp); } else { free(literal); } dest = literal = (char *)malloc(strlen(src) + num_cr + 1); literalLen = 0; *dest = '\0'; /* Now lets determine which keyword we have. */ MessageComponent *newcomp = (MessageComponent *)calloc(1, sizeof(MessageComponent)); if (!newcomp) { REPORT_ERROR("Out of memory!"); } newcomp->dialog_number = dialog_number; char keyword [KEYWORD_SIZE+1]; src++; /* Like strchr, but don't count things in quotes. */ // cast away const of src [*UGLY*] for(key = (char *) src; *key && *key != '\n'; key++) { if (*key == '\"') { do { key++; } while(*key && *key != '\"' && *key != '\n'); } if (*key == ']') break; } if (*key == '\n') REPORT_ERROR("Cannot have end of line characters in the middle of keywords. Possibly a missing ']' or a duplicate 'CDATA[' section in scenario while parsing '%s'.", current_line); if (*key != ']') { key = NULL; } if((!key) || ((key - src) > KEYWORD_SIZE) || (!(key - src))) { REPORT_ERROR("Syntax error or invalid [keyword] in scenario while parsing '%s'", current_line); } memcpy(keyword, src, key - src); keyword[key - src] = 0; src = key + 1; // allow +/-n for numeric variables newcomp->offset = 0; if ((strncmp(keyword, "authentication", strlen("authentication")) && strncmp(keyword, "tdmmap", strlen("tdmmap")))) { newcomp->offset = parseOffset(keyword); /* end the string before the +/- sign so that the parser doesn't read it as an unrecognized keyword */ if(((key = strchr(keyword,'+')) || (key = strchr(keyword,'-'))) && isdigit(*(key+1))) *key = 0; } char *spc = NULL; char ospc; if ((spc = strchr(keyword, ' '))) { ospc = *spc; *spc = '\0'; } kw_map::iterator it = keyword_map.find(keyword); if (spc) { *spc = ospc; } if (it != keyword_map.end()) { newcomp->type = E_Message_Custom; newcomp->comp_param.fxn = it->second; messageComponents.push_back(newcomp); continue; } bool simple_keyword = false; for (unsigned int i = 0; i < sizeof(SimpleKeywords)/sizeof(SimpleKeywords[0]); i++) { if (!strcmp(keyword, SimpleKeywords[i].keyword)) { newcomp->type = SimpleKeywords[i].type; simple_keyword = true; break; } } // check ip addresses for optional specifier for ipv6 esc bool ip_keyword = false; if (!simple_keyword) { for (unsigned int i = 0; i< sizeof(IP_Keywords)/sizeof(IP_Keywords[0]); i++) { //exact match or contains full keyword and a space if ( !strcmp(keyword, IP_Keywords[i].keyword) || ( !strncmp(keyword, IP_Keywords[i].keyword, strlen(IP_Keywords[i].keyword) ) && ( strlen(keyword)> strlen(IP_Keywords[i].keyword )) && ( keyword[strlen(IP_Keywords[i].keyword)] == ' ') ) ) { newcomp->type = IP_Keywords[i].type; if ((IP_Keywords[i].type == E_Message_Local_IP2)&&(strlen(local_ip2)==0)) REPORT_ERROR("Scenario uses [local_ip2], requires use of -i2 command line argument"); if( strstr(keyword, "no_square_bracket") ) { // want the no escape version of the ip address switch (IP_Keywords[i].type) { case (E_Message_Remote_IP): newcomp->type = E_Message_Remote_IP_noesc; break; case (E_Message_Local_IP): newcomp->type = E_Message_Local_IP_noesc; break; case (E_Message_Local_IP2): newcomp->type = E_Message_Local_IP2_noesc; break; case (E_Message_Server_IP): newcomp->type = E_Message_Server_IP_noesc; break; case(E_Message_Media_IP): newcomp->type = E_Message_Media_IP_noesc; break; default: REPORT_ERROR("Unknown ip address specifier type %d while building message to send", IP_Keywords[i].keyword); break; } } ip_keyword = true; break; } }//for } bool dialog_keyword = false; for (unsigned int i = 0; i < sizeof(DialogSpecificKeywords)/sizeof(DialogSpecificKeywords[0]); i++) { if (strstr(keyword, DialogSpecificKeywords[i].keyword) == keyword) { newcomp->type = DialogSpecificKeywords[i].type; parse_dialog_number(keyword, newcomp); if ((use_txn) && (i <= HighestTransactionSpecificKeywordsIndex) && (newcomp->dialog_number != dialog_number)) { REPORT_ERROR("Cannot use 'dialog=' attribute in [%s] keyword when also specifying 'use_txn' for the message.\n", keyword); } parse_encoding(keyword, newcomp); dialog_keyword = true; break; } } if (newcomp->type == E_Message_Peer_Tag_Param || newcomp->type == E_Message_Remote_Tag_Param || newcomp->type == E_Message_Remote_Tag ) { parse_generated(keyword, newcomp); } if (simple_keyword || dialog_keyword || ip_keyword) { messageComponents.push_back(newcomp); continue; } /* Now handle all the keywords which are neither simple nor determined solely by dialog */ if(!strncmp(keyword, "field", strlen("field"))) { newcomp->type = E_Message_Injection; /* Parse out the interesting things like file and number. */ newcomp->comp_param.field_param.field = atoi(keyword + strlen("field")); char fileName[KEYWORD_SIZE]; getKeywordParam(keyword, "file=", fileName); if (fileName[0] == '\0') { if (!default_file) { REPORT_ERROR("No injection file was specified!\n"); } newcomp->comp_param.field_param.filename = strdup(default_file); } else { newcomp->comp_param.field_param.filename = strdup(fileName); } if (inFiles.find(newcomp->comp_param.field_param.filename) == inFiles.end()) { REPORT_ERROR("Invalid injection file: %s\n", fileName); } char line[KEYWORD_SIZE]; getKeywordParam(keyword, "line=", line); if (line[0]) { /* Turn this into a new message component. */ newcomp->comp_param.field_param.line = new SendingMessage(msg_scenario, line, true, dialog_number); } } else if(!strncmp(keyword, "file", strlen("file"))) { newcomp->type = E_Message_File; /* Parse out the interesting things like file and number. */ char fileName[KEYWORD_SIZE]; getKeywordParam(keyword, "name=", fileName); if (fileName[0] == '\0') { REPORT_ERROR("No name specified for 'file' keyword!\n"); } /* Turn this into a new message component. */ newcomp->comp_param.filename = new SendingMessage(msg_scenario, fileName, true, dialog_number); } else if(*keyword == '$') { newcomp->type = E_Message_Variable; if (!msg_scenario) { REPORT_ERROR("SendingMessage with variable usage outside of scenario!"); } newcomp->varId = msg_scenario->get_var(keyword + 1, "Variable keyword"); } else if(!strncmp(keyword, "fill", strlen("fill"))) { newcomp->type = E_Message_Fill; char filltext[KEYWORD_SIZE]; char varName[KEYWORD_SIZE]; getKeywordParam(keyword, "text=", filltext); if (filltext[0] == '\0') { strcpy(filltext, "X"); } getKeywordParam(keyword, "variable=", varName); newcomp->literal = strdup(filltext); newcomp->literalLen = strlen(newcomp->literal); if (!msg_scenario) { REPORT_ERROR("SendingMessage with variable usage outside of scenario!"); } newcomp->varId = msg_scenario->get_var(varName, "Fill Variable"); } else if(!strncmp(keyword, "last_", strlen("last_"))) { newcomp->type = E_Message_Last_Header; // parse optional dialog/value only parameter bool is_dialog_number = parse_dialog_number(keyword, newcomp); bool is_value_only = parse_value_only(keyword, newcomp); if (is_dialog_number || is_value_only) { // if dialog= specified, only copy header portion if (use_txn && strstr(keyword, "dialog=")) { REPORT_ERROR("Cannot use 'dialog=' attribute in [last_] keyword when also specifying 'use_txn' for the message.\n"); } const char *diagptr = strstr(keyword, "dialog="); const char *valueptr = strstr(keyword, "value_only="); const char *index; if(diagptr) { // if both pointers exist start from the one closer to the beginning if(valueptr) index = (diagptr < valueptr) ? diagptr : valueptr; else index = diagptr; } else if (valueptr) { index = valueptr; } else REPORT_ERROR("Incorrect formatting of options in \"last_\" header"); //Back up the pointer to the end of the last_* so we can extract * correctly while ((index > keyword) && (*(index-1) == ' ')) index--; newcomp->literal = strndup(keyword + strlen("last_"), index - keyword - strlen("last_")); } else newcomp->literal = strdup(keyword + strlen("last_")); newcomp->literalLen = strlen(newcomp->literal); } else if(!strncmp(keyword, "authentication", strlen("authentication"))) { parseAuthenticationKeyword(msg_scenario, newcomp, keyword); } #ifndef PCAPPLAY else if(!strcmp(keyword, "auto_media_port") || !strcmp(keyword, "media_port") || !strcmp(keyword, "media_ip") || !strcmp(keyword, "media_ip_type")) { REPORT_ERROR("The %s keyword requires PCAPPLAY.\n", keyword); } #endif #ifndef _USE_OPENSSL else if(!strcmp(keyword, "authentication")) { REPORT_ERROR("The %s keyword requires OpenSSL.\n", keyword); } #endif else { // scan for the generic parameters - must be last test int i = 0; while (generic[i]) { char *msg1 = *generic[i]; char *msg2 = *(generic[i] + 1); if(!strcmp(keyword, msg1)) { newcomp->type = E_Message_Literal; newcomp->literal = strdup(msg2); newcomp->literalLen = strlen(newcomp->literal); break; } ++i; } if (!generic[i]) { REPORT_ERROR("Unsupported keyword '%s' in xml scenario file", keyword); } } messageComponents.push_back(newcomp); } } if (literal[0]) { *dest++ = '\0'; literalLen = dest - literal; literal = (char *)realloc(literal, literalLen); if (!literal) { REPORT_ERROR("Out of memory!"); } MessageComponent *newcomp = (MessageComponent *)calloc(1, sizeof(MessageComponent)); if (!newcomp) { REPORT_ERROR("Out of memory!"); } newcomp->type = E_Message_Literal; newcomp->literal = literal; newcomp->literalLen = literalLen-1; messageComponents.push_back(newcomp); } else { free(literal); } if (skip_sanity) { cancel = response = ack = false; method = NULL; return; } if (numComponents() < 1) { REPORT_ERROR("Can not create a message that is empty!"); } if (getComponent(0)->type != E_Message_Literal) { REPORT_ERROR("You can not use a keyword for the METHOD or to generate \"SIP/2.0\" to ensure proper [cseq] operation!\n%s\n", osrc); } char *p = method = strdup(getComponent(0)->literal); char *q; while (isspace(*p)) { p++; } if (!(q = strchr(method, ' '))) { REPORT_ERROR("You can not use a keyword for the METHOD or to generate \"SIP/2.0\" to ensure proper [cseq] operation!%s\n", osrc); } *q++ = '\0'; while (isspace(*q)) { q++; } if (!strcmp(method, "SIP/2.0")) { char *endptr; code = strtol(q, &endptr, 10); if (*endptr && !isspace(*endptr)) { REPORT_ERROR("Invalid reply code: %s\n", q); } if (code < 100 || code >= 700) { REPORT_ERROR("Response codes must be in the range of 100-700"); } response = true; ack = false; cancel = false; free(method); method = NULL; } else { if (p != method) { memmove(method, p, strlen(p) + 1); } method = (char *)realloc(method, strlen(method) + 1); if (!method) { REPORT_ERROR("Out of memory"); } ack = (!strcmp(method, "ACK")); cancel = (!strcmp(method, "CANCEL")); response = false; } }
//----------------------------------------------------------------------------------- void HlmsJsonPbs::loadMaterial( const rapidjson::Value &json, const HlmsJson::NamedBlocks &blocks, HlmsDatablock *datablock ) { assert( dynamic_cast<HlmsPbsDatablock*>(datablock) ); HlmsPbsDatablock *pbsDatablock = static_cast<HlmsPbsDatablock*>(datablock); rapidjson::Value::ConstMemberIterator itor = json.FindMember("workflow"); if( itor != json.MemberEnd() && itor->value.IsString() ) pbsDatablock->setWorkflow( parseWorkflow( itor->value.GetString() ) ); itor = json.FindMember("brdf"); if( itor != json.MemberEnd() && itor->value.IsString() ) pbsDatablock->setBrdf( parseBrdf(itor->value.GetString()) ); itor = json.FindMember("two_sided"); if( itor != json.MemberEnd() && itor->value.IsBool() ) { pbsDatablock->setTwoSidedLighting( itor->value.GetBool(), true, pbsDatablock->getMacroblock(true)->mCullMode ); } itor = json.FindMember( "receive_shadows" ); if( itor != json.MemberEnd() && itor->value.IsBool() ) pbsDatablock->setReceiveShadows( itor->value.GetBool() ); itor = json.FindMember("transparency"); if( itor != json.MemberEnd() && itor->value.IsObject() ) { const rapidjson::Value &subobj = itor->value; float transparencyValue = pbsDatablock->getTransparency(); HlmsPbsDatablock::TransparencyModes transpMode = pbsDatablock->getTransparencyMode(); bool useAlphaFromTextures = pbsDatablock->getUseAlphaFromTextures(); itor = subobj.FindMember( "value" ); if( itor != subobj.MemberEnd() && itor->value.IsNumber() ) transparencyValue = static_cast<float>( itor->value.GetDouble() ); itor = subobj.FindMember( "mode" ); if( itor != subobj.MemberEnd() && itor->value.IsString() ) transpMode = parseTransparencyMode( itor->value.GetString() ); itor = subobj.FindMember( "use_alpha_from_textures" ); if( itor != subobj.MemberEnd() && itor->value.IsBool() ) useAlphaFromTextures = itor->value.GetBool(); const bool changeBlendblock = !json.HasMember( "blendblock" ); pbsDatablock->setTransparency( transparencyValue, transpMode, useAlphaFromTextures, changeBlendblock ); } PackedTexture packedTextures[NUM_PBSM_TEXTURE_TYPES]; itor = json.FindMember("diffuse"); if( itor != json.MemberEnd() && itor->value.IsObject() ) { const rapidjson::Value &subobj = itor->value; loadTexture( subobj, blocks, PBSM_DIFFUSE, pbsDatablock, packedTextures ); itor = subobj.FindMember( "value" ); if( itor != subobj.MemberEnd() && itor->value.IsArray() ) pbsDatablock->setDiffuse( parseVector3Array( itor->value ) ); itor = subobj.FindMember( "background" ); if( itor != subobj.MemberEnd() && itor->value.IsArray() ) pbsDatablock->setBackgroundDiffuse( parseColourValueArray( itor->value ) ); } itor = json.FindMember("specular"); if( itor != json.MemberEnd() && itor->value.IsObject() ) { const rapidjson::Value &subobj = itor->value; loadTexture( subobj, blocks, PBSM_SPECULAR, pbsDatablock, packedTextures ); itor = subobj.FindMember( "value" ); if( itor != subobj.MemberEnd() && itor->value.IsArray() ) pbsDatablock->setSpecular( parseVector3Array( itor->value ) ); } itor = json.FindMember("roughness"); if( itor != json.MemberEnd() && itor->value.IsObject() ) { const rapidjson::Value &subobj = itor->value; loadTexture( subobj, blocks, PBSM_ROUGHNESS, pbsDatablock, packedTextures ); itor = subobj.FindMember( "value" ); if( itor != subobj.MemberEnd() && itor->value.IsNumber() ) pbsDatablock->setRoughness( static_cast<float>( itor->value.GetDouble() ) ); } itor = json.FindMember("fresnel"); if( itor != json.MemberEnd() && itor->value.IsObject() ) { const rapidjson::Value &subobj = itor->value; loadTexture( subobj, blocks, PBSM_SPECULAR, pbsDatablock, packedTextures ); bool useIOR = false; bool isColoured = false; itor = subobj.FindMember( "mode" ); if( itor != subobj.MemberEnd() && itor->value.IsString() ) parseFresnelMode( itor->value.GetString(), isColoured, useIOR ); itor = subobj.FindMember( "value" ); if( itor != subobj.MemberEnd() && (itor->value.IsArray() || itor->value.IsNumber()) ) { Vector3 value; if( itor->value.IsArray() ) value = parseVector3Array( itor->value ); else value = static_cast<Real>( itor->value.GetDouble() ); if( !useIOR ) pbsDatablock->setFresnel( value, isColoured ); else pbsDatablock->setIndexOfRefraction( value, isColoured ); } } //There used to be a typo, so allow the wrong spelling. itor = json.FindMember("metalness"); if( itor == json.MemberEnd() ) itor = json.FindMember("metallness"); if( itor != json.MemberEnd() && itor->value.IsObject() ) { const rapidjson::Value &subobj = itor->value; loadTexture( subobj, blocks, PBSM_METALLIC, pbsDatablock, packedTextures ); itor = subobj.FindMember( "value" ); if( itor != subobj.MemberEnd() && itor->value.IsNumber() ) pbsDatablock->setMetalness( static_cast<float>( itor->value.GetDouble() ) ); } itor = json.FindMember("normal"); if( itor != json.MemberEnd() && itor->value.IsObject() ) { const rapidjson::Value &subobj = itor->value; loadTexture( subobj, blocks, PBSM_NORMAL, pbsDatablock, packedTextures ); itor = subobj.FindMember( "value" ); if( itor != subobj.MemberEnd() && itor->value.IsNumber() ) pbsDatablock->setNormalMapWeight( static_cast<float>( itor->value.GetDouble() ) ); } itor = json.FindMember("detail_weight"); if( itor != json.MemberEnd() && itor->value.IsObject() ) { const rapidjson::Value &subobj = itor->value; loadTexture( subobj, blocks, PBSM_DETAIL_WEIGHT, pbsDatablock, packedTextures ); } for( int i=0; i<4; ++i ) { const String iAsStr = StringConverter::toString(i); String texTypeName = "detail_diffuse" + iAsStr; itor = json.FindMember(texTypeName.c_str()); if( itor != json.MemberEnd() && itor->value.IsObject() ) { const rapidjson::Value &subobj = itor->value; loadTexture( subobj, blocks, static_cast<PbsTextureTypes>(PBSM_DETAIL0 + i), pbsDatablock, packedTextures ); itor = subobj.FindMember( "value" ); if( itor != subobj.MemberEnd() && itor->value.IsNumber() ) pbsDatablock->setDetailMapWeight( i, static_cast<float>( itor->value.GetDouble() ) ); itor = subobj.FindMember( "mode" ); if( itor != subobj.MemberEnd() && itor->value.IsString() ) pbsDatablock->setDetailMapBlendMode( i, parseBlendMode( itor->value.GetString() ) ); Vector4 offsetScale( 0, 0, 1, 1 ); itor = subobj.FindMember( "offset" ); if( itor != subobj.MemberEnd() && itor->value.IsArray() ) parseOffset( itor->value, offsetScale ); itor = subobj.FindMember( "scale" ); if( itor != subobj.MemberEnd() && itor->value.IsArray() ) parseScale( itor->value, offsetScale ); pbsDatablock->setDetailMapOffsetScale( i, offsetScale ); } texTypeName = "detail_normal" + iAsStr; itor = json.FindMember(texTypeName.c_str()); if( itor != json.MemberEnd() && itor->value.IsObject() ) { const rapidjson::Value &subobj = itor->value; loadTexture( subobj, blocks, static_cast<PbsTextureTypes>(PBSM_DETAIL0_NM + i), pbsDatablock, packedTextures ); itor = subobj.FindMember( "value" ); if( itor != subobj.MemberEnd() && itor->value.IsNumber() ) { pbsDatablock->setDetailNormalWeight( i, static_cast<float>( itor->value.GetDouble() ) ); } Vector4 offsetScale( 0, 0, 1, 1 ); itor = subobj.FindMember( "offset" ); if( itor != subobj.MemberEnd() && itor->value.IsArray() ) parseOffset( itor->value, offsetScale ); itor = subobj.FindMember( "scale" ); if( itor != subobj.MemberEnd() && itor->value.IsArray() ) parseScale( itor->value, offsetScale ); pbsDatablock->setDetailMapOffsetScale( i, offsetScale ); } } itor = json.FindMember("emissive"); if( itor != json.MemberEnd() && itor->value.IsObject() ) { const rapidjson::Value &subobj = itor->value; loadTexture( subobj, blocks, PBSM_EMISSIVE, pbsDatablock, packedTextures ); itor = subobj.FindMember( "value" ); if( itor != subobj.MemberEnd() && itor->value.IsArray() ) pbsDatablock->setEmissive( parseVector3Array( itor->value ) ); } itor = json.FindMember("reflection"); if( itor != json.MemberEnd() && itor->value.IsObject() ) { const rapidjson::Value &subobj = itor->value; loadTexture( subobj, blocks, PBSM_REFLECTION, pbsDatablock, packedTextures ); } pbsDatablock->_setTextures( packedTextures ); }