POV-Ray : Newsgroups : povray.programming : Primitive BOX, how to wrap a texture? Server Time
12 Dec 2024 17:34:28 EST (-0500)
  Primitive BOX, how to wrap a texture? (Message 1 to 10 of 14)  
Goto Latest 10 Messages Next 4 Messages >>>
From: GioSeregni
Subject: Primitive BOX, how to wrap a texture?
Date: 12 Nov 2023 08:30:00
Message: <web.6550d2d966418b42d0d0a7c459126100@news.povray.org>
First of all, I apologize for the naivety of the question.
I am not able to get the surfaces of the BOX with the actual texture.

Example:

box{<0.5000,1.0000,0.2500>,<-3,-1.0000,-0.2500>
 texture {pigment {image_map
 {png "130PINK" map_type 1
 interpolate 2
}
 scale 1.30
}}
 rotate<0,360.0000,0> translate<46.7000,-0.0900,14.0700>
}

Well, Map 0 fails on some faces, Map 1 and map 2 deform the texture.
How can I wrap a texture correctly?
I studied the UV Mapping, but I practically understood nothing.
How should I correct my example to get the same texture uniformly on all faces?
A huge thank you if anyone helps me.

BR
Giovanni


Post a reply to this message

From: Mike Miller
Subject: Re: Primitive BOX, how to wrap a texture?
Date: 12 Nov 2023 09:55:00
Message: <web.6550e5f979784ca8f22cdb33dabc9342@news.povray.org>
"GioSeregni" <gms### [at] hotmailcom> wrote:
> First of all, I apologize for the naivety of the question.
> I am not able to get the surfaces of the BOX with the actual texture.
>
> Example:
>
> box{<0.5000,1.0000,0.2500>,<-3,-1.0000,-0.2500>
>  texture {pigment {image_map
>  {png "130PINK" map_type 1
>  interpolate 2
> }
>  scale 1.30
> }}
>  rotate<0,360.0000,0> translate<46.7000,-0.0900,14.0700>
> }
>
> Well, Map 0 fails on some faces, Map 1 and map 2 deform the texture.
> How can I wrap a texture correctly?
> I studied the UV Mapping, but I practically understood nothing.
> How should I correct my example to get the same texture uniformly on all faces?
> A huge thank you if anyone helps me.
>
> BR
> Giovanni

There is no 'box' mapping in POV. You could hand code the box out of clipped
planes, mapping each side by rotating map 'type 0' to face each side. There's
probably a macro that someone has written to do just that.

I wrote a macro that 'box maps' the Round_Box macro. It can simulate a square
edged box if you set the edge radius fillet very low.
Miller

//  make mapped box
//  diced Round_Box() into a 6 sided uv mapped Round Box
//  m.miller  05.21.23

#include "shapes.inc"
#include "shapes2.inc"


#macro make_mapped_box (w,h,d,f,mat,z_dir)
#declare _form = object{ Round_Box(<-w/2,0,0>,<w/2,h,d>, f , 1) }
union {
    // X  right
    difference {
         object { _form }
         plane { <1,0,0>, 0 translate <w/2-f/2,0,0> }
         plane { <1,0,0>, 0 rotate <0,-45,0> translate <w/2,0,0> }
         plane { <1,0,0>, 0 rotate <0,45,0> translate <w/2,0,d> }
         plane { <0,-1,0>, 0 rotate <0,0,45> translate <w/2,h,0> }
         plane { <0, 1,0>, 0 rotate <0,0,-45> translate <w/2,0,0> }
         material {mat rotate <0,-90,0> translate <0,0,0> }
         #if (z_dir)
            material {mat rotate <0,-90,0> rotate <90,0,0> translate <0,0,0> }
         #end
         rotate <0,0,0>
         translate <0,0,0>
   }


