Merge pull request #27940 from LeonardMeagher2/fix_csgshape_geometryinstance
CSGMesh gets material + CSGShape inherits from GeometryInstance
This commit is contained in:
commit
7d0275785b
2 changed files with 29 additions and 3 deletions
|
@ -724,6 +724,7 @@ CSGBrush *CSGMesh::_build_brush() {
|
||||||
PoolVector<bool> smooth;
|
PoolVector<bool> smooth;
|
||||||
PoolVector<Ref<Material> > materials;
|
PoolVector<Ref<Material> > materials;
|
||||||
PoolVector<Vector2> uvs;
|
PoolVector<Vector2> uvs;
|
||||||
|
Ref<Material> material = get_material();
|
||||||
|
|
||||||
for (int i = 0; i < mesh->get_surface_count(); i++) {
|
for (int i = 0; i < mesh->get_surface_count(); i++) {
|
||||||
|
|
||||||
|
@ -760,7 +761,12 @@ CSGBrush *CSGMesh::_build_brush() {
|
||||||
uvr_used = true;
|
uvr_used = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<Material> mat = mesh->surface_get_material(i);
|
Ref<Material> mat;
|
||||||
|
if (material.is_valid()) {
|
||||||
|
mat = material;
|
||||||
|
} else {
|
||||||
|
mat = mesh->surface_get_material(i);
|
||||||
|
}
|
||||||
|
|
||||||
PoolVector<int> aindices = arrays[Mesh::ARRAY_INDEX];
|
PoolVector<int> aindices = arrays[Mesh::ARRAY_INDEX];
|
||||||
if (aindices.size()) {
|
if (aindices.size()) {
|
||||||
|
@ -866,6 +872,18 @@ void CSGMesh::_mesh_changed() {
|
||||||
update_gizmo();
|
update_gizmo();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CSGMesh::set_material(const Ref<Material> &p_material) {
|
||||||
|
if (material == p_material)
|
||||||
|
return;
|
||||||
|
material = p_material;
|
||||||
|
_make_dirty();
|
||||||
|
}
|
||||||
|
|
||||||
|
Ref<Material> CSGMesh::get_material() const {
|
||||||
|
|
||||||
|
return material;
|
||||||
|
}
|
||||||
|
|
||||||
void CSGMesh::_bind_methods() {
|
void CSGMesh::_bind_methods() {
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("set_mesh", "mesh"), &CSGMesh::set_mesh);
|
ClassDB::bind_method(D_METHOD("set_mesh", "mesh"), &CSGMesh::set_mesh);
|
||||||
|
@ -873,7 +891,11 @@ void CSGMesh::_bind_methods() {
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("_mesh_changed"), &CSGMesh::_mesh_changed);
|
ClassDB::bind_method(D_METHOD("_mesh_changed"), &CSGMesh::_mesh_changed);
|
||||||
|
|
||||||
|
ClassDB::bind_method(D_METHOD("set_material", "material"), &CSGMesh::set_material);
|
||||||
|
ClassDB::bind_method(D_METHOD("get_material"), &CSGMesh::get_material);
|
||||||
|
|
||||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "mesh", PROPERTY_HINT_RESOURCE_TYPE, "Mesh"), "set_mesh", "get_mesh");
|
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "mesh", PROPERTY_HINT_RESOURCE_TYPE, "Mesh"), "set_mesh", "get_mesh");
|
||||||
|
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "material", PROPERTY_HINT_RESOURCE_TYPE, "SpatialMaterial,ShaderMaterial"), "set_material", "get_material");
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSGMesh::set_mesh(const Ref<Mesh> &p_mesh) {
|
void CSGMesh::set_mesh(const Ref<Mesh> &p_mesh) {
|
||||||
|
|
|
@ -38,8 +38,8 @@
|
||||||
#include "scene/resources/concave_polygon_shape.h"
|
#include "scene/resources/concave_polygon_shape.h"
|
||||||
#include "thirdparty/misc/mikktspace.h"
|
#include "thirdparty/misc/mikktspace.h"
|
||||||
|
|
||||||
class CSGShape : public VisualInstance {
|
class CSGShape : public GeometryInstance {
|
||||||
GDCLASS(CSGShape, VisualInstance);
|
GDCLASS(CSGShape, GeometryInstance);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum Operation {
|
enum Operation {
|
||||||
|
@ -187,6 +187,7 @@ class CSGMesh : public CSGPrimitive {
|
||||||
virtual CSGBrush *_build_brush();
|
virtual CSGBrush *_build_brush();
|
||||||
|
|
||||||
Ref<Mesh> mesh;
|
Ref<Mesh> mesh;
|
||||||
|
Ref<Material> material;
|
||||||
|
|
||||||
void _mesh_changed();
|
void _mesh_changed();
|
||||||
|
|
||||||
|
@ -196,6 +197,9 @@ protected:
|
||||||
public:
|
public:
|
||||||
void set_mesh(const Ref<Mesh> &p_mesh);
|
void set_mesh(const Ref<Mesh> &p_mesh);
|
||||||
Ref<Mesh> get_mesh();
|
Ref<Mesh> get_mesh();
|
||||||
|
|
||||||
|
void set_material(const Ref<Material> &p_material);
|
||||||
|
Ref<Material> get_material() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CSGSphere : public CSGPrimitive {
|
class CSGSphere : public CSGPrimitive {
|
||||||
|
|
Loading…
Reference in a new issue