POV-Ray : Newsgroups : povray.general : Can textures be applied to nested objects from outside? : Can textures be applied to nested objects from outside? Server Time
25 Apr 2024 09:13:01 EDT (-0400)
  Can textures be applied to nested objects from outside?  
From: kendfrey
Date: 23 Jan 2019 18:05:00
Message: <web.5c48ed2fe639bd6ec059c35f0@news.povray.org>
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.


Post a reply to this message

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