POV-Ray : Newsgroups : povray.newusers : Placing an image on part of a sphere Server Time
25 Nov 2024 09:34:35 EST (-0500)
  Placing an image on part of a sphere (Message 1 to 3 of 3)  
From: Mark
Subject: Placing an image on part of a sphere
Date: 28 Jan 2006 11:55:00
Message: <web.43dba0f381cd4ef87a062e590@news.povray.org>
Hi, I'm currently working on a pool table project and I'm having trouble
putting the numbers on the balls. I've got a nice pigment for the rest of
the ball but I'd like to place an image with the ball number on it. Is
there an easy way to do this or are there any other ways?

Thanks


Post a reply to this message

From: Warp
Subject: Re: Placing an image on part of a sphere
Date: 28 Jan 2006 12:31:02
Message: <43dbaa55@news.povray.org>
Mark <nomail@nomail> wrote:
> Hi, I'm currently working on a pool table project and I'm having trouble
> putting the numbers on the balls. I've got a nice pigment for the rest of
> the ball but I'd like to place an image with the ball number on it. Is
> there an easy way to do this or are there any other ways?

  You can simply use an image_map pigment using planar mapping (the
default). It should work ok.

  If it gets too distorted, you'll have to apply scaling and a spherical
warp to the pigment.

-- 
                                                          - Warp


Post a reply to this message

From: Smws
Subject: Re: Placing an image on part of a sphere
Date: 2 Feb 2006 15:55:00
Message: <web.43e2713da6428f70135b10720@news.povray.org>
"Mark" <nomail@nomail> wrote:
> Hi, I'm currently working on a pool table project and I'm having trouble
> putting the numbers on the balls. I've got a nice pigment for the rest of
> the ball but I'd like to place an image with the ball number on it. Is
> there an easy way to do this or are there any other ways?
>
> Thanks

Well, funny you should ask.... :)
I just finished a group of macros, one of which should do the trick
procedurally. This will only work if you have a font with the kind of
numbers you want in it. Here the example uses the "timrom.ttf" font
included with POV-Ray.

Also, it turns out there is a much easier and better way to do this, with
the various warps and mappings, but I didn't know that at the time. Anyway
it's already done.

The following example creates a sphere with a bozo base texture and a black
"2":

// begin code==============================================

#include "colors.inc"
#include "shapes.inc"

// Text Sphere
// =======================================================

//--------------------------------------
//****Sphere_Line****
//--------------------------------------
/* Sphere_Line( Radius, Font, Text, Degrees, Spacing, Longitude,
X_Justification,
Text_Texture, Sphere_Texture)

Sphere_Line code was *heavily* borrowed from the Circle_Text macro by Ron
Parker in shapes.inc

Creates a sphere object centered on the origin with text written in a line
around the equator,
in such a way that the text is a solid texture that allows (some) CSG. The
text does not scale
down toward the origin, though.

         Radius: The radius of the sphere around which the letters are
wrapped
           Font: The font to use (see the documentation for the text object)
           Text: The text string
        Degrees: The height of the text on the sphere, in degrees.
        Spacing: The amount of space to add between the letters.
      Longitude: The longitude of the text sart/center/end point
x_Justification: 0=start point (right) 1=center point 2=end point (left)
   Text_Texture: texture of the text
 Sphere_Texture: texture of the sphere
*/

#macro Sphere_Line( R, F, Text, Deg, Spacing, Long, X_Just, Text_Texture,
Sphere_Texture)
  #local Scale= (2*R*sin(radians(Deg/2)));
  #local Width= Text_Width(F, Text, Scale, Spacing);
  #local Text_Object= text {ttf F Text 1 0 scale<Scale, Scale, 1>}
  #local Text_Height= max_extent(Text_Object).y;
  #local C= array[strlen(Text)]
  #local Smidge= 1e-5;
  #if(Width > 2*pi*R)
    #warning concat("nn**** Text string "", Text, "" is too long for a
sphere of the specified radius. Object may not look as planned.nnn")
  #end
  #local Arc_Width= -Width*180/pi/R;
  #local Start_Arc= Long;
  #local End_Arc= Long + Arc_Width;
  #if(X_Just= 2)
     #local Start_Arc= Long - Arc_Width;
     #local End_Arc= Long;
  #else
     #if(X_Just = 1)
        #local Start_Arc= Long - Arc_Width/2;
        #local End_Arc= Long + Arc_Width/2;
     #end
  #end

  #local Count=1;
  #while(Count <= strlen(Text))
    #local Char_Width= Text_Width(F, substr(Text,Count,1), Scale, Spacing);
    #local Whitespace= Text_Width(F, substr(Text,1,Count),Scale,
Spacing)-Char_Width;
    #local Char_Angle= Start_Arc + Arc_Width*Whitespace/Width +
Char_Width/2/Width*Arc_Width;
    #local Text_Object= text {ttf F substr(Text,Count,1) (R-Smidge) 0
scale<Scale, Scale, 1>}
    #local C[Count-1] =
      object { Text_Object
        translate <-Char_Width/2,-Text_Height/2,-(R+Smidge)>
        rotate Char_Angle*y
     }
    #local Count = Count + 1;
  #end
  // create the text object, a union of individual letters.
  #local Text_Sphere_Object= union {
    #local Count=0;
    #while(Count < strlen(Text))
      object {C[Count]}
      #local Count = Count + 1;
    #end
  }
  // create the text texture
  #local Text_Sphere_Texture= texture {
    object {
      Text_Sphere_Object
      texture {Sphere_Texture} //outside text
      texture {Text_Texture} //inside text
    }
  }
  // create the sphere with the text on the surface
  sphere { 0, R
    texture {Text_Sphere_Texture}
  }
#end

#declare TBozo=texture { pigment {bozo color_map {[0 Gray30][.5 Gray35][.5
Gray50][1 Gray50]}} scale .2}
#declare TBlack=texture {pigment {color Black}}

// Sphere_Line( Radius, Font, Text, Degrees, Spacing, Longitude,
X_Justification,
//Text_Texture, Sphere_Texture)

object { Sphere_Line(2,"timrom.ttf","2",0,0,0,1,TBlack,TBozo)
  translate y*2
}
// end code===============================================

hope this helps...
I also have macros that write multiple lines, and that engrave/emboss the
text using csg, and one that writes on the faces of a dodecahedron.

-Stefan Sittler


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.