sketchucation logo sketchucation
    • Login
    1. Home
    2. Anton_S
    3. Posts
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    πŸ”Œ Smart Spline | Fluid way to handle splines for furniture design and complex structures. Download
    A
    Offline
    • Profile
    • Following 0
    • Followers 7
    • Topics 52
    • Posts 1,261
    • Groups 2

    Posts

    Recent Best Controversial
    • RE: Pass array to a c/c++ ruby extension

      Everything you pass to ruby and obtain from ruby is in a form of pointers (except for fixed numbers and some literals). So, an array passed to a c extension would be in a form of a pointer. Here is how you would process it:

      static VALUE process_array(VALUE self, VALUE v_array) {
          // Ensure the data passed is an array
          Check_Type(v_array, T_ARRAY);
          // Process the array
          unsigned int array_size = (unsigned int)RARRAY_LEN(v_array);
          for (unsigned int i = 0; i < array_size; ++i) {
              VALUE v_internal_array = rb_ary_entry(v_array, i);
              // Ensure the internal value is an array
              Check_Type(v_internal_array, T_ARRAY);
              // Process the internal array
              unsigned int internal_array_size = (unsigned int)RARRAY_LEN(v_internal_array);
              for (unsigned int j = 0; j < internal_array_size; ++j) {
                  VALUE v_res = rb_ary_entry(v_array, i);
                  int res = NUM2INT(v_res);
                  // Do something
              }
          }
          // Return something (nil in this case)
          return Qnil;
      }
      

      If you want to process an array of Geom::Point3d/Geom::Vector3d objects, you have to access them by their x, y, z interns:

      static VALUE process_array_of_points(VALUE self, VALUE v_array) {
          // Ensure the data passed is an array
          Check_Type(v_array, T_ARRAY);
          // Process the array
          unsigned int array_size = (unsigned int)RARRAY_LEN(v_array);
          for (unsigned int i = 0; i < array_size; ++i) {
              VALUE v_point = rb_ary_entry(v_array, i);
              double x = rb_num2dbl(rb_funcall(v_point, rb_intern("x"), 0));
              double y = rb_num2dbl(rb_funcall(v_point, rb_intern("y"), 0));
              double z = rb_num2dbl(rb_funcall(v_point, rb_intern("z"), 0));
              // Do something
          }
          // Return something (nil in this case)
          return Qnil;
      }
      

      Accessing even an Array object with x,y,z interns will work too, because SketchUp adds these functions to an Array class. So, this second function will work with an array of array, array of Point3d objects, and array of Vector3d objects.

      And then of course, you will have to link them with Ruby in the initiator function:

      void Init_some_lib() {
          VALUE mDacastror = rb_define_module("Dacastror");
      
          rb_define_module_function(mDacastror, "process_array", VALUEFUNC(process_array), 1);
          rb_define_module_function(mDacastror, "process_array_of_points", VALUEFUNC(process_array_of_points), 1);
      }
      

      Note: I did not check this code for typos, so it's up to you to fix it (if there are any).

      Here are a few links to Ruby c++ extension guides:
      http://clalance.blogspot.com/2011/01/writing-ruby-extensions-in-c-part-9.html
      https://silverhammermba.github.io/emberb/c/

      If you search the web, there are plenty of more links on that.

      posted in Developers' Forum
      A
      Anton_S
    • RE: MSPhysics tests and questions

      Wind tests are not possible with MSPhysics. I once came across a plugin dealing with fluid analysis but can't recall the name of it.

      posted in Plugins
      A
      Anton_S
    • RE: MSPhysics 1.0.3 (16 October 2017)

      Hi, Juju! I started working on Drape a few weeks ago. I first wanted to use NewtonDynamics for cloth but then figured to write my own specific purpose physics engine instead. I already got the cloth working. All I need to do now is add contacts and the user interface. Adding the collision contacts is the hardest part, but I'm researching that.

      posted in Plugins
      A
      Anton_S
    • RE: MSPhysics 1.0.3 (16 October 2017)

      Hello, Jon,

      The concept of joints in MSPhysics is similar to SketchyPhysics. If you check out YouTube tutorials on joints in SketchyPhysics, same things could be accomplished through MSPhysics in a similar way, just through using MSPhysics tools.

      So, to create a joint that is relative to another group, first, all arms should be top level groups. Then, within the context of each arm, add a joint and connect it to the next arm. Here, I made a quick tutorial on adding joints to a robot arm:

      For the tutorial, I used the latest version of MSPhysics, which I haven't released yet but the way of doing it is not any different from the current version.

      I know MSPhysics lacks the tutorials on many of its features, but that's because it is still under development. Making a tutorial with an unstable version, would make it obsolete when a better, stable, and more user-friendly version of MSPhysics is released; therefore, I want to finish the stable version first before proceeding to tutorials.

      Best regards,
      Anton

      posted in Plugins
      A
      Anton_S
    • RE: Creating a plaid on a chair - cloth simulator?

      Jorgensen, I haven't started yet. Once I finish with MSPhysics v1.0.0, I will transition to writing this plugin. It will take a lot less time to write as lots of physics engine code snippets will be used from MSPhysics.

      posted in SketchUp Discussions
      A
      Anton_S
    • RE: MS Physics 0.0.9

      Well, since you removed the cells, that initially served as a collision, you will have to apply Convexify to the outer, hollow cylinder. When you do so, ensure that convexified parts are inside the group where the convexified mixer is and that they are not ignored. You can check out the videos at Convexify's homepage for instructions on how to use it.

      posted in SketchUp Discussions
      A
      Anton_S
    • RE: MS Physics 0.0.9

      Hello, Richardo Mosci,

      To fix this, you have to divide the concave cylinder group into sub convex groups, so that the hollow cylinder is made up of additional internal groups. This can be done with Convexify plugin, by fredo6, which automatically divides solid concave shapes into convex groups. Then the top level shape must be set to compound.

      For your model, before using convexity, first divide the outer, hollow cylinder and the inner mixer into separate, internal groups. Then, set the outer cylinder's state to Ignore. You won't need it part of simulation because the green cells will serve as the collision instead. Then ensure that the mixer part is solid (has a valid volume) and doesn't have any invalid geometry. You can use TT Solid Inspector and TT Cleanup for that. Ensuring that the mixer is solid, will yield the proper generation of convex sub-groups when you use the Convexify.

      The fixed versions of your model is attached below. You can also try fixing it yourself, by following the instructions above, so that you know how it's done. Also, next time, use components for the green cells to reduce file size.

      Regards,
      Anton


      TREFOIL.skp

      posted in SketchUp Discussions
      A
      Anton_S
    • RE: MSPhysics disappearing drawing

      Hello, Marc,

      This is because there are hidden objects and/or layers in the model that fall too far away from camera. Unhide them, set their state to ignore (MSPhysics->State->Ignore), and then hide them again.

      If one of the visible objects fall down too far as well, simply add a floor or container below them, so that they don't fall beyond it. Also, enabling continuous collision option, will prevent objects from falling through each other. So, enable it in case they do.

      Anton

      posted in Newbie Forum
      A
      Anton_S
    • RE: Getting rid of grey border on 2d graphic save

      The best way to fix thus is by pasting this command into the Ruby Console:
      Sketchup.active_model.active_view.camera.aspect_ratio = 0

      There is also an option in SkIndigo render settings window, which will do the same thing.

      posted in SketchUp Discussions
      A
      Anton_S
    • RE: MSPhysics 1.0.3 (16 October 2017)

      Ecati,you understood it correctly.

      posted in Plugins
      A
      Anton_S
    • RE: [Plugin] Show and Hide your toolbar

      There is a better plugin, with a lot more features, such as switching SU fullscreen, called AMS Window Settings. But, unfortunately it's only for Windows.

      posted in Plugins
      A
      Anton_S
    • RE: MSPhysics 1.0.3 (16 October 2017)

      Ecati, that's too much joints and collisions. MSPhysics can't handle that much, especially that joints are weak and unstable when are linked into chains. If your intent is to simply play the bike, you should take an approach of making games, where only the essential parts are made to work. All you need is the frame (set to convex hull) and two wheels (set to to sphere shape). The rest could be removed or placed within the frame and set to ignore. Then a few joints, one for steering and two for motors, would guarantee you a fast working bike. But, if your approach is to simulate how the bike works, with all the moving parts, then MSPhysics is definitely not a plugin for that.

      posted in Plugins
      A
      Anton_S
    • RE: Help please. How to get transformation for the face

      There it is, TBoy:

      class BoundsHighlighterTool
      
        def initialize
          @ip = Sketchup;;InputPoint.new
          @hovered_inst = nil
          @global_parent_tra = nil
          @global_bb = nil
          @labb_global_faces = [] # Faces for the local axes aligned bounding box.
          @gabb_global_faces = [] # Faces for the global axes aligned bounding box.
          @labb_global_edges = []
          @gabb_global_edges = []
          @labb_face_color = Sketchup;;Color.new(255,40,0,80)
          @gabb_face_color = Sketchup;;Color.new(0,40,255,80)
          @labb_edge_color = Sketchup;;Color.new(255,0,0,255)
          @gabb_edge_color = Sketchup;;Color.new(0,0,255,255)
          @edge_width = 3
        end
      
        def deactivate(view)
          reset(view)
        end
      
        def onMouseMove(flags, x, y, view)
          @ip.pick(view, x, y)
          ip_path = @ip.instance_path
          if ip_path.empty?
            reset(view)
            return
          end
          inst = nil
          gptra = nil
          ip_path.each { |ent|
            break if !ent.is_a?(Sketchup;;Group) && !ent.is_a?(Sketchup;;ComponentInstance)
            if gptra
              gptra = gptra * inst.transformation
            elsif inst
              gptra = inst.transformation
            end
            inst = ent
          }
          unless inst
            reset(view)
            return
          end
          return if inst == @hovered_inst
          @hovered_inst = inst
          @global_parent_tra = gptra
          local_bb = @hovered_inst.bounds
          # Obtain corners of local axes aligned bounding box in global space
          lagc = []
          for i in 0..7
            lagc << local_bb.corner(i)
          end
          if @global_parent_tra
            lagc.each { |point| point.transform!(@global_parent_tra) }
          end
          @labb_global_faces = [
            [lagc[0], lagc[2], lagc[3], lagc[1]],
            [lagc[4], lagc[6], lagc[7], lagc[5]],
            [lagc[1], lagc[0], lagc[4], lagc[5]],
            [lagc[2], lagc[3], lagc[7], lagc[6]],
            [lagc[0], lagc[2], lagc[6], lagc[4]],
            [lagc[3], lagc[1], lagc[5], lagc[7]]
          ]
          @labb_global_edges = [
            lagc[0], lagc[2],
            lagc[2], lagc[6],
            lagc[6], lagc[4],
            lagc[4], lagc[0],
            lagc[3], lagc[1],
            lagc[1], lagc[5],
            lagc[5], lagc[7],
            lagc[7], lagc[3],
            lagc[0], lagc[1],
            lagc[2], lagc[3],
            lagc[4], lagc[5],
            lagc[6], lagc[7]
          ]
          # Create global axes aligned bounding box
          @global_bb = Geom;;BoundingBox.new()
          @global_bb.add(lagc)
          # Obtain corners of global axes aligned bounding box in global space
          gagc = []
          for i in 0..7
            gagc << @global_bb.corner(i)
          end
          @gabb_global_faces = [
            [gagc[0], gagc[2], gagc[3], gagc[1]],
            [gagc[4], gagc[6], gagc[7], gagc[5]],
            [gagc[1], gagc[0], gagc[4], gagc[5]],
            [gagc[2], gagc[3], gagc[7], gagc[6]],
            [gagc[0], gagc[2], gagc[6], gagc[4]],
            [gagc[3], gagc[1], gagc[5], gagc[7]]
          ]
          @gabb_global_edges = [
            gagc[0], gagc[2],
            gagc[2], gagc[6],
            gagc[6], gagc[4],
            gagc[4], gagc[0],
            gagc[3], gagc[1],
            gagc[1], gagc[5],
            gagc[5], gagc[7],
            gagc[7], gagc[3],
            gagc[0], gagc[1],
            gagc[2], gagc[3],
            gagc[4], gagc[5],
            gagc[6], gagc[7]
          ]
          view.invalidate
        end
      
        def draw(view)
          return unless @hovered_inst
          # Draw local axes aligned global bounding box
          view.drawing_color = @labb_face_color
          @labb_global_faces.each { |face|
            view.draw(GL_POLYGON, face)
          }
          view.drawing_color = @labb_edge_color
          view.line_width = @edge_width
          view.line_stipple = ''
          view.draw(GL_LINES, @labb_global_edges)
          # Draw global axes aligned global bounding box
          view.drawing_color = @gabb_face_color
          @gabb_global_faces.each { |face|
            view.draw(GL_POLYGON, face)
          }
          view.drawing_color = @gabb_edge_color
          view.line_width = @edge_width
          view.line_stipple = ''
          view.draw(GL_LINES, @gabb_global_edges)
        end
      
        def reset(view)
          return false unless @hovered_inst
          @hovered_inst = nil
          @global_parent_tra = nil
          @global_bb = nil
          @labb_global_faces.clear
          @gabb_global_faces.clear
          @labb_global_edges.clear
          @gabb_global_edges.clear
          view.invalidate
          return true
        end
      
      end # class BoundsHighlighterTool
      
      Sketchup.active_model.select_tool(BoundsHighlighterTool.new)
      

      This time we iterate through the InputPoint's instance_path and transform the bounding box of the deepest instance across all the the parent groups/component instances in the path.

      posted in Developers' Forum
      A
      Anton_S
    • RE: Help please. How to get transformation for the face

      cesaro36,

      Like TIG and others mentioned a face doesn't have a transformation, but its point positions are bound to the transformation of a group/component instance containing the face. In that case, you will need to transform all points of the face into global space before highlighting the face.

      Here is a sample face highligher tool:

      class FaceHighlighterTool
      
        def initialize
          @ip = Sketchup;;InputPoint.new
          @triplets = []
          @edge_points = []
          @hovered_face = nil
          @hovered_face_tra = nil
          @face_color = Sketchup;;Color.new(0,40,255,80)
          @edge_color = Sketchup;;Color.new(0,0,255,255)
          @edge_width = 3
        end
      
        def deactivate(view)
          @hovered_face = nil
          view.invalidate
        end
      
        def onMouseMove(flags, x, y, view)
          @ip.pick(view, x, y)
          face = @ip.face
          if face.nil?
            if @hovered_face
              @hovered_face = nil
              view.invalidate
            end
            return
          end
          if face != @hovered_face
            @hovered_face = face
            @hovered_face_tra = @ip.transformation
            # In order to draw a face with holes, we must draw its mesh
            mesh = face.mesh
            polygons_size = mesh.count_polygons
            @triplets = Array.new(polygons_size)
            for i in 0...polygons_size
              # Obtain one of the triangles making up the face
              triplet = mesh.polygon_points_at(i+1)
              # Transform to global space
              triplet.each { |pt| pt.transform!(@hovered_face_tra) }
              # Store for drawing
              @triplets[i] = triplet
            end
            # Get all edges for drawing a border
            @edge_points.clear
            face.edges.each { |edge|
              @edge_points << edge.start.position
              @edge_points << edge.end.position
            }
            # Transform all edge points to global space
            @edge_points.each { |point| point.transform!(@hovered_face_tra) }
            # Trigger the drawing
            view.invalidate
          end
        end
      
        def draw(view)
          return unless @hovered_face
          view.drawing_color = @face_color
          @triplets.each { |triplet|
            view.draw(GL_POLYGON, triplet)
          }
          view.drawing_color = @edge_color
          view.line_width = @edge_width
          view.line_stipple = ''
          view.draw(GL_LINES, @edge_points)
        end
      
      end # class FaceHighlighterTool
      
      Sketchup.active_model.select_tool(FaceHighlighterTool.new)
      

      If you paste it all into Ruby Console you will see the effect.

      Anton

      posted in Developers' Forum
      A
      Anton_S
    • RE: Earthquake shake table - preprogrammed motion

      For, that you can add a piston joint and connect it to the floor. Then in the piston joint add an oscillator controller, like oscillator(10). You can also multiply the oscillator value by some constant to increase the magnitude, like oscillator(10) * 50. Ensure the floor is movable and its shape is not static mesh.

      posted in SketchyPhysics
      A
      Anton_S
    • RE: MSPhysics 1.0.3 (16 October 2017)

      Well, same applies to that UAV. Just convert the code to MSPhysics. All tick tabs must be converted to onTick {...} in script all touch tabs must be converted to onTouch { ... } in script the rest code is just converting SP functions and concepts to MSPhysics.

      posted in Plugins
      A
      Anton_S
    • RE: MSPhysics tests and questions

      Hello, Zoltan,

      Yes, you understood the concept correctly.

      For such behavior, however, a script might not be necessary. You can use a Piston or a CurvyPiston joint. When you add a Piston joint, set its position units to m, linear rate to like, 1000, and the controller to, world.time % 10. This will generate a value b/w 0 and 10 on a timescale of 10 seconds.

      Also, in case you don't know how to use joints, here is a Wiki:
      https://github.com/AntonSynytsia/MSPhysics/wiki/Using-Joints

      But if you want a special behavior that would teleport a moving object after it surpasses a scalar of a coordinate, then this is how you do it:

      onStart {
        @max_x = 100.m
        @start_pos = this.get_position(1)
      }
      
      onUpdate {
        this.set_velocity(1,0,0)
        if this.get_position(1).x > @max_x
          this.set_position(@start_pos)
        end
      }
      

      Paste this script into the desired moving object(s).

      Basically, this will move an object at 1 m/s along the x-axis and teleport it back to start when the objects X coordinate surpasses maximum x position.

      You can also, instead, control it by force rather than velocity:

      onStart {
        @max_x = 100.m # in inches; the .m converts it meters to inches.
        @start_pos = this.get_position(1)
        @des_vel_x = 1 # in m/s
      }
      
      onUpdate {
        # Compute the desired acceleration in m/s/s -> (des_vel - cur_vel) / timestep
        ax = (@des_vel_x - this.get_velocity.x) / simulation.update_timestep
        # Apply force
        this.add_force(ax * this.mass, 0, 0)
        # Teleport if necessart
        if this.get_position(1).x > @max_x
          this.set_position(@start_pos)
        end
      }
      

      Applying forces are better than applying velocities because they don't dissipate any other forces like the force of gravity or the force of contacts. Also, if you don't want to have the object be affected by the gravity, you can, as well, add force to the z component, like 9.801 * this.mass or you can simply disable gravity for the object. Both yield the same behavior.

      But, like I said, to if you want to create moving platform that doesn't involve teleportation, you can add a Piston joint and connect it to the desired object. Then add an oscillator controller to the Piston joint, like oscillator(50)*100.

      Regards,
      Anton

      posted in Plugins
      A
      Anton_S
    • RE: How to really scale the World?

      That's an issues of MSPhysics and it will be fixed in version 1.0.0. I already made some descent improvements to world scale. So, once it's released it should be working all well.

      posted in SketchyPhysics
      A
      Anton_S
    • RE: MSPhysics 1.0.3 (16 October 2017)

      SynSuka3D, you should explore SketchyPhysics models at 3DWarehouse on that and then write a similar script for what you want. For instance, a Radar by Mr. K: https://3dwarehouse.sketchup.com/model/c8b415a0bbb385b87e683c55e87c0665/Radar-3

      posted in Plugins
      A
      Anton_S
    • RE: Problem with Compound from CD on Curvy faces.

      Yes, Compound from CD shape is unstable. You can use a plugin by Fredo6, called convexy, to divide the green piece into convex sub-groups. And also change the shape to Compound. Here it is: http://sketchucation.com/forums/viewtopic.php?f=323%26amp;t=61145

      posted in SketchyPhysics
      A
      Anton_S
    • 1
    • 2
    • 12
    • 13
    • 14
    • 15
    • 16
    • 63
    • 64
    • 14 / 64