[395] | 1 | // Copyright (C) 2014-2015 ChaosForge Ltd
|
---|
| 2 | // http://chaosforge.org/
|
---|
| 3 | //
|
---|
| 4 | // This file is part of Nova libraries.
|
---|
| 5 | // For conditions of distribution and use, see copying.txt file in root folder.
|
---|
[319] | 6 |
|
---|
[320] | 7 | #include "nv/engine/particle_engine.hh"
|
---|
[306] | 8 |
|
---|
| 9 | #include <nv/interface/device.hh>
|
---|
[319] | 10 | #include <nv/core/random.hh>
|
---|
[374] | 11 | #include <nv/stl/utility.hh>
|
---|
[452] | 12 | #include <nv/lua/lua_math.hh>
|
---|
[319] | 13 | #include <nv/core/logging.hh>
|
---|
[306] | 14 |
|
---|
[518] | 15 | nv::hash_store< nv::shash64, nv::particle_emitter_func > nv::particle_engine::m_emitters;
|
---|
| 16 | nv::hash_store< nv::shash64, nv::particle_affector_funcs > nv::particle_engine::m_affectors;
|
---|
[306] | 17 |
|
---|
[519] | 18 | nv::vector< nv::particle_emitter_func >* nv::particle_engine::m_debug_emitter_list;
|
---|
| 19 | nv::vector< nv::particle_affector_func >* nv::particle_engine::m_debug_affector_list;
|
---|
| 20 |
|
---|
| 21 |
|
---|
[518] | 22 | nv::hash_map< nv::particle_emitter_func, nv::const_string >* nv::particle_engine::m_debug_emitter_names = nullptr;
|
---|
| 23 | nv::hash_map< nv::particle_affector_func, nv::const_string >* nv::particle_engine::m_debug_affector_names = nullptr;
|
---|
| 24 | nv::hash_map< nv::particle_affector_func, nv::type_entry* >* nv::particle_engine::m_debug_affector_types = nullptr;
|
---|
| 25 |
|
---|
[312] | 26 | using namespace nv;
|
---|
| 27 |
|
---|
[518] | 28 | static void nv_particle_emitter_point( const particle_emitter_data*, particle* p, uint32 count )
|
---|
[312] | 29 | {
|
---|
| 30 | for ( uint32 i = 0; i < count; ++i )
|
---|
| 31 | {
|
---|
| 32 | p[i].position = vec3();
|
---|
| 33 | }
|
---|
| 34 | }
|
---|
| 35 |
|
---|
[518] | 36 | static void nv_particle_emitter_box( const particle_emitter_data* pe, particle* p, uint32 count )
|
---|
[312] | 37 | {
|
---|
| 38 | random& r = random::get();
|
---|
| 39 | for ( uint32 i = 0; i < count; ++i )
|
---|
| 40 | {
|
---|
| 41 | p[i].position =
|
---|
| 42 | r.frange( -pe->hextents[0], pe->hextents[0] ) * pe->cdir +
|
---|
| 43 | r.frange( 0.0f, pe->extents[1] ) * pe->dir +
|
---|
| 44 | r.frange( -pe->hextents[2], pe->hextents[2] ) * pe->odir;
|
---|
| 45 | }
|
---|
| 46 | }
|
---|
| 47 |
|
---|
[518] | 48 | static void nv_particle_emitter_cylinder( const particle_emitter_data* pe, particle* p, uint32 count )
|
---|
[312] | 49 | {
|
---|
| 50 | random& r = random::get();
|
---|
| 51 | for ( uint32 i = 0; i < count; ++i )
|
---|
| 52 | {
|
---|
| 53 | vec2 rellipse( r.disk_point( pe->precise ) * pe->extents[0] );
|
---|
| 54 | p[i].position =
|
---|
| 55 | rellipse.x * pe->cdir +
|
---|
| 56 | r.frange( 0.0f, pe->extents[1] ) * pe->dir +
|
---|
| 57 | rellipse.y * pe->odir;
|
---|
| 58 | }
|
---|
| 59 | }
|
---|
| 60 |
|
---|
[518] | 61 | static void nv_particle_emitter_sphere( const particle_emitter_data* pe, particle* p, uint32 count )
|
---|
[312] | 62 | {
|
---|
| 63 | random& r = random::get();
|
---|
| 64 | for ( uint32 i = 0; i < count; ++i )
|
---|
| 65 | {
|
---|
| 66 | vec3 rsphere = r.sphere_point( pe->precise ) * pe->extents[0];
|
---|
| 67 | p[i].position =
|
---|
| 68 | rsphere.x * pe->cdir +
|
---|
| 69 | rsphere.y * pe->dir +
|
---|
| 70 | rsphere.z * pe->odir;
|
---|
| 71 | }
|
---|
| 72 | }
|
---|
| 73 |
|
---|
[518] | 74 | static void nv_particle_emitter_cylindroid( const particle_emitter_data* pe, particle* p, uint32 count )
|
---|
[312] | 75 | {
|
---|
| 76 | random& r = random::get();
|
---|
| 77 | for ( uint32 i = 0; i < count; ++i )
|
---|
| 78 | {
|
---|
| 79 | vec2 rellipse = r.ellipse_point( vec2( pe->hextents[0], pe->hextents[2] ), pe->precise );
|
---|
| 80 | p[i].position =
|
---|
| 81 | rellipse.x * pe->cdir +
|
---|
| 82 | r.frange( 0.0f, pe->extents[1] ) * pe->dir +
|
---|
| 83 | rellipse.y * pe->odir;
|
---|
| 84 | }
|
---|
| 85 | }
|
---|
| 86 |
|
---|
[518] | 87 | static void nv_particle_emitter_ellipsoid( const particle_emitter_data* pe, particle* p, uint32 count )
|
---|
[312] | 88 | {
|
---|
| 89 | random& r = random::get();
|
---|
| 90 | for ( uint32 i = 0; i < count; ++i )
|
---|
| 91 | {
|
---|
| 92 | vec3 rsphere = r.ellipsoid_point( pe->hextents, pe->precise );
|
---|
| 93 | p[i].position =
|
---|
| 94 | rsphere.x * pe->cdir +
|
---|
| 95 | rsphere.y * pe->dir +
|
---|
| 96 | rsphere.z * pe->odir;
|
---|
| 97 | }
|
---|
| 98 | }
|
---|
| 99 |
|
---|
[518] | 100 | static void nv_particle_emitter_hollow_cylinder( const particle_emitter_data* pe, particle* p, uint32 count )
|
---|
[312] | 101 | {
|
---|
| 102 | random& r = random::get();
|
---|
| 103 | for ( uint32 i = 0; i < count; ++i )
|
---|
| 104 | {
|
---|
| 105 | vec2 rellipse = r.hollow_disk_point(
|
---|
| 106 | pe->ihextents[0],
|
---|
| 107 | pe->hextents[0],
|
---|
| 108 | pe->precise );
|
---|
| 109 | p[i].position =
|
---|
| 110 | rellipse.x * pe->cdir +
|
---|
| 111 | r.frange( 0.0f, pe->extents[1] ) * pe->dir +
|
---|
| 112 | rellipse.y * pe->odir;
|
---|
| 113 | }
|
---|
| 114 | }
|
---|
| 115 |
|
---|
[518] | 116 | static void nv_particle_emitter_hollow_sphere( const particle_emitter_data* pe, particle* p, uint32 count )
|
---|
[312] | 117 | {
|
---|
| 118 | random& r = random::get();
|
---|
| 119 | for ( uint32 i = 0; i < count; ++i )
|
---|
| 120 | {
|
---|
| 121 | vec3 rellipse = r.hollow_sphere_point( pe->ihextents[0], pe->hextents[0], pe->precise );
|
---|
| 122 | p[i].position =
|
---|
| 123 | rellipse.x * pe->cdir +
|
---|
| 124 | rellipse.y * pe->dir +
|
---|
| 125 | rellipse.z * pe->odir;
|
---|
| 126 | }
|
---|
| 127 | }
|
---|
| 128 |
|
---|
[518] | 129 | static void nv_particle_emitter_hollow_cylindroid( const particle_emitter_data* pe, particle* p, uint32 count )
|
---|
[312] | 130 | {
|
---|
| 131 | random& r = random::get();
|
---|
| 132 | for ( uint32 i = 0; i < count; ++i )
|
---|
| 133 | {
|
---|
| 134 | vec2 rellipse = r.hollow_ellipse_point(
|
---|
| 135 | vec2( pe->ihextents[0], pe->ihextents[2] ),
|
---|
| 136 | vec2( pe->hextents[0], pe->hextents[2] ),
|
---|
| 137 | pe->precise );
|
---|
| 138 | p[i].position =
|
---|
| 139 | rellipse.x * pe->cdir +
|
---|
| 140 | r.frange( 0.0f, pe->extents[1] ) * pe->dir +
|
---|
| 141 | rellipse.y * pe->odir;
|
---|
| 142 | }
|
---|
| 143 | }
|
---|
| 144 |
|
---|
[518] | 145 | static void nv_particle_emitter_hollow_ellipsoid( const particle_emitter_data* pe, particle* p, uint32 count )
|
---|
[312] | 146 | {
|
---|
| 147 | random& r = random::get();
|
---|
| 148 | for ( uint32 i = 0; i < count; ++i )
|
---|
| 149 | {
|
---|
| 150 | vec3 rellipse = r.hollow_ellipsoid_point( pe->ihextents, pe->hextents, pe->precise );
|
---|
| 151 | p[i].position =
|
---|
| 152 | rellipse.x * pe->cdir +
|
---|
| 153 | rellipse.y * pe->dir +
|
---|
| 154 | rellipse.z * pe->odir;
|
---|
| 155 | }
|
---|
| 156 | }
|
---|
| 157 |
|
---|
| 158 | struct nvpe_linear_force_data
|
---|
| 159 | {
|
---|
| 160 | nv::vec3 force_vector;
|
---|
| 161 | bool average;
|
---|
| 162 | };
|
---|
| 163 |
|
---|
[519] | 164 | NV_RTTI_DECLARE( nvpe_linear_force_data )
|
---|
| 165 |
|
---|
[312] | 166 | static bool nv_particle_affector_linear_force_init( lua::table_guard* table, particle_affector_data* data )
|
---|
| 167 | {
|
---|
[406] | 168 | nvpe_linear_force_data* datap = reinterpret_cast<nvpe_linear_force_data*>( data->paramters );
|
---|
[312] | 169 | datap->force_vector = table->get<vec3>("force_vector", vec3() );
|
---|
| 170 | datap->average = table->get<bool>("average", false );
|
---|
| 171 | return true;
|
---|
| 172 | }
|
---|
| 173 |
|
---|
| 174 | static void nv_particle_affector_linear_force( const particle_affector_data* data, particle* p, float factor, uint32 count )
|
---|
| 175 | {
|
---|
[406] | 176 | const nvpe_linear_force_data* datap = reinterpret_cast<const nvpe_linear_force_data*>( data->paramters );
|
---|
[312] | 177 | if ( datap->average )
|
---|
| 178 | {
|
---|
[500] | 179 | float norm_factor = nv::min( factor, 1.0f, p->lifetime );
|
---|
[312] | 180 | for ( uint32 i = 0; i < count; ++i )
|
---|
| 181 | p[i].velocity = datap->force_vector * norm_factor + p[i].velocity * ( 1.0f - norm_factor );
|
---|
| 182 | }
|
---|
| 183 | else
|
---|
| 184 | {
|
---|
[500] | 185 | vec3 scvector = datap->force_vector * nv::min( factor, p->lifetime );
|
---|
[312] | 186 | for ( uint32 i = 0; i < count; ++i ) p[i].velocity += scvector;
|
---|
| 187 | }
|
---|
| 188 | }
|
---|
| 189 |
|
---|
| 190 | struct nvpe_deflector_plane_data
|
---|
| 191 | {
|
---|
| 192 | nv::vec3 plane_point;
|
---|
| 193 | nv::vec3 plane_normal;
|
---|
| 194 | float bounce;
|
---|
| 195 | float distance;
|
---|
| 196 | };
|
---|
| 197 |
|
---|
[519] | 198 | NV_RTTI_DECLARE( nvpe_deflector_plane_data )
|
---|
| 199 |
|
---|
[312] | 200 | static bool nv_particle_affector_deflector_plane_init( lua::table_guard* table, particle_affector_data* data )
|
---|
| 201 | {
|
---|
[406] | 202 | nvpe_deflector_plane_data* datap = reinterpret_cast<nvpe_deflector_plane_data*>( data->paramters );
|
---|
[312] | 203 | datap->plane_point = table->get<vec3>("plane_point", vec3() );
|
---|
| 204 | datap->plane_normal = table->get<vec3>("plane_normal", vec3(0.0f,1.0f,0.0f) );
|
---|
| 205 | datap->plane_normal = normalize_safe( datap->plane_normal, vec3(0.0f,1.0f,0.0f) );
|
---|
| 206 | datap->bounce = table->get<float>("bounce", 0.0f );
|
---|
[471] | 207 | datap->distance = -math::dot( datap->plane_normal, datap->plane_point ) / sqrt( math::dot( datap->plane_normal, datap->plane_normal ) );
|
---|
[312] | 208 | return true;
|
---|
| 209 | }
|
---|
| 210 |
|
---|
| 211 | static void nv_particle_affector_deflector_plane( const particle_affector_data* data, particle* p, float factor, uint32 count )
|
---|
| 212 | {
|
---|
[406] | 213 | const nvpe_deflector_plane_data* datap = reinterpret_cast<const nvpe_deflector_plane_data*>( data->paramters );
|
---|
[312] | 214 | for ( uint32 i = 0; i < count; ++i )
|
---|
| 215 | {
|
---|
| 216 | particle& pt = p[i];
|
---|
[500] | 217 | vec3 direction = pt.velocity * nv::min( factor, p->lifetime );
|
---|
[454] | 218 | if ( math::dot( datap->plane_normal, pt.position + direction ) + datap->distance <= 0.0f )
|
---|
[312] | 219 | {
|
---|
[454] | 220 | float val = math::dot( datap->plane_normal, pt.position ) + datap->distance;
|
---|
[312] | 221 | if ( val > 0.0f )
|
---|
| 222 | {
|
---|
[454] | 223 | vec3 part_dir = direction * ( -val / math::dot( datap->plane_normal, direction ) );
|
---|
[312] | 224 | pt.position = pt.position + part_dir + ( part_dir - direction ) * datap->bounce;
|
---|
[454] | 225 | pt.velocity = math::reflect( pt.velocity, datap->plane_normal ) * datap->bounce;
|
---|
[312] | 226 | }
|
---|
| 227 | }
|
---|
| 228 | }
|
---|
| 229 | }
|
---|
| 230 |
|
---|
| 231 | struct nvpe_color_fader_data
|
---|
| 232 | {
|
---|
| 233 | nv::vec4 adjustment;
|
---|
| 234 | };
|
---|
| 235 |
|
---|
[519] | 236 | NV_RTTI_DECLARE( nvpe_color_fader_data )
|
---|
| 237 |
|
---|
[312] | 238 | static bool nv_particle_affector_color_fader_init( lua::table_guard* table, particle_affector_data* data )
|
---|
| 239 | {
|
---|
[406] | 240 | nvpe_color_fader_data* datap = reinterpret_cast<nvpe_color_fader_data*>( data->paramters );
|
---|
[312] | 241 | datap->adjustment = table->get<vec4>("adjustment", vec4() );
|
---|
| 242 | return true;
|
---|
| 243 | }
|
---|
| 244 |
|
---|
| 245 | static void nv_particle_affector_color_fader( const particle_affector_data* data, particle* p, float factor, uint32 count )
|
---|
| 246 | {
|
---|
[406] | 247 | const nvpe_color_fader_data* datap = reinterpret_cast<const nvpe_color_fader_data*>( data->paramters );
|
---|
[500] | 248 | vec4 adjustment = datap->adjustment * nv::min( factor, p->lifetime );
|
---|
[312] | 249 | for ( uint32 i = 0; i < count; ++i )
|
---|
| 250 | {
|
---|
[454] | 251 | p[i].color = math::clamp( p[i].color + adjustment, 0.0f, 1.0f );
|
---|
[312] | 252 | }
|
---|
| 253 | }
|
---|
| 254 |
|
---|
| 255 | struct nvpe_scaler_data
|
---|
| 256 | {
|
---|
| 257 | nv::vec2 adjustment;
|
---|
| 258 | };
|
---|
| 259 |
|
---|
[519] | 260 | NV_RTTI_DECLARE( nvpe_scaler_data )
|
---|
| 261 |
|
---|
[312] | 262 | static bool nv_particle_affector_scaler_init( lua::table_guard* table, particle_affector_data* data )
|
---|
| 263 | {
|
---|
[406] | 264 | nvpe_scaler_data* datap = reinterpret_cast<nvpe_scaler_data*>( data->paramters );
|
---|
[312] | 265 | float rate = table->get<float>("rate", 0.0f );
|
---|
| 266 | datap->adjustment = table->get<vec2>("adjustment", vec2(rate,rate) );
|
---|
| 267 | return true;
|
---|
| 268 | }
|
---|
| 269 |
|
---|
| 270 | static void nv_particle_affector_scaler( const particle_affector_data* data, particle* p, float factor, uint32 count )
|
---|
| 271 | {
|
---|
[406] | 272 | const nvpe_scaler_data* datap = reinterpret_cast<const nvpe_scaler_data*>( data->paramters );
|
---|
[500] | 273 | vec2 adjustment = datap->adjustment * nv::min( factor, p->lifetime );
|
---|
[312] | 274 | for ( uint32 i = 0; i < count; ++i )
|
---|
| 275 | {
|
---|
[454] | 276 | p[i].size = math::max( p[i].size + adjustment, vec2() );
|
---|
[312] | 277 | }
|
---|
| 278 | }
|
---|
| 279 |
|
---|
[518] | 280 | nv::particle_engine::particle_engine( context* a_context, bool debug_data )
|
---|
[306] | 281 | {
|
---|
[518] | 282 | m_context = a_context;
|
---|
| 283 | if ( debug_data )
|
---|
[306] | 284 | {
|
---|
[518] | 285 | m_debug_emitter_names = new nv::hash_map< nv::particle_emitter_func, nv::const_string >;
|
---|
| 286 | m_debug_affector_names = new nv::hash_map< nv::particle_affector_func, nv::const_string >;
|
---|
| 287 | m_debug_affector_types = new nv::hash_map< nv::particle_affector_func, nv::type_entry* >;
|
---|
[519] | 288 | m_debug_emitter_list = new nv::vector< nv::particle_emitter_func >;
|
---|
| 289 | m_debug_affector_list = new nv::vector< nv::particle_affector_func >;
|
---|
[306] | 290 | }
|
---|
| 291 |
|
---|
[518] | 292 | register_standard_emitters();
|
---|
[312] | 293 | register_standard_affectors();
|
---|
[306] | 294 | }
|
---|
| 295 |
|
---|
[518] | 296 | nv::particle_system nv::particle_engine::create_system( const particle_system_data* data, particle_system_group group )
|
---|
[306] | 297 | {
|
---|
[500] | 298 | particle_system_group_info* ginfo = m_groups.get( group );
|
---|
| 299 | if ( !ginfo ) return nv::particle_system();
|
---|
| 300 |
|
---|
[306] | 301 | particle_system result = m_systems.create();
|
---|
| 302 | particle_system_info* info = m_systems.get( result );
|
---|
[499] | 303 | info->group = group;
|
---|
[518] | 304 | info->data = data;
|
---|
| 305 | uint32 ecount = data->emitter_count;
|
---|
[306] | 306 | for ( uint32 i = 0; i < ecount; ++i )
|
---|
| 307 | {
|
---|
[518] | 308 | info->emitters[i].active = true;
|
---|
| 309 | if ( data->emitters[i].duration_max == 0.0f )
|
---|
| 310 | info->emitters[i].pause = 0;
|
---|
[353] | 311 | else
|
---|
[518] | 312 | info->emitters[i].pause = random::get().frange( data->emitters[i].duration_min, data->emitters[i].duration_max );
|
---|
[353] | 313 |
|
---|
[306] | 314 | }
|
---|
| 315 |
|
---|
| 316 | info->count = 0;
|
---|
[518] | 317 | info->particles = new particle[data->quota];
|
---|
[500] | 318 | ginfo->ref_counter++;
|
---|
[306] | 319 |
|
---|
| 320 | return result;
|
---|
| 321 | }
|
---|
| 322 |
|
---|
[518] | 323 | nv::particle_system nv::particle_engine::create_system( resource< nv::particle_system_data > rdata, particle_system_group group )
|
---|
[306] | 324 | {
|
---|
[518] | 325 | if ( auto data = rdata.lock() )
|
---|
| 326 | return create_system( &*data, group );
|
---|
| 327 | return {};
|
---|
[306] | 328 | }
|
---|
| 329 |
|
---|
[518] | 330 | void nv::particle_engine::prepare( particle_system_group group )
|
---|
[499] | 331 | {
|
---|
| 332 | particle_system_group_info* info = m_groups.get( group );
|
---|
| 333 | if ( info )
|
---|
| 334 | {
|
---|
[518] | 335 | info->count = 0;
|
---|
[499] | 336 | }
|
---|
| 337 | }
|
---|
| 338 |
|
---|
| 339 | nv::particle_system_group nv::particle_engine::create_group( uint32 max_particles )
|
---|
| 340 | {
|
---|
| 341 | particle_system_group result = m_groups.create();
|
---|
| 342 | particle_system_group_info* info = m_groups.get( result );
|
---|
| 343 | info->local = false;
|
---|
| 344 | info->count = 0;
|
---|
| 345 | info->quota = max_particles;
|
---|
[501] | 346 | info->vtx_buffer = m_context->create_buffer( VERTEX_BUFFER, STREAM_DRAW, info->quota * sizeof( particle_quad )/*, info->quads_[0].data*/ );
|
---|
[499] | 347 | vertex_array_desc desc;
|
---|
| 348 | desc.add_vertex_buffers< particle_vtx >( info->vtx_buffer, true );
|
---|
| 349 | info->vtx_array = m_context->create_vertex_array( desc );
|
---|
| 350 | info->quads = new particle_quad[info->quota];
|
---|
[500] | 351 | info->ref_counter = 0;
|
---|
[499] | 352 | return result;
|
---|
| 353 | }
|
---|
| 354 |
|
---|
[306] | 355 | nv::particle_engine::~particle_engine()
|
---|
| 356 | {
|
---|
[353] | 357 | clear();
|
---|
[306] | 358 | }
|
---|
| 359 |
|
---|
[353] | 360 | void nv::particle_engine::reset()
|
---|
| 361 | {
|
---|
| 362 | clear();
|
---|
[518] | 363 | register_standard_emitters( );
|
---|
[353] | 364 | register_standard_affectors();
|
---|
| 365 | }
|
---|
| 366 |
|
---|
| 367 | void nv::particle_engine::clear()
|
---|
| 368 | {
|
---|
| 369 | while ( m_systems.size() > 0 )
|
---|
| 370 | release( m_systems.get_handle( 0 ) );
|
---|
[499] | 371 | while ( m_groups.size() > 0 )
|
---|
| 372 | release( m_groups.get_handle( 0 ) );
|
---|
[518] | 373 | m_emitters.clear();
|
---|
[353] | 374 | m_affectors.clear();
|
---|
| 375 | }
|
---|
| 376 |
|
---|
| 377 |
|
---|
[306] | 378 | void nv::particle_engine::release( particle_system system )
|
---|
| 379 | {
|
---|
| 380 | particle_system_info* info = m_systems.get( system );
|
---|
| 381 | if ( info )
|
---|
| 382 | {
|
---|
[500] | 383 | particle_system_group_info* ginfo = m_groups.get( info->group );
|
---|
| 384 | if ( ginfo ) ginfo->ref_counter--;
|
---|
| 385 | delete[] info->particles;
|
---|
[499] | 386 | m_systems.destroy( system );
|
---|
| 387 | }
|
---|
| 388 | }
|
---|
| 389 |
|
---|
| 390 | void nv::particle_engine::release( particle_system_group group )
|
---|
| 391 | {
|
---|
| 392 | particle_system_group_info* info = m_groups.get( group );
|
---|
| 393 | if ( info )
|
---|
| 394 | {
|
---|
[306] | 395 | delete[] info->quads;
|
---|
[313] | 396 | m_context->release( info->vtx_array );
|
---|
[499] | 397 | m_groups.destroy( group );
|
---|
[306] | 398 | }
|
---|
| 399 | }
|
---|
| 400 |
|
---|
[500] | 401 | void nv::particle_engine::render( particle_system system, const scene_state& s )
|
---|
[306] | 402 | {
|
---|
[500] | 403 | particle_system_info* info = m_systems.get( system );
|
---|
| 404 | if ( info )
|
---|
| 405 | {
|
---|
| 406 | generate_data( info, s );
|
---|
| 407 | }
|
---|
[499] | 408 | }
|
---|
| 409 |
|
---|
[515] | 410 | void nv::particle_engine::update( particle_system system, transform model, float dtime )
|
---|
[499] | 411 | {
|
---|
[306] | 412 | particle_system_info* info = m_systems.get( system );
|
---|
| 413 | if ( info )
|
---|
| 414 | {
|
---|
[500] | 415 | // while ( dtime > 0.2 )
|
---|
| 416 | // {
|
---|
[518] | 417 | // update_emitters( info, 0.2 );
|
---|
[500] | 418 | // destroy_particles( info, 0.2 );
|
---|
| 419 | // create_particles( info, 0.2 );
|
---|
| 420 | // update_particles( info, 0.2 );
|
---|
| 421 | // dtime -= 0.2;
|
---|
| 422 | // }
|
---|
[306] | 423 |
|
---|
[518] | 424 | update_emitters( info, dtime );
|
---|
[500] | 425 | destroy_particles( info, dtime );
|
---|
[515] | 426 | create_particles( info, model, dtime );
|
---|
[500] | 427 | update_particles( info, dtime );
|
---|
| 428 |
|
---|
| 429 | // generate_data( info );
|
---|
[306] | 430 | }
|
---|
| 431 | }
|
---|
| 432 |
|
---|
| 433 | void nv::particle_engine::set_texcoords( particle_system system, vec2 a, vec2 b )
|
---|
| 434 | {
|
---|
[500] | 435 |
|
---|
[306] | 436 | particle_system_info* info = m_systems.get( system );
|
---|
| 437 | if ( info )
|
---|
| 438 | {
|
---|
[500] | 439 | info->texcoords[0] = a;
|
---|
| 440 | info->texcoords[1] = b;
|
---|
[306] | 441 | }
|
---|
| 442 | }
|
---|
| 443 |
|
---|
[500] | 444 | void nv::particle_engine::generate_data( particle_system_info* info, const scene_state& s )
|
---|
[306] | 445 | {
|
---|
[499] | 446 | // void* rawptr = m_context->map_buffer( info->vtx_buffer, nv::WRITE_UNSYNCHRONIZED, offset, info->count*sizeof( particle_quad ) );
|
---|
| 447 | // particle_quad* quads = reinterpret_cast<particle_quad*>( rawptr );
|
---|
| 448 |
|
---|
| 449 | particle_system_group_info* group = m_groups.get( info->group );
|
---|
| 450 | if ( !info )
|
---|
| 451 | {
|
---|
| 452 | return;
|
---|
| 453 | }
|
---|
| 454 |
|
---|
[309] | 455 | vec2 lb = vec2( -0.5f, -0.5f );
|
---|
| 456 | vec2 rt = vec2( 0.5f, 0.5f );
|
---|
[306] | 457 |
|
---|
[309] | 458 | switch ( info->data->origin )
|
---|
| 459 | {
|
---|
| 460 | case particle_origin::CENTER : break;
|
---|
| 461 | case particle_origin::TOP_LEFT : lb = vec2(0.f,-1.f); rt = vec2(1.f,0.f); break;
|
---|
[323] | 462 | case particle_origin::TOP_CENTER : lb.y = -1.f; rt.y = 0.f; break;
|
---|
[309] | 463 | case particle_origin::TOP_RIGHT : lb = vec2(-1.f,-1.f); rt = vec2(); break;
|
---|
| 464 | case particle_origin::CENTER_LEFT : lb.x = 0.f; rt.x = 1.f; break;
|
---|
| 465 | case particle_origin::CENTER_RIGHT : lb.x = -1.f; rt.x = 0.f; break;
|
---|
| 466 | case particle_origin::BOTTOM_LEFT : lb = vec2(); rt = vec2(1.f,1.f); break;
|
---|
| 467 | case particle_origin::BOTTOM_CENTER : lb.y = 0.f; rt.y = 1.f; break;
|
---|
| 468 | case particle_origin::BOTTOM_RIGHT : lb = vec2(-1.f,0.f); rt = vec2(.0f,1.f); break;
|
---|
| 469 | }
|
---|
| 470 |
|
---|
| 471 | const vec3 sm[4] =
|
---|
| 472 | {
|
---|
| 473 | vec3( lb.x, lb.y, 0.0f ),
|
---|
| 474 | vec3( rt.x, lb.y, 0.0f ),
|
---|
| 475 | vec3( lb.x, rt.y, 0.0f ),
|
---|
| 476 | vec3( rt.x, rt.y, 0.0f ),
|
---|
[306] | 477 | };
|
---|
[309] | 478 | vec3 z( 0.0f, 0.0f ,1.0f );
|
---|
[306] | 479 |
|
---|
| 480 | particle_orientation orientation = info->data->orientation;
|
---|
| 481 | vec3 common_up ( info->data->common_up );
|
---|
| 482 | vec3 common_dir( info->data->common_dir );
|
---|
| 483 | bool accurate_facing = info->data->accurate_facing;
|
---|
[312] | 484 | mat3 rot_mat;
|
---|
| 485 | vec3 right;
|
---|
| 486 | vec3 pdir( 0.0f, 1.0f, 0.0f );
|
---|
[306] | 487 |
|
---|
[500] | 488 | vec3 camera_pos = s.get_camera().get_position();
|
---|
| 489 | vec3 inv_view_dir = math::normalize( -s.get_camera().get_direction() );
|
---|
[499] | 490 |
|
---|
[306] | 491 | for ( uint32 i = 0; i < info->count; ++i )
|
---|
| 492 | {
|
---|
| 493 | const particle& pdata = info->particles[i];
|
---|
[499] | 494 | // particle_quad& rdata = quads[i];
|
---|
| 495 | particle_quad& rdata = group->quads[i + group->count];
|
---|
[306] | 496 |
|
---|
[500] | 497 | vec3 view_dir( inv_view_dir );
|
---|
| 498 | if ( accurate_facing ) view_dir = math::normalize( camera_pos - pdata.position );
|
---|
[306] | 499 |
|
---|
| 500 | switch ( orientation )
|
---|
| 501 | {
|
---|
| 502 | case particle_orientation::POINT :
|
---|
[454] | 503 | right = math::normalize( math::cross( view_dir, vec3( 0, 1, 0 ) ) );
|
---|
[500] | 504 | right = math::rotate( right, pdata.rotation, view_dir );
|
---|
[454] | 505 | rot_mat = mat3( right, math::cross( right, -view_dir ), -view_dir );
|
---|
[306] | 506 | break;
|
---|
| 507 | case particle_orientation::ORIENTED :
|
---|
[312] | 508 | pdir = normalize_safe( pdata.velocity, pdir );
|
---|
[454] | 509 | right = math::normalize( math::cross( pdir, view_dir ) );
|
---|
| 510 | rot_mat = mat3( right, pdir, math::cross( pdir, right ) );
|
---|
[306] | 511 | break;
|
---|
| 512 | case particle_orientation::ORIENTED_COMMON :
|
---|
[454] | 513 | right = math::normalize( math::cross( common_dir, view_dir ) );
|
---|
| 514 | rot_mat = mat3( right, common_dir, math::cross( common_dir, right ) );
|
---|
[306] | 515 | break;
|
---|
| 516 | case particle_orientation::PERPENDICULAR :
|
---|
[312] | 517 | pdir = normalize_safe( pdata.velocity, pdir );
|
---|
[454] | 518 | right = math::normalize( math::cross( common_up, pdir ) );
|
---|
| 519 | rot_mat = mat3( right, common_up, math::cross( common_up, right ) );
|
---|
[306] | 520 | break;
|
---|
| 521 | case particle_orientation::PERPENDICULAR_COMMON :
|
---|
[454] | 522 | right = math::normalize( math::cross( common_up, common_dir ) );
|
---|
| 523 | rot_mat = mat3( right, common_up, math::cross( common_up, right ) );
|
---|
[306] | 524 | break;
|
---|
| 525 | }
|
---|
| 526 |
|
---|
[500] | 527 | vec2 texcoords[4] =
|
---|
| 528 | {
|
---|
| 529 | pdata.tcoord_a,
|
---|
| 530 | vec2( pdata.tcoord_b.x, pdata.tcoord_a.y ),
|
---|
| 531 | vec2( pdata.tcoord_a.x, pdata.tcoord_b.y ),
|
---|
| 532 | pdata.tcoord_b
|
---|
| 533 | };
|
---|
| 534 |
|
---|
[306] | 535 | vec3 size( pdata.size.x, pdata.size.y, 0.0f );
|
---|
| 536 | vec3 s0 = rot_mat * ( ( size * sm[0] ) );
|
---|
| 537 | vec3 s1 = rot_mat * ( ( size * sm[1] ) );
|
---|
| 538 | vec3 s2 = rot_mat * ( ( size * sm[2] ) );
|
---|
| 539 | vec3 s3 = rot_mat * ( ( size * sm[3] ) );
|
---|
| 540 |
|
---|
| 541 | rdata.data[0].position = pdata.position + s0;
|
---|
| 542 | rdata.data[0].color = pdata.color;
|
---|
[499] | 543 | rdata.data[0].texcoord = texcoords[0];
|
---|
[306] | 544 |
|
---|
| 545 | rdata.data[1].position = pdata.position + s1;
|
---|
| 546 | rdata.data[1].color = pdata.color;
|
---|
[499] | 547 | rdata.data[1].texcoord = texcoords[1];
|
---|
[306] | 548 |
|
---|
| 549 | rdata.data[2].position = pdata.position + s2;
|
---|
| 550 | rdata.data[2].color = pdata.color;
|
---|
[499] | 551 | rdata.data[2].texcoord = texcoords[2];
|
---|
[306] | 552 |
|
---|
| 553 | rdata.data[3].position = pdata.position + s3;
|
---|
| 554 | rdata.data[3].color = pdata.color;
|
---|
[499] | 555 | rdata.data[3].texcoord = texcoords[3];
|
---|
[306] | 556 |
|
---|
| 557 | rdata.data[4] = rdata.data[2];
|
---|
| 558 | rdata.data[5] = rdata.data[1];
|
---|
| 559 | }
|
---|
[499] | 560 | // m_context->unmap_buffer( info->vtx_buffer );
|
---|
| 561 |
|
---|
| 562 | m_context->update( group->vtx_buffer, group->quads, group->count*sizeof(particle_quad), info->count*sizeof( particle_quad ) );
|
---|
| 563 | group->count += info->count;
|
---|
[306] | 564 | }
|
---|
| 565 |
|
---|
[500] | 566 | void nv::particle_engine::destroy_particles( particle_system_info* info, float dtime )
|
---|
[306] | 567 | {
|
---|
| 568 | if ( info->count > 0 )
|
---|
[406] | 569 | for ( sint32 i = sint32( info->count ) - 1; i >= 0; --i )
|
---|
[306] | 570 | {
|
---|
| 571 | particle& pinfo = info->particles[i];
|
---|
[500] | 572 | pinfo.lifetime += dtime;
|
---|
| 573 | if ( pinfo.lifetime >= pinfo.death )
|
---|
[306] | 574 | {
|
---|
| 575 | info->count--;
|
---|
[374] | 576 | swap( info->particles[i], info->particles[info->count] );
|
---|
[306] | 577 | }
|
---|
| 578 | }
|
---|
| 579 | }
|
---|
| 580 |
|
---|
[515] | 581 | void nv::particle_engine::create_particles( particle_system_info* info, transform model, float dtime )
|
---|
[306] | 582 | {
|
---|
[518] | 583 | uint32 ecount = info->data->emitter_count;
|
---|
[306] | 584 | if ( ecount == 0 ) return;
|
---|
| 585 |
|
---|
| 586 | random& r = random::get();
|
---|
[515] | 587 | bool local = model.is_identity();
|
---|
[500] | 588 | // if ( !local )
|
---|
| 589 | // {
|
---|
| 590 | // source = vec3( m_model_matrix[3] );
|
---|
| 591 | // orient = mat3( m_model_matrix );
|
---|
| 592 | // }
|
---|
[312] | 593 |
|
---|
[306] | 594 | for ( uint32 i = 0; i < ecount; ++i )
|
---|
| 595 | {
|
---|
[518] | 596 | const auto& edata = info->data->emitters[i];
|
---|
| 597 | auto& einfo = info->emitters[i];
|
---|
[307] | 598 | if ( einfo.active )
|
---|
[306] | 599 | {
|
---|
[500] | 600 | einfo.next -= dtime;
|
---|
| 601 | float fperiod = 1.0f / edata.rate;
|
---|
| 602 | while ( einfo.next < 0.0f )
|
---|
[306] | 603 | {
|
---|
[307] | 604 | if ( info->count < info->data->quota-1 )
|
---|
| 605 | {
|
---|
| 606 | particle& pinfo = info->particles[info->count];
|
---|
[518] | 607 | edata.emitter_func( &(info->data->emitters[i]), &pinfo, 1 );
|
---|
[500] | 608 | pinfo.position = vec3();
|
---|
| 609 | pinfo.position+= edata.position;
|
---|
[518] | 610 | // if ( !local )
|
---|
[515] | 611 | pinfo.position = pinfo.position * model;
|
---|
| 612 | pinfo.color = edata.color_min == edata.color_max ?
|
---|
[307] | 613 | edata.color_min : r.range( edata.color_min, edata.color_max );
|
---|
[500] | 614 | pinfo.size = edata.size_min == edata.size_max ?
|
---|
[307] | 615 | edata.size_min : r.range( edata.size_min, edata.size_max );
|
---|
| 616 | if ( edata.square ) pinfo.size.y = pinfo.size.x;
|
---|
[500] | 617 | float velocity = edata.velocity_min == edata.velocity_max ?
|
---|
[307] | 618 | edata.velocity_min : r.frange( edata.velocity_min, edata.velocity_max );
|
---|
[500] | 619 | pinfo.lifetime = dtime + einfo.next;
|
---|
| 620 | pinfo.death = ( edata.lifetime_min == edata.lifetime_max ?
|
---|
| 621 | edata.lifetime_min : r.frange( edata.lifetime_min, edata.lifetime_max ) );
|
---|
| 622 | pinfo.rotation = r.frand( 2* math::pi<float>() );
|
---|
| 623 | pinfo.tcoord_a = info->texcoords[0];
|
---|
| 624 | pinfo.tcoord_b = info->texcoords[1];
|
---|
[306] | 625 |
|
---|
[312] | 626 | pinfo.velocity = edata.dir;
|
---|
[307] | 627 | if ( edata.angle > 0.0f )
|
---|
| 628 | {
|
---|
[453] | 629 | float emission_angle = math::radians( edata.angle );
|
---|
[471] | 630 | float cos_theta = r.frange( cos( emission_angle ), 1.0f );
|
---|
| 631 | float sin_theta = sqrt(1.0f - cos_theta * cos_theta );
|
---|
[451] | 632 | float phi = r.frange( 0.0f, 2* math::pi<float>() );
|
---|
[515] | 633 | pinfo.velocity = model.get_orientation() *
|
---|
[471] | 634 | ( edata.odir * ( cos(phi) * sin_theta ) +
|
---|
| 635 | edata.cdir * ( sin(phi)*sin_theta ) +
|
---|
[307] | 636 | edata.dir * cos_theta );
|
---|
| 637 | }
|
---|
| 638 |
|
---|
[312] | 639 | pinfo.velocity *= velocity;
|
---|
| 640 |
|
---|
[307] | 641 | info->count++;
|
---|
[306] | 642 | }
|
---|
[500] | 643 | einfo.next += fperiod;
|
---|
[306] | 644 | }
|
---|
[500] | 645 |
|
---|
[306] | 646 | }
|
---|
| 647 | }
|
---|
| 648 | }
|
---|
| 649 |
|
---|
[500] | 650 | void nv::particle_engine::update_particles( particle_system_info* info, float dtime )
|
---|
[306] | 651 | {
|
---|
[500] | 652 | if ( dtime <= 0.0f ) return;
|
---|
[312] | 653 |
|
---|
| 654 | uint32 acount = info->data->affector_count;
|
---|
| 655 | for ( uint32 i = 0; i < acount; ++i )
|
---|
| 656 | {
|
---|
| 657 | const particle_affector_data* padata = &(info->data->affectors[i]);
|
---|
[500] | 658 | padata->process( padata, info->particles, dtime, info->count );
|
---|
[312] | 659 | }
|
---|
| 660 |
|
---|
| 661 |
|
---|
| 662 | for ( uint32 i = 0; i < info->count; ++i )
|
---|
| 663 | {
|
---|
| 664 | particle& pdata = info->particles[i];
|
---|
[500] | 665 | float factor = min( dtime, pdata.lifetime );
|
---|
[312] | 666 | pdata.position += pdata.velocity * factor;
|
---|
| 667 | }
|
---|
[307] | 668 | }
|
---|
| 669 |
|
---|
[518] | 670 | void nv::particle_engine::update_emitters( particle_system_info* info, float dtime )
|
---|
[307] | 671 | {
|
---|
[518] | 672 | uint32 ecount = info->data->emitter_count;
|
---|
[307] | 673 | if ( ecount == 0 ) return;
|
---|
| 674 | random& r = random::get();
|
---|
| 675 |
|
---|
| 676 | for ( uint32 i = 0; i < ecount; ++i )
|
---|
| 677 | {
|
---|
[518] | 678 | const auto& edata = info->data->emitters[i];
|
---|
| 679 | auto& einfo = info->emitters[i];
|
---|
[307] | 680 |
|
---|
[500] | 681 | if ( einfo.pause > 0.0f )
|
---|
[307] | 682 | {
|
---|
[500] | 683 | einfo.pause -= dtime;
|
---|
| 684 | if ( einfo.pause == 0.0f ) einfo.pause = -0.001f;
|
---|
| 685 | }
|
---|
| 686 |
|
---|
| 687 | if ( einfo.pause < 0.0f )
|
---|
| 688 | {
|
---|
[307] | 689 | if ( einfo.active )
|
---|
| 690 | {
|
---|
| 691 | einfo.active = false;
|
---|
[500] | 692 | if ( edata.repeat_min > 0.0f )
|
---|
| 693 | einfo.pause += r.frange( edata.repeat_min, edata.repeat_max );
|
---|
[307] | 694 | else
|
---|
[500] | 695 | einfo.pause = 0.0f;
|
---|
[307] | 696 | }
|
---|
| 697 | else
|
---|
| 698 | {
|
---|
| 699 | einfo.active = true;
|
---|
[500] | 700 | einfo.pause += r.frange( edata.duration_min, edata.duration_max );
|
---|
[307] | 701 | }
|
---|
| 702 | }
|
---|
| 703 | }
|
---|
| 704 |
|
---|
| 705 | }
|
---|
[312] | 706 |
|
---|
[518] | 707 | void nv::particle_engine::register_emitter_type( const string_view& name, particle_emitter_func func )
|
---|
[312] | 708 | {
|
---|
[518] | 709 | if ( m_debug_emitter_names )
|
---|
| 710 | ( *m_debug_emitter_names )[func] = name;
|
---|
[519] | 711 | if ( m_debug_emitter_list )
|
---|
| 712 | ( *m_debug_emitter_list ).push_back( func );
|
---|
| 713 |
|
---|
[518] | 714 | m_emitters[ name ] = func;
|
---|
[312] | 715 | }
|
---|
| 716 |
|
---|
[518] | 717 | void nv::particle_engine::register_standard_emitters()
|
---|
[312] | 718 | {
|
---|
[518] | 719 | register_emitter_type( "point", nv_particle_emitter_point );
|
---|
| 720 | register_emitter_type( "box", nv_particle_emitter_box );
|
---|
| 721 | register_emitter_type( "cylinder", nv_particle_emitter_cylinder );
|
---|
| 722 | register_emitter_type( "sphere", nv_particle_emitter_sphere );
|
---|
| 723 | register_emitter_type( "cylindroid", nv_particle_emitter_cylindroid );
|
---|
| 724 | register_emitter_type( "ellipsoid", nv_particle_emitter_ellipsoid );
|
---|
| 725 | register_emitter_type( "hollow_cylinder", nv_particle_emitter_hollow_cylinder );
|
---|
| 726 | register_emitter_type( "hollow_sphere", nv_particle_emitter_hollow_sphere );
|
---|
| 727 | register_emitter_type( "hollow_cylindroid", nv_particle_emitter_hollow_cylindroid );
|
---|
| 728 | register_emitter_type( "hollow_ellipsoid", nv_particle_emitter_hollow_ellipsoid );
|
---|
[312] | 729 | }
|
---|
| 730 |
|
---|
[439] | 731 | void nv::particle_engine::register_affector_type( const string_view& name, particle_affector_init_func init, particle_affector_func process )
|
---|
[312] | 732 | {
|
---|
[518] | 733 | if ( m_debug_affector_names )
|
---|
| 734 | ( *m_debug_affector_names )[process] = name;
|
---|
[519] | 735 | if ( m_debug_affector_list )
|
---|
| 736 | ( *m_debug_affector_list ).push_back( process );
|
---|
[518] | 737 |
|
---|
[312] | 738 | m_affectors[ name ].init = init;
|
---|
| 739 | m_affectors[ name ].process = process;
|
---|
| 740 | }
|
---|
| 741 |
|
---|
[518] | 742 | nv::particle_emitter_func nv::particle_engine::get_emitter( shash64 emitter )
|
---|
| 743 | {
|
---|
| 744 | auto emitter_iter = m_emitters.find( emitter );
|
---|
| 745 | if ( emitter_iter != m_emitters.end() )
|
---|
| 746 | {
|
---|
| 747 | return emitter_iter->second;
|
---|
| 748 | }
|
---|
| 749 | return nullptr;
|
---|
| 750 | }
|
---|
| 751 |
|
---|
| 752 | nv::particle_affector_funcs nv::particle_engine::get_affector( shash64 affector )
|
---|
| 753 | {
|
---|
| 754 | auto affector_iter = m_affectors.find( affector );
|
---|
| 755 | if ( affector_iter != m_affectors.end() )
|
---|
| 756 | {
|
---|
| 757 | return affector_iter->second;
|
---|
| 758 | }
|
---|
| 759 | return { nullptr, nullptr };
|
---|
| 760 | }
|
---|
| 761 |
|
---|
| 762 | nv::string_view nv::particle_engine::get_debug_name( particle_emitter_func f )
|
---|
| 763 | {
|
---|
| 764 | auto i = m_debug_emitter_names->find( f );
|
---|
| 765 | if ( i != m_debug_emitter_names->end() )
|
---|
| 766 | return i->second;
|
---|
| 767 | return {};
|
---|
| 768 | }
|
---|
| 769 |
|
---|
| 770 | nv::string_view nv::particle_engine::get_debug_name( particle_affector_func f )
|
---|
| 771 | {
|
---|
| 772 | auto i = m_debug_affector_names->find( f );
|
---|
| 773 | if ( i != m_debug_affector_names->end() )
|
---|
| 774 | return i->second;
|
---|
| 775 | return {};
|
---|
| 776 | }
|
---|
| 777 |
|
---|
[500] | 778 | nv::particle_render_data nv::particle_engine::get_render_data( particle_system_group group )
|
---|
| 779 | {
|
---|
| 780 | const particle_system_group_info* info = m_groups.get( group );
|
---|
| 781 | if ( info )
|
---|
| 782 | {
|
---|
| 783 | return{ info->count, info->vtx_array };
|
---|
| 784 | }
|
---|
| 785 | return { 0, nv::vertex_array() };
|
---|
| 786 | }
|
---|
| 787 |
|
---|
[312] | 788 | void nv::particle_engine::register_standard_affectors()
|
---|
| 789 | {
|
---|
| 790 | register_affector_type( "linear_force", nv_particle_affector_linear_force_init, nv_particle_affector_linear_force );
|
---|
| 791 | register_affector_type( "deflector_plane", nv_particle_affector_deflector_plane_init, nv_particle_affector_deflector_plane );
|
---|
| 792 | register_affector_type( "color_fader", nv_particle_affector_color_fader_init, nv_particle_affector_color_fader );
|
---|
| 793 | register_affector_type( "scaler", nv_particle_affector_scaler_init, nv_particle_affector_scaler );
|
---|
| 794 | }
|
---|
| 795 |
|
---|
[518] | 796 | void nv::particle_engine::register_types( type_database* db )
|
---|
| 797 | {
|
---|
[519] | 798 | db->create_type<particle_orientation>()
|
---|
[518] | 799 | .value( "PS_POINT", sint32( particle_orientation::POINT ), "Point" )
|
---|
| 800 | .value( "PS_ORIENTED", sint32( particle_orientation::ORIENTED ), "Oriented" )
|
---|
| 801 | .value( "PS_ORIENTED_COMMON", sint32( particle_orientation::ORIENTED_COMMON ), "Oriented Common" )
|
---|
| 802 | .value( "PS_PERPENDICULAR", sint32( particle_orientation::PERPENDICULAR ), "Perpendicular" )
|
---|
| 803 | .value( "PS_PERPENDICULAR_COMMON", sint32( particle_orientation::PERPENDICULAR_COMMON ), "Perpendicular Common" )
|
---|
| 804 | ;
|
---|
| 805 |
|
---|
[519] | 806 | db->create_type<particle_origin>()
|
---|
[518] | 807 | .value( "PS_CENTER", sint32( particle_origin::CENTER ), "Center" )
|
---|
| 808 | .value( "PS_TOP_LEFT", sint32( particle_origin::TOP_LEFT ), "Top left" )
|
---|
| 809 | .value( "PS_TOP_CENTER", sint32( particle_origin::TOP_CENTER ), "Top center" )
|
---|
| 810 | .value( "PS_TOP_RIGHT", sint32( particle_origin::TOP_RIGHT ), "Top right" )
|
---|
| 811 | .value( "PS_CENTER_LEFT", sint32( particle_origin::CENTER_LEFT ), "Center left" )
|
---|
| 812 | .value( "PS_CENTER_RIGHT", sint32( particle_origin::CENTER_RIGHT ), "Center right" )
|
---|
| 813 | .value( "PS_BOTTOM_LEFT", sint32( particle_origin::BOTTOM_LEFT ), "Bottom left" )
|
---|
| 814 | .value( "PS_BOTTOM_CENTER", sint32( particle_origin::BOTTOM_CENTER ), "Bottom center" )
|
---|
| 815 | .value( "PS_BOTTOM_RIGHT", sint32( particle_origin::BOTTOM_RIGHT ), "Bottom right" )
|
---|
| 816 | ;
|
---|
| 817 |
|
---|
| 818 | if ( m_debug_affector_types )
|
---|
| 819 | {
|
---|
| 820 | int you_could_get_rid_of_the_init_function_using_these; int error;
|
---|
[519] | 821 | int universal_vm_based_affector;
|
---|
| 822 | // compile_affector( ... ) in lua, returns array of bytecode
|
---|
| 823 | // function is a normal bytecode runner!
|
---|
[518] | 824 |
|
---|
[519] | 825 |
|
---|
[518] | 826 | (*m_debug_affector_types)[ nv_particle_affector_linear_force ]
|
---|
| 827 | = db->create_type<nvpe_linear_force_data>( "linear force" )
|
---|
| 828 | .field( "force_vector", &nvpe_linear_force_data::force_vector )
|
---|
| 829 | .field( "average", &nvpe_linear_force_data::average )
|
---|
| 830 | .get();
|
---|
| 831 |
|
---|
| 832 | ( *m_debug_affector_types )[nv_particle_affector_deflector_plane]
|
---|
| 833 | = db->create_type<nvpe_deflector_plane_data>( "deflector plane" )
|
---|
| 834 | .field( "plane_point", &nvpe_deflector_plane_data::plane_point )
|
---|
| 835 | .field( "plane_normal", &nvpe_deflector_plane_data::plane_normal )
|
---|
| 836 | .field( "bounce", &nvpe_deflector_plane_data::bounce )
|
---|
| 837 | .field( "distance", &nvpe_deflector_plane_data::distance )
|
---|
| 838 | .get();
|
---|
| 839 |
|
---|
| 840 | ( *m_debug_affector_types )[nv_particle_affector_color_fader]
|
---|
| 841 | = db->create_type<nvpe_linear_force_data>( "color fader" )
|
---|
| 842 | .field( "adjustment", & nvpe_color_fader_data::adjustment )
|
---|
| 843 | .get();
|
---|
| 844 |
|
---|
| 845 | ( *m_debug_affector_types )[nv_particle_affector_scaler]
|
---|
| 846 | = db->create_type<nvpe_scaler_data>( "scaler" )
|
---|
| 847 | .field( "adjustment", & nvpe_scaler_data::adjustment )
|
---|
| 848 | .get();
|
---|
| 849 | }
|
---|
| 850 | }
|
---|