@@ -121,10 +121,29 @@ public static BBModel Interpret(string fileContent)
121121 }
122122 if ( outliners is not null )
123123 {
124+ BBModel . Outliner rootOutline = null ;
124125 Debug ( "contains outliners" ) ;
125- foreach ( JObject jOutliner in outliners )
126+ foreach ( JToken jOutliner in outliners )
126127 {
127- ReadOutliner ( result , jOutliner , outlineNames ) ;
128+ if ( jOutliner . Type == JTokenType . String )
129+ {
130+ if ( rootOutline is null )
131+ {
132+ rootOutline = new ( )
133+ {
134+ Name = "__root__" ,
135+ Origin = new DoubleVector ( ) ,
136+ Rotation = new DoubleVector ( ) ,
137+ UUID = Guid . NewGuid ( )
138+ } ;
139+ result . Outlines . Add ( rootOutline ) ;
140+ }
141+ AddOutlineChild ( result , rootOutline , jOutliner , outlineNames ) ;
142+ }
143+ else
144+ {
145+ ReadOutliner ( result , ( JObject ) jOutliner , outlineNames ) ;
146+ }
128147 }
129148 }
130149 if ( animations is not null )
@@ -176,6 +195,48 @@ public static BBModel Interpret(string fileContent)
176195
177196 public static HashSet < double > AcceptableRotations = new ( ) { 0 , 22.5 , 45 , - 22.5 , - 45 } ;
178197
198+ public static void AddOutlineChild ( BBModel model , BBModel . Outliner outline , JToken child , Dictionary < string , int > names )
199+ {
200+ if ( child . Type == JTokenType . String )
201+ {
202+ Guid id = Guid . Parse ( ( string ) child ) ;
203+ BBModel . Element element = model . GetElement ( id ) ;
204+ if ( element is null )
205+ {
206+ if ( model . DiscardedIDs . Contains ( id ) )
207+ {
208+ return ;
209+ }
210+ throw new Exception ( $ "Cannot find required element { id } for outline { outline . Name } ") ;
211+ }
212+ if ( AcceptableRotations . Contains ( element . Rotation . X ) && AcceptableRotations . Contains ( element . Rotation . Y ) && AcceptableRotations . Contains ( element . Rotation . Z ) )
213+ {
214+ outline . Children . Add ( id ) ;
215+ }
216+ else
217+ {
218+ BBModel . Outliner specialSideOutline = new ( )
219+ {
220+ Name = $ "{ outline . Name } _auto_{ element . Name } ",
221+ Origin = element . Origin ,
222+ Rotation = element . Rotation ,
223+ UUID = Guid . NewGuid ( ) ,
224+ } ;
225+ element . Rotation = new DoubleVector ( ) ;
226+ element . Origin = new DoubleVector ( ) ;
227+ specialSideOutline . Children . Add ( element . UUID ) ;
228+ model . Outlines . Add ( specialSideOutline ) ;
229+ outline . Paired . Add ( specialSideOutline . UUID ) ;
230+ }
231+ }
232+ else
233+ {
234+ BBModel . Outliner subLine = ReadOutliner ( model , ( JObject ) child , names ) ;
235+ outline . Paired . Add ( subLine . UUID ) ;
236+ outline . Paired . AddRange ( subLine . Paired ) ;
237+ }
238+ }
239+
179240 public static BBModel . Outliner ReadOutliner ( BBModel model , JObject jOutliner , Dictionary < string , int > names )
180241 {
181242 string name = ( string ) jOutliner . GetRequired ( "name" ) ;
@@ -194,47 +255,7 @@ public static BBModel.Outliner ReadOutliner(BBModel model, JObject jOutliner, Di
194255 } ;
195256 foreach ( JToken child in ( JArray ) jOutliner . GetRequired ( "children" ) )
196257 {
197- if ( child . Type == JTokenType . String )
198- {
199- Guid id = Guid . Parse ( ( string ) child ) ;
200- BBModel . Element element = model . GetElement ( id ) ;
201- if ( element is null )
202- {
203- if ( model . DiscardedIDs . Contains ( id ) )
204- {
205- continue ;
206- }
207- throw new Exception ( $ "Cannot find required element { id } for outline { outline . Name } ") ;
208- }
209- if ( AcceptableRotations . Contains ( element . Rotation . X ) && AcceptableRotations . Contains ( element . Rotation . Y ) && AcceptableRotations . Contains ( element . Rotation . Z ) )
210- {
211- outline . Children . Add ( id ) ;
212- }
213- else
214- {
215- BBModel . Outliner specialSideOutline = new ( )
216- {
217- Name = $ "{ outline . Name } _auto_{ element . Name } ",
218- Origin = outline . Origin + element . Origin ,
219- Rotation = element . Rotation ,
220- UUID = Guid . NewGuid ( ) ,
221- } ;
222- // TODO: Is this shift needed?
223- //element.From -= element.Origin;
224- //element.To -= element.Origin;
225- element . Rotation = new DoubleVector ( ) ;
226- element . Origin = new DoubleVector ( ) ;
227- specialSideOutline . Children . Add ( element . UUID ) ;
228- model . Outlines . Add ( specialSideOutline ) ;
229- outline . Paired . Add ( specialSideOutline . UUID ) ;
230- }
231- }
232- else
233- {
234- BBModel . Outliner subLine = ReadOutliner ( model , ( JObject ) child , names ) ;
235- outline . Paired . Add ( subLine . UUID ) ;
236- outline . Paired . AddRange ( subLine . Paired ) ;
237- }
258+ AddOutlineChild ( model , outline , child , names ) ;
238259 }
239260 Debug ( $ "Read outliner { outline . Name } ") ;
240261 model . Outlines . Add ( outline ) ;
@@ -250,7 +271,7 @@ public static DoubleVector ParseDVecFromObj(JToken jVal)
250271 public static DoubleVector ParseDVecFromArr ( JToken jVal )
251272 {
252273 JArray jArr = ( JArray ) jVal ;
253- return new DoubleVector ( ( int ) jArr [ 0 ] , ( int ) jArr [ 1 ] , ( int ) jArr [ 2 ] ) ;
274+ return new DoubleVector ( ( double ) jArr [ 0 ] , ( double ) jArr [ 1 ] , ( double ) jArr [ 2 ] ) ;
254275 }
255276
256277 public static BBModel . Element . Face ParseFaceFromJson ( JToken jVal )
0 commit comments