Skip to content

Import a 3D Model and automatically assign and export animations

TypeScript
29.1 KB
Raw Blame
<!doctype html>
<html lang="en">
  <head>
    <title style="display: none">Create - Mesh2Motion</title>
    <link rel="icon" type="image/png" href="./images/favicon.png" />
    <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  </head>
  <body style="margin: 0">
    <script type="module" src="./CustomModelUploadBootstrap.ts"></script>
    <link href="./styles.css" rel="stylesheet" crossorigin="anonymous" />
    <link
      rel="stylesheet"
      href="./radio-button-group.css"
      crossorigin="anonymous"
    />
    <link
      rel="stylesheet"
      href="./animation-player.css"
      crossorigin="anonymous"
    />
    <link rel="stylesheet" href="./dialog.css" crossorigin="anonymous" />
    <link rel="stylesheet" href="./settings-dropdown.css" crossorigin="anonymous" />
    <link rel="stylesheet" href="./offline.css" crossorigin="anonymous" />
    <link rel="stylesheet" href="./lib/processes/animations-listing/props/props.css" crossorigin="anonymous" />


    <nav>
      <div style="display: inline-flex; align-items: center">
        <a id="logo-branding" href="https://mesh2motion.org"
          ><img src="./images/mesh2motion.svg" width="130" alt="Mesh2Motion logo"
        /></a>
        <a href="/">Explore</a>
        <span class="active-nav-item">Use Your Model</span>
        <a href="/retarget/index.html">Use Your Rigged Model</a>
        <a href="/composer/index.html">Remix</a>
      </div>

      <div style="display: inline-flex; align-items: center;">
      <div id="top-nav-links-mount"></div>
      </div>
    </nav>

    <div id="header-ui-mount"></div>

    <div id="tool-panel">
      <!-- create a radio button group. There are two options. Move Skeleton, Rotate Mesh -->
      <div id="tool-selection-group">
        <div style="margin-bottom: 1rem; padding: 0">
          <span id="current-step-label"></span>
        </div>

        <div id="load-model-tools">
          <!-- <p class="step-instructions">Supports GLB, GLTF, FBX</p> -->

          <!-- drop area for the model file. clicking anywhere in it also opens the file picker -->
          <label id="model-drop-zone" for="model-upload">
            <img src="images/icons/upload.svg" alt="" width="28" height="28" />
            <span class="model-drop-zone-subtext">Drop your 3D model here<br/> or click to browse</span>
            <span class="model-drop-zone-subtext">
              GLB, FBX, or ZIP
              <img
                data-tippy-content="GLB and FBX preferred. ZIP is for GLTF+BIN and textures separately. DAE+textures is also supported in ZIP format."
                src="images/icons/help.svg" alt="Help" width="16" height="16" />
            </span>
          </label>
          <input
            id="model-upload"
            type="file"
            name="file-upload"
            accept=".glb, .zip, .fbx"
          />

          <div style="text-align: center; font-size: 1.5rem">or</div>

          <div class="alternate-background-section">
            <p style="margin: 0">Reference model</p>
            <select id="model-selection">
              <option value="models/model-human.glb">Human</option>
              <option value="models/model-fox.glb">Fox</option>
              <option value="models/model-bird.glb">Bird</option>
              <option value="models/model-dragon.glb">Dragon</option>
              <option value="models/model-kaiju.glb">Kaiju</option>
            </select>
            <button id="load-model-button">Load</button>
          </div>

          <div class="styled-checkbox">
            <input
              type="checkbox"
              id="load-model-debug-checkbox"
              name="load-model-debug-checkbox"
            />
            <label for="load-model-debug-checkbox">Debug</label>

            <img 
              data-tippy-content="Replaces all materials with a 'normal' shader for debugging"
              src="images/icons/help.svg" alt="Help" width="20" height="20" />

          </div>
        </div>

        <div id="load-skeleton-tools">

          <span>
            <span style="max-width: 220px"
              >Rotate Model to face front <br />
              (blue origin line)</span
            >
            <div style="display: flex; flex-direction: row">
              <button class="secondary-button" id="rotate-model-x-button">
                X
              </button>
              <button class="secondary-button" id="rotate-model-y-button">
                Y
              </button>
              <button class="secondary-button" id="rotate-model-z-button">
                Z
              </button>
            </div>
          </span>

          <hr />

          <span style="max-width: 220px">
            <span>Position model</span>

            <button
            class="link-button"
            id="analyze-model-link"
          >
            Analyze Import
          </button>

            <div style="display: flex; flex-direction: column; gap: 0.5rem">
              <button class="secondary-button" id="reset-model-position-button">
                Reset position
              </button>
              <button class="secondary-button" id="auto-align-model-button">
                Auto-align to floor
              </button>
            </div>
          </span>

          <hr />

          <div style="display: flex; flex-direction: column; gap: 1rem;">
            <span>Skeleton template</span>
            <select id="skeleton-selection">
              <!-- populated dynamically from RigConfig -->
            </select>
          </div>

          <!-- Hand skeleton options for human skeleton -->
          <div id="hand-skeleton-options" class="alternate-background-section">
            <span style="display: flex; gap: 1rem;">
              <span>Hand Options</span>

              <img data-tippy-content="Variations on which finger bones you want to keep. Single Hand Bone removes all fingers and keeps only the hand bone." src="images/icons/help.svg" alt="Help" width="20" height="20" />

            </span>
            <select id="hand-skeleton-selection">
              <option value="all-fingers">All Fingers</option>
              <option value="thumb-and-index">Thumb + Main Finger</option>
              <option value="simplified-hand">All Fingers - Simplified</option>
              <option value="single-bone">Single Hand Bone</option>
            </select>
          </div>

          <!-- scale skeleton to get it close to the model size -->
          <div id="scale-skeleton-controls" style="display: none; flex-direction: column;">
            <div style="display: flex; flex-direction: row; align-items: center; justify-content: center; gap: 1rem;">
              <label style="display:inline-flex">Scale skeleton</label>

              <img data-tippy-content="Adjust the overall scale of the skeleton" src="images/icons/help.svg" alt="Help" width="20" height="20" />

              <button class="secondary-button" id="reset-skeleton-scale-button">
                <img src="images/icons/reset.svg" alt="Reset Skeleton Scale" width="20" height="20" />
              </button>
            </div>
            <div style="display: flex; flex-direction: row; gap: 1rem; justify-content: flex-start; align-items: center;">
              <span id="scale-skeleton-percentage-display">100%</span>
              <input id="scale-skeleton-input" style="flex-grow: 1;" type="range" min=".10" max="2.00" value="1.0" step="0.01" />
            </div>
          </div>

          <div style="display: flex; gap: 0.5rem;">
            <button class="no-style-button" id="action_back_to_load_model">&#x2039; Back</button>
            <button id="load-skeleton-button">Edit Skeleton &nbsp;&#x203a;</button>
          </div>
        </div>

        <span id="skeleton-step-actions">
          <!-- undo/redo system-->
          <fieldset style="position: fixed; right: 300px; top: 52px;">
            <div style="display: flex; gap: 2px;">
              <button id="undo-button" class="secondary-button" title="Undo (Ctrl+Z)" disabled>
                <img src="images/icons/undo.png" alt="Undo" width="16" height="16" />
              </button>
              <button id="redo-button" class="secondary-button" title="Redo (Ctrl+Y)" disabled>
                <img src="images/icons/redo.png" alt="Redo" width="16" height="16" />
              </button>
            </div>
          </fieldset>

          <!-- reference image for people to see example of rig fitting on a model -->
          <div id="skeleton-template-image" class="skeleton-template-image-clickable">
              <span>See bone reference placement</span>
              <img class="skeleton-template-image-preview ignore-filters" src="images/icons/zoom.svg" alt="" width="16" height="16" />
          </div>

          <!-- posing tips. only shown for the human skeleton -->
          <details id="model-pose-instructions">
            <summary class="model-pose-instructions-heading">Using A-Pose Character?</summary>
            <ol>
              <li>Set Positioning to <strong>Transform Widget</strong></li>
              <li>Choose the <strong>Rotation</strong> transform</li>
              <li>Select each shoulder / upper arm bone and rotate it down to line up with the arm</li>
            </ol>
          </details>

          <div style="display: flex; flex-direction: column;">
            
            <div class="pill-switch-group" aria-label="Positioning mode">
              <span class="pill-switch-label">Positioning</span>
              <div class="pill-switch">
                <input type="radio" id="mesh-drag-placement" name="positioning-mode" value="mesh-volume" checked />
                <label for="mesh-drag-placement">Mesh volume</label>

                <input type="radio" id="mesh-manual-placement" name="positioning-mode" value="manual" />
                <label for="mesh-manual-placement">Transform Widget</label>
              </div>
            </div>

            <div id="transform-manual-options" style="display: flex; flex-direction: row;">
              <fieldset>
                <span>Transform</span>
                <div id="transform-control-type-group" class="toggle">
                  <input type="radio" name="transform-control-type" value="translate" id="transform-translate" checked="checked" />
                  <label for="transform-translate">
                    <img src="images/icons/tool-move.svg" alt="Translate" width="20" height="20" title="Translation" />
                  </label>
                  <input type="radio" name="transform-control-type" value="rotation" id="transform-rotate" />
                  <label for="transform-rotate">
                    <img src="images/icons/tool-rotate.svg" alt="Rotate" width="20" height="20" title="Rotation" />
                  </label>
                </div>
              </fieldset>
              <fieldset>
                <span>Space</span>
                <div id="transform-space-group" class="toggle">
                  <input type="radio" name="transform-space" value="global" id="transform-global" checked="checked" />
                  <label for="transform-global">
                    <img src="images/icons/tool-global.svg" alt="Global" width="20" height="20" title="Global" />
                  </label>
                  <input type="radio" name="transform-space" value="local" id="transform-local" />
                  <label for="transform-local">
                    <img src="images/icons/tool-local.svg" alt="Local" width="20" height="20" title="Local" />
                  </label>
                </div>
              </fieldset>
            </div>
          </div>

          <div class="pill-switch-group" aria-label="Move Bone Children">
            <span class="pill-switch-label">Move Bone Children</span>
            <div id="independent-bone-movement-group" class="pill-switch">
              <input type="radio" id="independent-bone-movement" name="independent-bone-movement" value="yes" checked />
              <label for="independent-bone-movement">Yes</label>

              <input type="radio" id="independent-bone-movement-no" name="independent-bone-movement" value="no" />
              <label for="independent-bone-movement-no">No</label>
            </div>
          </div>

          <div class="pill-switch-group" aria-label="Preview Display">
            <span class="pill-switch-label">Preview Display</span>
            <div id="mesh-preview-group" class="pill-switch">
              <input id="preview-painted" type="radio" name="mesh-preview-type" value="weight-painted" />
              <label for="preview-painted" title="Weight painted mesh">Weights</label>
              <input id="preview-textured" type="radio" name="mesh-preview-type" value="textured" checked="checked" />
              <label for="preview-textured" title="Textured mesh">Textured</label>
            </div>
          </div>

          <details id="weight-painting-tools" style="max-width: 280px;" hidden>
            <summary>Weight painting</summary>
            <p><small>Paint weights on the colored mesh. Painted vertices override the automatic weights and are kept when binding and exporting. Use Add to strengthen a bone, Subtract to remove it, and Smooth to blend a vertex with its neighbours and soften steps around joints. Mirror L/R applies the stroke to the matching bone on the opposite side.</small></p>
            <button id="weight-paint-toggle" type="button" aria-pressed="false">Start painting</button>
            <div style="display: flex; flex-direction: column; gap: 0.5rem; margin-top: 0.5rem;">
              <label for="weight-paint-bone">Bone</label>
              <select id="weight-paint-bone"></select>

              <div class="pill-switch-group" aria-label="Weight paint mode" style="margin: 0;">
                <span class="pill-switch-label">Brush</span>
                <div class="pill-switch">
                  <input type="radio" id="weight-paint-add" name="weight-paint-mode" value="add" checked />
                  <label for="weight-paint-add">Add</label>
                  <input type="radio" id="weight-paint-subtract" name="weight-paint-mode" value="subtract" />
                  <label for="weight-paint-subtract">Subtract</label>
                  <input type="radio" id="weight-paint-smooth" name="weight-paint-mode" value="smooth" />
                  <label for="weight-paint-smooth">Smooth</label>
                </div>
              </div>

              <label for="weight-paint-radius">Brush size</label>
              <input id="weight-paint-radius" type="range" min="4" max="160" step="1" value="24" />
              <label for="weight-paint-strength">Strength</label>
              <input id="weight-paint-strength" type="range" min="0.05" max="1" step="0.05" value="0.5" />

              <div style="display: flex; gap: 0.5rem;">
                <button id="weight-paint-undo" type="button" disabled>Undo stroke</button>
                <button id="weight-paint-clear" type="button" disabled>Clear all</button>
              </div>

              <div class="styled-checkbox">
                <input type="checkbox" id="weight-paint-mirror" checked />
                <label for="weight-paint-mirror">Mirror L/R</label>
              </div>
            </div>
          </details>

          <div class="styled-checkbox">
            <input type="checkbox" id="enable-weight-paint-step" />
            <label for="enable-weight-paint-step">Add weight painting step</label>

            <img data-tippy-content="Adds an optional step after posing the bones where you can paint weights while testing a couple of animations." src="images/icons/help.svg" alt="Help" width="20" height="20" />
          </div>

          <div class="styled-checkbox">
            <input type="checkbox" id="mirror-skeleton" name="mirror-skeleton" value="mirror" checked>
            <label for="mirror-skeleton">Mirror Left/Right Joints</label>
          </div>



          <!-- Preview plane controls -->
          <div id="use-head-weight-correction-container" style="display: flex; flex-direction: column; gap: 0.5rem;">
            <div class="styled-checkbox">
              <input type="checkbox" id="preview-plane-checkbox" />
              <label for="preview-plane-checkbox">Use Head Weight Correction</label>

              <img data-tippy-content="If you are having issues with the arms distorting your head (e.g. chibi characters), use a divider to help define the head area." src="images/icons/help.svg" alt="Help" width="20" height="20" />

            </div>
            <div id="preview-plane-setting-container" style="display: flex; align-items: center; gap: 0.5rem;">
              <label for="preview-plane-height-input">Height:</label>
              <input type="range" id="preview-plane-height-input" min="0.20" max="2.00" step="0.01" value="0.50" />
              <span id="preview-plane-height-label" style="width: 2rem;">0.50</span>
            </div>

          </div>

          <!-- back to load skeleton -->
          <div class="display: flex; gap: 0.5rem;">
            <button class="no-style-button" id="action_back_to_load_skeleton">&#x2039; Back</button>
            <button id="action_bind_pose">Bind pose</button>
          </div>
        </span>

        <!-- <span id="skinned-step-tools">
                <p class="step-instructions">Select animations you want to export by checking them by animation</p>
            </span> -->

        <span id="weight-paint-step-tools" style="display: none; flex-direction: column; max-width: 320px;">
          <div style="display: flex; align-items: center; gap: 0.5rem; margin: 0 0 0.75rem;">
            <div class="pill-switch-group" aria-label="Weight painting mode" style="margin: 0;">
              <div class="pill-switch">
                <input type="radio" id="weight-paint-mode-paint" name="weight-paint-step-view-mode" value="paint" checked />
                <label for="weight-paint-mode-paint">Paint</label>

                <input type="radio" id="weight-paint-mode-test" name="weight-paint-step-view-mode" value="test" />
                <label for="weight-paint-mode-test">Test</label>
              </div>
            </div>

            <button id="weight-paint-step-reset" class="secondary-button" type="button" disabled
              aria-label="Reset weights to auto"
              data-tippy-content="Reset weights to auto: restore the automatic weights from skinning and remove all manual painting">
              <img src="images/icons/reset.svg" alt="" width="20" height="20" />
            </button>
          </div>

          <span id="weight-paint-paint-tools" style="display: flex; flex-direction: column; gap: 0.75rem;">
            <fieldset style="position: fixed; right: 300px; top: 52px;">
              <div style="display: flex; gap: 2px;">
                <button id="weight-paint-step-undo" class="secondary-button" title="Undo (Ctrl+Z)" disabled>
                  <img src="images/icons/undo.png" alt="Undo" width="16" height="16" />
                </button>
                <button id="weight-paint-step-redo" class="secondary-button" title="Redo (Ctrl+Y)" disabled>
                  <img src="images/icons/redo.png" alt="Redo" width="16" height="16" />
                </button>
              </div>
            </fieldset>

            <div style="display: flex; flex-direction: column; gap: 0.35rem;">
              <span class="weight-paint-tools-heading">Select Bone</span>
              <div style="display: flex; align-items: center; gap: 0.5rem;">
                <button id="weight-paint-step-pick-bone" class="secondary-button" type="button" aria-pressed="false"
                  aria-label="Pick a bone by clicking the model"
                  data-tippy-content="Pick a bone by clicking the model. Shortcut: Shift + click on the model.">
                  <img src="images/icons/color-picker.svg" alt="" width="20" height="20" />
                </button>
                <select id="weight-paint-step-bone-name" class="weight-paint-bone-name" aria-label="Bone"></select>
              </div>
            </div>

            <hr style="width: 100%; margin: 0;" />

            <div class="pill-switch-group" aria-label="Weight brush mode" style="margin: 0;"
              data-tippy-content="Brush mode. Shortcut: X">
              <div class="pill-switch">
                <input type="radio" id="weight-paint-step-add" name="weight-paint-step-mode" value="add" checked />
                <label for="weight-paint-step-add">Add</label>

                <input type="radio" id="weight-paint-step-subtract" name="weight-paint-step-mode" value="subtract" />
                <label for="weight-paint-step-subtract">Remove</label>

                <input type="radio" id="weight-paint-step-smooth" name="weight-paint-step-mode" value="smooth" />
                <label for="weight-paint-step-smooth">Smooth</label>
              </div>
            </div>

            <div class="weight-paint-slider-row">
              <label for="weight-paint-step-radius">Brush size</label>
              <input id="weight-paint-step-radius" type="range" min="4" max="160" step="1" value="24" />
              <span id="weight-paint-step-radius-value">24 px</span>
            </div>

            <div class="weight-paint-slider-row">
              <label for="weight-paint-step-strength">Strength</label>
              <input id="weight-paint-step-strength" type="range" min="0.05" max="1" step="0.05" value="0.5" />
              <span id="weight-paint-step-strength-value">50%</span>
            </div>

            <hr style="width: 100%; margin: 0;" />

            <div class="styled-checkbox">
              <input type="checkbox" id="weight-paint-step-mirror" checked />
              <label for="weight-paint-step-mirror">Mirror L/R</label>
            </div>

            <div class="styled-checkbox">
              <input type="checkbox" id="weight-paint-step-wireframe" checked />
              <label for="weight-paint-step-wireframe">Show wireframe</label>
            </div>
          </span>

          <span id="weight-paint-test-tools" style="display: none; flex-direction: column; gap: 0.75rem;">
            <div id="weight-paint-step-animation-list" class="weight-paint-animation-list"></div>

            <div style="display: flex; align-items: center; gap: 0.5rem;">
              <label for="weight-paint-step-speed">Speed</label>
              <select id="weight-paint-step-speed" style="flex: 1;">
                <option value="0.1">0.1x</option>
                <option value="0.25">0.25x</option>
                <option value="0.5">0.5x</option>
                <option value="1" selected>1x</option>
                <option value="1.5">1.5x</option>
                <option value="2">2x</option>
              </select>
            </div>
            <span id="weight-paint-step-animation-status" style="font-size: 0.85rem;"></span>
          </span>

          <div style="display: flex; gap: 0.5rem; margin-top: 1rem;">
            <button class="no-style-button" id="action_back_to_edit_skeleton_from_weight_paint">&#x2039; Back</button>
            <button id="action_continue_to_animations">Continue &nbsp;&#x203a;</button>
          </div>
        </span>

        <span id="skinned-step-animation-export-options">
          <div id="animations-listing">
            <!-- Filter textbox and tab switcher side by side -->
            <div style="display: flex; gap: 1rem; align-items: flex-start;">
                <!-- Tab switcher for Library vs Selected animations -->
                <div class="pill-switch-group" aria-label="Animation view mode" style="margin: 0;">
                    <div class="pill-switch">
                        <input type="radio" id="animation-view-library" name="animation-view-mode" value="library" checked />
                        <label for="animation-view-library">Library</label>
                        <input type="radio" id="animation-view-selected" name="animation-view-mode" value="selected" />
                        <label for="animation-view-selected">Selected</label>
                    </div>
                </div>

                <!-- Filter textbox for animations -->
                <span style="position: relative; flex: 1;">
                    <input type="text" id="animation-filter" placeholder="Filter">
                </span>
            </div>

            <!-- Select all / Deselect all button and animation count -->
            <div id="toggle-select-all-container">
                <button id="toggle-select-all-animations" class="secondary-button">Select All</button>
                <button id="animation-tag-filter-button" class="secondary-button" data-tippy-content="Filter by tag" aria-label="Filter by tag" style="display: none">
                    <img src="images/icons/tag.svg" alt="" width="20" height="20" />
                    <span id="animation-tag-filter-count" style="display: none">0</span>
                </button>
                <div id="animation-listing-count" style="white-space: nowrap;">0 animations</div>
            </div>


            <!-- loading progress when animations start getting larger. -->
            <div id="animation-progress-loader-container" style="display: none">
              <div id="loading-status-text">Loading animation data</div>
              <div id="loading-progress-bar"></div>
              <div id="current-file-progress-bar"></div>
            </div>

            <!-- javascript will populate this item with animations
                         that we get from the animations file(s)  -->
            <div id="animations-items" class="create-page"></div>

            <!-- slider to control arm extension. shared with the retarget workflow -->
            <div id="arm-extension-mount"></div>

            <div class="download-actions-row">
              <button class="no-style-button" id="action_back_to_edit_skeleton">
                &#x2039; Back
              </button>

              <!-- testing the mirroring options. Hide this for now until we get a better implementation for per animations -->
              <div style="display: none" class="styled-checkbox icon-toggle">
                <input
                  type="checkbox"
                  id="mirror-animations-checkbox"
                  name="mirror-animations"
                  value="true"
                  style="display: none"
                />
                <label
                  for="mirror-animations-checkbox"
                  data-tippy-content="Mirror animations"
                  tabindex="0"
                >
                  <img
                    class="action-icon"
                    src="images/icons/mirror.svg"
                    alt="Mirror animations"
                  />
                </label>
              </div>

              <button
                class="secondary-button"
                id="import-animations-button"
                data-tippy-content="Import GLB or FBX animations. Mesh2Motion rigs are supported, and Mixamo animations can be retargeted onto the Human rig."
                aria-label="Import GLB or FBX animations. Mesh2Motion rigs are supported, and Mixamo animations can be retargeted onto the Human rig."
              >

              <img src="images/icons/upload.svg" alt="Upload" width="16" height="16" />

              </button>
              <input
                id="import-animations-input"
                type="file"
                accept=".glb,.fbx"
                multiple
                style="display: none"
              />

              <div id="download-control-mount"></div>
            </div>
          </div>
        </span>
      </div>
    </div>
    <!-- end tool-panel-->

    <!-- floating props toggle and panel docked to the left of the tool panel -->
    <div id="props-dock" style="display: none">
      <button
        class="secondary-button"
        id="props-toggle-button"
        aria-expanded="false"
        aria-controls="props-panel"
        data-tippy-content="Attach props to the hands"
        aria-label="Attach props to the hands"
      >
        <img src="images/icons/props.svg" alt="Props" width="32" height="32" />
        Props
      </button>
      <div id="props-panel" class="props-panel" role="region" aria-label="Props" hidden>
        <div id="props-left-hand" class="prop-picker"></div>
        <div id="props-right-hand" class="prop-picker"></div>
        <button
          class="secondary-button"
          id="props-close-button"
          data-tippy-content="Close props"
          aria-label="Close props"
        >
          <img src="images/icons/props.svg" alt="" width="32" height="32" />
          Props
        </button>
      </div>
    </div>

    <div id="animation-player-mount"></div>

    <!-- 3d view controls shown on bottom right. This helps with click events -->
    <div id="view-control-hitbox"></div>

    <!-- large overlay banner showing the currently selected bone while editing the skeleton -->
    <div id="selected-bone-overlay">
      <span class="selected-bone-overlay-chip">
        <span class="selected-bone-overlay-label">Selected Bone</span> 
        <span id="selected-bone-overlay-text"></span>
      </span>
    </div>

    <!-- fixed-size outline that follows the pointer while painting weights -->
    <div id="weight-paint-brush-cursor" aria-hidden="true"></div>

    <!-- build version information-->
    <span id="build-version"></span>
  </body>
</html>