Offsetting the model in canvas without changing perspective

Aperta
#4,993 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 4 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
30/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
three.js, typescript

Direzione di ricerca

Inizia esaminando il comportamento della fotocamera di model-viewer descritto nell’issue e la discussione correlata all’indirizzo https://github.com/google/model-viewer/discussions/4733. Il lavoro è completo quando lo spostamento orizzontale del modello è integrato senza modificare la prospettiva, causare un salto al caricamento o compromettere gli orbit controls, inclusi i casi di zoom e panning indicati.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

In my very specific use case, I had a model view with a specific perspective I could not change, which caused a visually asymmetric alignment. I wanted to offset the model in the canvas to make it look centered initially. I tried many things before finding the working solution I am sharing here. Specifically, I could not find a responsive CSS solution. Also it is quite difficult to trigger a view update without resetting the frame (tried e.g. updateProjectionMatrix, queueRender, requestUpdate, updateBoundingBox... nothing worked). I would like to see a more integrated way to do this. My solution has the issue of showing the model jumping on load, it requires zoom control to be enabled, and i did not test it with panning. But it is minimal, responsive, and preserve user orbit control. BTW, my solution is only for horizontal offset... Replace the .07 with your desired horizontal shift fraction.

Image

<model-viewer onload="align(this, .07)" ...

function align(mv, dx) {
    const scene = mv[Object.getOwnPropertySymbols(mv).find(e => e.description == 'scene')]
    new ResizeObserver(() => {
        scene.camera.filmOffset = scene.camera.getFilmWidth() * dx
        mv.zoom(.001 * Math.sign(mv.zoomSensitivity))  // Trigger a view update without resetting the framing. Requires zoom to not be disabled and not be at maximum zoom-in
    }).observe(mv)
}

Edit: Multiplying by the sign of the zoom sensitivity is for the edge case where you set the zoom sensitivity to be negative and you start at maximum zoom-out

Might be related:
https://github.com/google/model-viewer/discussions/4733

Lingua principale
TypeScript
Stelle
8.4k
Fork
964
Merge medio
5g 11h
PR unite (30g)
8

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di google/model-viewer

Tutte le issue di google/model-viewer

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.