Skip to content
Draft
2 changes: 1 addition & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:
project: bsbhgkfhgc
context: .
file: ./docker/${{ matrix.variant }}.dockerfile
platforms: linux/amd64,linux/arm64
platforms: linux/arm64
push: true
tags: ${{ steps.docker_meta.outputs.tags }}
labels: ${{ steps.docker_meta.outputs.labels }}
Expand Down
6 changes: 3 additions & 3 deletions app/jobs/upgrade/backfill_image_derivatives.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ class Upgrade::BackfillImageDerivatives < ApplicationJob
def scope
ModelFile.unscoped.where(
DatabaseDetector.is_postgres? ?
"json_extract_path(attachment_data, 'derivatives', 'preview') IS NULL" :
"json_extract(attachment_data, '$.derivatives.preview') IS NULL"
"json_extract_path(attachment_data, 'derivatives', 'preview') IS NULL AND json_extract_path(attachment_data, 'derivatives', 'render') IS NULL" :
"json_extract(attachment_data, '$.derivatives.preview') IS NULL AND json_extract(attachment_data, '$.derivatives.render') IS NULL"
)
end

Expand All @@ -17,7 +17,7 @@ def build_enumerator(cursor:)
end

def each_iteration(modelfile)
return unless modelfile.is_image?
return unless modelfile.is_image? || SupportedMimeTypes.can_render?(modelfile.mime_type)
return if modelfile.extension.downcase == "svg"
Rails.logger.info("Creating image derivatives for: #{modelfile.path_within_library}")
modelfile.attachment_derivatives!
Expand Down
12 changes: 12 additions & 0 deletions app/lib/supported_mime_types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@ def can_export?(type)
end
memoize :can_export?

def renderable
readers = `f3d --list-readers`.lines
types = readers.filter_map { |it| it.match(/\w[a-z]*\/[0-9a-z.+-]*\w/)&.to_s }
types.filter_map { |it| Mime::Type.lookup(it).to_sym }.uniq
end
memoize :renderable

def can_render?(type)
renderable.include? type&.to_sym
end
memoize :can_render?

def indexable_types
image_types + model_types + video_types + document_types + archive_types
end
Expand Down
30 changes: 30 additions & 0 deletions app/uploaders/application_uploader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,28 @@ class ApplicationUploader < Shrine
downloads: Shrine::Storage::FileSystem.new("tmp/downloads")
}

F3D_OPTS = {
"ambient-occlusion" => "1",
"anti-aliasing" => "true",
"axis" => "0",
"background-color" => "0,0,0",
"filename" => "0",
"grid" => "1",
"grid-color" => "0,255,255",
"grid-subdivisions" => 0,
"grid-unit" => "10",
"no-config" => "1",
"output" => "-",
"resolution" => "512,512",
"tone-mapping" => "1",
"translucency-support" => "1"
}.map { |k, v| "--#{k}=#{v}" }.join(" ").freeze

CAMERA_OPTS = {
"+z" => "-1,1,-0.5",
"+y" => "-1,-0.5,-1"
}

storage(/library_(\d+)/) do |m|
Library.find(m[1]).storage # rubocop:disable Pundit/UsePolicyScope
rescue ActiveRecord::RecordNotFound
Expand Down Expand Up @@ -100,6 +122,14 @@ def generate_location(io, record: nil, derivative: nil, metadata: {}, **)
carousel: magick.resize_to_limit!(1024, 768)
}
end
elsif SupportedMimeTypes.can_render?(context[:record].mime_type)
Shrine.with_file(original) do |it|
up = context[:record]&.up_direction
render = StringIO.new(`f3d #{it.path} #{F3D_OPTS} --up=#{up} --camera-direction=#{CAMERA_OPTS[up]}`)
{
render: (render.length > 0) ? render : nil
}.compact
end
else
{}
end
Expand Down
2 changes: 1 addition & 1 deletion config/locales/settings/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ en:
description: Manyfold can create alternative versions of some files to increase site performance. Note that this will use more disk space.
heading: File Derivatives
images:
help: Generates lower-resolution versions of images that will load quicker on list and model pages.
help: Generates static images of models and low-resolution image previews that will load quicker on list and model pages.
label: Image thumbnails
description: Manyfold will generate ZIP files of models on request, but for busy sites you may want these available more quickly. Here you can tell Manyfold to create ZIP files immediately, and also set how long they are kept in the download cache. Beware; this may use a lot of disk space!
expiry:
Expand Down
11 changes: 10 additions & 1 deletion docker/base.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
RUN bundle config set --local deployment 'true'
RUN bundle config set --local without 'development test'

# Scripts for cross-platform architecture detection
COPY --from=tonistiigi/xx / /

Check warning on line 14 in docker/base.dockerfile

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

docker/base.dockerfile#L14

`COPY --from` should reference a previously defined `FROM` alias

RUN apk add --no-cache \
file \
s6-overlay \
Expand All @@ -19,4 +22,10 @@
imagemagick-jpeg \
imagemagick-webp \
imagemagick-heic \
assimp-dev
assimp-dev \
mesa-egl

RUN wget "https://github.com/manyfold3d/f3d-alpine/releases/download/v3.4.1-r2/f3d-3.4.1-r2.`xx-info alpine-arch`.apk" -O /tmp/f3d.apk
RUN wget "https://github.com/manyfold3d/f3d-alpine/releases/download/v3.4.1-r1/vtk-9.5.2-r0.`xx-info alpine-arch`.apk" -O /tmp/vtk.apk
RUN apk add --no-cache --allow-untrusted /tmp/f3d.apk /tmp/vtk.apk
RUN rm /tmp/f3d.apk /tmp/vtk.apk
Loading