Mercurial > hg > orthanc-stl
changeset 38:970994058acd
building O3DV
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 05 Apr 2024 08:19:54 +0200 (13 months ago) |
parents | 2cc9950018ab |
children | b6910092bcca |
files | Resources/CreateJavaScriptLibraries.sh Resources/CreateJavaScriptLibraries/build-o3dv.sh Sources/Plugin.cpp WebApplications/o3dv.js |
diffstat | 4 files changed, 100 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/Resources/CreateJavaScriptLibraries.sh Fri Apr 05 07:52:43 2024 +0200 +++ b/Resources/CreateJavaScriptLibraries.sh Fri Apr 05 08:19:54 2024 +0200 @@ -52,6 +52,30 @@ ## +## Building O3DV (Online 3D Viewer) +## https://github.com/kovacsv/Online3DViewer +## + +O3DV=Online3DViewer-0.12.0 + +echo "Creating the distribution of O3DV from $O3DV" + +if [ ! -f "${ROOT_DIR}/JavaScriptLibraries/${O3DV}.tar.gz" ]; then + mkdir -p "${ROOT_DIR}/JavaScriptLibraries" + ( cd ${ROOT_DIR}/JavaScriptLibraries && \ + wget https://orthanc.uclouvain.be/downloads/third-party-downloads/STL/${O3DV}.tar.gz ) +fi + +docker run -t ${DOCKER_FLAGS} --rm \ + --user $(id -u):$(id -g) \ + -v ${ROOT_DIR}/Resources/CreateJavaScriptLibraries/build-o3dv.sh:/source/build-o3dv.sh:ro \ + -v ${ROOT_DIR}/JavaScriptLibraries/${O3DV}.tar.gz:/source/${O3DV}.tar.gz:ro \ + -v ${ROOT_DIR}/JavaScriptLibraries/dist/:/target:rw \ + ${IMAGE} \ + bash /source/build-o3dv.sh ${O3DV} + + +## ## Building Three.js ##
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Resources/CreateJavaScriptLibraries/build-o3dv.sh Fri Apr 05 08:19:54 2024 +0200 @@ -0,0 +1,36 @@ +#!/bin/bash + +# SPDX-FileCopyrightText: 2023-2024 Sebastien Jodogne, UCLouvain, Belgium +# SPDX-License-Identifier: GPL-3.0-or-later + +# STL plugin for Orthanc +# Copyright (C) 2023-2024 Sebastien Jodogne, UCLouvain, Belgium +# +# This program is free software: you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +set -ex + +if [ "$1" = "" ]; then + echo "Please provide the source package of O3DV" + exit -1 +fi + +cd /tmp/ +tar xvf /source/$1.tar.gz + +cd /tmp/$1 +npm install --cache /tmp/npm-cache +npm run create_dist --cache /tmp/npm-cache + +cp -r /tmp/$1/build/engine/o3dv.min.js /target/
--- a/Sources/Plugin.cpp Fri Apr 05 07:52:43 2024 +0200 +++ b/Sources/Plugin.cpp Fri Apr 05 08:19:54 2024 +0200 @@ -58,9 +58,9 @@ /** - * As the Three.js static assets are gzipped by the - * "EmbedStaticAssets.py" script, we use a cache to maintain the - * uncompressed assets in order to avoid multiple gzip decodings. + * As the static assets are gzipped by the "EmbedStaticAssets.py" + * script, we use a cache to maintain the uncompressed assets in order + * to avoid multiple gzip decodings. **/ class ResourcesCache : public boost::noncopyable { @@ -133,22 +133,45 @@ std::string file = request->groups[0]; - if (file == "three.html") - { - std::string s; - Orthanc::EmbeddedResources::GetFileResource(s, Orthanc::EmbeddedResources::THREE_HTML); - OrthancPluginAnswerBuffer(OrthancPlugins::GetGlobalContext(), output, s.c_str(), s.size(), Orthanc::EnumerationToString(Orthanc::MimeType_Html)); - } - else if (file == "three.js") - { - std::string s; - Orthanc::EmbeddedResources::GetFileResource(s, Orthanc::EmbeddedResources::THREE_JS); - OrthancPluginAnswerBuffer(OrthancPlugins::GetGlobalContext(), output, s.c_str(), s.size(), Orthanc::EnumerationToString(Orthanc::MimeType_JavaScript)); - } - else if (boost::starts_with(file, "libs/")) + if (boost::starts_with(file, "libs/")) { cache_.Answer(output, file.substr(5)); } + else + { + Orthanc::EmbeddedResources::FileResourceId resourceId; + Orthanc::MimeType mimeType; + + if (file == "three.html") + { + resourceId = Orthanc::EmbeddedResources::THREE_HTML; + mimeType = Orthanc::MimeType_Html; + } + else if (file == "three.js") + { + resourceId = Orthanc::EmbeddedResources::THREE_JS; + mimeType = Orthanc::MimeType_JavaScript; + } + else if (file == "o3dv.html") + { + resourceId = Orthanc::EmbeddedResources::O3DV_HTML; + mimeType = Orthanc::MimeType_Html; + } + else if (file == "o3dv.js") + { + resourceId = Orthanc::EmbeddedResources::O3DV_JS; + mimeType = Orthanc::MimeType_JavaScript; + } + else + { + OrthancPluginSendHttpStatusCode(OrthancPlugins::GetGlobalContext(), output, 404); + return; + } + + std::string s; + Orthanc::EmbeddedResources::GetFileResource(s, resourceId); + OrthancPluginAnswerBuffer(OrthancPlugins::GetGlobalContext(), output, s.c_str(), s.size(), Orthanc::EnumerationToString(mimeType)); + } }
--- a/WebApplications/o3dv.js Fri Apr 05 07:52:43 2024 +0200 +++ b/WebApplications/o3dv.js Fri Apr 05 08:19:54 2024 +0200 @@ -56,6 +56,6 @@ }); viewer.LoadModelFromInputFiles ([ - new OV.InputFile('model.stl', OV.FileSource.Url, '../../instances/' + instance + '/stl'), + new OV.InputFile('model.stl', OV.FileSource.Url, '../../instances/' + instanceId + '/stl'), ]); });