[Plugin] SurfaceGen (0.9.0b) — 28 April 2012

[Plugin] SurfaceGen (0.9.0b) — 28 April 2012

Postby Diggsey » Fri Apr 29, 2011 12:08 am

SurfaceGen v0.9 (Beta)

SurfaceGen is a plugin which allows you to create surfaces from mathematical formulae. There are two modes supported:

Function Mode
The Z coordinates of points in a heightmap are specified as a function of X and Y. There can therefore only be one Z value per X, Y coordinate.



Equation Mode
An equation relating X, Y and Z is given. This mode can graph any 3D surface for which there is a formula, but may take slightly longer. The marching cubes algorithm (wow that one is a pain to implement!) is used to generate a surface around a 3D grid of data generated from the equation.



Instructions

- Select the SurfaceGen tool from its toolbar.
- Click to set one corner of the graph.
- Click again to set the opposite corner on the same level.
- Click a third time to set the height of the graph.
- You can transform the resulting group without causing problems.


- After creating the graph and it becoming selected, the SurfaceGen Options window should appear.
- Set the axis ranges, the SurfaceGen mode and enter an equation.
- Choose if you want to show the graph boundary. This will make a semi-transparent box around the graph. The sides facing the camera will always be invisible as you rotate the camera allowing you to see the surface.
- Choose if you want the graph to be smooth.
- Click generate. This may take a few seconds, so be patient. It will happen asynchronously, so you should still be able to move the camera around.
- You can set the surface material by using the paint bucket on the group. The surface will become the selected material.
- Opening the group will cause the graph to turn into a normal group. The plugin will ask if you really want to do this before it actually happens.


Install

Download and extract the attached zip file to your plugins folder. Please remember this is still in beta! I want to hear about any problems you encounter!

Update 0.6
- Updated to work with SketchUp 6

Update 0.7
- Updated to be more compatible with Macs
Now uses built in functions to locate resources and combine paths. Also uses WebDialog.show_modal on macs to get always-on-top behaviour.

- Added more functions
abs, min, max, clamp can now be used in an expression.

- Allowed expressions in axis ranges
You can now easily graph from -pi to pi etc.

- More error checking
You will be notified if an expression is invalid, and hopefully some useful information about why it was invalid will given.

Update 0.7b
- Added point validation to getExtents for the graph tool
The ruby console shouldn't show any errors when drawing a new graph.

Update 0.7c
- Fixed expression parsing bug
Previously, using the same function twice in a row didn't work: sqrt(sqrt(16)) due to the regex used. Now it does.

Update 0.8
- Changed use of pt units to px units in WebDialog
The font should display at the same size in all browsers.

- Now works from any directory
Resources are looked for starting with the directory containing surfacegen.rb.

- Can more easily change WebDialog size
The width as well as the height are constants in surfacegen.rb

Update 0.9
- Increased speed
Previously "eval" was used to evaluate the expression at each sample point, now it uses "eval" once to create a proc object which is called multiple times.
1
Last edited by thomthom on Sat Apr 28, 2012 2:56 pm, edited 11 times in total.
Reason: Added version number and time of update in title

Diggsey 
 

Re: [Plugin] SurfaceGen

Postby mitcorb » Fri Apr 29, 2011 3:34 am

Hi, Diggsey:
This looks interesting. You are off to a good start.
0
I take the slow, deliberate approach in my aimless wandering.
User avatar
mitcorb 
Top SketchUcator
 

Re: [Plugin] SurfaceGen

Postby d12dozr » Fri Apr 29, 2011 6:42 am

Diggsey, this is neat! I just started learning this week how to generate implicit surfaces using equations in Meshlab, and I've been importing them into SU - now I can do it all in Sketchup :thumb: :thumb: While I don't really understand the math, I just play around with equations and see what pops up.

On that note, do you have any ideas I can use as starters/seed equations for generating neat surfaces? What kind of math would I need to brush up on to understand this stuff better?

For now, I'm just playing, but I have dreams of making some beautiful math sculptures like Bathsheba Grossmanmakes.

