@@ -61,29 +61,33 @@ def generate_location(io, record: nil, derivative: nil, metadata: {}, **)
6161 rescue NoMethodError
6262 end
6363
64- BB_REGEXP = /Minimum point\s +\( (?<min_x>[[:digit:]\- \. ]+)\s +(?<min_y>[[:digit:]\- \. ]+)\s (?<min_z>[[:digit:]\- \. ]+)\) \n Maximum point\s +\( (?<max_x>[[:digit:]\- \. ]+)\s +(?<max_y>[[:digit:]\- \. ]+)\s (?<max_z>[[:digit:]\- \. ]+)\) /
65-
6664 add_metadata :object do |io |
6765 Shrine . with_file ( io ) do |it |
68- output = Open3 . capture2 "assimp" , "info" , it . path
69- if ( match = output . first . match ( BB_REGEXP ) )
70- {
71- "bounding_box" => {
72- "minimum" => {
73- "x" => match [ :min_x ] . to_f ,
74- "y" => match [ :min_y ] . to_f ,
75- "z" => match [ :min_z ] . to_f
76- } ,
77- "maximum" => {
78- "x" => match [ :max_x ] . to_f ,
79- "y" => match [ :max_y ] . to_f ,
80- "z" => match [ :max_z ] . to_f
81- }
66+ scene = Assimp . import_file ( it . path )
67+ scene . apply_post_processing (
68+ 0x80000000 # GenBoundingBox step, currently missing from assimp-ffi
69+ )
70+ bboxes = scene . meshes . map ( &:aabb )
71+ {
72+ "bounding_box" => {
73+ "minimum" => {
74+ "x" => bboxes . map { |it | it . min . x } . min ,
75+ "y" => bboxes . map { |it | it . min . y } . min ,
76+ "z" => bboxes . map { |it | it . min . z } . min
77+ } ,
78+ "maximum" => {
79+ "x" => bboxes . map { |it | it . max . x } . max ,
80+ "y" => bboxes . map { |it | it . max . y } . max ,
81+ "z" => bboxes . map { |it | it . max . z } . max
8282 }
8383 }
84- end
84+ }
85+ rescue => ex
86+ # Assimp doesn't raise a specific error for failed load,
87+ # just throws a string, so we have to catch all and absorb
88+ Rails . logger . debug { "Load error: '#{ ex . message } '" }
89+ nil
8590 end
86- rescue NoMethodError
8791 end
8892
8993 Attacher . derivatives do |original |
0 commit comments