mirror of
https://github.com/Almamu/linux-wallpaperengine.git
synced 2025-07-15 05:42:23 +08:00
+ Support for null textures in material passes
+ Basic parsing for object's effects (missing passes specified in the scene.json) Signed-off-by: Alexis Maiquez <almamu@almamu.com>
This commit is contained in:
parent
5e5dd47154
commit
e80ce94331
@ -75,6 +75,8 @@ add_executable(
|
||||
wallpaperengine/core/objects/image.h
|
||||
wallpaperengine/core/objects/sound.cpp
|
||||
wallpaperengine/core/objects/sound.h
|
||||
wallpaperengine/core/objects/effect.cpp
|
||||
wallpaperengine/core/objects/effect.h
|
||||
|
||||
wallpaperengine/core/objects/images/material.cpp
|
||||
wallpaperengine/core/objects/images/material.h
|
||||
|
@ -32,6 +32,7 @@ object* object::fromJSON (json data)
|
||||
json::const_iterator size_it = data.find ("size");
|
||||
json::const_iterator angles_it = data.find ("angles");
|
||||
json::const_iterator name_it = data.find ("name");
|
||||
json::const_iterator effects_it = data.find ("effects");
|
||||
|
||||
bool visible = true;
|
||||
|
||||
@ -96,5 +97,28 @@ object* object::fromJSON (json data)
|
||||
);
|
||||
}
|
||||
|
||||
if (effects_it != data.end () && (*effects_it).is_array () == true && object != nullptr)
|
||||
{
|
||||
json::const_iterator cur = (*effects_it).begin ();
|
||||
json::const_iterator end = (*effects_it).end ();
|
||||
|
||||
for (; cur != end; cur ++)
|
||||
{
|
||||
object->insertEffect (
|
||||
objects::effect::fromJSON (*cur)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
std::vector<objects::effect*>* object::getEffects ()
|
||||
{
|
||||
return &this->m_effects;
|
||||
}
|
||||
|
||||
void object::insertEffect (objects::effect* effect)
|
||||
{
|
||||
this->m_effects.push_back (effect);
|
||||
}
|
@ -3,6 +3,8 @@
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <irrlicht/irrlicht.h>
|
||||
|
||||
#include "objects/effect.h"
|
||||
|
||||
namespace wp::core
|
||||
{
|
||||
using json = nlohmann::json;
|
||||
@ -11,6 +13,8 @@ namespace wp::core
|
||||
{
|
||||
public:
|
||||
static object* fromJSON (json data);
|
||||
|
||||
std::vector<objects::effect*>* getEffects ();
|
||||
protected:
|
||||
object (
|
||||
bool visible,
|
||||
@ -20,6 +24,8 @@ namespace wp::core
|
||||
const irr::core::vector3df& scale,
|
||||
const irr::core::vector3df& angles
|
||||
);
|
||||
|
||||
void insertEffect (objects::effect* effect);
|
||||
private:
|
||||
bool m_visible;
|
||||
irr::u32 m_id;
|
||||
@ -27,5 +33,7 @@ namespace wp::core
|
||||
irr::core::vector3df m_origin;
|
||||
irr::core::vector3df m_scale;
|
||||
irr::core::vector3df m_angles;
|
||||
|
||||
std::vector<objects::effect*> m_effects;
|
||||
};
|
||||
};
|
||||
|
122
wallpaperengine/core/objects/effect.cpp
Normal file
122
wallpaperengine/core/objects/effect.cpp
Normal file
@ -0,0 +1,122 @@
|
||||
#include "effect.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "../../fs/utils.h"
|
||||
|
||||
using namespace wp::core::objects;
|
||||
|
||||
effect::effect (
|
||||
std::string name,
|
||||
std::string description,
|
||||
std::string group,
|
||||
std::string preview):
|
||||
m_name (std::move(name)),
|
||||
m_description (std::move(description)),
|
||||
m_group (std::move(group)),
|
||||
m_preview (std::move(preview))
|
||||
{
|
||||
}
|
||||
|
||||
effect* effect::fromJSON (json data)
|
||||
{
|
||||
json::const_iterator file_it = data.find ("file");
|
||||
|
||||
if (file_it == data.end ())
|
||||
{
|
||||
throw std::runtime_error ("Object effect must have a file");
|
||||
}
|
||||
|
||||
json content = json::parse (wp::fs::utils::loadFullFile ((*file_it).get <std::string> ().c_str ()));
|
||||
|
||||
json::const_iterator name_it = content.find ("name");
|
||||
json::const_iterator description_it = content.find ("description");
|
||||
json::const_iterator group_it = content.find ("group");
|
||||
json::const_iterator preview_it = content.find ("preview");
|
||||
json::const_iterator passes_it = content.find ("passes");
|
||||
json::const_iterator dependencies_it = content.find ("dependencies");
|
||||
|
||||
if (name_it == content.end ())
|
||||
{
|
||||
throw std::runtime_error ("Effect must have a name");
|
||||
}
|
||||
|
||||
if (description_it == content.end ())
|
||||
{
|
||||
throw std::runtime_error ("Effect must have a description");
|
||||
}
|
||||
|
||||
if (group_it == content.end ())
|
||||
{
|
||||
throw std::runtime_error ("Effect must have a group");
|
||||
}
|
||||
|
||||
if (preview_it == content.end ())
|
||||
{
|
||||
throw std::runtime_error ("Effect must have a preview");
|
||||
}
|
||||
|
||||
if (passes_it == content.end ())
|
||||
{
|
||||
throw std::runtime_error ("Effect must have a pass list");
|
||||
}
|
||||
|
||||
if (dependencies_it == content.end ())
|
||||
{
|
||||
throw std::runtime_error ("Effect must have dependencies");
|
||||
}
|
||||
|
||||
effect* effect = new class effect (
|
||||
*name_it,
|
||||
*description_it,
|
||||
*group_it,
|
||||
*preview_it
|
||||
);
|
||||
|
||||
json::const_iterator cur = (*passes_it).begin ();
|
||||
json::const_iterator end = (*passes_it).end ();
|
||||
|
||||
for (; cur != end; cur ++)
|
||||
{
|
||||
json::const_iterator materialfile = (*cur).find ("material");
|
||||
|
||||
if (materialfile == (*cur).end ())
|
||||
{
|
||||
throw std::runtime_error ("Effect pass must have a material file");
|
||||
}
|
||||
|
||||
effect->insertMaterial (
|
||||
images::material::fromFile ((*materialfile).get <std::string> ().c_str ())
|
||||
);
|
||||
}
|
||||
|
||||
cur = (*dependencies_it).begin ();
|
||||
end = (*dependencies_it).end ();
|
||||
|
||||
for (; cur != end; cur ++)
|
||||
{
|
||||
effect->insertDependency (*cur);
|
||||
}
|
||||
|
||||
return effect;
|
||||
}
|
||||
|
||||
std::vector<std::string>* effect::getDependencies ()
|
||||
{
|
||||
return &this->m_dependencies;
|
||||
}
|
||||
|
||||
std::vector<images::material*>* effect::getMaterials ()
|
||||
{
|
||||
return &this->m_materials;
|
||||
}
|
||||
|
||||
void effect::insertDependency (const std::string& dep)
|
||||
{
|
||||
this->m_dependencies.push_back (dep);
|
||||
}
|
||||
|
||||
void effect::insertMaterial (images::material* material)
|
||||
{
|
||||
this->m_materials.push_back (material);
|
||||
}
|
38
wallpaperengine/core/objects/effect.h
Normal file
38
wallpaperengine/core/objects/effect.h
Normal file
@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <irrlicht/irrlicht.h>
|
||||
|
||||
#include "images/material.h"
|
||||
|
||||
namespace wp::core::objects
|
||||
{
|
||||
using json = nlohmann::json;
|
||||
|
||||
class effect
|
||||
{
|
||||
public:
|
||||
effect (
|
||||
std::string name,
|
||||
std::string description,
|
||||
std::string group,
|
||||
std::string preview
|
||||
);
|
||||
|
||||
static effect* fromJSON (json data);
|
||||
|
||||
std::vector<std::string>* getDependencies ();
|
||||
std::vector<images::material*>* getMaterials ();
|
||||
protected:
|
||||
void insertDependency (const std::string& dep);
|
||||
void insertMaterial (images::material* material);
|
||||
private:
|
||||
std::string m_name;
|
||||
std::string m_description;
|
||||
std::string m_group;
|
||||
std::string m_preview;
|
||||
|
||||
std::vector<std::string> m_dependencies;
|
||||
std::vector<images::material*> m_materials;
|
||||
};
|
||||
}
|
@ -13,11 +13,16 @@ material::material ()
|
||||
|
||||
material* material::fromFile (irr::io::path filename)
|
||||
{
|
||||
json content = json::parse (wp::fs::utils::loadFullFile (filename));
|
||||
return fromJSON (
|
||||
json::parse (wp::fs::utils::loadFullFile (filename))
|
||||
);
|
||||
}
|
||||
|
||||
json::const_iterator passes_it = content.find ("passes");
|
||||
material* material::fromJSON (json data)
|
||||
{
|
||||
json::const_iterator passes_it = data.find ("passes");
|
||||
|
||||
if (passes_it == content.end ())
|
||||
if (passes_it == data.end ())
|
||||
{
|
||||
throw std::runtime_error ("Material must have at least one pass");
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ namespace wp::core::objects::images
|
||||
{
|
||||
public:
|
||||
static material* fromFile (irr::io::path filename);
|
||||
static material* fromJSON (json data);
|
||||
|
||||
void insertPass (materials::passes* mass);
|
||||
|
||||
|
@ -80,7 +80,14 @@ passes* passes::fromJSON (json data)
|
||||
|
||||
for (;cur != end; cur ++)
|
||||
{
|
||||
pass->insertTexture (*cur);
|
||||
if ((*cur).is_null () == true)
|
||||
{
|
||||
pass->insertTexture ("");
|
||||
}
|
||||
else
|
||||
{
|
||||
pass->insertTexture (*cur);
|
||||
}
|
||||
}
|
||||
|
||||
return pass;
|
||||
|
@ -24,7 +24,6 @@ namespace wp::core
|
||||
project* getProject ();
|
||||
std::vector<object*>* getObjects ();
|
||||
|
||||
|
||||
const irr::video::SColorf &getAmbientColor() const;
|
||||
bool isBloom() const;
|
||||
irr::f64 getBloomStrength() const;
|
||||
|
Loading…
Reference in New Issue
Block a user