From 36f8cbe04b01f3687fa853e71a170a4ab0c146ed Mon Sep 17 00:00:00 2001 From: Justin Georgi Date: Wed, 23 Oct 2024 09:20:32 -0700 Subject: [PATCH] Add hotspot functionality Signed-off-by: Justin Georgi --- includes/GlModelViewer.php | 30 ++++++++++++++++--- modules/glmv.css | 61 ++++++++++++++++++++++++++++++++++++-- modules/glmv.js | 46 ++++++++++++++++++++++++++-- 3 files changed, 128 insertions(+), 9 deletions(-) diff --git a/includes/GlModelViewer.php b/includes/GlModelViewer.php index 8c751d2..ccdf628 100644 --- a/includes/GlModelViewer.php +++ b/includes/GlModelViewer.php @@ -34,10 +34,32 @@ class GlModelViewer extends ImageHandler { } else { $viewClass = 'default'; } - $modelView = $metadata['viewerConfig'][$viewClass]; - $modelView = array_merge(['src' => $file->getFullUrl()], $modelView); - $modelView['style'] = 'width: 800px; height: 600px;'; - $result = Html::element('model-viewer', $modelView); + if (isset($metadata['annotations'])) { + $hotspots = []; + foreach($metadata['annotations'] as $idx => $an) { + $elAnnot = Html::rawElement('div',['class' => 'HotspotAnnotation HiddenAnnotation'],$an['label']); + $hsDefault = array( + 'class' => 'Hotspot', + 'slot' => 'hotspot-'.($idx +1), + 'onmousedown' => 'event.stopPropagation()', + 'ontouchstart' => 'event.stopPropagation()', + 'onclick' => 'onAnnotation(event)' + ); + $attrHotspot = array_merge($hsDefault, $an); + $elHotspot = Html::rawElement('button',$attrHotspot,$elAnnot.($idx +1)); + array_push($hotspots, $elHotspot); + } + } + $attrModelView = $metadata['viewerConfig'][$viewClass]; + $attrModelView = array_merge(['src' => $file->getFullUrl(), 'class' => 'mv-model'], $attrModelView); + $attrModelView['style'] = 'width: 100%; height: 100%; min-height: 400px;'; + $elModel = Html::rawElement('model-viewer', $attrModelView, implode($hotspots)); + $attrContainer = array( + 'style' => "width: 800px; height: 600px;", + 'onmousedown' => 'clearAnnotations()', + 'ontouchstart' => 'clearAnnotations()' + ); + $result = Html::rawElement('div', $attrContainer, $elModel); echo '