diff options
Diffstat (limited to 'modules/csg/csg_shape.h')
-rw-r--r-- | modules/csg/csg_shape.h | 64 |
1 files changed, 51 insertions, 13 deletions
diff --git a/modules/csg/csg_shape.h b/modules/csg/csg_shape.h index 6898cdaf64..6c9419b3c2 100644 --- a/modules/csg/csg_shape.h +++ b/modules/csg/csg_shape.h @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */ +/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -36,9 +36,10 @@ #include "csg.h" #include "scene/3d/visual_instance.h" #include "scene/resources/concave_polygon_shape.h" +#include "thirdparty/misc/mikktspace.h" -class CSGShape : public VisualInstance { - GDCLASS(CSGShape, VisualInstance); +class CSGShape : public GeometryInstance { + GDCLASS(CSGShape, GeometryInstance); public: enum Operation { @@ -60,9 +61,13 @@ private: float snap; bool use_collision; + uint32_t collision_layer; + uint32_t collision_mask; Ref<ConcavePolygonShape> root_collision_shape; RID root_collision_instance; + bool calculate_tangents; + Ref<ArrayMesh> root_mesh; struct Vector3Hasher { @@ -78,14 +83,25 @@ private: PoolVector<Vector3> vertices; PoolVector<Vector3> normals; PoolVector<Vector2> uvs; + PoolVector<float> tans; Ref<Material> material; int last_added; PoolVector<Vector3>::Write verticesw; PoolVector<Vector3>::Write normalsw; PoolVector<Vector2>::Write uvsw; + PoolVector<float>::Write tansw; }; + //mikktspace callbacks + static int mikktGetNumFaces(const SMikkTSpaceContext *pContext); + static int mikktGetNumVerticesOfFace(const SMikkTSpaceContext *pContext, const int iFace); + static void mikktGetPosition(const SMikkTSpaceContext *pContext, float fvPosOut[], const int iFace, const int iVert); + static void mikktGetNormal(const SMikkTSpaceContext *pContext, float fvNormOut[], const int iFace, const int iVert); + static void mikktGetTexCoord(const SMikkTSpaceContext *pContext, float fvTexcOut[], const int iFace, const int iVert); + static void mikktSetTSpaceDefault(const SMikkTSpaceContext *pContext, const float fvTangent[], const float fvBiTangent[], const float fMagS, const float fMagT, + const tbool bIsOrientationPreserving, const int iFace, const int iVert); + void _update_shape(); protected: @@ -101,6 +117,8 @@ protected: virtual void _validate_property(PropertyInfo &property) const; public: + Array get_meshes() const; + void set_operation(Operation p_operation); Operation get_operation() const; @@ -112,9 +130,24 @@ public: void set_use_collision(bool p_enable); bool is_using_collision() const; + void set_collision_layer(uint32_t p_layer); + uint32_t get_collision_layer() const; + + void set_collision_mask(uint32_t p_mask); + uint32_t get_collision_mask() const; + + void set_collision_layer_bit(int p_bit, bool p_value); + bool get_collision_layer_bit(int p_bit) const; + + void set_collision_mask_bit(int p_bit, bool p_value); + bool get_collision_mask_bit(int p_bit) const; + void set_snap(float p_snap); float get_snap() const; + void set_calculate_tangents(bool p_calculate_tangents); + bool is_calculating_tangents() const; + bool is_root_shape() const; CSGShape(); ~CSGShape(); @@ -123,7 +156,8 @@ public: VARIANT_ENUM_CAST(CSGShape::Operation) class CSGCombiner : public CSGShape { - GDCLASS(CSGCombiner, CSGShape) + GDCLASS(CSGCombiner, CSGShape); + private: virtual CSGBrush *_build_brush(); @@ -132,7 +166,7 @@ public: }; class CSGPrimitive : public CSGShape { - GDCLASS(CSGPrimitive, CSGShape) + GDCLASS(CSGPrimitive, CSGShape); private: bool invert_faces; @@ -149,11 +183,12 @@ public: }; class CSGMesh : public CSGPrimitive { - GDCLASS(CSGMesh, CSGPrimitive) + GDCLASS(CSGMesh, CSGPrimitive); virtual CSGBrush *_build_brush(); Ref<Mesh> mesh; + Ref<Material> material; void _mesh_changed(); @@ -163,11 +198,14 @@ protected: public: void set_mesh(const Ref<Mesh> &p_mesh); Ref<Mesh> get_mesh(); + + void set_material(const Ref<Material> &p_material); + Ref<Material> get_material() const; }; class CSGSphere : public CSGPrimitive { - GDCLASS(CSGSphere, CSGPrimitive) + GDCLASS(CSGSphere, CSGPrimitive); virtual CSGBrush *_build_brush(); Ref<Material> material; @@ -200,7 +238,7 @@ public: class CSGBox : public CSGPrimitive { - GDCLASS(CSGBox, CSGPrimitive) + GDCLASS(CSGBox, CSGPrimitive); virtual CSGBrush *_build_brush(); Ref<Material> material; @@ -229,7 +267,7 @@ public: class CSGCylinder : public CSGPrimitive { - GDCLASS(CSGCylinder, CSGPrimitive) + GDCLASS(CSGCylinder, CSGPrimitive); virtual CSGBrush *_build_brush(); Ref<Material> material; @@ -266,7 +304,7 @@ public: class CSGTorus : public CSGPrimitive { - GDCLASS(CSGTorus, CSGPrimitive) + GDCLASS(CSGTorus, CSGPrimitive); virtual CSGBrush *_build_brush(); Ref<Material> material; @@ -303,7 +341,7 @@ public: class CSGPolygon : public CSGPrimitive { - GDCLASS(CSGPolygon, CSGPrimitive) + GDCLASS(CSGPolygon, CSGPrimitive); public: enum Mode { @@ -366,7 +404,7 @@ public: void set_spin_degrees(float p_spin_degrees); float get_spin_degrees() const; - void set_spin_sides(int p_sides); + void set_spin_sides(int p_spin_sides); int get_spin_sides() const; void set_path_node(const NodePath &p_path); |