google/model-viewer

repository·master·Indexed 27 days ago

https://github.com/google/model-viewer

A collection of web components and tools for displaying and editing 3D models on the web. It includes the core <model-viewer> web component, @google/model-viewer-effects for post-processing (such as <bloom-effect>), rendering fidelity tools, and the modelviewer.dev documentation site.

Tokens
9.9K
Snippets
30
Records
55
Agent score
93%

What's inside model-viewer

  1. Run Render Fidelity Tests

    master

    Use npm run test to run a render fidelity check comparing <model-viewer> to other renderers.

    Note: When passing arguments to the underlying script via npm run, you must use -- to separate the npm command from the script arguments.

    To view test results after running the command, start a local web server (e.g., npx http-server) in the package directory and open test/results-viewer.html in a browser.

    npm run test -- --scenario=texture --quiet
  2. Set up the <model-viewer> development environment

    master

    To develop across all projects in the repository, ensure you have git, Node.js, and npm installed. Clone the repository with --depth=1 to avoid downloading large historical assets (approx. 3GB).

    git clone --depth=1 git@github.com:google/model-viewer.git
    cd model-viewer
    npm install
  3. Set up <model-viewer> on Windows 10/11 using WSL2

    master

    Due to dependency issues on Windows 10, it is recommended to use a WSL2 environment.

    1. Install WSL2 and Node.js/npm via NVM within WSL.
    2. Important: Clone the repository from inside the WSL environment (using HTTPS to avoid SSH key permission issues) rather than from Windows to prevent line ending and symlink issues.

    To clone via HTTPS in WSL:

    git clone --depth=1 https://github.com/google/model-viewer.git
    cd model-viewer
    npm install
  4. Install @google/model-viewer via NPM

    master

    To use <model-viewer> in a modern JavaScript project, install the package and its required peer dependency, three.

    Note: <model-viewer> requires a specific version of three.js to maintain rendering quality. If you need to use a different version of three.js than the one specified by <model-viewer>, you may need to use the --legacy-peer-deps flag during installation, but be aware that this is unsupported and may lead to issues.

    # install peer dependency ThreeJS
    npm install three 
    # install package
    npm install @google/model-viewer
    import '@google/model-viewer';
  5. Use post-processing effects in <model-viewer>

    master

    To apply effects to your 3D models, place an <effect-composer> element inside your <model-viewer> component. You can then nest specific effect components (like <bloom-effect>) inside the composer.

    Note: Effects are not supported in <model-viewer> XR modes; in those modes, the model will render without effects.

    <model-viewer src="...">
      <effect-composer>
        <bloom-effect></bloom-effect>
      </effect-composer>
    </model-viewer>
  6. Install @google/model-viewer-effects via HTML/CDN

    master

    To use the library directly in a browser via CDN, you must use an importmap to provide three to avoid version conflicts between <model-viewer> and <model-viewer-effects>. You should then import the module versions of both <model-viewer> and <model-viewer-effects>.

    <!-- ES-Shims for older browser compatibility -->
    <script async src="https://ga.jspm.io/npm:es-module-shims@2.6.2/dist/es-module-shims.js"></script>
    
    <!-- Import Three.js using an import-map -->
    <script type="importmap">
      {
        "imports": {
          "three": "https://cdn.jsdelivr.net/npm/three@^{{THREEJS_VERSION}}/build/three.module.min.js"
        }
      }
    </script>
    
    <!-- Import model-viewer and model-viewer-effects modules -->
    <script type="module" src="https://cdn.jsdelivr.net/npm/@google/model-viewer/dist/model-viewer-module.min.js"></script>
    <script type="module" src="https://cdn.jsdelivr.net/npm/@google/model-viewer-effects/dist/model-viewer-effects.min.js"></script>