@@ -9,52 +9,67 @@ import {
99 group ,
1010 bounds3ToSize ,
1111 vec3 ,
12- boundsScene ,
1312 rotationForCameraPos ,
13+ bounds3FromPosAndSize ,
14+ Bounds3 ,
15+ bounds3Merge ,
16+ bounds3Center ,
1417} from "../../abstract-3d.js" ;
15- import { dxfFooter , dxfHeader } from "./dxf-encoding.js" ;
18+ import { dxf , Handle } from "./dxf-encoding.js" ;
1619import { dxfPlane } from "./dxf-geometries/dxf-plane.js" ;
1720import { dxfBox } from "./dxf-geometries/dxf-box.js" ;
1821import { dxfCylinder } from "./dxf-geometries/dxf-cylinder.js" ;
1922import { dxfCone } from "./dxf-geometries/dxf-cone.js" ;
2023import { dxfPolygon } from "./dxf-geometries/dxf-polygon.js" ;
21- import { generateUUID } from "three/src/math/MathUtils.js" ;
2224import { Optional } from "../shared.js" ;
2325
2426const DEFAULT_CYLINDER_SIDE_COUNT = 18 ;
2527
2628export type DxfOrigin = "BottomLeftFront" | "Center" ;
2729export type DxfOptions = { readonly view : View ; readonly origin : DxfOrigin ; readonly cylinderSideCount : number } ;
2830
29- export const render = ( scene : Scene , options : Optional < DxfOptions > ) : string => {
31+ export function renderScenes (
32+ scenes : ReadonlyArray < { readonly scene : Scene ; readonly options ?: Optional < DxfOptions > ; readonly pos : Vec3 } >
33+ ) : string {
34+ let allGroups = "" ;
35+ const allBounds = Array < Bounds3 > ( ) ;
36+ const handle = { handle : 0x1000 } ;
37+ for ( const view of scenes ) {
38+ const { groups } = dxfGroups ( view . scene , { ...view . options , view : undefined , origin : undefined } , view . pos , handle ) ;
39+ allGroups += groups ;
40+ allBounds . push ( bounds3FromPosAndSize ( view . scene . center_deprecated ?? vec3Zero , view . scene . size_deprecated ) ) ;
41+ }
42+ const bounds = bounds3Merge ( ...allBounds ) ;
43+ return dxf ( allGroups , bounds3Center ( bounds ) , bounds3ToSize ( bounds ) ) ;
44+ }
45+
46+ export const render = ( scene : Scene , options ?: Optional < DxfOptions > ) : string => {
47+ const center = scene . center_deprecated ?? vec3Zero ;
48+ const bounds = bounds3FromPosAndSize ( center , scene . size_deprecated ) ;
49+ const offset =
50+ options ?. origin === "Center" ? vec3Zero : vec3 ( Math . abs ( bounds . min . x ) , Math . abs ( bounds . min . y ) , - bounds . max . z ) ;
51+ const res = dxfGroups ( scene , options , offset , { handle : 0x1000 } ) ;
52+ return dxf ( res . groups , center , scene . size_deprecated ) ;
53+ } ;
54+
55+ const dxfGroups = (
56+ scene : Scene ,
57+ options : Optional < DxfOptions > | undefined ,
58+ offset : Vec3 ,
59+ handleRef : Handle //make sure we start with a value higher than any other handle id's used in the header
60+ ) : { readonly groups : string } => {
3061 const opts : DxfOptions = {
31- view : options . view ?? "front" ,
32- origin : options . origin ?? "BottomLeftFront" ,
62+ view : options ? .view ?? "front" ,
63+ origin : options ? .origin ?? "BottomLeftFront" ,
3364 cylinderSideCount : DEFAULT_CYLINDER_SIDE_COUNT ,
3465 } ;
3566 const unitRot = vec3RotCombine ( rotationForCameraPos ( opts . view ) , scene . rotation_deprecated ?? vec3Zero ) ;
36- const boundingBox = boundsScene ( scene ) ;
37- const boundingBoxSize = bounds3ToSize ( boundingBox ) ;
38- const center = vec3Zero ;
39- const offset =
40- opts . origin === "Center"
41- ? vec3Zero
42- : vec3 ( Math . abs ( boundingBox . min . x ) , Math . abs ( boundingBox . min . y ) , - boundingBox . max . z ) ;
67+ const center = scene . center_deprecated ?? vec3Zero ;
4368 const groupRoot = group ( [ ] , offset , vec3Zero , scene . groups ) ;
44- const id = generateUUID ( ) ;
45- const handleRef = { handle : 0x1000 } ; //make sure we start with a value higher than any other handle id's used in the header
46- return (
47- dxfHeader ( boundingBoxSize , center , id ) + dxfGroup ( groupRoot , center , unitRot , options , handleRef ) + dxfFooter ( id )
48- ) ;
69+ return { groups : dxfGroup ( groupRoot , center , unitRot , opts , handleRef ) } ;
4970} ;
5071
51- function dxfGroup (
52- g : Group ,
53- parentPos : Vec3 ,
54- parentRot : Vec3 ,
55- options : Optional < DxfOptions > ,
56- handleRef : { handle : number }
57- ) : string {
72+ function dxfGroup ( g : Group , parentPos : Vec3 , parentRot : Vec3 , options : DxfOptions , handleRef : Handle ) : string {
5873 const pos = vec3TransRot ( g . pos , parentPos , parentRot ) ;
5974 const rot = vec3RotCombine ( parentRot , g . rot ?? vec3Zero ) ;
6075 return (
@@ -67,30 +82,10 @@ function dxfGroup(
6782 return a + dxfBox ( c . geometry , c . material , pos , rot , handleRef ) ;
6883 }
6984 case "Cylinder" : {
70- return (
71- a +
72- dxfCylinder (
73- c . geometry ,
74- c . material ,
75- options . cylinderSideCount ?? DEFAULT_CYLINDER_SIDE_COUNT ,
76- pos ,
77- rot ,
78- handleRef
79- )
80- ) ;
85+ return a + dxfCylinder ( c . geometry , c . material , options . cylinderSideCount , pos , rot , handleRef ) ;
8186 }
8287 case "Cone" : {
83- return (
84- a +
85- dxfCone (
86- c . geometry ,
87- c . material ,
88- options . cylinderSideCount ?? DEFAULT_CYLINDER_SIDE_COUNT ,
89- pos ,
90- rot ,
91- handleRef
92- )
93- ) ;
88+ return a + dxfCone ( c . geometry , c . material , options . cylinderSideCount , pos , rot , handleRef ) ;
9489 }
9590 case "Polygon" : {
9691 return a + dxfPolygon ( c . geometry , c . material , pos , rot , handleRef ) ;
0 commit comments