|
162 | 162 | // - sorted (bool): Sort drawables by maximum distance (front to back) |
163 | 163 | // - cull-face (none,str): Enable back-face culling if set to `"cw"` for clockwise |
164 | 164 | // or `"ccw"` for counter-clockwise. Polygons of the specified order will not get drawn. |
165 | | -#let _projection(body, view-matrix, projection-matrix, reset-transform: true, sorted: true, cull-face: "cw") = { |
| 165 | +// - flatten (bool): Set $z=0$ for all geometry |
| 166 | +#let _projection(body, view-matrix, projection-matrix, reset-transform: true, sorted: true, cull-face: "cw", flatten: false) = { |
166 | 167 | (ctx => { |
167 | 168 | let transform = ctx.transform |
168 | 169 | let perspective-mode = type(projection-matrix) == function |
169 | 170 | let previous-perspective-mode = ctx.at("_perspective-projection", default: false) |
170 | 171 | if perspective-mode { |
171 | 172 | ctx._perspective-projection = true |
172 | 173 | } |
173 | | - ctx.transform = view-matrix |
174 | 174 |
|
175 | | - let (ctx, drawables, bounds) = process.many(ctx, util.resolve-body(ctx, body)) |
| 175 | + let local-ctx = ctx |
| 176 | + let local-transform = if flatten { |
| 177 | + local-ctx.transform = matrix.mul-mat( |
| 178 | + ((1,0,0,0), (0,1,0,0), (0,0,0,0), (0,0,0,1.0)), |
| 179 | + view-matrix) |
| 180 | + } else { |
| 181 | + local-ctx.transform = view-matrix |
| 182 | + } |
| 183 | + |
| 184 | + let (ctx, drawables, bounds) = process.many(local-ctx, util.resolve-body(ctx, body)) |
176 | 185 |
|
177 | 186 | if cull-face != none { |
178 | 187 | assert(cull-face in ("cw", "ccw"), |
179 | 188 | message: "cull-face must be none, cw or ccw.") |
180 | 189 | drawables = _filter-cw-faces(drawables, mode: cull-face) |
181 | 190 | } |
| 191 | + |
182 | 192 | if sorted { |
183 | 193 | drawables = _sort-by-distance(drawables) |
184 | 194 | } |
185 | 195 |
|
186 | | - if projection-matrix != none { |
187 | | - drawables = drawable.apply-transform(projection-matrix, drawables) |
188 | | - } |
189 | | - |
190 | 196 | ctx.transform = transform |
191 | 197 | if perspective-mode { |
| 198 | + drawable.apply-transform(projection-matrix, drawables) |
192 | 199 | ctx._perspective-projection = previous-perspective-mode |
193 | 200 | } |
194 | 201 | if not reset-transform { |
|
0 commit comments