POV-Ray : Newsgroups : povray.general : Can textures be applied to nested objects from outside? : Re: Can textures be applied to nested objects from outside? Server Time
7 May 2024 19:54:46 EDT (-0400)
  Re: Can textures be applied to nested objects from outside?  
From: Alain
Date: 23 Jan 2019 18:58:51
Message: <5c48ffbb$1@news.povray.org>
Le 19-01-23 à 18:02, kendfrey a écrit :
> I have a composite object (union) in a declared identifier, and my scene will
> contain many copies of that object. What I need is a way to specify the texture
> for the various components of the object, per copy, without having to
> reconstruct the object every time.
> 
> For example, suppose my object is the figure of a person, with components for
> the person's hair, skin, and clothing. The goal is to be able to place the
> figure multiple times in the scene, with different hair, skin, and clothing for
> each instance.
> 
> I haven't been able to find a straightforward way to do this. Here are some
> things I considered:
> - Using a macro instead of declaring the object. This would bloat the code quite
> significantly, since each component would need to be stored separately in its
> own identifier, and recombined every time it's used.
> - UV mapping with non-overlapping UV ranges per component. Unfortunately this
> isn't supported by every type of object, and it may conflict* with other parts
> of the scene.
> - Temporarily using the #default texture. This won't work properly with multiple
> components, though.
> 
> What I'd like is something like this, where identifiers are evaluated when the
> object is added to the scene:
> 
> #declare Foo = union
> {
>      sphere
>      {
>          <0, 0, 0>, 1
>          pigment { SpherePigment }
>      }
>      box
>      {
>          <0, 0, 0>, <1, 1, 1>
>          pigment { BoxPigment }
>      }
> }
> #declare SpherePigment = pigment { color Red }
> #declare BoxPigment = pigment { color Blue }
> object { Foo } // A red sphere and a blue box
> 
> Is there something I missed, or is this impossible in general?
> 
> 
> * I eventually hope to use UV mapping (or something similar) in a way that
> selects from a 3D texture map instead of directly wrapping a 2D texture onto the
> surface. This is to avoid artifacts that would be caused by tiling a fixed 2D
> image. I don't know if this is relevant to the main question, but I'm including
> it for completeness.
> 
> 

The best way would be a macro. The macro would get the various colours 
as parameters, of from global variables set before it's invocation.
Also, the dominant texture could be left undefined. This allow it to be 
applied as follow :
#macro Foo =(C1)
  union{
     sphere
     {
         <0, 0, 0>, 1
         pigment { C1 }
     }
     box
     {
         <0, 0, 0>, <1, 1, 1>
     }
}
#end

#declare SpherePigment = pigment { color Red }
#declare MainPigment = pigment { color Blue }

object{Foo(SpherePigment) pigment{MainPigment }}


Post a reply to this message

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