Code review, beta test and gauge interest for bezier surface plugin

jps_beziersurf.rb (9.6 KB)


I am new to Ruby, SketchUp and developing plugins for it and would really appreciate any code review and testing anyone might be willing to do for a plugin I have developed to draw and edit bezier surfaces in SketchUp.

Please install the attached jps_beziersurf.rb file in your Plugins directory and if everything goes well, you should see the “Draw Bezier Surface” menu item under Plugins the next time you launch SketchUp.
Clicking on it should draw a default Bezier surface near the origin.
To edit a surface, select the surface and choose “Edit Bezier Surface” in the Right Mouse Button context menu which should show the surface’s 16 control points.
Moving any of the 16 control points will affect the resultant Bezier surface.

Please provide as much feedback as possible regarding the code, issues/bugs you see or ways to improve the tool/interface etc.

Also, do let me know if you feel the tool is useful and if it is worth spending time trying to enhance it, draw any kind of Nonuniform Rational B-Splines(NURBS) surface etc.

Thanks a lot!

I get the following error on the mac su2014. The extension doesn’t seem to work at all for me. I think there is a problem with your use of model.materials on line 98.

Error: # IndexError: index 0 out of range [0, 0)> .../Plugins/jps_beziersurf.rb:98:in `[]' .../Plugins/jps_beziersurf.rb:98:in `addTrianglesToModel' .../Plugins/jps_beziersurf.rb:131:in `activate' .../Plugins/jps_beziersurf.rb:323:in `select_tool' .../Plugins/jps_beziersurf.rb:323:in `block in ' -e:1:in `call'


jps_beziersurf.rb (9.6 KB)

Hi Bryce,

Thanks a lot for the quick reply.
I don’t have a Mac and so it is great that you can test it for me on yours and it is really nice of you to point me to the problematic code.
I have now removed the use of model.materials as it was optional anyway.
Could you please try the new version and let me know if you still see any issues?

Thanks again,

I’d say there is interest - but then again I’m biased. I have been working on a Bezier Surface extension myself in the past:

But it’s been put on hold while I work on a subdivision extension.

I’ve been pondering on what to do with the Bezier Surface project. Maybe I should just open source it…

As for the code:

fill_from_mesh is much faster than add_faces_from_mesh. (The slowest methods of adding faces are add_face)

For the usage:

When I added a patch there seemed to be a tool activated, but it didn’t do anything. Was this supposed to be the editing tool?

Would have been nice if the editing tool performed rectangle selections.

For Extension Warehouse compliance you would have to:

I have a couple of articles on my website that might be of interest:

That would be very cool!

Hi Jacob

The new version is working on the mac now. Editing works too but the grips are kind of hard to grab. I suspect the click taget is only a pixel or two wide. Not sure if my hi-dpi screen is compounding the problem.

Otherwise, great start on the tool!!

Thom’s advise is great too. Let us know if you want to publish on Extension warehouse.


Edit: please disregard my inferencing comment. I see that it works but can’t be locked (which is tricky in extensions). I did notice one issue with undos - they don’t affect the edit grips.

When I added the sample bezier model, the default front face material was replace by another material that was in my home Material list. Being that the applied material was a texture, it was quite a visual distraction.

I edited the shape, make a copy of it and tried to edit the copy. The plugin editing controls did not move with the copied model.

I liked how the movement of the control nodes could be axis constrained with the Shift key. Would like to see the same lock direction inference clue (the heavy,by-axis color) that one see in the SU workspace.

jps_beziersurf.rb (10.6 KB)

Hi thomthom,

Thanks a lot for the great feedback!

Your extension does look very nice but I thought about it and am going to continue developing my own just for my own creative satisfaction. And if you get busy with other projects and are not able to spend much time on your Bezier Surface project, it would be great if you can continue guiding me.

I have changed add_faces_from_mesh to fill_from_mesh.

You are right in that most users are not going to be happy with the default patch provided to them and so I have changed “Draw Bezier Surface” to activate the editing tool as well after the default patch is drawn for them.

By rectangle selections, I am assuming the ability to select more than one control point at the same time.
That is a great idea and hopefully I’ll be able to implement it soon.

I have gotten rid of the global variable $jps_bezier_surface_loaded.

I have submitted the Developer Application for the Extension Warehouse.

Your plugin checklist pointed me to the fact that groups can be locked which I am now checking for before allowing the edit.

Good to hear about the interest for NURBS.

Could you please review and test the attached jps_beziersurf.rb and let me know your thoughts?


Hi Bryce,

You are right in that the grips were indeed hard to grab and have now increased the click target. Please try the version attached and let me know if it needs to be increased further.

Inference locking is available with the shift key but have now added documentation about it in the header. I will also try and implement the lock direction inference clue (the heavy,by-axis color) that catamountain also wants soon.

I have replied to Thom’s post as well regarding all his great advice and have implemented most of the changes he wanted.

I would love to publish this on Extension warehouse once I try and fix most of the issues people find on this forum.

Thanks for your feedback and please keep it coming,

jps_beziersurf.rb (10.6 KB)

By all means - do continue. I haven’t had time lately. Though, if I made the project open source, would it be of interest to you?

Hi catamountain,

Thank you very much for your feedback.

I have removed using the material from the material list for the front face.

The issue with the plugin editing controls not moving with the copied model should also be fixed now.

I have also implemented the lock direction inference clue (the heavy,by-axis color).

Let me know if you still see any of the issues above or anything else with the attached jps_beziersurf.rb.

Thanks again!
jps_beziersurf.rb (11.5 KB)

Thanks Tom for offering to make your project open source but I would rather not have the temptation to always copy your code.
I will definitely ask you for it if I do get terribly stuck somewhere.

Thanks again,

Hi Bryce,

Just wanted to let you know that I have fixed the issue with undos not affecting the edit grips as well if you want to test the latest attached version.
jps_beziersurf.rb (12.2 KB)

Also, I have submitted my Extension Warehouse Developer Application and am awaiting the decision regarding whether or not I have been granted developer access.


Hi Tom,

Just wanted to let you know that I have now implemented selecting and moving anywhere along the lines of the control polygon, including the end points, just like in the Bezier curve tool as I thought the end users would be used to that interface by now.

Could you please take a look at the attached version and let me know if you feel it is ready to be submitted officially for review to be published in the Extension Warehouse?

Thanks a lot!
jps_beziersurf.rb (15.2 KB)

Hi Jacob

I recommend you review the guidelines we have at the Developer Center:

Among them is that extensions needs to we wrapped up in rbz packages and implement the SketchupExtension class so users can disable the extension from within SketchUp.

Looking at the rb files you posted some small things to note:

#module JPS::Plugins::BezierSurface
PLUGIN = self # Allows self reference later when calling function in module

You have constant there defined in the global scope. All though it appear you had it wrapped in a module earlier, but commented it out.

  # Add a context menu handler to let you edit a Bezier surface
  UI.add_context_menu_handler do |menu|
    if( (group = self.jps_selected_bezier_surface) )

This isn’t a requirement for EW but I would recommend not adding a separator in the root level menus or context menu. This is because if you have many extensions installed that does this it looks very odd and the separators eat up space eventually. This is a topic I think we should have a Guide for. (But I stress this is just a suggestion from me.)

Other than that constant and RBZ packaging I’d say you are good to go.

Hi Tom,

I have removed the use of the constant, wrapped the code in a module, removed adding the separator to the menu, implemented the SketchupExtension class, wrapped everything up into an rbz package and just submitted it to the EW for review.

Thanks again for your great, prompt advice!

1 Like