POV-Ray : Newsgroups : povray.newusers : Simple CSG Question : Re: Simple CSG Question Server Time
7 Jul 2024 08:35:53 EDT (-0400)
  Re: Simple CSG Question  
From: Alain
Date: 9 Jan 2010 16:46:49
Message: <4b48f949$1@news.povray.org>

> I apologise if this has been covered many times before.
It's the place to ask those question, even if they have been asked before.
>
> Is it possible to declare an object in such a way that when it is unioned with
> another object(s) it carries a "hole" with it?   There may be a clever way of
> doing this that I have missed, it must be a common enough situation for objects
> intended for reuse... Doors, Windows etc .
>
> For example declaring an object comprising of  a door Frame and a door slightly
> ajar which when unioned with  a wall it also punches a hole in the wall.    I
> appreciate I can do something like ...
>
It's best to never define any object inside an union, difference or 
intersection. It can get REALY confusing.
Declare those components before the start of the union.

> union
> {
>          #declare Wall = box {<-3*m, 0*m, -5*cm>   <  1*m,  3*m,  5*cm>    pigment
> {brick Grey, Orange scale 2}}
>          #declare door1 = object{SingleDoor translate -0.5*m*x}
>          object{door1}
>          #declare door2 = object{SingleDoor translate -1.5*m*x}
>          object{door2}
>          difference
>          {
>                  object{Wall}
>                  box{ min_extent(door1), max_extent(door1) }  //punch a hole!
>                  box{ min_extent(door2), max_extent(door2) }  //punch a hole!
>          }
> }
Use this construction instead:
#declare Wall = box {<-3*m, 0*m, -5*cm>   <  1*m,  3*m,  5*cm>}
#declare Door1 = object{SingleDoor translate -0.5*m*x}
#declare Door2 = object{SingleDoor translate -1.5*m*x}

union{
	difference{
		object{Wall}
		box{ min_extent(Door1), max_extent(door1) }
		box{ min_extent(Door2), max_extent(door2) }
		}
	object{Door1}
	object{Door2}
	pigment{brick Grey, Orange scale 2}
	}

It's much cleaner and easier to understand.
This assume that the object SingleDoor does have it's own texture.
You also can use the object SingleDoor directly and translate it as needed.

> but this feels long winded to me, and I just want to make sure it is the best
> approach that everyone uses for this situation.
>
> Ideally I would like to be able to declare SingleDoor such that it also defines
> the hole to be punched in the wall allowing the above to be replaced with
> something like ...
>
> union
> {
>          box {<-3*m, 0*m, -5*cm>   <  1*m,  3*m,  5*cm>    pigment {brick Grey,
> Orange scale 2}}
>          object{SingleDoorWithHole translate -0.5*m*x}
>          object{SingleDoorWithHole translate -1.5*m*x}
> }
>
> I appreciate the semantics of my above idealised example could be/is confusing
> and ambiguous with other objects in the union and is therefore probably not
> possible or implemented, but again I just want to make sure I'm adopting the
> best approach and that I've not missed any aspect of POV CSG type functionality
> which makes this task easier, clearer or more concise.
>
>
>
>
If you define an object as:
#declare Object_With_Hole=


That object can be used many times and will always have an hole in it.

On the other hand, it's not possible to define any object that will 
punsh a hole in another when unioned with it. Only difference and 
intersection can remove parts from an object.

Other ways that you can do something similar:

Make your doors, including their texture, with a part of untextured wall 
over them. Make an union with those doors and the parts of the wall that 
lies between the doors. Apply the wall's texture to the complete union. 
The texture will be applied to the wall, and the untextured parts of the 
door objects. There will be no discontinuity as you pass from one part 
the the next. The textured parts of the doors will keep their original 
texture.

Create the wall as a prism object that already include the cutouts for 
any door and windows.

Those two methods can be much faster to render if you have several 
walls, each with many openings.



Alain


Post a reply to this message

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