void Texture::SetParameters(const XMLElement& element) { XMLElement paramElem = element.GetChild(); while (paramElem) { String name = paramElem.GetName(); if (name == "address") { String coord = paramElem.GetAttributeLower("coord"); if (coord.Length() >= 1) { TextureCoordinate coordIndex = (TextureCoordinate)(coord[0] - 'u'); String mode = paramElem.GetAttributeLower("mode"); SetAddressMode(coordIndex, (TextureAddressMode)GetStringListIndex(mode.CString(), addressModeNames, ADDRESS_WRAP)); } } if (name == "border") SetBorderColor(paramElem.GetColor("color")); if (name == "filter") { String mode = paramElem.GetAttributeLower("mode"); SetFilterMode((TextureFilterMode)GetStringListIndex(mode.CString(), filterModeNames, FILTER_DEFAULT)); } if (name == "mipmap") SetNumLevels(paramElem.GetBool("enable") ? 0 : 1); if (name == "quality") { if (paramElem.HasAttribute("low")) SetMipsToSkip(QUALITY_LOW, paramElem.GetInt("low")); if (paramElem.HasAttribute("med")) SetMipsToSkip(QUALITY_MEDIUM, paramElem.GetInt("med")); if (paramElem.HasAttribute("medium")) SetMipsToSkip(QUALITY_MEDIUM, paramElem.GetInt("medium")); if (paramElem.HasAttribute("high")) SetMipsToSkip(QUALITY_HIGH, paramElem.GetInt("high")); } if (name == "srgb") SetSRGB(paramElem.GetBool("enable")); paramElem = paramElem.GetNext(); } }
bool ParticleEffect::Load(const XMLElement& source) { // Reset to defaults first so that missing parameters in case of a live reload behave as expected material_.Reset(); numParticles_ = DEFAULT_NUM_PARTICLES; updateInvisible_ = false; relative_ = true; scaled_ = true; sorted_ = false; fixedScreenSize_ = false; animationLodBias_ = 0.0f; emitterType_ = EMITTER_SPHERE; emitterSize_ = Vector3::ZERO; directionMin_ = DEFAULT_DIRECTION_MIN; directionMax_ = DEFAULT_DIRECTION_MAX; constantForce_ = Vector3::ZERO; dampingForce_ = 0.0f; activeTime_ = 0.0f; inactiveTime_ = 0.0; emissionRateMin_ = DEFAULT_EMISSION_RATE; emissionRateMax_ = DEFAULT_EMISSION_RATE; sizeMin_ = DEFAULT_PARTICLE_SIZE; sizeMax_ = DEFAULT_PARTICLE_SIZE; timeToLiveMin_ = DEFAULT_TIME_TO_LIVE; timeToLiveMax_ = DEFAULT_TIME_TO_LIVE; velocityMin_ = DEFAULT_VELOCITY; velocityMax_ = DEFAULT_VELOCITY; rotationMin_ = 0.0f; rotationMax_ = 0.0f; rotationSpeedMin_ = 0.0f; rotationSpeedMax_ = 0.0f; sizeAdd_ = 0.0f; sizeMul_ = 1.0f; colorFrames_.Clear(); textureFrames_.Clear(); faceCameraMode_ = FC_ROTATE_XYZ; if (source.IsNull()) { URHO3D_LOGERROR("Can not load particle effect from null XML element"); return false; } if (source.HasChild("material")) { loadMaterialName_ = source.GetChild("material").GetAttribute("name"); // If async loading, can not GetResource() the material. But can do a background request for it if (GetAsyncLoadState() == ASYNC_LOADING) GetSubsystem<ResourceCache>()->BackgroundLoadResource<Material>(loadMaterialName_, true, this); } if (source.HasChild("numparticles")) SetNumParticles((unsigned)source.GetChild("numparticles").GetInt("value")); if (source.HasChild("updateinvisible")) updateInvisible_ = source.GetChild("updateinvisible").GetBool("enable"); if (source.HasChild("relative")) relative_ = source.GetChild("relative").GetBool("enable"); if (source.HasChild("scaled")) scaled_ = source.GetChild("scaled").GetBool("enable"); if (source.HasChild("sorted")) sorted_ = source.GetChild("sorted").GetBool("enable"); if (source.HasChild("fixedscreensize")) fixedScreenSize_ = source.GetChild("fixedscreensize").GetBool("enable"); if (source.HasChild("animlodbias")) SetAnimationLodBias(source.GetChild("animlodbias").GetFloat("value")); if (source.HasChild("emittertype")) { String type = source.GetChild("emittertype").GetAttributeLower("value"); if (type == "point") { // Point emitter type is deprecated, handled as zero sized sphere emitterType_ = EMITTER_SPHERE; emitterSize_ = Vector3::ZERO; } else emitterType_ = (EmitterType)GetStringListIndex(type.CString(), emitterTypeNames, EMITTER_SPHERE); } if (source.HasChild("emittersize")) emitterSize_ = source.GetChild("emittersize").GetVector3("value"); if (source.HasChild("emitterradius")) emitterSize_.x_ = emitterSize_.y_ = emitterSize_.z_ = source.GetChild("emitterradius").GetFloat("value"); if (source.HasChild("direction")) GetVector3MinMax(source.GetChild("direction"), directionMin_, directionMax_); if (source.HasChild("constantforce")) constantForce_ = source.GetChild("constantforce").GetVector3("value"); if (source.HasChild("dampingforce")) dampingForce_ = source.GetChild("dampingforce").GetFloat("value"); if (source.HasChild("activetime")) activeTime_ = source.GetChild("activetime").GetFloat("value"); if (activeTime_ < 0.0f) activeTime_ = M_INFINITY; if (source.HasChild("inactivetime")) inactiveTime_ = source.GetChild("inactivetime").GetFloat("value"); if (inactiveTime_ < 0.0f) inactiveTime_ = M_INFINITY; if (source.HasChild("emissionrate")) GetFloatMinMax(source.GetChild("emissionrate"), emissionRateMin_, emissionRateMax_); if (source.HasChild("interval")) { float intervalMin = 0.0f; float intervalMax = 0.0f; GetFloatMinMax(source.GetChild("interval"), intervalMin, intervalMax); emissionRateMax_ = 1.0f / intervalMin; emissionRateMin_ = 1.0f / intervalMax; } if (source.HasChild("particlesize")) GetVector2MinMax(source.GetChild("particlesize"), sizeMin_, sizeMax_); if (source.HasChild("timetolive")) GetFloatMinMax(source.GetChild("timetolive"), timeToLiveMin_, timeToLiveMax_); if (source.HasChild("velocity")) GetFloatMinMax(source.GetChild("velocity"), velocityMin_, velocityMax_); if (source.HasChild("rotation")) GetFloatMinMax(source.GetChild("rotation"), rotationMin_, rotationMax_); if (source.HasChild("rotationspeed")) GetFloatMinMax(source.GetChild("rotationspeed"), rotationSpeedMin_, rotationSpeedMax_); if (source.HasChild("faceCameraMode")) { String type = source.GetChild("faceCameraMode").GetAttributeLower("value"); faceCameraMode_ = (FaceCameraMode)GetStringListIndex(type.CString(), faceCameraModeNames, FC_ROTATE_XYZ); } if (source.HasChild("sizedelta")) { XMLElement deltaElem = source.GetChild("sizedelta"); if (deltaElem.HasAttribute("add")) sizeAdd_ = deltaElem.GetFloat("add"); if (deltaElem.HasAttribute("mul")) sizeMul_ = deltaElem.GetFloat("mul"); } if (source.HasChild("color")) { ColorFrame colorFrame(source.GetChild("color").GetColor("value")); SetColorFrame(0, colorFrame); } if (source.HasChild("colorfade")) { Vector<ColorFrame> fades; for (XMLElement colorFadeElem = source.GetChild("colorfade"); colorFadeElem; colorFadeElem = colorFadeElem.GetNext("colorfade")) fades.Push(ColorFrame(colorFadeElem.GetColor("color"), colorFadeElem.GetFloat("time"))); SetColorFrames(fades); } if (colorFrames_.Empty()) colorFrames_.Push(ColorFrame(Color::WHITE)); if (source.HasChild("texanim")) { Vector<TextureFrame> animations; for (XMLElement animElem = source.GetChild("texanim"); animElem; animElem = animElem.GetNext("texanim")) { TextureFrame animation; animation.uv_ = animElem.GetRect("uv"); animation.time_ = animElem.GetFloat("time"); animations.Push(animation); } SetTextureFrames(animations); } return true; }
void RenderPathCommand::Load(const XMLElement& element) { type_ = (RenderCommandType)GetStringListIndex(element.GetAttributeLower("type").CString(), commandTypeNames, CMD_NONE); tag_ = element.GetAttribute("tag"); if (element.HasAttribute("enabled")) enabled_ = element.GetBool("enabled"); if (element.HasAttribute("metadata")) metadata_ = element.GetAttribute("metadata"); switch (type_) { case CMD_CLEAR: if (element.HasAttribute("color")) { clearFlags_ |= CLEAR_COLOR; if (element.GetAttributeLower("color") == "fog") useFogColor_ = true; else clearColor_ = element.GetColor("color"); } if (element.HasAttribute("depth")) { clearFlags_ |= CLEAR_DEPTH; clearDepth_ = element.GetFloat("depth"); } if (element.HasAttribute("stencil")) { clearFlags_ |= CLEAR_STENCIL; clearStencil_ = (unsigned)element.GetInt("stencil"); } break; case CMD_SCENEPASS: pass_ = element.GetAttribute("pass"); sortMode_ = (RenderCommandSortMode)GetStringListIndex(element.GetAttributeLower("sort").CString(), sortModeNames, SORT_FRONTTOBACK); if (element.HasAttribute("marktostencil")) markToStencil_ = element.GetBool("marktostencil"); if (element.HasAttribute("vertexlights")) vertexLights_ = element.GetBool("vertexlights"); break; case CMD_FORWARDLIGHTS: pass_ = element.GetAttribute("pass"); if (element.HasAttribute("uselitbase")) useLitBase_ = element.GetBool("uselitbase"); break; case CMD_LIGHTVOLUMES: case CMD_QUAD: vertexShaderName_ = element.GetAttribute("vs"); pixelShaderName_ = element.GetAttribute("ps"); vertexShaderDefines_ = element.GetAttribute("vsdefines"); pixelShaderDefines_ = element.GetAttribute("psdefines"); if (type_ == CMD_QUAD) { if (element.HasAttribute("blend")) { String blend = element.GetAttributeLower("blend"); blendMode_ = ((BlendMode)GetStringListIndex(blend.CString(), blendModeNames, BLEND_REPLACE)); } XMLElement parameterElem = element.GetChild("parameter"); while (parameterElem) { String name = parameterElem.GetAttribute("name"); shaderParameters_[name] = Material::ParseShaderParameterValue(parameterElem.GetAttribute("value")); parameterElem = parameterElem.GetNext("parameter"); } } break; default: break; } // By default use 1 output, which is the viewport outputs_.Resize(1); outputs_[0] = MakePair(String("viewport"), FACE_POSITIVE_X); if (element.HasAttribute("output")) outputs_[0].first_ = element.GetAttribute("output"); if (element.HasAttribute("face")) outputs_[0].second_ = (CubeMapFace)element.GetInt("face"); if (element.HasAttribute("depthstencil")) depthStencilName_ = element.GetAttribute("depthstencil"); // Check for defining multiple outputs XMLElement outputElem = element.GetChild("output"); while (outputElem) { unsigned index = (unsigned)outputElem.GetInt("index"); if (index < MAX_RENDERTARGETS) { if (index >= outputs_.Size()) outputs_.Resize(index + 1); outputs_[index].first_ = outputElem.GetAttribute("name"); outputs_[index].second_ = outputElem.HasAttribute("face") ? (CubeMapFace)outputElem.GetInt("face") : FACE_POSITIVE_X; } outputElem = outputElem.GetNext("output"); } XMLElement textureElem = element.GetChild("texture"); while (textureElem) { TextureUnit unit = TU_DIFFUSE; if (textureElem.HasAttribute("unit")) unit = ParseTextureUnitName(textureElem.GetAttribute("unit")); if (unit < MAX_TEXTURE_UNITS) { String name = textureElem.GetAttribute("name"); textureNames_[unit] = name; } textureElem = textureElem.GetNext("texture"); } }
bool ParticleEmitter::Load(XMLFile* file) { if (!file) { LOGERROR("Null particle emitter parameter file"); return false; } XMLElement rootElem = file->GetRoot(); if (!rootElem) { LOGERROR("Particle emitter parameter file does not have a valid root element"); return false; } if (rootElem.HasChild("material")) SetMaterial(GetSubsystem<ResourceCache>()->GetResource<Material>(rootElem.GetChild("material").GetAttribute("name"))); if (rootElem.HasChild("numparticles")) SetNumParticles(rootElem.GetChild("numparticles").GetInt("value")); if (rootElem.HasChild("updateinvisible")) updateInvisible_ = rootElem.GetChild("updateinvisible").GetBool("enable"); if (rootElem.HasChild("relative")) relative_ = rootElem.GetChild("relative").GetBool("enable"); if (rootElem.HasChild("scaled")) scaled_ = rootElem.GetChild("scaled").GetBool("enable"); if (rootElem.HasChild("sorted")) sorted_ = rootElem.GetChild("sorted").GetBool("enable"); if (rootElem.HasChild("animlodbias")) SetAnimationLodBias(rootElem.GetChild("relative").GetFloat("value")); if (rootElem.HasChild("emittertype")) { String type = rootElem.GetChild("emittertype").GetAttributeLower("value"); if (type == "point") { // Point emitter type is deprecated, handled as zero sized sphere emitterType_ = EMITTER_SPHERE; emitterSize_ = Vector3::ZERO; } else if (type == "box") emitterType_ = EMITTER_BOX; else if (type == "sphere") emitterType_ = EMITTER_SPHERE; else LOGERROR("Unknown particle emitter type " + type); } if (rootElem.HasChild("emittersize")) emitterSize_ = rootElem.GetChild("emittersize").GetVector3("value"); if (rootElem.HasChild("emitterradius")) emitterSize_.x_ = emitterSize_.y_ = emitterSize_.z_ = rootElem.GetChild("emitterradius").GetFloat("value"); if (rootElem.HasChild("direction")) GetVector3MinMax(rootElem.GetChild("direction"), directionMin_, directionMax_); if (rootElem.HasChild("constantforce")) constantForce_ = rootElem.GetChild("constantforce").GetVector3("value"); if (rootElem.HasChild("dampingforce")) dampingForce_ = rootElem.GetChild("dampingforce").GetFloat("value"); if (rootElem.HasChild("activetime")) activeTime_ = rootElem.GetChild("activetime").GetFloat("value"); if (activeTime_ < 0.0f) activeTime_ = M_INFINITY; if (rootElem.HasChild("inactivetime")) inactiveTime_ = rootElem.GetChild("inactivetime").GetFloat("value"); if (inactiveTime_ < 0.0f) inactiveTime_ = M_INFINITY; if (rootElem.HasChild("emissionrate")) GetFloatMinMax(rootElem.GetChild("emissionrate"), emissionRateMin_, emissionRateMax_); if (rootElem.HasChild("interval")) { float intervalMin = 0.0f; float intervalMax = 0.0f; GetFloatMinMax(rootElem.GetChild("interval"), intervalMin, intervalMax); emissionRateMax_ = 1.0f / intervalMin; emissionRateMin_ = 1.0f / intervalMax; } if (rootElem.HasChild("particlesize")) GetVector2MinMax(rootElem.GetChild("particlesize"), sizeMin_, sizeMax_); if (rootElem.HasChild("timetolive")) GetFloatMinMax(rootElem.GetChild("timetolive"), timeToLiveMin_, timeToLiveMax_); if (rootElem.HasChild("velocity")) GetFloatMinMax(rootElem.GetChild("velocity"), velocityMin_, velocityMax_); if (rootElem.HasChild("rotation")) GetFloatMinMax(rootElem.GetChild("rotation"), rotationMin_, rotationMax_); if (rootElem.HasChild("rotationspeed")) GetFloatMinMax(rootElem.GetChild("rotationspeed"), rotationSpeedMin_, rotationSpeedMax_); if (rootElem.HasChild("sizedelta")) { XMLElement deltaElem = rootElem.GetChild("sizedelta"); if (deltaElem.HasAttribute("add")) sizeAdd_ = deltaElem.GetFloat("add"); if (deltaElem.HasAttribute("mul")) sizeMul_ = deltaElem.GetFloat("mul"); } if (rootElem.HasChild("color")) SetColor(rootElem.GetChild("color").GetColor("value")); if (rootElem.HasChild("colorfade")) { Vector<ColorFrame> fades; XMLElement colorFadeElem = rootElem.GetChild("colorfade"); while (colorFadeElem) { fades.Push(ColorFrame(colorFadeElem.GetColor("color"), colorFadeElem.GetFloat("time"))); colorFadeElem = colorFadeElem.GetNext("colorfade"); } SetColors(fades); } if (rootElem.HasChild("texanim")) { Vector<TextureFrame> animations; XMLElement animElem = rootElem.GetChild("texanim"); while (animElem) { TextureFrame animation; animation.uv_ = animElem.GetRect("uv"); animation.time_ = animElem.GetFloat("time"); animations.Push(animation); animElem = animElem.GetNext("texanim"); } textureFrames_ = animations; } MarkNetworkUpdate(); return true; }
void RenderPathCommand::Load(const XMLElement& element) { type_ = (RenderCommandType)GetStringListIndex(element.GetAttributeLower("type").CString(), commandTypeNames, CMD_NONE); tag_ = element.GetAttribute("tag"); if (element.HasAttribute("enabled")) enabled_ = element.GetBool("enabled"); if (element.HasAttribute("metadata")) metadata_ = element.GetAttribute("metadata"); switch (type_) { case CMD_CLEAR: if (element.HasAttribute("color")) { clearFlags_ |= CLEAR_COLOR; // Mark fog color with negative values if (element.GetAttributeLower("color") == "fog") useFogColor_ = true; else clearColor_ = element.GetColor("color"); } if (element.HasAttribute("depth")) { clearFlags_ |= CLEAR_DEPTH; clearDepth_ = element.GetFloat("depth"); } if (element.HasAttribute("stencil")) { clearFlags_ |= CLEAR_STENCIL; clearStencil_ = element.GetInt("stencil"); } break; case CMD_SCENEPASS: pass_ = element.GetAttribute("pass"); sortMode_ = (RenderCommandSortMode)GetStringListIndex(element.GetAttributeLower("sort").CString(), sortModeNames, SORT_FRONTTOBACK); if (element.HasAttribute("marktostencil")) markToStencil_ = element.GetBool("marktostencil"); if (element.HasAttribute("vertexlights")) vertexLights_ = element.GetBool("vertexlights"); if (element.HasAttribute("usescissor")) useScissor_ = element.GetBool("usescissor"); break; case CMD_FORWARDLIGHTS: pass_ = element.GetAttribute("pass"); if (element.HasAttribute("uselitbase")) useLitBase_ = element.GetBool("uselitbase"); break; case CMD_LIGHTVOLUMES: case CMD_QUAD: vertexShaderName_ = element.GetAttribute("vs"); pixelShaderName_ = element.GetAttribute("ps"); if (type_ == CMD_QUAD) { XMLElement parameterElem = element.GetChild("parameter"); while (parameterElem) { String name = parameterElem.GetAttribute("name"); Variant value = parameterElem.GetVectorVariant("value"); shaderParameters_[name] = value; parameterElem = parameterElem.GetNext("parameter"); } } break; default: break; } // By default use 1 output, which is the viewport outputNames_.Push("viewport"); if (element.HasAttribute("output")) outputNames_[0] = element.GetAttribute("output"); // Check for defining multiple outputs XMLElement outputElem = element.GetChild("output"); while (outputElem) { unsigned index = outputElem.GetInt("index"); if (index < MAX_RENDERTARGETS) { if (index >= outputNames_.Size()) outputNames_.Resize(index + 1); outputNames_[index] = outputElem.GetAttribute("name"); } outputElem = outputElem.GetNext("output"); } XMLElement textureElem = element.GetChild("texture"); while (textureElem) { TextureUnit unit = TU_DIFFUSE; if (textureElem.HasAttribute("unit")) { String unitName = textureElem.GetAttributeLower("unit"); if (unitName.Length() > 1) unit = ParseTextureUnitName(unitName); else unit = (TextureUnit)Clamp(ToInt(unitName), 0, MAX_TEXTURE_UNITS - 1); } if (unit < MAX_TEXTURE_UNITS) { String name = textureElem.GetAttribute("name"); textureNames_[unit] = name; } textureElem = textureElem.GetNext("texture"); } }