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 aModelViewerusing 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 newModelViewerinstance with the specified stream resource.ModelViewer(String url) Constructs aModelViewerinstance with the specified media source URL. -
Method Summary
Methods inherited from class com.storedobject.vaadin.AbstractResourcedComponent
clear, init, onAttach, onDetach, setSource, setSource, setURIMethods 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, setVisibleMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListenerMethods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListenerMethods inherited from interface com.vaadin.flow.component.HasElement
getElementMethods 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, setWidthFullMethods 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 aModelViewerusing 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 aModelViewerinstance 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 newModelViewerinstance 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- TheAbstractStreamResourcefrom 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 theModelViewercomponent using the specifiedMediaFile. If theMediaFileis valid and represents an image, its path will be processed and used as the source for the component.- Parameters:
mediaFile- TheMediaFileto be used as the source for theModelViewer. If theMediaFileis null or not an image, the source will not be set.
-
getURIAttributeName
Description copied from class:AbstractResourcedComponentGet the name of the URI attribute. The default value returned is "src".- Specified by:
getURIAttributeNamein classAbstractResourcedComponent- Returns:
- URI attribute name.
-