visual_instance.h
1 /*************************************************************************/
2 /* visual_instance.h */
3 /*************************************************************************/
4 /* This file is part of: */
5 /* GODOT ENGINE */
6 /* http://www.godotengine.org */
7 /*************************************************************************/
8 /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
9 /* */
10 /* Permission is hereby granted, free of charge, to any person obtaining */
11 /* a copy of this software and associated documentation files (the */
12 /* "Software"), to deal in the Software without restriction, including */
13 /* without limitation the rights to use, copy, modify, merge, publish, */
14 /* distribute, sublicense, and/or sell copies of the Software, and to */
15 /* permit persons to whom the Software is furnished to do so, subject to */
16 /* the following conditions: */
17 /* */
18 /* The above copyright notice and this permission notice shall be */
19 /* included in all copies or substantial portions of the Software. */
20 /* */
21 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
22 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
23 /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
24 /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
25 /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
26 /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
27 /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
28 /*************************************************************************/
29 #ifndef VISUAL_INSTANCE_H
30 #define VISUAL_INSTANCE_H
31 
32 #include "scene/3d/spatial.h"
33 #include "face3.h"
34 #include "rid.h"
35 #include "scene/resources/material.h"
39 class VisualInstance : public Spatial {
40 
41  OBJ_TYPE( VisualInstance, Spatial );
42  OBJ_CATEGORY("3D Visual Nodes");
43 
44  RID instance;
45  uint32_t layers;
46 
47 
48  RID _get_visual_instance_rid() const;
49 
50 
51 protected:
52 
53 
54  void _notification(int p_what);
55  static void _bind_methods();
56 public:
57 
58  enum GetFacesFlags {
59  FACES_SOLID=1, // solid geometry
60  FACES_ENCLOSING=2,
61  FACES_DYNAMIC=4 // dynamic object geometry
62 
63  };
64 
65  RID get_instance() const;
66  virtual AABB get_aabb() const=0;
67  virtual DVector<Face3> get_faces(uint32_t p_usage_flags) const=0;
68 
69  virtual AABB get_transformed_aabb() const; // helper
70 
71  void set_base(const RID& p_base);
72 
73  void set_layer_mask(uint32_t p_mask);
74  uint32_t get_layer_mask() const;
75 
76 
78  ~VisualInstance();
79 
80 };
81 
82 class BakedLightInstance;
83 
85 
86  OBJ_TYPE( GeometryInstance, VisualInstance );
87 public:
88 
89  enum Flags {
90  FLAG_VISIBLE=VS::INSTANCE_FLAG_VISIBLE,
91  FLAG_CAST_SHADOW=VS::INSTANCE_FLAG_CAST_SHADOW,
92  FLAG_RECEIVE_SHADOWS=VS::INSTANCE_FLAG_RECEIVE_SHADOWS,
93  FLAG_BILLBOARD=VS::INSTANCE_FLAG_BILLBOARD,
94  FLAG_BILLBOARD_FIX_Y=VS::INSTANCE_FLAG_BILLBOARD_FIX_Y,
95  FLAG_DEPH_SCALE=VS::INSTANCE_FLAG_DEPH_SCALE,
96  FLAG_VISIBLE_IN_ALL_ROOMS=VS::INSTANCE_FLAG_VISIBLE_IN_ALL_ROOMS,
97  FLAG_USE_BAKED_LIGHT=VS::INSTANCE_FLAG_USE_BAKED_LIGHT,
98  FLAG_MAX=VS::INSTANCE_FLAG_MAX,
99  };
100 
101 
102 private:
103 
104  bool flags[FLAG_MAX];
105  Ref<Material> material_override;
106  float draw_begin;
107  float draw_end;
108  void _find_baked_light();
109  BakedLightInstance *baked_light_instance;
110  int baked_light_texture_id;
111  float extra_cull_margin;
112 
113  void _baked_light_changed();
114  void _update_visibility();
115 protected:
116 
117  void _notification(int p_what);
118  static void _bind_methods();
119 public:
120 
121  void set_flag(Flags p_flag,bool p_value);
122  bool get_flag(Flags p_flag) const;
123 
124  void set_draw_range_begin(float p_dist);
125  float get_draw_range_begin() const;
126 
127  void set_draw_range_end(float p_dist);
128  float get_draw_range_end() const;
129 
130  void set_material_override(const Ref<Material>& p_material);
131  Ref<Material> get_material_override() const;
132 
133  void set_baked_light_texture_id(int p_id);
134  int get_baked_light_texture_id() const;
135 
136  void set_extra_cull_margin(float p_margin);
137  float get_extra_cull_margin() const;
138 
140 };
141 
142 VARIANT_ENUM_CAST( GeometryInstance::Flags );
143 
144 #endif
Definition: baked_light_instance.h:10
Definition: aabb.h:43
Definition: rid.h:47
Definition: visual_instance.h:84
Definition: spatial.h:56
Definition: visual_instance.h:39