    // X  left
    difference {
         object { _form }
         plane { <1,0,0>, 0 translate <w/2-f/2,0,0> }
         plane { <1,0,0>, 0 rotate <0,-45,0> translate <w/2,0,0> }
         plane { <1,0,0>, 0 rotate <0,45,0> translate <w/2,0,d> }
         plane { <0,-1,0>, 0 rotate <0,0,45> translate <w/2,h,0> }
         plane { <0, 1,0>, 0 rotate <0,0,-45> translate <w/2,0,0> }
         material {mat rotate <0,-90,0> translate <0,0,0> }
         #if (z_dir)
            material {mat rotate <0,-90,0> rotate <90,0,0> translate <0,0,0> }
         #end
         rotate <0,180,0>
         translate <0,0,d>
    }


    // Y  top/bottom
    difference {
         object { _form }
         plane {<0,-1,0> 0 rotate <0,0,0> translate <0,f/2,0>}
         plane {<0,-1,0> 0 rotate <-45,0,0> translate <0,0,0>}
         plane {<0,-1,0> 0 rotate <45,0,0> translate <0,0,d>}
         plane {<0,-1,0> 0 rotate <0,0,-45> translate <w/2,0,0>}
         plane {<0,-1,0> 0 rotate <0,0,45> translate <-w/2,0,0>}
         material {mat rotate <-90,180,0> translate <-w/2,0,0> }
         rotate <0,0,0>
         translate <0,0,0>
    }

    // Y  top/bottom
    difference {
         object { _form }
         plane {<0,-1,0> 0 rotate <0,0,0> translate <0,f/2,0>}
         plane {<0,-1,0> 0 rotate <-45,0,0> translate <0,0,0>}
         plane {<0,-1,0> 0 rotate <45,0,0> translate <0,0,d>}
         plane {<0,-1,0> 0 rotate <0,0,-45> translate <w/2,0,0>}
         plane {<0,-1,0> 0 rotate <0,0,45> translate <-w/2,0,0>}
         material {mat rotate <-90,180,0> translate <-w/2,0,0> }
         rotate <0,0,180>
         translate <0,h,0>
    }

    // Y  front
    difference {
         object { _form }

         plane { <0,0,-1>, 0 translate <0,0,f/2> }
         plane {<-1,0,0>,0 rotate <0,-45,0> translate <w/2,0,0>     }
         plane {<1,0,0>,0  rotate <0,45,0>  translate <-w/2,0,0>   }
         plane {<0,-1,0>,0   rotate <45,0,0>  translate <0,h,0> }
         plane {<0,1,0>,0   rotate  <-45,0,0>  translate <0,0,0> }
         material {mat rotate <0,0,0> translate <-w/2,0,0> }
         rotate <0,0,0>
         translate <0,0,0>
    }

    // Y  back
    difference {
         object { _form }
         plane { <0,0,-1>, 0 translate <0,0,f/2> }
         plane {<-1,0,0>,0 rotate <0,-45,0> translate <w/2,0,0>     }
         plane {<1,0,0>,0  rotate <0,45,0>  translate <-w/2,0,0>   }
         plane {<0,-1,0>,0   rotate <45,0,0>  translate <0,h,0> }
         plane {<0,1,0>,0   rotate  <-45,0,0>  translate <0,0,0> }
         material {mat rotate <0,0,0> translate <-w/2,0,0> }
         rotate <0,180,0>
         translate <0,0,d>
    }

}
#end

---------------------------------------
Usage example:


#declare _mat    =   M_wood;
#declare _z_dir  =   1;
#declare _fillet =   .2;
#declare _width  =   5;
#declare _height =   5;
#declare _depth  =   10;

object { make_mapped_box(_width, _height, _depth, _fillet, _mat, _z_dir)
translate <0,0,-_depth/2> rotate <0,30,0> translate <-10,0,0>}


Post a reply to this message


Attachments:
Download 'box_mapped_uv.png' (703 KB)

Preview of image 'box_mapped_uv.png'
box_mapped_uv.png


 

