Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ runs:
- name: Install system requirements
uses: awalsh128/cache-apt-pkgs-action@latest
with:
packages: assimp-utils
packages: libassimp-dev
- name: Set up Ruby and install gems
uses: ruby/setup-ruby@v1
with:
Expand Down
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,5 @@ gem "image_processing"
gem "csv", "~> 3.3"

gem "arel_extensions", "~> 2.3"

gem "assimp-ffi", git: "https://github.com/Kerilk/assimp-ruby.git"
9 changes: 9 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
GIT
remote: https://github.com/Kerilk/assimp-ruby.git
revision: a36639b60556dcd9982e6305089fe32e6d716d6a
specs:
assimp-ffi (0.1.8)
ffi (~> 1.9, >= 1.9.19)

GIT
remote: https://github.com/el-cms/capybara-screenshot.git
revision: 386c0541a428b8d025c936e3b6ebd6d2d2240523
Expand Down Expand Up @@ -930,6 +937,7 @@ DEPENDENCIES
acts_as_favoritor (~> 6.0)
altcha-rails (~> 0.0.6)
arel_extensions (~> 2.3)
assimp-ffi!
aws-sdk-s3 (< 1.200)
better_content_security_policy (~> 0.1)
bootsnap (~> 1.18)
Expand Down Expand Up @@ -1065,6 +1073,7 @@ CHECKSUMS
aes_key_wrap (1.1.0) sha256=b935f4756b37375895db45669e79dfcdc0f7901e12d4e08974d5540c8e0776a5
altcha-rails (0.0.6) sha256=0da0f081439abae730a797ab2f6b86a46ad2b533017db2a872488785cc35fae4
arel_extensions (2.3.3) sha256=65bd6f4286d11447be528f4bb153d84a951870999149c76b4cbf3929226f4c1d
assimp-ffi (0.1.8)
ast (2.4.3) sha256=954615157c1d6a382bc27d690d973195e79db7f55e9765ac7c481c60bdb4d383
attr_required (1.0.2) sha256=f0ebfc56b35e874f4d0ae799066dbc1f81efefe2364ca3803dc9ea6a4de6cb99
aws-eventstream (1.4.0) sha256=116bf85c436200d1060811e6f5d2d40c88f65448f2125bc77ffce5121e6e183b
Expand Down
40 changes: 22 additions & 18 deletions app/uploaders/application_uploader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,29 +61,33 @@ def generate_location(io, record: nil, derivative: nil, metadata: {}, **)
rescue NoMethodError
end

BB_REGEXP = /Minimum point\s+\((?<min_x>[[:digit:]\-\.]+)\s+(?<min_y>[[:digit:]\-\.]+)\s(?<min_z>[[:digit:]\-\.]+)\)\nMaximum point\s+\((?<max_x>[[:digit:]\-\.]+)\s+(?<max_y>[[:digit:]\-\.]+)\s(?<max_z>[[:digit:]\-\.]+)\)/

add_metadata :object do |io|
Shrine.with_file(io) do |it|
output = Open3.capture2 "assimp", "info", it.path
if (match = output.first.match(BB_REGEXP))
{
"bounding_box" => {
"minimum" => {
"x" => match[:min_x].to_f,
"y" => match[:min_y].to_f,
"z" => match[:min_z].to_f
},
"maximum" => {
"x" => match[:max_x].to_f,
"y" => match[:max_y].to_f,
"z" => match[:max_z].to_f
}
scene = Assimp.import_file(it.path)
scene.apply_post_processing(
0x80000000 # GenBoundingBox step, currently missing from assimp-ffi
)
bboxes = scene.meshes.map(&:aabb)
{
"bounding_box" => {
"minimum" => {
"x" => bboxes.map { |it| it.min.x }.min,
"y" => bboxes.map { |it| it.min.y }.min,
"z" => bboxes.map { |it| it.min.z }.min
},
"maximum" => {
"x" => bboxes.map { |it| it.max.x }.max,
"y" => bboxes.map { |it| it.max.y }.max,
"z" => bboxes.map { |it| it.max.z }.max
}
}
end
}
rescue => ex
# Assimp doesn't raise a specific error for failed load,
# just throws a string, so we have to catch all and absorb
Rails.logger.debug { "Load error: '#{ex.message}'" }
nil
end
rescue NoMethodError
end

Attacher.derivatives do |original|
Expand Down
3 changes: 2 additions & 1 deletion docker/build.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ RUN apk add --no-cache \
imagemagick \
imagemagick-jpeg \
imagemagick-webp \
imagemagick-heic
imagemagick-heic \
assimp-dev

COPY package.json .
COPY yarn.lock .
Expand Down
2 changes: 1 addition & 1 deletion docker/runtime.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ RUN apk add --no-cache \
imagemagick-jpeg \
imagemagick-webp \
imagemagick-heic \
assimp
assimp-dev

COPY . .
COPY --from=build /usr/src/app/vendor/bundle vendor/bundle
Expand Down
Loading