Module: MSPhysics::Replay
- Defined in:
- RubyExtension/MSPhysics/replay.rb
Overview
Constant Summary collapse
- DEFAULT_RECORD_GROUPS =
true
- DEFAULT_RECORD_MATERIALS =
true
- DEFAULT_RECORD_LAYERS =
false
- DEFAULT_RECORD_CAMERA =
true
- DEFAULT_RECORD_RENDER =
false
- DEFAULT_RECORD_SHADOW =
false
- DEFAULT_REPLAY_GROUPS =
true
- DEFAULT_REPLAY_MATERIALS =
true
- DEFAULT_REPLAY_LAYERS =
false
- DEFAULT_REPLAY_CAMERA =
true
- DEFAULT_REPLAY_RENDER =
false
- DEFAULT_REPLAY_SHADOW =
false
- EXPORT_MESSAGE =
"SketchUp is in the process of exporting MSPhysics animation. You can wait until the process is complete or press OK to abort. If you do stop, you might have to wait a little for the current scene to finish exporting."
Class Method Summary collapse
-
.activate_frame(pframe) ⇒ Boolean
Activate frame data.
-
.active? ⇒ Boolean
Determine whether replay animation is in operation.
-
.active_data_valid? ⇒ Boolean
Determine whether active data is not empty.
-
.camera_data_valid? ⇒ Boolean
Determine whether camera data is not empty.
-
.camera_record_enabled=(state) ⇒ Object
Enable/disable camera recording.
-
.camera_record_enabled? ⇒ Boolean
Determine whether camera recording is enabled.
-
.camera_replay_enabled=(state) ⇒ Object
Enable/disable camera replay.
-
.camera_replay_enabled? ⇒ Boolean
Determine whether camera replay is enabled.
-
.clear_active_data ⇒ Object
Clear active data.
-
.clear_data_from_file ⇒ Boolean
Clear saved data from file.
-
.clear_data_from_model(wrap_in_op = true, delete_particle_defs = true) ⇒ void
Delete saved data from model.
-
.clear_recorded_data ⇒ Object
Clear recorded data.
-
.end_frame ⇒ Integer?
Get ending frame of all data recorded.
-
.export_to_images ⇒ Boolean
Export animation into image files.
-
.export_to_kerkythea ⇒ Boolean
Export animation into Kerkythea files.
-
.export_to_skindigo ⇒ Boolean
Export animation into SkIndigo files.
-
.export_to_skp ⇒ Boolean
Export animation into sketchup files.
-
.flatten_active_data ⇒ Object
Fill in the gaps within all the recorded information.
-
.frame ⇒ Numeric
Get replay animation frame.
-
.frame=(value) ⇒ Object
Set replay animation frame.
-
.get_camera_data(pframe) ⇒ Hash?
Get camera data at a particular frame.
-
.get_frame_data(data, pframe) ⇒ Hash?
Get data at a particular frame.
-
.get_group_data(group, pframe) ⇒ Hash?
Get group/component data at a particular frame.
-
.get_layer_data(layer, pframe) ⇒ Hash?
Get layer data at a particular frame.
-
.get_material_data(material, pframe) ⇒ Hash?
Get material data at a particular frame.
-
.get_render_data(pframe) ⇒ Hash?
Get render data at a particular frame.
-
.get_shadow_data(pframe) ⇒ Hash?
Get shadow data at a particular frame.
-
.groups_data_valid? ⇒ Boolean
Determine whether groups data is not empty.
-
.groups_record_enabled=(state) ⇒ Object
Enable/disable groups recording.
-
.groups_record_enabled? ⇒ Boolean
Determine whether groups recording is enabled.
-
.groups_replay_enabled=(state) ⇒ Object
Enable/disable groups replay.
-
.groups_replay_enabled? ⇒ Boolean
Determine whether groups replay is enabled.
-
.layers_data_valid? ⇒ Boolean
Determine whether layers data is not empty.
-
.layers_record_enabled=(state) ⇒ Object
Enable/disable layers recording.
-
.layers_record_enabled? ⇒ Boolean
Determine whether layers recording is enabled.
-
.layers_replay_enabled=(state) ⇒ Object
Enable/disable layers replay.
-
.layers_replay_enabled? ⇒ Boolean
Determine whether layers replay is enabled.
-
.load_data_from_file ⇒ Boolean
Load saved data from file.
-
.load_replay_proc ⇒ void
Load settings and data procedure.
-
.load_replay_settings ⇒ void
Load replay settings from model dictionary.
-
.materials_data_valid? ⇒ Boolean
Determine whether materials data is not empty.
-
.materials_record_enabled=(state) ⇒ Object
Enable/disable materials recording.
-
.materials_record_enabled? ⇒ Boolean
Determine whether materials recording is enabled.
-
.materials_replay_enabled=(state) ⇒ Object
Enable/disable materials replay.
-
.materials_replay_enabled? ⇒ Boolean
Determine whether materials replay is enabled.
-
.pause ⇒ Boolean
Pause replay animation.
-
.paused? ⇒ Boolean
Determine whether replay animation is paused.
-
.play(activate_animation = true) ⇒ Boolean
Play replay animation.
-
.playing? ⇒ Boolean
Determine whether replay animation is playing.
-
.preset_definition(instance, definition) ⇒ Object
When emitting groups, it would help to know their source, as as definitions often get purged.
-
.record_all(pframe) ⇒ Object
Record groups, camera, materials, layers, render, and shadow based on whether their recording is enabled.
-
.record_camera(pframe) ⇒ Object
Record camera.
-
.record_enabled=(state) ⇒ Object
Enable/disable simulation recording.
-
.record_enabled? ⇒ Boolean
Determine whether simulation recording is enabled.
-
.record_group(group, pframe) ⇒ Object
Record group/component.
-
.record_groups(pframe) ⇒ Object
Record all groups.
-
.record_layer(layer, pframe) ⇒ Object
Record layer.
-
.record_layers(pframe) ⇒ Object
Record all layers.
-
.record_material(material, pframe) ⇒ Object
Record material.
-
.record_materials(pframe) ⇒ Object
Record all materials.
-
.record_render(pframe) ⇒ Object
Record rendering options.
-
.record_shadow(pframe) ⇒ Object
Record shadow info.
-
.recorded_data_valid? ⇒ Boolean
Determine whether recorded data is not empty.
-
.render_data_valid? ⇒ Boolean
Determine whether render data is not empty.
-
.render_record_enabled=(state) ⇒ Object
Enable/disable render recording.
-
.render_record_enabled? ⇒ Boolean
Determine whether render recording is enabled.
-
.render_replay_enabled=(state) ⇒ Object
Enable/disable replay of rendering options.
-
.render_replay_enabled? ⇒ Boolean
Determine whether replay of rendering options is enabled.
-
.reset ⇒ Boolean
Stop replay animation and reset entity positions.
-
.reset_replay_settings ⇒ void
Reset replay settings.
-
.reversed=(state) ⇒ Object
Reverse replay animation.
-
.reversed? ⇒ Boolean
Determine whether replay animation is reversed.
-
.save_data_to_file(wrap_in_op = true) ⇒ Boolean
Save active data into file.
-
.save_recorded_data ⇒ Object
Activate recorded data.
-
.save_replay_settings(wrap_in_op = true) ⇒ void
Save replay settings into model dictionary.
-
.shadow_data_valid? ⇒ Boolean
Determine whether shadow data is not empty.
-
.shadow_record_enabled=(state) ⇒ Object
Enable/disable shadow recording.
-
.shadow_record_enabled? ⇒ Boolean
Determine whether shadow recording is enabled.
-
.shadow_replay_enabled=(state) ⇒ Object
Enable/disable replay of shadow info.
-
.shadow_replay_enabled? ⇒ Boolean
Determine whether relay of shadow info is enabled.
-
.smoothen_camera_data(interval) ⇒ Boolean
Smoothen the transitioning of active camera data.
-
.speed ⇒ Numeric
Get replay animation speed.
-
.speed=(value) ⇒ Object
Set replay animation speed.
-
.start(activate_animation = true) ⇒ Boolean
Start replay animation.
-
.start_frame ⇒ Integer?
Get starting frame of all data recorded.
-
.stop ⇒ Boolean
Stop replay animation, but avoid reseting entity positions.
-
.toggle_play ⇒ Boolean
Pause/Resume replay animation.
Class Method Details
.activate_frame(pframe) ⇒ Boolean
Activate frame data.
1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 |
# File 'RubyExtension/MSPhysics/replay.rb', line 1723 def activate_frame(pframe) return false unless active_data_valid? model = Sketchup.active_model pframe = AMS.clamp(pframe.to_i, @start_frame, @end_frame) # Activate group data @groups_data.each { |entity, data| instance = data[:instance] bentity_valid = (entity.is_a?(Sketchup::Group) || entity.is_a?(Sketchup::ComponentInstance)) && entity.valid? binstance_valid = instance && instance.valid? if pframe < data[:start_frame] || pframe > data[:end_frame] if bentity_valid && entity.visible? entity.visible = false end if binstance_valid && instance.visible? instance.visible = false end next end frame_data = get_frame_data(data, pframe) next unless frame_data material = frame_data[:material] if bentity_valid entity.move!(frame_data[:transformation]) if frame_data[:transformation] #~ entity.transformation = frame_data[:transformation] if @replay_groups if frame_data[:visible] != nil && entity.visible? != frame_data[:visible] entity.visible = frame_data[:visible] end if material if material == 0 entity.material = nil if entity.material elsif material.is_a?(Sketchup::Material) && material.valid? entity.material = material if entity.material != material else material_data = @materials_data[material] if material_data && material_data[:instance] && material_data[:instance].valid? entity.material = material_data[:instance] if entity.material != material_data[:instance] end end end entity.layer = frame_data[:layer] if frame_data[:layer] && frame_data[:layer] != 0 && frame_data[:layer].valid? && entity.layer != frame_data[:layer] end elsif binstance_valid && pframe >= data[:start_frame] && pframe <= data[:end_frame] instance.move!(frame_data[:transformation]) if frame_data[:transformation] #~ instance.transformation = frame_data[:transformation] if @replay_groups if frame_data[:visible] != nil && instance.visible? != frame_data[:visible] instance.visible = frame_data[:visible] end if material if material == 0 instance.material = nil if instance.material elsif material.is_a?(Sketchup::Material) && material.valid? instance.material = material if instance.material != material else material_data = @materials_data[material] if material_data && material_data[:instance] && material_data[:instance].valid? instance.material = material_data[:instance] if instance.material != material_data[:instance] end end end instance.layer = frame_data[:layer] if frame_data[:layer] && frame_data[:layer] != 0 && frame_data[:layer].valid? && instance.layer != frame_data[:layer] end end } # Activate material data if @replay_materials @materials_data.each { |material, data| frame_data = get_frame_data(data, pframe) next if frame_data.nil? mat = (material.is_a?(Sketchup::Material) && material.valid?) ? material : (data[:instance] && data[:instance].valid? ? data[:instance] : nil) next if mat.nil? mat.color = frame_data[:color] if frame_data[:color] && mat.color.to_i != frame_data[:color].to_i mat.alpha = frame_data[:alpha] if frame_data[:alpha] && mat.alpha != frame_data[:alpha] if mat.texture mat.texture = frame_data[:texture] if frame_data[:texture] && mat.texture.filename != frame_data[:texture] else mat.texture = frame_data[:texture] if frame_data[:texture] end if mat.texture && frame_data[:width] && frame_data[:height] && (mat.texture.width != frame_data[:width] || mat.texture.height != frame_data[:height]) mat.texture.size = [frame_data[:width], frame_data[:height]] end if Sketchup.version.to_i >= 15 && frame_data[:colorize_type] && mat.colorize_type != frame_data[:colorize_type] mat.colorize_type = frame_data[:colorize_type] end } end # Activate layer data if @replay_layers @layers_data.each { |layer, data| next unless layer.valid? frame_data = get_frame_data(data, pframe) next if frame_data.nil? layer.visible = frame_data[:visible] if frame_data[:visible] != nil && layer.visible? != frame_data[:visible] if Sketchup.version.to_i > 13 && frame_data[:color] && layer.color.to_i != frame_data[:color].to_i layer.color = frame_data[:color] end } end # Activate camera data. if @replay_camera frame_data = get_frame_data(@camera_data, pframe) if frame_data camera = model.active_view.camera eye = frame_data[:eye] ? frame_data[:eye] : camera.eye target = frame_data[:target] ? frame_data[:target] : camera.target up = frame_data[:up] ? frame_data[:up] : camera.up camera.set(eye, target, up) camera.perspective = frame_data[:perspective] if frame_data[:perspective] != nil #camera.aspect_ratio = frame_data[:aspect_ratio] if frame_data[:aspect_ratio] if camera.perspective? camera.focal_length = frame_data[:focal_length] if frame_data[:focal_length] camera.fov = frame_data[:fov] if frame_data[:fov] camera.image_width = frame_data[:image_width] if frame_data[:image_width] else camera.height = frame_data[:height] if frame_data[:height] end end end # Activate render data. if @replay_render frame_data = get_frame_data(@render_data, pframe) if frame_data frame_data.each { |k, v| model.[k] = v if model.[k] != nil && model.[k] != v } end end # Activate shadow data. if @replay_shadow frame_data = get_frame_data(@shadow_data, pframe) if frame_data frame_data.each { |k, v| model.shadow_info[k] = v if model.shadow_info[k] != nil && model.shadow_info[k] != v } end end true end |
.active? ⇒ Boolean
Determine whether replay animation is in operation.
409 410 411 |
# File 'RubyExtension/MSPhysics/replay.rb', line 409 def active? @active end |
.active_data_valid? ⇒ Boolean
Determine whether active data is not empty.
421 422 423 |
# File 'RubyExtension/MSPhysics/replay.rb', line 421 def active_data_valid? @groups_data.size > 0 || @materials_data.size > 0 || @layers_data.size > 0 || @camera_data.size > 0 || @render_data.size > 0 || @shadow_data.size > 0 end |
.camera_data_valid? ⇒ Boolean
Determine whether camera data is not empty.
1704 1705 1706 |
# File 'RubyExtension/MSPhysics/replay.rb', line 1704 def camera_data_valid? @camera_data[:start_frame] && @camera_data[:end_frame] ? true : false end |
.camera_record_enabled=(state) ⇒ Object
Enable/disable camera recording.
475 476 477 |
# File 'RubyExtension/MSPhysics/replay.rb', line 475 def camera_record_enabled=(state) @record_camera = state ? true : false end |
.camera_record_enabled? ⇒ Boolean
Determine whether camera recording is enabled.
481 482 483 |
# File 'RubyExtension/MSPhysics/replay.rb', line 481 def camera_record_enabled? @record_camera end |
.camera_replay_enabled=(state) ⇒ Object
Enable/disable camera replay.
547 548 549 |
# File 'RubyExtension/MSPhysics/replay.rb', line 547 def camera_replay_enabled=(state) @replay_camera = state ? true : false end |
.camera_replay_enabled? ⇒ Boolean
Determine whether camera replay is enabled.
553 554 555 |
# File 'RubyExtension/MSPhysics/replay.rb', line 553 def camera_replay_enabled? @replay_camera end |
.clear_active_data ⇒ Object
Clear active data.
858 859 860 861 862 863 864 865 866 867 |
# File 'RubyExtension/MSPhysics/replay.rb', line 858 def clear_active_data @groups_data.clear @materials_data.clear @layers_data.clear @camera_data.clear @render_data.clear @shadow_data.clear @start_frame = nil @end_frame = nil end |
.clear_data_from_file ⇒ Boolean
This attempts to delete the file if permissions are granted.
Clear saved data from file.
1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 |
# File 'RubyExtension/MSPhysics/replay.rb', line 1593 def clear_data_from_file model = Sketchup.active_model return false if model.path.empty? dict = 'MSPhysics Replay' # Parse path to the current model. model_path = model.path.gsub(/\\/, '/') mspr_path = File.dirname(model_path) mspr_name = File.basename(model_path, '.skp') + '.mspreplay' mspr_fpath = File.join(mspr_path, mspr_name) # Return if file doesn't exist. return false unless File.exists?(mspr_fpath) begin File.delete(mspr_fpath) rescue Exception => err File.open(mspr_fpath, 'w') { |f| f.truncate(0) } rescue Exception => err return false end # Return success true end |
.clear_data_from_model(wrap_in_op = true, delete_particle_defs = true) ⇒ void
This method returns an undefined value.
Delete saved data from model.
1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 |
# File 'RubyExtension/MSPhysics/replay.rb', line 1539 def clear_data_from_model(wrap_in_op = true, delete_particle_defs = true) op_started = false model = Sketchup.active_model # Start operation if wrap_in_op op = 'Clearing MSPhysics Replay' Sketchup.version.to_i > 6 ? model.start_operation(op, true, false, false) : model.start_operation(op) op_started = true end dict = model.attribute_dictionaries['MSPhysics Replay'] if dict dict.delete_key('Groups Data') dict.delete_key('Materials Data') dict.delete_key('Layers Data') dict.delete_key('Camera Data') dict.delete_key('Render Data') dict.delete_key('Shadow Data') dict.delete_key('Start Frame') dict.delete_key('End Frame') dict.delete_key('Groups Data Chop Count') dict.delete_key('Materials Data Chop Count') dict.delete_key('Layers Data Chop Count') dict.delete_key('Camera Data Chop Count') dict.delete_key('Render Data Chop Count') dict.delete_key('Shadow Data Chop Count') end model.definitions.each { |d| d.attribute_dictionaries.delete('MSPhysics Replay') if d.attribute_dictionaries d.instances.each { |i| i.attribute_dictionaries.delete('MSPhysics Replay') if i.attribute_dictionaries } } model.materials.each { |m| m.attribute_dictionaries.delete('MSPhysics Replay') if m.attribute_dictionaries } model.layers.each { |l| l.attribute_dictionaries.delete('MSPhysics Replay') if l.attribute_dictionaries } if delete_particle_defs model.entities.grep(Sketchup::ComponentInstance).each { |e| e.erase! if e.get_attribute('MSPhysics', 'Type', 'Body') == 'Particle' } end model.definitions.purge_unused # End operation model.commit_operation if wrap_in_op rescue Exception => err model.abort_operation if op_started raise err end |
.clear_recorded_data ⇒ Object
Clear recorded data.
845 846 847 848 849 850 851 852 853 854 855 |
# File 'RubyExtension/MSPhysics/replay.rb', line 845 def clear_recorded_data @tgroups_data.clear @tmaterials_data.clear @tlayers_data.clear @tcamera_data.clear @trender_data.clear @tshadow_data.clear @preset_definitions.clear @tstart_frame = nil @tend_frame = nil end |
.end_frame ⇒ Integer?
Get ending frame of all data recorded.
601 602 603 |
# File 'RubyExtension/MSPhysics/replay.rb', line 601 def end_frame @end_frame end |
.export_to_images ⇒ Boolean
Export animation into image files.
1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 |
# File 'RubyExtension/MSPhysics/replay.rb', line 1861 def export_to_images model = Sketchup.active_model view = model.active_view # Check if animation record is not empty. unless active_data_valid? ::UI.("Nothing to export!") return false end # Display options input box. prompts = ['Start Frame', 'End Frame', 'Speed (0.01 - 10000)', 'Reverse', 'Image Type', 'Resolution', 'Anti-alias', 'Compression', 'Transparent Background ', 'Replay Groups', 'Replay Materials', 'Replay Layers', 'Replay Camera', 'Replay Render', 'Replay Shadow'] yn = 'Yes|No' image_types = 'bmp|jpg|png|tif' res = 'Model-Inherited|Custom|320x240|640x480|768x576|800x600|1024x768|1280x720|1280x1024|1920x1080' compression = '0.0|0.1|0.2|0.3|0.4|0.5|0.6|0.7|0.8|0.9|1.0' drop_downs = ['', '', '', yn, image_types, res, yn, compression, yn, yn, yn, yn, yn, yn, yn] values = [@start_frame, @end_frame, @image_defaults[:speed], @image_defaults[:reversed], @image_defaults[:image_type], @image_defaults[:resolution], @image_defaults[:antialias], @image_defaults[:compression], @image_defaults[:tbackground], @replay_groups ? 'Yes' : 'No', @replay_materials ? 'Yes' : 'No', @replay_layers ? 'Yes' : 'No', @replay_camera ? 'Yes' : 'No', @replay_render ? 'Yes' : 'No', @replay_shadow ? 'Yes' : 'No'] results = ::UI.inputbox(prompts, values, drop_downs, 'Export Animation Options') return false unless results # Display Custom resolution input box if desired. if results[5] == 'Custom' results2 = ::UI.inputbox(['Width', 'Height'], [800, 600], 'Use Custom Resolution') return false unless results2 w = AMS.clamp(results2[0].to_i, 1, 16000) h = AMS.clamp(results2[1].to_i, 1, 16000) results[5] = "#{w}x#{h}" end # Select export path model_fname = File.basename(model.path, '.skp') model_fname = "msp_anim" if model_fname.empty? script_file = ::UI.savepanel('Choose Export Directory and Name', nil, model_fname) return false unless script_file fpath = File.dirname(script_file) fpath.force_encoding('UTF-8') unless AMS::IS_RUBY_VERSION_18 fname = File.basename(script_file, '.skp') # Preset user data sframe = results[0].to_i eframe = results[1].to_i speed = AMS.clamp(results[2].to_f, 0.01, 10000) reversed = results[3] == 'Yes' opts = {} if results[5] != 'Model-Inherited' wh = results[5].split('x') opts[:width] = wh[0].to_i opts[:height] = wh[1].to_i end opts[:antialias] = results[6] == 'Yes' opts[:compression] = results[7].to_f opts[:transparent] = results[8] == 'Yes' orig_rep_grp = @replay_groups orig_rep_mat = @replay_materials orig_rep_lay = @replay_layers orig_rep_cam = @replay_camera orig_rep_ren = @replay_render orig_rep_sha = @replay_shadow @replay_groups = results[9] == 'Yes' @replay_materials = results[10] == 'Yes' @replay_layers = results[11] == 'Yes' @replay_camera = results[12] == 'Yes' @replay_render = results[13] == 'Yes' @replay_shadow = results[14] == 'Yes' # Save defaults @image_defaults[:speed] = speed.to_s @image_defaults[:reversed] = results[3] @image_defaults[:image_type] = results[4] @image_defaults[:resolution] = results[5] @image_defaults[:antialias] = results[6] @image_defaults[:compression] = results[7] @image_defaults[:tbackground] = results[8] # Export animation start_time = Time.now called_while_active = @active start(false) unless called_while_active pframe = reversed ? eframe : sframe rframe = pframe last_frame = nil count = 1 babort = false if AMS::IS_PLATFORM_WINDOWS = "'#{AMS::Sketchup.}' - Animation Export" AMS::Sketchup.(, EXPORT_MESSAGE) { |result| babort = true } end while(rframe >= sframe && rframe <= eframe) break if babort # Export scene if rframe != last_frame activate_frame(rframe) last_frame = rframe end opts[:filename] = "#{fpath}/#{fname}#{sprintf("%04d", count)}.#{results[4]}" view.write_image(opts) progress = (rframe - sframe) * 100 / (eframe - sframe).to_f Sketchup.set_status_text("Exporting MSPhysics Replay Animation Progress: #{rframe - sframe} / #{eframe - sframe} -- #{sprintf("%.2f", progress)}%", SB_PROMPT) pframe += reversed ? -speed : speed rframe = pframe.round count += 1 end if AMS::IS_PLATFORM_WINDOWS hwnd = AMS::Sketchup.() AMS::Window.close(hwnd) if hwnd end reset unless called_while_active # Set original settings @replay_groups = orig_rep_grp @replay_materials = orig_rep_mat @replay_layers = orig_rep_lay @replay_camera = orig_rep_cam @replay_render = orig_rep_ren @replay_shadow = orig_rep_sha # Display results ::UI.("#{babort ? 'Stopped' : 'Finished'} exporting MSPhysics Replay Animation!\n\nExported #{count} frames in #{sprintf("%.2f", Time.now - start_time)} seconds.\n\nYou may now dispose of replay data to reduce file size.\n\nYou may use Movie Maker, MakeAVI, or a similar tool to combine all images into a video file.") # Return success true end |
.export_to_kerkythea ⇒ Boolean
Export animation into Kerkythea files.
2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 |
# File 'RubyExtension/MSPhysics/replay.rb', line 2093 def export_to_kerkythea unless defined?(::SU2KT) if ::UI.("Kerkythea (SU2KT) plugin is not installed. Would you like to visit the plugin's download page?", MB_YESNO) == IDYES UI.openURL('http://www.kerkythea.net/forum/viewtopic.php?f=10&t=12784') end return false end unless ::SU2KT.respond_to?(:export_msp_animation) add_in_script = %q{ def self.export_msp_animation model = Sketchup.active_model view = model.active_view # Check if animation record is not empty. unless MSPhysics::Replay.active_data_valid? ::UI.messagebox("Nothing to export!") return false end SU2KT.reset_global_variables # Get first stage settings. return false unless SU2KT.export_options_window # Get second stage settings. render_set, rend_files = SU2KT.get_render_settings settings = SU2KT.get_stored_values # If file doesn't exist use the first render setting file that was found. settings[6] = File.exist?(settings[6]) ? File.basename(settings[6], '.xml') : render_set[0] prompts = ['Start Frame', 'End Frame', 'Speed (0.01 - 10000)', 'Replay Camera?', 'Reverse?', 'Animated Lights and Sun?', 'Resolution', 'Render Settings'] res = %w[Model-Inherited Custom 320x240 640x480 768x576 800x600 1024x768 1280x720 1280x1024 1920x1080].join('|') drop_downs = ['', '', '', 'Yes|No', 'Yes|No', 'Yes|No', res, render_set.join('|')] values = [ MSPhysics::Replay.start_frame, MSPhysics::Replay.end_frame, MSPhysics::Replay.speed, MSPhysics::Replay.camera_replay_enabled? ? 'Yes' : 'No', MSPhysics::Replay.reversed? ? 'Yes' : 'No', settings[2], settings[5], settings[6] ] results = ::UI.inputbox(prompts, values, drop_downs, 'Export Animation Options') return false unless results # Use custom resolution if results[6] == 'Custom' results2 = ::UI.inputbox(['Width', 'Height'], [800, 600], 'Use Custom Resolution') return false unless results2 w = AMS.clamp(results2[0].to_i, 1, 16000) h = AMS.clamp(results2[1].to_i, 1, 16000) results[6] = "#{w}x#{h}" end # Replace rendering setting with full file path. results[7] = rend_files[render_set.index(results[7])] # Store new settings. settings[2] = results[5] settings[5] = results[6] settings[6] = results[7] SU2KT.store_values(settings) # Select export path and create export folder. #~ script_file = SU2KT.select_script_path_window #~ return false unless script_file model_filename = File.basename(model.path) model_filename.force_encoding('UTF-8') unless AMS::IS_RUBY_VERSION_18 if model_filename.empty? model_name = 'Untitled.kst' else model_name = File.basename(model_filename, '.*') + '.kst' end script_file = ::UI.savepanel('Select Export Directory and Name', '', model_name) return false unless script_file script_file.force_encoding('UTF-8') unless AMS::IS_RUBY_VERSION_18 script_file.gsub!(/\u005c/, '/') script_file = File.join(File.dirname(script_file), File.basename(script_file, '.*') + '.kst') @model_name = File.basename(script_file, '.*') @frames_path = File.dirname(script_file) + @ds + 'Anim_' + @model_name Dir.mkdir(@frames_path) unless FileTest.exist?(@frames_path) @path_textures = File.dirname(script_file) # Optimize values. sframe = results[0].to_i eframe = results[1].to_i speed = AMS.clamp(results[2].to_f, 0.01, 10000) reversed = results[4] == 'Yes' orig_replay_camera = MSPhysics::Replay.camera_replay_enabled? MSPhysics::Replay.camera_replay_enabled = results[3] == 'Yes' @anim_sun = (results[5] == 'Yes') @export_full_frame = true @scene_export = true @resolution = (results[6] == 'Model-Inherited') ? '4x4' : results[6] @instanced = false # Initiate replay start_time = Time.now called_while_active = MSPhysics::Replay.active? MSPhysics::Replay.start(false) unless called_while_active MSPhysics::Replay.pause # Create main XML file. out_file = File.join(File.dirname(script_file), File.basename(script_file, '.*') + '.xml') out = File.new(out_file, 'w') # Export data to the main XML file. #SU2KT.export_global_settings(out) SU2KT.export_render_settings(out, results[7]) SU2KT.find_lights(model.entities, Geom::Transformation.new) SU2KT.write_sky(out) if @instanced SU2KT.export_instanced(out, model.entities) else SU2KT.export_meshes(out, model.entities) end SU2KT.export_current_view(model.active_view, out) SU2KT.export_lights(out) if @export_lights SU2KT.write_sun(out) SU2KT.finish_close(out) # Update merge settings. SU2KT.set_merge_settings # Create script file. script = File.new(script_file, 'w') # Make sure it loads the main XML file. script.puts "message \"Load #{out_file}\"" # Export animation MSPhysics::Replay.play(false) pframe = reversed ? eframe : sframe rframe = pframe last_frame = nil count = 1 babort = false if AMS::IS_PLATFORM_WINDOWS msg_caption = "'#{AMS::Sketchup.get_caption}' - Animation Export" AMS::Sketchup.threaded_messagebox(msg_caption, MSPhysics::Replay::EXPORT_MESSAGE) { |result| babort = true } end while(rframe >= sframe && rframe <= eframe) break if babort # Export scene if rframe != last_frame MSPhysics::Replay.activate_frame(rframe) last_frame = rframe end # Export data to the frame file frame_name = sprintf("%0d", count) full_path = @frames_path + @ds + frame_name + '.xml' script.puts("message \"Merge '#{full_path}' 5 5 4 0 0\"") script.puts("message \"Render\"") script.puts("message \"SaveImage " + @frames_path + @ds + frame_name + ".jpg\"") out = File.new(full_path, 'w') SU2KT.export_render_settings(out, settings[6]) SU2KT.find_lights(model.entities, Geom::Transformation.new) SU2KT.write_sky(out) SU2KT.collect_faces(model.entities, Geom::Transformation.new) SU2KT.export_faces(out) SU2KT.export_fm_faces(out) SU2KT.export_current_view(model.active_view, out) SU2KT.export_lights(out) if @export_lights SU2KT.write_sun(out) SU2KT.finish_close(out) # Display progress progress = (rframe - sframe) * 100 / (eframe - sframe).to_f Sketchup.set_status_text("Exporting MSPhysics Replay to KT Progress: #{rframe - sframe} / #{eframe - sframe} -- #{sprintf("%.2f", progress)}%", SB_PROMPT) # Increment frame and counter pframe += reversed ? -speed : speed rframe = pframe.round count += 1 end if AMS::IS_PLATFORM_WINDOWS hwnd = AMS::Sketchup.find_window_by_caption(msg_caption) AMS::Window.close(hwnd) if hwnd end MSPhysics::Replay.reset unless called_while_active # Set original replay settings MSPhysics::Replay.camera_replay_enabled = orig_replay_camera # Finalize script.close # It is important that textures are exported last! SU2KT.write_textures msg = "#{babort ? 'Stopped' : 'Finished'} exporting MSPhysics Replay Animation!\n\nExported #{count} frames in #{sprintf("%.2f", Time.now - start_time)} seconds.\n\nNow you're left to adjust '#{File.basename(out_file)}' render settings, run '#{File.basename(script_file)}' render script, and combine rendered images using a software, like Windows Movie Maker.\n\nYou may skip adjusting render settings and get to the rendering right away. Would you like to start rendering right now?" result = ::UI.messagebox(msg, MB_YESNO) @export_file = script_file # Used by render_animation as the script path. # Render animation. kt_path = SU2KT.get_kt_path return unless kt_path kt_path.force_encoding('UTF-8') unless AMS::IS_RUBY_VERSION_18 if AMS::IS_PLATFORM_WINDOWS #batch_file_path = File.join(File.dirname(kt_path), 'start.bat') batch_file_path = File.join(File.dirname(script_file), "#{File.basename(script_file, '.kst')}_start_render.bat") batch = File.new(batch_file_path, 'w') batch.puts "start \"\" \"#{kt_path}\" \"#{script_file}\"" batch.close ::UI.openURL(batch_file_path) if result == IDYES else # MAC solution if result == IDYES Thread.new do script_file_path = File.join( script_file.split(@ds) ) system(`#{kt_path} "#{script_file_path}"`) end end end SU2KT.reset_global_variables # Return success true end} ::SU2KT.module_eval(add_in_script, __FILE__, 0) end ::SU2KT.export_msp_animation end |
.export_to_skindigo ⇒ Boolean
Export animation into SkIndigo files.
2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 |
# File 'RubyExtension/MSPhysics/replay.rb', line 2296 def export_to_skindigo unless defined?(::SkIndigo) if ::UI.("SkIndigo plugin is not installed. Would you like to visit the plugin's download page?", MB_YESNO) == IDYES UI.openURL('https://www.indigorenderer.com/forum/viewtopic.php?f=1&t=14374') UI.openURL('https://www.indigorenderer.com/forum/viewtopic.php?f=17&t=14375') end return false end unless ::SkIndigo.respond_to?(:export_msp_animation) add_in_script = %q{ def self.export_msp_animation model = Sketchup.active_model view = model.active_view # Check if animation record is not empty. unless MSPhysics::Replay.active_data_valid? ::UI.messagebox("Nothing to export!") return false end # Verify the halt time if IndigoRenderSettings.new.halt.to_i == -1 result = ::UI.messagebox("Warning: Halt time is set to -1. This means that each frame will render forever unless the halt time is set to a value such as 10 (s). Halt time can be set in Advanced tab of the SkIndigo render settings dialog. Press YES to proceed exporting or NO to adjust rendering settings first.", MB_YESNO) return false if result == IDNO end prompts = ['Start Frame', 'End Frame', 'Speed (0.01 - 10000)', 'Replay Camera?', 'Reverse?'] drop_downs = ['', '', '', 'Yes|No', 'Yes|No'] values = [ MSPhysics::Replay.start_frame, MSPhysics::Replay.end_frame, MSPhysics::Replay.speed, MSPhysics::Replay.camera_replay_enabled? ? 'Yes' : 'No', MSPhysics::Replay.reversed? ? 'Yes' : 'No' ] results = ::UI.inputbox(prompts, values, drop_downs, 'Export Animation Options') return false unless results # Select export path and create export folder. model_filename = File.basename(model.path) model_filename.force_encoding('UTF-8') unless AMS::IS_RUBY_VERSION_18 if model_filename.empty? queue_filename = 'Untitled.igq' else queue_filename = File.basename(model_filename, '.*') + '.igq' end batch_file_path = ::UI.savepanel('Select Export Directory and Name', '', queue_filename) return false unless batch_file_path batch_file_path.force_encoding('UTF-8') unless AMS::IS_RUBY_VERSION_18 batch_file_path.gsub!(/\u005c/, '/') batch_file_path = File.join(File.dirname(batch_file_path), File.basename(batch_file_path, '.*') + '.igq') export_dir = File.join(File.dirname(batch_file_path), File.basename(batch_file_path, '.*')) Dir.mkdir(export_dir) unless FileTest.exist?(export_dir) export_path = File.join(export_dir, File.basename(batch_file_path, '.*') + '.igs') export_path.force_encoding('UTF-8') unless AMS::IS_RUBY_VERSION_18 # Initiate indigo exporter ie = ::IndigoExporter.new(export_path) ie.settings.save_to_model() model_name = File.basename(ie.path, '.igs') return false if model_name.empty? tex_path = File.join(File.dirname(export_path), 'TX_' + model_name) ie.tex_path = 'TX_' + model_name # Optimize values. sframe = results[0].to_i eframe = results[1].to_i speed = AMS.clamp(results[2].to_f, 0.01, 10000) reversed = results[4] == 'Yes' orig_replay_camera = MSPhysics::Replay.camera_replay_enabled? MSPhysics::Replay.camera_replay_enabled = results[3] == 'Yes' print_timings = !SkIndigo.run_tests? # Initiate replay start_time = Time.now called_while_active = MSPhysics::Replay.active? MSPhysics::Replay.start(false) unless called_while_active MSPhysics::Replay.pause # Open the shared IGS file to export to. shared_igs_path = File.join(File.dirname(ie.path), model_name + '-shared.igs') shared_igs_file = File.new(shared_igs_path, 'w') shared_igs_file.puts "<?xml version=\"1.0\" encoding=\"utf-8\"?>" shared_igs_file.puts "<scenedata>" ie.export_default_mat(shared_igs_file) mesh_builder = IndigoMeshBuilder.new IndigoMeshBuilder.reset # Erases the stored meshes, instances, and spheres from last export # Process entities (iterate over scene, get list of components/groups etc.. to export) t = Time.now Sketchup.set_status_text("Collecting Instances...", SB_PROMPT) entities_to_export = Sketchup.active_model.entities mesh_builder.process_entities(entities_to_export) puts "Traversed model and got instances in #{Time.now - t} seconds." # Build required (visible, referenced) meshes t = Time.now Sketchup.set_status_text("Building Meshes...", SB_PROMPT) mesh_builder.build_meshes() puts "Built meshes in #{Time.now - t} seconds." # Write meshes t = Time.now Sketchup.set_status_text("Exporting Meshes...", SB_PROMPT) ie.export_meshes(mesh_builder, shared_igs_file) puts "Exported meshes in #{Time.now - t} seconds." ie.get_used_layers() # Build a set of the materials that were actually referenced by a model, so that we can just export those materials, and not all materials in the scene. referenced_materials = ie.get_referenced_materials(mesh_builder) # Export all the materials t = Time.now Sketchup.set_status_text("Exporting Materials...", SB_PROMPT) referenced_materials.each { |mat, generate_uvs| ie.export_material(IndigoMaterial.new(mat), shared_igs_file, generate_uvs) } puts "Exported materials in #{Time.now - t} seconds." if print_timings # Write scatters ie.export_scatters(mesh_builder, shared_igs_file) shared_igs_file.puts "</scenedata>" shared_igs_file.close # Export textures Sketchup.set_status_text("Exporting textures...", SB_PROMPT) Dir.mkdir(tex_path) if !FileTest.exist?(tex_path) # Export all textures collected during the material export process ie.export_textures(ie.textures) # Export all collected nkata #~ for path in ie.nkdata #~ nk = NKdata.new(path) #~ nk.export(tex_path) # exports the nkdata to the textures directory #~ end # Export all collected ies profiles for path in ie.ies profile = IESProfile.new(path) profile.export(tex_path) if profile.valid? # export the IES profiles to the textures directory end if print_timings puts "------ SkIndigo MSPhysics Animation Export Run ------" puts "Instances: #{mesh_builder.instances.size}" puts "Meshes: #{mesh_builder.num_meshes()}" puts "Meshes exported: #{mesh_builder.num_new_meshes_exported}" puts "Spheres: #{mesh_builder.spheres.length}" end # Export animation MSPhysics::Replay.play(false) pframe = reversed ? eframe : sframe rframe = pframe last_frame = nil count = 1 babort = false if AMS::IS_PLATFORM_WINDOWS msg_caption = "'#{AMS::Sketchup.get_caption}' - Animation Export" AMS::Sketchup.threaded_messagebox(msg_caption, MSPhysics::Replay::EXPORT_MESSAGE) { |result| babort = true } end while(rframe >= sframe && rframe <= eframe) break if babort if rframe != last_frame MSPhysics::Replay.activate_frame(rframe) last_frame = rframe end # Export data to the frame file ie.export_msp_frame(File.dirname(export_path), mesh_builder, shared_igs_path) # Display progress progress = (rframe - sframe) * 100 / (eframe - sframe).to_f Sketchup.set_status_text("Exporting MSPhysics Replay to SkIndigo Progress: #{rframe - sframe} / #{eframe - sframe} -- #{sprintf("%.2f", progress)}%", SB_PROMPT) # Increment frame and counter pframe += reversed ? -speed : speed rframe = pframe.round count += 1 end if AMS::IS_PLATFORM_WINDOWS hwnd = AMS::Sketchup.find_window_by_caption(msg_caption) AMS::Window.close(hwnd) if hwnd end MSPhysics::Replay.reset unless called_while_active # Set original replay settings MSPhysics::Replay.camera_replay_enabled = orig_replay_camera # Finalize ie.create_animation_igq_file(batch_file_path) msg = "#{babort ? 'Stopped' : 'Finished'} exporting MSPhysics Replay Animation!\n\nExported #{count} frames in #{sprintf("%.2f", Time.now - start_time)} seconds.\n\nNow you're left to adjust '#{File.basename(shared_igs_file)}' render settings, run '#{File.basename(batch_file_path)}' render script, and combine rendered images using a software, like Windows Movie Maker.\n\nYou may skip adjusting render settings and get to the rendering right away. Would you like to start rendering right now?" result = ::UI.messagebox(msg, MB_YESNO) # Render animation if result == IDYES # Open Indigo for rendering is = IndigoRenderSettings.new indigo_path = SkIndigo.get_indigo_path if indigo_path.nil? ::UI.messagebox("Indigo application not found. Rendering Aborted.") return true end if FileTest.exist?(indigo_path) output_param = "" case is.network_mode when 1 # master output_param += "-n m " unless SkIndigo.on_mac? when 2 # working master output_param += "-n wm " unless SkIndigo.on_mac? end SkIndigo.launch_indigo(indigo_path, batch_file_path, output_param, is.low_priority?, "normal") end end # Return success true end} add_in_script2 = %q{ def export_msp_frame(igs_path, mb, shared_igs_path) Dir.mkdir(igs_path) unless FileTest.exist?(igs_path) return false unless FileTest.exist?(igs_path) # failed to create path @next_uid += 100 # put this in initialization method? igs_path = File.basename(self.path) model_name = File.basename(igs_path, ".*") # minus the file extension # Begin exporting the current frame ents = Sketchup.active_model.entities #mb = IndigoMeshBuilder.new mb.reset_instances #mb.build_active_mesh(ents) # exported_entity_set = Set.new() # Used to prevent infinite loops on recursive components. # mb.get_instances(ents, Geom::Transformation.new, exported_entity_set) entities_to_export = Sketchup.active_model.entities mb.process_entities(entities_to_export) #mb.build_meshes() frame_num = "%04d" % @frame frame_path = File.join(File.dirname(self.path), model_name + "-#{frame_num}.igs") get_used_layers() out = File.new(frame_path, "w") out.puts "<?xml version=\"1.0\" encoding=\"utf-8\"?>" out.puts "<scene>" export_metadata(out) export_render_settings(out) export_tonemapping(out) export_camera(self.model.active_view, out) export_environment(out) export_default_mat(out) mb.spheres.each { |sphere| export_sphere(sphere, out) } export_fog(out) if self.model.rendering_options["DisplayFog"] out.puts " <include>" out.puts " <offset_uids>false</offset_uids>" out.puts " <pathname>#{File.basename(shared_igs_path)}</pathname>" out.puts " </include>" out.puts "" export_instances(mb, out) export_light_layer_names(out) out.puts "</scene>" out.close @frame += 1 return true end} ::SkIndigo.module_eval(add_in_script, __FILE__, 0) ::IndigoExporter.class_eval(add_in_script2, __FILE__, 0) end ::SkIndigo.export_msp_animation end |
.export_to_skp ⇒ Boolean
Export animation into sketchup files.
1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 |
# File 'RubyExtension/MSPhysics/replay.rb', line 1979 def export_to_skp model = Sketchup.active_model view = model.active_view # Check if animation record is not empty. unless active_data_valid? ::UI.("Nothing to export!") return false end # Display options input box. prompts = ['Start Frame', 'End Frame', 'Speed (0.01 - 10000) ', 'Reverse', 'Replay Groups', 'Replay Materials', 'Replay Layers', 'Replay Camera', 'Replay Render', 'Replay Shadow'] yn = 'Yes|No' drop_downs = ['', '', '', yn, yn, yn, yn, yn, yn, yn] values = [@start_frame, @end_frame, @skp_defaults[:speed], @skp_defaults[:reversed], @replay_groups ? 'Yes' : 'No', @replay_materials ? 'Yes' : 'No', @replay_layers ? 'Yes' : 'No', @replay_camera ? 'Yes' : 'No', @replay_render ? 'Yes' : 'No', @replay_shadow ? 'Yes' : 'No'] results = ::UI.inputbox(prompts, values, drop_downs, 'Export Animation Options') return false unless results # Select export path model_fname = File.basename(model.path, '.skp') model_fname = "msp_anim" if model_fname.empty? script_file = ::UI.savepanel('Choose Export Directory and Name', nil, model_fname) return false unless script_file fpath = File.dirname(script_file) fpath.force_encoding('UTF-8') unless AMS::IS_RUBY_VERSION_18 fname = File.basename(script_file, '.skp') # Preset user data sframe = results[0].to_i eframe = results[1].to_i speed = AMS.clamp(results[2].to_f, 0.01, 10000) reversed = results[3] == 'Yes' orig_rep_grp = @replay_groups orig_rep_mat = @replay_materials orig_rep_lay = @replay_layers orig_rep_cam = @replay_camera orig_rep_ren = @replay_render orig_rep_sha = @replay_shadow @replay_groups = results[4] == 'Yes' @replay_materials = results[5] == 'Yes' @replay_layers = results[6] == 'Yes' @replay_camera = results[7] == 'Yes' @replay_render = results[8] == 'Yes' @replay_shadow = results[9] == 'Yes' # Save skp defaults @skp_defaults[:speed] = speed.to_s @skp_defaults[:reversed] = results[3] # Export animation start_time = Time.now called_while_active = @active begin clear_data_from_model(true, false) rescue Exception => err puts 'Failed to initially clear replay data from model!' puts err end start(false) unless called_while_active pframe = reversed ? eframe : sframe rframe = pframe last_frame = nil count = 1 babort = false if AMS::IS_PLATFORM_WINDOWS = "'#{AMS::Sketchup.}' - Animation Export" AMS::Sketchup.(, EXPORT_MESSAGE) { |result| babort = true } end while(rframe >= sframe && rframe <= eframe) break if babort # Export scene if rframe != last_frame activate_frame(rframe) last_frame = rframe end full_path = "#{fpath}/#{fname}#{sprintf("%04d", count)}.skp" if Sketchup.version.to_i < 14 model.save(full_path) else if model.path.empty? model.save(full_path) else model.save_copy(full_path) end end progress = (rframe - sframe) * 100 / (eframe - sframe).to_f Sketchup.set_status_text("Exporting MSPhysics Replay Animation Progress: #{rframe - sframe} / #{eframe - sframe} -- #{sprintf("%.2f", progress)}%", SB_PROMPT) pframe += reversed ? -speed : speed rframe = pframe.round count += 1 end if AMS::IS_PLATFORM_WINDOWS hwnd = AMS::Sketchup.() AMS::Window.close(hwnd) if hwnd end reset unless called_while_active # Resave data begin save_data_to_file(true) rescue Exception => err puts 'Failed to resave replay data to model and file!' puts err end # Set original settings @replay_groups = orig_rep_grp @replay_materials = orig_rep_mat @replay_layers = orig_rep_lay @replay_camera = orig_rep_cam @replay_render = orig_rep_ren @replay_shadow = orig_rep_sha # Display results ::UI.("#{babort ? 'Stopped' : 'Finished'} exporting MSPhysics Replay Animation!\n\nExported #{count} frames in #{sprintf("%.2f", Time.now - start_time)} seconds.\n\nYou may now dispose of replay data to reduce file size.") # Return success true end |
.flatten_active_data ⇒ Object
Fill in the gaps within all the recorded information.
870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 |
# File 'RubyExtension/MSPhysics/replay.rb', line 870 def flatten_active_data # Flatten groups data @groups_data.each { |group, data| next if !data[:start_frame] || !data[:end_frame] last = {} for pframe in data[:start_frame]..data[:end_frame] fdata = data[pframe] unless fdata fdata = {} data[pframe] = fdata end last.each { |k,v| fdata[k] = v unless fdata.has_key?(k) } fdata.each { |k,v| last[k] = v } end } # Flatten materials data @materials_data.each { |material, data| next if !data[:start_frame] || !data[:end_frame] last = {} for pframe in data[:start_frame]..data[:end_frame] fdata = data[pframe] unless fdata fdata = {} data[pframe] = fdata end last.each { |k,v| fdata[k] = v unless fdata.has_key?(k) } fdata.each { |k,v| last[k] = v } end } # Flatten layers data @layers_data.each { |layer, data| next if !data[:start_frame] || !data[:end_frame] last = {} for pframe in data[:start_frame]..data[:end_frame] fdata = data[pframe] unless fdata fdata = {} data[pframe] = fdata end last.each { |k,v| fdata[k] = v unless fdata.has_key?(k) } fdata.each { |k,v| last[k] = v } end } # Flatten camera data if @camera_data[:start_frame] && @camera_data[:end_frame] last = {} for pframe in @camera_data[:start_frame]..@camera_data[:end_frame] fdata = @camera_data[pframe] unless fdata fdata = {} @camera_data[pframe] = fdata end last.each { |k,v| fdata[k] = v unless fdata.has_key?(k) } fdata.each { |k,v| last[k] = v } end end # Flatten render data if @render_data[:start_frame] && @render_data[:end_frame] last = {} for pframe in @render_data[:start_frame]..@render_data[:end_frame] fdata = @render_data[pframe] unless fdata fdata = {} @render_data[pframe] = fdata end last.each { |k,v| fdata[k] = v unless fdata.has_key?(k) } fdata.each { |k,v| last[k] = v } end end # Flatten shadow data if @shadow_data[:start_frame] && @shadow_data[:end_frame] last = {} for pframe in @shadow_data[:start_frame]..@shadow_data[:end_frame] fdata = @shadow_data[pframe] unless fdata fdata = {} @shadow_data[pframe] = fdata end last.each { |k,v| fdata[k] = v unless fdata.has_key?(k) } fdata.each { |k,v| last[k] = v } end end end |
.frame ⇒ Numeric
Get replay animation frame.
583 584 585 |
# File 'RubyExtension/MSPhysics/replay.rb', line 583 def frame @frame end |
.frame=(value) ⇒ Object
Set replay animation frame.
589 590 591 |
# File 'RubyExtension/MSPhysics/replay.rb', line 589 def frame=(value) @frame = value.to_f end |
.get_camera_data(pframe) ⇒ Hash?
Get camera data at a particular frame.
1666 1667 1668 |
# File 'RubyExtension/MSPhysics/replay.rb', line 1666 def get_camera_data(pframe) get_frame_data(@camera_data, pframe) end |
.get_frame_data(data, pframe) ⇒ Hash?
Get data at a particular frame.
1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 |
# File 'RubyExtension/MSPhysics/replay.rb', line 1619 def get_frame_data(data, pframe) pframe = pframe.to_i fdata = data[pframe] return fdata if fdata ld = nil data.each { |f, d| next if !f.is_a?(Integer) return d if pframe < f return ld if pframe == f ld = d } ld end |
.get_group_data(group, pframe) ⇒ Hash?
Get group/component data at a particular frame.
1637 1638 1639 1640 1641 |
# File 'RubyExtension/MSPhysics/replay.rb', line 1637 def get_group_data(group, pframe) data = @groups_data[group] return unless data get_frame_data(data, pframe) end |
.get_layer_data(layer, pframe) ⇒ Hash?
Get layer data at a particular frame.
1657 1658 1659 1660 1661 |
# File 'RubyExtension/MSPhysics/replay.rb', line 1657 def get_layer_data(layer, pframe) data = @layers_data[layer] return unless data get_frame_data(data, pframe) end |
.get_material_data(material, pframe) ⇒ Hash?
Get material data at a particular frame.
1647 1648 1649 1650 1651 |
# File 'RubyExtension/MSPhysics/replay.rb', line 1647 def get_material_data(material, pframe) data = @materials_data[group] return unless data get_frame_data(data, pframe) end |
.get_render_data(pframe) ⇒ Hash?
Get render data at a particular frame.
1673 1674 1675 |
# File 'RubyExtension/MSPhysics/replay.rb', line 1673 def get_render_data(pframe) get_frame_data(@render_data, pframe) end |
.get_shadow_data(pframe) ⇒ Hash?
Get shadow data at a particular frame.
1680 1681 1682 |
# File 'RubyExtension/MSPhysics/replay.rb', line 1680 def get_shadow_data(pframe) get_frame_data(@shadow_data, pframe) end |
.groups_data_valid? ⇒ Boolean
Determine whether groups data is not empty.
1686 1687 1688 |
# File 'RubyExtension/MSPhysics/replay.rb', line 1686 def groups_data_valid? @groups_data.size > 0 end |
.groups_record_enabled=(state) ⇒ Object
Enable/disable groups recording.
439 440 441 |
# File 'RubyExtension/MSPhysics/replay.rb', line 439 def groups_record_enabled=(state) @record_groups = state ? true : false end |
.groups_record_enabled? ⇒ Boolean
Determine whether groups recording is enabled.
445 446 447 |
# File 'RubyExtension/MSPhysics/replay.rb', line 445 def groups_record_enabled? @record_groups end |
.groups_replay_enabled=(state) ⇒ Object
Enable/disable groups replay.
511 512 513 |
# File 'RubyExtension/MSPhysics/replay.rb', line 511 def groups_replay_enabled=(state) @replay_groups = state ? true : false end |
.groups_replay_enabled? ⇒ Boolean
Determine whether groups replay is enabled.
517 518 519 |
# File 'RubyExtension/MSPhysics/replay.rb', line 517 def groups_replay_enabled? @replay_groups end |
.layers_data_valid? ⇒ Boolean
Determine whether layers data is not empty.
1698 1699 1700 |
# File 'RubyExtension/MSPhysics/replay.rb', line 1698 def layers_data_valid? @layers_data.size > 0 end |
.layers_record_enabled=(state) ⇒ Object
Enable/disable layers recording.
463 464 465 |
# File 'RubyExtension/MSPhysics/replay.rb', line 463 def layers_record_enabled=(state) @record_layers = state ? true : false end |
.layers_record_enabled? ⇒ Boolean
Determine whether layers recording is enabled.
469 470 471 |
# File 'RubyExtension/MSPhysics/replay.rb', line 469 def layers_record_enabled? @record_layers end |
.layers_replay_enabled=(state) ⇒ Object
Enable/disable layers replay.
535 536 537 |
# File 'RubyExtension/MSPhysics/replay.rb', line 535 def layers_replay_enabled=(state) @replay_layers = state ? true : false end |
.layers_replay_enabled? ⇒ Boolean
Determine whether layers replay is enabled.
541 542 543 |
# File 'RubyExtension/MSPhysics/replay.rb', line 541 def layers_replay_enabled? @replay_layers end |
.load_data_from_file ⇒ Boolean
Load saved data from file.
1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 |
# File 'RubyExtension/MSPhysics/replay.rb', line 1416 def load_data_from_file model = Sketchup.active_model return false if model.path.empty? dict = 'MSPhysics Replay' # Parse path to the current model. model_path = model.path.gsub(/\\/, '/') mspr_path = File.dirname(model_path) mspr_name = File.basename(model_path, '.skp') + '.mspreplay' mspr_fpath = File.join(mspr_path, mspr_name) # Return if file doesn't exist. return false unless File.exists?(mspr_fpath) # Notify Sketchup.set_status_text("Loading Replay data from file. This might take a while...", SB_PROMPT) # Clear active data @groups_data.clear @materials_data.clear @layers_data.clear @camera_data.clear @render_data.clear @shadow_data.clear # Read from file mspr_data = {} gz = File.open(mspr_fpath, 'r') begin gz.each_line { |line| res = eval(line) res.each { |k, v| if mspr_data[k] v.each { |sk, sv| mspr_data[k][sk] = sv } else mspr_data[k] = v end } } ensure gz.close end # Verify ID if mspr_data[:id] != model.get_attribute(dict, 'ID') return false end # Load general info @start_frame = mspr_data[:start_frame].is_a?(Integer) ? mspr_data[:start_frame] : nil @end_frame = mspr_data[:end_frame].is_a?(Integer) ? mspr_data[:end_frame] : nil # Load IDs id_to_grp = {} id_to_def = {} id_to_mat = {} id_to_lay = {} model.entities.each { |e| if e.is_a?(Sketchup::Group) || e.is_a?(Sketchup::ComponentInstance) id = e.get_attribute(dict, 'ID') id_to_grp[id] = e if id.is_a?(Integer) end } model.definitions.each { |d| ids = d.get_attribute(dict, 'IDs') if ids.is_a?(Array) ids.each { |id| id_to_def[id] = d if id.is_a?(Integer) } end } model.materials.each { |mat| id = mat.get_attribute(dict, 'ID') id_to_mat[id] = mat if id.is_a?(Integer) } model.layers.each { |lay| id = lay.get_attribute(dict, 'ID') id_to_lay[id] = lay if id.is_a?(Integer) } # Load groups mspr_data[:groups_data].each { |id, gdata| g = id_to_grp[id] d = id_to_def[id] gdata[:id] = id gdata[:definition] = d if d gdata.each { |pframe, fdata| next unless pframe.is_a?(Integer) if fdata[:layer].is_a?(Integer) lay = id_to_lay[fdata[:layer]] if lay fdata[:layer] = lay else fdata.delete(:layer) end end if fdata[:material].is_a?(Integer) mat = id_to_mat[fdata[:material]] fdata[:material] = mat if mat end } @groups_data[g ? g : id] = gdata } # Load materials mspr_data[:materials_data].each { |id, gdata| g = id_to_mat[id] gdata[:id] = id @materials_data[g ? g : id] = gdata } # Load layers mspr_data[:layers_data].each { |id, gdata| g = id_to_lay[id] gdata[:id] = id @layers_data[g ? g : id] = gdata } # Load camera @camera_data = mspr_data[:camera_data] # Load render @render_data = mspr_data[:render_data] # Load shadow @shadow_data = mspr_data[:shadow_data] # Flatten all data flatten_active_data # Return success true end |
.load_replay_proc ⇒ void
This method returns an undefined value.
Load settings and data procedure.
2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 |
# File 'RubyExtension/MSPhysics/replay.rb', line 2640 def load_replay_proc MSPhysics::Replay.stop MSPhysics::Replay.clear_recorded_data MSPhysics::Replay.clear_active_data MSPhysics::Replay.reset_replay_settings begin MSPhysics::Replay.load_replay_settings MSPhysics::Replay.load_data_from_file rescue Exception => err MSPhysics::Replay.clear_recorded_data MSPhysics::Replay.clear_active_data MSPhysics::Replay.reset_replay_settings MSPhysics::Replay.clear_data_from_model(true, true) MSPhysics::Replay.clear_data_from_file = err. err_backtrace = err.backtrace unless AMS::IS_RUBY_VERSION_18 .force_encoding('UTF-8') err_backtrace.each { |i| i.force_encoding('UTF-8') } end msg = "An error occurred while loading MSPhysics Replay data.\n#{err.class}:\n#{}\nBacktrace:\n#{err_backtrace.join("\n")}\n\nThis error could be a result of the saved Replay data being irrelevant with the current MSPhysics version." puts msg ::UI.(msg) end end |
.load_replay_settings ⇒ void
This method returns an undefined value.
Load replay settings from model dictionary.
2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 |
# File 'RubyExtension/MSPhysics/replay.rb', line 2604 def load_replay_settings model = Sketchup.active_model dict = 'MSPhysics Replay' @record_groups = model.get_attribute(dict, 'Record Group', DEFAULT_RECORD_GROUPS) ? true : false @record_materials = model.get_attribute(dict, 'Record Materials', DEFAULT_RECORD_MATERIALS) ? true : false @record_layers = model.get_attribute(dict, 'Record Layers', DEFAULT_RECORD_LAYERS) ? true : false @record_camera = model.get_attribute(dict, 'Record Camera', DEFAULT_RECORD_CAMERA) ? true : false @record_render = model.get_attribute(dict, 'Record Render', DEFAULT_RECORD_RENDER) ? true : false @record_shadow = model.get_attribute(dict, 'Record Shadow', DEFAULT_RECORD_SHADOW) ? true : false @replay_groups = model.get_attribute(dict, 'Replay Group', DEFAULT_REPLAY_GROUPS) ? true : false @replay_materials = model.get_attribute(dict, 'Replay Materials', DEFAULT_REPLAY_MATERIALS) ? true : false @replay_layers = model.get_attribute(dict, 'Replay Layers', DEFAULT_REPLAY_LAYERS) ? true : false @replay_camera = model.get_attribute(dict, 'Replay Camera', DEFAULT_REPLAY_CAMERA) ? true : false @replay_render = model.get_attribute(dict, 'Replay Render', DEFAULT_REPLAY_RENDER) ? true : false @replay_shadow = model.get_attribute(dict, 'Replay Shadow', DEFAULT_REPLAY_SHADOW) ? true : false end |
.materials_data_valid? ⇒ Boolean
Determine whether materials data is not empty.
1692 1693 1694 |
# File 'RubyExtension/MSPhysics/replay.rb', line 1692 def materials_data_valid? @materials_data.size > 0 end |
.materials_record_enabled=(state) ⇒ Object
Enable/disable materials recording.
451 452 453 |
# File 'RubyExtension/MSPhysics/replay.rb', line 451 def materials_record_enabled=(state) @record_materials = state ? true : false end |
.materials_record_enabled? ⇒ Boolean
Determine whether materials recording is enabled.
457 458 459 |
# File 'RubyExtension/MSPhysics/replay.rb', line 457 def materials_record_enabled? @record_materials end |
.materials_replay_enabled=(state) ⇒ Object
Enable/disable materials replay.
523 524 525 |
# File 'RubyExtension/MSPhysics/replay.rb', line 523 def materials_replay_enabled=(state) @replay_materials = state ? true : false end |
.materials_replay_enabled? ⇒ Boolean
Determine whether materials replay is enabled.
529 530 531 |
# File 'RubyExtension/MSPhysics/replay.rb', line 529 def materials_replay_enabled? @replay_materials end |
.pause ⇒ Boolean
Pause replay animation.
362 363 364 365 366 367 368 369 370 371 372 373 374 |
# File 'RubyExtension/MSPhysics/replay.rb', line 362 def pause return false unless @active @paused = true # Commit operation if @wop_started Sketchup.active_model.commit_operation @wop_started = false end # Show trays AMS::Sketchup.show_trays(true) if AMS::IS_PLATFORM_WINDOWS # Return success true end |
.paused? ⇒ Boolean
Determine whether replay animation is paused.
391 392 393 |
# File 'RubyExtension/MSPhysics/replay.rb', line 391 def paused? @active && @paused end |
.play(activate_animation = true) ⇒ Boolean
Play replay animation.
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 |
# File 'RubyExtension/MSPhysics/replay.rb', line 342 def play(activate_animation = true) return false unless @active @paused = false model = Sketchup.active_model # Wrap in operation block unless @wop_started op = 'MSPhysics Replay' Sketchup.version.to_i > 6 ? model.start_operation(op, true, false, false) : model.start_operation(op) @wop_started = true end # Hide trays AMS::Sketchup.show_trays(false) if AMS::IS_PLATFORM_WINDOWS # Activate tool @animation.activate_tool if activate_animation # Return success true end |
.playing? ⇒ Boolean
Determine whether replay animation is playing.
385 386 387 |
# File 'RubyExtension/MSPhysics/replay.rb', line 385 def @active && !@paused end |
.preset_definition(instance, definition) ⇒ Object
When emitting groups, it would help to know their source, as as definitions often get purged.
772 773 774 |
# File 'RubyExtension/MSPhysics/replay.rb', line 772 def preset_definition(instance, definition) @preset_definitions[instance] = definition end |
.record_all(pframe) ⇒ Object
Record groups, camera, materials, layers, render, and shadow based on whether their recording is enabled.
759 760 761 762 763 764 765 766 |
# File 'RubyExtension/MSPhysics/replay.rb', line 759 def record_all(pframe) record_groups(pframe) record_materials(pframe) if @record_materials record_layers(pframe) if @record_layers record_camera(pframe) if @record_camera record_render(pframe) if @record_render record_shadow(pframe) if @record_shadow end |
.record_camera(pframe) ⇒ Object
Record camera.
715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 |
# File 'RubyExtension/MSPhysics/replay.rb', line 715 def record_camera(pframe) camera = Sketchup.active_model.active_view.camera data = { :eye => camera.eye, :target => camera.target, :up => camera.up, :perspective => camera.perspective?, :aspect_ratio => camera.aspect_ratio, :xaxis => camera.xaxis, :yaxis => camera.yaxis, :zaxis => camera.zaxis } if camera.perspective? data[:focal_length] = camera.focal_length data[:fov] = camera.fov data[:image_width] = camera.image_width else data[:height] = camera.height end @tcamera_data[pframe] = data update_data_frame_limits(@tcamera_data, pframe) end |
.record_enabled=(state) ⇒ Object
Enable/disable simulation recording.
427 428 429 |
# File 'RubyExtension/MSPhysics/replay.rb', line 427 def record_enabled=(state) @record = state ? true : false end |
.record_enabled? ⇒ Boolean
Determine whether simulation recording is enabled.
433 434 435 |
# File 'RubyExtension/MSPhysics/replay.rb', line 433 def record_enabled? @record end |
.record_group(group, pframe) ⇒ Object
Record group/component.
628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 |
# File 'RubyExtension/MSPhysics/replay.rb', line 628 def record_group(group, pframe) data = @tgroups_data[group] unless data @tgroups_data[group] = {} data = @tgroups_data[group] data[:id] = group.entityID data[:definition] = @preset_definitions[group] || AMS::Group.get_definition(group) end pdata = {} data[pframe] = pdata pdata[:transformation] = group.transformation if @record_groups pdata[:visible] = group.visible? pdata[:material] = group.material ? group.material : 0 pdata[:layer] = group.layer ? group.layer : 0 end update_data_frame_limits(data, pframe) end |
.record_groups(pframe) ⇒ Object
Record all groups.
649 650 651 652 653 654 655 656 |
# File 'RubyExtension/MSPhysics/replay.rb', line 649 def record_groups(pframe) Sketchup.active_model.definitions.each { |d| d.instances.each { |i| next if i.get_attribute('MSPhysics Body', 'Ignore') || i.get_attribute('MSPhysics Joint', 'Type') record_group(i, pframe) } } end |
.record_layer(layer, pframe) ⇒ Object
Record layer.
693 694 695 696 697 698 699 700 701 702 703 |
# File 'RubyExtension/MSPhysics/replay.rb', line 693 def record_layer(layer, pframe) data = @tlayers_data[layer] unless data @tlayers_data[layer] = {} data = @tlayers_data[layer] data[:id] = layer.entityID end data[pframe] = { :visible => layer.visible? } data[pframe][:color] = layer.color if Sketchup.version.to_i > 13 update_data_frame_limits(data, pframe) end |
.record_layers(pframe) ⇒ Object
Record all layers.
707 708 709 710 711 |
# File 'RubyExtension/MSPhysics/replay.rb', line 707 def record_layers(pframe) Sketchup.active_model.layers.each { |l| record_layer(l, pframe) } end |
.record_material(material, pframe) ⇒ Object
Record material.
661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 |
# File 'RubyExtension/MSPhysics/replay.rb', line 661 def record_material(material, pframe) data = @tmaterials_data[material] unless data @tmaterials_data[material] = {} data = @tmaterials_data[material] data[:id] = material.entityID end t = material.texture data[pframe] = { :color => material.color, :alpha => material.alpha, :texture => t ? t.filename : nil, :width => t ? t.width : nil, :height => t ? t.height : nil } if Sketchup.version.to_i >= 15 data[pframe][:colorize_type] = material.colorize_type end update_data_frame_limits(data, pframe) end |
.record_materials(pframe) ⇒ Object
Record all materials.
684 685 686 687 688 |
# File 'RubyExtension/MSPhysics/replay.rb', line 684 def record_materials(pframe) Sketchup.active_model.materials.each { |m| record_material(m, pframe) } end |
.record_render(pframe) ⇒ Object
Record rendering options.
740 741 742 743 744 745 |
# File 'RubyExtension/MSPhysics/replay.rb', line 740 def record_render(pframe) data = {} Sketchup.active_model..each { |k, v| data[k] = v } @trender_data[pframe] = data update_data_frame_limits(@trender_data, pframe) end |
.record_shadow(pframe) ⇒ Object
Record shadow info.
749 750 751 752 753 754 |
# File 'RubyExtension/MSPhysics/replay.rb', line 749 def record_shadow(pframe) data = {} Sketchup.active_model.shadow_info.each { |k, v| data[k] = v } @tshadow_data[pframe] = data update_data_frame_limits(@tshadow_data, pframe) end |
.recorded_data_valid? ⇒ Boolean
Determine whether recorded data is not empty.
415 416 417 |
# File 'RubyExtension/MSPhysics/replay.rb', line 415 def recorded_data_valid? @tgroups_data.size > 0 || @tmaterials_data.size > 0 || @tlayers_data.size > 0 || @tcamera_data.size > 0 || @trender_data.size > 0 || @tshadow_data.size > 0 end |
.render_data_valid? ⇒ Boolean
Determine whether render data is not empty.
1710 1711 1712 |
# File 'RubyExtension/MSPhysics/replay.rb', line 1710 def render_data_valid? @render_data[:start_frame] && @render_data[:end_frame] ? true : false end |
.render_record_enabled=(state) ⇒ Object
Enable/disable render recording.
487 488 489 |
# File 'RubyExtension/MSPhysics/replay.rb', line 487 def render_record_enabled=(state) @record_render = state ? true : false end |
.render_record_enabled? ⇒ Boolean
Determine whether render recording is enabled.
493 494 495 |
# File 'RubyExtension/MSPhysics/replay.rb', line 493 def render_record_enabled? @record_render end |
.render_replay_enabled=(state) ⇒ Object
Enable/disable replay of rendering options.
559 560 561 |
# File 'RubyExtension/MSPhysics/replay.rb', line 559 def render_replay_enabled=(state) @replay_render = state ? true : false end |
.render_replay_enabled? ⇒ Boolean
Determine whether replay of rendering options is enabled.
565 566 567 |
# File 'RubyExtension/MSPhysics/replay.rb', line 565 def render_replay_enabled? @replay_render end |
.reset ⇒ Boolean
Stop replay animation and reset entity positions.
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 |
# File 'RubyExtension/MSPhysics/replay.rb', line 211 def reset return false unless @active # Reset Variables @active = false @paused = false @reversed = false @frame = 0 # Shortcuts model = Sketchup.active_model view = model.active_view camera = view.camera # Hide trays AMS::Sketchup.show_trays(false) if AMS::IS_PLATFORM_WINDOWS # Wrap in operation block unless @wop_started op = 'MSPhysics Replay' Sketchup.version.to_i > 6 ? model.start_operation(op, true, false, false) : model.start_operation(op) @wop_started = true end # Stop animation @animation.deactivate_tool # Reset selected page if @selected_page && @selected_page.valid? tt = @selected_page.transition_time @selected_page.transition_time = 0 model.pages.selected_page = @selected_page @selected_page.transition_time = tt @selected_page = nil end # Reset group data @groups_data.each { |group, data| instance = data[:instance] data.delete(:instance) if (group.is_a?(Sketchup::Group) || group.is_a?(Sketchup::ComponentInstance)) && group.valid? orig_data = data[:original] next if orig_data.nil? group.move!(orig_data[:transformation]) #~ group.transformation = orig_data[:transformation] group.visible = orig_data[:visible] if group.visible? != orig_data[:visible] if orig_data[:material].nil? group.material = nil if group.material elsif orig_data[:material].valid? group.material = orig_data[:material] if group.material != orig_data[:material] end group.layer = orig_data[:layer] if orig_data[:layer].valid? && group.layer != orig_data[:layer] data.delete(:original) end if instance && instance.valid? instance.material = nil if instance.material instance.erase! end } # Reset material data @materials_data.each { |material, data| instance = data[:instance] data.delete(:instance) if material.is_a?(Sketchup::Material) && material.valid? orig_data = data[:original] next if orig_data.nil? material.color = orig_data[:color] if material.color.to_i != orig_data[:color].to_i material.alpha = orig_data[:alpha] if material.alpha != orig_data[:alpha] if material.texture material.texture = orig_data[:texture] if material.texture.filename != orig_data[:texture] else material.texture = orig_data[:texture] if orig_data[:texture] end if material.texture && (material.texture.width != orig_data[:width] || material.texture.height != orig_data[:height]) material.texture.size = [orig_data[:width], orig_data[:height]] end if Sketchup.version.to_i >= 15 && material.colorize_type != orig_data[:colorize_type] material.colorize_type = orig_data[:colorize_type] end data.delete(:original) end if instance && instance.valid? && Sketchup.version.to_i >= 14 model.materials.remove(instance) end } if Sketchup.version.to_i < 14 model.materials.purge_unused end # Reset layer data @layers_data.each { |layer, data| next if !(layer.is_a?(Sketchup::Layer) && layer.valid?) orig_data = data[:original] next if orig_data.nil? layer.visible = orig_data[:visible] if layer.visible? != orig_data[:visible] if Sketchup.version.to_i > 13 && layer.color.to_i != orig_data[:color].to_i layer.color = orig_data[:color] end data.delete(:original) } # Reset camera data data = @camera_data[:original] if data camera.set(data[:eye], data[:target], data[:up]) camera.perspective = data[:perspective] #camera.aspect_ratio = data[:aspect_ratio] if camera.perspective? camera.focal_length = data[:focal_length] camera.fov = data[:fov] camera.image_width = data[:image_width] else camera.height = data[:height] end end @camera_data.delete(:original) # Reset render data if @render_data[:original] @render_data[:original].each { |k, v| model.[k] = v if model.[k] != v } end @render_data.delete(:original) # Reset shadow data if @shadow_data[:original] @shadow_data[:original].each { |k, v| model.shadow_info[k] = v if model.shadow_info[k] != v } end @shadow_data.delete(:original) # Commit operation if @wop_started model.commit_operation @wop_started = false end # Show trays AMS::Sketchup.show_trays(true) if AMS::IS_PLATFORM_WINDOWS # Return success true end |
.reset_replay_settings ⇒ void
This method returns an undefined value.
Reset replay settings.
2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 |
# File 'RubyExtension/MSPhysics/replay.rb', line 2623 def reset_replay_settings @record_groups = DEFAULT_RECORD_GROUPS @record_materials = DEFAULT_RECORD_MATERIALS @record_layers = DEFAULT_RECORD_LAYERS @record_camera = DEFAULT_RECORD_CAMERA @record_render = DEFAULT_RECORD_RENDER @record_shadow = DEFAULT_RECORD_SHADOW @replay_groups = DEFAULT_REPLAY_GROUPS @replay_materials = DEFAULT_REPLAY_MATERIALS @replay_layers = DEFAULT_REPLAY_LAYERS @replay_camera = DEFAULT_REPLAY_CAMERA @replay_render = DEFAULT_REPLAY_RENDER @replay_shadow = DEFAULT_REPLAY_SHADOW end |
.reversed=(state) ⇒ Object
Reverse replay animation.
397 398 399 |
# File 'RubyExtension/MSPhysics/replay.rb', line 397 def reversed=(state) @reversed = state ? true : false end |
.reversed? ⇒ Boolean
Determine whether replay animation is reversed.
403 404 405 |
# File 'RubyExtension/MSPhysics/replay.rb', line 403 def reversed? @reversed end |
.save_data_to_file(wrap_in_op = true) ⇒ Boolean
Save active data into file.
1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 |
# File 'RubyExtension/MSPhysics/replay.rb', line 1028 def save_data_to_file(wrap_in_op = true) op_started = false model = Sketchup.active_model return false if model.path.empty? dict = 'MSPhysics Replay' # Parse path to the current model. model_path = model.path.gsub(/\\/, '/') mspr_path = File.dirname(model_path) mspr_name = File.basename(model_path, '.skp') + '.mspreplay' mspr_fpath = File.join(mspr_path, mspr_name) # Start operation if wrap_in_op op = 'Saving MSPhysics Replay' Sketchup.version.to_i > 6 ? model.start_operation(op, true, false, false) : model.start_operation(op) op_started = true end # Notify Sketchup.set_status_text("Saving Replay data to file. This might take a while...", SB_PROMPT) # Create temporary variables to store unique information. fgroups_data = {} fmaterials_data = {} flayers_data = {} fcamera_data = {} frender_data = {} fshadow_data = {} # Filter groups data @groups_data.each { |group, data| gdata = {} gdata[:id] = data[:id] gdata[:definition] = data[:definition] if data[:definition] gdata[:start_frame] = data[:start_frame] if data[:start_frame] gdata[:end_frame] = data[:end_frame] if data[:end_frame] last = {} data.each { |pframe, fdata| next unless pframe.is_a?(Integer) sdata = {} fdata.each { |k, v| if v.is_a?(Sketchup::Material) || v.is_a?(Sketchup::Layer) v2 = v.__id__ elsif v.is_a?(Geom::Transformation) v2 = v.to_a else v2 = v end next if last.has_key?(k) && last[k] == v2 sdata[k] = v last[k] = v2 } gdata[pframe] = sdata unless sdata.empty? } fgroups_data[group] = gdata } # Filter materials data @materials_data.each { |material, data| gdata = {} gdata[:id] = data[:id] gdata[:start_frame] = data[:start_frame] if data[:start_frame] gdata[:end_frame] = data[:end_frame] if data[:end_frame] last = {} data.each { |pframe, fdata| next unless pframe.is_a?(Integer) sdata = {} fdata.each { |k, v| v2 = v.is_a?(Sketchup::Color) ? v.to_a : v next if last.has_key?(k) && last[k] == v2 sdata[k] = v last[k] = v2 } gdata[pframe] = sdata unless sdata.empty? } fmaterials_data[material] = gdata } # Filter layers data @layers_data.each { |layer, data| gdata = {} gdata[:id] = data[:id] gdata[:start_frame] = data[:start_frame] if data[:start_frame] gdata[:end_frame] = data[:end_frame] if data[:end_frame] last = {} data.each { |pframe, fdata| next unless pframe.is_a?(Integer) sdata = {} fdata.each { |k, v| v2 = v.is_a?(Sketchup::Color) ? v.to_a : v next if last.has_key?(k) && last[k] == v2 sdata[k] = v last[k] = v2 } gdata[pframe] = sdata unless sdata.empty? } flayers_data[layer] = gdata } # Filter camera data fcamera_data[:start_frame] = @camera_data[:start_frame] if @camera_data[:start_frame] fcamera_data[:end_frame] = @camera_data[:end_frame] if @camera_data[:end_frame] last = {} @camera_data.each { |pframe, fdata| next unless pframe.is_a?(Integer) sdata = {} fdata.each { |k, v| next if last.has_key?(k) && last[k] == v sdata[k] = v last[k] = v } fcamera_data[pframe] = sdata unless sdata.empty? } # Filter render data frender_data[:start_frame] = @render_data[:start_frame] if @render_data[:start_frame] frender_data[:end_frame] = @render_data[:end_frame] if @render_data[:end_frame] last = {} @render_data.each { |pframe, fdata| next unless pframe.is_a?(Integer) sdata = {} fdata.each { |k, v| v2 = v.is_a?(Sketchup::Color) ? v.to_a : v next if last.has_key?(k) && last[k] == v2 sdata[k] = v last[k] = v2 } frender_data[pframe] = sdata unless sdata.empty? } # Filter shadow data fshadow_data[:start_frame] = @shadow_data[:start_frame] if @shadow_data[:start_frame] fshadow_data[:end_frame] = @shadow_data[:end_frame] if @shadow_data[:end_frame] last = {} @shadow_data.each { |pframe, fdata| next unless pframe.is_a?(Integer) sdata = {} fdata.each { |k, v| v2 = v.is_a?(Sketchup::Color) ? v.to_a : v next if last.has_key?(k) && last[k] == v2 sdata[k] = v last[k] = v2 } fshadow_data[pframe] = sdata unless sdata.empty? } # Save unique ID to model. unique_id = 100000 + rand(100000) model.set_attribute(dict, 'ID', unique_id) # Create a file gz = File.open(mspr_fpath, 'w') gz.puts "{:id=>#{unique_id}}" # Save main info gz.puts "{:start_frame=>#{@start_frame}}" if @start_frame gz.puts "{:end_frame=>#{@end_frame}}" if @end_frame # Save groups fgroups_data.each { |group, data| next if !(((group.is_a?(Sketchup::Group) || group.is_a?(Sketchup::ComponentInstance)) && group.valid?) || (data[:definition] && data[:definition].valid?)) str = "{:groups_data=>{" str << "#{data[:id]}=>{" str << ":start_frame=>#{data[:start_frame]}," if data[:start_frame] str << ":end_frame=>#{data[:end_frame]}," if data[:end_frame] data.each { |pframe, fdata| next unless pframe.is_a?(Integer) str << "#{pframe}=>{" fdata.each { |k, v| res = nil if v.is_a?(Length) res = v.to_f.to_s elsif v.is_a?(Numeric) res = v.to_s elsif v.is_a?(Sketchup::Layer) if flayers_data[v] res = flayers_data[v][:id].to_s elsif v.valid? res = v.entityID.to_s else next end elsif v.is_a?(Sketchup::Material) if fmaterials_data[v] res = fmaterials_data[v][:id].to_s elsif v.valid? res = v.entityID.to_s else next end elsif v.is_a?(Sketchup::Color) res = "Sketchup::Color.new(#{v.red},#{v.green},#{v.blue},#{v.alpha})" elsif v.is_a?(Geom::Transformation) res = "Geom::Transformation.new(#{v.to_a.inspect})" elsif v.is_a?(Geom::Point3d) res = "Geom::Point3d.new(#{v.x.to_f},#{v.y.to_f},#{v.z.to_f})" elsif v.is_a?(Geom::Vector3d) res = "Geom::Vector3d.new(#{v.x.to_f},#{v.y.to_f},#{v.z.to_f})" else res = v.inspect end #res.gsub!(/\s/, '') res.gsub!('Infinity', '1.0/0.0') res.gsub!('NaN', '0.0/0.0') str << "#{k.inspect}=>#{res}," } str << "}," } str << "}}}" gz.puts str if (group.is_a?(Sketchup::Group) || group.is_a?(Sketchup::ComponentInstance)) && group.valid? group.set_attribute(dict, 'ID', data[:id]) else ids = data[:definition].get_attribute(dict, 'IDs') if ids.is_a?(Array) ids << data[:id] else ids = [data[:id]] end data[:definition].set_attribute(dict, 'IDs', ids) end } # Save materials saved_mats = {} str = "{:materials_data=>{" fmaterials_data.each { |material, data| if material.is_a?(Sketchup::Material) && material.valid? material.set_attribute(dict, 'ID', data[:id]) saved_mats[material] = true end str << "#{data[:id]}=>{" str << ":start_frame=>#{data[:start_frame]}," if data[:start_frame] str << ":end_frame=>#{data[:end_frame]}," if data[:end_frame] data.each { |pframe, fdata| next unless pframe.is_a?(Integer) str << "#{pframe}=>{" fdata.each { |k, v| res = nil if v.is_a?(Length) res = v.to_f.to_s elsif v.is_a?(Numeric) res = v.to_s elsif v.is_a?(Sketchup::Color) res = "Sketchup::Color.new(#{v.red},#{v.green},#{v.blue},#{v.alpha})" else res = v.inspect end #res.gsub!(/\s/, '') res.gsub!('Infinity', '1.0/0.0') res.gsub!('NaN', '0.0/0.0') str << "#{k.inspect}=>#{res}," } str << "}," } str << "}," } str << "}}" gz.puts str # Save layers saved_lays = {} str = "{:layers_data=>{" flayers_data.each { |layer, data| if layer.is_a?(Sketchup::Layer) && layer.valid? layer.set_attribute(dict, 'ID', data[:id]) saved_lays[layer] = true end str << "#{data[:id]}=>{" str << ":start_frame=>#{data[:start_frame]}," if data[:start_frame] str << ":end_frame=>#{data[:end_frame]}," if data[:end_frame] data.each { |pframe, fdata| next unless pframe.is_a?(Integer) str << "#{pframe}=>{" fdata.each { |k, v| res = nil if v.is_a?(Length) res = v.to_f.to_s elsif v.is_a?(Numeric) res = v.to_s elsif v.is_a?(Sketchup::Color) res = "Sketchup::Color.new(#{v.red},#{v.green},#{v.blue},#{v.alpha})" else res = v.inspect end #res.gsub!(/\s/, '') res.gsub!('Infinity', '1.0/0.0') res.gsub!('NaN', '0.0/0.0') str << "#{k.inspect}=>#{res}," } str << "}," } str << "}," } str << "}}" gz.puts str # Save camera str = "{:camera_data=>{" str << ":start_frame=>#{fcamera_data[:start_frame]}," if fcamera_data[:start_frame] str << ":end_frame=>#{fcamera_data[:end_frame]}," if fcamera_data[:end_frame] fcamera_data.each { |pframe, fdata| next unless pframe.is_a?(Integer) str << "#{pframe}=>{" fdata.each { |k, v| res = nil if v.is_a?(Length) res = v.to_f.to_s elsif v.is_a?(Numeric) res = v.to_s elsif v.is_a?(Geom::Point3d) res = "Geom::Point3d.new(#{v.x.to_f},#{v.y.to_f},#{v.z.to_f})" elsif v.is_a?(Geom::Vector3d) res = "Geom::Vector3d.new(#{v.x.to_f},#{v.y.to_f},#{v.z.to_f})" else res = v.inspect end #res.gsub!(/\s/, '') res.gsub!('Infinity', '1.0/0.0') res.gsub!('NaN', '0.0/0.0') str << "#{k.inspect}=>#{res}," } str << "}," } str << "}}" gz.puts str # Save render str = "{:render_data=>{" str << ":start_frame=>#{frender_data[:start_frame]}," if frender_data[:start_frame] str << ":end_frame=>#{frender_data[:end_frame]}," if frender_data[:end_frame] frender_data.each { |pframe, fdata| next unless pframe.is_a?(Integer) str << "#{pframe}=>{" fdata.each { |k, v| res = nil if v.is_a?(Length) res = v.to_f.to_s elsif v.is_a?(Numeric) res = v.to_s elsif v.is_a?(Sketchup::Color) res = "Sketchup::Color.new(#{v.red},#{v.green},#{v.blue},#{v.alpha})" elsif v.is_a?(Geom::Point3d) res = "Geom::Point3d.new(#{v.x.to_f},#{v.y.to_f},#{v.z.to_f})" elsif v.is_a?(Geom::Vector3d) res = "Geom::Vector3d.new(#{v.x.to_f},#{v.y.to_f},#{v.z.to_f})" else res = v.inspect end #res.gsub!(/\s/, '') res.gsub!('Infinity', '1.0/0.0') res.gsub!('NaN', '0.0/0.0') str << "#{k.inspect}=>#{res}," } str << "}," } str << "}}" gz.puts str # Save shadow str = "{:shadow_data=>{" str << ":start_frame=>#{fshadow_data[:start_frame]}," if fshadow_data[:start_frame] str << ":end_frame=>#{fshadow_data[:end_frame]}," if fshadow_data[:end_frame] fshadow_data.each { |pframe, fdata| next unless pframe.is_a?(Integer) str << "#{pframe}=>{" fdata.each { |k, v| res = nil if v.is_a?(Length) res = v.to_f.to_s elsif v.is_a?(Numeric) res = v.to_s elsif v.is_a?(Time) next elsif v.is_a?(Sketchup::Color) res = "Sketchup::Color.new(#{v.red},#{v.green},#{v.blue},#{v.alpha})" elsif v.is_a?(Geom::Point3d) res = "Geom::Point3d.new(#{v.x.to_f},#{v.y.to_f},#{v.z.to_f})" elsif v.is_a?(Geom::Vector3d) res = "Geom::Vector3d.new(#{v.x.to_f},#{v.y.to_f},#{v.z.to_f})" else res = v.inspect end #res.gsub!(/\s/, '') res.gsub!('Infinity', '1.0/0.0') res.gsub!('NaN', '0.0/0.0') str << "#{k.inspect}=>#{res}," } str << "}," } str << "}}" gz.puts str # Close the file gz.close # End operation model.commit_operation if op_started # Return success return true rescue Exception => err model.abort_operation if op_started gz.close if gz && !gz.closed? raise err end |
.save_recorded_data ⇒ Object
Activate recorded data.
777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 |
# File 'RubyExtension/MSPhysics/replay.rb', line 777 def save_recorded_data @groups_data.clear @materials_data.clear @layers_data.clear @camera_data.clear @render_data.clear @shadow_data.clear @start_frame = @tstart_frame @end_frame = @tend_frame # Save groups data @tgroups_data.each { |group, data| gdata = {} gdata[:id] = data[:id] gdata[:definition] = data[:definition] if data[:definition] gdata[:start_frame] = data[:start_frame] gdata[:end_frame] = data[:end_frame] data.keys.grep(Integer).sort.each { |pframe| gdata[pframe] = data[pframe] } @groups_data[group] = gdata } # Save materials data @tmaterials_data.each { |material, data| gdata = {} gdata[:id] = data[:id] gdata[:definition] = data[:definition] if data[:definition] gdata[:start_frame] = data[:start_frame] gdata[:end_frame] = data[:end_frame] data.keys.grep(Integer).sort.each { |pframe| gdata[pframe] = data[pframe] } @materials_data[material] = gdata } # Save layers data @tlayers_data.each { |layer, data| gdata = {} gdata[:id] = data[:id] gdata[:definition] = data[:definition] if data[:definition] gdata[:start_frame] = data[:start_frame] gdata[:end_frame] = data[:end_frame] data.keys.grep(Integer).sort.each { |pframe| gdata[pframe] = data[pframe] } @layers_data[layer] = gdata } # Save camera data @camera_data[:start_frame] = @tcamera_data[:start_frame] @camera_data[:end_frame] = @tcamera_data[:end_frame] @tcamera_data.keys.grep(Integer).sort.each { |pframe| @camera_data[pframe] = @tcamera_data[pframe] } # Save render data @render_data[:start_frame] = @trender_data[:start_frame] @render_data[:end_frame] = @trender_data[:end_frame] @trender_data.keys.grep(Integer).sort.each { |pframe| @render_data[pframe] = @trender_data[pframe] } # Save shadow data @shadow_data[:start_frame] = @tshadow_data[:start_frame] @shadow_data[:end_frame] = @tshadow_data[:end_frame] @tshadow_data.keys.grep(Integer).sort.each { |pframe| @shadow_data[pframe] = @tshadow_data[pframe] } # Flatten all data flatten_active_data end |
.save_replay_settings(wrap_in_op = true) ⇒ void
This method returns an undefined value.
Save replay settings into model dictionary.
2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 |
# File 'RubyExtension/MSPhysics/replay.rb', line 2575 def save_replay_settings(wrap_in_op = true) op_started = false model = Sketchup.active_model if wrap_in_op op = 'Saving MSPhysics Replay Settings' Sketchup.version.to_i > 6 ? model.start_operation(op, true, false, false) : model.start_operation(op) op_started = true end dict = 'MSPhysics Replay' model.set_attribute(dict, 'Record Groups', @record_groups) model.set_attribute(dict, 'Record Materials', @record_materials) model.set_attribute(dict, 'Record Layers', @record_layers) model.set_attribute(dict, 'Record Camera', @record_camera) model.set_attribute(dict, 'Record Render', @record_render) model.set_attribute(dict, 'Record Shadow', @record_shadow) model.set_attribute(dict, 'Replay Groups', @replay_groups) model.set_attribute(dict, 'Replay Materials', @replay_materials) model.set_attribute(dict, 'Replay Layers', @replay_layers) model.set_attribute(dict, 'Replay Camera', @replay_camera) model.set_attribute(dict, 'Replay Render', @replay_render) model.set_attribute(dict, 'Replay Shadow', @replay_shadow) model.commit_operation if wrap_in_op rescue Exception => err model.abort_operation if op_started raise err end |
.shadow_data_valid? ⇒ Boolean
Determine whether shadow data is not empty.
1716 1717 1718 |
# File 'RubyExtension/MSPhysics/replay.rb', line 1716 def shadow_data_valid? @shadow_data[:start_frame] && @shadow_data[:end_frame] ? true : false end |
.shadow_record_enabled=(state) ⇒ Object
Enable/disable shadow recording.
499 500 501 |
# File 'RubyExtension/MSPhysics/replay.rb', line 499 def shadow_record_enabled=(state) @record_shadow = state ? true : false end |
.shadow_record_enabled? ⇒ Boolean
Determine whether shadow recording is enabled.
505 506 507 |
# File 'RubyExtension/MSPhysics/replay.rb', line 505 def shadow_record_enabled? @record_shadow end |
.shadow_replay_enabled=(state) ⇒ Object
Enable/disable replay of shadow info.
571 572 573 |
# File 'RubyExtension/MSPhysics/replay.rb', line 571 def shadow_replay_enabled=(state) @replay_shadow = state ? true : false end |
.shadow_replay_enabled? ⇒ Boolean
Determine whether relay of shadow info is enabled.
577 578 579 |
# File 'RubyExtension/MSPhysics/replay.rb', line 577 def shadow_replay_enabled? @replay_shadow end |
.smoothen_camera_data(interval) ⇒ Boolean
Smoothen the transitioning of active camera data.
969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 |
# File 'RubyExtension/MSPhysics/replay.rb', line 969 def smoothen_camera_data(interval) return false if @camera_data.empty? || @camera_data[:start_frame].nil? interval = AMS.clamp(interval.to_i, 1, nil) sframe = @camera_data[:start_frame] eframe = @camera_data[:end_frame] half_interval = interval / 2 ncamera_data = {} for i in sframe..eframe fdata = get_frame_data(@camera_data, i) nfdata = {} ncamera_data[i] = nfdata fdata_eye = Geom::Point3d.new(fdata[:eye]) fdata_yaxis = Geom::Vector3d.new(fdata[:yaxis]) fdata_zaxis = Geom::Vector3d.new(fdata[:zaxis]) fhi = half_interval fhi = i - sframe if i - fhi < sframe fhi = eframe - i if i + fhi > eframe for j in (i-fhi)..(i+fhi) next if j == i sfdata = get_frame_data(@camera_data, j) sfdata_eye = sfdata[:eye] fdata_eye.x += sfdata_eye.x fdata_eye.y += sfdata_eye.y fdata_eye.z += sfdata_eye.z sfdata_yaxis = sfdata[:yaxis] fdata_yaxis.x += sfdata_yaxis.x fdata_yaxis.y += sfdata_yaxis.y fdata_yaxis.z += sfdata_yaxis.z sfdata_zaxis = sfdata[:zaxis] fdata_zaxis.x += sfdata_zaxis.x fdata_zaxis.y += sfdata_zaxis.y fdata_zaxis.z += sfdata_zaxis.z end nfdata[:eye] = AMS::Geometry.scale_point(fdata_eye, 1.0 / (fhi * 2 + 1)) if fdata_yaxis.length.to_f > MSPhysics::EPSILON fdata_yaxis.normalize! nfdata[:yaxis] = fdata_yaxis nfdata[:up] = fdata_yaxis end if fdata_zaxis.length.to_f > MSPhysics::EPSILON fdata_zaxis.normalize! nfdata[:zaxis] = fdata_zaxis nfdata[:target] = nfdata[:eye] + fdata_zaxis end end ncamera_data.each { |i, nfdata| fdata = @camera_data[i] if fdata nfdata.each { |k, v| fdata[k] = v } else @camera_data[i] = nfdata end } true end |
.speed ⇒ Numeric
Get replay animation speed.
607 608 609 |
# File 'RubyExtension/MSPhysics/replay.rb', line 607 def speed @speed end |
.speed=(value) ⇒ Object
Set replay animation speed.
613 614 615 |
# File 'RubyExtension/MSPhysics/replay.rb', line 613 def speed=(value) @speed = sprintf("%.3f", AMS.clamp(value.to_f, 0.01, 10000)).to_f end |
.start(activate_animation = true) ⇒ Boolean
Start replay animation.
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'RubyExtension/MSPhysics/replay.rb', line 84 def start(activate_animation = true) return false if @active model = Sketchup.active_model MSPhysics::Simulation.reset @active = true # Hide trays AMS::Sketchup.show_trays(false) if AMS::IS_PLATFORM_WINDOWS # Wrap in operation block unless @wop_started op = 'MSPhysics Replay' Sketchup.version.to_i > 6 ? model.start_operation(op, true, false, false) : model.start_operation(op) @wop_started = true end # Close active path if model.active_entities != model.entities state = true while state state = model.close_active end end # Record original material data. count = 0 @materials_data.each { |material, data| if material.is_a?(Sketchup::Material) && material.valid? t = material.texture data[:original] = { :color => material.color, :alpha => material.alpha, :texture => t ? t.filename : nil, :width => t ? t.width : nil, :height => t ? t.height : nil } if Sketchup.version.to_i >= 15 data[:original][:colorize_type] = material.colorize_type end elsif (data[:instance].nil? || data[:instance].deleted?) data[:instance] = model.materials.add("MSPReplay#{sprintf("%04d", count)}") count += 1 end } # Record original layer data. @layers_data.each { |layer, data| if layer.is_a?(Sketchup::Layer) && layer.valid? data[:original] = { :visible => layer.visible? } data[:original][:color] = layer.color if Sketchup.version.to_i > 13 end } # Record original group data. @groups_data.each { |group, data| if (group.is_a?(Sketchup::Group) || group.is_a?(Sketchup::ComponentInstance)) && group.valid? data[:original] = { :transformation => group.transformation, :visible => group.visible?, :material => group.material, :layer => group.layer } group.transformation = group.transformation # Do this once just to be able to undo. group.visible = true if !group.visible? group.move!(0) elsif data[:definition] && data[:definition].valid? && (data[:instance].nil? || data[:instance].deleted?) data[:instance] = model.entities.add_instance(data[:definition], Geom::Transformation.new()) data[:instance].move!(0) end } # Record original camera data. camera = model.active_view.camera data = { :eye => camera.eye, :target => camera.target, :up => camera.up, :perspective => camera.perspective?, :aspect_ratio => camera.aspect_ratio, :xaxis => camera.xaxis, :yaxis => camera.yaxis, :zaxis => camera.zaxis } if camera.perspective? data[:focal_length] = camera.focal_length data[:fov] = camera.fov data[:image_width] = camera.image_width else data[:height] = camera.height end @camera_data[:original] = data # Record original render data. data = {} Sketchup.active_model..each { |k, v| data[k] = v } @render_data[:original] = data # Record original shadow data. data = {} Sketchup.active_model.shadow_info.each { |k, v| data[k] = v } @shadow_data[:original] = data # Set starting frame @frame = @reversed ? @end_frame : @start_frame # Save selected page @selected_page = model.pages.selected_page # Activate animation @animation = MSPhysics::Replay::Animation.new @animation.activate_tool if activate_animation # Return success true end |
.start_frame ⇒ Integer?
Get starting frame of all data recorded.
595 596 597 |
# File 'RubyExtension/MSPhysics/replay.rb', line 595 def start_frame @start_frame end |
.stop ⇒ Boolean
Stop replay animation, but avoid reseting entity positions.
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'RubyExtension/MSPhysics/replay.rb', line 189 def stop return false unless @active # Reset Variables @active = false @paused = false @reversed = false @frame = 0 # Stop animation @animation.deactivate_tool # Commit operation if @wop_started Sketchup.active_model.commit_operation @wop_started = false end # Display trays AMS::Sketchup.show_trays(true) if AMS::IS_PLATFORM_WINDOWS # Return success true end |
.toggle_play ⇒ Boolean
Pause/Resume replay animation.
378 379 380 381 |
# File 'RubyExtension/MSPhysics/replay.rb', line 378 def toggle_play return false unless @active @paused ? play : pause end |