Here is a little test I did, using the settings shown in the screenshot.
SurfaceGen.JPG


Did I say thank you, Diggsey? :D
0
3D Printing with SketchUp Book
http://goo.gl/f7ooYh

d12dozr 
Top SketchUcator
 

Re: [Plugin] SurfaceGen

Postby d12dozr » Fri Apr 29, 2011 7:17 am

Heh, here's a truncated sphere, settings shown...this is fun! :mrgreen:
SurfaceGen2.JPG


Some suggestions:
-When switching to "Equation", change the default settings to something that will work just by pressing "Generate"
-Add a random equation/function generator, perhaps using preset equations
-Add an error message when the equation is invalid, pointing out why its invalid if possible

Like Jean says, just ideas...
0
3D Printing with SketchUp Book
http://goo.gl/f7ooYh

d12dozr 
Top SketchUcator
 

Re: [Plugin] SurfaceGen

Postby dedmin » Fri Apr 29, 2011 7:30 am

Diggsey, where have You been so far!! We need You! Keep up surprising Us! Thanks!
0

dedmin 
 

Re: [Plugin] SurfaceGen

Postby d12dozr » Fri Apr 29, 2011 8:05 am

Here's a question for you...is there a way to make the SurfaceGen geometry look like the first Meshlab image? I'm using the same equation, and trying to get results like changing the voxel size in Meshlab, but changing the # of cells in SurfaceGen doesn't seem to have the same effect...am I doing something wrong?
SurfaceGen1.JPG

Meshlab.JPG

Meshlab2.JPG


BTW, I like how the settings are saved for each generated surface!! :enlight:
0
3D Printing with SketchUp Book
http://goo.gl/f7ooYh

d12dozr 
Top SketchUcator
 

Re: [Plugin] SurfaceGen

Postby pilou » Fri Apr 29, 2011 8:19 am

ah very cool! :fro:
Topmod and K3dSurf in a same place! :thumb:
(you can take some formula from K3DSurf ;)

For now, I'm just playing, but I have dreams of making some beautiful math sculptures like Bathsheba Grossmanmakes.

Topmod above is perfect for that ;)
by me :)


By Jotero
2
Frenchy Pilou
Is beautiful that please without concept!
Speedy Galerie
User avatar
pilou 
Top SketchUcator
 

Re: [Plugin] SurfaceGen

Postby d12dozr » Fri Apr 29, 2011 8:38 am

Great links, Pilou! Thank you :thumb: Nice work on the sculpture, too.
0
3D Printing with SketchUp Book
http://goo.gl/f7ooYh

d12dozr 
Top SketchUcator
 

Re: [Plugin] SurfaceGen

Postby thomthom » Fri Apr 29, 2011 8:51 am

Very nice plugin. :thumb:
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: [Plugin] SurfaceGen

Postby pilou » Fri Apr 29, 2011 8:56 am

In the V6 don't works ;)
Error Loading File surfacegen.rb
cannot convert Hash into String


Works fine in the V7 ;)
surfacegen00.jpg
0
Frenchy Pilou
Is beautiful that please without concept!
Speedy Galerie
User avatar
pilou 
Top SketchUcator
 

Re: [Plugin] SurfaceGen

Postby Diggsey » Fri Apr 29, 2011 11:45 am

Thanks everyone who commented!

@d12dozr
I've no idea how to make such complicated structures as those ones you linked to, but you can get some interesting shapes by just mixing up a few of the built in functions:

sin, cos, tan, sinh, cosh, tanh, asin, acos, atan, asinh, acosh, atanh, atan2, hypot, sqrt, cbrt, log, log2, log10, ln, exp

and constants:

e, pi

When switching to "Equation", change the default settings to something that will work just by pressing "Generate"


I'll just make the default equation something that will work for both modes.

Add a random equation/function generator, perhaps using preset equations


That could be interesting. Perhaps the user could choose a level of complexity and it would use that many operations.

Add an error message when the equation is invalid, pointing out why its invalid if possible


