29 #define _unused(x) ((void)(x)) 31 #include "SUAPI-CppWrapper/model/Material.hpp" 36 #include "SUAPI-CppWrapper/String.hpp" 37 #include "SUAPI-CppWrapper/Color.hpp" 38 #include "SUAPI-CppWrapper/model/Texture.hpp" 46 SUMaterialRef Material::create_material() {
47 SUMaterialRef material = SU_INVALID;
48 SUResult res = SUMaterialCreate(&material);
49 assert(res == SU_ERROR_NONE); _unused(res);
54 SUMaterialRef Material::copy_reference(
const Material& other) {
55 if (other.m_attached || SUIsInvalid(other.m_entity)) {
58 return create_material();;
69 Material::Material(SUMaterialRef material_ref,
bool attached):
70 Entity(SUMaterialToEntity(material_ref), attached)
75 Entity(other, SUMaterialToEntity(copy_reference(other)))
90 SUMaterialRef material = this->ref();
91 SUResult res = SUMaterialRelease(&material);
92 assert(res == SU_ERROR_NONE); _unused(res);
94 m_entity = SUMaterialToEntity(copy_reference(other));
111 SUMaterialRef material = this->ref();
112 SUResult res = SUMaterialRelease(&material);
113 assert(res == SU_ERROR_NONE); _unused(res);
118 SUMaterialRef Material::ref()
const {
119 return SUMaterialFromEntity(
m_entity);
123 Material::operator SUMaterialRef()
const {
136 throw std::logic_error(
"CW::Material::copy(): Material is null");
138 Material new_material(create_material(),
false);
153 SUColor new_color = SU_INVALID;
154 SUResult res = SUMaterialGetColor(this->ref(), &new_color);
155 if (res == SU_ERROR_NONE) {
156 return Color(new_color);
164 throw std::logic_error(
"CW::Material::color(): Material is null");
166 SUColor set_color = color.ref();
167 SUResult res = SUMaterialSetColor(this->ref(), &set_color);
168 assert(res != SU_ERROR_INVALID_INPUT); _unused(res);
176 SUStringRef name_ref = SU_INVALID;
177 SUResult res = SUStringCreate(&name_ref);
178 assert(res == SU_ERROR_NONE);
179 res = SUMaterialGetName(this->ref(), &name_ref);
180 assert(res != SU_ERROR_INVALID_OUTPUT);
181 if (res == SU_ERROR_NONE) {
195 SUStringRef name_ref = SU_INVALID;
196 SUResult res = SUStringCreate(&name_ref);
197 assert(res == SU_ERROR_NONE);
198 res = SUMaterialGetNameLegacyBehavior(this->ref(), &name_ref);
199 assert(res != SU_ERROR_INVALID_OUTPUT);
200 if (res == SU_ERROR_NONE) {
210 throw std::logic_error(
"CW::Material::name(): Material is null");
212 const char *cstr =
string.std_string().c_str();
213 SUResult res = SUMaterialSetName(this->ref(), cstr);
214 assert(res == SU_ERROR_NONE); _unused(res);
221 throw std::logic_error(
"CW::Material::opacity(): Material is null");
224 SUResult res = SUMaterialGetOpacity(this->ref(), &alpha);
225 if (res == SU_ERROR_NONE) {
234 throw std::logic_error(
"CW::Material::opacity(): Material is null");
236 double input_alpha = 1.0;
240 else if (alpha < 0.0) {
243 SUResult res = SUMaterialSetOpacity(this->ref(), input_alpha);
244 assert(res != SU_ERROR_OUT_OF_RANGE); _unused(res);
250 throw std::logic_error(
"CW::Material::TEXTURE(): Material is null");
252 SUTextureRef get_texture = SU_INVALID;
253 SUResult res = SUMaterialGetTexture(this->ref(), &get_texture);
254 if (res != SU_ERROR_NONE) {
263 throw std::logic_error(
"CW::Material::texture(): Material is null");
272 SUTextureRef texture_ref = texture.ref();
273 SUResult res = SUMaterialSetTexture(this->ref(), texture_ref);
274 assert(res == SU_ERROR_NONE); _unused(res);
280 throw std::logic_error(
"CW::Material::type(): Material is null");
282 SUMaterialType mat_type;
283 SUResult res = SUMaterialGetType(this->ref(), &mat_type);
284 assert(res == SU_ERROR_NONE); _unused(res);
291 throw std::logic_error(
"CW::Material::type(): Material is null");
293 SUResult res = SUMaterialSetType(this->ref(), material_type);
294 assert(res == SU_ERROR_NONE); _unused(res);
300 throw std::logic_error(
"CW::Material::use_alpha(): Material is null");
303 SUResult res = SUMaterialGetUseOpacity(this->ref(), &flag);
304 assert(res == SU_ERROR_NONE); _unused(res);
311 throw std::logic_error(
"CW::Material::use_alpha(): Material is null");
314 SUResult res = SUMaterialSetUseOpacity(this->ref(), flag);
315 assert(res == SU_ERROR_NONE); _unused(res);
bool m_attached
Indicates whether the Entity has been attached to a model.
Material & operator=(const Material &other)
Entity()
Constructor representing a null objject.
bool attached() const
Returns true if the entity is attached to another object.
bool copy_attributes_from(const Entity &entity)
Copies attributes from another Entity object to this one.
SUEntityRef m_entity
The C SUEntityRef that this class wraps.
String display_name() const
SUMaterialType type() const
Entity & operator=(const Entity &other)
Copy assignment operator.