Class: MSPhysics::Simulation
- Defined in:
- RubyExtension/MSPhysics/simulation.rb
Overview
Constant Summary
- @@instance =
nil
Instance Attribute Summary collapse
-
#fps ⇒ Fixnum
readonly
Get simulation update rate in frames per second.
-
#frame ⇒ Fixnum
readonly
Get simulation frame.
-
#world ⇒ World
readonly
Get simulation world.
Simulation Control Functions collapse
-
#mode ⇒ Fixnum
Get simulation mode.
-
#mode=(value) ⇒ Object
Set simulation mode.
-
#pause ⇒ Boolean
Pause simulation.
-
#paused? ⇒ Boolean
Determine if simulation is paused.
-
#play ⇒ Boolean
Play simulation.
-
#playing? ⇒ Boolean
Determine if simulation is playing.
-
#started_from_selection? ⇒ Boolean
Determine whether simulation started from selection.
-
#toggle_play ⇒ Boolean
Play/pause simulation.
-
#update_rate ⇒ Fixnum
Get simulation update rate, the number of times to update newton world per frame.
-
#update_rate=(rate) ⇒ Object
Set simulation update rate, the number of times to update newton world per frame.
-
#update_timestep ⇒ Numeric
Get simulation update timestep in seconds.
-
#update_timestep=(timestep) ⇒ Object
Set simulation update time step in seconds.
-
#update_timestep_inv ⇒ Numeric
Get the inverse of simulation update timestep.
Cursor Functions collapse
-
#cursor ⇒ Fixnum
Get active cursor.
-
#cursor=(id) ⇒ Fixnum
Set active cursor.
-
#cursor_visible=(state) ⇒ Object
Show/hide mouse cursor.
-
#cursor_visible? ⇒ Boolean
Determine whether cursor is visible.
-
#get_cursor_pos ⇒ Array<Fixnum>
Get cursor position in view coordinates.
-
#set_cursor_pos(x, y) ⇒ Object
Set cursor position in view coordinates.
Mode and Debug Draw Functions collapse
-
#aabb_visible=(state) ⇒ Object
Enable/disable the drawing of world axes aligned bounding box for all bodies.
-
#aabb_visible? ⇒ Boolean
Determine whether the drawing of world axes aligned bounding box, for all bodies, is enabled.
-
#animate_scenes(state) ⇒ Boolean
Stimulate automatic scene transitioning.
-
#axes_visible=(state) ⇒ Object
Enable/disable the drawing of centre of mass axes for all bodies.
-
#axes_visible? ⇒ Boolean
Determine whether the drawing of centre of mass axes, for all bodies, is enabled.
-
#bodies_visible=(state) ⇒ Object
Show/hide all groups/components associated with the bodies.
-
#bodies_visible? ⇒ Boolean
Determine whether all groups/components associated with the bodies are intended to be visible.
-
#collision_wireframe_visible=(state) ⇒ Object
Enable/disable the drawing of collision wireframe for all bodies.
-
#collision_wireframe_visible? ⇒ Boolean
Determine whether the drawing of collision wireframe, for all bodies, is enabled.
-
#contact_forces_visible=(state) ⇒ Object
Enable/disable the drawing of collision contact forces.
-
#contact_forces_visible? ⇒ Boolean
Determine whether the drawing of collision contact forces is enabled.
-
#contact_points_visible=(state) ⇒ Object
Enable/disable the drawing of collision contact points.
-
#contact_points_visible? ⇒ Boolean
Determine whether the drawing of collision contact points is enabled.
-
#continuous_collision_check_enabled=(state) ⇒ Object
Enable/disable the continuous collision check for all bodies.
-
#continuous_collision_check_enabled? ⇒ Boolean
Determine whether the continuous collision check, for all bodies, is intended to be enabled.
-
#scenes_animating? ⇒ Boolean
Determine whether the scenes animation is active.
-
#scenes_transitioning? ⇒ Boolean
Determine whether the scene transitioning is active.
-
#view_full_screen(state, include_floating_windows = true) ⇒ Boolean
Set view full screen.
Body/Group Functions collapse
-
#add_group(group) ⇒ Body
Add a group/component to simulation.
-
#destroy_all_emitted_bodies ⇒ Fixnum
Destroy all emitted bodies and the entities associated with them.
-
#emit_body(*args) ⇒ Body
A new, emitted body.
-
#erase_on_end(entity) ⇒ void
Erase group/component when simulation resets.
-
#find_bodies_by_name(name) ⇒ Array<Body>
Reference all bodies by group name.
-
#find_body_by_group(group) ⇒ Body?
Reference body by group/component.
-
#find_body_by_name(name) ⇒ Body?
Reference body by group name.
-
#find_group_by_name(name, entities = nil) ⇒ Sketchup::Group, ...
Reference group by name.
-
#find_groups_by_name(name, entities = nil) ⇒ Array<Sketchup::Group, Sketchup::ComponentInstance>
Reference all groups by name.
-
#find_joint_by_group(group) ⇒ Joint?
Reference joint associated with a group.
-
#find_joint_by_name(name) ⇒ Joint?
Reference joint by name.
-
#find_joints_by_group(group) ⇒ Array<Joint>
Reference all joints associated with a group.
-
#find_joints_by_name(name) ⇒ Array<Joint>
Reference all joints by name.
-
#remove_group(group) ⇒ Boolean
Remove a group/component from simulation.
Text Control Functions collapse
-
#clear_display_note ⇒ void
Clear display-note text.
-
#clear_fancy_note ⇒ void
Clear fancy note.
-
#clear_log_line ⇒ void
Clear log-line text.
-
#display_note(text, color = MSPhysics::WATERMARK_COLOR) ⇒ String
Display text on screen.
-
#fancy_note(text, opts = {}) ⇒ void
Display a fancy text on screen.
-
#log_line(text, color = MSPhysics::WATERMARK_COLOR) ⇒ String
Display text on screen in logged form.
-
#log_line_limit ⇒ Fixnum
Get log-line text limit.
-
#log_line_limit=(limit) ⇒ Object
Set log-line text limit.
Viewport Drawing Functions collapse
-
#draw2d(type, points, color = 'black', width = 1, stipple = '') ⇒ void
Draw 2D geometry into view.
-
#draw3d(type, points, color = 'black', width = 1, stipple = '') ⇒ void
Draw 3D geometry into view.
-
#draw_points(points, size = 1, style = 0, color = 'black', width = 1, stipple = '') ⇒ void
Draw 3D points with custom style.
Music, Sound, and MIDI Functions collapse
-
#play_midi_note(instrument, note = 63, channel = 0, volume = 127) ⇒ Fixnum?
Play MIDI note.
-
#play_music(name, repeat = 0) ⇒ Boolean
Play embedded music by name.
-
#play_music2(path, repeat = 0) ⇒ Boolean
Play music from path.
-
#play_sound(name, channel = -1,, repeat = 0) ⇒ Fixnum?
Play embedded sound by name.
-
#play_sound2(path, channel = -1,, repeat = 0) ⇒ Fixnum?
Play sound from path.
-
#position_midi_note(id, pos, max_hearing_range = 100) ⇒ Boolean
Set MIDI note position in 3D space.
-
#position_sound(channel, pos, max_hearing_range = 100) ⇒ Boolean
Set sound 3D position.
-
#stop_midi_note(id) ⇒ Boolean
Stop MIDI note.
-
#stop_music ⇒ nil
Stop the currently playing music.
-
#stop_sound(channel) ⇒ Boolean
Stop the currently playing sound at channel.
Particle Effects collapse
-
#clear_particles ⇒ Object
Remove all particles.
-
#create_particle(opts) ⇒ void
Create a new particle.
-
#particles_count ⇒ Fixnum
Get number of particles.
-
#particles_visible=(state) ⇒ Object
Show/hide particles.
-
#particles_visible? ⇒ Boolean
Determine whether particles are visible.
Advanced collapse
-
#erase_instances_on_end=(state) ⇒ Object
Enable/disable the deletion of emitted/copied/split bodies and particles when simulation ends.
-
#erase_instances_on_end? ⇒ Boolean
Determine whether the deletion of emitted/copied/split bodies and particles when simulation ends is enabled.
-
#reset_camera_on_end=(state) ⇒ Object
Enable/disable the reseting of camera when simulation ends.
-
#reset_camera_on_end? ⇒ Boolean
Determine whether the reseting of camera when simulation ends is enabled.
-
#reset_positions_on_end=(state) ⇒ Object
Enable/disable the reseting of group/component transformations when simulation ends.
-
#reset_positions_on_end? ⇒ Boolean
Determine whether the reseting of group/component transformations when simulation ends is enabled.
-
#undo_on_reset=(state) ⇒ Object
Enable/disable the undo commend that is ought to be triggered after the simulation resets.
-
#undo_on_reset? ⇒ Boolean
Determine whether the undo command is ought to be triggered after the simulation resets.
Class Method Summary collapse
-
.active? ⇒ Boolean
Determine if simulation is running.
-
.external_control(from_selection = false) ⇒ Simulation?
Create a Simulation instance for external frame-by-frame.
-
.instance ⇒ Simulation?
Get Simulation instance.
-
.reset ⇒ Boolean
End simulation.
-
.start(from_selection = false) ⇒ Boolean
Start simulation.
Instance Method Summary collapse
-
#initialize(from_selection = false) ⇒ Simulation
constructor
A new instance of Simulation.
Methods inherited from Entity
Constructor Details
#initialize(from_selection = false) ⇒ Simulation
Returns a new instance of Simulation
Instance Attribute Details
#fps ⇒ Fixnum (readonly)
Get simulation update rate in frames per second.
#frame ⇒ Fixnum (readonly)
Get simulation frame.
#world ⇒ World (readonly)
Get simulation world.
Class Method Details
.active? ⇒ Boolean
Determine if simulation is running.
.external_control(from_selection = false) ⇒ Simulation?
Create a Simulation instance for external frame-by-frame.
.instance ⇒ Simulation?
Get MSPhysics::Simulation instance.
.reset ⇒ Boolean
End simulation.
.start(from_selection = false) ⇒ Boolean
Start simulation.
Instance Method Details
#aabb_visible=(state) ⇒ Object
Enable/disable the drawing of world axes aligned bounding box for all bodies.
#aabb_visible? ⇒ Boolean
Determine whether the drawing of world axes aligned bounding box, for all bodies, is enabled.
#add_group(group) ⇒ Body
Add a group/component to simulation.
#animate_scenes(state) ⇒ Boolean
Other settings like, delay and reverse mode, are acquired from the settings.
Stimulate automatic scene transitioning.
#axes_visible=(state) ⇒ Object
Enable/disable the drawing of centre of mass axes for all bodies.
#axes_visible? ⇒ Boolean
Determine whether the drawing of centre of mass axes, for all bodies, is enabled.
#bodies_visible=(state) ⇒ Object
Show/hide all groups/components associated with the bodies.
#bodies_visible? ⇒ Boolean
Determine whether all groups/components associated with the bodies are intended to be visible.
#clear_display_note ⇒ void
This method returns an undefined value.
Clear display-note text.
#clear_fancy_note ⇒ void
This method returns an undefined value.
Clear fancy note.
#clear_log_line ⇒ void
This method returns an undefined value.
Clear log-line text.
#clear_particles ⇒ Object
Remove all particles.
#collision_wireframe_visible=(state) ⇒ Object
Enable/disable the drawing of collision wireframe for all bodies.
#collision_wireframe_visible? ⇒ Boolean
Determine whether the drawing of collision wireframe, for all bodies, is enabled.
#contact_forces_visible=(state) ⇒ Object
Enable/disable the drawing of collision contact forces.
#contact_forces_visible? ⇒ Boolean
Determine whether the drawing of collision contact forces is enabled.
#contact_points_visible=(state) ⇒ Object
Enable/disable the drawing of collision contact points.
#contact_points_visible? ⇒ Boolean
Determine whether the drawing of collision contact points is enabled.
#continuous_collision_check_enabled=(state) ⇒ Object
Enable/disable the continuous collision check for all bodies. Continuous collision check prevents bodies from passing each other at high speeds.
#continuous_collision_check_enabled? ⇒ Boolean
Determine whether the continuous collision check, for all bodies, is intended to be enabled. Continuous collision check prevents bodies from passing each other at high speeds.
#create_particle(opts) ⇒ void
This method returns an undefined value.
Create a new particle.
#cursor ⇒ Fixnum
Get active cursor.
#cursor=(id) ⇒ Fixnum
Set active cursor.
#cursor_visible=(state) ⇒ Object
Windows only!
Show/hide mouse cursor.
#cursor_visible? ⇒ Boolean
Windows only!
Determine whether cursor is visible.
#destroy_all_emitted_bodies ⇒ Fixnum
Destroy all emitted bodies and the entities associated with them.
#display_note(text, color = MSPhysics::WATERMARK_COLOR) ⇒ String
Display text on screen.
#draw2d(type, points, color = 'black', width = 1, stipple = '') ⇒ void
This method returns an undefined value.
Draw 2D geometry into view.
#draw3d(type, points, color = 'black', width = 1, stipple = '') ⇒ void
This method returns an undefined value.
Draw 3D geometry into view.
#draw_points(points, size = 1, style = 0, color = 'black', width = 1, stipple = '') ⇒ void
This method returns an undefined value.
Draw 3D points with custom style.
#emit_body(body, force, lifetime) ⇒ Body #emit_body(body, transformation, force, lifetime) ⇒ Body
Returns A new, emitted body.
#erase_instances_on_end=(state) ⇒ Object
Enable/disable the deletion of emitted/copied/split bodies and particles when simulation ends.
#erase_instances_on_end? ⇒ Boolean
Determine whether the deletion of emitted/copied/split bodies and particles when simulation ends is enabled.
#erase_on_end(entity) ⇒ void
This method returns an undefined value.
Erase group/component when simulation resets. This method is commonly used
for copied bodies. Body.#copy method doesn't register
created entity to the “erase” queue. When simulation resets created
entities remain un-deleted. To erase these entities, one could simply use
this method.
#fancy_note(text, opts = {}) ⇒ void
This method returns an undefined value.
Display a fancy text on screen.
#find_bodies_by_name(name) ⇒ Array<Body>
Reference all bodies by group name.
#find_body_by_group(group) ⇒ Body?
Reference body by group/component.
#find_body_by_name(name) ⇒ Body?
Reference body by group name.
#find_group_by_name(name, entities = nil) ⇒ Sketchup::Group, ...
Reference group by name.
#find_groups_by_name(name, entities = nil) ⇒ Array<Sketchup::Group, Sketchup::ComponentInstance>
Reference all groups by name.
#find_joint_by_group(group) ⇒ Joint?
Reference joint associated with a group.
#find_joint_by_name(name) ⇒ Joint?
Reference joint by name.
#find_joints_by_group(group) ⇒ Array<Joint>
Reference all joints associated with a group.
#find_joints_by_name(name) ⇒ Array<Joint>
Reference all joints by name.
#get_cursor_pos ⇒ Array<Fixnum>
Get cursor position in view coordinates.
#log_line(text, color = MSPhysics::WATERMARK_COLOR) ⇒ String
Display text on screen in logged form.
#log_line_limit ⇒ Fixnum
Get log-line text limit.
#log_line_limit=(limit) ⇒ Object
Set log-line text limit.
#mode ⇒ Fixnum
Get simulation mode.
-
0 - Interactive mode: The pick and drag tool and orbiting camera via the middle mouse button is enabled.
-
1 - Game mode: The pick and drag tool and orbiting camera via the middle mouse button is disabled.
#mode=(value) ⇒ Object
Set simulation mode.
-
0 - Interactive mode: The pick and drag tool and orbiting camera via the middle mouse button is enabled.
-
1 - Game mode: The pick and drag tool and orbiting camera via the middle mouse button is disabled.
#particles_count ⇒ Fixnum
Get number of particles.
#particles_visible=(state) ⇒ Object
Show/hide particles.
#particles_visible? ⇒ Boolean
Determine whether particles are visible.
#pause ⇒ Boolean
Pause simulation.
#paused? ⇒ Boolean
Determine if simulation is paused.
#play ⇒ Boolean
Play simulation.
#play_midi_note(instrument, note = 63, channel = 0, volume = 127) ⇒ Fixnum?
Setting channel to 9 will play midi notes from the “General MIDI Percussion Key Map.” Any other channel will play midi notes from the “General MIDI Instrument Patch Map”. If channel is set to 9, the instrument parameter will have no effect and the note parameter will be used to play particular percussion sound, if note's value is between 27 and 87. According to my experiments, values outside that 27-87 range won't yield any sounds.
Some instruments have notes that never seem to end. For this reason it might come in handy to use #stop_midi_note function when needed.
Play MIDI note.
#play_music(name, repeat = 0) ⇒ Boolean
Play embedded music by name. This can load WAVE, AIFF, RIFF, OGG, FLAC, MOD, IT, XM, and S3M formats.
#play_music2(path, repeat = 0) ⇒ Boolean
Play music from path. This can load WAVE, AIFF, RIFF, OGG, FLAC, MOD, IT, XM, and S3M formats.
#play_sound(name, channel = -1,, repeat = 0) ⇒ Fixnum?
If this function succeeds, it returns a channel the sound was registered to play on. The returned channel can be adjusted to desired volume and panning.
On Windows, this can load WAVE, AIFF, RIFF, OGG, and VOC formats. Mac OS X is limited to WAVE sounds.
Play embedded sound by name.
#play_sound2(path, channel = -1,, repeat = 0) ⇒ Fixnum?
If this function succeeds, it returns a channel the sound was registered to play on. The returned channel can be adjusted to desired volume and panning.
On Windows, this can load WAVE, AIFF, RIFF, OGG, VOC, and FLAC formats. Mac OS X is limited to WAVE sounds.
Play sound from path.
#playing? ⇒ Boolean
Determine if simulation is playing.
#position_midi_note(id, pos, max_hearing_range = 100) ⇒ Boolean
Sound volume and panning is not adjusted automatically with respect to camera orientation. It is required to manually call this function every frame until the note is stopped or has finished playing. Sometimes it's just enough to call this function once after playing the note. Other times, when the note is endless or pretty long, it might be useful to update position of the note every frame until the note ends or is stopped. Meantime, there is no function to determine when the note ends. It is up to the user to decide for how long to call this function or when to stop calling this function.
When it comes to setting 3D positions of multiple sounds, make sure to play
each sound on separate channel. That is, play sound 1 on channel 0, sound 2
on channel 1, sound 3 on channel 2, and etcetera until channel gets to 15,
as there are only 15 channels available. Read the note below to find out
why each sound is supposed to be played on separate channel. I think it
would make more sense if the function was renamed to
set_midi_channel_position and had the 'id' parameter
replaced with 'channel'.
This function works by adjusting panning and volume of the note's and instrument's channel, based on camera's angle and distance to the origin of the sound. Now, there is only one function that adjusts stereo and panning, but it adjusts panning and volume of all notes and instruments that are played on same channel. As of my research, I haven't found a way to adjust panning and volume of channel that belongs to particular note and instrument. There's only a function that can adjust panning and volume of channel that belongs to all notes and instruments that are played on particular channel. For instance, if you play instrument 1 and instrument 2 both on channel zero, they will still play simultaneously, without cancelling out each other, as if they are playing on separate channels, but when it comes to adjusting panning and volume of one of them, the properties of both sounds will be adjusted. This means that this function is only limited to playing 16 3D sounds, with each sound played on different channel. Otherwise, sounds played on same channel at different locations, will endup being tuned as if they are playing from the same location.
Set MIDI note position in 3D space.
#position_sound(channel, pos, max_hearing_range = 100) ⇒ Boolean
Sound volume and panning is adjusted automatically with respect to camera orientation. You don't need to call this function every frame if sound remains in constant position. You do, however, need to call this function if sound position changes.
Set sound 3D position.
#remove_group(group) ⇒ Boolean
Remove a group/component from simulation.
#reset_camera_on_end=(state) ⇒ Object
Enable/disable the reseting of camera when simulation ends.
#reset_camera_on_end? ⇒ Boolean
Determine whether the reseting of camera when simulation ends is enabled.
#reset_positions_on_end=(state) ⇒ Object
Enable/disable the reseting of group/component transformations when simulation ends.
#reset_positions_on_end? ⇒ Boolean
Determine whether the reseting of group/component transformations when simulation ends is enabled.
#scenes_animating? ⇒ Boolean
Determine whether the scenes animation is active.
#scenes_transitioning? ⇒ Boolean
Determine whether the scene transitioning is active.
#set_cursor_pos(x, y) ⇒ Object
Windows only!
Set cursor position in view coordinates.
#started_from_selection? ⇒ Boolean
Determine whether simulation started from selection.
#stop_midi_note(id) ⇒ Boolean
Stop MIDI note.
#stop_music ⇒ nil
Stop the currently playing music.
#stop_sound(channel) ⇒ Boolean
Stop the currently playing sound at channel.
#toggle_play ⇒ Boolean
Play/pause simulation.
#undo_on_reset=(state) ⇒ Object
Enable/disable the undo commend that is ought to be triggered after the simulation resets.
#undo_on_reset? ⇒ Boolean
Determine whether the undo command is ought to be triggered after the simulation resets.
#update_rate ⇒ Fixnum
Get simulation update rate, the number of times to update newton world per frame.
#update_rate=(rate) ⇒ Object
Set simulation update rate, the number of times to update newton world per frame.
#update_timestep ⇒ Numeric
Get simulation update timestep in seconds.
#update_timestep=(timestep) ⇒ Object
Set simulation update time step in seconds.
#update_timestep_inv ⇒ Numeric
Get the inverse of simulation update timestep.
#view_full_screen(state, include_floating_windows = true) ⇒ Boolean
Windows only!
Set view full screen.