# Dynamic Volume Pattern?

Discussion in 'ShapeJS' started by Ontogenie, Nov 23, 2016.

1. Ontogenie Well-Known Member
Hi everyone,
I'm very new to ShapeJS and have been working my way through some of the tutorials but I'm beginning to think that what I want to do just isn't possible (yet) with ShapeJS. Before I delve any deeper into this, I'd like to ask for your guidance. I would like to be able to either (a) add multiple images to create textures, and have a slider that selects between them or (b) have a volume pattern/distance function that is dynamic, i.e. expressed as an algorithm with variable, non-static parameters. Am I dreaming here, or is this perhaps possible?

Thanks!
Kimberly

2. MrNib Well-Known Member
I would say I had part b) doing this in 2014 using ShapeJS v1. Now I'm trying to port that over to ShapeJS v2 and encountering some difficulties. The part of my code that did this was to pattern the surface of a cylinder using trig functions. Basically think of lots of equations to generate ridges, flutes, or combinations thereof on the surface. In general the use of all sorts of math functions are possible, but regular repeating sine wave functions would be the most common. In the parameter inputs you could specify things like the number of flutes, or how many cycles of ridges along a length, or a specific wavelength for the pattern of ridges, etc. Typical engineering stuff. But I'm not completely sure what was in v1 but is not in v2 or visa versa.

How this worked before... In the main function I had some simple code to define the voxel grid and the patterned cylinder:
---------------------------------------------------------
var grid = createGrid(-a,a,-a,a,-a,a,0.1*MM)
var union1 = new Union();
---------------------------------------------------------

Outside of the main function I had a routine that defined the pattern. I must have modeled that after some example code because I didn't fully understand it then and I don't fully understand it now. Suffice it to say it returned the desired patterned cylinder and put it into union1, which was then available for further manipulation in the main function. Anyway, the pattern thing looked like this:
----------------------------------------------------------------------
var Pattern = {
getDataValue : function(pnt, data) {
var x = pnt.v[0];
var y = pnt.v[1];
var z = pnt.v[2];

var vs = pnt.getScaledVoxelSize();
var bumps = messy equation of (x,y,z,) and some global variables;
var r = bumps +Math.sqrt(x*x+y*y);

return DataSource.RESULT_OK;
}
};
-----------------------------------------------------------------------

Anyway, the present hangup appears to happen when the main routine needs to deal with the Pattern variable and everything stops. The ShapeJS developer editor doesn't seem to be working right now so I can't show the error, but does anyone have a clue why this isn't working in v2? Is it a change in syntax, commands, or just a bone headed goof? Maybe some improper variable passing? Has this functionality been removed to speed things up?

I'm assuming that I archived the correct old code in the first place, that it is not backwards compatible with v2, and that there is no longer a run time editor window available for v1. It would be great to see the old code run again if only to use it as a benchmark.

3. AlanHudson Shapeways Employee Dev Team
Yes we removed implementing your own custom datasource from V2. We are now running the code on the GPU and it takes 30s to compile it. If we allowed custom datasources we'd have to recompile the code each time someone wanted to run it.

We've got some new distance to point and lineset primitives coming out that I think will accomplish what you want. Basically you would point sample the object the object with spheres. Question remains how many spheres you'd need to get the accuracy you want.

The other concept is to use the symmetry engine in ShapeJS. It's a way to make some interesting patterns: https://www.shapeways.com/blog/archives/25301-learn-shapejs-symmetry-and-reflections-part-1.html

I'll chat with the team and see if theirs another way to handle functional datasources. We might be able to map an expression into GPU functions.

4. MrNib Well-Known Member
I could use shape symmetry and add/subtract features with some softening to generate patterns, but that would require a new section of code for each specific pattern. The power of using equations is that in general this means only replacing a single line of code, or being able to conditionally choose one of several equation/pattern options from a parameter list using very compact code.

Using a sphere deposition approach should also work but the number of spheres is probably dependent on the pattern detail sizes assuming the spheres are always a constant size during deposition. Again a merging smoothing function or a post-smoothing operation would probably be beneficial.

For immediate purposes I mostly care about cylindrical structures although someone like @Ontogenie might benefit from doing similar things with spherical or elliptical structures to create pollen or similar scary organic structures. The more algorithms the merrier!

One thing I need for some pens is the ability to taper or bulge the basic profile. My original 2014 code is similar to the Shapeways ring creator with end bands, except that in my case the end bands can have different outside diameters and lengths. That means the patterned center part of the cylinder needs to have ends of different diameters. Again much easier and accurate to taper and/or bulge using equations directly.

The basis of all this stuff goes back to Tinkercad in which I created a lot of shape generators to make such patterned cylinders. Often it's just the pattern equation that is different. Very similar to 2D parametric generated surfaces but in the case of cylinders the cylindrical surface is modulated radially instead of a flat plane being modulated up and down.

Using ShapeJS it was MUCH easier to do the same things using much less code. This is work that has been many years in progress and it was just waiting for the capability to add generators to a Shapeways shop.

Ontogenie likes this.