mirror of
https://github.com/enduro2d/enduro2d.git
synced 2025-12-15 00:11:55 +07:00
remove materials from model asset
This commit is contained in:
@@ -38,14 +38,7 @@ namespace e2d
|
||||
model& assign(const model& other);
|
||||
|
||||
model& set_mesh(const mesh_asset::ptr& mesh);
|
||||
model& set_material(std::size_t index, const material_asset::ptr& material);
|
||||
|
||||
model& set_materials(vector<material_asset::ptr>&& materials) noexcept;
|
||||
model& set_materials(const vector<material_asset::ptr>& materials);
|
||||
|
||||
const mesh_asset::ptr& mesh() const noexcept;
|
||||
const material_asset::ptr& material(std::size_t index) const;
|
||||
std::size_t material_count() const noexcept;
|
||||
|
||||
// It can only be called from the main thread
|
||||
void regenerate_geometry();
|
||||
@@ -53,7 +46,6 @@ namespace e2d
|
||||
private:
|
||||
mesh_asset::ptr mesh_;
|
||||
render::geometry geometry_;
|
||||
vector<material_asset::ptr> materials_;
|
||||
};
|
||||
|
||||
void swap(model& l, model& r) noexcept;
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
{
|
||||
"mesh" : "gnome.e2d_mesh",
|
||||
"materials" : [
|
||||
"gnome_material.json"
|
||||
]
|
||||
"mesh" : "gnome.e2d_mesh"
|
||||
}
|
||||
|
||||
@@ -24,11 +24,7 @@ namespace
|
||||
"required" : [ "mesh" ],
|
||||
"additionalProperties" : false,
|
||||
"properties" : {
|
||||
"mesh" : { "$ref": "#/common_definitions/address" },
|
||||
"materials" : {
|
||||
"type" : "array",
|
||||
"items" : { "$ref" : "#/common_definitions/address" }
|
||||
}
|
||||
"mesh" : { "$ref": "#/common_definitions/address" }
|
||||
}
|
||||
})json";
|
||||
|
||||
@@ -59,31 +55,10 @@ namespace
|
||||
auto mesh_p = library.load_asset_async<mesh_asset>(
|
||||
path::combine(parent_address, root["mesh"].GetString()));
|
||||
|
||||
vector<stdex::promise<material_asset::load_result>> materials_p;
|
||||
|
||||
if ( root.HasMember("materials") ) {
|
||||
E2D_ASSERT(root["materials"].IsArray());
|
||||
const auto& materials_json = root["materials"];
|
||||
|
||||
materials_p.reserve(materials_json.Size());
|
||||
for ( rapidjson::SizeType i = 0; i < materials_json.Size(); ++i ) {
|
||||
E2D_ASSERT(materials_json[i].IsString());
|
||||
materials_p.emplace_back(
|
||||
library.load_asset_async<material_asset>(
|
||||
path::combine(parent_address, materials_json[i].GetString())));
|
||||
}
|
||||
}
|
||||
|
||||
return stdex::make_tuple_promise(std::make_tuple(
|
||||
std::move(mesh_p),
|
||||
stdex::make_all_promise(materials_p)))
|
||||
.then([](const std::tuple<
|
||||
mesh_asset::load_result,
|
||||
vector<material_asset::load_result>
|
||||
>& results){
|
||||
return mesh_p.then([
|
||||
](const mesh_asset::load_result& mesh){
|
||||
model content;
|
||||
content.set_mesh(std::get<0>(results));
|
||||
content.set_materials(std::get<1>(results));
|
||||
content.set_mesh(mesh);
|
||||
return the<deferrer>().do_in_main_thread([
|
||||
content = std::move(content)
|
||||
]() mutable {
|
||||
|
||||
@@ -166,14 +166,12 @@ namespace e2d
|
||||
void model::clear() noexcept {
|
||||
mesh_.reset();
|
||||
geometry_.clear();
|
||||
materials_.clear();
|
||||
}
|
||||
|
||||
void model::swap(model& other) noexcept {
|
||||
using std::swap;
|
||||
swap(mesh_, other.mesh_);
|
||||
swap(geometry_, other.geometry_);
|
||||
swap(materials_, other.materials_);
|
||||
}
|
||||
|
||||
model& model::assign(model&& other) noexcept {
|
||||
@@ -189,7 +187,6 @@ namespace e2d
|
||||
model m;
|
||||
m.mesh_ = other.mesh_;
|
||||
m.geometry_ = other.geometry_;
|
||||
m.materials_ = other.materials_;
|
||||
swap(m);
|
||||
}
|
||||
return *this;
|
||||
@@ -201,39 +198,10 @@ namespace e2d
|
||||
return *this;
|
||||
}
|
||||
|
||||
model& model::set_material(std::size_t index, const material_asset::ptr& material) {
|
||||
if ( materials_.size() <= index ) {
|
||||
materials_.resize(index + 1);
|
||||
}
|
||||
materials_[index] = material;
|
||||
return *this;
|
||||
}
|
||||
|
||||
model& model::set_materials(vector<material_asset::ptr>&& materials) noexcept {
|
||||
materials_ = std::move(materials);
|
||||
return *this;
|
||||
}
|
||||
|
||||
model& model::set_materials(const vector<material_asset::ptr>& materials) {
|
||||
materials_ = materials;
|
||||
return *this;
|
||||
}
|
||||
|
||||
const mesh_asset::ptr& model::mesh() const noexcept {
|
||||
return mesh_;
|
||||
}
|
||||
|
||||
const material_asset::ptr& model::material(std::size_t index) const {
|
||||
if ( index < materials_.size() ) {
|
||||
return materials_[index];
|
||||
}
|
||||
throw bad_model_access();
|
||||
}
|
||||
|
||||
std::size_t model::material_count() const noexcept {
|
||||
return materials_.size();
|
||||
}
|
||||
|
||||
void model::regenerate_geometry() {
|
||||
if ( mesh_ ) {
|
||||
geometry_ = make_geometry(mesh_->content());
|
||||
@@ -254,21 +222,8 @@ namespace e2d
|
||||
}
|
||||
|
||||
bool operator==(const model& l, const model& r) noexcept {
|
||||
if ( l.mesh() != r.mesh() ) {
|
||||
return false;
|
||||
}
|
||||
if ( l.geometry() != r.geometry() ) {
|
||||
return false;
|
||||
}
|
||||
if ( l.material_count() != r.material_count() ) {
|
||||
return false;
|
||||
}
|
||||
for ( std::size_t i = 0; i < l.material_count(); ++i ) {
|
||||
if ( l.material(i) != r.material(i) ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
return l.mesh() == r.mesh()
|
||||
&& l.geometry() == r.geometry();
|
||||
}
|
||||
|
||||
bool operator!=(const model& l, const model& r) noexcept {
|
||||
|
||||
@@ -83,7 +83,7 @@ namespace e2d { namespace render_system_impl
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !mdl_r.model() || !mdl_r.model()->content().mesh()) {
|
||||
if ( !mdl_r.model() || !mdl_r.model()->content().mesh() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -99,11 +99,11 @@ namespace e2d { namespace render_system_impl
|
||||
|
||||
const std::size_t submesh_count = math::min(
|
||||
msh.indices_submesh_count(),
|
||||
mdl.material_count());
|
||||
node_r.materials().size());
|
||||
|
||||
for ( std::size_t i = 0, first_index = 0; i < submesh_count; ++i ) {
|
||||
const std::size_t index_count = msh.indices(i).size();
|
||||
const material_asset::ptr& mat = mdl.material(i);
|
||||
const material_asset::ptr& mat = node_r.materials()[i];
|
||||
if ( mat ) {
|
||||
render_.execute(render::draw_command(
|
||||
mat->content(),
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
{
|
||||
"mesh" : "mesh.e2d_mesh",
|
||||
"materials" : [
|
||||
"material.json"
|
||||
]
|
||||
"mesh" : "mesh.e2d_mesh"
|
||||
}
|
||||
|
||||
@@ -179,8 +179,6 @@ TEST_CASE("library"){
|
||||
auto model_res = l.load_asset<model_asset>("model.json");
|
||||
REQUIRE(model_res);
|
||||
REQUIRE(model_res->content().mesh());
|
||||
REQUIRE(model_res->content().material_count() == 1);
|
||||
REQUIRE(model_res->content().material(0));
|
||||
REQUIRE_FALSE(model_res->content().mesh()->content().vertices().empty());
|
||||
REQUIRE(model_res->content().mesh()->content().indices_submesh_count() == 1);
|
||||
REQUIRE_FALSE(model_res->content().mesh()->content().indices(0).empty());
|
||||
|
||||
Reference in New Issue
Block a user