generateModelViewerHtml method

void generateModelViewerHtml()

To generate the HTML code for using the model viewer.

Implementation

void generateModelViewerHtml() async {
  final htmlTemplate = await rootBundle
      .loadString('packages/sni_model_viewer/assets/template.html');
  // allow to use elements
  final NodeValidator validator = NodeValidatorBuilder.common()
    ..allowElement(
      'meta',
      attributes: ['name', 'content'],
      uriPolicy: _AllowUriPolicy(),
    )
    ..allowElement('style')
    ..allowElement(
      'script',
      attributes: ['src', 'type', 'defer'],
      uriPolicy: _AllowUriPolicy(),
    )
    ..allowCustomElement(
      'model-viewer',
      attributes: [
        'style',

        // Loading Attributes
        'src',
        'alt',
        'poster',
        'seamless-poster',
        'loading',
        'reveal',
        'with-credentials',

        // Augmented Reality Attributes
        'ar',
        'ar-modes',
        'ar-scale',
        'ar-placement',
        'ios-src',
        'xr-environment',

        // Staing & Cameras Attributes
        'camera-controls',
        'enable-pan',
        'touch-action',
        'disable-zoom',
        'orbit-sensitivity',
        'auto-rotate',
        'auto-rotate-delay',
        'rotation-per-second',
        'interaction-policy',
        'interaction-prompt',
        'interaction-prompt-style',
        'interaction-prompt-threshold',
        'camera-orbit',
        'camera-target',
        'field-of-view',
        'max-camera-orbit',
        'min-camera-orbit',
        'max-field-of-view',
        'min-field-of-view',
        'bounds',
        'interpolation-decay',

        // Lighting & Env Attributes
        'skybox-image',
        'environment-image',
        'exposure',
        'shadow-intensity',
        'shadow-softness ',

        // Animation Attributes
        'animation-name',
        'animation-crossfade-duration',
        'autoplay',

        // Scene Graph Attributes
        'variant-name',
        'orientation',
        'scale',
      ],
      uriPolicy: _AllowUriPolicy(),
    );

  ui.platformViewRegistry.registerViewFactory(
    'model-viewer-html-$variableName',
    (int viewId) => HtmlHtmlElement()
      ..style.border = 'none'
      ..style.height = '100%'
      ..style.width = '100%'
      ..setInnerHtml(
        _buildHTML(htmlTemplate, viewId.toString()),
        validator: validator,
      ),
  );

  setState(() {
    _isLoading = false;
  });
}