Showing an error would be possible, but it might be difficult to point out where. It depends on how much information ruby gives me. For speed, the equation is converted into ruby code, so I can just eval it for each point instead of running my own interpretter.

Here's a question for you...is there a way to make the SurfaceGen geometry look like the first Meshlab image?


I don't know exactly how Meshlab works internally, but it seems like the voxel size is equivalent to the range of values divided by the number of cells. ie:
voxelSize = (max-min)/cells

I'm surprised it should look so different though, just by changing the voxel size.

@Pilou
I've found the problem. It won't let me pass a hash to WebDialog.new.
0

Diggsey 
 

Re: [Plugin] SurfaceGen

Postby thomthom » Fri Apr 29, 2011 12:12 pm

Diggsey wrote:@Pilou
I've found the problem. It won't let me pass a hash to WebDialog.new.


Additionally, SU6 only accepts one argument for model.start_operation.

I've used this wrapper:
Code: Select all

def self
.start_operation(name)
  
model Sketchup.active_model
  
if Sketchup.version.split('.')[0].to_i >= 7
    model
.start_operation(nametrue)
  else
    
model.start_operation(name)
  
end
end


The operation will run slower under SU6 - but at least it runs.
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: [Plugin] SurfaceGen

Postby Diggsey » Fri Apr 29, 2011 12:20 pm

Thanks thomthom, but I've just used a rescue statement so it will fallback on the older version if the newer one fails. The first post has the updated version which works with v6.
0

Diggsey 
 

Re: [Plugin] SurfaceGen

Postby TIG » Fri Apr 29, 2011 2:54 pm

There are also a few error-messages appearing in the Ruby Console that needs traps or begin/rescue forms [e.g. after you explode a special group]...
Some of them relate to your 'recurve' too...
But it's a neat tool :D
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [Plugin] SurfaceGen

Postby Diggsey » Fri Apr 29, 2011 4:02 pm

I've tried doing everything possible and can't seem to get any output in the ruby console from either plugin. Can you tell me exactly how to reproduce it?
0

Diggsey 
 

Re: [Plugin] SurfaceGen

Postby notareal » Fri Apr 29, 2011 4:23 pm

Nice! Can't wait some more complex math sculptures... and naturally even more functionality, like with K3DSurf.

Little test...
0
Last edited by notareal on Fri Apr 29, 2011 5:01 pm, edited 1 time in total.
Welcome to try Thea Render, Thea support | kerkythea.net -team member

notareal 
Thea Render Support
Thea Render Support
 

Re: [Plugin] SurfaceGen

Postby TIG » Fri Apr 29, 2011 4:42 pm

Diggsey wrote:I've tried doing everything possible and can't seem to get any output in the ruby console from either plugin. Can you tell me exactly how to reproduce it?
For example...
Error: #<NoMethodError: undefined method `curve' for #<Sketchup::Group:0xa9d06fc>>
C:/Program Files/Google/Google SketchUp 8/Plugins/recurve.rb:17:in `can_select_curve?'
C:/Program Files/Google/Google SketchUp 8/Plugins/recurve.rb:32:in `can_select_curve_selection?'
C:/Program Files/Google/Google SketchUp 8/Plugins/recurve.rb:352

