Slow creating obj file

22 views
Skip to first unread message

Wink Saville

unread,
Jun 11, 2020, 2:48:41 PM6/11/20
to Curv
I tweaked twist.curv and used 180deg twist and inlarged it, box[25,25,100]:

  parametric
    C :: colour_picker = sRGB.HSV[0, .7, .7];
    Angle :: slider[0,720] = 180;
  in
  box [25,25,100]
  >> colour C
  >> twist (Angle*deg/100)
  >> rotate {angle: 90*deg, axis: Y_axis}
  >> bend {}
  >> lipschitz 2

And then output to obj file with a "small" vsize:

  $ curv -o myshape.obj -O vsize=0.10 myshape.curv 
  vsize=0.1: 1031×1031×359 voxels. Use '-O vsize=N' to change voxel size.
  Rendered 381602999 voxels in 5896.62s (64715 voxels/s).
  3217266 quads.

And it took 98min, can this be sped up?

I can increase the voxel size (default):

  $ curv -o myshape.vsize-default.obj myshape.curv
  vsize=1.54912: 73×73×29 voxels. Use '-O vsize=N' to change voxel size.
  Rendered 154541 voxels in 1.50813s (102471 voxels/s).
  13130 quads.

 But then there is resolution loss, see attachment.

One other thing, why the "gap"?
Screenshot-slicer-myshape.vsize-default.obj.png

Doug Moen

unread,
Jun 11, 2020, 3:11:47 PM6/11/20
to Curv
Hi, Wink.

To speed things up, add the command line option '-O jit' when exporting to obj.

My best explanation for the gap is some kind of floating point inaccuracy problem.
It can sometimes happen when two flat surfaces are intended to abut.
The usual solution is to tweak the model so that there is some overlap or overshoot.
I see the same problem in other procedural 3D modelling languages, such as OpenSCAD.

I will run some experiments, and see if I can reproduce and fix the gap problem.

Doug Moen.

Wink Saville

unread,
Jun 11, 2020, 3:48:25 PM6/11/20
to Curv
I tried:

  $ curv -o twist.obj -O jit twist.curv 
  /home/wink/prgs/curv3d/projects/twist/,curv-47898-0.cpp:1:10: fatal error: glm/common.hpp: No such file or directory
      1 | #include <glm/common.hpp>
        |          ^~~~~~~~~~~~~~~~
  compilation terminated.
  ERROR: c++ compile failed; see "/home/wink/prgs/curv3d/projects/twist/,curv-47898-0.cpp"

So it seems I need OpenGL Mathematics, so I installed that.

  $ curv -o twist.obj -O jit twist.curv 
  Compiled shape in 0.222235s
  vsize=0.1: 51×51×21 voxels. Use '-O vsize=N' to change voxel size.
  Rendered 54621 voxels in 0.00745003s (7331644 voxels/s).
  5534 quads.

Quite a bit faster! I then tried "myshape.curv" and instead of 98min
it was 19secs, BRAVO:

$ curv -o myshape.obj -O vsize=0.10 -O jit myshape.curv 
Compiled shape in 0.20913s
vsize=0.1: 1031×1031×359 voxels. Use '-O vsize=N' to change voxel size.
Rendered 381602999 voxels in 19.0623s (20018695 voxels/s).
3217270 quads.

Question, why is the temporary file starting with a coma ",curv-47898-0.cpp"?


Doug Moen

unread,
Jun 11, 2020, 4:41:13 PM6/11/20
to Curv
On Thu, Jun 11, 2020, at 1:18 PM, Wink Saville wrote:
One other thing, why the "gap"?

I was able to mostly eliminate the gap by adding a line of code to the end:
  >> offset 0.05
This blows up the model like a balloon, and fills in the gap.
But there is still a slight crease visible.

Another technique is to add:
   >> rotate {angle: 3*deg, axis: Z_axis}
The mesh conversion algorithm works by sampling the distance function in a regular grid pattern, and the gap is aligned with the Z-Y plane. Rotating it slightly breaks up that alignment.
Again, there is still a slightly visible crease.

If I combine both techniques:
  >> offset 0.05
   >> rotate {angle: 3*deg, axis: Z_axis}
then the crease is no longer visible.

If I make the offset big enough, then the gap is completely filled in:
  >> offset 0.1
No need for the additional rotate.

But, a side effect of offset is that it rounds the edges.
At an offset of 0.1, the effect is just barely visible.
You can fix this by using a "mitred" box.
The mitre effect modifies the distance field in a way that prevents offset from rounding the edges.
So you use
    box.mitred [25,25,100]

I gave this much detail, to provide multiple techniques for people who run into this issue in a different context.
Reply all
Reply to author
Forward
0 new messages