File: Material.cpp

package info (click to toggle)
yade 2026.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 34,448 kB
  • sloc: cpp: 97,645; python: 52,173; sh: 677; makefile: 162
file content (34 lines) | stat: -rw-r--r-- 1,028 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <core/Material.hpp>
#include <core/Scene.hpp>
#include <stdexcept>

namespace yade { // Cannot have #include directive inside.

const shared_ptr<Material> Material::byId(int id, Scene* w_)
{
	Scene* w = w_ ? w_ : Omega::instance().getScene().get();
	assert(id >= 0 && (size_t)id < w->materials.size());
	assert(w->materials[id]->id == id);
	return w->materials[id];
}

const shared_ptr<Material> Material::byLabel(const std::string& label, Scene* w_)
{
	Scene* w = w_ ? w_ : Omega::instance().getScene().get();
	for (const auto& m : w->materials) {
		if (m->label == label) return m;
	}
	throw std::runtime_error(("No material labeled `" + label + "'.").c_str());
}

int Material::byLabelIndex(const std::string& label, Scene* w_)
{
	Scene* w    = w_ ? w_ : Omega::instance().getScene().get();
	size_t iMax = w->materials.size();
	for (size_t i = 0; i < iMax; i++) {
		if (w->materials[i]->label == label) return i;
	}
	throw std::runtime_error(("No material labeled `" + label + "'.").c_str());
}

} // namespace yade