20
20
21
21
module BimTools
22
22
module IfcJson
23
- require File . join ( PLUGIN_PATH , ' obj.rb' )
24
- require File . join ( PLUGIN_PATH , ' IfcGloballyUniqueId.rb' )
23
+ require File . join ( PLUGIN_PATH , " obj.rb" )
24
+ require File . join ( PLUGIN_PATH , " IfcGloballyUniqueId.rb" )
25
25
class IfcJsonExporter
26
26
attr_accessor :root_objects
27
27
def initialize ( entities )
28
- @root_objects = Array . new
28
+ @geometry = Array . new
29
+ @root_objects = {
30
+ "header" => {
31
+ "file_description" => {
32
+ "description" => "ViewDefinition [CoordinationView]" ,
33
+ "implementation_level" => "2;1"
34
+ } ,
35
+ "file_name" => {
36
+ "name" => "7m900_tue_hello_wall_with_door.json" ,
37
+ "time_stamp" => "2020-02-22T11:10:04" ,
38
+ "author" => "" ,
39
+ "organization" => "" ,
40
+ "preprocessor_version" => "IFC-manager for SketchUp (ifcjson-3.1.0)" ,
41
+ "originating_system" => "SketchUp Pro 2020 (20.0.373)" ,
42
+ "authorization" => ""
43
+ } ,
44
+ "file_schema" => "IFC2X3"
45
+ } ,
46
+ "data" => [ ]
47
+ }
29
48
export_path = get_export_path ( )
30
49
31
50
# only start export if path is valid
32
51
unless export_path . nil?
33
- @root_objects . concat ( collect_objects ( entities , Geom ::Transformation . new ( ) ) [ 0 ] )
52
+ @root_objects [ "data" ] . concat ( collect_objects ( entities , Geom ::Transformation . new ( ) ) [ 0 ] )
34
53
end
35
54
55
+ @root_objects [ "data" ] . concat ( @geometry )
56
+
36
57
to_file ( export_path )
37
58
end # def initialize
38
59
@@ -53,6 +74,11 @@ def collect_objects(entities, parent_transformation, parent_guid=nil)
53
74
end
54
75
object_hash [ "GlobalId" ] = guid . to_json ( )
55
76
77
+ # add volume if object is manifold
78
+ if entity . volume > 0
79
+ object_hash [ "Volume" ] = entity . volume
80
+ end
81
+
56
82
isDecomposedBy , child_faces = collect_objects ( entity . definition . entities , transformation , guid . to_s )
57
83
58
84
unless isDecomposedBy . empty?
@@ -62,7 +88,33 @@ def collect_objects(entities, parent_transformation, parent_guid=nil)
62
88
# only add representation if there are any faces
63
89
if child_faces . length > 0
64
90
obj = OBJ . new ( child_faces , parent_transformation )
65
- object_hash [ "Representation" ] = obj . to_s
91
+ representation_guid = BimTools ::IfcManager ::IfcGloballyUniqueId . new ( ) . to_json
92
+ object_hash [ "Representations" ] = [
93
+ {
94
+ "Class" : "ShapeRepresentation" ,
95
+ "ref" : representation_guid
96
+ }
97
+ ]
98
+ # {
99
+ # "Class": "ProductDefinitionShape",
100
+ # "Representations": [
101
+ # {
102
+ # "Class": "ShapeRepresentation",
103
+ # "RepresentationIdentifier": "Body",
104
+ # "RepresentationType": "OBJ",
105
+ # "Items": [obj.to_s]
106
+ # }
107
+ # ]
108
+ # }
109
+
110
+ # add geometry as seperate objects at the end of the file
111
+ @geometry << {
112
+ "Class" => "ShapeRepresentation" ,
113
+ "GlobalId" => representation_guid ,
114
+ "RepresentationIdentifier" => "Body" ,
115
+ "RepresentationType" => "OBJ" ,
116
+ "Items" => [ obj . to_s ]
117
+ }
66
118
end
67
119
child_objects << object_hash
68
120
elsif entity . is_a? ( Sketchup ::Face )
0 commit comments