Method: MSPhysics.make_compatible
- Defined in:
- RubyExtension/MSPhysics/main.rb
.make_compatible(wrap_op = true) ⇒ void
This method returns an undefined value.
Make model of previous MSPhysics version compatible with this version.
602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 |
# File 'RubyExtension/MSPhysics/main.rb', line 602 def make_compatible(wrap_op = true) model = Sketchup.active_model bdict = 'MSPhysics Body' # Start operation if wrap_op op = 'MSPhysics - Making Compatible' Sketchup.version.to_i > 6 ? model.start_operation(op, true, false, false) : model.start_operation(op) end # Make changes update_timestep = model.get_attribute('MSPhysics', 'Update Timestep', MSPhysics::DEFAULT_SIMULATION_SETTINGS[:update_timestep]).to_f model.definitions.each { |d| d.instances.each { |i| # Remove unused attributes i.delete_attribute(bdict, 'Connect Closest Joints') # Replace weight control weight_control = i.get_attribute(bdict, 'Weight Control') if weight_control if i.get_attribute(bdict, 'Mass Control').nil? i.set_attribute(bdict, 'Mass Control', weight_control == 'Mass' ? 2 : 1) end i.delete_attribute(bdict, 'Weight Control') end # Replace dynamic friction dynamic_friction = i.get_attribute(bdict, 'Dynamic Friction') if dynamic_friction if i.get_attribute(bdict, 'Kinetic Friction').nil? i.set_attribute(bdict, 'Kinetic Friction', dynamic_friction) end i.delete_attribute(bdict, 'Dynamic Friction') end # Update emitter to use seconds attr = i.get_attribute(bdict, 'Emitter Rate') i.set_attribute(bdict, 'Emitter Rate', attr.to_f * update_timestep) if attr attr = i.get_attribute(bdict, 'Emitter Delay') i.set_attribute(bdict, 'Emitter Delay', attr.to_f * update_timestep) if attr attr = i.get_attribute(bdict, 'Emitter Lifetime') i.set_attribute(bdict, 'Emitter Lifetime', attr.to_f * update_timestep) if attr # Update thruster lock axis to axes attr = i.get_attribute(bdict, 'Thruster Lock Axes') unless attr.nil? i.set_attribute(bdict, 'Thruster Lock Axes', attr) i.delete_attribute(bdict, 'Thruster Lock Axis') end # Update emitter lock axis to axes attr = i.get_attribute(bdict, 'Emitter Lock Axes') unless attr.nil? i.set_attribute(bdict, 'Emitter Lock Axes', attr) i.delete_attribute(bdict, 'Emitter Lock Axis') end # Replace Compound from CD shapes with default shape = i.get_attribute(bdict, 'Shape') if shape == 'Compound from CD' i.delete_attribute(bdict, 'Shape') shape = nil end # Replace shape with shape id to conserve size if shape.is_a?(String) found = false MSPhysics::SHAPES.each { |k, v| if shape == v i.set_attribute(bdict, 'Shape', k) found = true break end } i.delete_attribute(bdict, 'Shape') unless found end } } # Replace exact solver with iterative 4 passes and accurate joint solver if model.get_attribute('MSPhysics', 'Solver Model') == 0 model.set_attribute('MSPhysics', 'Solver Model', 4) unless model.get_attribute('MSPhysics', 'Joint Algorithm') model.set_attribute('MSPhysics', 'Joint Algorithm', 0) end end # Use fast joint algorithm unless set unless model.get_attribute('MSPhysics', 'Joint Algorithm') model.set_attribute('MSPhysics', 'Joint Algorithm', 2) end # End operation model.commit_operation if wrap_op end |