Package com.storedobject.ui
Class ModelViewer
java.lang.Object
com.vaadin.flow.component.Component
com.storedobject.vaadin.AbstractResourcedComponent
com.storedobject.ui.ModelViewer
- All Implemented Interfaces:
HasSize
,ResourcedComponent
,com.vaadin.flow.component.AttachNotifier
,com.vaadin.flow.component.DetachNotifier
,com.vaadin.flow.component.HasElement
,com.vaadin.flow.component.HasSize
,com.vaadin.flow.component.HasStyle
,Serializable
@NpmPackage(value="@google/model-viewer",
version="v4.1.0")
@JsModule("@google/model-viewer/dist/model-viewer.min.js")
@Tag("model-viewer")
public class ModelViewer
extends AbstractResourcedComponent
A component for rendering 3D models using the `@google/model-viewer` library. It supports various
media sources and enables camera controls by default for model interaction.
This class extends
AbstractResourcedComponent
and allows sources to be specified via URLs,
media files, or streamable data resources.
Features:
- Renders 3D models using a browser-supported viewer.
- Provides camera controls by default for interactive model viewing.
- Supports multiple constructors for various source types including media files and stream data.- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor for the ModelViewer component.ModelViewer
(HasStreamData streamData) Constructs aModelViewer
using a givenHasStreamData
.ModelViewer
(MediaFile mediaFile) Constructs a ModelViewer component using a media file as the source.ModelViewer
(com.vaadin.flow.server.AbstractStreamResource resource) Creates a newModelViewer
instance with the specified stream resource.ModelViewer
(String url) Constructs aModelViewer
instance with the specified media source URL. -
Method Summary
Methods inherited from class com.storedobject.vaadin.AbstractResourcedComponent
clear, init, onAttach, onDetach, setSource, setSource, setURI
Methods inherited from class com.vaadin.flow.component.Component
addListener, findAncestor, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onEnabledStateChanged, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setVisible
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListener
Methods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListener
Methods inherited from interface com.vaadin.flow.component.HasElement
getElement
Methods inherited from interface com.vaadin.flow.component.HasSize
getHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setHeight, setHeightFull, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidthFull
Methods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName
-
Constructor Details
-
ModelViewer
public ModelViewer()Default constructor for the ModelViewer component.This constructor initializes a basic instance of the ModelViewer without setting any specific source or attributes. It is primarily intended for use cases where the source or content is configured after instantiation.
-
ModelViewer
Constructs aModelViewer
using a givenHasStreamData
. It initializes the model viewer with the stream data source and enables camera controls by default.- Parameters:
streamData
- The streamable data source that provides the content to be rendered by the ModelViewer. Ifnull
, the initialization will rely on default or fallback behavior.
-
ModelViewer
Constructs aModelViewer
instance with the specified media source URL. This constructor initializes the viewer to render 3D models from the given URL and enables camera controls by default for interactive model viewing.- Parameters:
url
- The URL pointing to the media source (e.g., a 3D model file) to be rendered by the viewer.
-
ModelViewer
Constructs a ModelViewer component using a media file as the source. The media file is processed to generate a URL compatible with the viewer. If the media file is null or not an image, the source will not be set.- Parameters:
mediaFile
- The media file to be used as the source for the model viewer.
-
ModelViewer
public ModelViewer(com.vaadin.flow.server.AbstractStreamResource resource) Creates a newModelViewer
instance with the specified stream resource. This constructor allows initializing the 3D model viewer with a givenAbstractStreamResource
, enabling interaction with the model through camera controls by default.- Parameters:
resource
- TheAbstractStreamResource
from which the 3D model will be loaded. This resource can represent a streamable data source, such as a file, network stream, or in-memory data stream.
-
-
Method Details
-
setSource
Sets the source of theModelViewer
component using the specifiedMediaFile
. If theMediaFile
is valid and represents an image, its path will be processed and used as the source for the component.- Parameters:
mediaFile
- TheMediaFile
to be used as the source for theModelViewer
. If theMediaFile
is null or not an image, the source will not be set.
-
getURIAttributeName
Description copied from class:AbstractResourcedComponent
Get the name of the URI attribute. The default value returned is "src".- Specified by:
getURIAttributeName
in classAbstractResourcedComponent
- Returns:
- URI attribute name.
-