discuss@lists.openscad.org

OpenSCAD general discussion

View all threads

Quick alternative to projection() using

G
gingerbeardman
Mon, May 3, 2021 8:30 PM

I want to render a "footprint" shadow of a car, which is enough of a
convincing shadow for me to use in a video game I am making.
I tried using projection() as follows:
module shadow() {  color([0,0,0, 1])  projection()  car();}
...but it was slow.
So I had the idea to squash the model down on the z-axis into a "flat"
surface, which is close enough to what i need and very quick:
module shadow() {  flattenZ = [[ 1  , 0  , 0  , 0  ],        [ 0  , 1  , 0
, 0  ],        [ 0  , 0  , 0.01  , 0  ],        [ 0  , 0  , 0  , 1  ] ];
color([0,0,0, 1])    multmatrix(flattenZ)    car();}
As you can see it's not quite flat, but 0.01 flat, which avoids z-fighting
and is not noticeable to the eye.
Thought this was worth sharing.

--
Sent from: http://forum.openscad.org/

I want to render a "footprint" shadow of a car, which is enough of a convincing shadow for me to use in a video game I am making. I tried using projection() as follows: module shadow() { color([0,0,0, 1]) projection() car();} ...but it was slow. So I had the idea to squash the model down on the z-axis into a "flat" surface, which is close enough to what i need and very quick: module shadow() { flattenZ = [[ 1 , 0 , 0 , 0 ], [ 0 , 1 , 0 , 0 ], [ 0 , 0 , 0.01 , 0 ], [ 0 , 0 , 0 , 1 ] ]; color([0,0,0, 1]) multmatrix(flattenZ) car();} As you can see it's not quite flat, but 0.01 flat, which avoids z-fighting and is not noticeable to the eye. Thought this was worth sharing. -- Sent from: http://forum.openscad.org/
W
Whosawhatsis
Mon, May 3, 2021 8:35 PM

I've used scale() for this in the past. It obviously doesn't let you render or do booleans as if it was 2D, but when you just need the projection for visual purposes, it works fine.
On May 3, 2021, 13:30 -0700, gingerbeardman matt.sephton@gmail.com, wrote:

I want to render a "footprint" shadow of a car, which is enough of a convincing shadow for me to use in a video game I am making.
I tried using projection() as follows:
module shadow() {
color([0,0,0, 1])
projection()
car();
}
...but it was slow.
So I had the idea to squash the model down on the z-axis into a "flat" surface, which is close enough to what i need and very quick:
module shadow() {
flattenZ = [[ 1  , 0  , 0  , 0  ],
[ 0  , 1  , 0  , 0  ],
[ 0  , 0  , 0.01  , 0  ],
[ 0  , 0  , 0  , 1  ] ];

color([0,0,0, 1])
multmatrix(flattenZ)
car();

}
As you can see it's not quite flat, but 0.01 flat, which avoids z-fighting and is not noticeable to the eye.
Thought this was worth sharing.

Sent from the OpenSCAD mailing list archive at Nabble.com.


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

I've used scale() for this in the past. It obviously doesn't let you render or do booleans as if it was 2D, but when you just need the projection for visual purposes, it works fine. On May 3, 2021, 13:30 -0700, gingerbeardman <matt.sephton@gmail.com>, wrote: > I want to render a "footprint" shadow of a car, which is enough of a convincing shadow for me to use in a video game I am making. > I tried using projection() as follows: > module shadow() { > color([0,0,0, 1]) > projection() > car(); > } > ...but it was slow. > So I had the idea to squash the model down on the z-axis into a "flat" surface, which is close enough to what i need and very quick: > module shadow() { > flattenZ = [[ 1 , 0 , 0 , 0 ], > [ 0 , 1 , 0 , 0 ], > [ 0 , 0 , 0.01 , 0 ], > [ 0 , 0 , 0 , 1 ] ]; > > color([0,0,0, 1]) > multmatrix(flattenZ) > car(); > } > As you can see it's not quite flat, but 0.01 flat, which avoids z-fighting and is not noticeable to the eye. > Thought this was worth sharing. > > Sent from the OpenSCAD mailing list archive at Nabble.com. > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org
NH
nop head
Mon, May 3, 2021 9:23 PM

Yes I think the matrix is the same as scale([1,1,0.01])

On Mon, 3 May 2021 at 21:35, Whosawhatsis whosawhatsis@gmail.com wrote:

I've used scale() for this in the past. It obviously doesn't let you
render or do booleans as if it was 2D, but when you just need the
projection for visual purposes, it works fine.
On May 3, 2021, 13:30 -0700, gingerbeardman matt.sephton@gmail.com,
wrote:

I want to render a "footprint" shadow of a car, which is enough of a
convincing shadow for me to use in a video game I am making.

I tried using projection() as follows:

module shadow() {
color([0,0,0, 1])
projection()
car();
}

...but it was slow.

So I had the idea to squash the model down on the z-axis into a "flat"
surface, which is close enough to what i need and very quick:

module shadow() {
flattenZ = [[ 1  , 0  , 0  , 0  ],
[ 0  , 1  , 0  , 0  ],
[ 0  , 0  , 0.01  , 0  ],
[ 0  , 0  , 0  , 1  ] ];

 color([0,0,0, 1])
 multmatrix(flattenZ)
 car();

}

As you can see it's not quite flat, but 0.01 flat, which avoids z-fighting
and is not noticeable to the eye.

Thought this was worth sharing.


Sent from the OpenSCAD mailing list archive http://forum.openscad.org/
at Nabble.com.


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org


OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org

Yes I think the matrix is the same as scale([1,1,0.01]) On Mon, 3 May 2021 at 21:35, Whosawhatsis <whosawhatsis@gmail.com> wrote: > I've used scale() for this in the past. It obviously doesn't let you > render or do booleans as if it was 2D, but when you just need the > projection for visual purposes, it works fine. > On May 3, 2021, 13:30 -0700, gingerbeardman <matt.sephton@gmail.com>, > wrote: > > I want to render a "footprint" shadow of a car, which is enough of a > convincing shadow for me to use in a video game I am making. > > I tried using projection() as follows: > > module shadow() { > color([0,0,0, 1]) > projection() > car(); > } > > ...but it was slow. > > So I had the idea to squash the model down on the z-axis into a "flat" > surface, which is close enough to what i need and very quick: > > module shadow() { > flattenZ = [[ 1 , 0 , 0 , 0 ], > [ 0 , 1 , 0 , 0 ], > [ 0 , 0 , 0.01 , 0 ], > [ 0 , 0 , 0 , 1 ] ]; > > color([0,0,0, 1]) > multmatrix(flattenZ) > car(); > } > > As you can see it's not quite flat, but 0.01 flat, which avoids z-fighting > and is not noticeable to the eye. > > Thought this was worth sharing. > > ------------------------------ > Sent from the OpenSCAD mailing list archive <http://forum.openscad.org/> > at Nabble.com. > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org > > _______________________________________________ > OpenSCAD mailing list > To unsubscribe send an email to discuss-leave@lists.openscad.org >