From: GioSeregni
Subject: Re: Primitive BOX, how to wrap a texture?
Date: 12 Nov 2023 10:20:00
Message: <web.6550ecb079784ca8d0d0a7c459126100@news.povray.org>
"Mike Miller" <mil### [at] gmailcom> wrote:
> "GioSeregni" <gms### [at] hotmailcom> wrote:
> > First of all, I apologize for the naivety of the question.
> > I am not able to get the surfaces of the BOX with the actual texture.
> >
.....
> > How should I correct my example to get the same texture uniformly on all faces?
> > A huge thank you if anyone helps me.
> >
> > BR
> > Giovanni
>
> There is no 'box' mapping in POV. You could hand code the box out of clipped
> planes, mapping each side by rotating map 'type 0' to face each side. There's
> probably a macro that someone has written to do just that.
>
> I wrote a macro that 'box maps' the Round_Box macro. It can simulate a square
> edged box if you set the edge radius fillet very low.
> Miller
>
> //  make mapped box
> //  diced Round_Box() into a 6 sided uv mapped Round Box
> //  m.miller  05.21.23
>
> #include "shapes.inc"
> #include "shapes2.inc"
>
>
> #macro make_mapped_box (w,h,d,f,mat,z_dir)
> #declare _form = object{ Round_Box(<-w/2,0,0>,<w/2,h,d>, f , 1) }
> union {
>     // X  right
>     difference {
>          object { _form }
>          plane { <1,0,0>, 0 translate <w/2-f/2,0,0> }
>          plane { <1,0,0>, 0 rotate <0,-45,0> translate <w/2,0,0> }
>          plane { <1,0,0>, 0 rotate <0,45,0> translate <w/2,0,d> }
>          plane { <0,-1,0>, 0 rotate <0,0,45> translate <w/2,h,0> }
>          plane { <0, 1,0>, 0 rotate <0,0,-45> translate <w/2,0,0> }
>          material {mat rotate <0,-90,0> translate <0,0,0> }
>          #if (z_dir)
>             material {mat rotate <0,-90,0> rotate <90,0,0> translate <0,0,0> }
>          #end
>          rotate <0,0,0>
>          translate <0,0,0>
>    }
>
>
>     // X  left
>     difference {
>          object { _form }
>          plane { <1,0,0>, 0 translate <w/2-f/2,0,0> }
>          plane { <1,0,0>, 0 rotate <0,-45,0> translate <w/2,0,0> }
>          plane { <1,0,0>, 0 rotate <0,45,0> translate <w/2,0,d> }
>          plane { <0,-1,0>, 0 rotate <0,0,45> translate <w/2,h,0> }
>          plane { <0, 1,0>, 0 rotate <0,0,-45> translate <w/2,0,0> }
>          material {mat rotate <0,-90,0> translate <0,0,0> }
>          #if (z_dir)
>             material {mat rotate <0,-90,0> rotate <90,0,0> translate <0,0,0> }
>          #end
>          rotate <0,180,0>
>          translate <0,0,d>
>     }
>
>
>     // Y  top/bottom
>     difference {
>          object { _form }
>          plane {<0,-1,0> 0 rotate <0,0,0> translate <0,f/2,0>}
>          plane {<0,-1,0> 0 rotate <-45,0,0> translate <0,0,0>}
>          plane {<0,-1,0> 0 rotate <45,0,0> translate <0,0,d>}
>          plane {<0,-1,0> 0 rotate <0,0,-45> translate <w/2,0,0>}
>          plane {<0,-1,0> 0 rotate <0,0,45> translate <-w/2,0,0>}
>          material {mat rotate <-90,180,0> translate <-w/2,0,0> }
>          rotate <0,0,0>
>          translate <0,0,0>
>     }
>
>     // Y  top/bottom
>     difference {
>          object { _form }
>          plane {<0,-1,0> 0 rotate <0,0,0> translate <0,f/2,0>}
>          plane {<0,-1,0> 0 rotate <-45,0,0> translate <0,0,0>}
>          plane {<0,-1,0> 0 rotate <45,0,0> translate <0,0,d>}
>          plane {<0,-1,0> 0 rotate <0,0,-45> translate <w/2,0,0>}
>          plane {<0,-1,0> 0 rotate <0,0,45> translate <-w/2,0,0>}
>          material {mat rotate <-90,180,0> translate <-w/2,0,0> }
>          rotate <0,0,180>
>          translate <0,h,0>
>     }
>
>     // Y  front
>     difference {
>          object { _form }
>
>          plane { <0,0,-1>, 0 translate <0,0,f/2> }
>          plane {<-1,0,0>,0 rotate <0,-45,0> translate <w/2,0,0>     }
>          plane {<1,0,0>,0  rotate <0,45,0>  translate <-w/2,0,0>   }
>          plane {<0,-1,0>,0   rotate <45,0,0>  translate <0,h,0> }
>          plane {<0,1,0>,0   rotate  <-45,0,0>  translate <0,0,0> }
>          material {mat rotate <0,0,0> translate <-w/2,0,0> }
>          rotate <0,0,0>
>          translate <0,0,0>
>     }
>
>     // Y  back
>     difference {
>          object { _form }
>          plane { <0,0,-1>, 0 translate <0,0,f/2> }
>          plane {<-1,0,0>,0 rotate <0,-45,0> translate <w/2,0,0>     }
>          plane {<1,0,0>,0  rotate <0,45,0>  translate <-w/2,0,0>   }
>          plane {<0,-1,0>,0   rotate <45,0,0>  translate <0,h,0> }
>          plane {<0,1,0>,0   rotate  <-45,0,0>  translate <0,0,0> }
>          material {mat rotate <0,0,0> translate <-w/2,0,0> }
>          rotate <0,180,0>
>          translate <0,0,d>
>     }
>
> }
> #end
>
> ---------------------------------------
> Usage example:
>
>
> #declare _mat    =   M_wood;
> #declare _z_dir  =   1;
> #declare _fillet =   .2;
> #declare _width  =   5;
> #declare _height =   5;
> #declare _depth  =   10;
>
> object { make_mapped_box(_width, _height, _depth, _fillet, _mat, _z_dir)
> translate <0,0,-_depth/2> rotate <0,30,0> translate <-10,0,0>}


