diff options
Diffstat (limited to 'servers')
28 files changed, 1033 insertions, 401 deletions
diff --git a/servers/audio/audio_mixer_sw.cpp b/servers/audio/audio_mixer_sw.cpp index 2ca0c5e93a..873e19823a 100644 --- a/servers/audio/audio_mixer_sw.cpp +++ b/servers/audio/audio_mixer_sw.cpp @@ -35,7 +35,7 @@ #define NO_REVERB #endif -template<class Depth,bool is_stereo,bool use_filter,bool use_fx,AudioMixerSW::InterpolationType type,AudioMixerSW::MixChannels mix_mode> +template<class Depth,bool is_stereo,bool is_ima_adpcm,bool use_filter,bool use_fx,AudioMixerSW::InterpolationType type,AudioMixerSW::MixChannels mix_mode> void AudioMixerSW::do_resample(const Depth* p_src, int32_t *p_dst, ResamplerState *p_state) { // this function will be compiled branchless by any decent compiler @@ -48,37 +48,110 @@ void AudioMixerSW::do_resample(const Depth* p_src, int32_t *p_dst, ResamplerStat if (is_stereo) pos<<=1; - final=p_src[pos]; - if (is_stereo) - final_r=p_src[pos+1]; + if (is_ima_adpcm) { - if (sizeof(Depth)==1) { /* conditions will not exist anymore when compiled! */ - final<<=8; - if (is_stereo) - final_r<<=8; - } + int sample_pos = pos + p_state->ima_adpcm->window_ofs; - if (type==INTERPOLATION_LINEAR) { + while(sample_pos>p_state->ima_adpcm->last_nibble) { - if (is_stereo) { - next=p_src[pos+2]; - next_r=p_src[pos+3]; - } else { - next=p_src[pos+1]; + static const int16_t _ima_adpcm_step_table[89] = { + 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, + 19, 21, 23, 25, 28, 31, 34, 37, 41, 45, + 50, 55, 60, 66, 73, 80, 88, 97, 107, 118, + 130, 143, 157, 173, 190, 209, 230, 253, 279, 307, + 337, 371, 408, 449, 494, 544, 598, 658, 724, 796, + 876, 963, 1060, 1166, 1282, 1411, 1552, 1707, 1878, 2066, + 2272, 2499, 2749, 3024, 3327, 3660, 4026, 4428, 4871, 5358, + 5894, 6484, 7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899, + 15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767 + }; + + static const int8_t _ima_adpcm_index_table[16] = { + -1, -1, -1, -1, 2, 4, 6, 8, + -1, -1, -1, -1, 2, 4, 6, 8 + }; + + int16_t nibble,signed_nibble,diff,step; + + p_state->ima_adpcm->last_nibble++; + const uint8_t *src_ptr=p_state->ima_adpcm->ptr; + + nibble = (p_state->ima_adpcm->last_nibble&1)? + (src_ptr[p_state->ima_adpcm->last_nibble>>1]>>4):(src_ptr[p_state->ima_adpcm->last_nibble>>1]&0xF); + step=_ima_adpcm_step_table[p_state->ima_adpcm->step_index]; + + p_state->ima_adpcm->step_index += _ima_adpcm_index_table[nibble]; + if (p_state->ima_adpcm->step_index<0) + p_state->ima_adpcm->step_index=0; + if (p_state->ima_adpcm->step_index>88) + p_state->ima_adpcm->step_index=88; + + /* + signed_nibble = (nibble&7) * ((nibble&8)?-1:1); + diff = (2 * signed_nibble + 1) * step / 4; */ + + diff = step >> 3 ; + if (nibble & 1) + diff += step >> 2 ; + if (nibble & 2) + diff += step >> 1 ; + if (nibble & 4) + diff += step ; + if (nibble & 8) + diff = -diff ; + + p_state->ima_adpcm->predictor+=diff; + if (p_state->ima_adpcm->predictor<-0x8000) + p_state->ima_adpcm->predictor=-0x8000; + else if (p_state->ima_adpcm->predictor>0x7FFF) + p_state->ima_adpcm->predictor=0x7FFF; + + + /* store loop if there */ + if (p_state->ima_adpcm->last_nibble==p_state->ima_adpcm->loop_pos) { + + p_state->ima_adpcm->loop_step_index = p_state->ima_adpcm->step_index; + p_state->ima_adpcm->loop_predictor = p_state->ima_adpcm->predictor; + } + } - if (sizeof(Depth)==1) { - next<<=8; + final=p_state->ima_adpcm->predictor; + + } else { + final=p_src[pos]; + if (is_stereo) + final_r=p_src[pos+1]; + + if (sizeof(Depth)==1) { /* conditions will not exist anymore when compiled! */ + final<<=8; if (is_stereo) - next_r<<=8; + final_r<<=8; } - int32_t frac=int32_t(p_state->pos&MIX_FRAC_MASK); + if (type==INTERPOLATION_LINEAR) { - final=final+((next-final)*frac >> MIX_FRAC_BITS); - if (is_stereo) - final_r=final_r+((next_r-final_r)*frac >> MIX_FRAC_BITS); + if (is_stereo) { + + next=p_src[pos+2]; + next_r=p_src[pos+3]; + } else { + next=p_src[pos+1]; + } + + if (sizeof(Depth)==1) { + next<<=8; + if (is_stereo) + next_r<<=8; + } + + int32_t frac=int32_t(p_state->pos&MIX_FRAC_MASK); + + final=final+((next-final)*frac >> MIX_FRAC_BITS); + if (is_stereo) + final_r=final_r+((next_r-final_r)*frac >> MIX_FRAC_BITS); + } } if (use_filter) { @@ -314,6 +387,15 @@ void AudioMixerSW::mix_channel(Channel& c) { rstate.filter_l=&c.mix.filter_l; rstate.filter_r=&c.mix.filter_r; + if (format==AS::SAMPLE_FORMAT_IMA_ADPCM) { + + rstate.ima_adpcm=&c.mix.ima_adpcm; + if (loop_format!=AS::SAMPLE_LOOP_NONE) { + c.mix.ima_adpcm.loop_pos=loop_begin_fp>>MIX_FRAC_BITS; + loop_format=AS::SAMPLE_LOOP_FORWARD; + } + } + while (todo>0) { int64_t limit=0; @@ -354,7 +436,14 @@ void AudioMixerSW::mix_channel(Channel& c) { } else { /* go to loop-begin */ - c.mix.offset=loop_begin_fp+(c.mix.offset-loop_end_fp); + if (format==AS::SAMPLE_FORMAT_IMA_ADPCM) { + c.mix.ima_adpcm.step_index=c.mix.ima_adpcm.loop_step_index; + c.mix.ima_adpcm.predictor=c.mix.ima_adpcm.loop_predictor; + c.mix.ima_adpcm.last_nibble=loop_begin_fp>>MIX_FRAC_BITS; + c.mix.offset=loop_begin_fp; + } else { + c.mix.offset=loop_begin_fp+(c.mix.offset-loop_end_fp); + } } } else { @@ -393,48 +482,48 @@ void AudioMixerSW::mix_channel(Channel& c) { /* Macros to call the resample function for all possibilities, creating a dedicated-non branchy function call for each thanks to template magic*/ -#define CALL_RESAMPLE_FUNC( m_depth, m_stereo, m_use_filter, m_use_fx, m_interp, m_mode)\ - do_resample<m_depth,m_stereo,m_use_filter,m_use_fx,m_interp, m_mode>(\ +#define CALL_RESAMPLE_FUNC( m_depth, m_stereo, m_ima_adpcm, m_use_filter, m_use_fx, m_interp, m_mode)\ + do_resample<m_depth,m_stereo,m_ima_adpcm, m_use_filter,m_use_fx,m_interp, m_mode>(\ src_ptr,\ dst_buff,&rstate); -#define CALL_RESAMPLE_INTERP( m_depth, m_stereo, m_use_filter, m_use_fx, m_interp, m_mode)\ +#define CALL_RESAMPLE_INTERP( m_depth, m_stereo, m_ima_adpcm, m_use_filter, m_use_fx, m_interp, m_mode)\ if(m_interp==INTERPOLATION_RAW) {\ - CALL_RESAMPLE_FUNC(m_depth,m_stereo,m_use_filter,m_use_fx,INTERPOLATION_RAW,m_mode);\ + CALL_RESAMPLE_FUNC(m_depth,m_stereo, m_ima_adpcm,m_use_filter,m_use_fx,INTERPOLATION_RAW,m_mode);\ } else if(m_interp==INTERPOLATION_LINEAR) {\ - CALL_RESAMPLE_FUNC(m_depth,m_stereo,m_use_filter,m_use_fx,INTERPOLATION_LINEAR,m_mode);\ + CALL_RESAMPLE_FUNC(m_depth,m_stereo, m_ima_adpcm,m_use_filter,m_use_fx,INTERPOLATION_LINEAR,m_mode);\ } else if(m_interp==INTERPOLATION_CUBIC) {\ - CALL_RESAMPLE_FUNC(m_depth,m_stereo,m_use_filter,m_use_fx,INTERPOLATION_CUBIC,m_mode);\ + CALL_RESAMPLE_FUNC(m_depth,m_stereo, m_ima_adpcm,m_use_filter,m_use_fx,INTERPOLATION_CUBIC,m_mode);\ }\ -#define CALL_RESAMPLE_FX( m_depth, m_stereo, m_use_filter, m_use_fx, m_interp, m_mode)\ +#define CALL_RESAMPLE_FX( m_depth, m_stereo, m_ima_adpcm, m_use_filter, m_use_fx, m_interp, m_mode)\ if(m_use_fx) {\ - CALL_RESAMPLE_INTERP(m_depth,m_stereo,m_use_filter,true,m_interp, m_mode);\ + CALL_RESAMPLE_INTERP(m_depth,m_stereo, m_ima_adpcm,m_use_filter,true,m_interp, m_mode);\ } else {\ - CALL_RESAMPLE_INTERP(m_depth,m_stereo,m_use_filter,false,m_interp, m_mode);\ + CALL_RESAMPLE_INTERP(m_depth,m_stereo, m_ima_adpcm,m_use_filter,false,m_interp, m_mode);\ }\ -#define CALL_RESAMPLE_FILTER( m_depth, m_stereo, m_use_filter, m_use_fx, m_interp, m_mode)\ +#define CALL_RESAMPLE_FILTER( m_depth, m_stereo, m_ima_adpcm, m_use_filter, m_use_fx, m_interp, m_mode)\ if(m_use_filter) {\ - CALL_RESAMPLE_FX(m_depth,m_stereo,true,m_use_fx,m_interp, m_mode);\ + CALL_RESAMPLE_FX(m_depth,m_stereo, m_ima_adpcm,true,m_use_fx,m_interp, m_mode);\ } else {\ - CALL_RESAMPLE_FX(m_depth,m_stereo,false,m_use_fx,m_interp, m_mode);\ + CALL_RESAMPLE_FX(m_depth,m_stereo, m_ima_adpcm,false,m_use_fx,m_interp, m_mode);\ }\ -#define CALL_RESAMPLE_STEREO( m_depth, m_stereo, m_use_filter, m_use_fx, m_interp, m_mode)\ +#define CALL_RESAMPLE_STEREO( m_depth, m_stereo, m_ima_adpcm, m_use_filter, m_use_fx, m_interp, m_mode)\ if(m_stereo) {\ - CALL_RESAMPLE_FILTER(m_depth,true,m_use_filter,m_use_fx,m_interp, m_mode);\ + CALL_RESAMPLE_FILTER(m_depth,true,m_ima_adpcm, m_use_filter,m_use_fx,m_interp, m_mode);\ } else {\ - CALL_RESAMPLE_FILTER(m_depth,false,m_use_filter,m_use_fx,m_interp, m_mode);\ + CALL_RESAMPLE_FILTER(m_depth,false,m_ima_adpcm,m_use_filter,m_use_fx,m_interp, m_mode);\ }\ -#define CALL_RESAMPLE_MODE( m_depth, m_stereo, m_use_filter, m_use_fx, m_interp, m_mode)\ +#define CALL_RESAMPLE_MODE( m_depth, m_stereo, m_ima_adpcm, m_use_filter, m_use_fx, m_interp, m_mode)\ if(m_mode==MIX_STEREO) {\ - CALL_RESAMPLE_STEREO(m_depth,m_stereo,m_use_filter,m_use_fx,m_interp, MIX_STEREO);\ + CALL_RESAMPLE_STEREO(m_depth,m_stereo, m_ima_adpcm,m_use_filter,m_use_fx,m_interp, MIX_STEREO);\ } else {\ - CALL_RESAMPLE_STEREO(m_depth,m_stereo,m_use_filter,m_use_fx,m_interp, MIX_QUAD);\ + CALL_RESAMPLE_STEREO(m_depth,m_stereo, m_ima_adpcm,m_use_filter,m_use_fx,m_interp, MIX_QUAD);\ }\ @@ -443,11 +532,17 @@ void AudioMixerSW::mix_channel(Channel& c) { if (format==AS::SAMPLE_FORMAT_PCM8) { int8_t *src_ptr = &((int8_t*)data)[(c.mix.offset >> MIX_FRAC_BITS)<<(is_stereo?1:0) ]; - CALL_RESAMPLE_MODE(int8_t,is_stereo,use_filter,use_fx,interpolation_type,mix_channels); + CALL_RESAMPLE_MODE(int8_t,is_stereo,false,use_filter,use_fx,interpolation_type,mix_channels); } else if (format==AS::SAMPLE_FORMAT_PCM16) { int16_t *src_ptr = &((int16_t*)data)[(c.mix.offset >> MIX_FRAC_BITS)<<(is_stereo?1:0) ]; - CALL_RESAMPLE_MODE(int16_t,is_stereo,use_filter,use_fx,interpolation_type,mix_channels); + CALL_RESAMPLE_MODE(int16_t,is_stereo,false,use_filter,use_fx,interpolation_type,mix_channels); + + } else if (format==AS::SAMPLE_FORMAT_IMA_ADPCM) { + c.mix.ima_adpcm.window_ofs=c.mix.offset>>MIX_FRAC_BITS; + c.mix.ima_adpcm.ptr=(const uint8_t*)data; + int8_t *src_ptr = &((int8_t*)data)[(c.mix.offset >> MIX_FRAC_BITS)<<(is_stereo?1:0) ]; + CALL_RESAMPLE_MODE(int8_t,false,true,use_filter,use_fx,interpolation_type,mix_channels); } @@ -669,6 +764,19 @@ AudioMixer::ChannelID AudioMixerSW::channel_alloc(RID p_sample) { c.had_prev_reverb=false; c.had_prev_vol=false; + + if (sample_manager->sample_get_format(c.sample)==AudioServer::SAMPLE_FORMAT_IMA_ADPCM) { + + c.mix.ima_adpcm.step_index=0; + c.mix.ima_adpcm.predictor=0; + c.mix.ima_adpcm.loop_step_index=0; + c.mix.ima_adpcm.loop_predictor=0; + c.mix.ima_adpcm.last_nibble=-1; + c.mix.ima_adpcm.loop_pos=0x7FFFFFFF; + c.mix.ima_adpcm.window_ofs=0; + c.mix.ima_adpcm.ptr=NULL; + } + ChannelID ret_id = index+c.check*MAX_CHANNELS; return ret_id; diff --git a/servers/audio/audio_mixer_sw.h b/servers/audio/audio_mixer_sw.h index eb3feee1c8..d3caf03089 100644 --- a/servers/audio/audio_mixer_sw.h +++ b/servers/audio/audio_mixer_sw.h @@ -73,6 +73,7 @@ private: MAX_REVERBS=4 }; + struct Channel { RID sample; @@ -93,6 +94,19 @@ private: float ha[2],hb[2]; } filter_l,filter_r; + struct IMA_ADPCM_State { + + int16_t step_index; + int32_t predictor; + /* values at loop point */ + int16_t loop_step_index; + int32_t loop_predictor; + int32_t last_nibble; + int32_t loop_pos; + int32_t window_ofs; + const uint8_t *ptr; + } ima_adpcm; + } mix; float vol; @@ -163,17 +177,20 @@ private: int32_t chorus_vol_inc[4]; + Channel::Mix::Filter *filter_l; Channel::Mix::Filter *filter_r; Channel::Filter::Coefs coefs; Channel::Filter::Coefs coefs_inc; + Channel::Mix::IMA_ADPCM_State *ima_adpcm; + int32_t *reverb_buffer; }; - template<class Depth,bool is_stereo,bool use_filter,bool use_fx,InterpolationType type,MixChannels> + template<class Depth,bool is_stereo,bool use_filter,bool is_ima_adpcm,bool use_fx,InterpolationType type,MixChannels> _FORCE_INLINE_ void do_resample(const Depth* p_src, int32_t *p_dst, ResamplerState *p_state); MixChannels mix_channels; diff --git a/servers/audio/sample_manager_sw.cpp b/servers/audio/sample_manager_sw.cpp index 2c065a9375..5a5aa1a34c 100644 --- a/servers/audio/sample_manager_sw.cpp +++ b/servers/audio/sample_manager_sw.cpp @@ -46,8 +46,13 @@ RID SampleManagerMallocSW::sample_create(AS::SampleFormat p_format, bool p_stere datalen*=2; if (p_format==AS::SAMPLE_FORMAT_PCM16) datalen*=2; - else if (p_format==AS::SAMPLE_FORMAT_IMA_ADPCM) + else if (p_format==AS::SAMPLE_FORMAT_IMA_ADPCM) { + if (datalen&1) { + datalen++; + } datalen/=2; + datalen+=4; + } #define SAMPLE_EXTRA 16 s->data = memalloc(datalen+SAMPLE_EXTRA); //help the interpolator by allocating a little more.. @@ -128,11 +133,13 @@ void SampleManagerMallocSW::sample_set_data(RID p_sample, const DVector<uint8_t> int buff_size=p_buffer.size(); ERR_FAIL_COND(buff_size==0); + ERR_EXPLAIN("Sample buffer size does not match sample size."); ERR_FAIL_COND(s->length_bytes!=buff_size); DVector<uint8_t>::Read buffer_r=p_buffer.read(); const uint8_t *src = buffer_r.ptr(); uint8_t *dst = (uint8_t*)s->data; + print_line("set data: "+itos(s->length_bytes)); for(int i=0;i<s->length_bytes;i++) { diff --git a/servers/physics/body_sw.cpp b/servers/physics/body_sw.cpp index f0f72b471c..52edc0faa7 100644 --- a/servers/physics/body_sw.cpp +++ b/servers/physics/body_sw.cpp @@ -425,6 +425,27 @@ void BodySW::integrate_velocities(real_t p_step) { return; } + + + //apply axis lock + if (axis_lock!=PhysicsServer::BODY_AXIS_LOCK_DISABLED) { + + + int axis=axis_lock-1; + for(int i=0;i<3;i++) { + if (i==axis) { + linear_velocity[i]=0; + biased_linear_velocity[i]=0; + } else { + + angular_velocity[i]=0; + biased_angular_velocity[i]=0; + } + } + + } + + Vector3 total_angular_velocity = angular_velocity+biased_angular_velocity; @@ -441,7 +462,11 @@ void BodySW::integrate_velocities(real_t p_step) { } Vector3 total_linear_velocity=linear_velocity+biased_linear_velocity; - + /*for(int i=0;i<3;i++) { + if (axis_lock&(1<<i)) { + transform.origin[i]=0.0; + } + }*/ transform.origin+=total_linear_velocity * p_step; @@ -614,6 +639,7 @@ BodySW::BodySW() : CollisionObjectSW(TYPE_BODY), active_list(this), inertia_upda continuous_cd=false; can_sleep=false; fi_callback=NULL; + axis_lock=PhysicsServer::BODY_AXIS_LOCK_DISABLED; } diff --git a/servers/physics/body_sw.h b/servers/physics/body_sw.h index 9f0bbc00cf..8923899278 100644 --- a/servers/physics/body_sw.h +++ b/servers/physics/body_sw.h @@ -26,323 +26,328 @@ /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#ifndef BODY_SW_H
-#define BODY_SW_H
-
-#include "collision_object_sw.h"
-#include "vset.h"
-#include "area_sw.h"
-
-class ConstraintSW;
-
-
-class BodySW : public CollisionObjectSW {
-
-
- PhysicsServer::BodyMode mode;
-
- Vector3 linear_velocity;
- Vector3 angular_velocity;
-
- Vector3 biased_linear_velocity;
- Vector3 biased_angular_velocity;
- real_t mass;
- real_t bounce;
- real_t friction;
-
- real_t _inv_mass;
- Vector3 _inv_inertia;
- Matrix3 _inv_inertia_tensor;
-
- Vector3 gravity;
- real_t density;
-
- real_t still_time;
-
- Vector3 applied_force;
- Vector3 applied_torque;
-
- SelfList<BodySW> active_list;
- SelfList<BodySW> inertia_update_list;
- SelfList<BodySW> direct_state_query_list;
-
- VSet<RID> exceptions;
- bool omit_force_integration;
- bool active;
- bool simulated_motion;
- bool continuous_cd;
- bool can_sleep;
- void _update_inertia();
- virtual void _shapes_changed();
-
- Map<ConstraintSW*,int> constraint_map;
-
- struct AreaCMP {
-
- AreaSW *area;
- _FORCE_INLINE_ bool operator<(const AreaCMP& p_cmp) const { return area->get_self() < p_cmp.area->get_self() ; }
- _FORCE_INLINE_ AreaCMP() {}
- _FORCE_INLINE_ AreaCMP(AreaSW *p_area) { area=p_area;}
- };
-
-
- VSet<AreaCMP> areas;
-
- struct Contact {
-
-
- Vector3 local_pos;
- Vector3 local_normal;
- float depth;
- int local_shape;
- Vector3 collider_pos;
- int collider_shape;
- ObjectID collider_instance_id;
- RID collider;
- Vector3 collider_velocity_at_pos;
- };
-
- Vector<Contact> contacts; //no contacts by default
- int contact_count;
-
- struct ForceIntegrationCallback {
-
- ObjectID id;
- StringName method;
- Variant udata;
- };
-
- ForceIntegrationCallback *fi_callback;
-
-
- uint64_t island_step;
- BodySW *island_next;
- BodySW *island_list_next;
-
- _FORCE_INLINE_ void _compute_area_gravity(const AreaSW *p_area);
-
- _FORCE_INLINE_ void _update_inertia_tensor();
-
-friend class PhysicsDirectBodyStateSW; // i give up, too many functions to expose
-
-public:
-
-
- void set_force_integration_callback(ObjectID p_id,const StringName& p_method,const Variant& p_udata=Variant());
-
-
- _FORCE_INLINE_ void add_area(AreaSW *p_area) { areas.insert(AreaCMP(p_area)); }
- _FORCE_INLINE_ void remove_area(AreaSW *p_area) { areas.erase(AreaCMP(p_area)); }
-
- _FORCE_INLINE_ void set_max_contacts_reported(int p_size) { contacts.resize(p_size); contact_count=0; }
- _FORCE_INLINE_ int get_max_contacts_reported() const { return contacts.size(); }
-
- _FORCE_INLINE_ bool can_report_contacts() const { return !contacts.empty(); }
- _FORCE_INLINE_ void add_contact(const Vector3& p_local_pos,const Vector3& p_local_normal, float p_depth, int p_local_shape, const Vector3& p_collider_pos, int p_collider_shape, ObjectID p_collider_instance_id, const RID& p_collider,const Vector3& p_collider_velocity_at_pos);
-
-
- _FORCE_INLINE_ void add_exception(const RID& p_exception) { exceptions.insert(p_exception);}
- _FORCE_INLINE_ void remove_exception(const RID& p_exception) { exceptions.erase(p_exception);}
- _FORCE_INLINE_ bool has_exception(const RID& p_exception) const { return exceptions.has(p_exception);}
- _FORCE_INLINE_ const VSet<RID>& get_exceptions() const { return exceptions;}
-
- _FORCE_INLINE_ uint64_t get_island_step() const { return island_step; }
- _FORCE_INLINE_ void set_island_step(uint64_t p_step) { island_step=p_step; }
-
- _FORCE_INLINE_ BodySW* get_island_next() const { return island_next; }
- _FORCE_INLINE_ void set_island_next(BodySW* p_next) { island_next=p_next; }
-
- _FORCE_INLINE_ BodySW* get_island_list_next() const { return island_list_next; }
- _FORCE_INLINE_ void set_island_list_next(BodySW* p_next) { island_list_next=p_next; }
-
- _FORCE_INLINE_ void add_constraint(ConstraintSW* p_constraint, int p_pos) { constraint_map[p_constraint]=p_pos; }
- _FORCE_INLINE_ void remove_constraint(ConstraintSW* p_constraint) { constraint_map.erase(p_constraint); }
- const Map<ConstraintSW*,int>& get_constraint_map() const { return constraint_map; }
-
- _FORCE_INLINE_ void set_omit_force_integration(bool p_omit_force_integration) { omit_force_integration=p_omit_force_integration; }
- _FORCE_INLINE_ bool get_omit_force_integration() const { return omit_force_integration; }
-
- _FORCE_INLINE_ void set_linear_velocity(const Vector3& p_velocity) {linear_velocity=p_velocity; }
- _FORCE_INLINE_ Vector3 get_linear_velocity() const { return linear_velocity; }
-
- _FORCE_INLINE_ void set_angular_velocity(const Vector3& p_velocity) { angular_velocity=p_velocity; }
- _FORCE_INLINE_ Vector3 get_angular_velocity() const { return angular_velocity; }
-
- _FORCE_INLINE_ const Vector3& get_biased_linear_velocity() const { return biased_linear_velocity; }
- _FORCE_INLINE_ const Vector3& get_biased_angular_velocity() const { return biased_angular_velocity; }
-
- _FORCE_INLINE_ void apply_impulse(const Vector3& p_pos, const Vector3& p_j) {
-
- linear_velocity += p_j * _inv_mass;
- angular_velocity += _inv_inertia_tensor.xform( p_pos.cross(p_j) );
- }
-
- _FORCE_INLINE_ void apply_bias_impulse(const Vector3& p_pos, const Vector3& p_j) {
-
- biased_linear_velocity += p_j * _inv_mass;
- biased_angular_velocity += _inv_inertia_tensor.xform( p_pos.cross(p_j) );
- }
-
- _FORCE_INLINE_ void apply_torque_impulse(const Vector3& p_j) {
-
- angular_velocity += _inv_inertia_tensor.xform(p_j);
- }
-
- _FORCE_INLINE_ void add_force(const Vector3& p_force, const Vector3& p_pos) {
-
- applied_force += p_force;
- applied_torque += p_pos.cross(p_force);
- }
-
- void set_active(bool p_active);
- _FORCE_INLINE_ bool is_active() const { return active; }
-
- void set_param(PhysicsServer::BodyParameter p_param, float);
- float get_param(PhysicsServer::BodyParameter p_param) const;
-
- void set_mode(PhysicsServer::BodyMode p_mode);
- PhysicsServer::BodyMode get_mode() const;
-
- void set_state(PhysicsServer::BodyState p_state, const Variant& p_variant);
- Variant get_state(PhysicsServer::BodyState p_state) const;
-
- void set_applied_force(const Vector3& p_force) { applied_force=p_force; }
- Vector3 get_applied_force() const { return applied_force; }
-
- void set_applied_torque(const Vector3& p_torque) { applied_torque=p_torque; }
- Vector3 get_applied_torque() const { return applied_torque; }
-
- _FORCE_INLINE_ void set_continuous_collision_detection(bool p_enable) { continuous_cd=p_enable; }
- _FORCE_INLINE_ bool is_continuous_collision_detection_enabled() const { return continuous_cd; }
-
- void set_space(SpaceSW *p_space);
-
- void update_inertias();
-
- _FORCE_INLINE_ real_t get_inv_mass() const { return _inv_mass; }
- _FORCE_INLINE_ Vector3 get_inv_inertia() const { return _inv_inertia; }
- _FORCE_INLINE_ Matrix3 get_inv_inertia_tensor() const { return _inv_inertia_tensor; }
- _FORCE_INLINE_ real_t get_friction() const { return friction; }
- _FORCE_INLINE_ Vector3 get_gravity() const { return gravity; }
- _FORCE_INLINE_ real_t get_density() const { return density; }
- _FORCE_INLINE_ real_t get_bounce() const { return bounce; }
-
- void integrate_forces(real_t p_step);
- void integrate_velocities(real_t p_step);
-
- void simulate_motion(const Transform& p_xform,real_t p_step);
- void call_queries();
- void wakeup_neighbours();
-
- bool sleep_test(real_t p_step);
-
- BodySW();
- ~BodySW();
-
-};
-
-
-//add contact inline
-
-void BodySW::add_contact(const Vector3& p_local_pos,const Vector3& p_local_normal, float p_depth, int p_local_shape, const Vector3& p_collider_pos, int p_collider_shape, ObjectID p_collider_instance_id, const RID& p_collider,const Vector3& p_collider_velocity_at_pos) {
-
- int c_max=contacts.size();
-
- if (c_max==0)
- return;
-
- Contact *c = &contacts[0];
-
-
- int idx=-1;
-
- if (contact_count<c_max) {
- idx=contact_count++;
- } else {
-
- float least_depth=1e20;
- int least_deep=-1;
- for(int i=0;i<c_max;i++) {
-
- if (i==0 || c[i].depth<least_depth) {
- least_deep=i;
- least_depth=c[i].depth;
- }
- }
-
- if (least_deep>=0 && least_depth<p_depth) {
-
- idx=least_deep;
- }
- if (idx==-1)
- return; //none least deepe than this
- }
-
- c[idx].local_pos=p_local_pos;
- c[idx].local_normal=p_local_normal;
- c[idx].depth=p_depth;
- c[idx].local_shape=p_local_shape;
- c[idx].collider_pos=p_collider_pos;
- c[idx].collider_shape=p_collider_shape;
- c[idx].collider_instance_id=p_collider_instance_id;
- c[idx].collider=p_collider;
- c[idx].collider_velocity_at_pos=p_collider_velocity_at_pos;
-
-}
-
-
-class PhysicsDirectBodyStateSW : public PhysicsDirectBodyState {
-
- OBJ_TYPE( PhysicsDirectBodyStateSW, PhysicsDirectBodyState );
-
-public:
-
- static PhysicsDirectBodyStateSW *singleton;
- BodySW *body;
- real_t step;
-
- virtual Vector3 get_total_gravity() const { return body->get_gravity(); } // get gravity vector working on this body space/area
- virtual float get_total_density() const { return body->get_density(); } // get density of this body space/area
-
- virtual float get_inverse_mass() const { return body->get_inv_mass(); } // get the mass
- virtual Vector3 get_inverse_inertia() const { return body->get_inv_inertia(); } // get density of this body space
- virtual Matrix3 get_inverse_inertia_tensor() const { return body->get_inv_inertia_tensor(); } // get density of this body space
-
- virtual void set_linear_velocity(const Vector3& p_velocity) { body->set_linear_velocity(p_velocity); }
- virtual Vector3 get_linear_velocity() const { return body->get_linear_velocity(); }
-
- virtual void set_angular_velocity(const Vector3& p_velocity) { body->set_angular_velocity(p_velocity); }
- virtual Vector3 get_angular_velocity() const { return body->get_angular_velocity(); }
-
- virtual void set_transform(const Transform& p_transform) { body->set_state(PhysicsServer::BODY_STATE_TRANSFORM,p_transform); }
- virtual Transform get_transform() const { return body->get_transform(); }
-
- virtual void add_force(const Vector3& p_force, const Vector3& p_pos) { body->add_force(p_force,p_pos); }
-
- virtual void set_sleep_state(bool p_enable) { body->set_active(!p_enable); }
- virtual bool is_sleeping() const { return !body->is_active(); }
-
- virtual int get_contact_count() const { return body->contact_count; }
-
- virtual Vector3 get_contact_local_pos(int p_contact_idx) const {
- ERR_FAIL_INDEX_V(p_contact_idx,body->contact_count,Vector3());
- return body->contacts[p_contact_idx].local_pos;
- }
- virtual Vector3 get_contact_local_normal(int p_contact_idx) const { ERR_FAIL_INDEX_V(p_contact_idx,body->contact_count,Vector3()); return body->contacts[p_contact_idx].local_normal; }
- virtual int get_contact_local_shape(int p_contact_idx) const { ERR_FAIL_INDEX_V(p_contact_idx,body->contact_count,-1); return body->contacts[p_contact_idx].local_shape; }
-
- virtual RID get_contact_collider(int p_contact_idx) const { ERR_FAIL_INDEX_V(p_contact_idx,body->contact_count,RID()); return body->contacts[p_contact_idx].collider; }
- virtual Vector3 get_contact_collider_pos(int p_contact_idx) const { ERR_FAIL_INDEX_V(p_contact_idx,body->contact_count,Vector3()); return body->contacts[p_contact_idx].collider_pos; }
- virtual ObjectID get_contact_collider_id(int p_contact_idx) const { ERR_FAIL_INDEX_V(p_contact_idx,body->contact_count,0); return body->contacts[p_contact_idx].collider_instance_id; }
- virtual int get_contact_collider_shape(int p_contact_idx) const { ERR_FAIL_INDEX_V(p_contact_idx,body->contact_count,0); return body->contacts[p_contact_idx].collider_shape; }
- virtual Vector3 get_contact_collider_velocity_at_pos(int p_contact_idx) const { ERR_FAIL_INDEX_V(p_contact_idx,body->contact_count,Vector3()); return body->contacts[p_contact_idx].collider_velocity_at_pos; }
-
- virtual PhysicsDirectSpaceState* get_space_state();
-
-
- virtual real_t get_step() const { return step; }
- PhysicsDirectBodyStateSW() { singleton=this; body=NULL; }
-};
-
-
-#endif // BODY__SW_H
+#ifndef BODY_SW_H +#define BODY_SW_H + +#include "collision_object_sw.h" +#include "vset.h" +#include "area_sw.h" + +class ConstraintSW; + + +class BodySW : public CollisionObjectSW { + + + PhysicsServer::BodyMode mode; + + Vector3 linear_velocity; + Vector3 angular_velocity; + + Vector3 biased_linear_velocity; + Vector3 biased_angular_velocity; + real_t mass; + real_t bounce; + real_t friction; + + PhysicsServer::BodyAxisLock axis_lock; + + real_t _inv_mass; + Vector3 _inv_inertia; + Matrix3 _inv_inertia_tensor; + + Vector3 gravity; + real_t density; + + real_t still_time; + + Vector3 applied_force; + Vector3 applied_torque; + + SelfList<BodySW> active_list; + SelfList<BodySW> inertia_update_list; + SelfList<BodySW> direct_state_query_list; + + VSet<RID> exceptions; + bool omit_force_integration; + bool active; + bool simulated_motion; + bool continuous_cd; + bool can_sleep; + void _update_inertia(); + virtual void _shapes_changed(); + + Map<ConstraintSW*,int> constraint_map; + + struct AreaCMP { + + AreaSW *area; + _FORCE_INLINE_ bool operator<(const AreaCMP& p_cmp) const { return area->get_self() < p_cmp.area->get_self() ; } + _FORCE_INLINE_ AreaCMP() {} + _FORCE_INLINE_ AreaCMP(AreaSW *p_area) { area=p_area;} + }; + + + VSet<AreaCMP> areas; + + struct Contact { + + + Vector3 local_pos; + Vector3 local_normal; + float depth; + int local_shape; + Vector3 collider_pos; + int collider_shape; + ObjectID collider_instance_id; + RID collider; + Vector3 collider_velocity_at_pos; + }; + + Vector<Contact> contacts; //no contacts by default + int contact_count; + + struct ForceIntegrationCallback { + + ObjectID id; + StringName method; + Variant udata; + }; + + ForceIntegrationCallback *fi_callback; + + + uint64_t island_step; + BodySW *island_next; + BodySW *island_list_next; + + _FORCE_INLINE_ void _compute_area_gravity(const AreaSW *p_area); + + _FORCE_INLINE_ void _update_inertia_tensor(); + +friend class PhysicsDirectBodyStateSW; // i give up, too many functions to expose + +public: + + + void set_force_integration_callback(ObjectID p_id,const StringName& p_method,const Variant& p_udata=Variant()); + + + _FORCE_INLINE_ void add_area(AreaSW *p_area) { areas.insert(AreaCMP(p_area)); } + _FORCE_INLINE_ void remove_area(AreaSW *p_area) { areas.erase(AreaCMP(p_area)); } + + _FORCE_INLINE_ void set_max_contacts_reported(int p_size) { contacts.resize(p_size); contact_count=0; } + _FORCE_INLINE_ int get_max_contacts_reported() const { return contacts.size(); } + + _FORCE_INLINE_ bool can_report_contacts() const { return !contacts.empty(); } + _FORCE_INLINE_ void add_contact(const Vector3& p_local_pos,const Vector3& p_local_normal, float p_depth, int p_local_shape, const Vector3& p_collider_pos, int p_collider_shape, ObjectID p_collider_instance_id, const RID& p_collider,const Vector3& p_collider_velocity_at_pos); + + + _FORCE_INLINE_ void add_exception(const RID& p_exception) { exceptions.insert(p_exception);} + _FORCE_INLINE_ void remove_exception(const RID& p_exception) { exceptions.erase(p_exception);} + _FORCE_INLINE_ bool has_exception(const RID& p_exception) const { return exceptions.has(p_exception);} + _FORCE_INLINE_ const VSet<RID>& get_exceptions() const { return exceptions;} + + _FORCE_INLINE_ uint64_t get_island_step() const { return island_step; } + _FORCE_INLINE_ void set_island_step(uint64_t p_step) { island_step=p_step; } + + _FORCE_INLINE_ BodySW* get_island_next() const { return island_next; } + _FORCE_INLINE_ void set_island_next(BodySW* p_next) { island_next=p_next; } + + _FORCE_INLINE_ BodySW* get_island_list_next() const { return island_list_next; } + _FORCE_INLINE_ void set_island_list_next(BodySW* p_next) { island_list_next=p_next; } + + _FORCE_INLINE_ void add_constraint(ConstraintSW* p_constraint, int p_pos) { constraint_map[p_constraint]=p_pos; } + _FORCE_INLINE_ void remove_constraint(ConstraintSW* p_constraint) { constraint_map.erase(p_constraint); } + const Map<ConstraintSW*,int>& get_constraint_map() const { return constraint_map; } + + _FORCE_INLINE_ void set_omit_force_integration(bool p_omit_force_integration) { omit_force_integration=p_omit_force_integration; } + _FORCE_INLINE_ bool get_omit_force_integration() const { return omit_force_integration; } + + _FORCE_INLINE_ void set_linear_velocity(const Vector3& p_velocity) {linear_velocity=p_velocity; } + _FORCE_INLINE_ Vector3 get_linear_velocity() const { return linear_velocity; } + + _FORCE_INLINE_ void set_angular_velocity(const Vector3& p_velocity) { angular_velocity=p_velocity; } + _FORCE_INLINE_ Vector3 get_angular_velocity() const { return angular_velocity; } + + _FORCE_INLINE_ const Vector3& get_biased_linear_velocity() const { return biased_linear_velocity; } + _FORCE_INLINE_ const Vector3& get_biased_angular_velocity() const { return biased_angular_velocity; } + + _FORCE_INLINE_ void apply_impulse(const Vector3& p_pos, const Vector3& p_j) { + + linear_velocity += p_j * _inv_mass; + angular_velocity += _inv_inertia_tensor.xform( p_pos.cross(p_j) ); + } + + _FORCE_INLINE_ void apply_bias_impulse(const Vector3& p_pos, const Vector3& p_j) { + + biased_linear_velocity += p_j * _inv_mass; + biased_angular_velocity += _inv_inertia_tensor.xform( p_pos.cross(p_j) ); + } + + _FORCE_INLINE_ void apply_torque_impulse(const Vector3& p_j) { + + angular_velocity += _inv_inertia_tensor.xform(p_j); + } + + _FORCE_INLINE_ void add_force(const Vector3& p_force, const Vector3& p_pos) { + + applied_force += p_force; + applied_torque += p_pos.cross(p_force); + } + + void set_active(bool p_active); + _FORCE_INLINE_ bool is_active() const { return active; } + + void set_param(PhysicsServer::BodyParameter p_param, float); + float get_param(PhysicsServer::BodyParameter p_param) const; + + void set_mode(PhysicsServer::BodyMode p_mode); + PhysicsServer::BodyMode get_mode() const; + + void set_state(PhysicsServer::BodyState p_state, const Variant& p_variant); + Variant get_state(PhysicsServer::BodyState p_state) const; + + void set_applied_force(const Vector3& p_force) { applied_force=p_force; } + Vector3 get_applied_force() const { return applied_force; } + + void set_applied_torque(const Vector3& p_torque) { applied_torque=p_torque; } + Vector3 get_applied_torque() const { return applied_torque; } + + _FORCE_INLINE_ void set_continuous_collision_detection(bool p_enable) { continuous_cd=p_enable; } + _FORCE_INLINE_ bool is_continuous_collision_detection_enabled() const { return continuous_cd; } + + void set_space(SpaceSW *p_space); + + void update_inertias(); + + _FORCE_INLINE_ real_t get_inv_mass() const { return _inv_mass; } + _FORCE_INLINE_ Vector3 get_inv_inertia() const { return _inv_inertia; } + _FORCE_INLINE_ Matrix3 get_inv_inertia_tensor() const { return _inv_inertia_tensor; } + _FORCE_INLINE_ real_t get_friction() const { return friction; } + _FORCE_INLINE_ Vector3 get_gravity() const { return gravity; } + _FORCE_INLINE_ real_t get_density() const { return density; } + _FORCE_INLINE_ real_t get_bounce() const { return bounce; } + + _FORCE_INLINE_ void set_axis_lock(PhysicsServer::BodyAxisLock p_lock) { axis_lock=p_lock; } + _FORCE_INLINE_ PhysicsServer::BodyAxisLock get_axis_lock() const { return axis_lock; } + + void integrate_forces(real_t p_step); + void integrate_velocities(real_t p_step); + + void simulate_motion(const Transform& p_xform,real_t p_step); + void call_queries(); + void wakeup_neighbours(); + + bool sleep_test(real_t p_step); + + BodySW(); + ~BodySW(); + +}; + + +//add contact inline + +void BodySW::add_contact(const Vector3& p_local_pos,const Vector3& p_local_normal, float p_depth, int p_local_shape, const Vector3& p_collider_pos, int p_collider_shape, ObjectID p_collider_instance_id, const RID& p_collider,const Vector3& p_collider_velocity_at_pos) { + + int c_max=contacts.size(); + + if (c_max==0) + return; + + Contact *c = &contacts[0]; + + + int idx=-1; + + if (contact_count<c_max) { + idx=contact_count++; + } else { + + float least_depth=1e20; + int least_deep=-1; + for(int i=0;i<c_max;i++) { + + if (i==0 || c[i].depth<least_depth) { + least_deep=i; + least_depth=c[i].depth; + } + } + + if (least_deep>=0 && least_depth<p_depth) { + + idx=least_deep; + } + if (idx==-1) + return; //none least deepe than this + } + + c[idx].local_pos=p_local_pos; + c[idx].local_normal=p_local_normal; + c[idx].depth=p_depth; + c[idx].local_shape=p_local_shape; + c[idx].collider_pos=p_collider_pos; + c[idx].collider_shape=p_collider_shape; + c[idx].collider_instance_id=p_collider_instance_id; + c[idx].collider=p_collider; + c[idx].collider_velocity_at_pos=p_collider_velocity_at_pos; + +} + + +class PhysicsDirectBodyStateSW : public PhysicsDirectBodyState { + + OBJ_TYPE( PhysicsDirectBodyStateSW, PhysicsDirectBodyState ); + +public: + + static PhysicsDirectBodyStateSW *singleton; + BodySW *body; + real_t step; + + virtual Vector3 get_total_gravity() const { return body->get_gravity(); } // get gravity vector working on this body space/area + virtual float get_total_density() const { return body->get_density(); } // get density of this body space/area + + virtual float get_inverse_mass() const { return body->get_inv_mass(); } // get the mass + virtual Vector3 get_inverse_inertia() const { return body->get_inv_inertia(); } // get density of this body space + virtual Matrix3 get_inverse_inertia_tensor() const { return body->get_inv_inertia_tensor(); } // get density of this body space + + virtual void set_linear_velocity(const Vector3& p_velocity) { body->set_linear_velocity(p_velocity); } + virtual Vector3 get_linear_velocity() const { return body->get_linear_velocity(); } + + virtual void set_angular_velocity(const Vector3& p_velocity) { body->set_angular_velocity(p_velocity); } + virtual Vector3 get_angular_velocity() const { return body->get_angular_velocity(); } + + virtual void set_transform(const Transform& p_transform) { body->set_state(PhysicsServer::BODY_STATE_TRANSFORM,p_transform); } + virtual Transform get_transform() const { return body->get_transform(); } + + virtual void add_force(const Vector3& p_force, const Vector3& p_pos) { body->add_force(p_force,p_pos); } + + virtual void set_sleep_state(bool p_enable) { body->set_active(!p_enable); } + virtual bool is_sleeping() const { return !body->is_active(); } + + virtual int get_contact_count() const { return body->contact_count; } + + virtual Vector3 get_contact_local_pos(int p_contact_idx) const { + ERR_FAIL_INDEX_V(p_contact_idx,body->contact_count,Vector3()); + return body->contacts[p_contact_idx].local_pos; + } + virtual Vector3 get_contact_local_normal(int p_contact_idx) const { ERR_FAIL_INDEX_V(p_contact_idx,body->contact_count,Vector3()); return body->contacts[p_contact_idx].local_normal; } + virtual int get_contact_local_shape(int p_contact_idx) const { ERR_FAIL_INDEX_V(p_contact_idx,body->contact_count,-1); return body->contacts[p_contact_idx].local_shape; } + + virtual RID get_contact_collider(int p_contact_idx) const { ERR_FAIL_INDEX_V(p_contact_idx,body->contact_count,RID()); return body->contacts[p_contact_idx].collider; } + virtual Vector3 get_contact_collider_pos(int p_contact_idx) const { ERR_FAIL_INDEX_V(p_contact_idx,body->contact_count,Vector3()); return body->contacts[p_contact_idx].collider_pos; } + virtual ObjectID get_contact_collider_id(int p_contact_idx) const { ERR_FAIL_INDEX_V(p_contact_idx,body->contact_count,0); return body->contacts[p_contact_idx].collider_instance_id; } + virtual int get_contact_collider_shape(int p_contact_idx) const { ERR_FAIL_INDEX_V(p_contact_idx,body->contact_count,0); return body->contacts[p_contact_idx].collider_shape; } + virtual Vector3 get_contact_collider_velocity_at_pos(int p_contact_idx) const { ERR_FAIL_INDEX_V(p_contact_idx,body->contact_count,Vector3()); return body->contacts[p_contact_idx].collider_velocity_at_pos; } + + virtual PhysicsDirectSpaceState* get_space_state(); + + + virtual real_t get_step() const { return step; } + PhysicsDirectBodyStateSW() { singleton=this; body=NULL; } +}; + + +#endif // BODY__SW_H diff --git a/servers/physics/physics_server_sw.cpp b/servers/physics/physics_server_sw.cpp index 072f11aa52..aff60b5881 100644 --- a/servers/physics/physics_server_sw.cpp +++ b/servers/physics/physics_server_sw.cpp @@ -695,6 +695,25 @@ void PhysicsServerSW::body_set_axis_velocity(RID p_body, const Vector3& p_axis_v }; + +void PhysicsServerSW::body_set_axis_lock(RID p_body,BodyAxisLock p_lock) { + + BodySW *body = body_owner.get(p_body); + ERR_FAIL_COND(!body); + body->set_axis_lock(p_lock); + +} + +PhysicsServerSW::BodyAxisLock PhysicsServerSW::body_get_axis_lock(RID p_body) const{ + + const BodySW *body = body_owner.get(p_body); + ERR_FAIL_COND_V(!body,BODY_AXIS_LOCK_DISABLED); + return body->get_axis_lock(); + +} + + + void PhysicsServerSW::body_add_collision_exception(RID p_body, RID p_body_b) { BodySW *body = body_owner.get(p_body); diff --git a/servers/physics/physics_server_sw.h b/servers/physics/physics_server_sw.h index 2a46ba65fb..0822d76936 100644 --- a/servers/physics/physics_server_sw.h +++ b/servers/physics/physics_server_sw.h @@ -167,6 +167,9 @@ public: virtual void body_apply_impulse(RID p_body, const Vector3& p_pos, const Vector3& p_impulse); virtual void body_set_axis_velocity(RID p_body, const Vector3& p_axis_velocity); + virtual void body_set_axis_lock(RID p_body,BodyAxisLock p_lock); + virtual BodyAxisLock body_get_axis_lock(RID p_body) const; + virtual void body_add_collision_exception(RID p_body, RID p_body_b); virtual void body_remove_collision_exception(RID p_body, RID p_body_b); virtual void body_get_collision_exceptions(RID p_body, List<RID> *p_exceptions); diff --git a/servers/physics_2d/body_pair_2d_sw.cpp b/servers/physics_2d/body_pair_2d_sw.cpp index 669240b8da..ee169cde28 100644 --- a/servers/physics_2d/body_pair_2d_sw.cpp +++ b/servers/physics_2d/body_pair_2d_sw.cpp @@ -234,7 +234,7 @@ bool BodyPair2DSW::setup(float p_step) { //cannot collide - if (A->is_shape_set_as_trigger(shape_A) || B->is_shape_set_as_trigger(shape_B) || A->has_exception(B->get_self()) || B->has_exception(A->get_self()) || (A->get_mode()<=Physics2DServer::BODY_MODE_KINEMATIC && B->get_mode()<=Physics2DServer::BODY_MODE_KINEMATIC)) { + if ((A->get_layer_mask()&B->get_layer_mask())==0 || A->has_exception(B->get_self()) || B->has_exception(A->get_self()) || (A->get_mode()<=Physics2DServer::BODY_MODE_KINEMATIC && B->get_mode()<=Physics2DServer::BODY_MODE_KINEMATIC)) { collided=false; return false; } @@ -343,6 +343,11 @@ bool BodyPair2DSW::setup(float p_step) { } } + if (A->is_shape_set_as_trigger(shape_A) || B->is_shape_set_as_trigger(shape_B)) { + c.active=false; + collided=false; + } + // Precompute normal mass, tangent mass, and bias. real_t rnA = c.rA.dot(c.normal); real_t rnB = c.rB.dot(c.normal); diff --git a/servers/physics_2d/collision_object_2d_sw.cpp b/servers/physics_2d/collision_object_2d_sw.cpp index e07dca472b..277a286144 100644 --- a/servers/physics_2d/collision_object_2d_sw.cpp +++ b/servers/physics_2d/collision_object_2d_sw.cpp @@ -219,4 +219,5 @@ CollisionObject2DSW::CollisionObject2DSW(Type p_type) { space=NULL; instance_id=0; user_mask=0; + layer_mask=1; } diff --git a/servers/physics_2d/collision_object_2d_sw.h b/servers/physics_2d/collision_object_2d_sw.h index 8138cfcc69..cc7f8f50bd 100644 --- a/servers/physics_2d/collision_object_2d_sw.h +++ b/servers/physics_2d/collision_object_2d_sw.h @@ -66,6 +66,7 @@ private: Matrix32 transform; Matrix32 inv_transform; uint32_t user_mask; + uint32_t layer_mask; bool _static; void _update_shapes(); @@ -121,6 +122,9 @@ public: void set_user_mask(uint32_t p_mask) {user_mask=p_mask;} _FORCE_INLINE_ uint32_t get_user_mask() const { return user_mask; } + void set_layer_mask(uint32_t p_mask) {layer_mask=p_mask;} + _FORCE_INLINE_ uint32_t get_layer_mask() const { return layer_mask; } + void remove_shape(Shape2DSW *p_shape); void remove_shape(int p_index); diff --git a/servers/physics_2d/physics_2d_server_sw.cpp b/servers/physics_2d/physics_2d_server_sw.cpp index ee29d3aeff..2171a9c2c4 100644 --- a/servers/physics_2d/physics_2d_server_sw.cpp +++ b/servers/physics_2d/physics_2d_server_sw.cpp @@ -652,6 +652,22 @@ uint32_t Physics2DServerSW::body_get_object_instance_ID(RID p_body) const { return body->get_instance_id(); }; +void Physics2DServerSW::body_set_layer_mask(RID p_body, uint32_t p_flags) { + + Body2DSW *body = body_owner.get(p_body); + ERR_FAIL_COND(!body); + body->set_layer_mask(p_flags); + +}; + +uint32_t Physics2DServerSW::body_get_layer_mask(RID p_body, uint32_t p_flags) const { + + Body2DSW *body = body_owner.get(p_body); + ERR_FAIL_COND_V(!body,0); + + return body->get_layer_mask(); +}; + void Physics2DServerSW::body_set_user_mask(RID p_body, uint32_t p_flags) { diff --git a/servers/physics_2d/physics_2d_server_sw.h b/servers/physics_2d/physics_2d_server_sw.h index e50bb0ab96..09ca029127 100644 --- a/servers/physics_2d/physics_2d_server_sw.h +++ b/servers/physics_2d/physics_2d_server_sw.h @@ -161,6 +161,9 @@ public: virtual void body_set_continuous_collision_detection_mode(RID p_body,CCDMode p_mode); virtual CCDMode body_get_continuous_collision_detection_mode(RID p_body) const; + virtual void body_set_layer_mask(RID p_body, uint32_t p_mask); + virtual uint32_t body_get_layer_mask(RID p_body, uint32_t p_mask) const; + virtual void body_set_user_mask(RID p_body, uint32_t p_mask); virtual uint32_t body_get_user_mask(RID p_body, uint32_t p_mask) const; diff --git a/servers/physics_2d/space_2d_sw.cpp b/servers/physics_2d/space_2d_sw.cpp index d1aec92984..5fbf828c38 100644 --- a/servers/physics_2d/space_2d_sw.cpp +++ b/servers/physics_2d/space_2d_sw.cpp @@ -31,9 +31,9 @@ #include "physics_2d_server_sw.h" -_FORCE_INLINE_ static bool _match_object_type_query(CollisionObject2DSW *p_object, uint32_t p_user_mask, uint32_t p_type_mask) { +_FORCE_INLINE_ static bool _match_object_type_query(CollisionObject2DSW *p_object, uint32_t p_layer_mask, uint32_t p_type_mask) { - if (p_user_mask && !(p_object->get_user_mask()&p_user_mask)) + if ((p_object->get_layer_mask()&p_layer_mask)==0) return false; if (p_object->get_type()==CollisionObject2DSW::TYPE_AREA && !(p_type_mask&Physics2DDirectSpaceState::TYPE_MASK_AREA)) @@ -45,7 +45,7 @@ _FORCE_INLINE_ static bool _match_object_type_query(CollisionObject2DSW *p_objec } -bool Physics2DDirectSpaceStateSW::intersect_ray(const Vector2& p_from, const Vector2& p_to,RayResult &r_result,const Set<RID>& p_exclude,uint32_t p_user_mask,uint32_t p_object_type_mask) { +bool Physics2DDirectSpaceStateSW::intersect_ray(const Vector2& p_from, const Vector2& p_to,RayResult &r_result,const Set<RID>& p_exclude,uint32_t p_layer_mask,uint32_t p_object_type_mask) { @@ -70,7 +70,7 @@ bool Physics2DDirectSpaceStateSW::intersect_ray(const Vector2& p_from, const Vec for(int i=0;i<amount;i++) { - if (!_match_object_type_query(space->intersection_query_results[i],p_user_mask,p_object_type_mask)) + if (!_match_object_type_query(space->intersection_query_results[i],p_layer_mask,p_object_type_mask)) continue; if (p_exclude.has( space->intersection_query_results[i]->get_self())) @@ -135,7 +135,7 @@ bool Physics2DDirectSpaceStateSW::intersect_ray(const Vector2& p_from, const Vec } -int Physics2DDirectSpaceStateSW::intersect_shape(const RID& p_shape, const Matrix32& p_xform,const Vector2& p_motion,float p_margin,ShapeResult *r_results,int p_result_max,const Set<RID>& p_exclude,uint32_t p_user_mask,uint32_t p_object_type_mask) { +int Physics2DDirectSpaceStateSW::intersect_shape(const RID& p_shape, const Matrix32& p_xform,const Vector2& p_motion,float p_margin,ShapeResult *r_results,int p_result_max,const Set<RID>& p_exclude,uint32_t p_layer_mask,uint32_t p_object_type_mask) { if (p_result_max<=0) return 0; @@ -153,7 +153,7 @@ int Physics2DDirectSpaceStateSW::intersect_shape(const RID& p_shape, const Matri for(int i=0;i<amount;i++) { - if (!_match_object_type_query(space->intersection_query_results[i],p_user_mask,p_object_type_mask)) + if (!_match_object_type_query(space->intersection_query_results[i],p_layer_mask,p_object_type_mask)) continue; if (p_exclude.has( space->intersection_query_results[i]->get_self())) @@ -182,7 +182,7 @@ int Physics2DDirectSpaceStateSW::intersect_shape(const RID& p_shape, const Matri -bool Physics2DDirectSpaceStateSW::cast_motion(const RID& p_shape, const Matrix32& p_xform,const Vector2& p_motion,float p_margin,float &p_closest_safe,float &p_closest_unsafe, const Set<RID>& p_exclude,uint32_t p_user_mask,uint32_t p_object_type_mask) { +bool Physics2DDirectSpaceStateSW::cast_motion(const RID& p_shape, const Matrix32& p_xform,const Vector2& p_motion,float p_margin,float &p_closest_safe,float &p_closest_unsafe, const Set<RID>& p_exclude,uint32_t p_layer_mask,uint32_t p_object_type_mask) { @@ -204,7 +204,7 @@ bool Physics2DDirectSpaceStateSW::cast_motion(const RID& p_shape, const Matrix32 for(int i=0;i<amount;i++) { - if (!_match_object_type_query(space->intersection_query_results[i],p_user_mask,p_object_type_mask)) + if (!_match_object_type_query(space->intersection_query_results[i],p_layer_mask,p_object_type_mask)) continue; if (p_exclude.has( space->intersection_query_results[i]->get_self())) @@ -267,7 +267,7 @@ bool Physics2DDirectSpaceStateSW::cast_motion(const RID& p_shape, const Matrix32 } -bool Physics2DDirectSpaceStateSW::collide_shape(RID p_shape, const Matrix32& p_shape_xform,const Vector2& p_motion,float p_margin,Vector2 *r_results,int p_result_max,int &r_result_count, const Set<RID>& p_exclude,uint32_t p_user_mask,uint32_t p_object_type_mask) { +bool Physics2DDirectSpaceStateSW::collide_shape(RID p_shape, const Matrix32& p_shape_xform,const Vector2& p_motion,float p_margin,Vector2 *r_results,int p_result_max,int &r_result_count, const Set<RID>& p_exclude,uint32_t p_layer_mask,uint32_t p_object_type_mask) { if (p_result_max<=0) @@ -301,7 +301,7 @@ bool Physics2DDirectSpaceStateSW::collide_shape(RID p_shape, const Matrix32& p_s for(int i=0;i<amount;i++) { - if (!_match_object_type_query(space->intersection_query_results[i],p_user_mask,p_object_type_mask)) + if (!_match_object_type_query(space->intersection_query_results[i],p_layer_mask,p_object_type_mask)) continue; const CollisionObject2DSW *col_obj=space->intersection_query_results[i]; @@ -353,7 +353,7 @@ static void _rest_cbk_result(const Vector2& p_point_A,const Vector2& p_point_B,v } -bool Physics2DDirectSpaceStateSW::rest_info(RID p_shape, const Matrix32& p_shape_xform,const Vector2& p_motion,float p_margin,ShapeRestInfo *r_info, const Set<RID>& p_exclude,uint32_t p_user_mask,uint32_t p_object_type_mask) { +bool Physics2DDirectSpaceStateSW::rest_info(RID p_shape, const Matrix32& p_shape_xform,const Vector2& p_motion,float p_margin,ShapeRestInfo *r_info, const Set<RID>& p_exclude,uint32_t p_layer_mask,uint32_t p_object_type_mask) { Shape2DSW *shape = static_cast<Physics2DServerSW*>(Physics2DServer::get_singleton())->shape_owner.get(p_shape); @@ -373,7 +373,7 @@ bool Physics2DDirectSpaceStateSW::rest_info(RID p_shape, const Matrix32& p_shape for(int i=0;i<amount;i++) { - if (!_match_object_type_query(space->intersection_query_results[i],p_user_mask,p_object_type_mask)) + if (!_match_object_type_query(space->intersection_query_results[i],p_layer_mask,p_object_type_mask)) continue; const CollisionObject2DSW *col_obj=space->intersection_query_results[i]; diff --git a/servers/physics_2d/space_2d_sw.h b/servers/physics_2d/space_2d_sw.h index 9d3dfae9b5..bd41097fba 100644 --- a/servers/physics_2d/space_2d_sw.h +++ b/servers/physics_2d/space_2d_sw.h @@ -46,11 +46,11 @@ public: Space2DSW *space; - virtual bool intersect_ray(const Vector2& p_from, const Vector2& p_to,RayResult &r_result,const Set<RID>& p_exclude=Set<RID>(),uint32_t p_user_mask=0,uint32_t p_object_type_mask=TYPE_MASK_COLLISION); - virtual int intersect_shape(const RID& p_shape, const Matrix32& p_xform,const Vector2& p_motion,float p_margin,ShapeResult *r_results,int p_result_max,const Set<RID>& p_exclude=Set<RID>(),uint32_t p_user_mask=0,uint32_t p_object_type_mask=TYPE_MASK_COLLISION); - virtual bool cast_motion(const RID& p_shape, const Matrix32& p_xform,const Vector2& p_motion,float p_margin,float &p_closest_safe,float &p_closest_unsafe, const Set<RID>& p_exclude=Set<RID>(),uint32_t p_user_mask=0,uint32_t p_object_type_mask=TYPE_MASK_COLLISION); - virtual bool collide_shape(RID p_shape, const Matrix32& p_shape_xform,const Vector2& p_motion,float p_margin,Vector2 *r_results,int p_result_max,int &r_result_count, const Set<RID>& p_exclude=Set<RID>(),uint32_t p_user_mask=0,uint32_t p_object_type_mask=TYPE_MASK_COLLISION); - virtual bool rest_info(RID p_shape, const Matrix32& p_shape_xform,const Vector2& p_motion,float p_margin,ShapeRestInfo *r_info, const Set<RID>& p_exclude=Set<RID>(),uint32_t p_user_mask=0,uint32_t p_object_type_mask=TYPE_MASK_COLLISION); + virtual bool intersect_ray(const Vector2& p_from, const Vector2& p_to,RayResult &r_result,const Set<RID>& p_exclude=Set<RID>(),uint32_t p_layer_mask=0xFFFFFFFF,uint32_t p_object_type_mask=TYPE_MASK_COLLISION); + virtual int intersect_shape(const RID& p_shape, const Matrix32& p_xform,const Vector2& p_motion,float p_margin,ShapeResult *r_results,int p_result_max,const Set<RID>& p_exclude=Set<RID>(),uint32_t p_layer_mask=0xFFFFFFFF,uint32_t p_object_type_mask=TYPE_MASK_COLLISION); + virtual bool cast_motion(const RID& p_shape, const Matrix32& p_xform,const Vector2& p_motion,float p_margin,float &p_closest_safe,float &p_closest_unsafe, const Set<RID>& p_exclude=Set<RID>(),uint32_t p_layer_mask=0xFFFFFFFF,uint32_t p_object_type_mask=TYPE_MASK_COLLISION); + virtual bool collide_shape(RID p_shape, const Matrix32& p_shape_xform,const Vector2& p_motion,float p_margin,Vector2 *r_results,int p_result_max,int &r_result_count, const Set<RID>& p_exclude=Set<RID>(),uint32_t p_layer_mask=0xFFFFFFFF,uint32_t p_object_type_mask=TYPE_MASK_COLLISION); + virtual bool rest_info(RID p_shape, const Matrix32& p_shape_xform,const Vector2& p_motion,float p_margin,ShapeRestInfo *r_info, const Set<RID>& p_exclude=Set<RID>(),uint32_t p_layer_mask=0xFFFFFFFF,uint32_t p_object_type_mask=TYPE_MASK_COLLISION); Physics2DDirectSpaceStateSW(); }; diff --git a/servers/physics_2d_server.cpp b/servers/physics_2d_server.cpp index 0851ad59ef..9cbd7414bd 100644 --- a/servers/physics_2d_server.cpp +++ b/servers/physics_2d_server.cpp @@ -329,8 +329,12 @@ void Physics2DServer::_bind_methods() { ObjectTypeDB::bind_method(_MD("body_get_continuous_collision_detection_mode","body"),&Physics2DServer::body_get_continuous_collision_detection_mode); - //ObjectTypeDB::bind_method(_MD("body_set_user_flags","flags""),&Physics2DServer::body_set_shape,DEFVAL(Matrix32)); - //ObjectTypeDB::bind_method(_MD("body_get_user_flags","body","shape_idx","shape"),&Physics2DServer::body_get_shape); + ObjectTypeDB::bind_method(_MD("body_set_layer_mask","body","mask"),&Physics2DServer::body_set_layer_mask); + ObjectTypeDB::bind_method(_MD("body_get_layer_mask","body"),&Physics2DServer::body_get_layer_mask); + + ObjectTypeDB::bind_method(_MD("body_set_user_mask","body","mask"),&Physics2DServer::body_set_user_mask); + ObjectTypeDB::bind_method(_MD("body_get_user_mask","body"),&Physics2DServer::body_get_user_mask); + ObjectTypeDB::bind_method(_MD("body_set_param","body","param","value"),&Physics2DServer::body_set_param); ObjectTypeDB::bind_method(_MD("body_get_param","body","param"),&Physics2DServer::body_get_param); diff --git a/servers/physics_2d_server.h b/servers/physics_2d_server.h index 172fa1699b..def1e69992 100644 --- a/servers/physics_2d_server.h +++ b/servers/physics_2d_server.h @@ -88,9 +88,9 @@ class Physics2DDirectSpaceState : public Object { OBJ_TYPE( Physics2DDirectSpaceState, Object ); - Variant _intersect_ray(const Vector2& p_from, const Vector2& p_to,const Vector<RID>& p_exclude=Vector<RID>(),uint32_t p_user_mask=0); - Variant _intersect_shape(const RID& p_shape, const Matrix32& p_xform,int p_result_max=64,const Vector<RID>& p_exclude=Vector<RID>(),uint32_t p_user_mask=0); - Variant _cast_motion(const RID& p_shape, const Matrix32& p_xform,const Vector2& p_motion,const Vector<RID>& p_exclude=Vector<RID>(),uint32_t p_user_mask=0); + Variant _intersect_ray(const Vector2& p_from, const Vector2& p_to,const Vector<RID>& p_exclude=Vector<RID>(),uint32_t p_layers=0); + Variant _intersect_shape(const RID& p_shape, const Matrix32& p_xform,int p_result_max=64,const Vector<RID>& p_exclude=Vector<RID>(),uint32_t p_layers=0); + Variant _cast_motion(const RID& p_shape, const Matrix32& p_xform,const Vector2& p_motion,const Vector<RID>& p_exclude=Vector<RID>(),uint32_t p_layers=0); protected: @@ -118,7 +118,7 @@ public: int shape; }; - virtual bool intersect_ray(const Vector2& p_from, const Vector2& p_to,RayResult &r_result,const Set<RID>& p_exclude=Set<RID>(),uint32_t p_user_mask=0,uint32_t p_object_type_mask=TYPE_MASK_COLLISION)=0; + virtual bool intersect_ray(const Vector2& p_from, const Vector2& p_to,RayResult &r_result,const Set<RID>& p_exclude=Set<RID>(),uint32_t p_layer_mask=0xFFFFFFFF,uint32_t p_object_type_mask=TYPE_MASK_COLLISION)=0; struct ShapeResult { @@ -129,13 +129,13 @@ public: }; - virtual int intersect_shape(const RID& p_shape, const Matrix32& p_xform,const Vector2& p_motion,float p_margin,ShapeResult *r_results,int p_result_max,const Set<RID>& p_exclude=Set<RID>(),uint32_t p_user_mask=0,uint32_t p_object_type_mask=TYPE_MASK_COLLISION)=0; + virtual int intersect_shape(const RID& p_shape, const Matrix32& p_xform,const Vector2& p_motion,float p_margin,ShapeResult *r_results,int p_result_max,const Set<RID>& p_exclude=Set<RID>(),uint32_t p_layer_mask=0xFFFFFFFF,uint32_t p_object_type_mask=TYPE_MASK_COLLISION)=0; - virtual bool cast_motion(const RID& p_shape, const Matrix32& p_xform,const Vector2& p_motion,float p_margin,float &p_closest_safe,float &p_closest_unsafe, const Set<RID>& p_exclude=Set<RID>(),uint32_t p_user_mask=0,uint32_t p_object_type_mask=TYPE_MASK_COLLISION)=0; + virtual bool cast_motion(const RID& p_shape, const Matrix32& p_xform,const Vector2& p_motion,float p_margin,float &p_closest_safe,float &p_closest_unsafe, const Set<RID>& p_exclude=Set<RID>(),uint32_t p_layer_mask=0xFFFFFFFF,uint32_t p_object_type_mask=TYPE_MASK_COLLISION)=0; - virtual bool collide_shape(RID p_shape, const Matrix32& p_shape_xform,const Vector2& p_motion,float p_margin,Vector2 *r_results,int p_result_max,int &r_result_count, const Set<RID>& p_exclude=Set<RID>(),uint32_t p_user_mask=0,uint32_t p_object_type_mask=TYPE_MASK_COLLISION)=0; + virtual bool collide_shape(RID p_shape, const Matrix32& p_shape_xform,const Vector2& p_motion,float p_margin,Vector2 *r_results,int p_result_max,int &r_result_count, const Set<RID>& p_exclude=Set<RID>(),uint32_t p_layer_mask=0xFFFFFFFF,uint32_t p_object_type_mask=TYPE_MASK_COLLISION)=0; struct ShapeRestInfo { @@ -148,7 +148,7 @@ public: }; - virtual bool rest_info(RID p_shape, const Matrix32& p_shape_xform,const Vector2& p_motion,float p_margin,ShapeRestInfo *r_info, const Set<RID>& p_exclude=Set<RID>(),uint32_t p_user_mask=0,uint32_t p_object_type_mask=TYPE_MASK_COLLISION)=0; + virtual bool rest_info(RID p_shape, const Matrix32& p_shape_xform,const Vector2& p_motion,float p_margin,ShapeRestInfo *r_info, const Set<RID>& p_exclude=Set<RID>(),uint32_t p_layer_mask=0xFFFFFFFF,uint32_t p_object_type_mask=TYPE_MASK_COLLISION)=0; Physics2DDirectSpaceState(); @@ -338,6 +338,9 @@ public: virtual void body_set_continuous_collision_detection_mode(RID p_body,CCDMode p_mode)=0; virtual CCDMode body_get_continuous_collision_detection_mode(RID p_body) const=0; + virtual void body_set_layer_mask(RID p_body, uint32_t p_mask)=0; + virtual uint32_t body_get_layer_mask(RID p_body, uint32_t p_mask) const=0; + virtual void body_set_user_mask(RID p_body, uint32_t p_mask)=0; virtual uint32_t body_get_user_mask(RID p_body, uint32_t p_mask) const=0; diff --git a/servers/physics_server.cpp b/servers/physics_server.cpp index f1b4627b6c..69c82519dd 100644 --- a/servers/physics_server.cpp +++ b/servers/physics_server.cpp @@ -315,6 +315,9 @@ void PhysicsServer::_bind_methods() { ObjectTypeDB::bind_method(_MD("body_apply_impulse","body","pos","impulse"),&PhysicsServer::body_apply_impulse); ObjectTypeDB::bind_method(_MD("body_set_axis_velocity","body","axis_velocity"),&PhysicsServer::body_set_axis_velocity); + ObjectTypeDB::bind_method(_MD("body_set_axis_lock","body","axis"),&PhysicsServer::body_set_axis_lock); + ObjectTypeDB::bind_method(_MD("body_get_axis_lock","body"),&PhysicsServer::body_set_axis_lock); + ObjectTypeDB::bind_method(_MD("body_add_collision_exception","body","excepted_body"),&PhysicsServer::body_add_collision_exception); ObjectTypeDB::bind_method(_MD("body_remove_collision_exception","body","excepted_body"),&PhysicsServer::body_remove_collision_exception); // virtual void body_get_collision_exceptions(RID p_body, List<RID> *p_exceptions)=0; diff --git a/servers/physics_server.h b/servers/physics_server.h index 4276a4dab8..da51dbc8e1 100644 --- a/servers/physics_server.h +++ b/servers/physics_server.h @@ -341,6 +341,16 @@ public: virtual void body_apply_impulse(RID p_body, const Vector3& p_pos, const Vector3& p_impulse)=0; virtual void body_set_axis_velocity(RID p_body, const Vector3& p_axis_velocity)=0; + enum BodyAxisLock { + BODY_AXIS_LOCK_DISABLED, + BODY_AXIS_LOCK_X, + BODY_AXIS_LOCK_Y, + BODY_AXIS_LOCK_Z, + }; + + virtual void body_set_axis_lock(RID p_body,BodyAxisLock p_lock)=0; + virtual BodyAxisLock body_get_axis_lock(RID p_body) const=0; + //fix virtual void body_add_collision_exception(RID p_body, RID p_body_b)=0; virtual void body_remove_collision_exception(RID p_body, RID p_body_b)=0; @@ -420,6 +430,7 @@ VARIANT_ENUM_CAST( PhysicsServer::AreaSpaceOverrideMode ); VARIANT_ENUM_CAST( PhysicsServer::BodyMode ); VARIANT_ENUM_CAST( PhysicsServer::BodyParameter ); VARIANT_ENUM_CAST( PhysicsServer::BodyState ); +VARIANT_ENUM_CAST( PhysicsServer::BodyAxisLock ); //VARIANT_ENUM_CAST( PhysicsServer::JointParam ); //VARIANT_ENUM_CAST( PhysicsServer::JointType ); //VARIANT_ENUM_CAST( PhysicsServer::DampedStringParam ); diff --git a/servers/visual/rasterizer.cpp b/servers/visual/rasterizer.cpp index 2de49d3d81..e21848eac2 100644 --- a/servers/visual/rasterizer.cpp +++ b/servers/visual/rasterizer.cpp @@ -157,6 +157,9 @@ RID Rasterizer::_create_shader(const FixedMaterialShaderKey& p_key) { if (p_key.use_alpha) { code+="DIFFUSE_ALPHA=diffuse;\n"; + if (p_key.discard_alpha) { + code+="DISCARD=diffuse.a<0.5;\n"; + } } else { code+="DIFFUSE=diffuse.rgb;\n"; } @@ -262,6 +265,7 @@ void Rasterizer::_free_shader(const FixedMaterialShaderKey& p_key) { void Rasterizer::fixed_material_set_flag(RID p_material, VS::FixedMaterialFlags p_flag, bool p_enabled) { + Map<RID,FixedMaterial*>::Element *E = fixed_materials.find(p_material); ERR_FAIL_COND(!E); FixedMaterial &fm=*E->get(); @@ -271,6 +275,7 @@ void Rasterizer::fixed_material_set_flag(RID p_material, VS::FixedMaterialFlags case VS::FIXED_MATERIAL_FLAG_USE_ALPHA: fm.use_alpha=p_enabled; break; case VS::FIXED_MATERIAL_FLAG_USE_COLOR_ARRAY: fm.use_color_array=p_enabled; break; case VS::FIXED_MATERIAL_FLAG_USE_POINT_SIZE: fm.use_pointsize=p_enabled; break; + case VS::FIXED_MATERIAL_FLAG_DISCARD_ALPHA: fm.discard_alpha=p_enabled; break; } if (!fm.dirty_list.in_list()) @@ -288,6 +293,7 @@ bool Rasterizer::fixed_material_get_flag(RID p_material, VS::FixedMaterialFlags case VS::FIXED_MATERIAL_FLAG_USE_ALPHA: return fm.use_alpha;; break; case VS::FIXED_MATERIAL_FLAG_USE_COLOR_ARRAY: return fm.use_color_array;; break; case VS::FIXED_MATERIAL_FLAG_USE_POINT_SIZE: return fm.use_pointsize;; break; + case VS::FIXED_MATERIAL_FLAG_DISCARD_ALPHA: return fm.discard_alpha;; break; } diff --git a/servers/visual/rasterizer.h b/servers/visual/rasterizer.h index 0b54fec859..a3cdff9859 100644 --- a/servers/visual/rasterizer.h +++ b/servers/visual/rasterizer.h @@ -55,6 +55,7 @@ protected: bool use_alpha:1; bool use_color_array:1; bool use_pointsize:1; + bool discard_alpha:1; bool valid:1; }; @@ -80,6 +81,7 @@ protected: RID self; bool use_alpha; bool use_color_array; + bool discard_alpha; bool use_pointsize; float point_size; Transform uv_xform; @@ -100,6 +102,7 @@ protected: k.use_alpha=use_alpha; k.use_color_array=use_color_array; k.use_pointsize=use_pointsize; + k.discard_alpha=discard_alpha; k.detail_blend=detail_blend; k.valid=true; for(int i=0;i<VS::FIXED_MATERIAL_PARAM_MAX;i++) { @@ -119,6 +122,7 @@ protected: use_alpha=false; use_color_array=false; use_pointsize=false; + discard_alpha=false; point_size=1.0; detail_blend=VS::MATERIAL_BLEND_MODE_MIX; for(int i=0;i<VS::FIXED_MATERIAL_PARAM_MAX;i++) { @@ -153,6 +157,16 @@ protected: void _free_fixed_material(const RID& p_material); public: + + enum ShadowFilterTechnique { + SHADOW_FILTER_NONE, + SHADOW_FILTER_PCF5, + SHADOW_FILTER_PCF13, + SHADOW_FILTER_ESM, + SHADOW_FILTER_VSM, + }; + + /* TEXTURE API */ virtual RID texture_create()=0; @@ -264,6 +278,9 @@ public: virtual AABB mesh_get_aabb(RID p_mesh) const=0; + virtual void mesh_set_custom_aabb(RID p_mesh,const AABB& p_aabb)=0; + virtual AABB mesh_get_custom_aabb(RID p_mesh) const=0; + /* MULTIMESH API */ virtual RID multimesh_create()=0; @@ -285,6 +302,22 @@ public: virtual void multimesh_set_visible_instances(RID p_multimesh,int p_visible)=0; virtual int multimesh_get_visible_instances(RID p_multimesh) const=0; + /* IMMEDIATE API */ + + virtual RID immediate_create()=0; + virtual void immediate_begin(RID p_immediate,VS::PrimitiveType p_rimitive,RID p_texture=RID())=0; + virtual void immediate_vertex(RID p_immediate,const Vector3& p_vertex)=0; + virtual void immediate_normal(RID p_immediate,const Vector3& p_normal)=0; + virtual void immediate_tangent(RID p_immediate,const Plane& p_tangent)=0; + virtual void immediate_color(RID p_immediate,const Color& p_color)=0; + virtual void immediate_uv(RID p_immediate,const Vector2& tex_uv)=0; + virtual void immediate_uv2(RID p_immediate,const Vector2& tex_uv)=0; + virtual void immediate_end(RID p_immediate)=0; + virtual void immediate_clear(RID p_immediate)=0; + virtual AABB immediate_get_aabb(RID p_immediate) const=0; + virtual void immediate_set_material(RID p_immediate,RID p_material)=0; + virtual RID immediate_get_material(RID p_immediate) const=0; + /* PARTICLES API */ @@ -474,6 +507,7 @@ public: virtual void add_mesh( const RID& p_mesh, const InstanceData *p_data)=0; virtual void add_multimesh( const RID& p_multimesh, const InstanceData *p_data)=0; + virtual void add_immediate( const RID& p_immediate, const InstanceData *p_data)=0; virtual void add_particles( const RID& p_particle_instance, const InstanceData *p_data)=0; @@ -531,6 +565,7 @@ public: virtual bool is_material(const RID& p_rid) const=0; virtual bool is_mesh(const RID& p_rid) const=0; virtual bool is_multimesh(const RID& p_rid) const=0; + virtual bool is_immediate(const RID& p_rid) const=0; virtual bool is_particles(const RID &p_beam) const=0; virtual bool is_light(const RID& p_rid) const=0; diff --git a/servers/visual/rasterizer_dummy.cpp b/servers/visual/rasterizer_dummy.cpp index bfb427f2e8..1d55693bfb 100644 --- a/servers/visual/rasterizer_dummy.cpp +++ b/servers/visual/rasterizer_dummy.cpp @@ -587,6 +587,23 @@ AABB RasterizerDummy::mesh_get_aabb(RID p_mesh) const { return aabb; } +void RasterizerDummy::mesh_set_custom_aabb(RID p_mesh,const AABB& p_aabb) { + + Mesh *mesh = mesh_owner.get( p_mesh ); + ERR_FAIL_COND(!mesh); + + mesh->custom_aabb=p_aabb; +} + +AABB RasterizerDummy::mesh_get_custom_aabb(RID p_mesh) const { + + const Mesh *mesh = mesh_owner.get( p_mesh ); + ERR_FAIL_COND_V(!mesh,AABB()); + + return mesh->custom_aabb; + +} + /* MULTIMESH API */ RID RasterizerDummy::multimesh_create() { @@ -692,6 +709,74 @@ int RasterizerDummy::multimesh_get_visible_instances(RID p_multimesh) const { } +/* IMMEDIATE API */ + + +RID RasterizerDummy::immediate_create() { + + Immediate *im = memnew( Immediate ); + return immediate_owner.make_rid(im); + +} + +void RasterizerDummy::immediate_begin(RID p_immediate,VS::PrimitiveType p_rimitive,RID p_texture){ + + +} +void RasterizerDummy::immediate_vertex(RID p_immediate,const Vector3& p_vertex){ + + +} +void RasterizerDummy::immediate_normal(RID p_immediate,const Vector3& p_normal){ + + +} +void RasterizerDummy::immediate_tangent(RID p_immediate,const Plane& p_tangent){ + + +} +void RasterizerDummy::immediate_color(RID p_immediate,const Color& p_color){ + + +} +void RasterizerDummy::immediate_uv(RID p_immediate,const Vector2& tex_uv){ + + +} +void RasterizerDummy::immediate_uv2(RID p_immediate,const Vector2& tex_uv){ + + +} + +void RasterizerDummy::immediate_end(RID p_immediate){ + + +} +void RasterizerDummy::immediate_clear(RID p_immediate) { + + +} + +AABB RasterizerDummy::immediate_get_aabb(RID p_immediate) const { + + return AABB(Vector3(-1,-1,-1),Vector3(2,2,2)); +} + +void RasterizerDummy::immediate_set_material(RID p_immediate,RID p_material) { + + Immediate *im = immediate_owner.get(p_immediate); + ERR_FAIL_COND(!im); + im->material=p_material; + +} + +RID RasterizerDummy::immediate_get_material(RID p_immediate) const { + + const Immediate *im = immediate_owner.get(p_immediate); + ERR_FAIL_COND_V(!im,RID()); + return im->material; + +} /* PARTICLES API */ @@ -1610,6 +1695,12 @@ bool RasterizerDummy::is_mesh(const RID& p_rid) const { return mesh_owner.owns(p_rid); } + +bool RasterizerDummy::is_immediate(const RID& p_rid) const { + + return immediate_owner.owns(p_rid); +} + bool RasterizerDummy::is_multimesh(const RID& p_rid) const { return multimesh_owner.owns(p_rid); @@ -1686,6 +1777,12 @@ void RasterizerDummy::free(const RID& p_rid) { multimesh_owner.free(p_rid); memdelete(multimesh); + } else if (immediate_owner.owns(p_rid)) { + + Immediate *immediate = immediate_owner.get(p_rid); + immediate_owner.free(p_rid); + memdelete(immediate); + } else if (particles_owner.owns(p_rid)) { Particles *particles = particles_owner.get(p_rid); diff --git a/servers/visual/rasterizer_dummy.h b/servers/visual/rasterizer_dummy.h index e1fa521284..b683a25bdc 100644 --- a/servers/visual/rasterizer_dummy.h +++ b/servers/visual/rasterizer_dummy.h @@ -189,6 +189,7 @@ class RasterizerDummy : public Rasterizer { Vector<Surface*> surfaces; int morph_target_count; VS::MorphTargetMode morph_target_mode; + AABB custom_aabb; mutable uint64_t last_pass; Mesh() { @@ -230,8 +231,18 @@ class RasterizerDummy : public Rasterizer { }; + mutable RID_Owner<MultiMesh> multimesh_owner; + struct Immediate { + + + RID material; + int empty; + }; + + mutable RID_Owner<Immediate> immediate_owner; + struct Particles : public Geometry { ParticleSystemSW data; // software particle system @@ -464,6 +475,10 @@ public: virtual AABB mesh_get_aabb(RID p_mesh) const; + virtual void mesh_set_custom_aabb(RID p_mesh,const AABB& p_aabb); + virtual AABB mesh_get_custom_aabb(RID p_mesh) const; + + /* MULTIMESH API */ virtual RID multimesh_create(); @@ -485,6 +500,23 @@ public: virtual void multimesh_set_visible_instances(RID p_multimesh,int p_visible); virtual int multimesh_get_visible_instances(RID p_multimesh) const; + /* IMMEDIATE API */ + + virtual RID immediate_create(); + virtual void immediate_begin(RID p_immediate,VS::PrimitiveType p_rimitive,RID p_texture=RID()); + virtual void immediate_vertex(RID p_immediate,const Vector3& p_vertex); + virtual void immediate_normal(RID p_immediate,const Vector3& p_normal); + virtual void immediate_tangent(RID p_immediate,const Plane& p_tangent); + virtual void immediate_color(RID p_immediate,const Color& p_color); + virtual void immediate_uv(RID p_immediate,const Vector2& tex_uv); + virtual void immediate_uv2(RID p_immediate,const Vector2& tex_uv); + virtual void immediate_end(RID p_immediate); + virtual void immediate_clear(RID p_immediate); + virtual void immediate_set_material(RID p_immediate,RID p_material); + virtual RID immediate_get_material(RID p_immediate) const; + + virtual AABB immediate_get_aabb(RID p_mesh) const; + /* PARTICLES API */ virtual RID particles_create(); @@ -642,6 +674,7 @@ public: virtual void add_mesh( const RID& p_mesh, const InstanceData *p_data); virtual void add_multimesh( const RID& p_multimesh, const InstanceData *p_data); + virtual void add_immediate( const RID& p_immediate, const InstanceData *p_data) {} virtual void add_particles( const RID& p_particle_instance, const InstanceData *p_data); virtual void end_scene(); @@ -687,6 +720,7 @@ public: virtual bool is_texture(const RID& p_rid) const; virtual bool is_material(const RID& p_rid) const; virtual bool is_mesh(const RID& p_rid) const; + virtual bool is_immediate(const RID& p_rid) const; virtual bool is_multimesh(const RID& p_rid) const; virtual bool is_particles(const RID &p_beam) const; diff --git a/servers/visual/shader_language.cpp b/servers/visual/shader_language.cpp index 3061c2ddff..cdc1f678e7 100644 --- a/servers/visual/shader_language.cpp +++ b/servers/visual/shader_language.cpp @@ -1034,7 +1034,7 @@ const ShaderLanguage::BuiltinsDef ShaderLanguage::fragment_builtins_defs[]={ { "SPEC_EXP", TYPE_FLOAT}, { "GLOW", TYPE_FLOAT}, { "SHADE_PARAM", TYPE_FLOAT}, - { "DISCARD", TYPE_FLOAT}, + { "DISCARD", TYPE_BOOL}, { "SCREEN_UV", TYPE_VEC2}, { "POINT_COORD", TYPE_VEC2}, { "INV_CAMERA_MATRIX", TYPE_MAT4}, diff --git a/servers/visual/visual_server_raster.cpp b/servers/visual/visual_server_raster.cpp index 2108e5b9c2..bffc1c43fe 100644 --- a/servers/visual/visual_server_raster.cpp +++ b/servers/visual/visual_server_raster.cpp @@ -434,6 +434,21 @@ int VisualServerRaster::mesh_get_surface_count(RID p_mesh) const{ } + +void VisualServerRaster::mesh_set_custom_aabb(RID p_mesh,const AABB& p_aabb) { + + VS_CHANGED; + _dependency_queue_update(p_mesh,true); + rasterizer->mesh_set_custom_aabb(p_mesh,p_aabb); + +} + +AABB VisualServerRaster::mesh_get_custom_aabb(RID p_mesh) const { + + return rasterizer->mesh_get_custom_aabb(p_mesh); +} + + /* MULTIMESH */ RID VisualServerRaster::multimesh_create() { @@ -504,6 +519,72 @@ int VisualServerRaster::multimesh_get_visible_instances(RID p_multimesh) const { } +/* IMMEDIATE API */ + + +RID VisualServerRaster::immediate_create() { + + return rasterizer->immediate_create(); +} + +void VisualServerRaster::immediate_begin(RID p_immediate,PrimitiveType p_primitive,RID p_texture){ + + rasterizer->immediate_begin(p_immediate,p_primitive,p_texture); +} +void VisualServerRaster::immediate_vertex(RID p_immediate,const Vector3& p_vertex){ + + rasterizer->immediate_vertex(p_immediate,p_vertex); + +} +void VisualServerRaster::immediate_normal(RID p_immediate,const Vector3& p_normal){ + + rasterizer->immediate_normal(p_immediate,p_normal); + +} +void VisualServerRaster::immediate_tangent(RID p_immediate,const Plane& p_tangent){ + + rasterizer->immediate_tangent(p_immediate,p_tangent); + +} +void VisualServerRaster::immediate_color(RID p_immediate,const Color& p_color){ + + rasterizer->immediate_color(p_immediate,p_color); + +} +void VisualServerRaster::immediate_uv(RID p_immediate,const Vector2& p_uv){ + + rasterizer->immediate_uv(p_immediate,p_uv); + +} +void VisualServerRaster::immediate_uv2(RID p_immediate,const Vector2& p_uv2){ + + rasterizer->immediate_uv2(p_immediate,p_uv2); + +} +void VisualServerRaster::immediate_end(RID p_immediate){ + + VS_CHANGED; + _dependency_queue_update(p_immediate,true); + rasterizer->immediate_end(p_immediate); + +} +void VisualServerRaster::immediate_clear(RID p_immediate){ + + VS_CHANGED; + _dependency_queue_update(p_immediate,true); + rasterizer->immediate_clear(p_immediate); + +} + +void VisualServerRaster::immediate_set_material(RID p_immediate,RID p_material) { + + rasterizer->immediate_set_material(p_immediate,p_material); +} + +RID VisualServerRaster::immediate_get_material(RID p_immediate) const { + + return rasterizer->immediate_get_material(p_immediate); +} /* PARTICLES API */ @@ -1690,6 +1771,8 @@ void VisualServerRaster::instance_set_base(RID p_instance, RID p_base) { instance->data.morph_values.resize( rasterizer->mesh_get_morph_target_count(p_base)); } else if (rasterizer->is_multimesh(p_base)) { instance->base_type=INSTANCE_MULTIMESH; + } else if (rasterizer->is_immediate(p_base)) { + instance->base_type=INSTANCE_IMMEDIATE; } else if (rasterizer->is_particles(p_base)) { instance->base_type=INSTANCE_PARTICLES; instance->particles_info=memnew( Instance::ParticlesInfo ); @@ -2453,6 +2536,12 @@ void VisualServerRaster::_update_instance_aabb(Instance *p_instance) { new_aabb = rasterizer->multimesh_get_aabb(p_instance->base_rid); } break; + case VisualServer::INSTANCE_IMMEDIATE: { + + new_aabb = rasterizer->immediate_get_aabb(p_instance->base_rid); + + + } break; case VisualServer::INSTANCE_PARTICLES: { new_aabb = rasterizer->particles_get_aabb(p_instance->base_rid); @@ -3483,6 +3572,9 @@ void VisualServerRaster::_instance_draw(Instance *p_instance) { case INSTANCE_MULTIMESH: { rasterizer->add_multimesh(p_instance->base_rid, &p_instance->data); } break; + case INSTANCE_IMMEDIATE: { + rasterizer->add_immediate(p_instance->base_rid, &p_instance->data); + } break; case INSTANCE_PARTICLES: { rasterizer->add_particles(p_instance->particles_info->instance, &p_instance->data); } break; diff --git a/servers/visual/visual_server_raster.h b/servers/visual/visual_server_raster.h index d3d504a7c6..f6ef4ba6d5 100644 --- a/servers/visual/visual_server_raster.h +++ b/servers/visual/visual_server_raster.h @@ -742,7 +742,10 @@ public: virtual void mesh_remove_surface(RID p_mesh,int p_index); virtual int mesh_get_surface_count(RID p_mesh) const; - + + virtual void mesh_set_custom_aabb(RID p_mesh,const AABB& p_aabb); + virtual AABB mesh_get_custom_aabb(RID p_mesh) const; + /* MULTIMESH API */ @@ -763,6 +766,21 @@ public: virtual void multimesh_set_visible_instances(RID p_multimesh,int p_visible); virtual int multimesh_get_visible_instances(RID p_multimesh) const; + /* IMMEDIATE API */ + + virtual RID immediate_create(); + virtual void immediate_begin(RID p_immediate,PrimitiveType p_rimitive,RID p_texture=RID()); + virtual void immediate_vertex(RID p_immediate,const Vector3& p_vertex); + virtual void immediate_normal(RID p_immediate,const Vector3& p_normal); + virtual void immediate_tangent(RID p_immediate,const Plane& p_tangent); + virtual void immediate_color(RID p_immediate,const Color& p_color); + virtual void immediate_uv(RID p_immediate, const Vector2& p_uv); + virtual void immediate_uv2(RID p_immediate,const Vector2& tex_uv); + virtual void immediate_end(RID p_immediate); + virtual void immediate_clear(RID p_immediate); + virtual void immediate_set_material(RID p_immediate,RID p_material); + virtual RID immediate_get_material(RID p_immediate) const; + /* PARTICLES API */ diff --git a/servers/visual/visual_server_wrap_mt.h b/servers/visual/visual_server_wrap_mt.h index c8f00c3786..cfc4bd8605 100644 --- a/servers/visual/visual_server_wrap_mt.h +++ b/servers/visual/visual_server_wrap_mt.h @@ -696,6 +696,7 @@ public: FUNC2(mesh_set_morph_target_count,RID,int); FUNC1RC(int,mesh_get_morph_target_count,RID); + FUNC2(mesh_set_morph_target_mode,RID,MorphTargetMode); FUNC1RC(MorphTargetMode,mesh_get_morph_target_mode,RID); @@ -717,6 +718,9 @@ public: FUNC1RC(int,mesh_get_surface_count,RID); + FUNC2(mesh_set_custom_aabb,RID,const AABB&); + FUNC1RC(AABB,mesh_get_custom_aabb,RID); + /* MULTIMESH API */ @@ -737,6 +741,22 @@ public: FUNC2(multimesh_set_visible_instances,RID,int); FUNC1RC(int,multimesh_get_visible_instances,RID); + /* IMMEDIATE API */ + + + FUNC0R(RID,immediate_create); + FUNC3(immediate_begin,RID,PrimitiveType,RID); + FUNC2(immediate_vertex,RID,const Vector3&); + FUNC2(immediate_normal,RID,const Vector3&); + FUNC2(immediate_tangent,RID,const Plane&); + FUNC2(immediate_color,RID,const Color&); + FUNC2(immediate_uv,RID,const Vector2&); + FUNC2(immediate_uv2,RID,const Vector2&); + FUNC1(immediate_end,RID); + FUNC1(immediate_clear,RID); + FUNC2(immediate_set_material,RID,RID); + FUNC1RC(RID,immediate_get_material,RID); + /* PARTICLES API */ diff --git a/servers/visual_server.cpp b/servers/visual_server.cpp index a45e2c8eaf..08cc57e307 100644 --- a/servers/visual_server.cpp +++ b/servers/visual_server.cpp @@ -274,6 +274,55 @@ RID VisualServer::make_sphere_mesh(int p_lats,int p_lons,float p_radius) { return mesh; } + +RID VisualServer::material_2d_get(bool p_shaded, bool p_transparent, bool p_cut_alpha, bool p_opaque_prepass) { + + int version=0; + if (p_shaded) + version=1; + if (p_transparent) + version|=2; + if (p_cut_alpha) + version|=4; + if (p_opaque_prepass) + version|=8; + if (material_2d[version].is_valid()) + return material_2d[version]; + + //not valid, make + + material_2d[version]=fixed_material_create(); + fixed_material_set_flag(material_2d[version],FIXED_MATERIAL_FLAG_USE_ALPHA,p_transparent); + fixed_material_set_flag(material_2d[version],FIXED_MATERIAL_FLAG_USE_COLOR_ARRAY,true); + fixed_material_set_flag(material_2d[version],FIXED_MATERIAL_FLAG_DISCARD_ALPHA,p_cut_alpha); + material_set_flag(material_2d[version],MATERIAL_FLAG_UNSHADED,!p_shaded); + material_set_flag(material_2d[version],MATERIAL_FLAG_DOUBLE_SIDED,true); + material_set_hint(material_2d[version],MATERIAL_HINT_OPAQUE_PRE_PASS,p_opaque_prepass); + fixed_material_set_texture(material_2d[version],FIXED_MATERIAL_PARAM_DIFFUSE,get_white_texture()); + //material cut alpha? + return material_2d[version]; +} + +RID VisualServer::get_white_texture() { + + if (white_texture.is_valid()) + return white_texture; + + DVector<uint8_t> wt; + wt.resize(16*3); + { + DVector<uint8_t>::Write w =wt.write(); + for(int i=0;i<16*3;i++) + w[i]=255; + } + Image white(4,4,0,Image::FORMAT_RGB,wt); + white_texture=texture_create(); + texture_allocate(white_texture,4,4,Image::FORMAT_RGB); + texture_set_data(white_texture,white); + return white_texture; + +} + void VisualServer::_bind_methods() { diff --git a/servers/visual_server.h b/servers/visual_server.h index 4cf0c96228..e5d1e75702 100644 --- a/servers/visual_server.h +++ b/servers/visual_server.h @@ -56,6 +56,8 @@ class VisualServer : public Object { protected: RID _make_test_cube(); RID test_texture; + RID white_texture; + RID material_2d[16]; static VisualServer* (*create_func)(); static void _bind_methods(); @@ -189,6 +191,7 @@ public: MATERIAL_HINT_OPAQUE_PRE_PASS, MATERIAL_HINT_NO_SHADOW, MATERIAL_HINT_NO_DEPTH_DRAW, + MATERIAL_HINT_NO_DEPTH_DRAW_FOR_ALPHA, MATERIAL_HINT_MAX }; @@ -199,7 +202,8 @@ public: MATERIAL_BLEND_MODE_MIX, //default MATERIAL_BLEND_MODE_ADD, MATERIAL_BLEND_MODE_SUB, - MATERIAL_BLEND_MODE_MUL + MATERIAL_BLEND_MODE_MUL, + MATERIAL_BLEND_MODE_PREMULT_ALPHA }; @@ -240,6 +244,7 @@ public: FIXED_MATERIAL_FLAG_USE_ALPHA, FIXED_MATERIAL_FLAG_USE_COLOR_ARRAY, FIXED_MATERIAL_FLAG_USE_POINT_SIZE, + FIXED_MATERIAL_FLAG_DISCARD_ALPHA, FIXED_MATERIAL_FLAG_MAX, }; @@ -334,7 +339,10 @@ public: virtual void mesh_remove_surface(RID p_mesh,int p_index)=0; virtual int mesh_get_surface_count(RID p_mesh) const=0; - + + virtual void mesh_set_custom_aabb(RID p_mesh,const AABB& p_aabb)=0; + virtual AABB mesh_get_custom_aabb(RID p_mesh) const=0; + /* MULTIMESH API */ virtual RID multimesh_create()=0; @@ -356,7 +364,22 @@ public: virtual void multimesh_set_visible_instances(RID p_multimesh,int p_visible)=0; virtual int multimesh_get_visible_instances(RID p_multimesh) const=0; - + /* IMMEDIATE API */ + + virtual RID immediate_create()=0; + virtual void immediate_begin(RID p_immediate,PrimitiveType p_rimitive,RID p_texture=RID())=0; + virtual void immediate_vertex(RID p_immediate,const Vector3& p_vertex)=0; + virtual void immediate_normal(RID p_immediate,const Vector3& p_normal)=0; + virtual void immediate_tangent(RID p_immediate,const Plane& p_tangent)=0; + virtual void immediate_color(RID p_immediate,const Color& p_color)=0; + virtual void immediate_uv(RID p_immediate,const Vector2& tex_uv)=0; + virtual void immediate_uv2(RID p_immediate,const Vector2& tex_uv)=0; + virtual void immediate_end(RID p_immediate)=0; + virtual void immediate_clear(RID p_immediate)=0; + virtual void immediate_set_material(RID p_immediate,RID p_material)=0; + virtual RID immediate_get_material(RID p_immediate) const=0; + + /* PARTICLES API */ virtual RID particles_create()=0; @@ -502,7 +525,8 @@ public: enum LightDirectionalShadowMode { LIGHT_DIRECTIONAL_SHADOW_ORTHOGONAL, LIGHT_DIRECTIONAL_SHADOW_PERSPECTIVE, - LIGHT_DIRECTIONAL_SHADOW_PARALLEL_SPLIT + LIGHT_DIRECTIONAL_SHADOW_PARALLEL_2_SPLITS, + LIGHT_DIRECTIONAL_SHADOW_PARALLEL_4_SPLITS }; virtual void light_directional_set_shadow_mode(RID p_light,LightDirectionalShadowMode p_mode)=0; @@ -551,6 +575,8 @@ public: virtual void portal_set_connect_range(RID p_portal, float p_range) =0; virtual float portal_get_connect_range(RID p_portal) const =0; + + /* CAMERA API */ virtual RID camera_create()=0; @@ -670,6 +696,7 @@ public: ENV_BG_PARAM_CUBEMAP, ENV_BG_PARAM_ENERGY, ENV_BG_PARAM_SCALE, + ENV_BG_PARAM_GLOW, ENV_BG_PARAM_MAX }; @@ -678,6 +705,7 @@ public: virtual Variant environment_get_background_param(RID p_env,EnvironmentBGParam p_param) const=0; enum EnvironmentFx { + ENV_FX_FXAA, ENV_FX_GLOW, ENV_FX_DOF_BLUR, ENV_FX_HDR, @@ -692,8 +720,17 @@ public: virtual void environment_set_enable_fx(RID p_env,EnvironmentFx p_effect,bool p_enabled)=0; virtual bool environment_is_fx_enabled(RID p_env,EnvironmentFx p_mode) const=0; + enum EnvironmentFxBlurBlendMode { + ENV_FX_BLUR_BLEND_MODE_ADDITIVE, + ENV_FX_BLUR_BLEND_MODE_SCREEN, + ENV_FX_BLUR_BLEND_MODE_SOFTLIGHT, + }; + enum EnvironmentFxParam { ENV_FX_PARAM_GLOW_BLUR_PASSES, + ENV_FX_PARAM_GLOW_BLUR_SCALE, + ENV_FX_PARAM_GLOW_BLUR_STRENGTH, + ENV_FX_PARAM_GLOW_BLUR_BLEND_MODE, ENV_FX_PARAM_GLOW_BLOOM, ENV_FX_PARAM_GLOW_BLOOM_TRESHOLD, ENV_FX_PARAM_DOF_BLUR_PASSES, @@ -750,12 +787,13 @@ public: INSTANCE_NONE, INSTANCE_MESH, INSTANCE_MULTIMESH, + INSTANCE_IMMEDIATE, INSTANCE_PARTICLES, INSTANCE_LIGHT, INSTANCE_ROOM, INSTANCE_PORTAL, - INSTANCE_GEOMETRY_MASK=(1<<INSTANCE_MESH)|(1<<INSTANCE_MULTIMESH)|(1<<INSTANCE_PARTICLES) + INSTANCE_GEOMETRY_MASK=(1<<INSTANCE_MESH)|(1<<INSTANCE_MULTIMESH)|(1<<INSTANCE_IMMEDIATE)|(1<<INSTANCE_PARTICLES) }; @@ -811,6 +849,7 @@ public: INSTANCE_FLAG_RECEIVE_SHADOWS, INSTANCE_FLAG_DEPH_SCALE, INSTANCE_FLAG_VISIBLE_IN_ALL_ROOMS, + INSTANCE_FLAG_USE_BAKED_LIGHT_VOLUME, INSTANCE_FLAG_MAX }; @@ -924,6 +963,12 @@ public: }; virtual int get_render_info(RenderInfo p_info)=0; + + + /* Materials for 2D on 3D */ + + + RID material_2d_get(bool p_shaded, bool p_transparent, bool p_cut_alpha,bool p_opaque_prepass); /* TESTING */ @@ -931,6 +976,7 @@ public: virtual RID get_test_cube()=0; virtual RID get_test_texture(); + virtual RID get_white_texture(); virtual RID make_sphere_mesh(int p_lats,int p_lons,float p_radius); |