Map image to a truncated cone

Hi,

is it possible to create a truncated 3d cone with g’mic?
And how can I map an image to an 3d object like cone3d?

Not sure, as there are many different ways of mapping an image to a cone, but the following example somehow makes what you asked for :slight_smile:

foo :
  sp tiger
  cylinder3d 30,100
  l. s3d l[2]
    r 3,{h/3},1,1,-1 permute cyzx
    f "XYZ = I; XYZ[2]>0?XYZ*[0.35,0.35,1]:XYZ" # Make top of cylinder smaller.
    permute cyzx
  endl y a y endl
  t3d. .. rm..

Haven’t played with permute yet. The help description is short, so I don’t know what it does exactly…

@David_Tschumperle I don’t understand what you have done. (This is the first time I look deeper into gmic, till now I just used the GIMP plugin.)

I changed some values of your script with trial and error:

truncated_cone :
  sp tiger
  cylinder3d 91.5,139.5 #bottom radius = 91.5, height = 139.5
  l. s3d l[2]
    r 3,{h/3},1,1,-1 permute cyzx
    f "XYZ = I; XYZ[2]>0?XYZ*[0.7346,0.7346,1]:XYZ" # Make top of cylinder smaller. top radius = (134.5/2) | 134.5 is 73.46% of 183.1
    permute cyzx
  endl y a y endl
  t3d. .. rm..

Now it looks like the lampshade I’m trying to tweak:
https://www.ikea.com/de/de/p/lampan-tischleuchte-weiss-20046988/

as there are many different ways of mapping an image to a cone

You are right, I was not very specific. What I’m looking for is wrapping an rectangular image around the cone and perhaps project an other image to the top.

Ah OK, that is doable also, but probably a bit more difficult to manage.
I’ll see if I can do something, maybe tomorrow, but I’m not sure.

Do you have any news here?

I’ll probably give a try today.

1 Like

Here is what I’ve got so far:
lamp3d

inspired by the idea of having a “lamp”.

Here is the little script that generates this 3d object
(best viewed in flat shading, I don’t know why, looks like there is a bug in G’MIC for rendering lighting of very thin objects).

lamp3d :

  # Side texture.
  sp car

  # Create textured truncated cone.
  w,h={[w,h]} plane3d $w,$h,$w,1 t3d. .. rm..
  s3d l[2] r 3,{h/3},1,1,-1 permute cyzx
  f "P = I;
    ang = P[0]*2*pi/"$w";
    rad = 0.5*"$w"*(P[1]?1:0.5);
    [ rad*cos(ang),P[1],rad*sin(ang)]"
  permute cyzx y
  endl a y

  # Add top cover, with texture.
  cylinder3d {0.5*$w/2},1,$w
  sp lena
  t3d.. . rm.
  r3d. 1,0,0,90

  # Add bottom base.
  cylinder3d {0.25*$w/2},$h
  r3d. 1,0,0,90 +3d. 0,$h,0
  col3d. 0,128,255

  # Merge the 3d objects together.
  +3d
3 Likes

I know this is a little too far off, but NURBS would be interesting to have on G’MIC. Basic NURBS would be all that’s needed on G’MIC as it’s a little too computationally costly for more complicated NURBS/SOLIDS objects, and especially industrial design stuff (That’s probably impossible). It solves the issue of those edges and flatshade. That being said, this project gives me some interesting idea. Like, you could use high tri-count polygonal object to create interesting distortion.

With the lamp you are absolutely right. This is the result from the Lamp workshop at the LGM:

I played a little bit with the script and made some small changes for my need:

lamp3d :

# height = 140 
# top radius = (134.5/2)
# bottom radius = 91.5

  # Side texture.
  #sample car

  # Create textured truncated cone.
  w,h={[183,140]} plane3d $w,$h,$w,1 texturize3d. .. rm..        
  split3d l[2] r 3,{h/3},1,1,-1 permute cyzx
  f "P = I;
    ang = P[0]*2*pi/"$w";
    #rad = 0.5*"$w"*(P[1]?1:0.5);
    rad = 0.5*"$w"*(P[1]?1:0.7346);                             
    [ rad*cos(ang),P[1],rad*sin(ang)]"
  permute cyzx y
  endl a y

  # Add top cover, with texture.
  cylinder3d {0.7346*$w/2},1,$w
#  sample lena
#  texturize3d.. . rm.
  rotate3d. 1,0,0,90
  color3d. 255,255,255

  # Add bottom cover, without texture.
  cylinder3d {$w/2},1,$w
  rotate3d. 1,0,0,90
  add3d[2] 0,{$h},0
 
  # Add bottom base.
  cylinder3d {0.33*$w/2},{$h*2}
  rotate3d. 1,0,0,90 +3d. 0,{$h*2},0
  color3d. 255,255,255

  # Merge the 3d objects together.
  +3d #add3d

This is my test image:

And I start it with this command:
gmic Lampe4.png -command lamp.gmic -lamp3d

And this is my result:

@David_Tschumperle I was just not able to figure out how to replace the ’ sample lena’ with an image I can set via the parameters.

2 Likes

This small change makes it easier:

lamp3d :

  # Create truncated cone, with texture [0].
  l[0]
    w,h={[w,h]} plane3d $w,$h,$w,1 t3d. .. rm..
    s3d l[2] r 3,{h/3},1,1,-1 permute cyzx
    f "P = I;
      ang = P[0]*2*pi/"$w";
      rad = 0.5*"$w"*(P[1]?1:0.5);
      [ rad*cos(ang),P[1],rad*sin(ang)]"
    permute cyzx y
    endl a y
  endl

  # Add top cover, with texture [1].
  l[1]
    cylinder3d {0.5*$w/2},1,$w
    t3d. .. rm..
    r3d. 1,0,0,90
  endl

  # Add bottom base.
  cylinder3d {0.25*$w/2},$h
  r3d. 1,0,0,90 +3d. 0,$h,0
  col3d. 0,128,255

  # Merge the 3d objects together.
  +3d

Then:

$ gmic image1.jpg image2.jpg lamp3d

For what its worth here are the “original” values I used in preparation for the workshop:

upper diameter: 134.5mm
lower diameter: 183.1mm
height: 139.5mm

I did some more complicated math to get a more conformal mapping (i.e. the aspect ratios change as little as possible between the upper and the lower end). I’ll have to do a proper writeup on that though.

Bye,
Simon

1 Like