@@ -17,6 +17,8 @@ import {
1717 vec3Add ,
1818 vec3Rot ,
1919 sizeCenterBoundsForCameraPos ,
20+ vec3Sub ,
21+ vec3Scale ,
2022} from "../../abstract-3d.js" ;
2123import { dxf , DxfOrigin , Handle } from "./dxf-encoding.js" ;
2224import { dxfPlane } from "./dxf-geometries/dxf-plane.js" ;
@@ -36,6 +38,7 @@ export function renderScenes(scenes: ReadonlyArray<DxfScene>, baseOptions?: Opti
3638 let allGroups = "" ;
3739 const allBounds = Array < Bounds3 > ( ) ;
3840 const handle = { handle : 0x1000 } ;
41+
3942 for ( const view of scenes ) {
4043 const { groups, size, center } = dxfGroups (
4144 view . scene ,
@@ -44,8 +47,9 @@ export function renderScenes(scenes: ReadonlyArray<DxfScene>, baseOptions?: Opti
4447 handle
4548 ) ;
4649 allGroups += groups ;
47- allBounds . push ( bounds3FromPosAndSize ( center , size ) ) ;
50+ allBounds . push ( bounds3FromPosAndSize ( view . pos , size ) ) ;
4851 }
52+
4953 const bounds = bounds3Merge ( ...allBounds ) ;
5054 return dxf ( allGroups , bounds3Center ( bounds ) , bounds3ToSize ( bounds ) , "Center" ) ;
5155}
@@ -73,16 +77,16 @@ const dxfGroups = (
7377 scene : Scene ,
7478 options : DxfOptions ,
7579 offset : Vec3 ,
76- handleRef : Handle //make sure we start with a value higher than any other handle id's used in the header
80+ handleRef : Handle
7781) : { readonly groups : string ; readonly size : Vec3 ; readonly center : Vec3 } => {
7882 const unitRot = vec3RotCombine ( rotationForCameraPos ( options . view ) , scene . rotation_deprecated ?? vec3Zero ) ;
7983 const unitPos = vec3Rot ( scene . center_deprecated ?? vec3Zero , vec3Zero , scene . rotation_deprecated ?? vec3Zero ) ;
8084 const [ size , center ] = sizeCenterBoundsForCameraPos ( scene . size_deprecated , unitPos , unitRot , 1 ) ;
81- const centerWithOffset = vec3Add ( center , offset ) ;
85+ const origin = vec3 ( center . x + size . x * 0.5 , center . y + size . y * 0.5 , center . z ) ;
8286 return {
83- groups : scene . groups . reduce ( ( a , c ) => a + dxfGroup ( c , centerWithOffset , unitRot , options , handleRef ) , "" ) ,
87+ groups : scene . groups . reduce ( ( a , c ) => a + dxfGroup ( c , vec3Add ( origin , offset ) , unitRot , options , handleRef ) , "" ) ,
8488 size,
85- center : centerWithOffset ,
89+ center,
8690 } ;
8791} ;
8892
@@ -91,7 +95,7 @@ function dxfGroup(g: Group, parentPos: Vec3, parentRot: Vec3, options: DxfOption
9195 const rot = vec3RotCombine ( parentRot , g . rot ?? vec3Zero ) ;
9296
9397 let dxf = "" ;
94- for ( const mesh of g . meshes ?? [ ] ) {
98+ for ( const mesh of g . meshes ?? [ ] ) {
9599 switch ( mesh . geometry . type ) {
96100 case "Plane" : {
97101 dxf += dxfPlane ( mesh . geometry , mesh . material , pos , rot , handleRef ) ;
@@ -118,7 +122,7 @@ function dxfGroup(g: Group, parentPos: Vec3, parentRot: Vec3, options: DxfOption
118122 }
119123 }
120124
121- for ( const group of g . groups ?? [ ] ) {
125+ for ( const group of g . groups ?? [ ] ) {
122126 dxf += dxfGroup ( group , pos , rot , options , handleRef ) ;
123127 }
124128
0 commit comments