void SVGFEBlendElement::parseAttribute(const QualifiedName& name, const AtomicString& value) { if (!isSupportedAttribute(name)) { SVGFilterPrimitiveStandardAttributes::parseAttribute(name, value); return; } if (name == SVGNames::modeAttr) { BlendMode mode = BlendModeNormal; if (parseBlendMode(value, mode)) setModeBaseValue(mode); return; } if (name == SVGNames::inAttr) { setIn1BaseValue(value); return; } if (name == SVGNames::in2Attr) { setIn2BaseValue(value); return; } ASSERT_NOT_REACHED(); }
bool parseCompositeAndBlendOperator(const String& s, CompositeOperator& op, BlendMode& blendOp) { for (int i = 0; i < numCompositeOperatorNames; i++) { if (s == compositeOperatorNames[i]) { op = static_cast<CompositeOperator>(i); blendOp = BlendModeNormal; return true; } } if (parseBlendMode(s, blendOp)) { // For now, blending will always assume source-over. This will be fixed in the future op = CompositeSourceOver; return true; } return false; }
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; }
//----------------------------------------------------------------------------------- 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 ); }