@@ -21,6 +21,8 @@ import {
2121 bounds2ToSize ,
2222 bounds2Merge ,
2323 vec2Zero ,
24+ vec3Sub ,
25+ vec3Flip ,
2426} from "../../abstract-3d.js" ;
2527import { SvgOptions , zOrderElement } from "./svg-geometries/shared.js" ;
2628import { box } from "./svg-geometries/svg-box.js" ;
@@ -103,21 +105,19 @@ function renderInternal(
103105 ) ;
104106 const svgSize = vec2 ( unitSize . x + 1.5 * opts . stroke_thickness , unitSize . y + 1.5 * opts . stroke_thickness ) ;
105107 const svgCenter = vec2 ( - offset . x + opts . stroke_thickness * 0.75 , offset . y + opts . stroke_thickness * 0.75 ) ;
106-
107108 const point = ( x : number , y : number ) : Vec2 => vec2 ( svgCenter . x + x , svgCenter . y - y ) ;
109+ const unitCenterFlipped = vec3Flip ( unitCenter ) ;
108110
109111 const elements = Array < zOrderElement > ( ) ;
110112 for ( const g of scene . groups ) {
111- const pos = vec3Rot ( g . pos , unitCenter , unitRot ) ;
112- const rot = vec3RotCombine ( unitRot , g . rot ?? vec3Zero ) ;
113- elements . push ( ...svgGroup ( g , pos , rot , point , opts ) ) ;
113+ elements . push ( ...svgGroup ( g , unitCenterFlipped , unitRot , point , opts ) ) ;
114114 }
115115 const dimOpts : SvgOptions = { ...opts , only_stroke : false , gray_scale : false } ;
116116 elements . sort ( ( a , b ) => a . zOrder - b . zOrder ) ;
117117 const cameraPos = vec3Rot ( vec3 ( 1 , 1 , 1 ) , vec3Zero , unitRot ) ;
118118 for ( const d of scene . dimensions_deprecated ?. dimensions ?? [ ] ) {
119119 if ( flipViews ( d . views [ 0 ] , cameraPos ) === opts . view ) {
120- const pos = vec3Rot ( d . pos , unitCenter , unitRot ) ;
120+ const pos = vec3TransRot ( d . pos , unitCenterFlipped , unitRot ) ;
121121 const rot = vec3RotCombine ( unitRot , d . rot ) ;
122122 for ( const m of d . meshes ) {
123123 elements . push ( ...svgMesh ( m , pos , rot , point , scene . dimensions_deprecated ?. material ?? { normal : "" } , dimOpts ) ) ;
@@ -129,19 +129,19 @@ function renderInternal(
129129
130130function svgGroup (
131131 g : Group ,
132- pos : Vec3 ,
133- rot : Vec3 ,
132+ parentPos : Vec3 ,
133+ parentRot : Vec3 ,
134134 point : ( x : number , y : number ) => Vec2 ,
135135 opts : SvgOptions
136136) : ReadonlyArray < zOrderElement > {
137+ const pos = vec3TransRot ( g . pos , parentPos , parentRot ) ;
138+ const rot = vec3RotCombine ( parentRot , g . rot ?? vec3Zero ) ;
137139 const elements = Array < zOrderElement > ( ) ;
138140 for ( const m of g . meshes ?? [ ] ) {
139141 elements . push ( ...svgMesh ( m , pos , rot , point , m . material , opts ) ) ;
140142 }
141143 for ( const sg of g . groups ?? [ ] ) {
142- const sPos = vec3TransRot ( sg . pos , pos , rot ) ;
143- const sRot = vec3RotCombine ( rot , sg . rot ?? vec3Zero ) ;
144- elements . push ( ...svgGroup ( sg , sPos , sRot , point , opts ) ) ;
144+ elements . push ( ...svgGroup ( sg , pos , rot , point , opts ) ) ;
145145 }
146146 return elements ;
147147}
0 commit comments