When right clicking a tagged 'surfacegen-group'.
Explode the special surgfacegen-group and right-click gives
Error: #<NoMethodError: undefined method `curve' for #<Sketchup::ComponentInstance:0xb440344>>
C:/Program Files/Google/Google SketchUp 8/Plugins/recurve.rb:17:in `can_select_curve?'
C:/Program Files/Google/Google SketchUp 8/Plugins/recurve.rb:32:in `can_select_curve_selection?'
C:/Program Files/Google/Google SketchUp 8/Plugins/recurve.rb:352
C:/Program Files/Google/Google SketchUp 8/Plugins/recurve.rb:17:in `call'
C:/Program Files/Google/Google SketchUp 8/Plugins/recurve.rb:17

Erase that 'bounds' Instance then Select the surface...
Error: #<NoMethodError: undefined method `curve' for #<Sketchup::Face:0xad7783c>>
C:/Program Files/Google/Google SketchUp 8/Plugins/recurve.rb:17:in `can_select_curve?'
C:/Program Files/Google/Google SketchUp 8/Plugins/recurve.rb:32:in `can_select_curve_selection?'
C:/Program Files/Google/Google SketchUp 8/Plugins/recurve.rb:352
C:/Program Files/Google/Google SketchUp 8/Plugins/recurve.rb:17:in `call'
C:/Program Files/Google/Google SketchUp 8/Plugins/recurve.rb:17

These all relate to 'recurve' reaction to 'surfacegen' entities ?
I did have a surgacegen error but I can't get it to reproduce now :?
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [Plugin] SurfaceGen

Postby d12dozr » Fri Apr 29, 2011 4:42 pm

Diggsey wrote:I've no idea how to make such complicated structures as those ones you linked to, but you can get some interesting shapes by just mixing up a few of the built in functions:

sin, cos, tan, sinh, cosh, tanh, asin, acos, atan, asinh, acosh, atanh, atan2, hypot, sqrt, cbrt, log, log2, log10, ln, exp

and constants:

e, pi

Thank you for this, and considering my suggestions too!
0
3D Printing with SketchUp Book
http://goo.gl/f7ooYh

d12dozr 
Top SketchUcator
 

Re: [Plugin] SurfaceGen

Postby pilou » Fri Apr 29, 2011 5:55 pm

In the V6
We can draw the "Box" but dialog's window don't opening ;)
No error message, nothing in the Ruby console
0
Frenchy Pilou
Is beautiful that please without concept!
Speedy Galerie
User avatar
pilou 
Top SketchUcator
 

Re: [Plugin] SurfaceGen

Postby Diggsey » Fri Apr 29, 2011 6:08 pm

@notareal
That's really nice! What's the equation you used?

@TIG
Make sure you have the latest version of Recurve. I fixed that bug with the last update which is why I couldn't reproduce the error. If you ever get the SurfaceGen error again let me know.

@Pilou
Just re-select the group with the select tool. It seems that the SelectionObserver doesn't fire when the selection is changed in code.
0

Diggsey 
 

Re: [Plugin] SurfaceGen

Postby TIG » Fri Apr 29, 2011 6:24 pm

You are right, in that when I get v1.4 of 'recurve' I no longer get these errors with 'surfacegen'. However, I had v1.3 [with SUpv8] and there were no major changes except for making it SUpv6 friendly ?
Anyway... no more error messages... I'll try to break it ;)
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [Plugin] SurfaceGen

Postby Builder Boy » Fri Apr 29, 2011 9:03 pm

Sponge-like object:

Capture1.PNG
0

Builder Boy 
 

Re: [Plugin] SurfaceGen

Postby driven » Sat Apr 30, 2011 2:23 am

this is great,

some odd behavior on the Mac... when run from plugins (like you should) I get this
Code: Select all
Error: #<ArgumentError: Cannot convert argument to Sketchup::Point3d>
/Library/Application Support/Google SketchUp 8/SketchUp/Plugins/SURFACEGEN_Dir/surfacegen_tool.rb:266:in `add'
/Library/Application Support/Google SketchUp 8/SketchUp/Plugins/SURFACEGEN_Dir/surfacegen_tool.rb:266:in `getExtents'


if I put the surfacegen.rb into the folder do a restart and then load from Ruby Code Editor, I get this

Code: Select all
(eval):428: warning: don't put space before argument parentheses
"Run aborted (error has occurred)"
(eval):428: warning: don't put space before argument parentheses
(eval):10: warning: already initialized constant SURFACEGEN_DIR
(eval):11: warning: already initialized constant GRAPH_SIZE
(eval):12: warning: already initialized constant WINDOW_HEIGHT
(eval):13: warning: already initialized constant ATTR_DICTIONARY
"Run aborted (error has occurred)"


but if I restart again and use as_pluginloader.rb to load it I get
Code: Select all
/Library/Application Support/Google SketchUp 8/SketchUp/plugins/SURFACEGEN_Dir/surfacegen.rb:428: warning: don't put space before argument parentheses


it works, but has no tool button image...
surfacegen_mac.png

button image-no dialog.png
0
learn from the mistakes of others, you may not live long enough to make them all yourself...

driven 
PluginStore Author
PluginStore Author
 

Re: [Plugin] SurfaceGen

Postby notareal » Sat Apr 30, 2011 8:25 am

Diggsey wrote:@notareal
That's really nice! What's the equation you used?

Code: Select all
F(x,y,z) = 2-(cos(x+(1+sqrt(5))/2*y)+cos(x-(1+sqrt(5))/2*y)+cos(y+(1+sqrt(5))/2*z)+cos(y-(1+sqrt(5))/2*z)+cos(z-(1+sqrt(5))/2*x)+cos(z+(1+sqrt(5))/2*x))*16/(x*x+y*y+z*z)
[x]: -5, 5
[y]: -5, 5
[z]: -5, 5

There is plenty more at the k3dsurf forum.
0
Welcome to try Thea Render, Thea support | kerkythea.net -team member

notareal 
Thea Render Support
Thea Render Support
 

Re: [Plugin] SurfaceGen

Postby notareal » Sat Apr 30, 2011 9:20 am

Perhaps you could add some more functionality; like functions min, max and abs. Also allow use of arithmetic operations and pi in axes, like -2*pi.
0
Welcome to try Thea Render, Thea support | kerkythea.net -team member

notareal 
Thea Render Support
Thea Render Support
 

Re: [Plugin] SurfaceGen

Postby TIG » Sat Apr 30, 2011 9:59 am

You already have 'pi' [in lowercase] as a function?
Capture.PNG
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [Plugin] SurfaceGen

Postby thomthom » Sat Apr 30, 2011 11:30 am

Diggsey wrote:@Pilou
Just re-select the group with the select tool. It seems that the SelectionObserver doesn't fire when the selection is changed in code.

The SelectionObserver has always been very buggy: http://www.thomthom.net/software/sketchup/observers/
0
Thomas Thomassen — SketchUp Monkey & Coding addict
List of my plugins and link to the CookieWare fund
User avatar
thomthom 
PluginStore Author
PluginStore Author
 

Re: [Plugin] SurfaceGen

Postby Diggsey » Sat Apr 30, 2011 1:42 pm

Just uploaded a fairly major update to the first post!

@driven
This should fix the issues with macs. It now uses cross-platform methods to locate and load resource, and uses show_modal rather than show on macs with the WebDialog.

@notareal
The axes now let you use an expression such as 2*pi

@d12dozr
Helpful error message are now shown when an expression is invalid.
0

Diggsey 
 

Re: [Plugin] SurfaceGen

Postby TIG » Sat Apr 30, 2011 1:58 pm

Thanks :D

Code: Select all
Error: #<ArgumentError: Cannot convert argument to Sketchup::Point3d>
C:/Program Files/Google/Google SketchUp 8/Plugins/SURFACEGEN_Dir/surfacegen_tool.rb:270:in `add'
C:/Program Files/Google/Google SketchUp 8/Plugins/SURFACEGEN_Dir/surfacegen_tool.rb:270:in `getExtents'
One minor error in getExtents in surfacegen_tool.rb
Line #270 result.add @p0 if @state >= 0
can raise an error so adjusting it to
return if !@p0 or @p0.class!=Geom::Point3d; result.add @p0 if @state >= 0 might help - you could also add similar validity checks on the other points that are added to the extents ?
0
TIG
User avatar
TIG 
Global Moderator
 

Re: [Plugin] SurfaceGen

Postby Diggsey » Sat Apr 30, 2011 2:20 pm

Ah, I knew I'd forgotten something :)

I've updated the first post. It shouldn't show those errors anymore.
0

Diggsey 
 

SketchUcation One-Liner Adverts

by Ad Machine » 5 minutes ago



Ad Machine 
Robot
 

Next


 

Return to Plugins

Who is online

Users browsing this forum: Justom, sketchy22 and 16 guests

Visit our sponsors: