Skip to content

Commit e9f0272

Browse files
authored
Merge pull request #4784 from manyfold3d/assimp-ffi
Use assimp 3d library directly rather than calling the binary
2 parents 900393b + fa2b58a commit e9f0272

File tree

6 files changed

+37
-21
lines changed

6 files changed

+37
-21
lines changed

.github/actions/setup/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ runs:
77
- name: Install system requirements
88
uses: awalsh128/cache-apt-pkgs-action@latest
99
with:
10-
packages: assimp-utils
10+
packages: libassimp-dev
1111
- name: Set up Ruby and install gems
1212
uses: ruby/setup-ruby@v1
1313
with:

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,3 +215,5 @@ gem "image_processing"
215215
gem "csv", "~> 3.3"
216216

217217
gem "arel_extensions", "~> 2.3"
218+
219+
gem "assimp-ffi", git: "https://github.com/Kerilk/assimp-ruby.git"

Gemfile.lock

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
GIT
2+
remote: https://github.com/Kerilk/assimp-ruby.git
3+
revision: a36639b60556dcd9982e6305089fe32e6d716d6a
4+
specs:
5+
assimp-ffi (0.1.8)
6+
ffi (~> 1.9, >= 1.9.19)
7+
18
GIT
29
remote: https://github.com/el-cms/capybara-screenshot.git
310
revision: 386c0541a428b8d025c936e3b6ebd6d2d2240523
@@ -930,6 +937,7 @@ DEPENDENCIES
930937
acts_as_favoritor (~> 6.0)
931938
altcha-rails (~> 0.0.6)
932939
arel_extensions (~> 2.3)
940+
assimp-ffi!
933941
aws-sdk-s3 (< 1.200)
934942
better_content_security_policy (~> 0.1)
935943
bootsnap (~> 1.18)
@@ -1065,6 +1073,7 @@ CHECKSUMS
10651073
aes_key_wrap (1.1.0) sha256=b935f4756b37375895db45669e79dfcdc0f7901e12d4e08974d5540c8e0776a5
10661074
altcha-rails (0.0.6) sha256=0da0f081439abae730a797ab2f6b86a46ad2b533017db2a872488785cc35fae4
10671075
arel_extensions (2.3.3) sha256=65bd6f4286d11447be528f4bb153d84a951870999149c76b4cbf3929226f4c1d
1076+
assimp-ffi (0.1.8)
10681077
ast (2.4.3) sha256=954615157c1d6a382bc27d690d973195e79db7f55e9765ac7c481c60bdb4d383
10691078
attr_required (1.0.2) sha256=f0ebfc56b35e874f4d0ae799066dbc1f81efefe2364ca3803dc9ea6a4de6cb99
10701079
aws-eventstream (1.4.0) sha256=116bf85c436200d1060811e6f5d2d40c88f65448f2125bc77ffce5121e6e183b

app/uploaders/application_uploader.rb

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -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:]\-\.]+)\)\nMaximum 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|

docker/build.dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ RUN apk add --no-cache \
1919
imagemagick \
2020
imagemagick-jpeg \
2121
imagemagick-webp \
22-
imagemagick-heic
22+
imagemagick-heic \
23+
assimp-dev
2324

2425
COPY package.json .
2526
COPY yarn.lock .

docker/runtime.dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ RUN apk add --no-cache \
1010
imagemagick-jpeg \
1111
imagemagick-webp \
1212
imagemagick-heic \
13-
assimp
13+
assimp-dev
1414

1515
COPY . .
1616
COPY --from=build /usr/src/app/vendor/bundle vendor/bundle

0 commit comments

Comments
 (0)