Thank you very much, now I am sure that it is not possible and therefore my
technique makes sense, very similar to yours, for which I thank you.
My parser for PovRay from AutoCAD, written in lisp, in fact, works like this
(polygons instead of planes):

(if (= "DKBCASE"  block)
 (progn
 (IniPovObj)

(write-line (strcat "union
{polygon{5,<-.5,0,.5><.5,0,.5><.5,0,-.5><-.5,0,-.5><-.5,0,.5>") fil) ;1 BOTTOM
(write-line (strcat " scale<"(rtos scX)","(rtos scZ)","(rtos scY)">") fil)
(setq need 0) (filler)
(if (= need 1)(write-line "}" fil))(if (= need 2)(write-line "}}" fil))(if (=
need 3)(write-line "}}}" fil)) ;endif
(write-line rotateXstring fil)(write-line closestring fil)


(write-line (strcat "
polygon{5,<-.5,1,-.5><-.5,1,.5><.5,1,.5><.5,1,-.5><-.5,1,-.5>") fil) ;2 TOP
(write-line (strcat " scale<"(rtos scX)","(rtos scZ)","(rtos scY)">") fil)
(setq need 0) (filler) ............
.............

NOTE the Sub filler essewntially chooses the image...
MANY THANKS!
G.


Post a reply to this message

From: Bald Eagle
Subject: Re: Primitive BOX, how to wrap a texture?
Date: 12 Nov 2023 10:25:00
Message: <web.6550ed8079784ca81f9dae3025979125@news.povray.org>
"GioSeregni" <gms### [at] hotmailcom> wrote:
> First of all, I apologize for the naivety of the question.
> I am not able to get the surfaces of the BOX with the actual texture.
>
> Example:
>
> box{<0.5000,1.0000,0.2500>,<-3,-1.0000,-0.2500>
>  texture {pigment {image_map
>  {png "130PINK" map_type 1
>  interpolate 2
> }
>  scale 1.30
> }}
>  rotate<0,360.0000,0> translate<46.7000,-0.0900,14.0700>
> }
>
> Well, Map 0 fails on some faces, Map 1 and map 2 deform the texture.
> How can I wrap a texture correctly?
> I studied the UV Mapping, but I practically understood nothing.
> How should I correct my example to get the same texture uniformly on all faces?
> A huge thank you if anyone helps me.
>
> BR
> Giovanni

Check out:
https://wiki.povray.org/content/Reference:UV_Mapping

The key lines that you want to pay attention to are:

texture {
    uv_mapping

The uv_mapping statement needs to preceed everything else in the texture
definition for it to work.

Also, depending on how you want that box mapped, then yes, there is indeed a box
mapping, but you need to set up the texture specifically to do that, which might
not be a simple task.

- Bill


Post a reply to this message

From: GioSeregni
Subject: Re: Primitive BOX, how to wrap a texture?
Date: 12 Nov 2023 10:55:00
Message: <web.6550f50179784ca8d0d0a7c459126100@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
> "GioSeregni" <gms### [at] hotmailcom> wrote:
> > First of all, I apologize for the naivety of the question.
> > I am not able to get the surfaces of the BOX with the actual texture.
> >
> > Example:
> >
> > box{<0.5000,1.0000,0.2500>,<-3,-1.0000,-0.2500>
> >  texture {pigment {image_map
> >  {png "130PINK" map_type 1
> >  interpolate 2
> > }
> >  scale 1.30
> > }}
> >  rotate<0,360.0000,0> translate<46.7000,-0.0900,14.0700>
> > }
> >
> > Well, Map 0 fails on some faces, Map 1 and map 2 deform the texture.
> > How can I wrap a texture correctly?
> > I studied the UV Mapping, but I practically understood nothing.
> > How should I correct my example to get the same texture uniformly on all faces?
> > A huge thank you if anyone helps me.
> >
> > BR
> > Giovanni
>
> Check out:
> https://wiki.povray.org/content/Reference:UV_Mapping
>
> The key lines that you want to pay attention to are:
>
> texture {
>     uv_mapping
>
> The uv_mapping statement needs to preceed everything else in the texture
> definition for it to work.
>
> Also, depending on how you want that box mapped, then yes, there is indeed a box
> mapping, but you need to set up the texture specifically to do that, which might
> not be a simple task.
>
> - Bill

Thanks!

in fact I tried but I didn't understand how to implement UV mapping. We would
need at least one example on a cube, on which the texture is wrapped uniformly.
Then everything else, scaling, translating, rotating, re-proportioning on the
axes, is simple.
G


Post a reply to this message

From: Bald Eagle
Subject: Re: Primitive BOX, how to wrap a texture?
Date: 12 Nov 2023 11:30:00
Message: <web.6550fcf479784ca81f9dae3025979125@news.povray.org>
"GioSeregni" <gms### [at] hotmailcom> wrote:

> Thanks!
>
> in fact I tried but I didn't understand how to implement UV mapping.

No problem.  I've been at this for 10 years, and just recently got pretty
confused about the specifics.
https://news.povray.org/povray.general/thread/%3Cweb.641d4cf6eebe912c9b4924336e066e29%40news.povray.org%3E/


We would
> need at least one example on a cube, on which the texture is wrapped uniformly.

Right.  So if you look at the diagram on the wiki, it will show you what needs
to be where, and the exact coordinates for all of the faces.  So you could
image-map some squares and render that with an orthographic camera to give you
an image-map suitable for further uv-mapping,

or

you could write some more complex code to just grab the filenames and make the
uv-mapping texture in memory and do everything in a 1-step render.  And I'd
really need to go look up and study the exact details of doing it that way.

> Then everything else, scaling, translating, rotating, re-proportioning on the
> axes, is simple.

Yes.


- BW


Post a reply to this message

From: Mike Miller
Subject: Re: Primitive BOX, how to wrap a texture?
Date: 12 Nov 2023 12:15:00
Message: <web.6551072a79784ca8f22cdb33dabc9342@news.povray.org>
"GioSeregni" <gms### [at] hotmailcom> wrote:
> "Bald Eagle" <cre### [at] netscapenet> wrote:
> > "GioSeregni" <gms### [at] hotmailcom> wrote:
> > > First of all, I apologize for the naivety of the question.
> > > I am not able to get the surfaces of the BOX with the actual texture.
> > >
> > > Example:
> > >
> > > box{<0.5000,1.0000,0.2500>,<-3,-1.0000,-0.2500>
> > >  texture {pigment {image_map
> > >  {png "130PINK" map_type 1
> > >  interpolate 2
> > > }
> > >  scale 1.30
> > > }}
> > >  rotate<0,360.0000,0> translate<46.7000,-0.0900,14.0700>
> > > }
> > >
> > > Well, Map 0 fails on some faces, Map 1 and map 2 deform the texture.
> > > How can I wrap a texture correctly?
> > > I studied the UV Mapping, but I practically understood nothing.
> > > How should I correct my example to get the same texture uniformly on all faces?
> > > A huge thank you if anyone helps me.
> > >
> > > BR
> > > Giovanni
> >
> > Check out:
> > https://wiki.povray.org/content/Reference:UV_Mapping
> >
> > The key lines that you want to pay attention to are:
> >
> > texture {
> >     uv_mapping
> >
> > The uv_mapping statement needs to preceed everything else in the texture
> > definition for it to work.
> >
> > Also, depending on how you want that box mapped, then yes, there is indeed a box
> > mapping, but you need to set up the texture specifically to do that, which might
> > not be a simple task.
> >
> > - Bill
>
> Thanks!
>
> in fact I tried but I didn't understand how to implement UV mapping. We would
> need at least one example on a cube, on which the texture is wrapped uniformly.
> Then everything else, scaling, translating, rotating, re-proportioning on the
> axes, is simple.
> G

This is one simple way I've mapped boxes or flat surfaces at different angles.
Create the surface slightly larger than what's needed. Difference the surface
with plane or planes that match the angles needed. The planes would carry the
material and transferred the image_map or material to the differenced shape.
Each rotated plane can have its own material, so a 6-sided cube could have 6
materials.
Hope this help,
Mike.


Post a reply to this message


Attachments:
Download 'box_differenced_planes.png' (482 KB)

Preview of image 'box_differenced_planes.png'
box_differenced_planes.png


 

From: Bald Eagle
Subject: Re: Primitive BOX, how to wrap a texture?
Date: 12 Nov 2023 12:55:00
Message: <web.6551112779784ca81f9dae3025979125@news.povray.org>
Also, I forgot to mention the cubic pattern, which might make things
substantially easier.

https://wiki.povray.org/content/Reference:Cubic_Pattern


Post a reply to this message

From: Mike Miller
Subject: Re: Primitive BOX, how to wrap a texture?
Date: 12 Nov 2023 13:10:00
Message: <web.6551141d79784ca8f22cdb33dabc9342@news.povray.org>
"Bald Eagle" <cre### [at] netscapenet> wrote:
> Also, I forgot to mention the cubic pattern, which might make things
> substantially easier.
>
> https://wiki.povray.org/content/Reference:Cubic_Pattern

What! ...cubic pattern.
Does it work with image maps? I'm guessing so, since it references textures.
Must try out. I have an architectural project that could benefit.
Thanks, Mike.


Post a reply to this message

From: Bald Eagle
Subject: Re: Primitive BOX, how to wrap a texture?
Date: 12 Nov 2023 13:55:00
Message: <web.65511f7879784ca81f9dae3025979125@news.povray.org>
"Mike Miller" <mil### [at] gmailcom> wrote:

> What! ...cubic pattern.
> Does it work with image maps? I'm guessing so, since it references textures.
> Must try out. I have an architectural project that could benefit.
> Thanks, Mike.

:D
I know, right?   POV-Ray has SO much stuff that it's difficult to even keep
track of it all, let alone document it, or implement it.

Maybe check out this thread for starters:

https://news.povray.org/povray.binaries.images/thread/%3C5a6748f8%241%40news.povray.org%3E/

- Bill


Post a reply to this message

Goto Latest 10 Messages Next 4 Messages >>>

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